Ask for server decorations via ZXDG decoration manager

This commit is contained in:
Phireh 2024-12-07 19:57:56 +01:00
commit 55d142e224
3 changed files with 59 additions and 8 deletions

2
.gitignore vendored
View file

@ -3,3 +3,5 @@ xdg-shell-client-protocol.h
xdg-shell-protocol.c xdg-shell-protocol.c
zwp-text-input-unstable-v3-client-protocol.c zwp-text-input-unstable-v3-client-protocol.c
zwp-text-input-unstable-v3-protocol.h zwp-text-input-unstable-v3-protocol.h
xdg-decoration-unstable-v1.c
xdg-decoration-unstable-v1.h

View file

@ -1,8 +1,10 @@
INTERFACEDIR:=$(shell pkg-config --variable=pkgdatadir wayland-protocols) INTERFACEDIR:=$(shell pkg-config --variable=pkgdatadir wayland-protocols)
CFLAGS=-Wall -Wextra -Og -ggdb3 -Wno-unused-but-set-variable -Wno-unused-parameter CFLAGS=-Wall -Wextra -Og -ggdb3 -Wno-unused-but-set-variable -Wno-unused-parameter
LIBS=-lwayland-client -lwayland-egl -lEGL -lOpenGL -lxkbcommon LIBS=-lwayland-client -lwayland-egl -lEGL -lOpenGL -lxkbcommon
wayland: wayland.c xdg-shell-protocol.c xdg-shell-client-protocol.h zwp-text-input-unstable-v3-client-protocol.c zwp-text-input-unstable-v3-protocol.h wayland: wayland.c xdg-shell-protocol.c xdg-shell-client-protocol.h zwp-text-input-unstable-v3-client-protocol.c zwp-text-input-unstable-v3-protocol.h xdg-decoration-unstable-v1.c xdg-decoration-unstable-v1.h
gcc $(CFLAGS) $(LIBS) wayland.c xdg-shell-protocol.c zwp-text-input-unstable-v3-client-protocol.c -o wayland gcc $(CFLAGS) $(LIBS) wayland.c xdg-shell-protocol.c xdg-decoration-unstable-v1.c zwp-text-input-unstable-v3-client-protocol.c -o wayland
# TODO: Normalize these annoying names
xdg-shell-protocol.c: xdg-shell-protocol.c:
wayland-scanner private-code $(INTERFACEDIR)/stable/xdg-shell/xdg-shell.xml xdg-shell-protocol.c wayland-scanner private-code $(INTERFACEDIR)/stable/xdg-shell/xdg-shell.xml xdg-shell-protocol.c
xdg-shell-client-protocol.h: xdg-shell-client-protocol.h:
@ -11,3 +13,7 @@ zwp-text-input-unstable-v3-client-protocol.c:
wayland-scanner private-code $(INTERFACEDIR)/unstable/text-input/text-input-unstable-v3.xml zwp-text-input-unstable-v3-client-protocol.c wayland-scanner private-code $(INTERFACEDIR)/unstable/text-input/text-input-unstable-v3.xml zwp-text-input-unstable-v3-client-protocol.c
zwp-text-input-unstable-v3-protocol.h: zwp-text-input-unstable-v3-protocol.h:
wayland-scanner client-header $(INTERFACEDIR)/unstable/text-input/text-input-unstable-v3.xml zwp-text-input-unstable-v3-protocol.h wayland-scanner client-header $(INTERFACEDIR)/unstable/text-input/text-input-unstable-v3.xml zwp-text-input-unstable-v3-protocol.h
xdg-decoration-unstable-v1.c:
wayland-scanner private-code $(INTERFACEDIR)/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml xdg-decoration-unstable-v1.c
xdg-decoration-unstable-v1.h:
wayland-scanner client-header $(INTERFACEDIR)/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml xdg-decoration-unstable-v1.h

View file

