From de0b3532320e088440bd7607f7d5d7e8fc720d94 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 14 Jul 2014 13:41:36 +0200 Subject: [PATCH] Make InputDevice into a singleton Xorg input devices are global so it doesn't make sense that we have one InputDevice object per XserverDesktop. --- unix/xserver/hw/vnc/Input.cc | 7 +++++- unix/xserver/hw/vnc/Input.h | 32 ++++++++++++++++++--------- unix/xserver/hw/vnc/XserverDesktop.cc | 17 ++++++-------- unix/xserver/hw/vnc/XserverDesktop.h | 1 - 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/unix/xserver/hw/vnc/Input.cc b/unix/xserver/hw/vnc/Input.cc index 5497d97e..1d875746 100644 --- a/unix/xserver/hw/vnc/Input.cc +++ b/unix/xserver/hw/vnc/Input.cc @@ -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 diff --git a/unix/xserver/hw/vnc/Input.h b/unix/xserver/hw/vnc/Input.h index 8a3dd4f2..029b80d1 100644 --- a/unix/xserver/hw/vnc/Input.h +++ b/unix/xserver/hw/vnc/Input.h @@ -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 diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index cd76d068..8f426cce 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -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); } diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index ca6e8af9..20c89dc5 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -133,7 +133,6 @@ private: #endif ScreenPtr pScreen; - InputDevice *inputDevice; rfb::VNCServerST* server; rfb::HTTPServer* httpServer; network::TcpListener* listener; -- 2.39.5