1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:27:45 +00:00

WindowServer: Reload icons on scale changes

Since MultiScaleBitmaps only loads icons for the scales in use, we need
to unconditionally reload them so that we pick up the correct bitmaps
for a scale that hasn't been previously used.
This commit is contained in:
Tom 2021-06-19 13:19:18 -06:00 committed by Andreas Kling
parent 14fe7283e1
commit 75dc94064d
3 changed files with 20 additions and 35 deletions

View file

@ -38,6 +38,8 @@ bool MultiScaleBitmaps::load(StringView const& filename, StringView const& defau
Optional<Gfx::BitmapFormat> bitmap_format; Optional<Gfx::BitmapFormat> bitmap_format;
bool did_load_any = false; bool did_load_any = false;
m_bitmaps.clear(); // If we're reloading the bitmaps get rid of the old ones
auto add_bitmap = [&](StringView const& path, int scale_factor) { auto add_bitmap = [&](StringView const& path, int scale_factor) {
auto bitmap = Gfx::Bitmap::load_from_file(path, scale_factor); auto bitmap = Gfx::Bitmap::load_from_file(path, scale_factor);
if (bitmap) { if (bitmap) {

View file

@ -20,10 +20,10 @@ public:
Gfx::Bitmap const& default_bitmap() const { return bitmap(1); } Gfx::Bitmap const& default_bitmap() const { return bitmap(1); }
Gfx::Bitmap const& bitmap(int scale_factor) const; Gfx::Bitmap const& bitmap(int scale_factor) const;
Gfx::BitmapFormat format() const { return m_format; } Gfx::BitmapFormat format() const { return m_format; }
bool load(StringView const& filename, StringView const& default_filename = {});
private: private:
MultiScaleBitmaps() = default; MultiScaleBitmaps() = default;
bool load(StringView const& filename, StringView const& default_filename);
HashMap<int, NonnullRefPtr<Gfx::Bitmap>> m_bitmaps; HashMap<int, NonnullRefPtr<Gfx::Bitmap>> m_bitmaps;
Gfx::BitmapFormat m_format { Gfx::BitmapFormat::Invalid }; Gfx::BitmapFormat m_format { Gfx::BitmapFormat::Invalid };

View file

@ -41,8 +41,6 @@ static RefPtr<MultiScaleBitmaps> s_restore_icon;
static RefPtr<MultiScaleBitmaps> s_close_icon; static RefPtr<MultiScaleBitmaps> s_close_icon;
static RefPtr<MultiScaleBitmaps> s_close_modified_icon; static RefPtr<MultiScaleBitmaps> s_close_modified_icon;
static String s_last_title_button_icons_path;
static RefPtr<MultiScaleBitmaps> s_active_window_shadow; static RefPtr<MultiScaleBitmaps> s_active_window_shadow;
static RefPtr<MultiScaleBitmaps> s_inactive_window_shadow; static RefPtr<MultiScaleBitmaps> s_inactive_window_shadow;
static RefPtr<MultiScaleBitmaps> s_menu_shadow; static RefPtr<MultiScaleBitmaps> s_menu_shadow;
@ -126,46 +124,31 @@ void WindowFrame::reload_config()
{ {
String icons_path = WindowManager::the().palette().title_button_icons_path(); String icons_path = WindowManager::the().palette().title_button_icons_path();
StringBuilder full_path; auto reload_icon = [&](RefPtr<MultiScaleBitmaps>& icon, StringView const& path, StringView const& default_path) {
if (!s_minimize_icon || s_last_title_button_icons_path != icons_path) { StringBuilder full_path;
full_path.append(icons_path); full_path.append(icons_path);
full_path.append("window-minimize.png"); full_path.append(path);
s_minimize_icon = MultiScaleBitmaps::create(full_path.to_string(), "/res/icons/16x16/downward-triangle.png"); if (icon)
full_path.clear(); icon->load(full_path.to_string(), default_path);
} else
if (!s_maximize_icon || s_last_title_button_icons_path != icons_path) { icon = MultiScaleBitmaps::create(full_path.to_string(), default_path);
full_path.append(icons_path); };
full_path.append("window-maximize.png");
s_maximize_icon = MultiScaleBitmaps::create(full_path.to_string(), "/res/icons/16x16/upward-triangle.png");
full_path.clear();
}
if (!s_restore_icon || s_last_title_button_icons_path != icons_path) {
full_path.append(icons_path);
full_path.append("window-restore.png");
s_restore_icon = MultiScaleBitmaps::create(full_path.to_string(), "/res/icons/16x16/window-restore.png");
full_path.clear();
}
if (!s_close_icon || s_last_title_button_icons_path != icons_path) {
full_path.append(icons_path);
full_path.append("window-close.png");
s_close_icon = MultiScaleBitmaps::create(full_path.to_string(), "/res/icons/16x16/window-close.png");
full_path.clear();
}
if (!s_close_modified_icon || s_last_title_button_icons_path != icons_path) {
full_path.append(icons_path);
full_path.append("window-close-modified.png");
s_close_modified_icon = MultiScaleBitmaps::create(full_path.to_string(), "/res/icons/16x16/window-close-modified.png");
full_path.clear();
}
s_last_title_button_icons_path = icons_path; reload_icon(s_minimize_icon, "window-minimize.png", "/res/icons/16x16/downward-triangle.png");
reload_icon(s_maximize_icon, "window-maximize.png", "/res/icons/16x16/upward-triangle.png");
reload_icon(s_restore_icon, "window-restore.png", "/res/icons/16x16/window-restore.png");
reload_icon(s_close_icon, "window-close.png", "/res/icons/16x16/window-close.png");
reload_icon(s_close_modified_icon, "window-close-modified.png", "/res/icons/16x16/window-close-modified.png");
auto load_shadow = [](const String& path, String& last_path, RefPtr<MultiScaleBitmaps>& shadow_bitmap) { auto load_shadow = [](const String& path, String& last_path, RefPtr<MultiScaleBitmaps>& shadow_bitmap) {
if (path.is_empty()) { if (path.is_empty()) {
last_path = String::empty(); last_path = String::empty();
shadow_bitmap = nullptr; shadow_bitmap = nullptr;
} else if (!shadow_bitmap || last_path != path) { } else if (!shadow_bitmap || last_path != path) {
shadow_bitmap = MultiScaleBitmaps::create(path); if (shadow_bitmap)
shadow_bitmap->load(path);
else
shadow_bitmap = MultiScaleBitmaps::create(path);
if (shadow_bitmap) if (shadow_bitmap)
last_path = path; last_path = path;
else else