コード例 #1
0
static gboolean
handle_io (GIOChannel *source,
           GIOCondition condition,
           gpointer data) 
{
  SpiDEController *controller = (SpiDEController *) data;
    DEControllerPrivateData *priv = controller->priv;
  gboolean is_consumed = FALSE;
  XEvent ev;

  while (XCheckIfEvent(priv->xevie_display, &ev, isEvent, NULL))
    {
      if (ev.type == KeyPress || ev.type == KeyRelease)
        is_consumed = spi_device_event_controller_forward_key_event (controller, &ev);

      if (! is_consumed)
        XevieSendEvent(priv->xevie_display, &ev, XEVIE_UNMODIFIED);
    }

  return TRUE;
}
コード例 #2
0
void handle_x_event ( XEvent& event, 
		      GtkWidget* label )
{
    KeySym key;

    char completion_string_c[BUFSIZ];
    int completion_word_index = 0;
    int completion_flag = FALSE;

        switch(event.type) {
          case KeyPress:
            key = get_keysym(&event);

            if((isalpha(key) || isspace(key) || ispunct(key) || key == XK_BackSpace) && key < 256){
                XevieSendEvent(dpy, &event, XEVIE_UNMODIFIED);
                get_prediction(tolower(key), completion_string_c, FALSE, label);
                
                
                if(((key == ',') ||
                    (key == '.') ||
                    (key == '?') ||
                    (key == ';') ||
                    (key == ':')) && 
                   (completion_word_index == 0) && 
                   (completion_flag == TRUE)) {
					
                    event.xkey.keycode = XKeysymToKeycode(dpy, XK_BackSpace);
                    event.type = KeyPress; 
                    XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event);
                    event.type = KeyRelease;
                    XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event);
           
                    event.type = KeyPress; 
                    XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event);
                    event.type = KeyRelease;
                    XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event);
                    
                    event.xkey.keycode = XKeysymToKeycode(dpy, key);
                    event.type = KeyPress; 
                    XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event);
                    event.type = KeyRelease;
                    XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event);
                
                    event.xkey.keycode = XKeysymToKeycode(dpy, XK_space);
                    event.type = KeyPress; 
                    XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event);
                    event.type = KeyRelease;
                    XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event);
                }

                else if(isspace(key)) completion_word_index = 0;
                else completion_word_index++;
                
                completion_flag = FALSE;
            }
            
            // check for function keys
            else if(((key - XK_F1) >= 0) && ((key - XK_F1) <= no_suggestions-1)) {
            	
            	// inform presage that the prediction was successful.
               	// and ask presage to predict next token
	      get_prediction(tolower(key), completion_string_c, TRUE, label);
               
                char s[64];
                printf("%d\n", completion_word_index  );
                //  send the rest of the completion string and a ' ' to the client 
                while(completion_string_c[completion_word_index] != '\0'){               	
                    s[0] = completion_string_c[completion_word_index];
                    s[1] = '\0';
                    
                    event.xkey.keycode = XKeysymToKeycode(dpy, XStringToKeysym(s));               
                    event.type = KeyPress; 
                    XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event);
                    event.type = KeyRelease;
                    XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event);
               		
                    event.xkey.time++;
                          
                    completion_word_index++;
                }
                completion_word_index = 0;
                completion_flag = TRUE;
                
                event.xkey.keycode = XKeysymToKeycode(dpy, XK_space);
                event.type = KeyPress;
                XSendEvent(dpy, InputFocus, TRUE, KeyPressMask, &event);
                event.type = KeyRelease;
                XSendEvent(dpy, InputFocus, TRUE, KeyReleaseMask, &event);
            }
            else {   			
            	// anything else just send it to the client
            	XevieSendEvent(dpy, &event, XEVIE_UNMODIFIED);
                completion_word_index = 0;
                completion_flag = FALSE;
            }
            break;
            
          case KeyRelease:    			
            XevieSendEvent(dpy, &event, XEVIE_UNMODIFIED);
            break;
            
          default: 
            printf(" unknown event %x\n", event.type); 
            break;   
    	}
}