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

Taskbar: Only include "Normal" windows in the taskbar window list.

This commit is contained in:
Andreas Kling 2019-04-04 16:23:23 +02:00
parent 82b02ed82b
commit 64a5abf8db
10 changed files with 70 additions and 16 deletions

View file

@ -45,6 +45,11 @@ GButton* TaskbarWindow::create_button()
return button; return button;
} }
static bool should_include_window(GWindowType window_type)
{
return window_type == GWindowType::Normal;
}
void TaskbarWindow::wm_event(GWMEvent& event) void TaskbarWindow::wm_event(GWMEvent& event)
{ {
WindowIdentifier identifier { event.client_id(), event.window_id() }; WindowIdentifier identifier { event.client_id(), event.window_id() };
@ -58,6 +63,8 @@ void TaskbarWindow::wm_event(GWMEvent& event)
added_event.rect().to_string().characters(), added_event.rect().to_string().characters(),
added_event.is_active() added_event.is_active()
); );
if (!should_include_window(added_event.window_type()))
break;
auto& window = m_window_list.ensure_window(identifier); auto& window = m_window_list.ensure_window(identifier);
window.set_title(added_event.title()); window.set_title(added_event.title());
window.set_rect(added_event.rect()); window.set_rect(added_event.rect());
@ -86,6 +93,8 @@ void TaskbarWindow::wm_event(GWMEvent& event)
changed_event.rect().to_string().characters(), changed_event.rect().to_string().characters(),
changed_event.is_active() changed_event.is_active()
); );
if (!should_include_window(changed_event.window_type()))
break;
auto& window = m_window_list.ensure_window(identifier); auto& window = m_window_list.ensure_window(identifier);
window.set_title(changed_event.title()); window.set_title(changed_event.title());
window.set_rect(changed_event.rect()); window.set_rect(changed_event.rect());

View file

