Skip to content

Commit cf210fe

Browse files
committed
Add invisible extents to any view with SSDs
1 parent 6fd1514 commit cf210fe

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

src/decorations/ssd.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,28 @@ constexpr uint8_t TITLEBAR_HEIGHT = 24;
77
constexpr uint32_t TITLEBAR_ACTIVE_COLOR = 0x303030;
88
constexpr uint32_t TITLEBAR_INACTIVE_COLOR = 0x202020;
99
constexpr uint8_t BORDER_WIDTH = 1;
10+
constexpr uint8_t EXTENTS_WIDTH = 8;
1011
constexpr uint32_t BORDER_ACTIVE_COLOR = 0x505050;
1112
constexpr uint32_t BORDER_INACTIVE_COLOR = 0x404040;
1213

14+
static wlr_box border_dimensions(wlr_box& view_dimensions) {
15+
return {
16+
.x = EXTENTS_WIDTH,
17+
.y = EXTENTS_WIDTH,
18+
.width = view_dimensions.width + (BORDER_WIDTH * 2),
19+
.height = view_dimensions.height + TITLEBAR_HEIGHT + (BORDER_WIDTH * 2),
20+
};
21+
}
22+
23+
static wlr_box extents_dimensions(wlr_box& view_dimensions) {
24+
return {
25+
.x = 0,
26+
.y = 0,
27+
.width = view_dimensions.width + (EXTENTS_WIDTH * 2) + (BORDER_WIDTH * 2),
28+
.height = view_dimensions.height + TITLEBAR_HEIGHT + (EXTENTS_WIDTH * 2) + (BORDER_WIDTH * 2),
29+
};
30+
}
31+
1332
static constexpr std::array<float, 4> rrggbb_to_floats(uint32_t rrggbb) {
1433
return std::array<float, 4>(
1534
{(float) (rrggbb >> 16 & 0xff) / 255.0f, (float) (rrggbb >> 8 & 0xff) / 255.0f, (float) (rrggbb & 0xff) / 255.0f, 1.0});
@@ -25,29 +44,43 @@ Ssd::Ssd(View& parent) noexcept : view(parent) {
2544
auto view_geo = view.get_surface_geometry();
2645
titlebar_rect = wlr_scene_rect_create(scene_tree, view_geo.width, TITLEBAR_HEIGHT, titlebar_color.data());
2746
titlebar_rect->node.data = new SceneRectData{.type = SceneRectType::TITLEBAR, .parent = &parent};
28-
wlr_scene_node_set_position(&titlebar_rect->node, BORDER_WIDTH, BORDER_WIDTH);
47+
wlr_scene_node_set_position(&titlebar_rect->node, BORDER_WIDTH + EXTENTS_WIDTH, BORDER_WIDTH + EXTENTS_WIDTH);
2948
wlr_scene_node_lower_to_bottom(&titlebar_rect->node);
3049
wlr_scene_node_set_enabled(&titlebar_rect->node, true);
3150

51+
auto extents_color = std::array<float, 4>({0.0f, 0.0f, 0.0f, 0.0f});
52+
auto extents_box = extents_dimensions(view_geo);
53+
extents_rect = wlr_scene_rect_create(scene_tree, extents_box.width, extents_box.height, extents_color.data());
54+
extents_rect->node.data = new SceneRectData{.type = SceneRectType::EXTENTS, .parent = &parent};
55+
wlr_scene_node_set_position(&extents_rect->node, extents_box.x, extents_box.y);
56+
wlr_scene_node_lower_to_bottom(&extents_rect->node);
57+
wlr_scene_node_set_enabled(&extents_rect->node, true);
58+
3259
auto border_color = rrggbb_to_floats(BORDER_INACTIVE_COLOR);
33-
border_rect = wlr_scene_rect_create(
34-
scene_tree, view_geo.width + get_extra_width(), view_geo.height + get_extra_height(), border_color.data());
60+
auto border_box = border_dimensions(view_geo);
61+
border_rect = wlr_scene_rect_create(scene_tree, border_box.width, border_box.height, border_color.data());
3562
border_rect->node.data = new SceneRectData{.type = SceneRectType::BORDER, .parent = &parent};
36-
wlr_scene_node_set_position(&border_rect->node, 0, 0);
63+
wlr_scene_node_set_position(&border_rect->node, border_box.x, border_box.y);
3764
wlr_scene_node_lower_to_bottom(&border_rect->node);
3865
wlr_scene_node_set_enabled(&border_rect->node, true);
3966
}
4067

4168
Ssd::~Ssd() {
4269
delete static_cast<SceneRectData*>(titlebar_rect->node.data);
4370
delete static_cast<SceneRectData*>(border_rect->node.data);
71+
delete static_cast<SceneRectData*>(extents_rect->node.data);
4472
wlr_scene_node_destroy(&scene_tree->node);
4573
}
4674

4775
void Ssd::update() const {
4876
auto view_geo = view.get_surface_geometry();
4977
wlr_scene_rect_set_size(titlebar_rect, view_geo.width, TITLEBAR_HEIGHT);
50-
wlr_scene_rect_set_size(border_rect, view_geo.width + get_extra_width(), view_geo.height + get_extra_height());
78+
79+
auto border_box = border_dimensions(view_geo);
80+
wlr_scene_rect_set_size(border_rect, border_box.width, border_box.height);
81+
82+
auto extents_box = extents_dimensions(view_geo);
83+
wlr_scene_rect_set_size(extents_rect, extents_box.width, extents_box.height);
5184
}
5285

5386
void Ssd::set_activated(const bool activated) const {
@@ -67,17 +100,21 @@ wlr_box Ssd::get_geometry() const {
67100
}
68101

69102
uint8_t Ssd::get_vertical_offset() const {
103+
return TITLEBAR_HEIGHT + BORDER_WIDTH + EXTENTS_WIDTH;
104+
}
105+
106+
uint8_t Ssd::get_visual_vertical_offset() const {
70107
return TITLEBAR_HEIGHT + BORDER_WIDTH;
71108
}
72109

73110
uint8_t Ssd::get_horizontal_offset() const {
74-
return BORDER_WIDTH;
111+
return BORDER_WIDTH + EXTENTS_WIDTH;
75112
}
76113

77114
int32_t Ssd::get_extra_width() const {
78-
return BORDER_WIDTH * 2;
115+
return (BORDER_WIDTH * 2) + (EXTENTS_WIDTH * 2);
79116
}
80117

81118
int32_t Ssd::get_extra_height() const {
82-
return TITLEBAR_HEIGHT + BORDER_WIDTH * 2;
119+
return TITLEBAR_HEIGHT + (BORDER_WIDTH * 2) + (EXTENTS_WIDTH * 2);
83120
}

src/decorations/ssd.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Ssd final : public std::enable_shared_from_this<Ssd> {
1515
wlr_scene_tree* scene_tree = nullptr;
1616
wlr_scene_rect* titlebar_rect = nullptr;
1717
wlr_scene_rect* border_rect = nullptr;
18+
wlr_scene_rect* extents_rect = nullptr;
1819

1920
explicit Ssd(View& parent) noexcept;
2021
~Ssd();
@@ -24,6 +25,7 @@ class Ssd final : public std::enable_shared_from_this<Ssd> {
2425

2526
wlr_box get_geometry() const;
2627
uint8_t get_vertical_offset() const;
28+
uint8_t get_visual_vertical_offset() const;
2729
uint8_t get_horizontal_offset() const;
2830
int32_t get_extra_width() const;
2931
int32_t get_extra_height() const;

src/input/cursor.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ static void cursor_button_notify(wl_listener* listener, void* data) {
199199
/* Focus that client if the button was _pressed_ */
200200
server.focus_view(std::dynamic_pointer_cast<View>(magpie_surface));
201201

202-
203202
if (server.ssd_at(cursor.wlr.x, cursor.wlr.y) == SceneRectType::TITLEBAR) {
204203
view->begin_interactive(MAGPIE_CURSOR_MOVE, 0);
205204
}
@@ -443,15 +442,17 @@ void Cursor::process_motion(const uint32_t time) {
443442
double sy;
444443
wlr_surface* surface = nullptr;
445444
auto magpie_surface = seat.server.surface_at(wlr.x, wlr.y, &surface, &sx, &sy).lock();
446-
bool ssd_at_cursor = seat.server.ssd_at(wlr.x, wlr.y) != SceneRectType::NONE;
447-
if (ssd_at_cursor || magpie_surface == nullptr) {
445+
SceneRectType ssd_at_cursor = seat.server.ssd_at(wlr.x, wlr.y);
446+
if (ssd_at_cursor == SceneRectType::TITLEBAR || ssd_at_cursor == SceneRectType::NONE || magpie_surface == nullptr) {
448447
/* If there's no view under the cursor, set the cursor image to a
449448
* default. This is what makes the cursor image appear when you move it
450449
* around the screen, not over any views. */
451450
set_image("left_ptr");
451+
} else if (ssd_at_cursor == SceneRectType::BORDER || ssd_at_cursor == SceneRectType::EXTENTS) {
452+
set_image("fleur");
452453
}
453454

454-
if (!ssd_at_cursor && surface != nullptr) {
455+
if (ssd_at_cursor == SceneRectType::NONE && surface != nullptr) {
455456
/*
456457
* Send pointer enter and motion events.
457458
*

src/surface/view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ int32_t View::find_surface_min_y() const {
9898

9999
min_y = min_y == INT32_MAX ? 0 : min_y;
100100
if (ssd.has_value()) {
101-
return min_y + ssd->get_vertical_offset();
101+
return min_y + ssd->get_visual_vertical_offset();
102102
} else {
103103
return min_y;
104104
}

0 commit comments

Comments
 (0)