From 8c191d2d418ad56b5bd48032e93385a0700dc8e7 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Sun, 3 Apr 2022 11:59:31 +0000 Subject: [PATCH] Introduce kiwmi_strata With the migration to wlr_scene, some objects (desktop, output etc) will no longer have any reason to care about individual shells and similar; handling each one on its own would introduce code that is, from their perspective, over-complicated. Strata (sg. stratum; this name was chosen to avoid confusion with the over-used 'layer') represent logical layers of surfaces on the desktop, such as every layer shell layer, one for xdg shell, another for popups. --- include/desktop/layer_shell.h | 2 +- include/desktop/stratum.h | 33 +++++++++++++++++++++++++++++++++ kiwmi/desktop/stratum.c | 33 +++++++++++++++++++++++++++++++++ kiwmi/meson.build | 1 + 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 include/desktop/stratum.h create mode 100644 kiwmi/desktop/stratum.c diff --git a/include/desktop/layer_shell.h b/include/desktop/layer_shell.h index 837275e..cec4397 100644 --- a/include/desktop/layer_shell.h +++ b/include/desktop/layer_shell.h @@ -19,7 +19,7 @@ struct kiwmi_layer { struct wl_list link; struct wlr_layer_surface_v1 *layer_surface; - uint32_t layer; + uint32_t layer; // enum zwlr_layer_shell_v1_layer struct kiwmi_output *output; diff --git a/include/desktop/stratum.h b/include/desktop/stratum.h new file mode 100644 index 0000000..33ad252 --- /dev/null +++ b/include/desktop/stratum.h @@ -0,0 +1,33 @@ +/* Copyright (c), Niclas Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef KIWMI_DESKTOP_STRATUM_H +#define KIWMI_DESKTOP_STRATUM_H + +#include + +/** + * A stratum is a layer in the scene-graph (the name was chosen to avoid + * confusion with layer-shell). The root node contains a scene_tree for each + * stratum, which itself contains a scene_tree per output. + */ + +// There are some assumptions made about the values, don't mindlessly change. +enum kiwmi_stratum { + KIWMI_STRATUM_LS_BACKGROUND, // LS == layer_shell + KIWMI_STRATUM_LS_BOTTOM, + KIWMI_STRATUM_NORMAL, + KIWMI_STRATUM_LS_TOP, + KIWMI_STRATUM_LS_OVERLAY, + KIWMI_STRATUM_POPUPS, + KIWMI_STRATA_COUNT, + KIWMI_STRATUM_NONE = KIWMI_STRATA_COUNT, +}; + +enum kiwmi_stratum stratum_from_layer_shell_layer(uint32_t layer); + +#endif /* KIWMI_DESKTOP_STRATUM_H */ diff --git a/kiwmi/desktop/stratum.c b/kiwmi/desktop/stratum.c new file mode 100644 index 0000000..dd9adc0 --- /dev/null +++ b/kiwmi/desktop/stratum.c @@ -0,0 +1,33 @@ +/* Copyright (c), Niclas Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +#include "desktop/stratum.h" +#include "wlr-layer-shell-unstable-v1-protocol.h" + +enum kiwmi_stratum +stratum_from_layer_shell_layer(uint32_t layer) +{ + switch (layer) { + case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND: + return KIWMI_STRATUM_LS_BACKGROUND; + case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM: + return KIWMI_STRATUM_LS_BOTTOM; + case ZWLR_LAYER_SHELL_V1_LAYER_TOP: + return KIWMI_STRATUM_LS_TOP; + case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY: + return KIWMI_STRATUM_LS_OVERLAY; + default: + // We should update our codebase to support the layer + wlr_log( + WLR_ERROR, "No matching stratum for layer_shell layer %d", layer); + return KIWMI_STRATUM_NONE; + } +} diff --git a/kiwmi/meson.build b/kiwmi/meson.build index b61fac3..eb3a962 100644 --- a/kiwmi/meson.build +++ b/kiwmi/meson.build @@ -5,6 +5,7 @@ kiwmi_sources = files( 'desktop/desktop.c', 'desktop/layer_shell.c', 'desktop/output.c', + 'desktop/stratum.c', 'desktop/view.c', 'desktop/xdg_shell.c', 'input/cursor.c',