src/core/linux/SDL_ibus.c
changeset 9096 6454f71d6f15
parent 9095 ed277c1c9e7f
child 9097 56d712662a82
     1.1 --- a/src/core/linux/SDL_ibus.c	Tue Aug 19 22:28:53 2014 +0100
     1.2 +++ b/src/core/linux/SDL_ibus.c	Tue Aug 19 23:17:28 2014 +0100
     1.3 @@ -45,7 +45,7 @@
     1.4  static SDL_Rect ibus_cursor_rect = {0};
     1.5  static DBusConnection *ibus_conn = NULL;
     1.6  static char *ibus_addr_file = NULL;
     1.7 -int inotify_fd = -1;
     1.8 +int inotify_fd = -1, inotify_wd = -1;
     1.9  
    1.10  static Uint32
    1.11  IBus_ModState(void)
    1.12 @@ -166,8 +166,6 @@
    1.13                  i += sz;
    1.14                  cursor += chars;
    1.15              }
    1.16 -        } else {
    1.17 -            SDL_SendEditingText("", 0, 0);
    1.18          }
    1.19          
    1.20          SDL_IBus_UpdateTextRect(NULL);
    1.21 @@ -175,6 +173,11 @@
    1.22          return DBUS_HANDLER_RESULT_HANDLED;
    1.23      }
    1.24      
    1.25 +    if(dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "HidePreeditText")){
    1.26 +    	SDL_SendEditingText("", 0, 0);
    1.27 +    	return DBUS_HANDLER_RESULT_HANDLED;
    1.28 +    }
    1.29 +    
    1.30      return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    1.31  }
    1.32  
    1.33 @@ -360,7 +363,7 @@
    1.34          dbus->connection_flush(ibus_conn);
    1.35      }
    1.36  
    1.37 -    SDL_IBus_SetFocus(SDL_GetFocusWindow() != NULL);
    1.38 +    SDL_IBus_SetFocus(SDL_GetKeyboardFocus() != NULL);
    1.39      SDL_IBus_UpdateTextRect(NULL);
    1.40      
    1.41      return result;
    1.42 @@ -375,7 +378,7 @@
    1.43          return SDL_TRUE;
    1.44      }
    1.45      
    1.46 -    if(inotify_fd != -1){
    1.47 +    if(inotify_fd > 0 && inotify_wd > 0){
    1.48          char buf[1024];
    1.49          ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
    1.50          if(readsize > 0){
    1.51 @@ -428,15 +431,17 @@
    1.52          
    1.53          char *addr = IBus_ReadAddressFromFile(addr_file);
    1.54          
    1.55 -        inotify_fd = inotify_init();
    1.56 -        fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
    1.57 +        if(inotify_fd < 0){
    1.58 +            inotify_fd = inotify_init();
    1.59 +            fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
    1.60 +        }
    1.61          
    1.62          char *addr_file_dir = SDL_strrchr(addr_file, '/');
    1.63          if(addr_file_dir){
    1.64              *addr_file_dir = 0;
    1.65          }
    1.66          
    1.67 -        inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
    1.68 +        inotify_wd = inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
    1.69          SDL_free(addr_file);
    1.70          
    1.71          result = IBus_SetupConnection(dbus, addr);
    1.72 @@ -466,6 +471,11 @@
    1.73          dbus->connection_unref(ibus_conn);
    1.74      }
    1.75      
    1.76 +    if(inotify_fd > 0 && inotify_wd > 0){
    1.77 +        inotify_rm_watch(inotify_fd, inotify_wd);
    1.78 +        inotify_wd = -1;
    1.79 +    }
    1.80 +    
    1.81      SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect));
    1.82  }
    1.83  
    1.84 @@ -548,7 +558,7 @@
    1.85          SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
    1.86      }
    1.87      
    1.88 -    SDL_Window *focused_win = SDL_GetFocusWindow();
    1.89 +    SDL_Window *focused_win = SDL_GetKeyboardFocus();
    1.90  
    1.91      if(!focused_win) return;
    1.92