@ -18,6 +18,7 @@
// generated header using wayland-scanner // generated header using wayland-scanner
#include "xdg-shell-client-protocol.h" #include "xdg-shell-client-protocol.h"
#include "zwp-text-input-unstable-v3-protocol.h" #include "zwp-text-input-unstable-v3-protocol.h"
#include "xdg-decoration-unstable-v1.h"
// common headers for platform layer and application layer // common headers for platform layer and application layer
#include "input.h" #include "input.h"
#include "arena.h" #include "arena.h"
@ -40,6 +41,9 @@ struct wl_pointer *wl_pointer = NULL;
struct zwp_text_input_v3 *zwp_text_input_v3 = NULL; struct zwp_text_input_v3 *zwp_text_input_v3 = NULL;
struct zwp_text_input_manager_v3 *zwp_text_input_manager_v3 = NULL; struct zwp_text_input_manager_v3 *zwp_text_input_manager_v3 = NULL;
/* XDG decoration manager extension */
struct zxdg_decoration_manager_v1* zxdg_decoration_manager_v1 = NULL;
/* XKB library */ /* XKB library */
struct xkb_context *xkb_context = NULL; struct xkb_context *xkb_context = NULL;
@ -98,8 +102,29 @@ void registry_handle_global( void *data, struct wl_registry *registry,
if (!strcmp(interface, zwp_text_input_manager_v3_interface.name)) if (!strcmp(interface, zwp_text_input_manager_v3_interface.name))
{ {
console_log_ss(MODULE_WAYLAND, "Registering WL input manager v3 interface...\n");
zwp_text_input_manager_v3 = wl_registry_bind(registry, name, &zwp_text_input_manager_v3_interface, 1); zwp_text_input_manager_v3 = wl_registry_bind(registry, name, &zwp_text_input_manager_v3_interface, 1);
} }
if (!strcmp(interface, zxdg_decoration_manager_v1_interface.name))
{
console_log_ss(MODULE_WAYLAND, "Registering WL decoration manager v1 interface...\n");
zxdg_decoration_manager_v1 = wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1);
}
}
void zxdg_toplevel_decoration_configure_callback(void *data, struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, uint32_t mode)
{
// TODO: We are supposed to call xdg_surface_ack_configure here
console_log_ss(MODULE_WAYLAND, "Setting XDG toplevel to use %s decorations\n",
(ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE == mode ? "server" : "client"));
}
void xdg_surface_configure_callback(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
{
// confirm that you exist to the compositor
console_log_ss(MODULE_WAYLAND, "ACKing XDG configuration with serial %d\n", serial);
xdg_surface_ack_configure(xdg_surface, serial);
} }
void zwp_text_input_v3_enter_callback(void *data, struct zwp_text_input_v3 *text_input, struct wl_surface *surface) void zwp_text_input_v3_enter_callback(void *data, struct zwp_text_input_v3 *text_input, struct wl_surface *surface)
@ -358,22 +383,21 @@ void pointer_axis_relative_direction_callback(void *data, struct wl_pointer *poi
int main() int main()
{ {
fprintf(stdout, "Starting platform layer...\n"); console_log("Starting platform layer...\n");
main_arena = arena_create(1*GB); main_arena = arena_create(1*GB);
if (!main_arena.begin) if (!main_arena.begin)
fprintf(stderr, "Could not reserve memory for main arena!\n"); console_err("Could not reserve memory for main arena!\n");
struct wl_display *display = wl_display_connect(NULL); struct wl_display *display = wl_display_connect(NULL);
if (!display) if (!display)
{ {
fprintf(stderr, "Cannot retrieve wayland display!\n"); console_err_ss(MODULE_WAYLAND, "Cannot retrieve wayland display!\n");
} }
registry = wl_display_get_registry(display); registry = wl_display_get_registry(display);
if (!registry) if (!registry)
{ {
fprintf(stderr, "Cannot retrieve wayland registry!\n"); console_err_ss(MODULE_WAYLAND, "Cannot retrieve wayland registry!\n");
} }
fprintf(stdout, "Linking registry listener...\n"); fprintf(stdout, "Linking registry listener...\n");
@ -385,13 +409,32 @@ int main()
surface = wl_compositor_create_surface(compositor); surface = wl_compositor_create_surface(compositor);
if (!surface) if (!surface)
{ {
fprintf(stderr, "Can't create surface!\n"); console_err_ss(MODULE_WAYLAND, "Can't create WL surface!\n");
} }
xdg_surface = xdg_wm_base_get_xdg_surface(wm_base, surface); xdg_surface = xdg_wm_base_get_xdg_surface(wm_base, surface);
xdg_toplevel = xdg_surface_get_toplevel(xdg_surface); xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
xdg_toplevel_set_title(xdg_toplevel, "Hi"); xdg_toplevel_set_title(xdg_toplevel, "Hi");
const struct xdg_surface_listener xdg_surface_listener = {
.configure = xdg_surface_configure_callback
};
xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, NULL);
if (!zxdg_decoration_manager_v1)
console_warn_ss(MODULE_WAYLAND, "Could not get XDG decoration manager handle\n");
struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1 = zxdg_decoration_manager_v1_get_toplevel_decoration(zxdg_decoration_manager_v1, xdg_toplevel);
struct zxdg_toplevel_decoration_v1_listener zxdg_toplevel_decoration_v1_listener = {
.configure = zxdg_toplevel_decoration_configure_callback
};
if (zxdg_toplevel_decoration_v1_add_listener(zxdg_toplevel_decoration_v1, &zxdg_toplevel_decoration_v1_listener, NULL))
console_warn_ss(MODULE_WAYLAND, "Could not set ZXDG toplevel decoration listener\n");
zxdg_toplevel_decoration_v1_set_mode(zxdg_toplevel_decoration_v1, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
/* XKB library initialization */ /* XKB library initialization */
xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);