Skip to content

Commit

Permalink
WindowServer: Add action icons to the window menus
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Apr 30, 2020
1 parent 6c0fed3 commit 23d99e9
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 5 deletions.
Binary file added Base/res/icons/16x16/window-close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Base/res/icons/16x16/window-maximize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Base/res/icons/16x16/window-minimize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Base/res/icons/16x16/window-restore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Servers/WindowServer/MenuItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
2 changes: 1 addition & 1 deletion Servers/WindowServer/MenuItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MenuItem {
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; }
Expand Down
52 changes: 48 additions & 4 deletions Servers/WindowServer/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<MenuItem>(*m_window_menu, 1, m_minimized ? "Unminimize" : "Minimize"));
m_window_menu->add_item(make<MenuItem>(*m_window_menu, 2, m_maximized ? "Restore" : "Maximize"));
auto minimize_item = make<MenuItem>(*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<MenuItem>(*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<MenuItem>(*m_window_menu, MenuItem::Type::Separator));
m_window_menu->add_item(make<MenuItem>(*m_window_menu, 3, "Close"));

auto close_item = make<MenuItem>(*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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
}
}
Expand Down
3 changes: 3 additions & 0 deletions Servers/WindowServer/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace WindowServer {
class ClientConnection;
class Cursor;
class Menu;
class MenuItem;
class MouseEvent;

enum WMEventMask {
Expand Down Expand Up @@ -269,6 +270,8 @@ class Window final : public Core::Object
Gfx::Rect m_unmaximized_rect;
Gfx::Rect m_rect_in_menubar;
RefPtr<Menu> m_window_menu;
MenuItem* m_window_menu_minimize_item { nullptr };
MenuItem* m_window_menu_maximize_item { nullptr };
int m_minimize_animation_step { -1 };
};

Expand Down

0 comments on commit 23d99e9

Please sign in to comment.