File wayback.obscpio of Package wayback
07070100000000000081a4000000000000000000000001689c3e8c00000478000000000000000000000000000000000000001600000000wayback/.clang-format---
BasedOnStyle:  Mozilla
---
Language:                               Cpp
AccessModifierOffset:                   -4
AllowShortIfStatementsOnASingleLine:    false
AlwaysBreakAfterDefinitionReturnType:   None
AlwaysBreakAfterReturnType:             None
AlignAfterOpenBracket:                  true
AlignOperands:                          true
ColumnLimit:                            100
ConstructorInitializerIndentWidth:      4
ContinuationIndentWidth:                4
IncludeBlocks:                          Regroup
IndentWidth:                            4
PointerAlignment:                       Right
UseTab:                                 AlignWithSpaces
TabWidth:                               4
SpacesInCStyleCastParentheses:          false
Standard:                               c++20
BreakBeforeBraces:                      Custom
BraceWrapping:
  AfterClass:      true
  AfterControlStatement: false
  AfterEnum:       true
  AfterFunction:   true
  AfterNamespace:  true
  AfterObjCDeclaration: false
  AfterStruct:     true
  AfterUnion:      true
  BeforeCatch:     false
  BeforeElse:      false
  IndentBraces:    false
...
07070100000001000081a4000000000000000000000001689c3e8c00000020000000000000000000000000000000000000000d00000000wayback/.gitgitdir: ../.git/modules/wayback
07070100000002000081a4000000000000000000000001689c3e8c000006de000000000000000000000000000000000000002b00000000wayback/.gitlab/issue_templates/Default.md<!--
        Thank you for your time reporting bugs in Wayback!  In other to make it
        easy for us to fix it and speed up the process of troubleshooting, we
        ask you to fill in the following form.
-->
### Describe your issue
<!--
        Describe what is exactly happening.  Include as much information as
        possible to make it easier to know what is going on.
-->
#### Expected behavior
#### Current behavior
#### Steps to reproduce
### Environment
<!--
        Environment you tested in, where the bug is present.
        This helps for reproducibility.
-->
* Wayback version/commit (`git rev-parse --short HEAD`): 
* Operating system info (`uname -a`, `cat /etc/os-release`): 
* Window Manager/Desktop Environment (with version/commit): 
### Additional information
<!--
        This is where you can add logs, screenshots, or screencasts as needed.
        Use <details> or put in attachement if too long.
-->
### Checklist
<!--
        If you are using a distribution package, please note that as development
        continues they may become out of date very quickly, and we ask you to
        reproduce your issue on the latest git revision if possible as it may 
        have been fixed there already.
-->
* [ ] I confirm that the issue is still present on the latest git revision of 
      Wayback as of the time of reporting.
<!--
        We ask you to please check other bug reports to see if your bug has already
        been reported, to avoid duplicates.
        See <https://gitlab.freedesktop.org/wayback/wayback/-/issues>
-->
* [ ] I checked the existing [bug reports][gl-bugs] and confirmed the issue 
      has not been already reported
[gl-bugs]: https://gitlab.freedesktop.org/wayback/wayback/-/issues
07070100000003000081a4000000000000000000000001689c3e8c00000481000000000000000000000000000000000000003300000000wayback/.gitlab/issue_templates/Feature_request.md<!--
        Use this template to start discussing about a new wanted feature.
        Although we recommend submitting MRs instead of feature requests, if 
        you have no programming experience or otherwise cannot do that you 
        can request it here and someone else may possibly work on it.
-->
### Description
<!--
        Describe the feature you would like to have.
-->
### Checklist
<!--
        If you are using a distribution package, please note that as development
        continues they may become out of date very quickly, and we ask you to
        see if the feature you need is present on the latest git revision.
-->
* [ ] I confirm that the feature I want is not on the latest git revision of 
      Wayback as of the time of reporting.
<!--
        We ask you to please check other feature requests to see if yours has 
        already been reported, to avoid duplicates.
        See <https://gitlab.freedesktop.org/wayback/wayback/-/issues>
-->
* [ ] I checked the existing [feature requests][gl-feat] and confirmed this 
      is not a duplicate 
[gl-feat]: https://gitlab.freedesktop.org/wayback/wayback/-/issues
07070100000004000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000002000000000wayback/.gitlab/issue_templates07070100000005000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000001000000000wayback/.gitlab07070100000006000081a4000000000000000000000001689c3e8c000008f3000000000000000000000000000000000000001700000000wayback/.gitlab-ci.ymlstages:
    - style
    - build
clang-format:
    image: quay.io/almalinuxorg/almalinux:10
    stage: style
    cache:
      key: dnf-cache
      paths:
        - dnf-cache/
    script: |
          dnf --setopt=cachedir=`pwd`/dnf-cache --assumeyes install git-clang-format
          git clang-format --diff --commit ${CI_MERGE_REQUEST_DIFF_BASE_SHA}
    only:
        - merge_requests
alpine:
    image: docker.io/alpine:edge
    stage: build
    script: |
          apk update
          apk upgrade
          apk add \
            libc-dev \
            libxkbcommon-dev \
            gcc \
            meson \
            wayland-dev \
            wayland-protocols \
            wlroots-dev \
            xwayland-dev \
            scdoc
          meson setup --fatal-meson-warnings builddir/ -Dgenerate_manpages=enabled
          meson compile -C builddir/ -v
    only:
        - branches
        - merge_requests
arch:
    image: ghcr.io/archlinux/archlinux:base-devel
    stage: build
    cache:
      key: pacman-cache
      paths:
        - pacman-cache/
    script: |
          pacman --cachedir=`pwd`/pacman-cache -Syu --needed --noconfirm \
            libxkbcommon \
            meson \
            wayland \
            wayland-protocols \
            wlroots0.19 \
            xorg-xwayland \
            scdoc
          meson setup --fatal-meson-warnings builddir/ -Dgenerate_manpages=enabled
          meson compile -C builddir/ -v
    only:
        - branches
        - merge_requests
fedora:
    image: quay.io/fedora/fedora:rawhide
    stage: build
    cache:
      key: dnf-cache
      paths:
        - dnf-cache/
    script: |
          dnf --setopt=cachedir=`pwd`/dnf-cache --assumeyes install \
            meson \
            gcc \
            'pkgconfig(scdoc)' \
            'pkgconfig(wayland-client)' \
            'pkgconfig(wayland-cursor)' \
            'pkgconfig(wayland-egl)' \
            'pkgconfig(wayland-protocols)' \
            'pkgconfig(wayland-server)' \
            'pkgconfig(wlroots-0.19)' \
            'pkgconfig(xkbcommon)' \
            'pkgconfig(xwayland)'
          meson setup --fatal-meson-warnings builddir/ -Dgenerate_manpages=enabled
          meson compile -C builddir/ -v
    only:
        - branches
        - merge_requests
07070100000007000081a4000000000000000000000001689c3e8c0000042c000000000000000000000000000000000000001000000000wayback/LICENSECopyright (c) 2025 the wayback contributors
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.
07070100000008000081a4000000000000000000000001689c3e8c00000b14000000000000000000000000000000000000001200000000wayback/README.md# wayback
Wayback is a X11 compatibility layer which allows for running full X11
desktop environments using Wayland components.  It is essentially
a stub compositor which provides just enough Wayland capabilities to host
a rootful Xwayland server.
It is intended to eventually replace the classic X.Org server, thus reducing
maintenance burden of X11 applications, but a lot of work needs to be done first.
Wayback is an experimental state: expect breaking changes, and lots of
bugs.  Please submit pull requests fixing bugs instead of bug reports
if you are able.
## Installation
Dependencies:
- C compiler supporting the C23 standard (e.g. gcc >= 14 or clang >= 18)
- meson >= 1.4.0
- wayland (wayland-server, wayland-client, wayland-cursor, wayland-egl)
- wayland-protocol >=1.14
- xkbcommon
- wlroots-0.19
- xwayland >= 24.1
Building:
```
meson setup _build
cd _build
meson compile
```
Installing:
```
meson install
```
## Distribution packages
While Wayback is still alpha-quality software as of now there are packages in 
various popular distributions maintained by folks in the Wayback community.
***NOTE: These packages are NOT supported by Wayback developers, and as Wayback
development continues they may become out of date.  Wayback is still
alpha-quality software and development is rapidly moving, so before reporting any 
issues we ask you to replicate them on the git `main` branch to make sure they
are still applicable to the latest code.***
- Alpine Linux edge: [`wayback` and `wayback-doc`][alpine-pkg] in the `testing` 
  repository
- ALT Linux: [`wayback`][alt-pkg]
- Arch Linux: [`wayback-x11-git`][aur-pkg] in the AUR
- Fedora Linux: [`wayback`][fedora-pkg]
- Gentoo GURU: [`gui-wm/wayback`][gentoo-guru]
- Nixpkgs: [`wayback-x11`][nixpkgs-pkg]
- T2 SDE: [`wayback`][t2sde-pkg]
<!-- Keep sorted by link identifier, and then same order above -->
[alpine-pkg]: https://pkgs.alpinelinux.org/packages?name=wayback*&branch=edge&repo=&arch=&origin=&flagged=&maintainer=
[alt-pkg]: https://packages.altlinux.org/en/sisyphus/srpms/wayback/
[aur-pkg]: https://aur.archlinux.org/packages/wayback-x11-git
[fedora-pkg]: https://src.fedoraproject.org/rpms/wayback
[gentoo-guru]: https://wiki.gentoo.org/wiki/Project:GURU/Information_for_End_Users
[nixpkgs-pkg]: https://search.nixos.org/packages?channel=unstable&show=wayback-x11
[t2sde-pkg]: https://t2sde.org/packages/wayback
## Discussion
- Matrix: [`#wayback:catircservices.org`](https://matrix.to/#/#wayback:catircservices.org)
- IRC: irc.libera.chat `#wayback`
## Code of Conduct
As a project hosted on freedesktop.org, Wayback follows its [Code of Conduct][fdo-coc],
based on the Contributor Covenant.
Please conduct yourself in a respectful and civilized manner when using the above venues.
[fdo-coc]: https://www.freedesktop.org/wiki/CodeOfConduct
07070100000009000081a4000000000000000000000001689c3e8c000000b7000000000000000000000000000000000000001b00000000wayback/common/meson.buildcommon_sources = [
    'wayback_log.c',
    'utils.c',
    'optparse.c',
]
shared = declare_dependency(include_directories: '.', link_with: static_library('common', common_sources))
0707010000000a000081a4000000000000000000000001689c3e8c000003b1000000000000000000000000000000000000001a00000000wayback/common/optparse.c/*
 * Option parsing
 *
 * SPDX-License-Identifier: MIT
 */
#include "optparse.h"
#include "wayback_log.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int optind = 0, optpos = 0, optoper = 0;
int optparse(int argc, char *argv[], const struct optcmd opts[], uint32_t optlen)
{
	optpos++;
	optpos += optoper;
	optoper = 0;
	if (optpos >= argc || !argv[optpos]) {
		return -1;
	}
	for (uint32_t i = 0; i < optlen; i++) {
		if (strcmp(argv[optpos], opts[i].name) == 0) {
			if ((opts[i].req_operand) && (((optpos + 1) >= argc || !argv[optpos + 1]))) {
				wayback_log(LOG_ERROR, "Option %s requires operand", argv[optpos]);
				exit(EXIT_FAILURE);
			} else if (opts[i].ignore == true) {
				wayback_log(LOG_WARN, "Option %s ignored", argv[optpos]);
			}
			if (opts[i].req_operand) {
				optind++;
				optoper++;
			}
			optind++;
			break;
		}
	}
	return optpos;
}
0707010000000b000081a4000000000000000000000001689c3e8c00000262000000000000000000000000000000000000001a00000000wayback/common/optparse.h/*
 * Option parsing
 *
 * SPDX-License-Identifier: MIT
 */
#ifndef OPTPARSE_IMPORTED
#define OPTPARSE_IMPORTED
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
struct optcmd
{
	const char *name;
	const char *description;
	const bool req_operand;
	const bool ignore;
};
#define IGNORE_OPT(s, req_op)                                                                      \
	{ .name = s, .description = "", .req_operand = req_op, .ignore = true }
int optparse(int argc, char *argv[], const struct optcmd opts[], uint32_t optlen);
#endif
0707010000000c000081a4000000000000000000000001689c3e8c0000029a000000000000000000000000000000000000001700000000wayback/common/utils.c/*
 * Minor common utilities
 *
 * SPDX-License-Identifier: MIT
 */
#include "utils.h"
#include "wayback_log.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void asprintf_or_exit(char **restrict strp, const char *restrict fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	int ret = vasprintf(strp, fmt, args);
	va_end(args);
	if (ret == -1) {
		wayback_log(LOG_ERROR, "Failed to allocate memory for string");
		exit(EXIT_FAILURE);
	}
}
char *strdup_or_exit(const char *s)
{
	char *result = strdup(s);
	if (!result) {
		wayback_log(LOG_ERROR, "Failed to allocate memory for string");
		exit(EXIT_FAILURE);
	}
	return result;
}
0707010000000d000081a4000000000000000000000001689c3e8c0000011d000000000000000000000000000000000000001700000000wayback/common/utils.h/*
 * Minor common utilities
 *
 * SPDX-License-Identifier: MIT
 */
