void KGlobalAccel::setItemEnabled( const char * action, bool activate ) { debug("KGlobalAccel::setItemEnabled"); KKeyEntry *pEntry = aKeyDict[ action ]; if ( !pEntry ) { QString str; str.sprintf( "KGlobalAccel : cannont enable action %s"\ "which is not in the object dictionary", action ); warning( str ); return; } if ( pEntry->bEnabled == activate ) return; if ( pEntry->aCurrentKeyCode == 0 ) return; uint keysym = keyToXSym( pEntry->aCurrentKeyCode ); uint mod = keyToXMod( pEntry->aCurrentKeyCode ); if ( keysym == NoSymbol ) return; if ( !pEntry->bEnabled ) { pEntry->bEnabled = grabKey( keysym, mod ); } else { ungrabKey( keysym, mod ); pEntry->bEnabled = false; } return; }
/** * Initialize X connection, establish grab. */ Display* initX(const char* keyName, int keyModifier, int* keyCode) { KeySym sym = XStringToKeysym(keyName); if (sym == NoSymbol) { fprintf(stderr, "ERROR: Unknown key: %s\n", keyName); exit(2); } Display* display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "ERROR: Could not open display.\n"); exit(3); } *keyCode = XKeysymToKeycode(display, sym); Window rootWindow = DefaultRootWindow(display); initMasks(display); Bool detectableAutoRepeatSupported; XkbSetDetectableAutoRepeat(display, True, &detectableAutoRepeatSupported); if (!detectableAutoRepeatSupported) { fprintf(stderr, "ERROR: Detectable auto repeat is not supported.\n"); exit(4); } // Grab grabKey(display, rootWindow, *keyCode, keyModifier); // Enable events XAllowEvents(display, AsyncBoth, CurrentTime); XSelectInput(display, rootWindow, KeyPressMask | KeyReleaseMask); return display; }
void App::setDoGrab(bool doGrab) { if (m_doGrab != doGrab) {; if (doGrab) { grabKey(); } else { ungrabKey(); } m_doGrab = doGrab; } }
void App::setTriggerKeys(QList< TriggerKey > triggersList) { if (m_doGrab) { ungrabKey(); } m_triggersList = triggersList; if (m_doGrab) { grabKey(); } }
bool KGlobalAccel::setKeyDict( QDict<KKeyEntry> nKeyDict ) { // ungrab all connected and enabled keys QDictIterator<KKeyEntry> *aKeyIt = new QDictIterator<KKeyEntry>( aKeyDict ); aKeyIt->toFirst(); #define pE aKeyIt->current() while( pE ) { QString s; if ( pE->bEnabled ) { uint keysym = keyToXSym( pE->aCurrentKeyCode ); uint mod = keyToXMod( pE->aCurrentKeyCode ); ungrabKey( keysym, mod ); } ++*aKeyIt; } #undef pE // Clear the dictionary aKeyDict.clear(); // Insert the new items into the dictionary and reconnect if neccessary // Note also swap config and current key codes !!!!!! aKeyIt = new QDictIterator<KKeyEntry>( nKeyDict ); aKeyIt->toFirst(); #define pE aKeyIt->current() KKeyEntry *pEntry; while( pE ) { pEntry = new KKeyEntry; aKeyDict.insert( aKeyIt->currentKey(), pEntry ); pEntry->aDefaultKeyCode = pE->aDefaultKeyCode; // Not we write config key code to current key code !! pEntry->aCurrentKeyCode = pE->aConfigKeyCode; pEntry->aConfigKeyCode = pE->aConfigKeyCode; pEntry->bConfigurable = pE->bConfigurable; pEntry->aAccelId = pE->aAccelId; pEntry->receiver = pE->receiver; pEntry->member = new QString( pE->member->data() ); pEntry->bEnabled = pE->bEnabled; if ( pEntry->bEnabled ) { uint keysym = keyToXSym( pEntry->aCurrentKeyCode ); uint mod = keyToXMod( pEntry->aCurrentKeyCode ); grabKey( keysym, mod ); } ++*aKeyIt; } #undef pE return true; }
void myScreenGrabKeys (ScreenInfo *screen_info) { Display *dpy; int i; TRACE ("entering myScreenUnrabKeys"); g_return_if_fail (screen_info != NULL); dpy = myScreenGetXDisplay (screen_info); for (i = FIRST_KEY; i < KEY_COUNT; i++) { grabKey (dpy, &screen_info->params->keys[i], screen_info->xroot); } }
static void grab_key(Icon *icon) { MyKey *hash_key; int *count; g_return_if_fail(icon != NULL); g_return_if_fail(g_list_find(icon_shortcuts, icon) == NULL); if (!icon->shortcut_key.keycode) return; icon_shortcuts = g_list_prepend(icon_shortcuts, icon); if (!grab_counter) grab_counter = g_hash_table_new_full(mykey_hash, mykey_cmp, g_free, NULL); count = g_hash_table_lookup(grab_counter, &icon->shortcut_key); if (count) { (*count)++; return; /* Already grabbed */ } hash_key = g_new(MyKey, 1); *hash_key = icon->shortcut_key; count = g_new(int, 1); *count = 1; g_hash_table_insert(grab_counter, hash_key, count); if (!grabKey(&icon->shortcut_key)) g_warning("Failed to grab shortcut '%s' for '%s' icon.\n" "Some other application may be already using it!\n", icon->shortcut, icon->item->leafname); }
void KGlobalAccel::readSettings() { QString s; KConfig *pConfig = kapp->getConfig(); pConfig->setGroup( aGroup.data() ); QDictIterator<KKeyEntry> aKeyIt( aKeyDict ); aKeyIt.toFirst(); #define pE aKeyIt.current() while ( pE ) { s = pConfig->readEntry( aKeyIt.currentKey() ); if ( s.isNull() ) pE->aConfigKeyCode = pE->aDefaultKeyCode; else pE->aConfigKeyCode = stringToKey( s.data() ); if ( pE->bEnabled ) { uint keysym = keyToXSym( pE->aCurrentKeyCode ); uint mod = keyToXMod( pE->aCurrentKeyCode ); ungrabKey( keysym, mod ); } pE->aCurrentKeyCode = pE->aConfigKeyCode; if ( pE->bEnabled ) { uint keysym = keyToXSym( pE->aCurrentKeyCode ); uint mod = keyToXMod( pE->aCurrentKeyCode ); grabKey( keysym, mod ); } ++aKeyIt; } #undef pE }