diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 9e1e7235d..8eb3d178d 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -426,6 +426,21 @@ BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window win return TRUE; } + +BOOL xf_generic_RawMotionNotify(xfContext* xfc, int x, int y, Window window, BOOL app) +{ + WINPR_ASSERT(xfc); + + if (app) + { + WLog_ERR(TAG, "Relative mouse input is not supported with remoate app mode!"); + return FALSE; + } + + freerdp_client_send_button_event(&xfc->common, TRUE, PTR_FLAGS_MOVE, x, y); + return TRUE; +} + static BOOL xf_event_MotionNotify(xfContext* xfc, const XMotionEvent* event, BOOL app) { WINPR_ASSERT(xfc); @@ -1188,3 +1203,56 @@ BOOL xf_event_process(freerdp* instance, const XEvent* event) XSync(xfc->display, FALSE); return status; } + +BOOL xf_generic_RawButtonEvent(xfContext* xfc, int button, BOOL app, BOOL down) +{ + UINT16 flags = 0; + size_t i; + + if (app) + return FALSE; + + for (i = 0; i < ARRAYSIZE(xfc->button_map); i++) + { + const button_map* cur = &xfc->button_map[i]; + + if (cur->button == button) + { + flags = cur->flags; + break; + } + } + + if (flags != 0) + { + if (flags & (PTR_FLAGS_WHEEL | PTR_FLAGS_HWHEEL)) + { + if (down) + freerdp_client_send_wheel_event(&xfc->common, flags); + } + else + { + BOOL extended = FALSE; + + if (flags & (PTR_XFLAGS_BUTTON1 | PTR_XFLAGS_BUTTON2)) + { + extended = TRUE; + + if (down) + flags |= PTR_XFLAGS_DOWN; + } + else if (flags & (PTR_FLAGS_BUTTON1 | PTR_FLAGS_BUTTON2 | PTR_FLAGS_BUTTON3)) + { + if (down) + flags |= PTR_FLAGS_DOWN; + } + + if (extended) + freerdp_client_send_extended_button_event(&xfc->common, TRUE, flags, 0, 0); + else + freerdp_client_send_button_event(&xfc->common, TRUE, flags, 0, 0); + } + } + + return TRUE; +} diff --git a/client/X11/xf_event.h b/client/X11/xf_event.h index 2269d3eea..027cbf868 100644 --- a/client/X11/xf_event.h +++ b/client/X11/xf_event.h @@ -36,8 +36,9 @@ void xf_event_adjust_coordinates(xfContext* xfc, int* x, int* y); void xf_adjust_coordinates_to_screen(xfContext* xfc, UINT32* x, UINT32* y); BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window window, BOOL app); -BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button, Window window, BOOL app); +BOOL xf_generic_RawMotionNotify(xfContext* xfc, int x, int y, Window window, BOOL app); BOOL xf_generic_ButtonEvent(xfContext* xfc, int x, int y, int button, Window window, BOOL app, BOOL down); +BOOL xf_generic_RawButtonEvent(xfContext* xfc, int button, BOOL app, BOOL down); #endif /* FREERDP_CLIENT_X11_EVENT_H */ diff --git a/client/X11/xf_input.c b/client/X11/xf_input.c index 20fa2e135..9d310ede1 100644 --- a/client/X11/xf_input.c +++ b/client/X11/xf_input.c @@ -50,6 +50,8 @@ #define MIN_FINGER_DIST 5 +static int xf_input_event(xfContext* xfc, XIDeviceEvent* event, int evtype); + static const char* xf_input_get_class_string(int class) { if (class == XIKeyClass) @@ -68,16 +70,10 @@ static const char* xf_input_get_class_string(int class) int xf_input_init(xfContext* xfc, Window window) { - int i, j; - int nmasks = 0; - int ndevices = 0; - int major = 2; - int minor = 2; - XIDeviceInfo* info; - XIEventMask evmasks[64]; + int major = XI_2_Major; + int minor = XI_2_Minor; int opcode, event, error; - const rdpSettings* settings; - BYTE masks[8][XIMaskLen(XI_LASTEVENT)] = { 0 }; + rdpSettings* settings; WINPR_ASSERT(xfc); @@ -100,89 +96,45 @@ int xf_input_init(xfContext* xfc, Window window) xfc->XInputOpcode = opcode; XIQueryVersion(xfc->display, &major, &minor); - if (major * 1000 + minor < 2002) + if ((major < XI_2_Major) || ((major == XI_2_Major) && (minor < 2))) { WLog_WARN(TAG, "Server does not support XI 2.2"); return -1; } - if (settings->MultiTouchInput) - xfc->use_xinput = TRUE; - - info = XIQueryDevice(xfc->display, XIAllDevices, &ndevices); - - for (i = 0; i < ndevices; i++) + else { - BOOL touch = FALSE; - XIDeviceInfo* dev = &info[i]; + XIEventMask mask; + unsigned char mask_bytes[XIMaskLen(XI_LASTEVENT)] = { 0 }; - for (j = 0; j < dev->num_classes; j++) + if (freerdp_settings_get_bool(settings, FreeRDP_MouseUseRelativeMove)) { - XIAnyClassInfo* class = dev->classes[j]; - XITouchClassInfo* t = (XITouchClassInfo*)class; + XISetMask(mask_bytes, XI_RawMotion); + XISetMask(mask_bytes, XI_RawButtonPress); + XISetMask(mask_bytes, XI_RawButtonRelease); + } + else + { + XISetMask(mask_bytes, XI_Motion); + XISetMask(mask_bytes, XI_ButtonPress); + XISetMask(mask_bytes, XI_ButtonRelease); + } - if ((class->type == XITouchClass) && (t->mode == XIDirectTouch) && - (strcmp(dev->name, "Virtual core pointer") != 0)) - { - touch = TRUE; - } - } + if (freerdp_settings_get_bool(settings, FreeRDP_MultiTouchGestures) || + freerdp_settings_get_bool(settings, FreeRDP_MultiTouchInput)) + { + XISetMask(mask_bytes, XI_TouchBegin); + XISetMask(mask_bytes, XI_TouchUpdate); + XISetMask(mask_bytes, XI_TouchEnd); + } - for (j = 0; j < dev->num_classes; j++) - { - XIAnyClassInfo* class = dev->classes[j]; - XITouchClassInfo* t = (XITouchClassInfo*)class; + mask.deviceid = XIAllMasterDevices; + mask.mask_len = sizeof(mask_bytes); + mask.mask = mask_bytes; - if (xfc->common.context.settings->MultiTouchInput) - { - WLog_INFO(TAG, "%s (%d) \"%s\" id: %d", xf_input_get_class_string(class->type), - class->type, dev->name, dev->deviceid); - } - - evmasks[nmasks].mask = masks[nmasks]; - evmasks[nmasks].mask_len = sizeof(masks[0]); - ZeroMemory(masks[nmasks], sizeof(masks[0])); - evmasks[nmasks].deviceid = dev->deviceid; - - if ((class->type == XITouchClass) && (t->mode == XIDirectTouch) && - (strcmp(dev->name, "Virtual core pointer") != 0)) - { - if (settings->MultiTouchInput) - { - WLog_INFO(TAG, "%s %s touch device (id: %d, mode: %d), supporting %d touches.", - dev->name, (t->mode == XIDirectTouch) ? "direct" : "dependent", - dev->deviceid, t->mode, t->num_touches); - } - - XISetMask(masks[nmasks], XI_TouchBegin); - XISetMask(masks[nmasks], XI_TouchUpdate); - XISetMask(masks[nmasks], XI_TouchEnd); - nmasks++; - } - - if (xfc->use_xinput) - { - if (!touch && (class->type == XIButtonClass) && - strcmp(dev->name, "Virtual core pointer")) - { - WLog_INFO(TAG, "%s button device (id: %d, mode: %d)", dev->name, dev->deviceid, - t->mode); - XISetMask(masks[nmasks], XI_ButtonPress); - XISetMask(masks[nmasks], XI_ButtonRelease); - XISetMask(masks[nmasks], XI_Motion); - nmasks++; - } - } - } - } - - XIFreeDeviceInfo(info); - - if (nmasks > 0) - { - Status xstatus = XISelectEvents(xfc->display, window, evmasks, nmasks); - if (xstatus != 0) - WLog_WARN(TAG, "XISelectEvents returned %d", xstatus); + int scr = DefaultScreen(xfc->display); + Window root = RootWindow(xfc->display, scr); + XISelectEvents(xfc->display, root, &mask, 1); } return 0; @@ -477,7 +429,7 @@ static int xf_input_handle_event_local(xfContext* xfc, const XEvent* event) break; default: - WLog_ERR(TAG, "unhandled xi type= %d", cookie.cc->evtype); + xf_input_event(xfc, cookie.cc->data, cookie.cc->evtype); break; } } @@ -572,26 +524,28 @@ static int xf_input_touch_remote(xfContext* xfc, XIDeviceEvent* event, int evtyp y = (int)event->event_y; xf_event_adjust_coordinates(xfc, &x, &y); - if (evtype == XI_TouchBegin) + switch (evtype) { - WLog_DBG(TAG, "TouchBegin: %d", touchId); - rdpei->TouchBegin(rdpei, touchId, x, y, &contactId); - } - else if (evtype == XI_TouchUpdate) - { - WLog_DBG(TAG, "TouchUpdate: %d", touchId); - rdpei->TouchUpdate(rdpei, touchId, x, y, &contactId); - } - else if (evtype == XI_TouchEnd) - { - WLog_DBG(TAG, "TouchEnd: %d", touchId); - rdpei->TouchEnd(rdpei, touchId, x, y, &contactId); + case XI_TouchBegin: + WLog_DBG(TAG, "TouchBegin: %d", touchId); + rdpei->TouchBegin(rdpei, touchId, x, y, &contactId); + break; + case XI_TouchUpdate: + WLog_DBG(TAG, "TouchUpdate: %d", touchId); + rdpei->TouchUpdate(rdpei, touchId, x, y, &contactId); + break; + case XI_TouchEnd: + WLog_DBG(TAG, "TouchEnd: %d", touchId); + rdpei->TouchEnd(rdpei, touchId, x, y, &contactId); + break; + default: + break; } return 0; } -static int xf_input_event(xfContext* xfc, XIDeviceEvent* event, int evtype) +int xf_input_event(xfContext* xfc, XIDeviceEvent* event, int evtype) { xf_input_show_cursor(xfc); @@ -611,6 +565,29 @@ static int xf_input_event(xfContext* xfc, XIDeviceEvent* event, int evtype) xf_generic_MotionNotify(xfc, (int)event->event_x, (int)event->event_y, event->detail, event->event, xfc->remote_app); break; + case XI_RawButtonPress: + case XI_RawButtonRelease: + { + const XIRawEvent* ev = event; + xf_generic_RawButtonEvent(xfc, ev->detail, xfc->remote_app, + evtype == XI_RawButtonPress); + } + break; + case XI_RawMotion: + { + const XIRawEvent* ev = event; + double x = 0.0; + double y = 0.0; + if (XIMaskIsSet(ev->valuators.mask, 0)) + x = ev->raw_values[0]; + if (XIMaskIsSet(ev->valuators.mask, 1)) + y = ev->raw_values[1]; + xf_generic_RawMotionNotify(xfc, (int)x, (int)y, event->event, xfc->remote_app); + } + break; + default: + WLog_INFO(TAG, "xcxx"); + break; } return 0; @@ -630,15 +607,9 @@ static int xf_input_handle_event_remote(xfContext* xfc, const XEvent* event) switch (cookie.cc->evtype) { case XI_TouchBegin: - xf_input_touch_remote(xfc, cookie.cc->data, XI_TouchBegin); - break; - case XI_TouchUpdate: - xf_input_touch_remote(xfc, cookie.cc->data, XI_TouchUpdate); - break; - case XI_TouchEnd: - xf_input_touch_remote(xfc, cookie.cc->data, XI_TouchEnd); + xf_input_touch_remote(xfc, cookie.cc->data, cookie.cc->evtype); break; default: @@ -673,8 +644,11 @@ int xf_input_handle_event(xfContext* xfc, const XEvent* event) { return xf_input_handle_event_remote(xfc, event); } - - if (settings->MultiTouchGestures) + else if (settings->MultiTouchGestures) + { + return xf_input_handle_event_local(xfc, event); + } + else { return xf_input_handle_event_local(xfc, event); }