Skip to content

Commit

Permalink
Make SSD borders lighter than SSD titlebars
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Aug 25, 2024
1 parent 8b633ad commit 40c2cd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
38 changes: 22 additions & 16 deletions src/decorations/ssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

constexpr uint8_t TITLEBAR_HEIGHT = 24;
constexpr uint32_t TITLEBAR_COLOR = 0x303030;
constexpr uint8_t BORDER_WIDTH = 1;
constexpr uint32_t BORDER_COLOR = 0x505050;

static consteval std::array<float, 4> rrggbb_to_floats(uint32_t rrggbb) {
return std::array<float, 4>(
Expand All @@ -17,14 +19,18 @@ Ssd::Ssd(View& parent) noexcept : view(parent) {
wlr_scene_node_set_position(&scene_tree->node, 0, 0);
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.surface_current.width + get_extra_width(), get_titlebar_height(), color.data());
auto titlebar_color = rrggbb_to_floats(TITLEBAR_COLOR);
auto view_geo = view.get_surface_geometry();
titlebar_rect = wlr_scene_rect_create(scene_tree, view_geo.width, TITLEBAR_HEIGHT, titlebar_color.data());
wlr_scene_node_set_position(&titlebar_rect->node, BORDER_WIDTH, BORDER_WIDTH);
wlr_scene_node_lower_to_bottom(&titlebar_rect->node);
wlr_scene_node_set_enabled(&titlebar_rect->node, true);

border_rect = wlr_scene_rect_create(scene_tree, parent.surface_current.width + get_extra_width(),
parent.surface_current.height + get_border_width(), color.data());
wlr_scene_node_set_position(&border_rect->node, 0, TITLEBAR_HEIGHT);
auto border_color = rrggbb_to_floats(BORDER_COLOR);
border_rect = wlr_scene_rect_create(
scene_tree, view_geo.width + get_extra_width(), view_geo.height + get_extra_height(), border_color.data());
wlr_scene_node_set_position(&border_rect->node, 0, 0);
wlr_scene_node_lower_to_bottom(&border_rect->node);
wlr_scene_node_set_enabled(&border_rect->node, true);
}

Expand All @@ -34,30 +40,30 @@ Ssd::~Ssd() {

void Ssd::update() const {
auto view_geo = view.get_surface_geometry();
wlr_scene_rect_set_size(titlebar_rect, view_geo.width + 2, TITLEBAR_HEIGHT);
wlr_scene_rect_set_size(border_rect, view_geo.width + 2, view_geo.height + 1);
wlr_scene_rect_set_size(titlebar_rect, view_geo.width, TITLEBAR_HEIGHT);
wlr_scene_rect_set_size(border_rect, view_geo.width + get_extra_width(), view_geo.height + get_extra_height());
}

wlr_box Ssd::get_geometry() const {
auto view_geo = view.get_surface_geometry();
return {.x = view_geo.x - get_border_width(),
.y = view_geo.y - get_titlebar_height(),
return {.x = view_geo.x - get_horizontal_offset(),
.y = view_geo.y - get_vertical_offset(),
.width = view_geo.width + get_extra_width(),
.height = view_geo.height + get_extra_height()};
}

uint8_t Ssd::get_titlebar_height() const {
return TITLEBAR_HEIGHT;
uint8_t Ssd::get_vertical_offset() const {
return TITLEBAR_HEIGHT + BORDER_WIDTH;
}

uint8_t Ssd::get_border_width() const {
return 1;
uint8_t Ssd::get_horizontal_offset() const {
return BORDER_WIDTH;
}

int32_t Ssd::get_extra_width() const {
return get_border_width() * 2;
return BORDER_WIDTH * 2;
}

int32_t Ssd::get_extra_height() const {
return get_titlebar_height() + get_border_width();
return TITLEBAR_HEIGHT + BORDER_WIDTH * 2;
}
4 changes: 2 additions & 2 deletions src/decorations/ssd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Ssd final : public std::enable_shared_from_this<Ssd> {
void update() const;
wlr_box get_geometry() const;

uint8_t get_titlebar_height() const;
uint8_t get_border_width() const;
uint8_t get_vertical_offset() const;
uint8_t get_horizontal_offset() const;
int32_t get_extra_width() const;
int32_t get_extra_height() const;
};
Expand Down
12 changes: 6 additions & 6 deletions src/surface/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int32_t View::find_surface_min_y() const {

min_y = min_y == INT32_MAX ? 0 : min_y;
if (ssd.has_value()) {
return min_y + ssd->get_titlebar_height();
return min_y + ssd->get_vertical_offset();
} else {
return min_y;
}
Expand Down Expand Up @@ -151,8 +151,8 @@ void View::set_geometry(const int32_t x, const int32_t y, const int32_t width, c

if (scene_tree != nullptr) {
if (ssd.has_value()) {
wlr_scene_node_set_position(
&scene_tree->node, surface_current.x - ssd->get_border_width(), surface_current.y - ssd->get_titlebar_height());
wlr_scene_node_set_position(&scene_tree->node, surface_current.x - ssd->get_horizontal_offset(),
surface_current.y - ssd->get_vertical_offset());
} else {
wlr_scene_node_set_position(&scene_tree->node, surface_current.x, surface_current.y);
}
Expand All @@ -172,8 +172,8 @@ void View::set_position(const int32_t x, const int32_t y) {

if (scene_tree != nullptr) {
if (ssd.has_value()) {
wlr_scene_node_set_position(
&scene_tree->node, surface_current.x - ssd->get_border_width(), surface_current.y - ssd->get_titlebar_height());
wlr_scene_node_set_position(&scene_tree->node, surface_current.x - ssd->get_horizontal_offset(),
surface_current.y - ssd->get_vertical_offset());
} else {
wlr_scene_node_set_position(&scene_tree->node, surface_current.x, surface_current.y);
}
Expand Down Expand Up @@ -439,7 +439,7 @@ wlr_box View::get_max_size_with_decorations() const {

void View::update_surface_node_position() const {
if (ssd.has_value()) {
wlr_scene_node_set_position(surface_node, ssd->get_border_width(), ssd->get_titlebar_height());
wlr_scene_node_set_position(surface_node, ssd->get_horizontal_offset(), ssd->get_vertical_offset());
} else {
wlr_scene_node_set_position(surface_node, 0, 0);
}
Expand Down

0 comments on commit 40c2cd6

Please sign in to comment.