#ifndef UTILS_IMPORTED
#define UTILS_IMPORTED
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
void asprintf_or_exit(char **restrict strp, const char *restrict fmt, ...);
char *strdup_or_exit(const char *s);
#endif
0707010000000e000081a4000000000000000000000001689c3e8c00000788000000000000000000000000000000000000001d00000000wayback/common/wayback_log.c/*
 * Logging functions used by Xwayback and wayback-session.
 *
 * SPDX-License-Identifier: MIT
 */
#include "wayback_log.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static enum wayback_log_level logging_max_verbosity = LOG_INFO;
static char *logging_context = "wayback";
static bool logging_use_color = true;
static const char *log_colors[] = {
	[LOG_ERROR] = "\x1b[1;31m",
	[LOG_WARN] = "\x1b[1;33m",
	[LOG_INFO] = "\x1b[1;37m",
	[LOG_DEBUG] = "\x1b[1;39m]",
};
static const char *log_prefix[] = {
	[LOG_ERROR] = "[ERROR]",
	[LOG_WARN] = "[WARN]",
	[LOG_INFO] = "[INFO]",
	[LOG_DEBUG] = "[DEBUG]",
};
static void default_log_func(enum wayback_log_level verbosity, const char *fmt, va_list args)
{
	if (verbosity > logging_max_verbosity)
		return;
	unsigned verbosity_lvl = (verbosity < LOG_LAST) ? verbosity : LOG_LAST - 1;
	if (logging_use_color)
		fprintf(stderr, "%s", log_colors[verbosity_lvl]);
	fprintf(stderr, "%s (%s): ", log_prefix[verbosity_lvl], logging_context);
	vfprintf(stderr, fmt, args);
	if (logging_use_color)
		fprintf(stderr, "\x1b[0m");
	fprintf(stderr, "\n");
}
static wayback_log_func_t logging_func = default_log_func;
void wayback_log_init(char *ctx,
                      enum wayback_log_level max_verbosity,
                      wayback_log_func_t log_function)
{
	if (ctx)
		logging_context = ctx;
	logging_max_verbosity = max_verbosity;
	if (log_function)
		logging_func = log_function;
	char *no_color = getenv("NO_COLOR");
	if ((no_color != NULL && no_color[0] != '\0') || !isatty(STDERR_FILENO))
		logging_use_color = false;
}
void wayback_vlog(enum wayback_log_level verbosity, const char *format, va_list args)
{
	logging_func(verbosity, format, args);
}
void wayback_log(enum wayback_log_level verbosity, const char *format, ...)
{
	va_list args;
	va_start(args, format);
	logging_func(verbosity, format, args);
	va_end(args);
}
0707010000000f000081a4000000000000000000000001689c3e8c000002af000000000000000000000000000000000000001d00000000wayback/common/wayback_log.h/*
 * Logging functions used by all wayback executables.
 *
 * SPDX-License-Identifier: MIT
 */
#ifndef WAYBACK_LOG_IMPORTED
#define WAYBACK_LOG_IMPORTED
#include <stdarg.h>
enum wayback_log_level
{
	LOG_ERROR,
	LOG_WARN,
	LOG_INFO,
	LOG_DEBUG,
	LOG_LAST,
};
typedef void (*wayback_log_func_t)(enum wayback_log_level verbosity, const char *fmt, va_list args);
void wayback_log_init(char *ctx,
                      enum wayback_log_level max_verbosity,
                      wayback_log_func_t log_function);
void wayback_vlog(enum wayback_log_level verbosity, const char *format, va_list args);
void wayback_log(enum wayback_log_level verbosity, const char *format, ...);
#endif
07070100000010000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000000f00000000wayback/common07070100000011000081a4000000000000000000000001689c3e8c000002e1000000000000000000000000000000000000001b00000000wayback/doc/Xwayback.scdocXwayback(1)
# NAME
Xwayback - experimental X11 compatibility layer
# SYNOPSIS
*Xwayback* :_display_ _args_
# DESCRIPTION
*Xwayback* is a stub X server that uses a wayland compositor to launch Xwayland.
# OPTIONS
*Xwayback* accepts all flags *Xorg*(1) accepts.  However, some options are stubs.
Additionally, *Xwayback* supports the following:
	*-help*
		Show help page
	*-version*, *-showconfig*
		Show Xwayback version
# ENVVARS
	*WAYBACK_COMPOSITOR_PATH*
		Path to wayback-compositor
	*XWAYLAND_PATH*
		Path to Xwayland
	*WAYBACK_OUTPUT*
		The output to use, either in the format "<Make> <model>" or the display ID (i.e. "eDP-1")
# LICENSE
MIT
# SEE ALSO
*wayback-session*(1), *Xserver*(1), *Xorg*(1), *Xwayland*(1)
07070100000012000081a4000000000000000000000001689c3e8c000001fc000000000000000000000000000000000000001800000000wayback/doc/meson.buildscdoc = find_program('scdoc', required: get_option('generate_manpages'))
if scdoc.found()
  sh = find_program('sh')
  manpages = [
    ['wayback-session.scdoc', 'wayback-session.1'],
    ['Xwayback.scdoc', 'Xwayback.1'],
  ]
  foreach mp : manpages
    custom_target(
      mp[1],
      input: mp[0],
      output: mp[1],
      command: [sh, '-c', '@0@ < @INPUT@ > doc/@1@'.format(scdoc.full_path(), mp[1])],
      install: true,
      install_dir: get_option('mandir') / 'man1',
    )
  endforeach
endif
07070100000013000081a4000000000000000000000001689c3e8c00001214000000000000000000000000000000000000001d00000000wayback/doc/wayback-logo.svg<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
   width="512"
   height="512"
   viewBox="0 0 135.46666 135.46666"
   version="1.1"
   id="svg1"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <defs
     id="defs1">
    <linearGradient
       xlink:href="#linearGradient9"
       id="linearGradient63"
       gradientUnits="userSpaceOnUse"
       gradientTransform="matrix(2.1247805,0,0,1.4275465,-721.53751,-12.860029)"
       x1="331.58279"
       y1="168.63536"
       x2="511.59854"
       y2="171.54459" />
    <linearGradient
       id="linearGradient9">
      <stop
         style="stop-color:#ee591f;stop-opacity:1;"
         offset="0"
         id="stop9" />
      <stop
         style="stop-color:#fcb74e;stop-opacity:1;"
         offset="1"
         id="stop10" />
    </linearGradient>
    <linearGradient
       xlink:href="#linearGradient9"
       id="linearGradient1"
       gradientUnits="userSpaceOnUse"
       gradientTransform="matrix(2.1247805,0,0,1.4275465,-721.53751,-12.860029)"
       x1="331.58279"
       y1="168.63536"
       x2="511.59854"
       y2="171.54459" />
  </defs>
  <rect
     style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.017569;stroke-linecap:round;stroke-linejoin:round"
     id="rect58"
     width="16.149132"
     height="78.953194"
     x="58.267956"
     y="32.490822"
     transform="matrix(1,0,0.22357505,0.97468672,0,0)" />
  <rect
     style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.837008;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none"
     id="rect60"
     width="16.149132"
     height="83.662743"
     x="13.327144"
     y="27.46187"
     transform="matrix(1,0,0.21098955,0.97748832,0,0)" />
  <rect
     style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0209795;stroke-linecap:round;stroke-linejoin:round"
     id="rect61"
     width="7.4329948"
     height="84.141685"
     x="118.19677"
     y="27.619078"
     transform="matrix(1,0,-0.23529348,0.97192437,0,0)" />
  <rect
     style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0209795;stroke-linecap:round;stroke-linejoin:round"
     id="rect62"
     width="7.4329948"
     height="84.141685"
     x="71.785988"
     y="27.61908"
     transform="matrix(1,0,-0.23529348,0.97192437,0,0)" />
  <rect
     style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0180854;stroke-linecap:round;stroke-linejoin:round"
     id="rect63"
     width="16.149132"
     height="83.662743"
     x="59.737923"
     y="27.46187"
     transform="matrix(1,0,0.21098955,0.97748832,0,0)" />
  <path
     id="path63"
     style="fill:url(#linearGradient63);fill-opacity:1;stroke-width:3.48322;stroke-linecap:round;stroke-linejoin:round"
     d="M 373.38271,216.0462 C 373.38284,144.66151 280.84082,89.457789 174.59085,89.457886 68.340885,89.457792 -25.625444,144.66151 -25.6253,216.0462 l 43.843042,0.66625 c -1.45e-4,-65.39399 67.25743,-114.50128 156.373108,-114.50108 89.11526,2.4e-4 180.58535,48.44114 180.5852,113.83483"
     transform="matrix(0.27850317,0,0,0.27850317,19.307561,10.680935)" />
  <path
     id="path59"
     style="fill:url(#linearGradient1);fill-opacity:1;stroke-width:3.48322;stroke-linecap:round;stroke-linejoin:round"
     d="M 174.59085,89.457886 C 68.340885,89.457792 -25.625444,144.66151 -25.6253,216.0462 c -1.3e-4,71.38467 93.966199,129.2534 200.21615,129.2533 106.24996,10e-5 198.79198,-57.86863 198.79186,-129.2533 1.3e-4,-71.38469 -92.54189,-126.588411 -198.79186,-126.588314 z m 0,12.753484 c 89.11526,2.4e-4 180.58535,48.44114 180.5852,113.83483 1.3e-4,65.39369 -91.46994,109.0783 -180.5852,109.07854 -89.115678,2e-4 -156.373238,-43.01829 -156.373108,-108.41229 -1.45e-4,-65.39399 67.25743,-114.50128 156.373108,-114.50108 z"
     transform="matrix(0.27850317,0,0,0.27850317,19.307561,10.680935)" />
  <path
     id="rect2"
     style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.837008;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none"
     d="M 13.327107 27.462057 L 13.327243 71.537954 L 29.476129 71.537954 L 29.475992 27.462057 L 13.327107 27.462057 z "
     transform="matrix(1,0,0.21098955,0.97748832,0,0)" />
  <path
     id="rect3"
     style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0209795;stroke-linecap:round;stroke-linejoin:round"
     d="M 118.19673 27.619268 L 118.19701 71.947486 L 125.62963 71.947486 L 125.62986 27.619268 L 118.19673 27.619268 z "
     transform="matrix(1,0,-0.23529348,0.97192437,0,0)" />
