Implemented idle-inhibit

Now all the protocols in ./protocol are actually being used
This commit is contained in:
Keith Bowes 2023-12-30 15:30:52 -05:00
parent 3687099182
commit b5f4055904
9 changed files with 77 additions and 8 deletions

View file

@ -4,6 +4,7 @@
#include <time.h> #include <time.h>
#include "waybox/server.h" #include "waybox/server.h"
#include <wlr/types/wlr_output_management_v1.h>
struct wb_output { struct wb_output {
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
@ -34,6 +35,6 @@ struct wb_output {
void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data); void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data);
void output_frame_notify(struct wl_listener *listener, void *data); void output_frame_notify(struct wl_listener *listener, void *data);
void output_destroy_notify(struct wl_listener *listener, void *data); void output_destroy_notify(struct wl_listener *listener, void *data);
void new_output_notify(struct wl_listener *listener, void *data); void init_output(struct wb_server *server);
#endif /* output.h */ #endif /* output.h */

View file

@ -46,6 +46,7 @@ struct wb_server {
struct wlr_backend *backend; struct wlr_backend *backend;
struct wlr_compositor *compositor; struct wlr_compositor *compositor;
struct wlr_gamma_control_manager_v1 *gamma_control_manager; struct wlr_gamma_control_manager_v1 *gamma_control_manager;
struct wlr_idle_inhibit_manager_v1 *idle_inhibitor;
struct wlr_idle_notifier_v1 *idle_notifier; struct wlr_idle_notifier_v1 *idle_notifier;
struct wlr_output_layout *output_layout; struct wlr_output_layout *output_layout;
struct wlr_xdg_output_manager_v1 *output_manager; struct wlr_xdg_output_manager_v1 *output_manager;
@ -69,6 +70,8 @@ struct wb_server {
struct wlr_layer_shell_v1 *layer_shell; struct wlr_layer_shell_v1 *layer_shell;
struct wlr_xdg_shell *xdg_shell; struct wlr_xdg_shell *xdg_shell;
struct wlr_output_manager_v1 *wlr_output_manager;
struct wl_listener gamma_control_set_gamma; struct wl_listener gamma_control_set_gamma;
struct wl_listener new_layer_surface; struct wl_listener new_layer_surface;
struct wl_listener new_xdg_decoration; struct wl_listener new_xdg_decoration;
@ -81,6 +84,7 @@ struct wb_server {
struct wl_listener new_input; struct wl_listener new_input;
struct wl_listener new_output; struct wl_listener new_output;
struct wl_listener output_configuration_applied;
struct wl_list outputs; /* wb_output::link */ struct wl_list outputs; /* wb_output::link */
}; };

View file

@ -20,9 +20,12 @@ struct wb_toplevel {
struct wl_listener request_minimize; struct wl_listener request_minimize;
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wl_listener new_inhibitor;
struct wl_listener destroy_inhibitor;
struct wlr_box geometry; struct wlr_box geometry;
struct wlr_box previous_geometry; struct wlr_box previous_geometry;
bool inhibited;
}; };
void init_xdg_shell(struct wb_server *server); void init_xdg_shell(struct wb_server *server);

28
waybox/idle.c Normal file
View file

@ -0,0 +1,28 @@
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include "idle.h"
void idle_inhibitor_new(struct wl_listener *listener, void *data) {
struct wb_toplevel *toplevel = wl_container_of(listener, toplevel, new_inhibitor);
toplevel->inhibited = true;
}
void idle_inhibitor_destroy(struct wl_listener *listener, void *data) {
struct wb_toplevel *toplevel = wl_container_of(listener, toplevel, new_inhibitor);
toplevel->inhibited = false;
}
bool create_idle_manager(struct wb_server *server) {
server->idle_notifier = wlr_idle_notifier_v1_create(server->wl_display);
server->idle_inhibitor = wlr_idle_inhibit_v1_create(server->wl_display);
return true;
}
bool install_inhibitor(struct wb_toplevel *toplevel) {
toplevel->new_inhibitor.notify = idle_inhibitor_new;
wl_signal_add(&toplevel->server->idle_inhibitor->events.new_inhibitor, &toplevel->new_inhibitor);
toplevel->destroy_inhibitor.notify = idle_inhibitor_destroy;
wl_signal_add(&toplevel->server->idle_inhibitor->events.destroy, &toplevel->destroy_inhibitor);
return true;
}

4
waybox/idle.h Normal file
View file

@ -0,0 +1,4 @@
#include "waybox/server.h"
bool create_idle_manager(struct wb_server *server);
bool install_inhibitor(struct wb_toplevel *toplevel);

View file

@ -2,6 +2,7 @@ wb_src = files(
'config.c', 'config.c',
'cursor.c', 'cursor.c',
'decoration.c', 'decoration.c',
'idle.c',
'layer_shell.c', 'layer_shell.c',
'main.c', 'main.c',
'output.c', 'output.c',

View file

@ -41,9 +41,19 @@ void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_scene_output_send_frame_done(scene_output, &now); wlr_scene_output_send_frame_done(scene_output, &now);
} }
void output_configuration_applied(struct wl_listener *listener, void *data) {
struct wb_server *server = wl_container_of(listener, server, wlr_output_manager);
struct wlr_output_configuration_v1 *configuration = data;
wlr_output_configuration_v1_send_succeeded(configuration);
}
void output_request_state_notify(struct wl_listener *listener, void *data) { void output_request_state_notify(struct wl_listener *listener, void *data) {
struct wb_output *output = wl_container_of(listener, output, request_state); struct wb_output *output = wl_container_of(listener, output, request_state);
const struct wlr_output_event_request_state *event = data; const struct wlr_output_event_request_state *event = data;
struct wlr_output_configuration_v1 *configuration = wlr_output_configuration_v1_create();
wlr_output_manager_v1_set_configuration(output->server->wlr_output_manager, configuration);
wlr_output_commit_state(output->wlr_output, event->state); wlr_output_commit_state(output->wlr_output, event->state);
} }
@ -140,6 +150,22 @@ void new_output_notify(struct wl_listener *listener, void *data) {
return; return;
} }
struct wlr_output_configuration_v1 *configuration = wlr_output_configuration_v1_create();
wlr_output_configuration_head_v1_create(configuration, wlr_output);
wlr_output_manager_v1_set_configuration(server->wlr_output_manager, configuration);
struct wlr_scene_output *scene_output = wlr_scene_output_create(server->scene, wlr_output); struct wlr_scene_output *scene_output = wlr_scene_output_create(server->scene, wlr_output);
wlr_scene_output_layout_add_output(server->scene_layout, l_output, scene_output); wlr_scene_output_layout_add_output(server->scene_layout, l_output, scene_output);
} }
void init_output(struct wb_server *server) {
wl_list_init(&server->outputs);
server->new_output.notify = new_output_notify;
wl_signal_add(&server->backend->events.new_output, &server->new_output);
server->wlr_output_manager = wlr_output_manager_v1_create(server->wl_display);
server->output_configuration_applied.notify = output_configuration_applied;
wl_signal_add(&server->wlr_output_manager->events.apply, &server->output_configuration_applied);
wl_signal_add(&server->wlr_output_manager->events.test, &server->output_configuration_applied);
}

