@@ -690,10 +690,12 @@ static void nxagentSwitchDeferMode(void)
690690 }
691691}
692692
693- static autograb = False ;
693+ static Bool autograb = False ;
694+ static Bool focus = False ;
694695
695- static void nxagentGrab (void )
696+ static void nxagentAutoGrab (void )
696697{
698+ fprintf (stderr , "autograb\n" );
697699 if (!autograb )
698700 nxagentGrabPointerAndKeyboard (NULL );
699701 else
@@ -702,6 +704,19 @@ static void nxagentGrab(void)
702704 autograb = !autograb ;
703705}
704706
707+ static Bool inputlock = False ;
708+
709+ static void nxagentLockInput (void )
710+ {
711+ fprintf (stderr , "inputlock\n" );
712+ /* if (!inputlock)
713+ nxagentGrabPointerAndKeyboard(NULL);
714+ else
715+ nxagentUngrabPointerAndKeyboard(NULL);
716+ */
717+ inputlock = !inputlock ;
718+ }
719+
705720static Bool nxagentExposurePredicate (Display * display , XEvent * event , XPointer window )
706721{
707722 /*
@@ -1095,9 +1110,15 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
10951110
10961111 break ;
10971112 }
1098- case doGrab :
1113+ case doAutoGrab :
10991114 {
1100- nxagentGrab ();
1115+ nxagentAutoGrab ();
1116+
1117+ break ;
1118+ }
1119+ case doLockInput :
1120+ {
1121+ nxagentLockInput ();
11011122
11021123 break ;
11031124 }
@@ -1528,9 +1549,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was
15281549 {
15291550 WindowPtr pWin ;
15301551
1531- #ifdef TEST
1552+ #ifdef TEST
15321553 fprintf (stderr , "nxagentDispatchEvents: Going to handle new FocusIn event.\n" );
1533- #endif
1554+ #endif
15341555
15351556 /*
15361557 * Here we change the focus state in the agent.
@@ -1545,23 +1566,74 @@ FIXME: Don't enqueue the KeyRelease event if the key was
15451566 RevertToPointerRoot , GetTimeInMillis (), False );
15461567 }
15471568
1569+
1570+ switch (X .xfocus .mode )
1571+ {
1572+ case NotifyNormal : fprintf (stderr , "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyNormal\n" ); break ;
1573+ case NotifyWhileGrabbed : fprintf (stderr , "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyWhileGrabbed\n" ); break ;
1574+ case NotifyGrab : fprintf (stderr , "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyGrab\n" ); break ;
1575+ case NotifyUngrab : fprintf (stderr , "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyUngrab\n" ); break ;
1576+ }
1577+
1578+ /* if (autograb)
1579+ fprintf(stderr, "nxagentDispatchEvents(FocusIn): autogab is on\n");
1580+ else
1581+ fprintf(stderr, "nxagentDispatchEvents(FocusIn): autogab is off\n");
1582+ */
15481583 if (X .xfocus .detail != NotifyInferior )
15491584 {
15501585 pScreen = nxagentScreen (X .xfocus .window );
1551-
1586+ fprintf ( stderr , "nxagentDispatchEvents(FocusIn): X.xfocus.window %d\n" , ( int ) X . xfocus . window );
15521587 if (pScreen )
15531588 {
15541589 nxagentDirectInstallColormaps (pScreen );
15551590 }
1591+ /* if (X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode != NotifyNormal)*/
1592+ /* if (autograb && X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode == NotifyNormal)
1593+ {
1594+ fprintf(stderr, "nxagentDispatchEvents(FocusIn): grabbing\n");
1595+ nxagentGrabPointerAndKeyboard(NULL);
1596+ }*/
15561597 }
15571598
1599+ if (autograb )
1600+ {
1601+ if (X .xfocus .window == nxagentDefaultWindows [0 ] && X .xfocus .mode == NotifyNormal )
1602+ {
1603+ focus = True ;
1604+ fprintf (stderr , "nxagentDispatchEvents(FocusIn): grabbing\n" );
1605+ nxagentGrabPointerAndKeyboard (NULL );
1606+ {
1607+ #include <nx-X11/Xatom.h>
1608+ XTextProperty name = {
1609+ .value = (unsigned char * ) "grabbed" ,
1610+ .encoding = XA_STRING ,
1611+ .format = 8 ,
1612+ .nitems = strlen ((char * ) name .value )
1613+ };
1614+ XSetWMName (nxagentDisplay , nxagentDefaultWindows [0 ], & name );
1615+ }
1616+ XGrabPointer (nxagentDisplay ,nxagentDefaultWindows [0 ], True , ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask |EnterWindowMask |
1617+ LeaveWindowMask ,GrabModeAsync ,GrabModeAsync , nxagentDefaultWindows [0 ], None , CurrentTime );
1618+
1619+ }
1620+ }
15581621 break ;
15591622 }
15601623 case FocusOut :
15611624 {
1562- #ifdef TEST
1625+ #ifdef TEST
15631626 fprintf (stderr , "nxagentDispatchEvents: Going to handle new FocusOut event.\n" );
1564- #endif
1627+
1628+ switch (X .xfocus .mode )
1629+ {
1630+ case NotifyNormal : fprintf (stderr , "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyNormal\n" ); break ;
1631+ case NotifyWhileGrabbed : fprintf (stderr , "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyWhileGrabbed\n" ); break ;
1632+ case NotifyGrab : fprintf (stderr , "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyGrab\n" ); break ;
1633+ case NotifyUngrab : fprintf (stderr , "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyUngrab\n" ); break ;
1634+ }
1635+ #endif
1636+
15651637
15661638 if (X .xfocus .detail != NotifyInferior )
15671639 {
@@ -1572,7 +1644,8 @@ FIXME: Don't enqueue the KeyRelease event if the key was
15721644 nxagentDirectUninstallColormaps (pScreen );
15731645 }
15741646 }
1575-
1647+ /* nxagentUngrabPointerAndKeyboard(NULL);*/
1648+
15761649 #ifdef NXAGENT_FIXKEYS
15771650
15781651 {
@@ -1632,7 +1705,43 @@ FIXME: Don't enqueue the KeyRelease event if the key was
16321705 }
16331706
16341707 #endif /* NXAGENT_FIXKEYS */
1635-
1708+
1709+ if (autograb )
1710+ {
1711+ XlibWindow w ;
1712+ int revert_to ;
1713+ int ret ;
1714+ fprintf (stderr , "FocusOut: getting input focus window ... " );
1715+ ret = XGetInputFocus (nxagentDisplay , & w , & revert_to ); // see man
1716+ if (ret == BadValue ){
1717+ fprintf (stderr ,"FocusOut: BadValue\n" );
1718+ } else if (ret == BadWindow ){
1719+ fprintf (stderr ,"FocusOut: BadWindow\n" );
1720+ }else if (w == None ){
1721+ fprintf (stderr , "FocusOut: no focus window\n" );
1722+ }else {
1723+ fprintf (stderr , "FocusOut: success (window: %d)\n" , (int )w );
1724+ /* fprintf(stderr, "DefaultRootWindow: %d\n" ,(int)DefaultRootWindow(nxagentDisplay));
1725+ fprintf(stderr, "DefaultWindows: %d\n" ,(int)nxagentDefaultWindows[0]);*/
1726+ }
1727+
1728+
1729+ if (w != nxagentDefaultWindows [0 ] && X .xfocus .mode == NotifyWhileGrabbed )
1730+ {
1731+ focus = False ;
1732+ fprintf (stderr , "nxagentDispatchEvents(FocusOut): ungrabbing\n" );
1733+ nxagentUngrabPointerAndKeyboard (NULL );
1734+ #include <nx-X11/Xatom.h>
1735+ XTextProperty name = {
1736+ .value = nxagentWindowName ,
1737+ .encoding = XA_STRING ,
1738+ .format = 8 ,
1739+ .nitems = strlen ((char * ) name .value )
1740+ };
1741+ XSetWMName (nxagentDisplay , nxagentDefaultWindows [0 ], & name );
1742+
1743+ }
1744+ }
16361745 break ;
16371746 }
16381747 case KeymapNotify :
@@ -1714,9 +1823,43 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17141823 nxagentScreenTrap = 0 ;
17151824 }
17161825
1717- if (autograb || (nxagentOption (Fullscreen ) == 1 &&
1826+ {
1827+ XlibWindow w ;
1828+ int revert_to ;
1829+ int ret ;
1830+ fprintf (stderr , "EnterNotify: getting input focus window ... " );
1831+ ret = XGetInputFocus (nxagentDisplay , & w , & revert_to ); // see man
1832+ if (ret == BadValue ){
1833+ fprintf (stderr ,"EnterNotify: BadValue\n" );
1834+ } else if (ret == BadWindow ){
1835+ fprintf (stderr ,"EnterNotify: BadWindow\n" );
1836+ }else if (w == None ){
1837+ fprintf (stderr , "EnterNotify: no focus window\n" );
1838+ }else {
1839+ fprintf (stderr , "EnterNotify: success (window: %d)\n" , (int )w );
1840+ /* fprintf(stderr, "DefaultRootWindow: %d\n" ,(int)DefaultRootWindow(nxagentDisplay));
1841+ fprintf(stderr, "DefaultWindows: %d\n" ,(int)nxagentDefaultWindows[0]);*/
1842+ }
1843+ }
1844+ /* if (autograb)
1845+ {
1846+ if (X.xcrossing.focus)
1847+ {
1848+ fprintf(stderr, "nxagentDispatchEvents(EnterNotify): xcrossing.focus is True\n");
1849+ fprintf(stderr, "nxagentDispatchEvents(EnterNotify): grabbing\n");
1850+ nxagentGrabPointerAndKeyboard(&X);
1851+ }
1852+ else
1853+ {
1854+ fprintf(stderr, "nxagentDispatchEvents(EnterNotify): xcrossing.focus is False\n");
1855+ }
1856+ }
1857+ */
1858+ /* if (autograb || (nxagentOption(Fullscreen) == 1 &&*/
1859+ /*if (w == nxagentDefaultWindows[0] || (nxagentOption(Fullscreen) == 1 &&*/
1860+ if (nxagentOption (Fullscreen ) == 1 &&
17181861 X .xcrossing .window == nxagentFullscreenWindow &&
1719- X .xcrossing .detail != NotifyInferior ))
1862+ X .xcrossing .detail != NotifyInferior )
17201863 {
17211864 fprintf (stderr , "nxagentDispatchEvents(EnterNotify): grabbing\n" );
17221865 nxagentGrabPointerAndKeyboard (& X );
@@ -1769,10 +1912,10 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17691912 nxagentLastEnteredWindow = NULL ;
17701913 }
17711914
1772- if (X .xcrossing .window == nxagentDefaultWindows [0 ] &&
1915+ /* if (X.xcrossing.window == nxagentDefaultWindows[0] &&
17731916 X.xcrossing.detail != NotifyInferior &&
17741917 X.xcrossing.mode == NotifyNormal)
1775- {
1918+ {*/
17761919 /* if (!autograb)
17771920 {
17781921 fprintf(stderr, "nxagentDispatchEvents: no autograb -> ungrabbing\n");
@@ -1781,9 +1924,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17811924 else
17821925 fprintf(stderr, "nxagentDispatchEvents: autograb -> no ungrabbing\n");
17831926 */
1784- fprintf (stderr , "nxagentDispatchEvents(LeaveNotify): ungrabbing\n" );
1927+ /* fprintf(stderr, "nxagentDispatchEvents(LeaveNotify): ungrabbing\n");
17851928 nxagentUngrabPointerAndKeyboard(&X);
1786- }
1929+ }*/
17871930
17881931 if (X .xcrossing .detail != NotifyInferior )
17891932 {
@@ -1795,6 +1938,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17951938 }
17961939 }
17971940
1941+
1942+ /* if (!focus)
1943+ {
1944+ fprintf(stderr, "nxagentDispatchEvents(LeaveNotify): ungrabbing\n");
1945+ nxagentUngrabPointerAndKeyboard(&X);
1946+ }
1947+ */
17981948 nxagentInputEvent = 1 ;
17991949
18001950 break ;
0 commit comments