File gtk4-layer-shell-1.1.1.obscpio of Package gtk4-layer-shell

07070100000000000081A400000000000000000000000168059A4800000073000000000000000000000000000000000000002500000000gtk4-layer-shell-1.1.1/.editorconfigroot = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
07070100000001000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000001F00000000gtk4-layer-shell-1.1.1/.github07070100000002000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002900000000gtk4-layer-shell-1.1.1/.github/workflows07070100000003000081A400000000000000000000000168059A4800000285000000000000000000000000000000000000003C00000000gtk4-layer-shell-1.1.1/.github/workflows/build_and_test.ymlname: '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 wayland-protocols libgtk-4-dev gobject-introspection libgirepository1.0-dev valac gtk-doc-tools
    - name: Meson
      run: meson setup -Dexamples=true -Ddocs=true -Dtests=true build
      env:
        CFLAGS: -Werror
    - name: Build
      run: ninja -C build
    - name: Test
      run: meson test -C build --verbose
07070100000004000081A400000000000000000000000168059A480000069C000000000000000000000000000000000000003900000000gtk4-layer-shell-1.1.1/.github/workflows/deploy_docs.ymlname: '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 wayland-protocols 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.html ./_site/index.html
    - name: Upload artifact
      uses: actions/upload-pages-artifact@v3

  # 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@v4
07070100000005000081A400000000000000000000000168059A4800000038000000000000000000000000000000000000002200000000gtk4-layer-shell-1.1.1/.gitignorebuild/
gtk-priv/build/
*/__pycache__
*.pyc
.mypy_cache/
07070100000006000081A400000000000000000000000168059A4800000C11000000000000000000000000000000000000002400000000gtk4-layer-shell-1.1.1/CHANGELOG.md# Changelog

## [Unreleased]
## [1.1.1] - 29 Mar 2025
- Bump required meson version to 0.54.0
- Control which symbols are exported, do not expose private/unstable functions which have never been in public headers
- Correct annotations in doc comments
- Automatically remap surfaces when monitors change

## [1.1.0] - 29 Jan 2025
This release includes two important new features.

### ext_session_lock_v1
A 2nd Wayland protocol, is used to build lock screens for [these compositors](https://wayland.app/protocols/ext-session-lock-v1#compositor-support).

### liblayer-shell-preload.so
Hack for running arbitrary Wayland windows as Layer Shell surfaces without recompiling. More details [here](https://github.com/wmww/gtk4-layer-shell/blob/main/layer_shell_preload.md).

Changelog:
- Major refactor and improvements to internal architecture, made new features possible but this release is more likely to introduce bugs than others
- Use `RTLD_NEXT` in libwayland-shim, dlopening libwayland is no longer needed
- Add support for `ext_session_lock_v1` protocol (thanks @happenslol for the initial implementation!)
- Add examples, tests and docs for Session Lock support
- Add and document `liblayer-shell-preload.so`

## [1.0.4] - 4 Nov 2024
- Fix protocol error on Wayfire, due to sending zwlr_layer_shell_surface_v1->configure too early
- Fix crash when hovering over a tooltip on Hyprland, due to using an old copy of xdg-shell.xml
- Fix protocol error on GTK4 >=4.16 on KDE and Hyprland, due to request arguments including references to client-only objects
- Add xdg-dialog-v1 to the mock server used by the tests, so the invalid argument bug is regression tested
- Drop Lua example and smoke test (the library should work with Lua just as well as before, but this is no longer tested or officially supported)
- Fix and suppress various warnings

## [1.0.3] - 10 Sep 2024
- Tests: make tests compatible with new libwayland format
- Tests: fix `integration-test-menu-popup` by sending wl_buffer.release in mock server
- Fix: dlopen `libwayland-client.so.0` in addition to `libwayland-client.so`, fixes [#39](https://github.com/wmww/gtk4-layer-shell/issues/39)

## [1.0.2] - 7 Nov 2023
- Fix tests on Arch
- Realize and unrealize on remap instead of setting visibility
- Fix major use-after-free bug causing many crashes

## [1.0.1] - 1 Jul 2023
- Add lua example
- Add links to Rust and Ruby bindings
- Fix doc name conflicts with GTK3 library version
- Add smoke tests

## [1.0.0] - 11 Apr 2023
- Port library and examples from GTK3 to GTK4
- Remove deprecated functions `gtk_layer_set_keyboard_interactivity()` and `gtk_layer_get_keyboard_interactivity()` (`gtk_layer_set_keyboard_mode()` and `gtk_layer_get_keyboard_mode()` can be used instead)
- Change how layer surface window size is controlled, use `gtk_window_set_default_size()` now
- Build [documentation](https://wmww.github.io/gtk4-layer-shell/) with GitHub actions and host with GitHub Pages
- __EDIT:__ Change license from LGPL to MIT (most of the gtk-layer-shell code was always MIT, and the LGPL bits have all been dropped)
07070100000007000081A400000000000000000000000168059A4800000438000000000000000000000000000000000000001F00000000gtk4-layer-shell-1.1.1/LICENSEThe 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.
07070100000008000081A400000000000000000000000168059A48000017E0000000000000000000000000000000000000002100000000gtk4-layer-shell-1.1.1/README.md# GTK4 Layer Shell

![GTK4 Layer Demo screenshot](https://i.imgur.com/dR8X15i.png)

A library for using the Layer Shell and Session Lock Wayland protocols with [GTK4](https://www.gtk.org/). This Library is compatible with C, C++ and any language that supports GObject introspection files (Python, Vala, etc).

The [Layer Shell](https://wayland.app/protocols/wlr-layer-shell-unstable-v1) protocol allows building desktop shell components such as panels, notifications and wallpapers. It can be used to anchor your windows to a corner or edge of the output, or stretch them across the entire output.

The [Session Lock](https://wayland.app/protocols/ext-session-lock-v1) protocol allows building lock screens.

[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 your program includes GTK4 Layer Shell in any way and misbehaves, assume it's a GTK4 Layer Shell bug. If you can reproduce the problem without including or linking to the gtk4-layer-shell library **at all** then and only then report it to GTK instead of here.

## Supported Desktops
This library only works on Wayland, and only on Wayland compositors that support the Layer Shell protocol. Layer shell __is supported__ on:
- wlroots based compositors (such as __Sway__)
- Smithay based compositors (such as __COSMIC__)
- __Mir__ based compositors (some may not enable the protocol by default. It can be enabled with `--add-wayland-extension zwlr_layer_shell_v1`)
- __KDE Plasma__ on wayland

Layer shell __is not supported__ on:
- Gnome-on-Wayland
- Any X11 desktop

## Using the Library
### Demo
`gtk4-layer-demo` is built if examples are enabled. It's useful for testing layer shell support in compositors. Its code can be found in [examples/demo/](examples/demo/).

### C/C++
The easiest way to build against GTK Layer Shell is to use the `gtk-layer-shell-0` pkg-config package. Refer to your build system or the pkg-config docs for further instructions. [examples/simple-example.c](examples/simple-example.c) is a minimal complete app written in C. __If you link against libwayland, you must link libwayland after gtk4-layer-shell__. See [linking.md](linking.md) for details.

### Python
[examples/simple-example.py](examples/simple-example.py) contains sample Python code.

### Vala
[examples/simple-example.vala](examples/simple-example.vala) contains a minimal working Vala app.

### Rust
[@pentamassiv](https://github.com/pentamassiv) maintains [safe Rust bindings](https://github.com/pentamassiv/gtk4-layer-shell-gir) and the [crates.io crate](https://crates.io/crates/gtk4-layer-shell/). Rust examples can be found [here](https://github.com/pentamassiv/gtk4-layer-shell-gir/tree/main/gtk4-layer-shell/examples).

### Ruby
[mswiger](https://github.com/mswiger) maintains [Ruby bindings](https://github.com/mswiger/ruby-gtk4-layer-shell) which are published to [RubyGems](https://rubygems.org/gems/gtk4_layer_shell).

## Distro Packages
[![List of distros GTK Layer Shell is packaged for](https://repology.org/badge/vertical-allrepos/gtk4-layer-shell.svg)](https://repology.org/project/gtk4-layer-shell/versions)

## Building From Source
1. Clone this repo
2. Install build dependencies (see below)
3. `$ meson setup -Dexamples=true -Ddocs=true -Dtests=true build` (NOTE: `--prefix=/usr` may be needed on Arch Linux)
4. `$ ninja -C build`
5. `$ sudo ninja -C build install`
6. `$ sudo ldconfig`

### Build Dependencies
* [Meson](https://mesonbuild.com/) (>=0.45.1)
* [Ninja](https://ninja-build.org/) (>=1.8.2)
* [libwayland](https://gitlab.freedesktop.org/wayland/wayland) (>=1.10.0)
* [wayland-protocols](https://gitlab.freedesktop.org/wayland/wayland-protocols) (>=1.16.0)
* [GTK4](https://www.gtk.org/)
* __If `introspection` enabled:__ [GObject introspection](https://gitlab.gnome.org/GNOME/gobject-introspection/)
* __If `docs` enabled:__ [GTK Doc](https://wiki.gnome.org/DocumentationProject/GtkDoc)
* __If `tests` enabled:__ [Python3](https://www.python.org/)
* __If `vapi` enabled:__ [Vala](https://wiki.gnome.org/Projects/Vala)

To install these dependencies on Ubuntu 18.04 and later:
```
sudo apt install meson ninja-build libwayland-dev wayland-protocols 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 wayland-protocols 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 -C build --verbose <testname>`
* To watch a specific test run against the currently active Wayland compositor `ninja -C build && ./build/test/<testname> --auto`
* To run the test in interactive mode it's same as above, but without the `--auto` flag
* If you have [wayland-debug](https://github.com/wmww/wayland-debug), `wayland-debug -f 'zwlr_*, xdg_*' -r ./build/test/<testname> --auto` can be helpful for debugging

## Licensing
100% MIT (unlike the GTK3 version of this library which contained GPL code copied from GTK)
07070100000009000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000001B00000000gtk4-layer-shell-1.1.1/doc0707010000000A000081A400000000000000000000000168059A48000005E8000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/doc/gtk4-layer-shell-docs.sgml<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
[
  <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
  <!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
  %gtkdocentities;
]>
<book id="index">
  <bookinfo>
    <title>&package_name;</title>
    <releaseinfo>
      <para>
        This document is the API reference for for &package_name; &package_version;.
      </para>
    </releaseinfo>
  </bookinfo>

  <part id="gtk4-layer-shell">
    <title>API Reference</title>
    <partintro>
      <para>
        gtk4-layer-shell is a library to use Wayland protocol extensions (primarily Layer Shell) with
        <ulink type ="http" url="https://www.gtk.org/">GTK4</ulink>.
      </para>
      <para>
        Source code repo
        <ulink type="http" url="&package_url;">here</ulink>.
      </para>
    </partintro>
    <xi:include href="xml/gtk4-layer-shell.xml"/>
    <xi:include href="xml/gtk4-session-lock.xml"/>
  </part>

  <index id="api-index-full">
    <title>API Index</title>
    <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
  </index>

  <index id="deprecated-api-index" role="deprecated">
    <title>Index of deprecated API</title>
    <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
  </index>

  <!-- <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include> -->
</book>
0707010000000B000081A400000000000000000000000168059A48000003D7000000000000000000000000000000000000002700000000gtk4-layer-shell-1.1.1/doc/meson.buildsubdir('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.source_root(), 'src'),
        join_paths(meson.build_root(), 'include'),
    ],
    dependencies: [gtk_layer_shell, 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, 'gtk4')),
    ],
    scan_args: ['--rebuild-types'],
    install_dir: 'gtk4-layer-shell',
    install: true
)
0707010000000C000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000001F00000000gtk4-layer-shell-1.1.1/doc/xml0707010000000D000081A400000000000000000000000168059A480000015C000000000000000000000000000000000000003500000000gtk4-layer-shell-1.1.1/doc/xml/gtkdocentities.ent.in<!ENTITY package "@PACKAGE@">
<!ENTITY package_bugreport "@PACKAGE_BUGREPORT@">
<!ENTITY package_name "@PACKAGE_NAME@">
<!ENTITY package_string "@PACKAGE_STRING@">
<!ENTITY package_tarname "@PACKAGE_TARNAME@">
<!ENTITY package_url "@PACKAGE_URL@">
<!ENTITY package_version "@PACKAGE_VERSION@">
<!ENTITY package_api_version "@PACKAGE_API_VERSION@">
0707010000000E000081A400000000000000000000000168059A4800000279000000000000000000000000000000000000002B00000000gtk4-layer-shell-1.1.1/doc/xml/meson.buildent_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)

0707010000000F000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002000000000gtk4-layer-shell-1.1.1/examples07070100000010000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002500000000gtk4-layer-shell-1.1.1/examples/demo07070100000011000081A400000000000000000000000168059A4800000DA8000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/examples/demo/anchor-control.c#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;
}
07070100000012000081A400000000000000000000000168059A48000040C9000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/examples/demo/gtk-layer-demo.c#include "gtk-layer-demo.h"
#include <stdlib.h>

static GtkLayerShellLayer default_layer = GTK_LAYER_SHELL_LAYER_TOP;

static gboolean default_anchors[] = {FALSE, FALSE, FALSE, FALSE};
static int default_margins[] = {0, 0, 0, 0};

static gboolean default_auto_exclusive_zone = FALSE; // always set by command line option
static GtkLayerShellKeyboardMode default_keyboard_mode =
    GTK_LAYER_SHELL_KEYBOARD_MODE_NONE; // always set by command line option
static gboolean default_fixed_size = FALSE; // always set by command line option
static gboolean no_layer_shell = FALSE; // always set by command line option
static gboolean show_version_and_exit = FALSE; // always set by command line option

const char* prog_name = "gtk4-layer-demo";
const char* prog_summary = "A GTK application for demonstrating the functionality of the Layer Shell Wayland protocol";
const char* prog_details = "See https://github.com/wmww/gtk-layer-shell for more information, and to report bugs";

const char* anchor_edges_key = "anchor_edges";
const int fixed_size_width = 600;
const int fixed_size_height = 500;

gboolean layer_option_callback(const gchar* option_name, const gchar* value, void* data, GError **error);
gboolean anchor_option_callback(const gchar* option_name, const gchar* value, void* data, GError **error);
gboolean keyboard_option_callback(const gchar* option_name, const gchar* value, void* data, GError **error);
gboolean margin_option_callback(const gchar* option_name, const gchar* value, void* data, GError **error);

static const GOptionEntry options[] = { {
        .long_name = "version",
        .short_name = 'v',
        .flags = G_OPTION_FLAG_NONE,
        .arg = G_OPTION_ARG_NONE,
        .arg_data = &show_version_and_exit,
        .description = "Show version and exit",
        .arg_description = NULL,
    }, {
        .long_name = "layer",
        .short_name = 'l',
        .flags = G_OPTION_FLAG_NONE,
        .arg = G_OPTION_ARG_CALLBACK,
        .arg_data = (void*)&layer_option_callback,
        .description = "'overlay', 'top', 'bottom' or 'background' (or 'o', 't', 'b' or 'g')",
        .arg_description = NULL,
    }, {
        .long_name = "anchor",
        .short_name = 'a',
        .flags = G_OPTION_FLAG_OPTIONAL_ARG,
        .arg = G_OPTION_ARG_CALLBACK,
        .arg_data = (void*)&anchor_option_callback,
        .description = "A sequence of 'l', 'r', 't' and 'b' to anchor to those edges, or '0' for no anchor",
        .arg_description = NULL,
    }, {
        .long_name = "margin",
        .short_name = 'm',
        .flags = G_OPTION_FLAG_NONE,
        .arg = G_OPTION_ARG_CALLBACK,
        .arg_data = (void*)&margin_option_callback,
        .description = "Comma separated list of margin values, in the order LEFT,RIGHT,TOP,BOTTOM",
        .arg_description = NULL,
    }, {
        .long_name = "exclusive",
        .short_name = 'e',
        .flags = G_OPTION_FLAG_NONE,
        .arg = G_OPTION_ARG_NONE,
        .arg_data = &default_auto_exclusive_zone,
        .description = "Enable auto exclusive zone",
        .arg_description = NULL,
    }, {
        .long_name = "keyboard",
        .short_name = 'k',
        .flags = G_OPTION_FLAG_OPTIONAL_ARG,
        .arg = G_OPTION_ARG_CALLBACK,
        .arg_data = (void*)&keyboard_option_callback,
        .description = "Set keyboard interactivity: 'none', 'exclusive' or 'on-demand' (or 'n', 'e' or 'o')",
        .arg_description = NULL,
    }, {
        .long_name = "fixed-size",
        .short_name = 'f',
        .flags = G_OPTION_FLAG_NONE,
        .arg = G_OPTION_ARG_NONE,
        .arg_data = &default_fixed_size,
        .description = "Enable a fixed window size",
        .arg_description = NULL,
    }, {
        .long_name = "no-layer-shell",
        .short_name = 0,
        .flags = G_OPTION_FLAG_NONE,
        .arg = G_OPTION_ARG_NONE,
        .arg_data = &no_layer_shell,
        .description = "Disable gtk4-layer-shell, create a normal shell surface instead",
        .arg_description = NULL,
    }, { NULL, 0, 0, 0, NULL, NULL, NULL }
};

gboolean layer_option_callback(const gchar* _option_name, const gchar* value, void* _data, GError **error) {
    (void)_option_name;
    (void)_data;

    if (g_strcmp0(value, "overlay") == 0 || g_strcmp0(value, "o") == 0) {
        default_layer = GTK_LAYER_SHELL_LAYER_OVERLAY;
    } else if (g_strcmp0(value, "top") == 0 || g_strcmp0(value, "t") == 0) {
        default_layer = GTK_LAYER_SHELL_LAYER_TOP;
    } else if (g_strcmp0(value, "bottom") == 0 || g_strcmp0(value, "b") == 0) {
        default_layer = GTK_LAYER_SHELL_LAYER_BOTTOM;
    } else if (g_strcmp0(value, "background") == 0 || g_strcmp0(value, "g") == 0) {
        default_layer = GTK_LAYER_SHELL_LAYER_BACKGROUND;
    } else {
        g_set_error(error,
                     G_OPTION_ERROR,
                     G_OPTION_ERROR_FAILED,
                     "Invalid layer '%s' "
                     "(valid layers are 'overlay', 'top', 'bottom', 'background', 'o', 't', 'b' and 'g')",
                     value);
        return FALSE;
    }
    return TRUE;
}

gboolean anchor_option_callback(const gchar* _option_name, const gchar* value, void* _data, GError **error) {
    (void)_option_name;
    (void)_data;

    for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) {
        default_anchors[i] = FALSE;
    }

    if (!value || !*value || g_strcmp0(value, "0") == 0 || g_strcmp0(value, "none") == 0) {
        return TRUE;
    }

    for (const char* c = value; *c; c++) {
        if (*c == 'l') {
            default_anchors[GTK_LAYER_SHELL_EDGE_LEFT] = TRUE;
        } else if (*c == 'r') {
            default_anchors[GTK_LAYER_SHELL_EDGE_RIGHT] = TRUE;
        } else if (*c == 't') {
            default_anchors[GTK_LAYER_SHELL_EDGE_TOP] = TRUE;
        } else if (*c == 'b') {
            default_anchors[GTK_LAYER_SHELL_EDGE_BOTTOM] = TRUE;
        } else {
            g_set_error(error,
                         G_OPTION_ERROR,
                         G_OPTION_ERROR_FAILED,
                         "Invalid anchor edge '%c' (valid edges are 'l', 'r', 't' and 'b')", *c);
            return FALSE;
        }
    }

    return TRUE;
}

gboolean keyboard_option_callback(const gchar* _option_name, const gchar* value, void* _data, GError **error) {
    (void)_option_name;
    (void)_data;

    if (!value) {
        // without argument = exclusive(retain old behavior)
        default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE;
        return TRUE;
    }
    if (g_strcmp0(value, "none") == 0 || g_strcmp0(value, "n") == 0) {
        default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_NONE;
    } else if (g_strcmp0(value, "exclusive") == 0 || g_strcmp0(value, "e") == 0) {
        default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE;
    } else if (g_strcmp0(value, "on-demand") == 0 || g_strcmp0(value, "o") == 0) {
        default_keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND;
    } else {
        g_set_error(error,
                     G_OPTION_ERROR,
                     G_OPTION_ERROR_FAILED,
                     "Invalid keyboard interactivity '%s' "
                     "(valid values are 'none', 'exclusive', 'on-demand', 'n', 'e' and 'o')",
                     value);
        return FALSE;
    }
    return TRUE;
}

gboolean margin_option_callback(const gchar* _option_name, const gchar* value, void* _data, GError **error) {
    (void)_option_name;
    (void)_data;

    for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) {
        if (!*value) {
            g_set_error(error,
                         G_OPTION_ERROR,
                         G_OPTION_ERROR_FAILED,
                         "Not enough comma separated arguments for margin");
            return FALSE;
        }
        char* end;
        long long margin = strtol(value, &end, 10);
        default_margins[i] = margin;
        if (end == value) {
            g_set_error(error,
                         G_OPTION_ERROR,
                         G_OPTION_ERROR_FAILED,
                         "Unable to parse margin");
            return FALSE;
        }
        value = end;
        if (*value == ',')
            value++;
    }
    if (*value) {
        g_set_error(error,
                     G_OPTION_ERROR,
                     G_OPTION_ERROR_FAILED,
                     "Too many comma separated arguments for margin");
        return FALSE;
    }
    return TRUE;
}

static void process_args(int* argc, char ***argv) {
    GOptionContext* context = g_option_context_new("");
    //g_option_context_add_group(context, gtk_get_option_group(TRUE));
    g_option_context_set_summary(context, prog_summary);
    g_option_context_set_description(context, prog_details);
    g_option_context_add_main_entries(context, options, NULL);

    GError* error = NULL;
    if (!g_option_context_parse(context, argc, argv, &error)) {
        g_printerr("%s\n", error->message);
        g_error_free(error);
        g_option_context_free(context);
        exit(1);
    }

    if (show_version_and_exit) {
        g_print(
            "%s on gtk4-layer-shell v%d.%d.%d\n",
            prog_name,
            gtk_layer_get_major_version(),
            gtk_layer_get_minor_version(),
            gtk_layer_get_micro_version());
        exit(0);
    }

    g_option_context_free(context);
}

void layer_window_update_orientation(GtkWindow* layer_window) {
    ToplevelData* data = g_object_get_data(G_OBJECT(layer_window), anchor_edges_key);
    gboolean horiz = data->edges[GTK_LAYER_SHELL_EDGE_LEFT] == data->edges[GTK_LAYER_SHELL_EDGE_RIGHT];
    gboolean vert = data->edges[GTK_LAYER_SHELL_EDGE_TOP] == data->edges[GTK_LAYER_SHELL_EDGE_BOTTOM];
    WindowOrientation orientation = WINDOW_ORIENTATION_NONE;
    if (horiz && (!vert || (data->edges[GTK_LAYER_SHELL_EDGE_LEFT] && !data->edges[GTK_LAYER_SHELL_EDGE_TOP]))) {
        orientation = WINDOW_ORIENTATION_HORIZONTAL;
    } else if (vert && (!horiz || (data->edges[GTK_LAYER_SHELL_EDGE_TOP] && !data->edges[GTK_LAYER_SHELL_EDGE_LEFT]))) {
        orientation = WINDOW_ORIENTATION_VERTICAL;
    }
    if (orientation != data->orientation) {
        data->orientation = orientation;
        g_signal_emit_by_name(layer_window, "orientation-changed", orientation);
    }
}

static void on_orientation_changed(GtkWindow* window, WindowOrientation orientation, ToplevelData* data) {
    (void)window;
    GtkOrientation orient_toplevel, orient_sub;
    orient_toplevel = GTK_ORIENTATION_HORIZONTAL;
    orient_sub = GTK_ORIENTATION_VERTICAL;

    switch (orientation) {
        case WINDOW_ORIENTATION_HORIZONTAL:
            orient_toplevel = GTK_ORIENTATION_HORIZONTAL;
            orient_sub = GTK_ORIENTATION_HORIZONTAL;
            break;
        case WINDOW_ORIENTATION_VERTICAL:
            orient_toplevel = GTK_ORIENTATION_VERTICAL;
            orient_sub = GTK_ORIENTATION_VERTICAL;
            break;
        case WINDOW_ORIENTATION_NONE:
            orient_toplevel = GTK_ORIENTATION_HORIZONTAL;
            orient_sub = GTK_ORIENTATION_VERTICAL;
            break;
    }
    gtk_orientable_set_orientation(GTK_ORIENTABLE(data->toplevel_box), orient_toplevel);
    gtk_orientable_set_orientation(GTK_ORIENTABLE(data->first_box), orient_sub);
    gtk_orientable_set_orientation(GTK_ORIENTABLE(data->second_box), orient_sub);
    //gtk_window_resize(window, 1, 1); // force the window to shrink to the smallest size it can
}

static void on_window_destroy(GtkWindow* window, GApplication* _data) {
    (void)_data;
    g_application_quit(G_APPLICATION(gtk_window_get_application(window)));
}

static void activate(GtkApplication* app, void* _data) {
    (void)_data;

    GtkWindow* gtk_window = GTK_WINDOW(gtk_application_window_new(app));

    ToplevelData* data = g_new0(ToplevelData, 1);
    g_object_set_data_full(G_OBJECT(gtk_window), anchor_edges_key, data, g_free);
    for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++)
        data->edges[i] = default_anchors[i];

    if (default_fixed_size)
        gtk_window_set_default_size(gtk_window, fixed_size_width, fixed_size_height);

    if (no_layer_shell) {
        g_message("GTK layer shell disabled on command line");
        g_message("Expect controls to have no effect and warnings to be shown");
    } else {
        gtk_layer_init_for_window(gtk_window);
    }

    for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++)
        gtk_layer_set_anchor(gtk_window, i, default_anchors[i]);
    for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++)
        gtk_layer_set_margin(gtk_window, i, default_margins[i]);
    gtk_layer_set_layer(gtk_window, default_layer);
    gtk_layer_set_keyboard_mode(gtk_window, default_keyboard_mode);
    gtk_layer_set_namespace(gtk_window, "demo");
    if (default_auto_exclusive_zone)
        gtk_layer_auto_exclusive_zone_enable(gtk_window);

    set_up_menubar(gtk_window);
    GtkWidget* centered_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_widget_set_margin_bottom(centered_vbox, 10);
    gtk_widget_set_margin_top(centered_vbox, 10);
    gtk_widget_set_margin_start(centered_vbox, 10);
    gtk_widget_set_margin_end(centered_vbox, 10);
    gtk_window_set_child(gtk_window, centered_vbox);
    GtkWidget* centered_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
    gtk_box_append(GTK_BOX(centered_vbox), centered_hbox);
    data->toplevel_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
    //gtk_container_set_border_width(GTK_CONTAINER(data->toplevel_box), 16);
    gtk_box_append(GTK_BOX(centered_hbox), data->toplevel_box); {
        data->first_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
        gtk_widget_set_vexpand(data->first_box, TRUE);
        gtk_box_append(GTK_BOX(data->toplevel_box), data->first_box); {
            GtkWidget* selections_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
            gtk_widget_set_vexpand(selections_box, TRUE);
            gtk_box_append(GTK_BOX(data->first_box), selections_box);
            gtk_box_append(GTK_BOX(selections_box),
                            monitor_selection_new(gtk_window));
            gtk_box_append(GTK_BOX(selections_box),
                            layer_selection_new(gtk_window, default_layer));
        }{
            gtk_box_append(GTK_BOX(data->first_box),
                            anchor_control_new(gtk_window, default_anchors));
        }
    }{
        data->second_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
        gtk_box_append(GTK_BOX(data->toplevel_box), data->second_box); {
            GtkWidget* toggles_box = mscl_toggles_new(gtk_window,
                                                       default_auto_exclusive_zone,
                                                       default_fixed_size);
            gtk_box_append(GTK_BOX(data->second_box), toggles_box);
            GtkWidget* kb_box = keyboard_selection_new(gtk_window, default_keyboard_mode);
            gtk_box_append(GTK_BOX(data->second_box), kb_box);
        } {
            GtkWidget* margin_and_version_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
            gtk_box_append(GTK_BOX(margin_and_version_box),
                            margin_control_new(gtk_window, default_margins));
            gtk_box_append(GTK_BOX(margin_and_version_box),
                            version_info_new());
            gtk_box_append(GTK_BOX(data->second_box),
                            margin_and_version_box);
        }
    }

    g_signal_connect(gtk_window, "orientation-changed", G_CALLBACK(on_orientation_changed), data);
    data->orientation = -1; // invalid value will force anchor_edges_update_orientation to update
    layer_window_update_orientation(gtk_window);

    g_signal_connect(gtk_window, "destroy", G_CALLBACK(on_window_destroy), NULL);
    gtk_window_present(gtk_window);
}

int main(int argc, char **argv) {
    g_set_prgname(prog_name);
    process_args(&argc, &argv);

    // The int arg is an enum of type WindowOrientation
    // Signal is emitted in anchor-control.c
    g_signal_new("orientation-changed",
                  GTK_TYPE_WINDOW,
                  G_SIGNAL_RUN_FIRST,
                  0, NULL, NULL,
                  g_cclosure_marshal_VOID__INT,
                  G_TYPE_NONE, 1, G_TYPE_INT);

    GtkApplication* app = gtk_application_new("com.github.wmww.gtk4-layer-shell.demo", G_APPLICATION_DEFAULT_FLAGS);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    int status = g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);
    return status;
}
07070100000013000081A400000000000000000000000168059A4800000562000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/examples/demo/gtk-layer-demo.h#ifndef GTK_LAYER_DEMO_H
#define GTK_LAYER_DEMO_H

#include "gtk4-layer-shell.h"
#include <gtk/gtk.h>

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
07070100000014000081A400000000000000000000000168059A4800000540000000000000000000000000000000000000003A00000000gtk4-layer-shell-1.1.1/examples/demo/keyboard-selection.c#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;
}
07070100000015000081A400000000000000000000000168059A48000004B2000000000000000000000000000000000000003700000000gtk4-layer-shell-1.1.1/examples/demo/layer-selection.c#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;
}
07070100000016000081A400000000000000000000000168059A4800000DC3000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/examples/demo/margin-control.c#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;
}
07070100000017000081A400000000000000000000000168059A480000048C000000000000000000000000000000000000003000000000gtk4-layer-shell-1.1.1/examples/demo/menu-bar.c#include "gtk-layer-demo.h"

static void quit_activated(GSimpleAction* action, GVariant* parameter, GApplication* application) {
    (void)action; (void)parameter;
    g_application_quit(application);
}

void set_up_menubar(GtkWindow* layer_window) {
    GSimpleAction* act_quit = g_simple_action_new("quit", NULL);
    g_action_map_add_action(G_ACTION_MAP(gtk_window_get_application(layer_window)), G_ACTION(act_quit));
    g_signal_connect(act_quit, "activate", G_CALLBACK(quit_activated), gtk_window_get_application(layer_window));

    GMenu* menubar = g_menu_new();
    gtk_application_set_menubar(GTK_APPLICATION(gtk_window_get_application(layer_window)), G_MENU_MODEL(menubar));
    gtk_application_window_set_show_menubar(GTK_APPLICATION_WINDOW(layer_window), TRUE);
    GMenuItem* menu_item = g_menu_item_new("GTK4 Layer Demo", NULL);
    GMenu* menu = g_menu_new();
    GMenuItem* menu_item_quit = g_menu_item_new("Quit", "app.quit");
    g_menu_append_item(menu, menu_item_quit);
    g_menu_item_set_submenu(menu_item, G_MENU_MODEL(menu));
    g_menu_append_item(menubar, menu_item);
    g_object_unref(menu_item_quit);
    g_object_unref(menu_item);
}
07070100000018000081A400000000000000000000000168059A48000000E9000000000000000000000000000000000000003100000000gtk4-layer-shell-1.1.1/examples/demo/meson.builddemo_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')
07070100000019000081A400000000000000000000000168059A480000064A000000000000000000000000000000000000003900000000gtk4-layer-shell-1.1.1/examples/demo/monitor-selection.c#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;
}
0707010000001A000081A400000000000000000000000168059A480000094D000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/examples/demo/mscl-toggles.c#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;
}
0707010000001B000081A400000000000000000000000168059A4800000299000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/examples/demo/version-info.c#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;
}
0707010000001C000081A400000000000000000000000168059A48000003C3000000000000000000000000000000000000002C00000000gtk4-layer-shell-1.1.1/examples/meson.buildsubdir('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)

executable(
    'session-lock-c',
    files('session-lock.c'),
    build_by_default: get_option('examples'),
    dependencies: [gtk, gtk_layer_shell],
    install: false)

if get_option('vapi')
    add_languages('vala', native: false)
    executable(
        'simple-example-vala',
        files('simple-example.vala'),
        dependencies: [gtk, gtk_layer_shell, vapi],
        c_args: [
            '-Wno-unused-but-set-variable',
            '-Wno-unused-parameter',
            '-Wno-cast-function-type',
            '-Wno-deprecated-declarations',
        ],
        install: false)
endif
0707010000001D000081A400000000000000000000000168059A4800000BD7000000000000000000000000000000000000002F00000000gtk4-layer-shell-1.1.1/examples/session-lock.c#include "gtk4-session-lock.h"
#include <gtk/gtk.h>

static GtkApplication* app = NULL;
static GtkSessionLockInstance* lock = NULL;

static void unlock(GtkButton *button, void *data) {
    (void)button;
    (void)data;

    gtk_session_lock_instance_unlock(lock);
    g_application_quit(G_APPLICATION(app));
}

static void locked(GtkSessionLockInstance *lock, void *data) {
    (void)lock;
    (void)data;

    g_message("Session locked successfully");
}

static void failed(GtkSessionLockInstance *lock, void *data) {
    (void)lock;
    (void)data;

    g_critical("The session could not be locked");
    g_application_quit(G_APPLICATION(app));
}

static void unlocked(GtkSessionLockInstance *lock, void *data) {
    (void)lock;
    (void)data;

    g_message("Session unlocked");
    g_application_quit(G_APPLICATION(app));
}

static void activate(GtkApplication* app, void *data) {
    (void)data;
    g_application_hold(G_APPLICATION(app));

    lock = gtk_session_lock_instance_new();
    g_signal_connect(lock, "locked", G_CALLBACK(locked), NULL);
    g_signal_connect(lock, "failed", G_CALLBACK(failed), NULL);
    g_signal_connect(lock, "unlocked", G_CALLBACK(unlocked), NULL);

    if (!gtk_session_lock_instance_lock(lock)) {
        // Error message already shown when handling the ::failed signal
        return;
    }

    GdkDisplay *display = gdk_display_get_default();
    GListModel *monitors = gdk_display_get_monitors(display);
    guint n_monitors = g_list_model_get_n_items(monitors);

    for (guint i = 0; i < n_monitors; ++i) {
        GdkMonitor *monitor = g_list_model_get_item(monitors, i);

        GtkWindow *gtk_window = GTK_WINDOW(gtk_application_window_new(app));
        gtk_session_lock_instance_assign_window_to_monitor(lock, gtk_window, monitor);

        GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
        gtk_widget_set_halign(box, GTK_ALIGN_CENTER);
        gtk_widget_set_valign(box, GTK_ALIGN_CENTER);
        gtk_box_set_spacing(GTK_BOX (box), 10);

        GtkWidget *label = gtk_label_new("GTK Session Lock example");
        gtk_box_append(GTK_BOX(box), label);

        GtkWidget *button = gtk_button_new_with_label("Unlock");
        g_signal_connect(button, "clicked", G_CALLBACK(unlock), app);
        gtk_box_append(GTK_BOX(box), button);

        // Not displayed, but allows testing that creating popups doesn't crash GTK
        gtk_widget_set_tooltip_text(button, "Foo Bar Baz");

        gtk_window_set_child(GTK_WINDOW(gtk_window), box);
        gtk_window_present(gtk_window);
    }
}

int main(int argc, char **argv) {
    if (!gtk_session_lock_is_supported()) {
        g_message("Session lock not supported");
        return 1;
    }
    app = gtk_application_new(
        "com.github.wmww.gtk4-layer-shell.session-lock-example",
        G_APPLICATION_DEFAULT_FLAGS
    );
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    int status = g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);
    return status;
}
0707010000001E000081A400000000000000000000000168059A48000008E9000000000000000000000000000000000000003000000000gtk4-layer-shell-1.1.1/examples/session-lock.py# 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/session-lock.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('Gtk4SessionLock', '1.0')

from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Gtk4SessionLock as SessionLock

class ScreenLock:
    def __init__(self):
        self.lock_instance = SessionLock.Instance.new()
        self.lock_instance.connect('locked', self._on_locked)
        self.lock_instance.connect('unlocked', self._on_unlocked)
        self.lock_instance.connect('failed', self._on_failed)

    def _on_locked(self, lock_instance):
        print('Locked!')

    def _on_unlocked(self, lock_instance):
        print('Unlocked!')
        app.quit()

    def _on_failed(self, lock_instance):
        print('Failed to lock :(')
        app.quit()

    def _on_unlock_clicked(self, button):
        self.lock_instance.unlock()

    def _create_lock_window(self, monitor):
        window = Gtk.Window(application=app)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
        box.set_halign(Gtk.Align.CENTER)
        box.set_valign(Gtk.Align.CENTER)
        window.set_child(box)

        label = Gtk.Label(label="GTK Session Lock with Python")
        box.append(label)

        button = Gtk.Button(label='Unlock')
        button.connect('clicked', self._on_unlock_clicked)
        box.append(button)

        self.lock_instance.assign_window_to_monitor(window, monitor)
        window.present()

    def lock(self):
        if not self.lock_instance.lock():
            # Failure has already been handled in on_failed()
            return

        display = Gdk.Display.get_default()

        for monitor in display.get_monitors():
            self._create_lock_window(monitor)

app = Gtk.Application(application_id='com.github.wmww.gtk4-layer-shell.py-session-lock')
lock = ScreenLock()

def on_activate(app):
    lock.lock()

app.connect('activate', on_activate)
app.run(None)
0707010000001F000081A400000000000000000000000168059A48000007FD000000000000000000000000000000000000003100000000gtk4-layer-shell-1.1.1/examples/simple-example.c#include "gtk4-layer-shell.h"
#include <gtk/gtk.h>

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),
        "<span font_desc=\"100.0\">"
            "GTK Layer\nShell example!"
        "</span>"
    );
    gtk_window_set_child(gtk_window, label);
    gtk_window_present(gtk_window);
}

int main(int argc, char **argv) {
    GtkApplication* app = gtk_application_new("com.github.wmww.gtk4-layer-shell.example", G_APPLICATION_DEFAULT_FLAGS);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    int status = g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);
    return status;
}
07070100000020000081A400000000000000000000000168059A4800000509000000000000000000000000000000000000003200000000gtk4-layer-shell-1.1.1/examples/simple-example.py# 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)
07070100000021000081A400000000000000000000000168059A4800000356000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/examples/simple-example.valausing 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);
}
07070100000022000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000001F00000000gtk4-layer-shell-1.1.1/include07070100000023000081A400000000000000000000000168059A4800002EDE000000000000000000000000000000000000003200000000gtk4-layer-shell-1.1.1/include/gtk4-layer-shell.h#ifndef GTK_LAYER_SHELL_H
#define GTK_LAYER_SHELL_H

