Skip to content

Commit cff0984

Browse files
committed
[Wayland] Add support for xdg-toplevel-tag-v1 protocol
Implementation of the https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/238 wayland protocol. It allows to identify unique toplevels (windows) in order to set their initial size and position
1 parent a3f4407 commit cff0984

10 files changed

Lines changed: 197 additions & 0 deletions

src/core/window-private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ struct _MetaWindow
203203
char *sm_client_id;
204204
char *wm_client_machine;
205205

206+
char *tag;
207+
206208
char *startup_id;
207209
char *muffin_hints;
208210
char *sandboxed_app_id;
@@ -912,4 +914,7 @@ gboolean meta_window_is_focus_async (MetaWindow *window);
912914
gboolean meta_window_calculate_bounds (MetaWindow *window,
913915
int *bounds_width,
914916
int *bounds_height);
917+
918+
void meta_window_set_tag (MetaWindow *window,
919+
const char *tag);
915920
#endif

src/core/window.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ enum
219219
PROP_PROGRESS_PULSE,
220220
PROP_TILE_MODE,
221221
PROP_OPACITY,
222+
PROP_TAG,
222223
PROP_LAST,
223224
};
224225

@@ -352,6 +353,7 @@ meta_window_finalize (GObject *object)
352353
g_free (window->gtk_app_menu_object_path);
353354
g_free (window->gtk_menubar_object_path);
354355
g_free (window->placement.rule);
356+
g_free (window->tag);
355357

356358
G_OBJECT_CLASS (meta_window_parent_class)->finalize (object);
357359
}
@@ -453,6 +455,9 @@ meta_window_get_property(GObject *object,
453455
case PROP_OPACITY:
454456
g_value_set_uint (value, win->opacity);
455457
break;
458+
case PROP_TAG:
459+
g_value_set_string (value, win->tag);
460+
break;
456461
default:
457462
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
458463
break;
@@ -674,6 +679,12 @@ meta_window_class_init (MetaWindowClass *klass)
674679
0xFF,
675680
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
676681

682+
obj_props[PROP_TAG] =
683+
g_param_spec_string ("tag", NULL, NULL,
684+
NULL,
685+
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY |
686+
G_PARAM_STATIC_STRINGS);
687+
677688
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
678689

679690
window_signals[WORKSPACE_CHANGED] =
@@ -9534,3 +9545,29 @@ meta_window_calculate_bounds (MetaWindow *window,
95349545
return FALSE;
95359546
}
95369547
}
9548+
9549+
void
9550+
meta_window_set_tag (MetaWindow *window,
9551+
const char *tag)
9552+
{
9553+
if (g_set_str (&window->tag, tag))
9554+
g_object_notify_by_pspec (G_OBJECT (window), obj_props[PROP_TAG]);
9555+
}
9556+
9557+
/**
9558+
* meta_window_get_tag:
9559+
* @window: A #MetaWindow
9560+
*
9561+
* Get a tag associated to the window.
9562+
* Under wayland the tag can be set using the toplevel tag protocol,
9563+
* and under x11 it falls back to using `NET_WM_WINDOW_TAG` atom.
9564+
*
9565+
* Returns: (nullable): An associated toplevel tag
9566+
*/
9567+
const char *
9568+
meta_window_get_tag (MetaWindow *window)
9569+
{
9570+
g_return_val_if_fail (META_IS_WINDOW (window), NULL);
9571+
9572+
return window->tag;
9573+
}

src/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ if have_wayland
589589
'wayland/meta-wayland-xdg-shell.h',
590590
'wayland/meta-wayland-xdg-dialog.c',
591591
'wayland/meta-wayland-xdg-dialog.h',
592+
'wayland/meta-wayland-xdg-toplevel-tag.c',
593+
'wayland/meta-wayland-xdg-toplevel-tag.h',
592594
'wayland/meta-window-wayland.c',
593595
'wayland/meta-window-wayland.h',
594596
'wayland/meta-window-xwayland.c',
@@ -814,6 +816,7 @@ if have_wayland
814816
['xdg-foreign', 'unstable', 'v2', ],
815817
['xdg-output', 'unstable', 'v1', ],
816818
['xdg-shell', 'stable', ],
819+
['xdg-toplevel-tag', 'staging', 'v1', ],
817820
['xwayland-keyboard-grab', 'unstable', 'v1', ],
818821
]
819822
if have_wayland_eglstream

