Commit d90893bc3392b7829dfc864c43d375150c8a9ec6 Parent: 2ce713f01ff7ee183cc888677e3534dd5abf8616 Author: mcol <mcol@posteo.net> Date: 2021-01-24 01:03:51 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-01-24 01:03:51 +0000 Add wlr_xdg_decoration_manager_v1 (credit to sway)
src/types.h Modified
@@ -10,6 +10,7 @@ #include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_xdg_decoration_v1.h> #include <wlr/types/wlr_xdg_shell.h> #include <wlr/util/log.h> @@ -49,6 +50,9 @@ bool mark_waiting; struct mark_indicator mark_indicator; + struct wlr_xdg_decoration_manager_v1 *decoration_manager; + struct wl_listener decoration_listener; + struct wlr_cursor *cursor; struct wlr_xcursor_manager *cursor_manager; struct wl_listener cursor_motion_listener;
src/main.c Modified
@@ -12,6 +12,7 @@ #include "config.h" #include "cursor.h" +#include "decorations.h" #include "desk.h" #include "main.h" #include "keyboard.h" @@ -93,6 +94,7 @@ set_up_shell(&server); set_up_cursor(&server); set_up_keyboard(&server); + set_up_decorations(&server); // start const char *socket = wl_display_add_socket_auto(server.display);
src/decorations.h Added
@@ -0,0 +1,14 @@ +#ifndef DESKWM_DECORATIONS_H +#define DESKWM_DECORATIONS_H + +#include "types.h" + +struct decoration { + struct wlr_xdg_toplevel_decoration_v1 *wlr_xdg_decoration; + struct wl_listener destroy_listener; + struct wl_listener request_mode_listener; +}; + +void set_up_decorations(struct server *server); + +#endif
src/decorations.c Added
@@ -0,0 +1,50 @@ +#include "decorations.h" + + +static void on_destroy(struct wl_listener *listener, void *data) { + struct decoration *deco = wl_container_of(listener, deco, destroy_listener); + wl_list_remove(&deco->destroy_listener.link); + wl_list_remove(&deco->request_mode_listener.link); + free(deco); +} + + +static void on_request_mode(struct wl_listener *listener, void *data) { + struct decoration *deco = wl_container_of(listener, deco, request_mode_listener); + wlr_xdg_toplevel_decoration_v1_set_mode( + deco->wlr_xdg_decoration, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE + ); +} + + +static void on_new_decoration(struct wl_listener *listener, void *data) { + struct wlr_xdg_toplevel_decoration_v1 *wlr_deco = data; + + struct decoration *deco = calloc(1, sizeof(struct decoration)); + if (deco == NULL) { + return; + } + + deco->wlr_xdg_decoration = wlr_deco; + + wl_signal_add(&wlr_deco->events.destroy, &deco->destroy_listener); + deco->destroy_listener.notify = on_destroy; + + wl_signal_add(&wlr_deco->events.request_mode, &deco->request_mode_listener); + deco->request_mode_listener.notify = on_request_mode; + + wlr_xdg_toplevel_decoration_v1_set_mode( + wlr_deco, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE + ); +} + + +void set_up_decorations(struct server *server) { + server->decoration_manager = wlr_xdg_decoration_manager_v1_create(server->display); + + server->decoration_listener.notify = on_new_decoration; + wl_signal_add( + &server->decoration_manager->events.new_toplevel_decoration, + &server->decoration_listener + ); +}