2001-10-08 23:24:46 +04:00
|
|
|
#include "CXWindowsSecondaryScreen.h"
|
|
|
|
#include "CClient.h"
|
|
|
|
#include "CThread.h"
|
2001-10-24 02:41:46 +04:00
|
|
|
#include "CLog.h"
|
2001-10-08 23:24:46 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/extensions/XTest.h>
|
|
|
|
|
|
|
|
//
|
|
|
|
// CXWindowsSecondaryScreen
|
|
|
|
//
|
|
|
|
|
|
|
|
CXWindowsSecondaryScreen::CXWindowsSecondaryScreen() :
|
|
|
|
m_client(NULL),
|
2001-11-12 00:15:30 +03:00
|
|
|
m_window(None)
|
2001-10-08 23:24:46 +04:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
CXWindowsSecondaryScreen::~CXWindowsSecondaryScreen()
|
|
|
|
{
|
2001-11-25 21:32:41 +03:00
|
|
|
assert(m_window == None);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
2001-11-19 03:33:36 +03:00
|
|
|
void CXWindowsSecondaryScreen::run()
|
|
|
|
{
|
|
|
|
assert(m_window != None);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
// wait for and get the next event
|
|
|
|
XEvent xevent;
|
|
|
|
if (!getEvent(&xevent)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle event
|
|
|
|
switch (xevent.type) {
|
|
|
|
case LeaveNotify: {
|
|
|
|
// mouse moved out of hider window somehow. hide the window.
|
|
|
|
assert(m_window != None);
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XUnmapWindow(display, m_window);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SelectionClear:
|
2001-11-25 21:32:41 +03: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-26 01:20:41 +03:00
|
|
|
if (lostClipboard(xevent.xselectionclear.selection,
|
|
|
|
xevent.xselectionclear.time)) {
|
|
|
|
m_client->onClipboardChanged();
|
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SelectionNotify:
|
2001-11-25 21:32:41 +03: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 03:33:36 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SelectionRequest:
|
2001-11-25 21:32:41 +03: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);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PropertyNotify:
|
|
|
|
// 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 03:33:36 +03:00
|
|
|
break;
|
2002-04-25 14:43:53 +04:00
|
|
|
|
|
|
|
case DestroyNotify:
|
|
|
|
// looks like one of the windows that requested a clipboard
|
|
|
|
// transfer has gone bye-bye.
|
|
|
|
destroyClipboardRequest(xevent.xdestroywindow.window);
|
|
|
|
break;
|
2001-11-19 03:33:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsSecondaryScreen::stop()
|
|
|
|
{
|
|
|
|
doStop();
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:24:46 +04:00
|
|
|
void CXWindowsSecondaryScreen::open(CClient* client)
|
|
|
|
{
|
|
|
|
assert(m_client == NULL);
|
|
|
|
assert(client != NULL);
|
|
|
|
|
|
|
|
// set the client
|
|
|
|
m_client = client;
|
|
|
|
|
|
|
|
// open the display
|
2001-11-12 00:15:30 +03:00
|
|
|
openDisplay();
|
2001-10-08 23:24:46 +04:00
|
|
|
|
|
|
|
// verify the availability of the XTest extension
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-08 23:24:46 +04:00
|
|
|
int majorOpcode, firstEvent, firstError;
|
2001-11-12 00:15:30 +03:00
|
|
|
if (!XQueryExtension(display, XTestExtensionName,
|
2001-10-08 23:24:46 +04:00
|
|
|
&majorOpcode, &firstEvent, &firstError))
|
|
|
|
throw int(6); // FIXME -- make exception for this
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsSecondaryScreen::close()
|
|
|
|
{
|
|
|
|
assert(m_client != NULL);
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-10-08 23:24:46 +04:00
|
|
|
// close the display
|
2001-11-12 00:15:30 +03:00
|
|
|
closeDisplay();
|
|
|
|
|
|
|
|
// done with client
|
|
|
|
m_client = NULL;
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsSecondaryScreen::enter(SInt32 x, SInt32 y)
|
|
|
|
{
|
2001-10-24 02:41:46 +04:00
|
|
|
assert(m_window != None);
|
2001-10-08 23:24:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-25 02:33:24 +04:00
|
|
|
|
2001-10-08 23:24:46 +04:00
|
|
|
// warp to requested location
|
2001-11-12 00:15:30 +03:00
|
|
|
XTestFakeMotionEvent(display, getScreen(), x, y, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 23:24:46 +04:00
|
|
|
|
|
|
|
// show cursor
|
2001-11-12 00:15:30 +03:00
|
|
|
XUnmapWindow(display, m_window);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsSecondaryScreen::leave()
|
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
|
|
|
leaveNoLock(display);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 01:40:29 +04:00
|
|
|
void CXWindowsSecondaryScreen::keyDown(
|
2001-10-08 23:24:46 +04:00
|
|
|
KeyID key, KeyModifierMask mask)
|
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeKeyEvent(display, mapKey(key, mask), True, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 01:40:29 +04:00
|
|
|
void CXWindowsSecondaryScreen::keyRepeat(
|
2001-10-08 23:24:46 +04:00
|
|
|
KeyID, KeyModifierMask, SInt32)
|
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-08 23:24:46 +04:00
|
|
|
// FIXME
|
|
|
|
}
|
|
|
|
|
2001-10-26 01:40:29 +04:00
|
|
|
void CXWindowsSecondaryScreen::keyUp(
|
2001-10-08 23:24:46 +04:00
|
|
|
KeyID key, KeyModifierMask mask)
|
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeKeyEvent(display, mapKey(key, mask), False, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 01:40:29 +04:00
|
|
|
void CXWindowsSecondaryScreen::mouseDown(ButtonID button)
|
2001-10-08 23:24:46 +04:00
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeButtonEvent(display, mapButton(button), True, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 01:40:29 +04:00
|
|
|
void CXWindowsSecondaryScreen::mouseUp(ButtonID button)
|
2001-10-08 23:24:46 +04:00
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeButtonEvent(display, mapButton(button), False, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 01:40:29 +04:00
|
|
|
void CXWindowsSecondaryScreen::mouseMove(SInt32 x, SInt32 y)
|
2001-10-08 23:24:46 +04:00
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestFakeMotionEvent(display, getScreen(), x, y, CurrentTime);
|
|
|
|
XSync(display, False);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 01:40:29 +04:00
|
|
|
void CXWindowsSecondaryScreen::mouseWheel(SInt32)
|
2001-10-08 23:24:46 +04:00
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-08 23:24:46 +04:00
|
|
|
// FIXME
|
|
|
|
}
|
|
|
|
|
2001-11-25 21:32:41 +03:00
|
|
|
void CXWindowsSecondaryScreen::setClipboard(
|
|
|
|
const IClipboard* clipboard)
|
|
|
|
{
|
|
|
|
// FIXME -- don't use CurrentTime
|
|
|
|
setDisplayClipboard(clipboard, m_window, CurrentTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXWindowsSecondaryScreen::grabClipboard()
|
|
|
|
{
|
|
|
|
// FIXME -- don't use CurrentTime
|
|
|
|
setDisplayClipboard(NULL, m_window, CurrentTime);
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:24:46 +04:00
|
|
|
void CXWindowsSecondaryScreen::getSize(
|
|
|
|
SInt32* width, SInt32* height) const
|
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
getScreenSize(width, height);
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SInt32 CXWindowsSecondaryScreen::getJumpZoneSize() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-11-25 21:32:41 +03:00
|
|
|
void CXWindowsSecondaryScreen::getClipboard(
|
|
|
|
IClipboard* clipboard) const
|
|
|
|
{
|
|
|
|
// FIXME -- don't use CurrentTime
|
|
|
|
getDisplayClipboard(clipboard, m_window, CurrentTime);
|
|
|
|
}
|
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
void CXWindowsSecondaryScreen::onOpenDisplay()
|
2001-10-24 02:41:46 +04:00
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
assert(m_window == None);
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03: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;
|
|
|
|
attr.event_mask = LeaveWindowMask;
|
|
|
|
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);
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
// become impervious to server grabs
|
|
|
|
XTestGrabControl(display, True);
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
// hide the cursor
|
|
|
|
leaveNoLock(display);
|
|
|
|
}
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
void CXWindowsSecondaryScreen::onCloseDisplay()
|
|
|
|
{
|
|
|
|
assert(m_window != None);
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
// no longer impervious to server grabs
|
|
|
|
CDisplayLock display(this);
|
|
|
|
XTestGrabControl(display, False);
|
2001-10-24 02:41:46 +04:00
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
// destroy window
|
|
|
|
XDestroyWindow(display, m_window);
|
|
|
|
m_window = None;
|
2001-10-24 02:41:46 +04:00
|
|
|
}
|
|
|
|
|
2001-11-12 00:15:30 +03:00
|
|
|
void CXWindowsSecondaryScreen::leaveNoLock(Display* display)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:24:46 +04:00
|
|
|
KeyCode CXWindowsSecondaryScreen::mapKey(
|
|
|
|
KeyID id, KeyModifierMask /*mask*/) const
|
|
|
|
{
|
2001-11-12 00:15:30 +03:00
|
|
|
CDisplayLock display(this);
|
2001-10-08 23:24:46 +04:00
|
|
|
// FIXME -- use mask
|
2001-11-12 00:15:30 +03:00
|
|
|
return XKeysymToKeycode(display, static_cast<KeySym>(id));
|
2001-10-08 23:24:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CXWindowsSecondaryScreen::mapButton(
|
|
|
|
ButtonID id) const
|
|
|
|
{
|
|
|
|
// FIXME -- should use button mapping?
|
|
|
|
return static_cast<unsigned int>(id);
|
|
|
|
}
|