Blame SOURCES/tigervnc-inputreset.patch

288618
diff --git a/unix/xserver/hw/vnc/Input.cc b/unix/xserver/hw/vnc/Input.cc
288618
index 43c3ac3..4112fee 100644
288618
--- a/unix/xserver/hw/vnc/Input.cc
288618
+++ b/unix/xserver/hw/vnc/Input.cc
288618
@@ -68,6 +68,9 @@ rfb::BoolParameter avoidShiftNumLock("AvoidShiftNumLock", "Avoid fake Shift pres
288618
 
288618
 #define BUTTONS 7
288618
 
288618
+class InputDevice *vncInputDevice;
288618
+InputDevice InputDevice::singleton;
288618
+
288618
 /* Event queue is shared between all devices. */
288618
 #if XORG == 15
288618
 static xEvent *eventq = NULL;
288618
@@ -116,11 +119,12 @@ static void enqueueEvents(DeviceIntPtr dev, int n)
288618
 }
288618
 #endif /* XORG < 111 */
288618
 
288618
-InputDevice::InputDevice(rfb::VNCServerST *_server)
288618
-	: server(_server), initialized(false), oldButtonMask(0)
288618
+InputDevice::InputDevice()
288618
+	: oldButtonMask(0)
288618
 {
288618
 	int i;
288618
 
288618
+        vncInputDevice = this;
288618
 #if XORG < 111
288618
 	initEventq();
288618
 #endif
288618
@@ -195,7 +199,7 @@ void InputDevice::PointerMove(const rfb::Point &pos)
288618
 	cursorPos = pos;
288618
 }
288618
 
288618
-void InputDevice::PointerSync(void)
288618
+const rfb::Point &InputDevice::getPointerPos(void)
288618
 {
288618
 	if (pointerDev) {
288618
 		int x, y;
288618
@@ -205,14 +209,10 @@ void InputDevice::PointerSync(void)
288618
 		cursorPos.y = y;
288618
 	}
288618
 
288618
-	if (cursorPos.equals(oldCursorPos))
288618
-		return;
288618
-
288618
-	oldCursorPos = cursorPos;
288618
-	server->setCursorPos(cursorPos);
288618
+        return cursorPos;
288618
 }
288618
 
288618
-static int pointerProc(DeviceIntPtr pDevice, int onoff)
288618
+int InputDevice::pointerProc(DeviceIntPtr pDevice, int onoff)
288618
 {
288618
 	BYTE map[BUTTONS + 1];
288618
 	DevicePtr pDev = (DevicePtr)pDevice;
288618
@@ -237,6 +237,8 @@ static int pointerProc(DeviceIntPtr pDevice, int onoff)
288618
 		btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
288618
 		btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
288618
 		btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
288618
+		btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
288618
+		btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
288618
 
288618
 		axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
288618
 		axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
288618
@@ -261,10 +263,9 @@ static int pointerProc(DeviceIntPtr pDevice, int onoff)
288618
 	case DEVICE_OFF:
288618
 		pDev->on = FALSE;
288618
 		break;
288618
-#if 0
288618
 	case DEVICE_CLOSE:
288618
+		singleton.pointerDev = NULL;
288618
 		break;
288618
-#endif
288618
 	}
288618
 
288618
 	return Success;
288618
@@ -277,9 +278,7 @@ static void keyboardBell(int percent, DeviceIntPtr device, void * ctrl,
288618
 		vncBell();
288618
 }
288618
 
288618
-extern void GetInitKeyboardMap(KeySymsPtr keysyms, CARD8 *modmap);
288618
-
288618
-static int keyboardProc(DeviceIntPtr pDevice, int onoff)
288618
+int InputDevice::keyboardProc(DeviceIntPtr pDevice, int onoff)
288618
 {
288618
 #if XORG < 17
288618
 	KeySymsRec keySyms;
288618
@@ -306,6 +305,9 @@ static int keyboardProc(DeviceIntPtr pDevice, int onoff)
288618
 	case DEVICE_OFF:
288618
 		pDev->on = FALSE;
288618
 		break;
288618
+	case DEVICE_CLOSE:
288618
+		singleton.keyboardDev = NULL;
288618
+		break;
288618
 	}
288618
 
288618
 	return Success;
288618
@@ -313,11 +315,9 @@ static int keyboardProc(DeviceIntPtr pDevice, int onoff)
288618
 
288618
 void InputDevice::InitInputDevice(void)
