2001-10-08 19:24:46 +00:00
|
|
|
#include "CXWindowsSecondaryScreen.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "CClient.h"
|
2002-05-27 16:22:59 +00:00
|
|
|
#include "CXWindowsClipboard.h"
|
2002-06-22 19:20:21 +00:00
|
|
|
#include "CXWindowsScreenSaver.h"
|
2002-05-27 16:22:59 +00:00
|
|
|
#include "CXWindowsUtil.h"
|
2001-10-08 19:24:46 +00:00
|
|
|
#include "CThread.h"
|
2001-10-23 22:41:46 +00:00
|
|
|
#include "CLog.h"
|
2002-06-19 11:23:49 +00: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
|
|
|
|
# define XK_XKB_KEYS
|
|
|
|
# include <X11/keysymdef.h>
|
|
|
|
# if defined(HAVE_X11_EXTENSIONS_XTEST_H)
|
|
|
|
# include <X11/extensions/XTest.h>
|
|
|
|
# else
|
|
|
|
# error The XTest extension is required to build synergy
|
|
|
|
# endif
|
|
|
|
#endif
|
2001-10-08 19:24:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CXWindowsSecondaryScreen
|
|
|
|
//
|
|
|
|
|
|
|
|
CXWindowsSecondaryScreen::CXWindowsSecondaryScreen() :
|
2002-06-10 22:06:45 +00:00
|
|
|
m_client(NULL),
|
|
|
|
m_window(None)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
CXWindowsSecondaryScreen::~CXWindowsSecondaryScreen()
|
|
|
|
{
|
2001-11-25 18:32:41 +00:00
|
|
|
assert(m_window == None);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CXWindowsSecondaryScreen::run()
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
|
|
|
assert(m_window != None);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
// wait for and get the next event
|
|
|
|
XEvent xevent;
|
|
|
|
if (!getEvent(&xevent)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle event
|
|
|
|
switch (xevent.type) {
|
2002-06-10 22:06:45 +00:00
|
|
|
case MappingNotify:
|
|
|
|
{
|
|
|
|
// keyboard mapping changed
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XRefreshKeyboardMapping(&xevent.xmapping);
|
|
|
|
updateKeys(display);
|
|
|
|
updateKeycodeMap(display);
|
|
|
|
updateModifierMap(display);
|
|
|
|
updateModifiers(display);
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
break;
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
case LeaveNotify:
|
|
|
|
{
|
|
|
|
// mouse moved out of hider window somehow. hide the window.
|
|
|
|
assert(m_window != None);
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XUnmapWindow(display, m_window);
|
|
|
|
}
|
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-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CXWindowsSecondaryScreen::stop()
|
2001-11-19 00:33:36 +00:00
|
|
|
{
|
2002-06-21 17:55:47 +00:00
|
|
|
CDisplayLock display(this);
|
2001-11-19 00:33:36 +00:00
|
|
|
doStop();
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::open(CClient* client)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
|
|
|
assert(m_client == NULL);
|
|
|
|
assert(client != NULL);
|
|
|
|
|
|
|
|
// set the client
|
|
|
|
m_client = client;
|
|
|
|
|
|
|
|
// open the display
|
2001-11-11 21:15:30 +00:00
|
|
|
openDisplay();
|
2001-10-08 19:24:46 +00:00
|
|
|
|
2002-04-27 18:06:40 +00:00
|
|
|
{
|
|
|
|
// verify the availability of the XTest extension
|
|
|
|
CDisplayLock display(this);
|
|
|
|
int majorOpcode, firstEvent, firstError;
|
|
|
|
if (!XQueryExtension(display, XTestExtensionName,
|
2002-06-10 22:06:45 +00:00
|
|
|
&majorOpcode, &firstEvent, &firstError)) {
|
2002-04-27 18:06:40 +00:00
|
|
|
throw int(6); // FIXME -- make exception for this
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2002-04-27 18:06:40 +00:00
|
|
|
// update key state
|
|
|
|
updateKeys(display);
|
|
|
|
updateKeycodeMap(display);
|
|
|
|
updateModifierMap(display);
|
|
|
|
updateModifiers(display);
|
|
|
|
}
|
|
|
|
|
2002-04-30 16:25:29 +00:00
|
|
|
// check for peculiarities
|
|
|
|
// FIXME -- may have to get these from some database
|
2002-05-04 18:31:54 +00:00
|
|
|
m_numLockHalfDuplex = false;
|
2002-04-30 16:25:29 +00:00
|
|
|
m_capsLockHalfDuplex = false;
|
2002-06-11 18:33:03 +00:00
|
|
|
// m_numLockHalfDuplex = true;
|
|
|
|
// m_capsLockHalfDuplex = true;
|
2002-04-30 16:25:29 +00:00
|
|
|
|
2002-04-27 18:06:40 +00:00
|
|
|
// assume primary has all clipboards
|
2002-06-10 22:06:45 +00:00
|
|
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
2002-04-27 18:06:40 +00:00
|
|
|
grabClipboard(id);
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-06-22 19:20:21 +00:00
|
|
|
|
|
|
|
// disable the screen saver
|
|
|
|
getScreenSaver()->disable();
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CXWindowsSecondaryScreen::close()
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
|
|
|
assert(m_client != NULL);
|
2001-10-23 22:41:46 +00:00
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
// restore the screen saver settings
|
|
|
|
getScreenSaver()->enable();
|
|
|
|
|
2001-10-08 19:24:46 +00:00
|
|
|
// close the display
|
2001-11-11 21:15:30 +00:00
|
|
|
closeDisplay();
|
|
|
|
|
|
|
|
// done with client
|
|
|
|
m_client = NULL;
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::enter(SInt32 x, SInt32 y, KeyModifierMask mask)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2001-10-23 22:41:46 +00:00
|
|
|
assert(m_window != None);
|
2001-10-08 19:24:46 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
2001-10-24 22:33:24 +00:00
|
|
|
|
2001-10-08 19:24:46 +00:00
|
|
|
// warp to requested location
|
2001-11-11 21:15:30 +00:00
|
|
|
XTestFakeMotionEvent(display, getScreen(), x, y, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 19:24:46 +00:00
|
|
|
|
|
|
|
// show cursor
|
2001-11-11 21:15:30 +00:00
|
|
|
XUnmapWindow(display, m_window);
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// update our keyboard state to reflect the local state
|
|
|
|
updateKeys(display);
|
|
|
|
updateModifiers(display);
|
2002-04-30 17:48:11 +00:00
|
|
|
|
|
|
|
// toggle modifiers that don't match the desired state
|
|
|
|
unsigned int xMask = maskToX(mask);
|
|
|
|
if ((xMask & m_capsLockMask) != (m_mask & m_capsLockMask)) {
|
|
|
|
toggleKey(display, XK_Caps_Lock, m_capsLockMask);
|
|
|
|
}
|
|
|
|
if ((xMask & m_numLockMask) != (m_mask & m_numLockMask)) {
|
|
|
|
toggleKey(display, XK_Num_Lock, m_numLockMask);
|
|
|
|
}
|
|
|
|
if ((xMask & m_scrollLockMask) != (m_mask & m_scrollLockMask)) {
|
|
|
|
toggleKey(display, XK_Scroll_Lock, m_scrollLockMask);
|
|
|
|
}
|
|
|
|
XSync(display, False);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CXWindowsSecondaryScreen::leave()
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
|
|
|
leaveNoLock(display);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::keyDown(KeyID key, KeyModifierMask mask)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2002-04-26 17:38:01 +00:00
|
|
|
Keystrokes keys;
|
|
|
|
KeyCode keycode;
|
|
|
|
|
|
|
|
// get the sequence of keys to simulate key press and the final
|
|
|
|
// modifier state.
|
2002-05-03 11:26:44 +00:00
|
|
|
m_mask = mapKey(keys, keycode, key, mask, kPress);
|
2002-06-10 22:06:45 +00:00
|
|
|
if (keys.empty()) {
|
2002-04-26 17:38:01 +00:00
|
|
|
return;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// generate key events
|
2002-05-03 11:26:44 +00:00
|
|
|
doKeystrokes(keys, 1);
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// note that key is now down
|
|
|
|
m_keys[keycode] = true;
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::keyRepeat(KeyID key,
|
|
|
|
KeyModifierMask mask, SInt32 count)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2002-05-03 11:26:44 +00:00
|
|
|
Keystrokes keys;
|
|
|
|
KeyCode keycode;
|
|
|
|
|
|
|
|
// get the sequence of keys to simulate key repeat and the final
|
|
|
|
// modifier state.
|
|
|
|
m_mask = mapKey(keys, keycode, key, mask, kRepeat);
|
2002-06-10 22:06:45 +00:00
|
|
|
if (keys.empty()) {
|
2002-05-03 11:26:44 +00:00
|
|
|
return;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-05-03 11:26:44 +00:00
|
|
|
|
|
|
|
// generate key events
|
|
|
|
doKeystrokes(keys, count);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::keyUp(KeyID key, KeyModifierMask mask)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2002-04-26 17:38:01 +00:00
|
|
|
Keystrokes keys;
|
|
|
|
KeyCode keycode;
|
|
|
|
|
|
|
|
// get the sequence of keys to simulate key release and the final
|
|
|
|
// modifier state.
|
2002-05-03 11:26:44 +00:00
|
|
|
m_mask = mapKey(keys, keycode, key, mask, kRelease);
|
2002-06-10 22:06:45 +00:00
|
|
|
if (keys.empty()) {
|
2002-04-26 17:38:01 +00:00
|
|
|
return;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// generate key events
|
2002-05-03 11:26:44 +00:00
|
|
|
doKeystrokes(keys, 1);
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// note that key is now up
|
|
|
|
m_keys[keycode] = false;
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::mouseDown(ButtonID button)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeButtonEvent(display, mapButton(button), True, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::mouseUp(ButtonID button)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeButtonEvent(display, mapButton(button), False, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::mouseMove(SInt32 x, SInt32 y)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeMotionEvent(display, getScreen(), x, y, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::mouseWheel(SInt32 delta)
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2002-05-23 15:50:38 +00:00
|
|
|
// choose button depending on rotation direction
|
|
|
|
const unsigned int button = (delta >= 0) ? 4 : 5;
|
|
|
|
|
|
|
|
// now use absolute value of delta
|
|
|
|
if (delta < 0) {
|
|
|
|
delta = -delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send as many clicks as necessary
|
2001-11-11 21:15:30 +00:00
|
|
|
CDisplayLock display(this);
|
2002-05-23 15:50:38 +00:00
|
|
|
for (; delta >= 120; delta -= 120) {
|
|
|
|
XTestFakeButtonEvent(display, button, True, CurrentTime);
|
|
|
|
XTestFakeButtonEvent(display, button, False, CurrentTime);
|
|
|
|
}
|
|
|
|
XSync(display, False);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::setClipboard(ClipboardID id,
|
|
|
|
const IClipboard* clipboard)
|
2001-11-25 18:32:41 +00:00
|
|
|
{
|
2002-05-27 16:22:59 +00:00
|
|
|
setDisplayClipboard(id, clipboard);
|
2001-11-25 18:32:41 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::grabClipboard(ClipboardID id)
|
2001-11-25 18:32:41 +00:00
|
|
|
{
|
2002-05-27 16:22:59 +00:00
|
|
|
setDisplayClipboard(id, NULL);
|
2001-11-25 18:32:41 +00:00
|
|
|
}
|
|
|
|
|
2002-06-22 19:20:21 +00:00
|
|
|
void
|
|
|
|
CXWindowsSecondaryScreen::screenSaver(bool activate)
|
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
|
|
|
if (activate) {
|
|
|
|
getScreenSaver()->activate();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
getScreenSaver()->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-19 17:03:29 +00:00
|
|
|
CXWindowsSecondaryScreen::getMousePos(SInt32& x, SInt32& y) const
|
2002-05-24 17:54:28 +00:00
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
|
|
|
int xTmp, yTmp, dummy;
|
|
|
|
unsigned int dummyMask;
|
|
|
|
Window dummyWindow;
|
|
|
|
XQueryPointer(display, getRoot(), &dummyWindow, &dummyWindow,
|
|
|
|
&xTmp, &yTmp, &dummy, &dummy, &dummyMask);
|
2002-06-19 17:03:29 +00:00
|
|
|
x = xTmp;
|
|
|
|
y = yTmp;
|
2002-05-24 17:54:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-19 17:03:29 +00:00
|
|
|
CXWindowsSecondaryScreen::getShape(
|
|
|
|
SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
2002-06-19 17:03:29 +00:00
|
|
|
getScreenShape(x, y, w, h);
|
2001-10-08 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
SInt32
|
|
|
|
CXWindowsSecondaryScreen::getJumpZoneSize() const
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::getClipboard(ClipboardID id,
|
|
|
|
IClipboard* clipboard) const
|
2001-11-25 18:32:41 +00:00
|
|
|
{
|
2002-05-27 16:22:59 +00:00
|
|
|
getDisplayClipboard(id, clipboard);
|
2001-11-25 18:32:41 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::onOpenDisplay(Display* display)
|
2001-10-23 22:41:46 +00:00
|
|
|
{
|
2001-11-11 21:15:30 +00:00
|
|
|
assert(m_window == None);
|
2001-10-23 22:41:46 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
// create the cursor hiding window. this window is used to hide the
|
|
|
|
// cursor when it's not on the screen. the window is hidden as soon
|
|
|
|
// as the cursor enters the screen or the display's real cursor is
|
|
|
|
// moved.
|
|
|
|
XSetWindowAttributes attr;
|
2002-04-29 14:08:48 +00:00
|
|
|
attr.event_mask = LeaveWindowMask;
|
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, 1, 1, 0, 0,
|
|
|
|
InputOnly, CopyFromParent,
|
|
|
|
CWDontPropagate | CWEventMask |
|
|
|
|
CWOverrideRedirect | CWCursor,
|
|
|
|
&attr);
|
2002-05-27 18:28:06 +00:00
|
|
|
log((CLOG_DEBUG "window is 0x%08x", m_window));
|
2001-10-23 22:41:46 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
// become impervious to server grabs
|
|
|
|
XTestGrabControl(display, True);
|
2001-10-23 22:41:46 +00:00
|
|
|
|
2001-11-11 21:15:30 +00:00
|
|
|
// hide the cursor
|
|
|
|
leaveNoLock(display);
|
|
|
|
}
|
2001-10-23 22:41:46 +00:00
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CXWindowsClipboard*
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::createClipboard(ClipboardID id)
|
2002-05-27 16:22:59 +00:00
|
|
|
{
|
|
|
|
CDisplayLock display(this);
|
|
|
|
return new CXWindowsClipboard(display, m_window, id);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::onCloseDisplay(Display* display)
|
2001-11-11 21:15:30 +00:00
|
|
|
{
|
|
|
|
assert(m_window != None);
|
2001-10-23 22:41:46 +00:00
|
|
|
|
2002-06-03 13:45:30 +00:00
|
|
|
if (display != NULL) {
|
|
|
|
// no longer impervious to server grabs
|
|
|
|
XTestGrabControl(display, False);
|
2001-10-23 22:41:46 +00:00
|
|
|
|
2002-06-03 13:45:30 +00:00
|
|
|
// destroy window
|
|
|
|
XDestroyWindow(display, m_window);
|
|
|
|
}
|
2001-11-11 21:15:30 +00:00
|
|
|
m_window = None;
|
2002-05-27 16:22:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::onLostClipboard(ClipboardID id)
|
2002-05-27 16:22:59 +00:00
|
|
|
{
|
|
|
|
// tell client that the clipboard was grabbed locally
|
|
|
|
m_client->onClipboardChanged(id);
|
2001-10-23 22:41:46 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::leaveNoLock(Display* display)
|
2001-11-11 21:15:30 +00:00
|
|
|
{
|
|
|
|
assert(display != NULL);
|
|
|
|
assert(m_window != None);
|
|
|
|
|
|
|
|
// move hider window under the mouse (rather than moving the mouse
|
|
|
|
// somewhere else on the screen)
|
|
|
|
int x, y, dummy;
|
|
|
|
unsigned int dummyMask;
|
|
|
|
Window dummyWindow;
|
|
|
|
XQueryPointer(display, getRoot(), &dummyWindow, &dummyWindow,
|
|
|
|
&x, &y, &dummy, &dummy, &dummyMask);
|
|
|
|
XMoveWindow(display, m_window, x, y);
|
|
|
|
|
|
|
|
// raise and show the hider window
|
|
|
|
XMapRaised(display, m_window);
|
|
|
|
|
|
|
|
// hide cursor by moving it into the hider window
|
|
|
|
XWarpPointer(display, None, m_window, 0, 0, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
unsigned int
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::mapButton(ButtonID id) const
|
2001-10-08 19:24:46 +00:00
|
|
|
{
|
|
|
|
// FIXME -- should use button mapping?
|
|
|
|
return static_cast<unsigned int>(id);
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
KeyModifierMask
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::mapKey(Keystrokes& keys, KeyCode& keycode,
|
|
|
|
KeyID id, KeyModifierMask mask, EKeyAction action) const
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
|
|
|
// note -- must have display locked on entry
|
|
|
|
|
|
|
|
// the system translates key events into characters depending
|
|
|
|
// on the modifier key state at the time of the event. to
|
|
|
|
// generate the right keysym we need to set the modifier key
|
|
|
|
// states appropriately.
|
|
|
|
//
|
|
|
|
// the mask passed by the caller is the desired mask. however,
|
|
|
|
// there may not be a keycode mapping to generate the desired
|
|
|
|
// keysym with that mask. we override the bits in the mask
|
|
|
|
// that cannot be accomodated.
|
|
|
|
|
2002-04-30 16:25:29 +00:00
|
|
|
// note if the key is the caps lock and it's "half-duplex"
|
2002-05-04 18:31:54 +00:00
|
|
|
const bool isHalfDuplex = ((id == XK_Caps_Lock && m_capsLockHalfDuplex) ||
|
|
|
|
(id == XK_Num_Lock && m_numLockHalfDuplex));
|
2002-04-30 16:25:29 +00:00
|
|
|
|
2002-05-03 11:26:44 +00:00
|
|
|
// ignore releases and repeats for half-duplex keys
|
|
|
|
if (isHalfDuplex && action != kPress) {
|
2002-04-30 16:25:29 +00:00
|
|
|
return m_mask;
|
|
|
|
}
|
|
|
|
|
2002-04-26 17:38:01 +00:00
|
|
|
// lookup the a keycode for this key id. also return the
|
|
|
|
// key modifier mask required.
|
|
|
|
unsigned int outMask;
|
|
|
|
if (!findKeyCode(keycode, outMask, id, maskToX(mask))) {
|
|
|
|
// we cannot generate the desired keysym because no key
|
|
|
|
// maps to that keysym. just return the current mask.
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "no keycode for keysym %d modifiers 0x%04x", id, mask));
|
2002-04-26 17:38:01 +00:00
|
|
|
return m_mask;
|
|
|
|
}
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "keysym %d -> keycode %d modifiers 0x%04x", id, keycode, outMask));
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// if we cannot match the modifier mask then don't return any
|
|
|
|
// keys and just return the current mask.
|
|
|
|
if ((outMask & m_modifierMask) != outMask) {
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "cannot match modifiers to mask 0x%04x", m_modifierMask));
|
2002-04-26 17:38:01 +00:00
|
|
|
return m_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
// note if the key is a modifier
|
|
|
|
ModifierMap::const_iterator index = m_keycodeToModifier.find(keycode);
|
|
|
|
const bool isModifier = (index != m_keycodeToModifier.end());
|
|
|
|
|
|
|
|
// add the key events required to get to the modifier state
|
|
|
|
// necessary to generate an event yielding id. also save the
|
|
|
|
// key events required to restore the state. if the key is
|
|
|
|
// a modifier key then skip this because modifiers should not
|
|
|
|
// modify modifiers.
|
|
|
|
Keystrokes undo;
|
2002-05-03 11:26:44 +00:00
|
|
|
Keystroke keystroke;
|
2002-04-26 17:38:01 +00:00
|
|
|
if (outMask != m_mask && !isModifier) {
|
|
|
|
for (unsigned int i = 0; i < 8; ++i) {
|
|
|
|
unsigned int bit = (1 << i);
|
|
|
|
if ((outMask & bit) != (m_mask & bit)) {
|
2002-06-02 19:04:24 +00:00
|
|
|
// get list of keycodes for the modifier. if there isn't
|
2002-06-22 12:09:49 +00:00
|
|
|
// one then there's no key mapped to this modifier and we
|
|
|
|
// can't generate the desired key so bail.
|
2002-04-26 17:38:01 +00:00
|
|
|
const KeyCode* modifierKeys =
|
|
|
|
&m_modifierToKeycode[i * m_keysPerModifier];
|
2002-05-05 19:52:03 +00:00
|
|
|
KeyCode modifierKey = modifierKeys[0];
|
2002-06-02 19:04:24 +00:00
|
|
|
if (modifierKey == 0) {
|
2002-05-05 19:52:03 +00:00
|
|
|
modifierKey = modifierKeys[1];
|
2002-06-02 19:04:24 +00:00
|
|
|
}
|
|
|
|
if (modifierKey == 0) {
|
|
|
|
log((CLOG_DEBUG1 "no key mapped to modifier 0x%04x", bit));
|
|
|
|
return m_mask;
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
2002-06-22 12:09:49 +00:00
|
|
|
keystroke.m_keycode = modifierKey;
|
|
|
|
keystroke.m_repeat = false;
|
|
|
|
if ((outMask & bit) != 0) {
|
2002-04-26 17:38:01 +00:00
|
|
|
// modifier is not active but should be. if the
|
|
|
|
// modifier is a toggle then toggle it on with a
|
|
|
|
// press/release, otherwise activate it with a
|
|
|
|
// press. use the first keycode for the modifier.
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "modifier 0x%04x is not active", bit));
|
2002-04-26 17:38:01 +00:00
|
|
|
if ((bit & m_toggleModifierMask) != 0) {
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "modifier 0x%04x is a toggle", bit));
|
2002-05-04 18:31:54 +00:00
|
|
|
if ((bit == m_capsLockMask && m_capsLockHalfDuplex) ||
|
|
|
|
(bit == m_numLockMask && m_numLockHalfDuplex)) {
|
2002-06-22 12:09:49 +00:00
|
|
|
keystroke.m_press = True;
|
|
|
|
keys.push_back(keystroke);
|
2002-05-03 11:26:44 +00:00
|
|
|
keystroke.m_press = False;
|
|
|
|
undo.push_back(keystroke);
|
2002-04-30 17:48:11 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-06-22 12:09:49 +00:00
|
|
|
keystroke.m_press = True;
|
|
|
|
keys.push_back(keystroke);
|
2002-05-03 11:26:44 +00:00
|
|
|
keystroke.m_press = False;
|
2002-05-04 18:31:54 +00:00
|
|
|
keys.push_back(keystroke);
|
|
|
|
undo.push_back(keystroke);
|
|
|
|
keystroke.m_press = True;
|
2002-05-03 11:26:44 +00:00
|
|
|
undo.push_back(keystroke);
|
2002-04-30 17:48:11 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-06-22 12:09:49 +00:00
|
|
|
keystroke.m_press = True;
|
|
|
|
keys.push_back(keystroke);
|
2002-05-03 11:26:44 +00:00
|
|
|
keystroke.m_press = False;
|
|
|
|
undo.push_back(keystroke);
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-22 12:09:49 +00:00
|
|
|
else {
|
2002-04-26 17:38:01 +00:00
|
|
|
// modifier is active but should not be. if the
|
|
|
|
// modifier is a toggle then toggle it off with a
|
|
|
|
// press/release, otherwise deactivate it with a
|
|
|
|
// release. we must check each keycode for the
|
|
|
|
// modifier if not a toggle.
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "modifier 0x%04x is active", bit));
|
2002-04-30 17:48:11 +00:00
|
|
|
if ((bit & m_toggleModifierMask) != 0) {
|
2002-06-22 12:09:49 +00:00
|
|
|
log((CLOG_DEBUG2 "modifier 0x%04x is a toggle", bit));
|
|
|
|
if ((bit == m_capsLockMask && m_capsLockHalfDuplex) ||
|
|
|
|
(bit == m_numLockMask && m_numLockHalfDuplex)) {
|
|
|
|
keystroke.m_press = False;
|
|
|
|
keys.push_back(keystroke);
|
|
|
|
keystroke.m_press = True;
|
|
|
|
undo.push_back(keystroke);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
keystroke.m_press = True;
|
|
|
|
keys.push_back(keystroke);
|
|
|
|
keystroke.m_press = False;
|
|
|
|
keys.push_back(keystroke);
|
|
|
|
undo.push_back(keystroke);
|
|
|
|
keystroke.m_press = True;
|
|
|
|
undo.push_back(keystroke);
|
2002-04-30 17:48:11 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (unsigned int j = 0; j < m_keysPerModifier; ++j) {
|
|
|
|
const KeyCode key = modifierKeys[j];
|
2002-05-05 19:52:03 +00:00
|
|
|
if (key != 0 && m_keys[key]) {
|
2002-05-03 11:26:44 +00:00
|
|
|
keystroke.m_keycode = key;
|
|
|
|
keystroke.m_press = False;
|
|
|
|
keys.push_back(keystroke);
|
|
|
|
keystroke.m_press = True;
|
|
|
|
undo.push_back(keystroke);
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-30 16:25:29 +00:00
|
|
|
// note if the press of a half-duplex key should be treated as a release
|
|
|
|
if (isHalfDuplex && (m_mask & (1 << index->second)) != 0) {
|
2002-05-03 11:26:44 +00:00
|
|
|
action = kRelease;
|
2002-04-30 16:25:29 +00:00
|
|
|
}
|
|
|
|
|
2002-04-26 17:38:01 +00:00
|
|
|
// add the key event
|
2002-05-03 11:26:44 +00:00
|
|
|
keystroke.m_keycode = keycode;
|
|
|
|
switch (action) {
|
|
|
|
case kPress:
|
|
|
|
keystroke.m_press = True;
|
2002-05-05 19:52:03 +00:00
|
|
|
keystroke.m_repeat = false;
|
2002-05-03 11:26:44 +00:00
|
|
|
keys.push_back(keystroke);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kRelease:
|
|
|
|
keystroke.m_press = False;
|
2002-05-05 19:52:03 +00:00
|
|
|
keystroke.m_repeat = false;
|
2002-05-03 11:26:44 +00:00
|
|
|
keys.push_back(keystroke);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kRepeat:
|
|
|
|
keystroke.m_press = False;
|
2002-05-05 19:52:03 +00:00
|
|
|
keystroke.m_repeat = true;
|
2002-05-03 11:26:44 +00:00
|
|
|
keys.push_back(keystroke);
|
|
|
|
keystroke.m_press = True;
|
|
|
|
keys.push_back(keystroke);
|
|
|
|
break;
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// add key events to restore the modifier state. apply events in
|
|
|
|
// the reverse order that they're stored in undo.
|
|
|
|
while (!undo.empty()) {
|
|
|
|
keys.push_back(undo.back());
|
|
|
|
undo.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the key is a modifier key then compute the modifier map after
|
2002-05-03 11:26:44 +00:00
|
|
|
// this key is pressed or released. if repeating then ignore.
|
2002-04-26 17:38:01 +00:00
|
|
|
mask = m_mask;
|
2002-05-03 11:26:44 +00:00
|
|
|
if (isModifier && action != kRepeat) {
|
2002-04-26 17:38:01 +00:00
|
|
|
// get modifier
|
|
|
|
const unsigned int modifierBit = (1 << index->second);
|
|
|
|
|
2002-05-04 18:09:02 +00:00
|
|
|
// toggle keys modify the state on release. other keys set the
|
|
|
|
// bit on press and clear the bit on release. if half-duplex
|
|
|
|
// then toggle each time we get here.
|
2002-04-26 17:38:01 +00:00
|
|
|
if ((modifierBit & m_toggleModifierMask) != 0) {
|
2002-05-04 18:31:54 +00:00
|
|
|
if (isHalfDuplex || action == kRelease) {
|
2002-05-04 18:09:02 +00:00
|
|
|
mask ^= modifierBit;
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
2002-05-03 11:26:44 +00:00
|
|
|
else if (action == kPress) {
|
2002-04-26 17:38:01 +00:00
|
|
|
mask |= modifierBit;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// can't reset bit until all keys that set it are released.
|
|
|
|
// scan those keys to see if any (except keycode) are pressed.
|
|
|
|
bool down = false;
|
|
|
|
const KeyCode* modifierKeys = &m_modifierToKeycode[
|
|
|
|
index->second * m_keysPerModifier];
|
|
|
|
for (unsigned int j = 0; !down && j < m_keysPerModifier; ++j) {
|
2002-05-05 19:52:03 +00:00
|
|
|
if (modifierKeys[j] != 0 && m_keys[modifierKeys[j]])
|
2002-04-26 17:38:01 +00:00
|
|
|
down = true;
|
|
|
|
}
|
|
|
|
if (!down)
|
|
|
|
mask &= ~modifierBit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::findKeyCode(KeyCode& keycode,
|
|
|
|
unsigned int& maskOut, KeyID id, unsigned int maskIn) const
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
2002-05-03 12:23:48 +00:00
|
|
|
// if XK_Tab is requested with shift active then try XK_ISO_Left_Tab
|
|
|
|
// instead. if that doesn't work, we'll fall back to XK_Tab with
|
|
|
|
// shift active. this is to handle primary screens that don't map
|
|
|
|
// XK_ISO_Left_Tab sending events to secondary screens that do.
|
|
|
|
if (id == XK_Tab && (maskIn & ShiftMask) != 0) {
|
|
|
|
id = XK_ISO_Left_Tab;
|
|
|
|
maskIn &= ~ShiftMask;
|
|
|
|
}
|
|
|
|
|
2002-04-26 17:38:01 +00:00
|
|
|
// find a keycode to generate id. XKeysymToKeycode() almost does
|
|
|
|
// what we need but won't tell us which index to use with the
|
|
|
|
// keycode. return false if there's no keycode to generate id.
|
|
|
|
KeyCodeMap::const_iterator index = m_keycodeMap.find(id);
|
2002-04-30 18:30:05 +00:00
|
|
|
if (index == m_keycodeMap.end()) {
|
|
|
|
// try backup keysym for certain keys (particularly the numpad
|
|
|
|
// keys since most laptops don't have a separate numpad and the
|
|
|
|
// numpad overlaying the main keyboard may not have movement
|
|
|
|
// key bindings).
|
|
|
|
switch (id) {
|
|
|
|
case XK_KP_Home:
|
|
|
|
id = XK_Home;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Left:
|
|
|
|
id = XK_Left;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Up:
|
|
|
|
id = XK_Up;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Right:
|
|
|
|
id = XK_Right;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Down:
|
|
|
|
id = XK_Down;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Prior:
|
|
|
|
id = XK_Prior;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Next:
|
|
|
|
id = XK_Next;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_End:
|
|
|
|
id = XK_End;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Insert:
|
|
|
|
id = XK_Insert;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XK_KP_Delete:
|
|
|
|
id = XK_Delete;
|
|
|
|
break;
|
|
|
|
|
2002-05-03 12:14:55 +00:00
|
|
|
case XK_ISO_Left_Tab:
|
2002-05-03 12:23:48 +00:00
|
|
|
id = XK_Tab;
|
|
|
|
maskIn |= ShiftMask;
|
2002-05-03 12:14:55 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-30 18:30:05 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = m_keycodeMap.find(id);
|
|
|
|
if (index == m_keycodeMap.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// save the keycode
|
2002-05-03 11:26:44 +00:00
|
|
|
keycode = index->second.m_keycode;
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// compute output mask. that's the set of modifiers that need to
|
|
|
|
// be enabled when the keycode event is encountered in order to
|
|
|
|
// generate the id keysym and match maskIn. it's possible that
|
|
|
|
// maskIn wants, say, a shift key to be down but that would make
|
|
|
|
// it impossible to generate the keysym. in that case we must
|
2002-04-26 20:14:46 +00:00
|
|
|
// override maskIn. this is complicated by caps/shift-lock and
|
|
|
|
// num-lock.
|
2002-05-03 11:26:44 +00:00
|
|
|
maskOut = (maskIn & ~index->second.m_keyMaskMask);
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "maskIn(0x%04x) & ~maskMask(0x%04x) -> 0x%04x", maskIn, index->second.m_keyMaskMask, maskOut));
|
2002-04-26 17:38:01 +00:00
|
|
|
if (IsKeypadKey(id) || IsPrivateKeypadKey(id)) {
|
2002-05-04 19:43:20 +00:00
|
|
|
if ((m_mask & m_numLockMask) != 0) {
|
|
|
|
maskOut &= ~index->second.m_keyMask;
|
|
|
|
maskOut |= m_numLockMask;
|
|
|
|
log((CLOG_DEBUG2 "keypad key: & ~mask(0x%04x) | numLockMask(0x%04x) -> 0x%04x", index->second.m_keyMask, m_numLockMask, maskOut));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
maskOut |= index->second.m_keyMask;
|
|
|
|
maskOut &= ~m_numLockMask;
|
|
|
|
log((CLOG_DEBUG2 "keypad key: | mask(0x%04x) & ~numLockMask(0x%04x) -> 0x%04x", index->second.m_keyMask, m_numLockMask, maskOut));
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-05-03 11:26:44 +00:00
|
|
|
unsigned int maskShift = (index->second.m_keyMask & ShiftMask);
|
2002-05-04 11:23:11 +00:00
|
|
|
log((CLOG_DEBUG2 "maskShift = 0x%04x", maskShift));
|
2002-05-04 19:43:20 +00:00
|
|
|
if (maskShift != 0 && (m_mask & m_capsLockMask) != 0) {
|
2002-05-04 11:23:11 +00:00
|
|
|
// shift and capsLock cancel out for keysyms subject to
|
|
|
|
// case conversion but not for keys with shifted
|
|
|
|
// characters that are not case conversions. see if
|
|
|
|
// case conversion is necessary.
|
|
|
|
KeySym lKey, uKey;
|
|
|
|
XConvertCase(id, &lKey, &uKey);
|
|
|
|
if (lKey != uKey) {
|
2002-05-04 19:43:20 +00:00
|
|
|
log((CLOG_DEBUG2 "case convertable, shift && capsLock -> caps lock"));
|
|
|
|
maskShift = m_capsLockMask;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log((CLOG_DEBUG2 "case unconvertable, shift && capsLock -> shift, caps lock"));
|
|
|
|
maskShift |= m_capsLockMask;
|
2002-05-04 11:23:11 +00:00
|
|
|
}
|
|
|
|
}
|
2002-05-04 19:43:20 +00:00
|
|
|
log((CLOG_DEBUG2 "maskShift = 0x%04x", maskShift));
|
|
|
|
maskOut |= maskShift;
|
2002-05-03 11:26:44 +00:00
|
|
|
maskOut |= (index->second.m_keyMask & ~(ShiftMask | LockMask));
|
2002-05-04 19:43:20 +00:00
|
|
|
log((CLOG_DEBUG2 "| maskShift(0x%04x) | other (0x%04x) -> 0x%04x", maskShift, (index->second.m_keyMask & ~(ShiftMask | LockMask)), maskOut));
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::doKeystrokes(const Keystrokes& keys, SInt32 count)
|
2002-05-03 11:26:44 +00:00
|
|
|
{
|
|
|
|
// do nothing if no keys or no repeats
|
2002-06-10 22:06:45 +00:00
|
|
|
if (count < 1 || keys.empty()) {
|
2002-05-03 11:26:44 +00:00
|
|
|
return;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-05-03 11:26:44 +00:00
|
|
|
|
|
|
|
// lock display
|
|
|
|
CDisplayLock display(this);
|
|
|
|
|
|
|
|
// generate key events
|
|
|
|
for (Keystrokes::const_iterator k = keys.begin(); k != keys.end(); ) {
|
|
|
|
if (k->m_repeat) {
|
|
|
|
// repeat from here up to but not including the next key
|
|
|
|
// with m_repeat == false count times.
|
|
|
|
Keystrokes::const_iterator start = k;
|
|
|
|
for (; count > 0; --count) {
|
|
|
|
// send repeating events
|
|
|
|
for (k = start; k != keys.end() && k->m_repeat; ++k) {
|
|
|
|
XTestFakeKeyEvent(display,
|
2002-05-03 11:49:30 +00:00
|
|
|
k->m_keycode, k->m_press, CurrentTime);
|
2002-05-03 11:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// note -- k is now on the first non-repeat key after the
|
|
|
|
// repeat keys, exactly where we'd like to continue from.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// send event
|
|
|
|
XTestFakeKeyEvent(display, k->m_keycode, k->m_press, CurrentTime);
|
|
|
|
|
|
|
|
// next key
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update
|
|
|
|
XSync(display, False);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
unsigned int
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::maskToX(KeyModifierMask inMask) const
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
2002-05-27 18:28:06 +00:00
|
|
|
// FIXME -- should be configurable. also not using Mod3Mask.
|
2002-04-26 17:38:01 +00:00
|
|
|
unsigned int outMask = 0;
|
2002-06-10 22:06:45 +00:00
|
|
|
if (inMask & KeyModifierShift) {
|
2002-04-26 17:38:01 +00:00
|
|
|
outMask |= ShiftMask;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
|
|
|
if (inMask & KeyModifierControl) {
|
2002-04-26 17:38:01 +00:00
|
|
|
outMask |= ControlMask;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
|
|
|
if (inMask & KeyModifierAlt) {
|
2002-04-26 17:38:01 +00:00
|
|
|
outMask |= Mod1Mask;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
|
|
|
if (inMask & KeyModifierMeta) {
|
2002-04-26 17:38:01 +00:00
|
|
|
outMask |= Mod4Mask;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
|
|
|
if (inMask & KeyModifierCapsLock) {
|
2002-04-30 17:48:11 +00:00
|
|
|
outMask |= m_capsLockMask;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
|
|
|
if (inMask & KeyModifierNumLock) {
|
2002-04-30 17:48:11 +00:00
|
|
|
outMask |= m_numLockMask;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
|
|
|
if (inMask & KeyModifierScrollLock) {
|
2002-04-30 17:48:11 +00:00
|
|
|
outMask |= m_scrollLockMask;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
return outMask;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::updateKeys(Display* display)
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
|
|
|
// ask server which keys are pressed
|
|
|
|
char keys[32];
|
|
|
|
XQueryKeymap(display, keys);
|
|
|
|
|
|
|
|
// transfer to our state
|
|
|
|
for (unsigned int i = 0, j = 0; i < 32; j += 8, ++i) {
|
|
|
|
m_keys[j + 0] = ((keys[i] & 0x01) != 0);
|
|
|
|
m_keys[j + 1] = ((keys[i] & 0x02) != 0);
|
|
|
|
m_keys[j + 2] = ((keys[i] & 0x04) != 0);
|
|
|
|
m_keys[j + 3] = ((keys[i] & 0x08) != 0);
|
|
|
|
m_keys[j + 4] = ((keys[i] & 0x10) != 0);
|
|
|
|
m_keys[j + 5] = ((keys[i] & 0x20) != 0);
|
|
|
|
m_keys[j + 6] = ((keys[i] & 0x40) != 0);
|
|
|
|
m_keys[j + 7] = ((keys[i] & 0x80) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::updateModifiers(Display* display)
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
2002-05-27 18:28:06 +00:00
|
|
|
// query the pointer to get the keyboard state
|
|
|
|
Window root, window;
|
|
|
|
int xRoot, yRoot, xWindow, yWindow;
|
|
|
|
unsigned int state;
|
|
|
|
if (!XQueryPointer(display, m_window, &root, &window,
|
|
|
|
&xRoot, &yRoot, &xWindow, &yWindow, &state)) {
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
|
2002-04-26 17:38:01 +00:00
|
|
|
// update active modifier mask
|
|
|
|
m_mask = 0;
|
|
|
|
for (unsigned int i = 0; i < 8; ++i) {
|
|
|
|
const unsigned int bit = (1 << i);
|
|
|
|
if ((bit & m_toggleModifierMask) == 0) {
|
|
|
|
for (unsigned int j = 0; j < m_keysPerModifier; ++j) {
|
|
|
|
if (m_keys[m_modifierToKeycode[i * m_keysPerModifier + j]])
|
|
|
|
m_mask |= bit;
|
|
|
|
}
|
|
|
|
}
|
2002-05-27 18:28:06 +00:00
|
|
|
else if ((bit & state) != 0) {
|
|
|
|
// toggle is on
|
|
|
|
m_mask |= bit;
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::updateKeycodeMap(Display* display)
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
|
|
|
// get the number of keycodes
|
|
|
|
int minKeycode, maxKeycode;
|
|
|
|
XDisplayKeycodes(display, &minKeycode, &maxKeycode);
|
|
|
|
const int numKeycodes = maxKeycode - minKeycode + 1;
|
|
|
|
|
|
|
|
// get the keyboard mapping for all keys
|
|
|
|
int keysymsPerKeycode;
|
|
|
|
KeySym* keysyms = XGetKeyboardMapping(display,
|
|
|
|
minKeycode, numKeycodes,
|
|
|
|
&keysymsPerKeycode);
|
|
|
|
|
|
|
|
// restrict keysyms per keycode to 2 because, frankly, i have no
|
|
|
|
// idea how/what modifiers are used to access keysyms beyond the
|
|
|
|
// first 2.
|
|
|
|
int numKeysyms = 2; // keysymsPerKeycode
|
|
|
|
|
|
|
|
// initialize
|
|
|
|
KeyCodeMask entry;
|
|
|
|
m_keycodeMap.clear();
|
|
|
|
|
|
|
|
// insert keys
|
|
|
|
for (int i = 0; i < numKeycodes; ++i) {
|
|
|
|
// how many keysyms for this keycode?
|
|
|
|
int n;
|
|
|
|
for (n = 0; n < numKeysyms; ++n) {
|
|
|
|
if (keysyms[i * keysymsPerKeycode + n] == NoSymbol) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// move to next keycode if there are no keysyms
|
|
|
|
if (n == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the mask of modifiers that this keycode uses
|
2002-05-03 11:26:44 +00:00
|
|
|
entry.m_keyMaskMask = (n == 1) ? 0 : (ShiftMask | LockMask);
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// add entries for this keycode
|
2002-05-03 11:26:44 +00:00
|
|
|
entry.m_keycode = static_cast<KeyCode>(minKeycode + i);
|
2002-04-26 17:38:01 +00:00
|
|
|
for (int j = 0; j < numKeysyms; ++j) {
|
2002-05-03 11:26:44 +00:00
|
|
|
entry.m_keyMask = (j == 0) ? 0 : ShiftMask;
|
2002-04-26 17:38:01 +00:00
|
|
|
m_keycodeMap.insert(std::make_pair(keysyms[i *
|
|
|
|
keysymsPerKeycode + j], entry));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
XFree(keysyms);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::updateModifierMap(Display* display)
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
|
|
|
// get modifier map from server
|
|
|
|
XModifierKeymap* keymap = XGetModifierMapping(display);
|
|
|
|
|
|
|
|
// initialize
|
|
|
|
m_modifierMask = 0;
|
|
|
|
m_toggleModifierMask = 0;
|
|
|
|
m_numLockMask = 0;
|
|
|
|
m_capsLockMask = 0;
|
2002-04-30 17:48:11 +00:00
|
|
|
m_scrollLockMask = 0;
|
2002-04-26 17:38:01 +00:00
|
|
|
m_keysPerModifier = keymap->max_keypermod;
|
|
|
|
m_modifierToKeycode.clear();
|
|
|
|
m_modifierToKeycode.resize(8 * m_keysPerModifier);
|
|
|
|
|
|
|
|
// set keycodes and masks
|
|
|
|
for (unsigned int i = 0; i < 8; ++i) {
|
|
|
|
const unsigned int bit = (1 << i);
|
|
|
|
for (unsigned int j = 0; j < m_keysPerModifier; ++j) {
|
|
|
|
KeyCode keycode = keymap->modifiermap[i * m_keysPerModifier + j];
|
|
|
|
|
|
|
|
// save in modifier to keycode
|
|
|
|
m_modifierToKeycode[i * m_keysPerModifier + j] = keycode;
|
|
|
|
|
|
|
|
// save in keycode to modifier
|
|
|
|
m_keycodeToModifier.insert(std::make_pair(keycode, i));
|
|
|
|
|
|
|
|
// modifier is enabled if keycode isn't 0
|
2002-06-10 22:06:45 +00:00
|
|
|
if (keycode != 0) {
|
2002-04-26 17:38:01 +00:00
|
|
|
m_modifierMask |= bit;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
|
|
|
|
// modifier is a toggle if the keysym is a toggle modifier
|
|
|
|
const KeySym keysym = XKeycodeToKeysym(display, keycode, 0);
|
|
|
|
if (isToggleKeysym(keysym)) {
|
|
|
|
m_toggleModifierMask |= bit;
|
|
|
|
|
|
|
|
// note num/caps-lock
|
2002-04-30 17:48:11 +00:00
|
|
|
if (keysym == XK_Num_Lock) {
|
2002-04-26 17:38:01 +00:00
|
|
|
m_numLockMask |= bit;
|
2002-04-30 17:48:11 +00:00
|
|
|
}
|
|
|
|
else if (keysym == XK_Caps_Lock) {
|
2002-04-26 17:38:01 +00:00
|
|
|
m_capsLockMask |= bit;
|
2002-04-30 17:48:11 +00:00
|
|
|
}
|
|
|
|
else if (keysym == XK_Scroll_Lock) {
|
|
|
|
m_scrollLockMask |= bit;
|
|
|
|
}
|
2002-04-26 17:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFreeModifiermap(keymap);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::toggleKey(Display* display,
|
|
|
|
KeySym keysym, unsigned int mask)
|
2002-04-30 17:48:11 +00:00
|
|
|
{
|
|
|
|
// lookup the keycode
|
|
|
|
KeyCodeMap::const_iterator index = m_keycodeMap.find(keysym);
|
2002-06-10 22:06:45 +00:00
|
|
|
if (index == m_keycodeMap.end()) {
|
2002-04-30 17:48:11 +00:00
|
|
|
return;
|
2002-06-10 22:06:45 +00:00
|
|
|
}
|
2002-05-03 11:26:44 +00:00
|
|
|
KeyCode keycode = index->second.m_keycode;
|
2002-04-30 17:48:11 +00:00
|
|
|
|
|
|
|
// toggle the key
|
2002-05-04 18:31:54 +00:00
|
|
|
if ((keysym == XK_Caps_Lock && m_capsLockHalfDuplex) ||
|
|
|
|
(keysym == XK_Num_Lock && m_numLockHalfDuplex)) {
|
2002-04-30 17:48:11 +00:00
|
|
|
// "half-duplex" toggle
|
|
|
|
XTestFakeKeyEvent(display, keycode, (m_mask & mask) == 0, CurrentTime);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// normal toggle
|
|
|
|
XTestFakeKeyEvent(display, keycode, True, CurrentTime);
|
|
|
|
XTestFakeKeyEvent(display, keycode, False, CurrentTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// toggle shadow state
|
|
|
|
m_mask ^= mask;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CXWindowsSecondaryScreen::isToggleKeysym(KeySym key)
|
2002-04-26 17:38:01 +00:00
|
|
|
{
|
|
|
|
switch (key) {
|
|
|
|
case XK_Caps_Lock:
|
|
|
|
case XK_Shift_Lock:
|
|
|
|
case XK_Num_Lock:
|
|
|
|
case XK_Scroll_Lock:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|