Browse Source

Make InputDevice into a singleton

Xorg input devices are global so it doesn't make sense that we
have one InputDevice object per XserverDesktop.
tags/v1.3.90
Pierre Ossman 10 years ago
parent
commit
de0b353232

+ 6
- 1
unix/xserver/hw/vnc/Input.cc View File

@@ -68,6 +68,9 @@ rfb::BoolParameter avoidShiftNumLock("AvoidShiftNumLock", "Avoid fake Shift pres

#define BUTTONS 7

class InputDevice *vncInputDevice;
InputDevice InputDevice::singleton;

/* Event queue is shared between all devices. */
#if XORG == 15
static xEvent *eventq = NULL;
@@ -117,10 +120,12 @@ static void enqueueEvents(DeviceIntPtr dev, int n)
#endif /* XORG < 111 */

InputDevice::InputDevice()
: initialized(false), oldButtonMask(0)
: oldButtonMask(0)
{
int i;

vncInputDevice = this;

#if XORG < 111
initEventq();
#endif

+ 21
- 11
unix/xserver/hw/vnc/Input.h View File

@@ -40,12 +40,16 @@ extern "C" {

#include "xorg-version.h"

/* Represents input device (keyboard + pointer) */
/*
* Represents input device (keyboard + pointer)
*
* Is a singleton as input devices are global in the X server so
* we do not have one per desktop (i.e. per screen).
*/
extern class InputDevice *vncInputDevice;

class InputDevice {
public:
/* Create new InputDevice instance */
InputDevice();

/*
* Press or release buttons. Relationship between buttonMask and
* buttons is specified in RFB protocol.
@@ -63,17 +67,20 @@ public:
void KeyboardRelease(rdr::U32 keysym) { keyEvent(keysym, false); }

/*
* Init input device. This cannot be done in the constructor
* because constructor is called during X server extensions
* initialization. Devices must be initialized after core
* pointer/keyboard initialization which is actually after extesions
* initialization. Check InitExtensions(), InitCoreDevices() and
* InitInput() calls in dix/main.c. Instead it is called from
* XserverDesktop at an appropriate time.
* Init input device.
* This has to be called after core pointer/keyboard
* initialization which unfortunately is after extesions
* initialization (which means we cannot call it in
* vncExtensionInit(). Check InitExtensions(),
* InitCoreDevices() and InitInput() calls in dix/main.c.
* Instead we call it from XserverDesktop at an appropriate
* time.
*/
void InitInputDevice(void);

private:
InputDevice();

void keyEvent(rdr::U32 keysym, bool down);

/* Backend dependent functions below here */
@@ -117,6 +124,9 @@ private:
rfb::Point cursorPos;

KeySym pressedKeys[256];

private:
static InputDevice singleton;
};

#endif

+ 7
- 10
unix/xserver/hw/vnc/XserverDesktop.cc View File

@@ -158,15 +158,12 @@ XserverDesktop::XserverDesktop(ScreenPtr pScreen_,

if (httpListener)
httpServer = new FileHTTPServer(this);

inputDevice = new InputDevice(server);
}

XserverDesktop::~XserverDesktop()
{
if (!directFbptr)
delete [] data;
delete inputDevice;
delete httpServer;
delete server;
}
@@ -581,7 +578,7 @@ void XserverDesktop::blockHandler(fd_set* fds, OSTimePtr timeout)
// so we abuse the fact that this routine will be called first thing
// once the dix is done initialising.
// [1] Technically Xvnc has InitInput(), but libvnc.so has nothing.
inputDevice->InitInputDevice();
vncInputDevice->InitInputDevice();

try {
int nextTimeout;
@@ -690,8 +687,8 @@ void XserverDesktop::wakeupHandler(fd_set* fds, int nfds)
}

// We are responsible for propagating mouse movement between clients
if (!oldCursorPos.equals(inputDevice->getPointerPos())) {
oldCursorPos = inputDevice->getPointerPos();
if (!oldCursorPos.equals(vncInputDevice->getPointerPos())) {
oldCursorPos = vncInputDevice->getPointerPos();
server->setCursorPos(oldCursorPos);
}
}
@@ -820,8 +817,8 @@ void XserverDesktop::approveConnection(void* opaqueId, bool accept,

void XserverDesktop::pointerEvent(const Point& pos, int buttonMask)
{
inputDevice->PointerMove(pos);
inputDevice->PointerButtonAction(buttonMask);
vncInputDevice->PointerMove(pos);
vncInputDevice->PointerButtonAction(buttonMask);
}

void XserverDesktop::clientCutText(const char* str, int len)
@@ -1138,7 +1135,7 @@ void XserverDesktop::lookup(int index, int* r, int* g, int* b)
void XserverDesktop::keyEvent(rdr::U32 keysym, bool down)
{
if (down)
inputDevice->KeyboardPress(keysym);
vncInputDevice->KeyboardPress(keysym);
else
inputDevice->KeyboardRelease(keysym);
vncInputDevice->KeyboardRelease(keysym);
}

+ 0
- 1
unix/xserver/hw/vnc/XserverDesktop.h View File

@@ -133,7 +133,6 @@ private:
#endif

ScreenPtr pScreen;
InputDevice *inputDevice;
rfb::VNCServerST* server;
rfb::HTTPServer* httpServer;
network::TcpListener* listener;

Loading…
Cancel
Save