#include <gtk/gtk.h>

/**
 * SECTION:gtk4-layer-shell
 * @title: GTK4 Layer Shell
 * @short_description: GTK4 support for the Layer Shell Wayland protocol
 *
 * [Layer Shell](https://wayland.app/protocols/wlr-layer-shell-unstable-v1)
 * 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 aims to support all Layer Shell features,
 * and supports GTK popups and popovers.
 *
 * This library only functions on Wayland compositors that the support Layer Shell.
 * __It does not work on X11 or GNOME on Wayland.__
 *
 * # Note On Linking
 * 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:
 * |[<!-- language="C" -->
 *   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. Setting to 1, 1 is sometimes useful
 * to keep the window the smallest it can be while still fitting its contents.
 */

#define GTK4_LAYER_SHELL_EXPORT __attribute__((__visibility__("default")))

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 = 0,
    GTK_LAYER_SHELL_LAYER_BOTTOM = 1,
    GTK_LAYER_SHELL_LAYER_TOP = 2,
    GTK_LAYER_SHELL_LAYER_OVERLAY = 3,
    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: (nullable): 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: (transfer none) (nullable): 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: (transfer none) (not nullable): 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: (nullable): 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_surface().
 *
 * Returns: (transfer none) (nullable): the monitor this surface will/has requested to be on.
 */
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
07070100000024000081A400000000000000000000000168059A4800000F7A000000000000000000000000000000000000003300000000gtk4-layer-shell-1.1.1/include/gtk4-session-lock.h#ifndef GTK_SESSION_LOCK_H
#define GTK_SESSION_LOCK_H

#include <gtk/gtk.h>

/**
 * SECTION:gtk4-session-lock
 * @title: GTK4 Session Lock
 * @short_description: GTK4 support for the Session Lock Wayland protocol
 *
 * [Session Lock](https://wayland.app/protocols/ext-session-lock-v1)
 * is a Wayland protocol for lock screens. Use it to lock the compositor
 * and display the lock screen. This library and the underlying Wayland
 * protocol do not handle authentication.
 *
 * # Note on popups
 * Popups (such as menus and tooltips) do not currently display while the screen is locked. Please use alternatives,
 * such as GtkPopover (which is backed by a subsurface instead of a popup).
 *
 * # Note On Linking
 * 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.
 */

#define GTK4_LAYER_SHELL_EXPORT __attribute__((__visibility__("default")))

G_BEGIN_DECLS

/**
 * gtk_session_lock_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
 * Session Lock protocol.
 */
gboolean gtk_session_lock_is_supported();

/**
 * GtkSessionLockInstance:
 *
 * An instance of the object used to control locking the screen.
 * Multiple instances can exist at once, but only one can be locked at a time.
 */
GTK4_LAYER_SHELL_EXPORT
G_DECLARE_FINAL_TYPE(GtkSessionLockInstance, gtk_session_lock_instance, GTK_SESSION_LOCK, INSTANCE, GObject)

/**
 * GtkSessionLockInstance::locked:
 *
 * The ::locked signal is fired when the screen is successfully locked.
 */

/**
 * GtkSessionLockInstance::failed:
 *
 * The ::failed signal is fired when the lock could not be acquired.
 */

/**
 * GtkSessionLockInstance::unlocked:
 *
 * The ::unlocked signal is fired when the session is unlocked, which may have been caused by a call to
 * gtk_session_lock_instance_unlock() or by the compositor.
 */

/**
 * gtk_session_lock_instance_new:
 *
 * Returns: new session lock instance
 */
GtkSessionLockInstance* gtk_session_lock_instance_new();

/**
 * gtk_session_lock_instance_lock:
 * @self: the instance to lock
 *
 * Lock the screen. This should be called before assigning any windows to monitors. If this function fails the ::failed
 * signal is emitted, if it succeeds the ::locked signal is emitted. The ::failed signal may be emitted before the
 * function returns (for example, if another #GtkSessionLockInstance holds a lock) or later (if another process holds a
 * lock). The only case where neither signal is triggered is if the instance is already locked.
 *
 * Returns: false on immediate fail, true if lock acquisition was successfully started
 */
gboolean gtk_session_lock_instance_lock(GtkSessionLockInstance* self);

/**
 * gtk_session_lock_instance_unlock:
 * @self: the instance to unlock
 *
 * If the screen is locked by this instance unlocks it and fires ::unlocked. Otherwise has no effect
 */
void gtk_session_lock_instance_unlock(GtkSessionLockInstance* self);

/**
 * gtk_session_lock_instance_is_locked:
 * @self: the instance
 *
 * Returns if this instance currently holds a lock.
 */
gboolean gtk_session_lock_instance_is_locked(GtkSessionLockInstance* self);

/**
 * gtk_session_lock_instance_assign_window_to_monitor:
 * @self: the instance to use
 * @window: The GTK Window to use as a lock surface
 * @monitor: (not nullable): The monitor to show it on
 *
 * This must be called with a different window once for each monitor, immediately after calling
 * gtk_session_lock_lock(). Hiding a window that is active on a monitor or not letting a window be resized by the
 * library is not allowed (may result in a Wayland protocol error).
 */
void gtk_session_lock_instance_assign_window_to_monitor(
    GtkSessionLockInstance* self,
    GtkWindow *window,
    GdkMonitor *monitor
);

G_END_DECLS

#endif // GTK_SESSION_LOCK_H
07070100000025000081A400000000000000000000000168059A48000000B5000000000000000000000000000000000000002B00000000gtk4-layer-shell-1.1.1/include/meson.buildgtk_layer_shell_inc = include_directories('.')

install_headers('gtk4-layer-shell.h', subdir: 'gtk4-layer-shell')
install_headers('gtk4-session-lock.h', subdir: 'gtk4-layer-shell')
07070100000026000081A400000000000000000000000168059A48000008FB000000000000000000000000000000000000002E00000000gtk4-layer-shell-1.1.1/layer_shell_preload.md# Layer Shell Preload
`liblayer-shell-preload.so` is a hack to allow arbitrary Wayland apps to use the Layer Shell protocol. It uses the same approach as gtk4-layer-shell, but generalized to work with any `libwayland-client` program. It's designed to be `LD_PRELOAD`ed into pre-built binaries, no recompiling necessary.

There is no officially supported way to use Layer Shell Preload. If it works, it works. If it doesn't work or randomly stops working, that is a you problem. Not a me problem, and definitely not an upstream app dev problem. __Do not report bugs to app or toolkit developers if Layer Shell Preload is involved in any way.__ You're welcome to report bugs here, but I'm likely to ignore or close them (especially it's just "crashes X program").

## Usage
Run your program with `LD_PRELOAD` set to the path to `liblayer-shell-preload.so`, and use `LAYER_` environment variables to control the layer surface's properties. For example
```
$ LD_PRELOAD=/usr/lib/liblayer-shell-preload.so LAYER_ANCHOR='lrb' LAYER_HEIGHT=50 LAYER_EXCLUSIVE=1 LAYER_KEYBOARD=on-demand weston-terminal
```
The options are
| Variable | Values | Use |
| - | - | - |
| `LAYER_LAYER` | unset/`o`/`overlay`, `t`/`top`, `b`/`bottom`, `g`/`background` | The layer of the window (overlay and top are over other windows, bottom and background are below them) |
| `LAYER_ANCHOR` | One or more of the letters `l`, `r`, `t` and `b` in any order, or `0`/unset for none | Which edges of the screen to anchor the surface to |
| `LAYER_EXCLUSIVE` | unset/`0` or `1` | If to take up space and push other windows out of the way. Only works if anchored to an edge |
| `LAYER_WIDTH`/`LAYER_HEIGHT` | unset or any number | The preferred width and/or height for the surface when it's not being stretched across the screen |
| `LAYER_KEYBOARD` | unset/`n`/`none`, `e`/`exclusive` or `o`/`on-demand` | If to allow or lock keyboard focus on the window |
| `LAYER_NAMESPACE` | unset or any string | The `namespace` property for the layer shell surface, can be used by the Wayland compositor |
| `LAYER_ALL_SURFACES` | unset/`0` or `1` | By default only the first surface a program creates is a layer surface. With this set they all are. This breaks popups |

Output selection is not yet supported, but could be added in the future.
07070100000027000081A400000000000000000000000168059A4800000DA3000000000000000000000000000000000000002200000000gtk4-layer-shell-1.1.1/linking.md# 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 app 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)

Alternatively you can test by editing the CDLL call out of the example Python script and calling `ninja -C build && GI_TYPELIB_PATH=$PWD/build/src LD_LIBRARY_PATH=$PWD/build/src python examples/simple-example.py`.

## 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.
07070100000028000081A400000000000000000000000168059A4800000755000000000000000000000000000000000000002300000000gtk4-layer-shell-1.1.1/meson.buildproject('gtk4-layer-shell',
    ['c'],
    version: '1.1.1',
    license: 'MIT',
    meson_version: '>=0.54.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',
        '-fvisibility=hidden',
    ],
    language: 'c')

glib = dependency('glib-2.0', required: true) # Just needed for version check
if glib.version().version_compare('<2.74')
    add_project_arguments('-DG_APPLICATION_DEFAULT_FLAGS=G_APPLICATION_FLAGS_NONE', language: 'c')
endif

gtk = dependency('gtk4')
wayland_client = dependency('wayland-client', version: '>=1.10.0')

