summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-02-09 22:12:32 -0700
committerAndreas Kling <kling@serenityos.org>2021-02-10 09:12:49 +0100
commita807d92a32fc72ec6262e2c41024d67275a9656b (patch)
tree9b7b27af32e580c13d50bd4093809400036115e6
parent5d4c4bd37291b5b5fa8aee179bfeae99a5afd07c (diff)
downloadserenity-a807d92a32fc72ec6262e2c41024d67275a9656b.zip
WindowServer: Fix switching between shadows and no shadows with themes
We weren't properly handling switching between having a shadow and not having a shadow when switching themes. This allows an empty string in the theme configuration for a shadow path, meaning no shadow should be rendered.
-rw-r--r--Userland/Libraries/LibGfx/SystemTheme.cpp16
-rw-r--r--Userland/Services/WindowServer/WindowFrame.cpp15
-rw-r--r--Userland/Services/WindowServer/WindowFrame.h4
-rw-r--r--Userland/Services/WindowServer/WindowManager.cpp1
4 files changed, 25 insertions, 11 deletions
diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp
index 601e9b3dd0..51c31da807 100644
--- a/Userland/Libraries/LibGfx/SystemTheme.cpp
+++ b/Userland/Libraries/LibGfx/SystemTheme.cpp
@@ -85,14 +85,14 @@ Core::AnonymousBuffer load_system_theme(const String& path)
return metric;
};
- auto get_path = [&](auto& name, auto role) {
+ auto get_path = [&](auto& name, auto role, bool allow_empty) {
auto path = file->read_entry("Paths", name);
if (path.is_empty()) {
switch (role) {
case (int)PathRole::TitleButtonIcons:
return "/res/icons/16x16/";
default:
- return "/res/";
+ return allow_empty ? "" : "/res/";
}
}
return &path[0];
@@ -111,17 +111,17 @@ Core::AnonymousBuffer load_system_theme(const String& path)
DO_METRIC(TitleButtonWidth);
DO_METRIC(TitleButtonHeight);
-#define DO_PATH(x) \
+#define DO_PATH(x, allow_empty) \
do { \
- auto path = get_path(#x, (int)PathRole::x); \
+ auto path = get_path(#x, (int)PathRole::x, allow_empty); \
memcpy(data->path[(int)PathRole::x], path, min(strlen(path) + 1, sizeof(data->path[(int)PathRole::x]))); \
data->path[(int)PathRole::x][sizeof(data->path[(int)PathRole::x]) - 1] = '\0'; \
} while (0)
- DO_PATH(TitleButtonIcons);
- DO_PATH(MenuShadow);
- DO_PATH(TooltipShadow);
- DO_PATH(WindowShadow);
+ DO_PATH(TitleButtonIcons, false);
+ DO_PATH(MenuShadow, true);
+ DO_PATH(TooltipShadow, true);
+ DO_PATH(WindowShadow, true);
return buffer;
}
diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp
index 344b8ec528..bf938f0ccb 100644
--- a/Userland/Services/WindowServer/WindowFrame.cpp
+++ b/Userland/Services/WindowServer/WindowFrame.cpp
@@ -169,9 +169,20 @@ void WindowFrame::reload_config()
s_last_title_button_icons_scale = icons_scale;
auto load_shadow = [](const String& path, String& last_path, Gfx::Bitmap*& shadow_bitmap) {
- if (!shadow_bitmap || shadow_bitmap->scale() != s_last_title_button_icons_scale || last_path != path) {
+ if (path.is_empty()) {
+ last_path = String::empty();
+ if (shadow_bitmap) {
+ shadow_bitmap->unref();
+ shadow_bitmap = nullptr;
+ }
+ } else if (!shadow_bitmap || shadow_bitmap->scale() != s_last_title_button_icons_scale || last_path != path) {
+ if (shadow_bitmap)
+ shadow_bitmap->unref();
shadow_bitmap = Gfx::Bitmap::load_from_file(path, s_last_title_button_icons_scale).leak_ref();
- last_path = path;
+ if (shadow_bitmap)
+ last_path = path;
+ else
+ last_path = String::empty();
}
};
load_shadow(WindowManager::the().palette().window_shadow_path(), s_last_window_shadow_path, s_window_shadow);
diff --git a/Userland/Services/WindowServer/WindowFrame.h b/Userland/Services/WindowServer/WindowFrame.h
index 5ced0521ee..fa838c8a5b 100644
--- a/Userland/Services/WindowServer/WindowFrame.h
+++ b/Userland/Services/WindowServer/WindowFrame.h
@@ -90,6 +90,10 @@ public:
void theme_changed()
{
m_dirty = m_shadow_dirty = true;
+ m_top_bottom = nullptr;
+ m_left_right = nullptr;
+ m_bottom_y = m_right_x = 0;
+
layout_buttons();
set_button_icons();
}
diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp
index b555fdba7a..7f8c6bd284 100644
--- a/Userland/Services/WindowServer/WindowManager.cpp
+++ b/Userland/Services/WindowServer/WindowManager.cpp
@@ -1526,7 +1526,6 @@ void WindowManager::reload_icon_bitmaps_after_scale_change(bool allow_hidpi_icon
{
m_allow_hidpi_icons = allow_hidpi_icons;
reload_config();
- WindowFrame::reload_config();
for_each_window([&](Window& window) {
auto& window_frame = window.frame();
window_frame.theme_changed();