sharkcz / rpms / tigervnc

Forked from rpms/tigervnc 4 years ago
Clone
Blob Blame History Raw
From d400267b6f170b82ba826d598df78e0f5519481c Mon Sep 17 00:00:00 2001
From: Adam Tkac <atkac@redhat.com>
Date: Wed, 14 Apr 2010 11:15:07 +0200
Subject: [PATCH 2/2] Use AllocDevicePair instead of AddDevice/RegisterDevice functions and initialize
 TigerVNC input devices after core devices initialization.

---
 unix/xserver/hw/vnc/Input.cc |   37 ++++++++++++++++++++++++++++++++++++-
 unix/xserver/hw/vnc/Input.h  |   10 ++++++++++
 2 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/unix/xserver/hw/vnc/Input.cc b/unix/xserver/hw/vnc/Input.cc
index 3b60a5f..d108763 100644
--- a/unix/xserver/hw/vnc/Input.cc
+++ b/unix/xserver/hw/vnc/Input.cc
@@ -119,6 +119,7 @@ static void enqueueEvents(DeviceIntPtr dev, int n)
 InputDevice::InputDevice(rfb::VNCServerST *_server)
 	: server(_server), oldButtonMask(0)
 {
+#if XORG < 17
 	pointerDev = AddInputDevice(
 #if XORG >= 16
 				    serverClient,
@@ -132,7 +133,7 @@ InputDevice::InputDevice(rfb::VNCServerST *_server)
 #endif
 				     keyboardProc, TRUE);
 	RegisterKeyboardDevice(keyboardDev);
-
+#endif
 	initEventq();
 }
 
@@ -140,6 +141,8 @@ void InputDevice::PointerButtonAction(int buttonMask)
 {
 	int i, n;
 
+	initInputDevice();
+
 	for (i = 0; i < BUTTONS; i++) {
 		if ((buttonMask ^ oldButtonMask) & (1 << i)) {
 			int action = (buttonMask & (1<<i)) ?
@@ -161,6 +164,8 @@ void InputDevice::PointerMove(const rfb::Point &pos)
 	if (pos.equals(cursorPos))
 		return;
 
+	initInputDevice();
+
 	valuators[0] = pos.x;
 	valuators[1] = pos.y;
 	n = GetPointerEvents(eventq, pointerDev, MotionNotify, 0, POINTER_ABSOLUTE, 0,
@@ -238,6 +243,34 @@ static int pointerProc(DeviceIntPtr pDevice, int onoff)
 	return Success;
 }
 
+void InputDevice::initInputDevice(void)
+{
+#if XORG >= 17
+	int ret;
+	static int initialized = 0;
+
+	if (initialized != 0)
+		return;
+
+	initialized = 1;
+
+	ret = AllocDevicePair(serverClient, "TigerVNC", &pointerDev,
+			      &keyboardDev, pointerProc, keyboardProc,
+			      FALSE);
+
+	if (ret != Success)
+		FatalError("Failed to initialize TigerVNC input devices\n");
+
+	if (ActivateDevice(pointerDev, TRUE) != Success ||
+	    ActivateDevice(keyboardDev, TRUE) != Success)
+		FatalError("Failed to activate TigerVNC devices\n");
+
+	if (!EnableDevice(pointerDev, TRUE) ||
+	    !EnableDevice(keyboardDev, TRUE))
+		FatalError("Failed to activate TigerVNC devices\n");
+#endif
+}
+
 #define IS_PRESSED(keyc, keycode) \
 	((keyc)->down[(keycode) >> 3] & (1 << ((keycode) & 7)))
 
@@ -463,6 +496,8 @@ void InputDevice::keyEvent(rdr::U32 keysym, bool down)
 	unsigned int i, n;
 	int j, k, action, state, maxKeysPerMod;
 
+	initInputDevice();
+
 	/* 
 	 * Since we are checking the current state to determine if we need
 	 * to fake modifiers, we must make sure that everything put on the
diff --git a/unix/xserver/hw/vnc/Input.h b/unix/xserver/hw/vnc/Input.h
index 8987085..dbc78f8 100644
--- a/unix/xserver/hw/vnc/Input.h
+++ b/unix/xserver/hw/vnc/Input.h
@@ -56,6 +56,16 @@ public:
 	void KeyboardPress(rdr::U32 keysym) { keyEvent(keysym, true); }
 	void KeyboardRelease(rdr::U32 keysym) { keyEvent(keysym, false); }
 private:
+	/*
+	 * 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
+	 */
+	void initInputDevice(void);
+
 	void keyEvent(rdr::U32 keysym, bool down);
 
 	rfb::VNCServerST *server;
-- 
1.7.0.1