3
3
#include " surface/view.hpp"
4
4
#include " server.hpp"
5
5
6
+ #include " wlr-wrap-start.hpp"
7
+ #include < wlr/util/log.h>
8
+ #include " wlr-wrap-end.hpp"
9
+
6
10
constexpr uint8_t TITLEBAR_HEIGHT = 24 ;
7
11
constexpr uint32_t TITLEBAR_ACTIVE_COLOR = 0x303030 ;
8
12
constexpr uint32_t TITLEBAR_INACTIVE_COLOR = 0x202020 ;
@@ -11,7 +15,7 @@ constexpr uint8_t EXTENTS_WIDTH = 12;
11
15
constexpr uint32_t BORDER_ACTIVE_COLOR = 0x505050 ;
12
16
constexpr uint32_t BORDER_INACTIVE_COLOR = 0x404040 ;
13
17
14
- static wlr_box border_dimensions (wlr_box& view_dimensions) {
18
+ static wlr_box border_dimensions (const wlr_box& view_dimensions) {
15
19
return {
16
20
.x = EXTENTS_WIDTH,
17
21
.y = EXTENTS_WIDTH,
@@ -20,7 +24,7 @@ static wlr_box border_dimensions(wlr_box& view_dimensions) {
20
24
};
21
25
}
22
26
23
- static wlr_box extents_dimensions (wlr_box& view_dimensions) {
27
+ static wlr_box extents_dimensions (const wlr_box& view_dimensions) {
24
28
return {
25
29
.x = 0 ,
26
30
.y = 0 ,
@@ -29,7 +33,7 @@ static wlr_box extents_dimensions(wlr_box& view_dimensions) {
29
33
};
30
34
}
31
35
32
- static constexpr std::array<float , 4 > rrggbb_to_floats (uint32_t rrggbb) {
36
+ static constexpr std::array<float , 4 > rrggbb_to_floats (const uint32_t rrggbb) {
33
37
return std::array<float , 4 >(
34
38
{(float ) (rrggbb >> 16 & 0xff ) / 255 .0f , (float ) (rrggbb >> 8 & 0xff ) / 255 .0f , (float ) (rrggbb & 0xff ) / 255 .0f , 1.0 });
35
39
}
@@ -40,26 +44,41 @@ Ssd::Ssd(View& parent) noexcept : view(parent) {
40
44
wlr_scene_node_set_position (&scene_tree->node , 0 , 0 );
41
45
wlr_scene_node_set_enabled (&scene_tree->node , true );
42
46
43
- auto titlebar_color = rrggbb_to_floats (TITLEBAR_INACTIVE_COLOR);
47
+ constexpr auto titlebar_color = rrggbb_to_floats (TITLEBAR_INACTIVE_COLOR);
44
48
auto view_geo = view.get_surface_geometry ();
45
49
titlebar_rect = wlr_scene_rect_create (scene_tree, view_geo.width , TITLEBAR_HEIGHT, titlebar_color.data ());
46
- titlebar_rect->node .data = new SceneRectData{.type = SceneRectType::TITLEBAR, .parent = &parent};
50
+ try {
51
+ titlebar_rect->node .data = new SceneRectData{.type = SceneRectType::TITLEBAR, .parent = &parent};
52
+ } catch ([[maybe_unused]] std::bad_alloc& ex) {
53
+ wlr_log (WLR_ERROR, " Failed to allocate memory for window decoration titlebar" );
54
+ exit (EXIT_FAILURE);
55
+ }
47
56
wlr_scene_node_set_position (&titlebar_rect->node , BORDER_WIDTH + EXTENTS_WIDTH, BORDER_WIDTH + EXTENTS_WIDTH);
48
57
wlr_scene_node_lower_to_bottom (&titlebar_rect->node );
49
58
wlr_scene_node_set_enabled (&titlebar_rect->node , true );
50
59
51
- auto extents_color = std::array<float , 4 >({0 .0f , 0 .0f , 0 .0f , 0 .0f });
60
+ constexpr auto extents_color = std::array<float , 4 >({0 .0f , 0 .0f , 0 .0f , 0 .0f });
52
61
auto extents_box = extents_dimensions (view_geo);
53
62
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};
63
+ try {
64
+ extents_rect->node .data = new SceneRectData{.type = SceneRectType::EXTENTS, .parent = &parent};
65
+ } catch ([[maybe_unused]] std::bad_alloc& ex) {
66
+ wlr_log (WLR_ERROR, " Failed to allocate memory for window decoration extents" );
67
+ exit (EXIT_FAILURE);
68
+ }
55
69
wlr_scene_node_set_position (&extents_rect->node , extents_box.x , extents_box.y );
56
70
wlr_scene_node_lower_to_bottom (&extents_rect->node );
57
71
wlr_scene_node_set_enabled (&extents_rect->node , true );
58
72
59
- auto border_color = rrggbb_to_floats (BORDER_INACTIVE_COLOR);
73
+ constexpr auto border_color = rrggbb_to_floats (BORDER_INACTIVE_COLOR);
60
74
auto border_box = border_dimensions (view_geo);
61
75
border_rect = wlr_scene_rect_create (scene_tree, border_box.width , border_box.height , border_color.data ());
62
- border_rect->node .data = new SceneRectData{.type = SceneRectType::BORDER, .parent = &parent};
76
+ try {
77
+ border_rect->node .data = new SceneRectData{.type = SceneRectType::BORDER, .parent = &parent};
78
+ } catch ([[maybe_unused]] std::bad_alloc& ex) {
79
+ wlr_log (WLR_ERROR, " Failed to allocate memory for window decoration border" );
80
+ exit (EXIT_FAILURE);
81
+ }
63
82
wlr_scene_node_set_position (&border_rect->node , border_box.x , border_box.y );
64
83
wlr_scene_node_lower_to_bottom (&border_rect->node );
65
84
wlr_scene_node_set_enabled (&border_rect->node , true );
@@ -76,10 +95,10 @@ void Ssd::update() const {
76
95
auto view_geo = view.surface_current ;
77
96
wlr_scene_rect_set_size (titlebar_rect, view_geo.width , TITLEBAR_HEIGHT);
78
97
79
- auto border_box = border_dimensions (view_geo);
98
+ const auto border_box = border_dimensions (view_geo);
80
99
wlr_scene_rect_set_size (border_rect, border_box.width , border_box.height );
81
100
82
- auto extents_box = extents_dimensions (view_geo);
101
+ const auto extents_box = extents_dimensions (view_geo);
83
102
wlr_scene_rect_set_size (extents_rect, extents_box.width , extents_box.height );
84
103
}
85
104
0 commit comments