summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2009-04-28 16:49:45 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2009-05-01 09:07:37 +1000
commit6a618929a0c06ba0d6dac13d7e644cd9658d98ed (patch)
treec716ab8ca481e1b88e6e6a048eba00e42529dd02
parente8e26f700c9c70d3f1bb53bdb71d1100f5c43a69 (diff)
input: reshuffle CreateGrab and friends to take a GrabParameters param.
This is cleaning up work in preparation for XI2 passive grabs.
-rw-r--r--Xi/exevents.c76
-rw-r--r--Xi/grabdevb.c17
-rw-r--r--Xi/grabdevk.c16
-rw-r--r--dix/events.c64
-rw-r--r--dix/grabs.c36
-rw-r--r--include/dixgrabs.h19
-rw-r--r--include/exevents.h46
-rw-r--r--test/input.c62
8 files changed, 207 insertions, 129 deletions
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 164f0713c..07931132e 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1349,36 +1349,34 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
}
}
-static int
-CheckGrabValues(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
- BYTE other_devices_mode, CARD16 modifiers, BOOL ownerEvents)
+int
+CheckGrabValues(ClientPtr client, GrabParameters* param)
{
- if ((this_device_mode != GrabModeSync) &&
- (this_device_mode != GrabModeAsync)) {
- client->errorValue = this_device_mode;
+ if ((param->this_device_mode != GrabModeSync) &&
+ (param->this_device_mode != GrabModeAsync)) {
+ client->errorValue = param->this_device_mode;
return BadValue;
}
- if ((other_devices_mode != GrabModeSync) &&
- (other_devices_mode != GrabModeAsync)) {
- client->errorValue = other_devices_mode;
+ if ((param->other_devices_mode != GrabModeSync) &&
+ (param->other_devices_mode != GrabModeAsync)) {
+ client->errorValue = param->other_devices_mode;
return BadValue;
}
- if ((modifiers != AnyModifier) && (modifiers & ~AllModifiersMask)) {
- client->errorValue = modifiers;
+ if ((param->modifiers != AnyModifier) && (param->modifiers & ~AllModifiersMask)) {
+ client->errorValue = param->modifiers;
return BadValue;
}
- if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) {
- client->errorValue = ownerEvents;
+ if ((param->ownerEvents != xFalse) && (param->ownerEvents != xTrue)) {
+ client->errorValue = param->ownerEvents;
return BadValue;
}
return Success;
}
int
-GrabButton(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
- BYTE other_devices_mode, CARD16 modifiers,
- DeviceIntPtr modifier_device, CARD8 button, Window grabWindow,
- BOOL ownerEvents, Cursor rcursor, Window rconfineTo, Mask eventMask)
+GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
+ int button, GrabParameters *param, GrabType grabtype,
+ GrabMask *mask)
{
WindowPtr pWin, confineTo;
CursorPtr cursor;
@@ -1386,53 +1384,48 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
int rc;
Mask access_mode = DixGrabAccess;
- rc = CheckGrabValues(client, dev, this_device_mode, other_devices_mode,
- modifiers, ownerEvents);
+ rc = CheckGrabValues(client, param);
if (rc != Success)
return rc;
- if (rconfineTo == None)
+ if (param->confineTo == None)
confineTo = NullWindow;
else {
- rc = dixLookupWindow(&confineTo, rconfineTo, client, DixSetAttrAccess);
+ rc = dixLookupWindow(&confineTo, param->confineTo, client, DixSetAttrAccess);
if (rc != Success)
return rc;
}
- if (rcursor == None)
+ if (param->cursor == None)
cursor = NullCursor;
else {
- rc = dixLookupResourceByType((pointer *)&cursor, rcursor, RT_CURSOR,
- client, DixUseAccess);
+ rc = dixLookupResourceByType((pointer *)&cursor, param->cursor,
+ RT_CURSOR, client, DixUseAccess);
if (rc != Success)
{
- client->errorValue = rcursor;
+ client->errorValue = param->cursor;
return (rc == BadValue) ? BadCursor : rc;
}
access_mode |= DixForceAccess;
}
- if (this_device_mode == GrabModeSync || other_devices_mode == GrabModeSync)
+ if (param->this_device_mode == GrabModeSync || param->other_devices_mode == GrabModeSync)
access_mode |= DixFreezeAccess;
rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
if (rc != Success)
return rc;
- rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
+ rc = dixLookupWindow(&pWin, param->grabWindow, client, DixSetAttrAccess);
if (rc != Success)
return rc;
- grab = CreateGrab(client->index, dev, pWin, eventMask,
- (Bool) ownerEvents, (Bool) this_device_mode,
- (Bool) other_devices_mode, modifier_device, modifiers,
- DeviceButtonPress, GRABTYPE_XI, button, confineTo, cursor);
+ grab = CreateGrab(client->index, dev, modifier_device, pWin, grabtype,
+ mask, param, DeviceButtonPress, button, confineTo, cursor);
if (!grab)
return BadAlloc;
return AddPassiveGrabToList(client, grab);
}
int
-GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
- BYTE other_devices_mode, CARD16 modifiers,
- DeviceIntPtr modifier_device, CARD8 key, Window grabWindow,
- BOOL ownerEvents, Mask mask)
+GrabKey(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
+ int key, GrabParameters *param, GrabType grabtype, GrabMask *mask)
{
WindowPtr pWin;
GrabPtr grab;
@@ -1440,8 +1433,7 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
Mask access_mode = DixGrabAccess;
int rc;
- rc = CheckGrabValues(client, dev, this_device_mode, other_devices_mode,
- modifiers, ownerEvents);
+ rc = CheckGrabValues(client, param);
if (rc != Success)
return rc;
if (k == NULL)
@@ -1452,19 +1444,17 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
client->errorValue = key;
return BadValue;
}
- rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
+ rc = dixLookupWindow(&pWin, param->grabWindow, client, DixSetAttrAccess);
if (rc != Success)
return rc;
- if (this_device_mode == GrabModeSync || other_devices_mode == GrabModeSync)
+ if (param->this_device_mode == GrabModeSync || param->other_devices_mode == GrabModeSync)
access_mode |= DixFreezeAccess;
rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
if (rc != Success)
return rc;
- grab = CreateGrab(client->index, dev, pWin,
- mask, ownerEvents, this_device_mode, other_devices_mode,
- modifier_device, modifiers, DeviceKeyPress, GRABTYPE_XI,
- key, NullWindow, NullCursor);
+ grab = CreateGrab(client->index, dev, modifier_device, pWin, grabtype,
+ mask, param, DeviceKeyPress, key, NULL, NULL);
if (!grab)
return BadAlloc;
return AddPassiveGrabToList(client, grab);
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 61ced4813..0d1eb636b 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -103,6 +103,8 @@ ProcXGrabDeviceButton(ClientPtr client)
DeviceIntPtr mdev;
XEventClass *class;
struct tmask tmp[EMASKSIZE];
+ GrabParameters param;
+ GrabMask mask;
REQUEST(xGrabDeviceButtonReq);
REQUEST_AT_LEAST_SIZE(xGrabDeviceButtonReq);
@@ -135,10 +137,17 @@ ProcXGrabDeviceButton(ClientPtr client)
stuff->event_count, tmp, dev,
X_GrabDeviceButton)) != Success)
return ret;
- ret = GrabButton(client, dev, stuff->this_device_mode,
- stuff->other_devices_mode, stuff->modifiers, mdev,
- stuff->button, stuff->grabWindow, stuff->ownerEvents,
- (Cursor) 0, (Window) 0, tmp[stuff->grabbed_device].mask);
+
+ memset(&param, 0, sizeof(param));
+ param.ownerEvents = stuff->ownerEvents;
+ param.this_device_mode = stuff->this_device_mode;
+ param.other_devices_mode = stuff->other_devices_mode;
+ param.grabWindow = stuff->grabWindow;
+ param.modifiers = stuff->modifiers;
+ mask.xi = tmp[stuff->grabbed_device].mask;
+
+ ret = GrabButton(client, dev, mdev, stuff->button, &param,
+ GRABTYPE_XI, &mask);
return ret;
}
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index aefe11b1e..96e2e62ac 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -101,6 +101,8 @@ ProcXGrabDeviceKey(ClientPtr client)
DeviceIntPtr mdev;
XEventClass *class;
struct tmask tmp[EMASKSIZE];
+ GrabParameters param;
+ GrabMask mask;
REQUEST(xGrabDeviceKeyReq);
REQUEST_AT_LEAST_SIZE(xGrabDeviceKeyReq);
@@ -133,10 +135,16 @@ ProcXGrabDeviceKey(ClientPtr client)
X_GrabDeviceKey)) != Success)
return ret;
- ret = GrabKey(client, dev, stuff->this_device_mode,
- stuff->other_devices_mode, stuff->modifiers, mdev,
- stuff->key, stuff->grabWindow, stuff->ownerEvents,
- tmp[stuff->grabbed_device].mask);
+
+ memset(&param, 0, sizeof(param));
+ param.ownerEvents = stuff->ownerEvents;
+ param.this_device_mode = stuff->this_device_mode;
+ param.other_devices_mode = stuff->other_devices_mode;
+ param.grabWindow = stuff->grabWindow;
+ param.modifiers = stuff->modifiers;
+ mask.xi = tmp[stuff->grabbed_device].mask;
+
+ ret = GrabKey(client, dev, mdev, stuff->key, &param, GRABTYPE_XI, &mask);
return ret;
}
diff --git a/dix/events.c b/dix/events.c
index c87a36118..6fe218228 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5022,25 +5022,21 @@ ProcGrabKey(ClientPtr client)
GrabPtr grab;
DeviceIntPtr keybd = PickKeyboard(client);
int rc;
+ GrabParameters param;
+ GrabMask mask;
REQUEST_SIZE_MATCH(xGrabKeyReq);
- if ((stuff->ownerEvents != xTrue) && (stuff->ownerEvents != xFalse))
- {
- client->errorValue = stuff->ownerEvents;
- return(BadValue);
- }
- if ((stuff->pointerMode != GrabModeSync) &&
- (stuff->pointerMode != GrabModeAsync))
- {
- client->errorValue = stuff->pointerMode;
- return BadValue;
- }
- if ((stuff->keyboardMode != GrabModeSync) &&
- (stuff->keyboardMode != GrabModeAsync))
- {
- client->errorValue = stuff->keyboardMode;
- return BadValue;
- }
+
+ memset(&param, 0, sizeof(param));
+ param.ownerEvents = stuff->ownerEvents;
+ param.this_device_mode = stuff->keyboardMode;
+ param.other_devices_mode = stuff->pointerMode;
+ param.modifiers = stuff->modifiers;
+
+ rc = CheckGrabValues(client, &param);
+ if (rc != Success)
+ return rc;
+
if (((stuff->key > keybd->key->xkbInfo->desc->max_key_code) ||
(stuff->key < keybd->key->xkbInfo->desc->min_key_code))
&& (stuff->key != AnyKey))
@@ -5048,21 +5044,15 @@ ProcGrabKey(ClientPtr client)
client->errorValue = stuff->key;
return BadValue;
}
- if ((stuff->modifiers != AnyModifier) &&
- (stuff->modifiers & ~AllModifiersMask))
- {
- client->errorValue = stuff->modifiers;
- return BadValue;
- }
rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
if (rc != Success)
return rc;
- grab = CreateGrab(client->index, keybd, pWin,
- (Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents,
- (Bool)stuff->keyboardMode, (Bool)stuff->pointerMode,
- keybd, stuff->modifiers, KeyPress, GRABTYPE_CORE, stuff->key,
- NullWindow, NullCursor);
+
+ mask.core = (KeyPressMask | KeyReleaseMask);
+
+ grab = CreateGrab(client->index, keybd, keybd, pWin, GRABTYPE_CORE, &mask,
+ &param, KeyPress, stuff->key, NullWindow, NullCursor);
if (!grab)
return BadAlloc;
return AddPassiveGrabToList(client, grab);
@@ -5084,6 +5074,8 @@ ProcGrabButton(ClientPtr client)
GrabPtr grab;
DeviceIntPtr ptr, modifierDevice;
Mask access_mode = DixGrabAccess;
+ GrabMask mask;
+ GrabParameters param;
int rc;
REQUEST_SIZE_MATCH(xGrabButtonReq);
@@ -5150,11 +5142,17 @@ ProcGrabButton(ClientPtr client)
if (rc != Success)
return rc;
- grab = CreateGrab(client->index, ptr, pWin,
- (Mask)stuff->eventMask, (Bool)stuff->ownerEvents,
- (Bool) stuff->keyboardMode, (Bool)stuff->pointerMode,
- modifierDevice, stuff->modifiers, ButtonPress, GRABTYPE_CORE,
- stuff->button, confineTo, cursor);
+ memset(&param, 0, sizeof(param));
+ param.ownerEvents = stuff->ownerEvents;
+ param.this_device_mode = stuff->keyboardMode;
+ param.other_devices_mode = stuff->pointerMode;
+ param.modifiers = stuff->modifiers;
+
+ mask.core = stuff->eventMask;
+
+ grab = CreateGrab(client->index, ptr, modifierDevice, pWin,
+ GRABTYPE_CORE, &mask, &param, ButtonPress,
+ stuff->button, confineTo, cursor);
if (!grab)
return BadAlloc;
return AddPassiveGrabToList(client, grab);
diff --git a/dix/grabs.c b/dix/grabs.c
index cd34f7e51..06e1ebb6e 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -58,6 +58,7 @@ SOFTWARE.
#include "cursorstr.h"
#include "dixgrabs.h"
#include "xace.h"
+#include "exevents.h"
#define BITMASK(i) (((Mask)1) << ((i) & 31))
#define MASKIDX(i) ((i) >> 5)
@@ -70,13 +71,12 @@ GrabPtr
CreateGrab(
int client,
DeviceIntPtr device,
- WindowPtr window,
- Mask eventMask,
- Bool ownerEvents, Bool keyboardMode, Bool pointerMode,
DeviceIntPtr modDevice,
- unsigned short modifiers,
+ WindowPtr window,
+ GrabType grabtype,
+ GrabMask *mask,
+ GrabParameters *param,
int type,
- int grabtype,
KeyCode keybut, /* key or button */
WindowPtr confineTo,
CursorPtr cursor)
@@ -89,12 +89,12 @@ CreateGrab(
grab->resource = FakeClientID(client);
grab->device = device;
grab->window = window;
- grab->eventMask = eventMask;
+ grab->eventMask = mask->core; /* same for XI */
grab->deviceMask = 0;
- grab->ownerEvents = ownerEvents;
- grab->keyboardMode = keyboardMode;
- grab->pointerMode = pointerMode;
- grab->modifiersDetail.exact = modifiers;
+ grab->ownerEvents = param->ownerEvents;
+ grab->keyboardMode = param->this_device_mode;
+ grab->pointerMode = param->other_devices_mode;
+ grab->modifiersDetail.exact = param->modifiers;
grab->modifiersDetail.pMask = NULL;
grab->modifierDevice = modDevice;
grab->type = type;
@@ -434,17 +434,21 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
&& (pMinuendGrab->modifiersDetail.exact != AnyModifier))
{
GrabPtr pNewGrab;
+ GrabParameters param;
UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact);
+ memset(&param, 0, sizeof(param));
+ param.ownerEvents = grab->ownerEvents;
+ param.this_device_mode = grab->keyboardMode;
+ param.other_devices_mode = grab->pointerMode;
+ param.modifiers = AnyModifier;
+
pNewGrab = CreateGrab(CLIENT_ID(grab->resource), grab->device,
- grab->window, (Mask)grab->eventMask,
- (Bool)grab->ownerEvents,
- (Bool)grab->keyboardMode,
- (Bool)grab->pointerMode,
- grab->modifierDevice,
- AnyModifier, (int)grab->type,
+ grab->modifierDevice, grab->window,
grab->grabtype,
+ (GrabMask*)grab->eventMask,
+ &param, (int)grab->type,
pMinuendGrab->detail.exact,
grab->confineTo, grab->cursor);
if (!pNewGrab)
diff --git a/include/dixgrabs.h b/include/dixgrabs.h
index 512723986..3b2a46d72 100644
--- a/include/dixgrabs.h
+++ b/include/dixgrabs.h
@@ -26,21 +26,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef DIXGRABS_H
#define DIXGRABS_H 1
-extern _X_EXPORT GrabPtr CreateGrab(
+struct _GrabParameters;
+
+extern GrabPtr CreateGrab(
int /* client */,
DeviceIntPtr /* device */,
- WindowPtr /* window */,
- Mask /* eventMask */,
- Bool /* ownerEvents */,
- Bool /* keyboardMode */,
- Bool /* pointerMode */,
DeviceIntPtr /* modDevice */,
- unsigned short /* modifiers */,
+ WindowPtr /* window */,
+ GrabType /* grabtype */,
+ GrabMask * /* mask */,
+ struct _GrabParameters * /* param */,
int /* type */,
- int /* grabtype */,
KeyCode /* keybut */,
- WindowPtr /* confineTo */,
- CursorPtr /* cursor */);
+ WindowPtr /* confineTo */,
+ CursorPtr /* cursor */);
extern _X_EXPORT int DeletePassiveGrab(
pointer /* value */,
diff --git a/include/exevents.h b/include/exevents.h
index fc1c23f27..95d08cc7f 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -42,6 +42,18 @@ typedef struct _XIClientRec {
int minor_version;
} XIClientRec, *XIClientPtr;
+
+typedef struct _GrabParameters {
+ unsigned int ownerEvents;
+ unsigned int this_device_mode;
+ unsigned int other_devices_mode;
+ Window grabWindow;
+ Window confineTo;
+ Cursor cursor;
+ unsigned int modifiers;
+} GrabParameters;
+
+
extern _X_EXPORT void RegisterOtherDevice (
DeviceIntPtr /* device */);
@@ -73,31 +85,27 @@ extern _X_EXPORT void DeviceFocusEvent(
int /* detail */,
WindowPtr /* pWin */);
-extern _X_EXPORT int GrabButton(
+extern int CheckGrabValues(
+ ClientPtr /* client */,
+ GrabParameters* /* param */);
+
+extern int GrabButton(
ClientPtr /* client */,
DeviceIntPtr /* dev */,
- BYTE /* this_device_mode */,
- BYTE /* other_devices_mode */,
- CARD16 /* modifiers */,
DeviceIntPtr /* modifier_device */,
- CARD8 /* button */,
- Window /* grabWindow */,
- BOOL /* ownerEvents */,
- Cursor /* rcursor */,
- Window /* rconfineTo */,
- Mask /* eventMask */);
-
-extern _X_EXPORT int GrabKey(
+ int /* button */,
+ GrabParameters* /* param */,
+ GrabType /* grabtype */,
+ GrabMask* /* eventMask */);
+
+extern int GrabKey(
ClientPtr /* client */,
DeviceIntPtr /* dev */,
- BYTE /* this_device_mode */,
- BYTE /* other_devices_mode */,
- CARD16 /* modifiers */,
DeviceIntPtr /* modifier_device */,
- CARD8 /* key */,
- Window /* grabWindow */,
- BOOL /* ownerEvents */,
- Mask /* mask */);
+ int /* key */,
+ GrabParameters* /* param */,
+ GrabType /* grabtype */,
+ GrabMask* /* eventMask */);
extern int SelectForWindow(
DeviceIntPtr /* dev */,
diff --git a/test/input.c b/test/input.c
index eb0543eda..a9027f0d3 100644
--- a/test/input.c
+++ b/test/input.c
@@ -33,6 +33,7 @@
#include "windowstr.h"
#include "inputstr.h"
#include "eventconvert.h"
+#include "exevents.h"
#include <glib.h>
@@ -73,6 +74,66 @@ static void dix_init_valuators(void)
g_assert(dev.last.numValuators == num_axes);
}
+/* just check the known success cases, and that error cases set the client's
+ * error value correctly. */
+static void dix_check_grab_values(void)
+{
+ ClientRec client;
+ GrabParameters param;
+ int rc;
+
+ memset(&client, 0, sizeof(client));
+
+ param.this_device_mode = GrabModeSync;
+ param.other_devices_mode = GrabModeSync;
+ param.modifiers = AnyModifier;
+ param.ownerEvents = FALSE;
+
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == Success);
+
+ param.this_device_mode = GrabModeAsync;
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == Success);
+
+ param.this_device_mode = GrabModeAsync + 1;
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == BadValue);
+ g_assert(client.errorValue == param.this_device_mode);
+ g_assert(client.errorValue == GrabModeAsync + 1);
+
+ param.this_device_mode = GrabModeSync;
+ param.other_devices_mode = GrabModeAsync;
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == Success);
+
+ param.other_devices_mode = GrabModeAsync + 1;
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == BadValue);
+ g_assert(client.errorValue == param.other_devices_mode);
+ g_assert(client.errorValue == GrabModeAsync + 1);
+
+ param.other_devices_mode = GrabModeSync;
+
+ param.modifiers = 1 << 13;
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == BadValue);
+ g_assert(client.errorValue == param.modifiers);
+ g_assert(client.errorValue == (1 << 13));
+
+
+ param.modifiers = AnyModifier;
+ param.ownerEvents = TRUE;
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == Success);
+
+ param.ownerEvents = 3;
+ rc = CheckGrabValues(&client, &param);
+ g_assert(rc == BadValue);
+ g_assert(client.errorValue == param.ownerEvents);
+ g_assert(client.errorValue == 3);
+}
+
/**
* Convert various internal events to the matching core event and verify the
@@ -222,6 +283,7 @@ int main(int argc, char** argv)
g_test_add_func("/dix/input/init-valuators", dix_init_valuators);
g_test_add_func("/dix/input/event-core-conversion", dix_event_to_core_conversion);
+ g_test_add_func("/dix/input/check-grab-values", dix_check_grab_values);
return g_test_run();
}