src/meta/window.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,7 @@ void meta_window_set_opacity (MetaWindow *window,
469469
META_EXPORT
470470
guint8 meta_window_get_opacity (MetaWindow *window);
471471

472+
META_EXPORT
473+
const char * meta_window_get_tag (MetaWindow *window);
474+
472475
#endif

src/wayland/meta-wayland-versions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@
5757
#define META_XDG_ACTIVATION_V1_VERSION 1
5858
#define META_XDG_DIALOG_VERSION 1
5959
#define META_ZWP_PRIMARY_SELECTION_V1_VERSION 1
60+
#define META_XDG_TOPLEVEL_TAG_V1_VERSION 1
6061

6162
#endif
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (C) 2024 Red Hat
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* Written by:
18+
* Bilal Elmoussaoui <[email protected]>
19+
*/
20+
21+
#include "config.h"
22+
23+
#include "wayland/meta-wayland-xdg-toplevel-tag.h"
24+
25+
#include <wayland-server.h>
26+
27+
#include "wayland/meta-wayland-private.h"
28+
#include "wayland/meta-wayland-versions.h"
29+
#include "wayland/meta-wayland-xdg-shell.h"
30+
31+
#include "xdg-toplevel-tag-v1-server-protocol.h"
32+
33+
static void
34+
xdg_toplevel_tag_manager_destroy (struct wl_client *client,
35+
struct wl_resource *resource)
36+
{
37+
wl_resource_destroy (resource);
38+
}
39+
40+
static void
41+
xdg_toplevel_tag_manager_set_toplevel_tag (struct wl_client *client,
42+
struct wl_resource *resource,
43+
44+
45+
46+
47+
struct wl_resource *toplevel_resource,
48+
const char *tag)
49+
{
50+
MetaWaylandXdgToplevel *xdg_toplevel;
51+
MetaWaylandSurfaceRole *surface_role;
52+
MetaWaylandSurface *surface;
53+
MetaWindow *window;
54+
55+
if (!toplevel_resource)
56+
return;
57+
58+
xdg_toplevel = wl_resource_get_user_data (toplevel_resource);
59+
surface_role = META_WAYLAND_SURFACE_ROLE (xdg_toplevel);
60+
surface = meta_wayland_surface_role_get_surface (surface_role);
61+
window = meta_wayland_surface_get_window (surface);
62+
63+
meta_window_set_tag (window, tag);
64+
}
65+
66+
static void
67+
xdg_toplevel_tag_manager_set_toplevel_tag_description (struct wl_client *client,
68+
struct wl_resource *resource,
69+
struct wl_resource *toplevel,
70+
const char *tag_description)
71+
{
72+
/* We don't make use of the toplevel tag description */
73+
}
74+
75+
static const struct xdg_toplevel_tag_manager_v1_interface meta_xdg_toplevel_tag_interface = {
76+
xdg_toplevel_tag_manager_destroy,
77+
xdg_toplevel_tag_manager_set_toplevel_tag,
78+
xdg_toplevel_tag_manager_set_toplevel_tag_description,
79+
};
80+
81+
82+
static void
83+
bind_xdg_toplevel_tag (struct wl_client *client,
84+
void *data,
85+
uint32_t version,
86+
uint32_t id)
87+
{
88+
struct wl_resource *resource;
89+
90+
resource = wl_resource_create (client,
91+
&xdg_toplevel_tag_manager_v1_interface,
92+
META_XDG_TOPLEVEL_TAG_V1_VERSION,
93+
id);
94+
95+
wl_resource_set_implementation (resource,
96+
&meta_xdg_toplevel_tag_interface,
97+
NULL, NULL);
98+
}
99+
100+
void
101+
meta_wayland_xdg_toplevel_tag_init (MetaWaylandCompositor *compositor)
102+
{
103+
if (wl_global_create (compositor->wayland_display,
104+
&xdg_toplevel_tag_manager_v1_interface,
105+
META_XDG_TOPLEVEL_TAG_V1_VERSION,
106+
NULL,
107+
bind_xdg_toplevel_tag) == NULL)
108+
g_error ("Failed to register a global xdg-toplevel-tag object");
109+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2024 Red Hat
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* Written by:
18+
* Bilal Elmoussaoui <[email protected]>
19+
*/
20+
21+
#pragma once
22+
23+
#include <glib.h>
24+
25+
#include "wayland/meta-wayland-types.h"
26+
27+
void meta_wayland_xdg_toplevel_tag_init (MetaWaylandCompositor *compositor);

src/wayland/meta-wayland.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "wayland/meta-wayland-tablet-manager.h"
4747
#include "wayland/meta-wayland-xdg-dialog.h"
4848
#include "wayland/meta-wayland-xdg-foreign.h"
49+
#include "wayland/meta-wayland-xdg-toplevel-tag.h"
4950
#include "wayland/meta-xwayland-grab-keyboard.h"
5051
#include "wayland/meta-xwayland-private.h"
5152
#include "wayland/meta-xwayland.h"
@@ -442,6 +443,7 @@ meta_wayland_compositor_setup (MetaWaylandCompositor *wayland_compositor)
442443
meta_wayland_text_input_init (compositor);
443444
meta_wayland_activation_init (compositor);
444445
meta_wayland_init_xdg_wm_dialog (compositor);
446+
meta_wayland_xdg_toplevel_tag_init (compositor);
445447

446448
/* Xwayland specific protocol, needs to be filtered out for all other clients */
447449
if (meta_xwayland_grab_keyboard_init (compositor))

src/x11/atomnames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ item(_NET_WM_OPAQUE_REGION)
180180
item(_NET_WM_FRAME_DRAWN)
181181
item(_NET_WM_FRAME_TIMINGS)
182182
item(_NET_WM_WINDOW_OPACITY)
183+
item(_NET_WM_WINDOW_TAG)
183184
item(_NET_RESTACK_WINDOW)
184185
item(_NET_WM_XAPP_ICON_NAME)
185186
item(_NET_WM_XAPP_PROGRESS)

src/x11/window-props.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,14 @@ reload_struts (MetaWindow *window,
418418
meta_window_update_struts (window);
419419
}
420420

421+
static void
422+
reload_toplevel_tag (MetaWindow *window,
423+
MetaPropValue *value,
424+
gboolean initial)
425+
{
426+
meta_window_set_tag (window, value->v.str);
427+
}
428+
421429
static void
422430
reload_wm_window_role (MetaWindow *window,
423431
MetaPropValue *value,
@@ -2055,6 +2063,7 @@ meta_x11_display_init_window_prop_hooks (MetaX11Display *x11_display)
20552063
{ x11_display->atom__NET_WM_STRUT_PARTIAL, META_PROP_VALUE_INVALID, reload_struts, NONE },
20562064
{ x11_display->atom__NET_WM_BYPASS_COMPOSITOR, META_PROP_VALUE_CARDINAL, reload_bypass_compositor, LOAD_INIT | INCLUDE_OR },
20572065
{ x11_display->atom__NET_WM_WINDOW_OPACITY, META_PROP_VALUE_CARDINAL, reload_window_opacity, LOAD_INIT | INCLUDE_OR },
2066+
{ x11_display->atom__NET_WM_WINDOW_TAG, META_PROP_VALUE_STRING, reload_toplevel_tag, LOAD_INIT },
20582067
{ x11_display->atom__NET_WM_XAPP_ICON_NAME, META_PROP_VALUE_UTF8, reload_theme_icon_name, LOAD_INIT | INCLUDE_OR },
20592068
{ x11_display->atom__NET_WM_XAPP_PROGRESS, META_PROP_VALUE_CARDINAL, reload_progress, LOAD_INIT | INCLUDE_OR },
20602069
{ x11_display->atom__NET_WM_XAPP_PROGRESS_PULSE, META_PROP_VALUE_CARDINAL, reload_progress_pulse, LOAD_INIT | INCLUDE_OR },

0 commit comments

Comments
 (0)