├── docs
└── .gitignore
├── .envrc
├── subprojects
├── .gitignore
├── wlroots.wrap
├── expected.wrap
└── cereal.wrap
├── cardboard
├── wlr_cpp_fixes
│ ├── meson.build
│ └── include
│ │ └── wlr_cpp_fixes
│ │ ├── xwayland.h
│ │ └── types
│ │ └── wlr_layer_shell_v1.h
├── Helpers.h
├── Command.h
├── Spawn.h
├── Config.h
├── Spawn.cpp
├── main.cpp
├── StrongAlias.h
├── meson.build
├── ViewOperations.h
├── Output.h
├── SurfaceManager.h
├── Cursor.h
├── Layers.h
├── ViewAnimation.h
├── XDGView.h
├── NotNull.h
├── View.cpp
├── ViewAnimation.cpp
├── OutputManager.h
├── Xwayland.h
├── OptionalRef.h
├── Keyboard.h
├── Listener.h
├── Keyboard.cpp
├── Cursor.cpp
├── IPC.h
├── Server.h
├── SurfaceManager.cpp
├── ViewOperations.cpp
├── OutputManager.cpp
├── commands
│ └── dispatch_command.cpp
├── Workspace.h
├── View.h
├── Server.cpp
├── Seat.h
└── IPC.cpp
├── cardboard.desktop
├── .editorconfig
├── .gitignore
├── meson_options.txt
├── .gitlab-ci.yml
├── cutter
├── meson.build
├── main.cpp
└── parse_arguments.h
├── shell.nix
├── libcardboard
├── meson.build
├── src
│ ├── ipc.cpp
│ ├── client.cpp
│ └── command_protocol.cpp
└── include
│ └── cardboard
│ ├── ipc.h
│ ├── client.h
│ └── command_protocol.h
├── nix
├── sources.json
└── sources.nix
├── protocols
└── meson.build
├── meson.build
├── man
├── cardboard.1.md
└── cutter.1.md
├── .clang-format
└── README.md
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | gen
2 |
--------------------------------------------------------------------------------
/.envrc:
--------------------------------------------------------------------------------
1 | eval "$(lorri direnv)"
--------------------------------------------------------------------------------
/subprojects/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !*.wrap
--------------------------------------------------------------------------------
/subprojects/wlroots.wrap:
--------------------------------------------------------------------------------
1 | [wrap-git]
2 | url = https://github.com/swaywm/wlroots
3 | revision = 0.12.0
4 |
--------------------------------------------------------------------------------
/subprojects/expected.wrap:
--------------------------------------------------------------------------------
1 | [wrap-git]
2 | url = https://gitlab.com/cardboardwm/expected
3 | revision = master
4 |
--------------------------------------------------------------------------------
/cardboard/wlr_cpp_fixes/meson.build:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-3.0-only
2 | wlr_cpp_fixes_inc = include_directories('include')
3 |
--------------------------------------------------------------------------------
/cardboard.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Name=Cardboard
3 | Comment=A scrollable tiling Wayland compositor
4 | Exec=cardboard
5 | Type=Application
6 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 |
7 | [*.{cpp,h,hpp}]
8 | indent_style = space
9 | indent_size = 4
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea
3 | *.log
4 | tmp/
5 | .ccls-cache/
6 | *.plist
7 |
8 | build
9 | subprojects/wlroots
10 | subprojects/expected
11 | compile_commands.json
12 |
--------------------------------------------------------------------------------
/meson_options.txt:
--------------------------------------------------------------------------------
1 | option('xwayland', type: 'feature', value: 'auto', description: 'Enable support for X11 applications')
2 | option('man', type: 'boolean', value: 'false', description: 'Build man pages. (Requires pandoc)')
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | image: registry.gitlab.com/cardboardwm/cardboard-ci-image/ci-image
2 | stages:
3 | - build
4 |
5 | gnu:
6 | stage: build
7 | script:
8 | - CC=gcc CXX=g++ meson build-gnu
9 | - ninja -C build-gnu
10 |
11 | clang:
12 | stage: build
13 | script:
14 | - CC=clang CXX=clang++ meson build-clang
15 | - ninja -C build-clang
16 |
--------------------------------------------------------------------------------
/cutter/meson.build:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-3.0-only
2 | expected_proj = subproject('expected', required: true)
3 | expected = expected_proj.get_variable('expected_dep')
4 |
5 | executable(
6 | 'cutter',
7 | files('main.cpp'),
8 | include_directories: [libcardboard_inc],
9 | link_with: libcardboard,
10 | dependencies: [expected],
11 | install: true
12 | )
13 |
--------------------------------------------------------------------------------
/shell.nix:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-3.0-only
2 | let
3 | sources = import ./nix/sources.nix;
4 | pkgs = import sources.nixpkgs {};
5 | in
6 | pkgs.mkShell {
7 | nativeBuildInputs = with pkgs; [
8 | meson
9 | ninja
10 | pkg-config
11 | gcc10
12 | ] ++ pkgs.wlroots.nativeBuildInputs;
13 |
14 | buildInputs = with pkgs; [
15 | wayland
16 | libffi
17 | ] ++ pkgs.wlroots.buildInputs;
18 | }
19 |
--------------------------------------------------------------------------------
/subprojects/cereal.wrap:
--------------------------------------------------------------------------------
1 | [wrap-file]
2 | directory = cereal-1.3.0
3 |
4 | source_url = https://github.com/USCiLab/cereal/archive/v1.3.0.tar.gz
5 | source_filename = cereal-1.3.0.tar.gz
6 | source_hash = 329ea3e3130b026c03a4acc50e168e7daff4e6e661bc6a7dfec0d77b570851d5
7 |
8 | patch_url = https://wrapdb.mesonbuild.com/v1/projects/cereal/1.3.0/1/get_zip
9 | patch_filename = cereal-1.3.0-1-wrap.zip
10 | patch_hash = 418724e544fb7cf2eab4b0dbd623925f81e79e7b38f098f6dc07bf2c27cb48a6
11 |
--------------------------------------------------------------------------------
/libcardboard/meson.build:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-3.0-only
2 | libcardboard_inc = include_directories('include')
3 |
4 | expected_proj = subproject('expected', required: true)
5 | expected = expected_proj.get_variable('expected_dep')
6 |
7 | cereal_proj = subproject('cereal', required: true)
8 | cereal = cereal_proj.get_variable('cereal_dep')
9 |
10 | sources = files(
11 | 'src/command_protocol.cpp',
12 | 'src/ipc.cpp',
13 | 'src/client.cpp',
14 | )
15 |
16 | install_subdir('include/cardboard',
17 | install_dir: get_option('includedir')
18 | )
19 |
20 | libcardboard = library(
21 | 'cardboard',
22 | sources,
23 | include_directories: libcardboard_inc,
24 | install: true,
25 | dependencies: [cereal, expected],
26 | cpp_args: '-Wno-deprecated'
27 | )
28 |
--------------------------------------------------------------------------------
/cardboard/wlr_cpp_fixes/include/wlr_cpp_fixes/xwayland.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_WLR_CPP_FIXES_XWAYLAND_H_INCLUDED
12 | #define CARDBOARD_WLR_CPP_FIXES_XWAYLAND_H_INCLUDED
13 |
14 | extern "C" {
15 |
16 | #define class class_
17 | #define static
18 | #include
19 | #undef class
20 | #undef static
21 | }
22 |
23 | #endif // CARDBOARD_WLR_CPP_FIXES_XWAYLAND_H_INCLUDED
24 |
--------------------------------------------------------------------------------
/cardboard/wlr_cpp_fixes/include/wlr_cpp_fixes/types/wlr_layer_shell_v1.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_WLR_CPP_FIXES_WLR_LAYER_SHELL_V1_H_INCLUDED
12 | #define CARDBOARD_WLR_CPP_FIXES_WLR_LAYER_SHELL_V1_H_INCLUDED
13 |
14 | extern "C" {
15 |
16 | #define namespace namespace_
17 | #include
18 | #undef namespace
19 | }
20 |
21 | #endif // CARDBOARD_WLR_CPP_FIXES_WLR_LAYER_SHELL_V1_H_INCLUDED
22 |
--------------------------------------------------------------------------------
/nix/sources.json:
--------------------------------------------------------------------------------
1 | {
2 | "niv": {
3 | "branch": "master",
4 | "description": "Easy dependency management for Nix projects",
5 | "homepage": "https://github.com/nmattia/niv",
6 | "owner": "nmattia",
7 | "repo": "niv",
8 | "rev": "9d35b9e4837ab88517210b1701127612c260eccf",
9 | "sha256": "0q50xhnm8g2yfyakrh0nly4swyygxpi0a8cb9gp65wcakcgvzvdh",
10 | "type": "tarball",
11 | "url": "https://github.com/nmattia/niv/archive/9d35b9e4837ab88517210b1701127612c260eccf.tar.gz",
12 | "url_template": "https://github.com///archive/.tar.gz"
13 | },
14 | "nixpkgs": {
15 | "branch": "nixos-20.09",
16 | "description": "Nix Packages collection",
17 | "homepage": "",
18 | "owner": "NixOS",
19 | "repo": "nixpkgs",
20 | "rev": "05334ad78526ead39af85f846515606d9f052a11",
21 | "sha256": "1jrn6prplav0knaj859qqwg0l6mcyiv5yjd567hpgm4bi9hy1nxg",
22 | "type": "tarball",
23 | "url": "https://github.com/NixOS/nixpkgs/archive/05334ad78526ead39af85f846515606d9f052a11.tar.gz",
24 | "url_template": "https://github.com///archive/.tar.gz"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/cardboard/Helpers.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_HELPERS_H_INCLUDED
12 | #define CARDBOARD_HELPERS_H_INCLUDED
13 |
14 | #include
15 |
16 | #include "Listener.h"
17 | #include "Server.h"
18 |
19 | constexpr void register_handlers(Server& server, ListenerData subject, std::initializer_list pairs)
20 | {
21 | for (const auto& pair : pairs) {
22 | server.listeners.add_listener(pair.signal,
23 | Listener { pair.notify, &server, subject });
24 | }
25 | }
26 |
27 | #endif // CARDBOARD_HELPERS_H_INCLUDED
28 |
--------------------------------------------------------------------------------
/protocols/meson.build:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-3.0-only
2 | wayland_protos = dependency('wayland-protocols')
3 | wayland_server = dependency('wayland-server')
4 |
5 | wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir')
6 |
7 | wayland_scanner = find_program('wayland-scanner')
8 |
9 | if wayland_server.version().version_compare('>=1.14.91')
10 | code_type = 'private-code'
11 | else
12 | code_type = 'code'
13 | endif
14 |
15 | wayland_scanner_code = generator(
16 | wayland_scanner,
17 | output: '@BASENAME@-protocol.c',
18 | arguments: [code_type, '@INPUT@', '@OUTPUT@'],
19 | )
20 |
21 | wayland_scanner_server = generator(
22 | wayland_scanner,
23 | output: '@BASENAME@-protocol.h',
24 | arguments: ['server-header', '@INPUT@', '@OUTPUT@'],
25 | )
26 |
27 | server_protocols = [
28 | [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
29 | ['wlr-layer-shell-unstable-v1.xml'],
30 | ]
31 |
32 | server_protos_src = []
33 | server_protos_headers = []
34 |
35 | foreach p : server_protocols
36 | xml = join_paths(p)
37 | server_protos_src += wayland_scanner_code.process(xml)
38 | server_protos_headers += wayland_scanner_server.process(xml)
39 | endforeach
40 |
41 | lib_server_protos = static_library(
42 | 'server_protos',
43 | server_protos_src + server_protos_headers
44 | )
45 |
46 | server_protos = declare_dependency(
47 | link_with: lib_server_protos,
48 | sources: server_protos_headers,
49 | )
50 |
--------------------------------------------------------------------------------
/cardboard/Command.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_COMMAND_H_INCLUDED
12 | #define CARDBOARD_COMMAND_H_INCLUDED
13 |
14 | #include
15 | #include
16 |
17 | #include
18 |
19 | struct Server;
20 |
21 | /**
22 | * \brief This struct holds the result of an IPC command, which can be a string message
23 | * for the moment.
24 | */
25 | struct CommandResult {
26 | std::string message;
27 | };
28 |
29 | /**
30 | * \brief Callable that stores a bound command (internal function pointer and all arguments)
31 | */
32 | using Command = std::function;
33 |
34 | /**
35 | * \brief Dispatches a the command's arguments (CommandData) and binds the command into the Command type.
36 | */
37 | Command dispatch_command(const CommandData&);
38 |
39 | #endif //CARDBOARD_COMMAND_H_INCLUDED
40 |
--------------------------------------------------------------------------------
/cardboard/Spawn.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_SPAWN_H_INCLUDED
12 | #define CARDBOARD_SPAWN_H_INCLUDED
13 |
14 | #include
15 | #include
16 |
17 | #include
18 | #include
19 |
20 | /**
21 | * \file
22 | * \brief This header file holds a simple utility function for spawning
23 | * a system utility in another process.
24 | */
25 |
26 | /**
27 | * \brief Executes the function \a fn in a new process, in background.
28 | * \a fn should call a function from the \c exec(3) family.
29 | *
30 | * If any library call from \a fn encounters an error (especially the exec function),
31 | * it is caught by the parent and returned by this function.
32 | *
33 | * \returns The errno value if something failed, or 0 if successful.
34 | * */
35 | std::error_code spawn(std::function fn);
36 |
37 | #endif // CARDBOARD_SPAWN_H_INCLUDED
38 |
--------------------------------------------------------------------------------
/cardboard/Config.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_CONFIG_H_INCLUDED
12 | #define CARDBOARD_CONFIG_H_INCLUDED
13 |
14 | #include
15 |
16 | /// Various configurations for the compositor.
17 | struct Config {
18 | /**
19 | * \brief One or more keys that when pressed allow the user to move and/or resize
20 | * the window interactively.
21 | *
22 | * The config key in cutter is named 'mouse_mod' for simplicity, yet it allows more
23 | * if you want.
24 | * */
25 | uint32_t mouse_mods;
26 |
27 | /**
28 | * \brief The gap between the tiled windows (measured in pixels); default is 10 pixels
29 | */
30 | int gap = 10;
31 |
32 | /**
33 | * \brief The color behind the focused column
34 | */
35 | struct {
36 | float r, g, b, a;
37 | } focus_color { 0.f, 0.f, 0.7f, 0.5f };
38 | };
39 |
40 | #endif // CARDBOARD_CONFIG_H_INCLUDED
41 |
--------------------------------------------------------------------------------
/cardboard/Spawn.cpp:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #include "Spawn.h"
12 |
13 | template
14 | static void ignore(Args&&...)
15 | {
16 | }
17 |
18 | std::error_code spawn(std::function fn)
19 | {
20 | // credits: http://www.lubutu.com/code/spawning-in-unix
21 | int fd[2];
22 | if (pipe(fd) == -1) {
23 | int err = errno;
24 | return std::error_code(err, std::generic_category());
25 | }
26 | if (fork() == 0) {
27 | close(fd[0]);
28 | fcntl(fd[1], F_SETFD, FD_CLOEXEC);
29 |
30 | setsid();
31 | int status = fn();
32 |
33 | ignore(write(fd[1], &errno, sizeof(errno)));
34 | exit(status);
35 | }
36 |
37 | close(fd[1]);
38 |
39 | int code = 0;
40 | if (!read(fd[0], &code, sizeof(code))) {
41 | code = 0;
42 | }
43 | close(fd[0]);
44 | return std::error_code(code, std::generic_category());
45 | }
46 |
--------------------------------------------------------------------------------
/meson.build:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-3.0-only
2 | project(
3 | 'cardboardwm',
4 | 'c', 'cpp',
5 | version: '0.0.1',
6 | license: 'XXX',
7 | default_options: [
8 | 'c_std=c17',
9 | 'cpp_std=c++2a',
10 | 'warning_level=2',
11 | 'werror=true',
12 | 'default_library=static'
13 | ],
14 | )
15 |
16 | add_project_arguments(
17 | [
18 | '-DWLR_USE_UNSTABLE',
19 | '-Wno-missing-field-initializers',
20 | ],
21 | language: 'cpp'
22 | )
23 |
24 | # workaround for wlroots 0.10.1 on gcc 10
25 | add_global_arguments(
26 | ['-fcommon'], language: 'c'
27 | )
28 |
29 | datadir = get_option('datadir')
30 |
31 | install_data('cardboard.desktop', install_dir: join_paths(datadir, 'wayland-sessions'))
32 |
33 | subdir('protocols')
34 | subdir('libcardboard')
35 | subdir('cardboard')
36 | subdir('cutter')
37 |
38 | if get_option('man')
39 | pandoc = find_program('pandoc')
40 | mandir1 = join_paths(get_option('mandir'), 'man1')
41 |
42 | cardboard_man = custom_target(
43 | 'cardboard_man',
44 | output: 'cardboard.1',
45 | input: 'man/cardboard.1.md',
46 | command: [pandoc, '@INPUT@', '-o', '@OUTPUT@', '-s', '-t', 'man', '-f', 'markdown-smart'],
47 | install: true,
48 | install_dir: mandir1
49 | )
50 |
51 | cutter_man = custom_target(
52 | 'cutter_man',
53 | output: 'cutter.1',
54 | input: 'man/cutter.1.md',
55 | command: [pandoc, '@INPUT@', '-o', '@OUTPUT@', '-s', '-t', 'man', '-f', 'markdown-smart'],
56 | install: true,
57 | install_dir: mandir1
58 | )
59 | endif
--------------------------------------------------------------------------------
/cardboard/main.cpp:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | extern "C" {
12 | #include
13 | }
14 |
15 | #include
16 | #include
17 |
18 | #include "BuildConfig.h"
19 | #include "Server.h"
20 |
21 | Server server;
22 |
23 | void sig_handler(int signo)
24 | {
25 | if (signo == SIGCHLD) {
26 | signal(signo, sig_handler);
27 | while (waitpid(-1, 0, WNOHANG) > 0)
28 | ;
29 | } else if (signo == SIGINT || signo == SIGHUP || signo == SIGTERM) {
30 | server.teardown(0);
31 | }
32 | }
33 |
34 | int main()
35 | {
36 | wlr_log_init(WLR_DEBUG, nullptr);
37 |
38 | signal(SIGINT, sig_handler);
39 | signal(SIGHUP, sig_handler);
40 | signal(SIGTERM, sig_handler);
41 | signal(SIGCHLD, sig_handler);
42 | signal(SIGPIPE, SIG_IGN);
43 |
44 | if (!server.init()) {
45 | return EXIT_FAILURE;
46 | }
47 |
48 | server.run();
49 | server.stop();
50 | return server.exit_code;
51 | }
52 |
--------------------------------------------------------------------------------
/cardboard/StrongAlias.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_STRONG_ALIAS_H_INCLUDED
12 | #define CARDBOARD_STRONG_ALIAS_H_INCLUDED
13 |
14 | #include
15 |
16 | template
17 | class StrongAlias {
18 | public:
19 | explicit StrongAlias(const T& value)
20 | : m_value { value } {};
21 | explicit StrongAlias(T&& value)
22 | : m_value { std::move(value) } {};
23 | explicit StrongAlias()
24 | : m_value {}
25 | {
26 | }
27 |
28 | T& get() { return m_value; }
29 | const T& get() const { return m_value; }
30 |
31 | explicit operator T() { return m_value; }
32 | explicit operator T() const { return m_value; }
33 |
34 | auto& operator=(const T& t)
35 | {
36 | m_value = t;
37 |
38 | return *this;
39 | }
40 |
41 | auto& operator=(T&& t)
42 | {
43 | m_value = std::move(t);
44 |
45 | return *this;
46 | }
47 |
48 | private:
49 | T m_value;
50 | };
51 |
52 | #endif //CARDBOARD_STRONG_ALIAS_H_INCLUDED
53 |
--------------------------------------------------------------------------------
/man/cardboard.1.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: cardboard
3 | section: 1
4 | header: Cardboard Manual
5 | footer: Version 0.0.1
6 | ---
7 |
8 | # NAME
9 | cardboard - A scrollable tiling Wayland compositors designed with
10 | laptops in mind.
11 |
12 | # SYNOPSIS
13 | *cardboard*
14 |
15 | # DESCRIPTION
16 | Cardboard is a unique, scrollable tiling Wayland compositor designed with laptops
17 | in mind, based on *wlroots*.
18 |
19 | Scrollable tiling is an idea that comes from the Gnome extension PaperWM.
20 | In this tiling mode, the windows occupy the height of the screen and are displaced
21 | in a list, such as that the user can scroll through them, as opposed to tiling
22 | by filling the screen with windows disposed in a tree like structure. The main idea
23 | is based on the fact that the user will most likely not look at more than three windows
24 | at the same time.
25 |
26 | # ENVIRONMENT
27 | *CARDBOARD_SOCKET*
28 | The IPC unix domain socket address accepting commands
29 |
30 | # SEE ALSO
31 | *cutter(1)*
32 |
33 | # BUGS
34 | See GitLab issues: https://gitlab.com/cardboardwm/cardboard/-/issues
35 |
36 | # LICENSE
37 | Copyright (C) 2020-2021 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
38 |
39 | This program is free software: you can redistribute it and/or modify it under the terms of the
40 | GNU General Public License as published by the Free Software Foundation, version 3.
41 |
42 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
43 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
44 | See the GNU General Public License for more details.
45 |
46 | You should have received a copy of the GNU General Public License along with this program.
47 | If not, see .
48 |
--------------------------------------------------------------------------------
/libcardboard/src/ipc.cpp:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #include
12 |
13 | #include
14 |
15 | namespace libcardboard::ipc {
16 |
17 | Header interpret_header(const AlignedHeaderBuffer& buffer)
18 | {
19 | if constexpr (std::endian::native == std::endian::little) {
20 | return { *reinterpret_cast(buffer.data()) };
21 | } else {
22 | uint32_t r = *reinterpret_cast(buffer.data());
23 | r = (r & 0x000000ffu) << 24u | (r & 0x0000ff00u) << 8u | (r & 0x00ff0000u) >> 8u | (r & 0xff000000u) >> 24u;
24 |
25 | return { static_cast(r) };
26 | }
27 | }
28 |
29 | AlignedHeaderBuffer create_header_buffer(const Header& header)
30 | {
31 | AlignedHeaderBuffer buffer;
32 |
33 | *reinterpret_cast(buffer.data()) = header.incoming_bytes;
34 |
35 | if constexpr (std::endian::native == std::endian::big) {
36 | uint32_t r = *reinterpret_cast(buffer.data());
37 |
38 | r = ((r >> 24u) & 0x000000ffu) | ((r << 8u) & 0x00ff0000u) | ((r >> 8u) & 0x0000ff00u) | ((r << 24u) & 0xff000000u);
39 |
40 | *reinterpret_cast(buffer.data()) = r;
41 | }
42 |
43 | return buffer;
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/libcardboard/include/cardboard/ipc.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef LIBCARDBOARD_IPC_H_INCLUDED
12 | #define LIBCARDBOARD_IPC_H_INCLUDED
13 |
14 | #include
15 | #include
16 | #include
17 |
18 | /// Utility code for connecting to cardboard's socket and reading and writing the IPC header.
19 | namespace libcardboard::ipc {
20 |
21 | /**
22 | * \brief The IPC header that describes the payload
23 | */
24 | struct Header {
25 | int incoming_bytes;
26 | };
27 |
28 | /**
29 | * \brief The size of the IPC header in bytes
30 | */
31 | constexpr std::size_t HEADER_SIZE = 4;
32 |
33 | /**
34 | * \brief Buffer type where the IPC header can be stored for fast serialization and deserialization
35 | */
36 | struct alignas(alignof(Header)) AlignedHeaderBuffer : std::array {
37 | };
38 |
39 | /**
40 | * \brief Deserializes the data in the buffer into a Header value
41 | */
42 | Header interpret_header(const AlignedHeaderBuffer&);
43 |
44 | /**
45 | * \brief Serializes the Header value into the returned buffer
46 | */
47 | AlignedHeaderBuffer create_header_buffer(const Header&);
48 |
49 | /**
50 | * \brief The environment variable name where CARDBOARD_SOCKET path will be stored
51 | */
52 | [[maybe_unused]] static const char* SOCKET_ENV_VAR = "CARDBOARD_SOCKET";
53 |
54 | };
55 |
56 | #endif //LIBCARDBOARD_IPC_H_INCLUDED
57 |
--------------------------------------------------------------------------------
/cardboard/meson.build:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-3.0-only
2 | wayland_server = dependency('wayland-server')
3 | xkbcommon = dependency('xkbcommon')
4 | xcb = dependency('xcb', required: get_option('xwayland'))
5 |
6 | wlroots_version = '>=0.10.0'
7 | wlroots_proj = subproject(
8 | 'wlroots',
9 | default_options: ['examples=false'],
10 | required: true,
11 | version: wlroots_version,
12 | )
13 |
14 | wlroots = wlroots_proj.get_variable('wlroots')
15 | wlroots_conf = wlroots_proj.get_variable('conf_data')
16 | wlroots_has_xwayland = wlroots_conf.get('WLR_HAS_XWAYLAND') == 1
17 |
18 | if get_option('xwayland').enabled() and not wlroots_has_xwayland
19 | error('Cannot enable Xwayland support in cardboard: wlroots has been built without Xwayland support')
20 | endif
21 | have_xwayland = xcb.found() and wlroots_has_xwayland
22 |
23 | expected_proj = subproject('expected', required: true)
24 | expected = expected_proj.get_variable('expected_dep')
25 |
26 | conf_data = configuration_data()
27 | conf_data.set10('HAVE_XWAYLAND', have_xwayland)
28 |
29 | configure_file(output: 'BuildConfig.h', configuration: conf_data)
30 |
31 | cardboard_deps = [
32 | expected,
33 | wayland_server,
34 | wlroots,
35 | xkbcommon,
36 | server_protos,
37 | ]
38 |
39 | cardboard_sources = files(
40 | 'Cursor.cpp',
41 | 'IPC.cpp',
42 | 'Keyboard.cpp',
43 | 'Layers.cpp',
44 | 'Output.cpp',
45 | 'OutputManager.cpp',
46 | 'Seat.cpp',
47 | 'Server.cpp',
48 | 'Spawn.cpp',
49 | 'View.cpp',
50 | 'Workspace.cpp',
51 | 'XDGView.cpp',
52 | 'ViewOperations.cpp',
53 | 'ViewAnimation.cpp',
54 | 'SurfaceManager.cpp',
55 | 'main.cpp',
56 | 'commands/dispatch_command.cpp'
57 | )
58 |
59 | if have_xwayland
60 | cardboard_deps += xcb
61 | cardboard_sources += 'Xwayland.cpp'
62 | endif
63 |
64 | subdir('wlr_cpp_fixes')
65 |
66 | executable(
67 | 'cardboard',
68 | cardboard_sources,
69 | include_directories: [wlr_cpp_fixes_inc, libcardboard_inc],
70 | dependencies: cardboard_deps,
71 | link_with: libcardboard,
72 | install: true
73 | )
74 |
--------------------------------------------------------------------------------
/libcardboard/include/cardboard/client.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef LIBCARDBOARD_CLIENT_H_INCLUDED
12 | #define LIBCARDBOARD_CLIENT_H_INCLUDED
13 |
14 | #include
15 | #include
16 |
17 | #include
18 |
19 | #include "command_protocol.h"
20 |
21 | #include
22 |
23 | /// Code for sending commands to Cardboard and receiving responses.
24 | namespace libcutter {
25 |
26 | /**
27 | * \brief Manages a connection to the Cardboard IPC server
28 | */
29 | class Client {
30 | public:
31 | Client(const Client&) = delete;
32 | Client(Client&&) noexcept;
33 | ~Client();
34 |
35 | /**
36 | * \brief Serializes and sends a CommandData packet to the server
37 | */
38 | tl::expected send_command(const CommandData&);
39 |
40 | /**
41 | * \brief Waits for a string response from the server
42 | */
43 | tl::expected wait_response();
44 |
45 | private:
46 | Client(int, std::unique_ptr);
47 |
48 | int socket_fd;
49 | std::unique_ptr socket_address;
50 |
51 | friend tl::expected open_client();
52 | };
53 |
54 | /**
55 | * \brief Creates a client connection on the socket path reported by the system
56 | */
57 | tl::expected open_client();
58 |
59 | }
60 |
61 | #endif //LIBCARDBOARD_CLIENT_H_INCLUDED
62 |
--------------------------------------------------------------------------------
/cardboard/ViewOperations.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_VIEW_OPERATIONS_H_INCLUDED
12 | #define CARDBOARD_VIEW_OPERATIONS_H_INCLUDED
13 |
14 | #include "Server.h"
15 | #include "View.h"
16 |
17 | #include "NotNull.h"
18 | #include "StrongAlias.h"
19 |
20 | /**
21 | * \file
22 | * \brief ViewOperations hosts high-level View management functions, handling various low-level details.
23 | *
24 | * For example, if you want to move a View to a Workspace, you should use change_view_workspace instead of
25 | * assigning the workspace_id field manually.
26 | * */
27 |
28 | struct Workspace;
29 |
30 | using AbsoluteScroll = StrongAlias;
31 | using RelativeScroll = StrongAlias;
32 |
33 | /// Sends a view to another workspace
34 | void change_view_workspace(Server& server, View& view, Workspace& new_workspace);
35 |
36 | /// Moves window while maintaining windows manager integrity
37 | void reconfigure_view_position(Server& server, View& view, int x, int y, bool animate = true);
38 |
39 | /// Resizes window while maintaining windows manager integrity
40 | void reconfigure_view_size(Server& server, View& view, int width, int height);
41 |
42 | /// Sets the workspace absolute scroll position to `scroll`
43 | void scroll_workspace(OutputManager&, Workspace&, AbsoluteScroll scroll, bool animate = true);
44 |
45 | /// Scrolls workspace with as `scroll` as offset.
46 | void scroll_workspace(OutputManager&, Workspace&, RelativeScroll scroll, bool animate = true);
47 |
48 | #endif //CARDBOARD_VIEW_OPERATIONS_H_INCLUDED
49 |
--------------------------------------------------------------------------------
/cardboard/Output.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_OUTPUT_H_INCLUDED
12 | #define CARDBOARD_OUTPUT_H_INCLUDED
13 |
14 | extern "C" {
15 | #include
16 | #include
17 | #include
18 | }
19 |
20 | #include
21 |
22 | #include "Layers.h"
23 | #include "Server.h"
24 |
25 | /**
26 | * \file
27 | * \brief This file contains listeners and helper functions for simple output operations.
28 | *
29 | * Outputs are displays.
30 | */
31 |
32 | struct Output {
33 | struct wlr_output* wlr_output;
34 | struct wlr_output_damage* wlr_output_damage;
35 | struct wlr_box usable_area;
36 |
37 | /// Time of last presentation. Use it to calculate the delta time.
38 | struct timespec last_present;
39 |
40 | /// Executed for each frame render per output.
41 | static void frame_handler(struct wl_listener* listener, void* data);
42 | /// Executed as soon as the first pixel is put on the screen;
43 | static void present_handler(struct wl_listener* listener, void* data);
44 | /// Executed when the output is detached.
45 | static void destroy_handler(struct wl_listener* listener, void* data);
46 | /// Executed when the output changes fields (transform, scale etc).
47 | static void commit_handler(struct wl_listener* listener, void* data);
48 | /// Executed when the mode changes (resolution, framerate etc)
49 | static void mode_handler(struct wl_listener* listener, void* data);
50 | };
51 |
52 | /// Registers event listeners and does bookkeeping for a newly added output.
53 | void register_output(Server& server, Output&& output);
54 |
55 | #endif // CARDBOARD_OUTPUT_H_INCLUDED
56 |
--------------------------------------------------------------------------------
/cardboard/SurfaceManager.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_VIEW_MANAGER_H_INCLUDED
12 | #define CARDBOARD_VIEW_MANAGER_H_INCLUDED
13 |
14 | #include "BuildConfig.h"
15 |
16 | #include
17 | #include
18 |
19 | #include "Layers.h"
20 | #include "OptionalRef.h"
21 | #include "OutputManager.h"
22 | #include "View.h"
23 | #include "ViewAnimation.h"
24 | #include "Workspace.h"
25 | #include "Xwayland.h"
26 |
27 | struct SurfaceManager {
28 | std::list> views;
29 | #if HAVE_XWAYLAND
30 | std::list> xwayland_or_surfaces;
31 | #endif
32 | LayerArray layers;
33 |
34 | /// Common mapping procedure for views regardless of their underlying shell.
35 | void map_view(Server&, View&);
36 | /// Common unmapping procedure for views regardless of their underlying shell.
37 | void unmap_view(Server&, View&);
38 | /// Puts the \a view on top.
39 | void move_view_to_front(View&);
40 | void remove_view(ViewAnimation&, View&);
41 |
42 | /**
43 | * \brief Returns the xdg / xwayland / layer_shell surface leaf of the first
44 | * view / layer / xwayland override redirect surface under the cursor.
45 | *
46 | * \a lx and \a ly are root (output layout) coordinates. That is, coordinates relative to the imaginary plane of all surfaces.
47 | *
48 | * \param[out] surface The \c wlr_surface found under the cursor.
49 | * \param[out] sx The x coordinate of the found surface in root coordinates.
50 | * \param[out] sy The y coordinate of the found surface in root coordinates.
51 | */
52 | OptionalRef get_surface_under_cursor(OutputManager&, double lx, double ly, struct wlr_surface*& surface, double& sx, double& sy);
53 | };
54 |
55 | #endif // CARDBOARD_VIEW_MANAGER_H_INCLUDED
56 |
--------------------------------------------------------------------------------
/cutter/main.cpp:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #include
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 |
18 | #include "parse_arguments.h"
19 |
20 | void print_usage(char* argv0)
21 | {
22 | std::cerr << "Usage: " << argv0 << " [args...]" << std::endl;
23 | }
24 |
25 | int main(int argc, char* argv[])
26 | {
27 | if (argc < 2) {
28 | print_usage(argv[0]);
29 | return EXIT_FAILURE;
30 | }
31 |
32 | CommandData command_data = parse_arguments(argc, argv)
33 | .map_error([](const std::string& error) {
34 | std::cerr << "cutter: " << error << std::endl;
35 | exit(EXIT_FAILURE);
36 | })
37 | .value();
38 |
39 | libcutter::Client client = libcutter::open_client()
40 | .map_error([](const std::string& error) {
41 | std::cerr << "cutter: " << error << std::endl;
42 | exit(EXIT_FAILURE);
43 | })
44 | .value();
45 |
46 | client.send_command(command_data)
47 | .map_error([](const std::string& error) {
48 | std::cerr << "cutter: " << error << std::endl;
49 | exit(EXIT_FAILURE);
50 | });
51 |
52 | std::string response = client.wait_response()
53 | .map_error([](int error_code) {
54 | std::cerr << "cutter: error code " << error_code << std::endl;
55 | exit(EXIT_FAILURE);
56 | })
57 | .value();
58 |
59 | std::cout << response;
60 |
61 | return 0;
62 | }
63 |
--------------------------------------------------------------------------------
/cardboard/Cursor.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_CURSOR_H_INCLUDED
12 | #define CARDBOARD_CURSOR_H_INCLUDED
13 |
14 | extern "C" {
15 | #include
16 | #include
17 | #include
18 | }
19 |
20 | #include
21 |
22 | #include "OptionalRef.h"
23 | #include "OutputManager.h"
24 |
25 | struct Server;
26 | struct Seat;
27 |
28 | // TODO: rename to Cursor after namespacing all structs
29 | struct SeatCursor {
30 | struct wlr_cursor* wlr_cursor;
31 | struct wlr_xcursor_manager* wlr_xcursor_manager;
32 | OptionalRef image_surface_destroy_listener;
33 |
34 | private:
35 | /// Called when the surface of the mouse pointer is destroyed by the client.
36 | static void image_surface_destroy_handler(struct wl_listener* listener, void* data);
37 | };
38 |
39 | void init_cursor(OutputManager&, SeatCursor& cursor);
40 |
41 | /**
42 | * \brief Sets the cursor image to an xcursor named \a image.
43 | *
44 | * \param image - xcursor image name
45 | */
46 | void cursor_set_image(Server& server, Seat& seat, SeatCursor& cursor, const char* image);
47 | /**
48 | * \brief Sets the cursor image to a given \a surface with a given hotspot.
49 | *
50 | * The hotspot is the point of the cursor that interacts with the elements on the screen.
51 | * For a normal pointer, the hotspot is usually the tip of the cursor image.
52 | * For a cross pointer, the hotspot is usually in the center.
53 | */
54 | void cursor_set_image_surface(Server& server, Seat& seat, SeatCursor& cursor, struct wlr_surface* surface, int32_t hotspot_x, int32_t hotspot_y);
55 | /**
56 | * \brief Sets the cursor image according to the surface underneath,
57 | * and sends the appropriate cursor events to the surface underneath, if any.
58 | */
59 | void cursor_rebase(Server& server, Seat& seat, SeatCursor& cursor, uint32_t time = 0);
60 |
61 | /// Warps the cursor to the given output layout coordinates.
62 | void cursor_warp(Server& server, Seat& seat, SeatCursor& cursor, int lx, int ly);
63 |
64 | #endif // CARDBOARD_CURSOR_H_INCLUDED
65 |
--------------------------------------------------------------------------------
/cardboard/Layers.h:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-only
2 | /*
3 | Copyright (C) 2020 Alexandru-Iulian Magan, Tudor-Ioan Roman, and contributors.
4 |
5 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
6 |
7 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 |
9 | You should have received a copy of the GNU General Public License along with this program. If not, see .
10 | */
11 | #ifndef CARDBOARD_LAYERS_H_INCLUDED
12 | #define CARDBOARD_LAYERS_H_INCLUDED
13 |
14 | extern "C" {
15 | #include
16 | #include
17 | #include
18 |
19 | #include
20 | }
21 |
22 | #include
23 | #include
24 |
25 | #include "NotNull.h"
26 | #include "OptionalRef.h"
27 |
28 | struct Server;
29 | struct Output;
30 | struct OutputManager;
31 |
32 | /**
33 | * \brief Represents a layer_surface from the layer shell in the compositor.
34 | */
35 | struct LayerSurface {
36 | struct wlr_layer_surface_v1* surface;
37 | struct wlr_box geometry;
38 | enum zwlr_layer_shell_v1_layer layer;
39 | OptionalRef