mfreerdp-server: basic mouse input

This commit is contained in:
C-o-r-E 2013-02-21 19:56:32 -05:00
parent fab36f25d6
commit 5fea599d60
3 changed files with 76 additions and 48 deletions

View File

@ -39,9 +39,9 @@ typedef struct rdp_input rdpInput;
#define PTR_FLAGS_WHEEL_NEGATIVE 0x0100 #define PTR_FLAGS_WHEEL_NEGATIVE 0x0100
#define PTR_FLAGS_MOVE 0x0800 #define PTR_FLAGS_MOVE 0x0800
#define PTR_FLAGS_DOWN 0x8000 #define PTR_FLAGS_DOWN 0x8000
#define PTR_FLAGS_BUTTON1 0x1000 #define PTR_FLAGS_BUTTON1 0x1000 //left
#define PTR_FLAGS_BUTTON2 0x2000 #define PTR_FLAGS_BUTTON2 0x2000 //right
#define PTR_FLAGS_BUTTON3 0x4000 #define PTR_FLAGS_BUTTON3 0x4000 //middle
#define WheelRotationMask 0x01FF #define WheelRotationMask 0x01FF
/* Extended Pointer Flags */ /* Extended Pointer Flags */

View File

@ -21,13 +21,16 @@
#include "config.h" #include "config.h"
#endif #endif
#include <ApplicationServices/ApplicationServices.h>
#include <winpr/windows.h> #include <winpr/windows.h>
#include "wf_input.h" #include "mf_input.h"
#include "wf_info.h" #include "mf_info.h"
void wf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{ {
/*
INPUT keyboard_event; INPUT keyboard_event;
keyboard_event.type = INPUT_KEYBOARD; keyboard_event.type = INPUT_KEYBOARD;
@ -44,10 +47,12 @@ void wf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
keyboard_event.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; keyboard_event.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
SendInput(1, &keyboard_event, sizeof(INPUT)); SendInput(1, &keyboard_event, sizeof(INPUT));
*/
} }
void wf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{ {
/*
INPUT keyboard_event; INPUT keyboard_event;
keyboard_event.type = INPUT_KEYBOARD; keyboard_event.type = INPUT_KEYBOARD;
@ -61,18 +66,16 @@ void wf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP; keyboard_event.ki.dwFlags |= KEYEVENTF_KEYUP;
SendInput(1, &keyboard_event, sizeof(INPUT)); SendInput(1, &keyboard_event, sizeof(INPUT));
*/
} }
void wf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
INPUT mouse_event;
float width, height; float width, height;
ZeroMemory(&mouse_event, sizeof(INPUT));
mouse_event.type = INPUT_MOUSE;
if (flags & PTR_FLAGS_WHEEL) if (flags & PTR_FLAGS_WHEEL)
{ {
/*
mouse_event.mi.dwFlags = MOUSEEVENTF_WHEEL; mouse_event.mi.dwFlags = MOUSEEVENTF_WHEEL;
mouse_event.mi.mouseData = flags & WheelRotationMask; mouse_event.mi.mouseData = flags & WheelRotationMask;
@ -80,64 +83,87 @@ void wf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
mouse_event.mi.mouseData *= -1; mouse_event.mi.mouseData *= -1;
SendInput(1, &mouse_event, sizeof(INPUT)); SendInput(1, &mouse_event, sizeof(INPUT));
*/
} }
else else
{ {
wfInfo * wfi;
wfi = wf_info_get_instance(); mfInfo * mfi;
CGEventType mouseType = kCGEventNull;
CGMouseButton mouseButton = kCGMouseButtonLeft;
mfi = mf_info_get_instance();
//width and height of primary screen (even in multimon setups //width and height of primary screen (even in multimon setups
width = (float) GetSystemMetrics(SM_CXSCREEN); width = (float) mfi->servscreen_width;
height = (float) GetSystemMetrics(SM_CYSCREEN); height = (float) mfi->servscreen_height;
x += wfi->servscreen_xoffset; x += mfi->servscreen_xoffset;
y += wfi->servscreen_yoffset; y += mfi->servscreen_yoffset;
mouse_event.mi.dx = (LONG) ((float) x * (65535.0f / width));
mouse_event.mi.dy = (LONG) ((float) y * (65535.0f / height));
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
if (flags & PTR_FLAGS_MOVE) if (flags & PTR_FLAGS_MOVE)
{ {
mouse_event.mi.dwFlags |= MOUSEEVENTF_MOVE;
SendInput(1, &mouse_event, sizeof(INPUT)); mouseType = kCGEventMouseMoved;
CGEventRef move = CGEventCreateMouseEvent(NULL,
mouseType,
CGPointMake(x, y),
mouseButton // ignored for just movement
);
CGEventPost(kCGHIDEventTap, move);
CFRelease(move);
} }
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
if (flags & PTR_FLAGS_BUTTON1) if (flags & PTR_FLAGS_BUTTON1)
{ {
mouseButton = kCGMouseButtonLeft;
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN; mouseType = kCGEventLeftMouseDown;
else else
mouse_event.mi.dwFlags |= MOUSEEVENTF_LEFTUP; mouseType = kCGEventLeftMouseUp;
SendInput(1, &mouse_event, sizeof(INPUT));
} }
else if (flags & PTR_FLAGS_BUTTON2) else if (flags & PTR_FLAGS_BUTTON2)
{ {
mouseButton = kCGMouseButtonRight;
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN; mouseType = kCGEventRightMouseDown;
else else
mouse_event.mi.dwFlags |= MOUSEEVENTF_RIGHTUP; mouseType = kCGEventRightMouseUp;
SendInput(1, &mouse_event, sizeof(INPUT));
} }
else if (flags & PTR_FLAGS_BUTTON3) else if (flags & PTR_FLAGS_BUTTON3)
{ {
mouseButton = kCGMouseButtonCenter;
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN; mouseType = kCGEventOtherMouseDown;
else else
mouse_event.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP; mouseType = kCGEventOtherMouseUp;
SendInput(1, &mouse_event, sizeof(INPUT));
} }
/*else
{
return;
}
*/
CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL,
mouseType,
CGPointMake(x, y),
mouseButton
);
CGEventPost(kCGHIDEventTap, mouseEvent);
CFRelease(mouseEvent);
} }
} }
void wf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
/*
if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2)) if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
{ {
INPUT mouse_event; INPUT mouse_event;
@ -183,23 +209,24 @@ void wf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT
} }
else else
{ {
wf_input_mouse_event(input, flags, x, y); mf_input_mouse_event(input, flags, x, y);
} }
*/
} }
void wf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code) void mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
{ {
} }
void wf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code) void mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
{ {
} }
void wf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
} }
void wf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
} }

