mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:57:44 +00:00
Taskbar: Plumb window active state from the WindowServer to the taskbar.
This commit is contained in:
parent
19eb814850
commit
7b1384c4ef
11 changed files with 70 additions and 29 deletions
|
@ -19,6 +19,10 @@ TaskbarWindow::TaskbarWindow()
|
|||
|
||||
auto* widget = new TaskbarWidget(m_window_list);
|
||||
set_main_widget(widget);
|
||||
|
||||
m_window_list.aid_create_button = [this] {
|
||||
return create_button();
|
||||
};
|
||||
}
|
||||
|
||||
TaskbarWindow::~TaskbarWindow()
|
||||
|
@ -31,25 +35,34 @@ void TaskbarWindow::on_screen_rect_change(const Rect& rect)
|
|||
set_rect(new_rect);
|
||||
}
|
||||
|
||||
GButton* TaskbarWindow::create_button()
|
||||
{
|
||||
auto* button = new GButton(main_widget());
|
||||
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
button->set_preferred_size({ 100, 22 });
|
||||
button->set_checkable(true);
|
||||
return button;
|
||||
}
|
||||
|
||||
void TaskbarWindow::wm_event(GWMEvent& event)
|
||||
{
|
||||
WindowIdentifier identifier { event.client_id(), event.window_id() };
|
||||
switch (event.type()) {
|
||||
case GEvent::WM_WindowAdded: {
|
||||
auto& added_event = static_cast<GWMWindowAddedEvent&>(event);
|
||||
printf("WM_WindowAdded: client_id=%d, window_id=%d, title=%s, rect=%s\n",
|
||||
printf("WM_WindowAdded: client_id=%d, window_id=%d, title=%s, rect=%s, is_active=%u\n",
|
||||
added_event.client_id(),
|
||||
added_event.window_id(),
|
||||
added_event.title().characters(),
|
||||
added_event.rect().to_string().characters()
|
||||
added_event.rect().to_string().characters(),
|
||||
added_event.is_active()
|
||||
);
|
||||
auto& window = m_window_list.ensure_window(identifier);
|
||||
window.set_title(added_event.title());
|
||||
window.set_rect(added_event.rect());
|
||||
window.set_button(new GButton(main_widget()));
|
||||
window.button()->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
window.button()->set_preferred_size({ 100, 22 });
|
||||
window.set_active(added_event.is_active());
|
||||
window.button()->set_caption(window.title());
|
||||
window.button()->set_checked(window.is_active());
|
||||
update();
|
||||
break;
|
||||
}
|
||||
|
@ -65,16 +78,19 @@ 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\n",
|
||||
printf("WM_WindowStateChanged: client_id=%d, window_id=%d, title=%s, rect=%s, is_active=%u\n",
|
||||
changed_event.client_id(),
|
||||
changed_event.window_id(),
|
||||
changed_event.title().characters(),
|
||||
changed_event.rect().to_string().characters()
|
||||
changed_event.rect().to_string().characters(),
|
||||
changed_event.is_active()
|
||||
);
|
||||
auto& window = m_window_list.ensure_window(identifier);
|
||||
window.set_title(changed_event.title());
|
||||
window.set_rect(changed_event.rect());
|
||||
window.set_active(changed_event.is_active());
|
||||
window.button()->set_caption(changed_event.title());
|
||||
window.button()->set_checked(changed_event.is_active());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -13,6 +13,7 @@ public:
|
|||
|
||||
private:
|
||||
void on_screen_rect_change(const Rect&);
|
||||
GButton* create_button();
|
||||
|
||||
virtual void wm_event(GWMEvent&) override;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ Window& WindowList::ensure_window(const WindowIdentifier& identifier)
|
|||
if (it != m_windows.end())
|
||||
return *it->value;
|
||||
auto window = make<Window>(identifier);
|
||||
window->set_button(aid_create_button());
|
||||
auto& window_ref = *window;
|
||||
m_windows.set(identifier, move(window));
|
||||
return window_ref;
|
||||
|
|
|
@ -57,11 +57,15 @@ public:
|
|||
GButton* button() { return m_button; }
|
||||
void set_button(GButton* button) { m_button = button; }
|
||||
|
||||
void set_active(bool active) { m_active = active; }
|
||||
bool is_active() const { return m_active; }
|
||||
|
||||
private:
|
||||
WindowIdentifier m_identifier;
|
||||
String m_title;
|
||||
Rect m_rect;
|
||||
GButton* m_button { nullptr };
|
||||
bool m_active { false };
|
||||
};
|
||||
|
||||
class WindowList {
|
||||
|
@ -75,6 +79,8 @@ public:
|
|||
Window& ensure_window(const WindowIdentifier&);
|
||||
void remove_window(const WindowIdentifier&);
|
||||
|
||||
Function<GButton*()> aid_create_button;
|
||||
|
||||
private:
|
||||
HashMap<WindowIdentifier, OwnPtr<Window>> m_windows;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue