Skip to content

Commit c30335b

Browse files
committed
Add visually apparent SSD (nonfunctional)
1 parent e4619ef commit c30335b

File tree

8 files changed

+84
-3
lines changed

8 files changed

+84
-3
lines changed

src/decorations/ssd.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "ssd.hpp"
2+
3+
#include "surface/view.hpp"
4+
#include "server.hpp"
5+
6+
constexpr uint8_t TITLEBAR_HEIGHT = 24;
7+
constexpr uint32_t TITLEBAR_COLOR = 0x303030;
8+
9+
static consteval std::array<float, 4> rrggbb_to_floats(uint32_t rrggbb) {
10+
return std::array<float, 4>(
11+
{(float) (rrggbb >> 16 & 0xff) / 255.0f, (float) (rrggbb >> 8 & 0xff) / 255.0f, (float) (rrggbb & 0xff) / 255.0f, 1.0});
12+
}
13+
14+
Ssd::Ssd(View& parent) noexcept : view(parent) {
15+
scene_tree = wlr_scene_tree_create(wlr_scene_tree_from_node(parent.scene_node));
16+
wlr_scene_node_raise_to_top(&scene_tree->node);
17+
wlr_scene_node_set_position(&scene_tree->node, 0, -TITLEBAR_HEIGHT);
18+
wlr_scene_node_set_enabled(&scene_tree->node, true);
19+
20+
auto color = rrggbb_to_floats(TITLEBAR_COLOR);
21+
titlebar_rect = wlr_scene_rect_create(scene_tree, parent.current.width, TITLEBAR_HEIGHT, color.data());
22+
wlr_scene_node_set_enabled(&titlebar_rect->node, true);
23+
}
24+
25+
void Ssd::update() const {
26+
wlr_scene_rect_set_size(titlebar_rect, view.get_geometry().width, TITLEBAR_HEIGHT);
27+
wlr_scene_node_raise_to_top(&scene_tree->node);
28+
}
29+
30+
Ssd::~Ssd() {
31+
wlr_scene_node_destroy(&scene_tree->node);
32+
}

src/decorations/ssd.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef MAGPIE_SSD_HPP
2+
#define MAGPIE_SSD_HPP
3+
4+
#include "types.hpp"
5+
6+
#include <memory>
7+
8+
#include "wlr-wrap-start.hpp"
9+
#include <wlr/types/wlr_scene.h>
10+
#include "wlr-wrap-end.hpp"
11+
12+
class Ssd final : public std::enable_shared_from_this<Ssd> {
13+
public:
14+
View& view;
15+
wlr_scene_tree* scene_tree = nullptr;
16+
wlr_scene_rect* titlebar_rect = nullptr;
17+
18+
Ssd(View& parent) noexcept;
19+
~Ssd();
20+
21+
void update() const;
22+
};
23+
24+
#endif

src/surface/xdg_decoration.cpp renamed to src/decorations/xdg_decoration.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "xdg_decoration.hpp"
22

3-
#include "view.hpp"
3+
#include "ssd.hpp"
4+
#include "surface/view.hpp"
45

