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
Notes: sideshowbarker 2024-07-19 14:49:26 +09:00
10 changed files with 70 additions and 16 deletions

View File

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

View File

@ -6,6 +6,7 @@
#include <AK/Types.h>
#include <AK/WeakPtr.h>
#include <Kernel/KeyCode.h>
#include <LibGUI/GWindowType.h>
class GObject;
@ -74,22 +75,25 @@ private:
class GWMWindowAddedEvent : public GWMEvent {
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)
, m_title(title)
, m_rect(rect)
, m_active(is_active)
, m_window_type(window_type)
{
}
String title() const { return m_title; }
Rect rect() const { return m_rect; }
bool is_active() const { return m_active; }
GWindowType window_type() const { return m_window_type; }
private:
String m_title;
Rect m_rect;
bool m_active;
GWindowType m_window_type;
};
class GWMWindowRemovedEvent : public GWMEvent {
@ -102,22 +106,25 @@ public:
class GWMWindowStateChangedEvent : public GWMEvent {
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)
, m_title(title)
, m_rect(rect)
, m_active(is_active)
, m_window_type(window_type)
{
}
String title() const { return m_title; }
Rect rect() const { return m_rect; }
bool is_active() const { return m_active; }
GWindowType window_type() const { return m_window_type; }
private:
String m_title;
Rect m_rect;
bool m_active;
GWindowType m_window_type;
};
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)
{
#ifdef GEVENTLOOP_DEBUG
dbgprintf("GEventLoop: handle_wm_event: %d\n", (int)event.type);
#endif
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)
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)
return post_event(window, make<GWMWindowRemovedEvent>(event.wm.client_id, event.wm.window_id));
ASSERT_NOT_REACHED();

View File

@ -1,6 +1,7 @@
#pragma once
#include "GObject.h"
#include <LibGUI/GObject.h>
#include <LibGUI/GWindowType.h>
#include <SharedGraphics/Rect.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <AK/AKString.h>
@ -17,12 +18,6 @@ enum class GStandardCursor {
ResizeVertical,
};
enum class GWindowType {
Invalid = 0,
Normal,
Taskbar,
};
class GWindow : public GObject {
public:
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 {
Invalid = 0,
Normal,
Menu,
WindowSwitcher,
Taskbar,
};
@ -111,6 +113,7 @@ struct WSAPI_ServerMessage {
int window_id;
WSAPI_Rect rect;
bool is_active;
WSAPI_WindowType window_type;
} wm;
struct {
WSAPI_Rect rect;

View File

@ -623,22 +623,25 @@ private:
class WSWMWindowAddedEvent : public WSWMEvent {
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)
, m_title(title)
, m_rect(rect)
, m_active(is_active)
, m_window_type(window_type)
{
}
String title() const { return m_title; }
Rect rect() const { return m_rect; }
bool is_active() const { return m_active; }
WSWindowType window_type() const { return m_window_type; }
private:
String m_title;
Rect m_rect;
bool m_active;
WSWindowType m_window_type;
};
class WSWMWindowRemovedEvent : public WSWMEvent {
@ -651,20 +654,23 @@ public:
class WSWMWindowStateChangedEvent : public WSWMEvent {
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)
, m_title(title)
, m_rect(rect)
, m_active(is_active)
, m_window_type(window_type)
{
}
String title() const { return m_title; }
Rect rect() const { return m_rect; }
bool is_active() const { return m_active; }
WSWindowType window_type() const { return m_window_type; }
private:
String m_title;
Rect m_rect;
bool m_active;
WSWindowType m_window_type;
};

View File

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

View File

@ -94,6 +94,22 @@ void WSWindow::handle_mouse_event(const WSMouseEvent& event)
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)
{
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.window_id = added_event.window_id();
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));
memcpy(server_message.text, added_event.title().characters(), 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.window_id = changed_event.window_id();
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));
memcpy(server_message.text, changed_event.title().characters(), 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()) {
for_each_window([&window] (WSWindow& other_window) {
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;
});
}
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(), 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;
});
}
@ -545,7 +545,7 @@ 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()));
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;
});
}