swc

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

commit 192d691e06c01ad9f99a42e6e04c0ea959a7b7ed
parent a33ff2c82819a30afed91d74feb9a7fde3ed9860
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 25 Dec 2014 00:46:23 -0800

Move the (de)activation signal to the swc struct

This way, we will receive the initial activation event during
initialization, and the launcher doesn't have to set master on newly
opened DRM FDs.

Diffstat:
Mlaunch/launch.c | 5-----
Mlibswc/compositor.c | 30++++++++++++------------------
Mlibswc/cursor_plane.c | 10+++++-----
Mlibswc/cursor_plane.h | 2+-
Mlibswc/framebuffer_plane.c | 10+++++-----
Mlibswc/framebuffer_plane.h | 2+-
Mlibswc/internal.h | 15+++++++++++++--
Mlibswc/launch.c | 13++++---------
Mlibswc/launch.h | 11-----------
Mlibswc/seat.c | 15+++++++--------
Mlibswc/swc.c | 15++++++++++++++-
11 files changed, 62 insertions(+), 66 deletions(-)

diff --git a/launch/launch.c b/launch/launch.c @@ -264,11 +264,6 @@ static void handle_socket_data(int socket) launcher.input_fds[launcher.num_input_fds++] = fd; break; case DRM_MAJOR: - if (drmSetMaster(fd) == -1) - { - perror("Could not become DRM master"); - goto fail; - } launcher.drm_fds[launcher.num_drm_fds++] = fd; break; } diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -75,6 +75,7 @@ static struct { struct wl_list views; pixman_region32_t damage, opaque; + struct wl_listener swc_listener; /* A mask of screens that have been repainted but are waiting on a page * flip. */ @@ -84,8 +85,7 @@ static struct * idle. */ uint32_t scheduled_updates; - bool active, updating; - + bool updating; struct wl_global * global; } compositor; @@ -384,7 +384,7 @@ static bool update(struct view * base) { struct compositor_view * view = (void *) base; - if (!compositor.active || !view->visible) + if (!swc.active || !view->visible) return false; schedule_updates(view->base.screens); @@ -698,8 +698,7 @@ static void update_screen(struct screen * screen) /* If we get an EACCES, it is because this session is being * deactivated, but we haven't yet received the deactivate signal * from swc-launch. */ - compositor.active = false; - compositor.scheduled_updates = 0; + swc_deactivate(); break; case 0: compositor.pending_flips |= screen_mask(screen); @@ -713,7 +712,7 @@ static void perform_update(void * data) uint32_t updates = compositor.scheduled_updates & ~compositor.pending_flips; - if (!compositor.active || !updates) + if (!swc.active || !updates) return; DEBUG("Performing update\n"); @@ -773,27 +772,21 @@ static void handle_switch_vt(void * data, uint32_t time, swc_launch_activate_vt(vt); } -static void handle_launch_event(struct wl_listener * listener, void * data) +static void handle_swc_event(struct wl_listener * listener, void * data) { struct swc_event * event = data; switch (event->type) { - case SWC_LAUNCH_EVENT_ACTIVATED: - compositor.active = true; + case SWC_EVENT_ACTIVATED: schedule_updates(-1); break; - case SWC_LAUNCH_EVENT_DEACTIVATED: - compositor.active = false; + case SWC_EVENT_DEACTIVATED: compositor.scheduled_updates = 0; break; } } -static struct wl_listener launch_listener = { - .notify = &handle_launch_event -}; - static void create_surface(struct wl_client * client, struct wl_resource * resource, uint32_t id) { @@ -854,17 +847,18 @@ bool swc_compositor_initialize() compositor.scheduled_updates = 0; compositor.pending_flips = 0; - compositor.active = true; compositor.updating = false; pixman_region32_init(&compositor.damage); pixman_region32_init(&compositor.opaque); wl_list_init(&compositor.views); wl_signal_init(&swc_compositor.signal.new_surface); - wl_signal_add(&swc.launch->event_signal, &launch_listener); + compositor.swc_listener.notify = &handle_swc_event; + wl_signal_add(&swc.event_signal, &compositor.swc_listener); wl_list_for_each(screen, &swc.screens, link) target_new(screen); - schedule_updates(-1); + if (swc.active) + schedule_updates(-1); swc_add_binding(SWC_BINDING_KEY, SWC_MOD_CTRL | SWC_MOD_ALT, XKB_KEY_BackSpace, &handle_terminate, NULL); diff --git a/libswc/cursor_plane.c b/libswc/cursor_plane.c @@ -100,15 +100,15 @@ static const struct view_impl view_impl = { .move = &move }; -static void handle_launch_event(struct wl_listener * listener, void * data) +static void handle_swc_event(struct wl_listener * listener, void * data) { struct swc_event * event = data; struct cursor_plane * plane - = wl_container_of(listener, plane, launch_listener); + = wl_container_of(listener, plane, swc_listener); switch (event->type) { - case SWC_LAUNCH_EVENT_ACTIVATED: + case SWC_EVENT_ACTIVATED: move(&plane->view, plane->view.geometry.x, plane->view.geometry.y); attach(&plane->view, plane->view.buffer); break; @@ -123,8 +123,8 @@ bool cursor_plane_initialize(struct cursor_plane * plane, uint32_t crtc, plane->origin = origin; plane->crtc = crtc; - plane->launch_listener.notify = &handle_launch_event; - wl_signal_add(&swc.launch->event_signal, &plane->launch_listener); + plane->swc_listener.notify = &handle_swc_event; + wl_signal_add(&swc.event_signal, &plane->swc_listener); view_initialize(&plane->view, &view_impl); return true; diff --git a/libswc/cursor_plane.h b/libswc/cursor_plane.h @@ -31,7 +31,7 @@ struct cursor_plane struct view view; const struct swc_rectangle * origin; uint32_t crtc; - struct wl_listener launch_listener; + struct wl_listener swc_listener; }; bool cursor_plane_initialize(struct cursor_plane * plane, uint32_t crtc, diff --git a/libswc/framebuffer_plane.c b/libswc/framebuffer_plane.c @@ -175,15 +175,15 @@ static void handle_page_flip(struct swc_drm_handler * handler, uint32_t time) view_frame(&plane->view, time); } -static void handle_launch_event(struct wl_listener * listener, void * data) +static void handle_swc_event(struct wl_listener * listener, void * data) { struct swc_event * event = data; struct framebuffer_plane * plane - = wl_container_of(listener, plane, launch_listener); + = wl_container_of(listener, plane, swc_listener); switch (event->type) { - case SWC_LAUNCH_EVENT_ACTIVATED: + case SWC_EVENT_ACTIVATED: plane->need_modeset = true; break; } @@ -220,9 +220,9 @@ bool framebuffer_plane_initialize(struct framebuffer_plane * plane, plane->view.geometry.width = mode->width; plane->view.geometry.height = mode->height; plane->drm_handler.page_flip = &handle_page_flip; - plane->launch_listener.notify = &handle_launch_event; + plane->swc_listener.notify = &handle_swc_event; plane->mode = *mode; - wl_signal_add(&swc.launch->event_signal, &plane->launch_listener); + wl_signal_add(&swc.event_signal, &plane->swc_listener); return true; diff --git a/libswc/framebuffer_plane.h b/libswc/framebuffer_plane.h @@ -38,7 +38,7 @@ struct framebuffer_plane struct wl_array connectors; bool need_modeset; struct swc_drm_handler drm_handler; - struct wl_listener launch_listener; + struct wl_listener swc_listener; }; bool framebuffer_plane_initialize(struct framebuffer_plane * plane, diff --git a/libswc/internal.h b/libswc/internal.h @@ -24,15 +24,23 @@ #ifndef SWC_INTERNAL_H #define SWC_INTERNAL_H -#include <wayland-util.h> +#include <wayland-server.h> +#include <stdbool.h> + +enum +{ + SWC_EVENT_ACTIVATED, + SWC_EVENT_DEACTIVATED, +}; struct swc { struct wl_display * display; struct wl_event_loop * event_loop; const struct swc_manager * manager; + struct wl_signal event_signal; + bool active; - struct swc_launch * const launch; const struct swc_seat * const seat; const struct swc_bindings * const bindings; struct wl_list screens; @@ -47,5 +55,8 @@ struct swc extern struct swc swc; +void swc_activate(); +void swc_deactivate(); + #endif diff --git a/libswc/launch.c b/libswc/launch.c @@ -30,8 +30,6 @@ #include <unistd.h> #include <wayland-server.h> -struct swc_launch swc_launch; - static struct { int socket; @@ -44,14 +42,13 @@ static bool handle_event(struct swc_launch_event * event) switch (event->type) { case SWC_LAUNCH_EVENT_ACTIVATE: - swc_send_event(&swc.launch->event_signal, - SWC_LAUNCH_EVENT_ACTIVATED, NULL); + swc_activate(); break; case SWC_LAUNCH_EVENT_DEACTIVATE: - swc_send_event(&swc.launch->event_signal, - SWC_LAUNCH_EVENT_DEACTIVATED, NULL); + swc_deactivate(); break; - default: return false; + default: + return false; } return true; @@ -85,8 +82,6 @@ bool swc_launch_initialize() if (!launch.source) return false; - wl_signal_init(&swc.launch->event_signal); - return true; } diff --git a/libswc/launch.h b/libswc/launch.h @@ -27,17 +27,6 @@ #include <stdbool.h> #include <wayland-server.h> -enum -{ - SWC_LAUNCH_EVENT_ACTIVATED, - SWC_LAUNCH_EVENT_DEACTIVATED -}; - -struct swc_launch -{ - struct wl_signal event_signal; -}; - bool swc_launch_initialize(); void swc_launch_finalize(); diff --git a/libswc/seat.c b/libswc/seat.c @@ -56,6 +56,8 @@ static struct struct wl_list devices; #endif + struct wl_listener swc_listener; + struct keyboard keyboard; struct pointer pointer; struct data_device data_device; @@ -136,19 +138,19 @@ static struct wl_listener data_device_listener = { .notify = &handle_data_device_event }; -static void handle_launch_event(struct wl_listener * listener, void * data) +static void handle_swc_event(struct wl_listener * listener, void * data) { struct swc_event * event = data; switch (event->type) { - case SWC_LAUNCH_EVENT_DEACTIVATED: + case SWC_EVENT_DEACTIVATED: #ifdef ENABLE_LIBINPUT libinput_suspend(seat.libinput); #endif keyboard_reset(&seat.keyboard); break; - case SWC_LAUNCH_EVENT_ACTIVATED: + case SWC_EVENT_ACTIVATED: { #ifdef ENABLE_LIBINPUT if (libinput_resume(seat.libinput) != 0) @@ -171,10 +173,6 @@ static void handle_launch_event(struct wl_listener * listener, void * data) } } -static struct wl_listener launch_listener = { - .notify = &handle_launch_event -}; - /* Wayland Seat Interface */ static void get_pointer(struct wl_client * client, struct wl_resource * resource, uint32_t id) @@ -462,7 +460,8 @@ bool swc_seat_initialize(const char * seat_name) seat.capabilities = 0; wl_list_init(&seat.resources); - wl_signal_add(&swc.launch->event_signal, &launch_listener); + seat.swc_listener.notify = &handle_swc_event; + wl_signal_add(&swc.event_signal, &seat.swc_listener); if (!data_device_initialize(&seat.data_device)) { diff --git a/libswc/swc.c b/libswc/swc.c @@ -26,6 +26,7 @@ #include "compositor.h" #include "data_device_manager.h" #include "drm.h" +#include "event.h" #include "internal.h" #include "launch.h" #include "keyboard.h" @@ -55,7 +56,6 @@ extern struct swc_xserver swc_xserver; extern struct pointer_handler screens_pointer_handler; struct swc swc = { - .launch = &swc_launch, .seat = &swc_seat, .bindings = &swc_bindings, .compositor = &swc_compositor, @@ -98,6 +98,18 @@ static void setup_compositor() pixman_region32_fini(&pointer_region); } +void swc_activate() +{ + swc.active = true; + swc_send_event(&swc.event_signal, SWC_EVENT_ACTIVATED, NULL); +} + +void swc_deactivate() +{ + swc.active = false; + swc_send_event(&swc.event_signal, SWC_EVENT_DEACTIVATED, NULL); +} + EXPORT bool swc_initialize(struct wl_display * display, struct wl_event_loop * event_loop, @@ -107,6 +119,7 @@ bool swc_initialize(struct wl_display * display, swc.event_loop = event_loop ?: wl_display_get_event_loop(display); swc.manager = manager; const char * default_seat = "seat0"; + wl_signal_init(&swc.event_signal); if (!(swc_launch_initialize())) {