# only required for the tests
wayland_server = dependency('wayland-server', version: '>=1.10.0', required: false)

# wayland_scanner is required, but we can find it without pkg-config
wayland_scanner = dependency('wayland-scanner', version: '>=1.10.0', required: false, native: true)

# required, see https://github.com/wmww/gtk4-layer-shell/issues/24
wayland_protocols = dependency('wayland-protocols', version: '>=1.16', required: true)

pkg_config = import('pkgconfig')
gnome = import('gnome')

subdir('include')
subdir('protocol')
subdir('src')

gtk_layer_shell = declare_dependency(
    link_with: gtk_layer_shell_lib,
    include_directories: gtk_layer_shell_inc)

meson.override_dependency('gtk4-layer-shell', gtk_layer_shell)

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
07070100000029000081A400000000000000000000000168059A480000024C000000000000000000000000000000000000002900000000gtk4-layer-shell-1.1.1/meson_options.txtoption('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)')
0707010000002A000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002000000000gtk4-layer-shell-1.1.1/protocol0707010000002B000081A400000000000000000000000168059A48000005D7000000000000000000000000000000000000002C00000000gtk4-layer-shell-1.1.1/protocol/meson.buildif wayland_scanner.found()
    prog_wayland_scanner = find_program(wayland_scanner.get_variable(pkgconfig: 'wayland_scanner'))
else
    prog_wayland_scanner = find_program('wayland-scanner')
endif

protocols = [
    'wlr-layer-shell-unstable-v1.xml',
    join_paths(
        wayland_protocols.get_variable(pkgconfig: 'pkgdatadir'),
        'stable/xdg-shell/xdg-shell.xml'),
    join_paths(
        wayland_protocols.get_variable(pkgconfig: 'pkgdatadir'),
        'staging/ext-session-lock/ext-session-lock-v1.xml'),
]

if get_option('tests')
    protocols += 'xdg-dialog-v1.xml'
endif

gen_client_header = generator(prog_wayland_scanner,
    output: ['@BASENAME@-client.h'],
    arguments: ['-c', 'client-header', '@INPUT@', '@BUILD_DIR@/@BASENAME@-client.h'])

gen_server_header = generator(prog_wayland_scanner,
    output: ['@BASENAME@-server.h'],
    arguments: ['-c', 'server-header', '@INPUT@', '@BUILD_DIR@/@BASENAME@-server.h'])

gen_private_code = generator(prog_wayland_scanner,
    output: ['@BASENAME@.c'],
    arguments: ['-c', 'private-code', '@INPUT@', '@BUILD_DIR@/@BASENAME@.c'])

client_protocol_srcs = []
server_protocol_srcs = []

foreach protocol : protocols
    client_header = gen_client_header.process(protocol)
    code = gen_private_code.process(protocol)
    client_protocol_srcs += [client_header, code]
    if get_option('tests')
        server_header = gen_server_header.process(protocol)
        server_protocol_srcs += [server_header, code]
    endif
endforeach
0707010000002C000081A400000000000000000000000168059A480000481E000000000000000000000000000000000000004000000000gtk4-layer-shell-1.1.1/protocol/wlr-layer-shell-unstable-v1.xml<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_layer_shell_unstable_v1">
  <copyright>
    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.
  </copyright>

  <interface name="zwlr_layer_shell_v1" version="4">
    <description summary="create surfaces that are layers of the desktop">
      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.
    </description>

    <request name="get_layer_surface">
      <description summary="create a layer_surface from a surface">
        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.
      </description>
      <arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
      <arg name="surface" type="object" interface="wl_surface"/>
      <arg name="output" type="object" interface="wl_output" allow-null="true"/>
      <arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
      <arg name="namespace" type="string" summary="namespace for the layer surface"/>
    </request>

    <enum name="error">
      <entry name="role" value="0" summary="wl_surface has another role"/>
      <entry name="invalid_layer" value="1" summary="layer value is invalid"/>
      <entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
    </enum>

    <enum name="layer">
      <description summary="available layers for surfaces">
        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.
      </description>

      <entry name="background" value="0"/>
      <entry name="bottom" value="1"/>
      <entry name="top" value="2"/>
      <entry name="overlay" value="3"/>
    </enum>

    <!-- Version 3 additions -->

    <request name="destroy" type="destructor" since="3">
      <description summary="destroy the layer_shell object">
        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.
      </description>
    </request>
  </interface>

  <interface name="zwlr_layer_surface_v1" version="4">
    <description summary="layer metadata interface">
      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.
    </description>

    <request name="set_size">
      <description summary="sets the size of the surface">
        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.
      </description>
      <arg name="width" type="uint"/>
      <arg name="height" type="uint"/>
    </request>

    <request name="set_anchor">
      <description summary="configures the anchor point of the surface">
        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.
      </description>
      <arg name="anchor" type="uint" enum="anchor"/>
    </request>

    <request name="set_exclusive_zone">
      <description summary="configures the exclusive geometry of this surface">
        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.
      </description>
      <arg name="zone" type="int"/>
    </request>

    <request name="set_margin">
      <description summary="sets a margin from the anchor point">
        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.
      </description>
      <arg name="top" type="int"/>
      <arg name="right" type="int"/>
      <arg name="bottom" type="int"/>
      <arg name="left" type="int"/>
    </request>

    <enum name="keyboard_interactivity">
      <description summary="types of keyboard interaction possible for a layer shell surface">
        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.
      </description>

      <entry name="none" value="0">
        <description summary="no keyboard focus is possible">
          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.
        </description>
      </entry>
      <entry name="exclusive" value="1">
        <description summary="request exclusive keyboard focus">
          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.
        </description>
      </entry>
      <entry name="on_demand" value="2" since="4">
        <description summary="request regular keyboard focus semantics">
          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.
        </description>
      </entry>
    </enum>

    <request name="set_keyboard_interactivity">
      <description summary="requests keyboard events">
        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.
      </description>
      <arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
    </request>

    <request name="get_popup">
      <description summary="assign this layer_surface as an xdg_popup parent">
        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.
      </description>
      <arg name="popup" type="object" interface="xdg_popup"/>
    </request>

    <request name="ack_configure">
      <description summary="ack a configure event">
        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.
      </description>
      <arg name="serial" type="uint" summary="the serial from the configure event"/>
    </request>

    <request name="destroy" type="destructor">
      <description summary="destroy the layer_surface">
        This request destroys the layer surface.
      </description>
    </request>

    <event name="configure">
      <description summary="suggest a surface change">
        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.
      </description>
      <arg name="serial" type="uint"/>
      <arg name="width" type="uint"/>
      <arg name="height" type="uint"/>
    </event>

    <event name="closed">
      <description summary="surface should be closed">
        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.
      </description>
    </event>

    <enum name="error">
      <entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
      <entry name="invalid_size" value="1" summary="size is invalid"/>
      <entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
      <entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
    </enum>

    <enum name="anchor" bitfield="true">
      <entry name="top" value="1" summary="the top edge of the anchor rectangle"/>
      <entry name="bottom" value="2" summary="the bottom edge of the anchor rectangle"/>
      <entry name="left" value="4" summary="the left edge of the anchor rectangle"/>
      <entry name="right" value="8" summary="the right edge of the anchor rectangle"/>
    </enum>

    <!-- Version 2 additions -->

    <request name="set_layer" since="2">
      <description summary="change the layer of the surface">
        Change the layer that the surface is rendered on.

        Layer is double-buffered, see wl_surface.commit.
      </description>
      <arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
    </request>
  </interface>
</protocol>
0707010000002D000081A400000000000000000000000168059A48000012E0000000000000000000000000000000000000003200000000gtk4-layer-shell-1.1.1/protocol/xdg-dialog-v1.xml<?xml version="1.0" encoding="UTF-8"?>
<protocol name="xdg_dialog_v1">
  <copyright>
    Copyright © 2023 Carlos Garnacho

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice (including the next
    paragraph) shall be included in all copies or substantial portions of the
    Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
  </copyright>

  <interface name="xdg_wm_dialog_v1" version="1">
    <description summary="create dialogs related to other toplevels">
      The xdg_wm_dialog_v1 interface is exposed as a global object allowing
      to register surfaces with a xdg_toplevel role as "dialogs" relative to
      another toplevel.

      The compositor may let this relation influence how the surface is
      placed, displayed or interacted with.

      Warning! The protocol described in this file is currently in the testing
      phase. Backward compatible changes may be added together with the
      corresponding interface version bump. Backward incompatible changes can
      only be done by creating a new major version of the extension.
    </description>

    <enum name="error">
      <entry name="already_used" value="0"
             summary="the xdg_toplevel object has already been used to create a xdg_dialog_v1"/>
    </enum>

    <request name="destroy" type="destructor">
      <description summary="destroy the dialog manager object">
        Destroys the xdg_wm_dialog_v1 object. This does not affect
        the xdg_dialog_v1 objects generated through it.
      </description>
    </request>

    <request name="get_xdg_dialog">
      <description summary="create a dialog object">
        Creates a xdg_dialog_v1 object for the given toplevel. See the interface
        description for more details.

	Compositors must raise an already_used error if clients attempt to
	create multiple xdg_dialog_v1 objects for the same xdg_toplevel.
      </description>
      <arg name="id" type="new_id" interface="xdg_dialog_v1"/>
      <arg name="toplevel" type="object" interface="xdg_toplevel"/>
    </request>
  </interface>

  <interface name="xdg_dialog_v1" version="1">
    <description summary="dialog object">
      A xdg_dialog_v1 object is an ancillary object tied to a xdg_toplevel. Its
      purpose is hinting the compositor that the toplevel is a "dialog" (e.g. a
      temporary window) relative to another toplevel (see
      xdg_toplevel.set_parent). If the xdg_toplevel is destroyed, the xdg_dialog_v1
      becomes inert.

      Through this object, the client may provide additional hints about
      the purpose of the secondary toplevel. This interface has no effect
      on toplevels that are not attached to a parent toplevel.
    </description>

    <request name="destroy" type="destructor">
      <description summary="destroy the dialog object">
        Destroys the xdg_dialog_v1 object. If this object is destroyed
        before the related xdg_toplevel, the compositor should unapply its
        effects.
      </description>
    </request>

    <request name="set_modal">
      <description summary="mark dialog as modal">
        Hints that the dialog has "modal" behavior. Modal dialogs typically
        require to be fully addressed by the user (i.e. closed) before resuming
        interaction with the parent toplevel, and may require a distinct
        presentation.

        Clients must implement the logic to filter events in the parent
        toplevel on their own.

        Compositors may choose any policy in event delivery to the parent
        toplevel, from delivering all events unfiltered to using them for
        internal consumption.
      </description>
    </request>

    <request name="unset_modal">
      <description summary="mark dialog as not modal">
        Drops the hint that this dialog has "modal" behavior. See
        xdg_dialog_v1.set_modal for more details.
      </description>
    </request>
  </interface>
</protocol>
0707010000002E000081A400000000000000000000000168059A48000002DD000000000000000000000000000000000000002A00000000gtk4-layer-shell-1.1.1/release_process.md# 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
0707010000002F000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000001B00000000gtk4-layer-shell-1.1.1/src07070100000030000081A400000000000000000000000168059A4800003E27000000000000000000000000000000000000002E00000000gtk4-layer-shell-1.1.1/src/gtk4-layer-shell.c#include "gtk4-layer-shell.h"
#include "registry.h"
#include "layer-surface.h"
#include "libwayland-shim.h"

#include <gdk/wayland/gdkwayland.h>

static const char* layer_surface_key = "wayland_layer_surface";
static GList* all_layer_surfaces = NULL;
static GListModel* gtk_monitors = NULL;

struct gtk_layer_surface_t {
    struct layer_surface_t super;
    GtkWindow* gtk_window;
    GdkMonitor* monitor;
};

static void gtk_layer_surface_remap(struct layer_surface_t* super);
static void gtk_layer_surface_clear_monitor(struct gtk_layer_surface_t* layer_surface);

GTK4_LAYER_SHELL_EXPORT
guint gtk_layer_get_major_version() {
    return GTK_LAYER_SHELL_MAJOR;
}

GTK4_LAYER_SHELL_EXPORT
guint gtk_layer_get_minor_version() {
    return GTK_LAYER_SHELL_MINOR;
}

GTK4_LAYER_SHELL_EXPORT
guint gtk_layer_get_micro_version() {
    return GTK_LAYER_SHELL_MICRO;
}

static void monitors_changed(
    GListModel* self,
    guint position,
    guint removed,
    guint added,
    gpointer user_data
) {
    (void)self; (void)position; (void)removed; (void)added; (void)user_data;
    for (GList* item = all_layer_surfaces; item; item = item->next) {
        struct gtk_layer_surface_t* surface = item->data;
        if (surface->monitor == NULL) {
            // If the surface has a monitor set, it is in charge of responding to monitor changes
            gtk_layer_surface_remap(&surface->super);
        }
    }
}

static struct zwlr_layer_shell_v1* init_and_get_layer_shell_global() {
    gtk_init();
    GdkDisplay* gdk_display = gdk_display_get_default();
    g_return_val_if_fail(gdk_display, NULL);
    if (!gtk_monitors) {
        gtk_monitors = gdk_display_get_monitors(gdk_display);
        g_signal_connect(gtk_monitors, "items-changed",  G_CALLBACK(monitors_changed), NULL);
    }
    g_return_val_if_fail(GDK_IS_WAYLAND_DISPLAY(gdk_display), NULL);
    struct wl_display* wl_display = gdk_wayland_display_get_wl_display(gdk_display);
    return get_layer_shell_global_from_display(wl_display);
}

GTK4_LAYER_SHELL_EXPORT
gboolean gtk_layer_is_supported() {
    return init_and_get_layer_shell_global() != NULL && libwayland_shim_has_initialized();
}

GTK4_LAYER_SHELL_EXPORT
guint gtk_layer_get_protocol_version() {
    struct zwlr_layer_shell_v1* layer_shell_global = init_and_get_layer_shell_global();
    if (!layer_shell_global) {
        return 0;
    }
    return zwlr_layer_shell_v1_get_version(layer_shell_global);
}

static struct gtk_layer_surface_t* 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 struct gtk_layer_surface_t* gtk_window_get_layer_surface_or_warn(GtkWindow* window) {
    g_return_val_if_fail(window, NULL);
    struct gtk_layer_surface_t* 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;
}

static void gtk_layer_surface_destroy(struct gtk_layer_surface_t* self) {
    gtk_layer_surface_clear_monitor(self);
    layer_surface_uninit(&self->super);
    all_layer_surfaces = g_list_remove(all_layer_surfaces, self);
    g_free(self);
}

static gint find_layer_surface_with_wl_surface(gconstpointer layer_surface, gconstpointer needle) {
    struct gtk_layer_surface_t* self = (struct gtk_layer_surface_t*)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;
}

static struct layer_surface_t* layer_surface_hook_callback_impl(struct wl_surface* wl_surface) {
    GList* entry = g_list_find_custom(
        all_layer_surfaces,
        wl_surface,
        find_layer_surface_with_wl_surface
    );
    return entry ? entry->data : NULL;
}

static struct geom_size_t gtk_layer_surface_get_preferred_size(struct layer_surface_t* super) {
    struct gtk_layer_surface_t* self = (struct gtk_layer_surface_t*)super;
    struct geom_size_t size = {0};
    gtk_window_get_default_size(self->gtk_window, &size.width, &size.height);

    GtkRequisition natural;
    gtk_widget_get_preferred_size(GTK_WIDGET(self->gtk_window), NULL, &natural);

    if (!size.width)  size.width  = natural.width;
    if (!size.height) size.height = natural.height;

    return size;
}

static void gtk_layer_surface_on_default_size_set(
    GtkWindow* _window,
    const GParamSpec* _pspec,
    struct layer_surface_t* layer_surface
) {
    (void)_window;
    (void)_pspec;
    layer_surface_invalidate_preferred_size(&((struct gtk_layer_surface_t*)layer_surface)->super);
}

static void gtk_layer_surface_remap(struct layer_surface_t* super) {
    if (g_list_model_get_n_items(gtk_monitors) == 0) {
        // GTK will exit if you try to map a window while there are no monitors, so don't do that
        return;
    }
    struct gtk_layer_surface_t* self = (struct gtk_layer_surface_t*)super;
    gtk_widget_unrealize(GTK_WIDGET(self->gtk_window));
    gtk_widget_map(GTK_WIDGET(self->gtk_window));
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_init_for_window(GtkWindow* window) {
    if (!GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
        g_warning("Failed to initialize layer surface, not on Wayland");
        return;
    }

    if (!window) {
        g_warning("Failed to initialize layer surface, provided window is null");
        return;
    }

    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;
    }

    if (!init_and_get_layer_shell_global()) {
        g_warning("Failed to initialize layer surface, it appears your Wayland compositor doesn't support Layer Shell");
        return;
    }

    static gboolean has_installed_hook = false;
    if (!has_installed_hook) {
        has_installed_hook = true;
        layer_surface_install_hook(layer_surface_hook_callback_impl);
    }

    struct gtk_layer_surface_t* layer_surface = g_new0(struct gtk_layer_surface_t, 1);
    layer_surface->gtk_window = window;
    layer_surface->super = layer_surface_make();
    layer_surface->super.remap = gtk_layer_surface_remap;
    layer_surface->super.get_preferred_size = gtk_layer_surface_get_preferred_size;
    g_object_set_data_full(G_OBJECT(window), layer_surface_key, layer_surface, (GDestroyNotify)gtk_layer_surface_destroy);

    all_layer_surfaces = g_list_append(all_layer_surfaces, layer_surface);

    gtk_window_set_decorated(window, FALSE);
    g_signal_connect(window, "notify::default-width",  G_CALLBACK(gtk_layer_surface_on_default_size_set), layer_surface);
    g_signal_connect(window, "notify::default-height", G_CALLBACK(gtk_layer_surface_on_default_size_set), layer_surface);

    if (gtk_widget_get_mapped(GTK_WIDGET(window))) {
        layer_surface->super.remap(&layer_surface->super);
    }
}

GTK4_LAYER_SHELL_EXPORT
gboolean gtk_layer_is_layer_window(GtkWindow* window) {
    return gtk_window_get_layer_surface(window) != NULL;
}

GTK4_LAYER_SHELL_EXPORT
struct zwlr_layer_surface_v1* gtk_layer_get_zwlr_layer_surface_v1(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return NULL;
    return layer_surface->super.layer_surface;
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_set_namespace(GtkWindow* window, char const* name_space) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    layer_surface_set_name_space(&layer_surface->super, name_space);
}

GTK4_LAYER_SHELL_EXPORT
const char* gtk_layer_get_namespace(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    return layer_surface_get_namespace(&layer_surface->super); // NULL-safe
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_set_layer(GtkWindow* window, GtkLayerShellLayer layer) {
    g_return_if_fail(layer >= 0 && layer < GTK_LAYER_SHELL_LAYER_ENTRY_NUMBER);
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    // Our keyboard interactivity enum matches the layer shell one
    layer_surface_set_layer(&layer_surface->super, (enum zwlr_layer_shell_v1_layer)layer);
}

GTK4_LAYER_SHELL_EXPORT
GtkLayerShellLayer gtk_layer_get_layer(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return GTK_LAYER_SHELL_LAYER_TOP;
    // Our keyboard interactivity enum matches the layer shell one
    return (GtkLayerShellLayer)layer_surface->super.layer;
}

static void gtk_layer_surface_monitor_invalidated(GdkMonitor* self, struct gtk_layer_surface_t* layer_surface) {
    if (layer_surface->monitor != self) {
        g_error("got monitor_invalidated() signal for non-current monitor, please report to GTK4 Layer Shell");
        return;
    }
    gtk_layer_set_monitor(layer_surface->gtk_window, NULL);
}

static void gtk_layer_surface_clear_monitor(struct gtk_layer_surface_t* layer_surface) {
    if (layer_surface->monitor) {
        g_signal_handlers_disconnect_by_data(layer_surface->monitor, layer_surface);
        g_object_unref(G_OBJECT(layer_surface->monitor));
    }
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_set_monitor(GtkWindow* window, GdkMonitor* monitor) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    struct wl_output* output = NULL;
    if (monitor) {
        g_return_if_fail(GDK_IS_WAYLAND_MONITOR(monitor));
        output = gdk_wayland_monitor_get_wl_output(monitor);
        g_return_if_fail(output);
    }
    gtk_layer_surface_clear_monitor(layer_surface);
    layer_surface->monitor = monitor;
    if (monitor) {
        g_object_ref(G_OBJECT(monitor));
        // Connect after hopefully allows apps to handle this first
        g_signal_connect_after(monitor, "invalidate",  G_CALLBACK(gtk_layer_surface_monitor_invalidated), layer_surface);
    }
    layer_surface_set_output(&layer_surface->super, output);
}

GTK4_LAYER_SHELL_EXPORT
GdkMonitor* gtk_layer_get_monitor(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return NULL;
    return layer_surface->monitor;
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_set_anchor(GtkWindow* window, GtkLayerShellEdge edge, gboolean anchor_to_edge) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    struct geom_edges_t anchored = layer_surface->super.anchored;
    switch (edge) {
        case GTK_LAYER_SHELL_EDGE_LEFT:   anchored.left   = anchor_to_edge; break;
        case GTK_LAYER_SHELL_EDGE_RIGHT:  anchored.right  = anchor_to_edge; break;
        case GTK_LAYER_SHELL_EDGE_TOP:    anchored.top    = anchor_to_edge; break;
        case GTK_LAYER_SHELL_EDGE_BOTTOM: anchored.bottom = anchor_to_edge; break;
        default: g_warning("Invalid GtkLayerShellEdge %d", edge);
    }
    layer_surface_set_anchor(&layer_surface->super, anchored);
}

GTK4_LAYER_SHELL_EXPORT
gboolean gtk_layer_get_anchor(GtkWindow* window, GtkLayerShellEdge edge) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return FALSE;
    switch (edge) {
        case GTK_LAYER_SHELL_EDGE_LEFT:   return layer_surface->super.anchored.left;
        case GTK_LAYER_SHELL_EDGE_RIGHT:  return layer_surface->super.anchored.right;
        case GTK_LAYER_SHELL_EDGE_TOP:    return layer_surface->super.anchored.top;
        case GTK_LAYER_SHELL_EDGE_BOTTOM: return layer_surface->super.anchored.bottom;
        default: g_warning("Invalid GtkLayerShellEdge %d", edge); return FALSE;
    }
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_set_margin(GtkWindow* window, GtkLayerShellEdge edge, int margin_size) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    struct geom_edges_t margins = layer_surface->super.margin_size;
    switch (edge) {
        case GTK_LAYER_SHELL_EDGE_LEFT:   margins.left   = margin_size; break;
        case GTK_LAYER_SHELL_EDGE_RIGHT:  margins.right  = margin_size; break;
        case GTK_LAYER_SHELL_EDGE_TOP:    margins.top    = margin_size; break;
        case GTK_LAYER_SHELL_EDGE_BOTTOM: margins.bottom = margin_size; break;
        default: g_warning("Invalid GtkLayerShellEdge %d", edge);
    }
    layer_surface_set_margin(&layer_surface->super, margins);
}

GTK4_LAYER_SHELL_EXPORT
int gtk_layer_get_margin(GtkWindow* window, GtkLayerShellEdge edge) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return 0;
    switch (edge) {
        case GTK_LAYER_SHELL_EDGE_LEFT:   return layer_surface->super.margin_size.left;
        case GTK_LAYER_SHELL_EDGE_RIGHT:  return layer_surface->super.margin_size.right;
        case GTK_LAYER_SHELL_EDGE_TOP:    return layer_surface->super.margin_size.top;
        case GTK_LAYER_SHELL_EDGE_BOTTOM: return layer_surface->super.margin_size.bottom;
        default: g_warning("Invalid GtkLayerShellEdge %d", edge); return 0;
    }
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_set_exclusive_zone(GtkWindow* window, int exclusive_zone) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    layer_surface_set_exclusive_zone(&layer_surface->super, exclusive_zone);
}

