implements the idle_inhibit protocol type

This adds the types/wlr_idle_inhibit_v1 implementation.
This commit is contained in:
Markus Ongyerth 2018-02-07 11:10:49 +01:00
parent 088028c570
commit 50d573b2ca
6 changed files with 231 additions and 0 deletions

View file

@ -16,6 +16,10 @@
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_list.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include "rootston/view.h"
#include "rootston/config.h" #include "rootston/config.h"
#include "rootston/output.h" #include "rootston/output.h"
#include "rootston/view.h" #include "rootston/view.h"
@ -41,6 +45,7 @@ struct roots_desktop {
struct wlr_server_decoration_manager *server_decoration_manager; struct wlr_server_decoration_manager *server_decoration_manager;
struct wlr_primary_selection_device_manager *primary_selection_device_manager; struct wlr_primary_selection_device_manager *primary_selection_device_manager;
struct wlr_idle *idle; struct wlr_idle *idle;
struct wlr_idle_inhibit_v1 *idle_inhibit;
struct wl_listener new_output; struct wl_listener new_output;
struct wl_listener layout_change; struct wl_listener layout_change;

View file

@ -0,0 +1,27 @@
#ifndef WLR_TYPES_WLR_IDLE_INHIBIT_V1_H
#define WLR_TYPES_WLR_IDLE_INHIBIT_V1_H
#include <wayland-server.h>
struct wlr_idle_inhibit_v1 {
struct wl_list clients;
struct wl_global *global;
struct wl_listener display_destroy;
struct wl_signal new_inhibitor;
};
struct wlr_idle_inhibit_inhibitor_v1 {
struct wlr_surface *surface;
struct wl_resource *resource;
struct wl_listener surface_destroy;
struct wl_list link; // wlr_idle_inhibit_manager::inhibitors;
struct wl_signal destroy;
};
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);
#endif

View file

@ -23,6 +23,7 @@ wayland_scanner_client = generator(
protocols = [ 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'],
'gamma-control.xml', 'gamma-control.xml',
'gtk-primary-selection.xml', 'gtk-primary-selection.xml',
'idle.xml', 'idle.xml',
@ -32,8 +33,12 @@ protocols = [
client_protocols = [ 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, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'],
'gamma-control.xml',
'gtk-primary-selection.xml',
'idle.xml', 'idle.xml',
'screenshooter.xml', 'screenshooter.xml',
'server-decoration.xml',
] ]
wl_protos_src = [] wl_protos_src = []

View file

@ -10,6 +10,7 @@
#include <wlr/types/wlr_gamma_control.h> #include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_server_decoration.h> #include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
@ -703,6 +704,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->primary_selection_device_manager = desktop->primary_selection_device_manager =
wlr_primary_selection_device_manager_create(server->wl_display); wlr_primary_selection_device_manager_create(server->wl_display);
desktop->idle = wlr_idle_create(server->wl_display); desktop->idle = wlr_idle_create(server->wl_display);
desktop->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display);
return desktop; return desktop;
} }

View file

@ -27,6 +27,7 @@ lib_wlr_types = static_library(
'wlr_xcursor_manager.c', 'wlr_xcursor_manager.c',
'wlr_xdg_shell_v6.c', 'wlr_xdg_shell_v6.c',
'wlr_xdg_shell.c', 'wlr_xdg_shell.c',
'wlr_idle_inhibit_v1.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [pixman, xkbcommon, wayland_server, wlr_protos], dependencies: [pixman, xkbcommon, wayland_server, wlr_protos],

191
types/wlr_idle_inhibit_v1.c Normal file
View file

@ -0,0 +1,191 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/util/log.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;
struct wl_list link; // wlr_idle_inhibit_v1::clients
struct wl_list inhibitors;
};
static void idle_inhibit_inhibitor_destroy(struct wl_resource *resource) {
struct wlr_idle_inhibit_inhibitor_v1 *inhibitor = wl_resource_get_user_data(resource);
assert(inhibitor);
wl_signal_emit(&inhibitor->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);
struct wlr_idle_inhibit_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,
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,
};
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);
assert(surface && manager);
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;
}
struct wl_resource *wl_resource = wl_resource_create(client,
&zwp_idle_inhibitor_v1_interface, 1, id);
if (!wl_resource) {
wl_client_post_no_memory(client);
free(inhibitor);
return;
}
inhibitor->resource = wl_resource;
inhibitor->surface = surface;
wl_signal_init(&inhibitor->destroy);
inhibitor->surface_destroy.notify = idle_inhibit_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);
wl_list_insert(&manager->inhibitors, &inhibitor->link);
wl_signal_emit(&manager->wlr_idle_inhibit->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_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,
.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 =
wl_container_of(listener, idle_inhibit, display_destroy);
wlr_idle_inhibit_v1_destroy(idle_inhibit);
}
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;
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_resource_set_implementation(wl_resource, &idle_inhibit_impl,
manager, idle_inhibit_manager_destroy);
wlr_log(L_DEBUG, "idle_inhibit bound");
}
void wlr_idle_inhibit_v1_destroy(struct wlr_idle_inhibit_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);
}
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));
if (!idle_inhibit) {
return NULL;
}
wl_list_init(&idle_inhibit->clients);
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);
idle_inhibit->global = wl_global_create(display,
&zwp_idle_inhibit_manager_v1_interface, 1,
idle_inhibit, idle_inhibit_bind);
if (!idle_inhibit->global) {
wl_list_remove(&idle_inhibit->display_destroy.link);
free(idle_inhibit);
return NULL;
}
wlr_log(L_DEBUG, "idle_inhibit manager created");
return idle_inhibit;
}