2001-10-06 14:13:28 +00:00
|
|
|
#include "CXWindowsPrimaryScreen.h"
|
|
|
|
#include "CServer.h"
|
|
|
|
#include "CThread.h"
|
2001-10-14 14:37:41 +00:00
|
|
|
#include "CLog.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <X11/X.h>
|
2002-04-26 17:38:01 +00:00
|
|
|
#include <X11/Xutil.h>
|
2002-04-26 20:12:55 +00:00
|
|
|
#define XK_MISCELLANY
|
|
|
|
#include <X11/keysymdef.h>
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CXWindowsPrimaryScreen
|
|
|
|
//
|
|
|
|
|
|
|
|
CXWindowsPrimaryScreen::CXWindowsPrimaryScreen() :
|
|
|
|
m_server(NULL),
|
2001-11-11 21:15:30 +00:00
|
|
|
m_active(false),
|
|
|
|
m_window(None)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
CXWindowsPrimaryScreen::~CXWindowsPrimaryScreen()
|
|
|
|
{
|
2001-11-19 00:33:36 +00:00
|
|
|
assert(m_window == None);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::run()
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
// wait for and get the next event
|
|
|
|
XEvent xevent;
|
|
|
|
if (!getEvent(&xevent)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle event
|
|
|
|
switch (xevent.type) {
|
2002-04-29 14:40:01 +00:00
|
|
|
case CreateNotify: {
|
2001-11-19 00:33:36 +00:00
|
|
|
// select events on new window
|
|
|
|
CDisplayLock display(this);
|
|
|
|
selectEvents(display, xevent.xcreatewindow.window);
|
|
|
|
break;
|
2002-04-29 14:40:01 +00:00
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case MappingNotify: {
|
2002-04-26 17:38:01 +00:00
|
|
|
// keyboard mapping changed
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XRefreshKeyboardMapping(&xevent.xmapping);
|
|
|
|
break;
|
2002-04-29 14:40:01 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case KeyPress: {
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG1 "event: KeyPress code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
2001-11-19 00:33:36 +00:00
|
|
|
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
2002-04-26 17:38:01 +00:00
|
|
|
const KeyID key = mapKey(&xevent.xkey);
|
2001-11-19 00:33:36 +00:00
|
|
|
if (key != kKeyNone) {
|
|
|
|
m_server->onKeyDown(key, mask);
|
2002-04-26 20:12:55 +00:00
|
|
|
if (key == XK_Caps_Lock && m_capsLockHalfDuplex)
|
|
|
|
m_server->onKeyUp(key, mask | KeyModifierCapsLock);
|
2001-11-19 00:33:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-04-29 14:40:01 +00:00
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
// FIXME -- simulate key repeat. X sends press/release for
|
|
|
|
// repeat. must detect auto repeat and use kKeyRepeat.
|
|
|
|
case KeyRelease: {
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
|
2001-11-19 00:33:36 +00:00
|
|
|
const KeyModifierMask mask = mapModifier(xevent.xkey.state);
|
2002-04-26 17:38:01 +00:00
|
|
|
const KeyID key = mapKey(&xevent.xkey);
|
2001-11-19 00:33:36 +00:00
|
|
|
if (key != kKeyNone) {
|
2002-04-26 20:12:55 +00:00
|
|
|
if (key == XK_Caps_Lock && m_capsLockHalfDuplex)
|
|
|
|
m_server->onKeyDown(key, mask);
|
2001-11-19 00:33:36 +00:00
|
|
|
m_server->onKeyUp(key, mask);
|
|
|
|
}
|
|
|
|
break;
|
2002-04-29 14:40:01 +00:00
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case ButtonPress: {
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button));
|
2001-11-19 00:33:36 +00:00
|
|
|
const ButtonID button = mapButton(xevent.xbutton.button);
|
|
|
|
if (button != kButtonNone) {
|
|
|
|
m_server->onMouseDown(button);
|
|
|
|
}
|
|
|
|
break;
|
2002-04-29 14:40:01 +00:00
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case ButtonRelease: {
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button));
|
2001-11-19 00:33:36 +00:00
|
|
|
const ButtonID button = mapButton(xevent.xbutton.button);
|
|
|
|
if (button != kButtonNone) {
|
|
|
|
m_server->onMouseUp(button);
|
|
|
|
}
|
|
|
|
break;
|
2002-04-29 14:40:01 +00:00
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case MotionNotify: {
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG2 "event: MotionNotify %d,%d", xevent.xmotion.x_root, xevent.xmotion.y_root));
|
2001-11-19 00:33:36 +00:00
|
|
|
SInt32 x, y;
|
|
|
|
if (!m_active) {
|
|
|
|
x = xevent.xmotion.x_root;
|
|
|
|
y = xevent.xmotion.y_root;
|
|
|
|
m_server->onMouseMovePrimary(x, y);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// FIXME -- slurp up all remaining motion events?
|
|
|
|
// probably not since key strokes may go to wrong place.
|
|
|
|
|
|
|
|
// get mouse deltas
|
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
|
|
|
Window root, window;
|
|
|
|
int xRoot, yRoot, xWindow, yWindow;
|
|
|
|
unsigned int mask;
|
|
|
|
if (!XQueryPointer(display, m_window, &root, &window,
|
|
|
|
&xRoot, &yRoot, &xWindow, &yWindow, &mask))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// compute position of center of window
|
|
|
|
SInt32 w, h;
|
|
|
|
getScreenSize(&w, &h);
|
|
|
|
x = xRoot - (w >> 1);
|
|
|
|
y = yRoot - (h >> 1);
|
|
|
|
|
|
|
|
// warp mouse back to center
|
|
|
|
warpCursorNoLock(display, w >> 1, h >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_server->onMouseMoveSecondary(x, y);
|
|
|
|
}
|
|
|
|
break;
|
2002-04-29 14:40:01 +00:00
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case SelectionClear:
|
2001-11-25 18:32:41 +00:00
|
|
|
// we just lost the selection. that means someone else
|
|
|
|
// grabbed the selection so this screen is now the
|
|
|
|
// selection owner. report that to the server.
|
2001-11-25 22:20:41 +00:00
|
|
|
if (lostClipboard(xevent.xselectionclear.selection,
|
|
|
|
xevent.xselectionclear.time)) {
|
2002-04-27 14:19:53 +00:00
|
|
|
m_server->grabClipboard(getClipboardID(
|
|
|
|
xevent.xselectionclear.selection));
|
2001-11-25 22:20:41 +00:00
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case SelectionNotify:
|
2001-11-25 18:32:41 +00:00
|
|
|
// notification of selection transferred. we shouldn't
|
|
|
|
// get this here because we handle them in the selection
|
|
|
|
// retrieval methods. we'll just delete the property
|
|
|
|
// with the data (satisfying the usual ICCCM protocol).
|
|
|
|
if (xevent.xselection.property != None) {
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XDeleteProperty(display, m_window, xevent.xselection.property);
|
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case SelectionRequest:
|
2001-11-25 18:32:41 +00:00
|
|
|
// somebody is asking for clipboard data
|
|
|
|
if (xevent.xselectionrequest.owner == m_window) {
|
|
|
|
addClipboardRequest(m_window,
|
|
|
|
xevent.xselectionrequest.requestor,
|
|
|
|
xevent.xselectionrequest.selection,
|
|
|
|
xevent.xselectionrequest.target,
|
|
|
|
xevent.xselectionrequest.property,
|
|
|
|
xevent.xselectionrequest.time);
|
|
|
|
}
|
2002-04-28 00:46:15 +00:00
|
|
|
else {
|
|
|
|
// unknown window. return failure.
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XEvent event;
|
|
|
|
event.xselection.type = SelectionNotify;
|
|
|
|
event.xselection.display = display;
|
|
|
|
event.xselection.requestor = xevent.xselectionrequest.requestor;
|
|
|
|
event.xselection.selection = xevent.xselectionrequest.selection;
|
|
|
|
event.xselection.target = xevent.xselectionrequest.target;
|
|
|
|
event.xselection.property = None;
|
|
|
|
event.xselection.time = xevent.xselectionrequest.time;
|
|
|
|
XSendEvent(display, xevent.xselectionrequest.requestor,
|
|
|
|
False, 0, &event);
|
|
|
|
}
|
2001-11-25 18:32:41 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case PropertyNotify:
|
2001-11-25 18:32:41 +00:00
|
|
|
// clipboard transfers involve property changes so forward
|
|
|
|
// the event to the superclass. we only care about the
|
|
|
|
// deletion of properties.
|
|
|
|
if (xevent.xproperty.state == PropertyDelete) {
|
|
|
|
processClipboardRequest(xevent.xproperty.window,
|
|
|
|
xevent.xproperty.atom,
|
|
|
|
xevent.xproperty.time);
|
|
|
|
}
|
2001-11-19 00:33:36 +00:00
|
|
|
break;
|
2002-04-25 10:43:53 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
case DestroyNotify:
|
2002-04-25 10:43:53 +00:00
|
|
|
// looks like one of the windows that requested a clipboard
|
|
|
|
// transfer has gone bye-bye.
|
|
|
|
destroyClipboardRequest(xevent.xdestroywindow.window);
|
|
|
|
break;
|
2001-11-19 00:33:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::stop()
|
|
|
|
{
|
|
|
|
doStop();
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::open(CServer* server)
|
|
|
|
{
|
|
|
|
assert(m_server == NULL);
|
|
|
|
assert(server != NULL);
|
|
|
|
|
|
|
|
// set the server
|
|
|
|
m_server = server;
|
|
|
|
|
|
|
|
// open the display
|
2001-11-11 21:15:30 +00:00
|
|
|
openDisplay();
|
2002-04-26 20:12:55 +00:00
|
|
|
|
|
|
|
// check for peculiarities
|
|
|
|
// FIXME -- may have to get these from some database
|
|
|
|
m_capsLockHalfDuplex = false;
|
|
|
|
// m_capsLockHalfDuplex = true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::close()
|
|
|
|
{
|
|
|
|
assert(m_server != NULL);
|
|
|
|
|
|
|
|
// close the display
|
2001-11-11 21:15:30 +00:00
|
|
|
closeDisplay();
|
|
|
|
|
|
|
|
// done with server
|
|
|
|
m_server = NULL;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::enter(SInt32 x, SInt32 y)
|
|
|
|
{
|
2001-10-14 14:37:41 +00:00
|
|
|
log((CLOG_INFO "entering primary at %d,%d", x, y));
|
2001-11-11 21:15:30 +00:00
|
|
|
assert(m_active == true);
|
|
|
|
assert(m_window != None);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
2001-10-24 22:33:24 +00:00
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// warp to requested location
|
2001-11-11 21:15:30 +00:00
|
|
|
XWarpPointer(display, None, m_window, 0, 0, 0, 0, x, y);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// unmap the grab window. this also ungrabs the mouse and keyboard.
|
2001-11-11 21:15:30 +00:00
|
|
|
XUnmapWindow(display, m_window);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// remove all input events for grab window
|
|
|
|
XEvent event;
|
2001-11-11 21:15:30 +00:00
|
|
|
while (XCheckWindowEvent(display, m_window,
|
2001-10-06 14:13:28 +00:00
|
|
|
PointerMotionMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
KeymapStateMask,
|
|
|
|
&event)) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
// not active anymore
|
|
|
|
m_active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::leave()
|
|
|
|
{
|
2001-10-14 14:37:41 +00:00
|
|
|
log((CLOG_INFO "leaving primary"));
|
2001-11-11 21:15:30 +00:00
|
|
|
assert(m_active == false);
|
|
|
|
assert(m_window != None);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
2001-10-24 22:33:24 +00:00
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// raise and show the input window
|
2001-11-11 21:15:30 +00:00
|
|
|
XMapRaised(display, m_window);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// grab the mouse and keyboard. keep trying until we get them.
|
|
|
|
// if we can't grab one after grabbing the other then ungrab
|
|
|
|
// and wait before retrying.
|
|
|
|
int result;
|
|
|
|
do {
|
|
|
|
// mouse first
|
|
|
|
do {
|
2001-11-11 21:15:30 +00:00
|
|
|
result = XGrabPointer(display, m_window, True, 0,
|
2001-10-06 14:13:28 +00:00
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
m_window, None, CurrentTime);
|
|
|
|
assert(result != GrabNotViewable);
|
2001-10-14 14:37:41 +00:00
|
|
|
if (result != GrabSuccess) {
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG2 "waiting to grab pointer"));
|
2002-04-27 14:19:53 +00:00
|
|
|
CThread::sleep(0.1);
|
2001-10-14 14:37:41 +00:00
|
|
|
}
|
2001-10-06 14:13:28 +00:00
|
|
|
} while (result != GrabSuccess);
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG2 "grabbed pointer"));
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// now the keyboard
|
2001-11-11 21:15:30 +00:00
|
|
|
result = XGrabKeyboard(display, m_window, True,
|
2001-10-06 14:13:28 +00:00
|
|
|
GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
|
|
assert(result != GrabNotViewable);
|
|
|
|
if (result != GrabSuccess) {
|
2001-11-11 21:15:30 +00:00
|
|
|
// back off to avoid grab deadlock
|
|
|
|
XUngrabPointer(display, CurrentTime);
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG2 "ungrabbed pointer, waiting to grab keyboard"));
|
2002-04-27 14:19:53 +00:00
|
|
|
CThread::sleep(0.1);
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
} while (result != GrabSuccess);
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG1 "grabbed pointer and keyboard"));
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// move the mouse to the center of grab window
|
2001-11-11 21:15:30 +00:00
|
|
|
SInt32 w, h;
|
|
|
|
getScreenSize(&w, &h);
|
|
|
|
warpCursorNoLock(display, w >> 1, h >> 1);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// local client now active
|
|
|
|
m_active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::warpCursor(SInt32 x, SInt32 y)
|
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
|
|
|
warpCursorNoLock(display, x, y);
|
2001-10-24 22:33:24 +00:00
|
|
|
}
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2001-10-24 22:33:24 +00:00
|
|
|
void CXWindowsPrimaryScreen::warpCursorNoLock(
|
2001-11-11 21:15:30 +00:00
|
|
|
Display* display, SInt32 x, SInt32 y)
|
2001-10-24 22:33:24 +00:00
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
assert(display != NULL);
|
|
|
|
assert(m_window != None);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// warp the mouse
|
2001-11-11 21:15:30 +00:00
|
|
|
XWarpPointer(display, None, getRoot(), 0, 0, 0, 0, x, y);
|
|
|
|
XSync(display, False);
|
2002-04-27 18:49:03 +00:00
|
|
|
log((CLOG_DEBUG1 "warped to %d,%d", x, y));
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// discard mouse events since we just added one we don't want
|
|
|
|
XEvent xevent;
|
2001-11-11 21:15:30 +00:00
|
|
|
while (XCheckWindowEvent(display, m_window,
|
2001-10-06 14:13:28 +00:00
|
|
|
PointerMotionMask, &xevent)) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-13 23:34:12 +00:00
|
|
|
void CXWindowsPrimaryScreen::setClipboard(
|
2002-04-27 14:19:53 +00:00
|
|
|
ClipboardID id, const IClipboard* clipboard)
|
2001-11-13 23:34:12 +00:00
|
|
|
{
|
2002-04-28 00:46:15 +00:00
|
|
|
setDisplayClipboard(id, clipboard, m_window, getCurrentTime(m_window));
|
2001-11-25 18:32:41 +00:00
|
|
|
}
|
|
|
|
|
2002-04-27 14:19:53 +00:00
|
|
|
void CXWindowsPrimaryScreen::grabClipboard(ClipboardID id)
|
2001-11-25 18:32:41 +00:00
|
|
|
{
|
2002-04-28 00:46:15 +00:00
|
|
|
setDisplayClipboard(id, NULL, m_window, getCurrentTime(m_window));
|
2001-11-13 23:34:12 +00:00
|
|
|
}
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
void CXWindowsPrimaryScreen::getSize(
|
|
|
|
SInt32* width, SInt32* height) const
|
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
getScreenSize(width, height);
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SInt32 CXWindowsPrimaryScreen::getJumpZoneSize() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-11-13 23:34:12 +00:00
|
|
|
void CXWindowsPrimaryScreen::getClipboard(
|
2002-04-27 14:19:53 +00:00
|
|
|
ClipboardID id, IClipboard* clipboard) const
|
2001-11-13 23:34:12 +00:00
|
|
|
{
|
2002-04-28 00:46:15 +00:00
|
|
|
getDisplayClipboard(id, clipboard, m_window, getCurrentTime(m_window));
|
2001-11-13 23:34:12 +00:00
|
|
|
}
|
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
void CXWindowsPrimaryScreen::onOpenDisplay()
|
|
|
|
{
|
|
|
|
assert(m_window == None);
|
|
|
|
|
|
|
|
CDisplayLock display(this);
|
|
|
|
|
|
|
|
// get size of screen
|
|
|
|
SInt32 w, h;
|
|
|
|
getScreenSize(&w, &h);
|
|
|
|
|
|
|
|
// 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 00:46:15 +00:00
|
|
|
KeymapStateMask | PropertyChangeMask;
|
2001-11-11 21:15:30 +00:00
|
|
|
attr.do_not_propagate_mask = 0;
|
|
|
|
attr.override_redirect = True;
|
|
|
|
attr.cursor = createBlankCursor();
|
|
|
|
m_window = XCreateWindow(display, getRoot(), 0, 0, w, h, 0, 0,
|
|
|
|
InputOnly, CopyFromParent,
|
|
|
|
CWDontPropagate | CWEventMask |
|
|
|
|
CWOverrideRedirect | CWCursor,
|
|
|
|
&attr);
|
|
|
|
|
|
|
|
// start watching for events on other windows
|
|
|
|
selectEvents(display, getRoot());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsPrimaryScreen::onCloseDisplay()
|
|
|
|
{
|
|
|
|
assert(m_window != None);
|
|
|
|
|
|
|
|
// destroy window
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XDestroyWindow(display, m_window);
|
|
|
|
m_window = None;
|
|
|
|
}
|
|
|
|
|
2002-04-29 14:08:48 +00:00
|
|
|
long CXWindowsPrimaryScreen::getEventMask(Window w) const
|
|
|
|
{
|
|
|
|
if (w == m_window)
|
|
|
|
return PointerMotionMask |// PointerMotionHintMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
KeymapStateMask;
|
|
|
|
else
|
|
|
|
return PointerMotionMask | SubstructureNotifyMask;
|
|
|
|
}
|
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
void CXWindowsPrimaryScreen::selectEvents(
|
|
|
|
Display* display, Window w) const
|
2001-10-06 14:13:28 +00: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
|
|
|
|
if (w == m_window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// select events of interest
|
2002-04-29 14:08:48 +00:00
|
|
|
XSelectInput(display, w, PointerMotionMask | SubstructureNotifyMask);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// recurse on child windows
|
|
|
|
Window rw, pw, *cw;
|
|
|
|
unsigned int nc;
|
2001-11-11 21:15:30 +00:00
|
|
|
if (XQueryTree(display, w, &rw, &pw, &cw, &nc)) {
|
2001-10-06 14:13:28 +00:00
|
|
|
for (unsigned int i = 0; i < nc; ++i)
|
2001-11-11 21:15:30 +00:00
|
|
|
selectEvents(display, cw[i]);
|
2001-10-25 22:17:17 +00:00
|
|
|
XFree(cw);
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyModifierMask CXWindowsPrimaryScreen::mapModifier(
|
|
|
|
unsigned int state) const
|
|
|
|
{
|
|
|
|
// FIXME -- should be configurable
|
|
|
|
KeyModifierMask mask = 0;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (state & ShiftMask)
|
2001-10-06 14:13:28 +00:00
|
|
|
mask |= KeyModifierShift;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (state & LockMask)
|
2001-10-06 14:13:28 +00:00
|
|
|
mask |= KeyModifierCapsLock;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (state & ControlMask)
|
2001-10-06 14:13:28 +00:00
|
|
|
mask |= KeyModifierControl;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (state & Mod1Mask)
|
2001-10-06 14:13:28 +00:00
|
|
|
mask |= KeyModifierAlt;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (state & Mod2Mask)
|
2001-10-06 14:13:28 +00:00
|
|
|
mask |= KeyModifierNumLock;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (state & Mod4Mask)
|
2001-10-06 14:13:28 +00:00
|
|
|
mask |= KeyModifierMeta;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (state & Mod5Mask)
|
2001-10-06 14:13:28 +00:00
|
|
|
mask |= KeyModifierScrollLock;
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2002-04-26 17:38:01 +00:00
|
|
|
KeyID CXWindowsPrimaryScreen::mapKey(XKeyEvent* event) const
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2002-04-26 17:38:01 +00:00
|
|
|
KeySym keysym;
|
|
|
|
char dummy[1];
|
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
2002-04-26 17:38:01 +00:00
|
|
|
XLookupString(event, dummy, 0, &keysym, NULL);
|
|
|
|
return static_cast<KeyID>(keysym);
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ButtonID CXWindowsPrimaryScreen::mapButton(
|
|
|
|
unsigned int button) const
|
|
|
|
{
|
|
|
|
// FIXME -- should use button mapping?
|
|
|
|
if (button >= 1 && button <= 3)
|
|
|
|
return static_cast<ButtonID>(button);
|
|
|
|
else
|
|
|
|
return kButtonNone;
|
|
|
|
}
|