GTK4_LAYER_SHELL_EXPORT
int gtk_layer_get_exclusive_zone(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return 0;
    return layer_surface->super.exclusive_zone;
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_auto_exclusive_zone_enable(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    layer_surface_auto_exclusive_zone_enable(&layer_surface->super);
}

GTK4_LAYER_SHELL_EXPORT
gboolean gtk_layer_auto_exclusive_zone_is_enabled(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return FALSE;
    return layer_surface->super.auto_exclusive_zone;
}

GTK4_LAYER_SHELL_EXPORT
void gtk_layer_set_keyboard_mode(GtkWindow* window, GtkLayerShellKeyboardMode mode) {
    g_return_if_fail(mode >= 0 && mode < GTK_LAYER_SHELL_KEYBOARD_MODE_ENTRY_NUMBER);
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return;
    // Our keyboard interactivity enum matches the layer shell one
    layer_surface_set_keyboard_mode(&layer_surface->super, (enum zwlr_layer_surface_v1_keyboard_interactivity)mode);
}

GTK4_LAYER_SHELL_EXPORT
GtkLayerShellKeyboardMode gtk_layer_get_keyboard_mode(GtkWindow* window) {
    struct gtk_layer_surface_t* layer_surface = gtk_window_get_layer_surface_or_warn(window);
    if (!layer_surface) return GTK_LAYER_SHELL_KEYBOARD_MODE_NONE;
    // Our keyboard interactivity enum matches the layer shell one
    return (GtkLayerShellKeyboardMode)layer_surface->super.keyboard_mode;
}
07070100000031000081A400000000000000000000000168059A4800001EAA000000000000000000000000000000000000002F00000000gtk4-layer-shell-1.1.1/src/gtk4-session-lock.c#include "gtk4-session-lock.h"
#include "session-lock.h"
#include "lock-surface.h"
#include "registry.h"
#include "libwayland-shim.h"

#include <gdk/wayland/gdkwayland.h>

static const char* lock_surface_key = "wayland_layer_surface";
static GList* all_lock_surfaces = NULL;

GTK4_LAYER_SHELL_EXPORT
gboolean gtk_session_lock_is_supported() {
    gtk_init();
    GdkDisplay* gdk_display = gdk_display_get_default();
    struct wl_display* wl_display = GDK_IS_WAYLAND_DISPLAY(gdk_display) ?
        gdk_wayland_display_get_wl_display(gdk_display) : NULL;
    struct ext_session_lock_manager_v1* global = wl_display ?
        get_session_lock_global_from_display(wl_display) : NULL;
    return global != NULL;
}

struct _GtkSessionLockInstance {
    GObject parent_instance;
    void* wayland_object;
    gboolean is_locked;
    gboolean has_requested_lock;
    gboolean failed;
};

G_DEFINE_TYPE(GtkSessionLockInstance, gtk_session_lock_instance, G_TYPE_OBJECT)

enum {
    SESSION_LOCK_SIGNAL_LOCKED,
    SESSION_LOCK_SIGNAL_FAILED,
    SESSION_LOCK_SIGNAL_UNLOCKED,
    SESSION_LOCK_SIGNAL_LAST,
};

static guint session_lock_signals[SESSION_LOCK_SIGNAL_LAST] = {0};

static void gtk_session_lock_instance_class_init(GtkSessionLockInstanceClass *cclass) {
    session_lock_signals[SESSION_LOCK_SIGNAL_LOCKED] = g_signal_new(
        "locked", G_TYPE_FROM_CLASS(cclass), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);

    session_lock_signals[SESSION_LOCK_SIGNAL_FAILED] = g_signal_new(
        "failed", G_TYPE_FROM_CLASS(cclass), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);

    session_lock_signals[SESSION_LOCK_SIGNAL_UNLOCKED] = g_signal_new(
        "unlocked", G_TYPE_FROM_CLASS(cclass), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
}

static void gtk_session_lock_instance_init(GtkSessionLockInstance *self) {
    self->is_locked = FALSE;
    self->has_requested_lock = FALSE;
    self->failed = FALSE;
}

GTK4_LAYER_SHELL_EXPORT
GtkSessionLockInstance* gtk_session_lock_instance_new() {
    return g_object_new(gtk_session_lock_instance_get_type(), NULL);
}

static void session_lock_locked_callback_impl(bool locked, void* data) {
    GtkSessionLockInstance* self = data;
    if (!locked && !self->is_locked) {
        self->failed = TRUE;
    }
    self->is_locked = locked;
    if (!locked) {
        self->has_requested_lock = FALSE;
    }
    g_signal_emit(
        self,
        session_lock_signals[
            self->is_locked ? SESSION_LOCK_SIGNAL_LOCKED : (
                self->failed ? SESSION_LOCK_SIGNAL_FAILED : SESSION_LOCK_SIGNAL_UNLOCKED
            )
        ],
        0
    );
}

GTK4_LAYER_SHELL_EXPORT
gboolean gtk_session_lock_instance_lock(GtkSessionLockInstance* self) {
    if (self->has_requested_lock) {
        g_warning("Tried to lock multiple times without unlocking");
        return false;
    }

    GdkDisplay* gdk_display = gdk_display_get_default();
    struct wl_display* wl_display = GDK_IS_WAYLAND_DISPLAY(gdk_display) ?
        gdk_wayland_display_get_wl_display(gdk_display) :
        NULL;

    if (!wl_display) {
        g_signal_emit(self, session_lock_signals[SESSION_LOCK_SIGNAL_FAILED], 0);
        g_critical("Failed to get Wayland display");
        return false;
    }

    if (!get_session_lock_global_from_display(wl_display)) {
        g_critical("Session Lock protocol not supported");
        g_signal_emit(self, session_lock_signals[SESSION_LOCK_SIGNAL_FAILED], 0);
        return false;
    }

    if (!libwayland_shim_has_initialized()) {
        g_warning("Failed to initialize lock 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");
        g_signal_emit(self, session_lock_signals[SESSION_LOCK_SIGNAL_FAILED], 0);
        return false;
    }

    self->has_requested_lock = TRUE;
    session_lock_lock(wl_display, session_lock_locked_callback_impl, self);
    self->wayland_object = self->failed ? NULL : (void*)session_lock_get_active_lock();
    return !self->failed;
}

GTK4_LAYER_SHELL_EXPORT
void gtk_session_lock_instance_unlock(GtkSessionLockInstance* self) {
    if (self->is_locked) {
        self->is_locked = FALSE;
        self->has_requested_lock = FALSE;
        g_signal_emit(self, session_lock_signals[SESSION_LOCK_SIGNAL_UNLOCKED], 0);
        session_lock_unlock();
    }
}

GTK4_LAYER_SHELL_EXPORT
gboolean gtk_session_lock_instance_is_locked(GtkSessionLockInstance* self) {
    return self->is_locked;
}

struct gtk_lock_surface_t {
    struct lock_surface_t super;
    GtkWindow* gtk_window;
    GtkSessionLockInstance* lock;
};

static void gtk_lock_surface_destroy(struct gtk_lock_surface_t* self) {
    lock_surface_uninit(&self->super);
    g_object_unref(self->lock);
    all_lock_surfaces = g_list_remove(all_lock_surfaces, self);
    g_free(self);
}

static gint find_lock_surface_with_wl_surface(gconstpointer lock_surface, gconstpointer needle) {
    struct gtk_lock_surface_t* self = (struct gtk_lock_surface_t*)lock_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;
}

static struct lock_surface_t* lock_surface_hook_callback_impl(struct wl_surface* wl_surface) {
    GList* entry = g_list_find_custom(
        all_lock_surfaces,
        wl_surface,
        find_lock_surface_with_wl_surface
    );
    return entry ? entry->data : NULL;
}

static void on_window_mapped(GtkWindow *window, gpointer data) {
    (void)window;
    struct gtk_lock_surface_t* self = data;
    if (self->lock->wayland_object == session_lock_get_active_lock()) {
        lock_surface_map(&self->super);
    } else {
        g_warning("Not showing lock surface because the session lock it is linked to is not active");
    }
}

GTK4_LAYER_SHELL_EXPORT
void gtk_session_lock_instance_assign_window_to_monitor(
    GtkSessionLockInstance* self,
    GtkWindow *window,
    GdkMonitor *monitor
) {
    if (!GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
        g_warning("Failed to initialize lock surface, not on Wayland");
        return;
    }

    if (!window) {
        g_warning("Failed to initialize lock surface, provided window is null");
        return;
    }

    if (!monitor) {
        g_warning("Failed to initialize lock surface, provided monitor is null");
        return;
    }

    struct wl_output* output = gdk_wayland_monitor_get_wl_output(monitor);
    if (!monitor) {
        g_warning("Failed to initialize lock surface, monitor does not have a wl_output");
        return;
    }

    static gboolean has_installed_hook = false;
    if (!has_installed_hook) {
        has_installed_hook = true;
        lock_surface_install_hook(lock_surface_hook_callback_impl);
    }

    struct gtk_lock_surface_t* lock_surface = g_new0(struct gtk_lock_surface_t, 1);
    lock_surface->lock = g_object_ref(self);
    lock_surface->gtk_window = window;
    lock_surface->super = lock_surface_make(output);
    g_object_set_data_full(G_OBJECT(window), lock_surface_key, lock_surface, (GDestroyNotify)gtk_lock_surface_destroy);
    g_signal_connect(window, "map", G_CALLBACK(on_window_mapped), lock_surface);

    all_lock_surfaces = g_list_append(all_lock_surfaces, lock_surface);

    gtk_window_set_decorated(window, FALSE);

    if (gtk_widget_get_mapped(GTK_WIDGET(window))) {
        gtk_widget_unrealize(GTK_WIDGET(window));
        gtk_widget_map(GTK_WIDGET(window));
    }
}
07070100000032000081A400000000000000000000000168059A4800001146000000000000000000000000000000000000003100000000gtk4-layer-shell-1.1.1/src/layer-shell-preload.c#include "layer-surface.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"

static bool has_created_layer_surface = false;

static bool get_bool_from_env(const char* env) {
    const char* val = getenv(env);
    if (!val || strcmp(val, "") == 0 || strcmp(val, "0") == 0) {
        return false;
    } else if (strcmp(val, "1") == 0) {
        return true;
    } else {
        fprintf(stderr, "Invalid value for %s (expected '1', '0' or unset)", env);
        exit(1);
    }
}

static int get_int_from_env(const char* env) {
    const char* val = getenv(env);
    return val ? atoi(val) : 0;
}

static const char* get_string_from_env(const char* env, const char* fallback) {
    const char* val = getenv(env);
    if (val && *val) {
        return val;
    } else {
        return fallback;
    }
}

static struct geom_edges_t get_edges_from_env(const char* env) {
    const char* val = getenv(env);
    if (!val || strcmp(val, "0") == 0) {
        return (struct geom_edges_t){0};
    } else {
        struct geom_edges_t ret = {0};
        for (const char* c = val; *c; c++) {
            switch (*c) {
                case 'l': ret.left   = true; break;
                case 'r': ret.right  = true; break;
                case 't': ret.top    = true; break;
                case 'b': ret.bottom = true; break;
                default:
                    fprintf(stderr, "Invalid character '%c' in %s (expected 'l', 'r', 't' and 'b')", *c, env);
                    exit(1);
            }
        }
        return ret;
    }
}

static enum zwlr_layer_shell_v1_layer get_layer_from_env(const char* env) {
    const char* val = getenv(env);
    if (!val || strcmp(val, "") == 0 || strcmp(val, "o") == 0 || strcmp(val, "overlay") == 0) {
        return ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
    } else if (strcmp(val, "t") == 0 || strcmp(val, "top") == 0) {
        return ZWLR_LAYER_SHELL_V1_LAYER_TOP;
    } else if (strcmp(val, "b") == 0 || strcmp(val, "bottom") == 0) {
        return ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
    } else if (strcmp(val, "g") == 0 || strcmp(val, "background") == 0) {
        return ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
    } else {
        fprintf(stderr, "Invalid value for %s (expected unset/'o'/'overlay', 't'/'top', 'b'/'bottom', 'g'/'background')", env);
        exit(1);
    }
}

static enum zwlr_layer_surface_v1_keyboard_interactivity get_keyboard_interactivity_from_env(const char* env) {
    const char* val = getenv(env);
    if (!val || strcmp(val, "") == 0 || strcmp(val, "n") == 0 || strcmp(val, "none") == 0) {
        return ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
    } else if (strcmp(val, "e") == 0 || strcmp(val, "exclusive") == 0) {
        return ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
    } else if (strcmp(val, "o") == 0 || strcmp(val, "on-demand") == 0) {
        return ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND;
    } else {
        fprintf(stderr, "Invalid value for %s (expected unset/'n'/'none', 'e'/'exclusive' or 'o'/'on-demand')", env);
        exit(1);
    }
}

static struct geom_size_t get_preferred_size(struct layer_surface_t* surface) {
    (void)surface;
    return (struct geom_size_t){
        .width = get_int_from_env("LAYER_WIDTH"),
        .height = get_int_from_env("LAYER_HEIGHT"),
    };
}

static struct layer_surface_t* layer_surface_hook_callback_impl(struct wl_surface* wl_surface) {
    (void)wl_surface;
    if (has_created_layer_surface && !get_bool_from_env("LAYER_ALL_SURFACES")) {
        return NULL;
    }
    has_created_layer_surface = true;
    struct layer_surface_t* layer_surface = malloc(sizeof(struct layer_surface_t));
    *layer_surface = layer_surface_make();
    layer_surface->get_preferred_size = get_preferred_size;
    layer_surface_set_name_space(layer_surface, get_string_from_env("LAYER_NAMESPACE", "layer-shell-preload"));
    layer_surface_set_anchor(layer_surface, get_edges_from_env("LAYER_ANCHOR"));
    layer_surface_set_layer(layer_surface, get_layer_from_env("LAYER_LAYER"));
    layer_surface_set_keyboard_mode(layer_surface, get_keyboard_interactivity_from_env("LAYER_KEYBOARD"));
    if (get_bool_from_env("LAYER_EXCLUSIVE")) {
        layer_surface_auto_exclusive_zone_enable(layer_surface);
    }
    return layer_surface;
}

__attribute__((constructor))
static void setup(void) {
    layer_surface_install_hook(layer_surface_hook_callback_impl);
}
07070100000033000081A400000000000000000000000168059A480000423E000000000000000000000000000000000000002B00000000gtk4-layer-shell-1.1.1/src/layer-surface.c#include "layer-surface.h"

#include "registry.h"
#include "libwayland-shim.h"

#include "xdg-shell-client.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static void layer_surface_send_set_size(struct layer_surface_t* self) {
    if (!self->layer_surface) return;

    struct geom_size_t size = self->last_xdg_window_geom_size;

    // Default values because setting 0 is only allowed when anchored
    if (size.width  <= 0) size.width  = 200;
    if (size.height <= 0) size.height = 200;

    if (self->anchored.left && self->anchored.right) {
        size.width = 0;
    }

    if (self->anchored.top && self->anchored.bottom) {
        size.height = 0;
    }

    if (self->cached_layer_size_set.width  != size.width ||
        self->cached_layer_size_set.height != size.height
    ) {
        self->cached_layer_size_set = size;
        zwlr_layer_surface_v1_set_size(self->layer_surface, size.width, size.height);
    }
}

static void layer_surface_configure_xdg_surface(
    struct layer_surface_t* self,
    uint32_t serial, // Can be 0
    bool send_even_if_size_unchanged
) {
    if (!self->has_initial_layer_shell_configure) {
        // skip sending xdg_toplevel and xdg_surface configure to the client program since layer shell surface has not
        // been configured yet and attaching a buffer to an unconfigured surface is a protocol error
        return;
    }

    struct geom_size_t size = {0, 0};

    if (self->anchored.left && self->anchored.right && self->last_layer_configured_size.width > 0) {
        size.width = self->last_layer_configured_size.width;
    }

    if (self->anchored.top && self->anchored.bottom && self->last_layer_configured_size.height > 0) {
        size.height = self->last_layer_configured_size.height;
    }

    // Ideally this wouldn't be needed, see the layer_surface_t.get_preferred_size documentation
    if (self->get_preferred_size && (size.width == 0 || size.height == 0)) {
        struct geom_size_t preferred = self->get_preferred_size(self);
        if (size.width == 0 && preferred.width > 0) {
            size.width = preferred.width;
        }
        if (size.height == 0 && preferred.height > 0) {
            size.height = preferred.height;
        }
    }

    if (self->cached_xdg_configure_size.width  != size.width ||
        self->cached_xdg_configure_size.height != size.height ||
        send_even_if_size_unchanged
    ) {
        self->cached_xdg_configure_size = size;
        if (serial) {
            self->pending_configure_serial = serial;
        }

        xdg_surface_server_send_configure(&self->super, 0, 0, size.width, size.height, serial);
    }
}

static void layer_surface_needs_commit(struct layer_surface_t* self) {
    // Send a configure to force the client program 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;
    struct layer_surface_t* self = data;
    self->last_layer_configured_size = (struct geom_size_t){w, h};
    self->has_initial_layer_shell_configure = true;
    layer_surface_configure_xdg_surface(self, serial, true);
}

static void layer_surface_handle_closed(void* data, struct zwlr_layer_surface_v1* _surface) {
    (void)_surface;
    struct layer_surface_t* self = data;
    if (self->super.xdg_toplevel) {
        LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT(xdg_toplevel_listener, close, self->super.xdg_toplevel);
    }
}

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(struct layer_surface_t* self) {
    if (self->layer_surface) {
        zwlr_layer_surface_v1_set_anchor(
            self->layer_surface,
            (self->anchored.left   ? ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT   : 0) |
            (self->anchored.right  ? ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT  : 0) |
            (self->anchored.top    ? ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP    : 0) |
            (self->anchored.bottom ? ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM : 0)
        );
    }
}

static void layer_surface_send_set_margin(struct layer_surface_t* self) {
    if (self->layer_surface) {
        zwlr_layer_surface_v1_set_margin(
            self->layer_surface,
            self->margin_size.top,
            self->margin_size.right,
            self->margin_size.bottom,
            self->margin_size.left
        );
    }
}

static void layer_surface_send_set_keyboard_interactivity(struct layer_surface_t* self) {
    if (self->layer_surface) {
        enum zwlr_layer_surface_v1_keyboard_interactivity mode = self->keyboard_mode;
        if (mode == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
            uint32_t version = wl_proxy_get_version((struct wl_proxy*)self->layer_surface);
            if (version < ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND_SINCE_VERSION) {
                fprintf(
                    stderr,
                    "compositor uses layer shell version %d, which does not support on-demand keyboard interactivity\n",
                    version
                );
                mode = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
            }
        }
        zwlr_layer_surface_v1_set_keyboard_interactivity(self->layer_surface, mode);
    }
}

static void layer_surface_create_surface_object(struct layer_surface_t* self, struct wl_surface* wl_surface) {
    struct wl_display* display = libwayland_shim_proxy_get_display((struct wl_proxy*)wl_surface);
    struct zwlr_layer_shell_v1* layer_shell_global = get_layer_shell_global_from_display(display);
    if (!layer_shell_global) {
        fprintf(stderr, "failed to create layer surface, no layer shell global\n");
        return;
    }

    const char* name_space = layer_surface_get_namespace(self);

    self->has_initial_layer_shell_configure = false;
    self->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
        layer_shell_global,
        wl_surface,
        self->output,
        self->layer,
        name_space);
    assert(self->layer_surface);
    zwlr_layer_surface_v1_add_listener(self->layer_surface, &layer_surface_listener, self);

    layer_surface_send_set_keyboard_interactivity(self);
    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_update_auto_exclusive_zone(struct layer_surface_t* self) {
    if (!self->auto_exclusive_zone) return;

    bool horiz = (self->anchored.left == self->anchored.right);
    bool vert  = (self->anchored.top  == self->anchored.bottom);
    int new_exclusive_zone = -1;

    if (horiz && !vert) {
        new_exclusive_zone = self->last_xdg_window_geom_size.height;
        if (!self->anchored.top) {
            new_exclusive_zone += self->margin_size.top;
        }
        if (!self->anchored.bottom) {
            new_exclusive_zone += self->margin_size.bottom;
        }
    } else if (vert && !horiz) {
        new_exclusive_zone = self->last_xdg_window_geom_size.width;
        if (!self->anchored.left) {
            new_exclusive_zone += self->margin_size.left;
        }
        if (!self->anchored.right) {
            new_exclusive_zone += self->margin_size.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_window_geometry_set(struct xdg_surface_server_t* super, int width, int height) {
    struct layer_surface_t* self = (void*)super;

    self->last_xdg_window_geom_size = (struct geom_size_t){width, height};
    layer_surface_send_set_size(self);
    layer_surface_update_auto_exclusive_zone(self);
}

void layer_surface_configure_acked(struct xdg_surface_server_t* super, uint32_t serial) {
    struct layer_surface_t* self = (void*)super;

    if (serial && serial == self->pending_configure_serial) {
        self->pending_configure_serial = 0;
        zwlr_layer_surface_v1_ack_configure(self->layer_surface, serial);
    }
}

static void layer_surface_role_destroyed(struct xdg_surface_server_t* super) {
    struct layer_surface_t* self = (void*)super;

    if (self->layer_surface) {
        zwlr_layer_surface_v1_destroy(self->layer_surface);
        self->layer_surface = NULL;
    }

    self->cached_xdg_configure_size = GEOM_SIZE_UNSET;
    self->last_xdg_window_geom_size = GEOM_SIZE_UNSET;
    self->cached_layer_size_set = GEOM_SIZE_UNSET;
    self->last_layer_configured_size = GEOM_SIZE_UNSET;

    self->pending_configure_serial = 0;
    self->has_initial_layer_shell_configure = false;
}

struct layer_surface_t layer_surface_make() {
    struct layer_surface_t ret = {
        .super = {
            .window_geometry_set = layer_surface_window_geometry_set,
            .configure_acked = layer_surface_configure_acked,
            .toplevel_destroyed = layer_surface_role_destroyed,
            .popup_destroyed = layer_surface_role_destroyed,
        },
        .cached_xdg_configure_size = GEOM_SIZE_UNSET,
        .last_xdg_window_geom_size = GEOM_SIZE_UNSET,
        .cached_layer_size_set = GEOM_SIZE_UNSET,
        .last_layer_configured_size = GEOM_SIZE_UNSET,
        .has_initial_layer_shell_configure = false,
        .keyboard_mode = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE,
        .layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP,
    };
    return ret;
}

void layer_surface_uninit(struct layer_surface_t* self) {
    xdg_surface_server_uninit(&self->super);
    free((void*)self->name_space);
}

void layer_surface_set_output(struct layer_surface_t* self, struct wl_output* output) {
    if (self->output != output) {
        self->output = output;
        if (self->layer_surface && self->remap) {
            self->remap(self);
        }
    }
}

void layer_surface_set_name_space(struct layer_surface_t* self, char const* name_space) {
    if (strcmp(self->name_space ? self->name_space : "", name_space ? name_space : "") != 0) {
        free((void*)self->name_space);
        self->name_space = (name_space && *name_space) ? strdup(name_space) : NULL;
        if (self->layer_surface && self->remap) {
            self->remap(self);
        }
    }
}

const char* layer_surface_get_namespace(struct layer_surface_t* self) {
    if (self && self->name_space) {
        return self->name_space;
    } else {
        return "gtk4-layer-shell";
    }
}

void layer_surface_set_layer(struct layer_surface_t* self, enum zwlr_layer_shell_v1_layer 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) {
                zwlr_layer_surface_v1_set_layer(self->layer_surface, layer);
                layer_surface_needs_commit(self);
            } else if (self->remap) {
                self->remap(self);
            }
        }
    }
}

void layer_surface_set_anchor(struct layer_surface_t* self, struct geom_edges_t anchors) {
    // Normalize booleans or else strange things can happen
    anchors.left   = anchors.left   ? 1 : 0;
    anchors.right  = anchors.right  ? 1 : 0;
    anchors.top    = anchors.top    ? 1 : 0;
    anchors.bottom = anchors.bottom ? 1 : 0;

    if (self->anchored.left   != anchors.left ||
        self->anchored.right  != anchors.right ||
        self->anchored.top    != anchors.top   ||
        self->anchored.bottom != anchors.bottom
    ) {
        self->anchored = anchors;
        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(struct layer_surface_t* self, struct geom_edges_t margins) {
    if (self->margin_size.left   != margins.left ||
        self->margin_size.right  != margins.right ||
        self->margin_size.top    != margins.top   ||
        self->margin_size.bottom != margins.bottom
    ) {
        self->margin_size = margins;
        layer_surface_send_set_margin(self);
        layer_surface_update_auto_exclusive_zone(self);
        layer_surface_needs_commit(self);
    }
}

void layer_surface_set_exclusive_zone(struct layer_surface_t* 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(struct layer_surface_t* self) {
    if (!self->auto_exclusive_zone) {
        self->auto_exclusive_zone = true;
        layer_surface_update_auto_exclusive_zone(self);
    }
}

void layer_surface_set_keyboard_mode(struct layer_surface_t* self, enum zwlr_layer_surface_v1_keyboard_interactivity mode) {
    if (self->keyboard_mode != mode) {
        self->keyboard_mode = mode;
        if (self->layer_surface) {
            layer_surface_send_set_keyboard_interactivity(self);
            layer_surface_needs_commit(self);
        }
    }
}

void layer_surface_invalidate_preferred_size(struct layer_surface_t* self) {
    layer_surface_configure_xdg_surface(self, 0, false);
}

static bool xdg_wm_base_get_xdg_surface_hook(
    void* data,
    struct wl_proxy* proxy,
    uint32_t opcode,
    const struct wl_interface* create_interface,
    uint32_t create_version,
    uint32_t flags,
    union wl_argument* args,
    struct wl_proxy** ret_proxy
) {
    (void)data;
    (void)opcode;
    (void)create_interface;
    (void)create_version;
    (void)flags;

    layer_surface_hook_callback_t callback = data;
    struct wl_surface* wl_surface = (struct wl_surface*)args[1].o;
    struct layer_surface_t* self = callback(wl_surface);

    if (self) {
        *ret_proxy = xdg_surface_server_get_xdg_surface(&self->super, (struct xdg_wm_base*)proxy, wl_surface);
        layer_surface_create_surface_object(self, wl_surface);
        return true;
    } else {
        return false;
    }
}

static bool xdg_surface_get_popup_hook(
    void* data,
    struct wl_proxy* proxy,
    uint32_t opcode,
    const struct wl_interface* create_interface,
    uint32_t create_version,
    uint32_t flags,
    union wl_argument* args,
    struct wl_proxy** ret_proxy
) {
    (void)data;
    (void)opcode;
    (void)create_interface;
    (void)create_version;
    (void)flags;

    struct xdg_surface* parent_xdg_surface = (struct xdg_surface*)args[1].o;
    struct xdg_surface_server_t* super = get_xdg_surface_server_from_xdg_surface(parent_xdg_surface);
    // If super is non-null it's a valid xdg_surface_server_t, but we don't know it's part of a layer_surface_t. Check
    // to make sure one of its virtual functions match before casting it (basically a dynamic_case<>).
    struct layer_surface_t* self =
        super && super->configure_acked == layer_surface_configure_acked ?
        (void*)super : NULL;

    if (self) {
        if (self->layer_surface) {
            struct xdg_surface* popup_xdg_surface = (struct xdg_surface*)proxy;
            struct xdg_positioner* positioner = (struct xdg_positioner*)args[2].o;
            struct xdg_popup* xdg_popup = xdg_surface_get_popup(popup_xdg_surface, NULL, positioner);
            zwlr_layer_surface_v1_get_popup(self->layer_surface, xdg_popup);
            *ret_proxy = (struct wl_proxy*)xdg_popup;
            return true;
        } else {
            fprintf(stderr, "tried to create popup before layer shell surface\n");;
        }
    }
    return false;
}

void layer_surface_install_hook(layer_surface_hook_callback_t callback) {
    libwayland_shim_install_request_hook(
        &xdg_wm_base_interface,
        XDG_WM_BASE_GET_XDG_SURFACE,
        xdg_wm_base_get_xdg_surface_hook,
        callback
    );

    static bool popup_hook_initialized = false;
    if (!popup_hook_initialized) {
        popup_hook_initialized = true;
        libwayland_shim_install_request_hook(
            &xdg_surface_interface,
            XDG_SURFACE_GET_POPUP,
            xdg_surface_get_popup_hook,
            NULL
        );
    }
}
07070100000034000081A400000000000000000000000168059A480000168C000000000000000000000000000000000000002B00000000gtk4-layer-shell-1.1.1/src/layer-surface.h#pragma once

#include "xdg-surface-server.h"

#include <stdbool.h>
#include <wlr-layer-shell-unstable-v1-client.h>

struct geom_edges_t {
    int left, right, top, bottom;
};

struct geom_size_t {
    int width, height;
};

#define GEOM_SIZE_UNSET (struct geom_size_t){-1, -1}

struct layer_surface_t {
    struct xdg_surface_server_t super;

    // Virtual functions (NULL by default, can be overridden by the user of this library)
    // Ask the toolkit to unmap and remap the surface
    void (*remap)(struct layer_surface_t* super);
    // Get the preferred size of the surface from the client program. -1 (as is returned for both axes by the default
    // implementation) means to figure it out based on Wayland messages. In general this default behavior is correct,
    // however GTK seems to have a bug where if its configured with EITHER width or height as 0 it uses its preferred
    // size for both dimensions. This causes problems when anchored along one axis and not the other. By supplying an
    // implementation of this function that gets GTKs preferred widget size this issue can be bypassed.
    struct geom_size_t (*get_preferred_size)(struct layer_surface_t* super);

    // Can be set at any time
    struct geom_edges_t anchored; // Logically booleans, the edges of the output this layer surface is currently anchored to
    struct geom_edges_t margin_size; // The gap between each edge of the output and this layer surface (only applicable for anchored edges)
    int exclusive_zone; // The current exclusive zone(set either explicitly or automatically)
    bool auto_exclusive_zone; // If to automatically change the exclusive zone to match the window size
    enum zwlr_layer_surface_v1_keyboard_interactivity keyboard_mode; // Type of keyboard interactivity enabled for this surface
    enum zwlr_layer_shell_v1_layer layer; // The current layer, needs surface recreation on old layer shell versions

    // Need the surface to be recreated to change
    struct wl_output* output; // 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)
    // The last size we configured the client program with. -1 means unset, 0 means we've asked the program to decide
    // its own size. In theory we should be able to set only width or only height to 0. In practice GTK at least uses
    // its preferred size for both if either are set to 0, so we either use (0, 0) or (>0, >0).
    struct geom_size_t cached_xdg_configure_size;
    // The last size the client program set its window geometry to. -1 means unset, should never be 0 for well behaved
    // client programs.
    struct geom_size_t last_xdg_window_geom_size;
    // The last size we sent to the compositor for our layer surface's size (with the .set_size request). -1 is unset,
    // 0 means we requested the compositor give us a size, though this is only allowed for axes where we're currently
    // anchored to both edges.
    struct geom_size_t cached_layer_size_set;
    // The last size the compositor configured our layer surface with. -1 is unset. 0 means no preference from the
    // compositor. This is a hint, are allowed to ignore this size if we want.
    struct geom_size_t last_layer_configured_size;
    // If non-zero our layer surface received a configure with this serial, we passed it on to the client program's XDG
    // surface and will ack it once the client program acks its configure. Otherwise this is zero, all acks from the
    // client program can be ignored (they are for configures not originating from the compositor)
    uint32_t pending_configure_serial;
    // If this layer surface has gotten its first configure from the compositor
    bool has_initial_layer_shell_configure;
};

struct layer_surface_t layer_surface_make();
void layer_surface_uninit(struct layer_surface_t* self);

// Surface is remapped in order to set
void layer_surface_set_output(struct layer_surface_t* self, struct wl_output* output); // Can be null for default
void layer_surface_set_name_space(struct layer_surface_t* self, char const* name_space); // Makes a copy of the string, can be null

// Returns the effective namespace(default if unset). Does not return ownership. Never returns NULL. Handles NULL self.
const char* layer_surface_get_namespace(struct layer_surface_t* self);

// Can be set without remapping the surface
void layer_surface_set_layer(struct layer_surface_t* self, enum zwlr_layer_shell_v1_layer layer); // Remaps surface on old layer shell versions
void layer_surface_set_anchor(struct layer_surface_t* self, struct geom_edges_t anchors); // anchor values are treated as booleans
void layer_surface_set_margin(struct layer_surface_t* self, struct geom_edges_t margins);
void layer_surface_set_exclusive_zone(struct layer_surface_t* self, int exclusive_zone);
void layer_surface_auto_exclusive_zone_enable(struct layer_surface_t* self);
void layer_surface_set_keyboard_mode(
    struct layer_surface_t* self,
    enum zwlr_layer_surface_v1_keyboard_interactivity mode
);
void layer_surface_invalidate_preferred_size(struct layer_surface_t* self); // Called when preferred size may have changed

// Each time the current process attempts to create a new xdg_surface out of a wl_surface this callback will be called.
// If the given callback returns a non-null pointer, this layer surface is used to override the XDG surface. Else the
// XDG surface is created normally. Thus must be used for any layer surfaces to be displayed.
typedef struct layer_surface_t* (*layer_surface_hook_callback_t)(struct wl_surface*);
void layer_surface_install_hook(layer_surface_hook_callback_t callback);
07070100000035000081A400000000000000000000000168059A4800002D0A000000000000000000000000000000000000002D00000000gtk4-layer-shell-1.1.1/src/libwayland-shim.c#define _GNU_SOURCE

#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "libwayland-shim.h"
#include "stolen-from-libwayland.h"

struct wrapped_proxy {
    struct wl_proxy proxy;
    libwayland_shim_request_handler_func_t handler;
    libwayland_shim_destroy_handler_func_t destroy;
    void* data;
};

struct request_hook {
    const char* interface_name;
    uint32_t opcode;
    libwayland_shim_request_handler_func_t handler;
    void* data;
};

static bool has_initialized = false;

static struct wl_proxy* (*real_wl_proxy_marshal_array_flags)(
    struct wl_proxy* proxy,
    uint32_t opcode,
    const struct wl_interface* created_interface,
    uint32_t created_version,
    uint32_t flags,
    union wl_argument* args
) = NULL;

static void (*real_wl_proxy_destroy)(struct wl_proxy* proxy) = NULL;

#define MAX_REQUEST_HOOKS 100
static int request_hook_count = 0;
static struct request_hook request_hooks[MAX_REQUEST_HOOKS];

bool libwayland_shim_has_initialized() {
    return has_initialized;
}

static void libwayland_shim_init() {
    if (has_initialized) return;

#define INIT_SYM(name) \
    if (!(real_##name = dlsym(RTLD_NEXT, #name))) { \
        fprintf(stderr, "libwayland_shim: dlsym failed to load %s\n", #name); \
        exit(1); \
    }

    INIT_SYM(wl_proxy_marshal_array_flags);
    INIT_SYM(wl_proxy_destroy);

#undef INIT_SYM

    has_initialized = true;
}

void libwayland_shim_install_request_hook(
    struct wl_interface const* interface,
    uint32_t opcode,
    libwayland_shim_request_handler_func_t handler,
    void* data
) {
    assert(request_hook_count < MAX_REQUEST_HOOKS);
    request_hooks[request_hook_count] = (struct request_hook){
        .interface_name = interface->name,
        .opcode = opcode,
        .handler = handler,
        .data = data,
    };
    request_hook_count++;
}

// 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_request_handler_func_t handler,
    libwayland_shim_destroy_handler_func_t destroy,
    void* data
) {
    struct wrapped_proxy* allocation = calloc(1, sizeof(struct wrapped_proxy));
    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;
    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;
    }
}

struct wl_display* libwayland_shim_proxy_get_display(struct wl_proxy* proxy) {
    return proxy->display;
}

struct wl_event_queue* libwayland_shim_proxy_get_queue(struct wl_proxy* proxy) {
    return proxy->queue;
}

// Returns true if any arguments are proxies created by us(not known to libwayland)
static bool args_contains_client_facing_proxy(
    struct wl_proxy* proxy,
    uint32_t opcode,
    union wl_argument* args
) {
    const char* sig_iter = proxy->object.interface->methods[opcode].signature;
    int i = 0;
    while (true) {
        struct argument_details arg;
        sig_iter = get_next_argument(sig_iter, &arg);
        switch (arg.type) {
            case 'o':
                if (args[i].o && args[i].o->id == client_facing_proxy_id) {
                    return true;
                }
                break;

            case '\0':
                return false;
        }
        i++;
    }
}

static void client_proxy_destroy(struct wl_proxy* proxy) {
    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
    free(proxy);
}

// Overrides the function in wayland-client.c in libwayland
__attribute__((__visibility__("default")))
void wl_proxy_destroy(struct wl_proxy* proxy) {
    libwayland_shim_init();
    if (proxy->object.id == client_facing_proxy_id) {
        client_proxy_destroy(proxy);
    } else {
        real_wl_proxy_destroy(proxy);
    }
}

static struct wl_proxy* fallback_handle_request(
    struct wl_proxy* proxy,
    struct wl_interface const* create_interface,
    uint32_t create_version
) {
    if (create_interface) {
        // We need to create a stub object to make the client happy, it will ignore all requests and represents
        // nothing in libwayland/the server
        return libwayland_shim_create_client_proxy(proxy, create_interface, create_version, NULL, NULL, NULL);
    } else {
        // The request does not create an object
        return NULL;
    }
}

static struct wl_proxy* validate_request_result(
    struct wl_proxy* created_proxy,
    struct wl_proxy* request_proxy,
    uint32_t opcode,
    struct wl_interface const* create_interface,
    uint32_t create_version
) {
    if (create_interface) {
        if (!created_proxy) {
            fprintf(
                stderr,
                "libwayland_shim: request %s.%s should have created object of type %s, but handler created nothing\n",
                request_proxy->object.interface->name,
                request_proxy->object.interface->methods[opcode].name,
                create_interface->name
            );
            return fallback_handle_request(request_proxy, create_interface, create_version);
        } else if (strcmp(created_proxy->object.interface->name, create_interface->name) != 0) {
            fprintf(
                stderr,
                "libwayland_shim: request %s.%s should have created object of type %s, but handler created object of type %s\n",
                request_proxy->object.interface->name,
                request_proxy->object.interface->methods[opcode].name,
                create_interface->name,
                created_proxy->object.interface->name
            );
            wl_proxy_destroy(created_proxy);
            return fallback_handle_request(request_proxy, create_interface, create_version);
        } else {
            return created_proxy;
        }
    } else {
        if (created_proxy) {
            fprintf(
                stderr,
                "libwayland_shim: request %s.%s should not have created anything, but handler created object of type %s\n",
                request_proxy->object.interface->name,
                request_proxy->object.interface->methods[opcode].name,
                created_proxy->object.interface->name
            );
            wl_proxy_destroy(created_proxy);
        }
        return NULL;
    }
}

// Overrides the function in wayland-client.c in libwayland, handles requests made by the client program and optionally
// forwards them to libwayland/the compositor
__attribute__((__visibility__("default")))
struct wl_proxy* wl_proxy_marshal_array_flags(
    struct wl_proxy* proxy,
    uint32_t opcode,
    struct wl_interface const* create_interface,
    uint32_t create_version,
    uint32_t flags,
    union wl_argument* args)
{
    libwayland_shim_init();
    if (proxy->object.id == client_facing_proxy_id) {
        // libwayland doesn't know about the object this request is on. It must not find out about this object. If it
        // finds out it will be very upset.
        struct wrapped_proxy* wrapper = (struct wrapped_proxy*)proxy;
        bool handled = false;
        struct wl_proxy* ret_proxy = NULL;
        if (wrapper->handler) {
            // Call the custom request handler
            if (wrapper->handler(
                wrapper->data,
                proxy,
                opcode,
                create_interface,
                create_version,
                flags,
                args,
                &ret_proxy
            )) {
                handled = true;
                ret_proxy = validate_request_result(ret_proxy, proxy, opcode, create_interface, create_version);
            }
        }

        if (flags & WL_MARSHAL_FLAG_DESTROY) {
            // The caller has indicated this request destroys the proxy
            client_proxy_destroy(proxy);
        }

        return handled ? ret_proxy : fallback_handle_request(proxy, create_interface, create_version);
    } else {
        const char* interface_name = proxy->object.interface->name;
        for (int i = 0; i < request_hook_count; i++) {
            if (strcmp(request_hooks[i].interface_name, interface_name) == 0 && request_hooks[i].opcode == opcode) {
                struct wl_proxy* ret_proxy = NULL;
                if (request_hooks[i].handler(
                    request_hooks[i].data,
                    proxy,
                    opcode,
                    create_interface,
                    create_version,
                    flags,
                    args,
                    &ret_proxy
                )) {
                    return validate_request_result(ret_proxy, proxy, opcode, create_interface, create_version);
                }
            }
        }

        if (args_contains_client_facing_proxy(proxy, opcode, args)) {
            // We can't do the normal thing because one of the arguments is an object libwayand doesn't know about, but
            // no override behavior was taken. Hopefully we can safely ignore this request.
            return fallback_handle_request(proxy, create_interface, create_version);
        } else {
            // Forward the request on to libwayland without modification, this is the most common path
            return real_wl_proxy_marshal_array_flags(proxy, opcode, create_interface, create_version, flags, args);
        }
    }
}

wl_dispatcher_func_t libwayland_shim_proxy_get_dispatcher(struct wl_proxy* proxy) {
    return proxy->dispatcher;
}

void libwayland_shim_proxy_invoke_dispatcher(uint32_t opcode, struct wl_proxy* proxy, ...) {
    // This should be possible to implement if needed, but not much seems to use dispatchers
    fprintf(
        stderr,
        "libwayland_shim: invoking event %s@%d.%s: dispatchers not currently supported for client objects\n",
        proxy->object.interface->name,
        proxy->object.id,
        proxy->object.interface->methods[opcode].name
    );
}

void const* libwayland_shim_proxy_get_implementation(struct wl_proxy* proxy) {
    return proxy->object.implementation;
}

void* libwayland_shim_proxy_get_user_data(struct wl_proxy* proxy) {
    return proxy->user_data;
}
07070100000036000081A400000000000000000000000168059A4800001221000000000000000000000000000000000000002D00000000gtk4-layer-shell-1.1.1/src/libwayland-shim.h#pragma once

#include <wayland-client-core.h>
#include <stdbool.h>

// Function type for optionally overriding the behavior of requests from the client program (our process). *ret_proxy
// always starts as NULL. If true is returned this request is considered handled and *ret_proxy must be either left as
// NULL or set to a newly created proxy (whichever is required by the specific request being handled). If false is
// returned libwayland_shim falls back to it's default behavior, which may create a stub proxy to return if needed.
typedef bool (*libwayland_shim_request_handler_func_t)(
    void* data,
    struct wl_proxy* proxy,
    uint32_t opcode,
    struct wl_interface const* created_interface,
    uint32_t created_version,
    uint32_t flags,
    union wl_argument* args,
    struct wl_proxy** ret_proxy);

// Function type for handling the destruction of client proxies
typedef void (*libwayland_shim_destroy_handler_func_t)(void* data, struct wl_proxy* proxy);

// Detect if library has correctly initialized. This should happen automatically when something connects to a Wayland
// display. If this is false it may indicate the program was linked incorrectly.
bool libwayland_shim_has_initialized();

// The handler will be called and can optionally handle all matching requests. There is no way to uninstall a hook, and
// installing too many hooks may hurt performance.
void libwayland_shim_install_request_hook(
    struct wl_interface const* interface,
    uint32_t opcode,
    libwayland_shim_request_handler_func_t handler,
    void* data
);

// Create a "fake" wl_proxy the client program (our process) can interact with, but libwayland doesn't know about
// factory: the proxy this proxy was created from (for example an xdg_surface if the created proxy is an xdg_toplevel)
// interface: the type of this proxy, these structs are declared in wayland client headers
// version: the version of the created proxy object
// handler: will be called for each request the client program (our process) makes
// destroy: will be called when the proxy is destroyed
// data: user data handler() and destroy() are called with, the caller is responsible for memory management
struct wl_proxy* libwayland_shim_create_client_proxy(
    struct wl_proxy* factory,
    struct wl_interface const* interface,
    uint32_t version,
    libwayland_shim_request_handler_func_t handler,
    libwayland_shim_destroy_handler_func_t destroy,
    void* data
);

// May only be called on NULL (no-op) or proxies created with libwayland_shim_create_client_proxy(). The proxy remains
// valid but handler and destory will no longer be called. If this function is used destroy is never called.
void libwayland_shim_clear_client_proxy_data(struct wl_proxy* proxy);

// Get the user data for a given client proxy, returns NULL unless the given proxy is a client proxy and its handler is
// the given expected handler
void* libwayland_shim_get_client_proxy_data(struct wl_proxy* proxy, void* expected_handler);

// Yes wl_proxy_get_display exists, but only in libwayland >=1.23. This can be replaced with that once we can drop
// support for older libwaylands (though no rush, this works)
struct wl_display* libwayland_shim_proxy_get_display(struct wl_proxy* proxy);
// Same deal, wl_proxy_get_queue() exists but is new
struct wl_event_queue* libwayland_shim_proxy_get_queue(struct wl_proxy* proxy);

#define LIBWAYLAND_SHIM_FIRST_ARG(first, ...) first
#define LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT(listener, event, ...) \
    if (libwayland_shim_proxy_get_dispatcher((struct wl_proxy*)LIBWAYLAND_SHIM_FIRST_ARG(__VA_ARGS__))) { \
        libwayland_shim_proxy_invoke_dispatcher( \
            (long)((char*)((struct listener*)NULL)->event) / sizeof(void(*)()), \
            (struct wl_proxy*)__VA_ARGS__ \
        ); \
    } else if (libwayland_shim_proxy_get_implementation((struct wl_proxy*)LIBWAYLAND_SHIM_FIRST_ARG(__VA_ARGS__))) { \
        ((struct listener*)libwayland_shim_proxy_get_implementation((struct wl_proxy*)LIBWAYLAND_SHIM_FIRST_ARG(__VA_ARGS__))) \
            ->event( \
                libwayland_shim_proxy_get_user_data((struct wl_proxy*)LIBWAYLAND_SHIM_FIRST_ARG(__VA_ARGS__)), \
                __VA_ARGS__ \
            ); \
    }

// These functions are used by LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT()
wl_dispatcher_func_t libwayland_shim_proxy_get_dispatcher(struct wl_proxy* proxy);
void libwayland_shim_proxy_invoke_dispatcher(uint32_t opcode, struct wl_proxy* proxy, ...);
void const* libwayland_shim_proxy_get_implementation(struct wl_proxy* proxy);
void* libwayland_shim_proxy_get_user_data(struct wl_proxy* proxy);
07070100000037000081A400000000000000000000000168059A48000013A7000000000000000000000000000000000000002A00000000gtk4-layer-shell-1.1.1/src/lock-surface.c#include "lock-surface.h"

#include "libwayland-shim.h"
#include "stubbed-surface.h"
#include "session-lock.h"

#include <ext-session-lock-v1-client.h>
#include <wayland-client-protocol.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static void lock_surface_handle_configure(
    void* data,
    struct ext_session_lock_surface_v1* surface,
    uint32_t serial,
    uint32_t width,
    uint32_t height
) {
    (void)surface;
    struct lock_surface_t* self = data;

    self->pending_configure_serial = serial;
    self->last_configure.width = width;
    self->last_configure.height = height;

    xdg_surface_server_send_configure(
        &self->super,
        0, 0,
        self->last_configure.width, self->last_configure.height,
        self->pending_configure_serial
    );
}

static const struct ext_session_lock_surface_v1_listener lock_surface_listener = {
    .configure = lock_surface_handle_configure,
};

static void lock_surface_configure_acked(struct xdg_surface_server_t* super, uint32_t serial) {
    struct lock_surface_t* self = (void*)super;
    if (serial && serial == self->pending_configure_serial) {
        self->pending_configure_serial = 0;
        ext_session_lock_surface_v1_ack_configure(self->lock_surface, serial);
    }
}

static void lock_surface_role_destroyed(struct xdg_surface_server_t* super) {
    struct lock_surface_t* self = (void*)super;
    if (self->lock_surface) {
        ext_session_lock_surface_v1_destroy(self->lock_surface);
        self->lock_surface = NULL;
    }
    self->pending_configure_serial = 0;
}

struct lock_surface_t lock_surface_make(struct wl_output* output) {
    struct lock_surface_t ret = {
        .super = {
            .configure_acked = lock_surface_configure_acked,
            .toplevel_destroyed = lock_surface_role_destroyed,
            .popup_destroyed = lock_surface_role_destroyed,
        },
        .output = output
    };
    return ret;
}

void lock_surface_map(struct lock_surface_t* self) {
    if (self->lock_surface) {
        return;
    }

    struct ext_session_lock_v1* current_lock = session_lock_get_active_lock();
    if (!current_lock) {
        fprintf(stderr, "failed to create lock surface, no current lock in place\n");
        return;
    }

    if (!self->super.wl_surface) {
        fprintf(stderr, "failed to create lock surface, no wl_surface set\n");
        return;
    }

    self->lock_surface = ext_session_lock_v1_get_lock_surface(current_lock, self->super.wl_surface, self->output);
    assert(self->lock_surface);
    ext_session_lock_surface_v1_add_listener(self->lock_surface, &lock_surface_listener, self);

    // Not strictly necessary, but roundtripping here will hopefully let us handle our initial configure before this
    // function returns, which may reduce the chance of GTK committing the surface before that initial configure for one
    // reasons or another (which is a protocol error).
    wl_display_roundtrip(libwayland_shim_proxy_get_display((struct wl_proxy*)self->super.wl_surface));
}

void lock_surface_uninit(struct lock_surface_t* self) {
    xdg_surface_server_uninit(&self->super);
}

static bool xdg_wm_base_get_xdg_surface_hook(
    void* data,
    struct wl_proxy* proxy,
    uint32_t opcode,
    const struct wl_interface* create_interface,
    uint32_t create_version,
    uint32_t flags,
    union wl_argument* args,
    struct wl_proxy** ret_proxy
) {
    (void)data;
    (void)opcode;
    (void)create_interface;
    (void)create_version;
    (void)flags;

    lock_surface_hook_callback_t callback = data;
    struct wl_surface* wl_surface = (struct wl_surface*)args[1].o;
    struct lock_surface_t* self = callback(wl_surface);

    if (self) {
        *ret_proxy = xdg_surface_server_get_xdg_surface(&self->super, (struct xdg_wm_base*)proxy, wl_surface);
        return true;
    } else if (session_lock_get_active_lock()) {
        // A new XDG surface is being created while the screen is locked, but it's not a lock surface. Few possibilities
        // 1. it's going to be a toplevel
        // 2. it's going to be a popup on a non-lock toplevel
        // 3. it's going to be a popup on a lock surface
        // For 1 and 2 it could be created as normal, but it wont be slown until the lock surface is closed. 3 is most
        // likely, but if we allow the creation of an XDG surface for it there's no easy way to avoid a protocol error.
        // Therefore we create a stub surface that won't display anything, but will keep GTK happy.
        fprintf(stderr, "non-lock surface created while screen locked, it will not displayed\n");
        *ret_proxy = stubbed_surface_init((struct xdg_wm_base*)proxy, wl_surface);
        return true;
    } {
        return false;
    }
}

void lock_surface_install_hook(lock_surface_hook_callback_t callback) {
    libwayland_shim_install_request_hook(
        &xdg_wm_base_interface,
        XDG_WM_BASE_GET_XDG_SURFACE,
        xdg_wm_base_get_xdg_surface_hook,
        callback
    );
}
07070100000038000081A400000000000000000000000168059A48000003BF000000000000000000000000000000000000002A00000000gtk4-layer-shell-1.1.1/src/lock-surface.h#pragma once

#include "xdg-surface-server.h"

struct lock_surface_t {
    struct xdg_surface_server_t super;
    struct ext_session_lock_surface_v1* lock_surface;
    struct wl_output* output;
    uint32_t pending_configure_serial;
    struct {
        int width, height;
    } last_configure;
};

struct lock_surface_t lock_surface_make(struct wl_output* output);
void lock_surface_map(struct lock_surface_t* self);
void lock_surface_uninit(struct lock_surface_t* self);

// Each time the current process attempts to create a new xdg_surface out of a wl_surface this callback will be called.
// If the given callback returns a non-null pointer, this lock surface is used to override the XDG surface. Else the
// XDG surface is created normally. Thus must be used for any lock surfaces to be displayed.
typedef struct lock_surface_t* (*lock_surface_hook_callback_t)(struct wl_surface*);
void lock_surface_install_hook(lock_surface_hook_callback_t callback);
07070100000039000081A400000000000000000000000168059A4800000A4D000000000000000000000000000000000000002700000000gtk4-layer-shell-1.1.1/src/meson.buildcore_srcs = files(
    'stolen-from-libwayland.c',
    'libwayland-shim.c',
    'xdg-surface-server.c',
    'layer-surface.c',
    'session-lock.c',
    'lock-surface.c',
    'stubbed-surface.c',
    'registry.c')

gtk_srcs = files(
    'gtk4-layer-shell.c',
    'gtk4-session-lock.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',
    gtk_srcs, core_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)

layer_shell_preload_lib = library('layer-shell-preload',
    files('layer-shell-preload.c'), core_srcs, client_protocol_srcs,
    include_directories: [gtk_layer_shell_inc],
    dependencies: [wayland_client],
    install: true)

pkg_config_name = 'gtk4-layer-shell-0'

# GObject introspection file used to interface with other languages
if get_option('introspection')
    gir_layer = gnome.generate_gir(
        gtk_layer_shell_lib,
        dependencies: [gtk],
        sources: files('../include/gtk4-layer-shell.h') + gtk_srcs + core_srcs,
        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)

    gir_lock = gnome.generate_gir(
        gtk_layer_shell_lib,
        dependencies: [gtk],
        sources: files('../include/gtk4-session-lock.h') + gtk_srcs + core_srcs,
        namespace: 'Gtk4SessionLock',
        nsversion: '1.0',
        identifier_prefix: 'GtkSessionLock',
        symbol_prefix: 'gtk_session_lock',
        export_packages: pkg_config_name,
        includes: [ 'Gtk-4.0' ],
        header: 'gtk4-session-lock.h',
        install: true)

    if get_option('vapi')
        vapi = gnome.generate_vapi(
            pkg_config_name,
            sources: [gir_layer[0], gir_lock[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')
0707010000003A000081A400000000000000000000000168059A4800000D25000000000000000000000000000000000000002600000000gtk4-layer-shell-1.1.1/src/registry.c#include "registry.h"
#include <wayland-client-core.h>
#include <wayland-client-protocol.h>
#include "wlr-layer-shell-unstable-v1-client.h"
#include "ext-session-lock-v1-client.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>

struct wl_display* cached_display = NULL;

bool layer_shell_requested = false;
struct zwlr_layer_shell_v1* layer_shell_global = NULL;

bool session_lock_requested = false;
struct ext_session_lock_manager_v1* session_lock_global = NULL;

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 (layer_shell_requested && strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
        uint32_t supported_version = zwlr_layer_shell_v1_interface.version;
        layer_shell_global = wl_registry_bind(
            registry,
            id,
            &zwlr_layer_shell_v1_interface,
            supported_version < version ? supported_version : version
        );
    } else if (session_lock_requested && strcmp(interface, ext_session_lock_manager_v1_interface.name) == 0) {
        uint32_t supported_version = ext_session_lock_manager_v1_interface.version;
        session_lock_global = wl_registry_bind(
            registry,
            id,
            &ext_session_lock_manager_v1_interface,
            supported_version < version ? supported_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,
};

static void bind_globals(struct wl_display* display) {
    if (cached_display && display != cached_display) {
        fprintf(stderr, "Wayland display changed, binding a new layer shell global\n");
        cached_display = display;
        if (layer_shell_global) {
            zwlr_layer_shell_v1_destroy(layer_shell_global);
            layer_shell_global = NULL;
        }
        if (session_lock_global) {
            ext_session_lock_manager_v1_destroy(session_lock_global);
            session_lock_global = NULL;
        }
    }
    struct wl_registry* registry = wl_display_get_registry(display);
    wl_registry_add_listener(registry, &wl_registry_listener, NULL);
    wl_display_roundtrip(display);
    wl_registry_destroy(registry);
}

struct zwlr_layer_shell_v1* get_layer_shell_global_from_display(struct wl_display* display) {
    if (!layer_shell_requested) {
        layer_shell_requested = true;
        bind_globals(display);
        if (!layer_shell_global) {
            fprintf(stderr, "it appears your Wayland compositor does not support the Session Lock protocol\n");
        }
    }
    return layer_shell_global;
}

struct ext_session_lock_manager_v1* get_session_lock_global_from_display(struct wl_display* display) {
    if (!session_lock_requested) {
        session_lock_requested = true;
        bind_globals(display);
        if (!session_lock_global) {
            fprintf(stderr, "it appears your Wayland compositor does not support the Session Lock protocol\n");
        }
    }
    return session_lock_global;
}
0707010000003B000081A400000000000000000000000168059A4800000125000000000000000000000000000000000000002600000000gtk4-layer-shell-1.1.1/src/registry.h#pragma once

struct zwlr_layer_shell_v1;
struct ext_session_lock_manager_v1;
struct wl_display;

struct zwlr_layer_shell_v1* get_layer_shell_global_from_display(struct wl_display* display);
struct ext_session_lock_manager_v1* get_session_lock_global_from_display(struct wl_display* display);
0707010000003C000081A400000000000000000000000168059A48000009C0000000000000000000000000000000000000002A00000000gtk4-layer-shell-1.1.1/src/session-lock.c#include "session-lock.h"
#include "registry.h"

#include <ext-session-lock-v1-client.h>

struct wl_display* current_display = NULL;
struct ext_session_lock_v1* current_lock = NULL;
static session_lock_locked_callback_t current_callback = NULL;
static void* current_callback_data = NULL;
static bool is_locked = false;

static void session_lock_handle_locked(void* data, struct ext_session_lock_v1* session_lock) {
    (void)data;
    if (session_lock != current_lock) {
        ext_session_lock_v1_unlock_and_destroy(session_lock);
        return;
    }
    is_locked = true;
    if (current_callback) {
        current_callback(true, current_callback_data);
    }
}

static void session_lock_handle_finished(void* data, struct ext_session_lock_v1* session_lock) {
    (void)data;
    if (session_lock != current_lock) {
        ext_session_lock_v1_destroy(session_lock);
        return;
    }
    is_locked = false;
    current_lock = NULL;
    if (current_callback) {
        current_callback(false, current_callback_data);
        current_callback = NULL;
        current_callback_data = NULL;
    }
}

static const struct ext_session_lock_v1_listener session_lock_listener = {
    .locked = session_lock_handle_locked,
    .finished = session_lock_handle_finished,
};

bool session_lock_lock(struct wl_display* display, session_lock_locked_callback_t callback, void* data) {
    if (current_lock) {
        callback(false, data);
        return false;
    }
    struct ext_session_lock_manager_v1* manager = get_session_lock_global_from_display(display);
    if (!manager) {
        callback(false, data);
        return false;
    }
    current_display = display;
    current_lock = ext_session_lock_manager_v1_lock(manager);
    current_callback = callback;
    current_callback_data = data;
    is_locked = false;
    ext_session_lock_v1_add_listener(current_lock, &session_lock_listener, NULL);
    return true;
}

struct ext_session_lock_v1* session_lock_get_active_lock() {
    return current_lock;
}

void session_lock_unlock() {
    if (!current_lock) return;
    if (is_locked) {
        ext_session_lock_v1_unlock_and_destroy(current_lock);
        wl_display_roundtrip(current_display);
    }
    // if there is a current lock that is not yet locked, nulling it will cause it to be destroyed when it gets a locked
    // or finished event
    current_display = NULL;
    current_lock = NULL;
    current_callback = NULL;
    current_callback_data = NULL;
    is_locked = false;
}
0707010000003D000081A400000000000000000000000168059A4800000141000000000000000000000000000000000000002A00000000gtk4-layer-shell-1.1.1/src/session-lock.h#pragma once

#include <stdbool.h>
struct wl_display;

typedef void (*session_lock_locked_callback_t)(bool locked, void* data);
bool session_lock_lock(struct wl_display* display, session_lock_locked_callback_t callback, void* data);
struct ext_session_lock_v1* session_lock_get_active_lock();
void session_lock_unlock();
0707010000003E000081A400000000000000000000000168059A48000010B9000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/src/stolen-from-libwayland.c#include "stolen-from-libwayland.h"

// wayland-private.h
#define WL_CLOSURE_MAX_ARGS 20

// connection.c
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;
		}
	}
}

// The following functions may be unnecessary, as they are unmodified from libwayland, however it is possible that some
// builds of libwayland could inline the call they make to wl_proxy_marshal_array_flags(), which means we need to
// override all functions that call it.

// wayland-client.c
__attribute__((__visibility__("default")))
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);
}

// wayland-client.c
__attribute__((__visibility__("default")))
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);
}

