aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/Xi/exevents.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/Xi/exevents.c')
-rw-r--r--xorg-server/Xi/exevents.c147
1 files changed, 74 insertions, 73 deletions
diff --git a/xorg-server/Xi/exevents.c b/xorg-server/Xi/exevents.c
index 1fa030a92..1c8633a8f 100644
--- a/xorg-server/Xi/exevents.c
+++ b/xorg-server/Xi/exevents.c
@@ -706,6 +706,55 @@ ChangeMasterDeviceClasses(DeviceIntPtr device, DeviceChangedEvent *dce)
}
/**
+ * Add state and motionMask to the filter for this event. The protocol
+ * supports some extra masks for motion when a button is down:
+ * ButtonXMotionMask and the DeviceButtonMotionMask to trigger only when at
+ * least one button (or that specific button is down). These masks need to
+ * be added to the filters for core/XI motion events.
+ *
+ * @param device The device to update the mask for
+ * @param state The current button state mask
+ * @param motion_mask The motion mask (DeviceButtonMotionMask or 0)
+ */
+static void
+UpdateDeviceMotionMask(DeviceIntPtr device, unsigned short state,
+ Mask motion_mask)
+{
+ Mask mask;
+
+ mask = DevicePointerMotionMask | state | motion_mask;
+ SetMaskForEvent(device->id, mask, DeviceMotionNotify);
+ mask = PointerMotionMask | state | motion_mask;
+ SetMaskForEvent(device->id, mask, MotionNotify);
+}
+
+static void
+IncreaseButtonCount(DeviceIntPtr dev, int key, CARD8 *buttons_down,
+ Mask *motion_mask, unsigned short *state)
+{
+ if (dev->valuator)
+ dev->valuator->motionHintWindow = NullWindow;
+
+ (*buttons_down)++;
+ *motion_mask = DeviceButtonMotionMask;
+ if (dev->button->map[key] <= 5)
+ *state |= (Button1Mask >> 1) << dev->button->map[key];
+}
+
+static void
+DecreaseButtonCount(DeviceIntPtr dev, int key, CARD8 *buttons_down,
+ Mask *motion_mask, unsigned short *state)
+{
+ if (dev->valuator)
+ dev->valuator->motionHintWindow = NullWindow;
+
+ if (*buttons_down >= 1 && !--(*buttons_down))
+ *motion_mask = 0;
+ if (dev->button->map[key] <= 5)
+ *state &= ~((Button1Mask >> 1) << dev->button->map[key]);
+}
+
+/**
* Update the device state according to the data in the event.
*
* return values are
@@ -803,7 +852,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
device->valuator->motionHintWindow = NullWindow;
set_key_up(device, key, KEY_PROCESSED);
} else if (event->type == ET_ButtonPress) {
- Mask mask;
if (!b)
return DONT_PROCESS;
@@ -811,22 +859,13 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
return DONT_PROCESS;
set_button_down(device, key, BUTTON_PROCESSED);
- if (device->valuator)
- device->valuator->motionHintWindow = NullWindow;
+
if (!b->map[key])
return DONT_PROCESS;
- b->buttonsDown++;
- b->motionMask = DeviceButtonMotionMask;
- if (b->map[key] <= 5)
- b->state |= (Button1Mask >> 1) << b->map[key];
-
- /* Add state and motionMask to the filter for this event */
- mask = DevicePointerMotionMask | b->state | b->motionMask;
- SetMaskForEvent(device->id, mask, DeviceMotionNotify);
- mask = PointerMotionMask | b->state | b->motionMask;
- SetMaskForEvent(device->id, mask, MotionNotify);
+
+ IncreaseButtonCount(device, key, &b->buttonsDown, &b->motionMask, &b->state);
+ UpdateDeviceMotionMask(device, b->state, b->motionMask);
} else if (event->type == ET_ButtonRelease) {
- Mask mask;
if (!b)
return DONT_PROCESS;
@@ -852,20 +891,11 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
}
}
set_button_up(device, key, BUTTON_PROCESSED);
- if (device->valuator)
- device->valuator->motionHintWindow = NullWindow;
if (!b->map[key])
return DONT_PROCESS;
- if (b->buttonsDown >= 1 && !--b->buttonsDown)
- b->motionMask = 0;
- if (b->map[key] <= 5)
- b->state &= ~((Button1Mask >> 1) << b->map[key]);
-
- /* Add state and motionMask to the filter for this event */
- mask = DevicePointerMotionMask | b->state | b->motionMask;
- SetMaskForEvent(device->id, mask, DeviceMotionNotify);
- mask = PointerMotionMask | b->state | b->motionMask;
- SetMaskForEvent(device->id, mask, MotionNotify);
+
+ DecreaseButtonCount(device, key, &b->buttonsDown, &b->motionMask, &b->state);
+ UpdateDeviceMotionMask(device, b->state, b->motionMask);
} else if (event->type == ET_ProximityIn)
device->proximity->in_proximity = TRUE;
else if (event->type == ET_ProximityOut)
@@ -887,7 +917,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
int key = 0, rootX, rootY;
ButtonClassPtr b;
int ret = 0;
- int corestate, i;
+ int corestate;
DeviceIntPtr mouse = NULL, kbd = NULL;
DeviceEvent *event = &ev->device_event;
@@ -917,33 +947,8 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
mouse = NULL;
}
- /* core state needs to be assembled BEFORE the device is updated. */
- corestate = (kbd && kbd->key) ? XkbStateFieldFromRec(&kbd->key->xkbInfo->state) : 0;
- corestate |= (mouse && mouse->button) ? (mouse->button->state) : 0;
-
- for (i = 0; mouse && mouse->button && i < mouse->button->numButtons; i++)
- if (BitIsOn(mouse->button->down, i))
- SetBit(event->buttons, i);
-
- if (kbd && kbd->key)
- {
- XkbStatePtr state;
- /* we need the state before the event happens */
- if (event->type == ET_KeyPress || event->type == ET_KeyRelease)
- state = &kbd->key->xkbInfo->prev_state;
- else
- state = &kbd->key->xkbInfo->state;
-
- event->mods.base = state->base_mods;
- event->mods.latched = state->latched_mods;
- event->mods.locked = state->locked_mods;
- event->mods.effective = state->mods;
-
- event->group.base = state->base_group;
- event->group.latched = state->latched_group;
- event->group.locked = state->locked_group;
- event->group.effective = state->group;
- }
+ corestate = event_get_corestate(mouse, kbd);
+ event_set_state(mouse, kbd, event);
ret = UpdateDeviceState(device, event);
if (ret == DONT_PROCESS)
@@ -1000,9 +1005,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
case ET_KeyRelease:
if (grab && device->deviceGrab.fromPassiveGrab &&
(key == device->deviceGrab.activatingKey) &&
- (device->deviceGrab.grab->type == KeyPress ||
- device->deviceGrab.grab->type == DeviceKeyPress ||
- device->deviceGrab.grab->type == XI_KeyPress))
+ GrabIsKeyboardGrab(device->deviceGrab.grab))
deactivateDeviceGrab = TRUE;
break;
case ET_ButtonPress:
@@ -1022,9 +1025,7 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
event->detail.button = b->map[key];
if (grab && !b->buttonsDown &&
device->deviceGrab.fromPassiveGrab &&
- (device->deviceGrab.grab->type == ButtonPress ||
- device->deviceGrab.grab->type == DeviceButtonPress ||
- device->deviceGrab.grab->type == XI_ButtonPress))
+ GrabIsPointerGrab(device->deviceGrab.grab))
deactivateDeviceGrab = TRUE;
default:
break;
@@ -1392,9 +1393,9 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
int
CheckGrabValues(ClientPtr client, GrabParameters* param)
{
- if (param->grabtype != GRABTYPE_CORE &&
- param->grabtype != GRABTYPE_XI &&
- param->grabtype != GRABTYPE_XI2)
+ if (param->grabtype != CORE &&
+ param->grabtype != XI &&
+ param->grabtype != XI2)
{
ErrorF("[Xi] grabtype is invalid. This is a bug.\n");
return BadImplementation;
@@ -1411,7 +1412,7 @@ CheckGrabValues(ClientPtr client, GrabParameters* param)
return BadValue;
}
- if (param->grabtype != GRABTYPE_XI2 && (param->modifiers != AnyModifier) &&
+ if (param->grabtype != XI2 && (param->modifiers != AnyModifier) &&
(param->modifiers & ~AllModifiersMask)) {
client->errorValue = param->modifiers;
return BadValue;
@@ -1426,7 +1427,7 @@ CheckGrabValues(ClientPtr client, GrabParameters* param)
int
GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
- int button, GrabParameters *param, GrabType grabtype,
+ int button, GrabParameters *param, enum InputLevel grabtype,
GrabMask *mask)
{
WindowPtr pWin, confineTo;
@@ -1466,9 +1467,9 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
if (rc != Success)
return rc;
- if (grabtype == GRABTYPE_XI)
+ if (grabtype == XI)
type = DeviceButtonPress;
- else if (grabtype == GRABTYPE_XI2)
+ else if (grabtype == XI2)
type = XI_ButtonPress;
grab = CreateGrab(client->index, dev, modifier_device, pWin, grabtype,
@@ -1479,12 +1480,12 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
}
/**
- * Grab the given key. If grabtype is GRABTYPE_XI, the key is a keycode. If
- * grabtype is GRABTYPE_XI2, the key is a keysym.
+ * Grab the given key. If grabtype is XI, the key is a keycode. If
+ * grabtype is XI2, the key is a keysym.
*/
int
GrabKey(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
- int key, GrabParameters *param, GrabType grabtype, GrabMask *mask)
+ int key, GrabParameters *param, enum InputLevel grabtype, GrabMask *mask)
{
WindowPtr pWin;
GrabPtr grab;
@@ -1497,7 +1498,7 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
return rc;
if ((dev->id != XIAllDevices && dev->id != XIAllMasterDevices) && k == NULL)
return BadMatch;
- if (grabtype == GRABTYPE_XI)
+ if (grabtype == XI)
{
if ((key > k->xkbInfo->desc->max_key_code ||
key < k->xkbInfo->desc->min_key_code)
@@ -1506,7 +1507,7 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
return BadValue;
}
type = DeviceKeyPress;
- } else if (grabtype == GRABTYPE_XI2)
+ } else if (grabtype == XI2)
type = XI_KeyPress;
rc = dixLookupWindow(&pWin, param->grabWindow, client, DixSetAttrAccess);
@@ -1561,7 +1562,7 @@ GrabWindow(ClientPtr client, DeviceIntPtr dev, int type,
if (rc != Success)
return rc;
- grab = CreateGrab(client->index, dev, dev, pWin, GRABTYPE_XI2,
+ grab = CreateGrab(client->index, dev, dev, pWin, XI2,
mask, param, (type == XIGrabtypeEnter) ? XI_Enter : XI_FocusIn,
0, NULL, cursor);