Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --wallpaper argument to optionally disable wallpaper draws #157

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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