</svg>
07070100000014000081a4000000000000000000000001689c3e8c000003b2000000000000000000000000000000000000002200000000wayback/doc/wayback-session.scdocwayback-session(1)
# NAME
wayback-session - session launcher for *Xwayback*(1)
# SYNOPSIS
*wayback-session* _-sesscmd sessioncmd_ _args_
# DESCRIPTION
*wayback-session* is a session launcher using *Xwayback*(1).
Its behaviour is similiar to that of *startx*(1), and the same xinitrc files are used.
# OPTIONS
*wayback-session* optionally takes the command to launch a session.
If no command is specified it will try to launch ~/.xinitrc.
If ~/.xinitrc is not found, it will launch /etc/X11/xinit/xinitrc.
	*-help*
		Show help page
	*-sesscmd*
		Path to session command
	*-version*, *-showconfig*
		Show wayback-session version
# ENVVARS
	*XWAYBACK_PATH*
		Path to Xwayback
For other supported environment variables, see *Xwayback*(1) (section *ENVVARS*).
# FUTURE DIRECTIONS
This command will be deprecated and replaced by *xinit*(1) in the future.
# LICENSE
MIT
# SEE ALSO
*Xwayback*(1), *startx*(1), *Xserver*(1), *Xorg*(1)
07070100000015000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000000c00000000wayback/doc07070100000016000081a4000000000000000000000001689c3e8c0000057b000000000000000000000000000000000000001400000000wayback/meson.buildproject('wayback', 'c',
  version: '0.2',
  license: 'MIT',
  meson_version: '>= 1.4.0',
  default_options: [
    'c_std=gnu23',
    'warning_level=3',
  ])
cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments(['-Wno-unused-parameter']), language: 'c')
add_project_arguments('-DWLR_USE_UNSTABLE', language: 'c')
add_global_arguments('-DWAYBACK_COMPOSITOR_EXEC_PATH="@0@/wayback-compositor"'.format(get_option('prefix') /get_option('libexecdir')), language : 'c')
add_global_arguments('-DWAYBACK_VERSION="@0@"'.format(meson.project_version()), language : 'c')
wayland_server = dependency('wayland-server')
wayland_client = dependency('wayland-client')
wayland_cursor = dependency('wayland-cursor')
wayland_egl    = dependency('wayland-egl')
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
xkbcommon      = dependency('xkbcommon')
xwayland       = dependency('xwayland', version: '>=24.1')
wlroots        = dependency('wlroots-0.19', version: '>=0.19', required: false)
if not wlroots.found()
  wlroots = dependency('wlroots-0.18', version: '>=0.18')
endif
xwayland_executable_path = xwayland.get_variable(pkgconfig: 'xwayland')
add_global_arguments('-DXWAYLAND_EXEC_PATH="@0@"'.format(xwayland_executable_path), language : 'c')
subdir('common')
subdir('protocol')
subdir('wayback-compositor')
subdir('wayback-session')
subdir('xwayback')
subdir('doc')
07070100000017000081a4000000000000000000000001689c3e8c00000071000000000000000000000000000000000000001a00000000wayback/meson_options.txtoption('generate_manpages', type : 'feature', value : 'enabled', description : 'Generate and install man pages')
07070100000018000081a4000000000000000000000001689c3e8c00000845000000000000000000000000000000000000001d00000000wayback/protocol/meson.buildwayland_protos_inc = include_directories('.')
wl_protocol_dir = wayland_protos.get_variable(pkgconfig: 'pkgdatadir')
wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
if wayland_scanner_dep.found()
	wayland_scanner = find_program(
		wayland_scanner_dep.get_variable(pkgconfig: 'wayland_scanner'),
		native: true,
	)
else
	wayland_scanner = find_program('wayland-scanner', native: true)
