commit 27f27f1
Michael Forney
·
2013-06-14 08:58:02 +0000 UTC
parent 9b80eea
Use our own structs (removed in libwayland)
+4,
-0
1@@ -14,7 +14,11 @@ libswc_la_SOURCES = \
2 surface.c surface.h \
3 region.c region.h \
4 renderer.c renderer.h \
5+ keyboard.c keyboard.h \
6+ pointer.c pointer.h \
7 seat.c seat.h \
8+ data_device_manager.c data_device_manager.h \
9+ data_device.c data_device.h \
10 mode.c mode.h \
11 tty.c tty.h \
12 evdev_device.c evdev_device.h \
+37,
-39
1@@ -8,6 +8,8 @@
2 #include "output.h"
3 #include "surface.h"
4 #include "event.h"
5+#include "region.h"
6+#include "data_device_manager.h"
7
8 const char default_seat[] = "seat0";
9
10@@ -52,12 +54,10 @@ static void schedule_repaint_for_output(struct swc_compositor * compositor,
11 output->repaint_scheduled = true;
12 }
13
14-static void handle_key(struct wl_keyboard_grab * grab, uint32_t time,
15+static bool handle_key(struct swc_keyboard * keyboard, uint32_t time,
16 uint32_t key, uint32_t state)
17 {
18- struct wl_keyboard * keyboard = grab->keyboard;
19 struct swc_seat * seat;
20- struct wl_resource * resource = keyboard->focus_resource;
21 struct swc_binding * binding;
22 struct swc_compositor * compositor;
23 char keysym_name[64];
24@@ -73,38 +73,44 @@ static void handle_key(struct wl_keyboard_grab * grab, uint32_t time,
25
26 wl_array_for_each(binding, &compositor->key_bindings)
27 {
28- if (binding->value == keysym && (binding->modifiers == SWC_MOD_ANY
29- || binding->modifiers == seat->active_modifiers))
30+ if (binding->value == keysym)
31 {
32- binding->handler(time, keysym, binding->data);
33- return;
34+ xkb_mod_mask_t mod_mask;
35+ uint32_t modifiers = 0;
36+ mod_mask = xkb_state_serialize_mods(seat->xkb.state,
37+ XKB_STATE_MODS_EFFECTIVE);
38+ mod_mask = xkb_state_mod_mask_remove_consumed(seat->xkb.state, key + 8,
39+ mod_mask);
40+
41+ if (mod_mask & (1 << seat->xkb.indices.ctrl))
42+ modifiers |= SWC_MOD_CTRL;
43+ if (mod_mask & (1 << seat->xkb.indices.alt))
44+ modifiers |= SWC_MOD_ALT;
45+ if (mod_mask & (1 << seat->xkb.indices.super))
46+ modifiers |= SWC_MOD_SUPER;
47+ if (mod_mask & (1 << seat->xkb.indices.shift))
48+ modifiers |= SWC_MOD_SHIFT;
49+
50+ if (binding->modifiers == SWC_MOD_ANY
51+ || binding->modifiers == modifiers)
52+ {
53+ binding->handler(time, keysym, binding->data);
54+ printf("\t-> handled\n");
55+ return true;
56+ }
57 }
58 }
59 }
60
61- if (resource)
62- {
63- struct wl_display * display;
64- uint32_t serial;
65-
66- display = wl_client_get_display(resource->client);
67- serial = wl_display_next_serial(display);
68- wl_keyboard_send_key(resource, serial, time, key, state);
69- }
70-}
71-
72-static void handle_modifiers(struct wl_keyboard_grab * grab, uint32_t serial,
73- uint32_t mods_depressed, uint32_t mods_latched,
74- uint32_t mods_locked, uint32_t group)
75-{
76- //wl_keyboard_send_modifiers
77+ return false;
78 }
79
80-struct wl_keyboard_grab_interface binding_grab_interface = {
81+struct swc_keyboard_handler keyboard_handler = {
82 .key = &handle_key,
83- .modifiers = &handle_modifiers
84 };
85
86+
87+
88 /* XXX: maybe this should go in swc_drm */
89 static void handle_tty_event(struct wl_listener * listener, void * data)
90 {
91@@ -196,19 +202,10 @@ static void create_surface(struct wl_client * client,
92 wl_list_insert(&compositor->surfaces, &surface->link);
93 surface->output_mask |= 1 << output->id;
94
95- /* For some reason there is no Wayland method to initialize a preallocated
96- * resource. */
97- surface->wayland.resource = (struct wl_resource) {
98- .object = {
99- .interface = &wl_surface_interface,
100- .implementation = (void (**)()) &swc_surface_interface,
101- .id = id
102- },
103- .destroy = &destroy_surface,
104- .data = surface
105- };
106-
107- wl_client_add_resource(client, &surface->wayland.resource);
108+ surface->resource
109+ = wl_client_add_object(client, &wl_surface_interface,
110+ &swc_surface_interface, id, surface);
111+ wl_resource_set_destructor(surface->resource, &destroy_surface);
112 }
113
114 static void create_region(struct wl_client * client,
115@@ -284,7 +281,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
116 }
117
118 swc_seat_add_event_sources(&compositor->seat, event_loop);
119- compositor->seat.keyboard.default_grab.interface = &binding_grab_interface;
120+ compositor->seat.keyboard.handler = &keyboard_handler;
121
122 /* TODO: configurable seat */
123 if (!swc_drm_initialize(&compositor->drm, compositor->udev, default_seat))
124@@ -393,6 +390,7 @@ void swc_compositor_add_globals(struct swc_compositor * compositor,
125 wl_display_add_global(display, &wl_compositor_interface, compositor,
126 &bind_compositor);
127
128+ swc_data_device_manager_add_globals(display);
129 swc_seat_add_globals(&compositor->seat, display);
130
131 wl_list_for_each(output, &compositor->outputs, link)
+27,
-0
1@@ -0,0 +1,27 @@
2+#include "data_device.h"
3+
4+static void start_drag(struct wl_client * client, struct wl_resource * resource,
5+ struct wl_resource * source_resource,
6+ struct wl_resource * origin_resource,
7+ struct wl_resource * icon_resource, uint32_t serial)
8+{
9+}
10+
11+static void set_selection(struct wl_client * client,
12+ struct wl_resource * resource,
13+ struct wl_resource * source_resource, uint32_t serial)
14+{
15+}
16+
17+struct wl_data_device_interface data_device_implementation = {
18+ .start_drag = &start_drag,
19+ .set_selection = &set_selection
20+};
21+
22+void swc_data_device_initialize(struct wl_client * client, uint32_t id,
23+ struct swc_seat * seat)
24+{
25+ wl_client_add_object(client, &wl_data_device_interface,
26+ &data_device_implementation, id, NULL);
27+}
28+
+12,
-0
1@@ -0,0 +1,12 @@
2+#ifndef SWC_DATA_DEVICE_H
3+#define SWC_DATA_DEVICE_H 1
4+
5+#include <wayland-server.h>
6+
7+struct swc_seat;
8+
9+void swc_data_device_initialize(struct wl_client * client, uint32_t id,
10+ struct swc_seat * seat);
11+
12+#endif
13+
+41,
-0
1@@ -0,0 +1,41 @@
2+#include "data_device_manager.h"
3+#include "data_device.h"
4+
5+#include <stdio.h>
6+
7+static void create_data_source(struct wl_client * client,
8+ struct wl_resource * resource, uint32_t id)
9+{
10+}
11+
12+static void get_data_device(struct wl_client * client,
13+ struct wl_resource * resource, uint32_t id,
14+ struct wl_resource * seat_resource)
15+{
16+ struct swc_seat * seat = seat_resource->data;
17+
18+ printf("get_data_device\n");
19+
20+ // TODO: keep track of resource?
21+ swc_data_device_initialize(client, id, seat);
22+}
23+
24+static struct wl_data_device_manager_interface
25+data_device_manager_implementation = {
26+ .create_data_source = &create_data_source,
27+ .get_data_device = &get_data_device
28+};
29+
30+static void bind_data_device_manager(struct wl_client * client, void * data,
31+ uint32_t version, uint32_t id)
32+{
33+ wl_client_add_object(client, &wl_data_device_manager_interface,
34+ &data_device_manager_implementation, id, NULL);
35+}
36+
37+void swc_data_device_manager_add_globals(struct wl_display * display)
38+{
39+ wl_display_add_global(display, &wl_data_device_manager_interface, NULL,
40+ &bind_data_device_manager);
41+}
42+
+9,
-0
1@@ -0,0 +1,9 @@
2+#ifndef SWC_DATA_DEVICE_MANAGER_H
3+#define SWC_DATA_DEVICE_MANAGER_H 1
4+
5+#include <wayland-server.h>
6+
7+void swc_data_device_manager_add_globals(struct wl_display * display);
8+
9+#endif
10+
+84,
-0
1@@ -0,0 +1,84 @@
2+#include "keyboard.h"
3+#include "util.h"
4+
5+#include <stdio.h>
6+
7+bool swc_keyboard_initialize(struct swc_keyboard * keyboard)
8+{
9+ wl_list_init(&keyboard->resources);
10+ wl_array_init(&keyboard->keys);
11+ //wl_signal_init(&keyboard->focus_signal); // ?
12+
13+ keyboard->focus.surface = NULL;
14+ keyboard->focus.resource = NULL;
15+
16+ return true;
17+}
18+
19+void swc_keyboard_finish(struct swc_keyboard * keyboard)
20+{
21+ wl_array_release(&keyboard->keys);
22+}
23+
24+void swc_keyboard_set_focus(struct swc_keyboard * keyboard,
25+ struct swc_surface * surface)
26+{
27+ struct wl_client * client;
28+ struct wl_display * display;
29+ struct wl_resource * resource;
30+ uint32_t serial;
31+
32+ /* Unfocus previously focused surface. */
33+ if (keyboard->focus.resource && keyboard->focus.surface != surface)
34+ {
35+ client = wl_resource_get_client(keyboard->focus.surface->resource);
36+ display = wl_client_get_display(client);
37+ serial = wl_display_next_serial(display);
38+ wl_keyboard_send_leave(keyboard->focus.resource, serial,
39+ keyboard->focus.surface->resource);
40+ }
41+
42+ /* Focus new surface, if given. */
43+ if (surface)
44+ {
45+ client = wl_resource_get_client(surface->resource);
46+ resource = swc_find_resource_for_client(&keyboard->resources, client);
47+
48+ printf("keyboard: focusing surface: %p\n", surface);
49+
50+ if (resource)
51+ {
52+ display = wl_client_get_display(client);
53+ serial = wl_display_next_serial(display);
54+ wl_keyboard_send_enter(resource, serial, surface->resource,
55+ &keyboard->keys);
56+
57+ keyboard->focus.resource = resource;
58+ }
59+ else
60+ keyboard->focus.resource = NULL;
61+
62+ keyboard->focus.surface = surface;
63+ }
64+ else
65+ {
66+ keyboard->focus.surface = NULL;
67+ keyboard->focus.resource = NULL;
68+ }
69+}
70+
71+struct wl_resource * swc_keyboard_bind(struct swc_keyboard * keyboard,
72+ struct wl_client * client, uint32_t id)
73+{
74+ struct wl_resource * client_resource;
75+
76+ client_resource = wl_client_add_object(client, &wl_keyboard_interface,
77+ NULL, id, NULL);
78+ wl_resource_set_destructor(client_resource, &swc_unbind_resource);
79+ wl_list_insert(&keyboard->resources, &client_resource->link);
80+
81+ printf("keyboard: adding client %p, resource: %p\n", client, client_resource);
82+
83+ return client_resource;
84+}
85+
+53,
-0
1@@ -0,0 +1,53 @@
2+#ifndef SWC_KEYBOARD_H
3+#define SWC_KEYBOARD_H 1
4+
5+#include "surface.h"
6+
7+#include <wayland-server.h>
8+
9+struct swc_keyboard;
10+
11+struct swc_keyboard_handler
12+{
13+ bool (* key)(struct swc_keyboard * keyboard, uint32_t time,
14+ uint32_t key, uint32_t state);
15+ bool (* modifiers)(struct swc_keyboard * keyboyard, uint32_t serial,
16+ uint32_t mods_depressed, uint32_t mods_latched,
17+ uint32_t mods_locked, uint32_t group);
18+};
19+
20+struct swc_keyboard
21+{
22+ struct wl_list resources;
23+
24+ struct
25+ {
26+ struct swc_surface * surface;
27+ struct wl_resource * resource;
28+ } focus;
29+
30+ //struct wl_listener focus_listener;
31+ //struct wl_signal focus_signal;
32+
33+ struct swc_keyboard_handler * handler;
34+
35+ struct wl_array keys;
36+
37+ struct
38+ {
39+ uint32_t mods_depressed;
40+ uint32_t mods_latched;
41+ uint32_t mods_locked;
42+ uint32_t group;
43+ } modifiers;
44+};
45+
46+bool swc_keyboard_initialize(struct swc_keyboard * keyboard);
47+void swc_keyboard_finish(struct swc_keyboard * keyboard);
48+void swc_keyboard_set_focus(struct swc_keyboard * keyboard,
49+ struct swc_surface * surface);
50+struct wl_resource * swc_keyboard_bind(struct swc_keyboard * keyboard,
51+ struct wl_client * client, uint32_t id);
52+
53+#endif
54+
+115,
-0
1@@ -0,0 +1,115 @@
2+#include "pointer.h"
3+#include "util.h"
4+#include "event.h"
5+
6+#include <stdio.h>
7+
8+bool swc_pointer_initialize(struct swc_pointer * pointer)
9+{
10+ wl_list_init(&pointer->resources);
11+ wl_signal_init(&pointer->event_signal);
12+
13+ pointer->x = wl_fixed_from_int(0);
14+ pointer->y = wl_fixed_from_int(0);
15+
16+ pointer->focus.surface = NULL;
17+ pointer->focus.resource = NULL;
18+
19+ return true;
20+}
21+
22+void swc_pointer_finish(struct swc_pointer * pointer)
23+{
24+}
25+
26+void swc_pointer_set_focus(struct swc_pointer * pointer,
27+ struct swc_surface * surface)
28+{
29+ struct wl_client * client;
30+ struct wl_display * display;
31+ struct wl_resource * resource;
32+ uint32_t serial;
33+
34+ /* Unfocus previously focused surface. */
35+ if (pointer->focus.resource && pointer->focus.surface != surface)
36+ {
37+ client = wl_resource_get_client(pointer->focus.surface->resource);
38+ display = wl_client_get_display(client);
39+ serial = wl_display_next_serial(display);
40+ wl_pointer_send_leave(pointer->focus.resource, serial,
41+ pointer->focus.surface->resource);
42+ }
43+
44+ /* Focus new surface, if given. */
45+ if (surface)
46+ {
47+ client = wl_resource_get_client(surface->resource);
48+ resource = swc_find_resource_for_client(&pointer->resources, client);
49+
50+ printf("pointer: focusing surface: %p\n", surface);
51+
52+ if (resource)
53+ {
54+ uint32_t surface_x, surface_y;
55+
56+ surface_x = wl_fixed_to_int(pointer->x) - surface->geometry.x;
57+ surface_y = wl_fixed_to_int(pointer->y) - surface->geometry.y;
58+
59+ display = wl_client_get_display(client);
60+ serial = wl_display_next_serial(display);
61+ wl_pointer_send_enter(resource, serial, surface->resource,
62+ wl_fixed_from_int(surface_x),
63+ wl_fixed_from_int(surface_y));
64+
65+ pointer->focus.resource = resource;
66+ }
67+
68+ pointer->focus.surface = surface;
69+ }
70+ else
71+ {
72+ pointer->focus.surface = NULL;
73+ pointer->focus.resource = NULL;
74+ }
75+}
76+
77+static void set_cursor(struct wl_client * client,
78+ struct wl_resource * resource, uint32_t serial,
79+ struct wl_resource * surface_resource,
80+ int32_t hotspot_x, int32_t hotspot_y)
81+{
82+ struct swc_pointer * pointer = resource->data;
83+ struct swc_surface * surface = surface_resource->data;
84+ struct swc_event event;
85+
86+ printf("set_cursor\n");
87+
88+ pointer->cursor.surface = surface;
89+ pointer->cursor.hotspot_x = hotspot_x;
90+ pointer->cursor.hotspot_y = hotspot_y;
91+
92+ event.type = SWC_POINTER_CURSOR_CHANGED;
93+ event.data = surface;
94+
95+ wl_signal_emit(&pointer->event_signal, &event);
96+}
97+
98+struct wl_pointer_interface pointer_implementation = {
99+ .set_cursor = &set_cursor
100+};
101+
102+struct wl_resource * swc_pointer_bind(struct swc_pointer * pointer,
103+ struct wl_client * client, uint32_t id)
104+{
105+ struct wl_resource * client_resource;
106+
107+ printf("pointer: adding client %p\n", client);
108+
109+ client_resource = wl_client_add_object(client, &wl_pointer_interface,
110+ &pointer_implementation, id, pointer);
111+ wl_resource_set_destructor(client_resource, &swc_unbind_resource);
112+ wl_list_insert(&pointer->resources, &client_resource->link);
113+
114+ return client_resource;
115+}
116+
+58,
-0
1@@ -0,0 +1,58 @@
2+#ifndef SWC_POINTER_H
3+#define SWC_POINTER_H 1
4+
5+#include "surface.h"
6+
7+#include <wayland-server.h>
8+
9+struct swc_pointer;
10+
11+struct swc_pointer_handler
12+{
13+ void (* focus)(struct swc_pointer * pointer);
14+ void (* motion)(struct swc_pointer * pointer, uint32_t time);
15+ void (* button)(struct swc_pointer * pointer, uint32_t time,
16+ uint32_t button, uint32_t state);
17+};
18+
19+enum swc_pointer_event
20+{
21+ SWC_POINTER_CURSOR_CHANGED
22+};
23+
24+struct swc_pointer
25+{
26+ struct wl_list resources;
27+
28+ struct
29+ {
30+ struct swc_surface * surface;
31+ struct wl_resource * resource;
32+ } focus;
33+
34+ //uint32_t focus_serial;
35+ //struct wl_signal focus_signal;
36+ struct wl_signal event_signal;
37+
38+ struct
39+ {
40+ struct swc_surface * surface;
41+ int32_t hotspot_x, hotspot_y;
42+ } cursor;
43+
44+ struct swc_pointer_handler * handler;
45+
46+ wl_fixed_t x, y;
47+
48+ uint32_t button_count;
49+};
50+
51+bool swc_pointer_initialize(struct swc_pointer * pointer);
52+void swc_pointer_finish(struct swc_pointer * pointer);
53+void swc_pointer_set_focus(struct swc_pointer * pointer,
54+ struct swc_surface * surface);
55+struct wl_resource * swc_pointer_bind(struct swc_pointer * pointer,
56+ struct wl_client * client, uint32_t id);
57+
58+#endif
59+
M
seat.c
+58,
-45
1@@ -22,12 +22,20 @@ static void bind_seat(struct wl_client * client, void * data, uint32_t version,
2
3 resource = wl_client_add_object(client, &wl_seat_interface,
4 &swc_seat_interface, id, seat);
5- wl_list_insert(&seat->wayland.base_resource_list, &resource->link);
6- resource->destroy = &swc_unbind_resource;
7+ wl_list_insert(&seat->resources, &resource->link);
8+ wl_resource_set_destructor(resource, &swc_unbind_resource);
9
10 wl_seat_send_capabilities(resource, seat->capabilities);
11 }
12
13+static void update_capabilities(struct swc_seat * seat)
14+{
15+ struct wl_resource * resource;
16+
17+ wl_list_for_each(resource, &seat->resources, link)
18+ wl_seat_send_capabilities(resource, seat->capabilities);
19+}
20+
21 static void add_device(struct swc_seat * seat, struct udev_device * udev_device)
22 {
23 const char * device_seat;
24@@ -55,16 +63,18 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device)
25 && evdev_device->capabilities & WL_SEAT_CAPABILITY_POINTER)
26 {
27 printf("initializing pointer\n");
28- wl_pointer_init(&seat->pointer);
29- wl_seat_set_pointer(&seat->wayland, &seat->pointer);
30+ swc_pointer_initialize(&seat->pointer);
31+ seat->capabilities |= WL_SEAT_CAPABILITY_POINTER;
32+ update_capabilities(seat);
33 }
34
35 if (!(seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
36 && evdev_device->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
37 {
38 printf("initializing keyboard\n");
39- wl_keyboard_init(&seat->keyboard);
40- wl_seat_set_keyboard(&seat->wayland, &seat->keyboard);
41+ swc_keyboard_initialize(&seat->keyboard);
42+ seat->capabilities |= WL_SEAT_CAPABILITY_KEYBOARD;
43+ update_capabilities(seat);
44 }
45
46 seat->capabilities |= evdev_device->capabilities;
47@@ -75,11 +85,8 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device)
48 bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev,
49 const char * seat_name)
50 {
51- wl_seat_init(&seat->wayland);
52-
53 seat->name = strdup(seat_name);
54 seat->capabilities = 0;
55- seat->active_modifiers = 0;
56
57 if (!swc_xkb_initialize(&seat->xkb))
58 {
59@@ -87,6 +94,8 @@ bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev,
60 goto error_name;
61 }
62
63+ wl_list_init(&seat->resources);
64+ wl_signal_init(&seat->destroy_signal);
65 wl_list_init(&seat->devices);
66 swc_seat_add_devices(seat, udev);
67
68@@ -102,7 +111,14 @@ void swc_seat_finish(struct swc_seat * seat)
69 {
70 struct swc_evdev_device * device, * tmp;
71
72- wl_seat_release(&seat->wayland);
73+ wl_signal_emit(&seat->destroy_signal, seat);
74+
75+ if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
76+ swc_keyboard_finish(&seat->keyboard);
77+
78+ if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER)
79+ swc_pointer_finish(&seat->pointer);
80+
81 free(seat->name);
82 swc_xkb_finish(&seat->xkb);
83
84@@ -157,8 +173,10 @@ void swc_seat_handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
85 uint32_t state)
86 {
87 uint32_t * pressed_key;
88- struct wl_keyboard * keyboard = &seat->keyboard;
89+ struct swc_keyboard * keyboard = &seat->keyboard;
90 struct swc_xkb * xkb = &seat->xkb;
91+ struct wl_display * display;
92+ uint32_t serial;
93 enum xkb_key_direction direction;
94
95 /* Update XKB state */
96@@ -170,8 +188,8 @@ void swc_seat_handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
97
98 if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
99 {
100- keyboard->grab_key = key;
101- keyboard->grab_time = time;
102+ //keyboard->grab_key = key;
103+ //keyboard->grab_time = time;
104 pressed_key = wl_array_add(&keyboard->keys, sizeof key);
105 *pressed_key = key;
106 }
107@@ -191,10 +209,21 @@ void swc_seat_handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
108 }
109 }
110
111- keyboard->grab->interface->key(keyboard->grab, time, key, state);
112+ /* See if the key press is not handled by the compositor */
113+ if (!(keyboard->handler && keyboard->handler->key)
114+ || !keyboard->handler->key(keyboard, time, key, state))
115+ {
116+ if (keyboard->focus.resource)
117+ {
118+ serial = wl_display_next_serial(display);
119+ wl_keyboard_send_key(keyboard->focus.resource, serial, time, key, state);
120+
121+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
122+ printf("\t-> sent to client\n");
123+ }
124+ }
125
126 {
127- struct wl_keyboard * keyboard = &seat->keyboard;
128 uint32_t mods_depressed, mods_latched, mods_locked, mods_active;
129 uint32_t layout;
130
131@@ -216,17 +245,6 @@ void swc_seat_handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
132 keyboard->modifiers.mods_latched = mods_latched;
133 keyboard->modifiers.mods_locked = mods_locked;
134 keyboard->modifiers.group = layout;
135-
136- seat->active_modifiers = 0;
137-
138- if (mods_active & (1 << xkb->indices.ctrl))
139- seat->active_modifiers |= MOD_CTRL;
140- if (mods_active & (1 << xkb->indices.alt))
141- seat->active_modifiers |= MOD_ALT;
142- if (mods_active & (1 << xkb->indices.super))
143- seat->active_modifiers |= MOD_SUPER;
144- if (mods_active & (1 << xkb->indices.shift))
145- seat->active_modifiers |= MOD_SHIFT;
146 }
147 }
148
149@@ -239,20 +257,15 @@ void swc_seat_handle_button(struct swc_seat * seat, uint32_t time,
150 void swc_seat_get_pointer(struct wl_client * client,
151 struct wl_resource * resource, uint32_t id)
152 {
153- struct wl_resource * client_resource;
154 struct swc_seat * seat = resource->data;
155- struct wl_pointer * pointer = &seat->pointer;
156-
157- /* pointer interface? */
158- client_resource = wl_client_add_object(client, &wl_pointer_interface,
159- NULL, id, seat);
160- client_resource->destroy = &swc_unbind_resource;
161+ struct swc_pointer * pointer = &seat->pointer;
162
163- wl_list_insert(&pointer->resource_list, &client_resource->link);
164+ swc_pointer_bind(pointer, client, id);
165
166- if (pointer->focus && pointer->focus->resource.client == client)
167+ if (pointer->focus.surface
168+ && wl_resource_get_client(pointer->focus.surface->resource) == client)
169 {
170- //wl_pointer_set_focus(pointer, pointer->focus);
171+ swc_pointer_set_focus(pointer, pointer->focus.surface);
172 }
173 }
174
175@@ -260,20 +273,20 @@ void swc_seat_get_keyboard(struct wl_client * client,
176 struct wl_resource * resource, uint32_t id)
177 {
178 struct wl_resource * client_resource;
179- struct swc_seat * seat = resource->data;
180- struct wl_keyboard * keyboard = &seat->keyboard;
181-
182- client_resource = wl_client_add_object(client, &wl_keyboard_interface,
183- NULL, id, seat);
184- client_resource->destroy = &swc_unbind_resource;
185+ struct swc_seat * seat = wl_resource_get_user_data(resource);
186+ struct swc_keyboard * keyboard = &seat->keyboard;
187
188- wl_list_insert(&keyboard->resource_list, &client_resource->link);
189+ client_resource = swc_keyboard_bind(keyboard, client, id);
190
191 wl_keyboard_send_keymap(client_resource, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
192 seat->xkb.keymap.fd, seat->xkb.keymap.size);
193
194- if (keyboard->focus && keyboard->focus->resource.client == client)
195- wl_keyboard_set_focus(keyboard, keyboard->focus);
196+ if (keyboard->focus.surface
197+ && wl_resource_get_client(keyboard->focus.surface->resource) == client)
198+ {
199+ printf("focusing\n");
200+ swc_keyboard_set_focus(keyboard, keyboard->focus.surface);
201+ }
202 }
203
204 void swc_seat_get_touch(struct wl_client * client,
M
seat.h
+7,
-6
1@@ -2,6 +2,8 @@
2 #define SWC_SEAT_H 1
3
4 #include "xkb.h"
5+#include "keyboard.h"
6+#include "pointer.h"
7
8 #include <stdint.h>
9 #include <stdbool.h>
10@@ -10,17 +12,16 @@
11
12 struct swc_seat
13 {
14- struct wl_seat wayland;
15-
16 char * name;
17+ uint32_t capabilities;
18
19 struct swc_xkb xkb;
20
21- struct wl_keyboard keyboard;
22- struct wl_pointer pointer;
23+ struct wl_list resources;
24+ struct wl_signal destroy_signal;
25
26- uint32_t active_modifiers;
27- uint32_t capabilities;
28+ struct swc_keyboard keyboard;
29+ struct swc_pointer pointer;
30
31 struct wl_list devices;
32 };
+2,
-1
1@@ -31,7 +31,7 @@ struct swc_surface_state
2
3 struct swc_surface
4 {
5- struct wl_surface wayland;
6+ struct wl_resource * resource;
7
8 struct swc_surface_state state;
9
10@@ -46,6 +46,7 @@ struct swc_surface
11
12 struct
13 {
14+ uint32_t x, y;
15 uint32_t width, height;
16 } geometry;
17