mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
idle_inhibit: move server data to its own struct
This commit is contained in:
parent
072b334abc
commit
71224781c4
|
@ -1,17 +1,28 @@
|
||||||
|
|
||||||
#ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
|
#ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
|
||||||
#define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
|
#define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H
|
||||||
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
||||||
|
#include <wlr/types/wlr_idle.h>
|
||||||
#include "sway/server.h"
|
#include "sway/server.h"
|
||||||
|
|
||||||
|
struct sway_idle_inhibit_manager_v1 {
|
||||||
|
struct wlr_idle_inhibit_manager_v1 *wlr_manager;
|
||||||
|
struct wl_listener new_idle_inhibitor_v1;
|
||||||
|
struct wl_list inhibitors;
|
||||||
|
|
||||||
|
struct wlr_idle *idle;
|
||||||
|
};
|
||||||
|
|
||||||
struct sway_idle_inhibitor_v1 {
|
struct sway_idle_inhibitor_v1 {
|
||||||
struct sway_server *server;
|
struct sway_idle_inhibit_manager_v1 *manager;
|
||||||
struct sway_view *view;
|
struct sway_view *view;
|
||||||
|
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
};
|
};
|
||||||
|
|
||||||
void idle_inhibit_v1_check_active(struct sway_server *server);
|
void idle_inhibit_v1_check_active(
|
||||||
|
struct sway_idle_inhibit_manager_v1 *manager);
|
||||||
|
|
||||||
|
struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create(
|
||||||
|
struct wl_display *wl_display, struct wlr_idle *idle);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,16 +23,13 @@ struct sway_server {
|
||||||
|
|
||||||
struct wlr_compositor *compositor;
|
struct wlr_compositor *compositor;
|
||||||
struct wlr_data_device_manager *data_device_manager;
|
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 sway_input_manager *input;
|
||||||
|
|
||||||
struct wl_listener new_output;
|
struct wl_listener new_output;
|
||||||
|
|
||||||
struct wlr_idle_inhibit_manager_v1 *idle_inhibit_v1;
|
struct wlr_idle *idle;
|
||||||
struct wl_listener new_idle_inhibitor_v1;
|
struct sway_idle_inhibit_manager_v1 *idle_inhibit_manager_v1;
|
||||||
struct wl_list idle_inhibitors_v1;
|
|
||||||
|
|
||||||
struct wlr_layer_shell *layer_shell;
|
struct wlr_layer_shell *layer_shell;
|
||||||
struct wl_listener layer_shell_surface;
|
struct wl_listener layer_shell_surface;
|
||||||
|
|
|
@ -10,16 +10,16 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct sway_idle_inhibitor_v1 *inhibitor =
|
struct sway_idle_inhibitor_v1 *inhibitor =
|
||||||
wl_container_of(listener, inhibitor, destroy);
|
wl_container_of(listener, inhibitor, destroy);
|
||||||
wlr_log(L_DEBUG, "Sway idle inhibitor destroyed");
|
wlr_log(L_DEBUG, "Sway idle inhibitor destroyed");
|
||||||
wlr_idle_set_enabled(inhibitor->server->idle, NULL, true);
|
|
||||||
wl_list_remove(&inhibitor->link);
|
wl_list_remove(&inhibitor->link);
|
||||||
wl_list_remove(&inhibitor->destroy.link);
|
wl_list_remove(&inhibitor->destroy.link);
|
||||||
|
idle_inhibit_v1_check_active(inhibitor->manager);
|
||||||
free(inhibitor);
|
free(inhibitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) {
|
void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
|
struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
|
||||||
struct sway_server *server =
|
struct sway_idle_inhibit_manager_v1 *manager =
|
||||||
wl_container_of(listener, server, new_idle_inhibitor_v1);
|
wl_container_of(listener, manager, new_idle_inhibitor_v1);
|
||||||
wlr_log(L_DEBUG, "New sway idle inhibitor");
|
wlr_log(L_DEBUG, "New sway idle inhibitor");
|
||||||
|
|
||||||
struct sway_idle_inhibitor_v1 *inhibitor =
|
struct sway_idle_inhibitor_v1 *inhibitor =
|
||||||
|
@ -28,21 +28,22 @@ void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inhibitor->server = server;
|
inhibitor->manager = manager;
|
||||||
inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface);
|
inhibitor->view = view_from_wlr_surface(wlr_inhibitor->surface);
|
||||||
wl_list_insert(&server->idle_inhibitors_v1, &inhibitor->link);
|
wl_list_insert(&manager->inhibitors, &inhibitor->link);
|
||||||
|
|
||||||
|
|
||||||
inhibitor->destroy.notify = handle_destroy;
|
inhibitor->destroy.notify = handle_destroy;
|
||||||
wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy);
|
wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->destroy);
|
||||||
|
|
||||||
wlr_idle_set_enabled(server->idle, NULL, false);
|
idle_inhibit_v1_check_active(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
void idle_inhibit_v1_check_active(struct sway_server *server) {
|
void idle_inhibit_v1_check_active(
|
||||||
|
struct sway_idle_inhibit_manager_v1 *manager) {
|
||||||
struct sway_idle_inhibitor_v1 *inhibitor;
|
struct sway_idle_inhibitor_v1 *inhibitor;
|
||||||
bool inhibited = false;
|
bool inhibited = false;
|
||||||
wl_list_for_each(inhibitor, &server->idle_inhibitors_v1, link) {
|
wl_list_for_each(inhibitor, &manager->inhibitors, link) {
|
||||||
if (!inhibitor->view) {
|
if (!inhibitor->view) {
|
||||||
/* Cannot guess if view is visible so assume it is */
|
/* Cannot guess if view is visible so assume it is */
|
||||||
inhibited = true;
|
inhibited = true;
|
||||||
|
@ -53,5 +54,26 @@ void idle_inhibit_v1_check_active(struct sway_server *server) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wlr_idle_set_enabled(server->idle, NULL, !inhibited);
|
wlr_idle_set_enabled(manager->idle, NULL, !inhibited);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create(
|
||||||
|
struct wl_display *wl_display, struct wlr_idle *idle) {
|
||||||
|
struct sway_idle_inhibit_manager_v1 *manager =
|
||||||
|
calloc(1, sizeof(struct sway_idle_inhibit_manager_v1));
|
||||||
|
if (!manager) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
manager->wlr_manager = wlr_idle_inhibit_v1_create(wl_display);
|
||||||
|
if (!manager->wlr_manager) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
manager->idle = idle;
|
||||||
|
wl_signal_add(&manager->wlr_manager->events.new_inhibitor,
|
||||||
|
&manager->new_idle_inhibitor_v1);
|
||||||
|
manager->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1;
|
||||||
|
wl_list_init(&manager->inhibitors);
|
||||||
|
|
||||||
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ static void transaction_progress_queue() {
|
||||||
transaction_destroy(transaction);
|
transaction_destroy(transaction);
|
||||||
}
|
}
|
||||||
server.transactions->length = 0;
|
server.transactions->length = 0;
|
||||||
idle_inhibit_v1_check_active(&server);
|
idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_timeout(void *data) {
|
static int handle_timeout(void *data) {
|
||||||
|
@ -322,7 +322,7 @@ void transaction_commit(struct sway_transaction *transaction) {
|
||||||
wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction);
|
wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction);
|
||||||
transaction_apply(transaction);
|
transaction_apply(transaction);
|
||||||
transaction_destroy(transaction);
|
transaction_destroy(transaction);
|
||||||
idle_inhibit_v1_check_active(&server);
|
idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
||||||
#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_idle_inhibit_v1.h>
|
|
||||||
#include <wlr/types/wlr_layer_shell.h>
|
#include <wlr/types/wlr_layer_shell.h>
|
||||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||||
#include <wlr/types/wlr_primary_selection.h>
|
#include <wlr/types/wlr_primary_selection.h>
|
||||||
|
@ -23,6 +22,7 @@
|
||||||
// TODO WLR: make Xwayland optional
|
// TODO WLR: make Xwayland optional
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
|
#include "sway/desktop/idle_inhibit_v1.h"
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
#include "sway/server.h"
|
#include "sway/server.h"
|
||||||
#include "sway/tree/layout.h"
|
#include "sway/tree/layout.h"
|
||||||
|
@ -53,7 +53,6 @@ bool server_init(struct sway_server *server) {
|
||||||
server->data_device_manager =
|
server->data_device_manager =
|
||||||
wlr_data_device_manager_create(server->wl_display);
|
wlr_data_device_manager_create(server->wl_display);
|
||||||
|
|
||||||
server->idle = wlr_idle_create(server->wl_display);
|
|
||||||
wlr_screenshooter_create(server->wl_display);
|
wlr_screenshooter_create(server->wl_display);
|
||||||
wlr_gamma_control_manager_create(server->wl_display);
|
wlr_gamma_control_manager_create(server->wl_display);
|
||||||
wlr_primary_selection_device_manager_create(server->wl_display);
|
wlr_primary_selection_device_manager_create(server->wl_display);
|
||||||
|
@ -64,11 +63,9 @@ bool server_init(struct sway_server *server) {
|
||||||
wlr_xdg_output_manager_create(server->wl_display,
|
wlr_xdg_output_manager_create(server->wl_display,
|
||||||
root_container.sway_root->output_layout);
|
root_container.sway_root->output_layout);
|
||||||
|
|
||||||
server->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display);
|
server->idle = wlr_idle_create(server->wl_display);
|
||||||
wl_signal_add(&server->idle_inhibit->events.new_inhibitor,
|
server->idle_inhibit_manager_v1 =
|
||||||
&server->new_idle_inhibitor_v1);
|
sway_idle_inhibit_manager_v1_create(server->wl_display, server->idle);
|
||||||
server->new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1;
|
|
||||||
wl_list_init(&server->idle_inhibitors_v1);
|
|
||||||
|
|
||||||
server->layer_shell = wlr_layer_shell_create(server->wl_display);
|
server->layer_shell = wlr_layer_shell_create(server->wl_display);
|
||||||
wl_signal_add(&server->layer_shell->events.new_surface,
|
wl_signal_add(&server->layer_shell->events.new_surface,
|
||||||
|
|
Loading…
Reference in a new issue