1#include <gtk/gtk.h>
2
3static void
4test_list_seats (void)
5{
6 GdkDisplay *display;
7 GdkSeat *seat0, *seat;
8 GList *list, *l;
9 gboolean found_default;
10
11 display = gdk_display_get_default ();
12 seat0 = gdk_display_get_default_seat (display);
13 if (seat0 != NULL)
14 g_assert_true (GDK_IS_SEAT (seat0));
15
16 found_default = FALSE;
17 list = gdk_display_list_seats (display);
18
19 for (l = list; l; l = l->next)
20 {
21 seat = l->data;
22
23 g_assert_true (GDK_IS_SEAT (seat));
24 g_assert_true (gdk_seat_get_display (seat) == display);
25
26 if (seat == seat0)
27 found_default = TRUE;
28 }
29
30 if (seat0 != NULL)
31 g_assert_true (found_default);
32 else
33 g_assert_true (list == NULL);
34
35 g_list_free (list);
36}
37
38static void
39test_default_seat (void)
40{
41 GdkDisplay *display, *d;
42 GdkSeat *seat0;
43 GdkSeatCapabilities caps;
44 GdkDevice *pointer0, *keyboard0, *device;
45 GList *physical_devices, *tools, *l;
46 GdkDeviceTool *tool;
47
48 display = gdk_display_get_default ();
49 seat0 = gdk_display_get_default_seat (display);
50
51 if (seat0 == NULL)
52 {
53 g_test_skip (msg: "Display has no seats");
54 return;
55 }
56
57 g_assert_true (GDK_IS_SEAT (seat0));
58
59 g_assert_true (gdk_seat_get_display (seat0) == display);
60 g_object_get (object: seat0, first_property_name: "display", &d, NULL);
61 g_assert_true (display == d);
62 g_object_unref (object: d);
63
64 caps = gdk_seat_get_capabilities (seat: seat0);
65
66 g_assert_true (caps != GDK_SEAT_CAPABILITY_NONE);
67
68 pointer0 = gdk_seat_get_pointer (seat: seat0);
69 physical_devices = gdk_seat_get_devices (seat: seat0, capabilities: GDK_SEAT_CAPABILITY_POINTER);
70
71 if ((caps & GDK_SEAT_CAPABILITY_POINTER) != 0)
72 {
73 g_assert_nonnull (pointer0);
74 g_assert_true (gdk_device_get_display (pointer0) == display);
75 g_assert_true (gdk_device_get_seat (pointer0) == seat0);
76
77 g_assert_nonnull (physical_devices);
78 for (l = physical_devices; l; l = l->next)
79 {
80 device = l->data;
81 g_assert_true (gdk_device_get_display (device) == display);
82 g_assert_true (gdk_device_get_seat (device) == seat0);
83 }
84 g_list_free (list: physical_devices);
85 }
86 else
87 {
88 g_assert_null (pointer0);
89 g_assert_null (physical_devices);
90 }
91
92 keyboard0 = gdk_seat_get_keyboard (seat: seat0);
93 physical_devices = gdk_seat_get_devices (seat: seat0, capabilities: GDK_SEAT_CAPABILITY_KEYBOARD);
94
95 if ((caps & GDK_SEAT_CAPABILITY_KEYBOARD) != 0)
96 {
97 g_assert_nonnull (keyboard0);
98 g_assert_true (gdk_device_get_display (keyboard0) == display);
99 g_assert_true (gdk_device_get_seat (keyboard0) == seat0);
100 g_assert_true (gdk_device_get_source (keyboard0) == GDK_SOURCE_KEYBOARD);
101
102 g_assert_nonnull (physical_devices);
103 for (l = physical_devices; l; l = l->next)
104 {
105 device = l->data;
106 g_assert_true (gdk_device_get_display (device) == display);
107 g_assert_true (gdk_device_get_seat (device) == seat0);
108 g_assert_true (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD);
109 }
110 g_list_free (list: physical_devices);
111 }
112 else
113 {
114 g_assert_null (keyboard0);
115 g_assert_null (physical_devices);
116 }
117
118 tools = gdk_seat_get_tools (seat: seat0);
119 for (l = tools; l; l = l->next)
120 {
121 tool = l->data;
122 g_assert_true (GDK_IS_DEVICE_TOOL (tool));
123 }
124 g_list_free (list: tools);
125}
126
127int
128main (int argc, char *argv[])
129{
130 (g_test_init) (argc: &argc, argv: &argv, NULL);
131
132 gtk_init ();
133
134 g_test_add_func (testpath: "/seat/list", test_func: test_list_seats);
135 g_test_add_func (testpath: "/seat/default", test_func: test_default_seat);
136
137 return g_test_run ();
138}
139

source code of gtk/testsuite/gdk/seat.c