[gtk+/wip/garnacho/gdkseat: 6/14] x11: Use GdkSeatDefault to implement GdkSeat
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/garnacho/gdkseat: 6/14] x11: Use GdkSeatDefault to implement GdkSeat
- Date: Thu, 26 Nov 2015 19:28:06 +0000 (UTC)
commit 294d4bb112d04aa46171558aa5c9ced0852cb96c
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Nov 26 19:53:36 2015 +0100
x11: Use GdkSeatDefault to implement GdkSeat
gdk/x11/gdkdevicemanager-xi2.c | 117 ++++++++++++++++++++++++++++++++++------
1 files changed, 101 insertions(+), 16 deletions(-)
---
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 69e9b35..80140e2 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -28,6 +28,7 @@
#include "gdkintl.h"
#include "gdkkeysyms.h"
#include "gdkinternals.h"
+#include "gdkseatdefaultprivate.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -493,6 +494,37 @@ create_device (GdkDeviceManager *device_manager,
return device;
}
+static void
+ensure_seat_for_device_pair (GdkX11DeviceManagerXI2 *device_manager,
+ GdkDevice *device1,
+ GdkDevice *device2)
+{
+ GdkDevice *pointer, *keyboard;
+ GdkDisplay *display;
+ GdkSeat *seat;
+
+ display = gdk_device_manager_get_display (GDK_DEVICE_MANAGER (device_manager));
+ seat = gdk_device_get_seat (device1);
+
+ if (!seat)
+ {
+ if (gdk_device_get_source (device1) == GDK_SOURCE_KEYBOARD)
+ {
+ keyboard = device1;
+ pointer = device2;
+ }
+ else
+ {
+ pointer = device1;
+ keyboard = device2;
+ }
+
+ seat = gdk_seat_default_new_for_master_pair (pointer, keyboard);
+ gdk_display_add_seat (display, seat);
+ g_object_unref (seat);
+ }
+}
+
static GdkDevice *
add_device (GdkX11DeviceManagerXI2 *device_manager,
XIDeviceInfo *dev,
@@ -515,6 +547,7 @@ add_device (GdkX11DeviceManagerXI2 *device_manager,
if (dev->use == XISlavePointer || dev->use == XISlaveKeyboard)
{
GdkDevice *master;
+ GdkSeat *seat;
/* The device manager is already constructed, then
* keep the hierarchy coherent for the added device.
@@ -524,15 +557,48 @@ add_device (GdkX11DeviceManagerXI2 *device_manager,
_gdk_device_set_associated_device (device, master);
_gdk_device_add_slave (master, device);
+
+ seat = gdk_device_get_seat (master);
+ gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), device);
}
+ else if (dev->use == XIMasterPointer || dev->use == XIMasterKeyboard)
+ {
+ GdkDevice *relative;
+
+ relative = g_hash_table_lookup (device_manager->id_table,
+ GINT_TO_POINTER (dev->attachment));
- g_signal_emit_by_name (device_manager, "device-added", device);
+ if (relative)
+ {
+ _gdk_device_set_associated_device (device, relative);
+ _gdk_device_set_associated_device (relative, device);
+ ensure_seat_for_device_pair (device_manager, device, relative);
+ }
+ }
}
+ g_signal_emit_by_name (device_manager, "device-added", device);
+
return device;
}
static void
+detach_from_seat (GdkDevice *device)
+{
+ GdkSeat *seat = gdk_device_get_seat (device);
+
+ if (!seat)
+ return;
+
+ g_print ("AJOJOJOJOJ %s\n", gdk_device_get_name (device));
+
+ if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER)
+ gdk_display_remove_seat (gdk_device_get_display (device), seat);
+ else if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_SLAVE)
+ gdk_seat_default_remove_slave (GDK_SEAT_DEFAULT (seat), device);
+}
+
+static void
remove_device (GdkX11DeviceManagerXI2 *device_manager,
gint device_id)
{
@@ -543,6 +609,7 @@ remove_device (GdkX11DeviceManagerXI2 *device_manager,
if (device)
{
+ detach_from_seat (device);
device_manager->devices = g_list_remove (device_manager->devices, device);
g_signal_emit_by_name (device_manager, "device-removed", device);
@@ -568,6 +635,7 @@ relate_masters (gpointer key,
_gdk_device_set_associated_device (device, relative);
_gdk_device_set_associated_device (relative, device);
+ ensure_seat_for_device_pair (device_manager, device, relative);
}
static void
@@ -577,6 +645,7 @@ relate_slaves (gpointer key,
{
GdkX11DeviceManagerXI2 *device_manager;
GdkDevice *slave, *master;
+ GdkSeat *seat;
device_manager = user_data;
slave = g_hash_table_lookup (device_manager->id_table, key);
@@ -584,6 +653,9 @@ relate_slaves (gpointer key,
_gdk_device_set_associated_device (slave, master);
_gdk_device_add_slave (master, slave);
+
+ seat = gdk_device_get_seat (master);
+ gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), slave);
}
static void
@@ -812,6 +884,7 @@ handle_hierarchy_changed (GdkX11DeviceManagerXI2 *device_manager,
ev->info[i].flags & XISlaveDetached)
{
GdkDevice *master, *slave;
+ GdkSeat *seat;
slave = g_hash_table_lookup (device_manager->id_table,
GINT_TO_POINTER (ev->info[i].deviceid));
@@ -828,6 +901,9 @@ handle_hierarchy_changed (GdkX11DeviceManagerXI2 *device_manager,
_gdk_device_set_associated_device (slave, NULL);
g_signal_emit_by_name (device_manager, "device-changed", master);
+
+ seat = gdk_device_get_seat (master);
+ gdk_seat_default_remove_slave (GDK_SEAT_DEFAULT (seat), slave);
}
/* Add new master if it's an attachment event */
@@ -848,6 +924,9 @@ handle_hierarchy_changed (GdkX11DeviceManagerXI2 *device_manager,
_gdk_device_set_associated_device (slave, master);
_gdk_device_add_slave (master, slave);
+ seat = gdk_device_get_seat (master);
+ gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), slave);
+
g_signal_emit_by_name (device_manager, "device-changed", master);
}
}
@@ -1232,6 +1311,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
{
GdkX11DeviceManagerXI2 *device_manager;
XGenericEventCookie *cookie;
+ GdkDevice *device, *source_device;
gboolean return_val = TRUE;
GdkWindow *window;
GdkWindowImplX11 *impl;
@@ -1289,7 +1369,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
GdkModifierType consumed, state;
- GdkDevice *device, *source_device;
GDK_NOTE (EVENTS,
g_message ("key %s:\twindow %ld\n"
@@ -1320,6 +1399,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
event->key.keyval = GDK_KEY_VoidSymbol;
@@ -1349,7 +1429,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_ButtonRelease:
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
- GdkDevice *source_device;
GDK_NOTE (EVENTS,
g_message ("button %s:\twindow %ld\n"
@@ -1391,12 +1470,14 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
event->scroll.delta_x = 0;
event->scroll.delta_y = 0;
- event->scroll.device = g_hash_table_lookup (device_manager->id_table,
- GUINT_TO_POINTER (xev->deviceid));
+ device = g_hash_table_lookup (device_manager->id_table,
+ GUINT_TO_POINTER (xev->deviceid));
+ gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
event->scroll.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons,
&xev->group);
@@ -1416,12 +1497,14 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
event->button.x_root = (gdouble) xev->root_x / scale;
event->button.y_root = (gdouble) xev->root_y / scale;
- event->button.device = g_hash_table_lookup (device_manager->id_table,
- GUINT_TO_POINTER (xev->deviceid));
+ device = g_hash_table_lookup (device_manager->id_table,
+ GUINT_TO_POINTER (xev->deviceid));
+ gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
event->button.axes = translate_axes (event->button.device,
event->button.x,
@@ -1466,7 +1549,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_Motion:
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
- GdkDevice *source_device, *device;
gdouble delta_x, delta_y;
source_device = g_hash_table_lookup (device_manager->id_table,
@@ -1511,6 +1593,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
event->scroll.device = device;
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
event->scroll.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons,
&xev->group);
break;
@@ -1526,6 +1609,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
event->motion.device = device;
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
event->motion.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
@@ -1557,7 +1641,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_TouchEnd:
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
- GdkDevice *source_device;
GDK_NOTE(EVENTS,
g_message ("touch %s:\twindow %ld\n\ttouch id: %u\n\tpointer emulating: %s",
@@ -1578,12 +1661,14 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
event->touch.x_root = (gdouble) xev->root_x / scale;
event->touch.y_root = (gdouble) xev->root_y / scale;
- event->touch.device = g_hash_table_lookup (device_manager->id_table,
- GUINT_TO_POINTER (xev->deviceid));
+ device = g_hash_table_lookup (device_manager->id_table,
+ GUINT_TO_POINTER (xev->deviceid));
+ gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
event->touch.axes = translate_axes (event->touch.device,
event->touch.x,
@@ -1630,7 +1715,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_TouchUpdate:
{
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
- GdkDevice *source_device;
GDK_NOTE(EVENTS,
g_message ("touch update:\twindow %ld\n\ttouch id: %u\n\tpointer emulating: %s",
@@ -1647,12 +1731,14 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
event->touch.x_root = (gdouble) xev->root_x / scale;
event->touch.y_root = (gdouble) xev->root_y / scale;
- event->touch.device = g_hash_table_lookup (device_manager->id_table,
- GINT_TO_POINTER (xev->deviceid));
+ device = g_hash_table_lookup (device_manager->id_table,
+ GINT_TO_POINTER (xev->deviceid));
+ gdk_event_set_device (event, device);
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
event->touch.state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
@@ -1686,7 +1772,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
case XI_Leave:
{
XIEnterEvent *xev = (XIEnterEvent *) ev;
- GdkDevice *device, *source_device;
GDK_NOTE (EVENTS,
g_message ("%s notify:\twindow %ld\n\tsubwindow:%ld\n"
@@ -1716,6 +1801,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
source_device = g_hash_table_lookup (device_manager->id_table,
GUINT_TO_POINTER (xev->sourceid));
gdk_event_set_source_device (event, source_device);
+ gdk_event_set_seat (event, gdk_device_get_seat (device));
if (ev->evtype == XI_Enter &&
xev->detail != XINotifyInferior && xev->mode != XINotifyPassiveUngrab &&
@@ -1747,7 +1833,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
if (window)
{
XIEnterEvent *xev = (XIEnterEvent *) ev;
- GdkDevice *device, *source_device;
device = g_hash_table_lookup (device_manager->id_table,
GINT_TO_POINTER (xev->deviceid));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]