1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

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.
This commit is contained in:
Andreas Kling 2019-03-06 23:03:36 +01:00
parent 3729f7cc6a
commit 67ee579113
5 changed files with 34 additions and 5 deletions

BIN
Base/res/icons/window16.rgb Normal file

Binary file not shown.

View file

@ -5,9 +5,18 @@
#include <WindowServer/WSAPITypes.h>
#include <WindowServer/WSClientConnection.h>
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);
}

View file

@ -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<GraphicsBitmap>&& 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<GraphicsBitmap> m_icon;
};

View file

@ -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));

View file

@ -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&)
{
}