Commit 4ab524ee authored by Alexandros Frantzis's avatar Alexandros Frantzis Committed by Alexandre Julliard

winewayland.drv: Implement relative mouse motion.

When the cursor is hidden and a pointer constraint is active, transition to relative mouse motion to enable mouselook in 3D games.
parent bf1cabd1
......@@ -7,6 +7,7 @@ SOURCES = \
display.c \
dllmain.c \
pointer-constraints-unstable-v1.xml \
relative-pointer-unstable-v1.xml \
version.rc \
viewporter.xml \
vulkan.c \
......
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="relative_pointer_unstable_v1">
<copyright>
Copyright © 2014 Jonas Ådahl
Copyright © 2015 Red Hat Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<description summary="protocol for relative pointer motion events">
This protocol specifies a set of interfaces used for making clients able to
receive relative pointer events not obstructed by barriers (such as the
monitor edge or other pointer barriers).
To start receiving relative pointer events, a client must first bind the
global interface "wp_relative_pointer_manager" which, if a compositor
supports relative pointer motion events, is exposed by the registry. After
having created the relative pointer manager proxy object, the client uses
it to create the actual relative pointer object using the
"get_relative_pointer" request given a wl_pointer. The relative pointer
motion events will then, when applicable, be transmitted via the proxy of
the newly created relative pointer object. See the documentation of the
relative pointer interface for more details.
Warning! The protocol described in this file is experimental and backward
incompatible changes may be made. Backward compatible changes may be added
together with the corresponding interface version bump. Backward
incompatible changes are done by bumping the version number in the protocol
and interface names and resetting the interface version. Once the protocol
is to be declared stable, the 'z' prefix and the version number in the
protocol and interface names are removed and the interface version number is
reset.
</description>
<interface name="zwp_relative_pointer_manager_v1" version="1">
<description summary="get relative pointer objects">
A global interface used for getting the relative pointer object for a
given pointer.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the relative pointer manager object">
Used by the client to notify the server that it will no longer use this
relative pointer manager object.
</description>
</request>
<request name="get_relative_pointer">
<description summary="get a relative pointer object">
Create a relative pointer interface given a wl_pointer object. See the
wp_relative_pointer interface for more details.
</description>
<arg name="id" type="new_id" interface="zwp_relative_pointer_v1"/>
<arg name="pointer" type="object" interface="wl_pointer"/>
</request>
</interface>
<interface name="zwp_relative_pointer_v1" version="1">
<description summary="relative pointer object">
A wp_relative_pointer object is an extension to the wl_pointer interface
used for emitting relative pointer events. It shares the same focus as
wl_pointer objects of the same seat and will only emit events when it has
focus.
</description>
<request name="destroy" type="destructor">
<description summary="release the relative pointer object"/>
</request>
<event name="relative_motion">
<description summary="relative pointer motion">
Relative x/y pointer motion from the pointer of the seat associated with
this object.
A relative motion is in the same dimension as regular wl_pointer motion
events, except they do not represent an absolute position. For example,
moving a pointer from (x, y) to (x', y') would have the equivalent
relative motion (x' - x, y' - y). If a pointer motion caused the
absolute pointer position to be clipped by for example the edge of the
monitor, the relative motion is unaffected by the clipping and will
represent the unclipped motion.
This event also contains non-accelerated motion deltas. The
non-accelerated delta is, when applicable, the regular pointer motion
delta as it was before having applied motion acceleration and other
transformations such as normalization.
Note that the non-accelerated delta does not represent 'raw' events as
they were read from some device. Pointer motion acceleration is device-
and configuration-specific and non-accelerated deltas and accelerated
deltas may have the same value on some devices.
Relative motions are not coupled to wl_pointer.motion events, and can be
sent in combination with such events, but also independently. There may
also be scenarios where wl_pointer.motion is sent, but there is no
relative motion. The order of an absolute and relative motion event
originating from the same physical motion is not guaranteed.
If the client needs button events or focus state, it can receive them
from a wl_pointer object of the same seat that the wp_relative_pointer
object is associated with.
</description>
<arg name="utime_hi" type="uint"
summary="high 32 bits of a 64 bit timestamp with microsecond granularity"/>
<arg name="utime_lo" type="uint"
summary="low 32 bits of a 64 bit timestamp with microsecond granularity"/>
<arg name="dx" type="fixed"
summary="the x component of the motion vector"/>
<arg name="dy" type="fixed"
summary="the y component of the motion vector"/>
<arg name="dx_unaccel" type="fixed"
summary="the x component of the unaccelerated motion vector"/>
<arg name="dy_unaccel" type="fixed"
summary="the y component of the unaccelerated motion vector"/>
</event>
</interface>
</protocol>
......@@ -159,6 +159,11 @@ static void registry_handle_global(void *data, struct wl_registry *registry,
process_wayland.zwp_pointer_constraints_v1 =
wl_registry_bind(registry, id, &zwp_pointer_constraints_v1_interface, 1);
}
else if (strcmp(interface, "zwp_relative_pointer_manager_v1") == 0)
{
process_wayland.zwp_relative_pointer_manager_v1 =
wl_registry_bind(registry, id, &zwp_relative_pointer_manager_v1_interface, 1);
}
}
static void registry_handle_global_remove(void *data, struct wl_registry *registry,
......@@ -269,6 +274,11 @@ BOOL wayland_process_init(void)
ERR("Wayland compositor doesn't support zwp_pointer_constraints_v1\n");
return FALSE;
}
if (!process_wayland.zwp_relative_pointer_manager_v1)
{
ERR("Wayland compositor doesn't support zwp_relative_pointer_manager_v1\n");
return FALSE;
}
wayland_init_display_devices(FALSE);
......
......@@ -47,8 +47,7 @@ static HWND wayland_pointer_get_focused_hwnd(void)
return hwnd;
}
static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
static void pointer_handle_motion_internal(wl_fixed_t sx, wl_fixed_t sy)
{
INPUT input = {0};
RECT *window_rect;
......@@ -91,6 +90,17 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
__wine_send_input(hwnd, &input, NULL);
}
static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
{
struct wayland_pointer *pointer = &process_wayland.pointer;
/* Ignore absolute motion events if in relative mode. */
if (pointer->zwp_relative_pointer_v1) return;
pointer_handle_motion_internal(sx, sy);
}
static void wayland_set_cursor(HWND hwnd, HCURSOR hcursor, BOOL use_hcursor);
static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
......@@ -119,7 +129,7 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
/* Handle the enter as a motion, to account for cases where the
* window first appears beneath the pointer and won't get a separate
* motion event. */
pointer_handle_motion(data, wl_pointer, 0, sx, sy);
pointer_handle_motion_internal(sx, sy);
}
static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
......@@ -229,6 +239,83 @@ static const struct wl_pointer_listener pointer_listener =
pointer_handle_axis_discrete
};
static void relative_pointer_v1_relative_motion(void *data,
struct zwp_relative_pointer_v1 *zwp_relative_pointer_v1,
uint32_t utime_hi, uint32_t utime_lo,
wl_fixed_t dx, wl_fixed_t dy,
wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel)
{
INPUT input = {0};
HWND hwnd;
POINT screen, origin;
struct wayland_surface *surface;
RECT window_rect;
if (!(hwnd = wayland_pointer_get_focused_hwnd())) return;
if (!(surface = wayland_surface_lock_hwnd(hwnd))) return;
window_rect = surface->window.rect;
wayland_surface_coords_to_window(surface,
wl_fixed_to_double(dx),
wl_fixed_to_double(dy),
(int *)&screen.x, (int *)&screen.y);
pthread_mutex_unlock(&surface->mutex);
/* We clip the relative motion within the window rectangle so that
* the NtUserLogicalToPerMonitorDPIPhysicalPoint calls later succeed.
* TODO: Avoid clipping by using a more versatile dpi mapping function. */
if (screen.x >= 0)
{
origin.x = window_rect.left;
screen.x += origin.x;
if (screen.x >= window_rect.right) screen.x = window_rect.right - 1;
}
else
{
origin.x = window_rect.right;
screen.x += origin.x;
if (screen.x < window_rect.left) screen.x = window_rect.left;
}
if (screen.y >= 0)
{
origin.y = window_rect.top;
screen.y += origin.y;
if (screen.y >= window_rect.bottom) screen.y = window_rect.bottom - 1;
}
else
{
origin.y = window_rect.bottom;
screen.y += origin.y;
if (screen.y < window_rect.top) screen.y = window_rect.top;
}
/* Transform the relative motion from window coordinates to physical
* coordinates required for the input event. */
if (!NtUserLogicalToPerMonitorDPIPhysicalPoint(hwnd, &screen)) return;
if (!NtUserLogicalToPerMonitorDPIPhysicalPoint(hwnd, &origin)) return;
screen.x -= origin.x;
screen.y -= origin.y;
input.type = INPUT_MOUSE;
input.mi.dx = screen.x;
input.mi.dy = screen.y;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
TRACE("hwnd=%p wayland_dxdy=%.2f,%.2f screen_dxdy=%d,%d\n",
hwnd, wl_fixed_to_double(dx), wl_fixed_to_double(dy),
(int)screen.x, (int)screen.y);
__wine_send_input(hwnd, &input, NULL);
}
static const struct zwp_relative_pointer_v1_listener relative_pointer_v1_listener =
{
relative_pointer_v1_relative_motion
};
void wayland_pointer_init(struct wl_pointer *wl_pointer)
{
struct wayland_pointer *pointer = &process_wayland.pointer;
......@@ -251,6 +338,11 @@ void wayland_pointer_deinit(void)
zwp_confined_pointer_v1_destroy(pointer->zwp_confined_pointer_v1);
pointer->zwp_confined_pointer_v1 = NULL;
}
if (pointer->zwp_relative_pointer_v1)
{
zwp_relative_pointer_v1_destroy(pointer->zwp_relative_pointer_v1);
pointer->zwp_relative_pointer_v1 = NULL;
}
wl_pointer_release(pointer->wl_pointer);
pointer->wl_pointer = NULL;
pointer->focused_hwnd = NULL;
......@@ -558,6 +650,8 @@ static void wayland_set_cursor(HWND hwnd, HCURSOR hcursor, BOOL use_hcursor)
struct wayland_pointer *pointer = &process_wayland.pointer;
struct wayland_surface *surface;
double scale;
RECT clip;
BOOL reapply_clip = FALSE;
if ((surface = wayland_surface_lock_hwnd(hwnd)))
{
......@@ -580,8 +674,13 @@ static void wayland_set_cursor(HWND hwnd, HCURSOR hcursor, BOOL use_hcursor)
pointer->cursor.hotspot_x,
pointer->cursor.hotspot_y);
wl_display_flush(process_wayland.wl_display);
reapply_clip = TRUE;
}
pthread_mutex_unlock(&pointer->mutex);
/* Reapply cursor clip since cursor visibility affects pointer constraint
* behavior. */
if (reapply_clip && NtUserGetClipCursor(&clip)) NtUserClipCursor(&clip);
}
/**********************************************************************
......@@ -630,6 +729,7 @@ static void wayland_pointer_update_constraint(RECT *confine_rect,
struct wl_surface *wl_surface)
{
struct wayland_pointer *pointer = &process_wayland.pointer;
BOOL needs_relative;
assert(!confine_rect || wl_surface);
......@@ -677,6 +777,27 @@ static void wayland_pointer_update_constraint(RECT *confine_rect,
pointer->zwp_confined_pointer_v1 = NULL;
pointer->constraint_hwnd = NULL;
}
needs_relative = !pointer->cursor.wl_surface &&
pointer->constraint_hwnd &&
pointer->constraint_hwnd == pointer->focused_hwnd;
if (needs_relative && !pointer->zwp_relative_pointer_v1)
{
pointer->zwp_relative_pointer_v1 =
zwp_relative_pointer_manager_v1_get_relative_pointer(
process_wayland.zwp_relative_pointer_manager_v1,
pointer->wl_pointer);
zwp_relative_pointer_v1_add_listener(pointer->zwp_relative_pointer_v1,
&relative_pointer_v1_listener, NULL);
TRACE("Enabling relative motion\n");
}
else if (!needs_relative && pointer->zwp_relative_pointer_v1)
{
zwp_relative_pointer_v1_destroy(pointer->zwp_relative_pointer_v1);
pointer->zwp_relative_pointer_v1 = NULL;
TRACE("Disabling relative motion\n");
}
}
void wayland_pointer_clear_constraint(void)
......
......@@ -30,6 +30,7 @@
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbregistry.h>
#include "pointer-constraints-unstable-v1-client-protocol.h"
#include "relative-pointer-unstable-v1-client-protocol.h"
#include "viewporter-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
......@@ -91,6 +92,7 @@ struct wayland_pointer
{
struct wl_pointer *wl_pointer;
struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1;
struct zwp_relative_pointer_v1 *zwp_relative_pointer_v1;
HWND focused_hwnd;
HWND constraint_hwnd;
uint32_t enter_serial;
......@@ -119,6 +121,7 @@ struct wayland
struct wp_viewporter *wp_viewporter;
struct wl_subcompositor *wl_subcompositor;
struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1;
struct zwp_relative_pointer_manager_v1 *zwp_relative_pointer_manager_v1;
struct wayland_seat seat;
struct wayland_keyboard keyboard;
struct wayland_pointer pointer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment