From 964894dee628ac88a2e9c27a0f97fa75a6747e48 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 9 Feb 2021 14:13:06 -0700 Subject: [PATCH] WindowServer: Allow specifying different shadows for menus and tooltips Also update the Redmond 2000 theme to drop shadows more Redmond-like. --- Base/res/icons/themes/Redmond/menu-shadow.png | Bin 0 -> 1453 bytes Base/res/themes/Default.ini | 3 +- Base/res/themes/Redmond 2000.ini | 2 + Userland/Libraries/LibGfx/Palette.h | 2 + Userland/Libraries/LibGfx/SystemTheme.cpp | 2 + Userland/Libraries/LibGfx/SystemTheme.h | 2 + .../Services/WindowServer/WindowFrame.cpp | 47 ++++++++++++------ Userland/Services/WindowServer/WindowFrame.h | 2 + .../Services/WindowServer/WindowManager.cpp | 6 ++- 9 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 Base/res/icons/themes/Redmond/menu-shadow.png diff --git a/Base/res/icons/themes/Redmond/menu-shadow.png b/Base/res/icons/themes/Redmond/menu-shadow.png new file mode 100644 index 0000000000000000000000000000000000000000..aa9fb1cca6b0af184bcae25b956be581bedbb638 GIT binary patch literal 1453 zcmeAS@N?(olHy`uVBq!ia0y~yV5neVV2~4FV_;y|9?5o%fq}6l)7d$|)7e>}peR2r zGbfdSL1SX=L|c!;4l+mMgOBoSais|qo(Pz$)752>CE69R@Cw&js~IuBSbe1?iHN%& z-1^|b@uaHGhdT=VVJIvv4l0=_^nbcY)RBsUJN@O~<;vePEDTGUb=8b7V^^+P za-ini$f;IwiVL`vei^74pPu2Z^5}zX{CAEIU-b@c{&W7XW!056M;jVkY)8{ygpglwCqex-I z)sj=tr;KY!+u!}(_dT)do#^v4qc)bT!!xG~ zK4AIqWA;(A$@W5?g+?>a*#G+zbFOyT<(tPZtX{qB`Zb^U*srzsSF$yySUm7^H=oD4 zA%)?=qZ#M96FQeLY!Ivr4`bQj5)`A7Hi316OHcxf*a0EW#)&`P7l0T$9kPYIl{7UT zaXnb2ID6L~S#}mVNt3Np<;i6sn1l7k*LHrT>;ioF)pas#cKdJLFxa~{w<`Vk zmv`%4{;j=SUH$cSbo4TF^Vk2`KP+rFi~hNv@%69Ai`T`+``X*i+_&Gnwl??IpF3Y} z&U|^=`|=MRzPBH%|J?umJLiJsCV81N^>%;w=l9EaU(s)GUzVTe6CX3f&eE{9Cg<0e zEp>mtUHfwQ@SE>PKUeZieBb@=NNs=LwA%Zx%56ENzr9`ikLmpRW%BZ``52nSk9?oF zJuvf$^4A z^BJE>w(!1gW*ZSd& zYWpqS4tY_hI3G-#*u*X+eWQCvM*C}zxfjo^p6YFy^NQi?FY}@v9-~_e=kJ|jW~#JU zkwO1{OpZd0p|y#4pHYF4Ws>rLr`TPHTo zxn*(d#6^=wZpcolor(role); } int metric(MetricRole role) const { return m_impl->metric(role); } diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp index 635bea11f4..601e9b3dd0 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.cpp +++ b/Userland/Libraries/LibGfx/SystemTheme.cpp @@ -119,6 +119,8 @@ Core::AnonymousBuffer load_system_theme(const String& path) } while (0) DO_PATH(TitleButtonIcons); + DO_PATH(MenuShadow); + DO_PATH(TooltipShadow); DO_PATH(WindowShadow); return buffer; diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h index f12fc9b280..a34872c7a6 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.h +++ b/Userland/Libraries/LibGfx/SystemTheme.h @@ -145,6 +145,8 @@ enum class PathRole { NoRole, TitleButtonIcons, WindowShadow, + MenuShadow, + TooltipShadow, __Count, }; diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index 85b13b554d..344b8ec528 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -56,12 +56,16 @@ static Gfx::Bitmap* s_minimize_icon; static Gfx::Bitmap* s_maximize_icon; static Gfx::Bitmap* s_restore_icon; static Gfx::Bitmap* s_close_icon; -static Gfx::Bitmap* s_window_shadow; static String s_last_title_button_icons_path; static int s_last_title_button_icons_scale; +static Gfx::Bitmap* s_window_shadow; +static Gfx::Bitmap* s_menu_shadow; +static Gfx::Bitmap* s_tooltip_shadow; static String s_last_window_shadow_path; +static String s_last_menu_shadow_path; +static String s_last_tooltip_shadow_path; static Gfx::IntRect frame_rect_for_window(Window& window, const Gfx::IntRect& rect) { @@ -111,6 +115,15 @@ void WindowFrame::set_button_icons() if (m_window.is_frameless()) return; + m_close_button->set_icon(*s_close_icon); + if (m_window.is_minimizable()) + m_minimize_button->set_icon(*s_minimize_icon); + if (m_window.is_resizable()) + m_maximize_button->set_icon(m_window.is_maximized() ? *s_restore_icon : *s_maximize_icon); +} + +void WindowFrame::reload_config() +{ String icons_path = WindowManager::the().palette().title_button_icons_path(); int icons_scale = WindowManager::the().compositor_icon_scale(); @@ -152,30 +165,34 @@ void WindowFrame::set_button_icons() full_path.clear(); } - m_close_button->set_icon(*s_close_icon); - if (m_window.is_minimizable()) - m_minimize_button->set_icon(*s_minimize_icon); - if (m_window.is_resizable()) - m_maximize_button->set_icon(m_window.is_maximized() ? *s_restore_icon : *s_maximize_icon); - s_last_title_button_icons_path = icons_path; s_last_title_button_icons_scale = icons_scale; - String window_shadow_path = WindowManager::the().palette().window_shadow_path(); - if (!s_window_shadow || s_window_shadow->scale() != icons_scale || s_last_window_shadow_path != window_shadow_path) { - s_window_shadow = Gfx::Bitmap::load_from_file(window_shadow_path, icons_scale).leak_ref(); - m_shadow_dirty = true; - } - s_last_window_shadow_path = window_shadow_path; + 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) { + shadow_bitmap = Gfx::Bitmap::load_from_file(path, s_last_title_button_icons_scale).leak_ref(); + last_path = path; + } + }; + load_shadow(WindowManager::the().palette().window_shadow_path(), s_last_window_shadow_path, s_window_shadow); + load_shadow(WindowManager::the().palette().menu_shadow_path(), s_last_menu_shadow_path, s_menu_shadow); + load_shadow(WindowManager::the().palette().tooltip_shadow_path(), s_last_tooltip_shadow_path, s_tooltip_shadow); } Gfx::Bitmap* WindowFrame::window_shadow() const { if (m_window.is_frameless()) return nullptr; - if (m_window.type() == WindowType::Desktop) + switch (m_window.type()) { + case WindowType::Desktop: return nullptr; - return s_window_shadow; + case WindowType::Menu: + return s_menu_shadow; + case WindowType::Tooltip: + return s_tooltip_shadow; + default: + return s_window_shadow; + } } bool WindowFrame::frame_has_alpha() const diff --git a/Userland/Services/WindowServer/WindowFrame.h b/Userland/Services/WindowServer/WindowFrame.h index 28c38f04d2..5ced0521ee 100644 --- a/Userland/Services/WindowServer/WindowFrame.h +++ b/Userland/Services/WindowServer/WindowFrame.h @@ -41,6 +41,8 @@ class Window; class WindowFrame { public: + static void reload_config(); + WindowFrame(Window&); ~WindowFrame(); diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 134715eac1..b555fdba7a 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -107,6 +107,8 @@ void WindowManager::reload_config() m_drag_cursor = get_cursor("Drag"); m_wait_cursor = get_cursor("Wait"); m_crosshair_cursor = get_cursor("Crosshair"); + + WindowFrame::reload_config(); } const Gfx::Font& WindowManager::font() const @@ -1434,6 +1436,7 @@ bool WindowManager::update_theme(String theme_path, String theme_name) m_palette = Gfx::PaletteImpl::create_with_anonymous_buffer(new_theme); Compositor::the().set_background_color(palette().desktop_background().to_string()); HashTable notified_clients; + WindowFrame::reload_config(); for_each_window([&](Window& window) { if (window.client()) { if (!notified_clients.contains(window.client())) { @@ -1523,9 +1526,10 @@ 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.set_button_icons(); + window_frame.theme_changed(); return IterationDecision::Continue; }); }