[PATCH] hotkey for mousegrab (better late then never... I guess)

Fabian Bieler <[email protected]> Fri, 14 Oct 2005 18:17:43 +0200
Newsgroups gmane.comp.emulators.winex.devel
Message-ID <[email protected]>
--Boundary-00=_no9TDxn7n2VQVuq
Content-Type: text/plain;
  charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello!
Ok, so I found the time to look into this again. :-[

The key is now configurable via the config file.

Regarding the disabling-"want_grab"-when-suppressing-grab issue:
I really don't think this is a good idea since when grabbing is supressed I 
need another static variable to save the state that should be restored when 
supressing stops. Furthermore, if the application chooses to toggle grabs 
while supressing I would need to change said static variable. Isn't using 
want_grabs for this purpous cleaner?

Fabian

--Boundary-00=_no9TDxn7n2VQVuq
Content-Type: text/x-diff;
  charset="iso-8859-15";
  name="patch.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="patch.diff"

Index: dlls/x11drv/x11ddraw.c
===================================================================
RCS file: /cvsroot/winex/dlls/x11drv/x11ddraw.c,v
retrieving revision 1.111
diff -r1.111 x11ddraw.c
12a13,14
> #include <X11/Xatom.h>
> #include <X11/keysym.h>
55a58,60
> extern KeySym suppressDXGrabKeySym;
> extern unsigned int suppressDXGrabModMask;
> 
80a86,87
> void X11DRV_ToggleSuppressGrabs(void);
> 
420c427
< static BOOL has_focus, has_grab, want_grab, propagate;
---
> static BOOL has_focus, has_grab, want_grab, suppress_grab, propagate;
486a494,503
> 
>     if(suppressDXGrabKeySym != NoSymbol)
>     {
>       if(!(~event->xkey.state & suppressDXGrabModMask))
>         if(XKeycodeToKeysym(display, event->xkey.keycode, 0) == suppressDXGrabKeySym)
>         {
>           X11DRV_ToggleSuppressGrabs();
>           break;
>         }
>     }
1147c1164,1165
<     X11DRV_DD_PostCmd(DDMSG_GRAB);
---
>     if (!suppress_grab)
>       X11DRV_DD_PostCmd(DDMSG_GRAB);
1162a1181,1201
> void X11DRV_ToggleSuppressGrabs(void)
> {
> 	TRACE("\n");
> 	if (!dxgrab) return;
> 	if (!suppress_grab)
> 	{
> 		suppress_grab = TRUE;
> 		if (X11DRV_DD_PrimaryFrame)
> 			X11DRV_DD_PostCmd(DDMSG_UNGRAB);
> 	}
> 	else
> 	{
> 		suppress_grab = FALSE;
> 		if (want_grab)
> 		{
> 			if (X11DRV_DD_PrimaryFrame)
> 				X11DRV_DD_PostCmd(DDMSG_GRAB);
> 		}
> 	}
> }
> 
Index: dlls/x11drv/x11drv_main.c
===================================================================
RCS file: /cvsroot/winex/dlls/x11drv/x11drv_main.c,v
retrieving revision 1.44
diff -r1.44 x11drv_main.c
71a72,73
> KeySym suppressDXGrabKeySym = NoSymbol; //NoSymbol if disabled
> unsigned int suppressDXGrabModMask;
320a323,368
>     if (!get_config_key( hkey, appkey, "DXGrabHotKey", buffer, sizeof(buffer) ))
> 		{
> 		    //we expect a string of the form [<Modifier>+[<Modifier>+[...]]]<Key>
> 		    BOOL success=TRUE;
> 		    int i,j;
> 				unsigned int modMask=0;
> 				KeySym keySym;
> 		    j=0;
> 				
> 				//parse the modifiers
> 		    for(i=0; buffer[i]; i++)
> 				{
> 				    if(buffer[i]=='+')
> 						{
> 						    if(!strncmp("Shift", buffer+j, i-j))
> 								    modMask|=ShiftMask;
> 								else if(!strncmp("Ctrl", buffer+j, i-j))
> 								    modMask|=ControlMask;
> 								else if(!strncmp("Alt", buffer+j, i-j))
> 								    modMask|=Mod1Mask;
> 								else
> 								{
> 								    MESSAGE( "x11drv: Warning: Error parsing \"DXGrabHotKey\": unknown Modifier: \"%.*s\". Disabling DXGrabHotKey\n", i-j, buffer+j);
> 								    success=FALSE;
> 										break;
> 						    }
> 								j=i+1;
> 						}
> 				}
> 				
> 				//now get the keysym
> 				if(success)
> 				{
> 				    keySym = XStringToKeysym(buffer+j);
> 				    if(keySym==NoSymbol)
> 		    		{
>     			      MESSAGE( "x11drv: Warning: Error parsing \"DXGrabHotKey\": unknown key: \"%s\". Disabling DXGrabHotKey\n", buffer+j);
> 				    }
> 						else
> 						{
> 				        suppressDXGrabKeySym = keySym;
> 						    suppressDXGrabModMask = modMask;
> 						}
> 				}
> 		}
> 
Index: documentation/samples/config
===================================================================
RCS file: /cvsroot/winex/documentation/samples/config,v
retrieving revision 1.7
diff -r1.7 config
145a146,148
> ; Hotkey to suppress DXGrab
> ; e.g.: "Shift+g", "Ctrl+Alt+slash", "F10"
> ; "DXGrabHotKey" = "Ctrl+F9"

--Boundary-00=_no9TDxn7n2VQVuq--