From 48aa165729099cb12092023f88af8e2a3ee7702c Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Tue, 23 Jul 2013 23:24:46 -0700 Subject: [PATCH] xorg driver, mouse input --- xorg/server/Makefile | 6 ++ xorg/server/module/rdpInput.c | 10 +- xorg/server/module/rdpInput.h | 9 +- xorg/server/xrdpdev/xrdpdev.c | 2 +- xorg/server/xrdpkeyb/rdpKeyboard.c | 3 +- xorg/server/xrdpmouse/rdpMouse.c | 167 ++++++++++++++++++++++++++++- 6 files changed, 187 insertions(+), 10 deletions(-) diff --git a/xorg/server/Makefile b/xorg/server/Makefile index 12548dd9..ad82975a 100644 --- a/xorg/server/Makefile +++ b/xorg/server/Makefile @@ -14,3 +14,9 @@ allclean: cd xrdpdev; $(MAKE) clean cd xrdpkeyb; $(MAKE) clean cd xrdpmouse; $(MAKE) clean + +xinstall: + cp module/libxorgxrdp.so $(HOME)/xorg-modules/ + cp xrdpdev/xrdpdev_drv.so $(HOME)/xorg-modules/drivers/ + cp xrdpmouse/xrdpmouse_drv.so $(HOME)/xorg-modules/input/ + cp xrdpkeyb/xrdpkeyb_drv.so $(HOME)/xorg-modules/input/ diff --git a/xorg/server/module/rdpInput.c b/xorg/server/module/rdpInput.c index 156165e2..a7bafd08 100644 --- a/xorg/server/module/rdpInput.c +++ b/xorg/server/module/rdpInput.c @@ -87,24 +87,26 @@ rdpUnregisterInputCallback(rdpInputEventProcPtr proc) /******************************************************************************/ int -rdpInputKeyboardEvent(int msg, long param1, long param2, +rdpInputKeyboardEvent(rdpPtr dev, int msg, + long param1, long param2, long param3, long param4) { if (g_input_proc[0].proc != 0) { - return g_input_proc[0].proc(msg, param1, param2, param3, param4); + return g_input_proc[0].proc(dev, msg, param1, param2, param3, param4); } return 0; } /******************************************************************************/ int -rdpInputMouseEvent(int msg, long param1, long param2, +rdpInputMouseEvent(rdpPtr dev, int msg, + long param1, long param2, long param3, long param4) { if (g_input_proc[1].proc != 0) { - return g_input_proc[1].proc(msg, param1, param2, param3, param4); + return g_input_proc[1].proc(dev, msg, param1, param2, param3, param4); } return 0; } diff --git a/xorg/server/module/rdpInput.h b/xorg/server/module/rdpInput.h index f41a1025..19315026 100644 --- a/xorg/server/module/rdpInput.h +++ b/xorg/server/module/rdpInput.h @@ -24,7 +24,8 @@ input #ifndef _RDPINPUT_H #define _RDPINPUT_H -typedef int (*rdpInputEventProcPtr)(int msg, long param1, long param2, +typedef int (*rdpInputEventProcPtr)(rdpPtr dev, int msg, + long param1, long param2, long param3, long param4); int @@ -32,10 +33,12 @@ rdpRegisterInputCallback(int type, rdpInputEventProcPtr proc); int rdpUnregisterInputCallback(rdpInputEventProcPtr proc); int -rdpInputKeyboardEvent(int msg, long param1, long param2, +rdpInputKeyboardEvent(rdpPtr dev, int msg, + long param1, long param2, long param3, long param4); int -rdpInputMouseEvent(int msg, long param1, long param2, +rdpInputMouseEvent(rdpPtr dev, int msg, + long param1, long param2, long param3, long param4); int rdpInputInit(void); diff --git a/xorg/server/xrdpdev/xrdpdev.c b/xorg/server/xrdpdev/xrdpdev.c index ced9a8ee..73596ba3 100644 --- a/xorg/server/xrdpdev/xrdpdev.c +++ b/xorg/server/xrdpdev/xrdpdev.c @@ -304,7 +304,7 @@ rdpResizeSession(rdpPtr dev, int width, int height) { LLOGLN(0, (" calling RRScreenSizeSet")); ok = RRScreenSizeSet(dev->pScreen, width, height, mmwidth, mmheight); - LLOGLN(0, (" RRScreenSizeSet ok=[%d]", ok)); + LLOGLN(0, (" RRScreenSizeSet ok %d", ok)); } return ok; } diff --git a/xorg/server/xrdpkeyb/rdpKeyboard.c b/xorg/server/xrdpkeyb/rdpKeyboard.c index 572dc24d..231e4e05 100644 --- a/xorg/server/xrdpkeyb/rdpKeyboard.c +++ b/xorg/server/xrdpkeyb/rdpKeyboard.c @@ -494,7 +494,8 @@ KbdSync(int param1) /******************************************************************************/ static int -rdpInputKeyboard(int msg, long param1, long param2, long param3, long param4) +rdpInputKeyboard(rdpPtr dev, int msg, long param1, long param2, + long param3, long param4) { LLOGLN(0, ("rdpInputKeyboard:")); switch (msg) diff --git a/xorg/server/xrdpmouse/rdpMouse.c b/xorg/server/xrdpmouse/rdpMouse.c index 7142a4ee..acd7fe3e 100644 --- a/xorg/server/xrdpmouse/rdpMouse.c +++ b/xorg/server/xrdpmouse/rdpMouse.c @@ -42,6 +42,7 @@ xrdp mouse module #include #include "rdp.h" +#include "rdpInput.h" /******************************************************************************/ #define LOG_LEVEL 1 @@ -56,6 +57,14 @@ xrdp mouse module #define PACKAGE_VERSION_MINOR 0 #define PACKAGE_VERSION_PATCHLEVEL 0 +static DeviceIntPtr g_pointer = 0; + +static int g_cursor_x = 0; +static int g_cursor_y = 0; + +static int g_old_button_mask = 0; +static int g_button_mask = 0; + /******************************************************************************/ static void rdpmouseDeviceInit(void) @@ -84,6 +93,161 @@ rdpmouseCtrl(DeviceIntPtr pDevice, PtrCtrl *pCtrl) LLOGLN(0, ("rdpmouseCtrl:")); } +/******************************************************************************/ +static int +l_bound_by(int val, int low, int high) +{ + if (val > high) + { + val = high; + } + + if (val < low) + { + val = low; + } + + return val; +} + +/******************************************************************************/ +static void +rdpEnqueueMotion(int x, int y) +{ + int i; + int n; + int valuators[2]; + EventListPtr rdp_events; + xEvent *pev; + + miPointerSetPosition(g_pointer, &x, &y); + valuators[0] = x; + valuators[1] = y; + + GetEventList(&rdp_events); + n = GetPointerEvents(rdp_events, g_pointer, MotionNotify, 0, + POINTER_ABSOLUTE | POINTER_SCREEN, + 0, 2, valuators); + + for (i = 0; i < n; i++) + { + pev = (rdp_events + i)->event; + mieqEnqueue(g_pointer, (InternalEvent *)pev); + } +} + +/******************************************************************************/ +static void +rdpEnqueueButton(int type, int buttons) +{ + int i; + int n; + EventListPtr rdp_events; + xEvent *pev; + + i = GetEventList(&rdp_events); + n = GetPointerEvents(rdp_events, g_pointer, type, buttons, 0, 0, 0, 0); + + for (i = 0; i < n; i++) + { + pev = (rdp_events + i)->event; + mieqEnqueue(g_pointer, (InternalEvent *)pev); + } +} + +/******************************************************************************/ +void +PtrAddEvent(int buttonMask, int x, int y) +{ + int i; + int type; + int buttons; + + rdpEnqueueMotion(x, y); + + for (i = 0; i < 5; i++) + { + if ((buttonMask ^ g_old_button_mask) & (1 << i)) + { + if (buttonMask & (1 << i)) + { + type = ButtonPress; + buttons = i + 1; + rdpEnqueueButton(type, buttons); + } + else + { + type = ButtonRelease; + buttons = i + 1; + rdpEnqueueButton(type, buttons); + } + } + } + + g_old_button_mask = buttonMask; +} + +/******************************************************************************/ +static int +rdpInputMouse(rdpPtr dev, int msg, + long param1, long param2, + long param3, long param4) +{ + LLOGLN(0, ("rdpInputMouse:")); + + switch (msg) + { + case 100: + /* without the minus 2, strange things happen when dragging + past the width or height */ + g_cursor_x = l_bound_by(param1, 0, dev->width - 2); + g_cursor_y = l_bound_by(param2, 0, dev->height - 2); + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 101: + g_button_mask = g_button_mask & (~1); + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 102: + g_button_mask = g_button_mask | 1; + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 103: + g_button_mask = g_button_mask & (~4); + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 104: + g_button_mask = g_button_mask | 4; + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 105: + g_button_mask = g_button_mask & (~2); + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 106: + g_button_mask = g_button_mask | 2; + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 107: + g_button_mask = g_button_mask & (~8); + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 108: + g_button_mask = g_button_mask | 8; + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 109: + g_button_mask = g_button_mask & (~16); + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + case 110: + g_button_mask = g_button_mask | 16; + PtrAddEvent(g_button_mask, g_cursor_x, g_cursor_y); + break; + } + return 0; +} + /******************************************************************************/ static int rdpmouseControl(DeviceIntPtr device, int what) @@ -118,7 +282,8 @@ rdpmouseControl(DeviceIntPtr device, int what) InitPointerDeviceStruct(pDev, map, 5, btn_labels, rdpmouseCtrl, GetMotionHistorySize(), 2, axes_labels); - + g_pointer = device; + rdpRegisterInputCallback(1, rdpInputMouse); break; case DEVICE_ON: pDev->on = 1;