mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-12 16:35:58 +01:00
idle-inhibit: feedback pass
This commit is contained in:
parent
bab8c73d3c
commit
3016133f91
5 changed files with 79 additions and 86 deletions
|
@ -11,9 +11,12 @@
|
|||
#include <linux/input-event-codes.h>
|
||||
|
||||
/**
|
||||
* Usage: toplevel-decoration [mode]
|
||||
* Creates a xdg-toplevel supporting decoration negotiation. If `mode` is
|
||||
* specified, the client will prefer this decoration mode.
|
||||
* Usage: idle-inhibit
|
||||
* Creates a xdg-toplevel using the idle-inhibit protocol.
|
||||
* It will be solid green, when it has an idle inhibitor, and solid yellow if
|
||||
* it does not.
|
||||
* Left click with a pointer will toggle this state. (Touch is not supported
|
||||
* for now).
|
||||
*/
|
||||
|
||||
static int width = 500, height = 300;
|
||||
|
@ -49,7 +52,12 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32
|
|||
draw();
|
||||
}
|
||||
|
||||
static void noop () {}
|
||||
/* 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 const struct wl_pointer_listener pointer_listener = {
|
||||
.enter = noop,
|
||||
|
@ -107,11 +115,6 @@ static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
|||
.close = xdg_toplevel_handle_close,
|
||||
};
|
||||
|
||||
// static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = {
|
||||
// .preferred_mode = decoration_handle_preferred_mode,
|
||||
// .configure = decoration_handle_configure,
|
||||
// };
|
||||
|
||||
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) {
|
||||
|
@ -138,18 +141,6 @@ static const struct wl_registry_listener registry_listener = {
|
|||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// if (argc == 2) {
|
||||
// char *mode = argv[1];
|
||||
// if (strcmp(mode, "client") == 0) {
|
||||
// decoration_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT;
|
||||
// } else if (strcmp(mode, "server") == 0) {
|
||||
// decoration_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER;
|
||||
// } else {
|
||||
// fprintf(stderr, "Invalid decoration mode\n");
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// }
|
||||
|
||||
struct wl_display *display = wl_display_connect(NULL);
|
||||
if (display == NULL) {
|
||||
fprintf(stderr, "Failed to create display\n");
|
||||
|
|
|
@ -45,7 +45,7 @@ struct roots_desktop {
|
|||
struct wlr_server_decoration_manager *server_decoration_manager;
|
||||
struct wlr_primary_selection_device_manager *primary_selection_device_manager;
|
||||
struct wlr_idle *idle;
|
||||
struct wlr_idle_inhibit_v1 *idle_inhibit;
|
||||
struct wlr_idle_inhibit_manager_v1 *idle_inhibit;
|
||||
|
||||
struct wl_listener new_output;
|
||||
struct wl_listener layout_change;
|
||||
|
|
|
@ -3,12 +3,16 @@
|
|||
|
||||
#include <wayland-server.h>
|
||||
|
||||
struct wlr_idle_inhibit_v1 {
|
||||
struct wl_list clients;
|
||||
struct wlr_idle_inhibit_manager_v1 {
|
||||
struct wl_list wl_resources; // wl_resource_get_link
|
||||
struct wl_list inhibitors; // wlr_idle_inhibit_inhibitor_v1::link
|
||||
struct wl_global *global;
|
||||
|
||||
struct wl_listener display_destroy;
|
||||
struct wl_signal new_inhibitor;
|
||||
|
||||
struct {
|
||||
struct wl_signal new_inhibitor;
|
||||
} events;
|
||||
};
|
||||
|
||||
struct wlr_idle_inhibit_inhibitor_v1 {
|
||||
|
@ -16,12 +20,14 @@ struct wlr_idle_inhibit_inhibitor_v1 {
|
|||
struct wl_resource *resource;
|
||||
struct wl_listener surface_destroy;
|
||||
|
||||
struct wl_list link; // wlr_idle_inhibit_manager::inhibitors;
|
||||
struct wl_list link; // wlr_idle_inhibit_manager_v1::inhibitors;
|
||||
|
||||
struct wl_signal destroy;
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
};
|
||||
|
||||
struct wlr_idle_inhibit_v1 *wlr_idle_inhibit_v1_create(struct wl_display *display);
|
||||
void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_v1 *idle_inhibit);
|
||||
struct wlr_idle_inhibit_manager_v1 *wlr_idle_inhibit_v1_create(struct wl_display *display);
|
||||
void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_manager_v1 *idle_inhibit);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,7 +39,6 @@ client_protocols = [
|
|||
'gtk-primary-selection.xml',
|
||||
'idle.xml',
|
||||
'screenshooter.xml',
|
||||
'server-decoration.xml',
|
||||
]
|
||||
|
||||
wl_protos_src = []
|
||||
|
|
|
@ -1,35 +1,45 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <util/signal.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
||||
#include "wayland-util.h"
|
||||
#include "wayland-server.h"
|
||||
#include "idle-inhibit-unstable-v1-protocol.h"
|
||||
|
||||
struct wlr_idle_inhibit_manager {
|
||||
struct wlr_idle_inhibit_v1 *wlr_idle_inhibit;
|
||||
struct wl_resource *resource;
|
||||
static struct zwp_idle_inhibit_manager_v1_interface idle_inhibit_impl;
|
||||
|
||||
struct wl_list link; // wlr_idle_inhibit_v1::clients
|
||||
static struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl;
|
||||
|
||||
struct wl_list inhibitors;
|
||||
};
|
||||
struct wlr_idle_inhibit_manager_v1 *
|
||||
wlr_idle_inhibit_manager_v1_from_resource(struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &zwp_idle_inhibit_manager_v1_interface,
|
||||
&idle_inhibit_impl));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *
|
||||
wlr_idle_inhibit_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 = wl_resource_get_user_data(resource);
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor =
|
||||
wlr_idle_inhibit_inhibitor_v1_from_resource(resource);
|
||||
assert(inhibitor);
|
||||
|
||||
wl_signal_emit(&inhibitor->destroy, inhibitor->surface);
|
||||
wlr_signal_emit_safe(&inhibitor->events.destroy, inhibitor->surface);
|
||||
|
||||
wl_list_remove(&inhibitor->link);
|
||||
wl_list_remove(&inhibitor->surface_destroy.link);
|
||||
free(inhibitor);
|
||||
}
|
||||
|
||||
static void idle_inhibit_inhibitor_handle_surface_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
assert(listener);
|
||||
static void idle_inhibit_inhibitor_handle_surface_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor =
|
||||
wl_container_of(listener, inhibitor, surface_destroy);
|
||||
|
||||
|
@ -48,11 +58,13 @@ static struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl = {
|
|||
static void wlr_create_inhibitor(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id,
|
||||
struct wl_resource *surface_resource) {
|
||||
struct wlr_surface *surface = wl_resource_get_user_data(surface_resource);
|
||||
struct wlr_idle_inhibit_manager *manager = wl_resource_get_user_data(resource);
|
||||
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_inhibit_inhibitor_v1 *inhibitor =
|
||||
calloc(1, sizeof(struct wlr_idle_inhibit_inhibitor_v1));
|
||||
if (!inhibitor) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
|
@ -68,7 +80,7 @@ static void wlr_create_inhibitor(struct wl_client *client,
|
|||
|
||||
inhibitor->resource = wl_resource;
|
||||
inhibitor->surface = surface;
|
||||
wl_signal_init(&inhibitor->destroy);
|
||||
wl_signal_init(&inhibitor->events.destroy);
|
||||
|
||||
inhibitor->surface_destroy.notify = idle_inhibit_inhibitor_handle_surface_destroy;
|
||||
wl_signal_add(&surface->events.destroy, &inhibitor->surface_destroy);
|
||||
|
@ -78,38 +90,26 @@ static void wlr_create_inhibitor(struct wl_client *client,
|
|||
inhibitor, idle_inhibit_inhibitor_destroy);
|
||||
|
||||
wl_list_insert(&manager->inhibitors, &inhibitor->link);
|
||||
wl_signal_emit(&manager->wlr_idle_inhibit->new_inhibitor, inhibitor);
|
||||
wlr_signal_emit_safe(&manager->events.new_inhibitor, inhibitor);
|
||||
}
|
||||
|
||||
|
||||
static void idle_inhibit_manager_destroy(struct wl_resource *resource) {
|
||||
struct wlr_idle_inhibit_manager *manager = wl_resource_get_user_data(resource);
|
||||
assert(manager);
|
||||
|
||||
wl_list_remove(&manager->link);
|
||||
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor;
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *tmp;
|
||||
wl_list_for_each_safe(inhibitor, tmp, &manager->inhibitors, link) {
|
||||
wl_resource_destroy(inhibitor->resource);
|
||||
}
|
||||
static void idle_inhibit_manager_v1_destroy(struct wl_resource *resource) {
|
||||
wl_list_remove(wl_resource_get_link(resource));
|
||||
}
|
||||
|
||||
static void idle_inhibit_manager_handle_destroy(struct wl_client *client,
|
||||
static void idle_inhibit_manager_v1_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *manager_resource) {
|
||||
wl_resource_destroy(manager_resource);
|
||||
}
|
||||
|
||||
static struct zwp_idle_inhibit_manager_v1_interface idle_inhibit_impl = {
|
||||
.destroy = idle_inhibit_manager_handle_destroy,
|
||||
.destroy = idle_inhibit_manager_v1_handle_destroy,
|
||||
.create_inhibitor = wlr_create_inhibitor,
|
||||
};
|
||||
|
||||
void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_v1 *idle_inhibit);
|
||||
|
||||
|
||||
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_idle_inhibit_v1 *idle_inhibit =
|
||||
struct wlr_idle_inhibit_manager_v1 *idle_inhibit =
|
||||
wl_container_of(listener, idle_inhibit, display_destroy);
|
||||
|
||||
wlr_idle_inhibit_v1_destroy(idle_inhibit);
|
||||
|
@ -117,63 +117,60 @@ 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_v1 *idle_inhibit = data;
|
||||
struct wlr_idle_inhibit_manager_v1 *idle_inhibit = data;
|
||||
assert(wl_client && idle_inhibit);
|
||||
|
||||
struct wlr_idle_inhibit_manager *manager = calloc(1, sizeof(struct wlr_idle_inhibit_manager));
|
||||
if (!manager) {
|
||||
wl_client_post_no_memory(wl_client);
|
||||
return;
|
||||
}
|
||||
|
||||
struct wl_resource *wl_resource = wl_resource_create(wl_client,
|
||||
&zwp_idle_inhibit_manager_v1_interface, version, id);
|
||||
|
||||
if (!wl_resource) {
|
||||
wl_client_post_no_memory(wl_client);
|
||||
free(manager);
|
||||
return;
|
||||
}
|
||||
|
||||
manager->resource = wl_resource;
|
||||
wl_list_init(&manager->inhibitors);
|
||||
wl_list_insert(&idle_inhibit->clients, &manager->link);
|
||||
manager->wlr_idle_inhibit = idle_inhibit;
|
||||
|
||||
wl_list_insert(&idle_inhibit->wl_resources, wl_resource_get_link(wl_resource));
|
||||
|
||||
wl_resource_set_implementation(wl_resource, &idle_inhibit_impl,
|
||||
manager, idle_inhibit_manager_destroy);
|
||||
idle_inhibit, idle_inhibit_manager_v1_destroy);
|
||||
wlr_log(L_DEBUG, "idle_inhibit bound");
|
||||
}
|
||||
|
||||
void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_v1 *idle_inhibit) {
|
||||
void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_manager_v1 *idle_inhibit) {
|
||||
if (!idle_inhibit) {
|
||||
return;
|
||||
}
|
||||
|
||||
wl_list_remove(&idle_inhibit->display_destroy.link);
|
||||
|
||||
struct wlr_idle_inhibit_manager *manager;
|
||||
struct wlr_idle_inhibit_manager *tmp;
|
||||
wl_list_for_each_safe(manager, tmp, &idle_inhibit->clients, link) {
|
||||
wl_resource_destroy(manager->resource);
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor;
|
||||
struct wlr_idle_inhibit_inhibitor_v1 *tmp;
|
||||
wl_list_for_each_safe(inhibitor, tmp, &idle_inhibit->inhibitors, link) {
|
||||
wl_resource_destroy(inhibitor->resource);
|
||||
}
|
||||
|
||||
struct wl_resource *resource;
|
||||
struct wl_resource *tmp_resource;
|
||||
wl_resource_for_each_safe(resource, tmp_resource, &idle_inhibit->wl_resources) {
|
||||
wl_resource_destroy(inhibitor->resource);
|
||||
}
|
||||
|
||||
wl_global_destroy(idle_inhibit->global);
|
||||
free(idle_inhibit);
|
||||
}
|
||||
|
||||
struct wlr_idle_inhibit_v1 *wlr_idle_inhibit_v1_create(struct wl_display *display) {
|
||||
struct wlr_idle_inhibit_v1 *idle_inhibit = calloc(1, sizeof(struct wlr_idle_inhibit_v1));
|
||||
struct wlr_idle_inhibit_manager_v1 *wlr_idle_inhibit_v1_create(struct wl_display *display) {
|
||||
struct wlr_idle_inhibit_manager_v1 *idle_inhibit =
|
||||
calloc(1, sizeof(struct wlr_idle_inhibit_manager_v1));
|
||||
|
||||
if (!idle_inhibit) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_list_init(&idle_inhibit->clients);
|
||||
wl_list_init(&idle_inhibit->wl_resources);
|
||||
wl_list_init(&idle_inhibit->inhibitors);
|
||||
idle_inhibit->display_destroy.notify = handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &idle_inhibit->display_destroy);
|
||||
wl_signal_init(&idle_inhibit->new_inhibitor);
|
||||
wl_signal_init(&idle_inhibit->events.new_inhibitor);
|
||||
|
||||
idle_inhibit->global = wl_global_create(display,
|
||||
&zwp_idle_inhibit_manager_v1_interface, 1,
|
||||
|
|
Loading…
Reference in a new issue