// wayland-client.c
__attribute__((__visibility__("default")))
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);
}

// wayland-client.c
__attribute__((__visibility__("default")))
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);
}

// wayland-client.c
__attribute__((__visibility__("default")))
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);
}

// wayland-client.c
__attribute__((__visibility__("default")))
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);
}

// wayland-client.c
__attribute__((__visibility__("default")))
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);
}
0707010000003F000081A400000000000000000000000168059A48000003E7000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/src/stolen-from-libwayland.h#pragma once

#include <wayland-client-core.h>

// wayland-private.h
struct wl_object {
	const struct wl_interface *interface;
	const void *implementation;
	uint32_t id;
};

// wayland-client.c
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
};

// wayland-private.h
struct argument_details {
	char type;
	int nullable;
};

// connection.c
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;
}
07070100000040000081A400000000000000000000000168059A48000009FF000000000000000000000000000000000000002D00000000gtk4-layer-shell-1.1.1/src/stubbed-surface.c#include "stubbed-surface.h"
#include "libwayland-shim.h"
#include "xdg-surface-server.h"

#include <wayland-client.h>
#include <xdg-shell-client.h>
#include <stdlib.h>
#include <stdio.h>

struct stubbed_surface_t {
    struct xdg_surface_server_t super;
};

static void stubbed_configure_callback(void *data, struct wl_callback *callback, uint32_t callback_data) {
    (void)callback, (void)callback_data;
    struct stubbed_surface_t* self = data;

    xdg_surface_server_send_configure(&self->super, 0, 0, 100, 100, 0);
}

