2006-11-26 11:13:41 -07:00
|
|
|
/*
|
2012-06-10 07:21:05 -06:00
|
|
|
* Darwin event queue and event handling
|
|
|
|
*
|
|
|
|
* Copyright 2007-2008 Apple Inc.
|
|
|
|
* Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
|
|
|
|
* Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is based on mieq.c by Keith Packard,
|
|
|
|
* which contains the following copyright:
|
|
|
|
* Copyright 1990, 1998 The Open Group
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2012 Apple Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation files
|
|
|
|
* (the "Software"), to deal in the Software without restriction,
|
|
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
|
|
|
|
* HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name(s) of the above
|
|
|
|
* copyright holders shall not be used in advertising or otherwise to
|
|
|
|
* promote the sale, use or other dealings in this Software without
|
|
|
|
* prior written authorization.
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "sanitizedCarbon.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xmd.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#include "pixmapstr.h"
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "inpututils.h"
|
|
|
|
#include "eventstr.h"
|
|
|
|
#include "mi.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "mipointer.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "exglobals.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#include "darwin.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "quartz.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "quartzKeyboard.h"
|
2010-12-05 08:36:02 -07:00
|
|
|
#include "quartzRandR.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "darwinEvents.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <unistd.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <errno.h>
|
2011-11-05 07:32:40 -06:00
|
|
|
#include <time.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#include <IOKit/hidsystem/IOLLEvent.h>
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <X11/extensions/applewmconst.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "applewmExt.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* FIXME: Abstract this better */
|
2012-06-10 07:21:05 -06:00
|
|
|
extern Bool
|
|
|
|
QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int darwin_all_modifier_flags = 0; // last known modifier state
|
|
|
|
int darwin_all_modifier_mask = 0;
|
|
|
|
int darwin_x11_modifier_mask = 0;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
#define FD_ADD_MAX 128
|
|
|
|
static int fd_add[FD_ADD_MAX];
|
|
|
|
int fd_add_count = 0;
|
|
|
|
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;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
static InternalEvent* darwinEvents = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/*** Pthread Magics ***/
|
2012-06-10 07:21:05 -06:00
|
|
|
static pthread_t
|
|
|
|
create_thread(void *(*func)(void *), void *arg)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_t tid;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
pthread_create(&tid, &attr, func, arg);
|
|
|
|
pthread_attr_destroy(&attr);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return tid;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
darwinEvents_lock(void);
|
|
|
|
void
|
|
|
|
darwinEvents_lock(void)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
int err;
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((err = pthread_mutex_lock(&mieq_lock))) {
|
2009-09-06 13:44:18 -06:00
|
|
|
ErrorF("%s:%s:%d: Failed to lock mieq_lock: %d\n",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, err);
|
2011-11-05 07:32:40 -06:00
|
|
|
xorg_backtrace();
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (darwinEvents == NULL) {
|
2009-09-06 13:44:18 -06:00
|
|
|
pthread_cond_wait(&mieq_ready_cond, &mieq_lock);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
darwinEvents_unlock(void);
|
|
|
|
void
|
|
|
|
darwinEvents_unlock(void)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
int err;
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((err = pthread_mutex_unlock(&mieq_lock))) {
|
2009-09-06 13:44:18 -06:00
|
|
|
ErrorF("%s:%s:%d: Failed to unlock mieq_lock: %d\n",
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, err);
|
2011-11-05 07:32:40 -06:00
|
|
|
xorg_backtrace();
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
2009-09-06 13:44:18 -06:00
|
|
|
* DarwinPressModifierKey
|
|
|
|
* Press or release the given modifier key (one of NX_MODIFIERKEY_* constants)
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
DarwinPressModifierKey(int pressed, int key)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
int keycode = DarwinModifierNXKeyToNXKeycode(key, 0);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (keycode == 0) {
|
|
|
|
ErrorF("DarwinPressModifierKey bad keycode: key=%d\n", key);
|
|
|
|
return;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
DarwinSendKeyboardEvents(pressed, keycode);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-09-06 13:44:18 -06:00
|
|
|
* DarwinUpdateModifiers
|
|
|
|
* Send events to update the modifier state.
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static int darwin_x11_modifier_mask_list[] = {
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef NX_DEVICELCMDKEYMASK
|
2012-06-10 07:21:05 -06:00
|
|
|
NX_DEVICELCTLKEYMASK, NX_DEVICERCTLKEYMASK,
|
2009-09-06 13:44:18 -06:00
|
|
|
NX_DEVICELSHIFTKEYMASK, NX_DEVICERSHIFTKEYMASK,
|
2012-06-10 07:21:05 -06:00
|
|
|
NX_DEVICELCMDKEYMASK, NX_DEVICERCMDKEYMASK,
|
|
|
|
NX_DEVICELALTKEYMASK, NX_DEVICERALTKEYMASK,
|
2009-09-06 13:44:18 -06:00
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
NX_CONTROLMASK, NX_SHIFTMASK, NX_COMMANDMASK,
|
|
|
|
NX_ALTERNATEMASK,
|
2009-09-06 13:44:18 -06:00
|
|
|
#endif
|
|
|
|
NX_ALPHASHIFTMASK,
|
|
|
|
0
|
|
|
|
};
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static int darwin_all_modifier_mask_additions[] = { NX_SECONDARYFNMASK, };
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
DarwinUpdateModifiers(int pressed, // KeyPress or KeyRelease
|
|
|
|
int flags) // modifier flags that have changed
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
int *f;
|
|
|
|
int key;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Capslock is special. This mask is the state of capslock (on/off),
|
|
|
|
* not the state of the button. Hopefully we can find a better solution.
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
if (NX_ALPHASHIFTMASK & flags) {
|
2009-09-06 13:44:18 -06:00
|
|
|
DarwinPressModifierKey(KeyPress, NX_MODIFIERKEY_ALPHALOCK);
|
|
|
|
DarwinPressModifierKey(KeyRelease, NX_MODIFIERKEY_ALPHALOCK);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (f = darwin_x11_modifier_mask_list; *f; f++)
|
|
|
|
if (*f & flags && *f != NX_ALPHASHIFTMASK) {
|
2009-09-06 13:44:18 -06:00
|
|
|
key = DarwinModifierNXMaskToNXKey(*f);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (key == -1)
|
|
|
|
ErrorF("DarwinUpdateModifiers: Unsupported NXMask: 0x%x\n",
|
|
|
|
*f);
|
2009-09-06 13:44:18 -06:00
|
|
|
else
|
|
|
|
DarwinPressModifierKey(pressed, key);
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Generic handler for Xquartz-specifc events. When possible, these should
|
|
|
|
be moved into their own individual functions and set as handlers using
|
|
|
|
mieqSetHandler. */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
XQuartzEvent *e = &(ie->xquartz_event);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
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 (XQuartzIsRootless)
|
|
|
|
ErrorF(
|
|
|
|
"Ignoring kXquartzToggleFullscreen because of rootless mode.");
|
|
|
|
else
|
|
|
|
QuartzRandRToggleFullscreen();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kXquartzSetRootless:
|
|
|
|
DEBUG_LOG("kXquartzSetRootless\n");
|
|
|
|
if (e->data[0]) {
|
|
|
|
QuartzRandRSetFakeRootless();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QuartzRandRSetFakeFullscreen(FALSE);
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
DEBUG_LOG("kXquartzDisplayChanged\n");
|
|
|
|
QuartzUpdateScreens();
|
|
|
|
|
|
|
|
/* Update our RandR info */
|
|
|
|
QuartzRandRUpdateFakeModes(TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!QuartzModeEventHandler(screenNum, e, dev))
|
|
|
|
ErrorF("Unknown application defined event type %d.\n", e->subtype);
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
DarwinListenOnOpenFD(int fd)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
ErrorF("DarwinListenOnOpenFD: %d\n", fd);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
pthread_mutex_lock(&fd_add_lock);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (fd_add_count < FD_ADD_MAX)
|
2009-09-06 13:44:18 -06:00
|
|
|
fd_add[fd_add_count++] = fd;
|
|
|
|
else
|
|
|
|
ErrorF("FD Addition buffer at max. Dropping fd addition request.\n");
|
|
|
|
|
|
|
|
pthread_cond_broadcast(&fd_add_ready_cond);
|
|
|
|
pthread_mutex_unlock(&fd_add_lock);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void *
|
|
|
|
DarwinProcessFDAdditionQueue_thread(void *args)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
/* TODO: Possibly adjust this to no longer be a race... maybe trigger this
|
|
|
|
* once a client connects and claims to be the WM.
|
|
|
|
*
|
|
|
|
* From ajax:
|
|
|
|
* There's already an internal callback chain for setting selection [in 1.5]
|
|
|
|
* ownership. See the CallSelectionCallback at the bottom of
|
|
|
|
* ProcSetSelectionOwner, and xfixes/select.c for an example of how to hook
|
|
|
|
* into it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct timespec sleep_for;
|
|
|
|
struct timespec sleep_remaining;
|
|
|
|
|
|
|
|
sleep_for.tv_sec = 3;
|
|
|
|
sleep_for.tv_nsec = 0;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF(
|
|
|
|
"X11.app: DarwinProcessFDAdditionQueue_thread: Sleeping to allow xinitrc to catchup.\n");
|
|
|
|
while (nanosleep(&sleep_for, &sleep_remaining) != 0) {
|
2011-11-05 07:32:40 -06:00
|
|
|
sleep_for = sleep_remaining;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
pthread_mutex_lock(&fd_add_lock);
|
2012-06-10 07:21:05 -06:00
|
|
|
while (true) {
|
|
|
|
while (fd_add_count) {
|
|
|
|
DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1,
|
|
|
|
fd_add[--fd_add_count]);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
pthread_cond_wait(&fd_add_ready_cond, &fd_add_lock);
|
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
Bool
|
|
|
|
DarwinEQInit(void)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
int *p;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (p = darwin_x11_modifier_mask_list, darwin_all_modifier_mask = 0; *p;
|
|
|
|
p++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
darwin_x11_modifier_mask |= *p;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (p = darwin_all_modifier_mask_additions,
|
|
|
|
darwin_all_modifier_mask = darwin_x11_modifier_mask;
|
|
|
|
*p; p++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
darwin_all_modifier_mask |= *p;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
mieqInit();
|
|
|
|
mieqSetHandler(ET_XQuartz, DarwinEventHandler);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* Note that this *could* cause a potential async issue, since we're checking
|
|
|
|
* darwinEvents without holding the lock, but darwinEvents is only ever set
|
|
|
|
* here, so I don't bother.
|
|
|
|
*/
|
|
|
|
if (!darwinEvents) {
|
2012-06-10 07:21:05 -06:00
|
|
|
darwinEvents = InitEventList(GetMaximumEventsNum());
|
|
|
|
;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!darwinEvents)
|
|
|
|
FatalError("Couldn't allocate event buffer\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
darwinEvents_lock();
|
|
|
|
pthread_cond_broadcast(&mieq_ready_cond);
|
|
|
|
darwinEvents_unlock();
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!fd_add_tid)
|
2009-09-06 13:44:18 -06:00
|
|
|
fd_add_tid = create_thread(DarwinProcessFDAdditionQueue_thread, NULL);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
DarwinEQFini(void)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
mieqFini();
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* ProcessInputEvents
|
|
|
|
* Read and process events from the event queue until it is empty.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
ProcessInputEvents(void)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
char nullbyte;
|
2012-06-10 07:21:05 -06:00
|
|
|
int x = sizeof(nullbyte);
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
mieqProcessInputEvents();
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
// Empty the signaling pipe
|
2010-07-27 13:02:24 -06:00
|
|
|
while (x == sizeof(nullbyte)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
x = read(darwinEventReadFD, &nullbyte, sizeof(nullbyte));
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sends a null byte down darwinEventWriteFD, which will cause the
|
|
|
|
Dispatch() event loop to check out event queue */
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
DarwinPokeEQ(void)
|
|
|
|
{
|
|
|
|
char nullbyte = 0;
|
|
|
|
// <daniels> oh, i ... er ... christ.
|
|
|
|
write(darwinEventWriteFD, &nullbyte, sizeof(nullbyte));
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev)
|
|
|
|
{
|
|
|
|
darwinEvents_lock();
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (pDev->button) {
|
|
|
|
for (i = 0; i < pDev->button->numButtons; i++) {
|
|
|
|
if (BitIsOn(pDev->button->down, i)) {
|
|
|
|
QueuePointerEvents(pDev, ButtonRelease, i,
|
|
|
|
POINTER_ABSOLUTE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pDev->key) {
|
|
|
|
for (i = 0; i < NUM_KEYCODES; i++) {
|
|
|
|
if (BitIsOn(pDev->key->down, i + MIN_KEYCODE)) {
|
|
|
|
QueueKeyboardEvents(pDev, KeyRelease, i + MIN_KEYCODE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DarwinPokeEQ();
|
|
|
|
} darwinEvents_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
|
|
|
|
double pointer_x, double pointer_y,
|
|
|
|
double pressure, double tilt_x,
|
|
|
|
double tilt_y)
|
|
|
|
{
|
|
|
|
ScreenPtr screen;
|
|
|
|
ValuatorMask valuators;
|
|
|
|
|
|
|
|
if (!darwinEvents) {
|
|
|
|
DEBUG_LOG("%s called before darwinEvents was initialized\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen = miPointerGetScreen(pDev);
|
|
|
|
if (!screen) {
|
|
|
|
DEBUG_LOG("%s called before screen was initialized\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Fix offset between darwin and X screens */
|
2010-12-05 08:36:02 -07:00
|
|
|
pointer_x -= darwinMainScreenX + screen->x;
|
|
|
|
pointer_y -= darwinMainScreenY + screen->y;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Adjust our pointer location to the [0,1] range */
|
|
|
|
pointer_x = pointer_x / (double)screenInfo.width;
|
|
|
|
pointer_y = pointer_y / (double)screenInfo.height;
|
|
|
|
|
|
|
|
valuator_mask_zero(&valuators);
|
|
|
|
valuator_mask_set_double(&valuators, 0, XQUARTZ_VALUATOR_LIMIT * pointer_x);
|
|
|
|
valuator_mask_set_double(&valuators, 1, XQUARTZ_VALUATOR_LIMIT * pointer_y);
|
|
|
|
valuator_mask_set_double(&valuators, 2, XQUARTZ_VALUATOR_LIMIT * pressure);
|
|
|
|
valuator_mask_set_double(&valuators, 3, XQUARTZ_VALUATOR_LIMIT * tilt_x);
|
|
|
|
valuator_mask_set_double(&valuators, 4, XQUARTZ_VALUATOR_LIMIT * tilt_y);
|
|
|
|
|
|
|
|
darwinEvents_lock();
|
|
|
|
{
|
|
|
|
if (ev_type == ProximityIn || ev_type == ProximityOut) {
|
|
|
|
QueueProximityEvents(pDev, ev_type, &valuators);
|
|
|
|
} else {
|
|
|
|
QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE,
|
|
|
|
&valuators);
|
|
|
|
}
|
|
|
|
DarwinPokeEQ();
|
|
|
|
} darwinEvents_unlock();
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
|
|
|
|
double pointer_x, double pointer_y,
|
|
|
|
double pointer_dx, double pointer_dy)
|
|
|
|
{
|
|
|
|
static int darwinFakeMouseButtonDown = 0;
|
2009-09-06 13:44:18 -06:00
|
|
|
ScreenPtr screen;
|
2012-06-10 07:21:05 -06:00
|
|
|
ValuatorMask valuators;
|
|
|
|
|
|
|
|
if (!darwinEvents) {
|
|
|
|
DEBUG_LOG("%s called before darwinEvents was initialized\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
screen = miPointerGetScreen(pDev);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!screen) {
|
|
|
|
DEBUG_LOG("%s called before screen was initialized\n",
|
|
|
|
__FUNCTION__);
|
2009-09-06 13:44:18 -06:00
|
|
|
return;
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Handle fake click */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
|
|
|
|
if (darwinFakeMouseButtonDown != 0) {
|
2009-09-06 13:44:18 -06:00
|
|
|
/* We're currently "down" with another button, so release it first */
|
2012-06-10 07:21:05 -06:00
|
|
|
DarwinSendPointerEvents(pDev, ButtonRelease,
|
|
|
|
darwinFakeMouseButtonDown,
|
|
|
|
pointer_x, pointer_y, 0.0, 0.0);
|
|
|
|
darwinFakeMouseButtonDown = 0;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (darwin_all_modifier_flags & darwinFakeMouse2Mask) {
|
2009-09-06 13:44:18 -06:00
|
|
|
ev_button = 2;
|
2012-06-10 07:21:05 -06:00
|
|
|
darwinFakeMouseButtonDown = 2;
|
|
|
|
DarwinUpdateModKeys(
|
|
|
|
darwin_all_modifier_flags & ~darwinFakeMouse2Mask);
|
|
|
|
}
|
|
|
|
else if (darwin_all_modifier_flags & darwinFakeMouse3Mask) {
|
2009-09-06 13:44:18 -06:00
|
|
|
ev_button = 3;
|
2012-06-10 07:21:05 -06:00
|
|
|
darwinFakeMouseButtonDown = 3;
|
|
|
|
DarwinUpdateModKeys(
|
|
|
|
darwin_all_modifier_flags & ~darwinFakeMouse3Mask);
|
|
|
|
}
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ev_type == ButtonRelease && ev_button == 1) {
|
|
|
|
if (darwinFakeMouseButtonDown) {
|
2009-09-06 13:44:18 -06:00
|
|
|
ev_button = darwinFakeMouseButtonDown;
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (darwinFakeMouseButtonDown == 2) {
|
|
|
|
DarwinUpdateModKeys(
|
|
|
|
darwin_all_modifier_flags & ~darwinFakeMouse2Mask);
|
|
|
|
}
|
|
|
|
else if (darwinFakeMouseButtonDown == 3) {
|
|
|
|
DarwinUpdateModKeys(
|
|
|
|
darwin_all_modifier_flags & ~darwinFakeMouse3Mask);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
darwinFakeMouseButtonDown = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Fix offset between darwin and X screens */
|
|
|
|
pointer_x -= darwinMainScreenX + screen->x;
|
|
|
|
pointer_y -= darwinMainScreenY + screen->y;
|
|
|
|
|
|
|
|
valuator_mask_zero(&valuators);
|
|
|
|
valuator_mask_set_double(&valuators, 0, pointer_x);
|
|
|
|
valuator_mask_set_double(&valuators, 1, pointer_y);
|
|
|
|
|
|
|
|
if (ev_type == MotionNotify) {
|
|
|
|
if (pointer_dx != 0.0)
|
|
|
|
valuator_mask_set_double(&valuators, 2, pointer_dx);
|
|
|
|
if (pointer_dy != 0.0)
|
|
|
|
valuator_mask_set_double(&valuators, 3, pointer_dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
darwinEvents_lock();
|
|
|
|
{
|
|
|
|
QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE,
|
|
|
|
&valuators);
|
2011-11-05 07:32:40 -06:00
|
|
|
DarwinPokeEQ();
|
2012-06-10 07:21:05 -06:00
|
|
|
} darwinEvents_unlock();
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
DarwinSendKeyboardEvents(int ev_type, int keycode)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!darwinEvents) {
|
|
|
|
DEBUG_LOG(
|
|
|
|
"DarwinSendKeyboardEvents called before darwinEvents was initialized\n");
|
|
|
|
return;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
darwinEvents_lock();
|
|
|
|
{
|
|
|
|
QueueKeyboardEvents(darwinKeyboard, ev_type, keycode + MIN_KEYCODE,
|
|
|
|
NULL);
|
2011-11-05 07:32:40 -06:00
|
|
|
DarwinPokeEQ();
|
2009-09-06 13:44:18 -06:00
|
|
|
} darwinEvents_unlock();
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Send the appropriate number of button clicks to emulate scroll wheel */
|
|
|
|
void
|
|
|
|
DarwinSendScrollEvents(double scroll_x, double scroll_y) {
|
2009-09-06 13:44:18 -06:00
|
|
|
ScreenPtr screen;
|
2012-06-10 07:21:05 -06:00
|
|
|
ValuatorMask valuators;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!darwinEvents) {
|
|
|
|
DEBUG_LOG(
|
|
|
|
"DarwinSendScrollEvents called before darwinEvents was initialized\n");
|
2011-11-05 07:32:40 -06:00
|
|
|
return;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
screen = miPointerGetScreen(darwinPointer);
|
|
|
|
if (!screen) {
|
|
|
|
DEBUG_LOG(
|
|
|
|
"DarwinSendScrollEvents called before screen was initialized\n");
|
|
|
|
return;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
valuator_mask_zero(&valuators);
|
|
|
|
valuator_mask_set_double(&valuators, 4, scroll_y);
|
|
|
|
valuator_mask_set_double(&valuators, 5, scroll_x);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
darwinEvents_lock();
|
|
|
|
{
|
|
|
|
QueuePointerEvents(darwinPointer, MotionNotify, 0,
|
|
|
|
POINTER_RELATIVE, &valuators);
|
|
|
|
DarwinPokeEQ();
|
|
|
|
} darwinEvents_unlock();
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to
|
|
|
|
reflect changing modifier flags (alt, control, meta, etc) */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
DarwinUpdateModKeys(int flags)
|
|
|
|
{
|
|
|
|
DarwinUpdateModifiers(
|
|
|
|
KeyRelease, darwin_all_modifier_flags & ~flags &
|
|
|
|
darwin_x11_modifier_mask);
|
|
|
|
DarwinUpdateModifiers(
|
|
|
|
KeyPress, ~darwin_all_modifier_flags & flags &
|
|
|
|
darwin_x11_modifier_mask);
|
|
|
|
darwin_all_modifier_flags = flags;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DarwinSendDDXEvent
|
|
|
|
* Send the X server thread a message by placing it on the event queue.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
DarwinSendDDXEvent(int type, int argc, ...)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
XQuartzEvent e;
|
|
|
|
int i;
|
2009-09-06 13:44:18 -06:00
|
|
|
va_list args;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(&e, 0, sizeof(e));
|
|
|
|
e.header = ET_Internal;
|
|
|
|
e.type = ET_XQuartz;
|
|
|
|
e.length = sizeof(e);
|
|
|
|
e.time = GetTimeInMillis();
|
|
|
|
e.subtype = type;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (argc > 0 && argc < XQUARTZ_EVENT_MAXARGS) {
|
2012-06-10 07:21:05 -06:00
|
|
|
va_start(args, argc);
|
2009-09-06 13:44:18 -06:00
|
|
|
for (i = 0; i < argc; i++)
|
2012-06-10 07:21:05 -06:00
|
|
|
e.data[i] = (uint32_t)va_arg(args, uint32_t);
|
|
|
|
va_end(args);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
darwinEvents_lock();
|
|
|
|
{
|
|
|
|
mieqEnqueue(NULL, (InternalEvent *)&e);
|
2009-09-06 13:44:18 -06:00
|
|
|
DarwinPokeEQ();
|
|
|
|
} darwinEvents_unlock();
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|