pax_global_header00006660000000000000000000000064146677742730014541gustar00rootroot0000000000000052 comment=5d6628ee9e27b2d4760ced846235fe7c2086b5ac gtk4-layer-shell-1.0.3/000077500000000000000000000000001466777427300146325ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/.editorconfig000066400000000000000000000001631466777427300173070ustar00rootroot00000000000000root = true [*] end_of_line = lf insert_final_newline = true charset = utf-8 indent_style = space indent_size = 4 gtk4-layer-shell-1.0.3/.github/000077500000000000000000000000001466777427300161725ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/.github/workflows/000077500000000000000000000000001466777427300202275ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/.github/workflows/build_and_test.yml000066400000000000000000000016011466777427300237300ustar00rootroot00000000000000name: '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: Install Lua LGI run: sudo luarocks install https://raw.githubusercontent.com/lgi-devs/lgi/master/lgi-scm-1.rockspec # From https://github.com/lgi-devs/lgi/pull/305#issue-1459493105 - name: Test run: ninja -C build test - name: Install run: sudo ninja -C build install gtk4-layer-shell-1.0.3/.github/workflows/deploy_docs.yml000066400000000000000000000032331466777427300232570ustar00rootroot00000000000000name: '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.3/.gitignore000066400000000000000000000000701466777427300166170ustar00rootroot00000000000000build/ gtk-priv/build/ */__pycache__ *.pyc .mypy_cache/ gtk4-layer-shell-1.0.3/CHANGELOG.md000066400000000000000000000023671466777427300164530ustar00rootroot00000000000000# Changelog ## [Unreleased] ## [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.3/LICENSE000066400000000000000000000020701466777427300156360ustar00rootroot00000000000000The 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.3/README.md000066400000000000000000000131361466777427300161150ustar00rootroot00000000000000# 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. ### Lua [examples/simple-example.lua](examples/simple-example.lua) contains sample Lua code. It uses [FFI](https://luajit.org/ext_ffi.html) which requires [LuaJIT](https://luajit.org/). ### 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) * [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) - __If `smoke-tests` enabled:__ [LuaJIT](https://luajit.org/) - __If `smoke-tests` enabled:__ [LGI](https://github.com/lgi-devs/lgi) 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.3/doc/000077500000000000000000000000001466777427300153775ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/doc/gtk4-layer-shell-docs.sgml000066400000000000000000000072471466777427300223130ustar00rootroot00000000000000 %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.3/doc/meson.build000066400000000000000000000015651466777427300175500ustar00rootroot00000000000000subdir('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.3/doc/xml/000077500000000000000000000000001466777427300161775ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/doc/xml/gtkdocentities.ent.in000066400000000000000000000005341466777427300223360ustar00rootroot00000000000000 gtk4-layer-shell-1.0.3/doc/xml/meson.build000066400000000000000000000011711466777427300203410ustar00rootroot00000000000000ent_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.3/examples/000077500000000000000000000000001466777427300164505ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/examples/demo/000077500000000000000000000000001466777427300173745ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/examples/demo/anchor-control.c000066400000000000000000000070161466777427300224740ustar00rootroot00000000000000#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.3/examples/demo/gtk-layer-demo.c000066400000000000000000000406371466777427300223730ustar00rootroot00000000000000#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_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); int status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return status; } gtk4-layer-shell-1.0.3/examples/demo/gtk-layer-demo.h000066400000000000000000000025621466777427300223730ustar00rootroot00000000000000#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.3/examples/demo/keyboard-selection.c000066400000000000000000000025221466777427300233240ustar00rootroot00000000000000#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.3/examples/demo/layer-selection.c000066400000000000000000000023001466777427300226320ustar00rootroot00000000000000#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.3/examples/demo/margin-control.c000066400000000000000000000071241466777427300224770ustar00rootroot00000000000000#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.3/examples/demo/menu-bar.c000066400000000000000000000023231466777427300212460ustar00rootroot00000000000000#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); g_menu_append_item (menubar, menu_item); 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.3/examples/demo/meson.build000066400000000000000000000003511466777427300215350ustar00rootroot00000000000000demo_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.3/examples/demo/monitor-selection.c000066400000000000000000000031451466777427300232150ustar00rootroot00000000000000#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.3/examples/demo/mscl-toggles.c000066400000000000000000000045601466777427300221450ustar00rootroot00000000000000#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.3/examples/demo/version-info.c000066400000000000000000000015311466777427300221560ustar00rootroot00000000000000#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.3/examples/meson.build000066400000000000000000000011071466777427300206110ustar00rootroot00000000000000subdir('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], install: false) endif gtk4-layer-shell-1.0.3/examples/simple-example.c000066400000000000000000000040731466777427300215420ustar00rootroot00000000000000#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_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); int status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return status; } gtk4-layer-shell-1.0.3/examples/simple-example.lua000066400000000000000000000022651466777427300221020ustar00rootroot00000000000000-- 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 luajit examples/simple-example.lua -- For GTK4 Layer Shell to get linked before libwayland-client we must explicitly load it before importing with lgi local ffi = require("ffi") ffi.cdef[[ void *dlopen(const char *filename, int flags); ]] ffi.C.dlopen("libgtk4-layer-shell.so", 0x101) -- Now open the library normally with LGI local lgi = require("lgi") local Gtk = lgi.require("Gtk", "4.0") local layer_shell = lgi.require("Gtk4LayerShell") local app = Gtk.Application { application_id = "com.github.a-cloud-ninja.gtk4-layer-shell.lua-example", } app.on_activate = function() local win = Gtk.Window { application = app } layer_shell.init_for_window(win) layer_shell.set_layer(win, layer_shell.Layer.TOP) layer_shell.set_anchor(win, layer_shell.Edge.BOTTOM, true) layer_shell.set_exclusive_zone(win, 0) local button = Gtk.Button { label = "Gtk4 Layer Shell Example", } button.on_clicked = function() win:close() end win:set_child(button) win:present() end app:run() gtk4-layer-shell-1.0.3/examples/simple-example.py000066400000000000000000000024111466777427300217420ustar00rootroot00000000000000# 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.3/examples/simple-example.vala000066400000000000000000000015261466777427300222430ustar00rootroot00000000000000using 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.3/include/000077500000000000000000000000001466777427300162555ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/include/gtk4-layer-shell.h000066400000000000000000000257471466777427300215350ustar00rootroot00000000000000#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.3/include/meson.build000066400000000000000000000001621466777427300204160ustar00rootroot00000000000000gtk_layer_shell_inc = include_directories('.') install_headers('gtk4-layer-shell.h', subdir: 'gtk4-layer-shell') gtk4-layer-shell-1.0.3/linking.md000066400000000000000000000063151466777427300166140ustar00rootroot00000000000000# 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.3/meson.build000066400000000000000000000030001466777427300167650ustar00rootroot00000000000000project('gtk4-layer-shell', ['c'], version: '1.0.3', 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') 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) # use system xdg-shell protocol when available wayland_protocols = dependency('wayland-protocols', version: '>=1.16', required: false) 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.3/meson_options.txt000066400000000000000000000011141466777427300202640ustar00rootroot00000000000000option('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.3/protocol/000077500000000000000000000000001466777427300164735ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/protocol/meson.build000066400000000000000000000025161466777427300206410ustar00rootroot00000000000000if 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' ] if wayland_protocols.found() protocols += join_paths( wayland_protocols.get_variable(pkgconfig: 'pkgdatadir'), 'stable/xdg-shell/xdg-shell.xml') else # use bundled xdg-shell.xml protocols += 'xdg-shell.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) server_header = gen_server_header.process(protocol) code = gen_private_code.process(protocol) client_protocol_srcs += [client_header, code] server_protocol_srcs += [server_header, code] endforeach gtk4-layer-shell-1.0.3/protocol/wlr-layer-shell-unstable-v1.xml000066400000000000000000000440361466777427300244060ustar00rootroot00000000000000 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.3/protocol/xdg-shell.xml000066400000000000000000001412111466777427300211040ustar00rootroot00000000000000 Copyright © 2008-2013 Kristian Høgsberg Copyright © 2013 Rafael Antognolli Copyright © 2013 Jasper St. Pierre Copyright © 2010-2013 Intel Corporation Copyright © 2015-2017 Samsung Electronics Co., Ltd Copyright © 2015-2017 Red Hat Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The xdg_wm_base interface is exposed as a global object enabling clients to turn their wl_surfaces into windows in a desktop environment. It defines the basic functionality needed for clients and the compositor to create windows that can be dragged, resized, maximized, etc, as well as creating transient windows such as popup menus. Destroy this xdg_wm_base object. Destroying a bound xdg_wm_base object while there are surfaces still alive created by this xdg_wm_base object instance is illegal and will result in a protocol error. Create a positioner object. A positioner object is used to position surfaces relative to some parent surface. See the interface description and xdg_surface.get_popup for details. This creates an xdg_surface for the given surface. While xdg_surface itself is not a role, the corresponding surface may only be assigned a role extending xdg_surface, such as xdg_toplevel or xdg_popup. This creates an xdg_surface for the given surface. An xdg_surface is used as basis to define a role to a given surface, such as xdg_toplevel or xdg_popup. It also manages functionality shared between xdg_surface based surface roles. See the documentation of xdg_surface for more details about what an xdg_surface is and how it is used. A client must respond to a ping event with a pong request or the client may be deemed unresponsive. See xdg_wm_base.ping. The ping event asks the client if it's still alive. Pass the serial specified in the event back to the compositor by sending a "pong" request back with the specified serial. See xdg_wm_base.ping. Compositors can use this to determine if the client is still alive. It's unspecified what will happen if the client doesn't respond to the ping request, or in what timeframe. Clients should try to respond in a reasonable amount of time. A compositor is free to ping in any way it wants, but a client must always respond to any xdg_wm_base object it created. The xdg_positioner provides a collection of rules for the placement of a child surface relative to a parent surface. Rules can be defined to ensure the child surface remains within the visible area's borders, and to specify how the child surface changes its position, such as sliding along an axis, or flipping around a rectangle. These positioner-created rules are constrained by the requirement that a child surface must intersect with or be at least partially adjacent to its parent surface. See the various requests for details about possible rules. At the time of the request, the compositor makes a copy of the rules specified by the xdg_positioner. Thus, after the request is complete the xdg_positioner object can be destroyed or reused; further changes to the object will have no effect on previous usages. For an xdg_positioner object to be considered complete, it must have a non-zero size set by set_size, and a non-zero anchor rectangle set by set_anchor_rect. Passing an incomplete xdg_positioner object when positioning a surface raises an error. Notify the compositor that the xdg_positioner will no longer be used. Set the size of the surface that is to be positioned with the positioner object. The size is in surface-local coordinates and corresponds to the window geometry. See xdg_surface.set_window_geometry. If a zero or negative size is set the invalid_input error is raised. Specify the anchor rectangle within the parent surface that the child surface will be placed relative to. The rectangle is relative to the window geometry as defined by xdg_surface.set_window_geometry of the parent surface. When the xdg_positioner object is used to position a child surface, the anchor rectangle may not extend outside the window geometry of the positioned child's parent surface. If a negative size is set the invalid_input error is raised. Defines the anchor point for the anchor rectangle. The specified anchor is used derive an anchor point that the child surface will be positioned relative to. If a corner anchor is set (e.g. 'top_left' or 'bottom_right'), the anchor point will be at the specified corner; otherwise, the derived anchor point will be centered on the specified edge, or in the center of the anchor rectangle if no edge is specified. Defines in what direction a surface should be positioned, relative to the anchor point of the parent surface. If a corner gravity is specified (e.g. 'bottom_right' or 'top_left'), then the child surface will be placed towards the specified gravity; otherwise, the child surface will be centered over the anchor point on any axis that had no gravity specified. The constraint adjustment value define ways the compositor will adjust the position of the surface, if the unadjusted position would result in the surface being partly constrained. Whether a surface is considered 'constrained' is left to the compositor to determine. For example, the surface may be partly outside the compositor's defined 'work area', thus necessitating the child surface's position be adjusted until it is entirely inside the work area. The adjustments can be combined, according to a defined precedence: 1) Flip, 2) Slide, 3) Resize. Don't alter the surface position even if it is constrained on some axis, for example partially outside the edge of an output. Slide the surface along the x axis until it is no longer constrained. First try to slide towards the direction of the gravity on the x axis until either the edge in the opposite direction of the gravity is unconstrained or the edge in the direction of the gravity is constrained. Then try to slide towards the opposite direction of the gravity on the x axis until either the edge in the direction of the gravity is unconstrained or the edge in the opposite direction of the gravity is constrained. Slide the surface along the y axis until it is no longer constrained. First try to slide towards the direction of the gravity on the y axis until either the edge in the opposite direction of the gravity is unconstrained or the edge in the direction of the gravity is constrained. Then try to slide towards the opposite direction of the gravity on the y axis until either the edge in the direction of the gravity is unconstrained or the edge in the opposite direction of the gravity is constrained. Invert the anchor and gravity on the x axis if the surface is constrained on the x axis. For example, if the left edge of the surface is constrained, the gravity is 'left' and the anchor is 'left', change the gravity to 'right' and the anchor to 'right'. If the adjusted position also ends up being constrained, the resulting position of the flip_x adjustment will be the one before the adjustment. Invert the anchor and gravity on the y axis if the surface is constrained on the y axis. For example, if the bottom edge of the surface is constrained, the gravity is 'bottom' and the anchor is 'bottom', change the gravity to 'top' and the anchor to 'top'. The adjusted position is calculated given the original anchor rectangle and offset, but with the new flipped anchor and gravity values. If the adjusted position also ends up being constrained, the resulting position of the flip_y adjustment will be the one before the adjustment. Resize the surface horizontally so that it is completely unconstrained. Resize the surface vertically so that it is completely unconstrained. Specify how the window should be positioned if the originally intended position caused the surface to be constrained, meaning at least partially outside positioning boundaries set by the compositor. The adjustment is set by constructing a bitmask describing the adjustment to be made when the surface is constrained on that axis. If no bit for one axis is set, the compositor will assume that the child surface should not change its position on that axis when constrained. If more than one bit for one axis is set, the order of how adjustments are applied is specified in the corresponding adjustment descriptions. The default adjustment is none. Specify the surface position offset relative to the position of the anchor on the anchor rectangle and the anchor on the surface. For example if the anchor of the anchor rectangle is at (x, y), the surface has the gravity bottom|right, and the offset is (ox, oy), the calculated surface position will be (x + ox, y + oy). The offset position of the surface is the one used for constraint testing. See set_constraint_adjustment. An example use case is placing a popup menu on top of a user interface element, while aligning the user interface element of the parent surface with some user interface element placed somewhere in the popup surface. An interface that may be implemented by a wl_surface, for implementations that provide a desktop-style user interface. It provides a base set of functionality required to construct user interface elements requiring management by the compositor, such as toplevel windows, menus, etc. The types of functionality are split into xdg_surface roles. Creating an xdg_surface does not set the role for a wl_surface. In order to map an xdg_surface, the client must create a role-specific object using, e.g., get_toplevel, get_popup. The wl_surface for any given xdg_surface can have at most one role, and may not be assigned any role not based on xdg_surface. A role must be assigned before any other requests are made to the xdg_surface object. The client must call wl_surface.commit on the corresponding wl_surface for the xdg_surface state to take effect. Creating an xdg_surface from a wl_surface which has a buffer attached or committed is a client error, and any attempts by a client to attach or manipulate a buffer prior to the first xdg_surface.configure call must also be treated as errors. Mapping an xdg_surface-based role surface is defined as making it possible for the surface to be shown by the compositor. Note that a mapped surface is not guaranteed to be visible once it is mapped. For an xdg_surface to be mapped by the compositor, the following conditions must be met: (1) the client has assigned an xdg_surface-based role to the surface (2) the client has set and committed the xdg_surface state and the role-dependent state to the surface (3) the client has committed a buffer to the surface A newly-unmapped surface is considered to have met condition (1) out of the 3 required conditions for mapping a surface if its role surface has not been destroyed. Destroy the xdg_surface object. An xdg_surface must only be destroyed after its role object has been destroyed. This creates an xdg_toplevel object for the given xdg_surface and gives the associated wl_surface the xdg_toplevel role. See the documentation of xdg_toplevel for more details about what an xdg_toplevel is and how it is used. This creates an xdg_popup object for the given xdg_surface and gives the associated wl_surface the xdg_popup role. If null is passed as a parent, a parent surface must be specified using some other protocol, before committing the initial state. See the documentation of xdg_popup for more details about what an xdg_popup is and how it is used. The window geometry of a surface is its "visible bounds" from the user's perspective. Client-side decorations often have invisible portions like drop-shadows which should be ignored for the purposes of aligning, placing and constraining windows. The window geometry is double buffered, and will be applied at the time wl_surface.commit of the corresponding wl_surface is called. When maintaining a position, the compositor should treat the (x, y) coordinate of the window geometry as the top left corner of the window. A client changing the (x, y) window geometry coordinate should in general not alter the position of the window. Once the window geometry of the surface is set, it is not possible to unset it, and it will remain the same until set_window_geometry is called again, even if a new subsurface or buffer is attached. If never set, the value is the full bounds of the surface, including any subsurfaces. This updates dynamically on every commit. This unset is meant for extremely simple clients. The arguments are given in the surface-local coordinate space of the wl_surface associated with this xdg_surface. The width and height must be greater than zero. Setting an invalid size will raise an error. When applied, the effective window geometry will be the set window geometry clamped to the bounding rectangle of the combined geometry of the surface of the xdg_surface and the associated subsurfaces. When a configure event is received, if a client commits the surface in response to the configure event, then the client must make an ack_configure request sometime before the commit request, passing along the serial of the configure event. For instance, for toplevel surfaces the compositor might use this information to move a surface to the top left only when the client has drawn itself for the maximized or fullscreen state. If the client receives multiple configure events before it can respond to one, it only has to ack the last configure event. A client is not required to commit immediately after sending an ack_configure request - it may even ack_configure several times before its next surface commit. A client may send multiple ack_configure requests before committing, but only the last request sent before a commit indicates which configure event the client really is responding to. The configure event marks the end of a configure sequence. A configure sequence is a set of one or more events configuring the state of the xdg_surface, including the final xdg_surface.configure event. Where applicable, xdg_surface surface roles will during a configure sequence extend this event as a latched state sent as events before the xdg_surface.configure event. Such events should be considered to make up a set of atomically applied configuration states, where the xdg_surface.configure commits the accumulated state. Clients should arrange their surface for the new states, and then send an ack_configure request with the serial sent in this configure event at some point before committing the new surface. If the client receives multiple configure events before it can respond to one, it is free to discard all but the last event it received. This interface defines an xdg_surface role which allows a surface to, among other things, set window-like properties such as maximize, fullscreen, and minimize, set application-specific metadata like title and id, and well as trigger user interactive operations such as interactive resize and move. Unmapping an xdg_toplevel means that the surface cannot be shown by the compositor until it is explicitly mapped again. All active operations (e.g., move, resize) are canceled and all attributes (e.g. title, state, stacking, ...) are discarded for an xdg_toplevel surface when it is unmapped. Attaching a null buffer to a toplevel unmaps the surface. This request destroys the role surface and unmaps the surface; see "Unmapping" behavior in interface section for details. Set the "parent" of this surface. This surface should be stacked above the parent surface and all other ancestor surfaces. Parent windows should be set on dialogs, toolboxes, or other "auxiliary" surfaces, so that the parent is raised when the dialog is raised. Setting a null parent for a child window removes any parent-child relationship for the child. Setting a null parent for a window which currently has no parent is a no-op. If the parent is unmapped then its children are managed as though the parent of the now-unmapped parent has become the parent of this surface. If no parent exists for the now-unmapped parent then the children are managed as though they have no parent surface. Set a short title for the surface. This string may be used to identify the surface in a task bar, window list, or other user interface elements provided by the compositor. The string must be encoded in UTF-8. Set an application identifier for the surface. The app ID identifies the general class of applications to which the surface belongs. The compositor can use this to group multiple surfaces together, or to determine how to launch a new application. For D-Bus activatable applications, the app ID is used as the D-Bus service name. The compositor shell will try to group application surfaces together by their app ID. As a best practice, it is suggested to select app ID's that match the basename of the application's .desktop file. For example, "org.freedesktop.FooViewer" where the .desktop file is "org.freedesktop.FooViewer.desktop". See the desktop-entry specification [0] for more details on application identifiers and how they relate to well-known D-Bus names and .desktop files. [0] http://standards.freedesktop.org/desktop-entry-spec/ Clients implementing client-side decorations might want to show a context menu when right-clicking on the decorations, giving the user a menu that they can use to maximize or minimize the window. This request asks the compositor to pop up such a window menu at the given position, relative to the local surface coordinates of the parent surface. There are no guarantees as to what menu items the window menu contains. This request must be used in response to some sort of user action like a button press, key press, or touch down event. Start an interactive, user-driven move of the surface. This request must be used in response to some sort of user action like a button press, key press, or touch down event. The passed serial is used to determine the type of interactive move (touch, pointer, etc). The server may ignore move requests depending on the state of the surface (e.g. fullscreen or maximized), or if the passed serial is no longer valid. If triggered, the surface will lose the focus of the device (wl_pointer, wl_touch, etc) used for the move. It is up to the compositor to visually indicate that the move is taking place, such as updating a pointer cursor, during the move. There is no guarantee that the device focus will return when the move is completed. These values are used to indicate which edge of a surface is being dragged in a resize operation. Start a user-driven, interactive resize of the surface. This request must be used in response to some sort of user action like a button press, key press, or touch down event. The passed serial is used to determine the type of interactive resize (touch, pointer, etc). The server may ignore resize requests depending on the state of the surface (e.g. fullscreen or maximized). If triggered, the client will receive configure events with the "resize" state enum value and the expected sizes. See the "resize" enum value for more details about what is required. The client must also acknowledge configure events using "ack_configure". After the resize is completed, the client will receive another "configure" event without the resize state. If triggered, the surface also will lose the focus of the device (wl_pointer, wl_touch, etc) used for the resize. It is up to the compositor to visually indicate that the resize is taking place, such as updating a pointer cursor, during the resize. There is no guarantee that the device focus will return when the resize is completed. The edges parameter specifies how the surface should be resized, and is one of the values of the resize_edge enum. The compositor may use this information to update the surface position for example when dragging the top left corner. The compositor may also use this information to adapt its behavior, e.g. choose an appropriate cursor image. The different state values used on the surface. This is designed for state values like maximized, fullscreen. It is paired with the configure event to ensure that both the client and the compositor setting the state can be synchronized. States set in this way are double-buffered. They will get applied on the next commit. The surface is maximized. The window geometry specified in the configure event must be obeyed by the client. The client should draw without shadow or other decoration outside of the window geometry. The surface is fullscreen. The window geometry specified in the configure event is a maximum; the client cannot resize beyond it. For a surface to cover the whole fullscreened area, the geometry dimensions must be obeyed by the client. For more details, see xdg_toplevel.set_fullscreen. The surface is being resized. The window geometry specified in the configure event is a maximum; the client cannot resize beyond it. Clients that have aspect ratio or cell sizing configuration can use a smaller size, however. Client window decorations should be painted as if the window is active. Do not assume this means that the window actually has keyboard or pointer focus. The window is currently in a tiled layout and the left edge is considered to be adjacent to another part of the tiling grid. The window is currently in a tiled layout and the right edge is considered to be adjacent to another part of the tiling grid. The window is currently in a tiled layout and the top edge is considered to be adjacent to another part of the tiling grid. The window is currently in a tiled layout and the bottom edge is considered to be adjacent to another part of the tiling grid. Set a maximum size for the window. The client can specify a maximum size so that the compositor does not try to configure the window beyond this size. The width and height arguments are in window geometry coordinates. See xdg_surface.set_window_geometry. Values set in this way are double-buffered. They will get applied on the next commit. The compositor can use this information to allow or disallow different states like maximize or fullscreen and draw accurate animations. Similarly, a tiling window manager may use this information to place and resize client windows in a more effective way. The client should not rely on the compositor to obey the maximum size. The compositor may decide to ignore the values set by the client and request a larger size. If never set, or a value of zero in the request, means that the client has no expected maximum size in the given dimension. As a result, a client wishing to reset the maximum size to an unspecified state can use zero for width and height in the request. Requesting a maximum size to be smaller than the minimum size of a surface is illegal and will result in a protocol error. The width and height must be greater than or equal to zero. Using strictly negative values for width and height will result in a protocol error. Set a minimum size for the window. The client can specify a minimum size so that the compositor does not try to configure the window below this size. The width and height arguments are in window geometry coordinates. See xdg_surface.set_window_geometry. Values set in this way are double-buffered. They will get applied on the next commit. The compositor can use this information to allow or disallow different states like maximize or fullscreen and draw accurate animations. Similarly, a tiling window manager may use this information to place and resize client windows in a more effective way. The client should not rely on the compositor to obey the minimum size. The compositor may decide to ignore the values set by the client and request a smaller size. If never set, or a value of zero in the request, means that the client has no expected minimum size in the given dimension. As a result, a client wishing to reset the minimum size to an unspecified state can use zero for width and height in the request. Requesting a minimum size to be larger than the maximum size of a surface is illegal and will result in a protocol error. The width and height must be greater than or equal to zero. Using strictly negative values for width and height will result in a protocol error. Maximize the surface. After requesting that the surface should be maximized, the compositor will respond by emitting a configure event. Whether this configure actually sets the window maximized is subject to compositor policies. The client must then update its content, drawing in the configured state. The client must also acknowledge the configure when committing the new content (see ack_configure). It is up to the compositor to decide how and where to maximize the surface, for example which output and what region of the screen should be used. If the surface was already maximized, the compositor will still emit a configure event with the "maximized" state. If the surface is in a fullscreen state, this request has no direct effect. It may alter the state the surface is returned to when unmaximized unless overridden by the compositor. Unmaximize the surface. After requesting that the surface should be unmaximized, the compositor will respond by emitting a configure event. Whether this actually un-maximizes the window is subject to compositor policies. If available and applicable, the compositor will include the window geometry dimensions the window had prior to being maximized in the configure event. The client must then update its content, drawing it in the configured state. The client must also acknowledge the configure when committing the new content (see ack_configure). It is up to the compositor to position the surface after it was unmaximized; usually the position the surface had before maximizing, if applicable. If the surface was already not maximized, the compositor will still emit a configure event without the "maximized" state. If the surface is in a fullscreen state, this request has no direct effect. It may alter the state the surface is returned to when unmaximized unless overridden by the compositor. Make the surface fullscreen. After requesting that the surface should be fullscreened, the compositor will respond by emitting a configure event. Whether the client is actually put into a fullscreen state is subject to compositor policies. The client must also acknowledge the configure when committing the new content (see ack_configure). The output passed by the request indicates the client's preference as to which display it should be set fullscreen on. If this value is NULL, it's up to the compositor to choose which display will be used to map this surface. If the surface doesn't cover the whole output, the compositor will position the surface in the center of the output and compensate with with border fill covering the rest of the output. The content of the border fill is undefined, but should be assumed to be in some way that attempts to blend into the surrounding area (e.g. solid black). If the fullscreened surface is not opaque, the compositor must make sure that other screen content not part of the same surface tree (made up of subsurfaces, popups or similarly coupled surfaces) are not visible below the fullscreened surface. Make the surface no longer fullscreen. After requesting that the surface should be unfullscreened, the compositor will respond by emitting a configure event. Whether this actually removes the fullscreen state of the client is subject to compositor policies. Making a surface unfullscreen sets states for the surface based on the following: * the state(s) it may have had before becoming fullscreen * any state(s) decided by the compositor * any state(s) requested by the client while the surface was fullscreen The compositor may include the previous window geometry dimensions in the configure event, if applicable. The client must also acknowledge the configure when committing the new content (see ack_configure). Request that the compositor minimize your surface. There is no way to know if the surface is currently minimized, nor is there any way to unset minimization on this surface. If you are looking to throttle redrawing when minimized, please instead use the wl_surface.frame event for this, as this will also work with live previews on windows in Alt-Tab, Expose or similar compositor features. This configure event asks the client to resize its toplevel surface or to change its state. The configured state should not be applied immediately. See xdg_surface.configure for details. The width and height arguments specify a hint to the window about how its surface should be resized in window geometry coordinates. See set_window_geometry. If the width or height arguments are zero, it means the client should decide its own window dimension. This may happen when the compositor needs to configure the state of the surface but doesn't have any information about any previous or expected dimension. The states listed in the event specify how the width/height arguments should be interpreted, and possibly how it should be drawn. Clients must send an ack_configure in response to this event. See xdg_surface.configure and xdg_surface.ack_configure for details. The close event is sent by the compositor when the user wants the surface to be closed. This should be equivalent to the user clicking the close button in client-side decorations, if your application has any. This is only a request that the user intends to close the window. The client may choose to ignore this request, or show a dialog to ask the user to save their data, etc. A popup surface is a short-lived, temporary surface. It can be used to implement for example menus, popovers, tooltips and other similar user interface concepts. A popup can be made to take an explicit grab. See xdg_popup.grab for details. When the popup is dismissed, a popup_done event will be sent out, and at the same time the surface will be unmapped. See the xdg_popup.popup_done event for details. Explicitly destroying the xdg_popup object will also dismiss the popup and unmap the surface. Clients that want to dismiss the popup when another surface of their own is clicked should dismiss the popup using the destroy request. A newly created xdg_popup will be stacked on top of all previously created xdg_popup surfaces associated with the same xdg_toplevel. The parent of an xdg_popup must be mapped (see the xdg_surface description) before the xdg_popup itself. The x and y arguments passed when creating the popup object specify where the top left of the popup should be placed, relative to the local surface coordinates of the parent surface. See xdg_surface.get_popup. An xdg_popup must intersect with or be at least partially adjacent to its parent surface. The client must call wl_surface.commit on the corresponding wl_surface for the xdg_popup state to take effect. This destroys the popup. Explicitly destroying the xdg_popup object will also dismiss the popup, and unmap the surface. If this xdg_popup is not the "topmost" popup, a protocol error will be sent. This request makes the created popup take an explicit grab. An explicit grab will be dismissed when the user dismisses the popup, or when the client destroys the xdg_popup. This can be done by the user clicking outside the surface, using the keyboard, or even locking the screen through closing the lid or a timeout. If the compositor denies the grab, the popup will be immediately dismissed. This request must be used in response to some sort of user action like a button press, key press, or touch down event. The serial number of the event should be passed as 'serial'. The parent of a grabbing popup must either be an xdg_toplevel surface or another xdg_popup with an explicit grab. If the parent is another xdg_popup it means that the popups are nested, with this popup now being the topmost popup. Nested popups must be destroyed in the reverse order they were created in, e.g. the only popup you are allowed to destroy at all times is the topmost one. When compositors choose to dismiss a popup, they may dismiss every nested grabbing popup as well. When a compositor dismisses popups, it will follow the same dismissing order as required from the client. The parent of a grabbing popup must either be another xdg_popup with an active explicit grab, or an xdg_popup or xdg_toplevel, if there are no explicit grabs already taken. If the topmost grabbing popup is destroyed, the grab will be returned to the parent of the popup, if that parent previously had an explicit grab. If the parent is a grabbing popup which has already been dismissed, this popup will be immediately dismissed. If the parent is a popup that did not take an explicit grab, an error will be raised. During a popup grab, the client owning the grab will receive pointer and touch events for all their surfaces as normal (similar to an "owner-events" grab in X11 parlance), while the top most grabbing popup will always have keyboard focus. This event asks the popup surface to configure itself given the configuration. The configured state should not be applied immediately. See xdg_surface.configure for details. The x and y arguments represent the position the popup was placed at given the xdg_positioner rule, relative to the upper left corner of the window geometry of the parent surface. The popup_done event is sent out when a popup is dismissed by the compositor. The client should destroy the xdg_popup object at this point. gtk4-layer-shell-1.0.3/release_process.md000066400000000000000000000013351466777427300203340ustar00rootroot00000000000000# 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.3/src/000077500000000000000000000000001466777427300154215ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/src/api.c000066400000000000000000000134321466777427300163410ustar00rootroot00000000000000#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.3/src/layer-surface.c000066400000000000000000000477601466777427300203450ustar00rootroot00000000000000#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->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}; 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->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->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}; 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; } struct wl_proxy * 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) { 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); return xdg_surface; } } } 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); return (struct wl_proxy *)xdg_popup; } else { g_critical ("tried to create popup before layer shell surface"); return libwayland_shim_create_client_proxy (proxy, &xdg_popup_interface, version, NULL, NULL, NULL); } } } } return libwayland_shim_real_wl_proxy_marshal_array_flags (proxy, opcode, interface, version, flags, args); } gtk4-layer-shell-1.0.3/src/layer-surface.h000066400000000000000000000070261466777427300203410ustar00rootroot00000000000000#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; }; 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 struct wl_proxy *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); #endif // LAYER_SHELL_SURFACE_H gtk4-layer-shell-1.0.3/src/libwayland-shim.c000066400000000000000000000231001466777427300206450ustar00rootroot00000000000000#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; } } // 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) { 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 { return layer_surface_handle_request (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.3/src/libwayland-shim.h000066400000000000000000000037231466777427300206630ustar00rootroot00000000000000#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); extern 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); #endif // LIBWAYLAND_SHIM_H gtk4-layer-shell-1.0.3/src/meson.build000066400000000000000000000032411466777427300175630ustar00rootroot00000000000000srcs = 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.3/src/wayland-utils.c000066400000000000000000000135011466777427300203620ustar00rootroot00000000000000#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.3/src/wayland-utils.h000066400000000000000000000015451466777427300203740ustar00rootroot00000000000000#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.3/test/000077500000000000000000000000001466777427300156115ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/test/README.md000066400000000000000000000072121466777427300170720ustar00rootroot00000000000000# 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.3/test/check-all-tests-are-in-meson.py000077500000000000000000000025061466777427300234440ustar00rootroot00000000000000#!/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.3/test/integration-test-common/000077500000000000000000000000001466777427300223775ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/test/integration-test-common/integration-test-common.c000066400000000000000000000045741466777427300273430ustar00rootroot00000000000000#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.3/test/integration-test-common/integration-test-common.h000066400000000000000000000022741466777427300273430ustar00rootroot00000000000000#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.3/test/integration-test-common/meson.build000066400000000000000000000002631466777427300245420ustar00rootroot00000000000000integration_test_common = declare_dependency( dependencies: [test_common], include_directories: include_directories('.'), sources: files('integration-test-common.c')) gtk4-layer-shell-1.0.3/test/integration-tests/000077500000000000000000000000001466777427300212745ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/test/integration-tests/meson.build000066400000000000000000000020171466777427300234360ustar00rootroot00000000000000integration_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.3/test/integration-tests/test-adapts-to-screen-size.c000066400000000000000000000024761466777427300265470ustar00rootroot00000000000000#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.3/test/integration-tests/test-auto-exclusive-zone-no-margin.c000066400000000000000000000027521466777427300302360ustar00rootroot00000000000000#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.3/test/integration-tests/test-auto-exclusive-zone-weird-bool-values.c000066400000000000000000000014111466777427300316760ustar00rootroot00000000000000#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.3/test/integration-tests/test-auto-exclusive-zone-with-margin.c000066400000000000000000000014441466777427300305720ustar00rootroot00000000000000#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.3/test/integration-tests/test-close-layer-surface.c000066400000000000000000000006271466777427300262670ustar00rootroot00000000000000#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.3/test/integration-tests/test-create-xdg-toplevel.c000066400000000000000000000021341466777427300262700ustar00rootroot00000000000000#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.3/test/integration-tests/test-creation-properties.c000066400000000000000000000012561466777427300264170ustar00rootroot00000000000000#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.3/test/integration-tests/test-exclusive-zone-below-negative-1.c000066400000000000000000000010131466777427300304340ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-auto-exclusive-zone.c000066400000000000000000000017211466777427300271210ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-explicit-exclusive-zone.c000066400000000000000000000013651466777427300277760ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-keyboard-mode.c000066400000000000000000000014311466777427300257130ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-layer.c000066400000000000000000000014561466777427300243140ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-margin.c000066400000000000000000000033061466777427300244510ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-monitor.c000066400000000000000000000014461466777427300246660ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-namespace-custom-namespace.c000066400000000000000000000006041466777427300303700ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-namespace-default.c000066400000000000000000000005371466777427300265550ustar00rootroot00000000000000#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.3/test/integration-tests/test-get-namespace-on-non-layer-window.c000066400000000000000000000004301466777427300307440ustar00rootroot00000000000000#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.3/test/integration-tests/test-hide-and-show.c000066400000000000000000000012201466777427300250370ustar00rootroot00000000000000#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.3/test/integration-tests/test-init-after-window-created.c000066400000000000000000000010041466777427300273640ustar00rootroot00000000000000#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.3/test/integration-tests/test-is-layer-window.c000066400000000000000000000011231466777427300254440ustar00rootroot00000000000000#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.3/test/integration-tests/test-is-supported-true.c000066400000000000000000000002621466777427300260300ustar00rootroot00000000000000#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.3/test/integration-tests/test-layer-surface-not-created.c000066400000000000000000000004601466777427300273620ustar00rootroot00000000000000#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.3/test/integration-tests/test-menu-popup.c000066400000000000000000000014551466777427300245270ustar00rootroot00000000000000#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.3/test/integration-tests/test-multi-anchors.c000066400000000000000000000030151466777427300252010ustar00rootroot00000000000000#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.3/test/integration-tests/test-set-anchor-normalizes-booleans.c000066400000000000000000000012431466777427300304410ustar00rootroot00000000000000#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.3/test/integration-tests/test-set-default-size.c000066400000000000000000000036041466777427300256050ustar00rootroot00000000000000#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.3/test/integration-tests/test-set-keyboard-mode.c000066400000000000000000000015421466777427300257320ustar00rootroot00000000000000#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.3/test/integration-tests/test-set-layer.c000066400000000000000000000020001466777427300243120ustar00rootroot00000000000000#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.3/test/integration-tests/test-set-margin.c000066400000000000000000000024121466777427300244620ustar00rootroot00000000000000#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.3/test/integration-tests/test-set-monitor.c000066400000000000000000000013541466777427300247000ustar00rootroot00000000000000#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.3/test/integration-tests/test-single-anchors.c000066400000000000000000000025141466777427300253330ustar00rootroot00000000000000#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.3/test/meson.build000066400000000000000000000026471466777427300177640ustar00rootroot00000000000000subdir('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.3/test/mock-server/000077500000000000000000000000001466777427300200465ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/test/mock-server/meson.build000066400000000000000000000004111466777427300222040ustar00rootroot00000000000000mock_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.3/test/mock-server/mock-server.c000066400000000000000000000103411466777427300224460ustar00rootroot00000000000000#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.3/test/mock-server/mock-server.h000066400000000000000000000037641466777427300224660ustar00rootroot00000000000000// 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 "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.3/test/mock-server/overrides.c000066400000000000000000000334011466777427300222150ustar00rootroot00000000000000#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); } gtk4-layer-shell-1.0.3/test/run-integration-test.py000077500000000000000000000252041466777427300222730ustar00rootroot00000000000000#!/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.3/test/smoke-tests/000077500000000000000000000000001466777427300200675ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/test/smoke-tests/meson.build000066400000000000000000000002071466777427300222300ustar00rootroot00000000000000smoke_tests = [ 'test-c-example', 'test-c-demo', 'test-python-example', 'test-lua-example', 'test-vala-example', ] gtk4-layer-shell-1.0.3/test/smoke-tests/smoke_test_common.py000066400000000000000000000015331466777427300241700ustar00rootroot00000000000000import 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.3/test/smoke-tests/test-c-demo.py000077500000000000000000000003431466777427300225650ustar00rootroot00000000000000#!/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.3/test/smoke-tests/test-c-example.py000077500000000000000000000002401466777427300232700ustar00rootroot00000000000000#!/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.3/test/smoke-tests/test-lua-example.py000077500000000000000000000006521466777427300236360ustar00rootroot00000000000000#!/usr/bin/env python3 import os import smoke_test_common script_path = os.path.join(os.path.dirname(__file__), '..', '..', 'examples', 'simple-example.lua') 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(['luajit', script_path], env) gtk4-layer-shell-1.0.3/test/smoke-tests/test-python-example.py000077500000000000000000000006521466777427300243760ustar00rootroot00000000000000#!/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.3/test/smoke-tests/test-vala-example.py000077500000000000000000000002431466777427300237740ustar00rootroot00000000000000#!/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.3/test/test-common/000077500000000000000000000000001466777427300200565ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/test/test-common/meson.build000066400000000000000000000001251466777427300222160ustar00rootroot00000000000000test_common = declare_dependency( include_directories: include_directories('.')) gtk4-layer-shell-1.0.3/test/test-common/test-common.h000066400000000000000000000015251466777427300224770ustar00rootroot00000000000000#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.3/test/unit-tests/000077500000000000000000000000001466777427300177305ustar00rootroot00000000000000gtk4-layer-shell-1.0.3/test/unit-tests/meson.build000066400000000000000000000003201466777427300220650ustar00rootroot00000000000000test('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.3/test/unit-tests/test-get-version.c000066400000000000000000000007041466777427300233140ustar00rootroot00000000000000#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; }