Skip to content

Commit 1f5c747

Browse files
committed
LayerSubsurface -> Subsurface
1 parent 03cef50 commit 1f5c747

File tree

11 files changed

+122
-53
lines changed

11 files changed

+122
-53
lines changed

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ magpie_sources = [
1010
'input/seat.cpp',
1111
'surface/layer.cpp',
1212
'surface/popup.cpp',
13+
'surface/subsurface.cpp',
1314
'surface/view.cpp',
1415
'surface/xdg_view.cpp',
1516
'surface/xwayland_view.cpp',

src/surface/layer.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "popup.hpp"
55
#include "server.hpp"
66
#include "surface.hpp"
7+
#include "subsurface.hpp"
78
#include "types.hpp"
89

910
#include "wlr-wrap-start.hpp"
@@ -29,35 +30,6 @@ static magpie_scene_layer_t magpie_layer_from_wlr_layer(const zwlr_layer_shell_v
2930
}
3031
}
3132

32-
static void subsurface_map_notify(wl_listener* listener, [[maybe_unused]] void* data) {
33-
wlr_log(WLR_DEBUG, "wlr_subsurface.events.map(listener=%p, data=%p)", (void*) listener, data);
34-
35-
LayerSubsurface& subsurface = magpie_container_of(listener, subsurface, map);
36-
37-
wlr_surface_send_enter(subsurface.wlr->surface, &subsurface.parent.output.wlr);
38-
}
39-
40-
static void subsurface_destroy_notify(wl_listener* listener, [[maybe_unused]] void* data) {
41-
wlr_log(WLR_DEBUG, "wlr_subsurface.events.destroy(listener=%p, data=%p)", (void*) listener, data);
42-
43-
LayerSubsurface& subsurface = magpie_container_of(listener, subsurface, destroy);
44-
45-
subsurface.parent.subsurfaces.erase(subsurface.shared_from_this());
46-
}
47-
48-
LayerSubsurface::LayerSubsurface(Layer& parent, wlr_subsurface& subsurface) noexcept
49-
: listeners(*this), parent(parent), wlr(&subsurface) {
50-
listeners.map.notify = subsurface_map_notify;
51-
wl_signal_add(&subsurface.surface->events.map, &listeners.map);
52-
listeners.destroy.notify = subsurface_destroy_notify;
53-
wl_signal_add(&subsurface.events.destroy, &listeners.destroy);
54-
}
55-
56-
LayerSubsurface::~LayerSubsurface() noexcept {
57-
wl_list_remove(&listeners.map.link);
58-
wl_list_remove(&listeners.destroy.link);
59-
}
60-
6133
/* Called when the surface is mapped, or ready to display on-screen. */
6234
static void wlr_layer_surface_v1_map_notify(wl_listener* listener, [[maybe_unused]] void* data) {
6335
wlr_log(WLR_DEBUG, "wlr_layer_surface_v1.events.map(listener=%p, data=%p)", (void*) listener, data);
@@ -141,7 +113,7 @@ static void wlr_layer_surface_v1_new_subsurface_notify(wl_listener* listener, vo
141113
Layer& layer = magpie_container_of(listener, layer, new_subsurface);
142114
auto& subsurface = *static_cast<wlr_subsurface*>(data);
143115

144-
layer.subsurfaces.emplace(std::make_shared<LayerSubsurface>(layer, subsurface));
116+
layer.subsurfaces.emplace(std::make_shared<Subsurface>(layer, subsurface));
145117
}
146118

147119
Layer::Layer(Output& output, wlr_layer_surface_v1& surface) noexcept

src/surface/layer.hpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class Layer final : public Surface {
3737
wlr_scene_layer_surface_v1* scene_surface;
3838
magpie_scene_layer_t scene_layer = MAGPIE_SCENE_LAYER_NORMAL;
3939

40-
std::set<std::shared_ptr<LayerSubsurface>> subsurfaces;
41-
4240
Layer(Output& output, wlr_layer_surface_v1& surface) noexcept;
4341
~Layer() noexcept override;
4442

@@ -47,24 +45,4 @@ class Layer final : public Surface {
4745
[[nodiscard]] bool is_view() const override;
4846
};
4947

50-
class LayerSubsurface final : public std::enable_shared_from_this<LayerSubsurface> {
51-
public:
52-
struct Listeners {
53-
std::reference_wrapper<LayerSubsurface> parent;
54-
wl_listener map = {};
55-
wl_listener destroy = {};
56-
explicit Listeners(LayerSubsurface& parent) noexcept : parent(parent) {}
57-
};
58-
59-
private:
60-
Listeners listeners;
61-
62-
public:
63-
Layer& parent;
64-
wlr_subsurface* wlr;
65-
66-
LayerSubsurface(Layer& parent, wlr_subsurface& subsurface) noexcept;
67-
~LayerSubsurface() noexcept;
68-
};
69-
7048
#endif

src/surface/popup.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "output.hpp"
44
#include "server.hpp"
5+
#include "subsurface.hpp"
56
#include "surface.hpp"
67
#include "types.hpp"
78

@@ -53,6 +54,18 @@ static void popup_new_popup_notify(wl_listener* listener, void* data) {
5354
popup.popups.emplace(std::make_shared<Popup>(popup, *static_cast<wlr_xdg_popup*>(data)));
5455
}
5556

57+
static void popup_new_subsurface_notify(wl_listener* listener, void* data) {
58+
wlr_log(WLR_DEBUG, "wlr_xdg_popup.events.new_subsurface(listener=%p, data=%p)", (void*) listener, data);
59+
60+
if (data == nullptr) {
61+
wlr_log(WLR_ERROR, "No data passed to wlr_xdg_popup.events.new_subsurface");
62+
return;
63+
}
64+
65+
Popup& popup = magpie_container_of(listener, popup, new_subsurface);
66+
popup.subsurfaces.emplace(std::make_shared<Subsurface>(popup, *static_cast<wlr_subsurface*>(data)));
67+
}
68+
5669
Popup::Popup(Surface& parent, wlr_xdg_popup& wlr) noexcept
5770
: listeners(*this), server(parent.get_server()), parent(parent), wlr(&wlr) {
5871
auto* scene_tree = wlr_scene_xdg_surface_create(wlr_scene_tree_from_node(parent.scene_node), wlr.base);
@@ -67,12 +80,15 @@ Popup::Popup(Surface& parent, wlr_xdg_popup& wlr) noexcept
6780
wl_signal_add(&wlr.base->events.destroy, &listeners.destroy);
6881
listeners.new_popup.notify = popup_new_popup_notify;
6982
wl_signal_add(&wlr.base->events.new_popup, &listeners.new_popup);
83+
listeners.new_subsurface.notify = popup_new_subsurface_notify;
84+
wl_signal_add(&wlr.base->surface->events.new_subsurface, &listeners.new_subsurface);
7085
}
7186

7287
Popup::~Popup() noexcept {
7388
wl_list_remove(&listeners.map.link);
7489
wl_list_remove(&listeners.destroy.link);
7590
wl_list_remove(&listeners.new_popup.link);
91+
wl_list_remove(&listeners.new_subsurface.link);
7692
if (wlr != nullptr) {
7793
wlr_xdg_popup_destroy(wlr);
7894
}

src/surface/popup.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Popup final : public Surface {
1818
wl_listener map = {};
1919
wl_listener destroy = {};
2020
wl_listener new_popup = {};
21+
wl_listener new_subsurface = {};
2122
explicit Listeners(Popup& parent) noexcept : parent(parent) {}
2223
};
2324

src/surface/subsurface.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "subsurface.hpp"
2+
3+
#include "types.hpp"
4+
5+
#include <utility>
6+
7+
#include "wlr-wrap-start.hpp"
8+
#include <wlr/types/wlr_layer_shell_v1.h>
9+
#include <wlr/types/wlr_output_layout.h>
10+
#include <wlr/types/wlr_subcompositor.h>
11+
#include <wlr/util/log.h>
12+
#include "wlr-wrap-end.hpp"
13+
14+
static void subsurface_destroy_notify(wl_listener* listener, [[maybe_unused]] void* data) {
15+
wlr_log(WLR_DEBUG, "wlr_subsurface.events.destroy(listener=%p, data=%p)", (void*) listener, data);
16+
17+
Subsurface& subsurface = magpie_container_of(listener, subsurface, destroy);
18+
19+
subsurface.parent.subsurfaces.erase(std::dynamic_pointer_cast<Subsurface>(subsurface.shared_from_this()));
20+
}
21+
22+
Subsurface::Subsurface(Surface& parent, wlr_subsurface& subsurface) noexcept
23+
: listeners(*this), parent(parent), wlr(subsurface) {
24+
listeners.destroy.notify = subsurface_destroy_notify;
25+
wl_signal_add(&subsurface.events.destroy, &listeners.destroy);
26+
}
27+
28+
Subsurface::~Subsurface() noexcept {
29+
wl_list_remove(&listeners.map.link);
30+
wl_list_remove(&listeners.destroy.link);
31+
}
32+
33+
wlr_surface* Subsurface::get_wlr_surface() const {
34+
return wlr.surface;
35+
}
36+
37+
Server& Subsurface::get_server() const {
38+
return parent.get_server();
39+
}
40+
41+
bool Subsurface::is_view() const {
42+
return false;
43+
}

src/surface/subsurface.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef MAGPIE_SUBSURFACE_HPP
2+
#define MAGPIE_SUBSURFACE_HPP
3+
4+
#include "server.hpp"
5+
#include "surface.hpp"
6+
#include "types.hpp"
7+
8+
#include <functional>
9+
#include <memory>
10+
#include <set>
11+
12+
#include "wlr-wrap-start.hpp"
13+
#include <wlr/types/wlr_subcompositor.h>
14+
#include "wlr-wrap-end.hpp"
15+
16+
class Subsurface final : public Surface {
17+
public:
18+
struct Listeners {
19+
std::reference_wrapper<Subsurface> parent;
20+
wl_listener map = {};
21+
wl_listener destroy = {};
22+
explicit Listeners(Subsurface& parent) noexcept : parent(parent) {}
23+
};
24+
25+
private:
26+
Listeners listeners;
27+
28+
public:
29+
Surface& parent;
30+
wlr_subsurface& wlr;
31+
32+
Subsurface(Surface& parent, wlr_subsurface& subsurface) noexcept;
33+
~Subsurface() noexcept override;
34+
35+
[[nodiscard]] wlr_surface* get_wlr_surface() const override;
36+
[[nodiscard]] Server& get_server() const override;
37+
[[nodiscard]] bool is_view() const override;
38+
};
39+
40+
#endif

src/surface/surface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
struct Surface : public virtual std::enable_shared_from_this<Surface> {
1414
wlr_scene_node* scene_node = nullptr;
1515
std::set<std::shared_ptr<Popup>> popups;
16+
std::set<std::shared_ptr<Subsurface>> subsurfaces;
1617

1718
virtual ~Surface() noexcept = default;
1819

src/surface/view.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class XdgView final : public View {
8080
wl_listener set_app_id = {};
8181
wl_listener set_parent = {};
8282
wl_listener new_popup = {};
83+
wl_listener new_subsurface = {};
8384
explicit Listeners(XdgView& parent) noexcept : parent(parent) {}
8485
};
8586

src/surface/xdg_view.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "output.hpp"
55
#include "popup.hpp"
66
#include "server.hpp"
7+
#include "subsurface.hpp"
78
#include "surface.hpp"
89
#include "input/seat.hpp"
910

@@ -147,6 +148,18 @@ static void xdg_surface_new_popup_notify(wl_listener* listener, void* data) {
147148
view.popups.emplace(std::make_shared<Popup>(view, *static_cast<wlr_xdg_popup*>(data)));
148149
}
149150

151+
static void xdg_surface_new_subsurface_notify(wl_listener* listener, void* data) {
152+
wlr_log(WLR_DEBUG, "wlr_xdg_toplevel.events.new_subsurface(listener=%p, data=%p)", (void*) listener, data);
153+
154+
if (data == nullptr) {
155+
wlr_log(WLR_ERROR, "No data passed to wlr_xdg_surface.events.new_subsurface");
156+
return;
157+
}
158+
159+
XdgView& view = magpie_container_of(listener, view, new_subsurface);
160+
view.subsurfaces.emplace(std::make_shared<Subsurface>(view, *static_cast<wlr_subsurface*>(data)));
161+
}
162+
150163
XdgView::XdgView(Server& server, wlr_xdg_toplevel& xdg_toplevel) noexcept
151164
: listeners(*this), server(server), wlr(xdg_toplevel) {
152165
auto* scene_tree = wlr_scene_xdg_surface_create(&server.scene->tree, xdg_toplevel.base);
@@ -194,6 +207,8 @@ XdgView::XdgView(Server& server, wlr_xdg_toplevel& xdg_toplevel) noexcept
194207
wl_signal_add(&wlr.events.set_parent, &listeners.set_parent);
195208
listeners.new_popup.notify = xdg_surface_new_popup_notify;
196209
wl_signal_add(&wlr.base->events.new_popup, &listeners.new_popup);
210+
listeners.new_subsurface.notify = xdg_surface_new_subsurface_notify;
211+
wl_signal_add(&wlr.base->surface->events.new_subsurface, &listeners.new_subsurface);
197212
}
198213

199214
XdgView::~XdgView() noexcept {
@@ -208,6 +223,7 @@ XdgView::~XdgView() noexcept {
208223
wl_list_remove(&listeners.set_app_id.link);
209224
wl_list_remove(&listeners.set_parent.link);
210225
wl_list_remove(&listeners.new_popup.link);
226+
wl_list_remove(&listeners.new_subsurface.link);
211227
}
212228

213229
wlr_surface* XdgView::get_wlr_surface() const {

0 commit comments

Comments
 (0)