From a9f5148f77cb23de913206becf874dac735a6059 Mon Sep 17 00:00:00 2001 From: Sergey Udaltsov Date: Sat, 27 Nov 2004 15:47:04 +0000 Subject: first working version of xmodmap --- ChangeLog | 5 ++ libxklavier/xklavier.c | 15 ++++- libxklavier/xklavier_evt.c | 70 +++++++++++++++++++++- libxklavier/xklavier_evt_xkb.c | 115 +++++++++---------------------------- libxklavier/xklavier_evt_xmm.c | 30 +++++++++- libxklavier/xklavier_private.h | 5 ++ libxklavier/xklavier_private_xkb.h | 2 + libxklavier/xklavier_util.c | 3 +- libxklavier/xklavier_xkb.c | 27 ++++++++- libxklavier/xklavier_xmm.c | 1 - 10 files changed, 177 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed61206..29a7220 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-11-27 16:00 svu + + * libxklavier: Some fixes in xmodmap. First version, + working somehow + 2004-11-25 23:00 svu * libxklavier, tests: MASSIVE commit. First version diff --git a/libxklavier/xklavier.c b/libxklavier/xklavier.c index 5cfd752..94a7255 100644 --- a/libxklavier/xklavier.c +++ b/libxklavier/xklavier.c @@ -199,10 +199,23 @@ int XklInit( Display * a_dpy ) rv = _XklXkbInit(); #endif #ifdef ENABLE_XMM_SUPPORT - XklDebug( 150, "Trying XMM backend\n" ); if( rv != 0 ) + { + XklDebug( 150, "Trying XMM backend\n" ); rv = _XklXmmInit(); + } #endif + if( rv == 0 ) + { + XklDebug( 150, "Actual backend: %s\n", + XklGetBackendName() ); + } + else + { + XklDebug( 0, "All backends failed, last result: %d\n", rv ); + _xklDpy = NULL; + } + return ( rv == 0 ) ? ( _XklLoadAllInfo() ? 0 : _xklLastErrorCode ) : -1; } diff --git a/libxklavier/xklavier_evt.c b/libxklavier/xklavier_evt.c index 2950424..0ef3886 100644 --- a/libxklavier/xklavier_evt.c +++ b/libxklavier/xklavier_evt.c @@ -51,8 +51,8 @@ int XklFilterEvents( XEvent * xev ) break; /* Ignore these events */ default: { - XklDebug( 200, "Unknown event %d [%s]\n", xev->type, - _XklGetEventName( xev->type ) ); + XklDebug( 200, "Unknown event %d [%s]\n", + xev->type, _XklGetEventName( xev->type ) ); return 1; } } @@ -366,3 +366,69 @@ void _XklErrHandler( Display * dpy, XErrorEvent * evt ) ( *_xklDefaultErrHandler ) ( dpy, evt ); } } + +/** + * Some common functionality for Xkb handler + */ +void _XklStateModificationHandler( XklStateChange changeType, + int grp, + unsigned inds, + Bool setInds ) +{ + Window focused, focusedApp; + XklState oldState; + int revert; + Bool haveState; + Bool setGroup = changeType == GROUP_CHANGED; + + XGetInputFocus( _xklDpy, &focused, &revert ); + + if( ( focused == None ) || ( focused == PointerRoot ) ) + { + XklDebug( 160, "Something with focus: " WINID_FORMAT "\n", focused ); + return; + } + + if( !_XklGetAppWindow( focused, &focusedApp ) ) + focusedApp = _xklCurClient; /* what else can I do */ + + XklDebug( 150, "Focused window: " WINID_FORMAT ", '%s'\n", focusedApp, + _XklGetDebugWindowTitle( focusedApp ) ); + XklDebug( 150, "CurClient: " WINID_FORMAT ", '%s'\n", _xklCurClient, + _XklGetDebugWindowTitle( _xklCurClient ) ); + + if( focusedApp != _xklCurClient ) + { + if ( !_XklGetAppState( focusedApp, &oldState ) ) + { + _XklUpdateCurState( grp, inds, + "Updating the state from new focused window" ); + if( _xklListenerType & XKLL_MANAGE_WINDOW_STATES ) + _XklAddAppWindow( focusedApp, ( Window ) NULL, False, &_xklCurState ); + } + else + { + grp = oldState.group; + inds = oldState.indicators; + } + _xklCurClient = focusedApp; + XklDebug( 160, "CurClient:changed to " WINID_FORMAT ", '%s'\n", + _xklCurClient, _XklGetDebugWindowTitle( _xklCurClient ) ); + } + /* if the window already has this this state - we are just restoring it! + (see the second parameter of stateCallback */ + haveState = _XklGetAppState( _xklCurClient, &oldState ); + + if( setGroup || haveState ) + { + _XklUpdateCurState( setGroup ? grp : oldState.group, + setInds ? inds : oldState.indicators, + "Restoring the state from the window" ); + } + + if( haveState ) + _XklTryCallStateCallback( changeType, &oldState ); + + if( _xklListenerType & XKLL_MANAGE_WINDOW_STATES ) + _XklSaveAppState( _xklCurClient, &_xklCurState ); +} diff --git a/libxklavier/xklavier_evt_xkb.c b/libxklavier/xklavier_evt_xkb.c index 616f878..87142b8 100644 --- a/libxklavier/xklavier_evt_xkb.c +++ b/libxklavier/xklavier_evt_xkb.c @@ -8,72 +8,6 @@ #include "xklavier_private.h" #include "xklavier_private_xkb.h" -#ifdef XKB_HEADERS_PRESENT -/** - * Some common functionality for Xkb handler - */ -static void _XklStdXkbHandler( int grp, XklStateChange changeType, unsigned inds, - Bool setInds ) -{ - Window focused, focusedApp; - XklState oldState; - int revert; - Bool haveState; - Bool setGroup = changeType == GROUP_CHANGED; - - XGetInputFocus( _xklDpy, &focused, &revert ); - - if( ( focused == None ) || ( focused == PointerRoot ) ) - { - XklDebug( 160, "Something with focus: " WINID_FORMAT "\n", focused ); - return; - } - - if( !_XklGetAppWindow( focused, &focusedApp ) ) - focusedApp = _xklCurClient; /* what else can I do */ - - XklDebug( 150, "Focused window: " WINID_FORMAT ", '%s'\n", focusedApp, - _XklGetDebugWindowTitle( focusedApp ) ); - XklDebug( 150, "CurClient: " WINID_FORMAT ", '%s'\n", _xklCurClient, - _XklGetDebugWindowTitle( _xklCurClient ) ); - - if( focusedApp != _xklCurClient ) - { - if ( !_XklGetAppState( focusedApp, &oldState ) ) - { - _XklUpdateCurState( grp, inds, - "Updating the state from new focused window" ); - if( _xklListenerType & XKLL_MANAGE_WINDOW_STATES ) - _XklAddAppWindow( focusedApp, ( Window ) NULL, False, &_xklCurState ); - } - else - { - grp = oldState.group; - inds = oldState.indicators; - } - _xklCurClient = focusedApp; - XklDebug( 160, "CurClient:changed to " WINID_FORMAT ", '%s'\n", - _xklCurClient, _XklGetDebugWindowTitle( _xklCurClient ) ); - } - /* if the window already has this this state - we are just restoring it! - (see the second parameter of stateCallback */ - haveState = _XklGetAppState( _xklCurClient, &oldState ); - - if( setGroup || haveState ) - { - _XklUpdateCurState( setGroup ? grp : oldState.group, - setInds ? inds : oldState.indicators, - "Restoring the state from the window" ); - } - - if( haveState ) - _XklTryCallStateCallback( changeType, &oldState ); - - if( _xklListenerType & XKLL_MANAGE_WINDOW_STATES ) - _XklSaveAppState( _xklCurClient, &_xklCurState ); -} -#endif - /** * XKB event handler */ @@ -96,6 +30,9 @@ int _XklXkbEventHandler( XEvent *xev ) switch ( kev->any.xkb_type ) { + /** + * Group is changed! + */ case XkbStateNotify: #define GROUP_CHANGE_MASK \ ( XkbGroupStateMask | XkbGroupBaseMask | XkbGroupLatchMask | XkbGroupLockMask ) @@ -106,8 +43,11 @@ int _XklXkbEventHandler( XEvent *xev ) kev->state.locked_group ); if( kev->state.changed & GROUP_CHANGE_MASK ) - _XklStdXkbHandler( kev->state.locked_group, GROUP_CHANGED, 0, False ); - else + _XklStateModificationHandler( GROUP_CHANGED, + kev->state.locked_group, + 0, + False ); + else /* ...not interested... */ { XklDebug( 200, "This type of state notification is not regarding groups\n" ); @@ -120,6 +60,9 @@ int _XklXkbEventHandler( XEvent *xev ) break; + /** + * Indicators are changed! + */ case XkbIndicatorStateNotify: XklDebug( 150, "XkbIndicatorStateNotify\n" ); @@ -134,35 +77,31 @@ int _XklXkbEventHandler( XEvent *xev ) inds &= ~bit; } - _XklStdXkbHandler( 0, INDICATORS_CHANGED, inds, True ); + _XklStateModificationHandler( INDICATORS_CHANGED, + 0, + inds, + True ); break; + /** + * The configuration is changed! + */ case XkbIndicatorMapNotify: - XklDebug( 150, "XkbIndicatorMapNotify\n" ); - _XklFreeAllInfo( ); - _XklLoadAllInfo( ); - break; - case XkbControlsNotify: - XklDebug( 150, "XkbControlsNotify\n" ); - _XklFreeAllInfo( ); - _XklLoadAllInfo( ); - break; - case XkbNamesNotify: - XklDebug( 150, "XkbNamesNotify\n" ); - _XklFreeAllInfo( ); - _XklLoadAllInfo( ); - break; - case XkbNewKeyboardNotify: - XklDebug( 150, "XkbNewKeyboardNotify\n" ); - _XklFreeAllInfo( ); - _XklLoadAllInfo( ); + XklDebug( 150, "%s\n", + _XklXkbGetXkbEventName( kev->any.xkb_type ) ); + _XklFreeAllInfo(); + _XklLoadAllInfo(); break; + /** + * ...Not interested... + */ default: - XklDebug( 150, "Unknown xkb event %d\n", kev->any.xkb_type ); + XklDebug( 150, "Unknown XKB event %d [%s]\n", + kev->any.xkb_type, _XklXkbGetXkbEventName( kev->any.xkb_type ) ); return 0; } return 1; diff --git a/libxklavier/xklavier_evt_xmm.c b/libxklavier/xklavier_evt_xmm.c index 1046757..f2e3a4a 100644 --- a/libxklavier/xklavier_evt_xmm.c +++ b/libxklavier/xklavier_evt_xmm.c @@ -40,19 +40,45 @@ static int _XklXmmPropertyEventHandler( XPropertyEvent* kpe ) { XklDebug( 200, "Processing the PropertyNotify event: %d/%d\n", kpe->atom, xmmStateAtom ); + /** + * Group is changed! + */ if( kpe->atom == xmmStateAtom ) { + XklState state; + _XklXmmGetRealState( &state ); + if( _xklListenerType & XKLL_MANAGE_LAYOUTS ) { - XklState state; - _XklXmmGetRealState( &state ); 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 + /** + * Configuration is changed! + */ + if( kpe->atom == xklVTable->baseConfigAtom ) + { + _XklFreeAllInfo(); + _XklLoadAllInfo(); } + return 0; } diff --git a/libxklavier/xklavier_private.h b/libxklavier/xklavier_private.h index 42f93c3..c470721 100644 --- a/libxklavier/xklavier_private.h +++ b/libxklavier/xklavier_private.h @@ -243,6 +243,11 @@ extern Bool _XklIsTransparentAppWindow( Window appWin ); extern void _XklUpdateCurState( int group, unsigned indicators, const char reason[] ); +extern void _XklStateModificationHandler( XklStateChange changeType, + int grp, + unsigned inds, + Bool setInds ); + extern int _XklXkbInit( void ); extern int _XklXmmInit( void ); diff --git a/libxklavier/xklavier_private_xkb.h b/libxklavier/xklavier_private_xkb.h index 00ca966..2c6ced5 100644 --- a/libxklavier/xklavier_private_xkb.h +++ b/libxklavier/xklavier_private_xkb.h @@ -20,6 +20,8 @@ extern void XklDumpXkbDesc( const char *filename, XkbDescPtr kbd ); extern Bool _XklXkbConfigMultipleLayoutsSupported( void ); +extern const char *_XklXkbGetXkbEventName( int xkb_type ); + /* Start VTable methods */ extern Bool _XklXkbConfigActivate( const XklConfigRecPtr data ); diff --git a/libxklavier/xklavier_util.c b/libxklavier/xklavier_util.c index 6504b3b..55b5ed4 100644 --- a/libxklavier/xklavier_util.c +++ b/libxklavier/xklavier_util.c @@ -255,7 +255,8 @@ const char *_XklGetEventName( int type ) "ColormapNotify", "ClientMessage", "MappingNotify", "LASTEvent" }; type -= KeyPress; - if( type < 0 || type > ( sizeof( evtNames ) / sizeof( evtNames[0] ) ) ) + if( type < 0 || + type >= ( sizeof( evtNames ) / sizeof( evtNames[0] ) ) ) return "UNKNOWN"; return evtNames[type]; } diff --git a/libxklavier/xklavier_xkb.c b/libxklavier/xklavier_xkb.c index 5b2ffe4..2d25ea1 100644 --- a/libxklavier/xklavier_xkb.c +++ b/libxklavier/xklavier_xkb.c @@ -387,7 +387,6 @@ int _XklXkbInit( void ) &_xklXkbError, NULL, NULL ); if( !_xklXkbExtPresent ) { - _xklDpy = NULL; XSetErrorHandler( ( XErrorHandler ) _xklDefaultErrHandler ); return -1; } @@ -420,3 +419,29 @@ int _XklXkbInit( void ) return -1; #endif } + +const char *_XklXkbGetXkbEventName( int xkb_type ) +{ + /* Not really good to use the fact of consecutivity + but XKB protocol extension is already standartized so... */ + static const char *evtNames[] = { + "XkbNewKeyboardNotify", + "XkbMapNotify", + "XkbStateNotify", + "XkbControlsNotify", + "XkbIndicatorStateNotify", + "XkbIndicatorMapNotify", + "XkbNamesNotify", + "XkbCompatMapNotify", + "XkbBellNotify", + "XkbActionMessage", + "XkbAccessXNotify", + "XkbExtensionDeviceNotify", + "LASTEvent" + }; + xkb_type -= XkbNewKeyboardNotify; + if( xkb_type < 0 || + xkb_type >= ( sizeof( evtNames ) / sizeof( evtNames[0] ) ) ) + return "UNKNOWN"; + return evtNames[xkb_type]; +} diff --git a/libxklavier/xklavier_xmm.c b/libxklavier/xklavier_xmm.c index 2d68637..4644041 100755 --- a/libxklavier/xklavier_xmm.c +++ b/libxklavier/xklavier_xmm.c @@ -261,6 +261,5 @@ int _XklXmmInit( void ) xklVTable = &xklXmmVTable; - XklDebug( 0, "XMM backend inited\n" ); return 0; } -- cgit v1.2.1