diff options
author | Tom <tomut@yahoo.com> | 2021-06-19 13:19:18 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-20 14:57:26 +0200 |
commit | 75dc94064d3421881ea0d7daf77a022aebf7d74d (patch) | |
tree | 179007b5efcf44cf81c0a09ecde9de83af7b6662 /Userland/Services/WindowServer | |
parent | 14fe7283e1146cfdedf181c89db7acc9925021e5 (diff) | |
download | serenity-75dc94064d3421881ea0d7daf77a022aebf7d74d.zip |
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.
Diffstat (limited to 'Userland/Services/WindowServer')
-rw-r--r-- | Userland/Services/WindowServer/MultiScaleBitmaps.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/WindowServer/MultiScaleBitmaps.h | 2 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowFrame.cpp | 51 |
3 files changed, 20 insertions, 35 deletions
diff --git a/Userland/Services/WindowServer/MultiScaleBitmaps.cpp b/Userland/Services/WindowServer/MultiScaleBitmaps.cpp index 0d3fa827ea..8ad1a2184e 100644 --- a/Userland/Services/WindowServer/MultiScaleBitmaps.cpp +++ b/Userland/Services/WindowServer/MultiScaleBitmaps.cpp @@ -38,6 +38,8 @@ bool MultiScaleBitmaps::load(StringView const& filename, StringView const& defau Optional<Gfx::BitmapFormat> bitmap_format; 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 bitmap = Gfx::Bitmap::load_from_file(path, scale_factor); if (bitmap) { diff --git a/Userland/Services/WindowServer/MultiScaleBitmaps.h b/Userland/Services/WindowServer/MultiScaleBitmaps.h index 90e4c95cdf..830ef97c58 100644 --- a/Userland/Services/WindowServer/MultiScaleBitmaps.h +++ b/Userland/Services/WindowServer/MultiScaleBitmaps.h @@ -20,10 +20,10 @@ public: Gfx::Bitmap const& default_bitmap() const { return bitmap(1); } Gfx::Bitmap const& bitmap(int scale_factor) const; Gfx::BitmapFormat format() const { return m_format; } + bool load(StringView const& filename, StringView const& default_filename = {}); private: MultiScaleBitmaps() = default; - bool load(StringView const& filename, StringView const& default_filename); HashMap<int, NonnullRefPtr<Gfx::Bitmap>> m_bitmaps; Gfx::BitmapFormat m_format { Gfx::BitmapFormat::Invalid }; diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index ab394dc803..e237d5c8f5 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -41,8 +41,6 @@ static RefPtr<MultiScaleBitmaps> s_restore_icon; static RefPtr<MultiScaleBitmaps> s_close_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_inactive_window_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(); - StringBuilder full_path; - if (!s_minimize_icon || s_last_title_button_icons_path != icons_path) { - full_path.append(icons_path); - full_path.append("window-minimize.png"); - s_minimize_icon = MultiScaleBitmaps::create(full_path.to_string(), "/res/icons/16x16/downward-triangle.png"); - full_path.clear(); - } - if (!s_maximize_icon || s_last_title_button_icons_path != icons_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) { + auto reload_icon = [&](RefPtr<MultiScaleBitmaps>& icon, StringView const& path, StringView const& default_path) { + StringBuilder full_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(); - } + full_path.append(path); + if (icon) + icon->load(full_path.to_string(), default_path); + else + icon = MultiScaleBitmaps::create(full_path.to_string(), default_path); + }; - 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) { if (path.is_empty()) { last_path = String::empty(); shadow_bitmap = nullptr; } 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) last_path = path; else |