From 67ee579113edc2f5963372e04703848c87c89a94 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 6 Mar 2019 23:03:36 +0100 Subject: [PATCH] WindowServer: Add window icons. Every window has the same icon for now. The icons show up both in the title bars and in the window switcher. Eventually I'd like to be able to minimize to icon, and maybe even have myself a taskbar. --- Base/res/icons/window16.rgb | Bin 0 -> 1024 bytes WindowServer/WSWindow.cpp | 10 ++++++++++ WindowServer/WSWindow.h | 4 ++++ WindowServer/WSWindowManager.cpp | 19 +++++++++++++++++-- WindowServer/WSWindowSwitcher.cpp | 6 +++--- 5 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 Base/res/icons/window16.rgb diff --git a/Base/res/icons/window16.rgb b/Base/res/icons/window16.rgb new file mode 100644 index 0000000000000000000000000000000000000000..4353dfe6aa7aa7bc5d159ca2655bcf1897b8d9fa GIT binary patch literal 1024 zcmZP=Jm5bA0|O}--R1way?Xx}2TlEN9X;p2bIRiX-npy(2bXR5A6>uWe^UGY|5+1` v{V$q%7G?*AeoF2CPb7fagJD0B+HtynR6lVcK&$YFnhT2`LNt2(4+tLsPb-Yo literal 0 HcmV?d00001 diff --git a/WindowServer/WSWindow.cpp b/WindowServer/WSWindow.cpp index 7cfbc4b6e2..bcebe450cb 100644 --- a/WindowServer/WSWindow.cpp +++ b/WindowServer/WSWindow.cpp @@ -5,9 +5,18 @@ #include #include +static GraphicsBitmap& default_window_icon() +{ + static GraphicsBitmap* s_icon; + if (!s_icon) + s_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/window16.rgb", { 16, 16 }).leak_ref(); + return *s_icon; +} + WSWindow::WSWindow(WSMessageReceiver& internal_owner, WSWindowType type) : m_internal_owner(&internal_owner) , m_type(type) + , m_icon(default_window_icon()) { WSWindowManager::the().add_window(*this); } @@ -16,6 +25,7 @@ WSWindow::WSWindow(WSClientConnection& client, int window_id) : m_client(&client) , m_type(WSWindowType::Normal) , m_window_id(window_id) + , m_icon(default_window_icon()) { WSWindowManager::the().add_window(*this); } diff --git a/WindowServer/WSWindow.h b/WindowServer/WSWindow.h index 26c4a41bef..7d0273a742 100644 --- a/WindowServer/WSWindow.h +++ b/WindowServer/WSWindow.h @@ -78,6 +78,9 @@ public: Size base_size() const { return m_base_size; } void set_base_size(const Size& size) { m_base_size = size; } + const GraphicsBitmap& icon() const { return *m_icon; } + void set_icon(Retained&& icon) { m_icon = move(icon); } + // For InlineLinkedList. // FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that. WSWindow* m_next { nullptr }; @@ -99,4 +102,5 @@ private: Rect m_last_lazy_resize_rect; Size m_size_increment; Size m_base_size; + Retained m_icon; }; diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index f1e0c1123d..db28c3017c 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -41,13 +41,25 @@ static inline Rect title_bar_rect(const Rect& window) }; } -static inline Rect title_bar_text_rect(const Rect& window) +static inline Rect title_bar_icon_rect(const Rect& window) { auto titlebar_rect = title_bar_rect(window); return { titlebar_rect.x() + 2, titlebar_rect.y(), - titlebar_rect.width() - 4, + 16, + titlebar_rect.height(), + }; +} + +static inline Rect title_bar_text_rect(const Rect& window) +{ + auto titlebar_rect = title_bar_rect(window); + auto titlebar_icon_rect = title_bar_icon_rect(window); + return { + titlebar_rect.x() + 2 + titlebar_icon_rect.width() + 2, + titlebar_rect.y(), + titlebar_rect.width() - 4 - titlebar_icon_rect.width() - 2, titlebar_rect.height() }; } @@ -400,6 +412,7 @@ void WSWindowManager::paint_window_frame(WSWindow& window) return; auto titlebar_rect = title_bar_rect(window.rect()); + auto titlebar_icon_rect = title_bar_icon_rect(window.rect()); auto titlebar_inner_rect = title_bar_text_rect(window.rect()); auto outer_rect = outer_window_rect(window); auto border_rect = border_window_rect(window.rect()); @@ -459,6 +472,8 @@ void WSWindowManager::paint_window_frame(WSWindow& window) m_back_painter->fill_rect_with_gradient(close_button_rect.shrunken(2, 2), Color::LightGray, Color::White); + m_back_painter->blit(titlebar_icon_rect.location(), window.icon(), window.icon().rect()); + m_back_painter->draw_rect(close_button_rect, Color::DarkGray); auto x_location = close_button_rect.center(); x_location.move_by(-(s_close_button_bitmap_width / 2), -(s_close_button_bitmap_height / 2)); diff --git a/WindowServer/WSWindowSwitcher.cpp b/WindowServer/WSWindowSwitcher.cpp index f751de7188..5c1bae7993 100644 --- a/WindowServer/WSWindowSwitcher.cpp +++ b/WindowServer/WSWindowSwitcher.cpp @@ -80,8 +80,9 @@ void WSWindowSwitcher::draw() text_color = Color::Black; rect_text_color = Color::DarkGray; } + painter.blit(item_rect.location().translated(0, (item_rect.height() - window.icon().height()) / 2), window.icon(), window.icon().rect()); painter.set_font(Font::default_bold_font()); - painter.draw_text(item_rect, window.title(), TextAlignment::CenterLeft, text_color); + painter.draw_text(item_rect.translated(window.icon().width() + 4, 0), window.title(), TextAlignment::CenterLeft, text_color); painter.set_font(WSWindowManager::the().font()); painter.draw_text(item_rect, window.rect().to_string(), TextAlignment::CenterRight, rect_text_color); } @@ -118,7 +119,6 @@ void WSWindowSwitcher::refresh() draw(); } -void WSWindowSwitcher::on_message(WSMessage& message) +void WSWindowSwitcher::on_message(WSMessage&) { - }