kranewl

A wlroots-based dynamic Wayland compositor, written in C++, configurable with Lua
git clone git://git.deurzen.net/kranewl
Log | Files | Refs | LICENSE

commit e0695bae1453b6f4386469c023b43d17be4c8088
parent e2fd74623a56815b9d8aa6551d843f9ec49428bd
Author: deurzen <max@deurzen.net>
Date:   Fri,  3 Jun 2022 10:36:03 +0200

refactors public-exposed members to {set,get}ters

Diffstat:
Minclude/kranewl/tree/view.hh | 28+++++++++++++++++++++-------
Minclude/kranewl/tree/xdg-view.hh | 2+-
Minclude/kranewl/tree/xwayland-view.hh | 43++++++++++++++++++++++++++++++++-----------
Msrc/kranewl/model.cc | 8++++----
Msrc/kranewl/tree/view.cc | 4++--
Msrc/kranewl/tree/xdg-view.cc | 25+++++++++++--------------
Msrc/kranewl/tree/xwayland-view.cc | 63++++++++++++++++++++++++++++-----------------------------------
7 files changed, 99 insertions(+), 74 deletions(-)

diff --git a/include/kranewl/tree/view.hh b/include/kranewl/tree/view.hh @@ -64,7 +64,7 @@ typedef struct View : public Node { void format_uid() override; virtual Region constraints() = 0; - virtual pid_t pid() = 0; + virtual pid_t retrieve_pid() = 0; virtual bool prefers_floating() = 0; virtual void focus(Toggle) = 0; @@ -85,6 +85,19 @@ typedef struct View : public Node { void render_decoration(); + std::string const& title() const { return m_title; } + std::string const& title_formatted() const { return m_title_formatted; } + std::string const& app_id() const { return m_app_id; } + std::string const& handle() const { return m_handle; } + void set_title(std::string const& title) { m_title = title; } + void set_title_formatted(std::string const& title_formatted) { m_title_formatted = title_formatted; } + void set_app_id(std::string const& app_id) { m_app_id = app_id; } + void set_handle(std::string const& handle) { m_handle = handle; } + + + pid_t pid() const { return m_pid; } + void set_pid(pid_t pid) { m_pid = pid; } + bool activated() const { return m_activated; } bool focused() const { return m_focused; } bool mapped() const { return m_mapped; } @@ -167,15 +180,9 @@ typedef struct View : public Node { struct wlr_scene_node* mp_scene_surface; struct wlr_scene_rect* m_protrusions[4]; // top, bottom, left, right - std::string m_title; - std::string m_title_formatted; - std::string m_app_id; - float m_alpha; uint32_t m_resize; - pid_t m_pid; - protected: struct { @@ -211,6 +218,13 @@ private: bool m_iconified; bool m_disowned; + std::string m_title; + std::string m_title_formatted; + std::string m_app_id; + std::string m_handle; + + pid_t m_pid; + SceneLayer m_scene_layer; OutsideState m_outside_state; diff --git a/include/kranewl/tree/xdg-view.hh b/include/kranewl/tree/xdg-view.hh @@ -24,7 +24,7 @@ typedef struct XDGView final : public View { ~XDGView(); Region constraints() override; - pid_t pid() override; + pid_t retrieve_pid() override; bool prefers_floating() override; void focus(Toggle) override; diff --git a/include/kranewl/tree/xwayland-view.hh b/include/kranewl/tree/xwayland-view.hh @@ -25,8 +25,13 @@ typedef struct XWaylandView final : public View { void format_uid() override; + std::string const& class_() const { return m_class; } + std::string const& instance() const { return m_instance; } + void set_class(std::string const& class_) { m_class = class_; } + void set_instance(std::string const& instance) { m_instance = instance; } + Region constraints() override; - pid_t pid() override; + pid_t retrieve_pid() override; bool prefers_floating() override; void focus(Toggle) override; @@ -55,9 +60,6 @@ typedef struct XWaylandView final : public View { XWayland_ptr mp_xwayland; - std::string m_class; - std::string m_instance; - struct wlr_xwayland_surface* mp_wlr_xwayland_surface; struct wl_listener ml_map; @@ -76,6 +78,10 @@ typedef struct XWaylandView final : public View { struct wl_listener ml_set_hints; struct wl_listener ml_destroy; +private: + std::string m_class; + std::string m_instance; + }* XWaylandView_ptr; typedef struct XWaylandUnmanaged final : public Node { @@ -91,7 +97,21 @@ typedef struct XWaylandUnmanaged final : public Node { void format_uid() override; - pid_t pid(); + std::string const& title() const { return m_title; } + std::string const& title_formatted() const { return m_title_formatted; } + std::string const& app_id() const { return m_app_id; } + std::string const& class_() const { return m_class; } + std::string const& instance() const { return m_instance; } + void set_title(std::string const& title) { m_title = title; } + void set_title_formatted(std::string const& title_formatted) { m_title_formatted = title_formatted; } + void set_app_id(std::string const& app_id) { m_app_id = app_id; } + void set_class(std::string const& class_) { m_class = class_; } + void set_instance(std::string const& instance) { m_instance = instance; } + + pid_t retrieve_pid(); + + pid_t pid() const { return m_pid; } + void set_pid(pid_t pid) { m_pid = pid; } static void handle_map(struct wl_listener*, void*); static void handle_unmap(struct wl_listener*, void*); @@ -113,12 +133,6 @@ typedef struct XWaylandUnmanaged final : public Node { Region m_region; - std::string m_title; - std::string m_title_formatted; - std::string m_app_id; - std::string m_class; - std::string m_instance; - struct wlr_xwayland_surface* mp_wlr_xwayland_surface; struct wlr_surface* mp_wlr_surface; @@ -137,5 +151,12 @@ typedef struct XWaylandUnmanaged final : public Node { struct wl_listener ml_request_fullscreen; struct wl_listener ml_destroy; +private: + std::string m_title; + std::string m_title_formatted; + std::string m_app_id; + std::string m_class; + std::string m_instance; + }* XWaylandUnmanaged_ptr; #endif diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -405,13 +405,13 @@ Model::view_matches_search(View_ptr view, SearchSelector const& selector) const return false; } case SearchSelector::SelectionCriterium::ByTitleEquals: - return view->m_title == selector.string_value(); + return view->title() == selector.string_value(); case SearchSelector::SelectionCriterium::ByAppIdEquals: - return view->m_app_id == selector.string_value(); + return view->app_id() == selector.string_value(); case SearchSelector::SelectionCriterium::ByTitleContains: - return view->m_title.find(selector.string_value()) != std::string::npos; + return view->title().find(selector.string_value()) != std::string::npos; case SearchSelector::SelectionCriterium::ByAppIdContains: - return view->m_app_id.find(selector.string_value()) != std::string::npos; + return view->app_id().find(selector.string_value()) != std::string::npos; case SearchSelector::SelectionCriterium::ForCondition: return selector.filter()(view); default: break; diff --git a/src/kranewl/tree/view.cc b/src/kranewl/tree/view.cc @@ -517,8 +517,8 @@ View::format_uid() { std::stringstream uid_ss; uid_ss << "0x" << std::hex << uid() << std::dec; - uid_ss << " [" << m_title; - uid_ss << ", " << m_pid << "]"; + uid_ss << " [" << title(); + uid_ss << ", " << pid() << "]"; uid_ss << " (W)"; m_uid_formatted = uid_ss.str(); } diff --git a/src/kranewl/tree/xdg-view.cc b/src/kranewl/tree/xdg-view.cc @@ -70,7 +70,7 @@ XDGView::constraints() } pid_t -XDGView::pid() +XDGView::retrieve_pid() { TRACE(); @@ -277,10 +277,9 @@ XDGView::handle_set_title(struct wl_listener* listener, void* data) TRACE(); XDGView_ptr view = wl_container_of(listener, view, ml_set_title); - view->m_title = view->mp_wlr_xdg_toplevel->title - ? view->mp_wlr_xdg_toplevel->title - : "N/a"; - view->m_title_formatted = view->m_title; + view->set_title(view->mp_wlr_xdg_toplevel->title + ? view->mp_wlr_xdg_toplevel->title : ""); + view->set_title_formatted(view->title()); view->format_uid(); } @@ -290,7 +289,7 @@ XDGView::handle_set_app_id(struct wl_listener* listener, void* data) TRACE(); XDGView_ptr view = wl_container_of(listener, view, ml_set_app_id); - view->m_app_id = view->mp_wlr_xdg_toplevel->app_id; + view->set_app_id(view->mp_wlr_xdg_toplevel->app_id); view->format_uid(); } @@ -310,7 +309,7 @@ XDGView::handle_map(struct wl_listener* listener, void* data) Server_ptr server = view->mp_server; Model_ptr model = view->mp_model; - view->m_pid = view->pid(); + view->set_pid(view->retrieve_pid()); view->format_uid(); view->set_floating(view->prefers_floating()); @@ -339,13 +338,11 @@ XDGView::handle_map(struct wl_listener* listener, void* data) .h = state->min_height }); - view->m_app_id = wlr_xdg_toplevel->app_id - ? wlr_xdg_toplevel->app_id - : "N/a"; - view->m_title = wlr_xdg_toplevel->title - ? wlr_xdg_toplevel->title - : "N/a"; - view->m_title_formatted = view->m_title; // TODO: format title + view->set_app_id(wlr_xdg_toplevel->app_id + ? wlr_xdg_toplevel->app_id : "N/a"); + view->set_title(wlr_xdg_toplevel->title + ? wlr_xdg_toplevel->title : "N/a"); + view->set_title_formatted(view->title()); // TODO: format title wlr_xdg_toplevel_set_tiled( wlr_xdg_surface, diff --git a/src/kranewl/tree/xwayland-view.cc b/src/kranewl/tree/xwayland-view.cc @@ -82,16 +82,16 @@ XWaylandView::format_uid() { std::stringstream uid_ss; uid_ss << "0x" << std::hex << uid() << std::dec; - uid_ss << " [" << m_title; - uid_ss << "; " << m_class; - uid_ss << "; " << m_instance; - uid_ss << ", " << m_pid << "]"; + uid_ss << " [" << title(); + uid_ss << "; " << class_(); + uid_ss << "; " << instance(); + uid_ss << ", " << pid() << "]"; uid_ss << " (XM)"; m_uid_formatted = uid_ss.str(); } pid_t -XWaylandView::pid() +XWaylandView::retrieve_pid() { TRACE(); return mp_wlr_xwayland_surface->pid; @@ -295,7 +295,7 @@ XWaylandView::handle_map(struct wl_listener* listener, void* data) Server_ptr server = view->mp_server; Model_ptr model = view->mp_model; - view->m_pid = view->pid(); + view->set_pid(view->retrieve_pid()); view->format_uid(); view->set_floating(view->prefers_floating()); @@ -314,16 +314,13 @@ XWaylandView::handle_map(struct wl_listener* listener, void* data) preferred_dim.h += extents.top + extents.bottom; view->set_preferred_dim(preferred_dim); - view->m_app_id = view->m_class = xwayland_surface->class_ - ? xwayland_surface->class_ - : "N/a"; - view->m_instance = xwayland_surface->instance - ? xwayland_surface->instance - : "N/a"; - view->m_title = xwayland_surface->title - ? xwayland_surface->title - : "N/a"; - view->m_title_formatted = view->m_title; // TODO: format title + view->set_app_id(view->m_class = xwayland_surface->class_ + ? xwayland_surface->class_ : "N/a"); + view->set_instance(xwayland_surface->instance + ? xwayland_surface->instance : "N/a"); + view->set_title(xwayland_surface->title + ? xwayland_surface->title : "N/a"); + view->set_title_formatted(view->title()); // TODO: format title view->mp_scene = &wlr_scene_tree_create( server->m_scene_layers[SCENE_LAYER_TILE] @@ -548,10 +545,9 @@ XWaylandView::handle_set_title(struct wl_listener* listener, void*) TRACE(); XWaylandView_ptr view = wl_container_of(listener, view, ml_set_title); - view->m_title = view->mp_wlr_xwayland_surface->title - ? view->mp_wlr_xwayland_surface->title - : "N/a"; - view->m_title_formatted = view->m_title; // TODO: format title + view->set_title(view->mp_wlr_xwayland_surface->title + ? view->mp_wlr_xwayland_surface->title : "N/a"); + view->set_title_formatted(view->title()); // TODO: format title view->format_uid(); } @@ -561,9 +557,8 @@ XWaylandView::handle_set_class(struct wl_listener* listener, void*) TRACE(); XWaylandView_ptr view = wl_container_of(listener, view, ml_set_class); - view->m_class = view->mp_wlr_xwayland_surface->class_ - ? view->mp_wlr_xwayland_surface->class_ - : "N/a"; + view->set_class(view->mp_wlr_xwayland_surface->class_ + ? view->mp_wlr_xwayland_surface->class_ : "N/a"); view->format_uid(); } @@ -662,7 +657,7 @@ XWaylandUnmanaged::format_uid() } pid_t -XWaylandUnmanaged::pid() +XWaylandUnmanaged::retrieve_pid() { TRACE(); return mp_wlr_xwayland_surface->pid; @@ -677,7 +672,7 @@ XWaylandUnmanaged::handle_map(struct wl_listener* listener, void* data) Server_ptr server = unmanaged->mp_server; Model_ptr model = unmanaged->mp_model; - unmanaged->m_pid = unmanaged->pid(); + unmanaged->set_pid(unmanaged->retrieve_pid()); unmanaged->format_uid(); struct wlr_xwayland_surface* xwayland_surface @@ -695,16 +690,14 @@ XWaylandUnmanaged::handle_map(struct wl_listener* listener, void* data) } }; - unmanaged->m_app_id = unmanaged->m_class = xwayland_surface->class_ - ? xwayland_surface->class_ - : "N/a"; - unmanaged->m_instance = xwayland_surface->instance - ? xwayland_surface->instance - : "N/a"; - unmanaged->m_title = xwayland_surface->title - ? xwayland_surface->title - : "N/a"; - unmanaged->m_title_formatted = unmanaged->m_title; // TODO: format title + unmanaged->set_instance(xwayland_surface->instance + ? xwayland_surface->instance : "N/a"); + unmanaged->set_class(xwayland_surface->class_ + ? xwayland_surface->class_ : "N/a"); + unmanaged->set_title(xwayland_surface->title + ? xwayland_surface->title : "N/a"); + unmanaged->set_app_id(unmanaged->class_()); + unmanaged->set_title_formatted(unmanaged->title()); // TODO: format title unmanaged->mp_scene = &wlr_scene_tree_create( server->m_scene_layers[SCENE_LAYER_TILE]