src/native/globalshortcut/net_java_sip_communicator_impl_globalshortcut_NativeKeyboardHook.cc
/**
 * \brief X11 event loop thread entry point.
 * \param arg thread argument
 * \return NULL
 */
\brief X11 event loop thread entry point.
\param arg thread argument
\return NULL
\ brief X11 event loop thread entry point . \ param arg thread argument \ return NULL
static void* x11_event_loop_thread(void* arg)
{
  struct keyboard_hook* keyboard = (struct keyboard_hook*)arg;
  keystrok activeHotKey;
  bool hotKeyActivated = false;
  XSelectInput(keyboard->display, keyboard->root, KeyPressMask | KeyReleaseMask);
  while(keyboard->running)
  {
    XEvent ev, next_ev;
    while(XCheckMaskEvent(keyboard->display, 0xFFFFFFFF, &ev))
    {
      switch (ev.type)
      {
        case KeyPress:
        case KeyRelease:
          for(std::list<keystrok>::iterator it = keyboard->keystrokes.begin() ; it != keyboard->keystrokes.end() ; ++it)
          {
            keystrok& ks = (*it);
            XKeyEvent* keyEvent = (XKeyEvent*)&ev.xkey;
            unsigned long keycode = -1;
            XLookupString(keyEvent, NULL, 0, &keycode, NULL);
            keycode = convertX11KeycodeToJava(keycode);
            int modifiers = X11ModifiersToJavaUserDefined(keyEvent->state);
            if(ks.vkcode == keycode && ks.modifiers == modifiers)
            {
			  if(ev.type == KeyRelease)
			  {
				if(hotKeyActivated && activeHotKey.vkcode == keycode && activeHotKey.modifiers == modifiers)
				{
					if(XEventsQueued(keyboard->display, QueuedAfterReading))
					{
						XPeekEvent(keyboard->display, &next_ev);
						if(next_ev.type == KeyPress
						     && next_ev.xkey.time == keyEvent->time
							 && next_ev.xkey.keycode == keyEvent->keycode
							 && next_ev.xkey.state == keyEvent->state)
						{
							XCheckMaskEvent(keyboard->display, 0xFFFFFFFF, &ev);
							continue;
						}
					}
					hotKeyActivated = false;
				}
			    if(!ks.onrelease)
			    {
				  continue;
			    }
			  }
			  else
			  {
				hotKeyActivated = true;
			    activeHotKey = *it;
			  }
              notify(keyboard, ks.vkcode, ks.modifiers, (ev.type == KeyRelease));
            }
          }
          break;
        default:
          break;
      }
    }
    for(std::list<keystrok>::iterator it = keyboard->keystrokes.begin() ; it != keyboard->keystrokes.end() ; ++it)
    {
      keystrok& ks = (*it);
      if(ks.active == 0)
      {
        int x11Keycode = convertJavaKeycodeToX11(ks.vkcode);
        if(x11Keycode != -1)
        {
          x11Keycode = XKeysymToKeycode(keyboard->display, x11Keycode);
        }
        else
        {
          printf("failed\n");fflush(stdout);
          ks.active = -1;
          continue;
        }
        int x11Modifiers = JavaUserDefinedModifiersToX11(ks.modifiers);
        ks.active = 1;
        if(XGrabKey(keyboard->display, x11Keycode, x11Modifiers, keyboard->root, False, GrabModeAsync, GrabModeAsync) > 1)
        {
          fprintf(stderr, "[LOOP] Error when XGrabKey\n");fflush(stderr);
          ks.active = -1;
        }
      }
      else if(ks.active == -1)
      {
        int x11Keycode = XKeysymToKeycode(keyboard->display, 
            convertJavaKeycodeToX11(ks.vkcode));
        int x11Modifiers = JavaUserDefinedModifiersToX11(ks.modifiers);
        if(XUngrabKey(keyboard->display, x11Keycode, x11Modifiers, keyboard->root) > 1)
        {
          fprintf(stderr, "[LOOP] Error when XUngrabKey\n");fflush(stderr);
        }
        it = keyboard->keystrokes.erase(it)--;
      }
    }
    usleep(1000 * 1000);
    pthread_yield();
  }
  return NULL;
}
static void * x11_event_loop_thread ( void * arg ) { struct keyboard_hook * keyboard = ( struct keyboard_hook * ) arg ; keystrok activeHotKey ; bool hotKeyActivated = false ; XSelectInput ( keyboard -> display , keyboard -> root , KeyPressMask | KeyReleaseMask ) ; while ( keyboard -> running ) { XEvent ev , next_ev ; while ( XCheckMaskEvent ( keyboard -> display , 0xFFFFFFFF , & ev ) ) { switch ( ev . type ) { case KeyPress : case KeyRelease : for ( std :: list < keystrok > :: iterator it = keyboard -> keystrokes . begin ( ) ; it != keyboard -> keystrokes . end ( ) ; ++ it ) { keystrok & ks = ( * it ) ; XKeyEvent * keyEvent = ( XKeyEvent * ) & ev . xkey ; unsigned long keycode = -1 ; XLookupString ( keyEvent , NULL , 0 , & keycode , NULL ) ; keycode = convertX11KeycodeToJava ( keycode ) ; int modifiers = X11ModifiersToJavaUserDefined ( keyEvent -> state ) ; if ( ks . vkcode == keycode && ks . modifiers == modifiers ) { if ( ev . type == KeyRelease ) { if ( hotKeyActivated && activeHotKey . vkcode == keycode && activeHotKey . modifiers == modifiers ) { if ( XEventsQueued ( keyboard -> display , QueuedAfterReading ) ) { XPeekEvent ( keyboard -> display , & next_ev ) ; if ( next_ev . type == KeyPress && next_ev . xkey . time == keyEvent -> time && next_ev . xkey . keycode == keyEvent -> keycode && next_ev . xkey . state == keyEvent -> state ) { XCheckMaskEvent ( keyboard -> display , 0xFFFFFFFF , & ev ) ; continue ; } } hotKeyActivated = false ; } if ( ! ks . onrelease ) { continue ; } } else { hotKeyActivated = true ; activeHotKey = * it ; } notify ( keyboard , ks . vkcode , ks . modifiers , ( ev . type == KeyRelease ) ) ; } } break ; default : break ; } } for ( std :: list < keystrok > :: iterator it = keyboard -> keystrokes . begin ( ) ; it != keyboard -> keystrokes . end ( ) ; ++ it ) { keystrok & ks = ( * it ) ; if ( ks . active == 0 ) { int x11Keycode = convertJavaKeycodeToX11 ( ks . vkcode ) ; if ( x11Keycode != -1 ) { x11Keycode = XKeysymToKeycode ( keyboard -> display , x11Keycode ) ; } else { printf ( " \n " ) ; fflush ( stdout ) ; ks . active = -1 ; continue ; } int x11Modifiers = JavaUserDefinedModifiersToX11 ( ks . modifiers ) ; ks . active = 1 ; if ( XGrabKey ( keyboard -> display , x11Keycode , x11Modifiers , keyboard -> root , False , GrabModeAsync , GrabModeAsync ) > 1 ) { fprintf ( stderr , " \n " ) ; fflush ( stderr ) ; ks . active = -1 ; } } else if ( ks . active == -1 ) { int x11Keycode = XKeysymToKeycode ( keyboard -> display , convertJavaKeycodeToX11 ( ks . vkcode ) ) ; int x11Modifiers = JavaUserDefinedModifiersToX11 ( ks . modifiers ) ; if ( XUngrabKey ( keyboard -> display , x11Keycode , x11Modifiers , keyboard -> root ) > 1 ) { fprintf ( stderr , " \n " ) ; fflush ( stderr ) ; } it = keyboard -> keystrokes . erase ( it ) -- ; } } usleep ( 1000 * 1000 ) ; pthread_yield ( ) ; } return NULL ; }
\brief X11 event loop thread entry point.
\ brief X11 event loop thread entry point .
//XKeycodeToKeysym(keyboard->display, keyEvent->keycode, 1);
 //disable the autorepeat event from the queue and continue with next messages
 /* hotkey to add */ /* hotkey to remove */