From 23d99e92b9b67a6acc00f72c7ec29e80437a04c1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 30 Apr 2020 12:58:38 +0200 Subject: [PATCH] WindowServer: Add action icons to the window menus --- Base/res/icons/16x16/window-close.png | Bin 0 -> 115 bytes Base/res/icons/16x16/window-maximize.png | Bin 0 -> 90 bytes Base/res/icons/16x16/window-minimize.png | Bin 0 -> 92 bytes Base/res/icons/16x16/window-restore.png | Bin 0 -> 100 bytes Servers/WindowServer/MenuItem.cpp | 8 ++++ Servers/WindowServer/MenuItem.h | 2 +- Servers/WindowServer/Window.cpp | 52 +++++++++++++++++++++-- Servers/WindowServer/Window.h | 3 ++ 8 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 Base/res/icons/16x16/window-close.png create mode 100644 Base/res/icons/16x16/window-maximize.png create mode 100644 Base/res/icons/16x16/window-minimize.png create mode 100644 Base/res/icons/16x16/window-restore.png diff --git a/Base/res/icons/16x16/window-close.png b/Base/res/icons/16x16/window-close.png new file mode 100644 index 0000000000000000000000000000000000000000..61ddee97cc22c4a84cc5d1870b19df01e8230d68 GIT binary patch literal 115 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`R-P`7Ar_~T6C_wo82>Mvp;4&D z#Fm)6n88iSn|;>FYmb4Z OFnGH9xvXcxAr_~T6C_xb8UC~<&1sm} nkk*tX*?GmMr*(0{0S1OQmsl9j?b~7kRLtP%>gTe~DWM4f!2ucS literal 0 HcmV?d00001 diff --git a/Base/res/icons/16x16/window-minimize.png b/Base/res/icons/16x16/window-minimize.png new file mode 100644 index 0000000000000000000000000000000000000000..72ddab9fc5e0cf8eb20e284d596fdf06acfd4a6b GIT binary patch literal 92 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`%APKcAr_~T6C_vzopr0K%Xbl>h($ literal 0 HcmV?d00001 diff --git a/Base/res/icons/16x16/window-restore.png b/Base/res/icons/16x16/window-restore.png new file mode 100644 index 0000000000000000000000000000000000000000..cd305dbd6c58cd815a634001435c8034af264274 GIT binary patch literal 100 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`+MX_sAr_~T6C_wo*#9q-P)|@< xFmpkao06$;vSMXJl6Zg&o5=A)8VLyu456AFjIwY43j?(=c)I$ztaD0e0sutG7_k5V literal 0 HcmV?d00001 diff --git a/Servers/WindowServer/MenuItem.cpp b/Servers/WindowServer/MenuItem.cpp index b062a47d9da..eba593c136b 100644 --- a/Servers/WindowServer/MenuItem.cpp +++ b/Servers/WindowServer/MenuItem.cpp @@ -85,4 +85,12 @@ Gfx::Rect MenuItem::rect() const return m_rect.translated(0, m_menu.item_height() - (m_menu.scroll_offset() * m_menu.item_height())); } +void MenuItem::set_icon(const Gfx::Bitmap* icon) +{ + if (m_icon == icon) + return; + m_icon = icon; + m_menu.redraw(); +} + } diff --git a/Servers/WindowServer/MenuItem.h b/Servers/WindowServer/MenuItem.h index 297c7518489..3f297adb43f 100644 --- a/Servers/WindowServer/MenuItem.h +++ b/Servers/WindowServer/MenuItem.h @@ -70,7 +70,7 @@ public: unsigned identifier() const { return m_identifier; } const Gfx::Bitmap* icon() const { return m_icon; } - void set_icon(const Gfx::Bitmap* icon) { m_icon = icon; } + void set_icon(const Gfx::Bitmap*); bool is_submenu() const { return m_submenu_id != -1; } int submenu_id() const { return m_submenu_id; } diff --git a/Servers/WindowServer/Window.cpp b/Servers/WindowServer/Window.cpp index 550c067e13b..2bc92c35b3d 100644 --- a/Servers/WindowServer/Window.cpp +++ b/Servers/WindowServer/Window.cpp @@ -48,6 +48,38 @@ static Gfx::Bitmap& default_window_icon() return *s_icon; } +static Gfx::Bitmap& minimize_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-minimize.png").leak_ref(); + return *s_icon; +} + +static Gfx::Bitmap& maximize_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-maximize.png").leak_ref(); + return *s_icon; +} + +static Gfx::Bitmap& restore_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-restore.png").leak_ref(); + return *s_icon; +} + +static Gfx::Bitmap& close_icon() +{ + static Gfx::Bitmap* s_icon; + if (!s_icon) + s_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/window-close.png").leak_ref(); + return *s_icon; +} + Window::Window(Core::Object& parent, WindowType type) : Core::Object(&parent) , m_type(type) @@ -334,10 +366,19 @@ void Window::popup_window_menu(const Gfx::Point& position) m_window_menu = Menu::construct(nullptr, -1, "(Window Menu)"); m_window_menu->set_window_menu_of(*this); - m_window_menu->add_item(make(*m_window_menu, 1, m_minimized ? "Unminimize" : "Minimize")); - m_window_menu->add_item(make(*m_window_menu, 2, m_maximized ? "Restore" : "Maximize")); + auto minimize_item = make(*m_window_menu, 1, m_minimized ? "Unminimize" : "Minimize"); + m_window_menu_minimize_item = minimize_item.ptr(); + m_window_menu->add_item(move(minimize_item)); + + auto maximize_item = make(*m_window_menu, 2, m_maximized ? "Restore" : "Maximize"); + m_window_menu_maximize_item = maximize_item.ptr(); + m_window_menu->add_item(move(maximize_item)); + m_window_menu->add_item(make(*m_window_menu, MenuItem::Type::Separator)); - m_window_menu->add_item(make(*m_window_menu, 3, "Close")); + + auto close_item = make(*m_window_menu, 3, "Close"); + close_item->set_icon(&close_icon()); + m_window_menu->add_item(move(close_item)); m_window_menu->item((int)PopupMenuItem::Minimize).set_enabled(m_minimizable); m_window_menu->item((int)PopupMenuItem::Maximize).set_enabled(m_resizable); @@ -361,6 +402,9 @@ void Window::popup_window_menu(const Gfx::Point& position) } }; } + m_window_menu_minimize_item->set_icon(m_minimized ? nullptr : &minimize_icon()); + m_window_menu_maximize_item->set_icon(m_maximized ? &restore_icon() : &maximize_icon()); + m_window_menu->popup(position); } @@ -402,7 +446,7 @@ Gfx::Rect Window::tiled_rect(WindowTileType tiled) const WindowManager::the().maximized_window_rect(*this).y(), Screen::the().width() / 2 - frame_width, WindowManager::the().maximized_window_rect(*this).height()); - default : + default: ASSERT_NOT_REACHED(); } } diff --git a/Servers/WindowServer/Window.h b/Servers/WindowServer/Window.h index 31f05c76b8d..ce796b602fb 100644 --- a/Servers/WindowServer/Window.h +++ b/Servers/WindowServer/Window.h @@ -40,6 +40,7 @@ namespace WindowServer { class ClientConnection; class Cursor; class Menu; +class MenuItem; class MouseEvent; enum WMEventMask { @@ -269,6 +270,8 @@ private: Gfx::Rect m_unmaximized_rect; Gfx::Rect m_rect_in_menubar; RefPtr m_window_menu; + MenuItem* m_window_menu_minimize_item { nullptr }; + MenuItem* m_window_menu_maximize_item { nullptr }; int m_minimize_animation_step { -1 }; };