1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:07:35 +00:00

Taskbar: Plumb window active state from the WindowServer to the taskbar.

This commit is contained in:
Andreas Kling 2019-04-04 13:19:26 +02:00
parent 19eb814850
commit 7b1384c4ef
11 changed files with 70 additions and 29 deletions

View file

@ -110,6 +110,7 @@ struct WSAPI_ServerMessage {
int client_id;
int window_id;
WSAPI_Rect rect;
bool is_active;
} wm;
struct {
WSAPI_Rect rect;

View file

@ -605,19 +605,22 @@ private:
class WSWMWindowAddedEvent : public WSWMEvent {
public:
WSWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect)
WSWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active)
: WSWMEvent(WSMessage::WM_WindowAdded, client_id, window_id)
, m_title(title)
, m_rect(rect)
, m_active(is_active)
{
}
String title() const { return m_title; }
Rect rect() const { return m_rect; }
bool is_active() const { return m_active; }
private:
String m_title;
Rect m_rect;
bool m_active;
};
class WSWMWindowRemovedEvent : public WSWMEvent {
@ -630,17 +633,20 @@ public:
class WSWMWindowStateChangedEvent : public WSWMEvent {
public:
WSWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect)
WSWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active)
: WSWMEvent(WSMessage::WM_WindowStateChanged, client_id, window_id)
, m_title(title)
, m_rect(rect)
, m_active(is_active)
{
}
String title() const { return m_title; }
Rect rect() const { return m_rect; }
bool is_active() const { return m_active; }
private:
String m_title;
Rect m_rect;
bool m_active;
};

View file

@ -146,6 +146,7 @@ void WSWindow::on_message(const WSMessage& message)
server_message.type = WSAPI_ServerMessage::Type::WM_WindowAdded;
server_message.wm.client_id = added_event.client_id();
server_message.wm.window_id = added_event.window_id();
server_message.wm.is_active = added_event.is_active();
ASSERT(added_event.title().length() < sizeof(server_message.text));
memcpy(server_message.text, added_event.title().characters(), added_event.title().length());
server_message.text_length = added_event.title().length();
@ -164,6 +165,7 @@ void WSWindow::on_message(const WSMessage& message)
server_message.type = WSAPI_ServerMessage::Type::WM_WindowStateChanged;
server_message.wm.client_id = changed_event.client_id();
server_message.wm.window_id = changed_event.window_id();
server_message.wm.is_active = changed_event.is_active();
ASSERT(changed_event.title().length() < sizeof(server_message.text));
memcpy(server_message.text, changed_event.title().characters(), changed_event.title().length());
server_message.text_length = changed_event.title().length();

View file

@ -18,10 +18,6 @@
#include <SharedGraphics/PNGLoader.h>
#include "WSCursor.h"
#ifdef KERNEL
#include <Kernel/ProcFS.h>
#endif
//#define DEBUG_COUNTERS
//#define DEBUG_WID_IN_TITLE_BAR
//#define RESIZE_DEBUG
@ -510,7 +506,7 @@ void WSWindowManager::add_window(WSWindow& window)
for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
if (window.client())
WSMessageLoop::the().post_message(listener, make<WSWMWindowAddedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect()));
WSMessageLoop::the().post_message(listener, make<WSWMWindowAddedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active()));
return IterationDecision::Continue;
});
}
@ -548,6 +544,15 @@ void WSWindowManager::remove_window(WSWindow& window)
});
}
void WSWindowManager::tell_wm_listeners_window_state_changed(WSWindow& window)
{
for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
if (window.client())
WSMessageLoop::the().post_message(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active()));
return IterationDecision::Continue;
});
}
void WSWindowManager::notify_title_changed(WSWindow& window)
{
dbgprintf("[WM] WSWindow{%p} title set to '%s'\n", &window, window.title().characters());
@ -555,11 +560,7 @@ void WSWindowManager::notify_title_changed(WSWindow& window)
if (m_switcher.is_visible())
m_switcher.refresh();
for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
if (window.client())
WSMessageLoop::the().post_message(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect()));
return IterationDecision::Continue;
});
tell_wm_listeners_window_state_changed(window);
}
void WSWindowManager::notify_rect_changed(WSWindow& window, const Rect& old_rect, const Rect& new_rect)
@ -572,11 +573,7 @@ void WSWindowManager::notify_rect_changed(WSWindow& window, const Rect& old_rect
if (m_switcher.is_visible() && window.type() != WSWindowType::WindowSwitcher)
m_switcher.refresh();
for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
if (window.client())
WSMessageLoop::the().post_message(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect()));
return IterationDecision::Continue;
});
tell_wm_listeners_window_state_changed(window);
}
void WSWindowManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& event)
@ -1139,7 +1136,8 @@ void WSWindowManager::set_active_window(WSWindow* window)
if (window == m_active_window.ptr())
return;
if (auto* previously_active_window = m_active_window.ptr()) {
auto* previously_active_window = m_active_window.ptr();
if (previously_active_window) {
WSMessageLoop::the().post_message(*previously_active_window, make<WSMessage>(WSMessage::WindowDeactivated));
invalidate(*previously_active_window);
}
@ -1151,6 +1149,9 @@ void WSWindowManager::set_active_window(WSWindow* window)
auto* client = window->client();
ASSERT(client);
set_current_menubar(client->app_menubar());
if (previously_active_window)
tell_wm_listeners_window_state_changed(*previously_active_window);
tell_wm_listeners_window_state_changed(*m_active_window);
}
}

View file

@ -120,6 +120,7 @@ private:
void paint_window_frame(const WSWindow&);
void flip_buffers();
void tick_clock();
void tell_wm_listeners_window_state_changed(WSWindow&);
WSScreen& m_screen;
Rect m_screen_rect;