idle-inhibit: second feedback pass

This commit is contained in:
Markus Ongyerth 2018-02-21 16:17:59 +01:00
parent 3016133f91
commit 87a7afb641
4 changed files with 81 additions and 55 deletions

View File

@ -31,7 +31,20 @@ struct wlr_egl egl;
struct wl_egl_window *egl_window; struct wl_egl_window *egl_window;
struct wlr_egl_surface *egl_surface; struct wlr_egl_surface *egl_surface;
static void draw(void); static void draw(void) {
eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context);
float color[] = {1.0, 1.0, 0.0, 1.0};
if (idle_inhibitor) {
color[0] = 0.0;
}
glViewport(0, 0, width, height);
glClearColor(color[0], color[1], color[2], 1.0);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(egl.display, egl_surface);
}
static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
uint32_t time, uint32_t button, uint32_t state_w) { uint32_t time, uint32_t button, uint32_t state_w) {
@ -52,40 +65,58 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32
draw(); draw();
} }
/* Function that just does nothing. static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
* When it is noop(void) (like draw) the compiler complains about type uint32_t serial, struct wl_surface *surface,
* mismatches in the listener struct. wl_fixed_t surface_x, wl_fixed_t surface_y) {
* Without any arguments, it can be implicitly casted /* NOOP: ignore event */
*/ }
static void noop() {}
static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface) {
/* NOOP: ignore event */
}
static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
/* NOOP: ignore event */
}
static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value) {
/* NOOP: ignore event */
}
static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) {
/* NOOP: ignore event */
}
static void pointer_handle_axis_source(void *data,
struct wl_pointer *wl_pointer, uint32_t axis_source) {
/* NOOP: ignore event */
}
static void pointer_handle_axis_stop(void *data,
struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis) {
/* NOOP: ignore event */
}
static void pointer_handle_axis_discrete(void *data,
struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete) {
/* NOOP: ignore event */
}
static const struct wl_pointer_listener pointer_listener = { static const struct wl_pointer_listener pointer_listener = {
.enter = noop, .enter = pointer_handle_enter,
.leave = noop, .leave = pointer_handle_leave,
.motion = noop, .motion = pointer_handle_motion,
.button = pointer_handle_button, .button = pointer_handle_button,
.axis = noop, .axis = pointer_handle_axis,
.frame = noop, .frame = pointer_handle_frame,
.axis_source = noop, .axis_source = pointer_handle_axis_source,
.axis_stop = noop, .axis_stop = pointer_handle_axis_stop,
.axis_discrete = noop, .axis_discrete = pointer_handle_axis_discrete,
}; };
static void draw(void) {
eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context);
float color[] = {1.0, 1.0, 0.0, 1.0};
if (idle_inhibitor) {
color[0] = 0.0;
}
glViewport(0, 0, width, height);
glClearColor(color[0], color[1], color[2], 1.0);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(egl.display, egl_surface);
}
static void xdg_surface_handle_configure(void *data, static void xdg_surface_handle_configure(void *data,
struct xdg_surface *xdg_surface, uint32_t serial) { struct xdg_surface *xdg_surface, uint32_t serial) {
xdg_surface_ack_configure(xdg_surface, serial); xdg_surface_ack_configure(xdg_surface, serial);
@ -118,8 +149,8 @@ static const struct xdg_toplevel_listener xdg_toplevel_listener = {
static void handle_global(void *data, struct wl_registry *registry, static void handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) { uint32_t name, const char *interface, uint32_t version) {
if (strcmp(interface, "wl_compositor") == 0) { if (strcmp(interface, "wl_compositor") == 0) {
compositor = wl_registry_bind(registry, name, &wl_compositor_interface, compositor = wl_registry_bind(registry, name,
1); &wl_compositor_interface, 1);
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1); wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
} else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == 0) { } else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == 0) {
@ -132,7 +163,7 @@ static void handle_global(void *data, struct wl_registry *registry,
static void handle_global_remove(void *data, struct wl_registry *registry, static void handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name) { uint32_t name) {
// TODO // who cares
} }
static const struct wl_registry_listener registry_listener = { static const struct wl_registry_listener registry_listener = {
@ -194,7 +225,7 @@ int main(int argc, char **argv) {
draw(); draw();
while (wl_display_dispatch(display) != -1) { while (wl_display_dispatch(display) != -1) {
// No-op /** Do Nothing */
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -15,7 +15,7 @@ struct wlr_idle_inhibit_manager_v1 {
} events; } events;
}; };
struct wlr_idle_inhibit_inhibitor_v1 { struct wlr_idle_inhibitor_v1 {
struct wlr_surface *surface; struct wlr_surface *surface;
struct wl_resource *resource; struct wl_resource *resource;
struct wl_listener surface_destroy; struct wl_listener surface_destroy;

View File

@ -35,8 +35,6 @@ client_protocols = [
[wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
[wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'],
'gamma-control.xml',
'gtk-primary-selection.xml',
'idle.xml', 'idle.xml',
'screenshooter.xml', 'screenshooter.xml',
] ]

View File

@ -19,17 +19,16 @@ wlr_idle_inhibit_manager_v1_from_resource(struct wl_resource *resource) {
return wl_resource_get_user_data(resource); return wl_resource_get_user_data(resource);
} }
struct wlr_idle_inhibit_inhibitor_v1 * struct wlr_idle_inhibitor_v1 *
wlr_idle_inhibit_inhibitor_v1_from_resource(struct wl_resource *resource) { wlr_idle_inhibitor_v1_from_resource(struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &zwp_idle_inhibitor_v1_interface, assert(wl_resource_instance_of(resource, &zwp_idle_inhibitor_v1_interface,
&idle_inhibitor_impl)); &idle_inhibitor_impl));
return wl_resource_get_user_data(resource); return wl_resource_get_user_data(resource);
} }
static void idle_inhibit_inhibitor_destroy(struct wl_resource *resource) { static void idle_inhibitor_destroy(struct wl_resource *resource) {
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor = struct wlr_idle_inhibitor_v1 *inhibitor =
wlr_idle_inhibit_inhibitor_v1_from_resource(resource); wlr_idle_inhibitor_v1_from_resource(resource);
assert(inhibitor);
wlr_signal_emit_safe(&inhibitor->events.destroy, inhibitor->surface); wlr_signal_emit_safe(&inhibitor->events.destroy, inhibitor->surface);
@ -38,21 +37,21 @@ static void idle_inhibit_inhibitor_destroy(struct wl_resource *resource) {
free(inhibitor); free(inhibitor);
} }
static void idle_inhibit_inhibitor_handle_surface_destroy( static void idle_inhibitor_handle_surface_destroy(
struct wl_listener *listener, void *data) { struct wl_listener *listener, void *data) {
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor = struct wlr_idle_inhibitor_v1 *inhibitor =
wl_container_of(listener, inhibitor, surface_destroy); wl_container_of(listener, inhibitor, surface_destroy);
wl_resource_destroy(inhibitor->resource); wl_resource_destroy(inhibitor->resource);
} }
static void idle_inhibit_inhibitor_v1_handle_destroy(struct wl_client *client, static void idle_inhibitor_v1_handle_destroy(struct wl_client *client,
struct wl_resource *manager_resource) { struct wl_resource *manager_resource) {
wl_resource_destroy(manager_resource); wl_resource_destroy(manager_resource);
} }
static struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl = { static struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl = {
.destroy = idle_inhibit_inhibitor_v1_handle_destroy, .destroy = idle_inhibitor_v1_handle_destroy,
}; };
static void wlr_create_inhibitor(struct wl_client *client, static void wlr_create_inhibitor(struct wl_client *client,
@ -61,10 +60,9 @@ static void wlr_create_inhibitor(struct wl_client *client,
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
struct wlr_idle_inhibit_manager_v1 *manager = struct wlr_idle_inhibit_manager_v1 *manager =
wlr_idle_inhibit_manager_v1_from_resource(resource); wlr_idle_inhibit_manager_v1_from_resource(resource);
assert(surface && manager);
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor = struct wlr_idle_inhibitor_v1 *inhibitor =
calloc(1, sizeof(struct wlr_idle_inhibit_inhibitor_v1)); calloc(1, sizeof(struct wlr_idle_inhibitor_v1));
if (!inhibitor) { if (!inhibitor) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
@ -82,12 +80,12 @@ static void wlr_create_inhibitor(struct wl_client *client,
inhibitor->surface = surface; inhibitor->surface = surface;
wl_signal_init(&inhibitor->events.destroy); wl_signal_init(&inhibitor->events.destroy);
inhibitor->surface_destroy.notify = idle_inhibit_inhibitor_handle_surface_destroy; inhibitor->surface_destroy.notify = idle_inhibitor_handle_surface_destroy;
wl_signal_add(&surface->events.destroy, &inhibitor->surface_destroy); wl_signal_add(&surface->events.destroy, &inhibitor->surface_destroy);
wl_resource_set_implementation(wl_resource, &idle_inhibitor_impl, wl_resource_set_implementation(wl_resource, &idle_inhibitor_impl,
inhibitor, idle_inhibit_inhibitor_destroy); inhibitor, idle_inhibitor_destroy);
wl_list_insert(&manager->inhibitors, &inhibitor->link); wl_list_insert(&manager->inhibitors, &inhibitor->link);
wlr_signal_emit_safe(&manager->events.new_inhibitor, inhibitor); wlr_signal_emit_safe(&manager->events.new_inhibitor, inhibitor);
@ -118,7 +116,6 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
static void idle_inhibit_bind(struct wl_client *wl_client, void *data, static void idle_inhibit_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_idle_inhibit_manager_v1 *idle_inhibit = data; struct wlr_idle_inhibit_manager_v1 *idle_inhibit = data;
assert(wl_client && idle_inhibit);
struct wl_resource *wl_resource = wl_resource_create(wl_client, struct wl_resource *wl_resource = wl_resource_create(wl_client,
&zwp_idle_inhibit_manager_v1_interface, version, id); &zwp_idle_inhibit_manager_v1_interface, version, id);
@ -142,8 +139,8 @@ void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_manager_v1 *idle_inhibi
wl_list_remove(&idle_inhibit->display_destroy.link); wl_list_remove(&idle_inhibit->display_destroy.link);
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor; struct wlr_idle_inhibitor_v1 *inhibitor;
struct wlr_idle_inhibit_inhibitor_v1 *tmp; struct wlr_idle_inhibitor_v1 *tmp;
wl_list_for_each_safe(inhibitor, tmp, &idle_inhibit->inhibitors, link) { wl_list_for_each_safe(inhibitor, tmp, &idle_inhibit->inhibitors, link) {
wl_resource_destroy(inhibitor->resource); wl_resource_destroy(inhibitor->resource);
} }