endif
protocols = [
	[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
]
client_protocols = [
	[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
	[wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'],
]
wl_protos_src = []
wl_protos_headers = []
foreach p : protocols
	xml = join_paths(p)
	wl_protos_src += custom_target(
		xml.underscorify() + '_server_c',
		input: xml,
		output: '@BASENAME@-protocol.c',
		command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
	)
	wl_protos_headers += custom_target(
		xml.underscorify() + '_server_h',
		input: xml,
		output: '@BASENAME@-protocol.h',
		command: [wayland_scanner, 'server-header', '@INPUT@', '@OUTPUT@'],
	)
endforeach
foreach p : client_protocols
	xml = join_paths(p)
	wl_protos_src += custom_target(
		xml.underscorify() + '_client_c',
		input: xml,
		output: '@BASENAME@-client-protocol.c',
		command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
	)
	wl_protos_headers += custom_target(
		xml.underscorify() + '_client_h',
		input: xml,
		output: '@BASENAME@-client-protocol.h',
		command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
	)
endforeach
lib_client_protos = static_library(
	'client_protos',
	wl_protos_src + wl_protos_headers,
	dependencies: wayland_client.partial_dependency(compile_args: true),
)
client_protos = declare_dependency(
	link_with: lib_client_protos,
	sources: wl_protos_headers,
)
lib_server_protos = static_library(
	'server_protos',
	wl_protos_src + wl_protos_headers,
	dependencies: wayland_server.partial_dependency(compile_args: true),
)
server_protos = declare_dependency(
	link_with: lib_server_protos,
	sources: wl_protos_headers,
)
07070100000019000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000001100000000wayback/protocol0707010000001a000081a4000000000000000000000001689c3e8c00000101000000000000000000000000000000000000002700000000wayback/wayback-compositor/meson.buildexecutable(
	'wayback-compositor',
	['wayback-compositor.c'],
	dependencies: [wayland_server, wayland_client, wayland_cursor, wayland_egl, wayland_protos, wlroots, xkbcommon, server_protos, shared],
	install: true,
	install_dir: get_option('libexecdir'),
)
0707010000001b000081a4000000000000000000000001689c3e8c00009c50000000000000000000000000000000000000003000000000wayback/wayback-compositor/wayback-compositor.c/*
 * Wayback is essentially the tinywl compositor included in wlroots
 * but stripped down to only support an X session.
 *
 * SPDX-License-Identifier: MIT
 */
#include "utils.h"
#include "wayback_log.h"
#include <assert.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/multi.h>
#include <wlr/backend/session.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
/* For brevity's sake, struct members are annotated where they are used. */
struct tinywl_server
{
	struct wl_display *wl_display;
	struct wlr_backend *backend;
	struct wlr_renderer *renderer;
	struct wlr_allocator *allocator;
	struct wlr_session *session;
	struct wlr_scene *scene;
	struct wlr_scene_output_layout *scene_layout;
	struct wlr_xdg_shell *xdg_shell;
	struct wl_listener new_xdg_toplevel;
	struct wl_listener new_xdg_popup;
	struct wl_list toplevels;
	struct wlr_xdg_output_manager_v1 *xdg_output_manager_v1;
	struct wlr_cursor *cursor;
	struct wlr_xcursor_manager *cursor_mgr;
	struct wl_listener cursor_motion;
	struct wl_listener cursor_motion_absolute;
	struct wl_listener cursor_button;
	struct wl_listener cursor_axis;
	struct wl_listener cursor_frame;
	struct wlr_seat *seat;
	struct wl_listener new_input;
	struct wl_listener request_cursor;
	struct wl_listener request_set_selection;
	struct wl_list keyboards;
	struct tinywl_toplevel *grabbed_toplevel;
	double grab_x, grab_y;
	struct wlr_box grab_geobox;
	uint32_t resize_edges;
	struct wlr_output_layout *output_layout;
	struct wl_list outputs;
	struct wl_listener new_output;
	int width, height;
};
struct tinywl_output
{
	struct wl_list link;
	struct tinywl_server *server;
	struct wlr_output *wlr_output;
	struct wl_listener frame;
	struct wl_listener request_state;
	struct wl_listener destroy;
};
struct tinywl_toplevel
{
	struct wl_list link;
	struct tinywl_server *server;
	struct wlr_xdg_toplevel *xdg_toplevel;
	struct wlr_scene_tree *scene_tree;
	struct wl_listener map;
	struct wl_listener unmap;
	struct wl_listener commit;
	struct wl_listener destroy;
	struct wl_listener request_maximize;
	struct wl_listener request_fullscreen;
};
struct tinywl_popup
{
	struct wlr_xdg_popup *xdg_popup;
	struct wl_listener commit;
	struct wl_listener destroy;
};
struct tinywl_keyboard
{
	struct wl_list link;
	struct tinywl_server *server;
	struct wlr_keyboard *wlr_keyboard;
	struct wl_listener modifiers;
	struct wl_listener key;
	struct wl_listener destroy;
};
struct wayback_client
{
	struct tinywl_server *server;
	struct wl_listener destroy;
};
static void keyboard_handle_modifiers(struct wl_listener *listener, void *data)
{
	/* This event is raised when a modifier key, such as shift or alt, is
	 * pressed. We simply communicate this to the client. */
	struct tinywl_keyboard *keyboard = wl_container_of(listener, keyboard, modifiers);
	/*
	 * A seat can only have one keyboard, but this is a limitation of the
	 * Wayland protocol - not wlroots. We assign all connected keyboards to the
	 * same seat. You can swap out the underlying wlr_keyboard like this and
	 * wlr_seat handles this transparently.
	 */
	wlr_seat_set_keyboard(keyboard->server->seat, keyboard->wlr_keyboard);
	/* Send modifiers to the client. */
	wlr_seat_keyboard_notify_modifiers(keyboard->server->seat, &keyboard->wlr_keyboard->modifiers);
}
static bool handle_keybinding(struct tinywl_server *server, xkb_keysym_t sym)
{
	/*
	 * Here we handle compositor keybindings. This is when the compositor is
	 * processing keys, rather than passing them on to the client for its own
	 * processing.
	 *
	 * This function assumes Ctrl and Alt are held down.
	 */
	if (sym == XKB_KEY_BackSpace) {
		wl_display_terminate(server->wl_display);
	} else if (sym >= XKB_KEY_XF86Switch_VT_1 && sym <= XKB_KEY_XF86Switch_VT_12) {
		if (wlr_backend_is_multi(server->backend) && server->session) {
			unsigned int vt = sym - XKB_KEY_XF86Switch_VT_1 + 1;
			wlr_session_change_vt(server->session, vt);
		}
	} else {
		return false;
	}
	return true;
}
static void keyboard_handle_key(struct wl_listener *listener, void *data)
{
	/* This event is raised when a key is pressed or released. */
	struct tinywl_keyboard *keyboard = wl_container_of(listener, keyboard, key);
	struct tinywl_server *server = keyboard->server;
	struct wlr_keyboard_key_event *event = data;
	struct wlr_seat *seat = server->seat;
	/* Translate libinput keycode -> xkbcommon */
	uint32_t keycode = event->keycode + 8;
	/* Get a list of keysyms based on the keymap for this keyboard */
	const xkb_keysym_t *syms;
	int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms);
	bool handled = false;
	uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->wlr_keyboard);
	if ((modifiers & WLR_MODIFIER_ALT && modifiers & WLR_MODIFIER_CTRL) &&
	    event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
		/* If alt is held down and this button was _pressed_, we attempt to
		 * process it as a compositor keybinding. */
		for (int i = 0; i < nsyms; i++) {
			handled = handle_keybinding(server, syms[i]);
			if (handled)
				break;
		}
	}
	if (!handled) {
		/* Otherwise, we pass it along to the client. */
		wlr_seat_set_keyboard(seat, keyboard->wlr_keyboard);
		wlr_seat_keyboard_notify_key(seat, event->time_msec, event->keycode, event->state);
	}
}
static void keyboard_handle_destroy(struct wl_listener *listener, void *data)
{
	/* This event is raised by the keyboard base wlr_input_device to signal
	 * the destruction of the wlr_keyboard. It will no longer receive events
	 * and should be destroyed.
	 */
	struct tinywl_keyboard *keyboard = wl_container_of(listener, keyboard, destroy);
	wl_list_remove(&keyboard->modifiers.link);
	wl_list_remove(&keyboard->key.link);
	wl_list_remove(&keyboard->destroy.link);
	wl_list_remove(&keyboard->link);
	free(keyboard);
}
static void server_new_keyboard(struct tinywl_server *server, struct wlr_input_device *device)
{
	struct wlr_keyboard *wlr_keyboard = wlr_keyboard_from_input_device(device);
	struct tinywl_keyboard *keyboard = calloc(1, sizeof(*keyboard));
	keyboard->server = server;
	keyboard->wlr_keyboard = wlr_keyboard;
	/* We need to prepare an XKB keymap and assign it to the keyboard. This
	 * assumes the defaults (e.g. layout = "us"). */
	struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
	struct xkb_keymap *keymap =
		xkb_keymap_new_from_names(context, NULL, XKB_KEYMAP_COMPILE_NO_FLAGS);
	wlr_keyboard_set_keymap(wlr_keyboard, keymap);
	xkb_keymap_unref(keymap);
	xkb_context_unref(context);
	wlr_keyboard_set_repeat_info(wlr_keyboard, 25, 600);
	/* Here we set up listeners for keyboard events. */
	keyboard->modifiers.notify = keyboard_handle_modifiers;
	wl_signal_add(&wlr_keyboard->events.modifiers, &keyboard->modifiers);
	keyboard->key.notify = keyboard_handle_key;
	wl_signal_add(&wlr_keyboard->events.key, &keyboard->key);
	keyboard->destroy.notify = keyboard_handle_destroy;
	wl_signal_add(&device->events.destroy, &keyboard->destroy);
	wlr_seat_set_keyboard(server->seat, keyboard->wlr_keyboard);
	/* And add the keyboard to our list of keyboards */
	wl_list_insert(&server->keyboards, &keyboard->link);
}
static void server_new_pointer(struct tinywl_server *server, struct wlr_input_device *device)
{
	/* We don't do anything special with pointers. All of our pointer handling
	 * is proxied through wlr_cursor. On another compositor, you might take this
	 * opportunity to do libinput configuration on the device to set
	 * acceleration, etc. */
	wlr_cursor_attach_input_device(server->cursor, device);
}
static void server_new_input(struct wl_listener *listener, void *data)
{
	/* This event is raised by the backend when a new input device becomes
	 * available. */
	struct tinywl_server *server = wl_container_of(listener, server, new_input);
	struct wlr_input_device *device = data;
	switch (device->type) {
		case WLR_INPUT_DEVICE_KEYBOARD:
			server_new_keyboard(server, device);
			break;
		case WLR_INPUT_DEVICE_POINTER:
			server_new_pointer(server, device);
			break;
		default:
			break;
	}
	/* We need to let the wlr_seat know what our capabilities are, which is
	 * communiciated to the client. In TinyWL we always have a cursor, even if
	 * there are no pointer devices, so we always include that capability. */
	uint32_t caps = WL_SEAT_CAPABILITY_POINTER;
	if (!wl_list_empty(&server->keyboards)) {
		caps |= WL_SEAT_CAPABILITY_KEYBOARD;
	}
	wlr_seat_set_capabilities(server->seat, caps);
}
static void seat_request_cursor(struct wl_listener *listener, void *data)
{
	struct tinywl_server *server = wl_container_of(listener, server, request_cursor);
	/* This event is raised by the seat when a client provides a cursor image */
	struct wlr_seat_pointer_request_set_cursor_event *event = data;
	struct wlr_seat_client *focused_client = server->seat->pointer_state.focused_client;
	/* This can be sent by any client, so we check to make sure this one is
	 * actually has pointer focus first. */
	if (focused_client == event->seat_client) {
		/* Once we've vetted the client, we can tell the cursor to use the
		 * provided surface as the cursor image. It will set the hardware cursor
		 * on the output that it's currently on and continue to do so as the
		 * cursor moves between outputs. */
		wlr_cursor_set_surface(server->cursor, event->surface, event->hotspot_x, event->hotspot_y);
	}
}
static void seat_request_set_selection(struct wl_listener *listener, void *data)
{
	/* This event is raised by the seat when a client wants to set the selection,
	 * usually when the user copies something. wlroots allows compositors to
	 * ignore such requests if they so choose, but in tinywl we always honor
	 */
	struct tinywl_server *server = wl_container_of(listener, server, request_set_selection);
	struct wlr_seat_request_set_selection_event *event = data;
	wlr_seat_set_selection(server->seat, event->source, event->serial);
}
static void client_destroy(struct wl_listener *listener, void *data)
{
	struct wayback_client *client = wl_container_of(listener, client, destroy);
	wl_display_terminate(client->server->wl_display);
}
static struct tinywl_toplevel *desktop_toplevel_at(struct tinywl_server *server,
                                                   double lx,
                                                   double ly,
                                                   struct wlr_surface **surface,
                                                   double *sx,
                                                   double *sy)
{
	/* This returns the topmost node in the scene at the given layout coords.
	 * We only care about surface nodes as we are specifically looking for a
	 * surface in the surface tree of a tinywl_toplevel. */
	struct wlr_scene_node *node = wlr_scene_node_at(&server->scene->tree.node, lx, ly, sx, sy);
	if (node == NULL || node->type != WLR_SCENE_NODE_BUFFER) {
		return NULL;
	}
	struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
	struct wlr_scene_surface *scene_surface = wlr_scene_surface_try_from_buffer(scene_buffer);
	if (!scene_surface) {
		return NULL;
	}
	*surface = scene_surface->surface;
	/* Find the node corresponding to the tinywl_toplevel at the root of this
	 * surface tree, it is the only one for which we set the data field. */
	struct wlr_scene_tree *tree = node->parent;
	while (tree != NULL && tree->node.data == NULL) {
		tree = tree->node.parent;
	}
	return tree->node.data;
}
static void process_cursor_motion(struct tinywl_server *server, uint32_t time)
{
	/* Otherwise, find the toplevel under the pointer and send the event along. */
	double sx, sy;
	struct wlr_seat *seat = server->seat;
	struct wlr_surface *surface = NULL;
	struct tinywl_toplevel *toplevel =
		desktop_toplevel_at(server, server->cursor->x, server->cursor->y, &surface, &sx, &sy);
	if (!toplevel) {
		/* If there's no toplevel under the cursor, set the cursor image to a
		 * default. This is what makes the cursor image appear when you move it
		 * around the screen, not over any toplevels. */
		wlr_cursor_set_xcursor(server->cursor, server->cursor_mgr, "default");
	}
	if (surface) {
		/*
		 * Send pointer enter and motion events.
		 *
		 * The enter event gives the surface "pointer focus", which is distinct
		 * from keyboard focus. You get pointer focus by moving the pointer over
		 * a window.
		 *
		 * Note that wlroots will avoid sending duplicate enter/motion events if
		 * the surface has already has pointer focus or if the client is already
		 * aware of the coordinates passed.
		 */
		wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
		wlr_seat_pointer_notify_motion(seat, time, sx, sy);
	} else {
		/* Clear pointer focus so future button events and such are not sent to
		 * the last client to have the cursor over it. */
		wlr_seat_pointer_clear_focus(seat);
	}
}
static void server_cursor_motion(struct wl_listener *listener, void *data)
{
	/* This event is forwarded by the cursor when a pointer emits a _relative_
	 * pointer motion event (i.e. a delta) */
	struct tinywl_server *server = wl_container_of(listener, server, cursor_motion);
	struct wlr_pointer_motion_event *event = data;
	/* The cursor doesn't move unless we tell it to. The cursor automatically
	 * handles constraining the motion to the output layout, as well as any
	 * special configuration applied for the specific input device which
	 * generated the event. You can pass NULL for the device if you want to move
	 * the cursor around without any input. */
	wlr_cursor_move(server->cursor, &event->pointer->base, event->delta_x, event->delta_y);
	process_cursor_motion(server, event->time_msec);
}
static void server_cursor_motion_absolute(struct wl_listener *listener, void *data)
{
	/* This event is forwarded by the cursor when a pointer emits an _absolute_
	 * motion event, from 0..1 on each axis. This happens, for example, when
	 * wlroots is running under a Wayland window rather than KMS+DRM, and you
	 * move the mouse over the window. You could enter the window from any edge,
	 * so we have to warp the mouse there. There is also some hardware which
	 * emits these events. */
	struct tinywl_server *server = wl_container_of(listener, server, cursor_motion_absolute);
	struct wlr_pointer_motion_absolute_event *event = data;
	wlr_cursor_warp_absolute(server->cursor, &event->pointer->base, event->x, event->y);
	process_cursor_motion(server, event->time_msec);
}
static void server_cursor_button(struct wl_listener *listener, void *data)
{
	/* This event is forwarded by the cursor when a pointer emits a button
	 * event. */
	struct tinywl_server *server = wl_container_of(listener, server, cursor_button);
	struct wlr_pointer_button_event *event = data;
	/* Notify the client with pointer focus that a button press has occurred */
	wlr_seat_pointer_notify_button(server->seat, event->time_msec, event->button, event->state);
}
static void server_cursor_axis(struct wl_listener *listener, void *data)
{
	/* This event is forwarded by the cursor when a pointer emits an axis event,
	 * for example when you move the scroll wheel. */
	struct tinywl_server *server = wl_container_of(listener, server, cursor_axis);
	struct wlr_pointer_axis_event *event = data;
	/* Notify the client with pointer focus of the axis event. */
	wlr_seat_pointer_notify_axis(server->seat,
	                             event->time_msec,
	                             event->orientation,
	                             event->delta,
	                             event->delta_discrete,
	                             event->source,
	                             event->relative_direction);
}
static void server_cursor_frame(struct wl_listener *listener, void *data)
{
	/* This event is forwarded by the cursor when a pointer emits an frame
	 * event. Frame events are sent after regular pointer events to group
	 * multiple events together. For instance, two axis events may happen at the
	 * same time, in which case a frame event won't be sent in between. */
	struct tinywl_server *server = wl_container_of(listener, server, cursor_frame);
	/* Notify the client with pointer focus of the frame event. */
	wlr_seat_pointer_notify_frame(server->seat);
}
static void output_frame(struct wl_listener *listener, void *data)
{
	/* This function is called every time an output is ready to display a frame,
	 * generally at the output's refresh rate (e.g. 60Hz). */
	struct tinywl_output *output = wl_container_of(listener, output, frame);
	struct wlr_scene *scene = output->server->scene;
	struct wlr_scene_output *scene_output = wlr_scene_get_scene_output(scene, output->wlr_output);
	/* Render the scene if needed and commit the output */
	wlr_scene_output_commit(scene_output, NULL);
	struct timespec now;
	clock_gettime(CLOCK_MONOTONIC, &now);
	wlr_scene_output_send_frame_done(scene_output, &now);
}
static void output_request_state(struct wl_listener *listener, void *data)
{
	/* This function is called when the backend requests a new state for
	 * the output. For example, Wayland and X11 backends request a new mode
	 * when the output window is resized. */
	struct tinywl_output *output = wl_container_of(listener, output, request_state);
	const struct wlr_output_event_request_state *event = data;
	wlr_output_commit_state(output->wlr_output, event->state);
}
static void output_destroy(struct wl_listener *listener, void *data)
{
	struct tinywl_output *output = wl_container_of(listener, output, destroy);
	wl_list_remove(&output->frame.link);
	wl_list_remove(&output->request_state.link);
	wl_list_remove(&output->destroy.link);
	wl_list_remove(&output->link);
	free(output);
}
static void server_new_output(struct wl_listener *listener, void *data)
{
	/* This event is raised by the backend when a new output (aka a display or
	 * monitor) becomes available. */
	struct tinywl_server *server = wl_container_of(listener, server, new_output);
	struct wlr_output *wlr_output = data;
	/* Configures the output created by the backend to use our allocator
	 * and our renderer. Must be done once, before commiting the output */
	wlr_output_init_render(wlr_output, server->allocator, server->renderer);
	/* The output may be disabled, switch it on. */
	struct wlr_output_state state;
	wlr_output_state_init(&state);
	wlr_output_state_set_enabled(&state, true);
	/* Some backends don't have modes. DRM+KMS does, and we need to set a mode
	 * before we can use the output. The mode is a tuple of (width, height,
	 * refresh rate), and each monitor supports only a specific set of modes. We
	 * just pick the monitor's preferred mode, a more sophisticated compositor
	 * would let the user configure it. */
	struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
	if (mode != NULL) {
		wlr_output_state_set_mode(&state, mode);
	}
	/* Atomically applies the new output state. */
	wlr_output_commit_state(wlr_output, &state);
	wlr_output_state_finish(&state);
	/* Allocates and configures our state for this output */
	struct tinywl_output *output = calloc(1, sizeof(*output));
	output->wlr_output = wlr_output;
	output->server = server;
	/* Sets up a listener for the frame event. */
	output->frame.notify = output_frame;
	wl_signal_add(&wlr_output->events.frame, &output->frame);
	/* Sets up a listener for the state request event. */
	output->request_state.notify = output_request_state;
	wl_signal_add(&wlr_output->events.request_state, &output->request_state);
	/* Sets up a listener for the destroy event. */
	output->destroy.notify = output_destroy;
	wl_signal_add(&wlr_output->events.destroy, &output->destroy);
	wl_list_insert(&server->outputs, &output->link);
	/* Adds this to the output layout. The add_auto function arranges outputs
	 * from left-to-right in the order they appear. A more sophisticated
	 * compositor would let the user configure the arrangement of outputs in the
	 * layout.
	 *
	 * The output layout utility automatically adds a wl_output global to the
	 * display, which Wayland clients can see to find out information about the
	 * output (such as DPI, scale factor, manufacturer, etc).
	 */
	struct wlr_output_layout_output *l_output =
		wlr_output_layout_add_auto(server->output_layout, wlr_output);
	struct wlr_scene_output *scene_output = wlr_scene_output_create(server->scene, wlr_output);
	wlr_scene_output_layout_add_output(server->scene_layout, l_output, scene_output);
	int width, height;
	wlr_output_effective_resolution(wlr_output, &width, &height);
	/* XXX: this is definitely wrong, but whatever, it's good enough for now */
	server->width += width;
	server->height += height;
}
static void focus_toplevel(struct tinywl_toplevel *toplevel)
{
	/* Note: this function only deals with keyboard focus. */
	if (toplevel == NULL) {
		return;
	}
	struct tinywl_server *server = toplevel->server;
	struct wlr_seat *seat = server->seat;
	struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
	struct wlr_surface *surface = toplevel->xdg_toplevel->base->surface;
	if (prev_surface == surface) {
		/* Don't re-focus an already focused surface. */
		return;
	}
	if (prev_surface) {
		/*
		 * Deactivate the previously focused surface. This lets the client know
		 * it no longer has focus and the client will repaint accordingly, e.g.
		 * stop displaying a caret.
		 */
		struct wlr_xdg_toplevel *prev_toplevel =
			wlr_xdg_toplevel_try_from_wlr_surface(prev_surface);
		if (prev_toplevel != NULL) {
			wlr_xdg_toplevel_set_activated(prev_toplevel, false);
		}
	}
	struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
	/* Move the toplevel to the front */
	wlr_scene_node_raise_to_top(&toplevel->scene_tree->node);
	wl_list_remove(&toplevel->link);
	wl_list_insert(&server->toplevels, &toplevel->link);
	/* Activate the new surface */
	wlr_xdg_toplevel_set_activated(toplevel->xdg_toplevel, true);
	/*
	 * Tell the seat to have the keyboard enter this surface. wlroots will keep
	 * track of this and automatically send key events to the appropriate
	 * clients without additional work on your part.
	 */
	if (keyboard != NULL) {
		wlr_seat_keyboard_notify_enter(
			seat, surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
	}
}
static void xdg_toplevel_map(struct wl_listener *listener, void *data)
{
	/* Called when the surface is mapped, or ready to display on-screen. */
	struct tinywl_toplevel *toplevel = wl_container_of(listener, toplevel, map);
	wl_list_insert(&toplevel->server->toplevels, &toplevel->link);
	focus_toplevel(toplevel);
}
static void xdg_toplevel_unmap(struct wl_listener *listener, void *data)
{
	/* Called when the surface is unmapped, and should no longer be shown. */
	struct tinywl_toplevel *toplevel = wl_container_of(listener, toplevel, unmap);
	wl_list_remove(&toplevel->link);
}
static void xdg_toplevel_commit(struct wl_listener *listener, void *data)
{
	/* Called when a new surface state is committed. */
	struct tinywl_toplevel *toplevel = wl_container_of(listener, toplevel, commit);
	if (toplevel->xdg_toplevel->base->initial_commit) {
		/* When an xdg_surface performs an initial commit, the compositor must
		 * reply with a configure so the client can map the surface. tinywl
		 * configures the xdg_toplevel with 0,0 size to let the client pick the
		 * dimensions itself. */
		wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, 0, 0);
	}
}
static void xdg_toplevel_destroy(struct wl_listener *listener, void *data)
{
	/* Called when the xdg_toplevel is destroyed. */
	struct tinywl_toplevel *toplevel = wl_container_of(listener, toplevel, destroy);
	wl_list_remove(&toplevel->map.link);
	wl_list_remove(&toplevel->unmap.link);
	wl_list_remove(&toplevel->commit.link);
	wl_list_remove(&toplevel->destroy.link);
	wl_list_remove(&toplevel->request_maximize.link);
	wl_list_remove(&toplevel->request_fullscreen.link);
	free(toplevel);
}
static void xdg_toplevel_request_maximize(struct wl_listener *listener, void *data)
{
	/* This event is raised when a client would like to maximize itself,
	 * typically because the user clicked on the maximize button on client-side
	 * decorations. tinywl doesn't support maximization, but to conform to
	 * xdg-shell protocol we still must send a configure.
	 * wlr_xdg_surface_schedule_configure() is used to send an empty reply.
	 * However, if the request was sent before an initial commit, we don't do
	 * anything and let the client finish the initial surface setup. */
	struct tinywl_toplevel *toplevel = wl_container_of(listener, toplevel, request_maximize);
	if (toplevel->xdg_toplevel->base->initialized) {
		wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base);
	}
}
static void xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data)
{
	/* Just as with request_maximize, we must send a configure here. */
	struct tinywl_toplevel *toplevel = wl_container_of(listener, toplevel, request_fullscreen);
	if (toplevel->xdg_toplevel->base->initialized) {
		wlr_xdg_surface_schedule_configure(toplevel->xdg_toplevel->base);
	}
}
static void server_new_xdg_toplevel(struct wl_listener *listener, void *data)
{
	/* This event is raised when a client creates a new toplevel (application window). */
	struct tinywl_server *server = wl_container_of(listener, server, new_xdg_toplevel);
	struct wlr_xdg_toplevel *xdg_toplevel = data;
	/* Allocate a tinywl_toplevel for this surface */
	struct tinywl_toplevel *toplevel = calloc(1, sizeof(*toplevel));
	toplevel->server = server;
	toplevel->xdg_toplevel = xdg_toplevel;
	toplevel->scene_tree =
		wlr_scene_xdg_surface_create(&toplevel->server->scene->tree, xdg_toplevel->base);
	toplevel->scene_tree->node.data = toplevel;
	xdg_toplevel->base->data = toplevel->scene_tree;
	/* Listen to the various events it can emit */
	toplevel->map.notify = xdg_toplevel_map;
	wl_signal_add(&xdg_toplevel->base->surface->events.map, &toplevel->map);
	toplevel->unmap.notify = xdg_toplevel_unmap;
	wl_signal_add(&xdg_toplevel->base->surface->events.unmap, &toplevel->unmap);
	toplevel->commit.notify = xdg_toplevel_commit;
	wl_signal_add(&xdg_toplevel->base->surface->events.commit, &toplevel->commit);
	toplevel->destroy.notify = xdg_toplevel_destroy;
	wl_signal_add(&xdg_toplevel->events.destroy, &toplevel->destroy);
	/* cotd */
	toplevel->request_maximize.notify = xdg_toplevel_request_maximize;
	wl_signal_add(&xdg_toplevel->events.request_maximize, &toplevel->request_maximize);
	toplevel->request_fullscreen.notify = xdg_toplevel_request_fullscreen;
	wl_signal_add(&xdg_toplevel->events.request_fullscreen, &toplevel->request_fullscreen);
}
static void xdg_popup_commit(struct wl_listener *listener, void *data)
{
	/* Called when a new surface state is committed. */
	struct tinywl_popup *popup = wl_container_of(listener, popup, commit);
	if (popup->xdg_popup->base->initial_commit) {
		/* When an xdg_surface performs an initial commit, the compositor must
		 * reply with a configure so the client can map the surface.
		 * tinywl sends an empty configure. A more sophisticated compositor
		 * might change an xdg_popup's geometry to ensure it's not positioned
		 * off-screen, for example. */
		wlr_xdg_surface_schedule_configure(popup->xdg_popup->base);
	}
}
static void xdg_popup_destroy(struct wl_listener *listener, void *data)
{
	/* Called when the xdg_popup is destroyed. */
	struct tinywl_popup *popup = wl_container_of(listener, popup, destroy);
	wl_list_remove(&popup->commit.link);
	wl_list_remove(&popup->destroy.link);
	free(popup);
}
static void server_new_xdg_popup(struct wl_listener *listener, void *data)
{
	/* This event is raised when a client creates a new popup. */
	struct wlr_xdg_popup *xdg_popup = data;
	struct tinywl_popup *popup = calloc(1, sizeof(*popup));
	popup->xdg_popup = xdg_popup;
	/* We must add xdg popups to the scene graph so they get rendered. The
	 * wlroots scene graph provides a helper for this, but to use it we must
	 * provide the proper parent scene node of the xdg popup. To enable this,
	 * we always set the user data field of xdg_surfaces to the corresponding
	 * scene node. */
	struct wlr_xdg_surface *parent = wlr_xdg_surface_try_from_wlr_surface(xdg_popup->parent);
	assert(parent != NULL);
	struct wlr_scene_tree *parent_tree = parent->data;
	xdg_popup->base->data = wlr_scene_xdg_surface_create(parent_tree, xdg_popup->base);
	popup->commit.notify = xdg_popup_commit;
	wl_signal_add(&xdg_popup->base->surface->events.commit, &popup->commit);
	popup->destroy.notify = xdg_popup_destroy;
	wl_signal_add(&xdg_popup->events.destroy, &popup->destroy);
}
int set_cloexec(int fd)
{
	int flags = fcntl(fd, F_GETFD);
	if (flags == -1)
		return -1;
	return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
}
static void wayback_wlr_vlog(enum wayback_log_level verbosity, const char *fmt, va_list args)
{
	static const enum wlr_log_importance importance_map[LOG_LAST] = {
		[LOG_ERROR] = WLR_ERROR,
		[LOG_WARN] = WLR_INFO, // There is no WLR_WARN
		[LOG_INFO] = WLR_INFO,
		[LOG_DEBUG] = WLR_DEBUG,
	};
	enum wayback_log_level verbosity_clamped = verbosity < LOG_LAST ? verbosity : LOG_LAST - 1;
	enum wlr_log_importance importance = importance_map[verbosity_clamped];
	// Not wlr_vlog here because we don't need file and line number. It will just point back here
	// anyway.
	_wlr_vlog(importance, fmt, args);
}
int main(int argc, char *argv[])
{
	wlr_log_init(WLR_DEBUG, NULL);
	wayback_log_init("wayback-compositor", LOG_INFO, wayback_wlr_vlog);
	if (argc < 3) {
		wayback_log(LOG_INFO,
		            "Wayback <https://wayback.freedesktop.org/> X.Org compatibility layer");
		wayback_log(LOG_INFO, "Version %s", WAYBACK_VERSION);
		wayback_log(LOG_INFO, "Usage: %s <socket xwayback> <socket xwayland>", argv[0]);
		exit(EXIT_FAILURE);
	}
	int xwayback_session_socket = atoi(argv[1]);
	int xwayland_session_socket = atoi(argv[2]);
	struct tinywl_server server = { 0 };
	/* The Wayland display is managed by libwayland. It handles accepting
	 * clients from the Unix socket, manging Wayland globals, and so on. */
	server.wl_display = wl_display_create();
	/* The backend is a wlroots feature which abstracts the underlying input and
	 * output hardware. The autocreate option will choose the most suitable
	 * backend based on the current environment, such as opening an X11 window
	 * if an X11 server is running. */
	server.backend =
		wlr_backend_autocreate(wl_display_get_event_loop(server.wl_display), &server.session);
	if (server.backend == NULL) {
		wlr_log(WLR_ERROR, "failed to create wlr_backend");
		return 1;
	}
	/* Autocreates a renderer, either Pixman, GLES2 or Vulkan for us. The user
	 * can also specify a renderer using the WLR_RENDERER env var.
	 * The renderer is responsible for defining the various pixel formats it
	 * supports for shared memory, this configures that for clients. */
	server.renderer = wlr_renderer_autocreate(server.backend);
	if (server.renderer == NULL) {
		wlr_log(WLR_ERROR, "failed to create wlr_renderer");
		return 1;
	}
	wlr_renderer_init_wl_display(server.renderer, server.wl_display);
	/* Autocreates an allocator for us.
	 * The allocator is the bridge between the renderer and the backend. It
	 * handles the buffer creation, allowing wlroots to render onto the
	 * screen */
	server.allocator = wlr_allocator_autocreate(server.backend, server.renderer);
	if (server.allocator == NULL) {
		wlr_log(WLR_ERROR, "failed to create wlr_allocator");
		return 1;
	}
	/* This creates some hands-off wlroots interfaces. The compositor is
	 * necessary for clients to allocate surfaces, the subcompositor allows to
	 * assign the role of subsurfaces to surfaces and the data device manager
	 * handles the clipboard. Each of these wlroots interfaces has room for you
	 * to dig your fingers in and play with their behavior if you want. Note that
	 * the clients cannot set the selection directly without compositor approval,
	 * see the handling of the request_set_selection event below.*/
	wlr_compositor_create(server.wl_display, 5, server.renderer);
	wlr_subcompositor_create(server.wl_display);
	wlr_data_device_manager_create(server.wl_display);
	/* Creates an output layout, which a wlroots utility for working with an
	 * arrangement of screens in a physical layout. */
	server.output_layout = wlr_output_layout_create(server.wl_display);
	/* Configure a listener to be notified when new outputs are available on the
	 * backend. */
	wl_list_init(&server.outputs);
	server.new_output.notify = server_new_output;
	wl_signal_add(&server.backend->events.new_output, &server.new_output);
	/* Create a scene graph. This is a wlroots abstraction that handles all
	 * rendering and damage tracking. All the compositor author needs to do
	 * is add things that should be rendered to the scene graph at the proper
	 * positions and then call wlr_scene_output_commit() to render a frame if
	 * necessary.
	 */
	server.scene = wlr_scene_create();
	server.scene_layout = wlr_scene_attach_output_layout(server.scene, server.output_layout);
	/* Set up xdg-shell version 3. The xdg-shell is a Wayland protocol which is
	 * used for application windows. For more detail on shells, refer to
	 * https://drewdevault.com/2018/07/29/Wayland-shells.html.
	 */
	wl_list_init(&server.toplevels);
	server.xdg_shell = wlr_xdg_shell_create(server.wl_display, 3);
	server.new_xdg_toplevel.notify = server_new_xdg_toplevel;
	wl_signal_add(&server.xdg_shell->events.new_toplevel, &server.new_xdg_toplevel);
	server.new_xdg_popup.notify = server_new_xdg_popup;
	wl_signal_add(&server.xdg_shell->events.new_popup, &server.new_xdg_popup);
	/* Set up xdg-output protocol */
	server.xdg_output_manager_v1 =
		wlr_xdg_output_manager_v1_create(server.wl_display, server.output_layout);
	/*
	 * Creates a cursor, which is a wlroots utility for tracking the cursor
	 * image shown on screen.
	 */
	server.cursor = wlr_cursor_create();
	wlr_cursor_attach_output_layout(server.cursor, server.output_layout);
	/* Creates an xcursor manager, another wlroots utility which loads up
	 * Xcursor themes to source cursor images from and makes sure that cursor
	 * images are available at all scale factors on the screen (necessary for
	 * HiDPI support). */
	server.cursor_mgr = wlr_xcursor_manager_create(NULL, 24);
	/*
	 * wlr_cursor *only* displays an image on screen. It does not move around
	 * when the pointer moves. However, we can attach input devices to it, and
	 * it will generate aggregate events for all of them. In these events, we
	 * can choose how we want to process them, forwarding them to clients and
	 * moving the cursor around. More detail on this process is described in
	 * https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html.
	 *
	 * And more comments are sprinkled throughout the notify functions above.
	 */
	server.cursor_motion.notify = server_cursor_motion;
	wl_signal_add(&server.cursor->events.motion, &server.cursor_motion);
	server.cursor_motion_absolute.notify = server_cursor_motion_absolute;
	wl_signal_add(&server.cursor->events.motion_absolute, &server.cursor_motion_absolute);
	server.cursor_button.notify = server_cursor_button;
	wl_signal_add(&server.cursor->events.button, &server.cursor_button);
	server.cursor_axis.notify = server_cursor_axis;
	wl_signal_add(&server.cursor->events.axis, &server.cursor_axis);
	server.cursor_frame.notify = server_cursor_frame;
	wl_signal_add(&server.cursor->events.frame, &server.cursor_frame);
	/*
	 * Configures a seat, which is a single "seat" at which a user sits and
	 * operates the computer. This conceptually includes up to one keyboard,
	 * pointer, touch, and drawing tablet device. We also rig up a listener to
	 * let us know when new input devices are available on the backend.
	 */
	wl_list_init(&server.keyboards);
	server.new_input.notify = server_new_input;
	wl_signal_add(&server.backend->events.new_input, &server.new_input);
	server.seat = wlr_seat_create(server.wl_display, "seat0");
	server.request_cursor.notify = seat_request_cursor;
	wl_signal_add(&server.seat->events.request_set_cursor, &server.request_cursor);
	server.request_set_selection.notify = seat_request_set_selection;
	wl_signal_add(&server.seat->events.request_set_selection, &server.request_set_selection);
	/* Add a Unix socket to the Wayland display. */
	set_cloexec(xwayback_session_socket);
	struct wl_client *xwayback_client =
		wl_client_create(server.wl_display, xwayback_session_socket);
	if (!xwayback_client) {
		wlr_log(WLR_ERROR, "Failed to connect to xwayback client");
		exit(EXIT_FAILURE);
	}
	struct wayback_client xwayback = { 0 };
	xwayback.server = &server;
	xwayback.destroy.notify = client_destroy;
	wl_client_add_destroy_listener(xwayback_client, &xwayback.destroy);
	set_cloexec(xwayland_session_socket);
	struct wl_client *xwayland_client =
		wl_client_create(server.wl_display, xwayland_session_socket);
	if (!xwayland_client) {
		wlr_log(WLR_ERROR, "Failed to connect to xwayland client");
		exit(EXIT_FAILURE);
	}
	struct wayback_client xwayland = { 0 };
	xwayland.server = &server;
	xwayland.destroy.notify = client_destroy;
	wl_client_add_destroy_listener(xwayland_client, &xwayland.destroy);
	/* Start the backend. This will enumerate outputs and inputs, become the DRM
	 * master, etc */
	if (!wlr_backend_start(server.backend)) {
		wlr_backend_destroy(server.backend);
		wl_display_destroy(server.wl_display);
		return 1;
	}
	char *output = getenv("WAYBACK_OUTPUT");
	bool have_output = false;
	if (output != NULL) {
		struct tinywl_output *out, *out_tmp;
		wl_list_for_each_safe(out, out_tmp, &server.outputs, link) {
			char *output_make_model;
			asprintf_or_exit(
				&output_make_model, "%s %s", out->wlr_output->make, out->wlr_output->model);
			bool enabled = (strcmp(output_make_model, output) == 0) || (strcmp(out->wlr_output->name, output) == 0);
			if (!enabled)
				wlr_output_destroy(out->wlr_output);
			else
				have_output = true;
		}
	}
	if (!have_output && output != NULL) {
		wlr_log(WLR_ERROR, "No output enabled");
		exit(EXIT_FAILURE);
	}
	/* Run the Wayland event loop. This does not return until you exit the
	 * compositor. Starting the backend rigged up all of the necessary event
	 * loop configuration to listen to libinput events, DRM events, generate
	 * frame events at the refresh rate, and so on. */
	wl_display_run(server.wl_display);
	/* Once wl_display_run returns, we destroy all clients then shut down the
	 * server. */
	wl_display_destroy_clients(server.wl_display);
	wl_list_remove(&server.cursor_motion.link);
	wl_list_remove(&server.cursor_motion_absolute.link);
	wl_list_remove(&server.cursor_button.link);
	wl_list_remove(&server.cursor_axis.link);
	wl_list_remove(&server.cursor_frame.link);
	wl_list_remove(&server.new_input.link);
	wl_list_remove(&server.request_cursor.link);
	wl_list_remove(&server.request_set_selection.link);
	wl_list_remove(&server.new_output.link);
	wl_list_remove(&server.new_xdg_toplevel.link);
	wl_list_remove(&server.new_xdg_popup.link);
	wlr_scene_node_destroy(&server.scene->tree.node);
	wlr_xcursor_manager_destroy(server.cursor_mgr);
	wlr_cursor_destroy(server.cursor);
	wlr_allocator_destroy(server.allocator);
	wlr_renderer_destroy(server.renderer);
	wlr_backend_destroy(server.backend);
	wl_display_destroy(server.wl_display);
	return 0;
}
0707010000001c000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000001b00000000wayback/wayback-compositor0707010000001d000081a4000000000000000000000001689c3e8c000000d3000000000000000000000000000000000000002400000000wayback/wayback-session/meson.buildexecutable(
	'wayback-session',
	['wayback-session.c'],
	dependencies: [wayland_server, wayland_client, wayland_cursor, wayland_egl, wayland_protos, wlroots, xkbcommon, server_protos, shared],
	install: true,
)
0707010000001e000081a4000000000000000000000001689c3e8c000012c1000000000000000000000000000000000000002a00000000wayback/wayback-session/wayback-session.c/*
 * wayback-session launches the wayback compositor, XWayback/XWayland
 * and the given session executable
 *
 * SPDX-License-Identifier: MIT
 */
