diff options
author | Jeremy Huddleston <jeremyhu@freedesktop.org> | 2009-09-27 17:08:12 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@freedesktop.org> | 2009-09-27 23:31:07 -0700 |
commit | 226b1033b48807fd6871ba626e20ef1411904939 (patch) | |
tree | 7f6574b1ab5be11c988b0db44103a06ce750b47a /hw/xquartz/darwinEvents.c | |
parent | 0c2731596f27f2cdf5000ba41de37e7eb86ad6f9 (diff) |
XQuartz: Transition from xEvent based mieq to InternalEvent
(cherry picked from commit a3dbde2de87ee4f577748a8c447501a3ea462559)
Diffstat (limited to 'hw/xquartz/darwinEvents.c')
-rw-r--r-- | hw/xquartz/darwinEvents.c | 241 |
1 files changed, 112 insertions, 129 deletions
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c index 4822af479..d300cce05 100644 --- a/hw/xquartz/darwinEvents.c +++ b/hw/xquartz/darwinEvents.c @@ -43,6 +43,7 @@ in this Software without prior written authorization from The Open Group. #include "windowstr.h" #include "pixmapstr.h" #include "inputstr.h" +#include "eventstr.h" #include "mi.h" #include "scrnintstr.h" #include "mipointer.h" @@ -71,7 +72,7 @@ in this Software without prior written authorization from The Open Group. #include "applewmExt.h" /* FIXME: Abstract this better */ -void QuartzModeEQInit(void); +extern Bool QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev); int darwin_all_modifier_flags = 0; // last known modifier state int darwin_all_modifier_mask = 0; @@ -84,7 +85,7 @@ static pthread_mutex_t fd_add_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t fd_add_ready_cond = PTHREAD_COND_INITIALIZER; static pthread_t fd_add_tid = NULL; -static EventList *darwinEvents = NULL; +static EventListPtr darwinEvents = NULL; static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER; @@ -190,89 +191,98 @@ static void DarwinUpdateModifiers( be moved into their own individual functions and set as handlers using mieqSetHandler. */ -static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) { - int i; - +static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) { + XQuartzEvent *e = &(ie->xquartz_event); + TA_SERVER(); -// DEBUG_LOG("DarwinEventHandler(%d, %p, %p, %d)\n", screenNum, xe, dev, nevents); - for (i=0; i<nevents; i++) { - switch(xe[i].u.u.type) { - case kXquartzControllerNotify: - DEBUG_LOG("kXquartzControllerNotify\n"); - AppleWMSendEvent(AppleWMControllerNotify, - AppleWMControllerNotifyMask, - xe[i].u.clientMessage.u.l.longs0, - xe[i].u.clientMessage.u.l.longs1); - break; - - case kXquartzPasteboardNotify: - DEBUG_LOG("kXquartzPasteboardNotify\n"); - AppleWMSendEvent(AppleWMPasteboardNotify, - AppleWMPasteboardNotifyMask, - xe[i].u.clientMessage.u.l.longs0, - xe[i].u.clientMessage.u.l.longs1); - break; - - case kXquartzActivate: - DEBUG_LOG("kXquartzActivate\n"); - QuartzShow(xe[i].u.keyButtonPointer.rootX, - xe[i].u.keyButtonPointer.rootY); - AppleWMSendEvent(AppleWMActivationNotify, - AppleWMActivationNotifyMask, - AppleWMIsActive, 0); - break; - - case kXquartzDeactivate: - DEBUG_LOG("kXquartzDeactivate\n"); - AppleWMSendEvent(AppleWMActivationNotify, - AppleWMActivationNotifyMask, - AppleWMIsInactive, 0); + switch(e->subtype) { + case kXquartzControllerNotify: + DEBUG_LOG("kXquartzControllerNotify\n"); + AppleWMSendEvent(AppleWMControllerNotify, + AppleWMControllerNotifyMask, + e->data[0], + e->data[1]); + break; + + case kXquartzPasteboardNotify: + DEBUG_LOG("kXquartzPasteboardNotify\n"); + AppleWMSendEvent(AppleWMPasteboardNotify, + AppleWMPasteboardNotifyMask, + e->data[0], + e->data[1]); + break; + + case kXquartzActivate: + DEBUG_LOG("kXquartzActivate\n"); + QuartzShow(); + AppleWMSendEvent(AppleWMActivationNotify, + AppleWMActivationNotifyMask, + AppleWMIsActive, 0); + break; + + case kXquartzDeactivate: + DEBUG_LOG("kXquartzDeactivate\n"); + AppleWMSendEvent(AppleWMActivationNotify, + AppleWMActivationNotifyMask, + AppleWMIsInactive, 0); + QuartzHide(); + break; + + case kXquartzReloadPreferences: + DEBUG_LOG("kXquartzReloadPreferences\n"); + AppleWMSendEvent(AppleWMActivationNotify, + AppleWMActivationNotifyMask, + AppleWMReloadPreferences, 0); + break; + + case kXquartzToggleFullscreen: + DEBUG_LOG("kXquartzToggleFullscreen\n"); + if (quartzEnableRootless) + QuartzSetFullscreen(!quartzHasRoot); + else if (quartzHasRoot) QuartzHide(); - break; - - case kXquartzReloadPreferences: - DEBUG_LOG("kXquartzReloadPreferences\n"); - AppleWMSendEvent(AppleWMActivationNotify, - AppleWMActivationNotifyMask, - AppleWMReloadPreferences, 0); - break; - - case kXquartzToggleFullscreen: - DEBUG_LOG("kXquartzToggleFullscreen\n"); - if (quartzEnableRootless) - QuartzSetFullscreen(!quartzHasRoot); - else if (quartzHasRoot) - QuartzHide(); - else - QuartzShow(xe[i].u.keyButtonPointer.rootX, - xe[i].u.keyButtonPointer.rootY); - break; - - case kXquartzSetRootless: - DEBUG_LOG("kXquartzSetRootless\n"); - QuartzSetRootless(xe[i].u.clientMessage.u.l.longs0); - if (!quartzEnableRootless && !quartzHasRoot) - QuartzHide(); - break; - - case kXquartzSetRootClip: - QuartzSetRootClip((Bool)xe[i].u.clientMessage.u.l.longs0); - break; - - case kXquartzQuit: - GiveUp(0); - break; - - case kXquartzSpaceChanged: - DEBUG_LOG("kXquartzSpaceChanged\n"); - QuartzSpaceChanged(xe[i].u.clientMessage.u.l.longs0); - break; - - default: - ErrorF("Unknown application defined event type %d.\n", xe[i].u.u.type); - } - } + else + QuartzShow(); + break; + + case kXquartzSetRootless: + DEBUG_LOG("kXquartzSetRootless\n"); + QuartzSetRootless(e->data[0]); + if (!quartzEnableRootless && !quartzHasRoot) + QuartzHide(); + break; + + case kXquartzSetRootClip: + QuartzSetRootClip((Bool)e->data[0]); + break; + + case kXquartzQuit: + GiveUp(0); + break; + + case kXquartzSpaceChanged: + DEBUG_LOG("kXquartzSpaceChanged\n"); + QuartzSpaceChanged(e->data[0]); + break; + + case kXquartzListenOnOpenFD: + ErrorF("Calling ListenOnOpenFD() for new fd: %d\n", (int)e->data[0]); + ListenOnOpenFD((int)e->data[0], 1); + break; + + case kXquartzReloadKeymap: + DarwinKeyboardReloadHandler(); + break; + + case kXquartzDisplayChanged: + QuartzUpdateScreens(); + break; + + default: + if(!QuartzModeEventHandler(screenNum, e, dev)) + ErrorF("Unknown application defined event type %d.\n", e->subtype); + } } void DarwinListenOnOpenFD(int fd) { @@ -298,16 +308,6 @@ static void DarwinProcessFDAdditionQueue_thread(void *args) { } } -static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) { - size_t i; - TA_SERVER(); - - for (i=0; i<nevents; i++) { - ErrorF("Calling ListenOnOpenFD() for new fd: %d\n", (int)xe[i].u.clientMessage.u.l.longs0); - ListenOnOpenFD((int)xe[i].u.clientMessage.u.l.longs0, 1); - } -} - Bool DarwinEQInit(void) { int *p; @@ -320,23 +320,7 @@ Bool DarwinEQInit(void) { } mieqInit(); - mieqSetHandler(kXquartzReloadKeymap, DarwinKeyboardReloadHandler); - mieqSetHandler(kXquartzActivate, DarwinEventHandler); - mieqSetHandler(kXquartzDeactivate, DarwinEventHandler); - mieqSetHandler(kXquartzReloadPreferences, DarwinEventHandler); - mieqSetHandler(kXquartzSetRootClip, DarwinEventHandler); - mieqSetHandler(kXquartzQuit, DarwinEventHandler); - mieqSetHandler(kXquartzReadPasteboard, QuartzReadPasteboard); - mieqSetHandler(kXquartzWritePasteboard, QuartzWritePasteboard); - mieqSetHandler(kXquartzToggleFullscreen, DarwinEventHandler); - mieqSetHandler(kXquartzSetRootless, DarwinEventHandler); - mieqSetHandler(kXquartzSpaceChanged, DarwinEventHandler); - mieqSetHandler(kXquartzControllerNotify, DarwinEventHandler); - mieqSetHandler(kXquartzPasteboardNotify, DarwinEventHandler); - mieqSetHandler(kXquartzDisplayChanged, QuartzDisplayChangedHandler); - mieqSetHandler(kXquartzListenOnOpenFD, kXquartzListenOnOpenFDHandler); - - QuartzModeEQInit(); + mieqSetHandler(ET_XQuartz, DarwinEventHandler); /* Note that this *could* cause a potential async issue, since we're checking * darwinEvents without holding the lock, but darwinEvents is only ever set @@ -364,16 +348,16 @@ Bool DarwinEQInit(void) { * Read and process events from the event queue until it is empty. */ void ProcessInputEvents(void) { - xEvent xe; - int x = sizeof(xe); + char nullbyte; + int x = sizeof(nullbyte); TA_SERVER(); mieqProcessInputEvents(); // Empty the signaling pipe - while (x == sizeof(xe)) { - x = read(darwinEventReadFD, &xe, sizeof(xe)); + while (x == sizeof(nullbyte)) { + x = read(darwinEventReadFD, &nullbyte, sizeof(nullbyte)); } } @@ -382,7 +366,7 @@ void ProcessInputEvents(void) { static void DarwinPokeEQ(void) { char nullbyte=0; // <daniels> oh, i ... er ... christ. - write(darwinEventWriteFD, &nullbyte, 1); + write(darwinEventWriteFD, &nullbyte, sizeof(nullbyte)); } /* Convert from Appkit pointer input values to X input values: @@ -476,7 +460,7 @@ void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, floa darwinEvents_lock(); { num_events = GetPointerEvents(darwinEvents, pDev, ev_type, ev_button, POINTER_ABSOLUTE, 0, pDev==darwinTabletCurrent?5:2, valuators); - for(i=0; i<num_events; i++) mieqEnqueue (pDev, darwinEvents[i].event); + for(i=0; i<num_events; i++) mieqEnqueue (pDev, (InternalEvent*)darwinEvents[i].event); if(num_events > 0) DarwinPokeEQ(); } darwinEvents_unlock(); } @@ -491,7 +475,7 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) { darwinEvents_lock(); { num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE); - for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard,darwinEvents[i].event); + for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard, (InternalEvent*)darwinEvents[i].event); if(num_events > 0) DarwinPokeEQ(); } darwinEvents_unlock(); } @@ -519,7 +503,7 @@ void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y) { darwinEvents_lock(); { num_events = GetProximityEvents(darwinEvents, pDev, ev_type, 0, 5, valuators); - for(i=0; i<num_events; i++) mieqEnqueue (pDev,darwinEvents[i].event); + for(i=0; i<num_events; i++) mieqEnqueue (pDev, (InternalEvent*)darwinEvents[i].event); if(num_events > 0) DarwinPokeEQ(); } darwinEvents_unlock(); } @@ -566,27 +550,26 @@ void DarwinUpdateModKeys(int flags) { * Send the X server thread a message by placing it on the event queue. */ void DarwinSendDDXEvent(int type, int argc, ...) { - xEvent xe; - INT32 *argv; - int i, max_args; + XQuartzEvent e; + int i; va_list args; - memset(&xe, 0, sizeof(xe)); - xe.u.u.type = type; - xe.u.clientMessage.u.l.type = type; - - argv = &xe.u.clientMessage.u.l.longs0; - max_args = 4; + memset(&e, 0, sizeof(e)); + e.header = ET_Internal; + e.type = ET_XQuartz; + e.length = sizeof(e); + e.time = GetTimeInMillis(); + e.subtype = type; - if (argc > 0 && argc <= max_args) { + if (argc > 0 && argc < XQUARTZ_EVENT_MAXARGS) { va_start (args, argc); for (i = 0; i < argc; i++) - argv[i] = (int) va_arg (args, int); + e.data[i] = (uint32_t) va_arg (args, uint32_t); va_end (args); } darwinEvents_lock(); { - mieqEnqueue(NULL, &xe); + mieqEnqueue(NULL, (InternalEvent*)&e); DarwinPokeEQ(); } darwinEvents_unlock(); } |