diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2019-04-18 19:31:55 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2019-04-18 18:05:19 +0200 |
commit | e9757b9afc08daab7c5f0823ff15fc0eab568af4 (patch) | |
tree | 0923126122883a67c68596d415e2098e10f1dd1c | |
parent | ceeb55eac298370e6a2a58bbedb148595e2de7b0 (diff) | |
download | gtk+-e9757b9afc08daab7c5f0823ff15fc0eab568af4.tar.gz |
gdk/wayland: Listen to wl_surface events on tablet cursors
And update the surface accordingly (eg. scale on hidpi). The mechanism
that did that for wl_pointer has been made generic so it can be shared
with tablets too.
Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1675
-rw-r--r-- | gdk/wayland/gdkdevice-wayland.c | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index fb3cfcb505..0d06141ff2 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -310,9 +310,14 @@ struct _GdkWaylandDeviceManagerClass GdkDeviceManagerClass parent_class; }; +static void init_pointer_data (GdkWaylandPointerData *pointer_data, + GdkDisplay *display_wayland, + GdkDevice *master); + static void pointer_surface_update_scale (GdkDevice *device); + static void deliver_key_event (GdkWaylandSeat *seat, uint32_t time_, uint32_t key, @@ -2971,6 +2976,8 @@ tablet_handle_done (void *data, g_list_prepend (device_manager->devices, tablet->master); g_signal_emit_by_name (device_manager, "device-added", master); + init_pointer_data (&tablet->pointer_info, display, tablet->master); + tablet->stylus_device = stylus_device; device_manager->devices = g_list_prepend (device_manager->devices, tablet->stylus_device); @@ -4446,14 +4453,11 @@ tablet_seat_handle_tablet_added (void *data, struct zwp_tablet_v2 *wp_tablet) { GdkWaylandSeat *seat = data; - GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (seat->display); GdkWaylandTabletData *tablet; tablet = g_new0 (GdkWaylandTabletData, 1); tablet->seat = GDK_SEAT (seat); - tablet->pointer_info.current_output_scale = 1; - tablet->pointer_info.pointer_surface = - wl_compositor_create_surface (display_wayland->compositor); + tablet->wp_tablet = wp_tablet; seat->tablets = g_list_prepend (seat->tablets, tablet); @@ -4598,16 +4602,28 @@ pointer_surface_enter (void *data, struct wl_output *output) { - GdkWaylandSeat *seat = data; + GdkDevice *device = data; + GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); + GdkWaylandTabletData *tablet; GDK_NOTE (EVENTS, g_message ("pointer surface of seat %p entered output %p", seat, output)); - seat->pointer_info.pointer_surface_outputs = - g_slist_append (seat->pointer_info.pointer_surface_outputs, output); + tablet = gdk_wayland_device_manager_find_tablet (seat, device); - pointer_surface_update_scale (seat->master_pointer); + if (tablet) + { + tablet->pointer_info.pointer_surface_outputs = + g_slist_append (seat->pointer_info.pointer_surface_outputs, output); + } + else + { + seat->pointer_info.pointer_surface_outputs = + g_slist_append (seat->pointer_info.pointer_surface_outputs, output); + } + + pointer_surface_update_scale (device); } static void @@ -4615,16 +4631,28 @@ pointer_surface_leave (void *data, struct wl_surface *wl_surface, struct wl_output *output) { - GdkWaylandSeat *seat = data; + GdkDevice *device = data; + GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device)); + GdkWaylandTabletData *tablet; GDK_NOTE (EVENTS, g_message ("pointer surface of seat %p left output %p", seat, output)); - seat->pointer_info.pointer_surface_outputs = - g_slist_remove (seat->pointer_info.pointer_surface_outputs, output); + tablet = gdk_wayland_device_manager_find_tablet (seat, device); - pointer_surface_update_scale (seat->master_pointer); + if (tablet) + { + tablet->pointer_info.pointer_surface_outputs = + g_slist_remove (seat->pointer_info.pointer_surface_outputs, output); + } + else + { + seat->pointer_info.pointer_surface_outputs = + g_slist_remove (seat->pointer_info.pointer_surface_outputs, output); + } + + pointer_surface_update_scale (device); } static const struct wl_surface_listener pointer_surface_listener = { @@ -4985,6 +5013,23 @@ gdk_wayland_seat_init (GdkWaylandSeat *seat) { } +static void +init_pointer_data (GdkWaylandPointerData *pointer_data, + GdkDisplay *display, + GdkDevice *master) +{ + GdkWaylandDisplay *display_wayland; + + display_wayland = GDK_WAYLAND_DISPLAY (display); + + pointer_data->current_output_scale = 1; + pointer_data->pointer_surface = + wl_compositor_create_surface (display_wayland->compositor); + wl_surface_add_listener (pointer_data->pointer_surface, + &pointer_surface_listener, + master); +} + void _gdk_wayland_device_manager_add_seat (GdkDeviceManager *device_manager, guint32 id, @@ -5031,14 +5076,8 @@ _gdk_wayland_device_manager_add_seat (GdkDeviceManager *device_manager, wl_data_device_add_listener (seat->data_device, &data_device_listener, seat); - seat->pointer_info.current_output_scale = 1; - seat->pointer_info.pointer_surface = - wl_compositor_create_surface (display_wayland->compositor); - wl_surface_add_listener (seat->pointer_info.pointer_surface, - &pointer_surface_listener, - seat); - init_devices (seat); + init_pointer_data (&seat->pointer_info, display, seat->master_pointer); if (display_wayland->tablet_manager) { |