WindowServer+LibGUI: Add a way to bring a window to the front.
GWindow::move_to_front() can now be used to move a window to the top of the window stack. We use this in Terminal to bring the settings window to the front if it already exists when it's requested, in case it's hiding behind something.
This commit is contained in:
parent
8d7fbbe1fb
commit
51581c21fc
Notes:
sideshowbarker
2024-07-19 13:48:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/51581c21fca
8 changed files with 47 additions and 0 deletions
|
@ -174,6 +174,7 @@ int main(int argc, char** argv)
|
|||
settings_window =
|
||||
create_settings_window(terminal, config)->make_weak_ptr();
|
||||
settings_window->show();
|
||||
settings_window->move_to_front();
|
||||
}));
|
||||
app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) {
|
||||
dbgprintf("Terminal: Quit menu activated!\n");
|
||||
|
|
|
@ -49,6 +49,17 @@ void GWindow::close()
|
|||
delete_later();
|
||||
}
|
||||
|
||||
void GWindow::move_to_front()
|
||||
{
|
||||
if (!m_window_id)
|
||||
return;
|
||||
|
||||
WSAPI_ClientMessage request;
|
||||
request.type = WSAPI_ClientMessage::Type::MoveWindowToFront;
|
||||
request.window_id = m_window_id;
|
||||
GEventLoop::post_message_to_server(request);
|
||||
}
|
||||
|
||||
void GWindow::show()
|
||||
{
|
||||
if (m_window_id)
|
||||
|
|
|
@ -79,6 +79,7 @@ public:
|
|||
void show();
|
||||
void hide();
|
||||
void close();
|
||||
void move_to_front();
|
||||
|
||||
void start_wm_resize();
|
||||
|
||||
|
|
|
@ -232,6 +232,7 @@ struct WSAPI_ClientMessage {
|
|||
DismissMenu,
|
||||
SetWindowIcon,
|
||||
SetWindowHasAlphaChannel,
|
||||
MoveWindowToFront,
|
||||
};
|
||||
Type type { Invalid };
|
||||
int window_id { -1 };
|
||||
|
|
|
@ -329,6 +329,18 @@ void WSClientConnection::handle_request(const WSAPIAddMenuSeparatorRequest& requ
|
|||
post_message(response);
|
||||
}
|
||||
|
||||
void WSClientConnection::handle_request(const WSAPIMoveWindowToFrontRequest& request)
|
||||
{
|
||||
int window_id = request.window_id();
|
||||
auto it = m_windows.find(window_id);
|
||||
if (it == m_windows.end()) {
|
||||
post_error("WSAPIMoveWindowToFrontRequest: Bad window ID");
|
||||
return;
|
||||
}
|
||||
auto& window = *(*it).value;
|
||||
WSWindowManager::the().move_to_front_and_make_active(window);
|
||||
}
|
||||
|
||||
void WSClientConnection::handle_request(const WSAPISetWindowOpacityRequest& request)
|
||||
{
|
||||
int window_id = request.window_id();
|
||||
|
@ -786,6 +798,8 @@ void WSClientConnection::on_request(const WSAPIClientRequest& request)
|
|||
return handle_request(static_cast<const WSAPIDismissMenuRequest&>(request));
|
||||
case WSEvent::APISetWindowHasAlphaChannelRequest:
|
||||
return handle_request(static_cast<const WSAPISetWindowHasAlphaChannelRequest&>(request));
|
||||
case WSEvent::APIMoveWindowToFrontRequest:
|
||||
return handle_request(static_cast<const WSAPIMoveWindowToFrontRequest&>(request));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ private:
|
|||
void handle_request(const WSAPIPopupMenuRequest&);
|
||||
void handle_request(const WSAPIDismissMenuRequest&);
|
||||
void handle_request(const WSAPISetWindowHasAlphaChannelRequest&);
|
||||
void handle_request(const WSAPIMoveWindowToFrontRequest&);
|
||||
|
||||
void post_error(const String&);
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
APIGetWallpaperRequest,
|
||||
APISetWindowOverrideCursorRequest,
|
||||
APISetWindowHasAlphaChannelRequest,
|
||||
APIMoveWindowToFrontRequest,
|
||||
WMAPISetActiveWindowRequest,
|
||||
WMAPISetWindowMinimizedRequest,
|
||||
WMAPIStartWindowResizeRequest,
|
||||
|
@ -460,6 +461,20 @@ private:
|
|||
int m_window_id { 0 };
|
||||
};
|
||||
|
||||
class WSAPIMoveWindowToFrontRequest final : public WSAPIClientRequest {
|
||||
public:
|
||||
explicit WSAPIMoveWindowToFrontRequest(int client_id, int window_id)
|
||||
: WSAPIClientRequest(WSEvent::APIMoveWindowToFrontRequest, client_id)
|
||||
, m_window_id(window_id)
|
||||
{
|
||||
}
|
||||
|
||||
int window_id() const { return m_window_id; }
|
||||
|
||||
private:
|
||||
int m_window_id { 0 };
|
||||
};
|
||||
|
||||
class WSAPISetClipboardContentsRequest final : public WSAPIClientRequest {
|
||||
public:
|
||||
explicit WSAPISetClipboardContentsRequest(int client_id, int shared_buffer_id, int size)
|
||||
|
|
|
@ -309,6 +309,9 @@ bool WSEventLoop::on_receive_from_client(int client_id, const WSAPI_ClientMessag
|
|||
case WSAPI_ClientMessage::Type::WM_StartWindowResize:
|
||||
post_event(client, make<WSWMAPIStartWindowResizeRequest>(client_id, message.wm.client_id, message.wm.window_id));
|
||||
break;
|
||||
case WSAPI_ClientMessage::Type::MoveWindowToFront:
|
||||
post_event(client, make<WSAPIMoveWindowToFrontRequest>(client_id, message.window_id));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue