mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-21 22:52:20 +00:00
idle-inhibit: second feedback pass
This commit is contained in:
parent
3016133f91
commit
87a7afb641
@ -31,7 +31,20 @@ struct wlr_egl egl;
|
||||
struct wl_egl_window *egl_window;
|
||||
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,
|
||||
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();
|
||||
}
|
||||
|
||||
/* Function that just does nothing.
|
||||
* When it is noop(void) (like draw) the compiler complains about type
|
||||
* mismatches in the listener struct.
|
||||
* Without any arguments, it can be implicitly casted
|
||||
*/
|
||||
static void noop() {}
|
||||
static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
|
||||
uint32_t serial, struct wl_surface *surface,
|
||||
wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||
/* NOOP: ignore event */
|
||||
}
|
||||
|
||||
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 = {
|
||||
.enter = noop,
|
||||
.leave = noop,
|
||||
.motion = noop,
|
||||
.enter = pointer_handle_enter,
|
||||
.leave = pointer_handle_leave,
|
||||
.motion = pointer_handle_motion,
|
||||
.button = pointer_handle_button,
|
||||
.axis = noop,
|
||||
.frame = noop,
|
||||
.axis_source = noop,
|
||||
.axis_stop = noop,
|
||||
.axis_discrete = noop,
|
||||
.axis = pointer_handle_axis,
|
||||
.frame = pointer_handle_frame,
|
||||
.axis_source = pointer_handle_axis_source,
|
||||
.axis_stop = pointer_handle_axis_stop,
|
||||
.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,
|
||||
struct xdg_surface *xdg_surface, uint32_t 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,
|
||||
uint32_t name, const char *interface, uint32_t version) {
|
||||
if (strcmp(interface, "wl_compositor") == 0) {
|
||||
compositor = wl_registry_bind(registry, name, &wl_compositor_interface,
|
||||
1);
|
||||
compositor = wl_registry_bind(registry, name,
|
||||
&wl_compositor_interface, 1);
|
||||
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
|
||||
wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
|
||||
} 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,
|
||||
uint32_t name) {
|
||||
// TODO
|
||||
// who cares
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
@ -194,7 +225,7 @@ int main(int argc, char **argv) {
|
||||
draw();
|
||||
|
||||
while (wl_display_dispatch(display) != -1) {
|
||||
// No-op
|
||||
/** Do Nothing */
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -15,7 +15,7 @@ struct wlr_idle_inhibit_manager_v1 {
|
||||
} events;
|
||||
};
|
||||
|
||||
struct wlr_idle_inhibit_inhibitor_v1 {
|
||||
struct wlr_idle_inhibitor_v1 {
|
||||
struct wlr_surface *surface;
|
||||
struct wl_resource *resource;
|
||||
struct wl_listener surface_destroy;
|
||||
|
@ -35,8 +35,6 @@ client_protocols = [
|
||||
[wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
|
||||
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
|
||||
[wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'],
|
||||
'gamma-control.xml',
|
||||
'gtk-primary-selection.xml',
|
||||
'idle.xml',
|
||||
'screenshooter.xml',
|
||||
]
|
||||
|
@ -19,17 +19,16 @@ wlr_idle_inhibit_manager_v1_from_resource(struct wl_resource *resource) {
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *
|
||||
wlr_idle_inhibit_inhibitor_v1_from_resource(struct wl_resource *resource) {
|
||||
struct wlr_idle_inhibitor_v1 *
|
||||
wlr_idle_inhibitor_v1_from_resource(struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &zwp_idle_inhibitor_v1_interface,
|
||||
&idle_inhibitor_impl));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static void idle_inhibit_inhibitor_destroy(struct wl_resource *resource) {
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor =
|
||||
wlr_idle_inhibit_inhibitor_v1_from_resource(resource);
|
||||
assert(inhibitor);
|
||||
static void idle_inhibitor_destroy(struct wl_resource *resource) {
|
||||
struct wlr_idle_inhibitor_v1 *inhibitor =
|
||||
wlr_idle_inhibitor_v1_from_resource(resource);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void idle_inhibit_inhibitor_handle_surface_destroy(
|
||||
static void idle_inhibitor_handle_surface_destroy(
|
||||
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_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) {
|
||||
wl_resource_destroy(manager_resource);
|
||||
}
|
||||
|
||||
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,
|
||||
@ -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_idle_inhibit_manager_v1 *manager =
|
||||
wlr_idle_inhibit_manager_v1_from_resource(resource);
|
||||
assert(surface && manager);
|
||||
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor =
|
||||
calloc(1, sizeof(struct wlr_idle_inhibit_inhibitor_v1));
|
||||
struct wlr_idle_inhibitor_v1 *inhibitor =
|
||||
calloc(1, sizeof(struct wlr_idle_inhibitor_v1));
|
||||
if (!inhibitor) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
@ -82,12 +80,12 @@ static void wlr_create_inhibitor(struct wl_client *client,
|
||||
inhibitor->surface = surface;
|
||||
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_resource_set_implementation(wl_resource, &idle_inhibitor_impl,
|
||||
inhibitor, idle_inhibit_inhibitor_destroy);
|
||||
inhibitor, idle_inhibitor_destroy);
|
||||
|
||||
wl_list_insert(&manager->inhibitors, &inhibitor->link);
|
||||
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,
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_idle_inhibit_manager_v1 *idle_inhibit = data;
|
||||
assert(wl_client && idle_inhibit);
|
||||
|
||||
struct wl_resource *wl_resource = wl_resource_create(wl_client,
|
||||
&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);
|
||||
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor;
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *tmp;
|
||||
struct wlr_idle_inhibitor_v1 *inhibitor;
|
||||
struct wlr_idle_inhibitor_v1 *tmp;
|
||||
wl_list_for_each_safe(inhibitor, tmp, &idle_inhibit->inhibitors, link) {
|
||||
wl_resource_destroy(inhibitor->resource);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user