[gtk+/wip/wayland-tablet: 626/632] wayland: Refactor master pointer data into a separate struct
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/wayland-tablet: 626/632] wayland: Refactor master pointer data into a separate struct
- Date: Tue, 1 Mar 2016 11:47:37 +0000 (UTC)
commit a3d3698a820d9de5cdcc41979976cce3422c2a00
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jun 19 17:25:54 2015 +0200
wayland: Refactor master pointer data into a separate struct
This will enable multiple "pointers" to have separate data here.
Will come out useful when adding support for tablets, as they
will have a separate cursor for all purposes.
gdk/wayland/gdkdevice-wayland.c | 519 +++++++++++++++++++++------------------
1 files changed, 283 insertions(+), 236 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 9b085ad..9c2dd72 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -44,6 +44,7 @@
typedef struct _GdkWaylandTouchData GdkWaylandTouchData;
typedef struct _GdkWaylandPointerFrameData GdkWaylandPointerFrameData;
+typedef struct _GdkWaylandPointerData GdkWaylandPointerData;
struct _GdkWaylandTouchData
{
@@ -65,6 +66,33 @@ struct _GdkWaylandPointerFrameData
gint8 is_scroll_stop;
};
+struct _GdkWaylandPointerData {
+ GdkWindow *focus;
+
+ double surface_x, surface_y;
+
+ GdkModifierType button_modifiers;
+
+ uint32_t time;
+ uint32_t enter_serial;
+ uint32_t press_serial;
+
+ GdkWindow *grab_window;
+ uint32_t grab_time;
+
+ struct wl_surface *pointer_surface;
+ GdkCursor *cursor;
+ guint cursor_timeout_id;
+ guint cursor_image_index;
+ guint cursor_image_delay;
+
+ guint current_output_scale;
+ GSList *pointer_surface_outputs;
+
+ /* Accumulated event data for a pointer frame */
+ GdkWaylandPointerFrameData frame;
+};
+
struct _GdkWaylandSeat
{
GdkSeat parent_instance;
@@ -91,17 +119,14 @@ struct _GdkWaylandSeat
GHashTable *touches;
+ GdkWaylandPointerData pointer_info;
+ GdkWaylandPointerData touch_info;
+
GdkModifierType key_modifiers;
- GdkModifierType button_modifiers;
- GdkWindow *pointer_focus;
GdkWindow *keyboard_focus;
GdkAtom pending_selection;
- double surface_x, surface_y;
- uint32_t time;
- uint32_t enter_serial;
- uint32_t button_press_serial;
- GdkWindow *pointer_grab_window;
- uint32_t pointer_grab_time;
+ GdkWindow *grab_window;
+ uint32_t grab_time;
gboolean have_server_repeat;
uint32_t server_repeat_rate;
uint32_t server_repeat_delay;
@@ -110,18 +135,10 @@ struct _GdkWaylandSeat
guint32 repeat_count;
GSettings *keyboard_settings;
- guint cursor_timeout_id;
- guint cursor_image_index;
- guint cursor_image_delay;
-
struct gtk_primary_selection_device *primary_data_device;
struct wl_data_device *data_device;
GdkDragContext *drop_context;
- struct wl_surface *pointer_surface;
- guint current_output_scale;
- GSList *pointer_surface_outputs;
-
/* Source/dest for non-local dnd */
GdkWindow *foreign_dnd_window;
@@ -130,9 +147,6 @@ struct _GdkWaylandSeat
gdouble gesture_scale;
GdkCursor *grab_cursor;
-
- /* Accumulated event data for a pointer frame */
- GdkWaylandPointerFrameData pointer_frame;
};
G_DEFINE_TYPE (GdkWaylandSeat, gdk_wayland_seat, GDK_TYPE_SEAT)
@@ -142,6 +156,7 @@ struct _GdkWaylandDevice
GdkDevice parent_instance;
GdkWaylandDeviceData *device;
GdkWaylandTouchData *emulating_touch; /* Only used on wd->touch_master */
+ GdkWaylandPointerData *pointer;
};
struct _GdkWaylandDeviceClass
@@ -209,90 +224,87 @@ gdk_wayland_device_get_state (GdkDevice *device,
}
static void
-gdk_wayland_device_stop_window_cursor_animation (GdkWaylandDeviceData *wd)
+gdk_wayland_pointer_stop_cursor_animation (GdkWaylandPointerData *pointer)
{
- if (wd->cursor_timeout_id > 0)
+ if (pointer->cursor_timeout_id > 0)
{
- g_source_remove (wd->cursor_timeout_id);
- wd->cursor_timeout_id = 0;
+ g_source_remove (pointer->cursor_timeout_id);
+ pointer->cursor_timeout_id = 0;
}
- wd->cursor_image_index = 0;
- wd->cursor_image_delay = 0;
+
+ pointer->cursor_image_index = 0;
}
static gboolean
-gdk_wayland_device_update_window_cursor (GdkWaylandDeviceData *wd)
+gdk_wayland_device_update_window_cursor (GdkDevice *device)
{
+ GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device));
+ GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
struct wl_buffer *buffer;
int x, y, w, h, scale;
guint next_image_index, next_image_delay;
gboolean retval = G_SOURCE_REMOVE;
- if (wd->cursor)
+ if (pointer->cursor)
{
- buffer = _gdk_wayland_cursor_get_buffer (wd->cursor, wd->cursor_image_index,
+ buffer = _gdk_wayland_cursor_get_buffer (pointer->cursor,
+ pointer->cursor_image_index,
&x, &y, &w, &h, &scale);
}
else
{
- wd->cursor_timeout_id = 0;
- return retval;
+ pointer->cursor_timeout_id = 0;
+ return TRUE;
}
- if (!wd->wl_pointer)
+ if (!seat->wl_pointer)
return retval;
+ wl_pointer_set_cursor (seat->wl_pointer,
+ pointer->enter_serial,
+ pointer->pointer_surface,
+ x, y);
if (buffer)
{
- wl_surface_attach (wd->pointer_surface, buffer, 0, 0);
- wl_surface_set_buffer_scale (wd->pointer_surface, scale);
- wl_surface_damage (wd->pointer_surface, 0, 0, w, h);
- wl_surface_commit (wd->pointer_surface);
-
- wl_pointer_set_cursor (wd->wl_pointer,
- wd->enter_serial,
- wd->pointer_surface,
- x, y);
+ wl_surface_attach (pointer->pointer_surface, buffer, 0, 0);
+ wl_surface_set_buffer_scale (pointer->pointer_surface, scale);
+ wl_surface_damage (pointer->pointer_surface, 0, 0, w, h);
+ wl_surface_commit (pointer->pointer_surface);
}
else
{
- wl_pointer_set_cursor (wd->wl_pointer,
- wd->enter_serial,
- NULL,
- 0, 0);
-
- wl_surface_attach (wd->pointer_surface, NULL, 0, 0);
- wl_surface_commit (wd->pointer_surface);
+ wl_surface_attach (pointer->pointer_surface, NULL, 0, 0);
+ wl_surface_commit (pointer->pointer_surface);
}
next_image_index =
- _gdk_wayland_cursor_get_next_image_index (wd->cursor,
- wd->cursor_image_index,
+ _gdk_wayland_cursor_get_next_image_index (pointer->cursor,
+ pointer->cursor_image_index,
&next_image_delay);
- if (next_image_index != wd->cursor_image_index)
+ if (next_image_index != pointer->cursor_image_index)
{
- if (next_image_delay != wd->cursor_image_delay)
+ if (next_image_delay != pointer->cursor_image_delay)
{
guint id;
- gdk_wayland_device_stop_window_cursor_animation (wd);
+ gdk_wayland_pointer_stop_cursor_animation (pointer);
/* Queue timeout for next frame */
id = g_timeout_add (next_image_delay,
(GSourceFunc)gdk_wayland_device_update_window_cursor,
- wd);
+ device);
g_source_set_name_by_id (id, "[gtk+] gdk_wayland_device_update_window_cursor");
- wd->cursor_timeout_id = id;
+ pointer->cursor_timeout_id = id;
}
else
retval = G_SOURCE_CONTINUE;
- wd->cursor_image_index = next_image_index;
- wd->cursor_image_delay = next_image_delay;
+ pointer->cursor_image_index = next_image_index;
+ pointer->cursor_image_delay = next_image_delay;
}
else
- gdk_wayland_device_stop_window_cursor_animation (wd);
+ gdk_wayland_pointer_stop_cursor_animation (pointer);
return retval;
}
@@ -303,6 +315,7 @@ gdk_wayland_device_set_window_cursor (GdkDevice *device,
GdkCursor *cursor)
{
GdkWaylandDeviceData *wd = GDK_WAYLAND_DEVICE (device)->device;
+ GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
if (device == wd->touch_master)
return;
@@ -315,26 +328,26 @@ gdk_wayland_device_set_window_cursor (GdkDevice *device,
*/
if (!cursor)
{
- guint scale = wd->current_output_scale;
+ guint scale = pointer->current_output_scale;
cursor =
_gdk_wayland_display_get_cursor_for_type_with_scale (wd->display,
GDK_LEFT_PTR,
scale);
}
else
- _gdk_wayland_cursor_set_scale (cursor, wd->current_output_scale);
+ _gdk_wayland_cursor_set_scale (cursor, pointer->current_output_scale);
- if (cursor == wd->cursor)
+ if (cursor == pointer->cursor)
return;
- gdk_wayland_device_stop_window_cursor_animation (wd);
+ gdk_wayland_pointer_stop_cursor_animation (pointer);
- if (wd->cursor)
- g_object_unref (wd->cursor);
+ if (pointer->cursor)
+ g_object_unref (pointer->cursor);
- wd->cursor = g_object_ref (cursor);
+ pointer->cursor = g_object_ref (cursor);
- gdk_wayland_device_update_window_cursor (wd);
+ gdk_wayland_device_update_window_cursor (device);
}
static void
@@ -346,30 +359,31 @@ gdk_wayland_device_warp (GdkDevice *device,
}
static void
-get_coordinates (GdkWaylandDeviceData *data,
- double *x,
- double *y,
- double *x_root,
- double *y_root)
+get_coordinates (GdkDevice *device,
+ double *x,
+ double *y,
+ double *x_root,
+ double *y_root)
{
+ GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
int root_x, root_y;
if (x)
- *x = data->surface_x;
+ *x = pointer->surface_x;
if (y)
- *y = data->surface_y;
+ *y = pointer->surface_y;
- if (data->pointer_focus)
+ if (pointer->focus)
{
- gdk_window_get_root_coords (data->pointer_focus,
- data->surface_x,
- data->surface_y,
+ gdk_window_get_root_coords (pointer->focus,
+ pointer->surface_x,
+ pointer->surface_y,
&root_x, &root_y);
}
else
{
- root_x = data->surface_x;
- root_y = data->surface_y;
+ root_x = pointer->surface_x;
+ root_y = pointer->surface_y;
}
if (x_root)
@@ -378,6 +392,21 @@ get_coordinates (GdkWaylandDeviceData *data,
*y_root = root_y;
}
+static GdkModifierType
+device_get_modifiers (GdkDevice *device)
+{
+ GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device));
+ GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
+ GdkModifierType mask;
+
+ mask = seat->key_modifiers;
+
+ if (pointer)
+ mask |= pointer->button_modifiers;
+
+ return mask;
+}
+
static void
gdk_wayland_device_query_state (GdkDevice *device,
GdkWindow *window,
@@ -390,19 +419,21 @@ gdk_wayland_device_query_state (GdkDevice *device,
GdkModifierType *mask)
{
GdkWaylandDeviceData *wd;
+ GdkWaylandPointerData *pointer;
GdkScreen *default_screen;
wd = GDK_WAYLAND_DEVICE (device)->device;
+ pointer = GDK_WAYLAND_DEVICE (device)->pointer;
default_screen = gdk_display_get_default_screen (wd->display);
if (root_window)
*root_window = gdk_screen_get_root_window (default_screen);
if (child_window)
- *child_window = wd->pointer_focus;
+ *child_window = pointer->focus;
if (mask)
- *mask = wd->button_modifiers | wd->key_modifiers;
+ *mask = device_get_modifiers (device);
- get_coordinates (wd, win_x, win_y, root_x, root_y);
+ get_coordinates (device, win_x, win_y, root_x, root_y);
}
static void
@@ -509,16 +540,19 @@ static GdkWindow *
gdk_wayland_device_get_focus (GdkDevice *device)
{
GdkWaylandSeat *wayland_seat = GDK_WAYLAND_DEVICE (device)->device;
+ GdkWaylandPointerData *pointer;
if (device == wayland_seat->master_keyboard)
return wayland_seat->keyboard_focus;
- else if (device == wayland_seat->master_pointer)
- return wayland_seat->pointer_focus;
- else if (device == wayland_seat->touch_master &&
- GDK_WAYLAND_DEVICE(device)->emulating_touch)
- return GDK_WAYLAND_DEVICE(device)->emulating_touch->window;
else
- return NULL;
+ {
+ pointer = GDK_WAYLAND_DEVICE (device)->pointer;
+
+ if (pointer)
+ return pointer->focus;
+ }
+
+ return NULL;
}
static GdkGrabStatus
@@ -532,6 +566,7 @@ gdk_wayland_device_grab (GdkDevice *device,
{
GdkWaylandDeviceData *wayland_device = GDK_WAYLAND_DEVICE (device)->device;
GdkWindow *prev_focus = gdk_wayland_device_get_focus (device);
+ GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
if (prev_focus != window)
device_emit_grab_crossing (device, prev_focus, window, GDK_CROSSING_GRAB, time_);
@@ -544,17 +579,17 @@ gdk_wayland_device_grab (GdkDevice *device,
else
{
/* Device is a pointer */
- if (wayland_device->pointer_grab_window != NULL &&
- time_ != 0 && wayland_device->pointer_grab_time > time_)
+ if (pointer->grab_window != NULL &&
+ time_ != 0 && pointer->grab_time > time_)
{
return GDK_GRAB_ALREADY_GRABBED;
}
if (time_ == 0)
- time_ = wayland_device->time;
+ time_ = pointer->time;
- wayland_device->pointer_grab_window = window;
- wayland_device->pointer_grab_time = time_;
+ pointer->grab_window = window;
+ pointer->grab_time = time_;
_gdk_wayland_window_set_grab_seat (window, GDK_SEAT (wayland_device));
g_clear_object (&wayland_device->cursor);
@@ -562,7 +597,7 @@ gdk_wayland_device_grab (GdkDevice *device,
if (cursor)
wayland_device->cursor = g_object_ref (cursor);
- gdk_wayland_device_update_window_cursor (wayland_device);
+ gdk_wayland_device_update_window_cursor (device);
}
return GDK_GRAB_SUCCESS;
@@ -572,7 +607,7 @@ static void
gdk_wayland_device_ungrab (GdkDevice *device,
guint32 time_)
{
- GdkWaylandDeviceData *wayland_device = GDK_WAYLAND_DEVICE (device)->device;
+ GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
GdkDisplay *display;
GdkDeviceGrabInfo *grab;
GdkWindow *focus, *prev_focus = NULL;
@@ -599,10 +634,10 @@ gdk_wayland_device_ungrab (GdkDevice *device,
else
{
/* Device is a pointer */
- gdk_wayland_device_update_window_cursor (wayland_device);
+ gdk_wayland_device_update_window_cursor (device);
- if (wayland_device->pointer_grab_window)
- _gdk_wayland_window_set_grab_seat (wayland_device->pointer_grab_window,
+ if (pointer->grab_window)
+ _gdk_wayland_window_set_grab_seat (pointer->grab_window,
NULL);
}
}
@@ -614,46 +649,21 @@ gdk_wayland_device_window_at_position (GdkDevice *device,
GdkModifierType *mask,
gboolean get_toplevel)
{
- GdkWaylandDeviceData *wd;
- GdkWindow *window = NULL;
-
- wd = GDK_WAYLAND_DEVICE(device)->device;
-
- if (device == wd->master_pointer)
- {
- if (win_x)
- *win_x = wd->surface_x;
- if (win_y)
- *win_y = wd->surface_y;
+ GdkWaylandPointerData *pointer;
- if (mask)
- *mask |= wd->button_modifiers;
+ pointer = GDK_WAYLAND_DEVICE(device)->pointer;
- window = wd->pointer_focus;
- }
- else if (device == wd->touch_master)
- {
- GdkWaylandTouchData *touch;
-
- touch = GDK_WAYLAND_DEVICE(device)->emulating_touch;
-
- if (touch)
- {
- if (win_x)
- *win_x = touch->x;
- if (win_y)
- *win_y = touch->y;
- if (mask)
- *mask |= GDK_BUTTON1_MASK;
-
- window = touch->window;
- }
- }
+ if (!pointer)
+ return NULL;
+ if (win_x)
+ *win_x = pointer->surface_x;
+ if (win_y)
+ *win_y = pointer->surface_y;
if (mask)
- *mask = wd->key_modifiers;
+ *mask = device_get_modifiers (device);
- return window;
+ return pointer->focus;
}
static void
@@ -805,9 +815,9 @@ data_device_enter (void *data,
data_device, serial, surface, wl_fixed_to_double (x), wl_fixed_to_double (y), offer));
/* Update pointer state, so device state queries work during DnD */
- device->pointer_focus = g_object_ref (dest_window);
- device->surface_x = wl_fixed_to_double (x);
- device->surface_y = wl_fixed_to_double (y);
+ device->pointer_info.focus = g_object_ref (dest_window);
+ device->pointer_info.surface_x = wl_fixed_to_double (x);
+ device->pointer_info.surface_y = wl_fixed_to_double (y);
gdk_wayland_drop_context_update_targets (device->drop_context);
@@ -844,7 +854,8 @@ data_device_leave (void *data,
if (!gdk_drag_context_get_dest_window (device->drop_context))
return;
- device->pointer_focus = NULL;
+ g_object_unref (device->pointer_info.focus);
+ device->pointer_info.focus = NULL;
_gdk_wayland_drag_context_set_coords (device->drop_context, -1, -1);
_gdk_wayland_drag_context_emit_event (device->drop_context, GDK_DRAG_LEAVE,
@@ -868,8 +879,8 @@ data_device_motion (void *data,
return;
/* Update pointer state, so device state queries work during DnD */
- device->surface_x = wl_fixed_to_double (x);
- device->surface_y = wl_fixed_to_double (y);
+ device->pointer_info.surface_x = wl_fixed_to_double (x);
+ device->pointer_info.surface_y = wl_fixed_to_double (y);
gdk_wayland_drop_context_update_targets (device->drop_context);
_gdk_wayland_drag_context_set_coords (device->drop_context,
@@ -971,16 +982,16 @@ create_scroll_event (GdkWaylandSeat *seat,
GdkEvent *event;
event = gdk_event_new (GDK_SCROLL);
- event->scroll.window = g_object_ref (seat->pointer_focus);
+ event->scroll.window = g_object_ref (seat->pointer_info.focus);
gdk_event_set_device (event, seat->master_pointer);
gdk_event_set_source_device (event, seat->pointer);
- event->scroll.time = seat->time;
- event->scroll.state = seat->button_modifiers | seat->key_modifiers;
+ event->scroll.time = seat->pointer_info.time;
+ event->scroll.state = device_get_modifiers (seat->master_pointer);
gdk_event_set_screen (event, display->screen);
_gdk_event_set_pointer_emulated (event, emulated);
- get_coordinates (seat,
+ get_coordinates (seat->master_pointer,
&event->scroll.x,
&event->scroll.y,
&event->scroll.x_root,
@@ -1063,26 +1074,26 @@ flush_scroll_event (GdkWaylandSeat *seat,
static void
gdk_wayland_seat_flush_frame_event (GdkWaylandSeat *seat)
{
- if (seat->pointer_frame.event)
+ if (seat->pointer_info.frame.event)
{
_gdk_wayland_display_deliver_event (gdk_seat_get_display (GDK_SEAT (seat)),
- seat->pointer_frame.event);
- seat->pointer_frame.event = NULL;
+ seat->pointer_info.frame.event);
+ seat->pointer_info.frame.event = NULL;
}
else
- flush_scroll_event (seat, &seat->pointer_frame);
+ flush_scroll_event (seat, &seat->pointer_info.frame);
}
static GdkEvent *
gdk_wayland_seat_get_frame_event (GdkWaylandSeat *seat,
GdkEventType evtype)
{
- if (seat->pointer_frame.event &&
- seat->pointer_frame.event->type != evtype)
+ if (seat->pointer_info.frame.event &&
+ seat->pointer_info.frame.event->type != evtype)
gdk_wayland_seat_flush_frame_event (seat);
- seat->pointer_frame.event = gdk_event_new (evtype);
- return seat->pointer_frame.event;
+ seat->pointer_info.frame.event = gdk_event_new (evtype);
+ return seat->pointer_info.frame.event;
}
static void
@@ -1106,17 +1117,17 @@ pointer_handle_enter (void *data,
_gdk_wayland_display_update_serial (wayland_display, serial);
- device->pointer_focus = wl_surface_get_user_data(surface);
- g_object_ref(device->pointer_focus);
+ device->pointer_info.focus = wl_surface_get_user_data(surface);
+ g_object_ref(device->pointer_info.focus);
- device->button_modifiers = 0;
+ device->pointer_info.button_modifiers = 0;
- device->surface_x = wl_fixed_to_double (sx);
- device->surface_y = wl_fixed_to_double (sy);
- device->enter_serial = serial;
+ device->pointer_info.surface_x = wl_fixed_to_double (sx);
+ device->pointer_info.surface_y = wl_fixed_to_double (sy);
+ device->pointer_info.enter_serial = serial;
event = gdk_wayland_seat_get_frame_event (device, GDK_ENTER_NOTIFY);
- event->crossing.window = g_object_ref (device->pointer_focus);
+ event->crossing.window = g_object_ref (device->pointer_info.focus);
gdk_event_set_device (event, device->master_pointer);
gdk_event_set_source_device (event, device->pointer);
gdk_event_set_seat (event, gdk_device_get_seat (device->master_pointer));
@@ -1127,9 +1138,9 @@ pointer_handle_enter (void *data,
event->crossing.focus = TRUE;
event->crossing.state = 0;
- gdk_wayland_device_update_window_cursor (device);
+ gdk_wayland_device_update_window_cursor (device->master_pointer);
- get_coordinates (device,
+ get_coordinates (device->master_pointer,
&event->crossing.x,
&event->crossing.y,
&event->crossing.x_root,
@@ -1137,7 +1148,7 @@ pointer_handle_enter (void *data,
GDK_NOTE (EVENTS,
g_message ("enter, device %p surface %p",
- device, device->pointer_focus));
+ device, device->pointer_info.focus));
if (wayland_display->seat_version < WL_POINTER_HAS_FRAME)
gdk_wayland_seat_flush_frame_event (device);
@@ -1159,13 +1170,13 @@ pointer_handle_leave (void *data,
if (!GDK_IS_WINDOW (wl_surface_get_user_data (surface)))
return;
- if (!device->pointer_focus)
+ if (!device->pointer_info.focus)
return;
_gdk_wayland_display_update_serial (wayland_display, serial);
event = gdk_wayland_seat_get_frame_event (device, GDK_LEAVE_NOTIFY);
- event->crossing.window = g_object_ref (device->pointer_focus);
+ event->crossing.window = g_object_ref (device->pointer_info.focus);
gdk_event_set_device (event, device->master_pointer);
gdk_event_set_source_device (event, device->pointer);
gdk_event_set_seat (event, gdk_device_get_seat (device->master_pointer));
@@ -1176,9 +1187,9 @@ pointer_handle_leave (void *data,
event->crossing.focus = TRUE;
event->crossing.state = 0;
- gdk_wayland_device_update_window_cursor (device);
+ gdk_wayland_device_update_window_cursor (device->master_pointer);
- get_coordinates (device,
+ get_coordinates (device->master_pointer,
&event->crossing.x,
&event->crossing.y,
&event->crossing.x_root,
@@ -1186,13 +1197,14 @@ pointer_handle_leave (void *data,
GDK_NOTE (EVENTS,
g_message ("leave, device %p surface %p",
- device, device->pointer_focus));
+ device, device->pointer_info.focus));
- g_object_unref (device->pointer_focus);
+ g_object_unref (device->pointer_info.focus);
+ device->pointer_info.focus = NULL;
if (device->cursor)
- gdk_wayland_device_stop_window_cursor_animation (device);
+ gdk_wayland_pointer_stop_cursor_animation (&device->pointer_info);
- device->pointer_focus = NULL;
+ device->pointer_info.focus = NULL;
if (wayland_display->seat_version < WL_POINTER_HAS_FRAME)
gdk_wayland_seat_flush_frame_event (device);
@@ -1209,25 +1221,25 @@ pointer_handle_motion (void *data,
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
GdkEvent *event;
- if (!device->pointer_focus)
+ if (!device->pointer_info.focus)
return;
- device->time = time;
- device->surface_x = wl_fixed_to_double (sx);
- device->surface_y = wl_fixed_to_double (sy);
+ device->pointer_info.time = time;
+ device->pointer_info.surface_x = wl_fixed_to_double (sx);
+ device->pointer_info.surface_y = wl_fixed_to_double (sy);
event = gdk_wayland_seat_get_frame_event (device, GDK_MOTION_NOTIFY);
- event->motion.window = g_object_ref (device->pointer_focus);
+ event->motion.window = g_object_ref (device->pointer_info.focus);
gdk_event_set_device (event, device->master_pointer);
gdk_event_set_source_device (event, device->pointer);
gdk_event_set_seat (event, gdk_device_get_seat (device->master_pointer));
event->motion.time = time;
event->motion.axes = NULL;
- event->motion.state = device->button_modifiers | device->key_modifiers;
+ event->motion.state = device_get_modifiers (device->master_pointer);
event->motion.is_hint = 0;
gdk_event_set_screen (event, display->screen);
- get_coordinates (device,
+ get_coordinates (device->master_pointer,
&event->motion.x,
&event->motion.y,
&event->motion.x_root,
@@ -1256,7 +1268,7 @@ pointer_handle_button (void *data,
uint32_t modifier;
int gdk_button;
- if (!device->pointer_focus)
+ if (!device->pointer_info.focus)
return;
_gdk_wayland_display_update_serial (display, serial);
@@ -1278,24 +1290,24 @@ pointer_handle_button (void *data,
break;
}
- device->time = time;
+ device->pointer_info.time = time;
if (state)
- device->button_press_serial = serial;
+ device->pointer_info.press_serial = serial;
event = gdk_wayland_seat_get_frame_event (device,
state ? GDK_BUTTON_PRESS :
GDK_BUTTON_RELEASE);
- event->button.window = g_object_ref (device->pointer_focus);
+ event->button.window = g_object_ref (device->pointer_info.focus);
gdk_event_set_device (event, device->master_pointer);
gdk_event_set_source_device (event, device->pointer);
gdk_event_set_seat (event, gdk_device_get_seat (device->master_pointer));
event->button.time = time;
event->button.axes = NULL;
- event->button.state = device->button_modifiers | device->key_modifiers;
+ event->button.state = device_get_modifiers (device->master_pointer);
event->button.button = gdk_button;
gdk_event_set_screen (event, display->screen);
- get_coordinates (device,
+ get_coordinates (device->master_pointer,
&event->button.x,
&event->button.y,
&event->button.x_root,
@@ -1303,9 +1315,9 @@ pointer_handle_button (void *data,
modifier = 1 << (8 + gdk_button - 1);
if (state)
- device->button_modifiers |= modifier;
+ device->pointer_info.button_modifiers |= modifier;
else
- device->button_modifiers &= ~modifier;
+ device->pointer_info.button_modifiers &= ~modifier;
GDK_NOTE (EVENTS,
g_message ("button %d %s, device %p state %d",
@@ -1326,10 +1338,10 @@ pointer_handle_axis (void *data,
wl_fixed_t value)
{
GdkWaylandSeat *seat = data;
- GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_frame;
+ GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_info.frame;
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display);
- if (!seat->pointer_focus)
+ if (!seat->pointer_info.focus)
return;
/* get the delta and convert it into the expected range */
@@ -1345,7 +1357,7 @@ pointer_handle_axis (void *data,
g_return_if_reached ();
}
- seat->time = time;
+ seat->pointer_info.time = time;
GDK_NOTE (EVENTS,
g_message ("scroll, axis %d, value %f, seat %p",
@@ -1362,7 +1374,7 @@ pointer_handle_frame (void *data,
{
GdkWaylandSeat *seat = data;
- if (!seat->pointer_focus)
+ if (!seat->pointer_info.focus)
return;
GDK_NOTE (EVENTS,
@@ -1378,7 +1390,7 @@ pointer_handle_axis_source (void *data,
{
GdkWaylandSeat *seat = data;
- if (!seat->pointer_focus)
+ if (!seat->pointer_info.focus)
return;
/* We don't need to handle the scroll source right now. It only has real
@@ -1398,12 +1410,12 @@ pointer_handle_axis_stop (void *data,
uint32_t axis)
{
GdkWaylandSeat *seat = data;
- GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_frame;
+ GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_info.frame;
- if (!seat->pointer_focus)
+ if (!seat->pointer_info.focus)
return;
- seat->time = time;
+ seat->pointer_info.time = time;
switch (axis)
{
@@ -1430,9 +1442,9 @@ pointer_handle_axis_discrete (void *data,
int32_t value)
{
GdkWaylandSeat *seat = data;
- GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_frame;
+ GdkWaylandPointerFrameData *pointer_frame = &seat->pointer_info.frame;
- if (!seat->pointer_focus)
+ if (!seat->pointer_info.focus)
return;
switch (axis)
@@ -1713,7 +1725,7 @@ deliver_key_event (GdkWaylandDeviceData *device,
sym = xkb_state_key_get_one_sym (xkb_state, key);
- device->time = time_;
+ device->pointer_info.time = time_;
device->key_modifiers = gdk_keymap_get_modifier_state (keymap);
event = gdk_event_new (state ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
@@ -1722,7 +1734,7 @@ deliver_key_event (GdkWaylandDeviceData *device,
gdk_event_set_source_device (event, device->keyboard);
gdk_event_set_seat (event, gdk_device_get_seat (device->master_keyboard));
event->key.time = time_;
- event->key.state = device->button_modifiers | device->key_modifiers;
+ event->key.state = device_get_modifiers (device->master_pointer);
event->key.group = 0;
event->key.hardware_keycode = key;
event->key.keyval = sym;
@@ -1778,7 +1790,7 @@ keyboard_repeat (gpointer data)
{
GdkWaylandDeviceData *device = data;
- return deliver_key_event (device, device->time, device->repeat_key, 1);
+ return deliver_key_event (device, device->pointer_info.time, device->repeat_key, 1);
}
static void
@@ -1886,7 +1898,7 @@ _create_touch_event (GdkWaylandDeviceData *device,
gdk_event_set_source_device (event, device->touch);
gdk_event_set_seat (event, gdk_device_get_seat (device->touch_master));
event->touch.time = time;
- event->touch.state = device->button_modifiers | device->key_modifiers;
+ event->touch.state = device_get_modifiers (device->touch_master);
gdk_event_set_screen (event, display->screen);
event->touch.sequence = GDK_SLOT_TO_EVENT_SEQUENCE (touch->id);
@@ -1909,6 +1921,19 @@ _create_touch_event (GdkWaylandDeviceData *device,
}
static void
+mimic_pointer_emulating_touch_info (GdkDevice *device,
+ GdkWaylandTouchData *touch)
+{
+ GdkWaylandPointerData *pointer;
+
+ pointer = GDK_WAYLAND_DEVICE (device)->pointer;
+ g_set_object (&pointer->focus, touch->window);
+ pointer->press_serial = pointer->enter_serial = touch->touch_down_serial;
+ pointer->surface_x = touch->x;
+ pointer->surface_y = touch->y;
+}
+
+static void
touch_handle_down (void *data,
struct wl_touch *wl_touch,
uint32_t serial,
@@ -1937,7 +1962,9 @@ touch_handle_down (void *data,
emulate_touch_crossing (touch->window, NULL,
device->touch_master, device->touch, touch,
GDK_ENTER_NOTIFY, GDK_CROSSING_NORMAL, time);
+
GDK_WAYLAND_DEVICE(device->touch_master)->emulating_touch = touch;
+ mimic_pointer_emulating_touch_info (device->touch_master, touch);
}
GDK_NOTE (EVENTS,
@@ -1970,10 +1997,14 @@ touch_handle_up (void *data,
if (touch->initial_touch)
{
+ GdkWaylandPointerData *pointer_info;
+
emulate_touch_crossing (touch->window, NULL,
device->touch_master, device->touch, touch,
GDK_LEAVE_NOTIFY, GDK_CROSSING_NORMAL, time);
GDK_WAYLAND_DEVICE(device->touch_master)->emulating_touch = NULL;
+ pointer_info = GDK_WAYLAND_DEVICE (device->touch_master)->pointer;
+ g_clear_object (&pointer_info->focus);
}
gdk_wayland_device_remove_touch (device, id);
@@ -1995,6 +2026,9 @@ touch_handle_motion (void *data,
touch->x = wl_fixed_to_double (x);
touch->y = wl_fixed_to_double (y);
+ if (touch->initial_touch)
+ mimic_pointer_emulating_touch_info (device->touch_master, touch);
+
event = _create_touch_event (device, touch, GDK_TOUCH_UPDATE, time);
GDK_NOTE (EVENTS,
@@ -2052,25 +2086,25 @@ emit_gesture_swipe_event (GdkWaylandDeviceData *device,
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
GdkEvent *event;
- if (!device->pointer_focus)
+ if (!device->pointer_info.focus)
return;
- device->time = _time;
+ device->pointer_info.time = _time;
event = gdk_event_new (GDK_TOUCHPAD_SWIPE);
event->touchpad_swipe.phase = phase;
- event->touchpad_swipe.window = g_object_ref (device->pointer_focus);
+ event->touchpad_swipe.window = g_object_ref (device->pointer_info.focus);
gdk_event_set_device (event, device->master_pointer);
gdk_event_set_source_device (event, device->pointer);
gdk_event_set_seat (event, gdk_device_get_seat (device->master_pointer));
event->touchpad_swipe.time = _time;
- event->touchpad_swipe.state = device->button_modifiers | device->key_modifiers;
+ event->touchpad_swipe.state = device_get_modifiers (device->master_pointer);
gdk_event_set_screen (event, display->screen);
event->touchpad_swipe.dx = dx;
event->touchpad_swipe.dy = dy;
event->touchpad_swipe.n_fingers = n_fingers;
- get_coordinates (device,
+ get_coordinates (device->master_pointer,
&event->touchpad_swipe.x,
&event->touchpad_swipe.y,
&event->touchpad_swipe.x_root,
@@ -2155,19 +2189,19 @@ emit_gesture_pinch_event (GdkWaylandDeviceData *device,
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (device->display);
GdkEvent *event;
- if (!device->pointer_focus)
+ if (!device->pointer_info.focus)
return;
- device->time = _time;
+ device->pointer_info.time = _time;
event = gdk_event_new (GDK_TOUCHPAD_PINCH);
event->touchpad_pinch.phase = phase;
- event->touchpad_pinch.window = g_object_ref (device->pointer_focus);
+ event->touchpad_pinch.window = g_object_ref (device->pointer_info.focus);
gdk_event_set_device (event, device->master_pointer);
gdk_event_set_source_device (event, device->pointer);
gdk_event_set_seat (event, gdk_device_get_seat (device->master_pointer));
event->touchpad_pinch.time = _time;
- event->touchpad_pinch.state = device->button_modifiers | device->key_modifiers;
+ event->touchpad_pinch.state = device_get_modifiers (device->master_pointer);
gdk_event_set_screen (event, display->screen);
event->touchpad_pinch.dx = dx;
event->touchpad_pinch.dy = dy;
@@ -2175,7 +2209,7 @@ emit_gesture_pinch_event (GdkWaylandDeviceData *device,
event->touchpad_pinch.angle_delta = angle_delta * G_PI / 180;
event->touchpad_pinch.n_fingers = n_fingers;
- get_coordinates (device,
+ get_coordinates (device->master_pointer,
&event->touchpad_pinch.x,
&event->touchpad_pinch.y,
&event->touchpad_pinch.x_root,
@@ -2418,6 +2452,7 @@ seat_handle_capabilities (void *data,
"seat", device,
NULL);
GDK_WAYLAND_DEVICE (device->touch_master)->device = device;
+ GDK_WAYLAND_DEVICE (device->touch_master)->pointer = &device->touch_info;
_gdk_device_set_associated_device (device->touch_master, device->master_keyboard);
device_manager->devices =
@@ -2500,6 +2535,7 @@ init_devices (GdkWaylandDeviceData *device)
"seat", device,
NULL);
GDK_WAYLAND_DEVICE (device->master_pointer)->device = device;
+ GDK_WAYLAND_DEVICE (device->master_pointer)->pointer = &device->pointer_info;
device_manager->devices =
g_list_prepend (device_manager->devices, device->master_pointer);
@@ -2528,9 +2564,11 @@ init_devices (GdkWaylandDeviceData *device)
}
static void
-pointer_surface_update_scale (GdkWaylandDeviceData *device)
+pointer_surface_update_scale (GdkDevice *device)
{
- GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (device->display);
+ GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (gdk_device_get_seat (device));
+ GdkWaylandPointerData *pointer = GDK_WAYLAND_DEVICE (device)->pointer;
+ GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (seat->display);
guint32 scale;
GSList *l;
@@ -2541,7 +2579,7 @@ pointer_surface_update_scale (GdkWaylandDeviceData *device)
}
scale = 1;
- for (l = device->pointer_surface_outputs; l != NULL; l = l->next)
+ for (l = pointer->pointer_surface_outputs; l != NULL; l = l->next)
{
guint32 output_scale =
_gdk_wayland_screen_get_output_scale (wayland_display->screen,
@@ -2549,10 +2587,10 @@ pointer_surface_update_scale (GdkWaylandDeviceData *device)
scale = MAX (scale, output_scale);
}
- device->current_output_scale = scale;
+ pointer->current_output_scale = scale;
- if (device->cursor)
- _gdk_wayland_cursor_set_scale (device->cursor, scale);
+ if (pointer->cursor)
+ _gdk_wayland_cursor_set_scale (pointer->cursor, scale);
gdk_wayland_device_update_window_cursor (device);
}
@@ -2569,10 +2607,10 @@ pointer_surface_enter (void *data,
g_message ("pointer surface of device %p entered output %p",
device, output));
- device->pointer_surface_outputs =
- g_slist_append (device->pointer_surface_outputs, output);
+ device->pointer_info.pointer_surface_outputs =
+ g_slist_append (device->pointer_info.pointer_surface_outputs, output);
- pointer_surface_update_scale (device);
+ pointer_surface_update_scale (device->master_pointer);
}
static void
@@ -2586,10 +2624,10 @@ pointer_surface_leave (void *data,
g_message ("pointer surface of device %p left output %p",
device, output));
- device->pointer_surface_outputs =
- g_slist_remove (device->pointer_surface_outputs, output);
+ device->pointer_info.pointer_surface_outputs =
+ g_slist_remove (device->pointer_info.pointer_surface_outputs, output);
- pointer_surface_update_scale (device);
+ pointer_surface_update_scale (device->master_pointer);
}
static const struct wl_surface_listener pointer_surface_listener = {
@@ -2618,13 +2656,22 @@ create_foreign_dnd_window (GdkDisplay *display)
}
static void
+gdk_wayland_pointer_data_finalize (GdkWaylandPointerData *pointer)
+{
+ g_clear_object (&pointer->focus);
+ g_clear_object (&pointer->cursor);
+ wl_surface_destroy (pointer->pointer_surface);
+ g_slist_free (pointer->pointer_surface_outputs);
+}
+
+static void
gdk_wayland_seat_finalize (GObject *object)
{
GdkWaylandSeat *seat = GDK_WAYLAND_SEAT (object);
seat_handle_capabilities (seat, seat->wl_seat, 0);
g_object_unref (seat->keymap);
- wl_surface_destroy (seat->pointer_surface);
+ gdk_wayland_pointer_data_finalize (&seat->pointer_info);
/* FIXME: destroy data_device */
g_clear_object (&seat->keyboard_settings);
g_clear_object (&seat->drop_context);
@@ -2655,19 +2702,19 @@ static void
gdk_wayland_seat_set_grab_window (GdkWaylandSeat *seat,
GdkWindow *window)
{
- if (seat->pointer_grab_window)
+ if (seat->grab_window)
{
- _gdk_wayland_window_set_grab_seat (seat->pointer_grab_window, NULL);
- g_object_remove_weak_pointer (G_OBJECT (seat->pointer_grab_window),
- (gpointer *) &seat->pointer_grab_window);
- seat->pointer_grab_window = NULL;
+ _gdk_wayland_window_set_grab_seat (seat->grab_window, NULL);
+ g_object_remove_weak_pointer (G_OBJECT (seat->grab_window),
+ (gpointer *) &seat->grab_window);
+ seat->grab_window = NULL;
}
if (window)
{
- seat->pointer_grab_window = window;
+ seat->grab_window = window;
g_object_add_weak_pointer (G_OBJECT (window),
- (gpointer *) &seat->pointer_grab_window);
+ (gpointer *) &seat->grab_window);
_gdk_wayland_window_set_grab_seat (window, GDK_SEAT (seat));
}
}
@@ -2705,7 +2752,7 @@ gdk_wayland_seat_grab (GdkSeat *seat,
return GDK_GRAB_NOT_VIEWABLE;
gdk_wayland_seat_set_grab_window (wayland_seat, window);
- wayland_seat->pointer_grab_time = evtime;
+ wayland_seat->grab_time = evtime;
if (prepare_func)
(prepare_func) (seat, window, prepare_func_data);
@@ -2740,7 +2787,7 @@ gdk_wayland_seat_grab (GdkSeat *seat,
gdk_wayland_seat_set_global_cursor (seat, cursor);
g_set_object (&wayland_seat->cursor, cursor);
- gdk_wayland_device_update_window_cursor (wayland_seat);
+ gdk_wayland_device_update_window_cursor (wayland_seat->master_pointer);
}
if (wayland_seat->touch_master &&
@@ -2818,7 +2865,7 @@ gdk_wayland_seat_ungrab (GdkSeat *seat)
focus, GDK_CROSSING_UNGRAB,
GDK_CURRENT_TIME);
- gdk_wayland_device_update_window_cursor (wayland_seat);
+ gdk_wayland_device_update_window_cursor (wayland_seat->master_pointer);
}
if (wayland_seat->master_keyboard)
@@ -2936,10 +2983,10 @@ _gdk_wayland_device_manager_add_seat (GdkDeviceManager *device_manager,
wl_data_device_add_listener (seat->data_device,
&data_device_listener, seat);
- seat->current_output_scale = 1;
- seat->pointer_surface =
+ 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_surface,
+ wl_surface_add_listener (seat->pointer_info.pointer_surface,
&pointer_surface_listener,
seat);
@@ -3063,7 +3110,7 @@ _gdk_wayland_device_get_implicit_grab_serial (GdkWaylandDevice *device,
if (touch)
return touch->touch_down_serial;
else
- return device->device->button_press_serial;
+ return device->pointer->press_serial;
}
uint32_t
@@ -3081,8 +3128,8 @@ _gdk_wayland_seat_get_last_implicit_grab_serial (GdkSeat *seat,
if (sequence)
*sequence = NULL;
- if (wayland_seat->button_press_serial > serial)
- serial = wayland_seat->button_press_serial;
+ if (wayland_seat->pointer_info.press_serial > serial)
+ serial = wayland_seat->pointer_info.press_serial;
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &touch))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]