diff options
Diffstat (limited to 'xorg-server/dix/getevents.c')
-rw-r--r-- | xorg-server/dix/getevents.c | 206 |
1 files changed, 129 insertions, 77 deletions
diff --git a/xorg-server/dix/getevents.c b/xorg-server/dix/getevents.c index 4dc937476..2cd36f3d1 100644 --- a/xorg-server/dix/getevents.c +++ b/xorg-server/dix/getevents.c @@ -47,6 +47,7 @@ #include "eventstr.h"
#include "eventconvert.h"
#include "inpututils.h"
+#include "mi.h"
#include <X11/extensions/XKBproto.h>
#include "xkbsrv.h"
@@ -82,19 +83,12 @@ double roundd(double f) /* Number of motion history events to store. */
#define MOTION_HISTORY_SIZE 256
-/* InputEventList is the container list for all input events generated by the
- * DDX. The DDX is expected to call GetEventList() and then pass the list into
- * Get{Pointer|Keyboard}Events.
+/**
+ * InputEventList is the storage for input events generated by
+ * QueuePointerEvents, QueueKeyboardEvents, and QueueProximityEvents.
+ * This list is allocated on startup by the DIX.
*/
-EventListPtr InputEventList = NULL;
-int InputEventListLen = 0;
-
-int
-GetEventList(EventListPtr* list)
-{
- *list = InputEventList;
- return InputEventListLen;
-}
+InternalEvent* InputEventList = NULL;
/**
* Pick some arbitrary size for Xi motion history.
@@ -238,7 +232,7 @@ set_valuators(DeviceIntPtr dev, DeviceEvent* event, ValuatorMask *mask) }
void
-CreateClassesChangedEvent(EventList* event,
+CreateClassesChangedEvent(InternalEvent* event,
DeviceIntPtr master,
DeviceIntPtr slave,
int type)
@@ -247,7 +241,7 @@ CreateClassesChangedEvent(EventList* event, DeviceChangedEvent *dce;
CARD32 ms = GetTimeInMillis();
- dce = (DeviceChangedEvent*)event->event;
+ dce = &event->changed_event;
memset(dce, 0, sizeof(DeviceChangedEvent));
dce->deviceid = slave->id;
dce->masterid = master->id;
@@ -691,15 +685,15 @@ clipValuators(DeviceIntPtr pDev, ValuatorMask *mask) * is done in the event processing).
* Pull in the coordinates from the MD if necessary.
*
- * @param events Pointer to a pre-allocated event list.
+ * @param events Pointer to a pre-allocated event array.
* @param dev The slave device that generated an event.
* @param type Either DEVCHANGE_POINTER_EVENT and/or DEVCHANGE_KEYBOARD_EVENT
* @param num_events The current number of events, returns the number of
* events if a DCCE was generated.
* @return The updated @events pointer.
*/
-EventListPtr
-UpdateFromMaster(EventListPtr events, DeviceIntPtr dev, int type, int *num_events)
+InternalEvent*
+UpdateFromMaster(InternalEvent* events, DeviceIntPtr dev, int type, int *num_events)
{
DeviceIntPtr master;
@@ -939,16 +933,49 @@ updateHistory(DeviceIntPtr dev, ValuatorMask *mask, CARD32 ms) }
}
+static void
+queueEventList(DeviceIntPtr device, InternalEvent *events, int nevents)
+{
+ int i;
+ for (i = 0; i < nevents; i++)
+ mieqEnqueue(device, &events[i]);
+}
+
+/**
+ * Generate internal events representing this keyboard event and enqueue
+ * them on the event queue.
+ *
+ * This function is not reentrant. Disable signals before calling.
+ *
+ * FIXME: flags for relative/abs motion?
+ *
+ * @param device The device to generate the event for
+ * @param type Event type, one of KeyPress or KeyRelease
+ * @param keycode Key code of the pressed/released key
+ * @param mask Valuator mask for valuators present for this event.
+ *
+ */
+void
+QueueKeyboardEvents(DeviceIntPtr device, int type,
+ int keycode, const ValuatorMask *mask)
+{
+ int nevents;
+
+ nevents = GetKeyboardEvents(InputEventList, device, type, keycode, mask);
+ queueEventList(device, InputEventList, nevents);
+}
+
/**
* Returns a set of InternalEvents for KeyPress/KeyRelease, optionally
* also with valuator events.
*
- * events is not NULL-terminated; the return value is the number of events.
- * The DDX is responsible for allocating the event structure in the first
- * place via GetMaximumEventsNum(), and for freeing it.
+ * The DDX is responsible for allocating the event list in the first
+ * place via InitEventList(), and for freeing it.
+ *
+ * @return the number of events written into events.
*/
int
-GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type,
+GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
int key_code, const ValuatorMask *mask_in) {
int num_events = 0;
CARD32 ms = 0;
@@ -981,7 +1008,7 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, ms = GetTimeInMillis();
- raw = (RawDeviceEvent*)events->event;
+ raw = &events->raw_event;
events++;
num_events++;
@@ -994,7 +1021,7 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, set_raw_valuators(raw, &mask, raw->valuators.data);
- event = (DeviceEvent*) events->event;
+ event = &events->device_event;
init_event(pDev, event, ms);
event->detail.key = key_code;
@@ -1015,37 +1042,16 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, }
/**
- * Initialize an event list and fill with 32 byte sized events.
+ * Initialize an event array large enough for num_events arrays.
* This event list is to be passed into GetPointerEvents() and
* GetKeyboardEvents().
*
* @param num_events Number of elements in list.
*/
-EventListPtr
+InternalEvent*
InitEventList(int num_events)
{
- EventListPtr events;
- int i;
-
- events = (EventListPtr)calloc(num_events, sizeof(EventList));
- if (!events)
- return NULL;
-
- for (i = 0; i < num_events; i++)
- {
- events[i].evlen = sizeof(InternalEvent);
- events[i].event = calloc(1, sizeof(InternalEvent));
- if (!events[i].event)
- {
- /* rollback */
- while(i--)
- free(events[i].event);
- free(events);
- events = NULL;
- break;
- }
- }
-
+ InternalEvent *events = calloc(num_events, sizeof(InternalEvent));
return events;
}
@@ -1056,41 +1062,54 @@ InitEventList(int num_events) * @param num_events Number of elements in list.
*/
void
-FreeEventList(EventListPtr list, int num_events)
+FreeEventList(InternalEvent *list, int num_events)
{
- if (!list)
- return;
- while(num_events--)
- free(list[num_events].event);
free(list);
}
static void
-transformAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
+transformAbsolute(DeviceIntPtr dev, ValuatorMask *mask, int *x, int *y)
{
struct pixman_f_vector p;
-
- /* p' = M * p in homogeneous coordinates */
- p.v[0] = (valuator_mask_isset(mask, 0) ? valuator_mask_get(mask, 0) :
- dev->last.valuators[0]);
- p.v[1] = (valuator_mask_isset(mask, 1) ? valuator_mask_get(mask, 1) :
- dev->last.valuators[1]);
- p.v[2] = 1.0;
+
+ p.v[0] = *x;
+ p.v[1] = *y;
+ p.v[2] = 1;
pixman_f_transform_point(&dev->transform, &p);
- if (lround(p.v[0]) != dev->last.valuators[0])
- valuator_mask_set(mask, 0, lround(p.v[0]));
- if (lround(p.v[1]) != dev->last.valuators[1])
- valuator_mask_set(mask, 1, lround(p.v[1]));
+ *x = lround(p.v[0]);
+ *y = lround(p.v[1]);
}
/**
- * Generate a series of InternalEvents (filled into the EventList)
- * representing pointer motion, or button presses.
+ * Generate internal events representing this pointer event and enqueue them
+ * on the event queue.
+ *
+ * This function is not reentrant. Disable signals before calling.
*
- * events is not NULL-terminated; the return value is the number of events.
- * The DDX is responsible for allocating the event structure in the first
+ * @param device The device to generate the event for
+ * @param type Event type, one of ButtonPress, ButtonRelease, MotionNotify
+ * @param buttons Button number of the buttons modified. Must be 0 for
+ * MotionNotify
+ * @param flags Event modification flags
+ * @param mask Valuator mask for valuators present for this event.
+ */
+void
+QueuePointerEvents(DeviceIntPtr device, int type,
+ int buttons, int flags, const ValuatorMask *mask)
+{
+ int nevents;
+
+ nevents = GetPointerEvents(InputEventList, device, type, buttons, flags, mask);
+ queueEventList(device, InputEventList, nevents);
+}
+
+/**
+ * Generate a series of InternalEvents representing pointer motion, or
+ * button presses.
+ *
+ * The DDX is responsible for allocating the events in the first
* place via InitEventList() and GetMaximumEventsNum(), and for freeing it.
*
* In the generated events rootX/Y will be in absolute screen coords and
@@ -1100,9 +1119,11 @@ transformAbsolute(DeviceIntPtr dev, ValuatorMask *mask) * last.valuators[x] of the master device is in absolute screen coords.
*
* master->last.valuators[x] for x > 2 is undefined.
+ *
+ * @return the number of events written into events.
*/
int
-GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
+GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons,
int flags, const ValuatorMask *mask_in) {
int num_events = 1;
CARD32 ms;
@@ -1140,7 +1161,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events);
- raw = (RawDeviceEvent*)events->event;
+ raw = &events->raw_event;
events++;
num_events++;
@@ -1173,7 +1194,16 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, }
}
- transformAbsolute(pDev, &mask);
+ x = (valuator_mask_isset(&mask, 0) ? valuator_mask_get(&mask, 0) :
+ pDev->last.valuators[0]);
+ y = (valuator_mask_isset(&mask, 1) ? valuator_mask_get(&mask, 1) :
+ pDev->last.valuators[1]);
+ transformAbsolute(pDev, &mask, &x, &y);
+ if (valuator_mask_isset(&mask, 0))
+ valuator_mask_set(&mask, 0, x);
+ if (valuator_mask_isset(&mask, 1))
+ valuator_mask_set(&mask, 1, y);
+
moveAbsolute(pDev, &x, &y, &mask);
} else {
if (flags & POINTER_ACCELERATE) {
@@ -1200,7 +1230,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, clipValuators(pDev, &mask);
- event = (DeviceEvent*) events->event;
+ event = &events->device_event;
init_event(pDev, event, ms);
if (type == MotionNotify) {
@@ -1229,17 +1259,39 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, return num_events;
}
+/**
+ * Generate internal events representing this proximity event and enqueue
+ * them on the event queue.
+ *
+ * This function is not reentrant. Disable signals before calling.
+ *
+ * @param device The device to generate the event for
+ * @param type Event type, one of ProximityIn or ProximityOut
+ * @param keycode Key code of the pressed/released key
+ * @param mask Valuator mask for valuators present for this event.
+ *
+ */
+void
+QueueProximityEvents(DeviceIntPtr device, int type,
+ const ValuatorMask *mask)
+{
+ int nevents;
+
+ nevents = GetProximityEvents(InputEventList, device, type, mask);
+ queueEventList(device, InputEventList, nevents);
+}
/**
* Generate ProximityIn/ProximityOut InternalEvents, accompanied by
* valuators.
*
- * events is not NULL-terminated; the return value is the number of events.
- * The DDX is responsible for allocating the event structure in the first
- * place via GetMaximumEventsNum(), and for freeing it.
+ * The DDX is responsible for allocating the events in the first place via
+ * InitEventList(), and for freeing it.
+ *
+ * @return the number of events written into events.
*/
int
-GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type, const ValuatorMask *mask_in)
+GetProximityEvents(InternalEvent *events, DeviceIntPtr pDev, int type, const ValuatorMask *mask_in)
{
int num_events = 1, i;
DeviceEvent *event;
@@ -1271,7 +1323,7 @@ GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type, const Valuato events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events);
- event = (DeviceEvent *) events->event;
+ event = &events->device_event;
init_event(pDev, event, GetTimeInMillis());
event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut;
|