pax_global_header00006660000000000000000000000064147123064170014517gustar00rootroot0000000000000052 comment=536ff516ed68b9bb34afc4c07f942a54b2b4b03f gtk4-layer-shell-1.0.4/000077500000000000000000000000001471230641700146115ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/.editorconfig000066400000000000000000000001631471230641700172660ustar00rootroot00000000000000root = true [*] end_of_line = lf insert_final_newline = true charset = utf-8 indent_style = space indent_size = 4 gtk4-layer-shell-1.0.4/.github/000077500000000000000000000000001471230641700161515ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/.github/workflows/000077500000000000000000000000001471230641700202065ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/.github/workflows/build_and_test.yml000066400000000000000000000012641471230641700237140ustar00rootroot00000000000000name: 'Build library and run tests' on: push: branches: [ main ] pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Apt update run: sudo apt update - name: Install depends run: sudo apt install meson libwayland-dev libgtk-4-dev gobject-introspection libgirepository1.0-dev valac luajit luarocks gtk-doc-tools - name: Meson run: meson setup -Dexamples=true -Ddocs=true -Dtests=true build env: CFLAGS: -Werror - name: Build run: ninja -C build - name: Test run: ninja -C build test - name: Install run: sudo ninja -C build install gtk4-layer-shell-1.0.4/.github/workflows/deploy_docs.yml000066400000000000000000000032331471230641700232360ustar00rootroot00000000000000name: 'Deploy docs' on: # Runs on pushes targeting the default branch push: branches: ["main"] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" cancel-in-progress: false jobs: # Build job build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Setup Pages uses: actions/configure-pages@v3 - name: Apt update run: sudo apt update - name: Install depends run: sudo apt install meson libwayland-dev libgtk-4-dev gobject-introspection libgirepository1.0-dev valac gtk-doc-tools - name: Meson run: meson setup -Dexamples=false -Ddocs=true -Dtests=false --prefix $HOME build - name: Build Install run: ninja -C build install - name: Move files into place run: | mv $HOME/share/gtk-doc/html/gtk4-layer-shell ./_site cp ./_site/gtk4-layer-shell-GTK4-Layer-Shell.html ./_site/index.html - name: Upload artifact uses: actions/upload-pages-artifact@v1 # Deployment job deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v2 gtk4-layer-shell-1.0.4/.gitignore000066400000000000000000000000701471230641700165760ustar00rootroot00000000000000build/ gtk-priv/build/ */__pycache__ *.pyc .mypy_cache/ gtk4-layer-shell-1.0.4/CHANGELOG.md000066400000000000000000000035601471230641700164260ustar00rootroot00000000000000# Changelog ## [Unreleased] ## [1.0.4] - 4 Nov 2024 - Fix protocol error on Wayfire, due to sending zwlr_layer_shell_surface_v1->configure too early - Fix crash when hovering over a tooltip on Hyprland, due to using an old copy of xdg-shell.xml - Fix protocol error on GTK4 >=4.16 on KDE and Hyprland, due to request arguments including references to client-only objects - Add xdg-dialog-v1 to the mock server used by the tests, so the invalid argument bug is regression tested - Drop Lua example and smoke test (the library should work with Lua just as well as before, but this is no longer tested or officially supported) - Fix and suppress various warnings ## [1.0.3] - 10 Sep 2024 - Tests: make tests compatible with new libwayland format - Tests: fix `integration-test-menu-popup` by sending wl_buffer.release in mock server - Fix: dlopen `libwayland-client.so.0` in addition to `libwayland-client.so`, fixes [#39](https://github.com/wmww/gtk4-layer-shell/issues/39) ## [1.0.2] - 7 Nov 2023 - Fix tests on Arch - Realize and unrealize on remap instead of setting visibility - Fix major use-after-free bug causing many crashes ## [1.0.1] - 1 Jul 2023 - Add lua example - Add links to Rust and Ruby bindings - Fix doc name conflicts with GTK3 library version - Add smoke tests ## [1.0.0] - 11 Apr 2023 - Port library and examples from GTK3 to GTK4 - Remove deprecated functions `gtk_layer_set_keyboard_interactivity()` and `gtk_layer_get_keyboard_interactivity()` (`gtk_layer_set_keyboard_mode()` and `gtk_layer_get_keyboard_mode()` can be used instead) - Change how layer surface window size is controlled, use `gtk_window_set_default_size()` now - Build [documentation](https://wmww.github.io/gtk4-layer-shell/) with GitHub actions and host with GitHub Pages - __EDIT:__ Change license from LGPL to MIT (most of the gtk-layer-shell code was always MIT, and the LGPL bits have all been dropped) gtk4-layer-shell-1.0.4/LICENSE000066400000000000000000000020701471230641700156150ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2023 Sophie Winter 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. gtk4-layer-shell-1.0.4/README.md000066400000000000000000000125711471230641700160760ustar00rootroot00000000000000# GTK4 Layer Shell ![GTK4 Layer Demo screenshot](https://i.imgur.com/dR8X15i.png) A library for using the [Layer Shell](https://gitlab.freedesktop.org/wlroots/wlr-protocols/-/blob/master/unstable/wlr-layer-shell-unstable-v1.xml) Wayland protocol with [GTK4](https://www.gtk.org/). With this library you can build 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 is compatible with C, C++ and any language that supports GObject introspection files (Python, Vala, etc). [Documentation](https://wmww.github.io/gtk4-layer-shell/) [GTK3 version](https://github.com/wmww/gtk-layer-shell) ## Reporting Bugs To report a crash or other problem using this library open a new [issue on Github](https://github.com/wmww/gtk4-layer-shell/issues). Try to include a minimum reproducer if possible (ideally in C). **DO NOT REPORT GTK4 LAYER SHELL BUGS TO UPSTREAM GTK**. If you can reproduce the problem without including or linking to the gtk4-layer-shell library **at all** then and only then report it to GTK instead of here. ## Supported Desktops This library only works on Wayland, and only on Wayland compositors that support the Layer Shell protocol. Layer shell __is supported__ on: - wlroots based compositors (such as __Sway__) - Smithay based compositors (such as __COSMIC__) - __Mir__ based compositors (some may not enable the protocol by default. It can be enabled with `--add-wayland-extension zwlr_layer_shell_v1`) - __KDE Plasma__ on wayland Layer shell __is not supported__ on: - Gnome-on-Wayland - Any X11 desktop ## Using the Library ### Demo `gtk4-layer-demo` is built if examples are enabled. It's useful for testing layer shell support in compositors. Its code can be found in [examples/demo/](examples/demo/). ### C/C++ The easiest way to build against GTK Layer Shell is to use the `gtk-layer-shell-0` pkg-config package. Refer to your build system or the pkg-config docs for further instructions. [examples/simple-example.c](examples/simple-example.c) is a minimal complete app written in C. __If you link against libwayland, you must link libwayland after gtk4-layer-shell__. See [linking.md](linking.md) for details. ### Python [examples/simple-example.py](examples/simple-example.py) contains sample Python code. ### Vala [examples/simple-example.vala](examples/simple-example.vala) contains a minimal working Vala app. ### Rust [@pentamassiv](https://github.com/pentamassiv) maintains [safe Rust bindings](https://github.com/pentamassiv/gtk4-layer-shell-gir) and the [crates.io crate](https://crates.io/crates/gtk4-layer-shell/). Rust examples can be found [here](https://github.com/pentamassiv/gtk4-layer-shell-gir/tree/main/gtk4-layer-shell/examples). ### Ruby [mswiger](https://github.com/mswiger) maintains [Ruby bindings](https://github.com/mswiger/ruby-gtk4-layer-shell) which are published to [RubyGems](https://rubygems.org/gems/gtk4_layer_shell). ## Distro Packages [![List of distros GTK Layer Shell is packaged for](https://repology.org/badge/vertical-allrepos/gtk4-layer-shell.svg)](https://repology.org/project/gtk4-layer-shell/versions) ## Building From Source 1. Clone this repo 2. Install build dependencies (see below) 3. `$ meson setup -Dexamples=true -Ddocs=true -Dtests=true build` (NOTE: `--prefix=/usr` may be needed on Arch Linux) 4. `$ ninja -C build` 5. `$ sudo ninja -C build install` 6. `$ sudo ldconfig` ### Build Dependencies * [Meson](https://mesonbuild.com/) (>=0.45.1) * [Ninja](https://ninja-build.org/) (>=1.8.2) * [libwayland](https://gitlab.freedesktop.org/wayland/wayland) (>=1.10.0) * [wayland-protocols](https://gitlab.freedesktop.org/wayland/wayland-protocols) (>=1.16.0) * [GTK4](https://www.gtk.org/) * __If `introspection` enabled:__ [GObject introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/) * __If `docs` enabled:__ [GTK Doc](https://wiki.gnome.org/DocumentationProject/GtkDoc) * __If `tests` enabled:__ [Python3](https://www.python.org/) * __If `vapi` enabled:__ [Vala](https://wiki.gnome.org/Projects/Vala) To install these dependencies on Ubuntu 18.04 and later: ``` sudo apt install meson ninja-build libwayland-dev libgtk-4-dev gobject-introspection libgirepository1.0-dev gtk-doc-tools python3 valac ``` To install on Arch Linux: ``` pacman -S --needed meson ninja gtk4 wayland gobject-introspection libgirepository gtk-doc python vala ``` ### Meson Options * `-Dexamples` (default `false`): If to build the example C apps; gtk4-layer-demo is installed if examples are built; The Vala example is never built with the rest of the project * `-Ddocs` (default `false`): If to generate the docs * `-Dtests` (default `false`): If to build the tests * `-Dsmoke-tests` (default: `true`): If to test that all examples can run (disable if you don't want to install the various languages and dependencies required) * `-Dintrospection` (default: `true`): If to build GObject Introspection data (used for bindings to languages other than C/C++) * `-Dvapi` (default: `true`): If to build VAPI data and Vala example. The VAPI file allows this library to be used in Vala. Requires `-Dintrospection=true` ### Running the Tests * `ninja -C build test` * Or, to run a specific test and print the complete output `meson test --verbose -C build` ## Licensing 100% MIT (unlike the GTK3 version of this library which contained GPL code copied from GTK) gtk4-layer-shell-1.0.4/doc/000077500000000000000000000000001471230641700153565ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/doc/gtk4-layer-shell-docs.sgml000066400000000000000000000072471471230641700222720ustar00rootroot00000000000000 %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 Sophie Winter 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 gtk4-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 gtk4-layer-shell-1.0.4/doc/meson.build000066400000000000000000000015651471230641700175270ustar00rootroot00000000000000subdir('xml') glib_prefix = dependency('glib-2.0').get_variable(pkgconfig: 'prefix') glib_docpath = join_paths(glib_prefix, 'share', 'gtk-doc', 'html') docpath = join_paths(get_option('datadir'), 'gtk-doc', 'html') gnome.gtkdoc( 'gtk4-layer-shell', main_xml: 'gtk4-layer-shell-docs.sgml', src_dir: [ join_paths(meson.source_root(), 'include'), join_paths(meson.build_root(), 'include'), ], dependencies: [ gtk, wayland_client, wayland_scanner, ], 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: 'gtk4-layer-shell', install: true ) gtk4-layer-shell-1.0.4/doc/xml/000077500000000000000000000000001471230641700161565ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/doc/xml/gtkdocentities.ent.in000066400000000000000000000005341471230641700223150ustar00rootroot00000000000000 gtk4-layer-shell-1.0.4/doc/xml/meson.build000066400000000000000000000011711471230641700203200ustar00rootroot00000000000000ent_conf = configuration_data() ent_conf.set('PACKAGE', 'gtk4-layer-shell') ent_conf.set('PACKAGE_BUGREPORT', 'https://github.com/wmww/gtk4-layer-shell/issues') ent_conf.set('PACKAGE_NAME', 'gtk4-layer-shell') ent_conf.set('PACKAGE_STRING', 'gtk4-layer-shell') ent_conf.set('PACKAGE_TARNAME', 'gtk4-layer-shell-' + meson.project_version()) ent_conf.set('PACKAGE_URL', 'https://github.com/wmww/gtk4-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) gtk4-layer-shell-1.0.4/examples/000077500000000000000000000000001471230641700164275ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/examples/demo/000077500000000000000000000000001471230641700173535ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/examples/demo/anchor-control.c000066400000000000000000000070161471230641700224530ustar00rootroot00000000000000#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_icon_name (GTK_BUTTON (button), icon_name); 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); gtk_widget_set_vexpand (outside_vbox, TRUE); GtkWidget *outside_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_append (GTK_BOX (outside_vbox), outside_hbox); { GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_append (GTK_BOX (outside_hbox), hbox); { GtkWidget *vbox = gtk_center_box_new (); gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox), GTK_ORIENTATION_VERTICAL); gtk_box_append (GTK_BOX (hbox), vbox); { GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_LEFT, default_anchors, "go-previous", "Anchor left"); gtk_center_box_set_center_widget (GTK_CENTER_BOX (vbox), button); } }{ GtkWidget *center_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 40); gtk_box_append (GTK_BOX (hbox), center_vbox); { GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_TOP, default_anchors, "go-up", "Anchor top"); gtk_box_append (GTK_BOX (center_vbox), button); }{ GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_BOTTOM, default_anchors, "go-down", "Anchor bottom"); gtk_box_append (GTK_BOX (center_vbox), button); } }{ GtkWidget *vbox = gtk_center_box_new (); gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox), GTK_ORIENTATION_VERTICAL); gtk_box_append (GTK_BOX (hbox), vbox); { GtkWidget *button = anchor_edge_button_new (layer_window, GTK_LAYER_SHELL_EDGE_RIGHT, default_anchors, "go-next", "Anchor right"); gtk_center_box_set_center_widget (GTK_CENTER_BOX (vbox), button); } } } return outside_vbox; } gtk4-layer-shell-1.0.4/examples/demo/gtk-layer-demo.c000066400000000000000000000406421471230641700223460ustar00rootroot00000000000000#include "gtk-layer-demo.h" #include 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 GtkLayerShellKeyboardMode default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_NONE; // always set by command line option static gboolean default_fixed_size = FALSE; // always set by command line option static gboolean no_layer_shell = FALSE; // always set by command line option static gboolean show_version_and_exit = FALSE; // always set by command line option const char *prog_name = "gtk4-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"; const int fixed_size_width = 600; const int fixed_size_height = 500; 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 keyboard_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 = "version", .short_name = 'v', .flags = G_OPTION_FLAG_NONE, .arg = G_OPTION_ARG_NONE, .arg_data = &show_version_and_exit, .description = "Show version and exit", .arg_description = NULL, }, { .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_OPTIONAL_ARG, .arg = G_OPTION_ARG_CALLBACK, .arg_data = (void*)&keyboard_option_callback, .description = "Set keyboard interactivity: 'none', 'exclusive' or 'on-demand' (or 'n', 'e' or 'o')", .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, }, { .long_name = "no-layer-shell", .short_name = 0, .flags = G_OPTION_FLAG_NONE, .arg = G_OPTION_ARG_NONE, .arg_data = &no_layer_shell, .description = "Disable gtk4-layer-shell, create a normal shell surface instead", .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' " "(valid layers are 'overlay', 'top', 'bottom', 'background', 'o', 't', 'b' and 'g')", 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' (valid edges are 'l', 'r', 't' and 'b')", *c); return FALSE; } } return TRUE; } gboolean keyboard_option_callback (const gchar *_option_name, const gchar *value, void *_data, GError **error) { (void)_option_name; (void)_data; if (!value) { // without argument = exclusive (retain old behavior) default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE; return TRUE; } if (g_strcmp0 (value, "none") == 0 || g_strcmp0 (value, "n") == 0) { default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_NONE; } else if (g_strcmp0 (value, "exclusive") == 0 || g_strcmp0 (value, "e") == 0) { default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE; } else if (g_strcmp0 (value, "on-demand") == 0 || g_strcmp0 (value, "o") == 0) { default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND; } else { g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Invalid keyboard interactivity '%s' " "(valid values are 'none', 'exclusive', 'on-demand', 'n', 'e' and 'o')", value); 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 enough 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); } if (show_version_and_exit) { g_print ( "%s on gtk4-layer-shell v%d.%d.%d\n", prog_name, gtk_layer_get_major_version (), gtk_layer_get_minor_version (), gtk_layer_get_micro_version ()); exit(0); } 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) { (void)window; 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, GApplication *_data) { (void)_data; g_application_quit (G_APPLICATION (gtk_window_get_application (window))); } static void activate (GtkApplication* app, void *_data) { (void)_data; GtkWindow *gtk_window = GTK_WINDOW (gtk_application_window_new (app)); ToplevelData *data = g_new0 (ToplevelData, 1); 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++) data->edges[i] = default_anchors[i]; if (default_fixed_size) gtk_window_set_default_size (gtk_window, fixed_size_width, fixed_size_height); if (no_layer_shell) { g_message ("GTK layer shell disabled on command line"); g_message ("Expect controls to have no effect and warnings to be shown"); } else { gtk_layer_init_for_window (gtk_window); } for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) gtk_layer_set_anchor (gtk_window, i, default_anchors[i]); 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_keyboard_mode (gtk_window, default_keyboard_mode); gtk_layer_set_namespace (gtk_window, "demo"); if (default_auto_exclusive_zone) gtk_layer_auto_exclusive_zone_enable (gtk_window); set_up_menubar (gtk_window); GtkWidget *centered_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_margin_bottom (centered_vbox, 10); gtk_widget_set_margin_top (centered_vbox, 10); gtk_widget_set_margin_start (centered_vbox, 10); gtk_widget_set_margin_end (centered_vbox, 10); gtk_window_set_child (gtk_window, centered_vbox); GtkWidget *centered_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_append (GTK_BOX (centered_vbox), centered_hbox); data->toplevel_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); //gtk_container_set_border_width (GTK_CONTAINER (data->toplevel_box), 16); gtk_box_append (GTK_BOX (centered_hbox), data->toplevel_box); { data->first_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_widget_set_vexpand (data->first_box, TRUE); gtk_box_append (GTK_BOX (data->toplevel_box), data->first_box); { GtkWidget *selections_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_widget_set_vexpand (selections_box, TRUE); gtk_box_append (GTK_BOX (data->first_box), selections_box); gtk_box_append (GTK_BOX (selections_box), monitor_selection_new (gtk_window)); gtk_box_append (GTK_BOX (selections_box), layer_selection_new (gtk_window, default_layer)); }{ gtk_box_append (GTK_BOX (data->first_box), anchor_control_new (gtk_window, default_anchors)); } }{ data->second_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_box_append (GTK_BOX (data->toplevel_box), data->second_box); { GtkWidget *toggles_box = mscl_toggles_new (gtk_window, default_auto_exclusive_zone, default_fixed_size); gtk_box_append (GTK_BOX (data->second_box), toggles_box); GtkWidget *kb_box = keyboard_selection_new (gtk_window, default_keyboard_mode); gtk_box_append (GTK_BOX (data->second_box), kb_box); } { GtkWidget *margin_and_version_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_box_append (GTK_BOX (margin_and_version_box), margin_control_new (gtk_window, default_margins)); gtk_box_append (GTK_BOX (margin_and_version_box), version_info_new ()); gtk_box_append (GTK_BOX (data->second_box), margin_and_version_box); } } 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); g_signal_connect (gtk_window, "destroy", G_CALLBACK (on_window_destroy), NULL); gtk_window_present (gtk_window); } int main (int argc, char **argv) { g_set_prgname (prog_name); 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); GtkApplication * app = gtk_application_new ("com.github.wmww.gtk4-layer-shell.demo", G_APPLICATION_DEFAULT_FLAGS); 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; } gtk4-layer-shell-1.0.4/examples/demo/gtk-layer-demo.h000066400000000000000000000025621471230641700223520ustar00rootroot00000000000000#ifndef GTK_LAYER_DEMO_H #define GTK_LAYER_DEMO_H #include "gtk4-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; extern const int fixed_size_width; extern const int fixed_size_height; 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 * version_info_new (); GtkWidget * mscl_toggles_new (GtkWindow *layer_window, gboolean default_auto_exclusive_zone, gboolean default_fixed_size); void set_up_menubar (GtkWindow *layer_window); GtkWidget * keyboard_selection_new (GtkWindow *layer_window, GtkLayerShellKeyboardMode default_kb); #endif // GTK_LAYER_DEMO_H gtk4-layer-shell-1.0.4/examples/demo/keyboard-selection.c000066400000000000000000000025221471230641700233030ustar00rootroot00000000000000#include "gtk-layer-demo.h" const char *keyboard_strs[] = {"None", "Exclusive", "On demand", NULL}; GtkLayerShellKeyboardMode keyboard_vals[] = { GTK_LAYER_SHELL_KEYBOARD_MODE_NONE, GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE, GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND}; static void on_kb_selected (GtkDropDown *dropdown, const GParamSpec *_pspec, GtkWindow *layer_window) { (void)_pspec; guint index = gtk_drop_down_get_selected (dropdown); gtk_layer_set_keyboard_mode (layer_window, keyboard_vals[index]); } GtkWidget * keyboard_selection_new (GtkWindow *layer_window, GtkLayerShellKeyboardMode default_kb) { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); { GtkWidget *label = gtk_label_new ("Keyboard:"); GtkWidget *dropdown = gtk_drop_down_new_from_strings(keyboard_strs); gtk_widget_set_tooltip_text (dropdown, "Keyboard interactivity mode"); for (unsigned i = 0; i < sizeof(keyboard_vals) / sizeof(keyboard_vals[0]); i++) { if (keyboard_vals[i] == default_kb) gtk_drop_down_set_selected (GTK_DROP_DOWN (dropdown), i); } g_signal_connect (dropdown, "notify::selected", G_CALLBACK (on_kb_selected), layer_window); gtk_box_append (GTK_BOX (vbox), label); gtk_box_append (GTK_BOX (vbox), dropdown); } return vbox; } gtk4-layer-shell-1.0.4/examples/demo/layer-selection.c000066400000000000000000000023001471230641700226110ustar00rootroot00000000000000#include "gtk-layer-demo.h" const char *layer_strs[] = {"Overlay", "Top", "Bottom", "Background", NULL}; GtkLayerShellLayer layer_vals[] = { GTK_LAYER_SHELL_LAYER_OVERLAY, GTK_LAYER_SHELL_LAYER_TOP, GTK_LAYER_SHELL_LAYER_BOTTOM, GTK_LAYER_SHELL_LAYER_BACKGROUND}; static void on_layer_selected(GtkDropDown *dropdown, const GParamSpec *_pspec, GtkWindow *layer_window) { (void)_pspec; guint index = gtk_drop_down_get_selected (dropdown); gtk_layer_set_layer (layer_window, layer_vals[index]); } GtkWidget * layer_selection_new (GtkWindow *layer_window, GtkLayerShellLayer default_layer) { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); { GtkWidget *dropdown = gtk_drop_down_new_from_strings(layer_strs); gtk_widget_set_tooltip_text (dropdown, "Layer"); for (unsigned i = 0; i < sizeof(layer_vals) / sizeof(layer_vals[0]); i++) { if (layer_vals[i] == default_layer) gtk_drop_down_set_selected (GTK_DROP_DOWN (dropdown), i); } g_signal_connect (dropdown, "notify::selected", G_CALLBACK (on_layer_selected), layer_window); gtk_box_append (GTK_BOX (vbox), dropdown); } return vbox; } gtk4-layer-shell-1.0.4/examples/demo/margin-control.c000066400000000000000000000071241471230641700224560ustar00rootroot00000000000000#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; } 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_append (GTK_BOX (switch_box), vbox); { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_LEFT, "Left margin", default_margins); gtk_box_append (GTK_BOX (vbox), button); } { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_RIGHT, "Right margin", default_margins); gtk_box_append (GTK_BOX (vbox), button); } } { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, spacing); gtk_box_append (GTK_BOX (switch_box), vbox); { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_TOP, "Top margin", default_margins); gtk_box_append (GTK_BOX (vbox), button); } { GtkWidget *button = margin_spin_button_new (layer_window, GTK_LAYER_SHELL_EDGE_BOTTOM, "Bottom margin", default_margins); gtk_box_append (GTK_BOX (vbox), button); } } GtkWidget *popover = gtk_popover_new (); gtk_popover_set_child (GTK_POPOVER (popover), switch_box); GtkWidget *open_button = gtk_menu_button_new (); gtk_menu_button_set_label (GTK_MENU_BUTTON (open_button), "Set margin"); gtk_menu_button_set_popover (GTK_MENU_BUTTON (open_button), popover); gtk_widget_set_tooltip_text (open_button, "Space to leave empty around surface"); return open_button; } gtk4-layer-shell-1.0.4/examples/demo/menu-bar.c000066400000000000000000000022461471230641700212310ustar00rootroot00000000000000#include "gtk-layer-demo.h" static void quit_activated(GSimpleAction *action, GVariant *parameter, GApplication *application) { (void)action; (void)parameter; g_application_quit (application); } void set_up_menubar (GtkWindow *layer_window) { GSimpleAction *act_quit = g_simple_action_new ("quit", NULL); g_action_map_add_action (G_ACTION_MAP (gtk_window_get_application (layer_window)), G_ACTION (act_quit)); g_signal_connect (act_quit, "activate", G_CALLBACK (quit_activated), gtk_window_get_application (layer_window)); GMenu *menubar = g_menu_new (); gtk_application_set_menubar (GTK_APPLICATION (gtk_window_get_application (layer_window)), G_MENU_MODEL (menubar)); gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (layer_window), TRUE); GMenuItem *menu_item = g_menu_item_new ("GTK4 Layer Demo", NULL); GMenu *menu = g_menu_new (); GMenuItem *menu_item_quit = g_menu_item_new ("Quit", "app.quit"); g_menu_append_item (menu, menu_item_quit); g_menu_item_set_submenu (menu_item, G_MENU_MODEL (menu)); g_menu_append_item (menubar, menu_item); g_object_unref (menu_item_quit); g_object_unref (menu_item); } gtk4-layer-shell-1.0.4/examples/demo/meson.build000066400000000000000000000003511471230641700215140ustar00rootroot00000000000000demo_srcs = files( 'gtk-layer-demo.c', 'anchor-control.c', 'margin-control.c', 'layer-selection.c', 'monitor-selection.c', 'mscl-toggles.c', 'version-info.c', 'menu-bar.c', 'keyboard-selection.c') gtk4-layer-shell-1.0.4/examples/demo/monitor-selection.c000066400000000000000000000031451471230641700231740ustar00rootroot00000000000000#include "gtk-layer-demo.h" const char *current_monitor_key = "current_layer_monitor"; #include "gtk-layer-demo.h" #define MAX_MONIITORS 100 const char *monitor_strs[MAX_MONIITORS] = {"Default", NULL}; GdkMonitor *monitor_vals[MAX_MONIITORS] = {NULL}; static void on_monitor_selected (GtkDropDown *dropdown, const GParamSpec *_pspec, GtkWindow *layer_window) { (void)_pspec; guint index = gtk_drop_down_get_selected (dropdown); gtk_layer_set_monitor (layer_window, monitor_vals[index]); } GtkWidget * monitor_selection_new (GtkWindow *layer_window) { GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); { GListModel *monitors = gdk_display_get_monitors (gdk_display_get_default ()); // owned by display for (unsigned i = 0; i < g_list_model_get_n_items (monitors) && i < MAX_MONIITORS - 2; i++) { GdkMonitor *monitor = g_list_model_get_item (monitors, i); GString *text = g_string_new (""); g_string_printf (text, "%d. %s", i + 1, gdk_monitor_get_model (monitor)); monitor_strs[i + 1] = g_strdup (text->str); g_string_free (text, TRUE); monitor_vals[i + 1] = g_object_ref (monitor); monitor_strs[i + 2] = NULL; } GtkWidget *dropdown = gtk_drop_down_new_from_strings(monitor_strs); gtk_widget_set_tooltip_text (dropdown, "Monitor"); gtk_drop_down_set_selected (GTK_DROP_DOWN (dropdown), 0); g_signal_connect (dropdown, "notify::selected", G_CALLBACK (on_monitor_selected), layer_window); gtk_box_append (GTK_BOX (vbox), dropdown); } return vbox; } gtk4-layer-shell-1.0.4/examples/demo/mscl-toggles.c000066400000000000000000000045601471230641700221240ustar00rootroot00000000000000#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_fixed_size_set (GtkToggleButton *_toggle_button, gboolean state, GtkWindow *layer_window) { (void)_toggle_button; if (state) { gtk_window_set_default_size (layer_window, fixed_size_width, fixed_size_height); } else { gtk_window_set_default_size (layer_window, 0, 0); } 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}, {"Fixed size", "Set a fixed window size (ignored depending on anchors)", on_fixed_size_set}, }; GtkWidget * mscl_toggles_new (GtkWindow *layer_window, gboolean default_auto_exclusive_zone, 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_widget_set_halign (hbox, GTK_ALIGN_END); gtk_box_append (GTK_BOX (vbox), hbox); { GtkWidget *label = gtk_label_new (mscl_toggles[i].name); gtk_box_append (GTK_BOX (hbox), label); }{ 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_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_append (GTK_BOX (hbox), toggle); } } return vbox; } gtk4-layer-shell-1.0.4/examples/demo/version-info.c000066400000000000000000000015311471230641700221350ustar00rootroot00000000000000#include "gtk-layer-demo.h" GtkWidget * version_info_new () { gchar *version_str = g_strdup_printf("GTK4 LS v%d.%d.%d\nGTK v%d.%d.%d", gtk_layer_get_major_version (), gtk_layer_get_minor_version (), gtk_layer_get_micro_version (), gtk_get_major_version (), gtk_get_minor_version (), gtk_get_micro_version ()); GtkWidget *version_info = gtk_label_new(version_str); g_free(version_str); gtk_label_set_justify(GTK_LABEL(version_info), GTK_JUSTIFY_CENTER); gtk_label_set_xalign(GTK_LABEL(version_info), 0.5); gtk_label_set_yalign(GTK_LABEL(version_info), 0.25); return version_info; } gtk4-layer-shell-1.0.4/examples/meson.build000066400000000000000000000014101471230641700205650ustar00rootroot00000000000000subdir('demo') executable( 'gtk4-layer-demo', demo_srcs, build_by_default: get_option('examples'), dependencies: [gtk, gtk_layer_shell], install: get_option('examples')) executable( 'simple-example-c', files('simple-example.c'), build_by_default: get_option('examples'), dependencies: [gtk, gtk_layer_shell], install: false) if get_option('vapi') add_languages('vala') executable( 'simple-example-vala', files('simple-example.vala'), dependencies: [gtk, gtk_layer_shell, vapi], c_args: [ '-Wno-unused-but-set-variable', '-Wno-unused-parameter', '-Wno-cast-function-type', '-Wno-deprecated-declarations', ], install: false) endif gtk4-layer-shell-1.0.4/examples/simple-example.c000066400000000000000000000040761471230641700215240ustar00rootroot00000000000000#include "gtk4-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_TOP); // Push other windows out of the way gtk_layer_auto_exclusive_zone_enable (gtk_window); // We don't need to get keyboard input // gtk_layer_set_keyboard_mode (gtk_window, GTK_LAYER_SHELL_KEYBOARD_MODE_NONE); // NONE 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, FALSE, 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\nShell example!" ""); gtk_window_set_child (gtk_window, label); gtk_window_present (gtk_window); } int main (int argc, char **argv) { GtkApplication * app = gtk_application_new ("com.github.wmww.gtk4-layer-shell.example", G_APPLICATION_DEFAULT_FLAGS); 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; } gtk4-layer-shell-1.0.4/examples/simple-example.py000066400000000000000000000024111471230641700217210ustar00rootroot00000000000000# To run this script without installing the library, set GI_TYPELIB_PATH and LD_LIBRARY_PATH to the build/src directory # GI_TYPELIB_PATH=build/src LD_LIBRARY_PATH=build/src python3 examples/simple-example.py # For GTK4 Layer Shell to get linked before libwayland-client we must explicitly load it before importing with gi from ctypes import CDLL CDLL('libgtk4-layer-shell.so') import gi gi.require_version("Gtk", "4.0") gi.require_version('Gtk4LayerShell', '1.0') from gi.repository import Gtk from gi.repository import Gtk4LayerShell as LayerShell def on_activate(app): window = Gtk.Window(application=app) window.set_default_size(400, 70) LayerShell.init_for_window(window) LayerShell.set_layer(window, LayerShell.Layer.TOP) LayerShell.set_anchor(window, LayerShell.Edge.BOTTOM, True) LayerShell.set_margin(window, LayerShell.Edge.BOTTOM, 20) LayerShell.set_margin(window, LayerShell.Edge.TOP, 20) LayerShell.auto_exclusive_zone_enable(window) button = Gtk.Button(label="GTK4 Layer Shell with Python") button.connect('clicked', lambda x: window.close()) window.set_child(button) window.present() app = Gtk.Application(application_id='com.github.wmww.gtk4-layer-shell.py-example') app.connect('activate', on_activate) app.run(None) gtk4-layer-shell-1.0.4/examples/simple-example.vala000066400000000000000000000015261471230641700222220ustar00rootroot00000000000000using Gtk; using GtkLayerShell; int main(string[] argv) { var app = new Gtk.Application ( "com.github.wmww.gtk4-layer-shell.vala-example", GLib.ApplicationFlags.FLAGS_NONE); app.activate.connect (() => { var window = new Gtk.ApplicationWindow (app); GtkLayerShell.init_for_window(window); GtkLayerShell.auto_exclusive_zone_enable(window); GtkLayerShell.set_margin(window, GtkLayerShell.Edge.TOP, 10); GtkLayerShell.set_margin(window, GtkLayerShell.Edge.BOTTOM, 10); GtkLayerShell.set_anchor(window, GtkLayerShell.Edge.BOTTOM, true); var button = new Gtk.Button.with_label ("Hello, World!"); button.clicked.connect (() => { window.close (); }); window.set_child (button); window.present (); }); return app.run (argv); } gtk4-layer-shell-1.0.4/include/000077500000000000000000000000001471230641700162345ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/include/gtk4-layer-shell.h000066400000000000000000000257471471230641700215140ustar00rootroot00000000000000#ifndef GTK_LAYER_SHELL_H #define GTK_LAYER_SHELL_H #include /** * SECTION:gtk4-layer-shell * @title: GTK4 Layer Shell * @short_description: A library to use the Layer Shell Wayland protocol with GTK4 * * # Linking against this library and libwayland * If you link against libwayland you must link this library before libwayland. See * [linking.md](https://github.com/wmww/gtk4-layer-shell/blob/main/linking.md) for details. * * # Setting Window Size * If you wish to force your layer surface window to be a different size than it * is by default: * |[ * gtk_window_set_default_size (layer_gtk_window, width, height); * ]| * If width or height is 0, 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 requested here is ignored. If you later wish to use the default window size * repeat the call with both width and height as 0. */ 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. (NOTE: may change in * future releases as more entries are added) */ 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, // Should not be used except to get the number of entries } 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. (NOTE: may change in * future releases as more entries are added) */ 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; /** * GtkLayerShellKeyboardMode: * @GTK_LAYER_SHELL_KEYBOARD_MODE_NONE: This window should not receive keyboard events. * @GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE: This window should have exclusive focus if it is on the top or overlay layer. * @GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND: The user should be able to focus and unfocues this window in an implementation * defined way. Not supported for protocol version < 4. * @GTK_LAYER_SHELL_KEYBOARD_MODE_ENTRY_NUMBER: Should not be used except to get the number of entries. (NOTE: may change in * future releases as more entries are added) */ typedef enum { GTK_LAYER_SHELL_KEYBOARD_MODE_NONE = 0, GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE = 1, GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND = 2, GTK_LAYER_SHELL_KEYBOARD_MODE_ENTRY_NUMBER = 3, // Should not be used except to get the number of entries } GtkLayerShellKeyboardMode; /** * gtk_layer_get_major_version: * * Returns: the major version number of the GTK Layer Shell library */ guint gtk_layer_get_major_version (); /** * gtk_layer_get_minor_version: * * Returns: the minor version number of the GTK Layer Shell library */ guint gtk_layer_get_minor_version (); /** * gtk_layer_get_micro_version: * * Returns: the micro/patch version number of the GTK Layer Shell library */ guint gtk_layer_get_micro_version (); /** * gtk_layer_is_supported: * * May block for a Wayland roundtrip the first time it's called. * * Returns: %TRUE if the platform is Wayland and Wayland compositor supports the * zwlr_layer_shell_v1 protocol. */ gboolean gtk_layer_is_supported (); /** * gtk_layer_get_protocol_version: * * May block for a Wayland roundtrip the first time it's called. * * Returns: version of the zwlr_layer_shell_v1 protocol supported by the * compositor or 0 if the protocol is not supported. */ guint gtk_layer_get_protocol_version (); /** * 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_is_layer_window: * @window: A #GtkWindow that may or may not have a layer surface. * * Returns: if @window has been initialized as a layer surface. */ gboolean gtk_layer_is_layer_window (GtkWindow *window); /** * gtk_layer_get_zwlr_layer_surface_v1: * @window: A layer surface. * * Returns: The underlying layer surface Wayland object */ struct zwlr_layer_surface_v1 *gtk_layer_get_zwlr_layer_surface_v1 (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 maintains * ownership of original. If the window is currently mapped, it will get remapped so * the change can take effect. * * Default is "gtk4-layer-shell" (which will be used if set to %NULL) */ void gtk_layer_set_namespace (GtkWindow *window, char const* name_space); /** * gtk_layer_get_namespace: * @window: A layer surface. * * NOTE: this function does not return ownership of the string. Do not free the returned string. * Future calls into the library may invalidate the returned string. * * Returns: a reference to the namespace property. If namespace is unset, returns the * default namespace ("gtk4-layer-shell"). Never returns %NULL. */ const char *gtk_layer_get_namespace (GtkWindow *window); /** * 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). The layer may * be changed on-the-fly in the current version of the layer shell protocol, but on compositors that only support an * older version the @window is 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_get_layer: * @window: A layer surface. * * Returns: the current layer. */ GtkLayerShellLayer gtk_layer_get_layer (GtkWindow *window); /** * 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_get_monitor: * @window: A layer surface. * * NOTE: To get which monitor the surface is actually on, use * gdk_display_get_monitor_at_window(). * * Returns: (transfer none): the monitor this surface will/has requested to be on, can be %NULL. */ GdkMonitor *gtk_layer_get_monitor (GtkWindow *window); /** * gtk_layer_set_anchor: * @window: A layer surface. * @edge: A #GtkLayerShellEdge this layer surface 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_get_anchor: * @window: A layer surface. * @edge: the edge to which the surface may or may not be anchored * * Returns: if this surface is anchored to the given edge. */ gboolean gtk_layer_get_anchor (GtkWindow *window, GtkLayerShellEdge 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_get_margin: * @window: A layer surface. * @edge: the margin edge to get * * Returns: the size of the margin for the given edge. */ int gtk_layer_get_margin (GtkWindow *window, GtkLayerShellEdge edge); /** * gtk_layer_set_exclusive_zone: * @window: A layer surface. * @exclusive_zone: The size of the exclusive zone. * * Has no effect unless the surface is anchored to an edge. Requests that the compositor * does not place other surfaces within the given exclusive zone of the anchored edge. * For example, a panel can request to not be covered by maximized windows. See * wlr-layer-shell-unstable-v1.xml for details. * * Default is 0 */ void gtk_layer_set_exclusive_zone (GtkWindow *window, int exclusive_zone); /** * gtk_layer_get_exclusive_zone: * @window: A layer surface. * * Returns: the window's exclusive zone (which may have been set manually or automatically) */ int gtk_layer_get_exclusive_zone (GtkWindow *window); /** * gtk_layer_auto_exclusive_zone_enable: * @window: A layer surface. * * When auto exclusive zone is enabled, exclusive zone is automatically 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. * * NOTE: you can control the auto exclusive zone by changing the margin on the non-anchored * edge. This behavior is specific to gtk4-layer-shell and not part of the underlying protocol */ void gtk_layer_auto_exclusive_zone_enable (GtkWindow *window); /** * gtk_layer_auto_exclusive_zone_is_enabled: * @window: A layer surface. * * Returns: if the surface's exclusive zone is set to change based on the window's size */ gboolean gtk_layer_auto_exclusive_zone_is_enabled (GtkWindow *window); /** * gtk_layer_set_keyboard_mode: * @window: A layer surface. * @mode: The type of keyboard interactivity requested. * * Sets if/when @window should receive keyboard events from the compositor, see * GtkLayerShellKeyboardMode for details. * * Default is %GTK_LAYER_SHELL_KEYBOARD_MODE_NONE */ void gtk_layer_set_keyboard_mode (GtkWindow *window, GtkLayerShellKeyboardMode mode); /** * gtk_layer_get_keyboard_mode: * @window: A layer surface. * * Returns: current keyboard interactivity mode for @window. */ GtkLayerShellKeyboardMode gtk_layer_get_keyboard_mode (GtkWindow *window); G_END_DECLS #endif // GTK_LAYER_SHELL_H gtk4-layer-shell-1.0.4/include/meson.build000066400000000000000000000001621471230641700203750ustar00rootroot00000000000000gtk_layer_shell_inc = include_directories('.') install_headers('gtk4-layer-shell.h', subdir: 'gtk4-layer-shell') gtk4-layer-shell-1.0.4/linking.md000066400000000000000000000063151471230641700165730ustar00rootroot00000000000000# GTK4 Layer Shell Linking Weirdness ## TL;DR The dynamic linker needs to load `libgtk4-layer-shell.so` before `libwayland-client.so`. ## My code doesn't work, help! ### C/C++ (and other compiled languages) In your build system, make sure `gtk4-layer-shell` is explicitly linked to and first in the list. For example in meson it should appear first in the list of `dependencies` to your `executable`. To debug where a problem might be follow these steps: 1. Inspect the compiler commands (for example by running `ninja -C build -v`) and make sure gtk4-layer-shell is being linked before libwayland-client (ideally before GTK as well, though that doesn't seem to be necessary) 2. Run `ldd` on your binary and make sure gtk4-layer-shell appears before libwayland 3. Run your binary with `LD_DEBUG=libs` and make sure gtk4-layer-shell is loaded before libwayland. It may be helpful to redirect stderr to stdout and grep for "find library", so a full command might look like `LD_DEBUG=libs build/my-bin 2>&1 | grep 'find library='` ### Python GI Repository likes to load all dependencies before loading a library, so you need to make sure this is at the top of your main script: ```python # For GTK4 Layer Shell to get linked before libwayland-client we must explicitly load it before importing with gi from ctypes import CDLL CDLL('libgtk4-layer-shell.so') ``` If that still isn't working you can debug with `LD_DEBUG` as described above. ## LD_PRELOAD You should be able to get most things working using the `LD_PRELOAD` environment variable. Run the program with it set to the path of gtk4-layer-shell: ``` LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libgtk4-layer-shell.so my-app ``` ## Underlying cause At time of writing GTK4 has no official support for non-XDG Wayland shells (which is fair enough, since GTK3 only had partial broken support). To get around this we shim some libwayland calls. We define some symbols normally defined by libwayland, so that GTK calls into us when it thinks it's calling into libwayland. We `dlopen` the real libwayland and pass most calls directly on to it, while modifying calls that pertain to XDG Shell and Layer Shell. This allows us to provide GTK the XDG Shell interface it expects and speak Layer Shell to libwayland-client (and beyond that the Wayland compositor). The main downside is that if libwayland gets loaded before us, it's calls take precedence and the shim doesn't work. We attempt to detect this and display a warning. ## Triggering the error Triggering the link error intentionally (for example for testing that the library detects it) can be difficult. You need at least the following: 1. Build separate from the gtk4-layer-shell project. If your apps is built within the project (even if it's a different executable) meson links our library first. 2. Link libwayland-client before gtk4-layer-shell 3. Make at least one call to libwayland in your app (otherwise your linking of libwayland-client is ignored) ## Wayland Debug Old versions of my [wayland-debug](https://github.com/wmww/wayland-debug) tool set used `LD_PRELOAD` to load a patched libwayland, which breaks this library. wayland-debug has been updated to use `LD_LIBRARY_PATH` instead which seems to work fine. If you have any problems please let me know. gtk4-layer-shell-1.0.4/meson.build000066400000000000000000000033661471230641700167630ustar00rootroot00000000000000project('gtk4-layer-shell', ['c'], version: '1.0.4', license: 'MIT', meson_version: '>=0.51.0', default_options: ['c_std=gnu11', 'warning_level=3']) lib_so_version = '0' add_project_arguments( [ '-Wno-pedantic', '-Werror=implicit-function-declaration', '-Werror=return-type', ], language: 'c') glib = dependency('glib-2.0', required: true) # Just needed for version check if glib.version().version_compare('<2.74') add_project_arguments('-DG_APPLICATION_DEFAULT_FLAGS=G_APPLICATION_FLAGS_NONE', language: 'c') endif gtk = dependency('gtk4') wayland_client = dependency('wayland-client', version: '>=1.10.0') # only required for the tests wayland_server = dependency('wayland-server', version: '>=1.10.0', required: false) # wayland_scanner is required, but we can find it without pkg-config wayland_scanner = dependency('wayland-scanner', version: '>=1.10.0', required: false, native: true) # required, see https://github.com/wmww/gtk4-layer-shell/issues/24 wayland_protocols = dependency('wayland-protocols', version: '>=1.16', required: true) pkg_config = import('pkgconfig') gnome = import('gnome') subdir('include') subdir('protocol') subdir('src') gtk_layer_shell = declare_dependency( link_with: gtk_layer_shell_lib, include_directories: gtk_layer_shell_inc) subdir('examples') if get_option('docs') subdir('doc') endif if get_option('tests') subdir('test') else # Add a single always-failing test to tell the user to reconfigure with tests enabled test('Tests not enabled', find_program('sh'), args: ['-c', 'echo \'you must run `meson setup --reconfigure -Dtests=true build` in order to run the tests (where build is the path to your build directory)\'; exit 1']) endif gtk4-layer-shell-1.0.4/meson_options.txt000066400000000000000000000011141471230641700202430ustar00rootroot00000000000000option('examples', type: 'boolean', value: false, description: 'Build example applications') option('docs', type: 'boolean', value: false, description: 'Build devhelp API documentation') option('tests', type: 'boolean', value: false, description: 'Build tests') option('smoke-tests', type: 'boolean', value: true, description: 'Run smoke tests of all the examples') option('introspection', type: 'boolean', value: true, description: 'Build gobject-introspection data') option('vapi', type: 'boolean', value: true, description: 'Generate vapi data (needs vapigen & introspection option)') gtk4-layer-shell-1.0.4/protocol/000077500000000000000000000000001471230641700164525ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/protocol/meson.build000066400000000000000000000025111471230641700206130ustar00rootroot00000000000000if wayland_scanner.found() prog_wayland_scanner = find_program(wayland_scanner.get_variable(pkgconfig: 'wayland_scanner')) else prog_wayland_scanner = find_program('wayland-scanner') endif protocols = [ 'wlr-layer-shell-unstable-v1.xml', join_paths( wayland_protocols.get_variable(pkgconfig: 'pkgdatadir'), 'stable/xdg-shell/xdg-shell.xml'), ] if get_option('tests') protocols += 'xdg-dialog-v1.xml' endif gen_client_header = generator(prog_wayland_scanner, output: ['@BASENAME@-client.h'], arguments: ['-c', 'client-header', '@INPUT@', '@BUILD_DIR@/@BASENAME@-client.h']) gen_server_header = generator(prog_wayland_scanner, output: ['@BASENAME@-server.h'], arguments: ['-c', 'server-header', '@INPUT@', '@BUILD_DIR@/@BASENAME@-server.h']) gen_private_code = generator(prog_wayland_scanner, output: ['@BASENAME@.c'], arguments: ['-c', 'private-code', '@INPUT@', '@BUILD_DIR@/@BASENAME@.c']) client_protocol_srcs = [] server_protocol_srcs = [] foreach protocol : protocols client_header = gen_client_header.process(protocol) code = gen_private_code.process(protocol) client_protocol_srcs += [client_header, code] if get_option('tests') server_header = gen_server_header.process(protocol) server_protocol_srcs += [server_header, code] endif endforeach gtk4-layer-shell-1.0.4/protocol/wlr-layer-shell-unstable-v1.xml000066400000000000000000000440361471230641700243650ustar00rootroot00000000000000 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. After creating a layer_surface object and setting it up, the client must perform an initial commit without any buffer attached. The compositor will reply with a layer_surface.configure event. The client must acknowledge it and is then allowed to attach a buffer to map the surface. 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. This request indicates that the client will not use the layer_shell object any more. Objects that have been created through this instance are not affected. 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 (layer, 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. Attaching a null buffer to a layer surface unmaps it. Unmapping a layer_surface means that the surface cannot be shown by the compositor until it is explicitly mapped again. The layer_surface returns to the state it had right after layer_shell.get_layer_surface. The client can re-map the surface by performing a commit without any buffer attached, waiting for a configure event and handling it as usual. 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 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 one edge or an edge and both perpendicular edges. If the surface is not anchored, anchored to only two perpendicular edges (a corner), anchored to only two parallel edges or anchored to all edges, a positive value will be treated the same as zero. A positive zone is the distance from the edge in surface-local coordinates to consider 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. Types of keyboard interaction possible for layer shell surfaces. The rationale for this is twofold: (1) some applications are not interested in keyboard events and not allowing them to be focused can improve the desktop experience; (2) some applications will want to take exclusive keyboard focus. This value indicates that this surface is not interested in keyboard events and the compositor should never assign it the keyboard focus. This is the default value, set for newly created layer shell surfaces. This is useful for e.g. desktop widgets that display information or only have interaction with non-keyboard input devices. Request exclusive keyboard focus if this surface is above the shell surface layer. For the top and overlay layers, the seat will always give exclusive keyboard focus to the top-most layer which has keyboard interactivity set to exclusive. If this layer contains multiple surfaces with keyboard interactivity set to exclusive, the compositor determines the one receiving keyboard events in an implementation- defined manner. In this case, no guarantee is made when this surface will receive keyboard focus (if ever). For the bottom and background layers, the compositor is allowed to use normal focus semantics. This setting is mainly intended for applications that need to ensure they receive all keyboard events, such as a lock screen or a password prompt. This requests the compositor to allow this surface to be focused and unfocused by the user in an implementation-defined manner. The user should be able to unfocus this surface even regardless of the layer it is on. Typically, the compositor will want to use its normal mechanism to manage keyboard focus between layer shell surfaces with this setting and regular toplevels on the desktop layer (e.g. click to focus). Nevertheless, it is possible for a compositor to require a special interaction to focus or unfocus layer shell surfaces (e.g. requiring a click even if focus follows the mouse normally, or providing a keybinding to switch focus between layers). This setting is mainly intended for desktop shell components (e.g. panels) that allow keyboard interaction. Using this option can allow implementing a desktop shell that can be fully usable without the mouse. Set how keyboard events are delivered to this surface. By default, layer shell surfaces do not receive keyboard events; this request can be used to change this. This setting is inherited by child surfaces set by the get_popup request. 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. Keyboard interactivity 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. Change the layer that the surface is rendered on. Layer is double-buffered, see wl_surface.commit. gtk4-layer-shell-1.0.4/protocol/xdg-dialog-v1.xml000066400000000000000000000113401471230641700215360ustar00rootroot00000000000000 Copyright © 2023 Carlos Garnacho 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_dialog_v1 interface is exposed as a global object allowing to register surfaces with a xdg_toplevel role as "dialogs" relative to another toplevel. The compositor may let this relation influence how the surface is placed, displayed or interacted with. Warning! The protocol described in this file is currently in the testing phase. Backward compatible changes may be added together with the corresponding interface version bump. Backward incompatible changes can only be done by creating a new major version of the extension. Destroys the xdg_wm_dialog_v1 object. This does not affect the xdg_dialog_v1 objects generated through it. Creates a xdg_dialog_v1 object for the given toplevel. See the interface description for more details. Compositors must raise an already_used error if clients attempt to create multiple xdg_dialog_v1 objects for the same xdg_toplevel. A xdg_dialog_v1 object is an ancillary object tied to a xdg_toplevel. Its purpose is hinting the compositor that the toplevel is a "dialog" (e.g. a temporary window) relative to another toplevel (see xdg_toplevel.set_parent). If the xdg_toplevel is destroyed, the xdg_dialog_v1 becomes inert. Through this object, the client may provide additional hints about the purpose of the secondary toplevel. This interface has no effect on toplevels that are not attached to a parent toplevel. Destroys the xdg_dialog_v1 object. If this object is destroyed before the related xdg_toplevel, the compositor should unapply its effects. Hints that the dialog has "modal" behavior. Modal dialogs typically require to be fully addressed by the user (i.e. closed) before resuming interaction with the parent toplevel, and may require a distinct presentation. Clients must implement the logic to filter events in the parent toplevel on their own. Compositors may choose any policy in event delivery to the parent toplevel, from delivering all events unfiltered to using them for internal consumption. Drops the hint that this dialog has "modal" behavior. See xdg_dialog_v1.set_modal for more details. gtk4-layer-shell-1.0.4/release_process.md000066400000000000000000000013351471230641700203130ustar00rootroot00000000000000# GTK4 Layer Shell release process 1. Make sure you've pulled latest changes from main 1. Make sure the tests pass: `ninja -C build test` 1. Play with gtk4-layer-demo: `build/examples/gtk4-layer-demo` (catch anything the automatic tests missed) 1. Bump version in [meson.build](meson.build) 1. Update [CHANGELOG.md](CHANGELOG.md) ([GitHub compare](https://github.com/wmww/gtk4-layer-shell/compare/) is useful here) 1. Commit and push meson and changelog changes 1. Tag release: `git tag vA.B.C` 1. Push tag: `git push origin vA.B.C` 1. Under Releases in the GitHub repo, the tag should have already appeared, click it 1. Click Edit tag 1. Enter release name (version number, no v prefix) and copy in the changelog 1. Publish release gtk4-layer-shell-1.0.4/src/000077500000000000000000000000001471230641700154005ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/src/api.c000066400000000000000000000134321471230641700163200ustar00rootroot00000000000000#include "wayland-utils.h" #include "layer-surface.h" #include "libwayland-shim.h" #include guint gtk_layer_get_major_version () { return GTK_LAYER_SHELL_MAJOR; } guint gtk_layer_get_minor_version () { return GTK_LAYER_SHELL_MINOR; } guint gtk_layer_get_micro_version () { return GTK_LAYER_SHELL_MICRO; } gboolean gtk_layer_is_supported () { gtk_wayland_init_if_needed (); return libwayland_shim_has_initialized () && gtk_wayland_get_layer_shell_global () != NULL; } guint gtk_layer_get_protocol_version () { if (!GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) return 0; gtk_wayland_init_if_needed (); struct zwlr_layer_shell_v1 *layer_shell_global = gtk_wayland_get_layer_shell_global (); if (!layer_shell_global) return 0; return zwlr_layer_shell_v1_get_version (layer_shell_global); } static LayerSurface* gtk_window_get_layer_surface_or_warn (GtkWindow *window) { g_return_val_if_fail (window, NULL); LayerSurface *layer_surface = gtk_window_get_layer_surface (window); if (!layer_surface) { g_warning ("GtkWindow is not a layer surface. Make sure you called gtk_layer_init_for_window ()"); return NULL; } return layer_surface; } void gtk_layer_init_for_window (GtkWindow *window) { gtk_wayland_init_if_needed (); layer_surface_new (window); } gboolean gtk_layer_is_layer_window (GtkWindow *window) { return gtk_window_get_layer_surface (window) != NULL; } struct zwlr_layer_surface_v1 * gtk_layer_get_zwlr_layer_surface_v1 (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return NULL; return layer_surface->layer_surface; } void gtk_layer_set_namespace (GtkWindow *window, char const* name_space) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_set_name_space (layer_surface, name_space); } const char * gtk_layer_get_namespace (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); return layer_surface_get_namespace (layer_surface); // NULL-safe } void gtk_layer_set_layer (GtkWindow *window, GtkLayerShellLayer layer) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_set_layer (layer_surface, layer); } GtkLayerShellLayer gtk_layer_get_layer (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return GTK_LAYER_SHELL_LAYER_TOP; return layer_surface->layer; } void gtk_layer_set_monitor (GtkWindow *window, GdkMonitor *monitor) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_set_monitor (layer_surface, monitor); } GdkMonitor * gtk_layer_get_monitor (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return NULL; return layer_surface->monitor; } void gtk_layer_set_anchor (GtkWindow *window, GtkLayerShellEdge edge, gboolean anchor_to_edge) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_set_anchor (layer_surface, edge, anchor_to_edge); } gboolean gtk_layer_get_anchor (GtkWindow *window, GtkLayerShellEdge edge) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return FALSE; g_return_val_if_fail(edge >= 0 && edge < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER, FALSE); return layer_surface->anchors[edge]; } void gtk_layer_set_margin (GtkWindow *window, GtkLayerShellEdge edge, int margin_size) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_set_margin (layer_surface, edge, margin_size); } int gtk_layer_get_margin (GtkWindow *window, GtkLayerShellEdge edge) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return 0; g_return_val_if_fail(edge >= 0 && edge < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER, FALSE); return layer_surface->margins[edge]; } void gtk_layer_set_exclusive_zone (GtkWindow *window, int exclusive_zone) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_set_exclusive_zone (layer_surface, exclusive_zone); } int gtk_layer_get_exclusive_zone (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return 0; return layer_surface->exclusive_zone; } void gtk_layer_auto_exclusive_zone_enable (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_auto_exclusive_zone_enable (layer_surface); } gboolean gtk_layer_auto_exclusive_zone_is_enabled (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return FALSE; return layer_surface->auto_exclusive_zone; } void gtk_layer_set_keyboard_mode (GtkWindow *window, GtkLayerShellKeyboardMode mode) { g_return_if_fail(mode < GTK_LAYER_SHELL_KEYBOARD_MODE_ENTRY_NUMBER); LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return; layer_surface_set_keyboard_mode (layer_surface, mode); } GtkLayerShellKeyboardMode gtk_layer_get_keyboard_mode (GtkWindow *window) { LayerSurface *layer_surface = gtk_window_get_layer_surface_or_warn (window); if (!layer_surface) return GTK_LAYER_SHELL_KEYBOARD_MODE_NONE; return layer_surface->keyboard_mode; } gtk4-layer-shell-1.0.4/src/layer-surface.c000066400000000000000000000510701471230641700203110ustar00rootroot00000000000000#include "layer-surface.h" #include "wayland-utils.h" #include "libwayland-shim.h" #include "wlr-layer-shell-unstable-v1-client.h" #include "xdg-shell-client.h" #include #include static const char *layer_surface_key = "wayland_layer_surface"; GList* all_layer_surfaces = NULL; LayerSurface * gtk_window_get_layer_surface (GtkWindow *gtk_window) { if (!gtk_window) return NULL; return g_object_get_data (G_OBJECT (gtk_window), layer_surface_key); } static void layer_surface_remap (LayerSurface *self) { gtk_widget_unrealize (GTK_WIDGET (self->gtk_window)); gtk_widget_map (GTK_WIDGET (self->gtk_window)); } static void layer_surface_get_preferred_size (LayerSurface *self, int *width, int *height) { gtk_window_get_default_size (self->gtk_window, width, height); GtkRequisition natural; gtk_widget_get_preferred_size (GTK_WIDGET (self->gtk_window), NULL, &natural); if (!*width) *width = natural.width; if (!*height) *height = natural.height; } static void layer_surface_send_set_size (LayerSurface *self) { g_return_if_fail (self->layer_surface); int width = gtk_widget_get_width (GTK_WIDGET (self->gtk_window)); int height = gtk_widget_get_height (GTK_WIDGET (self->gtk_window)); if (!width || !height) layer_surface_get_preferred_size (self, &width, &height); if (self->anchors[GTK_LAYER_SHELL_EDGE_LEFT] && self->anchors[GTK_LAYER_SHELL_EDGE_RIGHT] ) { width = 0; } if (self->anchors[GTK_LAYER_SHELL_EDGE_TOP] && self->anchors[GTK_LAYER_SHELL_EDGE_BOTTOM] ) { height = 0; } if (self->cached_layer_size_set.width != width || self->cached_layer_size_set.height != height ) { self->cached_layer_size_set = (GtkRequisition){width, height}; zwlr_layer_surface_v1_set_size (self->layer_surface, width, height); } } static void layer_surface_configure_xdg_surface (LayerSurface *self, uint32_t serial, gboolean send_even_if_size_unchanged) { if (!self->client_facing_xdg_surface || !self->client_facing_xdg_toplevel) return; int width, height; layer_surface_get_preferred_size (self, &width, &height); if (self->anchors[GTK_LAYER_SHELL_EDGE_LEFT] && self->anchors[GTK_LAYER_SHELL_EDGE_RIGHT] && self->last_layer_configured_size.width ) { width = self->last_layer_configured_size.width; } if (self->anchors[GTK_LAYER_SHELL_EDGE_TOP] && self->anchors[GTK_LAYER_SHELL_EDGE_BOTTOM] && self->last_layer_configured_size.height ) { height = self->last_layer_configured_size.height; } if (!self->has_initial_layer_shell_configure) { // skip sending xdg_toplevel and xdg_surface configure to GTK // since layer shell surface has not been configured yet and // attaching a buffer to an unconfigured surface is a protocol error return; } if (self->cached_xdg_configure_size.width != width || self->cached_xdg_configure_size.height != height || send_even_if_size_unchanged ) { self->cached_xdg_configure_size = (GtkRequisition){width, height}; if (serial) self->pending_configure_serial = serial; struct wl_array states; wl_array_init(&states); { uint32_t *state = wl_array_add(&states, sizeof(uint32_t)); g_assert(state); *state = XDG_TOPLEVEL_STATE_ACTIVATED; } { uint32_t *state = wl_array_add(&states, sizeof(uint32_t)); g_assert(state); *state = XDG_TOPLEVEL_STATE_MAXIMIZED; } LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT( xdg_toplevel_listener, self->client_facing_xdg_toplevel, configure, self->client_facing_xdg_toplevel, width, height, &states); wl_array_release(&states); LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT( xdg_surface_listener, self->client_facing_xdg_surface, configure, self->client_facing_xdg_surface, serial); } } static void layer_surface_needs_commit (LayerSurface *self) { // Send a configure to force GTK to commit the surface layer_surface_configure_xdg_surface (self, 0, TRUE); } static void layer_surface_handle_configure (void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t w, uint32_t h) { (void)surface; LayerSurface *self = data; self->last_layer_configured_size = (GtkRequisition){w, h}; self->has_initial_layer_shell_configure = true; layer_surface_configure_xdg_surface (self, serial, TRUE); } static void layer_surface_handle_closed (void *data, struct zwlr_layer_surface_v1 *_surface) { LayerSurface *self = data; (void)_surface; gtk_window_close (self->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_create_surface_object (LayerSurface *self, struct wl_surface *wl_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 = layer_surface_get_namespace(self); struct wl_output *output = NULL; if (self->monitor) { output = gdk_wayland_monitor_get_wl_output (self->monitor); } enum zwlr_layer_shell_v1_layer layer = gtk_layer_shell_layer_get_zwlr_layer_shell_v1_layer(self->layer); self->has_initial_layer_shell_configure = false; self->layer_surface = zwlr_layer_shell_v1_get_layer_surface (layer_shell_global, wl_surface, output, layer, name_space); g_return_if_fail (self->layer_surface); zwlr_layer_surface_v1_add_listener (self->layer_surface, &layer_surface_listener, self); zwlr_layer_surface_v1_set_keyboard_interactivity (self->layer_surface, self->keyboard_mode); 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); layer_surface_send_set_size (self); } static void layer_surface_unmap (LayerSurface *super) { LayerSurface *self = (LayerSurface *)super; if (self->layer_surface) { zwlr_layer_surface_v1_destroy (self->layer_surface); self->layer_surface = NULL; } libwayland_shim_clear_client_proxy_data((struct wl_proxy *)self->client_facing_xdg_surface); libwayland_shim_clear_client_proxy_data((struct wl_proxy *)self->client_facing_xdg_toplevel); self->client_facing_xdg_surface = NULL; self->client_facing_xdg_toplevel = NULL; self->has_initial_layer_shell_configure = false; self->cached_xdg_configure_size = (GtkRequisition){-1, -1}; self->cached_layer_size_set = (GtkRequisition){-1, -1}; self->last_layer_configured_size = (GtkRequisition){0, 0}; self->pending_configure_serial = 0; } static void layer_surface_destroy (LayerSurface *self) { layer_surface_unmap (self); all_layer_surfaces = g_list_remove (all_layer_surfaces, self); g_free ((gpointer)self->name_space); g_free (self); } 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; int window_width = gtk_widget_get_width (GTK_WIDGET (self->gtk_window)); int window_height = gtk_widget_get_height (GTK_WIDGET (self->gtk_window)); if (horiz && !vert) { new_exclusive_zone = window_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 = window_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_default_size_set(GtkWindow *_window, const GParamSpec *_pspec, LayerSurface *self) { (void)_window; (void)_pspec; layer_surface_configure_xdg_surface (self, 0, FALSE); } LayerSurface * layer_surface_new (GtkWindow *gtk_window) { if (!GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) { g_warning ("Failed to initialize layer surface, not on Wayland"); return NULL; } if (!libwayland_shim_has_initialized ()) { g_warning ("Failed to initialize layer surface, GTK4 Layer Shell may have been linked after libwayland."); g_message ("Move gtk4-layer-shell before libwayland-client in the linker options."); g_message ("You may be able to fix with without recompiling by setting LD_PRELOAD=/path/to/libgtk4-layer-shell.so"); g_message ("See https://github.com/wmww/gtk4-layer-shell/blob/main/linking.md for more info"); return NULL; } if (!gtk_wayland_get_layer_shell_global ()) { g_warning ("Failed to initialize layer surface, it appears your Wayland compositor doesn't support Layer Shell"); return NULL; } if (!gtk_window) { g_warning ("Failed to initialize layer surface, provided window is null"); return NULL; } LayerSurface *self = g_new0 (LayerSurface, 1); self->cached_xdg_configure_size = (GtkRequisition){-1, -1}; self->cached_layer_size_set = (GtkRequisition){-1, -1}; self->has_initial_layer_shell_configure = false; all_layer_surfaces = g_list_append (all_layer_surfaces, self); self->gtk_window = gtk_window; g_object_set_data_full (G_OBJECT (gtk_window), layer_surface_key, self, (GDestroyNotify) layer_surface_destroy); self->layer = GTK_LAYER_SHELL_LAYER_TOP; self->keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_NONE; gtk_window_set_decorated (gtk_window, FALSE); g_signal_connect (gtk_window, "notify::default-width", G_CALLBACK (layer_surface_on_default_size_set), self); g_signal_connect (gtk_window, "notify::default-height", G_CALLBACK (layer_surface_on_default_size_set), self); if (gtk_widget_get_mapped (GTK_WIDGET (gtk_window))) { layer_surface_remap (self); } return 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) { layer_surface_remap (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) { layer_surface_remap (self); } } } void layer_surface_set_layer (LayerSurface *self, GtkLayerShellLayer layer) { if (self->layer != layer) { self->layer = layer; if (self->layer_surface) { uint32_t version = zwlr_layer_surface_v1_get_version (self->layer_surface); if (version >= ZWLR_LAYER_SURFACE_V1_SET_LAYER_SINCE_VERSION) { enum zwlr_layer_shell_v1_layer wlr_layer = gtk_layer_shell_layer_get_zwlr_layer_shell_v1_layer(layer); zwlr_layer_surface_v1_set_layer (self->layer_surface, wlr_layer); layer_surface_needs_commit (self); } else { layer_surface_remap (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); anchor_to_edge = (anchor_to_edge != FALSE); 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_send_set_size (self); layer_surface_configure_xdg_surface (self, 0, FALSE); layer_surface_update_auto_exclusive_zone (self); layer_surface_needs_commit (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); layer_surface_needs_commit (self); } } void layer_surface_set_exclusive_zone (LayerSurface *self, int exclusive_zone) { self->auto_exclusive_zone = FALSE; if (exclusive_zone < -1) exclusive_zone = -1; 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); layer_surface_needs_commit (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_mode (LayerSurface *self, GtkLayerShellKeyboardMode mode) { if (mode == GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND) { uint32_t version = gtk_layer_get_protocol_version(); if (version <= 3) { g_warning ( "Compositor uses layer shell version %d, which does not support on-demand keyboard interactivity", version); mode = GTK_LAYER_SHELL_KEYBOARD_MODE_NONE; } } if (self->keyboard_mode != mode) { self->keyboard_mode = mode; if (self->layer_surface) { zwlr_layer_surface_v1_set_keyboard_interactivity (self->layer_surface, self->keyboard_mode); layer_surface_needs_commit (self); } } } const char* layer_surface_get_namespace (LayerSurface *self) { if (self && self->name_space) return self->name_space; else return "gtk4-layer-shell"; } static void stubbed_xdg_toplevel_handle_destroy (void* data, struct wl_proxy *proxy) { (void)proxy; LayerSurface *self = (LayerSurface *)data; layer_surface_unmap(self); } static struct wl_proxy * stubbed_xdg_surface_handle_request ( void* data, struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, union wl_argument *args) { (void)interface; (void)flags; LayerSurface *self = (LayerSurface *)data; if (opcode == XDG_SURFACE_GET_TOPLEVEL) { struct wl_proxy *toplevel = libwayland_shim_create_client_proxy ( proxy, &xdg_toplevel_interface, version, NULL, stubbed_xdg_toplevel_handle_destroy, data); self->client_facing_xdg_toplevel = (struct xdg_toplevel *)toplevel; return toplevel; } else if (opcode == XDG_SURFACE_GET_POPUP) { g_critical ("XDG surface intercepted, but is now being used as popup"); return libwayland_shim_create_client_proxy (proxy, &xdg_popup_interface, version, NULL, NULL, NULL); } else if (opcode == XDG_SURFACE_SET_WINDOW_GEOMETRY) { layer_surface_send_set_size (self); layer_surface_update_auto_exclusive_zone (self); return NULL; } else if (opcode == XDG_SURFACE_ACK_CONFIGURE) { uint32_t serial = args[0].u; if (serial && serial == self->pending_configure_serial) { self->pending_configure_serial = 0; zwlr_layer_surface_v1_ack_configure (self->layer_surface, serial); } return NULL; } else { return NULL; } } static void stubbed_xdg_surface_handle_destroy (void* data, struct wl_proxy *proxy) { (void)proxy; LayerSurface *self = (LayerSurface *)data; layer_surface_unmap(self); } gint find_layer_surface_with_wl_surface (gconstpointer layer_surface, gconstpointer needle) { const LayerSurface *self = layer_surface; GdkSurface *gdk_surface = gtk_native_get_surface (GTK_NATIVE (self->gtk_window)); if (!gdk_surface) return 1; struct wl_surface *wl_surface = gdk_wayland_surface_get_wl_surface (gdk_surface); return wl_surface == needle ? 0 : 1; } gboolean layer_surface_handle_request ( struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, union wl_argument *args, struct wl_proxy **ret_proxy) { (void)interface; (void)flags; const char* type = proxy->object.interface->name; if (strcmp(type, xdg_wm_base_interface.name) == 0) { if (opcode == XDG_WM_BASE_GET_XDG_SURFACE) { struct wl_surface *wl_surface = (struct wl_surface *)args[1].o; GList *layer_surface_entry = g_list_find_custom (all_layer_surfaces, wl_surface, find_layer_surface_with_wl_surface); if (layer_surface_entry) { LayerSurface *self = layer_surface_entry->data; struct wl_proxy *xdg_surface = libwayland_shim_create_client_proxy ( proxy, &xdg_surface_interface, version, stubbed_xdg_surface_handle_request, stubbed_xdg_surface_handle_destroy, self); self->client_facing_xdg_surface = (struct xdg_surface *)xdg_surface; layer_surface_create_surface_object(self, wl_surface); *ret_proxy = xdg_surface; return TRUE; } } } else if (strcmp(type, xdg_surface_interface.name) == 0) { if (opcode == XDG_SURFACE_GET_POPUP) { LayerSurface *self = libwayland_shim_get_client_proxy_data ((struct wl_proxy *)args[1].o, stubbed_xdg_surface_handle_request); if (self) { if (self->layer_surface) { struct xdg_popup *xdg_popup = xdg_surface_get_popup ( (struct xdg_surface *)proxy, NULL, (struct xdg_positioner *)args[2].o); zwlr_layer_surface_v1_get_popup (self->layer_surface, xdg_popup); *ret_proxy = (struct wl_proxy *)xdg_popup; return TRUE; } else { g_critical ("tried to create popup before layer shell surface"); *ret_proxy = libwayland_shim_create_client_proxy (proxy, &xdg_popup_interface, version, NULL, NULL, NULL); return TRUE; } } } } return FALSE; } gtk4-layer-shell-1.0.4/src/layer-surface.h000066400000000000000000000071331471230641700203170ustar00rootroot00000000000000#ifndef LAYER_SHELL_SURFACE_H #define LAYER_SHELL_SURFACE_H #include "wlr-layer-shell-unstable-v1-client.h" #include "gtk4-layer-shell.h" #include struct wl_surface; struct xdg_surface; struct xdg_positioner; typedef struct _LayerSurface LayerSurface; // Functions that mutate this structure should all be in layer-surface.c to make the logic easier to understand // Struct is declared in this header to prevent the need for excess getters struct _LayerSurface { GtkWindow *gtk_window; // Can be set at any time gboolean anchors[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]; // The current anchor int margins[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]; // The current margins int exclusive_zone; // The current exclusive zone (set either explicitly or automatically) gboolean auto_exclusive_zone; // If to automatically change the exclusive zone to match the window size GtkLayerShellKeyboardMode keyboard_mode; // Type of keyboard interactivity enabled for this surface GtkLayerShellLayer layer; // The current layer, needs surface recreation on old layer shell versions // Need the surface to be recreated to change GdkMonitor *monitor; // Can be null const char *name_space; // Can be null, freed on destruction // Not set by user requests struct zwlr_layer_surface_v1 *layer_surface; // The actual layer surface Wayland object (can be NULL) GtkRequisition cached_xdg_configure_size; // The last size we configured GTK's XDG surface with GtkRequisition cached_layer_size_set; // The last size we set the layer surface to with the compositor GtkRequisition last_layer_configured_size; // The last size our layer surface received from the compositor uint32_t pending_configure_serial; // If non-zero our layer surface received a configure with this serial, we passed // it on to GTK's XDG surface and will ack it once GTK acks it's configure. Otherwise this is zero, all acks from // GTK can be ignored (they are for configures not originating from the compositor) struct xdg_surface *client_facing_xdg_surface; struct xdg_toplevel *client_facing_xdg_toplevel; bool has_initial_layer_shell_configure; }; LayerSurface *layer_surface_new (GtkWindow *gtk_window); LayerSurface *gtk_window_get_layer_surface (GtkWindow *gtk_window); // Surface is remapped in order to set 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_layer (LayerSurface *self, GtkLayerShellLayer layer); // Remaps surface on old layer shell versions 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_mode (LayerSurface *self, GtkLayerShellKeyboardMode mode); // Returns the effective namespace (default if unset). Does not return ownership. Never returns NULL. Handles NULL self. const char* layer_surface_get_namespace (LayerSurface *self); // Used by libwayland wrappers gboolean layer_surface_handle_request ( struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, union wl_argument *args, struct wl_proxy **ret_proxy); #endif // LAYER_SHELL_SURFACE_H gtk4-layer-shell-1.0.4/src/libwayland-shim.c000066400000000000000000000305331471230641700206340ustar00rootroot00000000000000#include #include #include "libwayland-shim.h" #include "layer-surface.h" #include "wayland-utils.h" struct wl_proxy *(*libwayland_shim_real_wl_proxy_marshal_array_flags) ( struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, union wl_argument *args) = NULL; void (*libwayland_shim_real_wl_proxy_destroy) (struct wl_proxy *proxy) = NULL; int (*libwayland_shim_real_wl_proxy_add_dispatcher)(struct wl_proxy *proxy, wl_dispatcher_func_t dispatcher_func, const void * dispatcher_data, void *data) = NULL; gboolean libwayland_shim_has_initialized () { return libwayland_shim_real_wl_proxy_marshal_array_flags != NULL; } static void libwayland_shim_init () { if (libwayland_shim_has_initialized ()) return; void *handle = dlopen("libwayland-client.so.0", RTLD_LAZY); if (handle == NULL) { handle = dlopen("libwayland-client.so", RTLD_LAZY); } if (handle == NULL) { g_error ("failed to dlopen libwayland"); } #define INIT_SYM(name) if (!(libwayland_shim_real_##name = dlsym(handle, #name))) {\ g_error ("dlsym failed to load %s", #name); } INIT_SYM(wl_proxy_marshal_array_flags); INIT_SYM(wl_proxy_destroy); INIT_SYM(wl_proxy_add_dispatcher); #undef INIT_SYM //dlclose(handle); } // From wayland-private.h in libwayland #define WL_CLOSURE_MAX_ARGS 20 // From wayland-private.h in libwayland struct argument_details { char type; int nullable; }; // From connection.c in libwayland static const char * get_next_argument(const char *signature, struct argument_details *details) { details->nullable = 0; for(; *signature; ++signature) { switch(*signature) { case 'i': case 'u': case 'f': case 's': case 'o': case 'n': case 'a': case 'h': details->type = *signature; return signature + 1; case '?': details->nullable = 1; } } details->type = '\0'; return signature; } // From connection.c in libwayland static void wl_argument_from_va_list(const char *signature, union wl_argument *args, int count, va_list ap) { int i; const char *sig_iter; struct argument_details arg; sig_iter = signature; for (i = 0; i < count; i++) { sig_iter = get_next_argument(sig_iter, &arg); switch(arg.type) { case 'i': args[i].i = va_arg(ap, int32_t); break; case 'u': args[i].u = va_arg(ap, uint32_t); break; case 'f': args[i].f = va_arg(ap, wl_fixed_t); break; case 's': args[i].s = va_arg(ap, const char *); break; case 'o': args[i].o = va_arg(ap, struct wl_object *); break; case 'n': args[i].o = va_arg(ap, struct wl_object *); break; case 'a': args[i].a = va_arg(ap, struct wl_array *); break; case 'h': args[i].h = va_arg(ap, int32_t); break; case '\0': return; } } } struct wrapped_proxy { struct wl_proxy proxy; libwayland_shim_client_proxy_handler_func_t handler; libwayland_shim_client_proxy_destroy_func_t destroy; void* data; }; // The ID for ALL proxies that are created by us and not managed by the real libwayland const uint32_t client_facing_proxy_id = 6942069; struct wl_proxy * libwayland_shim_create_client_proxy ( struct wl_proxy *factory, const struct wl_interface *interface, uint32_t version, libwayland_shim_client_proxy_handler_func_t handler, libwayland_shim_client_proxy_destroy_func_t destroy, void* data) { struct wrapped_proxy* allocation = g_new0 (struct wrapped_proxy, 1); g_assert (allocation); allocation->proxy.object.interface = interface; allocation->proxy.display = factory->display; allocation->proxy.queue = factory->queue; allocation->proxy.refcount = 1; allocation->proxy.version = version; allocation->proxy.object.id = client_facing_proxy_id; wl_list_init(&allocation->proxy.queue_link); allocation->handler = handler; allocation->destroy = destroy; allocation->data = data; return &allocation->proxy; } void libwayland_shim_clear_client_proxy_data (struct wl_proxy *proxy) { if (!proxy) { return; } g_assert(proxy->object.id == client_facing_proxy_id); struct wrapped_proxy *wrapper = (struct wrapped_proxy *)proxy; wrapper->data = NULL; wrapper->destroy = NULL; wrapper->handler = NULL; } void * libwayland_shim_get_client_proxy_data (struct wl_proxy *proxy, void* expected_handler) { if (proxy && proxy->object.id == client_facing_proxy_id) { struct wrapped_proxy *wrapper = (struct wrapped_proxy *)proxy; if (wrapper->handler == expected_handler) { return wrapper->data; } else { return NULL; } } else { return NULL; } } // Returns true if any arguments are proxies created by us (not known to libwayland) gboolean args_contains_client_facing_proxy ( struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, union wl_argument *args) { (void)interface; const char *sig_iter = proxy->object.interface->methods[opcode].signature; int i = 0; while (true) { struct argument_details arg; sig_iter = get_next_argument(sig_iter, &arg); switch (arg.type) { case 'o': if (args[i].o && args[i].o->id == client_facing_proxy_id) { return TRUE; } break; case '\0': return FALSE; } i++; } } // Returns the interface of the proxy object that this request is supposed to create, or NULL if none const struct wl_interface* get_interface_of_object_created_by_request ( struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface) { const char *sig_iter = proxy->object.interface->methods[opcode].signature; int i = 0; while (true) { struct argument_details arg; sig_iter = get_next_argument(sig_iter, &arg); switch (arg.type) { case 'n': g_assert(interface[i].name); return interface + i; case '\0': return NULL; } i++; } } // Overrides the function in wayland-client.c in libwayland void wl_proxy_destroy (struct wl_proxy *proxy) { libwayland_shim_init (); if (proxy->object.id == client_facing_proxy_id) { struct wrapped_proxy *wrapper = (struct wrapped_proxy *)proxy; if (wrapper->destroy) { wrapper->destroy(wrapper->data, proxy); } wl_list_remove(&proxy->queue_link); // No need to worry about the refcount since it's only accessibly within libwayland, and it's only used by // functions that never see client facing objects g_free (proxy); } else { libwayland_shim_real_wl_proxy_destroy (proxy); } } // Overrides the function in wayland-client.c in libwayland struct wl_proxy * wl_proxy_marshal_array_flags ( struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, union wl_argument *args) { libwayland_shim_init (); if (proxy->object.id == client_facing_proxy_id) { // libwayland doesn't know about the object this request is on. It must not find out about this object. If it // finds out it will be very upset. struct wrapped_proxy *wrapper = (struct wrapped_proxy *)proxy; struct wl_proxy *result = NULL; if (wrapper->handler) result = wrapper->handler(wrapper->data, proxy, opcode, interface, version, flags, args); if (flags & WL_MARSHAL_FLAG_DESTROY) wl_proxy_destroy(proxy); return result; } else { struct wl_proxy *ret_proxy = NULL; if (layer_surface_handle_request (proxy, opcode, interface, version, flags, args, &ret_proxy)) { // The behavior of the request has been overridden return ret_proxy; } else if (args_contains_client_facing_proxy (proxy, opcode, interface, args)) { // We can't do the normal thing because one of the arguments is an object libwayand doesn't know about, but // no override behavior was taken. Hopefully we can safely ignore this request. const struct wl_interface *created = get_interface_of_object_created_by_request(proxy, opcode, interface); if (created) { // We need to create a stub object to make the client happy, it will ignore all requests and represents // nothing in libwayland/the server return libwayland_shim_create_client_proxy (proxy, created, created->version, NULL, NULL, NULL); } else { // Ignore the request return NULL; } } else { // Forward the request on to libwayland without modification, this is the most common path return libwayland_shim_real_wl_proxy_marshal_array_flags (proxy, opcode, interface, version, flags, args); } } } // Overrides the function in wayland-client.c in libwayland struct wl_proxy * wl_proxy_marshal_flags(struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, ...) { union wl_argument args[WL_CLOSURE_MAX_ARGS]; va_list ap; va_start(ap, flags); wl_argument_from_va_list(proxy->object.interface->methods[opcode].signature, args, WL_CLOSURE_MAX_ARGS, ap); va_end(ap); return wl_proxy_marshal_array_flags(proxy, opcode, interface, version, flags, args); } // Overrides the function in wayland-client.c in libwayland void wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...) { union wl_argument args[WL_CLOSURE_MAX_ARGS]; va_list ap; va_start(ap, opcode); wl_argument_from_va_list(proxy->object.interface->methods[opcode].signature, args, WL_CLOSURE_MAX_ARGS, ap); va_end(ap); wl_proxy_marshal_array_constructor(proxy, opcode, args, NULL); } // Overrides the function in wayland-client.c in libwayland void wl_proxy_marshal_array(struct wl_proxy *proxy, uint32_t opcode, union wl_argument *args) { wl_proxy_marshal_array_constructor(proxy, opcode, args, NULL); } // Overrides the function in wayland-client.c in libwayland struct wl_proxy * wl_proxy_marshal_constructor(struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, ...) { union wl_argument args[WL_CLOSURE_MAX_ARGS]; va_list ap; va_start(ap, interface); wl_argument_from_va_list(proxy->object.interface->methods[opcode].signature, args, WL_CLOSURE_MAX_ARGS, ap); va_end(ap); return wl_proxy_marshal_array_constructor(proxy, opcode, args, interface); } // Overrides the function in wayland-client.c in libwayland struct wl_proxy * wl_proxy_marshal_constructor_versioned(struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, ...) { union wl_argument args[WL_CLOSURE_MAX_ARGS]; va_list ap; va_start(ap, version); wl_argument_from_va_list(proxy->object.interface->methods[opcode].signature, args, WL_CLOSURE_MAX_ARGS, ap); va_end(ap); return wl_proxy_marshal_array_constructor_versioned(proxy, opcode, args, interface, version); } // Overrides the function in wayland-client.c in libwayland struct wl_proxy * wl_proxy_marshal_array_constructor(struct wl_proxy *proxy, uint32_t opcode, union wl_argument *args, const struct wl_interface *interface) { return wl_proxy_marshal_array_constructor_versioned(proxy, opcode, args, interface, proxy->version); } // Overrides the function in wayland-client.c in libwayland struct wl_proxy * wl_proxy_marshal_array_constructor_versioned(struct wl_proxy *proxy, uint32_t opcode, union wl_argument *args, const struct wl_interface *interface, uint32_t version) { return wl_proxy_marshal_array_flags(proxy, opcode, interface, version, 0, args); } // Overrides the function in wayland-client.c in libwayland int wl_proxy_add_dispatcher(struct wl_proxy *proxy, wl_dispatcher_func_t dispatcher_func, const void * dispatcher_data, void *data) { libwayland_shim_init (); if (proxy->object.id == client_facing_proxy_id) { g_critical ("wl_proxy_add_dispatcher () not supported for client-facing proxies"); } return libwayland_shim_real_wl_proxy_add_dispatcher(proxy, dispatcher_func, dispatcher_data, data); } gtk4-layer-shell-1.0.4/src/libwayland-shim.h000066400000000000000000000033371471230641700206430ustar00rootroot00000000000000#ifndef LIBWAYLAND_SHIM_H #define LIBWAYLAND_SHIM_H #include #include #define LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT(listener, proxy, event, ...) \ if (((struct wl_proxy*)proxy)->object.implementation) { \ ((struct listener *)((struct wl_proxy*)proxy)->object.implementation)->event( \ ((struct wl_proxy*)proxy)->user_data, __VA_ARGS__); } // From wayland-private.h in libwayland struct wl_object { const struct wl_interface *interface; const void *implementation; uint32_t id; }; // From wayland-client.c in libwayland struct wl_proxy { struct wl_object object; struct wl_display *display; struct wl_event_queue *queue; uint32_t flags; int refcount; void *user_data; wl_dispatcher_func_t dispatcher; uint32_t version; const char * const *tag; struct wl_list queue_link; // appears in wayland 1.22 }; typedef struct wl_proxy *(*libwayland_shim_client_proxy_handler_func_t) ( void* data, struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, union wl_argument *args); typedef void (*libwayland_shim_client_proxy_destroy_func_t) ( void* data, struct wl_proxy *proxy); gboolean libwayland_shim_has_initialized (); struct wl_proxy *libwayland_shim_create_client_proxy ( struct wl_proxy *factory, const struct wl_interface *interface, uint32_t version, libwayland_shim_client_proxy_handler_func_t handler, libwayland_shim_client_proxy_destroy_func_t destroy, void* data); void libwayland_shim_clear_client_proxy_data (struct wl_proxy *proxy); void *libwayland_shim_get_client_proxy_data (struct wl_proxy *proxy, void* expected_handler); #endif // LIBWAYLAND_SHIM_H gtk4-layer-shell-1.0.4/src/meson.build000066400000000000000000000032411471230641700175420ustar00rootroot00000000000000srcs = files( 'api.c', 'libwayland-shim.c', 'layer-surface.c', 'wayland-utils.c') version_args = [ '-DGTK_LAYER_SHELL_MAJOR=' + meson.project_version().split('.')[0], '-DGTK_LAYER_SHELL_MINOR=' + meson.project_version().split('.')[1], '-DGTK_LAYER_SHELL_MICRO=' + meson.project_version().split('.')[2], ] gtk_layer_shell_lib = library('gtk4-layer-shell', srcs, client_protocol_srcs, c_args: version_args, include_directories: [gtk_layer_shell_inc], dependencies: [gtk, wayland_client], version: meson.project_version(), soversion: lib_so_version, install: true) pkg_config_name = 'gtk4-layer-shell-0' # GObject introspection file used to interface with other languages if get_option('introspection') gir = gnome.generate_gir( gtk_layer_shell_lib, dependencies: [gtk], sources: srcs + files('../include/gtk4-layer-shell.h'), namespace: 'Gtk4LayerShell', nsversion: '1.0', identifier_prefix: 'GtkLayerShell', symbol_prefix: 'gtk_layer', export_packages: pkg_config_name, includes: [ 'Gtk-4.0' ], header: 'gtk4-layer-shell.h', install: true) if get_option('vapi') vapi = gnome.generate_vapi( pkg_config_name, sources: gir[0], packages: 'gtk4', install: true) endif endif pkg_config.generate( name: 'gtk4-layer-shell', version: meson.project_version(), libraries: [gtk_layer_shell_lib], filebase: pkg_config_name, subdirs: 'gtk4-layer-shell', description: 'Use the Layer Shell Wayland protocol with GTK4', url: 'https://github.com/wmww/gtk4-layer-shell') gtk4-layer-shell-1.0.4/src/wayland-utils.c000066400000000000000000000135011471230641700203410ustar00rootroot00000000000000#include "wayland-utils.h" #include #include #include static struct wl_registry *wl_registry_global = NULL; static struct zwlr_layer_shell_v1 *layer_shell_global = NULL; static gboolean has_initialized = FALSE; struct zwlr_layer_shell_v1 * gtk_wayland_get_layer_shell_global () { return layer_shell_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 >= 3); layer_shell_global = wl_registry_bind (registry, id, &zwlr_layer_shell_v1_interface, MIN((uint32_t)zwlr_layer_shell_v1_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; } static const struct wl_registry_listener wl_registry_listener = { .global = wl_registry_handle_global, .global_remove = wl_registry_handle_global_remove, }; void gtk_wayland_init_if_needed () { if (has_initialized) return; gtk_init (); 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"); has_initialized = TRUE; } 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; } gtk4-layer-shell-1.0.4/src/wayland-utils.h000066400000000000000000000015451471230641700203530ustar00rootroot00000000000000#ifndef WAYLAND_UTILS_H #define WAYLAND_UTILS_H #include "xdg-shell-client.h" #include "wlr-layer-shell-unstable-v1-client.h" #include "gtk4-layer-shell.h" #include #include void gtk_wayland_init_if_needed (void); struct zwlr_layer_shell_v1 *gtk_wayland_get_layer_shell_global (void); 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 // WAYLAND_UTILS_H gtk4-layer-shell-1.0.4/test/000077500000000000000000000000001471230641700155705ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/test/README.md000066400000000000000000000072121471230641700170510ustar00rootroot00000000000000# GTK Layer Shell tests This directory is home to the gtk4-layer-shell test suite. ## To run tests `ninja -C build test` (where `build` is the path to your build directory). ### To add a new integration test 1. Copy an existing integration test file 2. Implement your test as a series of one or more callbacks 3. Add its name to the list in `test/integration-tests/meson.build` ## Scripts - `tests-not-enabled.py` is only run if tests are disabled, and explains to the user how to enable them - `run-integration-test.py` runs a single integration test - `check-all-tests-are-in-meson.py` fails if any test files exist that haven't been added to meson (an easy mistake to make) ## Integration tests Most of the potential bugs in GTK Layer Shell arise from interactions between the library, GTK and the Wayland compositor, so unit tests aren't particularly useful. Instead, most of our tests are integration tests. ### Integration test app Each integration test is a single unique GTK app that uses GTK Layer Shell. All test clients are located in `integration-tests`. Anything common to multiple tests gets pulled into `integration-test-common` or `test-common`. Tests consist of a sequence of callbacks. At the start of each callback the app can state that specific Wayland messages should be sent during or after the callback is run (see expectations format below). Each meson test runs a single integration test. Integration tests can be run directly on a normal Wayland compositor (this may be useful for debugging). When run without arguments, they open an additional layer shell window with a `Continue ->` button to manually advance the test. Pass `--auto` to run each test callback with a timeout the way they are run when automated. ### Expectations format Integration tests emit protocol expectations by using the `EXPECT_MESSAGE` macro. Each expectation is a white-space-separated sequence of tokens written to a line of stdout. The first element must be `EXPECT:` (this is automatically inserted by `EXPECT_MESSAGE`). For an expectation to match a message, each following token must appear in order in the message line. The list of expected messages must match in the correct order. Messages are matched against the output of the app run with `WAYLAND_DEBUG=1`. Events and requests are not distinguished. When the script encounters `CHECK EXPECTATIONS COMPLETED` (emitted by the `CHECK_EXPECTATIONS()` macro), it will assert that all previous expectations have been met. This is emitted automatically at the start of each test callback. ### Test runner `ninja -C build test` will run `run-integration-test.py` for each test defined in `test/meson.build`. This script: - Creates a temporary directory in `/tmp` to serve as `XDG_RUNTIME_DIR` (this allows tests to run in parallel without interfering with each other) - Spins up a mock Wayland server - Runs the given integration test within it - (Both are run with `WAYLAND_DEBUG=1` so protocol messages are written to stderr by libwayland) - Ensures both the client and server exit successfully - Parses the client's protocol message expectations - Ensures they match the protocol messages generated by libwayland ### Mock server Rather than running the integration tests in an external Wayland compositor, we implement our own mock Wayland compositor (located in `mock-server`). This doesn't show anything on-screen or get real user input, it simply gives the required responses to protocol messages. It's only dependency is libwayland. It implements most of the protocol with a single default dispatcher. This reads the message signature and takes whatever action appears to be required. The behavior of some messages is overridden in `overrides.c`. gtk4-layer-shell-1.0.4/test/check-all-tests-are-in-meson.py000077500000000000000000000025061471230641700234230ustar00rootroot00000000000000#!/usr/bin/python3 # Tests need to be added to meson.build. This script makes sure they are. import os from os import path import logging logger = logging.getLogger(__name__) logging.basicConfig(level=logging.WARNING) dead_tests = [] def check_dir(dir_path): logger.info('checking ' + dir_path) assert path.isdir(dir_path) meson_path = path.join(dir_path, 'meson.build') assert path.isfile(meson_path) with open(meson_path, 'r') as f: meson = f.read() for filename in os.listdir(dir_path): root, ext = path.splitext(filename) if root.startswith('test-'): search_str = "'" + root + "'" if search_str in meson: logger.info(search_str + ' is in meson') else: logger.info(search_str + ' is not in meson') dead_tests.append(path.join(dir_path, filename)) else: logger.info(filename + ' ignored') if __name__ == '__main__': test_dir = path.dirname(path.realpath(__file__)) check_dir(path.join(test_dir, 'integration-tests')) check_dir(path.join(test_dir, 'smoke-tests')) check_dir(path.join(test_dir, 'unit-tests')) if dead_tests: print('The following test(s) have not been added to meson:') for test in dead_tests: print(' ' + test) exit(1) gtk4-layer-shell-1.0.4/test/integration-test-common/000077500000000000000000000000001471230641700223565ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/test/integration-test-common/integration-test-common.c000066400000000000000000000045741471230641700273220ustar00rootroot00000000000000#include "integration-test-common.h" int step_time = 300; static int return_code = 0; static int callback_index = 0; static gboolean auto_continue = FALSE; static gboolean next_step(gpointer _data) { (void)_data; CHECK_EXPECTATIONS(); if (test_callbacks[callback_index]) { test_callbacks[callback_index](); callback_index++; if (auto_continue) g_timeout_add(step_time, next_step, NULL); } else { while (g_list_model_get_n_items(gtk_window_get_toplevels()) > 0) gtk_window_destroy(g_list_model_get_item(gtk_window_get_toplevels(), 0)); } return FALSE; } GtkWindow* create_default_window() { GtkWindow* window = GTK_WINDOW(gtk_window_new()); GtkWidget *label = gtk_label_new(""); gtk_label_set_markup( GTK_LABEL(label), "" "Layer shell test" ""); gtk_window_set_child(window, label); return window; } static void continue_button_callback(GtkWidget *_widget, gpointer _data) { (void)_widget; (void)_data; next_step(NULL); } static void create_debug_control_window() { // Make a window with a continue button for debugging GtkWindow *window = GTK_WINDOW(gtk_window_new()); gtk_layer_init_for_window(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM, 200); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_OVERLAY); GtkWidget* button = gtk_button_new_with_label("Continue ->"); g_signal_connect (button, "clicked", G_CALLBACK(continue_button_callback), NULL); gtk_window_set_child(window, button); gtk_window_present(window); // This will only be called once, so leaking the window is fine } int main(int argc, char** argv) { EXPECT_MESSAGE(wl_display .get_registry); gtk_init(); if (argc == 1) { // Run with a debug mode window that lets the user advance manually create_debug_control_window(); } else if (argc == 2 && g_strcmp0(argv[1], "--auto") == 0) { // Run normally with a timeout auto_continue = TRUE; } else { g_critical("Invalid arguments to integration test"); return 1; } next_step(NULL); while (g_list_model_get_n_items(gtk_window_get_toplevels()) > 0) g_main_context_iteration(NULL, TRUE); return return_code; } gtk4-layer-shell-1.0.4/test/integration-test-common/integration-test-common.h000066400000000000000000000022741471230641700273220ustar00rootroot00000000000000#ifndef TEST_CLIENT_COMMON_H #define TEST_CLIENT_COMMON_H #include "gtk4-layer-shell.h" #include "test-common.h" #include #include #include #include // Time in milliseconds for each callback to run extern int step_time; // Tell the test script that a request containing the given space-separated components is expected #define EXPECT_MESSAGE(message) fprintf(stderr, "EXPECT: %s\n", #message) // Tell the test script this request is not expected #define DONT_EXPECT_MESSAGE(message) fprintf(stderr, "DONT_EXPECT: %s\n", #message) // Tell the test script that all expected messages should now be fulfilled // (called automatically before each callback and at the end of the test) #define CHECK_EXPECTATIONS() fprintf(stderr, "CHECK EXPECTATIONS COMPLETED\n") // NULL-terminated list of callbacks that will be called before quitting // Should be defined in the test file using TEST_CALLBACKS() extern void (* test_callbacks[])(void); // Input is a sequence of callback names with a trailing comma #define TEST_CALLBACKS(...) void (* test_callbacks[])(void) = {__VA_ARGS__ NULL}; GtkWindow* create_default_window(); #endif // TEST_CLIENT_COMMON_H gtk4-layer-shell-1.0.4/test/integration-test-common/meson.build000066400000000000000000000002631471230641700245210ustar00rootroot00000000000000integration_test_common = declare_dependency( dependencies: [test_common], include_directories: include_directories('.'), sources: files('integration-test-common.c')) gtk4-layer-shell-1.0.4/test/integration-tests/000077500000000000000000000000001471230641700212535ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/test/integration-tests/meson.build000066400000000000000000000020171471230641700234150ustar00rootroot00000000000000integration_tests = [ 'test-is-supported-true', 'test-layer-surface-not-created', 'test-creation-properties', 'test-is-layer-window', 'test-single-anchors', 'test-multi-anchors', 'test-set-anchor-normalizes-booleans', 'test-set-layer', 'test-get-layer', 'test-set-margin', 'test-get-margin', 'test-set-default-size', 'test-adapts-to-screen-size', 'test-auto-exclusive-zone-no-margin', 'test-auto-exclusive-zone-with-margin', 'test-auto-exclusive-zone-weird-bool-values', 'test-get-explicit-exclusive-zone', 'test-get-auto-exclusive-zone', 'test-exclusive-zone-below-negative-1', 'test-menu-popup', 'test-close-layer-surface', 'test-get-namespace-default', 'test-get-namespace-on-non-layer-window', 'test-get-namespace-custom-namespace', 'test-set-keyboard-mode', 'test-get-keyboard-mode', 'test-get-monitor', 'test-set-monitor', 'test-create-xdg-toplevel', 'test-hide-and-show', 'test-init-after-window-created', ] gtk4-layer-shell-1.0.4/test/integration-tests/test-adapts-to-screen-size.c000066400000000000000000000024761471230641700265260ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 0 0); EXPECT_MESSAGE(.create_buffer 1920 1080); // size must match DEFAULT_OUTPUT_WIDTH/DEFAULT_OUTPUT_HEIGHT in common.h window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BOTTOM); gtk_layer_set_namespace(window, "foobar"); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); gtk_window_set_default_size(window, 600, 700); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(.create_buffer 600 1080); // size must match DEFAULT_OUTPUT_HEIGHT in common.h EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 600 0); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, FALSE); } static void callback_2() { EXPECT_MESSAGE(.create_buffer 600 700); EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 600 700); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); } TEST_CALLBACKS( callback_0, callback_1, callback_2, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-auto-exclusive-zone-no-margin.c000066400000000000000000000027521471230641700302150ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { // First, anchor to bottom EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 200); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_auto_exclusive_zone_enable(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_window_set_default_size(window, 300, 200); gtk_window_present(window); } static void callback_1() { // Resize EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 240); gtk_window_set_default_size(window, 320, 240); } static void callback_2() { // Streatch across left edge EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 320); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE); } static void callback_3() { // Stretch across top EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 240); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); } static void callback_4() { // Anchor right EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 320); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, FALSE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, FALSE); } TEST_CALLBACKS( callback_0, callback_1, callback_2, callback_3, callback_4, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-auto-exclusive-zone-weird-bool-values.c000066400000000000000000000014111471230641700316550ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 300); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_auto_exclusive_zone_enable(window); // Note that true bools are normally 1, but can be other non-zero values // This used to cause a problem, as noted in https://github.com/wmww/gtk-layer-shell/pull/79 gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, 1); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, 2); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, 3); gtk_window_set_default_size(window, 300, 200); gtk_window_present(window); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-auto-exclusive-zone-with-margin.c000066400000000000000000000014441471230641700305510ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 240); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_auto_exclusive_zone_enable(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_window_set_default_size(window, 320, 240); gtk_window_present(window); } static void callback_1() { // Bottom margin should have no effect on exclusive zone but top margin should EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 250); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_TOP, 10); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM, 5); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-close-layer-surface.c000066400000000000000000000006271471230641700262460ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .destroy); EXPECT_MESSAGE(wl_surface .destroy); gtk_window_close(window); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-create-xdg-toplevel.c000066400000000000000000000021341471230641700262470ustar00rootroot00000000000000#include "integration-test-common.h" static void callback_0() { EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface); EXPECT_MESSAGE(xdg_surface .get_toplevel); EXPECT_MESSAGE(xdg_toplevel .configure); EXPECT_MESSAGE(xdg_surface .configure); EXPECT_MESSAGE(xdg_surface .ack_configure); GtkWindow* window = create_default_window(); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface); EXPECT_MESSAGE(zwlr_layer_surface_v1 .configure); EXPECT_MESSAGE(zwlr_layer_surface_v1 .ack_configure); GtkWindow* window = create_default_window(); gtk_layer_init_for_window(window); gtk_window_present(window); } static void callback_2() { EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface); EXPECT_MESSAGE(xdg_surface .get_toplevel); EXPECT_MESSAGE(xdg_toplevel .configure); EXPECT_MESSAGE(xdg_surface .configure); EXPECT_MESSAGE(xdg_surface .ack_configure); GtkWindow* window = create_default_window(); gtk_window_present(window); } TEST_CALLBACKS( callback_0, callback_1, callback_2, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-creation-properties.c000066400000000000000000000012561471230641700263760ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BOTTOM); gtk_layer_set_namespace(window, "foobar"); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_layer_set_exclusive_zone(window, 32); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface 1 "foobar"); EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone 32); EXPECT_MESSAGE(wl_surface .commit); gtk_window_present(window); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-exclusive-zone-below-negative-1.c000066400000000000000000000010131471230641700304130ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_exclusive_zone -1); EXPECT_MESSAGE(wl_surface .commit); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_window_present(window); gtk_layer_set_exclusive_zone(window, -2); ASSERT_EQ(gtk_layer_get_exclusive_zone(window), -1, "%d"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-auto-exclusive-zone.c000066400000000000000000000017211471230641700271000ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_window_set_default_size(window, 300, 200); gtk_layer_init_for_window(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); ASSERT(!gtk_layer_auto_exclusive_zone_is_enabled(window)); gtk_layer_auto_exclusive_zone_enable(window); ASSERT(gtk_layer_auto_exclusive_zone_is_enabled(window)); gtk_window_present(window); } static void callback_1() { ASSERT_EQ(gtk_layer_get_exclusive_zone(window), 200, "%d"); gtk_window_set_default_size(window, 320, 240); } static void callback_2() { ASSERT_EQ(gtk_layer_get_exclusive_zone(window), 240, "%d"); ASSERT(gtk_layer_auto_exclusive_zone_is_enabled(window)); gtk_layer_set_exclusive_zone(window, 20); ASSERT(!gtk_layer_auto_exclusive_zone_is_enabled(window)); } TEST_CALLBACKS( callback_0, callback_1, callback_2, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-explicit-exclusive-zone.c000066400000000000000000000013651471230641700277550ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); ASSERT_EQ(gtk_layer_get_exclusive_zone(window), 0, "%d"); gtk_layer_set_exclusive_zone(window, 12); ASSERT_EQ(gtk_layer_get_exclusive_zone(window), 12, "%d"); gtk_window_present(window); ASSERT_EQ(gtk_layer_get_exclusive_zone(window), 12, "%d"); gtk_layer_set_exclusive_zone(window, 0); ASSERT_EQ(gtk_layer_get_exclusive_zone(window), 0, "%d"); gtk_layer_set_exclusive_zone(window, -1); ASSERT_EQ(gtk_layer_get_exclusive_zone(window), -1, "%d"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-keyboard-mode.c000066400000000000000000000014311471230641700256720ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); ASSERT_EQ(gtk_layer_get_keyboard_mode(window), GTK_LAYER_SHELL_KEYBOARD_MODE_NONE, "%d"); gtk_layer_set_keyboard_mode(window, GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND); ASSERT_EQ(gtk_layer_get_keyboard_mode(window), GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND, "%d"); gtk_window_present(window); ASSERT_EQ(gtk_layer_get_keyboard_mode(window), GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND, "%d"); gtk_layer_set_keyboard_mode(window, GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE); ASSERT_EQ(gtk_layer_get_keyboard_mode(window), GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE, "%d"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-layer.c000066400000000000000000000014561471230641700242730ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_OVERLAY); ASSERT_EQ(gtk_layer_get_layer(window), GTK_LAYER_SHELL_LAYER_OVERLAY, "%d"); gtk_window_present(window); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_TOP); ASSERT_EQ(gtk_layer_get_layer(window), GTK_LAYER_SHELL_LAYER_TOP, "%d"); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BACKGROUND); ASSERT_EQ(gtk_layer_get_layer(window), GTK_LAYER_SHELL_LAYER_BACKGROUND, "%d"); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BOTTOM); ASSERT_EQ(gtk_layer_get_layer(window), GTK_LAYER_SHELL_LAYER_BOTTOM, "%d"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-margin.c000066400000000000000000000033061471230641700244300ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, TRUE); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_TOP, 2); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_RIGHT, 6); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM, 12); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_LEFT, 14); gtk_window_present(window); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_TOP), 2, "%d"); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_RIGHT), 6, "%d"); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM), 12, "%d"); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_LEFT), 14, "%d"); } static void callback_1() { gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_TOP, 5); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_RIGHT, 10); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM, 25); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_LEFT, 30); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_TOP), 5, "%d"); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_RIGHT), 10, "%d"); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM), 25, "%d"); ASSERT_EQ(gtk_layer_get_margin(window, GTK_LAYER_SHELL_EDGE_LEFT), 30, "%d"); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-monitor.c000066400000000000000000000014461471230641700246450ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); ASSERT_EQ(g_list_model_get_n_items(gdk_display_get_monitors(gdk_display_get_default())), 1, "%d"); GdkMonitor *monitor = g_list_model_get_item(gdk_display_get_monitors(gdk_display_get_default()), 0); ASSERT(GDK_IS_MONITOR(monitor)); ASSERT_EQ(gtk_layer_get_monitor(window), NULL, "%p"); gtk_layer_set_monitor(window, monitor); ASSERT_EQ(gtk_layer_get_monitor(window), monitor, "%p"); gtk_window_present(window); ASSERT_EQ(gtk_layer_get_monitor(window), monitor, "%p"); gtk_layer_set_monitor(window, NULL); ASSERT_EQ(gtk_layer_get_monitor(window), NULL, "%p"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-namespace-custom-namespace.c000066400000000000000000000006041471230641700303470ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_namespace(window, "foobar"); gtk_window_present(window); const char *name_space = gtk_layer_get_namespace(window); ASSERT_STR_EQ(name_space, "foobar"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-namespace-default.c000066400000000000000000000005371471230641700265340ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_window_present(window); const char *name_space = gtk_layer_get_namespace(window); ASSERT_STR_EQ(name_space, "gtk4-layer-shell"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-get-namespace-on-non-layer-window.c000066400000000000000000000004301471230641700307230ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); const char *name_space = gtk_layer_get_namespace(window); ASSERT_STR_EQ(name_space, "gtk4-layer-shell"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-hide-and-show.c000066400000000000000000000012201471230641700250160ustar00rootroot00000000000000#include "integration-test-common.h" GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .destroy); gtk_widget_set_visible(GTK_WIDGET(window), FALSE); } static void callback_2() { EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface); EXPECT_MESSAGE(zwlr_layer_surface_v1 .configure); EXPECT_MESSAGE(zwlr_layer_surface_v1 .ack_configure); gtk_widget_set_visible(GTK_WIDGET(window), TRUE); } TEST_CALLBACKS( callback_0, callback_1, callback_2, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-init-after-window-created.c000066400000000000000000000010041471230641700273430ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface); EXPECT_MESSAGE(wl_surface .commit); window = create_default_window(); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(xdg_surface .destroy); EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_init_for_window(window); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-is-layer-window.c000066400000000000000000000011231471230641700254230ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window_a; static GtkWindow* window_b; static void callback_0() { window_a = create_default_window(); window_b = create_default_window(); gtk_layer_init_for_window(window_a); ASSERT(gtk_layer_is_layer_window(window_a)); ASSERT(!gtk_layer_is_layer_window(window_b)); gtk_window_present(window_a); gtk_window_present(window_b); } static void callback_1() { ASSERT(gtk_layer_is_layer_window(window_a)); ASSERT(!gtk_layer_is_layer_window(window_b)); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-is-supported-true.c000066400000000000000000000002621471230641700260070ustar00rootroot00000000000000#include "integration-test-common.h" static void callback_0() { ASSERT(gtk_layer_is_supported()); ASSERT(gtk_layer_is_supported()); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-layer-surface-not-created.c000066400000000000000000000004601471230641700273410ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow *window; static void callback_0() { DONT_EXPECT_MESSAGE(.get_layer_surface zwlr_layer_shell_v1); window = create_default_window(); gtk_layer_init_for_window(window); gtk_window_present(window); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-menu-popup.c000066400000000000000000000014551471230641700245060ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow *window; static GtkWidget *dropdown; static const char *options[] = {"Foo", "Bar", "Baz", NULL}; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface); // The popup is weirdly slow to open, so slow the tests down step_time = 600; window = GTK_WINDOW(gtk_window_new()); dropdown = gtk_drop_down_new_from_strings(options); gtk_window_set_child(window, dropdown); gtk_layer_init_for_window(window); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface); EXPECT_MESSAGE(xdg_surface .get_popup); EXPECT_MESSAGE(xdg_popup .grab); g_signal_emit_by_name (dropdown, "activate", NULL); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-multi-anchors.c000066400000000000000000000030151471230641700251600ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void set_anchors(GtkWindow* window, gboolean top, gboolean bottom, gboolean left, gboolean right) { gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, top); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, bottom); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, left); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, right); } static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 0); EXPECT_MESSAGE(wl_surface .commit); window = create_default_window(); gtk_layer_init_for_window(window); gtk_window_present(window); set_anchors(window, FALSE, FALSE, FALSE, FALSE); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 3); EXPECT_MESSAGE(wl_surface .commit); set_anchors(window, TRUE, TRUE, FALSE, FALSE); } static void callback_2() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 13); EXPECT_MESSAGE(wl_surface .commit); set_anchors(window, TRUE, FALSE, TRUE, TRUE); } static void callback_3() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 15); EXPECT_MESSAGE(wl_surface .commit); set_anchors(window, TRUE, TRUE, TRUE, TRUE); } static void callback_4() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 0); EXPECT_MESSAGE(wl_surface .commit); set_anchors(window, FALSE, FALSE, FALSE, FALSE); } TEST_CALLBACKS( callback_0, callback_1, callback_2, callback_3, callback_4, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-set-anchor-normalizes-booleans.c000066400000000000000000000012431471230641700304200ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, 1); ASSERT_EQ(gtk_layer_get_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT), 1, "%d"); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, 2); ASSERT_EQ(gtk_layer_get_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT), 1, "%d"); gtk_window_present(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, -1); ASSERT_EQ(gtk_layer_get_anchor(window, GTK_LAYER_SHELL_EDGE_TOP), 1, "%d"); } TEST_CALLBACKS( callback_0, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-set-default-size.c000066400000000000000000000036041471230641700255640ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 0 0); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BOTTOM); gtk_layer_set_namespace(window, "foobar"); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 600 700); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, FALSE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, FALSE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); gtk_window_set_default_size(window, 600, 700); } static void callback_2() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 0 700); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); } static void callback_3() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 0 0); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, TRUE); } static void callback_4() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 600 0); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); } TEST_CALLBACKS( callback_0, callback_1, callback_2, callback_3, callback_4, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-set-keyboard-mode.c000066400000000000000000000015421471230641700257110ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_keyboard_interactivity 1); EXPECT_MESSAGE(wl_surface .commit); EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_keyboard_interactivity 0); EXPECT_MESSAGE(wl_surface .commit); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_keyboard_mode(window, GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE); gtk_window_present(window); gtk_layer_set_keyboard_mode(window, GTK_LAYER_SHELL_KEYBOARD_MODE_NONE); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_keyboard_interactivity 2); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_keyboard_mode(window, GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-set-layer.c000066400000000000000000000020001471230641700242710ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface 2); EXPECT_MESSAGE(wl_surface .commit); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_TOP); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_layer 3); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_OVERLAY); } static void callback_2() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_layer 0); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BACKGROUND); } static void callback_3() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_layer 1); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BOTTOM); } TEST_CALLBACKS( callback_0, callback_1, callback_2, callback_3, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-set-margin.c000066400000000000000000000024121471230641700244410ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_margin 2 6 12 14); EXPECT_MESSAGE(wl_surface .commit); window = create_default_window(); gtk_layer_init_for_window(window); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, TRUE); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_TOP, 2); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_RIGHT, 6); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM, 12); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_LEFT, 14); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_margin 5 10 25 30); EXPECT_MESSAGE(wl_surface .commit); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_TOP, 5); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_RIGHT, 10); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_BOTTOM, 25); gtk_layer_set_margin(window, GTK_LAYER_SHELL_EDGE_LEFT, 30); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-set-monitor.c000066400000000000000000000013541471230641700246570ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void callback_0() { EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface wl_output); window = create_default_window(); gtk_layer_init_for_window(window); ASSERT_EQ(g_list_model_get_n_items(gdk_display_get_monitors(gdk_display_get_default())), 1, "%d"); GdkMonitor *monitor = g_list_model_get_item(gdk_display_get_monitors(gdk_display_get_default()), 0); ASSERT(GDK_IS_MONITOR(monitor)); gtk_layer_set_monitor(window, monitor); gtk_window_present(window); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface nil); gtk_layer_set_monitor(window, NULL); } TEST_CALLBACKS( callback_0, callback_1, ) gtk4-layer-shell-1.0.4/test/integration-tests/test-single-anchors.c000066400000000000000000000025141471230641700253120ustar00rootroot00000000000000#include "integration-test-common.h" static GtkWindow* window; static void set_anchors(GtkWindow* window, gboolean top, gboolean bottom, gboolean left, gboolean right) { gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, top); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, bottom); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, left); gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, right); } static void callback_0() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 1); EXPECT_MESSAGE(wl_surface .commit); window = create_default_window(); gtk_layer_init_for_window(window); gtk_window_present(window); set_anchors(window, TRUE, FALSE, FALSE, FALSE); } static void callback_1() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 2); EXPECT_MESSAGE(wl_surface .commit); set_anchors(window, FALSE, TRUE, FALSE, FALSE); } static void callback_2() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 4); EXPECT_MESSAGE(wl_surface .commit); set_anchors(window, FALSE, FALSE, TRUE, FALSE); } static void callback_3() { EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_anchor 8); EXPECT_MESSAGE(wl_surface .commit); set_anchors(window, FALSE, FALSE, FALSE, TRUE); } TEST_CALLBACKS( callback_0, callback_1, callback_2, callback_3, ) gtk4-layer-shell-1.0.4/test/meson.build000066400000000000000000000026471471230641700177430ustar00rootroot00000000000000subdir('test-common') subdir('mock-server') subdir('integration-test-common') subdir('integration-tests') subdir('unit-tests') py = find_program('python3') run_test_script = files(meson.current_source_dir() + '/run-integration-test.py') env = environment() env.set('GTK4_LAYER_SHELL_BUILD', meson.build_root()) foreach integration_test : integration_tests integration_test_srcs = files('integration-tests/' + integration_test + '.c') exe = executable( integration_test, integration_test_srcs, dependencies: [gtk, wayland_client, gtk_layer_shell, integration_test_common]) test( 'integration-' + integration_test, py, workdir: meson.current_source_dir(), env: env, args: [ run_test_script, meson.current_build_dir() + '/' + integration_test, ]) endforeach if get_option('smoke-tests') subdir('smoke-tests') foreach smoke_test : smoke_tests test( 'smoke-' + smoke_test, py, workdir: meson.current_source_dir(), env: env, args: [ run_test_script, meson.current_source_dir() + '/smoke-tests/' + smoke_test + '.py', ]) endforeach endif check_tests_in_meson_script = files(meson.current_source_dir() + '/check-all-tests-are-in-meson.py') test('check-all-tests-are-in-meson', py, args: [check_tests_in_meson_script]) gtk4-layer-shell-1.0.4/test/mock-server/000077500000000000000000000000001471230641700200255ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/test/mock-server/meson.build000066400000000000000000000004111471230641700221630ustar00rootroot00000000000000mock_server_srcs = files( 'mock-server.h', 'mock-server.c', 'overrides.c') mock_server = executable( 'mock-server', mock_server_srcs, server_protocol_srcs, c_args: ['-Wno-unused-parameter'], dependencies: [wayland_server, test_common]) gtk4-layer-shell-1.0.4/test/mock-server/mock-server.c000066400000000000000000000103411471230641700224250ustar00rootroot00000000000000#include "mock-server.h" struct wl_display* display = NULL; void* alloc_zeroed(size_t size) { void* data = malloc(size); memset(data, 0, size); return data; } static const char* get_display_name() { const char* result = getenv("WAYLAND_DISPLAY"); if (!result) { FATAL("WAYLAND_DISPLAY not set"); } return result; } typedef struct { const struct wl_message* message; RequestOverrideFunction function; struct wl_list link; } RequestOverride; struct wl_list request_overrides; void install_request_override(const struct wl_interface* interface, const char* name, RequestOverrideFunction function) { for (int i = 0; i < interface->method_count; i++) { if (strcmp(name, interface->methods[i].name) == 0) { RequestOverride* override = ALLOC_STRUCT(RequestOverride); override->message = &interface->methods[i]; override->function = function; wl_list_insert(&request_overrides, &override->link); return; } } FATAL_FMT("Interface %s does not have a request named %s", interface->name, name); } static int default_dispatcher(const void* data, void* resource, uint32_t opcode, const struct wl_message* message, union wl_argument* args) { // First, check if there is an override RequestOverride* override; wl_list_for_each(override, &request_overrides, link) { if (override->message == message) { override->function(resource, message, args); return 0; } } // If there are any new-id type arguments, resources need to be created for them // See https://wayland.freedesktop.org/docs/html/apb.html#Client-structwl__message int arg = 0; for (const char* c = message->signature; *c; c++) { if (*c == 'n' && args[arg].n != 0) { struct wl_resource* new_resource = wl_resource_create( wl_resource_get_client(resource), message->types[arg], wl_resource_get_version(resource), args[arg].n); wl_resource_set_dispatcher(new_resource, default_dispatcher, NULL, NULL, NULL); } if (*c >= 'a' && *c <= 'z') arg++; } if (strcmp(message->name, "destroy") == 0) { wl_resource_destroy(resource); } return 0; } void use_default_impl(struct wl_resource* resource) { wl_resource_set_dispatcher(resource, default_dispatcher, NULL, NULL, NULL); } static void default_global_bind(struct wl_client* client, void* data, uint32_t version, uint32_t id) { struct wl_interface* interface = data; struct wl_resource* resource = wl_resource_create(client, interface, version, id); use_default_impl(resource); }; void default_global_create(struct wl_display* display, const struct wl_interface* interface, int version) { wl_global_create(display, interface, version, (void*)interface, default_global_bind); } char type_code_at_index(const struct wl_message* message, int index) { int i = 0; for (const char* c = message->signature; *c; c++) { if (*c >= 'a' && *c <= 'z') { if (i == index) return *c; else i++; } } FATAL_FMT(".%s does not have an argument %d", message->name, index); } static void client_disconnect(struct wl_listener *listener, void *data) { wl_display_terminate(display); } static struct wl_listener client_disconnect_listener = { .notify = client_disconnect, }; static void client_connect(struct wl_listener *listener, void *data) { struct wl_client* client = (struct wl_client*)data; wl_client_add_destroy_listener(client, &client_disconnect_listener); } static struct wl_listener client_connect_listener = { .notify = client_connect, }; int main(int argc, const char** argv) { wl_list_init(&request_overrides); display = wl_display_create(); if (wl_display_add_socket(display, get_display_name()) != 0) { FATAL_FMT("server failed to connect to Wayland display %s", get_display_name()); } wl_display_add_client_created_listener(display, &client_connect_listener); init(); wl_display_run(display); wl_display_destroy(display); return 0; } gtk4-layer-shell-1.0.4/test/mock-server/mock-server.h000066400000000000000000000040261471230641700224350ustar00rootroot00000000000000// This is an implementation of a mock Wayland compositor for testing // It does not show anything on the screen, and is only as conforment as is required by GTK // Useful regex for importing a Wayland protocol. First, copy from header file then: // Find: (struct (\w+)_interface (\{?\n\t.*)*)[\{;]\n(\t[/ ]\*.*\n)+\tvoid \(\*(\w+)\)(\((.*(,\n)?)*\));\n\};((([^=]*\n)*)\nstatic const struct \w+ \w+ = \{\n(( \.\w+ = \w+\,\n)*)\};)? // Replace with: \1;\n};\nstatic void \2_\5\6\n{\n FATAL_NOT_IMPL;\n}\n\{10}\nstatic const struct \2_interface \2_impl = {\n .\5 = \2_\5,\n\{12}}; // Then remove the struct artifact and replace this with a space: \n\t\s* #ifndef MOCK_SERVER_H #define MOCK_SERVER_H #include "test-common.h" #include #include "xdg-shell-server.h" #include "xdg-dialog-v1-server.h" #include "wlr-layer-shell-unstable-v1-server.h" extern struct wl_display* display; #define ALLOC_STRUCT(type) ((type*)alloc_zeroed(sizeof(type))) void* alloc_zeroed(size_t size); #define OVERRIDE_REQUEST(type, method) install_request_override(&type##_interface, #method, type##_##method) #define NEW_ID_ARG(name, index) ASSERT(type_code_at_index(message, index) == 'n'); uint32_t name = args[index].n; #define RESOURCE_ARG(type, name, index) ASSERT(type_code_at_index(message, index) == 'o'); ASSERT(message->types[index] == &type##_interface); struct wl_resource* name = (struct wl_resource*)args[index].o; #define UINT_ARG(name, index) ASSERT(type_code_at_index(message, index) == 'u'); uint32_t name = args[index].u; typedef void (*RequestOverrideFunction)(struct wl_resource* resource, const struct wl_message* message, union wl_argument* args); void install_request_override(const struct wl_interface* interface, const char* name, RequestOverrideFunction function); void use_default_impl(struct wl_resource* resource); void default_global_create(struct wl_display* display, const struct wl_interface* interface, int version); char type_code_at_index(const struct wl_message* message, int index); void init(); #endif // MOCK_SERVER_H gtk4-layer-shell-1.0.4/test/mock-server/overrides.c000066400000000000000000000335051471230641700222010ustar00rootroot00000000000000#include "mock-server.h" #include "linux/input.h" typedef enum { SURFACE_ROLE_NONE = 0, SURFACE_ROLE_XDG_TOPLEVEL, SURFACE_ROLE_XDG_POPUP, SURFACE_ROLE_LAYER, } SurfaceRole; typedef struct SurfaceData SurfaceData; struct SurfaceData { SurfaceRole role; struct wl_resource* surface; struct wl_resource* pending_frame; struct wl_resource* pending_buffer; // The attached but not committed buffer char buffer_cleared; // If the buffer has been explicitly cleared since the last commit struct wl_resource* xdg_toplevel; struct wl_resource* xdg_popup; struct wl_resource* xdg_surface; struct wl_resource* layer_surface; char has_committed_buffer; // This surface has a non-null committed buffer char initial_commit_for_role; // Set to 1 when a role is created for a surface, and cleared after the first commit char layer_send_configure; // If to send a layer surface configure on the next commit int layer_set_w; // The width to configure the layer surface with int layer_set_h; // The height to configure the layer surface with uint32_t layer_anchor; // The layer surface's anchor SurfaceData* most_recent_popup; // Start of the popup linked list SurfaceData* previous_popup_sibling; // Forms a linked list of popups SurfaceData* popup_parent; }; static struct wl_resource* seat_global = NULL; static struct wl_resource* pointer_global = NULL; static struct wl_resource* output_global = NULL; // Needs to be called before any role objects are assigned static void surface_data_set_role(SurfaceData* data, SurfaceRole role) { if (data->role != SURFACE_ROLE_NONE) { ASSERT_EQ(data->role, role, "%u"); } char is_xdg_role = (role == SURFACE_ROLE_XDG_TOPLEVEL || role == SURFACE_ROLE_XDG_POPUP); ASSERT_EQ(data->xdg_surface != NULL, is_xdg_role, "%d"); ASSERT(!data->xdg_toplevel); ASSERT(!data->xdg_popup); ASSERT(!data->layer_surface); ASSERT(!data->has_committed_buffer); data->role = role; data->initial_commit_for_role = 1; } static void surface_data_unmap(SurfaceData* data) { SurfaceData* popup = data->most_recent_popup; while (popup) { // Popups must be unmapped before their parents ASSERT(!popup->surface); ASSERT(!popup->layer_surface); ASSERT(!popup->xdg_popup); ASSERT(!popup->xdg_toplevel); ASSERT(!popup->xdg_surface); popup = popup->previous_popup_sibling; } } static void surface_data_add_pupup(SurfaceData* parent, SurfaceData* popup) { ASSERT(!popup->previous_popup_sibling); popup->previous_popup_sibling = parent->most_recent_popup; parent->most_recent_popup = popup; popup->popup_parent = parent; } static void wl_surface_frame(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { NEW_ID_ARG(callback, 0); SurfaceData* data = wl_resource_get_user_data(resource); ASSERT(!data->pending_frame); data->pending_frame = wl_resource_create( wl_resource_get_client(resource), &wl_callback_interface, wl_resource_get_version(resource), callback); } static void wl_surface_attach(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { RESOURCE_ARG(wl_buffer, buffer, 0); SurfaceData* data = wl_resource_get_user_data(resource); data->pending_buffer = buffer; data->buffer_cleared = buffer == NULL; } static void wl_surface_commit(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { SurfaceData* data = wl_resource_get_user_data(resource); if (data->buffer_cleared) { data->has_committed_buffer = 0; data->buffer_cleared = 0; } else if (data->pending_buffer) { data->has_committed_buffer = 1; } if (data->pending_buffer) { wl_buffer_send_release(data->pending_buffer); data->pending_buffer = NULL; } if (data->pending_frame) { wl_callback_send_done(data->pending_frame, 0); wl_resource_destroy(data->pending_frame); data->pending_frame = NULL; } if (data->initial_commit_for_role) { ASSERT(!data->has_committed_buffer); data->initial_commit_for_role = 0; } if (data->layer_surface && data->layer_send_configure) { char horiz = ( (data->layer_anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) && (data->layer_anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)); char vert = ( (data->layer_anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP) && (data->layer_anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)); int width = data->layer_set_w; int height = data->layer_set_h; if (width == 0 && !horiz) FATAL("not horizontally stretched and no width given"); if (height == 0 && !vert) FATAL("not horizontally stretched and no width given"); if (horiz) width = DEFAULT_OUTPUT_WIDTH; if (vert) height = DEFAULT_OUTPUT_HEIGHT; zwlr_layer_surface_v1_send_configure(data->layer_surface, wl_display_next_serial(display), width, height); data->layer_send_configure = 0; } } static void wl_surface_destroy(struct wl_resource* resource, const struct wl_message* message, union wl_argument* args) { SurfaceData* data = wl_resource_get_user_data(resource); ASSERT(!data->xdg_popup); ASSERT(!data->xdg_toplevel); ASSERT(!data->xdg_surface); ASSERT(!data->layer_surface); data->surface = NULL; // Don't free surfaces to guarantee traversing popups is always safe // We're employing the missile memory management pattern here https://x.com/pomeranian99/status/858856994438094848 } static void wl_compositor_create_surface(struct wl_resource* resource, const struct wl_message* message, union wl_argument* args) { NEW_ID_ARG(id, 0); struct wl_resource* surface = wl_resource_create( wl_resource_get_client(resource), &wl_surface_interface, wl_resource_get_version(resource), id); SurfaceData* data = ALLOC_STRUCT(SurfaceData); data->surface = surface; use_default_impl(surface); wl_resource_set_user_data(surface, data); } void wl_seat_bind(struct wl_client* client, void* data, uint32_t version, uint32_t id) { ASSERT(!seat_global); seat_global = wl_resource_create(client, &wl_seat_interface, version, id); use_default_impl(seat_global); wl_seat_send_capabilities(seat_global, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD); }; void wl_output_bind(struct wl_client* client, void* data, uint32_t version, uint32_t id) { ASSERT(!output_global); output_global = wl_resource_create(client, &wl_output_interface, version, id); use_default_impl(output_global); wl_output_send_done(output_global); }; static void wl_seat_get_pointer(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { NEW_ID_ARG(id, 0); ASSERT(!pointer_global); pointer_global = wl_resource_create( wl_resource_get_client(resource), &wl_pointer_interface, wl_resource_get_version(resource), id); use_default_impl(pointer_global); } static void xdg_wm_base_get_xdg_surface(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { NEW_ID_ARG(id, 0); RESOURCE_ARG(wl_surface, surface, 1); struct wl_resource* xdg_surface = wl_resource_create( wl_resource_get_client(resource), &xdg_surface_interface, wl_resource_get_version(resource), id); use_default_impl(xdg_surface); SurfaceData* data = wl_resource_get_user_data(surface); wl_resource_set_user_data(xdg_surface, data); data->xdg_surface = xdg_surface; } static void xdg_surface_destroy(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { SurfaceData* data = wl_resource_get_user_data(resource); ASSERT(!data->xdg_toplevel); ASSERT(!data->xdg_popup); data->xdg_surface = NULL; } static void xdg_surface_get_toplevel(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { NEW_ID_ARG(id, 0); struct wl_resource* toplevel = wl_resource_create( wl_resource_get_client(resource), &xdg_toplevel_interface, wl_resource_get_version(resource), id); use_default_impl(toplevel); struct wl_array states; wl_array_init(&states); xdg_toplevel_send_configure(toplevel, 0, 0, &states); wl_array_release(&states); xdg_surface_send_configure(resource, wl_display_next_serial(display)); SurfaceData* data = wl_resource_get_user_data(resource); surface_data_set_role(data, SURFACE_ROLE_XDG_TOPLEVEL); wl_resource_set_user_data(toplevel, data); data->xdg_toplevel = toplevel; } static void xdg_toplevel_destroy(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { SurfaceData* data = wl_resource_get_user_data(resource); ASSERT(data->xdg_surface); data->xdg_toplevel = NULL; surface_data_unmap(data); } static void xdg_surface_get_popup(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { NEW_ID_ARG(id, 0); RESOURCE_ARG(xdg_surface, parent, 1); struct wl_resource* popup = wl_resource_create( wl_resource_get_client(resource), &xdg_popup_interface, wl_resource_get_version(resource), id); use_default_impl(popup); xdg_popup_send_configure(popup, 0, 0, 100, 100); xdg_surface_send_configure(resource, wl_display_next_serial(display)); SurfaceData* data = wl_resource_get_user_data(resource); surface_data_set_role(data, SURFACE_ROLE_XDG_POPUP); wl_resource_set_user_data(popup, data); data->xdg_popup = popup; if (parent) { SurfaceData* parent_data = wl_resource_get_user_data(parent); surface_data_add_pupup(parent_data, data); } } static void xdg_popup_grab(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { SurfaceData* data = wl_resource_get_user_data(resource); RESOURCE_ARG(wl_seat, seat, 0); ASSERT_EQ(seat, seat_global, "%p"); ASSERT(data->popup_parent); } static void xdg_popup_destroy(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { SurfaceData* data = wl_resource_get_user_data(resource); ASSERT(data->xdg_surface); data->xdg_popup = NULL; surface_data_unmap(data); } static void zwlr_layer_surface_v1_set_anchor(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { UINT_ARG(anchor, 0); SurfaceData* data = wl_resource_get_user_data(resource); data->layer_send_configure = 1; data->layer_anchor = anchor; } static void zwlr_layer_surface_v1_set_size(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { UINT_ARG(width, 0); UINT_ARG(height, 1); SurfaceData* data = wl_resource_get_user_data(resource); data->layer_send_configure = 1; data->layer_set_w = width; data->layer_set_h = height; } static void zwlr_layer_surface_v1_get_popup(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { RESOURCE_ARG(xdg_popup, popup, 0); SurfaceData* data = wl_resource_get_user_data(resource); SurfaceData* popup_data = wl_resource_get_user_data(popup); ASSERT(!popup_data->popup_parent); surface_data_add_pupup(data, popup_data); } static void zwlr_layer_shell_v1_get_layer_surface(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { NEW_ID_ARG(id, 0); RESOURCE_ARG(wl_surface, surface, 1); struct wl_resource* layer_surface = wl_resource_create( wl_resource_get_client(resource), &zwlr_layer_surface_v1_interface, wl_resource_get_version(resource), id); use_default_impl(layer_surface); SurfaceData* data = wl_resource_get_user_data(surface); surface_data_set_role(data, SURFACE_ROLE_LAYER); wl_resource_set_user_data(layer_surface, data); data->layer_send_configure = 1; data->layer_surface = layer_surface; } static void zwlr_layer_surface_v1_destroy(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args) { SurfaceData* data = wl_resource_get_user_data(resource); data->layer_surface = NULL; surface_data_unmap(data); } void init() { OVERRIDE_REQUEST(wl_surface, commit); OVERRIDE_REQUEST(wl_surface, frame); OVERRIDE_REQUEST(wl_surface, attach); OVERRIDE_REQUEST(wl_surface, destroy); OVERRIDE_REQUEST(wl_compositor, create_surface); OVERRIDE_REQUEST(wl_seat, get_pointer); OVERRIDE_REQUEST(xdg_wm_base, get_xdg_surface); OVERRIDE_REQUEST(xdg_surface, destroy); OVERRIDE_REQUEST(xdg_surface, get_toplevel); OVERRIDE_REQUEST(xdg_toplevel, destroy); OVERRIDE_REQUEST(xdg_surface, get_popup); OVERRIDE_REQUEST(xdg_popup, grab); OVERRIDE_REQUEST(xdg_popup, destroy); OVERRIDE_REQUEST(zwlr_layer_shell_v1, get_layer_surface); OVERRIDE_REQUEST(zwlr_layer_surface_v1, set_anchor); OVERRIDE_REQUEST(zwlr_layer_surface_v1, set_size); OVERRIDE_REQUEST(zwlr_layer_surface_v1, get_popup); OVERRIDE_REQUEST(zwlr_layer_surface_v1, destroy); wl_global_create(display, &wl_seat_interface, 6, NULL, wl_seat_bind); wl_global_create(display, &wl_output_interface, 2, NULL, wl_output_bind); default_global_create(display, &wl_shm_interface, 1); default_global_create(display, &wl_data_device_manager_interface, 2); default_global_create(display, &wl_compositor_interface, 4); default_global_create(display, &wl_subcompositor_interface, 1); default_global_create(display, &xdg_wm_base_interface, 2); default_global_create(display, &zwlr_layer_shell_v1_interface, 4); default_global_create(display, &xdg_wm_dialog_v1_interface, 1); } gtk4-layer-shell-1.0.4/test/run-integration-test.py000077500000000000000000000252041471230641700222520ustar00rootroot00000000000000#!/usr/bin/python3 # This script runs an integration test. See test/README.md for details usage = 'Usage: python3 run-test ' import os from os import path import sys import shutil import time import subprocess import threading from typing import List, Dict, Optional, Any # All callables (generally lambdas) appended to this list will be called at the end of the program cleanup_funcs = [] class TestError(RuntimeError): pass def get_xdg_runtime_dir() -> str: ''' Creates a directory to use as the XDG_RUNTIME_DIR. It bases the result on the current PID because each test running in parallel needs a unique directory. ''' tmp_runtime_dir = '/tmp/layer-shell-test-runtime-dir-' + str(os.getpid()) if (path.exists(tmp_runtime_dir)): # We should wipe the dir on cleanup, but things can go wrong wipe_xdg_runtime_dir(tmp_runtime_dir) os.mkdir(tmp_runtime_dir) cleanup_funcs.append(lambda: wipe_xdg_runtime_dir(tmp_runtime_dir)) return tmp_runtime_dir def wipe_xdg_runtime_dir(p: str): assert p.startswith('/tmp'), 'Sanity check' assert 'layer-shell-test-runtime-dir' in p, 'Sanity check' shutil.rmtree(p) def wait_until_appears(p: str): '''Waits for something to appear at the given path''' sleep_time = 0.01 timeout = 5.0 for i in range(int(timeout / sleep_time)): if path.exists(p): return time.sleep(0.01) raise TestError(p + ' did not appear in ' + str(timeout) + ' seconds') def format_stream(name: str, stream: str) -> str: ''' After collecting a programs output stream into a string, this function formats it for easy reading. Specifically, it gives it a colored border and a name. ''' l_pad = 28 - len(name) // 2 r_pad = l_pad if len(name) % 2 == 1: r_pad -= 1 l_pad = max(l_pad, 1) r_pad = max(r_pad, 1) header = '─' * l_pad + '┤ ' + name + ' ├' + '─' * r_pad + '┈' divider = '\n│' body = divider.join(' ' + line for line in stream.strip().splitlines()) footer = '─' * 60 + '┈' return '╭' + header + divider + body + '\n╰' + footer def format_process_report(name: str, returncode: int, stdout: str, stderr: str) -> str: '''After running a program, this function is used to format it's output for easy reading''' result = format_stream(name + ' stderr', stderr) + '\n\n' if stdout: result += format_stream(name + ' stdout', stdout) + '\n\n' else: result += 'stdout empty, ' result += 'exit code: ' + str(returncode) return result class Pipe: ''' The normal Python subprocess.PIPE freezes the subprocess after it fills up a finite output buffer. This class solves that by opening a pipe and reading from it from another thread whil the subprocess runs. This increases the output limit to the system's available memory See: https://github.com/wmww/gtk-layer-shell/issues/91#issuecomment-719082062 See: https://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/ ''' def __init__(self, name: str): '''name is only for debugging''' readable, writable = os.pipe() self.fd = writable self.data: Any = bytes() self.result: Optional[str] = None # Read the data coming out of the pipe on a background thread # This keeps the buffer from filling up and blocking self.reader_thread = threading.Thread(name=name, target=self.read, args=(readable,)) self.reader_thread.start() cleanup_funcs.append(lambda: self.close()) def read(self, readable: int): '''Reads from the given fd until the other side closes''' while True: data = os.read(readable, 1000) if not data: # We've reached the end of the data os.close(readable) return self.data += data def close(self): '''Closes the fd and stops the reader''' if self.reader_thread.is_alive(): os.close(self.fd) self.reader_thread.join(timeout=1) assert not self.reader_thread.is_alive(), 'Failed to join pipe reader thread' def collect_str(self) -> str: '''Closes the pipe if needed and returns the read data decoded as UTF-8''' if self.result is None: self.close() self.result = self.data.decode('utf-8') self.data = None return self.result class Program: '''A program to run as a subprocess''' def __init__(self, name: str, args: List[str], env: Dict[str, str]): self.name = name self.stdout = Pipe(name + ' stdout') self.stderr = Pipe(name + ' stderr') self.subprocess = subprocess.Popen(args, stdout=self.stdout.fd, stderr=self.stderr.fd, env=env) cleanup_funcs.append(lambda: self.kill()) def finish(self, timeout: float): try: self.subprocess.wait(timeout=timeout) except subprocess.TimeoutExpired: self.kill() raise TestError(self.format_output() + '\n\n' + self.name + ' timed out') def kill(self): if self.subprocess.returncode is None: self.subprocess.kill() self.subprocess.wait() def format_output(self): assert self.subprocess.returncode is not None, 'Program.format_output() called before process exited' return format_process_report( self.name, self.subprocess.returncode, self.stdout.collect_str(), self.stderr.collect_str()) def check_returncode(self): assert self.subprocess.returncode is not None, repr(self.name) + '.check_returncode() called before process exited' if self.subprocess.returncode != 0: raise TestError( self.format_output() + '\n\n' + self.name + ' failed (return code ' + str(self.subprocess.returncode) + ')') def collect_output(self): return self.stdout.collect_str(), self.stderr.collect_str() def run_test(name: str, server_args: List[str], client_args: List[str], xdg_runtime: str, wayland_display: str) -> str: ''' Runs two processes: a mock server and the test client Does *not* check that client's message assertions pass, this must be done later using the returned output ''' env = os.environ.copy() env['XDG_RUNTIME_DIR'] = xdg_runtime env['WAYLAND_DISPLAY'] = wayland_display env['WAYLAND_DEBUG'] = '1' server = Program('server', server_args, env) try: wait_until_appears(path.join(xdg_runtime, wayland_display)) except TestError as e: server.kill() raise TestError(server.format_output() + '\n\n' + str(e)) client = Program(name, client_args, env) errors: List[str] = [] try: client.finish(timeout=10) client.check_returncode() except TestError as e: errors.append(str(e)) try: server.finish(timeout=1) server.check_returncode() except TestError as e: errors.append(str(e)) if errors: raise TestError('\n\n'.join(errors)) client_stdout, client_stderr = client.collect_output() if client_stdout.strip() != '': raise TestError(format_stream(name + ' stdout', client_stdout) + '\n\n' + name + ' stdout not empty') return client_stderr def line_contains(line: str, tokens: List[str]) -> bool: '''Returns if the given line contains a list of tokens in the given order (anything can be between tokens)''' found = True for token in tokens: if token in line: line = line[line.find(token) + len(token):] else: found = False return found def verify_result(lines: List[str]): '''Runs through the output of a client and verifies that all expectations pass, see the test README.md details''' assertions: List[List[str]] = [] negative_assertions: List[List[str]] = [] section_start = 0 set_expectation = False checked_expectation = False for i, line in enumerate(lines): if line.startswith('EXPECT: '): assertions.append(line.split()[1:]) set_expectation = True elif line.startswith('DONT_EXPECT: '): negative_assertions.append(line.split()[1:]) set_expectation = True elif line.startswith('[') and line.endswith(')') and ('@' in line or '#' in line): if assertions and line_contains(line, assertions[0]): assertions = assertions[1:] for negative_assertion in negative_assertions: if line_contains(line, negative_assertion): section = format_stream('relevant section', '\n'.join(lines[section_start:i + 1])) raise TestError(section + '\n\nunexpected message matching "' + ' '.join(negative_assertion) + '"') elif line == 'CHECK EXPECTATIONS COMPLETED' or i == len(lines) - 1: checked_expectation = True if assertions: section = format_stream('relevant section', '\n'.join(lines[section_start:i])) raise TestError(section + '\n\ndid not find "' + ' '.join(assertions[0]) + '"') section_start = i + 1 if not set_expectation or not checked_expectation: # If the test didn't use the right expectation format or something we don't want to silently pass raise TestError('test did not correctly set and check an expectation') def main(): client_bin = sys.argv[1] name = path.basename(client_bin) build_dir = os.environ.get('GTK4_LAYER_SHELL_BUILD') assert build_dir, 'GTK4_LAYER_SHELL_BUILD environment variable not set' server_bin = path.join(build_dir, 'test', 'mock-server', 'mock-server') assert path.exists(client_bin), 'Could not find client at ' + client_bin assert os.access(client_bin, os.X_OK), client_bin + ' is not executable' assert path.exists(server_bin), 'Could not find server at ' + server_bin assert os.access(server_bin, os.X_OK), server_bin + ' is not executable' wayland_display = 'wayland-test' xdg_runtime = get_xdg_runtime_dir() client_stderr = run_test(name, [server_bin], [client_bin, '--auto'], xdg_runtime, wayland_display) client_lines = [line.strip() for line in client_stderr.strip().splitlines()] try: verify_result(client_lines) except TestError as e: raise TestError(format_stream(name + ' stderr', client_stderr) + '\n\n' + str(e)) if __name__ == '__main__': assert len(sys.argv) == 2, 'Incorrect number of args. ' + usage fail = False try: main() print('Passed') except TestError as e: fail = True print(e) finally: for func in cleanup_funcs: func() if fail: exit(1) gtk4-layer-shell-1.0.4/test/smoke-tests/000077500000000000000000000000001471230641700200465ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/test/smoke-tests/meson.build000066400000000000000000000001571471230641700222130ustar00rootroot00000000000000smoke_tests = [ 'test-c-example', 'test-c-demo', 'test-python-example', 'test-vala-example', ] gtk4-layer-shell-1.0.4/test/smoke-tests/smoke_test_common.py000066400000000000000000000015331471230641700241470ustar00rootroot00000000000000import subprocess import os import sys from typing import List, Dict timeout = 3 def build_dir() -> str: p = os.environ.get('GTK4_LAYER_SHELL_BUILD') assert p, 'GTK4_LAYER_SHELL_BUILD environment variable not set' assert os.path.isdir(p), p + ' (from GTK4_LAYER_SHELL_BUILD) does not exist' return p def expect(*args) -> None: print('EXPECT: ' + ' '.join(args), file=sys.stderr) def run(cmd: List[str], env: Dict[str, str]) -> None: expect('zwlr_layer_shell_v1', '.get_layer_surface') expect('wl_surface', '.commit') try: result = subprocess.run(cmd, env={**os.environ, **env}, timeout=timeout) assert False, 'subprocess completed without timeout expiring, return code: ' + str(result.returncode) except subprocess.TimeoutExpired: pass print('CHECK EXPECTATIONS COMPLETED', file=sys.stderr) gtk4-layer-shell-1.0.4/test/smoke-tests/test-c-demo.py000077500000000000000000000003431471230641700225440ustar00rootroot00000000000000#!/usr/bin/env python3 import smoke_test_common bin_path = smoke_test_common.build_dir() + '/examples/gtk4-layer-demo' args = [bin_path] + '-l top -a lrb -m 20,20,20,0 -e -k on-demand'.split() smoke_test_common.run(args, {}) gtk4-layer-shell-1.0.4/test/smoke-tests/test-c-example.py000077500000000000000000000002401471230641700232470ustar00rootroot00000000000000#!/usr/bin/env python3 import smoke_test_common bin_path = smoke_test_common.build_dir() + '/examples/simple-example-c' smoke_test_common.run([bin_path], {}) gtk4-layer-shell-1.0.4/test/smoke-tests/test-python-example.py000077500000000000000000000006521471230641700243550ustar00rootroot00000000000000#!/usr/bin/env python3 import os import smoke_test_common script_path = os.path.join(os.path.dirname(__file__), '..', '..', 'examples', 'simple-example.py') assert os.path.isfile(script_path), 'script not found at ' + script_path src_build_dir = smoke_test_common.build_dir() + '/src' env = { 'GI_TYPELIB_PATH': src_build_dir, 'LD_LIBRARY_PATH': src_build_dir, } smoke_test_common.run(['python3', script_path], env) gtk4-layer-shell-1.0.4/test/smoke-tests/test-vala-example.py000077500000000000000000000002431471230641700237530ustar00rootroot00000000000000#!/usr/bin/env python3 import smoke_test_common bin_path = smoke_test_common.build_dir() + '/examples/simple-example-vala' smoke_test_common.run([bin_path], {}) gtk4-layer-shell-1.0.4/test/test-common/000077500000000000000000000000001471230641700200355ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/test/test-common/meson.build000066400000000000000000000001251471230641700221750ustar00rootroot00000000000000test_common = declare_dependency( include_directories: include_directories('.')) gtk4-layer-shell-1.0.4/test/test-common/test-common.h000066400000000000000000000015251471230641700224560ustar00rootroot00000000000000#ifndef TEST_COMMON_H #define TEST_COMMON_H #include #include #include #include #define DEFAULT_OUTPUT_WIDTH 1920 #define DEFAULT_OUTPUT_HEIGHT 1080 #define FATAL_FMT(format, ...) do {fprintf(stderr, "Fatal error at %s:%d in %s(): " format "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__); exit(1);} while (0) #define FATAL(message) FATAL_FMT(message"%s", "") #define ASSERT(assertion) do {if (!(assertion)) {FATAL_FMT("\n assertion failed: %s", #assertion);}} while (0) #define ASSERT_EQ(a, b, format) do {if (!((a) == (b))) {FATAL_FMT("\n expected: %s == %s\n actual: " format " != " format "\n", #a, #b, a, b);}} while (0) #define ASSERT_STR_EQ(a, b) do {if (strcmp(a, b)) {FATAL_FMT("\n expected: %s ≈ %s\n actual: \"%s\" ≠ \"%s\"\n", #a, #b, a, b);}} while (0) #endif // TEST_COMMON_H gtk4-layer-shell-1.0.4/test/unit-tests/000077500000000000000000000000001471230641700177075ustar00rootroot00000000000000gtk4-layer-shell-1.0.4/test/unit-tests/meson.build000066400000000000000000000003201471230641700220440ustar00rootroot00000000000000test('unit-test-get-version', executable( 'test-get-version', files('test-get-version.c'), dependencies: [gtk, gtk_layer_shell, test_common]), args: [meson.project_version()]) gtk4-layer-shell-1.0.4/test/unit-tests/test-get-version.c000066400000000000000000000007041471230641700232730ustar00rootroot00000000000000#include "gtk4-layer-shell.h" #include "test-common.h" int main(int argc, char** argv) { ASSERT_EQ(argc, 2, "%d"); char version_provided_by_gtk_layer_shell[1024]; sprintf( version_provided_by_gtk_layer_shell, "%d.%d.%d", gtk_layer_get_major_version(), gtk_layer_get_minor_version(), gtk_layer_get_micro_version()); ASSERT_STR_EQ(version_provided_by_gtk_layer_shell, argv[1]); return 0; }