diff options
author | Jay Sorg <jay.sorg@gmail.com> | 2013-07-23 23:24:46 -0700 |
---|---|---|
committer | Jay Sorg <jay.sorg@gmail.com> | 2013-07-23 23:24:46 -0700 |
commit | 48aa165729099cb12092023f88af8e2a3ee7702c (patch) | |
tree | fca7372a9744820cad9fc23273ab6a52ccbf215c /xorg/server/xrdpmouse/rdpMouse.c | |
parent | 17bf2abe309c5e146ae53c25e634089842e847f1 (diff) | |
download | xrdp-proprietary-48aa165729099cb12092023f88af8e2a3ee7702c.tar.gz xrdp-proprietary-48aa165729099cb12092023f88af8e2a3ee7702c.zip |
xorg driver, mouse input
Diffstat (limited to 'xorg/server/xrdpmouse/rdpMouse.c')
-rw-r--r-- | xorg/server/xrdpmouse/rdpMouse.c | 167 |
1 files changed, 166 insertions, 1 deletions
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 <xserver-properties.h> #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) @@ -86,6 +95,161 @@ rdpmouseCtrl(DeviceIntPtr pDevice, PtrCtrl *pCtrl) /******************************************************************************/ 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) { BYTE map[6]; @@ -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; |