View File

@ -29,6 +29,7 @@
#include "mf_peer.h" #include "mf_peer.h"
#include "mf_info.h" #include "mf_info.h"
#include "mf_input.h"
#include "mf_event.h" #include "mf_event.h"
#include "mf_rdpsnd.h" #include "mf_rdpsnd.h"
@ -373,7 +374,7 @@ void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
printf("Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)\n", flags, code); printf("Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)\n", flags, code);
} }
void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) /*void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
//printf("Client sent a mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); //printf("Client sent a mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y);
} }
@ -382,7 +383,7 @@ void mf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT1
{ {
//printf("Client sent an extended mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); //printf("Client sent an extended mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y);
} }
*/
/*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) /*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas)
{ {
BYTE i; BYTE i;
@ -509,8 +510,8 @@ void* mf_peer_main_loop(void* arg)
client->input->SynchronizeEvent = mf_peer_synchronize_event; client->input->SynchronizeEvent = mf_peer_synchronize_event;
client->input->KeyboardEvent = mf_peer_keyboard_event; client->input->KeyboardEvent = mf_peer_keyboard_event;
client->input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event; client->input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event;
client->input->MouseEvent = mf_peer_mouse_event; client->input->MouseEvent = mf_input_mouse_event;
client->input->ExtendedMouseEvent = mf_peer_extended_mouse_event; client->input->ExtendedMouseEvent = mf_input_extended_mouse_event;
//client->update->RefreshRect = mf_peer_refresh_rect; //client->update->RefreshRect = mf_peer_refresh_rect;
client->update->SuppressOutput = mf_peer_suppress_output; client->update->SuppressOutput = mf_peer_suppress_output;