Skip to content

Commit

Permalink
Add wp_content_type_v1 protocol support
Browse files Browse the repository at this point in the history
The wp_content_type_v1 protocol allow the Wayland client to describe the kind
of content a surface will display, to allow the compositor to optimize its
behavior for it.

See
    https://wayland.app/protocols/content-type-v1
    https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/117

Implementation here sets the content type to PHOTO, only if the compositor
advertises this protocol, otherwise, log nothing to the user.

Signed-off-by: nferhat <[email protected]>
  • Loading branch information
nferhat authored Oct 30, 2024
1 parent 23fc19e commit 8503d58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ xdg_shell_h = custom_target(
command: [wl_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
)

# wp_content_type_v1 Wayland protocol
wp_content_type_v1_xml = wlproto_dir / 'staging/content-type/content-type-v1.xml'
wp_content_type_v1_c = custom_target(
'wp-content-type-v1-protocol.c',
output: 'wp-content-type-v1-protocol.c',
input: wp_content_type_v1_xml,
command: [wl_scanner, 'private-code', '@INPUT@', '@OUTPUT@']
)
wp_content_type_v1_h = custom_target(
'wp-content-type-v1-protocol.h',
output: 'wp-content-type-v1-protocol.h',
input: wp_content_type_v1_xml,
command: [wl_scanner, 'client-header', '@INPUT@', '@OUTPUT@']
)

# install sample config
install_data('extra/swayimgrc', install_dir: get_option('datadir') / 'swayimg')

Expand Down Expand Up @@ -194,6 +209,8 @@ sources = [
'src/formats/tga.c',
xdg_shell_h,
xdg_shell_c,
wp_content_type_v1_h,
wp_content_type_v1_c,
]
if exif.found()
sources += 'src/exif.c'
Expand Down
13 changes: 13 additions & 0 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "buildcfg.h"
#include "config.h"
#include "xdg-shell-protocol.h"
#include "wp-content-type-v1-protocol.h"

#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -50,6 +51,7 @@ struct ui {
struct wl_keyboard* keyboard;
struct wl_pointer* pointer;
struct wl_surface* surface;
struct wp_content_type_manager_v1* content_type_manager;
struct wl_output* output;
} wl;

Expand Down Expand Up @@ -600,6 +602,8 @@ static void on_registry_global(void* data, struct wl_registry* registry,
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
ctx.wl.seat = wl_registry_bind(registry, name, &wl_seat_interface, 4);
wl_seat_add_listener(ctx.wl.seat, &seat_listener, data);
} else if (strcmp(interface, wp_content_type_manager_v1_interface.name) == 0) {
ctx.wl.content_type_manager = wl_registry_bind(registry, name, &wp_content_type_manager_v1_interface, 1);
}
}

Expand Down Expand Up @@ -679,6 +683,12 @@ bool ui_init(const char* app_id, size_t width, size_t height)
xdg_toplevel_set_fullscreen(ctx.xdg.toplevel, NULL);
}

if (ctx.wl.content_type_manager) {
struct wp_content_type_v1* content_type;
content_type = wp_content_type_manager_v1_get_surface_content_type(ctx.wl.content_type_manager, ctx.wl.surface);
wp_content_type_v1_set_content_type(content_type, WP_CONTENT_TYPE_V1_TYPE_PHOTO);
}

wl_surface_commit(ctx.wl.surface);

app_watch(wl_display_get_fd(ctx.wl.display), on_wayland_event, NULL);
Expand Down Expand Up @@ -735,6 +745,9 @@ void ui_destroy(void)
if (ctx.wl.compositor) {
wl_compositor_destroy(ctx.wl.compositor);
}
if (ctx.wl.content_type_manager) {
wp_content_type_manager_v1_destroy(ctx.wl.content_type_manager);
}
if (ctx.wl.registry) {
wl_registry_destroy(ctx.wl.registry);
}
Expand Down

0 comments on commit 8503d58

Please sign in to comment.