idle-inhibit: second feedback pass
Markus Ongyerth
6 years ago
30 | 30 | struct wl_egl_window *egl_window; |
31 | 31 | struct wlr_egl_surface *egl_surface; |
32 | 32 | |
33 | static void draw(void); | |
33 | static void draw(void) { | |
34 | eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context); | |
35 | ||
36 | float color[] = {1.0, 1.0, 0.0, 1.0}; | |
37 | if (idle_inhibitor) { | |
38 | color[0] = 0.0; | |
39 | } | |
40 | ||
41 | glViewport(0, 0, width, height); | |
42 | glClearColor(color[0], color[1], color[2], 1.0); | |
43 | glClear(GL_COLOR_BUFFER_BIT); | |
44 | ||
45 | eglSwapBuffers(egl.display, egl_surface); | |
46 | } | |
34 | 47 | |
35 | 48 | static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, |
36 | 49 | uint32_t time, uint32_t button, uint32_t state_w) { |
51 | 64 | draw(); |
52 | 65 | } |
53 | 66 | |
54 | /* Function that just does nothing. | |
55 | * When it is noop(void) (like draw) the compiler complains about type | |
56 | * mismatches in the listener struct. | |
57 | * Without any arguments, it can be implicitly casted | |
58 | */ | |
59 | static void noop() {} | |
67 | static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, | |
68 | uint32_t serial, struct wl_surface *surface, | |
69 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | |
70 | /* NOOP: ignore event */ | |
71 | } | |
72 | ||
73 | static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, | |
74 | uint32_t serial, struct wl_surface *surface) { | |
75 | /* NOOP: ignore event */ | |
76 | } | |
77 | ||
78 | static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, | |
79 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | |
80 | /* NOOP: ignore event */ | |
81 | } | |
82 | ||
83 | static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, | |
84 | uint32_t time, uint32_t axis, wl_fixed_t value) { | |
85 | /* NOOP: ignore event */ | |
86 | } | |
87 | ||
88 | static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { | |
89 | /* NOOP: ignore event */ | |
90 | } | |
91 | ||
92 | static void pointer_handle_axis_source(void *data, | |
93 | struct wl_pointer *wl_pointer, uint32_t axis_source) { | |
94 | /* NOOP: ignore event */ | |
95 | } | |
96 | ||
97 | static void pointer_handle_axis_stop(void *data, | |
98 | struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis) { | |
99 | /* NOOP: ignore event */ | |
100 | } | |
101 | ||
102 | static void pointer_handle_axis_discrete(void *data, | |
103 | struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete) { | |
104 | /* NOOP: ignore event */ | |
105 | } | |
60 | 106 | |
61 | 107 | static const struct wl_pointer_listener pointer_listener = { |
62 | .enter = noop, | |
63 | .leave = noop, | |
64 | .motion = noop, | |
108 | .enter = pointer_handle_enter, | |
109 | .leave = pointer_handle_leave, | |
110 | .motion = pointer_handle_motion, | |
65 | 111 | .button = pointer_handle_button, |
66 | .axis = noop, | |
67 | .frame = noop, | |
68 | .axis_source = noop, | |
69 | .axis_stop = noop, | |
70 | .axis_discrete = noop, | |
71 | }; | |
72 | ||
73 | static void draw(void) { | |
74 | eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context); | |
75 | ||
76 | float color[] = {1.0, 1.0, 0.0, 1.0}; | |
77 | if (idle_inhibitor) { | |
78 | color[0] = 0.0; | |
79 | } | |
80 | ||
81 | glViewport(0, 0, width, height); | |
82 | glClearColor(color[0], color[1], color[2], 1.0); | |
83 | glClear(GL_COLOR_BUFFER_BIT); | |
84 | ||
85 | eglSwapBuffers(egl.display, egl_surface); | |
86 | } | |
112 | .axis = pointer_handle_axis, | |
113 | .frame = pointer_handle_frame, | |
114 | .axis_source = pointer_handle_axis_source, | |
115 | .axis_stop = pointer_handle_axis_stop, | |
116 | .axis_discrete = pointer_handle_axis_discrete, | |
117 | }; | |
87 | 118 | |
88 | 119 | static void xdg_surface_handle_configure(void *data, |
89 | 120 | struct xdg_surface *xdg_surface, uint32_t serial) { |
117 | 148 | static void handle_global(void *data, struct wl_registry *registry, |
118 | 149 | uint32_t name, const char *interface, uint32_t version) { |
119 | 150 | if (strcmp(interface, "wl_compositor") == 0) { |
120 | compositor = wl_registry_bind(registry, name, &wl_compositor_interface, | |
121 | 1); | |
151 | compositor = wl_registry_bind(registry, name, | |
152 | &wl_compositor_interface, 1); | |
122 | 153 | } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { |
123 | 154 | wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1); |
124 | 155 | } else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == 0) { |
131 | 162 | |
132 | 163 | static void handle_global_remove(void *data, struct wl_registry *registry, |
133 | 164 | uint32_t name) { |
134 | // TODO | |
165 | // who cares | |
135 | 166 | } |
136 | 167 | |
137 | 168 | static const struct wl_registry_listener registry_listener = { |
193 | 224 | draw(); |
194 | 225 | |
195 | 226 | while (wl_display_dispatch(display) != -1) { |
196 | // No-op | |
227 | /** Do Nothing */ | |
197 | 228 | } |
198 | 229 | |
199 | 230 | return EXIT_SUCCESS; |
14 | 14 | } events; |
15 | 15 | }; |
16 | 16 | |
17 | struct wlr_idle_inhibit_inhibitor_v1 { | |
17 | struct wlr_idle_inhibitor_v1 { | |
18 | 18 | struct wlr_surface *surface; |
19 | 19 | struct wl_resource *resource; |
20 | 20 | struct wl_listener surface_destroy; |
34 | 34 | [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], |
35 | 35 | [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], |
36 | 36 | [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], |
37 | 'gamma-control.xml', | |
38 | 'gtk-primary-selection.xml', | |
39 | 37 | 'idle.xml', |
40 | 38 | 'screenshooter.xml', |
41 | 39 | ] |
18 | 18 | return wl_resource_get_user_data(resource); |
19 | 19 | } |
20 | 20 | |
21 | struct wlr_idle_inhibit_inhibitor_v1 * | |
22 | wlr_idle_inhibit_inhibitor_v1_from_resource(struct wl_resource *resource) { | |
21 | struct wlr_idle_inhibitor_v1 * | |
22 | wlr_idle_inhibitor_v1_from_resource(struct wl_resource *resource) { | |
23 | 23 | assert(wl_resource_instance_of(resource, &zwp_idle_inhibitor_v1_interface, |
24 | 24 | &idle_inhibitor_impl)); |
25 | 25 | return wl_resource_get_user_data(resource); |
26 | 26 | } |
27 | 27 | |
28 | static void idle_inhibit_inhibitor_destroy(struct wl_resource *resource) { | |
29 | struct wlr_idle_inhibit_inhibitor_v1 *inhibitor = | |
30 | wlr_idle_inhibit_inhibitor_v1_from_resource(resource); | |
31 | assert(inhibitor); | |
28 | static void idle_inhibitor_destroy(struct wl_resource *resource) { | |
29 | struct wlr_idle_inhibitor_v1 *inhibitor = | |
30 | wlr_idle_inhibitor_v1_from_resource(resource); | |
32 | 31 | |
33 | 32 | wlr_signal_emit_safe(&inhibitor->events.destroy, inhibitor->surface); |
34 | 33 | |
37 | 36 | free(inhibitor); |
38 | 37 | } |
39 | 38 | |
40 | static void idle_inhibit_inhibitor_handle_surface_destroy( | |
39 | static void idle_inhibitor_handle_surface_destroy( | |
41 | 40 | struct wl_listener *listener, void *data) { |
42 | struct wlr_idle_inhibit_inhibitor_v1 *inhibitor = | |
41 | struct wlr_idle_inhibitor_v1 *inhibitor = | |
43 | 42 | wl_container_of(listener, inhibitor, surface_destroy); |
44 | 43 | |
45 | 44 | wl_resource_destroy(inhibitor->resource); |
46 | 45 | } |
47 | 46 | |
48 | static void idle_inhibit_inhibitor_v1_handle_destroy(struct wl_client *client, | |
47 | static void idle_inhibitor_v1_handle_destroy(struct wl_client *client, | |
49 | 48 | struct wl_resource *manager_resource) { |
50 | 49 | wl_resource_destroy(manager_resource); |
51 | 50 | } |
52 | 51 | |
53 | 52 | static struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl = { |
54 | .destroy = idle_inhibit_inhibitor_v1_handle_destroy, | |
53 | .destroy = idle_inhibitor_v1_handle_destroy, | |
55 | 54 | }; |
56 | 55 | |
57 | 56 | static void wlr_create_inhibitor(struct wl_client *client, |
60 | 59 | struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); |
61 | 60 | struct wlr_idle_inhibit_manager_v1 *manager = |
62 | 61 | wlr_idle_inhibit_manager_v1_from_resource(resource); |
63 | assert(surface && manager); | |
64 | 62 | |
65 | struct wlr_idle_inhibit_inhibitor_v1 *inhibitor = | |
66 | calloc(1, sizeof(struct wlr_idle_inhibit_inhibitor_v1)); | |
63 | struct wlr_idle_inhibitor_v1 *inhibitor = | |
64 | calloc(1, sizeof(struct wlr_idle_inhibitor_v1)); | |
67 | 65 | if (!inhibitor) { |
68 | 66 | wl_client_post_no_memory(client); |
69 | 67 | return; |
81 | 79 | inhibitor->surface = surface; |
82 | 80 | wl_signal_init(&inhibitor->events.destroy); |
83 | 81 | |
84 | inhibitor->surface_destroy.notify = idle_inhibit_inhibitor_handle_surface_destroy; | |
82 | inhibitor->surface_destroy.notify = idle_inhibitor_handle_surface_destroy; | |
85 | 83 | wl_signal_add(&surface->events.destroy, &inhibitor->surface_destroy); |
86 | 84 | |
87 | 85 | |
88 | 86 | wl_resource_set_implementation(wl_resource, &idle_inhibitor_impl, |
89 | inhibitor, idle_inhibit_inhibitor_destroy); | |
87 | inhibitor, idle_inhibitor_destroy); | |
90 | 88 | |
91 | 89 | wl_list_insert(&manager->inhibitors, &inhibitor->link); |
92 | 90 | wlr_signal_emit_safe(&manager->events.new_inhibitor, inhibitor); |
117 | 115 | static void idle_inhibit_bind(struct wl_client *wl_client, void *data, |
118 | 116 | uint32_t version, uint32_t id) { |
119 | 117 | struct wlr_idle_inhibit_manager_v1 *idle_inhibit = data; |
120 | assert(wl_client && idle_inhibit); | |
121 | 118 | |
122 | 119 | struct wl_resource *wl_resource = wl_resource_create(wl_client, |
123 | 120 | &zwp_idle_inhibit_manager_v1_interface, version, id); |
141 | 138 | |
142 | 139 | wl_list_remove(&idle_inhibit->display_destroy.link); |
143 | 140 | |
144 | struct wlr_idle_inhibit_inhibitor_v1 *inhibitor; | |
145 | struct wlr_idle_inhibit_inhibitor_v1 *tmp; | |
141 | struct wlr_idle_inhibitor_v1 *inhibitor; | |
142 | struct wlr_idle_inhibitor_v1 *tmp; | |
146 | 143 | wl_list_for_each_safe(inhibitor, tmp, &idle_inhibit->inhibitors, link) { |
147 | 144 | wl_resource_destroy(inhibitor->resource); |
148 | 145 | } |