Add idle inhibit unstable v1 support

This commit is contained in:
Dominique Martinet 2018-06-27 18:16:49 +09:00
parent 649e084f41
commit e4bfb3bc98
5 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,13 @@
#ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
#define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include "sway/server.h"
struct sway_idle_inhibitor_v1 {
struct sway_server *server;
struct wl_listener destroy;
};
#endif

View file

@ -24,11 +24,15 @@ struct sway_server {
struct wlr_compositor *compositor;
struct wlr_data_device_manager *data_device_manager;
struct wlr_idle *idle;
struct wlr_idle_inhibit_manager_v1 *idle_inhibit;
struct sway_input_manager *input;
struct wl_listener new_output;
struct wlr_idle_inhibit_manager_v1 *idle_inhibit_v1;
struct wl_listener new_idle_inhibitor_v1;
struct wlr_layer_shell *layer_shell;
struct wl_listener layer_shell_surface;
@ -61,6 +65,7 @@ void server_run(struct sway_server *server);
void handle_new_output(struct wl_listener *listener, void *data);
void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data);
void handle_layer_shell_surface(struct wl_listener *listener, void *data);
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
void handle_xdg_shell_surface(struct wl_listener *listener, void *data);

View file

@ -0,0 +1,35 @@
#include <stdlib.h>
#include <wlr/types/wlr_idle.h>
#include "log.h"
#include "sway/desktop/idle_inhibit_v1.h"
#include "sway/server.h"
static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_idle_inhibitor_v1 *inhibitor =
wl_container_of(listener, inhibitor, destroy);
wlr_log(L_DEBUG, "Sway idle inhibitor destroyed");
wlr_idle_set_enabled(inhibitor->server->idle, NULL, true);
wl_list_remove(&inhibitor->destroy.link);
free(inhibitor);
}
void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) {
struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
struct sway_server *server =
wl_container_of(listener, server, new_idle_inhibitor_v1);
wlr_log(L_DEBUG, "New sway idle inhibitor");
struct sway_idle_inhibitor_v1 *inhibitor =
calloc(1, sizeof(struct sway_idle_inhibitor_v1));
if (!inhibitor) {
return;
}
inhibitor->server = server;
inhibitor->destroy.notify = handle_destroy;
wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy);
wlr_idle_set_enabled(server->idle, NULL, false);
}

View file

@ -10,6 +10,7 @@ sway_sources = files(
'security.c',
'desktop/desktop.c',
'desktop/idle_inhibit_v1.c',
'desktop/layer_shell.c',
'desktop/output.c',
'desktop/transaction.c',

View file

@ -10,6 +10,7 @@
#include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_layer_shell.h>
#include <wlr/types/wlr_linux_dmabuf.h>
#include <wlr/types/wlr_primary_selection.h>
@ -63,6 +64,11 @@ bool server_init(struct sway_server *server) {
wlr_xdg_output_manager_create(server->wl_display,
root_container.sway_root->output_layout);
server->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display);
wl_signal_add(&server->idle_inhibit->events.new_inhibitor,
&server->new_idle_inhibitor_v1);
server->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1;
server->layer_shell = wlr_layer_shell_create(server->wl_display);
wl_signal_add(&server->layer_shell->events.new_surface,
&server->layer_shell_surface);