|
| 1 | +/* wayland-utils.c - Wayland utility functions for CSD plugins |
| 2 | + * |
| 3 | + * Copyright (C) 2026 Linux Mint |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation; either version 2 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + */ |
| 10 | + |
| 11 | +#include "config.h" |
| 12 | +#include "wayland-utils.h" |
| 13 | + |
| 14 | +#include <wayland-client.h> |
| 15 | + |
| 16 | +static gboolean layer_shell_available = FALSE; |
| 17 | + |
| 18 | +static void |
| 19 | +registry_handle_global (void *data, |
| 20 | + struct wl_registry *registry, |
| 21 | + uint32_t name, |
| 22 | + const char *interface, |
| 23 | + uint32_t version) |
| 24 | +{ |
| 25 | + if (g_strcmp0 (interface, "zwlr_layer_shell_v1") == 0) |
| 26 | + layer_shell_available = TRUE; |
| 27 | +} |
| 28 | + |
| 29 | +static void |
| 30 | +registry_handle_global_remove (void *data, |
| 31 | + struct wl_registry *registry, |
| 32 | + uint32_t name) |
| 33 | +{ |
| 34 | +} |
| 35 | + |
| 36 | +static const struct wl_registry_listener registry_listener = { |
| 37 | + registry_handle_global, |
| 38 | + registry_handle_global_remove, |
| 39 | +}; |
| 40 | + |
| 41 | +/** |
| 42 | + * csd_check_layer_shell_support: |
| 43 | + * |
| 44 | + * Check if wlr-layer-shell protocol is supported by connecting to the |
| 45 | + * Wayland display and checking the registry. This can be called before |
| 46 | + * gtk_init() unlike gtk_layer_is_supported(). |
| 47 | + * |
| 48 | + * Returns: %TRUE if layer shell is available, %FALSE otherwise |
| 49 | + */ |
| 50 | +gboolean |
| 51 | +csd_check_layer_shell_support (void) |
| 52 | +{ |
| 53 | + struct wl_display *display; |
| 54 | + struct wl_registry *registry; |
| 55 | + |
| 56 | + layer_shell_available = FALSE; |
| 57 | + |
| 58 | + display = wl_display_connect (NULL); |
| 59 | + if (!display) |
| 60 | + return FALSE; |
| 61 | + |
| 62 | + registry = wl_display_get_registry (display); |
| 63 | + wl_registry_add_listener (registry, ®istry_listener, NULL); |
| 64 | + wl_display_roundtrip (display); |
| 65 | + |
| 66 | + wl_registry_destroy (registry); |
| 67 | + wl_display_disconnect (display); |
| 68 | + |
| 69 | + return layer_shell_available; |
| 70 | +} |
0 commit comments