#include "optparse.h"
#include "utils.h"
#include "wayback_log.h"
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
pid_t xwayback_pid;
pid_t session_pid;
char *get_xinitrc_path()
{
	char *home = getenv("HOME");
	if (home) {
		char *xinitrc;
		asprintf_or_exit(&xinitrc, "%s/.xinitrc", home);
		if (access(xinitrc, R_OK) == 0)
			return xinitrc;
		free(xinitrc);
	}
	if (access("/etc/X11/xinit/xinitrc", R_OK) == 0)
		return strdup_or_exit("/etc/X11/xinit/xinitrc");
	wayback_log(LOG_ERROR, "Unable to find xinitrc file");
	exit(EXIT_FAILURE);
}
void handle_child_exit(int sig)
{
	pid_t pid = waitpid(-1, NULL, WNOHANG);
	if (pid == session_pid || pid == xwayback_pid) {
		if (pid == session_pid && xwayback_pid > 0)
			kill(xwayback_pid, SIGTERM);
		if (pid == xwayback_pid && session_pid > 0)
			kill(session_pid, SIGTERM);
		exit(EXIT_SUCCESS);
	}
}
int main(int argc, char *argv[])
{
	wayback_log_init("wayback-session", LOG_INFO, NULL);
	char **session_cmd = NULL;
	char *xinitrc_path = NULL;
	const struct optcmd opts[] = {
		{ .name = "-help", .description = "show help page", .req_operand = false, .ignore = false },
		{ .name = "-sesscmd",
		  .description = "run custom session command",
		  .req_operand = true,
		  .ignore = false },
		{ .name = "-showconfig",
		  .description = "alias to -version",
		  .req_operand = false,
		  .ignore = false },
		{ .name = "-version",
		  .description = "show wayback-session version",
		  .req_operand = false,
		  .ignore = false },
	};
	signal(SIGCHLD, handle_child_exit);
	int cur_opt = 0;
	while (cur_opt = optparse(argc, argv, opts, ARRAY_SIZE(opts)), cur_opt != -1) {
		/* help message */
		if (strcmp(argv[cur_opt], "-help") == 0) {
			wayback_log(LOG_INFO,
			            "Wayback <https://wayback.freedesktop.org/> X.Org compatibility layer");
			wayback_log(
				LOG_INFO,
				"Report bugs to <https://gitlab.freedesktop.org/wayback/wayback/-/issues>.");
			wayback_log(LOG_INFO, "Usage: %s [option]", argv[0]);
			for (size_t j = 0; j < ARRAY_SIZE(opts); j++) {
				if (!opts[j].ignore) {
					wayback_log(LOG_INFO,
					            "\t%s%s\t\t %s",
					            opts[j].name,
					            opts[j].req_operand ? " opt" : "",
					            opts[j].description);
				}
			}
			exit(EXIT_SUCCESS);
		} else if (strcmp(argv[cur_opt], "-version") == 0 ||
		           strcmp(argv[cur_opt], "-showconfig") == 0) {
			wayback_log(LOG_INFO,
			            "Wayback <https://wayback.freedesktop.org/> X.Org compatibility layer");
			wayback_log(LOG_INFO, "Version %s", WAYBACK_VERSION);
			exit(EXIT_SUCCESS);
		} else if (strcmp(argv[cur_opt], "-sesscmd") == 0) {
			session_cmd = &argv[cur_opt + 1];
		} else {
			wayback_log(LOG_ERROR, "Unknown option %s", argv[cur_opt]);
			exit(EXIT_FAILURE);
		}
	}
	if ((argc - optind) <= 0) {
		wayback_log(LOG_ERROR, "Argument count is <= 0");
	}
	if (!session_cmd) {
		xinitrc_path = get_xinitrc_path();
	}
	char *xwayback_path = getenv("XWAYBACK_PATH");
	if (xwayback_path != NULL) {
		if (access(xwayback_path, X_OK) == -1) {
			wayback_log(
				LOG_ERROR, "Xwayback executable %s not found or not executable", xwayback_path);
			exit(EXIT_FAILURE);
		}
	} else {
		xwayback_path = "Xwayback";
	}
	int fd[2];
	if (pipe(fd) == -1) {
		wayback_log(LOG_ERROR, "Failed to create pipe");
		exit(EXIT_FAILURE);
	}
	xwayback_pid = fork();
	if (xwayback_pid == 0) {
		close(fd[0]);
		wayback_log(LOG_INFO, "Launching with fd %d", fd[1]);
		char *fd_str;
		asprintf_or_exit(&fd_str, "%d", fd[1]);
		execlp(xwayback_path, xwayback_path, "-displayfd", fd_str, (void *)NULL);
		wayback_log(LOG_ERROR, "Failed to launch Xwayback: %s", strerror(errno));
		exit(EXIT_FAILURE);
	}
	char buffer[4095];
	close(fd[1]);
	ssize_t n = read(fd[0], buffer, sizeof(buffer) - 1);
	if (n > 0) {
		buffer[n - 1] = '\0'; // Convert from newline-terminated to null-terminated string
		wayback_log(LOG_INFO, "Received display %s", buffer);
	}
	char *x_display;
	asprintf_or_exit(&x_display, ":%s", buffer);
	session_pid = fork();
	if (session_pid == 0) {
		unsetenv("WAYLAND_DISPLAY");
		setenv("XDG_SESSION_TYPE", "x11", true);
		setenv("DISPLAY", x_display, true);
		if (xinitrc_path != NULL) {
			execlp("sh", "sh", xinitrc_path, (void *)NULL);
		} else if (session_cmd != NULL) {
			execvp(session_cmd[0], session_cmd);
		}
		wayback_log(LOG_ERROR, "Failed to launch session: %s", strerror(errno));
		free(xinitrc_path);
		exit(EXIT_FAILURE);
	}
	while (1)
		pause();
	return 0;
}
0707010000001f000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000001800000000wayback/wayback-session07070100000020000081a4000000000000000000000001689c3e8c00000074000000000000000000000000000000000000001d00000000wayback/xwayback/meson.buildexecutable(
	'Xwayback',
	['xwayback.c'],
	dependencies: [wayland_client, client_protos, shared],
	install: true,
)
07070100000021000081a4000000000000000000000001689c3e8c000037d3000000000000000000000000000000000000001c00000000wayback/xwayback/xwayback.c/*
 * XWayback is a wrapper around wayback-compositor
 * and XWayland, it launches both in succession and
 * functions similiar to a traditional X server.
 *
 * SPDX-License-Identifier: MIT
 */
