1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:37:46 +00:00

WindowServer+LibGUI: Add ability to set per-window icons.

The icons are passed around as filesystem paths for now, since the shared
memory bitmaps only support 2 sides.
This commit is contained in:
Andreas Kling 2019-04-13 16:59:55 +02:00
parent 7a74b76769
commit c09c114d77
19 changed files with 151 additions and 16 deletions

View file

@ -74,13 +74,14 @@ void TaskbarWindow::wm_event(GWMEvent& event)
}
case GEvent::WM_WindowStateChanged: {
auto& changed_event = static_cast<GWMWindowStateChangedEvent&>(event);
printf("WM_WindowStateChanged: client_id=%d, window_id=%d, title=%s, rect=%s, is_active=%u, is_minimized=%u\n",
printf("WM_WindowStateChanged: client_id=%d, window_id=%d, title=%s, rect=%s, is_active=%u, is_minimized=%u, icon_path=%s\n",
changed_event.client_id(),
changed_event.window_id(),
changed_event.title().characters(),
changed_event.rect().to_string().characters(),
changed_event.is_active(),
changed_event.is_minimized()
changed_event.is_minimized(),
changed_event.icon_path().characters()
);
if (!should_include_window(changed_event.window_type()))
break;
@ -89,6 +90,7 @@ void TaskbarWindow::wm_event(GWMEvent& event)
window.set_rect(changed_event.rect());
window.set_active(changed_event.is_active());
window.set_minimized(changed_event.is_minimized());
window.set_icon_path(changed_event.icon_path());
if (window.is_minimized()) {
window.button()->set_foreground_color(Color::DarkGray);
window.button()->set_caption(String::format("[%s]", changed_event.title().characters()));
@ -96,6 +98,7 @@ void TaskbarWindow::wm_event(GWMEvent& event)
window.button()->set_foreground_color(Color::Black);
window.button()->set_caption(changed_event.title());
}
window.button()->set_icon(window.icon());
window.button()->set_checked(changed_event.is_active());
break;
}

View file

@ -63,11 +63,27 @@ public:
void set_minimized(bool minimized) { m_minimized = minimized; }
bool is_minimized() const { return m_minimized; }
String icon_path() const { return m_icon_path; }
void set_icon_path(const String& icon_path)
{
if (m_icon_path == icon_path)
return;
auto icon = GraphicsBitmap::load_from_file(icon_path);
if (!icon)
return;
m_icon_path = icon_path;
m_icon = move(icon);
}
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
private:
WindowIdentifier m_identifier;
String m_title;
Rect m_rect;
GButton* m_button { nullptr };
String m_icon_path;
RetainPtr<GraphicsBitmap> m_icon;
bool m_active { false };
bool m_minimized { false };
};

View file

@ -151,5 +151,7 @@ int main(int argc, char** argv)
text_editor->set_focus(true);
window->show();
window->set_icon_path("/res/icons/TextEditor16.png");
return app.exec();
}