@ -6,6 +6,7 @@
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/WeakPtr.h> #include <AK/WeakPtr.h>
#include <Kernel/KeyCode.h> #include <Kernel/KeyCode.h>
#include <LibGUI/GWindowType.h>
class GObject; class GObject;
@ -74,22 +75,25 @@ private:
class GWMWindowAddedEvent : public GWMEvent { class GWMWindowAddedEvent : public GWMEvent {
public: public:
GWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active) GWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, GWindowType window_type)
: GWMEvent(GEvent::Type::WM_WindowAdded, client_id, window_id) : GWMEvent(GEvent::Type::WM_WindowAdded, client_id, window_id)
, m_title(title) , m_title(title)
, m_rect(rect) , m_rect(rect)
, m_active(is_active) , m_active(is_active)
, m_window_type(window_type)
{ {
} }
String title() const { return m_title; } String title() const { return m_title; }
Rect rect() const { return m_rect; } Rect rect() const { return m_rect; }
bool is_active() const { return m_active; } bool is_active() const { return m_active; }
GWindowType window_type() const { return m_window_type; }
private: private:
String m_title; String m_title;
Rect m_rect; Rect m_rect;
bool m_active; bool m_active;
GWindowType m_window_type;
}; };
class GWMWindowRemovedEvent : public GWMEvent { class GWMWindowRemovedEvent : public GWMEvent {
@ -102,22 +106,25 @@ public:
class GWMWindowStateChangedEvent : public GWMEvent { class GWMWindowStateChangedEvent : public GWMEvent {
public: public:
GWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active) GWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, GWindowType window_type)
: GWMEvent(GEvent::Type::WM_WindowStateChanged, client_id, window_id) : GWMEvent(GEvent::Type::WM_WindowStateChanged, client_id, window_id)
, m_title(title) , m_title(title)
, m_rect(rect) , m_rect(rect)
, m_active(is_active) , m_active(is_active)
, m_window_type(window_type)
{ {
} }
String title() const { return m_title; } String title() const { return m_title; }
Rect rect() const { return m_rect; } Rect rect() const { return m_rect; }
bool is_active() const { return m_active; } bool is_active() const { return m_active; }
GWindowType window_type() const { return m_window_type; }
private: private:
String m_title; String m_title;
Rect m_rect; Rect m_rect;
bool m_active; bool m_active;
GWindowType m_window_type;
}; };
class QuitEvent final : public GEvent { class QuitEvent final : public GEvent {

View file

@ -270,10 +270,13 @@ void GEventLoop::handle_menu_event(const WSAPI_ServerMessage& event)
void GEventLoop::handle_wm_event(const WSAPI_ServerMessage& event, GWindow& window) void GEventLoop::handle_wm_event(const WSAPI_ServerMessage& event, GWindow& window)
{ {
#ifdef GEVENTLOOP_DEBUG
dbgprintf("GEventLoop: handle_wm_event: %d\n", (int)event.type);
#endif
if (event.type == WSAPI_ServerMessage::WM_WindowAdded) if (event.type == WSAPI_ServerMessage::WM_WindowAdded)
return post_event(window, make<GWMWindowAddedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length), event.wm.rect, event.wm.is_active)); return post_event(window, make<GWMWindowAddedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length), event.wm.rect, event.wm.is_active, (GWindowType)event.wm.window_type));
if (event.type == WSAPI_ServerMessage::WM_WindowStateChanged) if (event.type == WSAPI_ServerMessage::WM_WindowStateChanged)
return post_event(window, make<GWMWindowStateChangedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length), event.wm.rect, event.wm.is_active)); return post_event(window, make<GWMWindowStateChangedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length), event.wm.rect, event.wm.is_active, (GWindowType)event.wm.window_type));
if (event.type == WSAPI_ServerMessage::WM_WindowRemoved) if (event.type == WSAPI_ServerMessage::WM_WindowRemoved)
return post_event(window, make<GWMWindowRemovedEvent>(event.wm.client_id, event.wm.window_id)); return post_event(window, make<GWMWindowRemovedEvent>(event.wm.client_id, event.wm.window_id));
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "GObject.h" #include <LibGUI/GObject.h>
#include <LibGUI/GWindowType.h>
#include <SharedGraphics/Rect.h> #include <SharedGraphics/Rect.h>
#include <SharedGraphics/GraphicsBitmap.h> #include <SharedGraphics/GraphicsBitmap.h>
#include <AK/AKString.h> #include <AK/AKString.h>
@ -17,12 +18,6 @@ enum class GStandardCursor {
ResizeVertical, ResizeVertical,
}; };
enum class GWindowType {
Invalid = 0,
Normal,
Taskbar,
};
class GWindow : public GObject { class GWindow : public GObject {
public: public:
GWindow(GObject* parent = nullptr); GWindow(GObject* parent = nullptr);

9
LibGUI/GWindowType.h Normal file
View file

@ -0,0 +1,9 @@
#pragma once
enum class GWindowType {
Invalid = 0,
Normal,
Menu,
WindowSwitcher,
Taskbar,
};

View file

@ -23,6 +23,8 @@ struct WSAPI_Rect {
enum WSAPI_WindowType { enum WSAPI_WindowType {
Invalid = 0, Invalid = 0,
Normal, Normal,
Menu,
WindowSwitcher,
Taskbar, Taskbar,
}; };
@ -111,6 +113,7 @@ struct WSAPI_ServerMessage {
int window_id; int window_id;
WSAPI_Rect rect; WSAPI_Rect rect;
bool is_active; bool is_active;
WSAPI_WindowType window_type;
} wm; } wm;
struct { struct {
WSAPI_Rect rect; WSAPI_Rect rect;

View file

@ -623,22 +623,25 @@ private:
class WSWMWindowAddedEvent : public WSWMEvent { class WSWMWindowAddedEvent : public WSWMEvent {
public: public:
WSWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active) WSWMWindowAddedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, WSWindowType window_type)
: WSWMEvent(WSMessage::WM_WindowAdded, client_id, window_id) : WSWMEvent(WSMessage::WM_WindowAdded, client_id, window_id)
, m_title(title) , m_title(title)
, m_rect(rect) , m_rect(rect)
, m_active(is_active) , m_active(is_active)
, m_window_type(window_type)
{ {
} }
String title() const { return m_title; } String title() const { return m_title; }
Rect rect() const { return m_rect; } Rect rect() const { return m_rect; }
bool is_active() const { return m_active; } bool is_active() const { return m_active; }
WSWindowType window_type() const { return m_window_type; }
private: private:
String m_title; String m_title;
Rect m_rect; Rect m_rect;
bool m_active; bool m_active;
WSWindowType m_window_type;
}; };
class WSWMWindowRemovedEvent : public WSWMEvent { class WSWMWindowRemovedEvent : public WSWMEvent {
@ -651,20 +654,23 @@ public:
class WSWMWindowStateChangedEvent : public WSWMEvent { class WSWMWindowStateChangedEvent : public WSWMEvent {
public: public:
WSWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active) WSWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, WSWindowType window_type)
: WSWMEvent(WSMessage::WM_WindowStateChanged, client_id, window_id) : WSWMEvent(WSMessage::WM_WindowStateChanged, client_id, window_id)
, m_title(title) , m_title(title)
, m_rect(rect) , m_rect(rect)
, m_active(is_active) , m_active(is_active)
, m_window_type(window_type)
{ {
} }
String title() const { return m_title; } String title() const { return m_title; }
Rect rect() const { return m_rect; } Rect rect() const { return m_rect; }
bool is_active() const { return m_active; } bool is_active() const { return m_active; }
WSWindowType window_type() const { return m_window_type; }
private: private:
String m_title; String m_title;
Rect m_rect; Rect m_rect;
bool m_active; bool m_active;
WSWindowType m_window_type;
}; };

View file

@ -254,6 +254,10 @@ static WSWindowType from_api(WSAPI_WindowType api_type)
switch (api_type) { switch (api_type) {
case WSAPI_WindowType::Normal: case WSAPI_WindowType::Normal:
return WSWindowType::Normal; return WSWindowType::Normal;
case WSAPI_WindowType::Menu:
return WSWindowType::Menu;
case WSAPI_WindowType::WindowSwitcher:
return WSWindowType::WindowSwitcher;
case WSAPI_WindowType::Taskbar: case WSAPI_WindowType::Taskbar:
return WSWindowType::Taskbar; return WSWindowType::Taskbar;
default: default:

View file

@ -94,6 +94,22 @@ void WSWindow::handle_mouse_event(const WSMouseEvent& event)
m_client->post_message(server_message); m_client->post_message(server_message);
} }
static WSAPI_WindowType to_api(WSWindowType ws_type)
{
switch (ws_type) {
case WSWindowType::Normal:
return WSAPI_WindowType::Normal;
case WSWindowType::Menu:
return WSAPI_WindowType::Menu;
case WSWindowType::WindowSwitcher:
return WSAPI_WindowType::WindowSwitcher;
case WSWindowType::Taskbar:
return WSAPI_WindowType::Taskbar;
default:
ASSERT_NOT_REACHED();
}
}
void WSWindow::on_message(const WSMessage& message) void WSWindow::on_message(const WSMessage& message)
{ {
if (m_internal_owner) if (m_internal_owner)
@ -147,6 +163,7 @@ void WSWindow::on_message(const WSMessage& message)
server_message.wm.client_id = added_event.client_id(); server_message.wm.client_id = added_event.client_id();
server_message.wm.window_id = added_event.window_id(); server_message.wm.window_id = added_event.window_id();
server_message.wm.is_active = added_event.is_active(); server_message.wm.is_active = added_event.is_active();
server_message.wm.window_type = to_api(added_event.window_type());
ASSERT(added_event.title().length() < sizeof(server_message.text)); ASSERT(added_event.title().length() < sizeof(server_message.text));
memcpy(server_message.text, added_event.title().characters(), added_event.title().length()); memcpy(server_message.text, added_event.title().characters(), added_event.title().length());
server_message.text_length = added_event.title().length(); server_message.text_length = added_event.title().length();
@ -166,6 +183,7 @@ void WSWindow::on_message(const WSMessage& message)
server_message.wm.client_id = changed_event.client_id(); server_message.wm.client_id = changed_event.client_id();
server_message.wm.window_id = changed_event.window_id(); server_message.wm.window_id = changed_event.window_id();
server_message.wm.is_active = changed_event.is_active(); server_message.wm.is_active = changed_event.is_active();
server_message.wm.window_type = to_api(changed_event.window_type());
ASSERT(changed_event.title().length() < sizeof(server_message.text)); ASSERT(changed_event.title().length() < sizeof(server_message.text));
memcpy(server_message.text, changed_event.title().characters(), changed_event.title().length()); memcpy(server_message.text, changed_event.title().characters(), changed_event.title().length());
server_message.text_length = changed_event.title().length(); server_message.text_length = changed_event.title().length();

View file

@ -496,14 +496,14 @@ void WSWindowManager::add_window(WSWindow& window)
if (window.listens_to_wm_events()) { if (window.listens_to_wm_events()) {
for_each_window([&window] (WSWindow& other_window) { for_each_window([&window] (WSWindow& other_window) {
if (&window != &other_window && other_window.client()) if (&window != &other_window && other_window.client())
WSMessageLoop::the().post_message(window, make<WSWMWindowAddedEvent>(other_window.client()->client_id(), other_window.window_id(), other_window.title(), other_window.rect(), other_window.is_active())); WSMessageLoop::the().post_message(window, make<WSWMWindowAddedEvent>(other_window.client()->client_id(), other_window.window_id(), other_window.title(), other_window.rect(), other_window.is_active(), other_window.type()));
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
} }
for_each_window_listening_to_wm_events([&window] (WSWindow& listener) { for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
if (window.client()) if (window.client())
WSMessageLoop::the().post_message(listener, make<WSWMWindowAddedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active())); WSMessageLoop::the().post_message(listener, make<WSWMWindowAddedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type()));
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
} }
@ -545,7 +545,7 @@ void WSWindowManager::tell_wm_listeners_window_state_changed(WSWindow& window)
{ {
for_each_window_listening_to_wm_events([&window] (WSWindow& listener) { for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
if (window.client()) if (window.client())
WSMessageLoop::the().post_message(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active())); WSMessageLoop::the().post_message(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type()));
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
} }