#include "optparse.h"
#include "utils.h"
#include "wayback_log.h"
#include "xdg-output-unstable-v1-client-protocol.h"
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <spawn.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <wayland-client.h>
struct xwayback
{
	struct wl_display *display;
	struct zxdg_output_manager_v1 *xdg_output_manager;
	struct xway_output *first_output;
	struct wl_list outputs;
};
struct xway_output
{
	struct wl_list link;
	struct wl_output *output;
	struct zxdg_output_v1 *xdg_output;
	struct xwayback *xwayback;
	uint32_t wl_name;
	char *name;
	char *description;
	char *make;
	char *model;
	uint32_t height, width, x, y;
	int32_t physical_height, physical_width;
	int32_t subpixel;
	int32_t transform;
	int32_t scale;
	float refresh;
};
static pid_t comp_pid;
static pid_t xway_pid;
static void output_geometry(void *data,
                            struct wl_output *wl_output,
                            int32_t x,
                            int32_t y,
                            int32_t width_mm,
                            int32_t height_mm,
                            int32_t subpixel,
                            const char *make,
                            const char *model,
                            int32_t transform)
{
	struct xway_output *output = data;
	free(output->make);
	free(output->model);
	output->physical_height = height_mm;
	output->physical_width = width_mm;
	output->make = make != NULL ? strdup_or_exit(make) : NULL;
	output->model = model != NULL ? strdup_or_exit(model) : NULL;
	output->subpixel = subpixel;
	output->transform = transform;
	return;
}
static void output_mode(void *data,
                        struct wl_output *wl_output,
                        uint32_t flags,
                        int32_t width,
                        int32_t height,
                        int32_t refresh)
{
	struct xway_output *output = data;
	output->refresh = (float)refresh / 1000;
	output->width = width;
	output->height = height;
	return;
}
static void output_done(void *data, struct wl_output *wl_output)
{
	// No extra output processing needed
	return;
}
static void output_scale(void *data, struct wl_output *wl_output, int32_t factor)
{
	struct xway_output *output = data;
	output->scale = factor;
	return;
}
static const struct wl_output_listener output_listener = {
	.geometry = output_geometry,
	.mode = output_mode,
	.done = output_done,
	.scale = output_scale,
};
static void xdg_output_handle_logical_position(void *data,
                                               struct zxdg_output_v1 *xdg_output,
                                               int32_t x,
                                               int32_t y)
{
	struct xway_output *output = data;
	output->x = x;
	output->y = y;
}
static void xdg_output_handle_logical_size(void *data,
                                           struct zxdg_output_v1 *xdg_output,
                                           int32_t width,
                                           int32_t height)
{
	struct xway_output *output = data;
	output->height = height;
	output->width = width;
}
static void xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output)
{
	// No extra processing is currently required.
	return;
}
static void xdg_output_handle_name(void *data, struct zxdg_output_v1 *xdg_output, const char *name)
{
	struct xway_output *output = data;
	free(output->name);
	output->name = strdup_or_exit(name);
}
static void xdg_output_handle_description(void *data,
                                          struct zxdg_output_v1 *xdg_output,
                                          const char *description)
{
	struct xway_output *output = data;
	free(output->description);
	output->description = strdup_or_exit(description);
}
static const struct zxdg_output_v1_listener xdg_output_listener = {
	.logical_position = xdg_output_handle_logical_position,
	.logical_size = xdg_output_handle_logical_size,
	.done = xdg_output_handle_done,
	.name = xdg_output_handle_name,
	.description = xdg_output_handle_description,
};
static void add_xdg_output(struct xway_output *output)
{
	if (output->xdg_output != NULL) {
		return;
	}
	output->xdg_output =
		zxdg_output_manager_v1_get_xdg_output(output->xwayback->xdg_output_manager, output->output);
	zxdg_output_v1_add_listener(output->xdg_output, &xdg_output_listener, output);
}
static void handle_global(void *data,
                          struct wl_registry *registry,
                          uint32_t name,
                          const char *interface,
                          uint32_t version)
{
	struct xwayback *xwayback = data;
	if (strcmp(interface, wl_output_interface.name) == 0) {
		struct xway_output *output = calloc(1, sizeof(struct xway_output));
		output->xwayback = xwayback;
		output->output = wl_registry_bind(registry, name, &wl_output_interface, 3);
		wl_output_add_listener(output->output, &output_listener, output);
		output->wl_name = name;
		wl_list_init(&output->link);
		wl_list_insert(&xwayback->outputs, &output->link);
		if (xwayback->first_output == NULL)
			xwayback->first_output = output;
		if (xwayback->xdg_output_manager != NULL)
			add_xdg_output(output);
	} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
		xwayback->xdg_output_manager =
			wl_registry_bind(registry, name, &zxdg_output_manager_v1_interface, 2);
	}
}
static const struct wl_registry_listener registry_listener = {
	.global = handle_global,
	.global_remove = NULL, // TODO: handle_global_remove
};
static void handle_segv(int sig)
{
	const char *errormsg =
		"[ERROR] (Xwayback): Received SIGSEGV (Segmentation fault)!\n"
		"This is a bug!\nPlease visit https://gitlab.freedesktop.org/wayback/wayback/-/issues/ to "
		"check\nif this bug has already been reported.  If not, fill a new bug report with "
		"steps\nto reproduce this error.  If you need assistance, join #wayback on Libera.Chat\nor "
		"#wayback:catircservices.org on Matrix.\n";
	write(STDERR_FILENO, errormsg, strlen(errormsg));
}
extern char **environ;
int main(int argc, char *argv[])
{
	struct xwayback *xwayback = malloc(sizeof(struct xwayback));
	const struct optcmd opts[] = {
		/* options handled by Xwayback */
		{ .name = "-help", .description = "show help page", .req_operand = false, .ignore = false },
		{ .name = "-showconfig",
		  .description = "alias to -version",
		  .req_operand = false,
		  .ignore = false },
		{ .name = "-version",
		  .description = "show Xwayback version",
		  .req_operand = false,
		  .ignore = false },
		/* ignored options */
		IGNORE_OPT("-decorate", false),
		IGNORE_OPT("-enable‐ei‐portal", false),
		IGNORE_OPT("-fullscreen", false),
		IGNORE_OPT("-geometry", true),
		IGNORE_OPT("-glamor", true),
		IGNORE_OPT("-hidpi", false),
		IGNORE_OPT("-host‐grab", false),
		IGNORE_OPT("-noTouchPointerEmulation", false),
		IGNORE_OPT("-force‐xrandr‐emulation", false),
		IGNORE_OPT("-nokeymap", false),
		IGNORE_OPT("-rootless", false),
		IGNORE_OPT("-shm", false),
		IGNORE_OPT("-wm", true),
		/* Xorg(1)-specific options */
		IGNORE_OPT("-allowMouseOpenFail", false),
		IGNORE_OPT("-allowNonLocalXvidtune", false),
		IGNORE_OPT("-bgamma", true),
		IGNORE_OPT("-bpp", true), /* no longer supported by upstream Xorg(1) */
		IGNORE_OPT("-config", true),
		IGNORE_OPT("-configdir", true),
		IGNORE_OPT("-configure", true),
		IGNORE_OPT("-crt", true),
		IGNORE_OPT("-depth", true),
		IGNORE_OPT("-disableVidMode", false),
		IGNORE_OPT("-fbbbp", true),
		IGNORE_OPT("-gamma", true),
		IGNORE_OPT("-ggamma", true),
		IGNORE_OPT("-ignoreABI", false),
		IGNORE_OPT("-isolateDevice", true),
		IGNORE_OPT("-keeptty", false),
		IGNORE_OPT("-keyboard", true),
		IGNORE_OPT("-layout", true),
		IGNORE_OPT("-logverbose", true),
		IGNORE_OPT("-modulepath", true),
		IGNORE_OPT("-noautoBindCPU", false),
		IGNORE_OPT("-nosilk", false),
		IGNORE_OPT("-novtswitch", false),
		IGNORE_OPT("-pointer", true),
		IGNORE_OPT("-quiet", false),
		IGNORE_OPT("-rgamma", true),
		IGNORE_OPT("-sharevts", false),
		IGNORE_OPT("-screen", true),
		IGNORE_OPT("-showDefaultModulePath", false),
		IGNORE_OPT("-showDefaultLibPath", false),
		IGNORE_OPT("-showopts", false),
		IGNORE_OPT("-weight", true),
		IGNORE_OPT("-verbose", true),
	};
	int socket_xwayback[2];
	int socket_xwayland[2];
	signal(SIGSEGV, handle_segv);
	wayback_log_init("Xwayback", LOG_INFO, NULL);
	int cur_opt = 0;
	while (cur_opt = optparse(argc, argv, opts, ARRAY_SIZE(opts)), cur_opt != -1) {
		/* help message */
		if (strcmp(argv[cur_opt], "-help") == 0) {
			wayback_log(LOG_INFO,
			            "Wayback <https://wayback.freedesktop.org/> X.Org compatibility layer");
			wayback_log(
				LOG_INFO,
				"Report bugs to <https://gitlab.freedesktop.org/wayback/wayback/-/issues>.");
			wayback_log(LOG_INFO, "Usage: %s [:<display>] [option]", argv[0]);
			for (size_t j = 0; j < ARRAY_SIZE(opts); j++) {
				if (!opts[j].ignore) {
					wayback_log(LOG_INFO,
					            "\t%s%s\t\t %s",
					            opts[j].name,
					            opts[j].req_operand ? " opt" : "",
					            opts[j].description);
				}
			}
			exit(EXIT_SUCCESS);
		} else if (strcmp(argv[cur_opt], "-version") == 0 ||
		           strcmp(argv[cur_opt], "-showconfig") == 0) {
			wayback_log(LOG_INFO,
			            "Wayback <https://wayback.freedesktop.org/> X.Org compatibility layer");
			wayback_log(LOG_INFO, "Version %s", WAYBACK_VERSION);
			exit(EXIT_SUCCESS);
		}
	}
	if ((argc - optind) <= 0) {
		wayback_log(LOG_ERROR, "Argument count is <= 0");
	}
	// check if the compositor/Xwayland binaries are accessible before doing anything else
	const char *wayback_compositor_path = getenv("WAYBACK_COMPOSITOR_PATH");
	const char *xwayland_path = getenv("XWAYLAND_PATH");
	if (wayback_compositor_path == NULL)
		wayback_compositor_path = WAYBACK_COMPOSITOR_EXEC_PATH;
	if (xwayland_path == NULL)
		xwayland_path = XWAYLAND_EXEC_PATH;
	if (access(wayback_compositor_path, X_OK) == -1) {
		wayback_log(LOG_ERROR,
		            "wayback-compositor executable %s not found or not executable",
		            wayback_compositor_path);
		exit(EXIT_FAILURE);
	}
	if (access(xwayland_path, X_OK) == -1) {
		wayback_log(LOG_ERROR, "Xwayland executable %s not found or not executable", xwayland_path);
		exit(EXIT_FAILURE);
	}
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_xwayback) == -1) {
		wayback_log(LOG_ERROR, "Unable to create Xwayback socket");
		exit(EXIT_FAILURE);
	}
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_xwayland) == -1) {
		wayback_log(LOG_ERROR, "Unable to create Xwayland socket");
		exit(EXIT_FAILURE);
	}
	posix_spawn_file_actions_t file_actions;
	posix_spawn_file_actions_init(&file_actions);
	posix_spawn_file_actions_addclose(&file_actions, socket_xwayback[1]);
	posix_spawn_file_actions_addclose(&file_actions, socket_xwayland[1]);
	char fd_xwayback[64];
	char fd_xwayland[64];
	snprintf(fd_xwayback, sizeof(fd_xwayback), "%d", socket_xwayback[0]);
	snprintf(fd_xwayland, sizeof(fd_xwayland), "%d", socket_xwayland[0]);
	if (posix_spawn(&comp_pid,
	                wayback_compositor_path,
	                &file_actions,
	                NULL,
	                (char *[]){ (char *)wayback_compositor_path, fd_xwayback, fd_xwayland, NULL },
	                environ) != 0) {
		wayback_log(LOG_ERROR, "Failed to launch wayback-compositor: %s", strerror(errno));
		exit(EXIT_FAILURE);
	}
	posix_spawn_file_actions_destroy(&file_actions);
	close(socket_xwayback[0]);
	close(socket_xwayland[0]);
	unsetenv("WAYLAND_DISPLAY");
	unsetenv("WAYLAND_SOCKET");
	xwayback->display = wl_display_connect_to_fd(socket_xwayback[1]);
	if (!xwayback->display) {
		wayback_log(LOG_ERROR, "Unable to connect to wayback-compositor");
		exit(EXIT_FAILURE);
	}
	wl_list_init(&xwayback->outputs);
	xwayback->first_output = NULL;
	struct wl_registry *registry = wl_display_get_registry(xwayback->display);
	wl_registry_add_listener(registry, ®istry_listener, xwayback);
	wl_display_roundtrip(xwayback->display);
	wl_display_roundtrip(xwayback->display); // xdg-output requires two roundtrips
	const char *output = getenv("WAYBACK_OUTPUT");
	if (output != NULL) {
		struct xway_output *out;
		wl_list_for_each(out, &xwayback->outputs, link)
		{
			char *output_make_model;
			asprintf_or_exit(&output_make_model, "%s %s", out->make, out->model);
			if (strcmp(output_make_model, output) == 0 || strcmp(out->make, output) == 0)
				xwayback->first_output = out;
		}
	}
	if (xwayback->first_output == NULL) {
		wayback_log(LOG_ERROR, "Unable to get outputs");
		exit(EXIT_FAILURE);
	}
	char way_display[64];
	snprintf(way_display, sizeof(way_display), "%d", socket_xwayland[1]);
	setenv("WAYLAND_SOCKET", way_display, true);
	char geometry[4096] = "";
	const char *xwayback_args[] = {
		"-terminate",
		"3",
		"-geometry",
		geometry,
	};
	snprintf(geometry,
	         sizeof(geometry),
	         "%dx%d",
	         xwayback->first_output->width,
	         xwayback->first_output->height);
	size_t count = 0;
	const char *arguments[argc - optind + ARRAY_SIZE(xwayback_args) + 1];
	arguments[count++] = xwayland_path;
	for (size_t i = 0; i < ARRAY_SIZE(xwayback_args); i++)
		arguments[count++] = xwayback_args[i];
	for (int i = 1; i < argc; i++) {
		size_t j = 0;
		for (; j < ARRAY_SIZE(opts); j++) {
			if (strcmp(opts[j].name, argv[i]) == 0) {
				if (opts[j].req_operand && (i + 1) < argc) {
					i++;
				}
				break;
			}
		}
		if (j == ARRAY_SIZE(opts)) {
			arguments[count++] = argv[i];
		}
	}
	arguments[count++] = NULL;
	posix_spawn_file_actions_init(&file_actions);
	posix_spawn_file_actions_addclose(&file_actions, socket_xwayback[1]);
	if (posix_spawn(&xway_pid, xwayland_path, &file_actions, NULL, (char **)arguments, environ) !=
	    0) {
		wayback_log(LOG_ERROR, "Failed to launch Xwayland");
		exit(EXIT_FAILURE);
	}
	close(socket_xwayland[1]);
	waitid(P_PID, comp_pid, NULL, WEXITED);
	return 0;
}
07070100000022000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000001100000000wayback/xwayback07070100000023000041ed000000000000000000000001689c3e8c00000000000000000000000000000000000000000000000800000000wayback07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000b00000000TRAILER!!!