Skip to content

Commit a8f0b2c

Browse files
committed
Add a --wallpaper argument to optionally disable wallpaper draws
1 parent 8cb0ee6 commit a8f0b2c

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/background_client.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct BackgroundClient::Self : egmde::FullscreenClient
9494
wl_display* display,
9595
miral::MirRunner* runner,
9696
WindowManagerObserver* window_manager_observer,
97+
bool wallpaper_enabled,
9798
Colour const& wallpaper_top_colour,
9899
Colour const& wallpaper_bottom_colour,
99100
Colour const& crash_background_colour,
@@ -105,6 +106,7 @@ struct BackgroundClient::Self : egmde::FullscreenClient
105106

106107
void render_text(uint32_t width, uint32_t height, unsigned char* buffer) const;
107108

109+
bool const wallpaper_enabled;
108110
Colour const& wallpaper_top_colour;
109111
Colour const& wallpaper_bottom_colour;
110112
Colour const& crash_background_colour;
@@ -182,6 +184,11 @@ void BackgroundClient::set_colour(std::string const& option, Colour& colour)
182184
}
183185
}
184186

187+
void BackgroundClient::set_wallpaper_enabled(bool option)
188+
{
189+
wallpaper_enabled = option;
190+
}
191+
185192
void BackgroundClient::set_wallpaper_top_colour(std::string const& option)
186193
{
187194
set_colour(option, wallpaper_top_colour);
@@ -293,6 +300,7 @@ void BackgroundClient::operator()(wl_display* display)
293300
display,
294301
runner,
295302
window_manager_observer,
303+
wallpaper_enabled,
296304
wallpaper_top_colour,
297305
wallpaper_bottom_colour,
298306
crash_background_colour,
@@ -319,6 +327,7 @@ BackgroundClient::Self::Self(
319327
wl_display* display,
320328
miral::MirRunner* runner,
321329
WindowManagerObserver* window_manager_observer,
330+
bool wallpaper_enabled,
322331
Colour const& wallpaper_top_colour,
323332
Colour const& wallpaper_bottom_colour,
324333
Colour const& crash_background_colour,
@@ -327,6 +336,7 @@ BackgroundClient::Self::Self(
327336
uint diagnostic_delay)
328337
: FullscreenClient(display, diagnostic_path, diagnostic_delay, runner, window_manager_observer),
329338
runner{runner},
339+
wallpaper_enabled{wallpaper_enabled},
330340
wallpaper_top_colour{wallpaper_top_colour},
331341
wallpaper_bottom_colour{wallpaper_bottom_colour},
332342
crash_background_colour{crash_background_colour},
@@ -377,6 +387,14 @@ void BackgroundClient::Self::draw_screen(SurfaceInfo& info, bool draws_crash) co
377387
{
378388
std::lock_guard lock{buffer_mutex};
379389

390+
// Don't draw diagnostic background if file is empty or font not found
391+
bool const have_diagnostic = diagnostic_path && fs::exists(diagnostic_path.value()) && fs::file_size(diagnostic_path.value());
392+
bool const should_show_diagnostic = draws_crash && have_diagnostic;
393+
if (!wallpaper_enabled && !should_show_diagnostic)
394+
{
395+
return;
396+
}
397+
380398
bool const rotated = info.output->transform & WL_OUTPUT_TRANSFORM_90;
381399
auto const width = rotated ? info.output->height : info.output->width;
382400
auto const height = rotated ? info.output->width : info.output->height;
@@ -418,18 +436,7 @@ void BackgroundClient::Self::draw_screen(SurfaceInfo& info, bool draws_crash) co
418436

419437
auto buffer = static_cast<unsigned char*>(info.content_area);
420438

421-
// Don't draw diagnostic background if file is empty or font not found
422-
bool file_exists;
423-
if (fs::exists(diagnostic_path.value_or("")))
424-
{
425-
file_exists = fs::file_size(diagnostic_path.value());
426-
}
427-
else
428-
{
429-
file_exists = false;
430-
}
431-
432-
if (draws_crash && file_exists)
439+
if (should_show_diagnostic)
433440
{
434441
render_background(width, height, buffer, crash_background_colour);
435442
render_text(width, height, buffer);

src/background_client.h

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class BackgroundClient
4444
public:
4545
BackgroundClient(miral::MirRunner* runner, WindowManagerObserver* window_manager_observer);
4646

47+
void set_wallpaper_enabled(bool option);
4748
void set_wallpaper_top_colour(std::string const& option);
4849
void set_wallpaper_bottom_colour(std::string const& option);
4950
void set_crash_background_colour(std::string const& option);
@@ -76,6 +77,7 @@ class BackgroundClient
7677

7778
std::mutex mutable mutex;
7879

80+
bool wallpaper_enabled = true;
7981
Colour wallpaper_top_colour = {127, 127, 127, 255};
8082
Colour wallpaper_bottom_colour = {31, 31, 31, 255};
8183
Colour crash_background_colour = {36, 12, 56, 255};

src/frame_main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ int main(int argc, char const* argv[])
5050
wayland_extensions,
5151
display_config,
5252
display_config.layout_option(),
53+
ConfigurationOption{[&](bool option) { background_client.set_wallpaper_enabled(option); },
54+
"wallpaper", "Specifies whether or not the wallpaper is enabled", true},
5355
ConfigurationOption{[&](auto& option) { background_client.set_wallpaper_top_colour(option);},
5456
"wallpaper-top", "Colour of wallpaper RGB", "0x7f7f7f"},
5557
ConfigurationOption{[&](auto& option) { background_client.set_wallpaper_bottom_colour(option);},

0 commit comments

Comments
 (0)