static const struct wl_callback_listener stubbed_configure_callback_listener = { stubbed_configure_callback };

static void stubbed_role_created(struct xdg_surface_server_t* super) {
    struct stubbed_surface_t* self = (void*)super;

    if (self->super.xdg_popup) {
        fprintf(stderr, "stubbed popup not displayed\n");
    } else if (self->super.xdg_toplevel) {
        fprintf(stderr, "stubbed toplevel not displayed\n");
    }

    // We need to send the initial configure event. If we send it now, GTK will get it before it gets returned the
    // popup the configure is on, which obviously wont work. By creating a wl_callback we can bounce a message
    // back from the compositor and send configure when it arrives, which solves this problem. HOWEVER the GDK
    // surface is dispatching on a specific event queue. Our callback needs to be on the same queue, or else it
    // wont get processed and everything will lock up.
    struct wl_event_queue* queue = libwayland_shim_proxy_get_queue((struct wl_proxy*)self->super.xdg_surface);
    struct wl_display* display = libwayland_shim_proxy_get_display((struct wl_proxy*)self->super.xdg_surface);
    struct wl_display* wrapped_display = wl_proxy_create_wrapper(display);
    wl_proxy_set_queue((struct wl_proxy*)wrapped_display, queue);
    struct wl_callback* callback = wl_display_sync(wrapped_display);
    wl_callback_add_listener(callback, &stubbed_configure_callback_listener, self);
    wl_proxy_wrapper_destroy(wrapped_display);
}

void stubbed_surface_destroyed(struct xdg_surface_server_t* super) {
    struct stubbed_surface_t* self = (void*)super;
    free(self);
}

struct wl_proxy* stubbed_surface_init(struct xdg_wm_base* creating_object, struct wl_surface* surface) {
    struct stubbed_surface_t* self = calloc(1, sizeof(struct stubbed_surface_t));
    self->super.popup_created = stubbed_role_created;
    self->super.toplevel_created = stubbed_role_created;
    return xdg_surface_server_get_xdg_surface(&self->super, creating_object, surface);
}
07070100000041000081A400000000000000000000000168059A48000000B1000000000000000000000000000000000000002D00000000gtk4-layer-shell-1.1.1/src/stubbed-surface.h#pragma once

#include <wayland-client.h>
#include <xdg-shell-client.h>

struct wl_proxy* stubbed_surface_init(struct xdg_wm_base* creating_object, struct wl_surface* surface);
07070100000042000081A400000000000000000000000168059A48000018D9000000000000000000000000000000000000003000000000gtk4-layer-shell-1.1.1/src/xdg-surface-server.c#include "xdg-surface-server.h"
#include "libwayland-shim.h"

#include <assert.h>

static bool xdg_popup_handle_request(
    void* data,
    struct wl_proxy* proxy,
    uint32_t opcode,
    const struct wl_interface* create_interface,
    uint32_t create_version,
    uint32_t flags,
    union wl_argument* args,
    struct wl_proxy** ret_proxy
) {
    (void)data, (void)proxy, (void)opcode, (void)create_interface, (void)create_version, (void)flags, (void)args, (void)ret_proxy;
    return false;
}

static void xdg_popup_handle_destroy(void* data, struct wl_proxy* proxy) {
    (void)proxy;
    struct xdg_surface_server_t* self = data;
    self->xdg_popup = NULL;
    if (self->popup_destroyed) self->popup_destroyed(self);
}

static bool xdg_toplevel_handle_request(
    void* data,
    struct wl_proxy* proxy,
    uint32_t opcode,
    const struct wl_interface* create_interface,
    uint32_t create_version,
    uint32_t flags,
    union wl_argument* args,
    struct wl_proxy** ret_proxy
) {
    (void)data, (void)proxy, (void)opcode, (void)create_interface, (void)create_version, (void)flags, (void)args, (void)ret_proxy;
    return false;
}

static void xdg_toplevel_handle_destroy(void* data, struct wl_proxy* proxy) {
    (void)proxy;
    struct xdg_surface_server_t* self = data;
    self->xdg_toplevel = NULL;
    if (self->toplevel_destroyed) self->toplevel_destroyed(self);
}

static bool xdg_surface_handle_request(
    void* data,
    struct wl_proxy* proxy,
    uint32_t opcode,
    const struct wl_interface* create_interface,
    uint32_t create_version,
    uint32_t flags,
    union wl_argument* args,
    struct wl_proxy** ret_proxy
) {
    (void)proxy, (void)create_interface, (void)create_version, (void)flags;
    struct xdg_surface_server_t* self = data;
    switch (opcode) {
        case XDG_SURFACE_GET_TOPLEVEL:
            // Make sure surface doesn't already have a role
            assert(!self->xdg_toplevel);
            assert(!self->xdg_popup);
            *ret_proxy = libwayland_shim_create_client_proxy(
                proxy,
                &xdg_toplevel_interface,
                create_version,
                xdg_toplevel_handle_request,
                xdg_toplevel_handle_destroy,
                self
            );
            self->xdg_toplevel = (struct xdg_toplevel*)*ret_proxy;
            if (self->toplevel_created) self->toplevel_created(self);
            return true;

        case XDG_SURFACE_GET_POPUP:
            // Make sure surface doesn't already have a role
            assert(!self->xdg_toplevel);
            assert(!self->xdg_popup);
            *ret_proxy = libwayland_shim_create_client_proxy(
                proxy,
                &xdg_popup_interface,
                create_version,
                xdg_popup_handle_request,
                xdg_popup_handle_destroy,
                self
            );
            self->xdg_popup = (struct xdg_popup*)*ret_proxy;
            if (self->popup_created) self->popup_created(self);
            return true;

        case XDG_SURFACE_SET_WINDOW_GEOMETRY:
            if (self->window_geometry_set) self->window_geometry_set(self, args[2].i, args[3].i);
            return true;

        case XDG_SURFACE_ACK_CONFIGURE:
            if (self->configure_acked) self->configure_acked(self, args[0].u);
            return true;

        default: return false;
    }
}

static void xdg_surface_handle_destroy(void* data, struct wl_proxy* proxy) {
    (void)proxy;
    struct xdg_surface_server_t* self = data;
    self->xdg_surface = NULL;
    if (self->surface_destroyed) self->surface_destroyed(self);
    self->wl_surface = NULL;
}

struct xdg_surface_server_t* get_xdg_surface_server_from_xdg_surface(struct xdg_surface* source) {
    return libwayland_shim_get_client_proxy_data((struct wl_proxy*)source, xdg_surface_handle_request);
}

struct wl_proxy* xdg_surface_server_get_xdg_surface(
    struct xdg_surface_server_t* self,
    struct xdg_wm_base* creating_object,
    struct wl_surface* surface
) {
    assert(!self->xdg_surface);
    self->wl_surface = surface;
    struct wl_proxy* xdg_surface = libwayland_shim_create_client_proxy(
        (struct wl_proxy*)creating_object,
        &xdg_surface_interface,
        1, // XDG shell v1 is simpler to implement, for example this stops GTK from trying to reposition popups
        xdg_surface_handle_request,
        xdg_surface_handle_destroy,
        self
    );
    self->xdg_surface = (struct xdg_surface*)xdg_surface;
    return xdg_surface;
}

void xdg_surface_server_send_configure(
    struct xdg_surface_server_t* self,
    int x, int y,
    int width, int height,
    uint32_t serial
) {
    if (self->xdg_toplevel) {
        struct wl_array states;
        wl_array_init(&states);
        {
            uint32_t* state = wl_array_add(&states, sizeof(uint32_t));
            assert(state);
            *state = XDG_TOPLEVEL_STATE_ACTIVATED;
        }{
            uint32_t* state = wl_array_add(&states, sizeof(uint32_t));
            assert(state);
            *state = XDG_TOPLEVEL_STATE_FULLSCREEN;
        }

        LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT(
            xdg_toplevel_listener,
            configure,
            self->xdg_toplevel,
            width, height,
            &states
        );

        wl_array_release(&states);
    }

    if (self->xdg_popup) {
        LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT(
            xdg_popup_listener,
            configure,
            self->xdg_popup,
            x, y,
            width, height
        );
    }

    if (self->xdg_surface) {
        LIBWAYLAND_SHIM_DISPATCH_CLIENT_EVENT(
            xdg_surface_listener,
            configure,
            self->xdg_surface,
            serial
        );
    }
}

void xdg_surface_server_uninit(struct xdg_surface_server_t* self) {
    struct wl_proxy* proxy;
    if ((proxy = (struct wl_proxy*)self->xdg_popup)) {
        libwayland_shim_clear_client_proxy_data(proxy);
        xdg_popup_handle_destroy(self, proxy);
    }
    if ((proxy = (struct wl_proxy*)self->xdg_toplevel)) {
        libwayland_shim_clear_client_proxy_data(proxy);
        xdg_toplevel_handle_destroy(self, proxy);
    }
    if ((proxy = (struct wl_proxy*)self->xdg_surface)) {
        libwayland_shim_clear_client_proxy_data(proxy);
        xdg_surface_handle_destroy(self, proxy);
    }
}
07070100000043000081A400000000000000000000000168059A48000006AA000000000000000000000000000000000000003000000000gtk4-layer-shell-1.1.1/src/xdg-surface-server.h#pragma once

#include <wayland-client.h>
#include <xdg-shell-client.h>

struct xdg_surface_server_t {
    // Virtual functions, can be null
    void (*window_geometry_set)(struct xdg_surface_server_t* super, int width, int height);
    void (*configure_acked)(struct xdg_surface_server_t* super, uint32_t serial);
    void (*toplevel_created)(struct xdg_surface_server_t* super);
    void (*toplevel_destroyed)(struct xdg_surface_server_t* super);
    void (*popup_created)(struct xdg_surface_server_t* super);
    void (*popup_destroyed)(struct xdg_surface_server_t* super);
    void (*surface_destroyed)(struct xdg_surface_server_t* super);

    struct wl_surface* wl_surface;
    struct xdg_surface* xdg_surface;
    struct xdg_popup* xdg_popup;
    struct xdg_toplevel* xdg_toplevel;
};

// If the xdg_surface is managed by a surface server, this returns the surface server
struct xdg_surface_server_t* get_xdg_surface_server_from_xdg_surface(struct xdg_surface* source);

// Used in .get_popup to create a "stubbed" XDG popup, which is not displayed but shouldn't lock up GTK
struct wl_proxy* xdg_surface_server_get_xdg_surface(
    struct xdg_surface_server_t* self,
    struct xdg_wm_base* creating_object,
    struct wl_surface* surface
);