288618
 {
288618
-	if (initialized)
288618
+	if ((pointerDev != NULL) || (keyboardDev != NULL))
288618
 		return;
288618
 
288618
-	initialized = true;
288618
-
288618
 #if XORG < 17
288618
 	pointerDev = AddInputDevice(
288618
 #if XORG >= 16
288618
diff --git a/unix/xserver/hw/vnc/Input.h b/unix/xserver/hw/vnc/Input.h
288618
index e893049..f58242d 100644
288618
--- a/unix/xserver/hw/vnc/Input.h
288618
+++ b/unix/xserver/hw/vnc/Input.h
288618
@@ -29,20 +29,26 @@
288618
 
288618
 #include <list>
288618
 
288618
-#include <rfb/VNCServerST.h>
288618
+#include <rdr/types.h>
288618
+#include <rfb/Rect.h>
288618
 
288618
 extern "C" {
288618
 #include "input.h"
288618
+/* The Xorg headers define macros that wreak havoc with STL */
288618
+#undef max
288618
 };
288618
 
288618
 #include "xorg-version.h"
288618
 
288618
-/* Represents input device (keyboard + pointer) */
288618
+/*
288618
+ * Represents input device (keyboard + pointer)
288618
+ *
288618
+ * Is a singleton as input devices are global in the X server so
288618
+ * we do not have one per desktop (i.e. per screen).
288618
+ */
288618
+extern class InputDevice *vncInputDevice;
288618
 class InputDevice {
288618
 public:
288618
-	/* Create new InputDevice instance */
288618
-	InputDevice(rfb::VNCServerST *_server);
288618
-
288618
 	/*
288618
 	 * Press or release buttons. Relationship between buttonMask and
288618
 	 * buttons is specified in RFB protocol.
288618
@@ -52,27 +58,28 @@ public:
288618
 	/* Move pointer to target location (point coords are absolute). */
288618
 	void PointerMove(const rfb::Point &point);
288618
 
288618
-	/*
288618
-	 * Send pointer position to clients. If not called then Move() calls
288618
-	 * won't be visible to VNC clients.
288618
-	 */
288618
-	void PointerSync(void);
288618
+	/* Get current known location of the pointer */
288618
+	const rfb::Point &getPointerPos(void);
288618
 
288618
+	/* Press or release one or more keys to get the given symbol */
288618
 	void KeyboardPress(rdr::U32 keysym) { keyEvent(keysym, true); }
288618
 	void KeyboardRelease(rdr::U32 keysym) { keyEvent(keysym, false); }
288618
 
288618
 	/*
288618
-	 * Init input device. This cannot be done in the constructor
288618
-	 * because constructor is called during X server extensions
288618
-	 * initialization. Devices must be initialized after core
288618
-	 * pointer/keyboard initialization which is actually after extesions
288618
-	 * initialization. Check InitExtensions(), InitCoreDevices() and
288618
-	 * InitInput() calls in dix/main.c. Instead it is called from
288618
-	 * XserverDesktop at an appropriate time.
288618
+	 * Init input device.
288618
+	 * This has to be called after core pointer/keyboard
288618
+	 * initialization which unfortunately is after extesions
288618
+	 * initialization (which means we cannot call it in
288618
+	 * vncExtensionInit(). Check InitExtensions(),
288618
+	 * InitCoreDevices() and InitInput() calls in dix/main.c.
288618
+	 * Instead we call it from XserverDesktop at an appropriate
288618
+	 * time.
288618
 	 */
288618
 	void InitInputDevice(void);
288618
 
288618
 private:
288618
+	InputDevice();
288618
+
288618
 	void keyEvent(rdr::U32 keysym, bool down);
288618
 
288618
 	/* Backend dependent functions below here */
288618
@@ -96,22 +103,26 @@ private:
288618
 	KeyCode addKeysym(KeySym keysym, unsigned state);
288618
 
288618
 private:
288618
+	static int pointerProc(DeviceIntPtr pDevice, int onoff);
288618
+	static int keyboardProc(DeviceIntPtr pDevice, int onoff);
288618
+
288618
 #if XORG >= 17
288618
 	static void vncXkbProcessDeviceEvent(int screenNum,
288618
 	                                     InternalEvent *event,
288618
 	                                     DeviceIntPtr dev);
288618
+#else
288618
+	static void GetInitKeyboardMap(KeySymsPtr keysyms, CARD8 *modmap);
288618
 #endif
288618
 
288618
 private:
288618
-	rfb::VNCServerST *server;
288618
-	bool initialized;
288618
 	DeviceIntPtr keyboardDev;
288618
 	DeviceIntPtr pointerDev;
288618
 
288618
 	int oldButtonMask;
288618
-	rfb::Point cursorPos, oldCursorPos;
288618
-
288618
+	rfb::Point cursorPos;
288618
 	KeySym pressedKeys[256];
288618
+private:
288618
+	static InputDevice singleton;
288618
 };
288618
 
288618
 #endif
288618
diff --git a/unix/xserver/hw/vnc/InputCore.cc b/unix/xserver/hw/vnc/InputCore.cc
288618
index a880ca0..b565c73 100644
288618
--- a/unix/xserver/hw/vnc/InputCore.cc
288618
+++ b/unix/xserver/hw/vnc/InputCore.cc
288618
@@ -174,7 +174,7 @@ KeySym keyboardMap[MAP_LEN * KEYSYMS_PER_KEY] = {
288618
 	XK_Menu, NoSymbol,
288618
 };
288618
 
288618
-void GetInitKeyboardMap(KeySymsPtr keysyms, CARD8 *modmap)
288618
+void InputDevice::GetInitKeyboardMap(KeySymsPtr keysyms, CARD8 *modmap)
288618
 {
288618
 	int i;
288618
 
288618
diff --git a/unix/xserver/hw/vnc/InputXKB.cc b/unix/xserver/hw/vnc/InputXKB.cc
288618
index ed93afc..92288aa 100644
288618
--- a/unix/xserver/hw/vnc/InputXKB.cc
288618
+++ b/unix/xserver/hw/vnc/InputXKB.cc
288618
@@ -42,18 +42,6 @@ extern "C" {
288618
 #undef class
288618
 }
288618
 
288618
-#if XORG < 19
288618
-static int vncXkbScreenPrivateKeyIndex;
288618
-static DevPrivateKey vncXkbScreenPrivateKey = &vncXkbScreenPrivateKeyIndex;
288618
-#else
288618
-static DevPrivateKeyRec vncXkbPrivateKeyRec;
288618
-#define vncXkbScreenPrivateKey (&vncXkbPrivateKeyRec)
288618
-#endif
288618
-
288618
-#define vncXkbScreenPrivate(pScreen) \
288618
-	(*(InputDevice**) dixLookupPrivate(&(pScreen)->devPrivates, \
288618
-	                                   vncXkbScreenPrivateKey))
288618
-
288618
 #ifndef KEYBOARD_OR_FLOAT
288618
 #define KEYBOARD_OR_FLOAT MASTER_KEYBOARD
288618
 #endif
288618
@@ -209,18 +197,6 @@ static unsigned XkbKeyEffectiveGroup(XkbDescPtr xkb, KeyCode key, unsigned int m
288618
 
288618
 void InputDevice::PrepareInputDevices(void)
288618
 {
288618
-#if XORG < 19
288618
-	if (!dixRequestPrivate(vncXkbScreenPrivateKey, sizeof(InputDevice*)))
288618
-		FatalError("Failed to register TigerVNC XKB screen key\n");
288618
-#else
288618
-	if (!dixRegisterPrivateKey(vncXkbScreenPrivateKey, PRIVATE_SCREEN,
288618
-	                           sizeof(InputDevice*)))
288618
-		FatalError("Failed to register TigerVNC XKB screen key\n");
288618
-#endif
288618
-
288618
-	for (int scr = 0; scr < screenInfo.numScreens; scr++)
288618
-		vncXkbScreenPrivate(screenInfo.screens[scr]) = this;
288618
-
288618
 	/*
288618
 	 * Not ideal since these callbacks do not stack, but it's the only
288618
 	 * decent way we can reliably catch events for both the slave and
288618
@@ -636,10 +612,9 @@ void InputDevice::vncXkbProcessDeviceEvent(int screenNum,
288618
                                            InternalEvent *event,
288618
                                            DeviceIntPtr dev)
288618
 {
288618
-	InputDevice *self = vncXkbScreenPrivate(screenInfo.screens[screenNum]);
288618
 	unsigned int backupctrls;
288618
 
288618
-	if (event->device_event.sourceid == self->keyboardDev->id) {
288618
+	if (event->device_event.sourceid == singleton.keyboardDev->id) {
288618
 		XkbControlsPtr ctrls;
288618
 
288618
 		/*
288618
@@ -661,7 +636,7 @@ void InputDevice::vncXkbProcessDeviceEvent(int screenNum,
288618
 
288618
 	dev->c_public.processInputProc(event, dev);
288618
 
288618
-	if (event->device_event.sourceid == self->keyboardDev->id) {
288618
+	if (event->device_event.sourceid == singleton.keyboardDev->id) {
288618
 		XkbControlsPtr ctrls;
288618
 
288618
 		ctrls = dev->key->xkbInfo->desc->ctrls;
288618
diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc
288618
index fc0646d..05169b0 100644
288618
--- a/unix/xserver/hw/vnc/XserverDesktop.cc
288618
+++ b/unix/xserver/hw/vnc/XserverDesktop.cc
288618
@@ -157,15 +157,12 @@ XserverDesktop::XserverDesktop(ScreenPtr pScreen_,
288618
 
288618
   if (httpListener)
288618
     httpServer = new FileHTTPServer(this);
288618
-
288618
-  inputDevice = new InputDevice(server);
288618
 }
288618
 
288618
 XserverDesktop::~XserverDesktop()
288618
 {
288618
   if (!directFbptr)
288618
     delete [] data;
288618
-  delete inputDevice;
288618
   delete httpServer;
288618
   delete server;
288618
 }
288618
@@ -583,7 +580,7 @@ void XserverDesktop::blockHandler(fd_set* fds, OSTimePtr timeout)
288618
   // so we abuse the fact that this routine will be called first thing
288618
   // once the dix is done initialising.
288618
   // [1] Technically Xvnc has InitInput(), but libvnc.so has nothing.
288618
-  inputDevice->InitInputDevice();
288618
+  vncInputDevice->InitInputDevice();
288618
 
288618
   try {
288618
     int nextTimeout;
288618
@@ -691,7 +688,11 @@ void XserverDesktop::wakeupHandler(fd_set* fds, int nfds)
288618
         }
288618
       }
288618
 
288618
-      inputDevice->PointerSync();
288618
+      // We are responsible for propagating mouse movement between clients
288618
+      if (!oldCursorPos.equals(vncInputDevice->getPointerPos())) {
288618
+        oldCursorPos = vncInputDevice->getPointerPos();
288618
+        server->setCursorPos(oldCursorPos);
288618
+      }
288618
     }
288618
 
288618
     // Then let the timers do some processing. Rescheduling is done in
288618
@@ -818,8 +819,8 @@ void XserverDesktop::approveConnection(void* opaqueId, bool accept,
288618
 
288618
 void XserverDesktop::pointerEvent(const Point& pos, int buttonMask)
288618
 {
288618
-  inputDevice->PointerMove(pos);
288618
-  inputDevice->PointerButtonAction(buttonMask);
288618
+  vncInputDevice->PointerMove(pos);
288618
+  vncInputDevice->PointerButtonAction(buttonMask);
288618
 }
288618
 
288618
 void XserverDesktop::clientCutText(const char* str, int len)
288618
@@ -1136,7 +1137,7 @@ void XserverDesktop::lookup(int index, int* r, int* g, int* b)
288618
 void XserverDesktop::keyEvent(rdr::U32 keysym, bool down)
288618
 {
288618
 	if (down)
288618
-		inputDevice->KeyboardPress(keysym);
288618
+		vncInputDevice->KeyboardPress(keysym);
288618
 	else
288618
-		inputDevice->KeyboardRelease(keysym);
288618
+		vncInputDevice->KeyboardRelease(keysym);
288618
 }
288618
diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h
288618
index fb247b0..ca6e8af 100644
288618
--- a/unix/xserver/hw/vnc/XserverDesktop.h
288618
+++ b/unix/xserver/hw/vnc/XserverDesktop.h
288618
@@ -153,5 +153,7 @@ private:
288618
   typedef std::map<RROutputPtr, rdr::U32> OutputIdMap;
288618
   OutputIdMap outputIdMap;
288618
 #endif
288618
+
288618
+  rfb::Point oldCursorPos;
288618
 };
288618
 #endif
288618
diff --git a/unix/xserver/hw/vnc/xf86vncModule.cc b/unix/xserver/hw/vnc/xf86vncModule.cc
288618
index 3187bba..596d399 100644
288618
--- a/unix/xserver/hw/vnc/xf86vncModule.cc
288618
+++ b/unix/xserver/hw/vnc/xf86vncModule.cc
288618
@@ -112,9 +112,9 @@ static void vncExtensionInitWithParams(INITARGS)
288618
           i.param->setParam(val);
288618
       }
288618
     }
288618
-
288618
-    vncExtensionInit();
288618
   }
288618
+
288618
+  vncExtensionInit();
288618
 }
288618
 }
288618