Skip to content

Commit

Permalink
Change lightness of decorations based on window focus
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Aug 26, 2024
1 parent 0f6c314 commit b9d8619
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/decorations/ssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include "server.hpp"

constexpr uint8_t TITLEBAR_HEIGHT = 24;
constexpr uint32_t TITLEBAR_COLOR = 0x303030;
constexpr uint32_t TITLEBAR_ACTIVE_COLOR = 0x303030;
constexpr uint32_t TITLEBAR_INACTIVE_COLOR = 0x202020;
constexpr uint8_t BORDER_WIDTH = 1;
constexpr uint32_t BORDER_COLOR = 0x505050;
constexpr uint32_t BORDER_ACTIVE_COLOR = 0x505050;
constexpr uint32_t BORDER_INACTIVE_COLOR = 0x404040;

static consteval std::array<float, 4> rrggbb_to_floats(uint32_t rrggbb) {
static constexpr 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});
}
Expand All @@ -19,15 +21,15 @@ 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 titlebar_color = rrggbb_to_floats(TITLEBAR_COLOR);
auto titlebar_color = rrggbb_to_floats(TITLEBAR_INACTIVE_COLOR);
auto view_geo = view.get_surface_geometry();
titlebar_rect = wlr_scene_rect_create(scene_tree, view_geo.width, TITLEBAR_HEIGHT, titlebar_color.data());
titlebar_rect->node.data = &parent;
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);

auto border_color = rrggbb_to_floats(BORDER_COLOR);
auto border_color = rrggbb_to_floats(BORDER_INACTIVE_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);
Expand All @@ -45,6 +47,14 @@ void Ssd::update() const {
wlr_scene_rect_set_size(border_rect, view_geo.width + get_extra_width(), view_geo.height + get_extra_height());
}

void Ssd::set_activated(const bool activated) const {
auto titlebar_color = rrggbb_to_floats(activated ? TITLEBAR_ACTIVE_COLOR : TITLEBAR_INACTIVE_COLOR);
wlr_scene_rect_set_color(titlebar_rect, titlebar_color.data());

auto border_color = rrggbb_to_floats(activated ? BORDER_ACTIVE_COLOR : BORDER_INACTIVE_COLOR);
wlr_scene_rect_set_color(border_rect, border_color.data());
}

wlr_box Ssd::get_geometry() const {
auto view_geo = view.get_surface_geometry();
return {.x = view_geo.x - get_horizontal_offset(),
Expand Down
3 changes: 2 additions & 1 deletion src/decorations/ssd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class Ssd final : public std::enable_shared_from_this<Ssd> {
~Ssd();

void update() const;
wlr_box get_geometry() const;
void set_activated(bool activated) const;

wlr_box get_geometry() const;
uint8_t get_vertical_offset() const;
uint8_t get_horizontal_offset() const;
int32_t get_extra_width() const;
Expand Down
4 changes: 4 additions & 0 deletions src/surface/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ void View::set_activated(const bool activated) {
toplevel_handle->set_activated(activated);
}

if (ssd.has_value()) {
ssd->set_activated(activated);
}

const auto seat = get_server().seat;
if (activated) {
wlr_scene_node_raise_to_top(&scene_tree->node);
Expand Down

0 comments on commit b9d8619

Please sign in to comment.