commit 192d691

Michael Forney  ·  2014-12-25 08:46:23 +0000 UTC
parent a33ff2c
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.
11 files changed,  +62, -66
+0, -5
 1@@ -264,11 +264,6 @@ static void handle_socket_data(int socket)
 2                     launcher.input_fds[launcher.num_input_fds++] = fd;
 3                     break;
 4                 case DRM_MAJOR:
 5-                    if (drmSetMaster(fd) == -1)
 6-                    {
 7-                        perror("Could not become DRM master");
 8-                        goto fail;
 9-                    }
10                     launcher.drm_fds[launcher.num_drm_fds++] = fd;
11                     break;
12             }
+12, -18
 1@@ -75,6 +75,7 @@ static struct
 2 {
 3     struct wl_list views;
 4     pixman_region32_t damage, opaque;
 5+    struct wl_listener swc_listener;
 6 
 7     /* A mask of screens that have been repainted but are waiting on a page
 8      * flip. */
 9@@ -84,8 +85,7 @@ static struct
10      * idle. */
11     uint32_t scheduled_updates;
12 
13-    bool active, updating;
14-
15+    bool updating;
16     struct wl_global * global;
17 } compositor;
18 
19@@ -384,7 +384,7 @@ static bool update(struct view * base)
20 {
21     struct compositor_view * view = (void *) base;
22 
23-    if (!compositor.active || !view->visible)
24+    if (!swc.active || !view->visible)
25         return false;
26 
27     schedule_updates(view->base.screens);
28@@ -698,8 +698,7 @@ static void update_screen(struct screen * screen)
29             /* If we get an EACCES, it is because this session is being
30              * deactivated, but we haven't yet received the deactivate signal
31              * from swc-launch. */
32-            compositor.active = false;
33-            compositor.scheduled_updates = 0;
34+            swc_deactivate();
35             break;
36         case 0:
37             compositor.pending_flips |= screen_mask(screen);
38@@ -713,7 +712,7 @@ static void perform_update(void * data)
39     uint32_t updates = compositor.scheduled_updates
40                      & ~compositor.pending_flips;
41 
42-    if (!compositor.active || !updates)
43+    if (!swc.active || !updates)
44         return;
45 
46     DEBUG("Performing update\n");
47@@ -773,27 +772,21 @@ static void handle_switch_vt(void * data, uint32_t time,
48         swc_launch_activate_vt(vt);
49 }
50 
51-static void handle_launch_event(struct wl_listener * listener, void * data)
52+static void handle_swc_event(struct wl_listener * listener, void * data)
53 {
54     struct swc_event * event = data;
55 
56     switch (event->type)
57     {
58-        case SWC_LAUNCH_EVENT_ACTIVATED:
59-            compositor.active = true;
60+        case SWC_EVENT_ACTIVATED:
61             schedule_updates(-1);
62             break;
63-        case SWC_LAUNCH_EVENT_DEACTIVATED:
64-            compositor.active = false;
65+        case SWC_EVENT_DEACTIVATED:
66             compositor.scheduled_updates = 0;
67             break;
68     }
69 }
70 
71-static struct wl_listener launch_listener = {
72-    .notify = &handle_launch_event
73-};
74-
75 static void create_surface(struct wl_client * client,
76                            struct wl_resource * resource, uint32_t id)
77 {
78@@ -854,17 +847,18 @@ bool swc_compositor_initialize()
79 
80     compositor.scheduled_updates = 0;
81     compositor.pending_flips = 0;
82-    compositor.active = true;
83     compositor.updating = false;
84     pixman_region32_init(&compositor.damage);
85     pixman_region32_init(&compositor.opaque);
86     wl_list_init(&compositor.views);
87     wl_signal_init(&swc_compositor.signal.new_surface);
88-    wl_signal_add(&swc.launch->event_signal, &launch_listener);
89+    compositor.swc_listener.notify = &handle_swc_event;
90+    wl_signal_add(&swc.event_signal, &compositor.swc_listener);
91 
92     wl_list_for_each(screen, &swc.screens, link)
93         target_new(screen);
94-    schedule_updates(-1);
95+    if (swc.active)
96+        schedule_updates(-1);
97 
98     swc_add_binding(SWC_BINDING_KEY, SWC_MOD_CTRL | SWC_MOD_ALT,
99                     XKB_KEY_BackSpace, &handle_terminate, NULL);
+5, -5
 1@@ -100,15 +100,15 @@ static const struct view_impl view_impl = {
 2     .move = &move
 3 };
 4 
 5-static void handle_launch_event(struct wl_listener * listener, void * data)
 6+static void handle_swc_event(struct wl_listener * listener, void * data)
 7 {
 8     struct swc_event * event = data;
 9     struct cursor_plane * plane
10-        = wl_container_of(listener, plane, launch_listener);
11+        = wl_container_of(listener, plane, swc_listener);
12 
13     switch (event->type)
14     {
15-        case SWC_LAUNCH_EVENT_ACTIVATED:
16+        case SWC_EVENT_ACTIVATED:
17             move(&plane->view, plane->view.geometry.x, plane->view.geometry.y);
18             attach(&plane->view, plane->view.buffer);
19             break;
20@@ -123,8 +123,8 @@ bool cursor_plane_initialize(struct cursor_plane * plane, uint32_t crtc,
21 
22     plane->origin = origin;
23     plane->crtc = crtc;
24-    plane->launch_listener.notify = &handle_launch_event;
25-    wl_signal_add(&swc.launch->event_signal, &plane->launch_listener);
26+    plane->swc_listener.notify = &handle_swc_event;
27+    wl_signal_add(&swc.event_signal, &plane->swc_listener);
28     view_initialize(&plane->view, &view_impl);
29 
30     return true;
+1, -1
1@@ -31,7 +31,7 @@ struct cursor_plane
2     struct view view;
3     const struct swc_rectangle * origin;
4     uint32_t crtc;
5-    struct wl_listener launch_listener;
6+    struct wl_listener swc_listener;
7 };
8 
9 bool cursor_plane_initialize(struct cursor_plane * plane, uint32_t crtc,
+5, -5
 1@@ -175,15 +175,15 @@ static void handle_page_flip(struct swc_drm_handler * handler, uint32_t time)
 2     view_frame(&plane->view, time);
 3 }
 4 
 5-static void handle_launch_event(struct wl_listener * listener, void * data)
 6+static void handle_swc_event(struct wl_listener * listener, void * data)
 7 {
 8     struct swc_event * event = data;
 9     struct framebuffer_plane * plane
10-        = wl_container_of(listener, plane, launch_listener);
11+        = wl_container_of(listener, plane, swc_listener);
12 
13     switch (event->type)
14     {
15-        case SWC_LAUNCH_EVENT_ACTIVATED:
16+        case SWC_EVENT_ACTIVATED:
17             plane->need_modeset = true;
18             break;
19     }
20@@ -220,9 +220,9 @@ bool framebuffer_plane_initialize(struct framebuffer_plane * plane,
21     plane->view.geometry.width = mode->width;
22     plane->view.geometry.height = mode->height;
23     plane->drm_handler.page_flip = &handle_page_flip;
24-    plane->launch_listener.notify = &handle_launch_event;
25+    plane->swc_listener.notify = &handle_swc_event;
26     plane->mode = *mode;
27-    wl_signal_add(&swc.launch->event_signal, &plane->launch_listener);
28+    wl_signal_add(&swc.event_signal, &plane->swc_listener);
29 
30     return true;
31 
+1, -1
1@@ -38,7 +38,7 @@ struct framebuffer_plane
2     struct wl_array connectors;
3     bool need_modeset;
4     struct swc_drm_handler drm_handler;
5-    struct wl_listener launch_listener;
6+    struct wl_listener swc_listener;
7 };
8 
9 bool framebuffer_plane_initialize(struct framebuffer_plane * plane,
+13, -2
 1@@ -24,15 +24,23 @@
 2 #ifndef SWC_INTERNAL_H
 3 #define SWC_INTERNAL_H
 4 
 5-#include <wayland-util.h>
 6+#include <wayland-server.h>
 7+#include <stdbool.h>
 8+
 9+enum
10+{
11+    SWC_EVENT_ACTIVATED,
12+    SWC_EVENT_DEACTIVATED,
13+};
14 
15 struct swc
16 {
17     struct wl_display * display;
18     struct wl_event_loop * event_loop;
19     const struct swc_manager * manager;
20+    struct wl_signal event_signal;
21+    bool active;
22 
23-    struct swc_launch * const launch;
24     const struct swc_seat * const seat;
25     const struct swc_bindings * const bindings;
26     struct wl_list screens;
27@@ -47,5 +55,8 @@ struct swc
28 
29 extern struct swc swc;
30 
31+void swc_activate();
32+void swc_deactivate();
33+
34 #endif
35 
+4, -9
 1@@ -30,8 +30,6 @@
 2 #include <unistd.h>
 3 #include <wayland-server.h>
 4 
 5-struct swc_launch swc_launch;
 6-
 7 static struct
 8 {
 9     int socket;
10@@ -44,14 +42,13 @@ static bool handle_event(struct swc_launch_event * event)
11     switch (event->type)
12     {
13         case SWC_LAUNCH_EVENT_ACTIVATE:
14-            swc_send_event(&swc.launch->event_signal,
15-                           SWC_LAUNCH_EVENT_ACTIVATED, NULL);
16+            swc_activate();
17             break;
18         case SWC_LAUNCH_EVENT_DEACTIVATE:
19-            swc_send_event(&swc.launch->event_signal,
20-                           SWC_LAUNCH_EVENT_DEACTIVATED, NULL);
21+            swc_deactivate();
22             break;
23-        default: return false;
24+        default:
25+            return false;
26     }
27 
28     return true;
29@@ -85,8 +82,6 @@ bool swc_launch_initialize()
30     if (!launch.source)
31         return false;
32 
33-    wl_signal_init(&swc.launch->event_signal);
34-
35     return true;
36 }
37 
+0, -11
 1@@ -27,17 +27,6 @@
 2 #include <stdbool.h>
 3 #include <wayland-server.h>
 4 
 5-enum
 6-{
 7-    SWC_LAUNCH_EVENT_ACTIVATED,
 8-    SWC_LAUNCH_EVENT_DEACTIVATED
 9-};
10-
11-struct swc_launch
12-{
13-    struct wl_signal event_signal;
14-};
15-
16 bool swc_launch_initialize();
17 void swc_launch_finalize();
18 
+7, -8
 1@@ -56,6 +56,8 @@ static struct
 2     struct wl_list devices;
 3 #endif
 4 
 5+    struct wl_listener swc_listener;
 6+
 7     struct keyboard keyboard;
 8     struct pointer pointer;
 9     struct data_device data_device;
10@@ -136,19 +138,19 @@ static struct wl_listener data_device_listener = {
11     .notify = &handle_data_device_event
12 };
13 
14-static void handle_launch_event(struct wl_listener * listener, void * data)
15+static void handle_swc_event(struct wl_listener * listener, void * data)
16 {
17     struct swc_event * event = data;
18 
19     switch (event->type)
20     {
21-        case SWC_LAUNCH_EVENT_DEACTIVATED:
22+        case SWC_EVENT_DEACTIVATED:
23 #ifdef ENABLE_LIBINPUT
24             libinput_suspend(seat.libinput);
25 #endif
26             keyboard_reset(&seat.keyboard);
27             break;
28-        case SWC_LAUNCH_EVENT_ACTIVATED:
29+        case SWC_EVENT_ACTIVATED:
30         {
31 #ifdef ENABLE_LIBINPUT
32             if (libinput_resume(seat.libinput) != 0)
33@@ -171,10 +173,6 @@ static void handle_launch_event(struct wl_listener * listener, void * data)
34     }
35 }
36 
37-static struct wl_listener launch_listener = {
38-    .notify = &handle_launch_event
39-};
40-
41 /* Wayland Seat Interface */
42 static void get_pointer(struct wl_client * client,
43                         struct wl_resource * resource, uint32_t id)
44@@ -462,7 +460,8 @@ bool swc_seat_initialize(const char * seat_name)
45 
46     seat.capabilities = 0;
47     wl_list_init(&seat.resources);
48-    wl_signal_add(&swc.launch->event_signal, &launch_listener);
49+    seat.swc_listener.notify = &handle_swc_event;
50+    wl_signal_add(&swc.event_signal, &seat.swc_listener);
51 
52     if (!data_device_initialize(&seat.data_device))
53     {
+14, -1
 1@@ -26,6 +26,7 @@
 2 #include "compositor.h"
 3 #include "data_device_manager.h"
 4 #include "drm.h"
 5+#include "event.h"
 6 #include "internal.h"
 7 #include "launch.h"
 8 #include "keyboard.h"
 9@@ -55,7 +56,6 @@ extern struct swc_xserver swc_xserver;
10 extern struct pointer_handler screens_pointer_handler;
11 
12 struct swc swc = {
13-    .launch = &swc_launch,
14     .seat = &swc_seat,
15     .bindings = &swc_bindings,
16     .compositor = &swc_compositor,
17@@ -98,6 +98,18 @@ static void setup_compositor()
18     pixman_region32_fini(&pointer_region);
19 }
20 
21+void swc_activate()
22+{
23+    swc.active = true;
24+    swc_send_event(&swc.event_signal, SWC_EVENT_ACTIVATED, NULL);
25+}
26+
27+void swc_deactivate()
28+{
29+    swc.active = false;
30+    swc_send_event(&swc.event_signal, SWC_EVENT_DEACTIVATED, NULL);
31+}
32+
33 EXPORT
34 bool swc_initialize(struct wl_display * display,
35                     struct wl_event_loop * event_loop,
36@@ -107,6 +119,7 @@ bool swc_initialize(struct wl_display * display,
37     swc.event_loop = event_loop ?: wl_display_get_event_loop(display);
38     swc.manager = manager;
39     const char * default_seat = "seat0";
40+    wl_signal_init(&swc.event_signal);
41 
42     if (!(swc_launch_initialize()))
43     {