Skip to content

Commit b9d8619

Browse files
committed
Change lightness of decorations based on window focus
1 parent 0f6c314 commit b9d8619

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/decorations/ssd.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
#include "server.hpp"
55

66
constexpr uint8_t TITLEBAR_HEIGHT = 24;
7-
constexpr uint32_t TITLEBAR_COLOR = 0x303030;
7+
constexpr uint32_t TITLEBAR_ACTIVE_COLOR = 0x303030;
8+
constexpr uint32_t TITLEBAR_INACTIVE_COLOR = 0x202020;
89
constexpr uint8_t BORDER_WIDTH = 1;
9-
constexpr uint32_t BORDER_COLOR = 0x505050;
10+
constexpr uint32_t BORDER_ACTIVE_COLOR = 0x505050;
11+
constexpr uint32_t BORDER_INACTIVE_COLOR = 0x404040;
1012

11-
static consteval std::array<float, 4> rrggbb_to_floats(uint32_t rrggbb) {
13+
static constexpr std::array<float, 4> rrggbb_to_floats(uint32_t rrggbb) {
1214
return std::array<float, 4>(
1315
{(float) (rrggbb >> 16 & 0xff) / 255.0f, (float) (rrggbb >> 8 & 0xff) / 255.0f, (float) (rrggbb & 0xff) / 255.0f, 1.0});
1416
}
@@ -19,15 +21,15 @@ Ssd::Ssd(View& parent) noexcept : view(parent) {
1921
wlr_scene_node_set_position(&scene_tree->node, 0, 0);
2022
wlr_scene_node_set_enabled(&scene_tree->node, true);
2123

22-
auto titlebar_color = rrggbb_to_floats(TITLEBAR_COLOR);
24+
auto titlebar_color = rrggbb_to_floats(TITLEBAR_INACTIVE_COLOR);
2325
auto view_geo = view.get_surface_geometry();
2426
titlebar_rect = wlr_scene_rect_create(scene_tree, view_geo.width, TITLEBAR_HEIGHT, titlebar_color.data());
2527
titlebar_rect->node.data = &parent;
2628
wlr_scene_node_set_position(&titlebar_rect->node, BORDER_WIDTH, BORDER_WIDTH);
2729
wlr_scene_node_lower_to_bottom(&titlebar_rect->node);
2830
wlr_scene_node_set_enabled(&titlebar_rect->node, true);
2931

30-
auto border_color = rrggbb_to_floats(BORDER_COLOR);
32+
auto border_color = rrggbb_to_floats(BORDER_INACTIVE_COLOR);
3133
border_rect = wlr_scene_rect_create(
3234
scene_tree, view_geo.width + get_extra_width(), view_geo.height + get_extra_height(), border_color.data());
3335
wlr_scene_node_set_position(&border_rect->node, 0, 0);
@@ -45,6 +47,14 @@ void Ssd::update() const {
4547
wlr_scene_rect_set_size(border_rect, view_geo.width + get_extra_width(), view_geo.height + get_extra_height());
4648
}
4749

50+
void Ssd::set_activated(const bool activated) const {
51+
auto titlebar_color = rrggbb_to_floats(activated ? TITLEBAR_ACTIVE_COLOR : TITLEBAR_INACTIVE_COLOR);
52+
wlr_scene_rect_set_color(titlebar_rect, titlebar_color.data());
53+
54+
auto border_color = rrggbb_to_floats(activated ? BORDER_ACTIVE_COLOR : BORDER_INACTIVE_COLOR);
55+
wlr_scene_rect_set_color(border_rect, border_color.data());
56+
}
57+
4858
wlr_box Ssd::get_geometry() const {
4959
auto view_geo = view.get_surface_geometry();
5060
return {.x = view_geo.x - get_horizontal_offset(),

src/decorations/ssd.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class Ssd final : public std::enable_shared_from_this<Ssd> {
2020
~Ssd();
2121

2222
void update() const;
23-
wlr_box get_geometry() const;
23+
void set_activated(bool activated) const;
2424

25+
wlr_box get_geometry() const;
2526
uint8_t get_vertical_offset() const;
2627
uint8_t get_horizontal_offset() const;
2728
int32_t get_extra_width() const;

src/surface/view.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ void View::set_activated(const bool activated) {
249249
toplevel_handle->set_activated(activated);
250250
}
251251

252+
if (ssd.has_value()) {
253+
ssd->set_activated(activated);
254+
}
255+
252256
const auto seat = get_server().seat;
253257
if (activated) {
254258
wlr_scene_node_raise_to_top(&scene_tree->node);

0 commit comments

Comments
 (0)