idle-inhibit: Style and naming improvements

Port back style and naming improvements suggested in
https://github.com/swaywm/wlroots/pull/2026 for
keyboard-shortcuts-inhibit. These are all internal to the implementation
and therefore unproblematic.

Also, retrieve the inhibitor resource version from the manager resource
instead of setting it statically.

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
master
Michael Weiser 5 years ago committed by Simon Ser
parent 208e6da3c3
commit 3ff6a5def3

@ -13,17 +13,19 @@ static const struct zwp_idle_inhibit_manager_v1_interface idle_inhibit_impl;
static const struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl;
static 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,
wlr_idle_inhibit_manager_v1_from_resource(struct wl_resource *manager_resource) {
assert(wl_resource_instance_of(manager_resource,
&zwp_idle_inhibit_manager_v1_interface,
&idle_inhibit_impl));
return wl_resource_get_user_data(resource);
return wl_resource_get_user_data(manager_resource);
}
static 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,
wlr_idle_inhibitor_v1_from_resource(struct wl_resource *inhibitor_resource) {
assert(wl_resource_instance_of(inhibitor_resource,
&zwp_idle_inhibitor_v1_interface,
&idle_inhibitor_impl));
return wl_resource_get_user_data(resource);
return wl_resource_get_user_data(inhibitor_resource);
}
static void idle_inhibitor_v1_destroy(struct wlr_idle_inhibitor_v1 *inhibitor) {
@ -39,9 +41,10 @@ static void idle_inhibitor_v1_destroy(struct wlr_idle_inhibitor_v1 *inhibitor) {
free(inhibitor);
}
static void idle_inhibitor_v1_handle_resource_destroy(struct wl_resource *resource) {
static void idle_inhibitor_v1_handle_resource_destroy(
struct wl_resource *inhibitor_resource) {
struct wlr_idle_inhibitor_v1 *inhibitor =
wlr_idle_inhibitor_v1_from_resource(resource);
wlr_idle_inhibitor_v1_from_resource(inhibitor_resource);
idle_inhibitor_v1_destroy(inhibitor);
}
@ -53,8 +56,8 @@ static void idle_inhibitor_handle_surface_destroy(
}
static void idle_inhibitor_v1_handle_destroy(struct wl_client *client,
struct wl_resource *manager_resource) {
wl_resource_destroy(manager_resource);
struct wl_resource *inhibitor_resource) {
wl_resource_destroy(inhibitor_resource);
}
static const struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl = {
@ -62,11 +65,11 @@ static const struct zwp_idle_inhibitor_v1_interface idle_inhibitor_impl = {
};
static void manager_handle_create_inhibitor(struct wl_client *client,
struct wl_resource *resource, uint32_t id,
struct wl_resource *manager_resource, uint32_t id,
struct wl_resource *surface_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);
wlr_idle_inhibit_manager_v1_from_resource(manager_resource);
struct wlr_idle_inhibitor_v1 *inhibitor =
calloc(1, sizeof(struct wlr_idle_inhibitor_v1));
@ -75,23 +78,23 @@ static void manager_handle_create_inhibitor(struct wl_client *client,
return;
}
struct wl_resource *wl_resource = wl_resource_create(client,
&zwp_idle_inhibitor_v1_interface, 1, id);
if (!wl_resource) {
uint32_t version = wl_resource_get_version(manager_resource);
struct wl_resource *inhibitor_resource = wl_resource_create(client,
&zwp_idle_inhibitor_v1_interface, version, id);
if (!inhibitor_resource) {
wl_client_post_no_memory(client);
free(inhibitor);
return;
}
inhibitor->resource = wl_resource;
inhibitor->resource = inhibitor_resource;
inhibitor->surface = surface;
wl_signal_init(&inhibitor->events.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,
wl_resource_set_implementation(inhibitor_resource, &idle_inhibitor_impl,
inhibitor, idle_inhibitor_v1_handle_resource_destroy);
wl_list_insert(&manager->inhibitors, &inhibitor->link);
@ -109,50 +112,50 @@ static const struct zwp_idle_inhibit_manager_v1_interface idle_inhibit_impl = {
};
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_idle_inhibit_manager_v1 *idle_inhibit =
wl_container_of(listener, idle_inhibit, display_destroy);
wlr_signal_emit_safe(&idle_inhibit->events.destroy, idle_inhibit);
wl_list_remove(&idle_inhibit->display_destroy.link);
wl_global_destroy(idle_inhibit->global);
free(idle_inhibit);
struct wlr_idle_inhibit_manager_v1 *manager =
wl_container_of(listener, manager, display_destroy);
wlr_signal_emit_safe(&manager->events.destroy, manager);
wl_list_remove(&manager->display_destroy.link);
wl_global_destroy(manager->global);
free(manager);
}
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;
struct wlr_idle_inhibit_manager_v1 *manager = data;
struct wl_resource *wl_resource = wl_resource_create(wl_client,
struct wl_resource *manager_resource = wl_resource_create(wl_client,
&zwp_idle_inhibit_manager_v1_interface, version, id);
if (!wl_resource) {
if (!manager_resource) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource, &idle_inhibit_impl,
idle_inhibit, NULL);
wl_resource_set_implementation(manager_resource, &idle_inhibit_impl,
manager, NULL);
}
struct wlr_idle_inhibit_manager_v1 *wlr_idle_inhibit_v1_create(struct wl_display *display) {
struct wlr_idle_inhibit_manager_v1 *idle_inhibit =
struct wlr_idle_inhibit_manager_v1 *manager =
calloc(1, sizeof(struct wlr_idle_inhibit_manager_v1));
if (!idle_inhibit) {
if (!manager) {
return NULL;
}
wl_list_init(&idle_inhibit->inhibitors);
wl_signal_init(&idle_inhibit->events.new_inhibitor);
wl_signal_init(&idle_inhibit->events.destroy);
wl_list_init(&manager->inhibitors);
wl_signal_init(&manager->events.new_inhibitor);
wl_signal_init(&manager->events.destroy);
idle_inhibit->global = wl_global_create(display,
manager->global = wl_global_create(display,
&zwp_idle_inhibit_manager_v1_interface, 1,
idle_inhibit, idle_inhibit_bind);
if (!idle_inhibit->global) {
free(idle_inhibit);
manager, idle_inhibit_bind);
if (!manager->global) {
free(manager);
return NULL;
}
idle_inhibit->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &idle_inhibit->display_destroy);
manager->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &manager->display_destroy);
return idle_inhibit;
return manager;
}

Loading…
Cancel
Save