Skip to content

Commit

Permalink
Add enable_shared_from_this to all classes
Browse files Browse the repository at this point in the history
For use with smart pointers
  • Loading branch information
serebit committed Apr 13, 2024
1 parent 4ad779b commit f4e3e1f
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/foreign_toplevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include "types.hpp"

#include <functional>
#include <memory>
#include <optional>
#include <string>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
#include "wlr-wrap-end.hpp"

class ForeignToplevelHandle {
class ForeignToplevelHandle final : public std::enable_shared_from_this<ForeignToplevelHandle> {
public:
struct Listeners {
std::reference_wrapper<ForeignToplevelHandle> parent;
Expand Down
3 changes: 2 additions & 1 deletion src/input/constraint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include "types.hpp"

#include <functional>
#include <memory>
#include <wayland-server-core.h>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include "wlr-wrap-end.hpp"

class PointerConstraint {
class PointerConstraint final : public std::enable_shared_from_this<PointerConstraint> {
public:
struct Listeners {
std::reference_wrapper<PointerConstraint> parent;
Expand Down
4 changes: 2 additions & 2 deletions src/input/cursor.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef MAGPIE_CURSOR_HPP
#define MAGPIE_CURSOR_HPP

#include "input/constraint.hpp"
#include "types.hpp"

#include <functional>
#include <memory>
#include <string>

#include "wlr-wrap-start.hpp"
Expand All @@ -16,7 +16,7 @@

enum CursorMode { MAGPIE_CURSOR_PASSTHROUGH, MAGPIE_CURSOR_MOVE, MAGPIE_CURSOR_RESIZE };

class Cursor {
class Cursor final : std::enable_shared_from_this<Cursor> {
public:
struct Listeners {
std::reference_wrapper<Cursor> parent;
Expand Down
3 changes: 2 additions & 1 deletion src/input/keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#include "types.hpp"

#include <functional>
#include <memory>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_keyboard.h>
#include "wlr-wrap-end.hpp"

class Keyboard {
class Keyboard final : std::enable_shared_from_this<Keyboard> {
public:
struct Listeners {
std::reference_wrapper<Keyboard> parent;
Expand Down
2 changes: 1 addition & 1 deletion src/input/seat.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "seat.hpp"

#include "cursor.hpp"
#include "constraint.hpp"
#include "keyboard.hpp"
#include "server.hpp"
#include "surface/view.hpp"
Expand Down
5 changes: 2 additions & 3 deletions src/input/seat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#define MAGPIE_SEAT_HPP

#include "cursor.hpp"
#include "constraint.hpp"
#include "types.hpp"

#include <memory>
#include <optional>
#include <vector>

Expand All @@ -15,7 +14,7 @@
#include <wlr/types/wlr_virtual_pointer_v1.h>
#include "wlr-wrap-end.hpp"

class Seat {
class Seat final : std::enable_shared_from_this<Seat> {
public:
struct Listeners {
std::reference_wrapper<Seat> parent;
Expand Down
3 changes: 2 additions & 1 deletion src/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "types.hpp"

#include <functional>
#include <memory>
#include <set>

#include "wlr-wrap-start.hpp"
Expand All @@ -12,7 +13,7 @@
#include <wlr/util/box.h>
#include "wlr-wrap-end.hpp"

class Output {
class Output final : public std::enable_shared_from_this<Output> {
public:
struct Listeners {
std::reference_wrapper<Output> parent;
Expand Down
3 changes: 2 additions & 1 deletion src/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <functional>
#include <list>
#include <memory>
#include <set>

#include "wlr-wrap-start.hpp"
Expand Down Expand Up @@ -32,7 +33,7 @@ typedef enum {
MAGPIE_SCENE_LAYER_LOCK
} magpie_scene_layer_t;

class Server {
class Server final : std::enable_shared_from_this<Server> {
public:
struct Listeners {
std::reference_wrapper<Server> parent;
Expand Down
5 changes: 3 additions & 2 deletions src/surface/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "types.hpp"

#include <functional>
#include <memory>
#include <set>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_subcompositor.h>
#include "wlr-wrap-end.hpp"

class Layer final : public Surface {
class Layer final : public Surface, public std::enable_shared_from_this<Layer> {
public:
struct Listeners {
std::reference_wrapper<Layer> parent;
Expand Down Expand Up @@ -44,7 +45,7 @@ class Layer final : public Surface {
[[nodiscard]] constexpr bool is_view() const override;
};

class LayerSubsurface {
class LayerSubsurface final : std::enable_shared_from_this<LayerSubsurface> {
public:
struct Listeners {
std::reference_wrapper<LayerSubsurface> parent;
Expand Down
3 changes: 2 additions & 1 deletion src/surface/popup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include "types.hpp"

#include <functional>
#include <memory>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_xdg_shell.h>
#include "wlr-wrap-end.hpp"

class Popup final : public Surface {
class Popup final : public Surface, public std::enable_shared_from_this<Popup> {
public:
struct Listeners {
std::reference_wrapper<Popup> parent;
Expand Down
3 changes: 2 additions & 1 deletion src/surface/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "types.hpp"

#include <memory>
#include <set>

#include "wlr-wrap-start.hpp"
Expand All @@ -11,7 +12,7 @@

enum SurfaceType { MAGPIE_SURFACE_TYPE_VIEW, MAGPIE_SURFACE_TYPE_LAYER, MAGPIE_SURFACE_TYPE_POPUP };

struct Surface {
struct Surface : public std::enable_shared_from_this<Surface> {
wlr_scene_node* scene_node = nullptr;
std::set<Popup*> popups;

Expand Down
6 changes: 3 additions & 3 deletions src/surface/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <wlr/xwayland.h>
#include "wlr-wrap-end.hpp"

struct View : Surface {
struct View : public Surface, public std::enable_shared_from_this<View> {
ViewPlacement prev_placement = VIEW_PLACEMENT_STACKING;
ViewPlacement curr_placement = VIEW_PLACEMENT_STACKING;
bool is_minimized = false;
Expand Down Expand Up @@ -63,7 +63,7 @@ struct View : Surface {
virtual void impl_set_minimized(bool minimized) = 0;
};

class XdgView final : public View {
class XdgView final : public View, public std::enable_shared_from_this<XdgView> {
public:
struct Listeners {
std::reference_wrapper<XdgView> parent;
Expand Down Expand Up @@ -115,7 +115,7 @@ class XdgView final : public View {
void impl_set_minimized(bool minimized) override;
};

class XWaylandView final : public View {
class XWaylandView final : public View, public std::enable_shared_from_this<XWaylandView> {
public:
struct Listeners {
std::reference_wrapper<XWaylandView> parent;
Expand Down
3 changes: 2 additions & 1 deletion src/xwayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "types.hpp"

#include <functional>
#include <memory>
#include <xcb/xproto.h>

#include "wlr-wrap-start.hpp"
Expand All @@ -25,7 +26,7 @@ enum atom_name {
ATOM_LAST,
};

class XWayland {
class XWayland final : std::enable_shared_from_this<XWayland> {
public:
struct Listeners {
std::reference_wrapper<XWayland> parent;
Expand Down

0 comments on commit f4e3e1f

Please sign in to comment.