Wire up xdg-toplevel-tag-v1

This commit is contained in:
Simon Ser 2025-07-10 16:44:48 +02:00 committed by Kenny Levinsen
parent f57c82a6f7
commit 3826535ab0
5 changed files with 39 additions and 1 deletions

View file

@ -119,6 +119,8 @@ struct sway_server {
struct wl_listener xdg_activation_v1_request_activate; struct wl_listener xdg_activation_v1_request_activate;
struct wl_listener xdg_activation_v1_new_token; struct wl_listener xdg_activation_v1_new_token;
struct wl_listener xdg_toplevel_tag_manager_v1_set_tag;
struct wl_listener request_set_cursor_shape; struct wl_listener request_set_cursor_shape;
struct wlr_tearing_control_manager_v1 *tearing_control_v1; struct wlr_tearing_control_manager_v1 *tearing_control_v1;

View file

@ -25,6 +25,7 @@ enum sway_view_type {
enum sway_view_prop { enum sway_view_prop {
VIEW_PROP_TITLE, VIEW_PROP_TITLE,
VIEW_PROP_APP_ID, VIEW_PROP_APP_ID,
VIEW_PROP_TAG,
VIEW_PROP_CLASS, VIEW_PROP_CLASS,
VIEW_PROP_INSTANCE, VIEW_PROP_INSTANCE,
VIEW_PROP_WINDOW_TYPE, VIEW_PROP_WINDOW_TYPE,
@ -128,6 +129,7 @@ struct sway_xdg_shell_view {
struct sway_view view; struct sway_view view;
struct wlr_scene_tree *image_capture_tree; struct wlr_scene_tree *image_capture_tree;
char *tag;
struct wl_listener commit; struct wl_listener commit;
struct wl_listener request_move; struct wl_listener request_move;
@ -236,6 +238,8 @@ const char *view_get_sandbox_app_id(struct sway_view *view);
const char *view_get_sandbox_instance_id(struct sway_view *view); const char *view_get_sandbox_instance_id(struct sway_view *view);
const char *view_get_tag(struct sway_view *view);
const char *view_get_shell(struct sway_view *view); const char *view_get_shell(struct sway_view *view);
void view_get_constraints(struct sway_view *view, double *min_width, void view_get_constraints(struct sway_view *view, double *min_width,
@ -360,4 +364,6 @@ void view_send_frame_done(struct sway_view *view);
bool view_can_tear(struct sway_view *view); bool view_can_tear(struct sway_view *view);
void xdg_toplevel_tag_manager_v1_handle_set_tag(struct wl_listener *listener, void *data);
#endif #endif

View file

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_xdg_toplevel_tag_v1.h>
#include <wlr/util/edges.h> #include <wlr/util/edges.h>
#include "log.h" #include "log.h"
#include "sway/decoration.h" #include "sway/decoration.h"
@ -157,7 +158,8 @@ static void get_constraints(struct sway_view *view, double *min_width,
static const char *get_string_prop(struct sway_view *view, static const char *get_string_prop(struct sway_view *view,
enum sway_view_prop prop) { enum sway_view_prop prop) {
if (xdg_shell_view_from_view(view) == NULL) { struct sway_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
if (xdg_shell_view == NULL) {
return NULL; return NULL;
} }
switch (prop) { switch (prop) {
@ -165,6 +167,8 @@ static const char *get_string_prop(struct sway_view *view,
return view->wlr_xdg_toplevel->title; return view->wlr_xdg_toplevel->title;
case VIEW_PROP_APP_ID: case VIEW_PROP_APP_ID:
return view->wlr_xdg_toplevel->app_id; return view->wlr_xdg_toplevel->app_id;
case VIEW_PROP_TAG:
return xdg_shell_view->tag;
default: default:
return NULL; return NULL;
} }
@ -265,6 +269,7 @@ static void destroy(struct sway_view *view) {
if (xdg_shell_view == NULL) { if (xdg_shell_view == NULL) {
return; return;
} }
free(xdg_shell_view->tag);
free(xdg_shell_view); free(xdg_shell_view);
} }
@ -581,3 +586,12 @@ void handle_xdg_shell_toplevel(struct wl_listener *listener, void *data) {
xdg_toplevel->base->data = xdg_shell_view; xdg_toplevel->base->data = xdg_shell_view;
} }
void xdg_toplevel_tag_manager_v1_handle_set_tag(struct wl_listener *listener, void *data) {
const struct wlr_xdg_toplevel_tag_manager_v1_set_tag_event *event = data;
struct sway_view *view = view_from_wlr_xdg_surface(event->toplevel->base);
struct sway_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
free(xdg_shell_view->tag);
xdg_shell_view->tag = strdup(event->tag);
view_execute_criteria(view);
}

View file

@ -49,6 +49,7 @@
#include <wlr/types/wlr_xdg_foreign_v1.h> #include <wlr/types/wlr_xdg_foreign_v1.h>
#include <wlr/types/wlr_xdg_foreign_v2.h> #include <wlr/types/wlr_xdg_foreign_v2.h>
#include <wlr/types/wlr_xdg_output_v1.h> #include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_toplevel_tag_v1.h>
#include <xf86drm.h> #include <xf86drm.h>
#include "config.h" #include "config.h"
#include "list.h" #include "list.h"
@ -439,6 +440,13 @@ bool server_init(struct sway_server *server) {
wl_signal_add(&server->xdg_activation_v1->events.new_token, wl_signal_add(&server->xdg_activation_v1->events.new_token,
&server->xdg_activation_v1_new_token); &server->xdg_activation_v1_new_token);
struct wlr_xdg_toplevel_tag_manager_v1 *xdg_toplevel_tag_manager_v1 =
wlr_xdg_toplevel_tag_manager_v1_create(server->wl_display, 1);
server->xdg_toplevel_tag_manager_v1_set_tag.notify =
xdg_toplevel_tag_manager_v1_handle_set_tag;
wl_signal_add(&xdg_toplevel_tag_manager_v1->events.set_tag,
&server->xdg_toplevel_tag_manager_v1_set_tag);
struct wlr_cursor_shape_manager_v1 *cursor_shape_manager = struct wlr_cursor_shape_manager_v1 *cursor_shape_manager =
wlr_cursor_shape_manager_v1_create(server->wl_display, 1); wlr_cursor_shape_manager_v1_create(server->wl_display, 1);
server->request_set_cursor_shape.notify = handle_request_set_cursor_shape; server->request_set_cursor_shape.notify = handle_request_set_cursor_shape;
@ -536,6 +544,7 @@ void server_fini(struct sway_server *server) {
wl_list_remove(&server->tearing_control_new_object.link); wl_list_remove(&server->tearing_control_new_object.link);
wl_list_remove(&server->xdg_activation_v1_request_activate.link); wl_list_remove(&server->xdg_activation_v1_request_activate.link);
wl_list_remove(&server->xdg_activation_v1_new_token.link); wl_list_remove(&server->xdg_activation_v1_new_token.link);
wl_list_remove(&server->xdg_toplevel_tag_manager_v1_set_tag.link);
wl_list_remove(&server->request_set_cursor_shape.link); wl_list_remove(&server->request_set_cursor_shape.link);
wl_list_remove(&server->new_foreign_toplevel_capture_request.link); wl_list_remove(&server->new_foreign_toplevel_capture_request.link);
input_manager_finish(server->input); input_manager_finish(server->input);

View file

@ -190,6 +190,13 @@ const char *view_get_sandbox_instance_id(struct sway_view *view) {
return security_context ? security_context->instance_id : NULL; return security_context ? security_context->instance_id : NULL;
} }
const char *view_get_tag(struct sway_view *view) {
if (view->impl->get_string_prop) {
return view->impl->get_string_prop(view, VIEW_PROP_TAG);
}
return NULL;
}
const char *view_get_shell(struct sway_view *view) { const char *view_get_shell(struct sway_view *view) {
switch(view->type) { switch(view->type) {
case SWAY_VIEW_XDG_SHELL: case SWAY_VIEW_XDG_SHELL: