pax_global_header00006660000000000000000000000064135371660130014517gustar00rootroot0000000000000052 comment=d1f9d94be32f8cc61c0a53af7558146570f0fa9f gtk-layer-shell-0.1.0/000077500000000000000000000000001353716601300145215ustar00rootroot00000000000000gtk-layer-shell-0.1.0/.editorconfig000066400000000000000000000001631353716601300171760ustar00rootroot00000000000000root = true [*] end_of_line = lf insert_final_newline = true charset = utf-8 indent_style = space indent_size = 4 gtk-layer-shell-0.1.0/.gitignore000066400000000000000000000000071353716601300165060ustar00rootroot00000000000000build/ gtk-layer-shell-0.1.0/COPYING000066400000000000000000000021361353716601300155560ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Dennis Blommesteijn Copyright (c) 2019 William Wold Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gtk-layer-shell-0.1.0/README.md000066400000000000000000000041201353716601300157750ustar00rootroot00000000000000# GTK Layer Shell ![GTK Layer Shell demo screenshot](https://i.imgur.com/dIuYcBM.png) A library to write [GTK](https://www.gtk.org/) applications that use [Layer Shell](https://github.com/swaywm/wlr-protocols/blob/master/unstable/wlr-layer-shell-unstable-v1.xml). Layer Shell is a Wayland protocol for desktop shell components, such as panels, notifications and wallpapers. You can use it to anchor your windows to a corner or edge of the output, or stretch them across the entire output. This library only makes sense on Wayland compositors that support Layer Shell, and will not work on X11. It supports all Layer Shell features including popups and popovers (GTK popups Just Work™). Please open issues for any bugs you come across. ## To install 1. Clone this repo 2. Install build dependencies (see below) 3. `$ meson build -Dexamples=true -Ddocs=true` 4. `$ ninja -C build` 5. `$ sudo ninja -C build install` 6. `$ sudo ldconfig` ### Build dependencies * [Meson](https://mesonbuild.com/) (>=0.45.1) * [libwayland](https://gitlab.freedesktop.org/wayland/wayland) (>=1.10.0) * [GTK3](https://www.gtk.org/) (>=3.22.0) * [GObject introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/) * [GTK Doc](https://www.gtk.org/gtk-doc/) (Optional) #### Install dependencies on Ubuntu 18.04 and later ``` sudo apt install meson libwayland-dev libgtk-3-dev gobject-introspection libgirepository1.0-dev ``` ### Options * `examples`: If to build gtk-layer-example and if to build and install gtk-layer-demo (default false) * `docs`: If to generate the docs (default false) ## To use * `gtk-layer-demo` is installed if examples are enabled. Its UI exposes all features of the library, and it's useful for testing layer shell support in compositors * [gtk-layer-shell.h](include/gtk-layer-shell.h) contains the full API * [example/example.c](example/example.c) is a minimal working app * [demo/](demo/) contains the code for `gtk-layer-demo` (a more complex app) * The easiest way to build is to use the `gtk-layer-shell-0` pkg-config package. Refer to your build system or the pkg-config docs for further instructions gtk-layer-shell-0.1.0/demo/000077500000000000000000000000001353716601300154455ustar00rootroot00000000000000gtk-layer-shell-0.1.0/demo/anchor-control.c000066400000000000000000000067331353716601300205520ustar00rootroot00000000000000#include "gtk-layer-demo.h" typedef struct { GtkLayerShellEdge edge; GtkWindow *layer_window; } AnchorButtonData; static void on_anchor_toggled (GtkToggleButton *button, AnchorButtonData *data) { gboolean is_anchored = gtk_toggle_button_get_active (button); ToplevelData *toplevel_data = g_object_get_data (G_OBJECT (data->layer_window), anchor_edges_key); g_return_if_fail (toplevel_data); toplevel_data->edges[data->edge] = is_anchored; layer_window_update_orientation (data->layer_window); gtk_layer_set_anchor (data->layer_window, data->edge, is_anchored); } static GtkWidget * anchor_edge_button_new (GtkWindow *layer_window, GtkLayerShellEdge edge, const gboolean defaults[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER], const char *icon_name, const char *tooltip) { GtkWidget *button = gtk_toggle_button_new (); gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON)); gtk_widget_set_tooltip_text (button, tooltip); AnchorButtonData *data = g_new0 (AnchorButtonData, 1); *data = (AnchorButtonData) { .edge = edge, .layer_window = layer_window, }; g_object_set_data_full(G_OBJECT (button), "clicked_signal_data", data, (GDestroyNotify)g_free); g_signal_connect (button, "clicked", G_CALLBACK (on_anchor_toggled), data); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), defaults[edge]); return button; } GtkWidget * anchor_control_new (GtkWindow *layer_window, const gboolean default_anchors[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]) { GtkWidget *outside_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); GtkWidget *outside_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (outside_vbox), outside_hbox, TRUE, FALSE, 0); { GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_pack_start (GTK_BOX (outside_hbox), hbox, TRUE, FALSE, 0); { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (hbox), vbox); { GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_LEFT, default_anchors, "go-first", "Anchor left"); gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, FALSE, 0); } }{ GtkWidget *center_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 40); gtk_container_add (GTK_CONTAINER (hbox), center_vbox); { GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_TOP, default_anchors, "go-top", "Anchor top"); gtk_box_pack_start (GTK_BOX (center_vbox), button, FALSE, FALSE, 0); }{ GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_BOTTOM, default_anchors, "go-bottom", "Anchor bottom"); gtk_box_pack_end (GTK_BOX (center_vbox), button, FALSE, FALSE, 0); } }{ GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (hbox), vbox); { GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_RIGHT, default_anchors, "go-last", "Anchor right"); gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, FALSE, 0); } } } return outside_vbox; } gtk-layer-shell-0.1.0/demo/gtk-layer-demo.c000066400000000000000000000317761353716601300204500ustar00rootroot00000000000000#include "gtk-layer-demo.h" static GtkLayerShellLayer default_layer = GTK_LAYER_SHELL_LAYER_TOP; static gboolean default_anchors[] = {FALSE, FALSE, FALSE, FALSE}; static int default_margins[] = {0, 0, 0, 0}; static gboolean default_auto_exclusive_zone = FALSE; // always set by command line option static gboolean default_keyboard_interactivity = FALSE; // always set by command line option static gboolean default_fixed_size = FALSE; // always set by command line option const char *prog_name = "gtk-layer-demo"; const char *prog_summary = "A GTK application for demonstrating the functionality of the Layer Shell Wayland protocol"; const char *prog_details = "See https://github.com/wmww/gtk-layer-shell for more information, and to report bugs"; const char *anchor_edges_key = "anchor_edges"; gboolean layer_option_callback (const gchar *option_name, const gchar *value, void *data, GError **error); gboolean anchor_option_callback (const gchar *option_name, const gchar *value, void *data, GError **error); gboolean margin_option_callback (const gchar *option_name, const gchar *value, void *data, GError **error); static const GOptionEntry options[] = { { .long_name = "layer", .short_name = 'l', .flags = G_OPTION_FLAG_NONE, .arg = G_OPTION_ARG_CALLBACK, .arg_data = (void *)&layer_option_callback, .description = "\"overlay\", \"top\", \"bottom\" or background (or \"o\", \"t\", \"b\" or \"g\")", .arg_description = NULL, }, { .long_name = "anchor", .short_name = 'a', .flags = G_OPTION_FLAG_OPTIONAL_ARG, .arg = G_OPTION_ARG_CALLBACK, .arg_data = (void *)&anchor_option_callback, .description = "A sequence of 'l', 'r', 't' and 'b' to anchor to those edges, or \"0\" for no anchor", .arg_description = NULL, }, { .long_name = "margin", .short_name = 'm', .flags = G_OPTION_FLAG_NONE, .arg = G_OPTION_ARG_CALLBACK, .arg_data = (void *)&margin_option_callback, .description = "Comma separated list of margin values, in the order LEFT,RIGHT,TOP,BOTTOM", .arg_description = NULL, }, { .long_name = "exclusive", .short_name = 'e', .flags = G_OPTION_FLAG_NONE, .arg = G_OPTION_ARG_NONE, .arg_data = &default_auto_exclusive_zone, .description = "Enable auto exclusive zone", .arg_description = NULL, }, { .long_name = "keyboard", .short_name = 'k', .flags = G_OPTION_FLAG_NONE, .arg = G_OPTION_ARG_NONE, .arg_data = &default_keyboard_interactivity, .description = "Enable keyboard interactivity", .arg_description = NULL, }, { .long_name = "fixed-size", .short_name = 'f', .flags = G_OPTION_FLAG_NONE, .arg = G_OPTION_ARG_NONE, .arg_data = &default_fixed_size, .description = "Enable a fixed window size", .arg_description = NULL, }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; gboolean layer_option_callback (const gchar *_option_name, const gchar *value, void *_data, GError **error) { (void)_option_name; (void)_data; if (g_strcmp0 (value, "overlay") == 0 || g_strcmp0 (value, "o") == 0) { default_layer = GTK_LAYER_SHELL_LAYER_OVERLAY; } else if (g_strcmp0 (value, "top") == 0 || g_strcmp0 (value, "t") == 0) { default_layer = GTK_LAYER_SHELL_LAYER_TOP; } else if (g_strcmp0 (value, "bottom") == 0 || g_strcmp0 (value, "b") == 0) { default_layer = GTK_LAYER_SHELL_LAYER_BOTTOM; } else if (g_strcmp0 (value, "background") == 0 || g_strcmp0 (value, "g") == 0) { default_layer = GTK_LAYER_SHELL_LAYER_BACKGROUND; } else { g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Invalid layer \"%s\"", value); return FALSE; } return TRUE; } gboolean anchor_option_callback (const gchar *_option_name, const gchar *value, void *_data, GError **error) { (void)_option_name; (void)_data; for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) { default_anchors[i] = FALSE; } if (!value || !*value || g_strcmp0 (value, "0") == 0 || g_strcmp0 (value, "none") == 0) { return TRUE; } for (const char *c = value; *c; c++) { if (*c == 'l') { default_anchors[GTK_LAYER_SHELL_EDGE_LEFT] = TRUE; } else if (*c == 'r') { default_anchors[GTK_LAYER_SHELL_EDGE_RIGHT] = TRUE; } else if (*c == 't') { default_anchors[GTK_LAYER_SHELL_EDGE_TOP] = TRUE; } else if (*c == 'b') { default_anchors[GTK_LAYER_SHELL_EDGE_BOTTOM] = TRUE; } else { g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Invalid anchor edge '%c'", *c); return FALSE; } } return TRUE; } gboolean margin_option_callback (const gchar *_option_name, const gchar *value, void *_data, GError **error) { (void)_option_name; (void)_data; for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) { if (!*value) { g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Not enought comma separated arguments for margin"); return FALSE; } char *end; long long margin = strtol (value, &end, 10); default_margins[i] = margin; if (end == value) { g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Unable to parse margin"); return FALSE; } value = end; if (*value == ',') value++; } if (*value) { g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Too many comma separated arguments for margin"); return FALSE; } return TRUE; } static void process_args (int *argc, char ***argv) { GOptionContext *context = g_option_context_new (""); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_set_summary (context, prog_summary); g_option_context_set_description (context, prog_details); g_option_context_add_main_entries (context, options, NULL); GError *error = NULL; if (!g_option_context_parse (context, argc, argv, &error)) { g_printerr ("%s\n", error->message); g_error_free (error); g_option_context_free (context); exit (1); } g_option_context_free (context); } void layer_window_update_orientation (GtkWindow *layer_window) { ToplevelData *data = g_object_get_data (G_OBJECT (layer_window), anchor_edges_key); gboolean horiz = data->edges[GTK_LAYER_SHELL_EDGE_LEFT] == data->edges[GTK_LAYER_SHELL_EDGE_RIGHT]; gboolean vert = data->edges[GTK_LAYER_SHELL_EDGE_TOP] == data->edges[GTK_LAYER_SHELL_EDGE_BOTTOM]; WindowOrientation orientation = WINDOW_ORIENTATION_NONE; if (horiz && (!vert || (data->edges[GTK_LAYER_SHELL_EDGE_LEFT] && !data->edges[GTK_LAYER_SHELL_EDGE_TOP]))) { orientation = WINDOW_ORIENTATION_HORIZONTAL; } else if (vert && (!horiz || (data->edges[GTK_LAYER_SHELL_EDGE_TOP] && !data->edges[GTK_LAYER_SHELL_EDGE_LEFT]))) { orientation = WINDOW_ORIENTATION_VERTICAL; } if (orientation != data->orientation) { data->orientation = orientation; g_signal_emit_by_name(layer_window, "orientation-changed", orientation); } } static void on_orientation_changed (GtkWindow *window, WindowOrientation orientation, ToplevelData *data) { GtkOrientation orient_toplevel, orient_sub; orient_toplevel = GTK_ORIENTATION_HORIZONTAL; orient_sub = GTK_ORIENTATION_VERTICAL; switch (orientation) { case WINDOW_ORIENTATION_HORIZONTAL: orient_toplevel = GTK_ORIENTATION_HORIZONTAL; orient_sub = GTK_ORIENTATION_HORIZONTAL; break; case WINDOW_ORIENTATION_VERTICAL: orient_toplevel = GTK_ORIENTATION_VERTICAL; orient_sub = GTK_ORIENTATION_VERTICAL; break; case WINDOW_ORIENTATION_NONE: orient_toplevel = GTK_ORIENTATION_HORIZONTAL; orient_sub = GTK_ORIENTATION_VERTICAL; break; } gtk_orientable_set_orientation (GTK_ORIENTABLE (data->toplevel_box), orient_toplevel); gtk_orientable_set_orientation (GTK_ORIENTABLE (data->first_box), orient_sub); gtk_orientable_set_orientation (GTK_ORIENTABLE (data->second_box), orient_sub); gtk_window_resize (window, 1, 1); // force the window to shrink to the smallest size it can } static void on_window_destroy(GtkWindow *_window, void *_data) { (void)_window; (void)_data; gtk_main_quit (); } static GtkWidget * layer_window_new () { GtkWindow *gtk_window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); gtk_layer_init_for_window (gtk_window); ToplevelData *data = g_new0 (ToplevelData, 1); for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) { data->edges[i] = default_anchors[i]; gtk_layer_set_anchor (gtk_window, i, default_anchors[i]); } g_object_set_data_full (G_OBJECT (gtk_window), anchor_edges_key, data, g_free); for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) gtk_layer_set_margin (gtk_window, i, default_margins[i]); gtk_layer_set_layer (gtk_window, default_layer); gtk_layer_set_exclusive_zone (gtk_window, default_auto_exclusive_zone); gtk_layer_set_keyboard_interactivity (gtk_window, default_keyboard_interactivity); gtk_layer_set_namespace (gtk_window, "demo"); GtkWidget *centered_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (gtk_window), centered_vbox); GtkWidget *centered_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (centered_vbox), centered_hbox, TRUE, FALSE, 0); data->toplevel_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (data->toplevel_box), 16); gtk_box_pack_start (GTK_BOX (centered_hbox), data->toplevel_box, TRUE, FALSE, 0); { data->first_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_box_pack_start (GTK_BOX (data->toplevel_box), data->first_box, FALSE, FALSE, 0); { GtkWidget *selections_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (selections_box), menu_bar_new (gtk_window), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (data->first_box), selections_box, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (selections_box), monitor_selection_new (gtk_window), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (selections_box), layer_selection_new (gtk_window, default_layer), FALSE, FALSE, 0); }{ gtk_box_pack_start (GTK_BOX (data->first_box), anchor_control_new (gtk_window, default_anchors), FALSE, FALSE, 0); } }{ data->second_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_box_pack_start (GTK_BOX (data->toplevel_box), data->second_box, FALSE, FALSE, 0); { GtkWidget *toggles_box = mscl_toggles_new (gtk_window, default_auto_exclusive_zone, default_keyboard_interactivity, default_fixed_size); gtk_box_pack_start (GTK_BOX (data->second_box), toggles_box, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (data->second_box), margin_control_new (gtk_window, default_margins), FALSE, FALSE, 0); } } g_signal_connect (gtk_window, "orientation-changed", G_CALLBACK (on_orientation_changed), data); data->orientation = -1; // invalid value will force anchor_edges_update_orientation to update layer_window_update_orientation (gtk_window); return GTK_WIDGET (gtk_window); } int main (int argc, char **argv) { g_set_prgname (prog_name); gtk_init (&argc, &argv); process_args (&argc, &argv); // The int arg is an enum of type WindowOrientation // Signal is emitted in anchor-control.c g_signal_new ("orientation-changed", GTK_TYPE_WINDOW, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); GtkWidget *initial_window = layer_window_new (); g_signal_connect (initial_window, "destroy", G_CALLBACK (on_window_destroy), NULL); gtk_widget_show_all (GTK_WIDGET (initial_window)); gtk_main (); } gtk-layer-shell-0.1.0/demo/gtk-layer-demo.h000066400000000000000000000023431353716601300204410ustar00rootroot00000000000000#ifndef GTK_LAYER_DEMO_H #define GTK_LAYER_DEMO_H #include "gtk-layer-shell.h" #include typedef enum { WINDOW_ORIENTATION_NONE = 0, WINDOW_ORIENTATION_HORIZONTAL, WINDOW_ORIENTATION_VERTICAL, } WindowOrientation; typedef struct { gboolean edges[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]; WindowOrientation orientation; GtkWidget *toplevel_box; GtkWidget *first_box; GtkWidget *second_box; } ToplevelData; extern const char *anchor_edges_key; void layer_window_update_orientation (GtkWindow *layer_window); GtkWidget * layer_selection_new (GtkWindow *layer_window, GtkLayerShellLayer default_layer); GtkWidget * monitor_selection_new (GtkWindow *layer_window); GtkWidget * anchor_control_new (GtkWindow *layer_window, const gboolean default_anchors[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]); GtkWidget * margin_control_new (GtkWindow *layer_window, const int default_margins[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]); GtkWidget * mscl_toggles_new (GtkWindow *layer_window, gboolean default_auto_exclusive_zone, gboolean default_keyboard_interactivity, gboolean default_fixed_size); GtkWidget * menu_bar_new (GtkWindow *layer_window); #endif // GTK_LAYER_DEMO_H gtk-layer-shell-0.1.0/demo/layer-selection.c000066400000000000000000000032161353716601300207120ustar00rootroot00000000000000#include "gtk-layer-demo.h" struct { const char *name; GtkLayerShellLayer value; } const all_layers[] = { {"Overlay", GTK_LAYER_SHELL_LAYER_OVERLAY}, {"Top", GTK_LAYER_SHELL_LAYER_TOP}, {"Bottom", GTK_LAYER_SHELL_LAYER_BOTTOM}, {"Background", GTK_LAYER_SHELL_LAYER_BACKGROUND}, }; static void on_layer_selected (GtkComboBox *widget, GtkWindow *layer_window) { GtkComboBox *combo_box = widget; gchar *layer = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (combo_box)); gboolean layer_was_set = FALSE; for (unsigned i = 0; i < sizeof(all_layers) / sizeof(all_layers[0]); i++) { if (g_strcmp0 (layer, all_layers[i].name) == 0) { gtk_layer_set_layer (layer_window, all_layers[i].value); layer_was_set = TRUE; break; } } g_free (layer); g_return_if_fail (layer_was_set); } GtkWidget * layer_selection_new (GtkWindow *layer_window, GtkLayerShellLayer default_layer) { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); { GtkWidget *combo_box = gtk_combo_box_text_new (); gtk_widget_set_tooltip_text (combo_box, "Layer"); for (unsigned i = 0; i < sizeof(all_layers) / sizeof(all_layers[0]); i++) { gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), all_layers[i].name); if (all_layers[i].value == default_layer) gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), i); } g_signal_connect (combo_box, "changed", G_CALLBACK (on_layer_selected), layer_window); gtk_box_pack_start (GTK_BOX (vbox), combo_box, FALSE, FALSE, 0); } return vbox; } gtk-layer-shell-0.1.0/demo/margin-control.c000066400000000000000000000101671353716601300205510ustar00rootroot00000000000000#include "gtk-layer-demo.h" static void on_orientation_changed (GtkWindow *_window, WindowOrientation orientation, GtkWidget *box) { (void)_window; switch (orientation) { case WINDOW_ORIENTATION_HORIZONTAL: gtk_orientable_set_orientation (GTK_ORIENTABLE (box), GTK_ORIENTATION_HORIZONTAL); break; case WINDOW_ORIENTATION_VERTICAL: gtk_orientable_set_orientation (GTK_ORIENTABLE (box), GTK_ORIENTATION_VERTICAL); break; case WINDOW_ORIENTATION_NONE: gtk_orientable_set_orientation (GTK_ORIENTABLE (box), GTK_ORIENTATION_VERTICAL); break; } } typedef struct { GtkLayerShellEdge edge; GtkWindow *layer_window; } MarginSpinButtonData; static void on_margin_changed (GtkSpinButton *button, MarginSpinButtonData *data) { int value = gtk_spin_button_get_value (button); gtk_layer_set_margin (data->layer_window, data->edge, value); } static GtkWidget * margin_spin_button_new (GtkWindow *layer_window, GtkLayerShellEdge edge, const char *tooltip, const int default_margins[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]) { GtkAdjustment *adjustment = gtk_adjustment_new (default_margins[edge], 0.0, 4000.0, 20.0, 50.0, 0.0); GtkWidget *button = gtk_spin_button_new (adjustment, 0.5, 0); gtk_widget_set_tooltip_text (button, tooltip); MarginSpinButtonData *data = g_new0 (MarginSpinButtonData, 1); *data = (MarginSpinButtonData) { .edge = edge, .layer_window = layer_window, }; g_object_set_data_full(G_OBJECT (button), "value-changed_signal_data", data, (GDestroyNotify)g_free); g_signal_connect (button, "value-changed", G_CALLBACK (on_margin_changed), data); return button; } static void on_open_clicked (GtkWidget *_button, GtkWidget *popover) { (void)_button; gtk_popover_popup (GTK_POPOVER (popover)); } GtkWidget * margin_control_new (GtkWindow *layer_window, const int default_margins[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]) { const int spacing = 4; GtkWidget *switch_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, spacing); g_signal_connect (layer_window, "orientation-changed", G_CALLBACK (on_orientation_changed), switch_box); { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, spacing); gtk_box_pack_start (GTK_BOX (switch_box), vbox, FALSE, FALSE, 0); { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_LEFT, "Left margin", default_margins); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); } { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_RIGHT, "Right margin", default_margins); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); } } { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, spacing); gtk_box_pack_start (GTK_BOX (switch_box), vbox, FALSE, FALSE, 0); { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_TOP, "Top margin", default_margins); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); } { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_BOTTOM, "Bottom margin", default_margins); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); } } GtkWidget *open_button = gtk_button_new_with_label ("Set margin"); GtkWidget *popover = gtk_popover_new (open_button); gtk_popover_set_modal (GTK_POPOVER (popover), TRUE); gtk_popover_set_constrain_to (GTK_POPOVER (popover), GTK_POPOVER_CONSTRAINT_WINDOW); gtk_popover_set_position (GTK_POPOVER (popover), GTK_POS_BOTTOM); gtk_container_add (GTK_CONTAINER (popover), switch_box); gtk_widget_show_all (switch_box); g_signal_connect (open_button, "clicked", G_CALLBACK (on_open_clicked), popover); GtkWidget *padding_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (padding_box), open_button, TRUE, FALSE, 0); return padding_box; } gtk-layer-shell-0.1.0/demo/menu-bar.c000066400000000000000000000053121353716601300173200ustar00rootroot00000000000000#include "gtk-layer-demo.h" static void on_close_clicked (GtkMenuItem *_item, GtkWindow *layer_window) { (void)_item; gtk_window_close (layer_window); } GtkWidget * menu_bar_new (GtkWindow *layer_window) { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); { GtkWidget *menu_bar = gtk_menu_bar_new (); gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, FALSE, 0); { GtkWidget *menu_item = gtk_menu_item_new_with_label ("Popup menu"); gtk_container_add (GTK_CONTAINER (menu_bar), menu_item); { GtkWidget *submenu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu); { GtkWidget *nested_menu_item = gtk_menu_item_new_with_label ("Nested popup"); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), nested_menu_item); { GtkWidget *nested_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (nested_menu_item), nested_menu); for (int i = 0; i < 3; i++) { GString *label = g_string_new (""); g_string_printf (label, "Menu item %d", i); GtkWidget *submenu_item = gtk_menu_item_new_with_label (label->str); g_string_free (label, TRUE); gtk_menu_shell_append (GTK_MENU_SHELL (nested_menu), submenu_item); } { GtkWidget *submenu_item = gtk_menu_item_new_with_label ("Nested again"); gtk_menu_shell_append (GTK_MENU_SHELL (nested_menu), submenu_item); { GtkWidget *nested_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenu_item), nested_menu); { GtkWidget *submenu_item = gtk_menu_item_new_with_label ("Final item"); gtk_menu_shell_append (GTK_MENU_SHELL (nested_menu), submenu_item); } } } } } { GtkWidget *close_item = gtk_menu_item_new_with_label ("Close"); g_signal_connect (close_item, "activate", G_CALLBACK (on_close_clicked), layer_window); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), close_item); } } } } return vbox; } gtk-layer-shell-0.1.0/demo/meson.build000066400000000000000000000006121353716601300176060ustar00rootroot00000000000000demo = executable('gtk-layer-demo', 'gtk-layer-demo.c', 'anchor-control.c', 'margin-control.c', 'layer-selection.c', 'monitor-selection.c', 'mscl-toggles.c', 'menu-bar.c', build_by_default: get_option('examples'), dependencies: [gtk], include_directories: [gtk_layer_shell_inc], link_with: [gtk_layer_shell_lib], install: get_option('examples')) gtk-layer-shell-0.1.0/demo/monitor-selection.c000066400000000000000000000050321353716601300212630ustar00rootroot00000000000000#include "gtk-layer-demo.h" const char *current_monitor_key = "current_layer_monitor"; static void on_monitor_selected (GtkComboBox *combo_box, GtkWindow *layer_window) { int monitor_index = gtk_combo_box_get_active (combo_box) - 1; // 1st element is default monitor GdkMonitor *monitor = NULL; if (monitor_index >= 0) { GdkDisplay *display = gdk_display_get_default (); g_return_if_fail (monitor_index < gdk_display_get_n_monitors (display)); monitor = gdk_display_get_monitor (display, monitor_index); } g_object_set_data (G_OBJECT (combo_box), current_monitor_key, monitor); gtk_layer_set_monitor (layer_window, monitor); } void on_monitors_changed (GdkDisplay *display, GdkMonitor *_monitor, GtkComboBox *combo_box) { (void)_monitor; gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (combo_box)); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "Default"); GdkMonitor *current_monitor = g_object_get_data (G_OBJECT (combo_box), current_monitor_key); if (current_monitor == NULL) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0); } for (int i = 0; i < gdk_display_get_n_monitors (display); i++) { GdkMonitor *monitor = gdk_display_get_monitor (display, i); GString *text = g_string_new (""); g_string_printf (text, "%d. %s", i + 1, gdk_monitor_get_model (monitor)); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), text->str); g_string_free (text, TRUE); if (monitor == current_monitor) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), i + 1); } } } GtkWidget * monitor_selection_new (GtkWindow *layer_window) { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); { GtkWidget *combo_box = gtk_combo_box_text_new (); gtk_widget_set_tooltip_text (combo_box, "Monitor"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo_box), NULL, "Default"); gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0); GdkDisplay *display = gdk_display_get_default (); g_signal_connect (display, "monitor-added", G_CALLBACK (on_monitors_changed), combo_box); g_signal_connect (display, "monitor-removed", G_CALLBACK (on_monitors_changed), combo_box); on_monitors_changed (display, NULL, GTK_COMBO_BOX (combo_box)); g_signal_connect (combo_box, "changed", G_CALLBACK (on_monitor_selected), layer_window); gtk_box_pack_start (GTK_BOX (vbox), combo_box, FALSE, FALSE, 0); } return vbox; } gtk-layer-shell-0.1.0/demo/mscl-toggles.c000066400000000000000000000056151353716601300202200ustar00rootroot00000000000000#include "gtk-layer-demo.h" gboolean on_exclusive_zone_state_set (GtkToggleButton *_toggle_button, gboolean state, GtkWindow *layer_window) { (void)_toggle_button; if (state) { gtk_layer_auto_exclusive_zone_enable (layer_window); } else { gtk_layer_set_exclusive_zone (layer_window, 0); } return FALSE; } gboolean on_keyboard_interactivity_state_set (GtkToggleButton *_toggle_button, gboolean state, GtkWindow *layer_window) { (void)_toggle_button; gtk_layer_set_keyboard_interactivity (layer_window, state); return FALSE; } gboolean on_fixed_size_set (GtkToggleButton *_toggle_button, gboolean state, GtkWindow *layer_window) { (void)_toggle_button; if (state) { gtk_widget_set_size_request (GTK_WIDGET (layer_window), 600, 500); } else { gtk_widget_set_size_request (GTK_WIDGET (layer_window), -1, -1); } gtk_window_resize (layer_window, 1, 1); return FALSE; } struct { const char *name; const char *tooltip; gboolean (*callback) (GtkToggleButton *toggle_button, gboolean state, GtkWindow *layer_window); } const mscl_toggles[] = { {"Exclusive", "Create an exclusive zone when anchored", on_exclusive_zone_state_set}, {"Keyboard", "Get keyboard events", on_keyboard_interactivity_state_set}, {"Set Size", "Set a fixed window size", on_fixed_size_set}, }; GtkWidget * mscl_toggles_new (GtkWindow *layer_window, gboolean default_auto_exclusive_zone, gboolean default_keyboard_interactivity, gboolean default_fixed_size) { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); for (unsigned i = 0; i < sizeof (mscl_toggles) / sizeof (mscl_toggles[0]); i++) { GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); { GtkWidget *label = gtk_label_new (mscl_toggles[i].name); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); }{ GtkWidget *toggle = gtk_switch_new (); gtk_widget_set_tooltip_text (toggle, mscl_toggles[i].tooltip); gboolean default_value; if (mscl_toggles[i].callback == on_exclusive_zone_state_set) default_value = default_auto_exclusive_zone; else if (mscl_toggles[i].callback == on_keyboard_interactivity_state_set) default_value = default_keyboard_interactivity; else if (mscl_toggles[i].callback == on_fixed_size_set) default_value = default_fixed_size; else g_assert_not_reached (); gtk_switch_set_active (GTK_SWITCH (toggle), default_value); g_signal_connect (toggle, "state-set", G_CALLBACK (mscl_toggles[i].callback), layer_window); gtk_box_pack_end (GTK_BOX (hbox), toggle, FALSE, FALSE, 0); } } return vbox; } gtk-layer-shell-0.1.0/doc/000077500000000000000000000000001353716601300152665ustar00rootroot00000000000000gtk-layer-shell-0.1.0/doc/gtk-layer-shell-docs.sgml000066400000000000000000000072431353716601300221120ustar00rootroot00000000000000 %gtkdocentities; ]> &package_name; Reference Manual This document is the API reference for for &package_name; &package_version;. If you find any issues in this API reference, please report it using the online bug reporting tool. The MIT License (MIT) 2014 Dennis Blommesteijn 2019 William Wold Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. API Reference Gtk-layer-shell is a library to write GTK applications that use Layer Shell. Layer Shell is a Wayland protocol for desktop shell components, such as panels, notifications and wallpapers. You can use it to anchor your windows to a corner or edge of the output, or stretch them across the entire output. This library only makes sense on Wayland compositors that support Layer Shell, and will not work on X11. It supports all Layer Shell features including popups and popovers (GTK popups Just Work™). Please open issues for any bugs you come across. API Index Index of deprecated API gtk-layer-shell-0.1.0/doc/gtk-layer-shell.types000066400000000000000000000000521353716601300213550ustar00rootroot00000000000000#include gtk_window_get_type gtk-layer-shell-0.1.0/doc/meson.build000066400000000000000000000021251353716601300174300ustar00rootroot00000000000000subdir('xml') glib_prefix = dependency('glib-2.0').get_pkgconfig_variable('prefix') glib_docpath = join_paths(glib_prefix, 'share', 'gtk-doc', 'html') docpath = join_paths(get_option('datadir'), 'gtk-doc', 'html') gtk_doc_dep = dependency('gtk-doc') gnome.gtkdoc( 'gtk-layer-shell', main_xml: 'gtk-layer-shell-docs.sgml', src_dir: [ join_paths(meson.source_root(), 'include'), join_paths(meson.build_root(), 'include'), ], dependencies: [ gtk, wayland_client, wayland_scanner, ], gobject_typesfile: 'gtk-layer-shell.types', #scan_args: [ # '--rebuild-types', # '--rebuild-sections', # '--ignore-headers=' + ' '.join(private_headers), #], fixxref_args: [ '--html-dir=@0@'.format(docpath), '--extra-dir=@0@'.format(join_paths(glib_docpath, 'glib')), '--extra-dir=@0@'.format(join_paths(glib_docpath, 'gobject')), '--extra-dir=@0@'.format(join_paths(glib_docpath, 'gio')), '--extra-dir=@0@'.format(join_paths(glib_docpath, 'gtk3')), ], install_dir: 'gtk-layer-shell', install: true ) gtk-layer-shell-0.1.0/doc/xml/000077500000000000000000000000001353716601300160665ustar00rootroot00000000000000gtk-layer-shell-0.1.0/doc/xml/gtkdocentities.ent.in000066400000000000000000000005341353716601300222250ustar00rootroot00000000000000 gtk-layer-shell-0.1.0/doc/xml/meson.build000066400000000000000000000011631353716601300202310ustar00rootroot00000000000000ent_conf = configuration_data() ent_conf.set('PACKAGE', 'gtk-layer-shell') ent_conf.set('PACKAGE_BUGREPORT', 'https://github.com/wmww/gtk-layer-shell/issues') ent_conf.set('PACKAGE_NAME', 'gtk-layer-shell') ent_conf.set('PACKAGE_STRING', 'gtk-layer-shell') ent_conf.set('PACKAGE_TARNAME', 'gtk-layer-shell-' + meson.project_version()) ent_conf.set('PACKAGE_URL', 'https://github.com/wmww/gtk-layer-shell') ent_conf.set('PACKAGE_VERSION', meson.project_version()) ent_conf.set('PACKAGE_API_VERSION', meson.project_version()) configure_file(input: 'gtkdocentities.ent.in', output: 'gtkdocentities.ent', configuration: ent_conf) gtk-layer-shell-0.1.0/example/000077500000000000000000000000001353716601300161545ustar00rootroot00000000000000gtk-layer-shell-0.1.0/example/example.c000066400000000000000000000041721353716601300177570ustar00rootroot00000000000000#include "gtk-layer-shell.h" #include static void activate (GtkApplication* app, void *_data) { (void)_data; // Create a normal GTK window however you like GtkWindow *gtk_window = GTK_WINDOW (gtk_application_window_new (app)); // Before the window is first realized, set it up to be a layer surface gtk_layer_init_for_window (gtk_window); // Order below normal windows gtk_layer_set_layer (gtk_window, GTK_LAYER_SHELL_LAYER_BOTTOM); // Push other windows out of the way gtk_layer_auto_exclusive_zone_enable (gtk_window); // We don't need to get keybard input // gtk_layer_set_keyboard_interactivity (gtk_window, FALSE); // FALSE is default // The margins are the gaps around the window's edges // Margins and anchors can be set like this... gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, 40); gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, 40); gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_TOP, 20); // gtk_layer_set_margin (gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, 0); // 0 is default // ... or like this // Anchors are if the window is pinned to each edge of the output static const gboolean anchors[] = {TRUE, TRUE, FALSE, TRUE}; for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) { gtk_layer_set_anchor (gtk_window, i, anchors[i]); } // Set up a widget GtkWidget *label = gtk_label_new (""); gtk_label_set_markup (GTK_LABEL (label), "" "GTK Layer Shell example!" ""); gtk_container_add (GTK_CONTAINER (gtk_window), label); gtk_container_set_border_width (GTK_CONTAINER (gtk_window), 12); gtk_widget_show_all (GTK_WIDGET (gtk_window)); } int main (int argc, char **argv) { GtkApplication * app = gtk_application_new ("sh.wmww.gtk-layer-example", G_APPLICATION_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); int status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return status; } gtk-layer-shell-0.1.0/example/meson.build000066400000000000000000000003301353716601300203120ustar00rootroot00000000000000example = executable('gtk-layer-example', 'example.c', build_by_default: get_option('examples'), dependencies: [gtk], include_directories: [gtk_layer_shell_inc], link_with: [gtk_layer_shell_lib]) gtk-layer-shell-0.1.0/include/000077500000000000000000000000001353716601300161445ustar00rootroot00000000000000gtk-layer-shell-0.1.0/include/gtk-layer-shell.h000066400000000000000000000136151353716601300213270ustar00rootroot00000000000000#ifndef GTK_LAYER_SHELL_H #define GTK_LAYER_SHELL_H #include /** * SECTION:gtk-layer-shell * @title: Gtk Layer Shell * @short_description: A library to write GTK Applications using Layer Shell * * insert more general verbiage here * * # Forcing Window Size * If you wish to force your layer surface window to be a different size than it * is by default: * |[ * gtk_widget_set_size_request (GTK_WIDGET (layer_gtk_window), width, height); * // force the window to resize to the new request * gtk_window_resize (layer_gtk_window, 1, 1); * ]| * If width or height is -1, the default is used for that axis. If the window is * anchored to opposite edges of the output (see gtk_layer_set_anchor ()), the * size request is ignored. If you later wish to use the default window size, * simply repeat the two calls but with both width and height as -1. */ G_BEGIN_DECLS /** * GtkLayerShellLayer: * @GTK_LAYER_SHELL_LAYER_BACKGROUND: The background layer. * @GTK_LAYER_SHELL_LAYER_BOTTOM: The bottom layer. * @GTK_LAYER_SHELL_LAYER_TOP: The top layer. * @GTK_LAYER_SHELL_LAYER_OVERLAY: The overlay layer. * @GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER: Should not be used except to get the number of entries */ typedef enum { GTK_LAYER_SHELL_LAYER_BACKGROUND, GTK_LAYER_SHELL_LAYER_BOTTOM, GTK_LAYER_SHELL_LAYER_TOP, GTK_LAYER_SHELL_LAYER_OVERLAY, GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER, } GtkLayerShellLayer; /** * GtkLayerShellEdge: * @GTK_LAYER_SHELL_EDGE_LEFT: The left edge of the screen. * @GTK_LAYER_SHELL_EDGE_RIGHT: The right edge of the screen. * @GTK_LAYER_SHELL_EDGE_TOP: The top edge of the screen. * @GTK_LAYER_SHELL_EDGE_BOTTOM: The bottom edge of the screen. * @GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER: Should not be used except to get the number of entries */ typedef enum { GTK_LAYER_SHELL_EDGE_LEFT = 0, GTK_LAYER_SHELL_EDGE_RIGHT, GTK_LAYER_SHELL_EDGE_TOP, GTK_LAYER_SHELL_EDGE_BOTTOM, GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER, // Should not be used except to get the number of entries } GtkLayerShellEdge; /** * gtk_layer_init_for_window: * @window: A #GtkWindow to be turned into a layer surface. * * Set the @window up to be a layer surface once it is mapped: * This must be called before the @window is realized. */ void gtk_layer_init_for_window (GtkWindow *window); /** * gtk_layer_set_namespace: * @window: A layer surface. * @name_space: The namespace of this layer surface. * * Set the "namespace" of the surface. * * No one is quite sure what this is for, but it probably should be something generic * ("panel", "osk", etc). The @name_space string is copied, and caller maintians * ownership of original. If the window is currently mapped, it will get remapped so * the change can take effect. * * Default is "gtk-layer-shell" (which will be used if set to %NULL) */ void gtk_layer_set_namespace (GtkWindow *window, char const* name_space); /** * gtk_layer_set_layer: * @window: A layer surface. * @layer: The layer on which this surface appears. * * Set the "layer" on which the surface appears (controls if it is over top of or below other surfaces). If the @window is currently mapped, it will get remapped so the change * can take effect. * * Default is #GTK_LAYER_SHELL_LAYER_TOP */ void gtk_layer_set_layer (GtkWindow *window, GtkLayerShellLayer layer); /** * gtk_layer_set_monitor: * @window: A layer surface. * @monitor: The output this layer surface will be placed on (%NULL to let the compositor decide). * * Set the output for the window to be placed on, or %NULL to let the compositor choose. * If the window is currently mapped, it will get remapped so the change can take effect. * * Default is %NULL */ void gtk_layer_set_monitor (GtkWindow *window, GdkMonitor *monitor); /** * gtk_layer_set_anchor: * @window: A layer surface. * @edge: A #GtkLayerShellEdge this layer suface may be anchored to. * @anchor_to_edge: Whether or not to anchor this layer surface to @edge. * * Set whether @window should be anchored to @edge. * - If two perpendicular edges are anchored, the surface with be anchored to that corner * - If two opposite edges are anchored, the window will be stretched across the screen in that direction * * Default is %FALSE for each #GtkLayerShellEdge */ void gtk_layer_set_anchor (GtkWindow *window, GtkLayerShellEdge edge, gboolean anchor_to_edge); /** * gtk_layer_set_margin: * @window: A layer surface. * @edge: The #GtkLayerShellEdge for which to set the margin. * @margin_size: The margin for @edge to be set. * * Set the margin for a specific @edge of a @window. Effects both surface's distance from * the edge and its exclusive zone size (if auto exclusive zone enabled). * * Default is 0 for each #GtkLayerShellEdge */ void gtk_layer_set_margin (GtkWindow *window, GtkLayerShellEdge edge, int margin_size); /** * gtk_layer_set_exclusive_zone: * @window: A layer surface. * @exclusive_zone: The size of the exclusive zone. * * If auto exclusive zone is enabled, exclusive zone will automatically be set to the * size of the @window + relevant margin. To disable auto exclusive zone, just set the * exclusive zone to 0 or any other fixed value. There is no need to manually set the * exclusive zone size when using auto exclusive zone. * * Default is 0 */ void gtk_layer_set_exclusive_zone (GtkWindow *window, int exclusive_zone); /** * gtk_layer_auto_exclusive_zone_enable: * @window: A layer surface. * * Enables auto exclusive zone for @window. */ void gtk_layer_auto_exclusive_zone_enable (GtkWindow *window); /** * gtk_layer_set_keyboard_interactivity: * @window: A layer surface. * @interacitvity: Whether the layer surface should receive keyboard events. * * Whether the @window should receive keyboard events from the compositor. * * Default is %FALSE */ void gtk_layer_set_keyboard_interactivity (GtkWindow *window, gboolean interacitvity); G_END_DECLS #endif // GTK_LAYER_SHELL_H gtk-layer-shell-0.1.0/include/meson.build000066400000000000000000000001601353716601300203030ustar00rootroot00000000000000gtk_layer_shell_inc = include_directories('.') install_headers('gtk-layer-shell.h', subdir: 'gtk-layer-shell') gtk-layer-shell-0.1.0/meson.build000066400000000000000000000014531353716601300166660ustar00rootroot00000000000000project('gtk-layer-shell', ['c'], version: '0.1.0', license: 'MIT', meson_version: '>=0.45.1', default_options: ['c_std=gnu11', 'warning_level=3']) add_project_arguments( ['-Wno-pedantic'], language: 'c') gtk = dependency('gtk+-wayland-3.0', version: '>=3.22.0') wayland_client = dependency('wayland-client', version: '>=1.10.0') # wayland_scanner is required, but we can find it without pkg-config wayland_scanner = dependency('wayland-scanner', version: '>=1.10.0', required: false) pkg_config = import('pkgconfig') gnome = import('gnome') subdir('include') subdir('src') subdir('example') subdir('demo') if get_option('docs') subdir('doc') endif gtk_layer_shell_dep = declare_dependency( link_with: gtk_layer_shell_lib, include_directories: gtk_layer_shell_inc) gtk-layer-shell-0.1.0/meson_options.txt000066400000000000000000000002731353716601300201600ustar00rootroot00000000000000option('examples', type: 'boolean', value: false, description: 'Build example applications') option('docs', type: 'boolean', value: false, description: 'Build devhelp API documentation') gtk-layer-shell-0.1.0/src/000077500000000000000000000000001353716601300153105ustar00rootroot00000000000000gtk-layer-shell-0.1.0/src/custom-shell-surface.c000066400000000000000000000101341353716601300215200ustar00rootroot00000000000000#include "custom-shell-surface.h" #include "gtk-wayland.h" #include "gdk-window-hack.h" #include #include #include static const char *custom_shell_surface_key = "wayland_custom_shell_surface"; struct _CustomShellSurfacePrivate { GtkWindow *gtk_window; }; static void custom_shell_surface_on_window_destroy (CustomShellSurface *self) { self->virtual->finalize (self); g_free (self->private); g_free (self); } static void custom_shell_surface_on_window_realize (GtkWidget *widget, CustomShellSurface *self) { g_return_if_fail (GTK_WIDGET (self->private->gtk_window) == widget); GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (self->private->gtk_window)); g_return_if_fail (gdk_window); gdk_window_hack_init (gdk_window); gdk_wayland_window_set_use_custom_surface (gdk_window); } static void custom_shell_surface_on_window_map (GtkWidget *widget, CustomShellSurface *self) { g_return_if_fail (GTK_WIDGET (self->private->gtk_window) == widget); GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (self->private->gtk_window)); g_return_if_fail (gdk_window); struct wl_surface *wl_surface = gdk_wayland_window_get_wl_surface (gdk_window); g_return_if_fail (wl_surface); // In some cases (observed when a mate panel has an image background) GDK will attach a buffer just after creating // the surface (see the implementation of gdk_wayland_window_show() for details). Giving the surface a role with a // buffer attached is a protocol violation, so we attach a null buffer. GDK hasn't commited the buffer it may have // attached, so we don't need to commit. wl_surface_attach (wl_surface, NULL, 0, 0); self->virtual->map (self, wl_surface); wl_surface_commit (wl_surface); wl_display_roundtrip (gdk_wayland_display_get_wl_display (gdk_display_get_default ())); } void custom_shell_surface_init (CustomShellSurface *self, GtkWindow *gtk_window) { g_assert (self->virtual); // Subclass should have set this up first self->private = g_new0 (CustomShellSurfacePrivate, 1); self->private->gtk_window = gtk_window; g_return_if_fail (gtk_window); g_return_if_fail (!gtk_widget_get_mapped (GTK_WIDGET (gtk_window))); g_object_set_data_full (G_OBJECT (gtk_window), custom_shell_surface_key, self, (GDestroyNotify) custom_shell_surface_on_window_destroy); g_signal_connect (gtk_window, "realize", G_CALLBACK (custom_shell_surface_on_window_realize), self); g_signal_connect (gtk_window, "map", G_CALLBACK (custom_shell_surface_on_window_map), self); if (gtk_widget_get_realized (GTK_WIDGET (gtk_window))) { // We must be in the process of realizing now custom_shell_surface_on_window_realize (GTK_WIDGET (gtk_window), self); } } CustomShellSurface * gtk_window_get_custom_shell_surface (GtkWindow *gtk_window) { if (!gtk_window) return NULL; return g_object_get_data (G_OBJECT (gtk_window), custom_shell_surface_key); } GtkWindow * custom_shell_surface_get_gtk_window (CustomShellSurface *self) { g_return_val_if_fail (self, NULL); return self->private->gtk_window; } void custom_shell_surface_get_window_geom (CustomShellSurface *self, GdkRectangle *geom) { g_return_if_fail (self); // TODO: Store the actual window geometry used *geom = gtk_wayland_get_logical_geom (self->private->gtk_window); } void custom_shell_surface_needs_commit (CustomShellSurface *self) { if (!self->private->gtk_window) return; GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (self->private->gtk_window)); if (!gdk_window) return; struct wl_surface *wl_surface = gdk_wayland_window_get_wl_surface (gdk_window); if (!wl_surface) return; wl_surface_commit (wl_surface); } void custom_shell_surface_remap (CustomShellSurface *self) { GtkWidget *window_widget = GTK_WIDGET (self->private->gtk_window); g_return_if_fail (window_widget); gtk_widget_hide (window_widget); gtk_widget_show (window_widget); } gtk-layer-shell-0.1.0/src/custom-shell-surface.h000066400000000000000000000043361353716601300215340ustar00rootroot00000000000000#ifndef CUSTOM_SHELL_SURFACE_H #define CUSTOM_SHELL_SURFACE_H #include #include struct wl_surface; struct xdg_surface; struct xdg_positioner; typedef struct _CustomShellSurface CustomShellSurface; typedef struct _CustomShellSurfacePrivate CustomShellSurfacePrivate; typedef struct _CustomShellSurfaceVirtual CustomShellSurfaceVirtual; struct _CustomShellSurfaceVirtual { // Called during the window's gtk signal of the same name // Should create the wayland objects needed to map the surface void (*map) (CustomShellSurface *super, struct wl_surface *wl_surface); // Must be called before the associated GtkWindow is unmapped void (*unmap) (CustomShellSurface *super); // Will usually call unmap; can be the same function if no other resources need to be freed void (*finalize) (CustomShellSurface *super); struct xdg_popup *(*get_popup) (CustomShellSurface *super, struct xdg_surface *popup_xdg_surface, struct xdg_positioner *positioner); // Returns the logical geometry of the window (excludes shadows and such) GdkRectangle (*get_logical_geom) (CustomShellSurface *super); }; struct _CustomShellSurface { CustomShellSurfaceVirtual const *virtual; CustomShellSurfacePrivate *private; }; // Usually called by the subclass constructors // Does not map the surface yet void custom_shell_surface_init (CustomShellSurface *self, GtkWindow *gtk_window); // If the window has a shell surface, return it; else return NULL // NULL input is handled gracefully CustomShellSurface *gtk_window_get_custom_shell_surface (GtkWindow *gtk_window); GtkWindow *custom_shell_surface_get_gtk_window (CustomShellSurface *self); // In theory this could commit once on next event loop, but for now it will just commit every time it is called // Does nothing is the shell surface does not currently have a GdkWindow with a wl_surface void custom_shell_surface_needs_commit (CustomShellSurface *self); // Unmap and remap a currently mapped shell surface void custom_shell_surface_remap (CustomShellSurface *self); // Destruction is taken care of automatically when the associated window is destroyed #endif // CUSTOM_SHELL_SURFACE_H gtk-layer-shell-0.1.0/src/gdk-window-hack.c000066400000000000000000000102721353716601300204340ustar00rootroot00000000000000#include "gdk-window-hack.h" #include "gtk-wayland.h" #include "xdg-popup-surface.h" #include // The type of the function pointer of GdkWindowImpl's move_to_rect method (gdkwindowimpl.h:78)' typedef void (*MoveToRectFunc) (GdkWindow *window, const GdkRectangle *rect, GdkGravity rect_anchor, GdkGravity window_anchor, GdkAnchorHints anchor_hints, int rect_anchor_dx, int rect_anchor_dy); static MoveToRectFunc gdk_window_move_to_rect_real = NULL; static GdkWindow * gdk_window_hack_get_transient_for (GdkWindow *gdk_window) { // Assume the transient_for GdkWindow* is the 3rd pointer after the GObject in GdkWindow (gdkinternals.h:206) void **transient_for = (void**)((char *)gdk_window + sizeof(GObject) + 2 * sizeof(void *)); return GDK_WINDOW (*transient_for); } static void gdk_window_move_to_rect_impl_override (GdkWindow *window, const GdkRectangle *rect, GdkGravity rect_anchor, GdkGravity window_anchor, GdkAnchorHints anchor_hints, int rect_anchor_dx, int rect_anchor_dy) { g_assert (gdk_window_move_to_rect_real); gdk_window_move_to_rect_real (window, rect, rect_anchor, window_anchor, anchor_hints, rect_anchor_dx, rect_anchor_dy); GdkWindow *transient_for_gdk_window = gdk_window_hack_get_transient_for (window); CustomShellSurface *transient_for_shell_surface = NULL; GdkWindow *toplevel_gdk_window = transient_for_gdk_window; while (toplevel_gdk_window) { toplevel_gdk_window = gdk_window_get_toplevel (toplevel_gdk_window); GtkWindow *toplevel_gtk_window = gtk_wayland_gdk_to_gtk_window (toplevel_gdk_window); transient_for_shell_surface = gtk_window_get_custom_shell_surface (toplevel_gtk_window); if (transient_for_shell_surface) break; toplevel_gdk_window = gdk_window_hack_get_transient_for (toplevel_gdk_window); } if (transient_for_shell_surface) { g_return_if_fail (rect); XdgPopupPosition position = { .transient_for_shell_surface = transient_for_shell_surface, .transient_for_gdk_window = transient_for_gdk_window, .rect = *rect, .rect_anchor = rect_anchor, .window_anchor = window_anchor, .anchor_hints = anchor_hints, .rect_anchor_d = { .x = rect_anchor_dx, .y = rect_anchor_dy, }, }; gtk_wayland_setup_window_as_custom_popup (window, &position); } } void gdk_window_hack_init (GdkWindow *gdk_window) { // Don't do anything once this has run successfully once if (gdk_window_move_to_rect_real) return; // Assume a GdkWindowImpl* is the first thing in a GdkWindow after the parent GObject (gdkinternals.h:203) void *gdk_window_impl = *(void **)((char *)gdk_window + sizeof(GObject)); // Assume a GdkWindowImplClass* is the first thing in a GdkWindowImpl (a class pointer is the first thing in a GObject) void *gdk_window_impl_class = *(void **)gdk_window_impl; // Assume there is a GObjectClass and 10 function pointers in GdkWindowImplClass before move_to_rect (gdkwindowimpl.h:78) MoveToRectFunc *move_to_rect_func_ptr_ptr = (MoveToRectFunc *)((char *)gdk_window_impl_class + sizeof(GObjectClass) + 10 * sizeof(void *)); // If we have not already done the override, set the window's function to be the override and our "real" fp to the one that was there before if (*move_to_rect_func_ptr_ptr != gdk_window_move_to_rect_impl_override) { gdk_window_move_to_rect_real = *move_to_rect_func_ptr_ptr; *move_to_rect_func_ptr_ptr = gdk_window_move_to_rect_impl_override; } } gtk-layer-shell-0.1.0/src/gdk-window-hack.h000066400000000000000000000004151353716601300204370ustar00rootroot00000000000000#ifndef GDK_WINDOW_HACK_H #define GDK_WINDOW_HACK_H #include // This only has an effect the first time it's called // It enables gtk_window_hack_get_position () working later void gdk_window_hack_init (GdkWindow *gdk_window); #endif // GDK_WINDOW_HACK_H gtk-layer-shell-0.1.0/src/gtk-layer-shell.c000066400000000000000000000075671353716601300204770ustar00rootroot00000000000000#include "gtk-layer-shell.h" #include "gtk-wayland.h" #include "custom-shell-surface.h" #include "simple-conversions.h" #include "layer-surface.h" #include "xdg-toplevel-surface.h" static LayerSurface* gtk_window_get_layer_surface (GtkWindow *window) { g_return_val_if_fail (window, NULL); CustomShellSurface *shell_surface = gtk_window_get_custom_shell_surface (window); if (!shell_surface) { g_critical ("GtkWindow is not a layer surface. Make sure you called gtk_layer_init_for_window ()"); return NULL; } LayerSurface *layer_surface = custom_shell_surface_get_layer_surface (shell_surface); if (!layer_surface) { g_critical ("Custom wayland shell surface is not a layer surface, your Wayland compositor may not support Layer Shell"); return NULL; } return layer_surface; } void gtk_layer_init_for_window (GtkWindow *window) { gtk_wayland_init_if_needed (); LayerSurface* layer_surface = layer_surface_new (window); if (!layer_surface) { g_warning ("Falling back to XDG shell instead of Layer Shell (surface should appear but layer features will not work)"); XdgToplevelSurface* toplevel_surface = xdg_toplevel_surface_new (window); if (!toplevel_surface) { g_warning ("Shell does not support XDG shell stable. Falling back to default GTK behavior"); } } } void gtk_layer_set_namespace (GtkWindow *window, char const* name_space) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_set_name_space (layer_surface, name_space); } void gtk_layer_set_layer (GtkWindow *window, GtkLayerShellLayer layer) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_set_layer (layer_surface, gtk_layer_shell_layer_get_zwlr_layer_shell_v1_layer(layer)); } void gtk_layer_set_monitor (GtkWindow *window, GdkMonitor *monitor) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_set_monitor (layer_surface, monitor); } void gtk_layer_set_anchor (GtkWindow *window, GtkLayerShellEdge edge, gboolean anchor_to_edge) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_set_anchor (layer_surface, edge, anchor_to_edge); } void gtk_layer_set_margin (GtkWindow *window, GtkLayerShellEdge edge, int margin_size) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_set_margin (layer_surface, edge, margin_size); } void gtk_layer_set_exclusive_zone (GtkWindow *window, int exclusive_zone) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_set_exclusive_zone (layer_surface, exclusive_zone); } void gtk_layer_auto_exclusive_zone_enable (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_auto_exclusive_zone_enable (layer_surface); } void gtk_layer_set_keyboard_interactivity (GtkWindow *window, gboolean interacitvity) { LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface layer_surface_set_keyboard_interactivity (layer_surface, interacitvity); } gtk-layer-shell-0.1.0/src/gtk-wayland.c000066400000000000000000000165361353716601300177110ustar00rootroot00000000000000#include "gtk-wayland.h" #include "custom-shell-surface.h" #include "xdg-popup-surface.h" #include "gdk-window-hack.h" #include "xdg-shell-client.h" #include "wlr-layer-shell-unstable-v1-client.h" #include #include #include static const char *gtk_window_key = "linked-gtk-window"; static const char *popup_position_key = "custom-popup-position"; static struct wl_registry *wl_registry_global = NULL; static struct xdg_wm_base *xdg_wm_base_global = NULL; static struct zwlr_layer_shell_v1 *layer_shell_global = NULL; static gboolean has_initialized = FALSE; gboolean gtk_wayland_get_has_initialized (void) { return has_initialized; } struct zwlr_layer_shell_v1 * gtk_wayland_get_layer_shell_global () { return layer_shell_global; } struct xdg_wm_base * gtk_wayland_get_xdg_wm_base_global () { return xdg_wm_base_global; } static void wl_registry_handle_global (void *_data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) { (void)_data; // pull out needed globals if (strcmp (interface, zwlr_layer_shell_v1_interface.name) == 0) { g_warn_if_fail (zwlr_layer_shell_v1_interface.version == 1); layer_shell_global = wl_registry_bind (registry, id, &zwlr_layer_shell_v1_interface, MIN((uint32_t)zwlr_layer_shell_v1_interface.version, version)); } else if (strcmp (interface, xdg_wm_base_interface.name) == 0) { g_warn_if_fail (xdg_wm_base_interface.version == 2); xdg_wm_base_global = wl_registry_bind (registry, id, &xdg_wm_base_interface, MIN((uint32_t)xdg_wm_base_interface.version, version)); } } static void wl_registry_handle_global_remove (void *_data, struct wl_registry *_registry, uint32_t _id) { (void)_data; (void)_registry; (void)_id; // TODO } static const struct wl_registry_listener wl_registry_listener = { .global = wl_registry_handle_global, .global_remove = wl_registry_handle_global_remove, }; // Does not take ownership of position static void gtk_wayland_setup_custom_popup (GtkWindow *gtk_window, XdgPopupPosition const *position) { CustomShellSurface *shell_surface = gtk_window_get_custom_shell_surface (gtk_window); if (shell_surface) { XdgPopupSurface *popup_surface = custom_shell_surface_get_xdg_popup (shell_surface); // If there's already a custom surface on the window, it better be a popup g_return_if_fail (popup_surface); xdg_popup_surface_update_position (popup_surface, position); } else { xdg_popup_surface_new (gtk_window, position); } } // This function associates a GTK window with a GDK window // It overrides the default so it can run for EVERY window without needed to be attached to each one static void gtk_wayland_override_on_window_realize (GtkWindow *gtk_window, void *_data) { (void)_data; // Call the super class's realize handler GValue args[1] = { G_VALUE_INIT }; g_value_init_from_instance (&args[0], gtk_window); g_signal_chain_from_overridden (args, NULL); g_value_unset (&args[0]); GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (gtk_window)); g_object_set_data (G_OBJECT (gdk_window), gtk_window_key, gtk_window); XdgPopupPosition *position = g_object_get_data (G_OBJECT (gdk_window), popup_position_key); if (position) { // This is a custom popup waiting to be realized gtk_wayland_setup_custom_popup (gtk_window, position); g_object_set_data (G_OBJECT (gdk_window), popup_position_key, NULL); } } // This callback must override the default unmap handler, so it can run first // The custom surface's unmap method must be called before GtkWidget's unmap, or Wayland objects are destroyed in the wrong order static void gtk_wayland_override_on_window_unmap (GtkWindow *gtk_window, void *_data) { (void)_data; CustomShellSurface *shell_surface = gtk_window_get_custom_shell_surface (gtk_window); if (shell_surface) shell_surface->virtual->unmap (shell_surface); // Call the super class's unmap handler GValue args[1] = { G_VALUE_INIT }; g_value_init_from_instance (&args[0], gtk_window); g_signal_chain_from_overridden (args, NULL); g_value_unset (&args[0]); } void gtk_wayland_init_if_needed () { if (has_initialized) return; GdkDisplay *gdk_display = gdk_display_get_default (); g_return_if_fail (gdk_display); g_return_if_fail (GDK_IS_WAYLAND_DISPLAY (gdk_display)); struct wl_display *wl_display = gdk_wayland_display_get_wl_display (gdk_display); wl_registry_global = wl_display_get_registry (wl_display); wl_registry_add_listener (wl_registry_global, &wl_registry_listener, NULL); wl_display_roundtrip (wl_display); if (!layer_shell_global) g_warning ("It appears your Wayland compositor does not support the Layer Shell protocol"); if (!xdg_wm_base_global) g_warning ("It appears your Wayland compositor does not support the XDG Shell stable protocol"); gint realize_signal_id = g_signal_lookup ("realize", GTK_TYPE_WINDOW); GClosure *realize_closure = g_cclosure_new (G_CALLBACK (gtk_wayland_override_on_window_realize), NULL, NULL); g_signal_override_class_closure (realize_signal_id, GTK_TYPE_WINDOW, realize_closure); gint unmap_signal_id = g_signal_lookup ("unmap", GTK_TYPE_WINDOW); GClosure *unmap_closure = g_cclosure_new (G_CALLBACK (gtk_wayland_override_on_window_unmap), NULL, NULL); g_signal_override_class_closure (unmap_signal_id, GTK_TYPE_WINDOW, unmap_closure); has_initialized = TRUE; } GtkWindow * gtk_wayland_gdk_to_gtk_window (GdkWindow *gdk_window) { return GTK_WINDOW (g_object_get_data (G_OBJECT (gdk_window), gtk_window_key)); } void gtk_wayland_setup_window_as_custom_popup (GdkWindow *gdk_window, XdgPopupPosition const *position) { GtkWindow *gtk_window = gtk_wayland_gdk_to_gtk_window (gdk_window); if (GTK_IS_WINDOW (gtk_window)) { // The GDK window has been connected to a GTK window gtk_wayland_setup_custom_popup (gtk_window, position); } else { // We need to hold the position and wait for a connected GTK window to be realized XdgPopupPosition *position_owned = g_new (XdgPopupPosition, 1); *position_owned = *position; g_object_set_data_full (G_OBJECT (gdk_window), popup_position_key, position_owned, g_free); } } // Gets the upper left and size of the portion of the window that is actually used (not shadows and whatnot) // It does this by walking down the gdk_window tree, as long as there is exactly one child GdkRectangle gtk_wayland_get_logical_geom (GtkWindow *gtk_window) { GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (gtk_window)); GList *list = gdk_window_get_children (window); if (list && !list->next) // If there is exactly one child window window = list->data; GdkRectangle geom; gdk_window_get_geometry (window, &geom.x, &geom.y, &geom.width, &geom.height); return geom; } gtk-layer-shell-0.1.0/src/gtk-wayland.h000066400000000000000000000012211353716601300176770ustar00rootroot00000000000000#ifndef WAYLAND_GLOBALS_H #define WAYLAND_GLOBALS_H #include #include #include "xdg-popup-surface.h" gboolean gtk_wayland_get_has_initialized (void); struct xdg_wm_base *gtk_wayland_get_xdg_wm_base_global (void); struct zwlr_layer_shell_v1 *gtk_wayland_get_layer_shell_global (void); void gtk_wayland_init_if_needed (void); GtkWindow *gtk_wayland_gdk_to_gtk_window (GdkWindow *gdk_window); // Does not take ownership of position void gtk_wayland_setup_window_as_custom_popup (GdkWindow *gdk_window, XdgPopupPosition const *position); GdkRectangle gtk_wayland_get_logical_geom (GtkWindow *widget); #endif // WAYLAND_GLOBALS_H gtk-layer-shell-0.1.0/src/layer-surface.c000066400000000000000000000360761353716601300202320ustar00rootroot00000000000000#include "layer-surface.h" #include "gtk-layer-shell.h" #include "simple-conversions.h" #include "custom-shell-surface.h" #include "gtk-wayland.h" #include "wlr-layer-shell-unstable-v1-client.h" #include "xdg-shell-client.h" #include #include struct _LayerSurface { CustomShellSurface super; // Can be set at any time gboolean anchors[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]; int margins[GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER]; int exclusive_zone; gboolean auto_exclusive_zone; // if to automatically change the exclusive zone to match the window size GtkRequisition current_allocation; // Last size allocation, or (0, 0) if there hasn't been one GtkRequisition cached_layer_size; // Last size sent to zwlr_layer_surface_v1_set_size (starts as 0, 0) GtkRequisition last_configure_size; // Last size received from a configure event gboolean keyboard_interactivity; // Need the surface to be recreated to change GdkMonitor *monitor; enum zwlr_layer_shell_v1_layer layer; const char* name_space; // can be null, freed on destruction // The actual layer surface Wayland object (can be NULL) struct zwlr_layer_surface_v1 *layer_surface; }; /* * Sends the .set_size request if the current allocation differs from the last size sent * Needs to be called whenever current_allocation or anchors are changed * If .set_size is sent, it should trigger the compositor to send a .configure event */ static void layer_surface_send_set_size (LayerSurface *self) { GtkRequisition request_size = self->current_allocation; if ((self->anchors[GTK_LAYER_SHELL_EDGE_LEFT]) && (self->anchors[GTK_LAYER_SHELL_EDGE_RIGHT])) { request_size.width = 0; } if ((self->anchors[GTK_LAYER_SHELL_EDGE_TOP]) && (self->anchors[GTK_LAYER_SHELL_EDGE_BOTTOM])) { request_size.height = 0; } if (request_size.width != self->cached_layer_size.width || request_size.height != self->cached_layer_size.height) { self->cached_layer_size = request_size; if (self->layer_surface) { zwlr_layer_surface_v1_set_size (self->layer_surface, self->cached_layer_size.width, self->cached_layer_size.height); } } } /* * Sets the window's geometry hints (used to force the window to be a specific size) * Needs to be called whenever last_configure_size or anchors are changed * Lets windows decide their own size along any axis the surface is not stretched along * Forces window (by setting the max and min hints) to be of configured size along axises they are stretched along */ static void layer_surface_update_size (LayerSurface *self) { GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); gint width = -1; gint height = -1; if ((self->anchors[GTK_LAYER_SHELL_EDGE_LEFT]) && (self->anchors[GTK_LAYER_SHELL_EDGE_RIGHT])) { width = self->last_configure_size.width; } if ((self->anchors[GTK_LAYER_SHELL_EDGE_TOP]) && (self->anchors[GTK_LAYER_SHELL_EDGE_BOTTOM])) { height = self->last_configure_size.height; } GdkGeometry hints; hints.min_width = width; hints.max_width = width; hints.min_height = height; hints.max_height = height; gtk_window_set_geometry_hints (gtk_window, NULL, &hints, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); // This will usually get called in a moment by the layer_surface_on_size_allocate () triggered by the above // gtk_window_set_geometry_hints (). However in some cases (such as a streatching a window after a size request has // been set), an allocate will not be triggered but the set size does need to change. For this reason we make the // call here as well and let the later call clean up any mistakes this one makes. This makes the flicker problem // worse, but I think it's more important that the end result is correct. layer_surface_send_set_size (self); } static void layer_surface_handle_configure (void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t w, uint32_t h) { LayerSurface *self = data; zwlr_layer_surface_v1_ack_configure (surface, serial); self->last_configure_size = (GtkRequisition) { .width = (gint)w, .height = (gint)h, }; layer_surface_update_size (self); } static void layer_surface_handle_closed (void *data, struct zwlr_layer_surface_v1 *_surface) { LayerSurface *self = data; (void)_surface; GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); gtk_window_close (gtk_window); } static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { .configure = layer_surface_handle_configure, .closed = layer_surface_handle_closed, }; static void layer_surface_send_set_anchor (LayerSurface *self) { if (self->layer_surface) { uint32_t wlr_anchor = gtk_layer_shell_edge_array_get_zwlr_layer_shell_v1_anchor (self->anchors); zwlr_layer_surface_v1_set_anchor (self->layer_surface, wlr_anchor); } } static void layer_surface_send_set_margin (LayerSurface *self) { if (self->layer_surface) { zwlr_layer_surface_v1_set_margin (self->layer_surface, self->margins[GTK_LAYER_SHELL_EDGE_TOP], self->margins[GTK_LAYER_SHELL_EDGE_RIGHT], self->margins[GTK_LAYER_SHELL_EDGE_BOTTOM], self->margins[GTK_LAYER_SHELL_EDGE_LEFT]); } } static void layer_surface_map (CustomShellSurface *super, struct wl_surface *wl_surface) { LayerSurface *self = (LayerSurface *)super; g_return_if_fail (!self->layer_surface); struct zwlr_layer_shell_v1 *layer_shell_global = gtk_wayland_get_layer_shell_global (); g_return_if_fail (layer_shell_global); const char *name_space = self->name_space; if (name_space == NULL) name_space = "gtk-layer-shell"; struct wl_output *output = NULL; if (self->monitor) { output = gdk_wayland_monitor_get_wl_output (self->monitor); } self->layer_surface = zwlr_layer_shell_v1_get_layer_surface (layer_shell_global, wl_surface, output, self->layer, name_space); g_return_if_fail (self->layer_surface); zwlr_layer_surface_v1_set_keyboard_interactivity (self->layer_surface, self->keyboard_interactivity); zwlr_layer_surface_v1_set_exclusive_zone (self->layer_surface, self->exclusive_zone); layer_surface_send_set_anchor (self); layer_surface_send_set_margin (self); if (self->cached_layer_size.width >= 0 && self->cached_layer_size.height >= 0) { zwlr_layer_surface_v1_set_size (self->layer_surface, self->cached_layer_size.width, self->cached_layer_size.height); } zwlr_layer_surface_v1_add_listener (self->layer_surface, &layer_surface_listener, self); } static void layer_surface_unmap (CustomShellSurface *super) { LayerSurface *self = (LayerSurface *)super; if (self->layer_surface) { zwlr_layer_surface_v1_destroy (self->layer_surface); self->layer_surface = NULL; } } static void layer_surface_finalize (CustomShellSurface *super) { LayerSurface *self = (LayerSurface *)super; layer_surface_unmap (super); g_free ((gpointer)self->name_space); } static struct xdg_popup * layer_surface_get_popup (CustomShellSurface *super, struct xdg_surface *popup_xdg_surface, struct xdg_positioner *positioner) { LayerSurface *self = (LayerSurface *)super; if (!self->layer_surface) { g_critical ("layer_surface_get_popup () called when the layer surface wayland object has not yet been created"); return NULL; } struct xdg_popup *xdg_popup = xdg_surface_get_popup (popup_xdg_surface, NULL, positioner); zwlr_layer_surface_v1_get_popup (self->layer_surface, xdg_popup); return xdg_popup; } static GdkRectangle layer_surface_get_logical_geom (CustomShellSurface *super) { (void)super; return (GdkRectangle){0, 0, 0, 0}; } static const CustomShellSurfaceVirtual layer_surface_virtual = { .map = layer_surface_map, .unmap = layer_surface_unmap, .finalize = layer_surface_finalize, .get_popup = layer_surface_get_popup, .get_logical_geom = layer_surface_get_logical_geom, }; static void layer_surface_update_auto_exclusive_zone (LayerSurface *self) { if (!self->auto_exclusive_zone) return; gboolean horiz = (self->anchors[GTK_LAYER_SHELL_EDGE_LEFT] == self->anchors[GTK_LAYER_SHELL_EDGE_RIGHT]); gboolean vert = (self->anchors[GTK_LAYER_SHELL_EDGE_TOP] == self->anchors[GTK_LAYER_SHELL_EDGE_BOTTOM]); int new_exclusive_zone = -1; if (horiz && !vert) { new_exclusive_zone = self->current_allocation.height; if (!self->anchors[GTK_LAYER_SHELL_EDGE_TOP]) new_exclusive_zone += self->margins[GTK_LAYER_SHELL_EDGE_TOP]; if (!self->anchors[GTK_LAYER_SHELL_EDGE_BOTTOM]) new_exclusive_zone += self->margins[GTK_LAYER_SHELL_EDGE_BOTTOM]; } else if (vert && !horiz) { new_exclusive_zone = self->current_allocation.width; if (!self->anchors[GTK_LAYER_SHELL_EDGE_LEFT]) new_exclusive_zone += self->margins[GTK_LAYER_SHELL_EDGE_LEFT]; if (!self->anchors[GTK_LAYER_SHELL_EDGE_RIGHT]) new_exclusive_zone += self->margins[GTK_LAYER_SHELL_EDGE_RIGHT]; } if (new_exclusive_zone >= 0 && self->exclusive_zone != new_exclusive_zone) { self->exclusive_zone = new_exclusive_zone; if (self->layer_surface) { zwlr_layer_surface_v1_set_exclusive_zone (self->layer_surface, self->exclusive_zone); } } } static void layer_surface_on_size_allocate (GtkWidget *_gtk_window, GdkRectangle *allocation, LayerSurface *self) { (void)_gtk_window; if (self->current_allocation.width != allocation->width || self->current_allocation.height != allocation->height) { self->current_allocation = (GtkRequisition) { .width = allocation->width, .height = allocation->height, }; layer_surface_send_set_size (self); layer_surface_update_auto_exclusive_zone (self); } } LayerSurface * layer_surface_new (GtkWindow *gtk_window) { g_return_val_if_fail (gtk_wayland_get_layer_shell_global (), NULL); LayerSurface *self = g_new0 (LayerSurface, 1); self->super.virtual = &layer_surface_virtual; custom_shell_surface_init ((CustomShellSurface *)self, gtk_window); self->current_allocation = (GtkRequisition) { .width = 0, .height = 0, }; self->cached_layer_size = self->current_allocation; self->last_configure_size = self->current_allocation; self->monitor = NULL; self->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP; self->name_space = NULL; self->exclusive_zone = 0; self->auto_exclusive_zone = FALSE; self->keyboard_interactivity = FALSE; self->layer_surface = NULL; gtk_window_set_decorated (gtk_window, FALSE); g_signal_connect (gtk_window, "size-allocate", G_CALLBACK (layer_surface_on_size_allocate), self); return self; } LayerSurface * custom_shell_surface_get_layer_surface (CustomShellSurface *shell_surface) { if (shell_surface && shell_surface->virtual == &layer_surface_virtual) return (LayerSurface *)shell_surface; else return NULL; } void layer_surface_set_layer (LayerSurface *self, enum zwlr_layer_shell_v1_layer layer) { if (self->layer != layer) { self->layer = layer; if (self->layer_surface) { custom_shell_surface_remap ((CustomShellSurface *)self); } } } void layer_surface_set_monitor (LayerSurface *self, GdkMonitor *monitor) { if (monitor) g_return_if_fail (GDK_IS_WAYLAND_MONITOR (monitor)); if (monitor != self->monitor) { self->monitor = monitor; if (self->layer_surface) { custom_shell_surface_remap ((CustomShellSurface *)self); } } } void layer_surface_set_name_space (LayerSurface *self, char const* name_space) { if (g_strcmp0(self->name_space, name_space) != 0) { g_free ((gpointer)self->name_space); self->name_space = g_strdup (name_space); if (self->layer_surface) { custom_shell_surface_remap ((CustomShellSurface *)self); } } } void layer_surface_set_anchor (LayerSurface *self, GtkLayerShellEdge edge, gboolean anchor_to_edge) { g_return_if_fail (edge >= 0 && edge < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER); if (anchor_to_edge != self->anchors[edge]) { self->anchors[edge] = anchor_to_edge; if (self->layer_surface) { layer_surface_send_set_anchor (self); layer_surface_update_size (self); layer_surface_update_auto_exclusive_zone (self); custom_shell_surface_needs_commit ((CustomShellSurface *)self); } } } void layer_surface_set_margin (LayerSurface *self, GtkLayerShellEdge edge, int margin_size) { g_return_if_fail (edge >= 0 && edge < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER); if (margin_size != self->margins[edge]) { self->margins[edge] = margin_size; layer_surface_send_set_margin (self); layer_surface_update_auto_exclusive_zone (self); custom_shell_surface_needs_commit ((CustomShellSurface *)self); } } void layer_surface_set_exclusive_zone (LayerSurface *self, int exclusive_zone) { self->auto_exclusive_zone = FALSE; if (self->exclusive_zone != exclusive_zone) { self->exclusive_zone = exclusive_zone; if (self->layer_surface) { zwlr_layer_surface_v1_set_exclusive_zone (self->layer_surface, self->exclusive_zone); custom_shell_surface_needs_commit ((CustomShellSurface *)self); } } } void layer_surface_auto_exclusive_zone_enable (LayerSurface *self) { if (!self->auto_exclusive_zone) { self->auto_exclusive_zone = TRUE; layer_surface_update_auto_exclusive_zone (self); } } void layer_surface_set_keyboard_interactivity (LayerSurface *self, gboolean interactivity) { if (self->keyboard_interactivity != interactivity) { self->keyboard_interactivity = interactivity; if (self->layer_surface) { zwlr_layer_surface_v1_set_keyboard_interactivity (self->layer_surface, self->keyboard_interactivity); custom_shell_surface_needs_commit ((CustomShellSurface *)self); } } } gtk-layer-shell-0.1.0/src/layer-surface.h000066400000000000000000000025231353716601300202250ustar00rootroot00000000000000#ifndef LAYER_SHELL_SURFACE_H #define LAYER_SHELL_SURFACE_H #include "custom-shell-surface.h" #include "wlr-layer-shell-unstable-v1-client.h" #include "gtk-layer-shell.h" #include // a LayerSurface * can be safely cast to a CustomShellSurface * typedef struct _LayerSurface LayerSurface; LayerSurface *layer_surface_new (GtkWindow *gtk_window); // Safe cast, returns NULL if wrong type sent LayerSurface *custom_shell_surface_get_layer_surface (CustomShellSurface *shell_surface); // Surface is remapped in order to set void layer_surface_set_layer (LayerSurface *self, enum zwlr_layer_shell_v1_layer layer); void layer_surface_set_monitor (LayerSurface *self, GdkMonitor *monitor); // Can be null for default void layer_surface_set_name_space (LayerSurface *self, char const* name_space); // Makes a copy of the string, can be null // Can be set without remapping the surface void layer_surface_set_anchor (LayerSurface *self, GtkLayerShellEdge edge, gboolean anchor_to_edge); void layer_surface_set_margin (LayerSurface *self, GtkLayerShellEdge edge, int margin_size); void layer_surface_set_exclusive_zone (LayerSurface *self, int exclusive_zone); void layer_surface_auto_exclusive_zone_enable (LayerSurface *self); void layer_surface_set_keyboard_interactivity (LayerSurface *self, gboolean interactivity); #endif // LAYER_SHELL_SURFACE_H gtk-layer-shell-0.1.0/src/meson.build000066400000000000000000000023731353716601300174570ustar00rootroot00000000000000subdir('protocol') srcs = files( 'gtk-layer-shell.c', 'gtk-wayland.c', 'custom-shell-surface.c', 'layer-surface.c', 'xdg-popup-surface.c', 'xdg-toplevel-surface.c', 'gdk-window-hack.c', 'simple-conversions.c') gtk_layer_shell_lib = library('gtk-layer-shell', srcs, xdg_shell_client_header, xdg_shell_private_code, layer_shell_client_header, layer_shell_private_code, include_directories: [gtk_layer_shell_inc], dependencies: [gtk, wayland_client], version: meson.project_version(), install: true) pkg_config_name = 'gtk-layer-shell-0' gir = gnome.generate_gir( gtk_layer_shell_lib, sources: srcs + [ '../include/gtk-layer-shell.h' ], namespace: 'GtkLayerShell', nsversion: '0.1', identifier_prefix: 'GtkLayerShell', symbol_prefix: 'gtk_layer', export_packages: pkg_config_name, includes: [ 'Gtk-3.0' ], header: 'gtk-layer-shell/gtk-layer-shell.h', install: true) pkg_config.generate( name: 'gtk-layer-shell', version: meson.project_version(), libraries: [gtk_layer_shell_lib], filebase: pkg_config_name, subdirs: 'gtk-layer-shell', description: 'Use the Layer Shell Wayland protocol with GTK', url: 'https://github.com/wmww/gtk-layer-shell') gtk-layer-shell-0.1.0/src/protocol/000077500000000000000000000000001353716601300171515ustar00rootroot00000000000000gtk-layer-shell-0.1.0/src/protocol/meson.build000066400000000000000000000016731353716601300213220ustar00rootroot00000000000000if wayland_scanner.found() prog_wayland_scanner = find_program(wayland_scanner.get_pkgconfig_variable('wayland_scanner')) else prog_wayland_scanner = find_program('wayland-scanner') endif gen_client_header = generator(prog_wayland_scanner, output: ['@BASENAME@-client.h'], arguments: ['-c', 'client-header', '@INPUT@', '@BUILD_DIR@/@BASENAME@-client.h']) gen_private_code = generator(prog_wayland_scanner, output: ['@BASENAME@.c'], arguments: ['-c', 'code', '@INPUT@', '@BUILD_DIR@/@BASENAME@.c']) # 'code' is deprecated, and can be replaced with 'private-code' when all platforms have a new enough wayland-scanner xdg_shell_client_header = gen_client_header.process('xdg-shell.xml') xdg_shell_private_code = gen_private_code.process('xdg-shell.xml') layer_shell_client_header = gen_client_header.process('wlr-layer-shell-unstable-v1.xml') layer_shell_private_code = gen_private_code.process('wlr-layer-shell-unstable-v1.xml') gtk-layer-shell-0.1.0/src/protocol/wlr-layer-shell-unstable-v1.xml000066400000000000000000000320701353716601300250570ustar00rootroot00000000000000 Copyright © 2017 Drew DeVault Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the copyright holders not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The copyright holders make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Clients can use this interface to assign the surface_layer role to wl_surfaces. Such surfaces are assigned to a "layer" of the output and rendered with a defined z-depth respective to each other. They may also be anchored to the edges and corners of a screen and specify input handling semantics. This interface should be suitable for the implementation of many desktop shell components, and a broad number of other applications that interact with the desktop. Create a layer surface for an existing surface. This assigns the role of layer_surface, or raises a protocol error if another role is already assigned. Creating a layer surface from a wl_surface which has a buffer attached or committed is a client error, and any attempts by a client to attach or manipulate a buffer prior to the first layer_surface.configure call must also be treated as errors. You may pass NULL for output to allow the compositor to decide which output to use. Generally this will be the one that the user most recently interacted with. Clients can specify a namespace that defines the purpose of the layer surface. These values indicate which layers a surface can be rendered in. They are ordered by z depth, bottom-most first. Traditional shell surfaces will typically be rendered between the bottom and top layers. Fullscreen shell surfaces are typically rendered at the top layer. Multiple surfaces can share a single layer, and ordering within a single layer is undefined. An interface that may be implemented by a wl_surface, for surfaces that are designed to be rendered as a layer of a stacked desktop-like environment. Layer surface state (size, anchor, exclusive zone, margin, interactivity) is double-buffered, and will be applied at the time wl_surface.commit of the corresponding wl_surface is called. Sets the size of the surface in surface-local coordinates. The compositor will display the surface centered with respect to its anchors. If you pass 0 for either value, the compositor will assign it and inform you of the assignment in the configure event. You must set your anchor to opposite edges in the dimensions you omit; not doing so is a protocol error. Both values are 0 by default. Size is double-buffered, see wl_surface.commit. Requests that the compositor anchor the surface to the specified edges and corners. If two orthogonal edges are specified (e.g. 'top' and 'left'), then the anchor point will be the intersection of the edges (e.g. the top left corner of the output); otherwise the anchor point will be centered on that edge, or in the center if none is specified. Anchor is double-buffered, see wl_surface.commit. Requests that the compositor avoids occluding an area of the surface with other surfaces. The compositor's use of this information is implementation-dependent - do not assume that this region will not actually be occluded. A positive value is only meaningful if the surface is anchored to an edge, rather than a corner. The zone is the number of surface-local coordinates from the edge that is considered exclusive. Surfaces that do not wish to have an exclusive zone may instead specify how they should interact with surfaces that do. If set to zero, the surface indicates that it would like to be moved to avoid occluding surfaces with a positive exclusive zone. If set to -1, the surface indicates that it would not like to be moved to accommodate for other surfaces, and the compositor should extend it all the way to the edges it is anchored to. For example, a panel might set its exclusive zone to 10, so that maximized shell surfaces are not shown on top of it. A notification might set its exclusive zone to 0, so that it is moved to avoid occluding the panel, but shell surfaces are shown underneath it. A wallpaper or lock screen might set their exclusive zone to -1, so that they stretch below or over the panel. The default value is 0. Exclusive zone is double-buffered, see wl_surface.commit. Requests that the surface be placed some distance away from the anchor point on the output, in surface-local coordinates. Setting this value for edges you are not anchored to has no effect. The exclusive zone includes the margin. Margin is double-buffered, see wl_surface.commit. Set to 1 to request that the seat send keyboard events to this layer surface. For layers below the shell surface layer, the seat will use normal focus semantics. For layers above the shell surface layers, the seat will always give exclusive keyboard focus to the top-most layer which has keyboard interactivity set to true. Layer surfaces receive pointer, touch, and tablet events normally. If you do not want to receive them, set the input region on your surface to an empty region. Events is double-buffered, see wl_surface.commit. This assigns an xdg_popup's parent to this layer_surface. This popup should have been created via xdg_surface::get_popup with the parent set to NULL, and this request must be invoked before committing the popup's initial state. See the documentation of xdg_popup for more details about what an xdg_popup is and how it is used. When a configure event is received, if a client commits the surface in response to the configure event, then the client must make an ack_configure request sometime before the commit request, passing along the serial of the configure event. If the client receives multiple configure events before it can respond to one, it only has to ack the last configure event. A client is not required to commit immediately after sending an ack_configure request - it may even ack_configure several times before its next surface commit. A client may send multiple ack_configure requests before committing, but only the last request sent before a commit indicates which configure event the client really is responding to. This request destroys the layer surface. The configure event asks the client to resize its surface. Clients should arrange their surface for the new states, and then send an ack_configure request with the serial sent in this configure event at some point before committing the new surface. The client is free to dismiss all but the last configure event it received. The width and height arguments specify the size of the window in surface-local coordinates. The size is a hint, in the sense that the client is free to ignore it if it doesn't resize, pick a smaller size (to satisfy aspect ratio or resize in steps of NxM pixels). If the client picks a smaller size and is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the surface will be centered on this axis. If the width or height arguments are zero, it means the client should decide its own window dimension. The closed event is sent by the compositor when the surface will no longer be shown. The output may have been destroyed or the user may have asked for it to be removed. Further changes to the surface will be ignored. The client should destroy the resource after receiving this event, and create a new surface if they so choose. gtk-layer-shell-0.1.0/src/protocol/xdg-shell.xml000066400000000000000000001412111353716601300215620ustar00rootroot00000000000000 Copyright © 2008-2013 Kristian Høgsberg Copyright © 2013 Rafael Antognolli Copyright © 2013 Jasper St. Pierre Copyright © 2010-2013 Intel Corporation Copyright © 2015-2017 Samsung Electronics Co., Ltd Copyright © 2015-2017 Red Hat Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The xdg_wm_base interface is exposed as a global object enabling clients to turn their wl_surfaces into windows in a desktop environment. It defines the basic functionality needed for clients and the compositor to create windows that can be dragged, resized, maximized, etc, as well as creating transient windows such as popup menus. Destroy this xdg_wm_base object. Destroying a bound xdg_wm_base object while there are surfaces still alive created by this xdg_wm_base object instance is illegal and will result in a protocol error. Create a positioner object. A positioner object is used to position surfaces relative to some parent surface. See the interface description and xdg_surface.get_popup for details. This creates an xdg_surface for the given surface. While xdg_surface itself is not a role, the corresponding surface may only be assigned a role extending xdg_surface, such as xdg_toplevel or xdg_popup. This creates an xdg_surface for the given surface. An xdg_surface is used as basis to define a role to a given surface, such as xdg_toplevel or xdg_popup. It also manages functionality shared between xdg_surface based surface roles. See the documentation of xdg_surface for more details about what an xdg_surface is and how it is used. A client must respond to a ping event with a pong request or the client may be deemed unresponsive. See xdg_wm_base.ping. The ping event asks the client if it's still alive. Pass the serial specified in the event back to the compositor by sending a "pong" request back with the specified serial. See xdg_wm_base.ping. Compositors can use this to determine if the client is still alive. It's unspecified what will happen if the client doesn't respond to the ping request, or in what timeframe. Clients should try to respond in a reasonable amount of time. A compositor is free to ping in any way it wants, but a client must always respond to any xdg_wm_base object it created. The xdg_positioner provides a collection of rules for the placement of a child surface relative to a parent surface. Rules can be defined to ensure the child surface remains within the visible area's borders, and to specify how the child surface changes its position, such as sliding along an axis, or flipping around a rectangle. These positioner-created rules are constrained by the requirement that a child surface must intersect with or be at least partially adjacent to its parent surface. See the various requests for details about possible rules. At the time of the request, the compositor makes a copy of the rules specified by the xdg_positioner. Thus, after the request is complete the xdg_positioner object can be destroyed or reused; further changes to the object will have no effect on previous usages. For an xdg_positioner object to be considered complete, it must have a non-zero size set by set_size, and a non-zero anchor rectangle set by set_anchor_rect. Passing an incomplete xdg_positioner object when positioning a surface raises an error. Notify the compositor that the xdg_positioner will no longer be used. Set the size of the surface that is to be positioned with the positioner object. The size is in surface-local coordinates and corresponds to the window geometry. See xdg_surface.set_window_geometry. If a zero or negative size is set the invalid_input error is raised. Specify the anchor rectangle within the parent surface that the child surface will be placed relative to. The rectangle is relative to the window geometry as defined by xdg_surface.set_window_geometry of the parent surface. When the xdg_positioner object is used to position a child surface, the anchor rectangle may not extend outside the window geometry of the positioned child's parent surface. If a negative size is set the invalid_input error is raised. Defines the anchor point for the anchor rectangle. The specified anchor is used derive an anchor point that the child surface will be positioned relative to. If a corner anchor is set (e.g. 'top_left' or 'bottom_right'), the anchor point will be at the specified corner; otherwise, the derived anchor point will be centered on the specified edge, or in the center of the anchor rectangle if no edge is specified. Defines in what direction a surface should be positioned, relative to the anchor point of the parent surface. If a corner gravity is specified (e.g. 'bottom_right' or 'top_left'), then the child surface will be placed towards the specified gravity; otherwise, the child surface will be centered over the anchor point on any axis that had no gravity specified. The constraint adjustment value define ways the compositor will adjust the position of the surface, if the unadjusted position would result in the surface being partly constrained. Whether a surface is considered 'constrained' is left to the compositor to determine. For example, the surface may be partly outside the compositor's defined 'work area', thus necessitating the child surface's position be adjusted until it is entirely inside the work area. The adjustments can be combined, according to a defined precedence: 1) Flip, 2) Slide, 3) Resize. Don't alter the surface position even if it is constrained on some axis, for example partially outside the edge of an output. Slide the surface along the x axis until it is no longer constrained. First try to slide towards the direction of the gravity on the x axis until either the edge in the opposite direction of the gravity is unconstrained or the edge in the direction of the gravity is constrained. Then try to slide towards the opposite direction of the gravity on the x axis until either the edge in the direction of the gravity is unconstrained or the edge in the opposite direction of the gravity is constrained. Slide the surface along the y axis until it is no longer constrained. First try to slide towards the direction of the gravity on the y axis until either the edge in the opposite direction of the gravity is unconstrained or the edge in the direction of the gravity is constrained. Then try to slide towards the opposite direction of the gravity on the y axis until either the edge in the direction of the gravity is unconstrained or the edge in the opposite direction of the gravity is constrained. Invert the anchor and gravity on the x axis if the surface is constrained on the x axis. For example, if the left edge of the surface is constrained, the gravity is 'left' and the anchor is 'left', change the gravity to 'right' and the anchor to 'right'. If the adjusted position also ends up being constrained, the resulting position of the flip_x adjustment will be the one before the adjustment. Invert the anchor and gravity on the y axis if the surface is constrained on the y axis. For example, if the bottom edge of the surface is constrained, the gravity is 'bottom' and the anchor is 'bottom', change the gravity to 'top' and the anchor to 'top'. The adjusted position is calculated given the original anchor rectangle and offset, but with the new flipped anchor and gravity values. If the adjusted position also ends up being constrained, the resulting position of the flip_y adjustment will be the one before the adjustment. Resize the surface horizontally so that it is completely unconstrained. Resize the surface vertically so that it is completely unconstrained. Specify how the window should be positioned if the originally intended position caused the surface to be constrained, meaning at least partially outside positioning boundaries set by the compositor. The adjustment is set by constructing a bitmask describing the adjustment to be made when the surface is constrained on that axis. If no bit for one axis is set, the compositor will assume that the child surface should not change its position on that axis when constrained. If more than one bit for one axis is set, the order of how adjustments are applied is specified in the corresponding adjustment descriptions. The default adjustment is none. Specify the surface position offset relative to the position of the anchor on the anchor rectangle and the anchor on the surface. For example if the anchor of the anchor rectangle is at (x, y), the surface has the gravity bottom|right, and the offset is (ox, oy), the calculated surface position will be (x + ox, y + oy). The offset position of the surface is the one used for constraint testing. See set_constraint_adjustment. An example use case is placing a popup menu on top of a user interface element, while aligning the user interface element of the parent surface with some user interface element placed somewhere in the popup surface. An interface that may be implemented by a wl_surface, for implementations that provide a desktop-style user interface. It provides a base set of functionality required to construct user interface elements requiring management by the compositor, such as toplevel windows, menus, etc. The types of functionality are split into xdg_surface roles. Creating an xdg_surface does not set the role for a wl_surface. In order to map an xdg_surface, the client must create a role-specific object using, e.g., get_toplevel, get_popup. The wl_surface for any given xdg_surface can have at most one role, and may not be assigned any role not based on xdg_surface. A role must be assigned before any other requests are made to the xdg_surface object. The client must call wl_surface.commit on the corresponding wl_surface for the xdg_surface state to take effect. Creating an xdg_surface from a wl_surface which has a buffer attached or committed is a client error, and any attempts by a client to attach or manipulate a buffer prior to the first xdg_surface.configure call must also be treated as errors. Mapping an xdg_surface-based role surface is defined as making it possible for the surface to be shown by the compositor. Note that a mapped surface is not guaranteed to be visible once it is mapped. For an xdg_surface to be mapped by the compositor, the following conditions must be met: (1) the client has assigned an xdg_surface-based role to the surface (2) the client has set and committed the xdg_surface state and the role-dependent state to the surface (3) the client has committed a buffer to the surface A newly-unmapped surface is considered to have met condition (1) out of the 3 required conditions for mapping a surface if its role surface has not been destroyed. Destroy the xdg_surface object. An xdg_surface must only be destroyed after its role object has been destroyed. This creates an xdg_toplevel object for the given xdg_surface and gives the associated wl_surface the xdg_toplevel role. See the documentation of xdg_toplevel for more details about what an xdg_toplevel is and how it is used. This creates an xdg_popup object for the given xdg_surface and gives the associated wl_surface the xdg_popup role. If null is passed as a parent, a parent surface must be specified using some other protocol, before committing the initial state. See the documentation of xdg_popup for more details about what an xdg_popup is and how it is used. The window geometry of a surface is its "visible bounds" from the user's perspective. Client-side decorations often have invisible portions like drop-shadows which should be ignored for the purposes of aligning, placing and constraining windows. The window geometry is double buffered, and will be applied at the time wl_surface.commit of the corresponding wl_surface is called. When maintaining a position, the compositor should treat the (x, y) coordinate of the window geometry as the top left corner of the window. A client changing the (x, y) window geometry coordinate should in general not alter the position of the window. Once the window geometry of the surface is set, it is not possible to unset it, and it will remain the same until set_window_geometry is called again, even if a new subsurface or buffer is attached. If never set, the value is the full bounds of the surface, including any subsurfaces. This updates dynamically on every commit. This unset is meant for extremely simple clients. The arguments are given in the surface-local coordinate space of the wl_surface associated with this xdg_surface. The width and height must be greater than zero. Setting an invalid size will raise an error. When applied, the effective window geometry will be the set window geometry clamped to the bounding rectangle of the combined geometry of the surface of the xdg_surface and the associated subsurfaces. When a configure event is received, if a client commits the surface in response to the configure event, then the client must make an ack_configure request sometime before the commit request, passing along the serial of the configure event. For instance, for toplevel surfaces the compositor might use this information to move a surface to the top left only when the client has drawn itself for the maximized or fullscreen state. If the client receives multiple configure events before it can respond to one, it only has to ack the last configure event. A client is not required to commit immediately after sending an ack_configure request - it may even ack_configure several times before its next surface commit. A client may send multiple ack_configure requests before committing, but only the last request sent before a commit indicates which configure event the client really is responding to. The configure event marks the end of a configure sequence. A configure sequence is a set of one or more events configuring the state of the xdg_surface, including the final xdg_surface.configure event. Where applicable, xdg_surface surface roles will during a configure sequence extend this event as a latched state sent as events before the xdg_surface.configure event. Such events should be considered to make up a set of atomically applied configuration states, where the xdg_surface.configure commits the accumulated state. Clients should arrange their surface for the new states, and then send an ack_configure request with the serial sent in this configure event at some point before committing the new surface. If the client receives multiple configure events before it can respond to one, it is free to discard all but the last event it received. This interface defines an xdg_surface role which allows a surface to, among other things, set window-like properties such as maximize, fullscreen, and minimize, set application-specific metadata like title and id, and well as trigger user interactive operations such as interactive resize and move. Unmapping an xdg_toplevel means that the surface cannot be shown by the compositor until it is explicitly mapped again. All active operations (e.g., move, resize) are canceled and all attributes (e.g. title, state, stacking, ...) are discarded for an xdg_toplevel surface when it is unmapped. Attaching a null buffer to a toplevel unmaps the surface. This request destroys the role surface and unmaps the surface; see "Unmapping" behavior in interface section for details. Set the "parent" of this surface. This surface should be stacked above the parent surface and all other ancestor surfaces. Parent windows should be set on dialogs, toolboxes, or other "auxiliary" surfaces, so that the parent is raised when the dialog is raised. Setting a null parent for a child window removes any parent-child relationship for the child. Setting a null parent for a window which currently has no parent is a no-op. If the parent is unmapped then its children are managed as though the parent of the now-unmapped parent has become the parent of this surface. If no parent exists for the now-unmapped parent then the children are managed as though they have no parent surface. Set a short title for the surface. This string may be used to identify the surface in a task bar, window list, or other user interface elements provided by the compositor. The string must be encoded in UTF-8. Set an application identifier for the surface. The app ID identifies the general class of applications to which the surface belongs. The compositor can use this to group multiple surfaces together, or to determine how to launch a new application. For D-Bus activatable applications, the app ID is used as the D-Bus service name. The compositor shell will try to group application surfaces together by their app ID. As a best practice, it is suggested to select app ID's that match the basename of the application's .desktop file. For example, "org.freedesktop.FooViewer" where the .desktop file is "org.freedesktop.FooViewer.desktop". See the desktop-entry specification [0] for more details on application identifiers and how they relate to well-known D-Bus names and .desktop files. [0] http://standards.freedesktop.org/desktop-entry-spec/ Clients implementing client-side decorations might want to show a context menu when right-clicking on the decorations, giving the user a menu that they can use to maximize or minimize the window. This request asks the compositor to pop up such a window menu at the given position, relative to the local surface coordinates of the parent surface. There are no guarantees as to what menu items the window menu contains. This request must be used in response to some sort of user action like a button press, key press, or touch down event. Start an interactive, user-driven move of the surface. This request must be used in response to some sort of user action like a button press, key press, or touch down event. The passed serial is used to determine the type of interactive move (touch, pointer, etc). The server may ignore move requests depending on the state of the surface (e.g. fullscreen or maximized), or if the passed serial is no longer valid. If triggered, the surface will lose the focus of the device (wl_pointer, wl_touch, etc) used for the move. It is up to the compositor to visually indicate that the move is taking place, such as updating a pointer cursor, during the move. There is no guarantee that the device focus will return when the move is completed. These values are used to indicate which edge of a surface is being dragged in a resize operation. Start a user-driven, interactive resize of the surface. This request must be used in response to some sort of user action like a button press, key press, or touch down event. The passed serial is used to determine the type of interactive resize (touch, pointer, etc). The server may ignore resize requests depending on the state of the surface (e.g. fullscreen or maximized). If triggered, the client will receive configure events with the "resize" state enum value and the expected sizes. See the "resize" enum value for more details about what is required. The client must also acknowledge configure events using "ack_configure". After the resize is completed, the client will receive another "configure" event without the resize state. If triggered, the surface also will lose the focus of the device (wl_pointer, wl_touch, etc) used for the resize. It is up to the compositor to visually indicate that the resize is taking place, such as updating a pointer cursor, during the resize. There is no guarantee that the device focus will return when the resize is completed. The edges parameter specifies how the surface should be resized, and is one of the values of the resize_edge enum. The compositor may use this information to update the surface position for example when dragging the top left corner. The compositor may also use this information to adapt its behavior, e.g. choose an appropriate cursor image. The different state values used on the surface. This is designed for state values like maximized, fullscreen. It is paired with the configure event to ensure that both the client and the compositor setting the state can be synchronized. States set in this way are double-buffered. They will get applied on the next commit. The surface is maximized. The window geometry specified in the configure event must be obeyed by the client. The client should draw without shadow or other decoration outside of the window geometry. The surface is fullscreen. The window geometry specified in the configure event is a maximum; the client cannot resize beyond it. For a surface to cover the whole fullscreened area, the geometry dimensions must be obeyed by the client. For more details, see xdg_toplevel.set_fullscreen. The surface is being resized. The window geometry specified in the configure event is a maximum; the client cannot resize beyond it. Clients that have aspect ratio or cell sizing configuration can use a smaller size, however. Client window decorations should be painted as if the window is active. Do not assume this means that the window actually has keyboard or pointer focus. The window is currently in a tiled layout and the left edge is considered to be adjacent to another part of the tiling grid. The window is currently in a tiled layout and the right edge is considered to be adjacent to another part of the tiling grid. The window is currently in a tiled layout and the top edge is considered to be adjacent to another part of the tiling grid. The window is currently in a tiled layout and the bottom edge is considered to be adjacent to another part of the tiling grid. Set a maximum size for the window. The client can specify a maximum size so that the compositor does not try to configure the window beyond this size. The width and height arguments are in window geometry coordinates. See xdg_surface.set_window_geometry. Values set in this way are double-buffered. They will get applied on the next commit. The compositor can use this information to allow or disallow different states like maximize or fullscreen and draw accurate animations. Similarly, a tiling window manager may use this information to place and resize client windows in a more effective way. The client should not rely on the compositor to obey the maximum size. The compositor may decide to ignore the values set by the client and request a larger size. If never set, or a value of zero in the request, means that the client has no expected maximum size in the given dimension. As a result, a client wishing to reset the maximum size to an unspecified state can use zero for width and height in the request. Requesting a maximum size to be smaller than the minimum size of a surface is illegal and will result in a protocol error. The width and height must be greater than or equal to zero. Using strictly negative values for width and height will result in a protocol error. Set a minimum size for the window. The client can specify a minimum size so that the compositor does not try to configure the window below this size. The width and height arguments are in window geometry coordinates. See xdg_surface.set_window_geometry. Values set in this way are double-buffered. They will get applied on the next commit. The compositor can use this information to allow or disallow different states like maximize or fullscreen and draw accurate animations. Similarly, a tiling window manager may use this information to place and resize client windows in a more effective way. The client should not rely on the compositor to obey the minimum size. The compositor may decide to ignore the values set by the client and request a smaller size. If never set, or a value of zero in the request, means that the client has no expected minimum size in the given dimension. As a result, a client wishing to reset the minimum size to an unspecified state can use zero for width and height in the request. Requesting a minimum size to be larger than the maximum size of a surface is illegal and will result in a protocol error. The width and height must be greater than or equal to zero. Using strictly negative values for width and height will result in a protocol error. Maximize the surface. After requesting that the surface should be maximized, the compositor will respond by emitting a configure event. Whether this configure actually sets the window maximized is subject to compositor policies. The client must then update its content, drawing in the configured state. The client must also acknowledge the configure when committing the new content (see ack_configure). It is up to the compositor to decide how and where to maximize the surface, for example which output and what region of the screen should be used. If the surface was already maximized, the compositor will still emit a configure event with the "maximized" state. If the surface is in a fullscreen state, this request has no direct effect. It may alter the state the surface is returned to when unmaximized unless overridden by the compositor. Unmaximize the surface. After requesting that the surface should be unmaximized, the compositor will respond by emitting a configure event. Whether this actually un-maximizes the window is subject to compositor policies. If available and applicable, the compositor will include the window geometry dimensions the window had prior to being maximized in the configure event. The client must then update its content, drawing it in the configured state. The client must also acknowledge the configure when committing the new content (see ack_configure). It is up to the compositor to position the surface after it was unmaximized; usually the position the surface had before maximizing, if applicable. If the surface was already not maximized, the compositor will still emit a configure event without the "maximized" state. If the surface is in a fullscreen state, this request has no direct effect. It may alter the state the surface is returned to when unmaximized unless overridden by the compositor. Make the surface fullscreen. After requesting that the surface should be fullscreened, the compositor will respond by emitting a configure event. Whether the client is actually put into a fullscreen state is subject to compositor policies. The client must also acknowledge the configure when committing the new content (see ack_configure). The output passed by the request indicates the client's preference as to which display it should be set fullscreen on. If this value is NULL, it's up to the compositor to choose which display will be used to map this surface. If the surface doesn't cover the whole output, the compositor will position the surface in the center of the output and compensate with with border fill covering the rest of the output. The content of the border fill is undefined, but should be assumed to be in some way that attempts to blend into the surrounding area (e.g. solid black). If the fullscreened surface is not opaque, the compositor must make sure that other screen content not part of the same surface tree (made up of subsurfaces, popups or similarly coupled surfaces) are not visible below the fullscreened surface. Make the surface no longer fullscreen. After requesting that the surface should be unfullscreened, the compositor will respond by emitting a configure event. Whether this actually removes the fullscreen state of the client is subject to compositor policies. Making a surface unfullscreen sets states for the surface based on the following: * the state(s) it may have had before becoming fullscreen * any state(s) decided by the compositor * any state(s) requested by the client while the surface was fullscreen The compositor may include the previous window geometry dimensions in the configure event, if applicable. The client must also acknowledge the configure when committing the new content (see ack_configure). Request that the compositor minimize your surface. There is no way to know if the surface is currently minimized, nor is there any way to unset minimization on this surface. If you are looking to throttle redrawing when minimized, please instead use the wl_surface.frame event for this, as this will also work with live previews on windows in Alt-Tab, Expose or similar compositor features. This configure event asks the client to resize its toplevel surface or to change its state. The configured state should not be applied immediately. See xdg_surface.configure for details. The width and height arguments specify a hint to the window about how its surface should be resized in window geometry coordinates. See set_window_geometry. If the width or height arguments are zero, it means the client should decide its own window dimension. This may happen when the compositor needs to configure the state of the surface but doesn't have any information about any previous or expected dimension. The states listed in the event specify how the width/height arguments should be interpreted, and possibly how it should be drawn. Clients must send an ack_configure in response to this event. See xdg_surface.configure and xdg_surface.ack_configure for details. The close event is sent by the compositor when the user wants the surface to be closed. This should be equivalent to the user clicking the close button in client-side decorations, if your application has any. This is only a request that the user intends to close the window. The client may choose to ignore this request, or show a dialog to ask the user to save their data, etc. A popup surface is a short-lived, temporary surface. It can be used to implement for example menus, popovers, tooltips and other similar user interface concepts. A popup can be made to take an explicit grab. See xdg_popup.grab for details. When the popup is dismissed, a popup_done event will be sent out, and at the same time the surface will be unmapped. See the xdg_popup.popup_done event for details. Explicitly destroying the xdg_popup object will also dismiss the popup and unmap the surface. Clients that want to dismiss the popup when another surface of their own is clicked should dismiss the popup using the destroy request. A newly created xdg_popup will be stacked on top of all previously created xdg_popup surfaces associated with the same xdg_toplevel. The parent of an xdg_popup must be mapped (see the xdg_surface description) before the xdg_popup itself. The x and y arguments passed when creating the popup object specify where the top left of the popup should be placed, relative to the local surface coordinates of the parent surface. See xdg_surface.get_popup. An xdg_popup must intersect with or be at least partially adjacent to its parent surface. The client must call wl_surface.commit on the corresponding wl_surface for the xdg_popup state to take effect. This destroys the popup. Explicitly destroying the xdg_popup object will also dismiss the popup, and unmap the surface. If this xdg_popup is not the "topmost" popup, a protocol error will be sent. This request makes the created popup take an explicit grab. An explicit grab will be dismissed when the user dismisses the popup, or when the client destroys the xdg_popup. This can be done by the user clicking outside the surface, using the keyboard, or even locking the screen through closing the lid or a timeout. If the compositor denies the grab, the popup will be immediately dismissed. This request must be used in response to some sort of user action like a button press, key press, or touch down event. The serial number of the event should be passed as 'serial'. The parent of a grabbing popup must either be an xdg_toplevel surface or another xdg_popup with an explicit grab. If the parent is another xdg_popup it means that the popups are nested, with this popup now being the topmost popup. Nested popups must be destroyed in the reverse order they were created in, e.g. the only popup you are allowed to destroy at all times is the topmost one. When compositors choose to dismiss a popup, they may dismiss every nested grabbing popup as well. When a compositor dismisses popups, it will follow the same dismissing order as required from the client. The parent of a grabbing popup must either be another xdg_popup with an active explicit grab, or an xdg_popup or xdg_toplevel, if there are no explicit grabs already taken. If the topmost grabbing popup is destroyed, the grab will be returned to the parent of the popup, if that parent previously had an explicit grab. If the parent is a grabbing popup which has already been dismissed, this popup will be immediately dismissed. If the parent is a popup that did not take an explicit grab, an error will be raised. During a popup grab, the client owning the grab will receive pointer and touch events for all their surfaces as normal (similar to an "owner-events" grab in X11 parlance), while the top most grabbing popup will always have keyboard focus. This event asks the popup surface to configure itself given the configuration. The configured state should not be applied immediately. See xdg_surface.configure for details. The x and y arguments represent the position the popup was placed at given the xdg_positioner rule, relative to the upper left corner of the window geometry of the parent surface. The popup_done event is sent out when a popup is dismissed by the compositor. The client should destroy the xdg_popup object at this point. gtk-layer-shell-0.1.0/src/simple-conversions.c000066400000000000000000000072721353716601300213230ustar00rootroot00000000000000#include "simple-conversions.h" enum zwlr_layer_shell_v1_layer gtk_layer_shell_layer_get_zwlr_layer_shell_v1_layer (GtkLayerShellLayer layer) { switch (layer) { case GTK_LAYER_SHELL_LAYER_BACKGROUND: return ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; case GTK_LAYER_SHELL_LAYER_BOTTOM: return ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM; case GTK_LAYER_SHELL_LAYER_TOP: return ZWLR_LAYER_SHELL_V1_LAYER_TOP; case GTK_LAYER_SHELL_LAYER_OVERLAY: return ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY; default: g_critical ("Invalid GtkLayerShellLayer %d", layer); return ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; } } uint32_t gtk_layer_shell_edge_array_get_zwlr_layer_shell_v1_anchor (gboolean edges[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]) { uint32_t anchor = 0; if (edges[GTK_LAYER_SHELL_EDGE_LEFT]) anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT; if (edges[GTK_LAYER_SHELL_EDGE_RIGHT]) anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; if (edges[GTK_LAYER_SHELL_EDGE_TOP]) anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; if (edges[GTK_LAYER_SHELL_EDGE_BOTTOM]) anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; return anchor; } enum xdg_positioner_gravity gdk_gravity_get_xdg_positioner_gravity (GdkGravity gravity) { switch (gravity) { case GDK_GRAVITY_NORTH_WEST: return XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT; case GDK_GRAVITY_NORTH: return XDG_POSITIONER_GRAVITY_BOTTOM; case GDK_GRAVITY_NORTH_EAST: return XDG_POSITIONER_GRAVITY_BOTTOM_LEFT; case GDK_GRAVITY_WEST: return XDG_POSITIONER_GRAVITY_RIGHT; case GDK_GRAVITY_CENTER: return XDG_POSITIONER_GRAVITY_NONE; case GDK_GRAVITY_EAST: return XDG_POSITIONER_GRAVITY_LEFT; case GDK_GRAVITY_SOUTH_WEST: return XDG_POSITIONER_GRAVITY_TOP_RIGHT; case GDK_GRAVITY_SOUTH: return XDG_POSITIONER_GRAVITY_TOP; case GDK_GRAVITY_SOUTH_EAST: return XDG_POSITIONER_GRAVITY_TOP_LEFT; case GDK_GRAVITY_STATIC: return XDG_POSITIONER_GRAVITY_NONE; default: g_critical ("Invalid GdkGravity %d", gravity); return XDG_POSITIONER_GRAVITY_NONE; } } enum xdg_positioner_anchor gdk_gravity_get_xdg_positioner_anchor (GdkGravity anchor) { switch (anchor) { case GDK_GRAVITY_NORTH_WEST: return XDG_POSITIONER_ANCHOR_TOP_LEFT; case GDK_GRAVITY_NORTH: return XDG_POSITIONER_ANCHOR_TOP; case GDK_GRAVITY_NORTH_EAST: return XDG_POSITIONER_ANCHOR_TOP_RIGHT; case GDK_GRAVITY_WEST: return XDG_POSITIONER_ANCHOR_LEFT; case GDK_GRAVITY_CENTER: return XDG_POSITIONER_ANCHOR_NONE; case GDK_GRAVITY_EAST: return XDG_POSITIONER_ANCHOR_RIGHT; case GDK_GRAVITY_SOUTH_WEST: return XDG_POSITIONER_ANCHOR_BOTTOM_LEFT; case GDK_GRAVITY_SOUTH: return XDG_POSITIONER_ANCHOR_BOTTOM; case GDK_GRAVITY_SOUTH_EAST: return XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT; case GDK_GRAVITY_STATIC: return XDG_POSITIONER_ANCHOR_NONE; default: g_critical ("Invalid GdkGravity %d", anchor); return XDG_POSITIONER_ANCHOR_NONE; } } enum xdg_positioner_constraint_adjustment gdk_anchor_hints_get_xdg_positioner_constraint_adjustment (GdkAnchorHints hints) { enum xdg_positioner_constraint_adjustment adjustment = 0; if (hints & GDK_ANCHOR_FLIP_X) adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X; if (hints & GDK_ANCHOR_FLIP_Y) adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y; if (hints & GDK_ANCHOR_SLIDE_X) adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X; if (hints & GDK_ANCHOR_SLIDE_Y) adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y; if (hints & GDK_ANCHOR_RESIZE_X) adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X; if (hints & GDK_ANCHOR_RESIZE_Y) adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y; return adjustment; } gtk-layer-shell-0.1.0/src/simple-conversions.h000066400000000000000000000013561353716601300213250ustar00rootroot00000000000000#ifndef SIMPLE_CONVERSIONS_H #define SIMPLE_CONVERSIONS_H #include "xdg-shell-client.h" #include "wlr-layer-shell-unstable-v1-client.h" #include "gtk-layer-shell.h" #include enum zwlr_layer_shell_v1_layer gtk_layer_shell_layer_get_zwlr_layer_shell_v1_layer (GtkLayerShellLayer layer); uint32_t gtk_layer_shell_edge_array_get_zwlr_layer_shell_v1_anchor (gboolean edges[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]); enum xdg_positioner_gravity gdk_gravity_get_xdg_positioner_gravity (GdkGravity gravity); enum xdg_positioner_anchor gdk_gravity_get_xdg_positioner_anchor (GdkGravity anchor); enum xdg_positioner_constraint_adjustment gdk_anchor_hints_get_xdg_positioner_constraint_adjustment (GdkAnchorHints hints); #endif // SIMPLE_CONVERSIONS_H gtk-layer-shell-0.1.0/src/xdg-popup-surface.c000066400000000000000000000242721353716601300210340ustar00rootroot00000000000000#include "xdg-popup-surface.h" #include "custom-shell-surface.h" #include "gtk-wayland.h" #include "simple-conversions.h" #include "xdg-shell-client.h" #include #include #include struct _XdgPopupSurface { CustomShellSurface super; XdgPopupPosition position; GdkRectangle cached_allocation; GdkRectangle geom; // These can be NULL struct xdg_surface *xdg_surface; struct xdg_popup *xdg_popup; }; static void xdg_surface_handle_configure (void *data, struct xdg_surface *_xdg_surface, uint32_t serial) { XdgPopupSurface *self = data; (void)_xdg_surface; xdg_surface_ack_configure (self->xdg_surface, serial); } static const struct xdg_surface_listener xdg_surface_listener = { .configure = xdg_surface_handle_configure, }; static void xdg_popup_handle_configure (void *data, struct xdg_popup *_xdg_popup, int32_t _x, int32_t _y, int32_t width, int32_t height) { XdgPopupSurface *self = data; (void)_xdg_popup; (void)_x; (void)_y; g_return_if_fail(width >= 0 && height >= 0); // Protocol error // Technically this should not be applied until we get a xdg_surface.configure GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); gtk_window_resize (gtk_window, width, height); GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (gtk_window)); g_return_if_fail (gdk_window); // calculating the correct values is hard, but we're not required to provide them g_signal_emit_by_name (gdk_window, "moved-to-rect", NULL, NULL, FALSE, FALSE); } static void xdg_popup_handle_popup_done (void *data, struct xdg_popup *_xdg_popup) { (void)_xdg_popup; XdgPopupSurface *self = data; GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); gtk_widget_unmap (GTK_WIDGET (gtk_window)); } static const struct xdg_popup_listener xdg_popup_listener = { .configure = xdg_popup_handle_configure, .popup_done = xdg_popup_handle_popup_done, }; static void xdg_popup_surface_get_anchor_rect (XdgPopupSurface *self, GdkRectangle *rect) { // The anchor rect is given relative to the actual top-left of the parent GDK window surface // We need it realative to the logical geometry of the transient-for window, which may be sevel layers up *rect = self->position.rect; // It is a protocol error for size to be <= 0 rect->width = MAX (rect->width, 1); rect->height = MAX (rect->height, 1); GdkWindow *parent_window = self->position.transient_for_gdk_window; CustomShellSurface *transient_for_shell_surface = self->position.transient_for_shell_surface; GtkWidget *transient_for_widget = GTK_WIDGET (custom_shell_surface_get_gtk_window (transient_for_shell_surface)); GdkWindow *transient_for_window = gtk_widget_get_window (transient_for_widget); g_return_if_fail (parent_window); g_return_if_fail (transient_for_window); // Traverse up to the transient-for window adding each window's position relative to it's parent along the way while (parent_window && parent_window != transient_for_window) { gint x, y; gdk_window_get_position (parent_window, &x, &y); rect->x += x; rect->y += y; parent_window = gdk_window_get_effective_parent (parent_window); } if (parent_window != transient_for_window) { g_warning ("Could not find position of child window %p relative to parent window %p", (void *)self->position.transient_for_gdk_window, (void *)transient_for_window); } // Subtract the transient-for window's logical top-left GdkRectangle transient_for_geom = transient_for_shell_surface->virtual->get_logical_geom (transient_for_shell_surface); rect->x -= transient_for_geom.x; rect->y -= transient_for_geom.y; } static void xdg_popup_surface_map (CustomShellSurface *super, struct wl_surface *wl_surface) { XdgPopupSurface *self = (XdgPopupSurface *)super; g_return_if_fail (!self->xdg_popup); g_return_if_fail (!self->xdg_surface); GtkWindow *gtk_window = custom_shell_surface_get_gtk_window (super); GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (gtk_window)); g_return_if_fail (gdk_window); GdkRectangle rect; xdg_popup_surface_get_anchor_rect (self, &rect); struct xdg_wm_base *xdg_wm_base_global = gtk_wayland_get_xdg_wm_base_global (); g_return_if_fail (xdg_wm_base_global); struct xdg_positioner *positioner = xdg_wm_base_create_positioner (xdg_wm_base_global); self->geom = gtk_wayland_get_logical_geom (gtk_window); enum xdg_positioner_anchor anchor = gdk_gravity_get_xdg_positioner_anchor(self->position.rect_anchor); enum xdg_positioner_gravity gravity = gdk_gravity_get_xdg_positioner_gravity(self->position.window_anchor); enum xdg_positioner_constraint_adjustment constraint_adjustment = gdk_anchor_hints_get_xdg_positioner_constraint_adjustment (self->position.anchor_hints); xdg_positioner_set_size (positioner, self->geom.width, self->geom.height); xdg_positioner_set_anchor_rect (positioner, rect.x, rect.y, rect.width, rect.height); xdg_positioner_set_offset (positioner, self->position.rect_anchor_d.x, self->position.rect_anchor_d.y); xdg_positioner_set_anchor (positioner, anchor); xdg_positioner_set_gravity (positioner, gravity); xdg_positioner_set_constraint_adjustment (positioner, constraint_adjustment); self->xdg_surface = xdg_wm_base_get_xdg_surface (xdg_wm_base_global, wl_surface); g_return_if_fail (self->xdg_surface); xdg_surface_add_listener (self->xdg_surface, &xdg_surface_listener, self); CustomShellSurface *transient_for_shell_surface = self->position.transient_for_shell_surface; self->xdg_popup = transient_for_shell_surface->virtual->get_popup (transient_for_shell_surface, self->xdg_surface, positioner); g_return_if_fail (self->xdg_popup); xdg_popup_add_listener (self->xdg_popup, &xdg_popup_listener, self); xdg_positioner_destroy (positioner); xdg_surface_set_window_geometry (self->xdg_surface, self->geom.x, self->geom.y, self->geom.width, self->geom.height); wl_surface_commit (wl_surface); wl_display_roundtrip (gdk_wayland_display_get_wl_display (gdk_display_get_default ())); } static void xdg_popup_surface_unmap (CustomShellSurface *super) { XdgPopupSurface *self = (XdgPopupSurface *)super; if (self->xdg_popup) { xdg_popup_destroy (self->xdg_popup); self->xdg_popup = NULL; } if (self->xdg_surface) { xdg_surface_destroy (self->xdg_surface); self->xdg_surface = NULL; } } static void xdg_popup_surface_finalize (CustomShellSurface *super) { xdg_popup_surface_unmap (super); } static struct xdg_popup * xdg_popup_surface_get_popup (CustomShellSurface *super, struct xdg_surface *popup_xdg_surface, struct xdg_positioner *positioner) { XdgPopupSurface *self = (XdgPopupSurface *)super; if (!self->xdg_surface) { g_critical ("xdg_popup_surface_get_popup () called when the xdg surface wayland object has not yet been created"); return NULL; } return xdg_surface_get_popup (popup_xdg_surface, self->xdg_surface, positioner); } static GdkRectangle xdg_popup_surface_get_logical_geom (CustomShellSurface *super) { XdgPopupSurface *self = (XdgPopupSurface *)super; return self->geom; } static const CustomShellSurfaceVirtual xdg_popup_surface_virtual = { .map = xdg_popup_surface_map, .unmap = xdg_popup_surface_unmap, .finalize = xdg_popup_surface_finalize, .get_popup = xdg_popup_surface_get_popup, .get_logical_geom = xdg_popup_surface_get_logical_geom, }; static void xdg_popup_surface_on_size_allocate (GtkWidget *_widget, GdkRectangle *allocation, XdgPopupSurface *self) { (void)_widget; if (self->xdg_surface && !gdk_rectangle_equal (&self->cached_allocation, allocation)) { self->cached_allocation = *allocation; // allocation only used for catching duplicate calls. To get the correct geom we need to check something else GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); self->geom = gtk_wayland_get_logical_geom (gtk_window); xdg_surface_set_window_geometry (self->xdg_surface, self->geom.x, self->geom.y, self->geom.width, self->geom.height); } } XdgPopupSurface * xdg_popup_surface_new (GtkWindow *gtk_window, XdgPopupPosition const* position) { XdgPopupSurface *self = g_new0 (XdgPopupSurface, 1); g_assert (gtk_window); g_assert (position); self->super.virtual = &xdg_popup_surface_virtual; custom_shell_surface_init ((CustomShellSurface *)self, gtk_window); self->position = *position; self->cached_allocation = (GdkRectangle) { .x = 0, .y = 0, .width = 0, .height = 0, }; self->xdg_surface = NULL; self->xdg_popup = NULL; g_signal_connect (gtk_window, "size-allocate", G_CALLBACK (xdg_popup_surface_on_size_allocate), self); return self; } void xdg_popup_surface_update_position (XdgPopupSurface *self, XdgPopupPosition const* position) { self->position = *position; // Don't bother trying to remap. It's not needed and breaks shit } XdgPopupSurface * custom_shell_surface_get_xdg_popup (CustomShellSurface *shell_surface) { if (shell_surface && shell_surface->virtual == &xdg_popup_surface_virtual) return (XdgPopupSurface *)shell_surface; else return NULL; } gtk-layer-shell-0.1.0/src/xdg-popup-surface.h000066400000000000000000000016331353716601300210350ustar00rootroot00000000000000#ifndef XDG_POPUP_SURFACE_H #define XDG_POPUP_SURFACE_H #include "custom-shell-surface.h" // an XdgPopupSurface * can be safely cast to a CustomShellSurface * typedef struct _XdgPopupSurface XdgPopupSurface; typedef struct { CustomShellSurface *transient_for_shell_surface; GdkWindow *transient_for_gdk_window; GdkRectangle rect; GdkGravity rect_anchor, window_anchor; GdkAnchorHints anchor_hints; GdkPoint rect_anchor_d; } XdgPopupPosition; // Copies position, does not take ownership XdgPopupSurface *xdg_popup_surface_new (GtkWindow *gtk_window, XdgPopupPosition const* position); // Copies position, does not take ownership void xdg_popup_surface_update_position (XdgPopupSurface *self, XdgPopupPosition const* position); // Safe cast, returns NULL if wrong type sent XdgPopupSurface *custom_shell_surface_get_xdg_popup (CustomShellSurface *shell_surface); #endif // XDG_POPUP_SURFACE_H gtk-layer-shell-0.1.0/src/xdg-toplevel-surface.c000066400000000000000000000154111353716601300215160ustar00rootroot00000000000000#include "xdg-toplevel-surface.h" #include "custom-shell-surface.h" #include "gtk-wayland.h" #include "simple-conversions.h" #include "xdg-shell-client.h" #include #include #include struct _XdgToplevelSurface { CustomShellSurface super; GdkRectangle cached_allocation; GdkRectangle geom; // These can be NULL struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; }; static void xdg_surface_handle_configure (void *_data, struct xdg_surface *xdg_surface, uint32_t serial) { (void)_data; xdg_surface_ack_configure (xdg_surface, serial); } static const struct xdg_surface_listener xdg_surface_listener = { .configure = xdg_surface_handle_configure, }; static void xdg_toplevel_handle_configure (void *data, struct xdg_toplevel *_xdg_toplevel, int32_t width, int32_t height, struct wl_array *_states) { XdgToplevelSurface *self = data; (void)_xdg_toplevel; (void)_states; // Technically this should not be applied until we get a xdg_surface.configure if (width > 0 || height > 0) { GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); gtk_window_resize (gtk_window, width, height); } // Ignore the states } static void xdg_toplevel_handle_close (void *data, struct xdg_toplevel *_xdg_toplevel) { XdgToplevelSurface *self = data; (void)_xdg_toplevel; GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); gtk_window_close (gtk_window); } static const struct xdg_toplevel_listener xdg_toplevel_listener = { .configure = xdg_toplevel_handle_configure, .close = xdg_toplevel_handle_close, }; static void xdg_toplevel_surface_map (CustomShellSurface *super, struct wl_surface *wl_surface) { XdgToplevelSurface *self = (XdgToplevelSurface *)super; g_return_if_fail (!self->xdg_toplevel); g_return_if_fail (!self->xdg_surface); struct xdg_wm_base *xdg_wm_base_global = gtk_wayland_get_xdg_wm_base_global (); g_return_if_fail (xdg_wm_base_global); self->xdg_surface = xdg_wm_base_get_xdg_surface (xdg_wm_base_global, wl_surface); g_return_if_fail (self->xdg_surface); xdg_surface_add_listener (self->xdg_surface, &xdg_surface_listener, self); self->xdg_toplevel = xdg_surface_get_toplevel (self->xdg_surface); // name is either static or managed by the window widget const char *name = gtk_window_get_title (custom_shell_surface_get_gtk_window (super)); if (name == NULL) name = "gtk-layer-shell"; xdg_toplevel_set_title (self->xdg_toplevel, name); GtkWindow *gtk_window = custom_shell_surface_get_gtk_window (super); self->geom = gtk_wayland_get_logical_geom (gtk_window); xdg_surface_set_window_geometry (self->xdg_surface, self->geom.x, self->geom.y, self->geom.width, self->geom.height); xdg_toplevel_add_listener (self->xdg_toplevel, &xdg_toplevel_listener, self); wl_surface_commit (wl_surface); wl_display_roundtrip (gdk_wayland_display_get_wl_display (gdk_display_get_default ())); } static void xdg_toplevel_surface_unmap (CustomShellSurface *super) { XdgToplevelSurface *self = (XdgToplevelSurface *)super; if (self->xdg_toplevel) { xdg_toplevel_destroy (self->xdg_toplevel); self->xdg_toplevel = NULL; } if (self->xdg_surface) { xdg_surface_destroy (self->xdg_surface); self->xdg_surface = NULL; } } static void xdg_toplevel_surface_finalize (CustomShellSurface *super) { xdg_toplevel_surface_unmap (super); } static struct xdg_popup * xdg_toplevel_surface_get_popup (CustomShellSurface *super, struct xdg_surface *popup_xdg_surface, struct xdg_positioner *positioner) { XdgToplevelSurface *self = (XdgToplevelSurface *)super; if (!self->xdg_surface) { g_critical ("xdg_toplevel_surface_get_popup () called when the xdg surface wayland object has not yet been created"); return NULL; } return xdg_surface_get_popup (popup_xdg_surface, self->xdg_surface, positioner); } static GdkRectangle xdg_toplevel_surface_get_logical_geom (CustomShellSurface *super) { XdgToplevelSurface *self = (XdgToplevelSurface *)super; return self->geom; } static const CustomShellSurfaceVirtual xdg_toplevel_surface_virtual = { .map = xdg_toplevel_surface_map, .unmap = xdg_toplevel_surface_unmap, .finalize = xdg_toplevel_surface_finalize, .get_popup = xdg_toplevel_surface_get_popup, .get_logical_geom = xdg_toplevel_surface_get_logical_geom, }; static void xdg_toplevel_surface_on_size_allocate (GtkWidget *_widget, GdkRectangle *allocation, XdgToplevelSurface *self) { (void)_widget; if (self->xdg_surface && !gdk_rectangle_equal (&self->cached_allocation, allocation)) { self->cached_allocation = *allocation; // allocation only used for catching duplicate calls. To get the correct geom we need to check something else GtkWindow *gtk_window = custom_shell_surface_get_gtk_window ((CustomShellSurface *)self); self->geom = gtk_wayland_get_logical_geom (gtk_window); xdg_surface_set_window_geometry (self->xdg_surface, self->geom.x, self->geom.y, self->geom.width, self->geom.height); } } XdgToplevelSurface * xdg_toplevel_surface_new (GtkWindow *gtk_window) { g_return_val_if_fail (gtk_wayland_get_xdg_wm_base_global (), NULL); XdgToplevelSurface *self = g_new0 (XdgToplevelSurface, 1); self->super.virtual = &xdg_toplevel_surface_virtual; custom_shell_surface_init ((CustomShellSurface *)self, gtk_window); self->cached_allocation = (GdkRectangle) { .x = 0, .y = 0, .width = 0, .height = 0, }; self->xdg_surface = NULL; self->xdg_toplevel = NULL; gtk_window_set_decorated (gtk_window, FALSE); g_signal_connect (gtk_window, "size-allocate", G_CALLBACK (xdg_toplevel_surface_on_size_allocate), self); return self; } XdgToplevelSurface * custom_shell_surface_get_xdg_toplevel (CustomShellSurface *shell_surface) { if (shell_surface && shell_surface->virtual == &xdg_toplevel_surface_virtual) return (XdgToplevelSurface *)shell_surface; else return NULL; } gtk-layer-shell-0.1.0/src/xdg-toplevel-surface.h000066400000000000000000000007301353716601300215210ustar00rootroot00000000000000#ifndef XDG_TOPLEVEL_SURFACE_H #define XDG_TOPLEVEL_SURFACE_H #include "custom-shell-surface.h" // an XdgToplevelSurface * can be safely cast to a CustomShellSurface * typedef struct _XdgToplevelSurface XdgToplevelSurface; XdgToplevelSurface *xdg_toplevel_surface_new (GtkWindow *gtk_window); // Safe cast, returns NULL if wrong type sent XdgToplevelSurface *custom_shell_surface_get_xdg_toplevel (CustomShellSurface *shell_surface); #endif // XDG_TOPLEVEL_SURFACE_H