From a8f0b2c143ebd022987375eeef5a97d297083848 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 25 Oct 2023 09:06:59 -0400 Subject: [PATCH] Add a --wallpaper argument to optionally disable wallpaper draws --- src/background_client.cpp | 31 +++++++++++++++++++------------ src/background_client.h | 2 ++ src/frame_main.cpp | 2 ++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/background_client.cpp b/src/background_client.cpp index 774a34f..267976f 100644 --- a/src/background_client.cpp +++ b/src/background_client.cpp @@ -94,6 +94,7 @@ struct BackgroundClient::Self : egmde::FullscreenClient wl_display* display, miral::MirRunner* runner, WindowManagerObserver* window_manager_observer, + bool wallpaper_enabled, Colour const& wallpaper_top_colour, Colour const& wallpaper_bottom_colour, Colour const& crash_background_colour, @@ -105,6 +106,7 @@ struct BackgroundClient::Self : egmde::FullscreenClient void render_text(uint32_t width, uint32_t height, unsigned char* buffer) const; + bool const wallpaper_enabled; Colour const& wallpaper_top_colour; Colour const& wallpaper_bottom_colour; Colour const& crash_background_colour; @@ -182,6 +184,11 @@ void BackgroundClient::set_colour(std::string const& option, Colour& colour) } } +void BackgroundClient::set_wallpaper_enabled(bool option) +{ + wallpaper_enabled = option; +} + void BackgroundClient::set_wallpaper_top_colour(std::string const& option) { set_colour(option, wallpaper_top_colour); @@ -293,6 +300,7 @@ void BackgroundClient::operator()(wl_display* display) display, runner, window_manager_observer, + wallpaper_enabled, wallpaper_top_colour, wallpaper_bottom_colour, crash_background_colour, @@ -319,6 +327,7 @@ BackgroundClient::Self::Self( wl_display* display, miral::MirRunner* runner, WindowManagerObserver* window_manager_observer, + bool wallpaper_enabled, Colour const& wallpaper_top_colour, Colour const& wallpaper_bottom_colour, Colour const& crash_background_colour, @@ -327,6 +336,7 @@ BackgroundClient::Self::Self( uint diagnostic_delay) : FullscreenClient(display, diagnostic_path, diagnostic_delay, runner, window_manager_observer), runner{runner}, + wallpaper_enabled{wallpaper_enabled}, wallpaper_top_colour{wallpaper_top_colour}, wallpaper_bottom_colour{wallpaper_bottom_colour}, crash_background_colour{crash_background_colour}, @@ -377,6 +387,14 @@ void BackgroundClient::Self::draw_screen(SurfaceInfo& info, bool draws_crash) co { std::lock_guard lock{buffer_mutex}; + // Don't draw diagnostic background if file is empty or font not found + bool const have_diagnostic = diagnostic_path && fs::exists(diagnostic_path.value()) && fs::file_size(diagnostic_path.value()); + bool const should_show_diagnostic = draws_crash && have_diagnostic; + if (!wallpaper_enabled && !should_show_diagnostic) + { + return; + } + bool const rotated = info.output->transform & WL_OUTPUT_TRANSFORM_90; auto const width = rotated ? info.output->height : info.output->width; 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 auto buffer = static_cast(info.content_area); - // Don't draw diagnostic background if file is empty or font not found - bool file_exists; - if (fs::exists(diagnostic_path.value_or(""))) - { - file_exists = fs::file_size(diagnostic_path.value()); - } - else - { - file_exists = false; - } - - if (draws_crash && file_exists) + if (should_show_diagnostic) { render_background(width, height, buffer, crash_background_colour); render_text(width, height, buffer); diff --git a/src/background_client.h b/src/background_client.h index d90ac52..0f8879f 100644 --- a/src/background_client.h +++ b/src/background_client.h @@ -44,6 +44,7 @@ class BackgroundClient public: BackgroundClient(miral::MirRunner* runner, WindowManagerObserver* window_manager_observer); + void set_wallpaper_enabled(bool option); void set_wallpaper_top_colour(std::string const& option); void set_wallpaper_bottom_colour(std::string const& option); void set_crash_background_colour(std::string const& option); @@ -76,6 +77,7 @@ class BackgroundClient std::mutex mutable mutex; + bool wallpaper_enabled = true; Colour wallpaper_top_colour = {127, 127, 127, 255}; Colour wallpaper_bottom_colour = {31, 31, 31, 255}; Colour crash_background_colour = {36, 12, 56, 255}; diff --git a/src/frame_main.cpp b/src/frame_main.cpp index d5b9a1d..2d99c72 100644 --- a/src/frame_main.cpp +++ b/src/frame_main.cpp @@ -50,6 +50,8 @@ int main(int argc, char const* argv[]) wayland_extensions, display_config, display_config.layout_option(), + ConfigurationOption{[&](bool option) { background_client.set_wallpaper_enabled(option); }, + "wallpaper", "Specifies whether or not the wallpaper is enabled", true}, ConfigurationOption{[&](auto& option) { background_client.set_wallpaper_top_colour(option);}, "wallpaper-top", "Colour of wallpaper RGB", "0x7f7f7f"}, ConfigurationOption{[&](auto& option) { background_client.set_wallpaper_bottom_colour(option);},