Skip to content

Commit e4619ef

Browse files
committed
Wire up SSDs for XDG windows
1 parent 221970d commit e4619ef

8 files changed

+93
-0
lines changed

src/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ magpie_sources = [
1414
'surface/popup.cpp',
1515
'surface/subsurface.cpp',
1616
'surface/view.cpp',
17+
'surface/xdg_decoration.cpp',
1718
'surface/xdg_view.cpp',
1819
'surface/xwayland_view.cpp',
1920
budgie_keyboard_shortcuts_protocol,

src/server.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "surface/popup.hpp"
77
#include "surface/surface.hpp"
88
#include "surface/view.hpp"
9+
#include "surface/xdg_decoration.hpp"
910
#include "types.hpp"
1011
#include "xwayland.hpp"
1112

@@ -253,6 +254,25 @@ static void new_xdg_toplevel_notify(wl_listener* listener, void* data) {
253254
server.views.emplace_back(std::make_shared<XdgView>(server, xdg_toplevel));
254255
}
255256

257+
static void new_toplevel_decoration_notify(wl_listener* listener, void* data) {
258+
wlr_log(WLR_DEBUG, "wlr_xdg_decoration_v1.events.new_toplevel_decoration(listener=%p, data=%p)", (void*) listener, data);
259+
260+
if (data == nullptr) {
261+
wlr_log(WLR_ERROR, "No data passed to wlr_xdg_decoration_v1.events.new_toplevel_decoration");
262+
return;
263+
}
264+
265+
auto& xdg_toplevel_decoration = *static_cast<wlr_xdg_toplevel_decoration_v1*>(data);
266+
267+
auto* view = static_cast<XdgView*>(xdg_toplevel_decoration.toplevel->base->data);
268+
if (view == nullptr) {
269+
wlr_log(WLR_ERROR, "xdg_toplevel_decoration_v1 created for toplevel surface without data ptr set");
270+
return;
271+
}
272+
273+
view->set_decoration(std::make_shared<XdgDecoration>(*view, xdg_toplevel_decoration));
274+
}
275+
256276
static void new_layer_surface_notify(wl_listener* listener, void* data) {
257277
wlr_log(WLR_DEBUG, "wlr_layer_shell_v1.events.new_surface(listener=%p, data=%p)", (void*) listener, data);
258278

@@ -579,6 +599,10 @@ Server::Server() : listeners(*this) {
579599
listeners.xdg_shell_new_xdg_toplevel.notify = new_xdg_toplevel_notify;
580600
wl_signal_add(&xdg_shell->events.new_toplevel, &listeners.xdg_shell_new_xdg_toplevel);
581601

602+
xdg_decoration_manager = wlr_xdg_decoration_manager_v1_create(display);
603+
listeners.xdg_decoration_new_toplevel_decoration.notify = new_toplevel_decoration_notify;
604+
wl_signal_add(&xdg_decoration_manager->events.new_toplevel_decoration, &listeners.xdg_decoration_new_toplevel_decoration);
605+
582606
layer_shell = wlr_layer_shell_v1_create(display, 4);
583607
listeners.layer_shell_new_layer_surface.notify = new_layer_surface_notify;
584608
wl_signal_add(&layer_shell->events.new_surface, &listeners.layer_shell_new_layer_surface);

src/server.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <wlr/types/wlr_screencopy_v1.h>
2727
#include <wlr/types/wlr_security_context_v1.h>
2828
#include <wlr/types/wlr_xdg_activation_v1.h>
29+
#include <wlr/types/wlr_xdg_decoration_v1.h>
2930
#include <wlr/types/wlr_xdg_shell.h>
3031
#include "wlr-wrap-end.hpp"
3132

@@ -43,6 +44,7 @@ class Server final : public std::enable_shared_from_this<Server> {
4344
struct Listeners {
4445
std::reference_wrapper<Server> parent;
4546
wl_listener xdg_shell_new_xdg_toplevel = {};
47+
wl_listener xdg_decoration_new_toplevel_decoration = {};
4648
wl_listener layer_shell_new_layer_surface = {};
4749
wl_listener activation_request_activation = {};
4850
wl_listener backend_new_output = {};
@@ -71,6 +73,7 @@ class Server final : public std::enable_shared_from_this<Server> {
7173
std::array<wlr_scene_tree*, MAGPIE_SCENE_LAYER_LOCK + 1> scene_layers = {};
7274

7375
wlr_xdg_shell* xdg_shell;
76+
wlr_xdg_decoration_manager_v1* xdg_decoration_manager;
7477

7578
wlr_xdg_activation_v1* xdg_activation;
7679

src/surface/view.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class XdgView final : public View {
9191
public:
9292
Server& server;
9393
wlr_xdg_toplevel& wlr;
94+
std::shared_ptr<XdgDecoration> deco = nullptr;
9495

9596
XdgView(Server& server, wlr_xdg_toplevel& xdg_toplevel) noexcept;
9697
~XdgView() noexcept override;
@@ -106,6 +107,8 @@ class XdgView final : public View {
106107
void unmap() override;
107108
void close() override;
108109

110+
void set_decoration(std::shared_ptr<XdgDecoration> deco);
111+
109112
protected:
110113
void impl_set_position(int32_t x, int32_t y) override;
111114
void impl_set_size(int32_t width, int32_t height) override;

src/surface/xdg_decoration.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "xdg_decoration.hpp"
2+
3+
#include "view.hpp"
4+
5+
#include "wlr-wrap-start.hpp"
6+
#include <wlr/util/log.h>
7+
#include "wlr-wrap-end.hpp"
8+
9+
static void xdg_decoration_destroy_notify(wl_listener* listener, [[maybe_unused]] void* data) {
10+
wlr_log(WLR_DEBUG, "wlr_xdg_toplevel_decoration_v1.events.destroy(listener=%p, data=%p)", (void*) listener, data);
11+
12+
XdgDecoration& deco = magpie_container_of(listener, deco, destroy);
13+
14+
deco.view.set_decoration(nullptr);
15+
}
16+
17+
XdgDecoration::XdgDecoration(XdgView& view, wlr_xdg_toplevel_decoration_v1& deco) noexcept
18+
: listeners(*this), view(view), wlr(deco) {
19+
listeners.destroy.notify = xdg_decoration_destroy_notify;
20+
wl_signal_add(&deco.events.destroy, &listeners.destroy);
21+
}
22+
23+
XdgDecoration::~XdgDecoration() noexcept {
24+
wl_list_remove(&listeners.destroy.link);
25+
}

src/surface/xdg_decoration.hpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef MAGPIE_XDG_DECORATION_HPP
2+
#define MAGPIE_XDG_DECORATION_HPP
3+
4+
#include "types.hpp"
5+
6+
#include <memory>
7+
8+
#include "wlr-wrap-start.hpp"
9+
#include <wlr/types/wlr_xdg_decoration_v1.h>
10+
#include "wlr-wrap-end.hpp"
11+
12+
class XdgDecoration : public std::enable_shared_from_this<XdgDecoration> {
13+
public:
14+
struct Listeners {
15+
std::reference_wrapper<XdgDecoration> parent;
16+
wl_listener destroy = {};
17+
explicit Listeners(XdgDecoration& parent) noexcept : parent(parent) {}
18+
};
19+
20+
private:
21+
Listeners listeners;
22+
23+
public:
24+
XdgView& view;
25+
wlr_xdg_toplevel_decoration_v1& wlr;
26+
27+
XdgDecoration(XdgView& view, wlr_xdg_toplevel_decoration_v1& deco) noexcept;
28+
~XdgDecoration() noexcept;
29+
};
30+
31+
#endif

src/surface/xdg_view.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ XdgView::XdgView(Server& server, wlr_xdg_toplevel& xdg_toplevel) noexcept
193193
scene_node = &scene_tree->node;
194194

195195
scene_node->data = this;
196+
wlr.base->data = this;
196197
wlr.base->surface->data = this;
197198

198199
toplevel_handle.emplace(*this);
@@ -321,6 +322,10 @@ void XdgView::close() {
321322
wlr_xdg_toplevel_send_close(&wlr);
322323
}
323324

325+
void XdgView::set_decoration(std::shared_ptr<XdgDecoration> new_deco) {
326+
this->deco = std::move(new_deco);
327+
}
328+
324329
void XdgView::impl_set_position(const int32_t x, const int32_t y) {
325330
(void) x;
326331
(void) y;

src/types.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PointerConstraint;
1313
struct Surface;
1414
struct View;
1515
class XdgView;
16+
class XdgDecoration;
1617
class XWaylandView;
1718
class Layer;
1819
class Subsurface;

0 commit comments

Comments
 (0)