swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 610fc7f52dc716802bf99c2d5b0f393d5139d9a0
parent 166eccd102941117e58a7889cf44630713ecefba
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 25 Nov 2013 18:02:13 -0800

Move seat-related stuff out of compositor.c

Diffstat:
Mlibswc/compositor.c | 43++++++++++++++-----------------------------
Mlibswc/compositor.h | 2--
Mlibswc/compositor_surface.c | 1+
Mlibswc/data_device_manager.c | 7++-----
Mlibswc/internal.h | 1+
Mlibswc/seat.c | 240++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mlibswc/seat.h | 67+++++++++++++++++++++++++++++--------------------------------------
Mlibswc/swc.c | 31++++++++++++++++++++++++-------
Mlibswc/window.c | 6++++--
9 files changed, 189 insertions(+), 209 deletions(-)

diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -3,13 +3,17 @@ #include "compositor_surface.h" #include "cursor_surface.h" #include "data_device_manager.h" +#include "internal.h" #include "output.h" +#include "pointer.h" #include "region.h" +#include "seat.h" #include "surface.h" #include "util.h" #include <stdlib.h> #include <stdio.h> +#include <xkbcommon/xkbcommon-keysyms.h> static const char default_seat[] = "seat0"; @@ -144,14 +148,11 @@ static void perform_update(void * data) static void handle_focus(struct swc_pointer * pointer) { - struct swc_seat * seat; - struct swc_compositor * compositor; + /* XXX: Temporary hack */ + struct swc_compositor * compositor = swc.compositor; struct swc_surface * surface; int32_t x, y; - seat = CONTAINER_OF(pointer, typeof(*seat), pointer); - compositor = CONTAINER_OF(seat, typeof(*compositor), seat); - wl_list_for_each(surface, &compositor->surfaces, link) { pixman_region32_t region; @@ -306,7 +307,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, struct wl_list * outputs; struct swc_output * output; pixman_region32_t pointer_region; - xkb_keysym_t keysym; + uint32_t keysym; compositor->display = display; compositor->drm_listener.notify = &handle_drm_event; @@ -322,22 +323,10 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, }; /* TODO: configurable seat */ - if (!swc_seat_initialize(&compositor->seat, default_seat)) - { - printf("could not initialize seat\n"); - goto error_base; - } - - swc_seat_add_event_sources(&compositor->seat, event_loop); - compositor->seat.pointer.handler = &compositor->pointer_handler; - wl_signal_add(&compositor->seat.pointer.event_signal, - &compositor->pointer_listener); - - /* TODO: configurable seat */ if (!swc_drm_initialize(&compositor->drm, default_seat)) { printf("could not initialize drm\n"); - goto error_seat; + goto error0; } wl_signal_add(&compositor->drm.event_signal, &compositor->drm_listener); @@ -346,7 +335,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, if (!swc_renderer_initialize(&compositor->renderer, &compositor->drm)) { printf("could not initialize renderer\n"); - goto error_drm; + goto error1; } outputs = swc_drm_create_outputs(&compositor->drm); @@ -360,7 +349,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, else { printf("could not create outputs\n"); - goto error_renderer; + goto error2; } /* Calculate pointer region */ @@ -374,7 +363,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, output->geometry.height); } - swc_pointer_set_region(&compositor->seat.pointer, &pointer_region); + swc_pointer_set_region(swc.seat->pointer, &pointer_region); pixman_region32_fini(&pointer_region); pixman_region32_init(&compositor->damage); @@ -396,13 +385,11 @@ bool swc_compositor_initialize(struct swc_compositor * compositor, return true; - error_renderer: + error2: swc_renderer_finalize(&compositor->renderer); - error_drm: + error1: swc_drm_finish(&compositor->drm); - error_seat: - swc_seat_finish(&compositor->seat); - error_base: + error0: return false; } @@ -419,7 +406,6 @@ void swc_compositor_finish(struct swc_compositor * compositor) } swc_drm_finish(&compositor->drm); - swc_seat_finish(&compositor->seat); } void swc_compositor_add_globals(struct swc_compositor * compositor, @@ -431,7 +417,6 @@ void swc_compositor_add_globals(struct swc_compositor * compositor, &bind_compositor); swc_data_device_manager_add_globals(display); - swc_seat_add_globals(&compositor->seat, display); swc_drm_add_globals(&compositor->drm, display); wl_list_for_each(output, &compositor->outputs, link) diff --git a/libswc/compositor.h b/libswc/compositor.h @@ -3,7 +3,6 @@ #include "drm.h" #include "pointer.h" -#include "seat.h" #include "renderer.h" #include <wayland-server.h> @@ -12,7 +11,6 @@ struct swc_compositor { struct wl_display * display; - struct swc_seat seat; struct swc_drm drm; struct swc_renderer renderer; diff --git a/libswc/compositor_surface.c b/libswc/compositor_surface.c @@ -23,6 +23,7 @@ #include "compositor_surface.h" #include "compositor.h" +#include "event.h" #include "util.h" #include <stdio.h> diff --git a/libswc/data_device_manager.c b/libswc/data_device_manager.c @@ -24,6 +24,7 @@ #include "data_device_manager.h" #include "data.h" #include "data_device.h" +#include "internal.h" #include "seat.h" static void create_data_source(struct wl_client * client, @@ -41,11 +42,7 @@ static void get_data_device(struct wl_client * client, struct wl_resource * resource, uint32_t id, struct wl_resource * seat_resource) { - struct swc_seat * seat = wl_resource_get_user_data(seat_resource); - - printf("data_device_manager.get_data_device\n"); - - swc_data_device_bind(&seat->data_device, client, id); + swc_data_device_bind(swc.seat->data_device, client, id); } static struct wl_data_device_manager_interface diff --git a/libswc/internal.h b/libswc/internal.h @@ -32,6 +32,7 @@ struct swc struct udev * udev; + const struct swc_seat_global * const seat; const struct swc_bindings_global * const bindings; struct swc_compositor * compositor; }; diff --git a/libswc/seat.c b/libswc/seat.c @@ -1,7 +1,10 @@ #include "seat.h" +#include "data_device.h" #include "evdev_device.h" #include "event.h" #include "internal.h" +#include "keyboard.h" +#include "pointer.h" #include "util.h" #include <stdlib.h> @@ -9,48 +12,63 @@ #include <string.h> #include <libudev.h> +#define SEAT_NAME "seat0" + +static struct +{ + char * name; + uint32_t capabilities; + + struct swc_keyboard keyboard; + struct swc_pointer pointer; + struct swc_data_device data_device; + + struct wl_global * global; + struct wl_list resources; + struct wl_list devices; +} seat; + +const struct swc_seat_global swc_seat_global = { + .pointer = &seat.pointer, + .keyboard = &seat.keyboard, + .data_device = &seat.data_device +}; + static void handle_key(const struct swc_evdev_device_handler * handler, uint32_t time, uint32_t key, uint32_t state) { - struct swc_seat * seat = CONTAINER_OF(handler, typeof(*seat), - evdev_handler); - - swc_keyboard_handle_key(&seat->keyboard, time, key, state); + swc_keyboard_handle_key(&seat.keyboard, time, key, state); } static void handle_button(const struct swc_evdev_device_handler * handler, uint32_t time, uint32_t button, uint32_t state) { - struct swc_seat * seat = CONTAINER_OF(handler, typeof(*seat), - evdev_handler); - - swc_pointer_handle_button(&seat->pointer, time, button, state); + swc_pointer_handle_button(&seat.pointer, time, button, state); } static void handle_axis(const struct swc_evdev_device_handler * handler, uint32_t time, uint32_t axis, wl_fixed_t amount) { - struct swc_seat * seat = CONTAINER_OF(handler, typeof(*seat), - evdev_handler); - - swc_pointer_handle_axis(&seat->pointer, time, axis, amount); + swc_pointer_handle_axis(&seat.pointer, time, axis, amount); } static void handle_relative_motion (const struct swc_evdev_device_handler * handler, uint32_t time, wl_fixed_t dx, wl_fixed_t dy) { - struct swc_seat * seat = CONTAINER_OF(handler, typeof(*seat), - evdev_handler); - - swc_pointer_handle_relative_motion(&seat->pointer, time, dx, dy); + swc_pointer_handle_relative_motion(&seat.pointer, time, dx, dy); } +const static struct swc_evdev_device_handler evdev_handler = { + .key = &handle_key, + .button = &handle_button, + .axis = &handle_axis, + .relative_motion = &handle_relative_motion +}; + static void handle_keyboard_focus_event(struct wl_listener * listener, void * data) { - struct swc_seat * seat = CONTAINER_OF(listener, typeof(*seat), - keyboard_focus_listener); struct swc_event * event = data; struct swc_input_focus_event_data * event_data = event->data; @@ -63,48 +81,48 @@ static void handle_keyboard_focus_event(struct wl_listener * listener, = wl_resource_get_client(event_data->new->resource); /* Offer the selection to the new focus. */ - swc_data_device_offer_selection(&seat->data_device, client); + swc_data_device_offer_selection(&seat.data_device, client); } break; } } +static struct wl_listener keyboard_focus_listener = { + .notify = &handle_keyboard_focus_event +}; + static void handle_data_device_event(struct wl_listener * listener, void * data) { - struct swc_seat * seat = CONTAINER_OF(listener, typeof(*seat), - data_device_listener); struct swc_event * event = data; switch (event->type) { case SWC_DATA_DEVICE_EVENT_SELECTION_CHANGED: - if (seat->keyboard.focus.resource) + if (seat.keyboard.focus.resource) { struct wl_client * client - = wl_resource_get_client(seat->keyboard.focus.resource); - swc_data_device_offer_selection(&seat->data_device, client); + = wl_resource_get_client(seat.keyboard.focus.resource); + swc_data_device_offer_selection(&seat.data_device, client); } break; } } +static struct wl_listener data_device_listener = { + .notify = &handle_data_device_event +}; + /* Wayland Seat Interface */ static void get_pointer(struct wl_client * client, struct wl_resource * resource, uint32_t id) { - struct swc_seat * seat = wl_resource_get_user_data(resource); - struct swc_pointer * pointer = &seat->pointer; - - swc_pointer_bind(pointer, client, id); + swc_pointer_bind(&seat.pointer, client, id); } static void get_keyboard(struct wl_client * client, struct wl_resource * resource, uint32_t id) { - struct swc_seat * seat = wl_resource_get_user_data(resource); - struct swc_keyboard * keyboard = &seat->keyboard; - - swc_keyboard_bind(keyboard, client, id); + swc_keyboard_bind(&seat.keyboard, client, id); } static void get_touch(struct wl_client * client, struct wl_resource * resource, @@ -122,32 +140,23 @@ static struct wl_seat_interface seat_implementation = { static void bind_seat(struct wl_client * client, void * data, uint32_t version, uint32_t id) { - struct swc_seat * seat = data; struct wl_resource * resource; if (version >= 2) version = 2; resource = wl_resource_create(client, &wl_seat_interface, version, id); - wl_resource_set_implementation(resource, &seat_implementation, seat, + wl_resource_set_implementation(resource, &seat_implementation, NULL, &swc_remove_resource); - wl_list_insert(&seat->resources, wl_resource_get_link(resource)); + wl_list_insert(&seat.resources, wl_resource_get_link(resource)); if (version >= 2) - wl_seat_send_name(resource, seat->name); - - wl_seat_send_capabilities(resource, seat->capabilities); -} - -static void update_capabilities(struct swc_seat * seat) -{ - struct wl_resource * resource; + wl_seat_send_name(resource, seat.name); - wl_list_for_each(resource, &seat->resources, link) - wl_seat_send_capabilities(resource, seat->capabilities); + wl_seat_send_capabilities(resource, seat.capabilities); } -static void add_device(struct swc_seat * seat, struct udev_device * udev_device) +static void add_device(struct udev_device * udev_device) { const char * device_seat; const char * device_path; @@ -159,11 +168,11 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device) if (!device_seat) device_seat = "seat0"; - if (strcmp(device_seat, seat->name) != 0) + if (strcmp(device_seat, seat.name) != 0) return; device_path = udev_device_get_devnode(udev_device); - device = swc_evdev_device_new(device_path, &seat->evdev_handler); + device = swc_evdev_device_new(device_path, &evdev_handler); if (!device) { @@ -171,123 +180,102 @@ static void add_device(struct swc_seat * seat, struct udev_device * udev_device) return; } - if (~seat->capabilities & device->capabilities) + if (~seat.capabilities & device->capabilities) { - seat->capabilities |= device->capabilities; - update_capabilities(seat); + struct wl_resource * resource; + + seat.capabilities |= device->capabilities; + wl_list_for_each(resource, &seat.resources, link) + wl_seat_send_capabilities(resource, seat.capabilities); } - wl_list_insert(&seat->devices, &device->link); + wl_list_insert(&seat.devices, &device->link); + swc_evdev_device_add_event_sources(device, swc.event_loop); } -bool swc_seat_initialize(struct swc_seat * seat, const char * seat_name) +static void add_devices() { - seat->name = strdup(seat_name); - seat->capabilities = 0; - seat->keyboard_focus_listener.notify = &handle_keyboard_focus_event; - seat->data_device_listener.notify = &handle_data_device_event; - seat->evdev_handler.key = &handle_key; - seat->evdev_handler.button = &handle_button; - seat->evdev_handler.axis = &handle_axis; - seat->evdev_handler.relative_motion = &handle_relative_motion; - - if (!seat->name) + struct udev_enumerate * enumerate; + struct udev_list_entry * entry; + const char * path; + struct udev_device * device; + + enumerate = udev_enumerate_new(swc.udev); + udev_enumerate_add_match_subsystem(enumerate, "input"); + udev_enumerate_add_match_sysname(enumerate, "event[0-9]*"); + + udev_enumerate_scan_devices(enumerate); + + udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(enumerate)) + { + path = udev_list_entry_get_name(entry); + device = udev_device_new_from_syspath(swc.udev, path); + add_device(device); + udev_device_unref(device); + } + + udev_enumerate_unref(enumerate); +} + +bool swc_seat_initialize() +{ + seat.name = SEAT_NAME; + seat.capabilities = 0; + wl_list_init(&seat.resources); + wl_list_init(&seat.devices); + + seat.global = wl_global_create(swc.display, &wl_seat_interface, 2, + NULL, &bind_seat); + + if (!seat.global) goto error0; - if (!swc_data_device_initialize(&seat->data_device)) + if (!swc_data_device_initialize(&seat.data_device)) { printf("could not initialize data device\n"); goto error1; } - if (!swc_keyboard_initialize(&seat->keyboard)) + wl_signal_add(&seat.data_device.event_signal, &data_device_listener); + + if (!swc_keyboard_initialize(&seat.keyboard)) { printf("could not initialize keyboard\n"); goto error2; } - wl_signal_add(&seat->keyboard.focus.event_signal, - &seat->keyboard_focus_listener); + wl_signal_add(&seat.keyboard.focus.event_signal, &keyboard_focus_listener); - if (!swc_pointer_initialize(&seat->pointer)) + if (!swc_pointer_initialize(&seat.pointer)) { printf("could not initialize pointer\n"); goto error3; } - wl_signal_add(&seat->data_device.event_signal, &seat->data_device_listener); - - wl_list_init(&seat->resources); - wl_signal_init(&seat->destroy_signal); - wl_list_init(&seat->devices); - swc_seat_add_devices(seat); + add_devices(); return true; error3: - swc_keyboard_finish(&seat->keyboard); + swc_keyboard_finish(&seat.keyboard); error2: - swc_data_device_finish(&seat->data_device); + swc_data_device_finish(&seat.data_device); error1: - free(seat->name); + wl_global_destroy(seat.global); error0: return false; } -void swc_seat_finish(struct swc_seat * seat) +void swc_seat_finalize() { struct swc_evdev_device * device, * tmp; - wl_signal_emit(&seat->destroy_signal, seat); + swc_pointer_finish(&seat.pointer); + swc_keyboard_finish(&seat.keyboard); - swc_pointer_finish(&seat->pointer); - swc_keyboard_finish(&seat->keyboard); - - free(seat->name); - - wl_list_for_each_safe(device, tmp, &seat->devices, link) - { + wl_list_for_each_safe(device, tmp, &seat.devices, link) swc_evdev_device_destroy(device); - } -} - -void swc_seat_add_globals(struct swc_seat * seat, struct wl_display * display) -{ - wl_global_create(display, &wl_seat_interface, 2, seat, &bind_seat); -} - -void swc_seat_add_event_sources(struct swc_seat * seat, - struct wl_event_loop * event_loop) -{ - struct swc_evdev_device * device; - - wl_list_for_each(device, &seat->devices, link) - { - swc_evdev_device_add_event_sources(device, event_loop); - } -} -void swc_seat_add_devices(struct swc_seat * seat) -{ - struct udev_enumerate * enumerate; - struct udev_list_entry * entry; - const char * path; - struct udev_device * device; - - enumerate = udev_enumerate_new(swc.udev); - udev_enumerate_add_match_subsystem(enumerate, "input"); - udev_enumerate_add_match_sysname(enumerate, "event[0-9]*"); - - udev_enumerate_scan_devices(enumerate); - - udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(enumerate)) - { - path = udev_list_entry_get_name(entry); - device = udev_device_new_from_syspath(swc.udev, path); - add_device(seat, device); - udev_device_unref(device); - } - - udev_enumerate_unref(enumerate); + wl_global_destroy(seat.global); } diff --git a/libswc/seat.h b/libswc/seat.h @@ -1,49 +1,40 @@ +/* swc: libswc/seat.h + * + * Copyright (c) 2013 Michael Forney + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #ifndef SWC_SEAT_H #define SWC_SEAT_H -#include "xkb.h" -#include "data_device.h" -#include "keyboard.h" -#include "pointer.h" -#include "evdev_device.h" - -#include <stdint.h> #include <stdbool.h> -#include <wayland-util.h> - -struct wl_display; -struct wl_event_loop; -struct swc_seat +struct swc_seat_global { - char * name; - uint32_t capabilities; - - struct wl_list resources; - struct wl_signal destroy_signal; - - struct swc_data_device data_device; - struct wl_listener data_device_listener; - - struct swc_keyboard keyboard; - struct wl_listener keyboard_focus_listener; - - struct swc_pointer pointer; - - struct wl_list devices; - struct swc_evdev_device_handler evdev_handler; + struct swc_pointer * pointer; + struct swc_keyboard * keyboard; + struct swc_data_device * data_device; }; -bool swc_seat_initialize(struct swc_seat * seat, const char * seat_name); - -void swc_seat_finish(struct swc_seat * seat); - -void swc_seat_add_globals(struct swc_seat * seat, struct wl_display * display); - -void swc_seat_add_event_sources(struct swc_seat * seat, - struct wl_event_loop * event_loop); - -void swc_seat_add_devices(struct swc_seat * seat); +bool swc_seat_initialize(); +void swc_seat_finalize(); #endif diff --git a/libswc/swc.c b/libswc/swc.c @@ -25,24 +25,32 @@ #include "bindings.h" #include "compositor.h" #include "internal.h" +#include "keyboard.h" +#include "pointer.h" +#include "seat.h" #include "shell.h" #include "window.h" #include <libudev.h> +extern const struct swc_seat_global swc_seat_global; extern const struct swc_bindings_global swc_bindings_global; static struct swc_compositor compositor; struct swc swc = { + .seat = &swc_seat_global, .bindings = &swc_bindings_global, .compositor = &compositor }; static void setup_compositor() { - compositor.seat.keyboard.handler = swc.bindings->keyboard_handler; - wl_signal_add(&compositor.seat.pointer.focus.event_signal, + swc.seat->keyboard->handler = swc.bindings->keyboard_handler; + swc.seat->pointer->handler = &compositor.pointer_handler; + wl_signal_add(&swc.seat->pointer->focus.event_signal, swc_window_enter_listener); + wl_signal_add(&swc.seat->pointer->event_signal, + &compositor.pointer_listener); } EXPORT @@ -60,16 +68,22 @@ bool swc_initialize(struct wl_display * display, goto error0; } + if (!swc_seat_initialize()) + { + fprintf(stderr, "Could not initialize seat\n"); + goto error1; + } + if (!swc_bindings_initialize()) { fprintf(stderr, "Could not initialize bindings\n"); - goto error1; + goto error2; } if (!swc_compositor_initialize(&compositor, display, swc.event_loop)) { fprintf(stderr, "Could not initialize compositor\n"); - goto error2; + goto error3; } swc_compositor_add_globals(&compositor, display); @@ -77,17 +91,19 @@ bool swc_initialize(struct wl_display * display, if (!swc_shell_initialize()) { fprintf(stderr, "Could not initialize shell\n"); - goto error3; + goto error4; } setup_compositor(); return true; - error3: + error4: swc_compositor_finish(&compositor); - error2: + error3: swc_bindings_finalize(); + error2: + swc_seat_finalize(); error1: udev_unref(swc.udev); error0: @@ -100,6 +116,7 @@ void swc_finalize() swc_shell_finalize(); swc_compositor_finish(&compositor); swc_bindings_finalize(); + swc_seat_finalize(); udev_unref(swc.udev); } diff --git a/libswc/window.c b/libswc/window.c @@ -24,7 +24,10 @@ #include "window.h" #include "compositor.h" #include "compositor_surface.h" +#include "event.h" #include "internal.h" +#include "keyboard.h" +#include "seat.h" #include "swc.h" #include <stdlib.h> @@ -70,8 +73,7 @@ void swc_window_focus(struct swc_window * window) if (INTERNAL(window)->impl->focus) INTERNAL(window)->impl->focus(window); - swc_keyboard_set_focus(&swc.compositor->seat.keyboard, - INTERNAL(window)->surface); + swc_keyboard_set_focus(swc.seat->keyboard, INTERNAL(window)->surface); } EXPORT