From 20a50016974d6882b8821b3e8245b4e5786be168 Mon Sep 17 00:00:00 2001 From: Sergey Udaltsov Date: Thu, 30 Dec 2004 23:00:21 +0000 Subject: secondary layouts are managed through the root window property --- ChangeLog | 5 ++++ libxklavier/xklavier.c | 60 ++++++++++++++++++++++++++++++++++++------ libxklavier/xklavier_evt.c | 2 +- libxklavier/xklavier_private.h | 10 ++++++- libxklavier/xklavier_xmm.c | 24 ++++++++--------- 5 files changed, 78 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1cd3f1..eba3e6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ 2004-12-30 svu * libxklavier/xklavier_config_xkb.c: some memory leak nailed + * libxklavier/xklavier.c, + libxklavier/xklavier_evt.c, + libxklavier/xklavier_private.h, + libxklavier/xklavier_xmm.c: internal polish, + secondary layouts are managed through the root window property. 2004-12-27 svu diff --git a/libxklavier/xklavier.c b/libxklavier/xklavier.c index 2109eaa..fd03a41 100644 --- a/libxklavier/xklavier.c +++ b/libxklavier/xklavier.c @@ -25,8 +25,6 @@ Atom _xklAtoms[TOTAL_ATOMS]; Window _xklRootWindow; -Bool _xklAllowSecondaryGroupOnce; - int _xklDefaultGroup; Bool _xklSkipOneRestore; @@ -82,10 +80,53 @@ Bool XklIsGroupPerApp( void ) return groupPerApp; } +static void _XklSetSwitchToSecondaryGroup( Bool val ) +{ + CARD32 propval = (CARD32)val; + XChangeProperty( _xklDpy, _xklRootWindow, _xklAtoms[XKLAVIER_ALLOW_SECONDARY], + XA_INTEGER, 32, PropModeReplace, + (unsigned char*)&propval, 1 ); + XSync( _xklDpy, False ); +} + void XklAllowOneSwitchToSecondaryGroup( void ) { XklDebug( 150, "Setting allowOneSwitchToSecondaryGroup flag\n" ); - _xklAllowSecondaryGroupOnce = True; + _XklSetSwitchToSecondaryGroup( True ); +} + +Bool _XklIsOneSwitchToSecondaryGroupAllowed( void ) +{ + Bool rv = False; + unsigned char *propval = NULL; + Atom actualType; + int actualFormat; + unsigned long bytesRemaining; + unsigned long actualItems; + int result; + + result = XGetWindowProperty( _xklDpy, _xklRootWindow, + _xklAtoms[XKLAVIER_ALLOW_SECONDARY], 0L, 1L, + False, XA_INTEGER, &actualType, &actualFormat, + &actualItems, &bytesRemaining, + &propval ); + + if( Success == result ) + { + if( actualFormat == 32 && actualItems == 1 ) + { + rv = *(Bool*)propval; + } + XFree( propval ); + } + + return rv; +} + +void _XklOneSwitchToSecondaryGroupPerformed( void ) +{ + XklDebug( 150, "Resetting allowOneSwitchToSecondaryGroup flag\n" ); + _XklSetSwitchToSecondaryGroup( False ); } void XklSetDefaultGroup( int group ) @@ -180,7 +221,6 @@ int XklInit( Display * a_dpy ) scr = DefaultScreen( _xklDpy ); _xklRootWindow = RootWindow( _xklDpy, scr ); - _xklAllowSecondaryGroupOnce = False; _xklSkipOneRestore = False; _xklDefaultGroup = -1; _xklSecondaryGroupsMask = 0L; @@ -191,6 +231,10 @@ int XklInit( Display * a_dpy ) _xklAtoms[XKLAVIER_STATE] = XInternAtom( _xklDpy, "XKLAVIER_STATE", False ); _xklAtoms[XKLAVIER_TRANSPARENT] = XInternAtom( _xklDpy, "XKLAVIER_TRANSPARENT", False ); + _xklAtoms[XKLAVIER_ALLOW_SECONDARY] = + XInternAtom( _xklDpy, "XKLAVIER_ALLOW_SECONDARY", False ); + + _XklOneSwitchToSecondaryGroupPerformed(); rv = -1; XklDebug( 150, "Trying all backends:\n" ); @@ -388,7 +432,7 @@ void _XklAddAppWindow( Window appWin, Window parent, Bool ignoreExistingState, if( _xklCurClient == appWin ) { if( ( _xklSecondaryGroupsMask & ( 1 << defGroupToUse ) ) != 0 ) - XklAllowOneSwitchToSecondaryGroup( ); + XklAllowOneSwitchToSecondaryGroup(); XklLockGroup( defGroupToUse ); } } @@ -680,14 +724,14 @@ void _XklTryCallStateCallback( XklStateChange changeType, XklDebug( 150, "changeType: %d, group: %d, secondaryGroupMask: %X, allowsecondary: %d\n", changeType, group, _xklSecondaryGroupsMask, - _xklAllowSecondaryGroupOnce ); + _XklIsOneSwitchToSecondaryGroupAllowed() ); if( changeType == GROUP_CHANGED ) { if( !restore ) { if( ( _xklSecondaryGroupsMask & ( 1 << group ) ) != 0 && - !_xklAllowSecondaryGroupOnce ) + !_XklIsOneSwitchToSecondaryGroupAllowed() ) { XklDebug( 150, "secondary -> go next\n" ); group = XklGetNextGroup( ); @@ -695,7 +739,7 @@ void _XklTryCallStateCallback( XklStateChange changeType, return; /* we do not need to revalidate */ } } - _xklAllowSecondaryGroupOnce = False; + _XklOneSwitchToSecondaryGroupPerformed(); } if( stateCallback != NULL ) { diff --git a/libxklavier/xklavier_evt.c b/libxklavier/xklavier_evt.c index 9202b20..e0188e6 100644 --- a/libxklavier/xklavier_evt.c +++ b/libxklavier/xklavier_evt.c @@ -166,7 +166,7 @@ void _XklFocusInEvHandler( XFocusChangeEvent * fev ) XklDebug( 150, "Both old and new focused window have group %d so no point restoring it\n", selectedWindowState.group ); - _xklAllowSecondaryGroupOnce = False; + _XklOneSwitchToSecondaryGroupPerformed(); } } diff --git a/libxklavier/xklavier_private.h b/libxklavier/xklavier_private.h index 6547926..8841e6e 100644 --- a/libxklavier/xklavier_private.h +++ b/libxklavier/xklavier_private.h @@ -274,6 +274,10 @@ extern int _XklXkbInit( void ); extern int _XklXmmInit( void ); +extern Bool _XklIsOneSwitchToSecondaryGroupAllowed( void ); + +extern void _XklOneSwitchToSecondaryGroupPerformed( void ); + extern Display *_xklDpy; extern Window _xklRootWindow; @@ -290,7 +294,11 @@ extern XErrorHandler _xklDefaultErrHandler; extern char *_xklIndicatorNames[]; -enum { WM_NAME, WM_STATE, XKLAVIER_STATE, XKLAVIER_TRANSPARENT, +enum { WM_NAME, + WM_STATE, + XKLAVIER_STATE, + XKLAVIER_TRANSPARENT, + XKLAVIER_ALLOW_SECONDARY, TOTAL_ATOMS }; #define XKLAVIER_STATE_PROP_LENGTH 2 diff --git a/libxklavier/xklavier_xmm.c b/libxklavier/xklavier_xmm.c index 23eafe1..c211aac 100755 --- a/libxklavier/xklavier_xmm.c +++ b/libxklavier/xklavier_xmm.c @@ -171,22 +171,20 @@ void _XklXmmGetRealState( XklState * state ) &actualItems, &bytesRemaining, &propval ); - if( Success != result ) + if( Success == result ) + { + if( actualFormat == 32 || actualItems == 1 ) + { + state->group = *(CARD32*)propval; + } else + { + XklDebug( 160, "Could not get the xmodmap current group\n" ); + } + XFree( propval ); + } else { XklDebug( 160, "Could not get the xmodmap current group: %d\n", result ); - return; } - - if( actualFormat != 32 || - actualItems != 1 ) - { - XklDebug( 160, "Could not get the xmodmap current group\n" ); - return; - } - - state->group = *(CARD32*)propval; - XFree( propval ); - state->indicators = 0; } void _XklXmmActualizeGroup( int group ) -- cgit v1.2.1