diff --git a/main.c b/main.c index a076fb24..c9a7b64c 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #include #include +#include #define LOG_MODULE "main" #define LOG_ENABLE_DBG 0 @@ -215,6 +216,10 @@ handle_global(void *data, struct wl_registry *registry, xdg_wm_base_add_listener(term->wl.shell, &xdg_wm_base_listener, term); } + else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) + term->wl.xdg_decoration_manager = wl_registry_bind( + term->wl.registry, name, &zxdg_decoration_manager_v1_interface, 1); + else if (strcmp(interface, wl_seat_interface.name) == 0) { term->wl.seat = wl_registry_bind( term->wl.registry, name, &wl_seat_interface, 5); @@ -340,6 +345,30 @@ static const struct xdg_surface_listener xdg_surface_listener = { .configure = &xdg_surface_configure, }; +static void +xdg_toplevel_decoration_configure(void *data, + struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, + uint32_t mode) +{ + switch (mode) { + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: + LOG_ERR("unimplemented: client-side decorations"); + break; + + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: + LOG_DBG("using server-side decorations"); + break; + + default: + LOG_ERR("unimplemented: unknown XDG toplevel decoration mode: %u", mode); + break; + } +} + +static const struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = { + .configure = &xdg_toplevel_decoration_configure, +}; + static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { @@ -741,6 +770,14 @@ main(int argc, char *const *argv) xdg_toplevel_set_app_id(term.wl.xdg_toplevel, "foot"); term_set_window_title(&term, "foot"); + /* Request server-side decorations */ + term.wl.xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( + term.wl.xdg_decoration_manager, term.wl.xdg_toplevel); + zxdg_toplevel_decoration_v1_set_mode( + term.wl.xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + zxdg_toplevel_decoration_v1_add_listener( + term.wl.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, &term); + /* Scrollback search box */ term.wl.search_surface = wl_compositor_create_surface(term.wl.compositor); term.wl.search_sub_surface = wl_subcompositor_get_subsurface( @@ -1061,6 +1098,10 @@ out: wl_surface_destroy(term.wl.search_surface); if (term.render.frame_callback != NULL) wl_callback_destroy(term.render.frame_callback); + if (term.wl.xdg_toplevel_decoration != NULL) + zxdg_toplevel_decoration_v1_destroy(term.wl.xdg_toplevel_decoration); + if (term.wl.xdg_decoration_manager != NULL) + zxdg_decoration_manager_v1_destroy(term.wl.xdg_decoration_manager); if (term.wl.xdg_toplevel != NULL) xdg_toplevel_destroy(term.wl.xdg_toplevel); if (term.wl.xdg_surface != NULL) diff --git a/meson.build b/meson.build index 01a85cc8..632da62d 100644 --- a/meson.build +++ b/meson.build @@ -60,6 +60,7 @@ wl_proto_headers = [] wl_proto_src = [] foreach prot : [ wayland_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml', + wayland_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml', wayland_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml', wayland_protocols_datadir + '/unstable/primary-selection/primary-selection-unstable-v1.xml', ] diff --git a/terminal.h b/terminal.h index d81ff76d..f5eabad1 100644 --- a/terminal.h +++ b/terminal.h @@ -72,6 +72,9 @@ struct wayland { struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; + struct zxdg_decoration_manager_v1 *xdg_decoration_manager; + struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; + /* Scrollback search */ struct wl_surface *search_surface; struct wl_subsurface *search_sub_surface;