Skip to content

Commit

Permalink
Add visually apparent SSD (nonfunctional)
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Aug 24, 2024
1 parent e4619ef commit c30335b
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/decorations/ssd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "ssd.hpp"

#include "surface/view.hpp"
#include "server.hpp"

constexpr uint8_t TITLEBAR_HEIGHT = 24;
constexpr uint32_t TITLEBAR_COLOR = 0x303030;

static consteval std::array<float, 4> rrggbb_to_floats(uint32_t rrggbb) {
return std::array<float, 4>(
{(float) (rrggbb >> 16 & 0xff) / 255.0f, (float) (rrggbb >> 8 & 0xff) / 255.0f, (float) (rrggbb & 0xff) / 255.0f, 1.0});
}

Ssd::Ssd(View& parent) noexcept : view(parent) {
scene_tree = wlr_scene_tree_create(wlr_scene_tree_from_node(parent.scene_node));
wlr_scene_node_raise_to_top(&scene_tree->node);
wlr_scene_node_set_position(&scene_tree->node, 0, -TITLEBAR_HEIGHT);
wlr_scene_node_set_enabled(&scene_tree->node, true);

auto color = rrggbb_to_floats(TITLEBAR_COLOR);
titlebar_rect = wlr_scene_rect_create(scene_tree, parent.current.width, TITLEBAR_HEIGHT, color.data());
wlr_scene_node_set_enabled(&titlebar_rect->node, true);
}

void Ssd::update() const {
wlr_scene_rect_set_size(titlebar_rect, view.get_geometry().width, TITLEBAR_HEIGHT);
wlr_scene_node_raise_to_top(&scene_tree->node);
}

Ssd::~Ssd() {
wlr_scene_node_destroy(&scene_tree->node);
}
24 changes: 24 additions & 0 deletions src/decorations/ssd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef MAGPIE_SSD_HPP
#define MAGPIE_SSD_HPP

#include "types.hpp"

#include <memory>

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

class Ssd final : public std::enable_shared_from_this<Ssd> {
public:
View& view;
wlr_scene_tree* scene_tree = nullptr;
wlr_scene_rect* titlebar_rect = nullptr;

Ssd(View& parent) noexcept;
~Ssd();

void update() const;
};

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "xdg_decoration.hpp"

#include "view.hpp"
#include "ssd.hpp"
#include "surface/view.hpp"

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

static void xdg_decoration_request_mode_notify(wl_listener* listener, [[maybe_unused]] void* data) {
wlr_log(WLR_DEBUG, "wlr_xdg_toplevel_decoration_v1.events.request_mode(listener=%p, data=%p)", (void*) listener, data);

XdgDecoration& deco = magpie_container_of(listener, deco, request_mode);

deco.view.ssd.emplace(deco.view);
}

XdgDecoration::XdgDecoration(XdgView& view, wlr_xdg_toplevel_decoration_v1& deco) noexcept
: listeners(*this), view(view), wlr(deco) {
listeners.destroy.notify = xdg_decoration_destroy_notify;
wl_signal_add(&deco.events.destroy, &listeners.destroy);
listeners.request_mode.notify = xdg_decoration_request_mode_notify;
wl_signal_add(&deco.events.request_mode, &listeners.request_mode);
}

XdgDecoration::~XdgDecoration() noexcept {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class XdgDecoration : public std::enable_shared_from_this<XdgDecoration> {
struct Listeners {
std::reference_wrapper<XdgDecoration> parent;
wl_listener destroy = {};
wl_listener request_mode = {};
explicit Listeners(XdgDecoration& parent) noexcept : parent(parent) {}
};

Expand Down
3 changes: 2 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ magpie_sources = [
'output.cpp',
'server.cpp',
'xwayland.cpp',
'decorations/xdg_decoration.cpp',
'decorations/ssd.cpp',
'input/constraint.cpp',
'input/cursor.cpp',
'input/keyboard.cpp',
Expand All @@ -14,7 +16,6 @@ magpie_sources = [
'surface/popup.cpp',
'surface/subsurface.cpp',
'surface/view.cpp',
'surface/xdg_decoration.cpp',
'surface/xdg_view.cpp',
'surface/xwayland_view.cpp',
budgie_keyboard_shortcuts_protocol,
Expand Down
2 changes: 1 addition & 1 deletion src/server.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "server.hpp"

#include "decorations/xdg_decoration.hpp"
#include "input/seat.hpp"
#include "output.hpp"
#include "surface/layer.hpp"
#include "surface/popup.hpp"
#include "surface/surface.hpp"
#include "surface/view.hpp"
#include "surface/xdg_decoration.hpp"
#include "types.hpp"
#include "xwayland.hpp"

Expand Down
10 changes: 10 additions & 0 deletions src/surface/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ void View::set_size(const int32_t width, const int32_t height) {
current.width = bounded_width;
current.height = bounded_height;
impl_set_size(current.width, current.height);
if (ssd.has_value()) {
ssd->update();
}
}

void View::update_outputs(const bool ignore_previous) const {
Expand Down Expand Up @@ -249,6 +252,10 @@ void View::set_activated(const bool activated) {
wlr_seat_keyboard_notify_clear_focus(seat->wlr);
seat->set_constraint(nullptr);
}

if (ssd.has_value()) {
ssd->update();
}
}

void View::set_placement(const ViewPlacement new_placement, const bool force) {
Expand Down Expand Up @@ -294,6 +301,9 @@ void View::stack() {
impl_set_fullscreen(false);
set_geometry(previous.x, previous.y, previous.width, previous.height);
update_outputs();
if (ssd.has_value()) {
ssd->update();
}
}

bool View::maximize() {
Expand Down
2 changes: 2 additions & 0 deletions src/surface/view.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MAGPIE_VIEW_HPP
#define MAGPIE_VIEW_HPP

#include "decorations/ssd.hpp"
#include "foreign_toplevel.hpp"
#include "input/cursor.hpp"
#include "surface.hpp"
Expand All @@ -21,6 +22,7 @@ struct View : public Surface {
wlr_box current = {};
wlr_box previous = {};
std::optional<ForeignToplevelHandle> toplevel_handle;
std::optional<Ssd> ssd;

~View() noexcept override = default;

Expand Down

0 comments on commit c30335b

Please sign in to comment.