mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 21:25:07 +00:00
WindowServer: Add WM_SetActiveWindow client request and use it in Taskbar.
This makes it possible for Taskbar to switch windows. :^)
This commit is contained in:
parent
8a50218190
commit
ce7341be87
7 changed files with 58 additions and 1 deletions
|
@ -1,4 +1,6 @@
|
||||||
#include "WindowList.h"
|
#include "WindowList.h"
|
||||||
|
#include <WindowServer/WSAPITypes.h>
|
||||||
|
#include <LibGUI/GEventLoop.h>
|
||||||
|
|
||||||
Window& WindowList::ensure_window(const WindowIdentifier& identifier)
|
Window& WindowList::ensure_window(const WindowIdentifier& identifier)
|
||||||
{
|
{
|
||||||
|
@ -7,6 +9,14 @@ Window& WindowList::ensure_window(const WindowIdentifier& identifier)
|
||||||
return *it->value;
|
return *it->value;
|
||||||
auto window = make<Window>(identifier);
|
auto window = make<Window>(identifier);
|
||||||
window->set_button(aid_create_button());
|
window->set_button(aid_create_button());
|
||||||
|
window->button()->on_click = [identifier] (GButton&) {
|
||||||
|
WSAPI_ClientMessage message;
|
||||||
|
message.type = WSAPI_ClientMessage::Type::WM_SetActiveWindow;
|
||||||
|
message.wm.client_id = identifier.client_id();
|
||||||
|
message.wm.window_id = identifier.window_id();
|
||||||
|
bool success = GEventLoop::post_message_to_server(message);
|
||||||
|
ASSERT(success);
|
||||||
|
};
|
||||||
auto& window_ref = *window;
|
auto& window_ref = *window;
|
||||||
m_windows.set(identifier, move(window));
|
m_windows.set(identifier, move(window));
|
||||||
return window_ref;
|
return window_ref;
|
||||||
|
|
|
@ -185,6 +185,7 @@ struct WSAPI_ClientMessage {
|
||||||
SetWallpaper,
|
SetWallpaper,
|
||||||
GetWallpaper,
|
GetWallpaper,
|
||||||
SetWindowOverrideCursor,
|
SetWindowOverrideCursor,
|
||||||
|
WM_SetActiveWindow,
|
||||||
};
|
};
|
||||||
Type type { Invalid };
|
Type type { Invalid };
|
||||||
int window_id { -1 };
|
int window_id { -1 };
|
||||||
|
@ -196,6 +197,10 @@ struct WSAPI_ClientMessage {
|
||||||
struct {
|
struct {
|
||||||
int client_pid;
|
int client_pid;
|
||||||
} greeting;
|
} greeting;
|
||||||
|
struct {
|
||||||
|
int client_id;
|
||||||
|
int window_id;
|
||||||
|
} wm;
|
||||||
struct {
|
struct {
|
||||||
int menubar_id;
|
int menubar_id;
|
||||||
int menu_id;
|
int menu_id;
|
||||||
|
|
|
@ -519,6 +519,22 @@ void WSClientConnection::handle_request(const WSAPISetWindowOverrideCursorReques
|
||||||
window.set_override_cursor(WSCursor::create(request.cursor()));
|
window.set_override_cursor(WSCursor::create(request.cursor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WSClientConnection::handle_request(const WSWMAPISetActiveWindowRequest& request)
|
||||||
|
{
|
||||||
|
auto* client = WSClientConnection::from_client_id(request.target_client_id());
|
||||||
|
if (!client) {
|
||||||
|
post_error("Bad client ID");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto it = client->m_windows.find(request.target_window_id());
|
||||||
|
if (it == client->m_windows.end()) {
|
||||||
|
post_error("Bad window ID");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto& window = *(*it).value;
|
||||||
|
WSWindowManager::the().set_active_window(&window);
|
||||||
|
}
|
||||||
|
|
||||||
void WSClientConnection::on_request(const WSAPIClientRequest& request)
|
void WSClientConnection::on_request(const WSAPIClientRequest& request)
|
||||||
{
|
{
|
||||||
switch (request.type()) {
|
switch (request.type()) {
|
||||||
|
@ -572,6 +588,8 @@ void WSClientConnection::on_request(const WSAPIClientRequest& request)
|
||||||
return handle_request(static_cast<const WSAPIGetWallpaperRequest&>(request));
|
return handle_request(static_cast<const WSAPIGetWallpaperRequest&>(request));
|
||||||
case WSMessage::APISetWindowOverrideCursorRequest:
|
case WSMessage::APISetWindowOverrideCursorRequest:
|
||||||
return handle_request(static_cast<const WSAPISetWindowOverrideCursorRequest&>(request));
|
return handle_request(static_cast<const WSAPISetWindowOverrideCursorRequest&>(request));
|
||||||
|
case WSMessage::WMAPISetActiveWindowRequest:
|
||||||
|
return handle_request(static_cast<const WSWMAPISetActiveWindowRequest&>(request));
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ private:
|
||||||
void handle_request(const WSAPISetWallpaperRequest&);
|
void handle_request(const WSAPISetWallpaperRequest&);
|
||||||
void handle_request(const WSAPIGetWallpaperRequest&);
|
void handle_request(const WSAPIGetWallpaperRequest&);
|
||||||
void handle_request(const WSAPISetWindowOverrideCursorRequest&);
|
void handle_request(const WSAPISetWindowOverrideCursorRequest&);
|
||||||
|
void handle_request(const WSWMAPISetActiveWindowRequest&);
|
||||||
|
|
||||||
void post_error(const String&);
|
void post_error(const String&);
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
APISetWallpaperRequest,
|
APISetWallpaperRequest,
|
||||||
APIGetWallpaperRequest,
|
APIGetWallpaperRequest,
|
||||||
APISetWindowOverrideCursorRequest,
|
APISetWindowOverrideCursorRequest,
|
||||||
|
WMAPISetActiveWindowRequest,
|
||||||
__End_API_Client_Requests,
|
__End_API_Client_Requests,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,6 +102,23 @@ private:
|
||||||
int m_client_id { 0 };
|
int m_client_id { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WSWMAPISetActiveWindowRequest : public WSAPIClientRequest {
|
||||||
|
public:
|
||||||
|
WSWMAPISetActiveWindowRequest(int client_id, int target_client_id, int target_window_id)
|
||||||
|
: WSAPIClientRequest(WSMessage::WMAPISetActiveWindowRequest, client_id)
|
||||||
|
, m_target_client_id(target_client_id)
|
||||||
|
, m_target_window_id(target_window_id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int target_client_id() const { return m_target_client_id; }
|
||||||
|
int target_window_id() const { return m_target_window_id; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_target_client_id;
|
||||||
|
int m_target_window_id;
|
||||||
|
};
|
||||||
|
|
||||||
class WSAPISetGlobalCursorTrackingRequest : public WSAPIClientRequest {
|
class WSAPISetGlobalCursorTrackingRequest : public WSAPIClientRequest {
|
||||||
public:
|
public:
|
||||||
WSAPISetGlobalCursorTrackingRequest(int client_id, int window_id, bool value)
|
WSAPISetGlobalCursorTrackingRequest(int client_id, int window_id, bool value)
|
||||||
|
|
|
@ -346,6 +346,10 @@ void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMess
|
||||||
break;
|
break;
|
||||||
case WSAPI_ClientMessage::Type::SetWindowOverrideCursor:
|
case WSAPI_ClientMessage::Type::SetWindowOverrideCursor:
|
||||||
post_message(client, make<WSAPISetWindowOverrideCursorRequest>(client_id, message.window_id, (WSStandardCursor)message.cursor.cursor));
|
post_message(client, make<WSAPISetWindowOverrideCursorRequest>(client_id, message.window_id, (WSStandardCursor)message.cursor.cursor));
|
||||||
|
break;
|
||||||
|
case WSAPI_ClientMessage::Type::WM_SetActiveWindow:
|
||||||
|
post_message(client, make<WSWMAPISetActiveWindowRequest>(client_id, message.wm.client_id, message.wm.window_id));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,8 @@ public:
|
||||||
const WSCursor& disallowed_cursor() const { return *m_disallowed_cursor; }
|
const WSCursor& disallowed_cursor() const { return *m_disallowed_cursor; }
|
||||||
const WSCursor& move_cursor() const { return *m_move_cursor; }
|
const WSCursor& move_cursor() const { return *m_move_cursor; }
|
||||||
|
|
||||||
|
void set_active_window(WSWindow*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void process_mouse_event(const WSMouseEvent&, WSWindow*& event_window);
|
void process_mouse_event(const WSMouseEvent&, WSWindow*& event_window);
|
||||||
bool process_ongoing_window_resize(const WSMouseEvent&, WSWindow*& event_window);
|
bool process_ongoing_window_resize(const WSMouseEvent&, WSWindow*& event_window);
|
||||||
|
@ -106,7 +108,6 @@ private:
|
||||||
void start_window_resize(WSWindow&, const WSMouseEvent&);
|
void start_window_resize(WSWindow&, const WSMouseEvent&);
|
||||||
void start_window_drag(WSWindow&, const WSMouseEvent&);
|
void start_window_drag(WSWindow&, const WSMouseEvent&);
|
||||||
void handle_client_request(const WSAPIClientRequest&);
|
void handle_client_request(const WSAPIClientRequest&);
|
||||||
void set_active_window(WSWindow*);
|
|
||||||
void set_hovered_window(WSWindow*);
|
void set_hovered_window(WSWindow*);
|
||||||
template<typename Callback> IterationDecision for_each_visible_window_of_type_from_back_to_front(WSWindowType, Callback);
|
template<typename Callback> IterationDecision for_each_visible_window_of_type_from_back_to_front(WSWindowType, Callback);
|
||||||
template<typename Callback> IterationDecision for_each_visible_window_of_type_from_front_to_back(WSWindowType, Callback);
|
template<typename Callback> IterationDecision for_each_visible_window_of_type_from_front_to_back(WSWindowType, Callback);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue