|
| 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 | +} |
0 commit comments