56
#include "wlr-wrap-start.hpp"
67
#include <wlr/util/log.h>
@@ -14,10 +15,20 @@ static void xdg_decoration_destroy_notify(wl_listener* listener, [[maybe_unused]
1415
deco.view.set_decoration(nullptr);
1516
}
1617

18+
static void xdg_decoration_request_mode_notify(wl_listener* listener, [[maybe_unused]] void* data) {
19+
wlr_log(WLR_DEBUG, "wlr_xdg_toplevel_decoration_v1.events.request_mode(listener=%p, data=%p)", (void*) listener, data);
20+
21+
XdgDecoration& deco = magpie_container_of(listener, deco, request_mode);
22+
23+
deco.view.ssd.emplace(deco.view);
24+
}
25+
1726
XdgDecoration::XdgDecoration(XdgView& view, wlr_xdg_toplevel_decoration_v1& deco) noexcept
1827
: listeners(*this), view(view), wlr(deco) {
1928
listeners.destroy.notify = xdg_decoration_destroy_notify;
2029
wl_signal_add(&deco.events.destroy, &listeners.destroy);
30+
listeners.request_mode.notify = xdg_decoration_request_mode_notify;
31+
wl_signal_add(&deco.events.request_mode, &listeners.request_mode);
2132
}
2233

2334
XdgDecoration::~XdgDecoration() noexcept {

src/surface/xdg_decoration.hpp renamed to src/decorations/xdg_decoration.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class XdgDecoration : public std::enable_shared_from_this<XdgDecoration> {
1414
struct Listeners {
1515
std::reference_wrapper<XdgDecoration> parent;
1616
wl_listener destroy = {};
17+
wl_listener request_mode = {};
1718
explicit Listeners(XdgDecoration& parent) noexcept : parent(parent) {}
1819
};
1920

src/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ magpie_sources = [
44
'output.cpp',
55
'server.cpp',
66
'xwayland.cpp',
7+
'decorations/xdg_decoration.cpp',
8+
'decorations/ssd.cpp',
79
'input/constraint.cpp',
810
'input/cursor.cpp',
911
'input/keyboard.cpp',
@@ -14,7 +16,6 @@ magpie_sources = [
1416
'surface/popup.cpp',
1517
'surface/subsurface.cpp',
1618
'surface/view.cpp',
17-
'surface/xdg_decoration.cpp',
1819
'surface/xdg_view.cpp',
1920
'surface/xwayland_view.cpp',
2021
budgie_keyboard_shortcuts_protocol,

src/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include "server.hpp"
22

3+
#include "decorations/xdg_decoration.hpp"
34
#include "input/seat.hpp"
45
#include "output.hpp"
56
#include "surface/layer.hpp"
67
#include "surface/popup.hpp"
78
#include "surface/surface.hpp"
89
#include "surface/view.hpp"
9-
#include "surface/xdg_decoration.hpp"
1010
#include "types.hpp"
1111
#include "xwayland.hpp"
1212

src/surface/view.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ void View::set_size(const int32_t width, const int32_t height) {
176176
current.width = bounded_width;
177177
current.height = bounded_height;
178178
impl_set_size(current.width, current.height);
179+
if (ssd.has_value()) {
180+
ssd->update();
181+
}
179182
}
180183

181184
void View::update_outputs(const bool ignore_previous) const {
@@ -249,6 +252,10 @@ void View::set_activated(const bool activated) {
249252
wlr_seat_keyboard_notify_clear_focus(seat->wlr);
250253
seat->set_constraint(nullptr);
251254
}
255+
256+
if (ssd.has_value()) {
257+
ssd->update();
258+
}
252259
}
253260

254261
void View::set_placement(const ViewPlacement new_placement, const bool force) {
@@ -294,6 +301,9 @@ void View::stack() {
294301
impl_set_fullscreen(false);
295302
set_geometry(previous.x, previous.y, previous.width, previous.height);
296303
update_outputs();
304+
if (ssd.has_value()) {
305+
ssd->update();
306+
}
297307
}
298308

299309
bool View::maximize() {

src/surface/view.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef MAGPIE_VIEW_HPP
22
#define MAGPIE_VIEW_HPP
33

4+
#include "decorations/ssd.hpp"
45
#include "foreign_toplevel.hpp"
56
#include "input/cursor.hpp"
67
#include "surface.hpp"
@@ -21,6 +22,7 @@ struct View : public Surface {
2122
wlr_box current = {};
2223
wlr_box previous = {};
2324
std::optional<ForeignToplevelHandle> toplevel_handle;
25+
std::optional<Ssd> ssd;
2426

2527
~View() noexcept override = default;
2628

0 commit comments

Comments
 (0)