// x and y are only used for popups
void xdg_surface_server_send_configure(
    struct xdg_surface_server_t* self,
    int x, int y,
    int width, int height,
    uint32_t serial
);

// Simulates a destruction of the proxies. They are cleared, the *_destroyed virtual functions are called and any future
// requests made to them will be safely ignored. This object can be safely re-used.
void xdg_surface_server_uninit(struct xdg_surface_server_t* self);
07070100000044000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000001C00000000gtk4-layer-shell-1.1.1/test07070100000045000081A400000000000000000000000168059A4800000F75000000000000000000000000000000000000002600000000gtk4-layer-shell-1.1.1/test/README.md# 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 an integration test subdirectory (eg `layer-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.

Tests can also use the `UNEXPECT_MESSAGE()` macro to emit `UNEXPECT:` lines. They're the same, except if a matching message is encountered the test fails.

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, and implicitly exists at the end of the test.

### 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`.
07070100000046000081ED00000000000000000000000168059A4800000571000000000000000000000000000000000000003C00000000gtk4-layer-shell-1.1.1/test/check-all-tests-are-in-meson.py#!/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, 'layer-tests'))
    check_dir(path.join(test_dir, 'lock-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)
07070100000047000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/test/integration-test-common07070100000048000081A400000000000000000000000168059A4800000FB7000000000000000000000000000000000000004E00000000gtk4-layer-shell-1.1.1/test/integration-test-common/integration-test-common.c#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),
        "<span font_desc=\"20.0\">"
            "Test window"
        "</span>");
    gtk_window_set_child(window, label);
    return window;
}

struct lock_signal_data_t {

};

static void on_locked(GtkSessionLockInstance *lock, void *data) {
    (void)lock;
    enum lock_state_t* state = data;
    ASSERT_EQ(*state, LOCK_STATE_UNLOCKED, "%d");
    *state = LOCK_STATE_LOCKED;
}

static void on_failed(GtkSessionLockInstance *lock, void *data) {
    (void)lock;
    enum lock_state_t* state = data;
    ASSERT_EQ(*state, LOCK_STATE_UNLOCKED, "%d");
    *state = LOCK_STATE_FAILED;
}

static void on_unlocked(GtkSessionLockInstance *lock, void *data) {
    (void)lock;
    enum lock_state_t* state = data;
    ASSERT_EQ(*state, LOCK_STATE_LOCKED, "%d");
    *state = LOCK_STATE_UNLOCKED;
}

void connect_lock_signals(GtkSessionLockInstance* lock, enum lock_state_t* state) {
    g_signal_connect(lock, "locked", G_CALLBACK(on_locked), state);
    g_signal_connect(lock, "failed", G_CALLBACK(on_failed), state);
    g_signal_connect(lock, "unlocked", G_CALLBACK(on_unlocked), state);
}

void create_lock_windows(GtkSessionLockInstance* lock, GtkWindow* (*builder)()) {
    GdkDisplay *display = gdk_display_get_default();
    GListModel *monitors = gdk_display_get_monitors(display);
    guint n_monitors = g_list_model_get_n_items(monitors);

    for (guint i = 0; i < n_monitors; ++i) {
        GdkMonitor *monitor = g_list_model_get_item(monitors, i);

        GtkWindow* window = builder();
        gtk_session_lock_instance_assign_window_to_monitor(lock, window, monitor);
        gtk_window_present(window);
    }
}

void create_default_lock_windows(GtkSessionLockInstance* lock) {
    create_lock_windows(lock, create_default_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;
}
07070100000049000081A400000000000000000000000168059A480000061C000000000000000000000000000000000000004E00000000gtk4-layer-shell-1.1.1/test/integration-test-common/integration-test-common.h#ifndef TEST_CLIENT_COMMON_H
#define TEST_CLIENT_COMMON_H

#include "gtk4-layer-shell.h"
#include "gtk4-session-lock.h"
#include "test-common.h"
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/wayland/gdkwayland.h>
#include <stdio.h>

// 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 UNEXPECT_MESSAGE(message) fprintf(stderr, "UNEXPECT: %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();

enum lock_state_t {
    LOCK_STATE_UNLOCKED = 0,
    LOCK_STATE_LOCKED,
    LOCK_STATE_FAILED,
};
void connect_lock_signals(GtkSessionLockInstance* lock, enum lock_state_t* state);
void create_lock_windows(GtkSessionLockInstance* lock, GtkWindow* (*builder)());
void create_default_lock_windows(GtkSessionLockInstance* lock);

#endif // TEST_CLIENT_COMMON_H
0707010000004A000081A400000000000000000000000168059A48000000B3000000000000000000000000000000000000004000000000gtk4-layer-shell-1.1.1/test/integration-test-common/meson.buildintegration_test_common = declare_dependency(
    dependencies: [test_common],
    include_directories: include_directories('.'),
    sources: files('integration-test-common.c'))
0707010000004B000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002800000000gtk4-layer-shell-1.1.1/test/layer-tests0707010000004C000081A400000000000000000000000168059A4800000496000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/test/layer-tests/meson.buildlayer_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-uses-widget-size',
    '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-layer-surface-popup',
    'test-xdg-toplevel-popup-with-layer-surface',
    'test-xdg-toplevel-popup-without-layer-surface',
    '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',
]
0707010000004D000081A400000000000000000000000168059A48000006E3000000000000000000000000000000000000004500000000gtk4-layer-shell-1.1.1/test/layer-tests/test-adapts-to-screen-size.c#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);
}

static void callback_3() {
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 0 700);
    EXPECT_MESSAGE(.create_buffer 1920 700);

    gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
}

static void callback_4() {
    EXPECT_MESSAGE(.create_buffer 1920 300);
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 0 300);

    gtk_window_set_default_size(window, 200, 300);
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
    callback_3,
    callback_4,
)
0707010000004E000081A400000000000000000000000168059A48000005EA000000000000000000000000000000000000004D00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-auto-exclusive-zone-no-margin.c#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,
)
0707010000004F000081A400000000000000000000000168059A4800000309000000000000000000000000000000000000005500000000gtk4-layer-shell-1.1.1/test/layer-tests/test-auto-exclusive-zone-weird-bool-values.c#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,
)
07070100000050000081A400000000000000000000000168059A4800000324000000000000000000000000000000000000004F00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-auto-exclusive-zone-with-margin.c#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,
)
07070100000051000081A400000000000000000000000168059A4800000197000000000000000000000000000000000000004300000000gtk4-layer-shell-1.1.1/test/layer-tests/test-close-layer-surface.c#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,
)
07070100000052000081A400000000000000000000000168059A480000045C000000000000000000000000000000000000004300000000gtk4-layer-shell-1.1.1/test/layer-tests/test-create-xdg-toplevel.c#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,
)
07070100000053000081A400000000000000000000000168059A48000002AE000000000000000000000000000000000000004300000000gtk4-layer-shell-1.1.1/test/layer-tests/test-creation-properties.c#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,
)
07070100000054000081A400000000000000000000000168059A480000020B000000000000000000000000000000000000004F00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-exclusive-zone-below-negative-1.c#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,
)
07070100000055000081A400000000000000000000000168059A48000003D1000000000000000000000000000000000000004700000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-auto-exclusive-zone.c#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,
)
07070100000056000081A400000000000000000000000168059A48000002F5000000000000000000000000000000000000004B00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-explicit-exclusive-zone.c#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,
)
07070100000057000081A400000000000000000000000168059A4800000319000000000000000000000000000000000000004100000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-keyboard-mode.c#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,
)
07070100000058000081A400000000000000000000000168059A480000032E000000000000000000000000000000000000003900000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-layer.c#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,
)
07070100000059000081A400000000000000000000000168059A48000006C6000000000000000000000000000000000000003A00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-margin.c#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,
)
0707010000005A000081A400000000000000000000000168059A4800000326000000000000000000000000000000000000003B00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-monitor.c#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,
)
0707010000005B000081A400000000000000000000000168059A4800000184000000000000000000000000000000000000004E00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-namespace-custom-namespace.c#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,
)
0707010000005C000081A400000000000000000000000168059A480000015F000000000000000000000000000000000000004500000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-namespace-default.c#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,
)
0707010000005D000081A400000000000000000000000168059A4800000118000000000000000000000000000000000000005100000000gtk4-layer-shell-1.1.1/test/layer-tests/test-get-namespace-on-non-layer-window.c#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,
)
0707010000005E000081A400000000000000000000000168059A4800000290000000000000000000000000000000000000003D00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-hide-and-show.c#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,
)
0707010000005F000081A400000000000000000000000168059A4800000204000000000000000000000000000000000000004900000000gtk4-layer-shell-1.1.1/test/layer-tests/test-init-after-window-created.c#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,
)
07070100000060000081A400000000000000000000000168059A4800000253000000000000000000000000000000000000003F00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-is-layer-window.c#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,
)
07070100000061000081A400000000000000000000000168059A48000000B2000000000000000000000000000000000000004100000000gtk4-layer-shell-1.1.1/test/layer-tests/test-is-supported-true.c#include "integration-test-common.h"

static void callback_0() {
    ASSERT(gtk_layer_is_supported());
    ASSERT(gtk_layer_is_supported());
}

TEST_CALLBACKS(
    callback_0,
)
07070100000062000081A400000000000000000000000168059A480000012D000000000000000000000000000000000000004900000000gtk4-layer-shell-1.1.1/test/layer-tests/test-layer-surface-not-created.c#include "integration-test-common.h"

static GtkWindow *window;

static void callback_0() {
    UNEXPECT_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,
)
07070100000063000081A400000000000000000000000168059A48000004C4000000000000000000000000000000000000004300000000gtk4-layer-shell-1.1.1/test/layer-tests/test-layer-surface-popup.c#include "integration-test-common.h"

static GtkWindow *layer_window;
static GtkWidget *layer_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;

    layer_window = GTK_WINDOW(gtk_window_new());
    layer_dropdown = gtk_drop_down_new_from_strings(options);
    gtk_window_set_child(layer_window, layer_dropdown);
    gtk_layer_init_for_window(layer_window);
    gtk_window_present(layer_window);
}

static void callback_1() {
    EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface);
    EXPECT_MESSAGE(xdg_surface .get_popup nil);
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .get_popup);
    EXPECT_MESSAGE(xdg_popup .grab);

    UNEXPECT_MESSAGE(xdg_popup .destroy);

    g_signal_emit_by_name(layer_dropdown, "activate", NULL);
}

static void callback_2() {
    EXPECT_MESSAGE(xdg_popup .destroy);
    EXPECT_MESSAGE(xdg_surface .destroy);
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .destroy);

    gtk_window_close(layer_window);
    gtk_window_close(layer_window);
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
)
07070100000064000081A400000000000000000000000168059A480000060D000000000000000000000000000000000000003D00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-multi-anchors.c#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,
)
07070100000065000081A400000000000000000000000168059A48000002A3000000000000000000000000000000000000004E00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-set-anchor-normalizes-booleans.c#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,
)
07070100000066000081A400000000000000000000000168059A4800000784000000000000000000000000000000000000004000000000gtk4-layer-shell-1.1.1/test/layer-tests/test-set-default-size.c#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,
)
07070100000067000081A400000000000000000000000168059A4800000362000000000000000000000000000000000000004100000000gtk4-layer-shell-1.1.1/test/layer-tests/test-set-keyboard-mode.c#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,
)
07070100000068000081A400000000000000000000000168059A4800000400000000000000000000000000000000000000003900000000gtk4-layer-shell-1.1.1/test/layer-tests/test-set-layer.c#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,
)
07070100000069000081A400000000000000000000000168059A480000050A000000000000000000000000000000000000003A00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-set-margin.c#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,
)
0707010000006A000081A400000000000000000000000168059A48000002EC000000000000000000000000000000000000003B00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-set-monitor.c#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,
)
0707010000006B000081A400000000000000000000000168059A480000054C000000000000000000000000000000000000003E00000000gtk4-layer-shell-1.1.1/test/layer-tests/test-single-anchors.c#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,
)
0707010000006C000081A400000000000000000000000168059A48000006E9000000000000000000000000000000000000004000000000gtk4-layer-shell-1.1.1/test/layer-tests/test-uses-widget-size.c#include "integration-test-common.h"

static GtkWindow* window;
static GtkWidget* child;

static void callback_0() {
    EXPECT_MESSAGE(.create_buffer 850 940);
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 850 940);

    window = create_default_window();
    child = gtk_window_get_child(window);
    gtk_widget_set_size_request(child, 850, 940);

    gtk_layer_init_for_window(window);
    gtk_window_present(window);
}

static void callback_1() {
    EXPECT_MESSAGE(.create_buffer 1001 610);
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 1001 610);

    gtk_widget_set_size_request(child, 1001, 610);
}

static void callback_2() {
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 1001 0);
    EXPECT_MESSAGE(.create_buffer 1001 1080); // size must match DEFAULT_OUTPUT_HEIGHT in common.h

    gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, TRUE);
    gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE);
}

static void callback_3() {
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 0 0);
    EXPECT_MESSAGE(.create_buffer 1920 1080);

    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_4() {
    EXPECT_MESSAGE(.create_buffer 555 777);
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .set_size 555 777);

    gtk_widget_set_size_request(child, 555, 777);
    gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_LEFT, FALSE);
    gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_RIGHT, FALSE);
    gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_TOP, FALSE);
    gtk_layer_set_anchor(window, GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE);
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
    callback_3,
    callback_4,
)
0707010000006D000081A400000000000000000000000168059A480000065D000000000000000000000000000000000000005500000000gtk4-layer-shell-1.1.1/test/layer-tests/test-xdg-toplevel-popup-with-layer-surface.c#include "integration-test-common.h"

static GtkWindow *layer_window;
static GtkWindow *normal_window;
static GtkWidget *normal_dropdown;
static const char *options[] = {"Foo", "Bar", "Baz", NULL};

static void callback_0() {
    EXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface);
    EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface);
    EXPECT_MESSAGE(xdg_surface .get_toplevel);

    // The popup is weirdly slow to open, so slow the tests down
    step_time = 600;

    layer_window = create_default_window();
    gtk_layer_init_for_window(layer_window);
    gtk_window_present(layer_window);

    normal_window = GTK_WINDOW(gtk_window_new());
    normal_dropdown = gtk_drop_down_new_from_strings(options);
    GtkWidget *grid = gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), normal_dropdown, 0, 0, 1, 1);
    gtk_window_set_child(normal_window, grid);
    gtk_window_present(normal_window);
}

static void callback_1() {
    EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface);
    EXPECT_MESSAGE(xdg_surface .get_popup xdg_surface);
    EXPECT_MESSAGE(xdg_popup .grab);

    UNEXPECT_MESSAGE(zwlr_layer_surface_v1 .get_popup);
    UNEXPECT_MESSAGE(xdg_popup .destroy);

    g_signal_emit_by_name(normal_dropdown, "activate", NULL);
}

static void callback_2() {
    EXPECT_MESSAGE(xdg_popup .destroy);
    EXPECT_MESSAGE(xdg_surface .destroy);
    EXPECT_MESSAGE(xdg_toplevel .destroy);
    EXPECT_MESSAGE(xdg_surface .destroy);
    EXPECT_MESSAGE(zwlr_layer_surface_v1 .destroy);

    gtk_window_close(normal_window);
    gtk_window_close(layer_window);
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
)
0707010000006E000081A400000000000000000000000168059A4800000569000000000000000000000000000000000000005800000000gtk4-layer-shell-1.1.1/test/layer-tests/test-xdg-toplevel-popup-without-layer-surface.c#include "integration-test-common.h"

static GtkWindow *normal_window;
static GtkWidget *normal_dropdown;
static const char *options[] = {"Foo", "Bar", "Baz", NULL};

static void callback_0() {
    EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface);
    EXPECT_MESSAGE(xdg_surface .get_toplevel);

    UNEXPECT_MESSAGE(zwlr_layer_shell_v1 .get_layer_surface);

    // The popup is weirdly slow to open, so slow the tests down
    step_time = 1200;

    normal_window = GTK_WINDOW(gtk_window_new());
    normal_dropdown = gtk_drop_down_new_from_strings(options);
    GtkWidget *grid = gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), normal_dropdown, 0, 0, 1, 1);
    gtk_window_set_child(normal_window, grid);
    gtk_window_present(normal_window);
}

static void callback_1() {
    EXPECT_MESSAGE(xdg_wm_base .get_xdg_surface);
    EXPECT_MESSAGE(xdg_surface .get_popup xdg_surface);
    EXPECT_MESSAGE(xdg_popup .grab);

    UNEXPECT_MESSAGE(zwlr_layer_surface_v1 .get_popup);
    UNEXPECT_MESSAGE(xdg_popup .destroy);

    g_signal_emit_by_name(normal_dropdown, "activate", NULL);
}

static void callback_2() {
    EXPECT_MESSAGE(xdg_popup .destroy);
    EXPECT_MESSAGE(xdg_surface .destroy);
    EXPECT_MESSAGE(xdg_toplevel .destroy);
    EXPECT_MESSAGE(xdg_surface .destroy);

    gtk_window_close(normal_window);
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
)
0707010000006F000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002700000000gtk4-layer-shell-1.1.1/test/lock-tests07070100000070000081A400000000000000000000000168059A48000000D6000000000000000000000000000000000000003300000000gtk4-layer-shell-1.1.1/test/lock-tests/meson.buildlock_tests = [
    'test-lock-can-be-created-without-locking',
    'test-can-lock-display',
    'test-can-relock-display',
    'test-immediate-failure',
    'test-async-failure',
    'test-popup-on-lock-screen',
]
07070100000071000081A400000000000000000000000168059A4800000820000000000000000000000000000000000000003C00000000gtk4-layer-shell-1.1.1/test/lock-tests/test-async-failure.c#include "integration-test-common.h"

#include "ext-session-lock-v1-client.h"
#include "dlfcn.h"

enum lock_state_t state = 0;
struct ext_session_lock_manager_v1* global;
GtkSessionLockInstance* lock;

static void wl_registry_handle_global(
    void* _data,
    struct wl_registry* registry,
    uint32_t id,
    const char* interface,
    uint32_t version
) {
    (void)_data;

    if (strcmp(interface, ext_session_lock_manager_v1_interface.name) == 0) {
        global = wl_registry_bind(registry, id, &ext_session_lock_manager_v1_interface, 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,
};

static void bind_global(struct wl_display* display) {
    struct wl_registry* registry = wl_display_get_registry(display);
    wl_registry_add_listener(registry, &wl_registry_listener, NULL);
    wl_display_roundtrip(display);
    wl_registry_destroy(registry);
}

static void callback_0() {
    // We lock the display without going through the library in order to simulate a lock being held by another process
    bind_global(gdk_wayland_display_get_wl_display(gdk_display_get_default()));
    ASSERT(global);
    struct ext_session_lock_v1* session_lock = ext_session_lock_manager_v1_lock(global);
    (void)session_lock;
}

static void callback_1() {
    EXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    EXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    EXPECT_MESSAGE(ext_session_lock_v1 .finished);

    lock = gtk_session_lock_instance_new();
    connect_lock_signals(lock, &state);

    ASSERT(gtk_session_lock_instance_lock(lock));
    ASSERT_EQ(state, LOCK_STATE_UNLOCKED, "%d");
    create_default_lock_windows(lock);
}

static void callback_2() {
    ASSERT_EQ(state, LOCK_STATE_FAILED, "%d");
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
)
07070100000072000081A400000000000000000000000168059A480000031A000000000000000000000000000000000000003F00000000gtk4-layer-shell-1.1.1/test/lock-tests/test-can-lock-display.c#include "integration-test-common.h"

enum lock_state_t state = 0;
GtkSessionLockInstance* lock;

static void callback_0() {
    EXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    EXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    EXPECT_MESSAGE(ext_session_lock_v1 .locked);

    lock = gtk_session_lock_instance_new();
    connect_lock_signals(lock, &state);

    ASSERT(gtk_session_lock_instance_lock(lock));
    create_default_lock_windows(lock);
}

static void callback_1() {
    ASSERT_EQ(state, LOCK_STATE_LOCKED, "%d");
    EXPECT_MESSAGE(ext_session_lock_v1 .unlock_and_destroy);

    gtk_session_lock_instance_unlock(lock);
}

static void callback_2() {
    ASSERT_EQ(state, LOCK_STATE_UNLOCKED, "%d");
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
)
07070100000073000081A400000000000000000000000168059A4800000965000000000000000000000000000000000000004100000000gtk4-layer-shell-1.1.1/test/lock-tests/test-can-relock-display.c#include "integration-test-common.h"

enum lock_state_t state_a = 0;
GtkSessionLockInstance* lock_a;

enum lock_state_t state_b = 0;
GtkSessionLockInstance* lock_b;

static void callback_0() {
    EXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    EXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    EXPECT_MESSAGE(ext_session_lock_v1 .locked);

    lock_a = gtk_session_lock_instance_new();
    connect_lock_signals(lock_a, &state_a);
    ASSERT(!gtk_session_lock_instance_is_locked(lock_a));

    ASSERT(gtk_session_lock_instance_lock(lock_a));
    create_default_lock_windows(lock_a);
}

static void callback_1() {
    ASSERT(gtk_session_lock_instance_is_locked(lock_a));
    ASSERT_EQ(state_a, LOCK_STATE_LOCKED, "%d");

    EXPECT_MESSAGE(ext_session_lock_v1 .unlock_and_destroy);

    gtk_session_lock_instance_unlock(lock_a);
    ASSERT(!gtk_session_lock_instance_is_locked(lock_a));
    ASSERT_EQ(state_a, LOCK_STATE_UNLOCKED, "%d");
    CHECK_EXPECTATIONS();

    EXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    EXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    EXPECT_MESSAGE(ext_session_lock_v1 .locked);

    ASSERT(gtk_session_lock_instance_lock(lock_a));
    create_default_lock_windows(lock_a);
}

static void callback_2() {
    ASSERT(gtk_session_lock_instance_is_locked(lock_a));
    ASSERT_EQ(state_a, LOCK_STATE_LOCKED, "%d");

    EXPECT_MESSAGE(ext_session_lock_v1 .unlock_and_destroy);

    gtk_session_lock_instance_unlock(lock_a);
    ASSERT(!gtk_session_lock_instance_is_locked(lock_a));
    ASSERT_EQ(state_a, LOCK_STATE_UNLOCKED, "%d");
    CHECK_EXPECTATIONS();

    EXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    EXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    EXPECT_MESSAGE(ext_session_lock_v1 .locked);

    lock_b = gtk_session_lock_instance_new();
    connect_lock_signals(lock_b, &state_b);

    ASSERT(gtk_session_lock_instance_lock(lock_b));
    create_default_lock_windows(lock_b);
}

static void callback_3() {
    ASSERT(gtk_session_lock_instance_is_locked(lock_b));
    ASSERT_EQ(state_b, LOCK_STATE_LOCKED, "%d");
    ASSERT(!gtk_session_lock_instance_is_locked(lock_a));
    ASSERT_EQ(state_a, LOCK_STATE_UNLOCKED, "%d");

    EXPECT_MESSAGE(ext_session_lock_v1 .unlock_and_destroy);

    gtk_session_lock_instance_unlock(lock_b);
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
    callback_3,
)
07070100000074000081A400000000000000000000000168059A480000051C000000000000000000000000000000000000004000000000gtk4-layer-shell-1.1.1/test/lock-tests/test-immediate-failure.c#include "integration-test-common.h"

enum lock_state_t state_a = 0;
GtkSessionLockInstance* lock_a;

enum lock_state_t state_b = 0;
GtkSessionLockInstance* lock_b;

static void callback_0() {
    EXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    EXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    EXPECT_MESSAGE(ext_session_lock_v1 .locked);

    lock_a = gtk_session_lock_instance_new();
    connect_lock_signals(lock_a, &state_a);

    lock_b = gtk_session_lock_instance_new();
    connect_lock_signals(lock_b, &state_b);

    ASSERT(gtk_session_lock_instance_lock(lock_b));
    ASSERT(!gtk_session_lock_instance_lock(lock_b));
    create_default_lock_windows(lock_b);
}

static void callback_1() {
    ASSERT_EQ(state_a, LOCK_STATE_UNLOCKED, "%d");
    ASSERT_EQ(state_b, LOCK_STATE_LOCKED, "%d");
    UNEXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    UNEXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    UNEXPECT_MESSAGE(ext_session_lock_v1 .unlock_and_destroy);
    UNEXPECT_MESSAGE(ext_session_lock_v1 .destroy);
    UNEXPECT_MESSAGE(ext_session_lock_v1 .locked);
    UNEXPECT_MESSAGE(ext_session_lock_v1 .finished);

    ASSERT(!gtk_session_lock_instance_lock(lock_a));
    ASSERT_EQ(state_a, LOCK_STATE_FAILED, "%d");
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
)
07070100000075000081A400000000000000000000000168059A480000021A000000000000000000000000000000000000005200000000gtk4-layer-shell-1.1.1/test/lock-tests/test-lock-can-be-created-without-locking.c#include "integration-test-common.h"

enum lock_state_t state = 0;
GtkSessionLockInstance* lock;

static void callback_0() {
    UNEXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    UNEXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    UNEXPECT_MESSAGE(ext_session_lock_v1 .locked);

    ASSERT(gtk_session_lock_is_supported());

    lock = gtk_session_lock_instance_new();
    connect_lock_signals(lock, &state);
    g_object_unref(lock);

    ASSERT_EQ(state, LOCK_STATE_UNLOCKED, "%d");
}

TEST_CALLBACKS(
    callback_0,
)
07070100000076000081A400000000000000000000000168059A4800000458000000000000000000000000000000000000004300000000gtk4-layer-shell-1.1.1/test/lock-tests/test-popup-on-lock-screen.c#include "integration-test-common.h"

enum lock_state_t state = 0;
GtkSessionLockInstance* lock;
GtkWindow* window;
static GtkWidget *dropdown;
static const char *options[] = {"Foo", "Bar", "Baz", NULL};

GtkWindow* build_window() {
    window = GTK_WINDOW(gtk_window_new());
    dropdown = gtk_drop_down_new_from_strings(options);
    gtk_window_set_child(window, dropdown);
    return window;
}

static void callback_0() {
    // The popup is weirdly slow to open, so slow the tests down
    step_time = 1200;

    lock = gtk_session_lock_instance_new();
    connect_lock_signals(lock, &state);

    ASSERT(gtk_session_lock_instance_lock(lock));
    create_lock_windows(lock, build_window);
}

static void callback_1() {
    ASSERT_EQ(state, LOCK_STATE_LOCKED, "%d");

    g_signal_emit_by_name(dropdown, "activate", NULL);
}

static void callback_2() {
    ASSERT_EQ(state, LOCK_STATE_LOCKED, "%d");

    gtk_session_lock_instance_unlock(lock);
}

static void callback_3() {
    ASSERT_EQ(state, LOCK_STATE_UNLOCKED, "%d");
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
    callback_3,
)
07070100000077000081A400000000000000000000000168059A4800000675000000000000000000000000000000000000002800000000gtk4-layer-shell-1.1.1/test/meson.buildsubdir('test-common')
subdir('mock-server')
subdir('integration-test-common')
subdir('layer-tests')
subdir('lock-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 test_list : [['layer', layer_tests], ['lock', lock_tests]]
    test_prefix = test_list[0]
    test_dir = test_prefix + '-tests'
    foreach test_name : test_list[1]
        test_full_name = test_prefix + '-' + test_name
        exe = executable(
            test_full_name,
            files(join_paths(test_dir, test_name + '.c')), client_protocol_srcs,
            dependencies: [gtk, wayland_client, gtk_layer_shell, integration_test_common])
        test(
            test_full_name,
            py,
            workdir: meson.current_source_dir(),
            env: env,
            args: [
                run_test_script,
                meson.current_build_dir() + '/' + test_full_name,
            ])
    endforeach
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])
07070100000078000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002800000000gtk4-layer-shell-1.1.1/test/mock-server07070100000079000081A400000000000000000000000168059A4800000109000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/test/mock-server/meson.buildmock_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])
0707010000007A000081A400000000000000000000000168059A4800001044000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/test/mock-server/mock-server.c#include "mock-server.h"

