diff options
author | Sergey Udaltsov <svu@gnome.org> | 2006-03-12 04:20:01 +0000 |
---|---|---|
committer | Sergey Udaltsov <svu@gnome.org> | 2006-03-12 04:20:01 +0000 |
commit | 2c88cc80147b72eba939d6358939ef59d403c34e (patch) | |
tree | b6b145f6d50e1f4bba8145bef5963aee8a5f3180 /libxklavier/xklavier_evt_xmm.c | |
parent | d7bc98fb5f9d55c37a08ceeedbc87cb70ee6f133 (diff) | |
download | libxklavier-2c88cc80147b72eba939d6358939ef59d403c34e.tar.gz |
branching 2.x, merging GLIBing to HEAD
Diffstat (limited to 'libxklavier/xklavier_evt_xmm.c')
-rw-r--r-- | libxklavier/xklavier_evt_xmm.c | 280 |
1 files changed, 150 insertions, 130 deletions
diff --git a/libxklavier/xklavier_evt_xmm.c b/libxklavier/xklavier_evt_xmm.c index 7574f3e..91d3699 100644 --- a/libxklavier/xklavier_evt_xmm.c +++ b/libxklavier/xklavier_evt_xmm.c @@ -3,170 +3,190 @@ #include <X11/Xatom.h> #include <X11/Xlib.h> #include <X11/Xutil.h> -#include <X11/Xlibint.h> #include <X11/keysym.h> #include "xklavier_private.h" #include "xklavier_private_xmm.h" -static int _XklXmmKeypressEventHandler( XKeyPressedEvent* kpe ) +static gint +xkl_xmm_process_keypress_event(XklEngine * engine, XKeyPressedEvent * kpe) { - if( _xklListenerType & XKLL_MANAGE_LAYOUTS ) - { - XklDebug( 200, "Processing the KeyPress event\n" ); - int currentShortcut = 0; - const XmmSwitchOptionPtr sop = _XklXmmFindSwitchOption( kpe->keycode, - kpe->state, - ¤tShortcut ); - if( sop != NULL ) - { - XklDebug( 150, "It is THE shortcut\n" ); - XklState state; - _XklXmmGetRealState( &state ); - if( state.group != -1 ) - { - int newGroup = ( state.group + sop->shortcutSteps[currentShortcut] ) % - currentXmmConfig.numLayouts; - XklDebug( 150, "Setting new xmm group %d\n", newGroup ); - _XklXmmLockGroup( newGroup ); - return 1; - } - } - } - return 0; + if (xkl_engine_priv(engine, listener_type) & XKLL_MANAGE_LAYOUTS) { + xkl_debug(200, "Processing the KeyPress event\n"); + gint current_shortcut = 0; + const XmmSwitchOption *sop = + xkl_xmm_find_switch_option(engine, kpe->keycode, + kpe->state, + ¤t_shortcut); + if (sop != NULL) { + xkl_debug(150, "It is THE shortcut\n"); + XklState state; + xkl_xmm_get_server_state(engine, &state); + if (state.group != -1) { + gint new_group = + (state.group + + sop-> + shortcut_steps[current_shortcut]) % + g_strv_length(xkl_engine_backend + (engine, XklXmm, + current_config). + layouts); + xkl_debug(150, + "Setting new xmm group %d\n", + new_group); + xkl_xmm_lock_group(engine, new_group); + return 1; + } + } + } + return 0; } -static int _XklXmmPropertyEventHandler( XPropertyEvent* kpe ) +static gint +xkl_xmm_process_property_event(XklEngine * engine, XPropertyEvent * kpe) { - XklDebug( 200, "Processing the PropertyNotify event: %d/%d\n", - kpe->atom, xmmStateAtom ); - /** + Atom state_atom = xkl_engine_backend(engine, XklXmm, state_atom); + xkl_debug(200, "Processing the PropertyNotify event: %d/%d\n", + kpe->atom, state_atom); + /* * Group is changed! */ - if( kpe->atom == xmmStateAtom ) - { - XklState state; - _XklXmmGetRealState( &state ); - - if( _xklListenerType & XKLL_MANAGE_LAYOUTS ) - { - XklDebug( 150, "Current group from the root window property %d\n", state.group ); - _XklXmmUngrabShortcuts(); - _XklXmmActualizeGroup( state.group ); - _XklXmmGrabShortcuts(); - return 1; - } - - if( _xklListenerType & - ( XKLL_MANAGE_WINDOW_STATES | XKLL_TRACK_KEYBOARD_STATE ) ) - { - XklDebug( 150, - "XMM state changed, new 'group' %d\n", - state.group ); - - _XklStateModificationHandler( GROUP_CHANGED, - state.group, - 0, - False ); - } - } else - /** + if (kpe->atom == state_atom) { + XklState state; + xkl_xmm_get_server_state(engine, &state); + + if (xkl_engine_priv(engine, listener_type) & + XKLL_MANAGE_LAYOUTS) { + xkl_debug(150, + "Current group from the root window property %d\n", + state.group); + xkl_xmm_shortcuts_ungrab(engine); + xkl_xmm_actualize_group(engine, state.group); + xkl_xmm_shortcuts_grab(engine); + return 1; + } + + if (xkl_engine_priv(engine, listener_type) & + (XKLL_MANAGE_WINDOW_STATES | + XKLL_TRACK_KEYBOARD_STATE)) { + xkl_debug(150, + "XMM state changed, new 'group' %d\n", + state.group); + + xkl_engine_process_state_modification(engine, + GROUP_CHANGED, + state.group, + 0, False); + } + } else + /* * Configuration is changed! */ - if( kpe->atom == xklVTable->baseConfigAtom ) - { - _XklResetAllInfo( "base config atom changed" ); - } - - return 0; + if (kpe->atom == xkl_engine_priv(engine, base_config_atom)) { + xkl_engine_reset_all_info(engine, + "base config atom changed"); + } + + return 0; } -/** +/* * XMM event handler */ -int _XklXmmEventHandler( XEvent *xev ) +gint +xkl_xmm_process_x_event(XklEngine * engine, XEvent * xev) { - switch( xev->type ) - { - case KeyPress: - return _XklXmmKeypressEventHandler( (XKeyPressedEvent*)xev ); - case PropertyNotify: - return _XklXmmPropertyEventHandler( (XPropertyEvent*)xev ); - } - return 0; + switch (xev->type) { + case KeyPress: + return xkl_xmm_process_keypress_event(engine, + (XKeyPressedEvent *) + xev); + case PropertyNotify: + return xkl_xmm_process_property_event(engine, + (XPropertyEvent *) + xev); + } + return 0; } -/** +/* * We have to find which of Shift/Lock/Control/ModX masks * belong to Caps/Num/Scroll lock */ -static void _XklXmmInitXmmIndicatorsMap( int* pCapsLockMask, - int* pNumLockMask, - int* pScrollLockMask ) +static void +xkl_xmm_init_xmm_indicators_map(XklEngine * engine, + guint * p_caps_lock_mask, + guint * p_num_lock_mask, + guint * p_scroll_lock_mask) { - XModifierKeymap *xmkm = NULL; - KeyCode *kcmap, nlkc, clkc, slkc; - int m, k, mask; - - xmkm = XGetModifierMapping( _xklDpy ); - if( xmkm ) - { - clkc = XKeysymToKeycode( _xklDpy, XK_Num_Lock ); - nlkc = XKeysymToKeycode( _xklDpy, XK_Caps_Lock ); - slkc = XKeysymToKeycode( _xklDpy, XK_Scroll_Lock ); - - kcmap = xmkm->modifiermap; - mask = 1; - for( m = 8; --m >= 0; mask <<= 1 ) - for( k = xmkm->max_keypermod; --k >= 0; kcmap++ ) - { - if( *kcmap == clkc ) - *pCapsLockMask = mask; - if( *kcmap == slkc ) - *pScrollLockMask = mask; - if( *kcmap == nlkc ) - *pNumLockMask = mask; - } - XFreeModifiermap( xmkm ); - } + XModifierKeymap *xmkm = NULL; + KeyCode *kcmap, nlkc, clkc, slkc; + int m, k, mask; + + Display *display = xkl_engine_get_display(engine); + xmkm = XGetModifierMapping(display); + if (xmkm) { + clkc = XKeysymToKeycode(display, XK_Num_Lock); + nlkc = XKeysymToKeycode(display, XK_Caps_Lock); + slkc = XKeysymToKeycode(display, XK_Scroll_Lock); + + kcmap = xmkm->modifiermap; + mask = 1; + for (m = 8; --m >= 0; mask <<= 1) + for (k = xmkm->max_keypermod; --k >= 0; kcmap++) { + if (*kcmap == clkc) + *p_caps_lock_mask = mask; + if (*kcmap == slkc) + *p_scroll_lock_mask = mask; + if (*kcmap == nlkc) + *p_num_lock_mask = mask; + } + XFreeModifiermap(xmkm); + } } -void _XklXmmGrabIgnoringIndicators( int keycode, int modifiers ) +void +xkl_xmm_grab_ignoring_indicators(XklEngine * engine, gint keycode, + guint modifiers) { - int CapsLockMask = 0, NumLockMask = 0, ScrollLockMask = 0; - - _XklXmmInitXmmIndicatorsMap( &CapsLockMask, &NumLockMask, &ScrollLockMask ); + guint caps_lock_mask = 0, num_lock_mask = 0, scroll_lock_mask = 0; + + xkl_xmm_init_xmm_indicators_map(engine, &caps_lock_mask, + &num_lock_mask, &scroll_lock_mask); #define GRAB(mods) \ - XklGrabKey( keycode, modifiers|(mods) ) - - GRAB( 0 ); - GRAB( CapsLockMask ); - GRAB( NumLockMask ); - GRAB( ScrollLockMask ); - GRAB( CapsLockMask | NumLockMask ); - GRAB( CapsLockMask | ScrollLockMask ); - GRAB( NumLockMask | ScrollLockMask ); - GRAB( CapsLockMask | NumLockMask | ScrollLockMask ); + xkl_engine_grab_key(engine, keycode, modifiers|(mods)) + + GRAB(0); + GRAB(caps_lock_mask); + GRAB(num_lock_mask); + GRAB(scroll_lock_mask); + GRAB(caps_lock_mask | num_lock_mask); + GRAB(caps_lock_mask | scroll_lock_mask); + GRAB(num_lock_mask | scroll_lock_mask); + GRAB(caps_lock_mask | num_lock_mask | scroll_lock_mask); #undef GRAB } -void _XklXmmUngrabIgnoringIndicators( int keycode, int modifiers ) +void +xkl_xmm_ungrab_ignoring_indicators(XklEngine * engine, gint keycode, + guint modifiers) { - int CapsLockMask = 0, NumLockMask = 0, ScrollLockMask = 0; + guint caps_lock_mask = 0, num_lock_mask = 0, scroll_lock_mask = 0; + + xkl_xmm_init_xmm_indicators_map(engine, &caps_lock_mask, + &num_lock_mask, &scroll_lock_mask); - _XklXmmInitXmmIndicatorsMap( &CapsLockMask, &NumLockMask, &ScrollLockMask ); - #define UNGRAB(mods) \ - XklUngrabKey( keycode, modifiers|(mods) ) - - UNGRAB( 0 ); - UNGRAB( CapsLockMask ); - UNGRAB( NumLockMask ); - UNGRAB( ScrollLockMask ); - UNGRAB( CapsLockMask | NumLockMask ); - UNGRAB( CapsLockMask | ScrollLockMask ); - UNGRAB( NumLockMask | ScrollLockMask ); - UNGRAB( CapsLockMask | NumLockMask | ScrollLockMask ); + xkl_engine_ungrab_key(engine, keycode, modifiers|(mods)) + + UNGRAB(0); + UNGRAB(caps_lock_mask); + UNGRAB(num_lock_mask); + UNGRAB(scroll_lock_mask); + UNGRAB(caps_lock_mask | num_lock_mask); + UNGRAB(caps_lock_mask | scroll_lock_mask); + UNGRAB(num_lock_mask | scroll_lock_mask); + UNGRAB(caps_lock_mask | num_lock_mask | scroll_lock_mask); #undef UNGRAB } |