From c30335b38f58e492d27b8a68bdb8c2f1c645132a Mon Sep 17 00:00:00 2001 From: Campbell Jones Date: Sat, 24 Aug 2024 17:21:28 -0400 Subject: [PATCH] Add visually apparent SSD (nonfunctional) --- src/decorations/ssd.cpp | 32 +++++++++++++++++++ src/decorations/ssd.hpp | 24 ++++++++++++++ .../xdg_decoration.cpp | 13 +++++++- .../xdg_decoration.hpp | 1 + src/meson.build | 3 +- src/server.cpp | 2 +- src/surface/view.cpp | 10 ++++++ src/surface/view.hpp | 2 ++ 8 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 src/decorations/ssd.cpp create mode 100644 src/decorations/ssd.hpp rename src/{surface => decorations}/xdg_decoration.cpp (60%) rename src/{surface => decorations}/xdg_decoration.hpp (95%) diff --git a/src/decorations/ssd.cpp b/src/decorations/ssd.cpp new file mode 100644 index 000000000..177865070 --- /dev/null +++ b/src/decorations/ssd.cpp @@ -0,0 +1,32 @@ +#include "ssd.hpp" + +#include "surface/view.hpp" +#include "server.hpp" + +constexpr uint8_t TITLEBAR_HEIGHT = 24; +constexpr uint32_t TITLEBAR_COLOR = 0x303030; + +static consteval std::array rrggbb_to_floats(uint32_t rrggbb) { + return std::array( + {(float) (rrggbb >> 16 & 0xff) / 255.0f, (float) (rrggbb >> 8 & 0xff) / 255.0f, (float) (rrggbb & 0xff) / 255.0f, 1.0}); +} + +Ssd::Ssd(View& parent) noexcept : view(parent) { + scene_tree = wlr_scene_tree_create(wlr_scene_tree_from_node(parent.scene_node)); + wlr_scene_node_raise_to_top(&scene_tree->node); + wlr_scene_node_set_position(&scene_tree->node, 0, -TITLEBAR_HEIGHT); + wlr_scene_node_set_enabled(&scene_tree->node, true); + + auto color = rrggbb_to_floats(TITLEBAR_COLOR); + titlebar_rect = wlr_scene_rect_create(scene_tree, parent.current.width, TITLEBAR_HEIGHT, color.data()); + wlr_scene_node_set_enabled(&titlebar_rect->node, true); +} + +void Ssd::update() const { + wlr_scene_rect_set_size(titlebar_rect, view.get_geometry().width, TITLEBAR_HEIGHT); + wlr_scene_node_raise_to_top(&scene_tree->node); +} + +Ssd::~Ssd() { + wlr_scene_node_destroy(&scene_tree->node); +} diff --git a/src/decorations/ssd.hpp b/src/decorations/ssd.hpp new file mode 100644 index 000000000..9e5683695 --- /dev/null +++ b/src/decorations/ssd.hpp @@ -0,0 +1,24 @@ +#ifndef MAGPIE_SSD_HPP +#define MAGPIE_SSD_HPP + +#include "types.hpp" + +#include + +#include "wlr-wrap-start.hpp" +#include +#include "wlr-wrap-end.hpp" + +class Ssd final : public std::enable_shared_from_this { + public: + View& view; + wlr_scene_tree* scene_tree = nullptr; + wlr_scene_rect* titlebar_rect = nullptr; + + Ssd(View& parent) noexcept; + ~Ssd(); + + void update() const; +}; + +#endif diff --git a/src/surface/xdg_decoration.cpp b/src/decorations/xdg_decoration.cpp similarity index 60% rename from src/surface/xdg_decoration.cpp rename to src/decorations/xdg_decoration.cpp index 3fb3bb843..c2ae37d77 100644 --- a/src/surface/xdg_decoration.cpp +++ b/src/decorations/xdg_decoration.cpp @@ -1,6 +1,7 @@ #include "xdg_decoration.hpp" -#include "view.hpp" +#include "ssd.hpp" +#include "surface/view.hpp" #include "wlr-wrap-start.hpp" #include @@ -14,10 +15,20 @@ static void xdg_decoration_destroy_notify(wl_listener* listener, [[maybe_unused] deco.view.set_decoration(nullptr); } +static void xdg_decoration_request_mode_notify(wl_listener* listener, [[maybe_unused]] void* data) { + wlr_log(WLR_DEBUG, "wlr_xdg_toplevel_decoration_v1.events.request_mode(listener=%p, data=%p)", (void*) listener, data); + + XdgDecoration& deco = magpie_container_of(listener, deco, request_mode); + + deco.view.ssd.emplace(deco.view); +} + XdgDecoration::XdgDecoration(XdgView& view, wlr_xdg_toplevel_decoration_v1& deco) noexcept : listeners(*this), view(view), wlr(deco) { listeners.destroy.notify = xdg_decoration_destroy_notify; wl_signal_add(&deco.events.destroy, &listeners.destroy); + listeners.request_mode.notify = xdg_decoration_request_mode_notify; + wl_signal_add(&deco.events.request_mode, &listeners.request_mode); } XdgDecoration::~XdgDecoration() noexcept { diff --git a/src/surface/xdg_decoration.hpp b/src/decorations/xdg_decoration.hpp similarity index 95% rename from src/surface/xdg_decoration.hpp rename to src/decorations/xdg_decoration.hpp index df1fb3e72..05b34a3b3 100644 --- a/src/surface/xdg_decoration.hpp +++ b/src/decorations/xdg_decoration.hpp @@ -14,6 +14,7 @@ class XdgDecoration : public std::enable_shared_from_this { struct Listeners { std::reference_wrapper parent; wl_listener destroy = {}; + wl_listener request_mode = {}; explicit Listeners(XdgDecoration& parent) noexcept : parent(parent) {} }; diff --git a/src/meson.build b/src/meson.build index d5bd90a33..45c0ed20a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,6 +4,8 @@ magpie_sources = [ 'output.cpp', 'server.cpp', 'xwayland.cpp', + 'decorations/xdg_decoration.cpp', + 'decorations/ssd.cpp', 'input/constraint.cpp', 'input/cursor.cpp', 'input/keyboard.cpp', @@ -14,7 +16,6 @@ magpie_sources = [ 'surface/popup.cpp', 'surface/subsurface.cpp', 'surface/view.cpp', - 'surface/xdg_decoration.cpp', 'surface/xdg_view.cpp', 'surface/xwayland_view.cpp', budgie_keyboard_shortcuts_protocol, diff --git a/src/server.cpp b/src/server.cpp index dbed9646e..73070bcb6 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,12 +1,12 @@ #include "server.hpp" +#include "decorations/xdg_decoration.hpp" #include "input/seat.hpp" #include "output.hpp" #include "surface/layer.hpp" #include "surface/popup.hpp" #include "surface/surface.hpp" #include "surface/view.hpp" -#include "surface/xdg_decoration.hpp" #include "types.hpp" #include "xwayland.hpp" diff --git a/src/surface/view.cpp b/src/surface/view.cpp index 05d2e72c9..923056e94 100644 --- a/src/surface/view.cpp +++ b/src/surface/view.cpp @@ -176,6 +176,9 @@ void View::set_size(const int32_t width, const int32_t height) { current.width = bounded_width; current.height = bounded_height; impl_set_size(current.width, current.height); + if (ssd.has_value()) { + ssd->update(); + } } void View::update_outputs(const bool ignore_previous) const { @@ -249,6 +252,10 @@ void View::set_activated(const bool activated) { wlr_seat_keyboard_notify_clear_focus(seat->wlr); seat->set_constraint(nullptr); } + + if (ssd.has_value()) { + ssd->update(); + } } void View::set_placement(const ViewPlacement new_placement, const bool force) { @@ -294,6 +301,9 @@ void View::stack() { impl_set_fullscreen(false); set_geometry(previous.x, previous.y, previous.width, previous.height); update_outputs(); + if (ssd.has_value()) { + ssd->update(); + } } bool View::maximize() { diff --git a/src/surface/view.hpp b/src/surface/view.hpp index bfc0fc76e..b4e993d64 100644 --- a/src/surface/view.hpp +++ b/src/surface/view.hpp @@ -1,6 +1,7 @@ #ifndef MAGPIE_VIEW_HPP #define MAGPIE_VIEW_HPP +#include "decorations/ssd.hpp" #include "foreign_toplevel.hpp" #include "input/cursor.hpp" #include "surface.hpp" @@ -21,6 +22,7 @@ struct View : public Surface { wlr_box current = {}; wlr_box previous = {}; std::optional toplevel_handle; + std::optional ssd; ~View() noexcept override = default;