View file

@ -1,3 +1,4 @@
#include "idle.h"
#include "waybox/server.h" #include "waybox/server.h"
#include "waybox/xdg_shell.h" #include "waybox/xdg_shell.h"
@ -61,10 +62,7 @@ bool wb_create_backend(struct wb_server* server) {
bool wb_start_server(struct wb_server* server) { bool wb_start_server(struct wb_server* server) {
init_config(server); init_config(server);
wl_list_init(&server->outputs); init_output(server);
server->new_output.notify = new_output_notify;
wl_signal_add(&server->backend->events.new_output, &server->new_output);
/* Create a scene graph. This is a wlroots abstraction that handles all /* Create a scene graph. This is a wlroots abstraction that handles all
* rendering and damage tracking. All the compositor author needs to do * rendering and damage tracking. All the compositor author needs to do
@ -100,7 +98,7 @@ bool wb_start_server(struct wb_server* server) {
wl_signal_add(&server->gamma_control_manager->events.set_gamma, &server->gamma_control_set_gamma); wl_signal_add(&server->gamma_control_manager->events.set_gamma, &server->gamma_control_set_gamma);
wlr_screencopy_manager_v1_create(server->wl_display); wlr_screencopy_manager_v1_create(server->wl_display);
server->idle_notifier = wlr_idle_notifier_v1_create(server->wl_display); create_idle_manager(server);
wl_list_init(&server->toplevels); wl_list_init(&server->toplevels);
init_xdg_decoration(server); init_xdg_decoration(server);

View file

@ -1,3 +1,4 @@
#include "idle.h"
#include "waybox/xdg_shell.h" #include "waybox/xdg_shell.h"
struct wb_toplevel *get_toplevel_at( struct wb_toplevel *get_toplevel_at(
@ -35,7 +36,7 @@ void focus_toplevel(struct wb_toplevel *toplevel, struct wlr_surface *surface) {
} }
struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_try_from_wlr_surface(surface); struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_try_from_wlr_surface(surface);
if (xdg_surface) if (xdg_surface != NULL)
wlr_log(WLR_INFO, "%s: %s", _("Keyboard focus is now on surface"), wlr_log(WLR_INFO, "%s: %s", _("Keyboard focus is now on surface"),
xdg_surface->toplevel->app_id); xdg_surface->toplevel->app_id);
@ -46,7 +47,7 @@ void focus_toplevel(struct wb_toplevel *toplevel, struct wlr_surface *surface) {
/* Don't re-focus an already focused surface. */ /* Don't re-focus an already focused surface. */
return; return;
} }
if (prev_surface) { if (prev_surface != NULL) {
/* /*
* Deactivate the previously focused surface. This lets the client know * Deactivate the previously focused surface. This lets the client know
* it no longer has focus and the client will repaint accordingly, e.g. * it no longer has focus and the client will repaint accordingly, e.g.
@ -72,6 +73,7 @@ void focus_toplevel(struct wb_toplevel *toplevel, struct wlr_surface *surface) {
* clients without additional work on your part. * clients without additional work on your part.
*/ */
seat_focus_surface(server->seat, toplevel->xdg_toplevel->base->surface); seat_focus_surface(server->seat, toplevel->xdg_toplevel->base->surface);
wlr_idle_notifier_v1_set_inhibited(server->idle_notifier, toplevel->inhibited);
} }
struct wlr_output *get_active_output(struct wb_toplevel *toplevel) { struct wlr_output *get_active_output(struct wb_toplevel *toplevel) {
@ -355,6 +357,8 @@ static void handle_new_xdg_toplevel(struct wl_listener *listener, void *data) {
toplevel->new_popup.notify = handle_new_popup; toplevel->new_popup.notify = handle_new_popup;
wl_signal_add(&xdg_toplevel->base->events.new_popup, &toplevel->new_popup); wl_signal_add(&xdg_toplevel->base->events.new_popup, &toplevel->new_popup);
install_inhibitor(toplevel);
toplevel->scene_tree = wlr_scene_xdg_surface_create( toplevel->scene_tree = wlr_scene_xdg_surface_create(
&toplevel->server->scene->tree, xdg_toplevel->base); &toplevel->server->scene->tree, xdg_toplevel->base);
toplevel->scene_tree->node.data = toplevel; toplevel->scene_tree->node.data = toplevel;