Skip to content

Commit

Permalink
Merge pull request #157 from MirServer/feature/disable_background_option
Browse files Browse the repository at this point in the history
Add a --wallpaper argument to optionally disable wallpaper draws
  • Loading branch information
AlanGriffiths authored Oct 25, 2023
2 parents 8cb0ee6 + a8f0b2c commit b1504c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/background_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -418,18 +436,7 @@ void BackgroundClient::Self::draw_screen(SurfaceInfo& info, bool draws_crash) co

auto buffer = static_cast<unsigned char*>(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);
Expand Down
2 changes: 2 additions & 0 deletions src/background_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand Down
2 changes: 2 additions & 0 deletions src/frame_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);},
Expand Down

0 comments on commit b1504c6

Please sign in to comment.