struct wl_display* display = NULL;

static const char* get_display_name() {
    const char* result = getenv("WAYLAND_DISPLAY");
    if (!result) {
        FATAL("WAYLAND_DISPLAY not set");
    }
    return result;
}

struct request_override_t {
    const struct wl_message* message;
    request_override_function_t function;
    struct wl_list link;
};

struct wl_list request_overrides;

void install_request_override(
    const struct wl_interface* interface,
    const char* name,
    request_override_function_t function
) {
    for (int i = 0; i < interface->method_count; i++) {
        if (strcmp(name, interface->methods[i].name) == 0) {
            struct request_override_t* override = calloc(1, sizeof(struct request_override_t));
            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
) {
    struct wl_resource* created = NULL;

    // If there is a new-id type argument, a resource needs to be created for it
    // 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) {
            created = wl_resource_create(
                wl_resource_get_client(resource),
                message->types[arg],
                wl_resource_get_version(resource),
                args[arg].n);
            use_default_impl(created);
            break;
        }
        if (*c >= 'a' && *c <= 'z')
            arg++;
    }

    struct request_override_t* override;
    wl_list_for_each(override, &request_overrides, link) {
        if (override->message == message) {
            override->function(resource, message, created, args);
            break;
        }
    }

    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;
}
0707010000007B000081A400000000000000000000000168059A480000089E000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/test/mock-server/mock-server.h// 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*

#pragma once

#include "test-common.h"
#include <wayland-server.h>
#include "xdg-shell-server.h"
#include "xdg-dialog-v1-server.h"
#include "ext-session-lock-v1-server.h"
#include "wlr-layer-shell-unstable-v1-server.h"

extern struct wl_display* display;

#define REQUEST_OVERRIDE_IMPL(type, method) static void type##_##method( \
    struct wl_resource* type, \
    const struct wl_message* message, \
    struct wl_resource* new_resource, \
    union wl_argument* args)
#define OVERRIDE_REQUEST(type, method) install_request_override(&type##_interface, #method, type##_##method)
#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;
#define INT_ARG(name, index) ASSERT(type_code_at_index(message, index) == 'i'); int32_t name = args[index].i;

typedef void (*request_override_function_t)(struct wl_resource* resource, const struct wl_message* message, struct wl_resource* created, union wl_argument* args);
void install_request_override(const struct wl_interface* interface, const char* name, request_override_function_t 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();
0707010000007C000081A400000000000000000000000168059A4800003C29000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/test/mock-server/overrides.c#include "mock-server.h"
#include "linux/input.h"

enum surface_role_t {
    SURFACE_ROLE_NONE = 0,
    SURFACE_ROLE_XDG_TOPLEVEL,
    SURFACE_ROLE_XDG_POPUP,
    SURFACE_ROLE_LAYER,
    SURFACE_ROLE_SESSION_LOCK,
};

struct surface_data_t {
    enum surface_role_t role;
    struct wl_resource* surface;
    struct wl_resource* pending_frame;
    struct wl_resource* pending_buffer; // The attached but not committed buffer
    bool buffer_cleared; // If the buffer has been explicitly cleared since the last commit
    bool pending_window_geom; // If the window geom has been set since last commit
    struct wl_resource* xdg_toplevel;
    struct wl_resource* xdg_popup;
    struct wl_resource* xdg_surface;
    struct wl_resource* layer_surface;
    struct wl_resource* lock_surface;
    bool has_committed_buffer; // This surface has a non-null committed buffer
    bool initial_commit_for_role; // Set to 1 when a role is created for a surface, and cleared after the first commit
    bool 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
    uint32_t lock_surface_pending_serial;
    bool lock_surface_initial_configure_acked;
    struct surface_data_t* most_recent_popup; // Start of the popup linked list
    struct surface_data_t* previous_popup_sibling; // Forms a linked list of popups
    struct surface_data_t* popup_parent;
};

static struct wl_resource* seat_global = NULL;
static struct wl_resource* pointer_global = NULL;
static struct wl_resource* output_global = NULL;
static struct wl_resource* current_session_lock = NULL;

static void surface_data_assert_no_role(struct surface_data_t* data) {
    ASSERT(!data->xdg_popup);
    ASSERT(!data->xdg_toplevel);
    ASSERT(!data->xdg_surface);
    ASSERT(!data->layer_surface);
    ASSERT(!data->lock_surface);
}

// Needs to be called before any role objects are assigned
static void surface_data_set_role(struct surface_data_t* data, enum surface_role_t role) {
    if (data->role != SURFACE_ROLE_NONE) {
        ASSERT_EQ(data->role, role, "%u");
    }

    if (role == SURFACE_ROLE_XDG_TOPLEVEL || role == SURFACE_ROLE_XDG_POPUP) {
        ASSERT(data->xdg_surface != NULL);
    } else {
        ASSERT(data->xdg_surface == NULL);
    }

    struct wl_resource* xdg_surface = data->xdg_surface;
    data->xdg_surface = NULL; // XDG surfaces are allowed, so hide it from surface_data_assert_no_role()
    surface_data_assert_no_role(data);
    data->xdg_surface = xdg_surface;

    ASSERT(!data->has_committed_buffer);
    data->role = role;
    data->initial_commit_for_role = 1;
}

static void surface_data_unmap(struct surface_data_t* data) {
    struct surface_data_t* popup = data->most_recent_popup;
    while (popup) {
        // Popups must be unmapped before their parents
        surface_data_assert_no_role(data);
        popup = popup->previous_popup_sibling;
    }
}

static void surface_data_add_pupup(struct surface_data_t* parent, struct surface_data_t* popup) {
    ASSERT(!popup->previous_popup_sibling);
    popup->previous_popup_sibling = parent->most_recent_popup;
    parent->most_recent_popup = popup;
    popup->popup_parent = parent;
}

REQUEST_OVERRIDE_IMPL(wl_surface, frame) {
    struct surface_data_t* data = wl_resource_get_user_data(wl_surface);
    ASSERT(!data->pending_frame);
    data->pending_frame = new_resource;
}

REQUEST_OVERRIDE_IMPL(wl_surface, attach) {
    RESOURCE_ARG(wl_buffer, buffer, 0);
    struct surface_data_t* data = wl_resource_get_user_data(wl_surface);
    data->pending_buffer = buffer;
    data->buffer_cleared = buffer == NULL;
}

REQUEST_OVERRIDE_IMPL(wl_surface, commit) {
    struct surface_data_t* data = wl_resource_get_user_data(wl_surface);

    if (data->role == SURFACE_ROLE_SESSION_LOCK) {
        if (data->buffer_cleared) {
            FATAL("null buffer committed to session lock surface");
        } else if (!data->pending_buffer && !data->has_committed_buffer) {
            FATAL("no buffer has been attached to committed session lock surface");
        } else if (!data->lock_surface_initial_configure_acked) {
            FATAL("session lock surface committed before initial configure acked");
        }
    }

    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_window_geom) {
        ASSERT(data->has_committed_buffer);
        data->pending_window_geom = 0;
    }

    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 && data->role != SURFACE_ROLE_SESSION_LOCK) {
        ASSERT(!data->has_committed_buffer);
        data->initial_commit_for_role = 0;
    }

    if (data->layer_surface && data->layer_send_configure) {
        bool horiz = (
            (data->layer_anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT) &&
            (data->layer_anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT));
        bool 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;
    }
}

REQUEST_OVERRIDE_IMPL(wl_surface, destroy) {
    struct surface_data_t* data = wl_resource_get_user_data(wl_surface);
    surface_data_assert_no_role(data);
    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
}

REQUEST_OVERRIDE_IMPL(wl_compositor, create_surface) {
    struct surface_data_t* data = calloc(1, sizeof(struct surface_data_t));
    wl_resource_set_user_data(new_resource, data);
    data->surface = new_resource;
}

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);
};

REQUEST_OVERRIDE_IMPL(wl_seat, get_pointer) {
    ASSERT(!pointer_global);
    pointer_global = new_resource;
}

REQUEST_OVERRIDE_IMPL(xdg_wm_base, get_xdg_surface) {
    RESOURCE_ARG(wl_surface, surface, 1);
    struct surface_data_t* data = wl_resource_get_user_data(surface);
    wl_resource_set_user_data(new_resource, data);
    data->xdg_surface = new_resource;
}

REQUEST_OVERRIDE_IMPL(xdg_surface, destroy) {
    struct surface_data_t* data = wl_resource_get_user_data(xdg_surface);
    ASSERT(!data->xdg_toplevel);
    ASSERT(!data->xdg_popup);
    data->xdg_surface = NULL;
}

REQUEST_OVERRIDE_IMPL(xdg_surface, set_window_geometry) {
    //INT_ARG(x, 0);
    //INT_ARG(y, 1);
    INT_ARG(width, 2);
    INT_ARG(height, 3);
    struct surface_data_t* data = wl_resource_get_user_data(xdg_surface);
    ASSERT(width > 0);
    ASSERT(height > 0);
    data->pending_window_geom = true;
}

REQUEST_OVERRIDE_IMPL(xdg_surface, get_toplevel) {
    struct wl_array states;
    wl_array_init(&states);
    xdg_toplevel_send_configure(new_resource, 0, 0, &states);
    wl_array_release(&states);
    xdg_surface_send_configure(xdg_surface, wl_display_next_serial(display));
    struct surface_data_t* data = wl_resource_get_user_data(xdg_surface);
    surface_data_set_role(data, SURFACE_ROLE_XDG_TOPLEVEL);
    wl_resource_set_user_data(new_resource, data);
    data->xdg_toplevel = new_resource;
}

REQUEST_OVERRIDE_IMPL(xdg_toplevel, destroy) {
    struct surface_data_t* data = wl_resource_get_user_data(xdg_toplevel);
    ASSERT(data->xdg_surface);
    data->xdg_toplevel = NULL;
    surface_data_unmap(data);
}

REQUEST_OVERRIDE_IMPL(xdg_surface, get_popup) {
    RESOURCE_ARG(xdg_surface, parent, 1);
    // If the configure size is too small GTK gets upset and unmaps its popup in protest
    // https://gitlab.gnome.org/GNOME/gtk/-/blob/4.16.12/gtk/gtkpopover.c?ref_type=tags#L719
    xdg_popup_send_configure(new_resource, 0, 0, 500, 500);
    xdg_surface_send_configure(xdg_surface, wl_display_next_serial(display));
    struct surface_data_t* data = wl_resource_get_user_data(xdg_surface);
    surface_data_set_role(data, SURFACE_ROLE_XDG_POPUP);
    wl_resource_set_user_data(new_resource, data);
    data->xdg_popup = new_resource;
    if (parent) {
        struct surface_data_t* parent_data = wl_resource_get_user_data(parent);
        surface_data_add_pupup(parent_data, data);
    }
}

REQUEST_OVERRIDE_IMPL(xdg_popup, grab) {
    struct surface_data_t* data = wl_resource_get_user_data(xdg_popup);
    RESOURCE_ARG(wl_seat, seat, 0);
    ASSERT_EQ(seat, seat_global, "%p");
    ASSERT(data->popup_parent);
}

REQUEST_OVERRIDE_IMPL(xdg_popup, destroy) {
    struct surface_data_t* data = wl_resource_get_user_data(xdg_popup);
    ASSERT(data->xdg_surface);
    data->xdg_popup = NULL;
    surface_data_unmap(data);
}

REQUEST_OVERRIDE_IMPL(zwlr_layer_surface_v1, set_anchor) {
    UINT_ARG(anchor, 0);
    struct surface_data_t* data = wl_resource_get_user_data(zwlr_layer_surface_v1);
    data->layer_send_configure = 1;
    data->layer_anchor = anchor;
}

REQUEST_OVERRIDE_IMPL(zwlr_layer_surface_v1, set_size) {
    UINT_ARG(width, 0);
    UINT_ARG(height, 1);
    struct surface_data_t* data = wl_resource_get_user_data(zwlr_layer_surface_v1);
    data->layer_send_configure = 1;
    data->layer_set_w = width;
    data->layer_set_h = height;
}

REQUEST_OVERRIDE_IMPL(zwlr_layer_surface_v1, get_popup) {
    RESOURCE_ARG(xdg_popup, popup, 0);
    struct surface_data_t* data = wl_resource_get_user_data(zwlr_layer_surface_v1);
    struct surface_data_t* popup_data = wl_resource_get_user_data(popup);
    ASSERT(!popup_data->popup_parent);
    surface_data_add_pupup(data, popup_data);
}

REQUEST_OVERRIDE_IMPL(zwlr_layer_shell_v1, get_layer_surface) {
    RESOURCE_ARG(wl_surface, surface, 1);
    struct surface_data_t* data = wl_resource_get_user_data(surface);
    surface_data_set_role(data, SURFACE_ROLE_LAYER);
    wl_resource_set_user_data(new_resource, data);
    data->layer_send_configure = 1;
    data->layer_surface = new_resource;
}

REQUEST_OVERRIDE_IMPL(zwlr_layer_surface_v1, destroy) {
    struct surface_data_t* data = wl_resource_get_user_data(zwlr_layer_surface_v1);
    data->layer_surface = NULL;
    surface_data_unmap(data);
}

REQUEST_OVERRIDE_IMPL(ext_session_lock_manager_v1, lock) {
    if (current_session_lock) {
        ext_session_lock_v1_send_finished(new_resource);
    } else {
        current_session_lock = new_resource;
        ext_session_lock_v1_send_locked(new_resource);
    }
}

REQUEST_OVERRIDE_IMPL(ext_session_lock_v1, destroy) {
    if (ext_session_lock_v1 == current_session_lock) {
        FATAL(".destroy (instead of .unlock_and_destroy) called on active lock");
    }
}

REQUEST_OVERRIDE_IMPL(ext_session_lock_v1, unlock_and_destroy) {
    if (ext_session_lock_v1 != current_session_lock) {
        FATAL(".unlock_and_destroy (instead of .destroy) called on inactive lock");
    }
    current_session_lock = NULL;
}

static void lock_surface_send_configure(struct surface_data_t* data, uint32_t width, uint32_t height) {
    data->lock_surface_pending_serial = wl_display_next_serial(display);
    ext_session_lock_surface_v1_send_configure(data->lock_surface, data->lock_surface_pending_serial, width, height);
}

REQUEST_OVERRIDE_IMPL(ext_session_lock_v1, get_lock_surface) {
    RESOURCE_ARG(wl_surface, surface, 1);
    RESOURCE_ARG(wl_output, output, 2);
    ASSERT_EQ(output, output_global, "%p");
    struct surface_data_t* data = wl_resource_get_user_data(surface);
    surface_data_set_role(data, SURFACE_ROLE_SESSION_LOCK);
    wl_resource_set_user_data(new_resource, data);
    data->lock_surface = new_resource;
    lock_surface_send_configure(data, DEFAULT_OUTPUT_WIDTH, DEFAULT_OUTPUT_HEIGHT);
}

REQUEST_OVERRIDE_IMPL(ext_session_lock_surface_v1, ack_configure) {
    UINT_ARG(serial, 0);
    struct surface_data_t* data = wl_resource_get_user_data(ext_session_lock_surface_v1);
    if (serial == data->lock_surface_pending_serial) {
        data->lock_surface_initial_configure_acked = 1;
    }
}

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, set_window_geometry);
    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);
    OVERRIDE_REQUEST(ext_session_lock_manager_v1, lock);
    OVERRIDE_REQUEST(ext_session_lock_v1, destroy);
    OVERRIDE_REQUEST(ext_session_lock_v1, unlock_and_destroy);
    OVERRIDE_REQUEST(ext_session_lock_v1, get_lock_surface);
    OVERRIDE_REQUEST(ext_session_lock_surface_v1, ack_configure);

    wl_global_create(display, &wl_seat_interface, 6, NULL, wl_seat_bind);
    wl_global_create(display, &wl_output_interface, 2, NULL, wl_output_bind);
    default_global_create(display, &wl_shm_interface, 1);
    default_global_create(display, &wl_data_device_manager_interface, 2);
    default_global_create(display, &wl_compositor_interface, 4);
    default_global_create(display, &wl_subcompositor_interface, 1);
    default_global_create(display, &xdg_wm_base_interface, 2);
    default_global_create(display, &zwlr_layer_shell_v1_interface, 4);
    default_global_create(display, &ext_session_lock_manager_v1_interface, 1);
    default_global_create(display, &xdg_wm_dialog_v1_interface, 1);
}
0707010000007D000081ED00000000000000000000000168059A4800002AA7000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/test/run-integration-test.py#!/usr/bin/python3
# This script runs an integration test. See test/README.md for details
usage = 'Usage: python3 run-test <test-binary>'

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('UNEXPECT: '):
            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) + '"')

        if 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
            negative_assertions = []

    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)
0707010000007E000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002800000000gtk4-layer-shell-1.1.1/test/smoke-tests0707010000007F000081A400000000000000000000000168059A48000000AA000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/test/smoke-tests/meson.buildsmoke_tests = [
    'test-c-example',
    'test-c-demo',
    'test-c-session-lock',
    'test-python-example',
    'test-python-session-lock',
    'test-vala-example',
]
07070100000080000081A400000000000000000000000168059A4800000446000000000000000000000000000000000000003D00000000gtk4-layer-shell-1.1.1/test/smoke-tests/smoke_test_common.pyimport 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], mode: str, env: Dict[str, str]) -> None:
    if mode == 'layer':
        expect('zwlr_layer_shell_v1', '.get_layer_surface')
        expect('wl_surface', '.commit')
    elif mode == 'lock':
        expect('ext_session_lock_manager_v1', '.lock');
        expect('ext_session_lock_v1', '.get_lock_surface');
        expect('ext_session_lock_v1', '.locked');
    else:
        assert False, 'Invalid mode ' + str(mode)
    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
07070100000081000081ED00000000000000000000000168059A48000000EC000000000000000000000000000000000000003700000000gtk4-layer-shell-1.1.1/test/smoke-tests/test-c-demo.py#!/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, 'layer', {})
07070100000082000081ED00000000000000000000000168059A48000000A9000000000000000000000000000000000000003A00000000gtk4-layer-shell-1.1.1/test/smoke-tests/test-c-example.py#!/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], 'layer', {})
07070100000083000081ED00000000000000000000000168059A48000000A6000000000000000000000000000000000000003F00000000gtk4-layer-shell-1.1.1/test/smoke-tests/test-c-session-lock.py#!/usr/bin/env python3

import smoke_test_common

bin_path = smoke_test_common.build_dir() + '/examples/session-lock-c'
smoke_test_common.run([bin_path], 'lock', {})
07070100000084000081ED00000000000000000000000168059A48000001B3000000000000000000000000000000000000003F00000000gtk4-layer-shell-1.1.1/test/smoke-tests/test-python-example.py#!/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], 'layer', env)
07070100000085000081ED00000000000000000000000168059A48000001B0000000000000000000000000000000000000004400000000gtk4-layer-shell-1.1.1/test/smoke-tests/test-python-session-lock.py#!/usr/bin/env python3

import os
import smoke_test_common

script_path = os.path.join(os.path.dirname(__file__), '..', '..', 'examples', 'session-lock.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], 'lock', env)
07070100000086000081ED00000000000000000000000168059A48000000AC000000000000000000000000000000000000003D00000000gtk4-layer-shell-1.1.1/test/smoke-tests/test-vala-example.py#!/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], 'layer', {})
07070100000087000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002800000000gtk4-layer-shell-1.1.1/test/test-common07070100000088000081A400000000000000000000000168059A4800000055000000000000000000000000000000000000003400000000gtk4-layer-shell-1.1.1/test/test-common/meson.buildtest_common = declare_dependency(
    include_directories: include_directories('.'))
07070100000089000081A400000000000000000000000168059A4800000332000000000000000000000000000000000000003600000000gtk4-layer-shell-1.1.1/test/test-common/test-common.h#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>

#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)

0707010000008A000041ED00000000000000000000000268059A4800000000000000000000000000000000000000000000002700000000gtk4-layer-shell-1.1.1/test/unit-tests0707010000008B000081A400000000000000000000000168059A48000000D0000000000000000000000000000000000000003300000000gtk4-layer-shell-1.1.1/test/unit-tests/meson.buildtest('unit-test-get-version',
    executable(
        'test-get-version',
        files('test-get-version.c'),
        dependencies: [gtk, gtk_layer_shell, test_common]),
    args: [meson.project_version()])
0707010000008C000081A400000000000000000000000168059A48000001C9000000000000000000000000000000000000003A00000000gtk4-layer-shell-1.1.1/test/unit-tests/test-get-version.c#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;
}
07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!633 blocks
openSUSE Build Service is sponsored by