2001-10-06 18:13:28 +04:00
|
|
|
#include "CXWindowsPrimaryScreen.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "CServer.h"
|
2002-05-27 20:22:59 +04:00
|
|
|
#include "CXWindowsClipboard.h"
|
|
|
|
#include "CXWindowsUtil.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
#include "CThread.h"
|
2001-10-14 18:37:41 +04:00
|
|
|
#include "CLog.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "CStopwatch.h"
|
2002-06-19 15:23:49 +04:00
|
|
|
#if defined(X_DISPLAY_MISSING)
|
|
|
|
# error X11 is required to build synergy
|
|
|
|
#else
|
|
|
|
# include <X11/X.h>
|
|
|
|
# include <X11/Xutil.h>
|
|
|
|
# define XK_MISCELLANY
|
|
|
|
# include <X11/keysymdef.h>
|
|
|
|
#endif
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// CXWindowsPrimaryScreen
|
|
|
|
//
|
|
|
|
|
|
|
|
CXWindowsPrimaryScreen::CXWindowsPrimaryScreen() :
|
2002-06-11 02:06:45 +04:00
|
|
|
m_server(NULL),
|
|
|
|
m_active(false),
|
|
|
|
m_window(None)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
CXWindowsPrimaryScreen::~CXWindowsPrimaryScreen()
|
|
|
|
{
|
2001-11-19 03:33:36 +03:00
|
|
|
assert(m_window == None);
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CXWindowsPrimaryScreen::run()
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
// wait for and get the next event
|
|
|
|
XEvent xevent;
|
|
|
|
if (!getEvent(&xevent)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle event
|
|
|
|
switch (xevent.type) {
|
2002-06-11 02:06:45 +04:00
|
|
|
case CreateNotify:
|
|
|
|
{
|
|
|
|
// select events on new window
|
|
|
|
CDisplayLock display(this);
|
|
|
|
selectEvents(display, xevent.xcreatewindow.window);
|
|
|
|
}
|
2002-04-26 21:38:01 +04:00
|
|
|
break;
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
case MappingNotify:
|
|
|
|
{
|
|
|
|
// keyboard mapping changed
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XRefreshKeyboardMapping(&xevent.xmapping);
|
|
|
|
updateModifierMap(display);
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
case KeyPress:
|
|
|
|
{
|
|
|
|
log((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
|
|
|
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
|
|
|
const KeyID key = mapKey(&xevent.xkey);
|
|
|
|
if (key != kKeyNone) {
|
|
|
|
m_server->onKeyDown(key, mask);
|
2002-05-04 22:33:48 +04:00
|
|
|
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
|
2002-06-11 02:06:45 +04:00
|
|
|
m_server->onKeyUp(key, mask | KeyModifierCapsLock);
|
2002-05-04 22:33:48 +04:00
|
|
|
}
|
|
|
|
else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
|
2002-06-11 02:06:45 +04:00
|
|
|
m_server->onKeyUp(key, mask | KeyModifierNumLock);
|
2002-05-04 22:33:48 +04:00
|
|
|
}
|
2002-05-03 15:26:44 +04:00
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
case KeyRelease:
|
|
|
|
{
|
|
|
|
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
|
|
|
const KeyID key = mapKey(&xevent.xkey);
|
|
|
|
if (key != kKeyNone) {
|
|
|
|
// check if this is a key repeat by getting the next
|
|
|
|
// KeyPress event that has the same key and time as
|
|
|
|
// this release event, if any. first prepare the
|
|
|
|
// filter info.
|
|
|
|
CKeyEventInfo filter;
|
|
|
|
filter.m_event = KeyPress;
|
|
|
|
filter.m_window = xevent.xkey.window;
|
|
|
|
filter.m_time = xevent.xkey.time;
|
|
|
|
filter.m_keycode = xevent.xkey.keycode;
|
|
|
|
|
|
|
|
// now check for event
|
|
|
|
XEvent xevent2;
|
|
|
|
CDisplayLock display(this);
|
|
|
|
if (XCheckIfEvent(display, &xevent2,
|
|
|
|
&CXWindowsPrimaryScreen::findKeyEvent,
|
|
|
|
(XPointer)&filter) != True) {
|
|
|
|
// no press event follows so it's a plain release
|
|
|
|
log((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
|
|
|
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
|
|
|
|
m_server->onKeyDown(key, mask);
|
|
|
|
}
|
|
|
|
else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
|
|
|
|
m_server->onKeyDown(key, mask);
|
|
|
|
}
|
|
|
|
m_server->onKeyUp(key, mask);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// found a press event following so it's a repeat.
|
|
|
|
// we could attempt to count the already queued
|
|
|
|
// repeats but we'll just send a repeat of 1.
|
|
|
|
// note that we discard the press event.
|
|
|
|
log((CLOG_DEBUG1 "event: repeat code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
|
|
|
m_server->onKeyRepeat(key, mask, 1);
|
|
|
|
}
|
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
case ButtonPress:
|
|
|
|
{
|
|
|
|
log((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button));
|
|
|
|
const ButtonID button = mapButton(xevent.xbutton.button);
|
|
|
|
if (button != kButtonNone) {
|
|
|
|
m_server->onMouseDown(button);
|
|
|
|
}
|
2002-05-23 19:50:38 +04:00
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
break;
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
case ButtonRelease:
|
|
|
|
{
|
|
|
|
log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button));
|
|
|
|
const ButtonID button = mapButton(xevent.xbutton.button);
|
|
|
|
if (button != kButtonNone) {
|
|
|
|
m_server->onMouseUp(button);
|
|
|
|
}
|
|
|
|
else if (xevent.xbutton.button == 4) {
|
|
|
|
// wheel forward (away from user)
|
|
|
|
m_server->onMouseWheel(120);
|
|
|
|
}
|
|
|
|
else if (xevent.xbutton.button == 5) {
|
|
|
|
// wheel backward (toward user)
|
|
|
|
m_server->onMouseWheel(-120);
|
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
2002-06-11 02:06:45 +04:00
|
|
|
break;
|
2001-11-19 03:33:36 +03:00
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
case MotionNotify:
|
|
|
|
{
|
|
|
|
log((CLOG_DEBUG2 "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root));
|
2002-06-20 00:24:35 +04:00
|
|
|
SInt32 x = xevent.xmotion.x_root;
|
|
|
|
SInt32 y = xevent.xmotion.y_root;
|
2002-06-11 02:06:45 +04:00
|
|
|
if (!m_active) {
|
|
|
|
m_server->onMouseMovePrimary(x, y);
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
2002-06-11 02:06:45 +04:00
|
|
|
else {
|
2002-06-20 00:24:35 +04:00
|
|
|
// compute motion delta. this is relative to the
|
|
|
|
// last known mouse position.
|
|
|
|
x -= m_x;
|
|
|
|
y -= m_y;
|
|
|
|
|
|
|
|
// save position to compute delta of next motion
|
|
|
|
m_x = xevent.xmotion.x_root;
|
|
|
|
m_y = xevent.xmotion.y_root;
|
|
|
|
|
|
|
|
// if event was sent then ignore it and discard
|
|
|
|
// the event from the mouse warp. this is how we
|
|
|
|
// warp the mouse back to the center of the screen
|
|
|
|
// without that causing a corresponding motion on
|
|
|
|
// the secondary screen.
|
|
|
|
if (xevent.xmotion.send_event) {
|
|
|
|
// ignore event
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
|
|
|
|
// discard events until we find the matching
|
|
|
|
// sent event. see below for where the events
|
|
|
|
// are sent. we discard the matching sent
|
|
|
|
// event and can be sure we've skipped the
|
|
|
|
// warp event.
|
2002-06-11 02:06:45 +04:00
|
|
|
CDisplayLock display(this);
|
2002-06-20 00:24:35 +04:00
|
|
|
do {
|
|
|
|
XMaskEvent(display, PointerMotionMask, &xevent);
|
|
|
|
} while (!xevent.xmotion.send_event);
|
|
|
|
}
|
2002-06-11 02:06:45 +04:00
|
|
|
|
2002-06-20 13:19:55 +04:00
|
|
|
// warp mouse back to center. my lombard (powerbook
|
|
|
|
// g3) using the adbmouse driver has two problems:
|
|
|
|
// first, the driver only sends motions of +/-2
|
|
|
|
// pixels and, second, it seems to discard some
|
|
|
|
// physical input after a warp. the former isn't a
|
|
|
|
// big deal (we're just limited to every other
|
|
|
|
// pixel) but the latter is a PITA. to work around
|
|
|
|
// it we only warp when the mouse has moved more
|
|
|
|
// than s_size pixels from the center.
|
|
|
|
static const SInt32 s_size = 32;
|
|
|
|
if (xevent.xmotion.x_root - m_xCenter < -s_size ||
|
|
|
|
xevent.xmotion.x_root - m_xCenter > s_size ||
|
|
|
|
xevent.xmotion.y_root - m_yCenter < -s_size ||
|
|
|
|
xevent.xmotion.y_root - m_yCenter > s_size) {
|
2002-06-20 00:24:35 +04:00
|
|
|
CDisplayLock display(this);
|
|
|
|
// send an event that we can recognize before
|
|
|
|
// the mouse warp.
|
|
|
|
XEvent eventBefore = xevent;
|
|
|
|
xevent.xmotion.window = m_window;
|
|
|
|
xevent.xmotion.time = CurrentTime;
|
|
|
|
xevent.xmotion.x = m_xCenter;
|
|
|
|
xevent.xmotion.y = m_yCenter;
|
|
|
|
xevent.xmotion.x_root = m_xCenter;
|
|
|
|
xevent.xmotion.y_root = m_yCenter;
|
|
|
|
XEvent eventAfter = eventBefore;
|
|
|
|
XSendEvent(display, m_window, False, 0, &xevent);
|
2002-06-11 02:06:45 +04:00
|
|
|
|
|
|
|
// warp mouse back to center
|
2002-06-20 00:24:35 +04:00
|
|
|
XWarpPointer(display, None, getRoot(),
|
|
|
|
0, 0, 0, 0, m_xCenter, m_yCenter);
|
|
|
|
|
|
|
|
// send an event that we can recognize after
|
|
|
|
// the mouse warp.
|
|
|
|
XSendEvent(display, m_window, False, 0, &xevent);
|
2002-06-11 02:06:45 +04:00
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
|
2002-06-20 00:24:35 +04:00
|
|
|
// send event if mouse moved
|
|
|
|
if (x != 0 || y != 0) {
|
|
|
|
m_server->onMouseMoveSecondary(x, y);
|
|
|
|
}
|
2002-06-11 02:06:45 +04:00
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
break;
|
2002-04-29 18:40:01 +04:00
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CXWindowsPrimaryScreen::stop()
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
2002-06-03 17:45:30 +04:00
|
|
|
CDisplayLock display(this);
|
2001-11-19 03:33:36 +03:00
|
|
|
doStop();
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::open(CServer* server)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
|
|
|
assert(m_server == NULL);
|
|
|
|
assert(server != NULL);
|
|
|
|
|
|
|
|
// open the display
|
2001-11-12 00:15:30 +03:00
|
|
|
openDisplay();
|
2002-04-27 00:12:55 +04:00
|
|
|
|
2002-06-03 17:45:30 +04:00
|
|
|
// set the server
|
|
|
|
m_server = server;
|
|
|
|
|
2002-04-27 00:12:55 +04:00
|
|
|
// check for peculiarities
|
|
|
|
// FIXME -- may have to get these from some database
|
2002-05-04 22:33:48 +04:00
|
|
|
m_numLockHalfDuplex = false;
|
2002-04-27 00:12:55 +04:00
|
|
|
m_capsLockHalfDuplex = false;
|
2002-05-04 22:33:48 +04:00
|
|
|
// m_numLockHalfDuplex = true;
|
2002-04-27 00:12:55 +04:00
|
|
|
// m_capsLockHalfDuplex = true;
|
2002-04-30 21:48:11 +04:00
|
|
|
|
2002-06-19 21:03:29 +04:00
|
|
|
// get screen shape
|
|
|
|
SInt32 x, y, w, h;
|
|
|
|
getScreenShape(x, y, w, h);
|
2002-06-10 14:08:36 +04:00
|
|
|
|
2002-04-30 21:48:11 +04:00
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
2002-06-10 14:08:36 +04:00
|
|
|
|
|
|
|
// update key state
|
2002-04-30 21:48:11 +04:00
|
|
|
updateModifierMap(display);
|
2002-06-10 14:08:36 +04:00
|
|
|
|
|
|
|
// get mouse position
|
|
|
|
Window root, window;
|
2002-06-20 00:24:35 +04:00
|
|
|
int mx, my, xWindow, yWindow;
|
2002-06-10 14:08:36 +04:00
|
|
|
unsigned int mask;
|
|
|
|
if (!XQueryPointer(display, m_window, &root, &window,
|
2002-06-19 21:03:29 +04:00
|
|
|
&mx, &my, &xWindow, &yWindow, &mask)) {
|
|
|
|
mx = w >> 1;
|
|
|
|
my = h >> 1;
|
2002-06-10 14:08:36 +04:00
|
|
|
}
|
2002-06-20 00:24:35 +04:00
|
|
|
|
|
|
|
// save mouse position
|
|
|
|
m_x = x;
|
|
|
|
m_y = y;
|
2002-04-30 21:48:11 +04:00
|
|
|
}
|
2002-05-24 21:54:28 +04:00
|
|
|
|
2002-06-20 00:24:35 +04:00
|
|
|
// save position of center of screen
|
|
|
|
m_xCenter = x + (w >> 1);
|
|
|
|
m_yCenter = y + (h >> 1);
|
|
|
|
|
2002-05-24 21:54:28 +04:00
|
|
|
// send screen info
|
2002-06-20 00:24:35 +04:00
|
|
|
m_server->setInfo(x, y, w, h, getJumpZoneSize(), m_x, m_y);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CXWindowsPrimaryScreen::close()
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
|
|
|
assert(m_server != NULL);
|
|
|
|
|
|
|
|
// close the display
|
2001-11-12 00:15:30 +03:00
|
|
|
closeDisplay();
|
|
|
|
|
|
|
|
// done with server
|
|
|
|
m_server = NULL;
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2001-10-14 18:37:41 +04:00
|
|
|
log((CLOG_INFO "entering primary at %d,%d", x, y));
|
2001-11-12 00:15:30 +03:00
|
|
|
assert(m_active == true);
|
|
|
|
assert(m_window != None);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-25 02:33:24 +04:00
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// warp to requested location
|
2001-11-12 00:15:30 +03:00
|
|
|
XWarpPointer(display, None, m_window, 0, 0, 0, 0, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// unmap the grab window. this also ungrabs the mouse and keyboard.
|
2001-11-12 00:15:30 +03:00
|
|
|
XUnmapWindow(display, m_window);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// remove all input events for grab window
|
|
|
|
XEvent event;
|
2001-11-12 00:15:30 +03:00
|
|
|
while (XCheckWindowEvent(display, m_window,
|
2001-10-06 18:13:28 +04:00
|
|
|
PointerMotionMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
KeymapStateMask,
|
|
|
|
&event)) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
// not active anymore
|
|
|
|
m_active = false;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
bool
|
|
|
|
CXWindowsPrimaryScreen::leave()
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2001-10-14 18:37:41 +04:00
|
|
|
log((CLOG_INFO "leaving primary"));
|
2001-11-12 00:15:30 +03:00
|
|
|
assert(m_active == false);
|
|
|
|
assert(m_window != None);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-25 02:33:24 +04:00
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// raise and show the input window
|
2001-11-12 00:15:30 +03:00
|
|
|
XMapRaised(display, m_window);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// grab the mouse and keyboard. keep trying until we get them.
|
|
|
|
// if we can't grab one after grabbing the other then ungrab
|
2002-06-03 22:53:18 +04:00
|
|
|
// and wait before retrying. give up after s_timeout seconds.
|
|
|
|
static const double s_timeout = 1.0;
|
2001-10-06 18:13:28 +04:00
|
|
|
int result;
|
2002-06-03 22:53:18 +04:00
|
|
|
CStopwatch timer;
|
2001-10-06 18:13:28 +04:00
|
|
|
do {
|
2002-06-03 22:53:18 +04:00
|
|
|
// keyboard first
|
2001-10-06 18:13:28 +04:00
|
|
|
do {
|
2002-06-03 22:53:18 +04:00
|
|
|
result = XGrabKeyboard(display, m_window, True,
|
|
|
|
GrabModeAsync, GrabModeAsync, CurrentTime);
|
2001-10-06 18:13:28 +04:00
|
|
|
assert(result != GrabNotViewable);
|
2001-10-14 18:37:41 +04:00
|
|
|
if (result != GrabSuccess) {
|
2002-06-03 22:53:18 +04:00
|
|
|
log((CLOG_DEBUG2 "waiting to grab keyboard"));
|
|
|
|
CThread::sleep(0.05);
|
|
|
|
if (timer.getTime() >= s_timeout) {
|
|
|
|
log((CLOG_DEBUG2 "grab keyboard timed out"));
|
|
|
|
XUnmapWindow(display, m_window);
|
|
|
|
return false;
|
|
|
|
}
|
2001-10-14 18:37:41 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
} while (result != GrabSuccess);
|
2002-06-03 22:53:18 +04:00
|
|
|
log((CLOG_DEBUG2 "grabbed keyboard"));
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-06-03 22:53:18 +04:00
|
|
|
// now the mouse
|
|
|
|
result = XGrabPointer(display, m_window, True, 0,
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
m_window, None, CurrentTime);
|
2001-10-06 18:13:28 +04:00
|
|
|
assert(result != GrabNotViewable);
|
|
|
|
if (result != GrabSuccess) {
|
2001-11-12 00:15:30 +03:00
|
|
|
// back off to avoid grab deadlock
|
2002-06-03 22:53:18 +04:00
|
|
|
XUngrabKeyboard(display, CurrentTime);
|
|
|
|
log((CLOG_DEBUG2 "ungrabbed keyboard, waiting to grab pointer"));
|
|
|
|
CThread::sleep(0.05);
|
|
|
|
if (timer.getTime() >= s_timeout) {
|
|
|
|
log((CLOG_DEBUG2 "grab pointer timed out"));
|
|
|
|
XUnmapWindow(display, m_window);
|
|
|
|
return false;
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
} while (result != GrabSuccess);
|
2002-04-27 22:49:03 +04:00
|
|
|
log((CLOG_DEBUG1 "grabbed pointer and keyboard"));
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// move the mouse to the center of grab window
|
2002-06-20 00:24:35 +04:00
|
|
|
warpCursorNoLock(display, m_xCenter, m_yCenter);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// local client now active
|
|
|
|
m_active = true;
|
2002-06-03 22:53:18 +04:00
|
|
|
|
|
|
|
return true;
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CXWindowsPrimaryScreen::onConfigure()
|
2002-06-01 23:26:11 +04:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::warpCursor(SInt32 x, SInt32 y)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
|
|
|
warpCursorNoLock(display, x, y);
|
2001-10-25 02:33:24 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::warpCursorNoLock(Display* display, SInt32 x, SInt32 y)
|
2001-10-25 02:33:24 +04:00
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
assert(display != NULL);
|
|
|
|
assert(m_window != None);
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// warp the mouse
|
2001-11-12 00:15:30 +03:00
|
|
|
XWarpPointer(display, None, getRoot(), 0, 0, 0, 0, x, y);
|
|
|
|
XSync(display, False);
|
2002-05-01 18:36:52 +04:00
|
|
|
log((CLOG_DEBUG2 "warped to %d,%d", x, y));
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// discard mouse events since we just added one we don't want
|
|
|
|
XEvent xevent;
|
2001-11-12 00:15:30 +03:00
|
|
|
while (XCheckWindowEvent(display, m_window,
|
2001-10-06 18:13:28 +04:00
|
|
|
PointerMotionMask, &xevent)) {
|
|
|
|
// do nothing
|
|
|
|
}
|
2002-06-20 00:24:35 +04:00
|
|
|
|
|
|
|
// save position as last position
|
|
|
|
m_x = x;
|
|
|
|
m_y = y;
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::setClipboard(ClipboardID id,
|
|
|
|
const IClipboard* clipboard)
|
2001-11-14 02:34:12 +03:00
|
|
|
{
|
2002-05-27 20:22:59 +04:00
|
|
|
setDisplayClipboard(id, clipboard);
|
2001-11-25 21:32:41 +03:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::grabClipboard(ClipboardID id)
|
2001-11-25 21:32:41 +03:00
|
|
|
{
|
2002-05-27 20:22:59 +04:00
|
|
|
setDisplayClipboard(id, NULL);
|
2001-11-14 02:34:12 +03:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-19 21:03:29 +04:00
|
|
|
CXWindowsPrimaryScreen::getShape(
|
|
|
|
SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2002-06-19 21:03:29 +04:00
|
|
|
getScreenShape(x, y, w, h);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
SInt32
|
|
|
|
CXWindowsPrimaryScreen::getJumpZoneSize() const
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::getClipboard(ClipboardID id,
|
|
|
|
IClipboard* clipboard) const
|
2001-11-14 02:34:12 +03:00
|
|
|
{
|
2002-05-27 20:22:59 +04:00
|
|
|
getDisplayClipboard(id, clipboard);
|
2001-11-14 02:34:12 +03:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
KeyModifierMask
|
|
|
|
CXWindowsPrimaryScreen::getToggleMask() const
|
2002-04-30 21:48:11 +04:00
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
|
|
|
|
|
|
|
// query the pointer to get the keyboard state
|
|
|
|
// FIXME -- is there a better way to do this?
|
|
|
|
Window root, window;
|
|
|
|
int xRoot, yRoot, xWindow, yWindow;
|
|
|
|
unsigned int state;
|
|
|
|
if (!XQueryPointer(display, m_window, &root, &window,
|
2002-05-24 18:37:12 +04:00
|
|
|
&xRoot, &yRoot, &xWindow, &yWindow, &state)) {
|
2002-04-30 21:48:11 +04:00
|
|
|
return 0;
|
2002-05-24 18:37:12 +04:00
|
|
|
}
|
2002-04-30 21:48:11 +04:00
|
|
|
|
|
|
|
// convert to KeyModifierMask
|
2002-05-01 18:36:52 +04:00
|
|
|
KeyModifierMask mask = 0;
|
2002-04-30 21:48:11 +04:00
|
|
|
if (state & m_numLockMask)
|
|
|
|
mask |= KeyModifierNumLock;
|
|
|
|
if (state & m_capsLockMask)
|
|
|
|
mask |= KeyModifierCapsLock;
|
|
|
|
if (state & m_scrollLockMask)
|
|
|
|
mask |= KeyModifierScrollLock;
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
bool
|
|
|
|
CXWindowsPrimaryScreen::isLockedToScreen() const
|
2002-05-24 18:37:12 +04:00
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
|
|
|
|
|
|
|
// query the pointer to get the button state
|
|
|
|
Window root, window;
|
|
|
|
int xRoot, yRoot, xWindow, yWindow;
|
|
|
|
unsigned int state;
|
|
|
|
if (XQueryPointer(display, m_window, &root, &window,
|
|
|
|
&xRoot, &yRoot, &xWindow, &yWindow, &state)) {
|
|
|
|
if ((state & (Button1Mask | Button2Mask | Button3Mask |
|
|
|
|
Button4Mask | Button5Mask)) != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get logical keyboard state
|
|
|
|
char keyMap[32];
|
|
|
|
memset(keyMap, 0, sizeof(keyMap));
|
|
|
|
XQueryKeymap(display, keyMap);
|
|
|
|
|
|
|
|
// locked if any key is down
|
|
|
|
for (unsigned int i = 0; i < sizeof(keyMap); ++i) {
|
|
|
|
if (keyMap[i] != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// not locked
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::onOpenDisplay(Display* display)
|
2001-11-12 00:15:30 +03:00
|
|
|
{
|
|
|
|
assert(m_window == None);
|
|
|
|
|
|
|
|
// get size of screen
|
2002-06-19 21:03:29 +04:00
|
|
|
SInt32 x, y, w, h;
|
|
|
|
getScreenShape(x, y, w, h);
|
2001-11-12 00:15:30 +03:00
|
|
|
|
|
|
|
// create the grab window. this window is used to capture user
|
|
|
|
// input when the user is focussed on another client. don't let
|
|
|
|
// the window manager mess with it.
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
attr.event_mask = PointerMotionMask |// PointerMotionHintMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
2002-04-28 04:46:15 +04:00
|
|
|
KeymapStateMask | PropertyChangeMask;
|
2001-11-12 00:15:30 +03:00
|
|
|
attr.do_not_propagate_mask = 0;
|
|
|
|
attr.override_redirect = True;
|
|
|
|
attr.cursor = createBlankCursor();
|
2002-06-19 21:03:29 +04:00
|
|
|
m_window = XCreateWindow(display, getRoot(), x, y, w, h, 0, 0,
|
2001-11-12 00:15:30 +03:00
|
|
|
InputOnly, CopyFromParent,
|
|
|
|
CWDontPropagate | CWEventMask |
|
|
|
|
CWOverrideRedirect | CWCursor,
|
|
|
|
&attr);
|
2002-05-27 22:30:13 +04:00
|
|
|
log((CLOG_DEBUG "window is 0x%08x", m_window));
|
2001-11-12 00:15:30 +03:00
|
|
|
|
|
|
|
// start watching for events on other windows
|
|
|
|
selectEvents(display, getRoot());
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
CXWindowsClipboard*
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::createClipboard(ClipboardID id)
|
2002-05-27 20:22:59 +04:00
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
|
|
|
return new CXWindowsClipboard(display, m_window, id);
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::onCloseDisplay(Display* display)
|
2001-11-12 00:15:30 +03:00
|
|
|
{
|
|
|
|
assert(m_window != None);
|
|
|
|
|
|
|
|
// destroy window
|
2002-06-03 17:45:30 +04:00
|
|
|
if (display != NULL) {
|
|
|
|
XDestroyWindow(display, m_window);
|
|
|
|
}
|
2001-11-12 00:15:30 +03:00
|
|
|
m_window = None;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
|
|
|
CXWindowsPrimaryScreen::onUnexpectedClose()
|
2002-06-03 17:45:30 +04:00
|
|
|
{
|
|
|
|
// tell server to shutdown
|
|
|
|
if (m_server != NULL) {
|
|
|
|
m_server->shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::onLostClipboard(ClipboardID id)
|
2002-05-27 20:22:59 +04:00
|
|
|
{
|
|
|
|
// tell server that the clipboard was grabbed locally
|
|
|
|
m_server->grabClipboard(id);
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::selectEvents(Display* display, Window w) const
|
2002-04-29 18:08:48 +04:00
|
|
|
{
|
2002-05-27 22:30:13 +04:00
|
|
|
// ignore errors while we adjust event masks
|
|
|
|
CXWindowsUtil::CErrorLock lock;
|
|
|
|
|
|
|
|
// adjust event masks
|
|
|
|
doSelectEvents(display, w);
|
2002-04-29 18:08:48 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::doSelectEvents(Display* display, Window w) const
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
|
|
|
// we want to track the mouse everywhere on the display. to achieve
|
|
|
|
// that we select PointerMotionMask on every window. we also select
|
|
|
|
// SubstructureNotifyMask in order to get CreateNotify events so we
|
|
|
|
// select events on new windows too.
|
|
|
|
|
|
|
|
// we don't want to adjust our grab window
|
2002-06-11 02:06:45 +04:00
|
|
|
if (w == m_window) {
|
2001-10-06 18:13:28 +04:00
|
|
|
return;
|
2002-06-11 02:06:45 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// select events of interest
|
2002-04-29 18:08:48 +04:00
|
|
|
XSelectInput(display, w, PointerMotionMask | SubstructureNotifyMask);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// recurse on child windows
|
|
|
|
Window rw, pw, *cw;
|
|
|
|
unsigned int nc;
|
2001-11-12 00:15:30 +03:00
|
|
|
if (XQueryTree(display, w, &rw, &pw, &cw, &nc)) {
|
2002-06-11 02:06:45 +04:00
|
|
|
for (unsigned int i = 0; i < nc; ++i) {
|
2002-05-27 22:30:13 +04:00
|
|
|
doSelectEvents(display, cw[i]);
|
2002-06-11 02:06:45 +04:00
|
|
|
}
|
2001-10-26 02:17:17 +04:00
|
|
|
XFree(cw);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
KeyModifierMask
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::mapModifier(unsigned int state) const
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
|
|
|
// FIXME -- should be configurable
|
|
|
|
KeyModifierMask mask = 0;
|
2002-04-26 21:38:01 +04:00
|
|
|
if (state & ShiftMask)
|
2001-10-06 18:13:28 +04:00
|
|
|
mask |= KeyModifierShift;
|
2002-04-26 21:38:01 +04:00
|
|
|
if (state & LockMask)
|
2001-10-06 18:13:28 +04:00
|
|
|
mask |= KeyModifierCapsLock;
|
2002-04-26 21:38:01 +04:00
|
|
|
if (state & ControlMask)
|
2001-10-06 18:13:28 +04:00
|
|
|
mask |= KeyModifierControl;
|
2002-04-26 21:38:01 +04:00
|
|
|
if (state & Mod1Mask)
|
2001-10-06 18:13:28 +04:00
|
|
|
mask |= KeyModifierAlt;
|
2002-04-26 21:38:01 +04:00
|
|
|
if (state & Mod2Mask)
|
2001-10-06 18:13:28 +04:00
|
|
|
mask |= KeyModifierNumLock;
|
2002-04-26 21:38:01 +04:00
|
|
|
if (state & Mod4Mask)
|
2001-10-06 18:13:28 +04:00
|
|
|
mask |= KeyModifierMeta;
|
2002-04-26 21:38:01 +04:00
|
|
|
if (state & Mod5Mask)
|
2001-10-06 18:13:28 +04:00
|
|
|
mask |= KeyModifierScrollLock;
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
KeyID
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::mapKey(XKeyEvent* event) const
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2002-04-26 21:38:01 +04:00
|
|
|
KeySym keysym;
|
|
|
|
char dummy[1];
|
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2002-04-26 21:38:01 +04:00
|
|
|
XLookupString(event, dummy, 0, &keysym, NULL);
|
|
|
|
return static_cast<KeyID>(keysym);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
ButtonID
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::mapButton(unsigned int button) const
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
|
|
|
// FIXME -- should use button mapping?
|
2002-06-11 02:06:45 +04:00
|
|
|
if (button >= 1 && button <= 3) {
|
2001-10-06 18:13:28 +04:00
|
|
|
return static_cast<ButtonID>(button);
|
2002-06-11 02:06:45 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-10-06 18:13:28 +04:00
|
|
|
return kButtonNone;
|
2002-06-11 02:06:45 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
2002-04-30 21:48:11 +04:00
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::updateModifierMap(Display* display)
|
2002-04-30 21:48:11 +04:00
|
|
|
{
|
|
|
|
// get modifier map from server
|
|
|
|
XModifierKeymap* keymap = XGetModifierMapping(display);
|
|
|
|
|
|
|
|
// initialize
|
|
|
|
m_numLockMask = 0;
|
|
|
|
m_capsLockMask = 0;
|
|
|
|
m_scrollLockMask = 0;
|
|
|
|
|
|
|
|
// set keycodes and masks
|
|
|
|
for (unsigned int i = 0; i < 8; ++i) {
|
|
|
|
const unsigned int bit = (1 << i);
|
|
|
|
for (int j = 0; j < keymap->max_keypermod; ++j) {
|
|
|
|
KeyCode keycode = keymap->modifiermap[i *
|
|
|
|
keymap->max_keypermod + j];
|
|
|
|
|
|
|
|
// note toggle modifier bits
|
|
|
|
const KeySym keysym = XKeycodeToKeysym(display, keycode, 0);
|
|
|
|
if (keysym == XK_Num_Lock) {
|
|
|
|
m_numLockMask |= bit;
|
|
|
|
}
|
|
|
|
else if (keysym == XK_Caps_Lock) {
|
|
|
|
m_capsLockMask |= bit;
|
|
|
|
}
|
|
|
|
else if (keysym == XK_Scroll_Lock) {
|
|
|
|
m_scrollLockMask |= bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFreeModifiermap(keymap);
|
|
|
|
}
|
2002-05-03 15:26:44 +04:00
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
Bool
|
2002-06-17 17:31:21 +04:00
|
|
|
CXWindowsPrimaryScreen::findKeyEvent(Display*, XEvent* xevent, XPointer arg)
|
2002-05-03 15:26:44 +04:00
|
|
|
{
|
|
|
|
CKeyEventInfo* filter = reinterpret_cast<CKeyEventInfo*>(arg);
|
|
|
|
return (xevent->type == filter->m_event &&
|
|
|
|
xevent->xkey.window == filter->m_window &&
|
|
|
|
xevent->xkey.time == filter->m_time &&
|
|
|
|
xevent->xkey.keycode == filter->m_keycode) ? True : False;
|
|
|
|
}
|