mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
WindowServer: Normalize preferred rect before applying
Previously, SetWindowRect and SetWindowRect could supply basically arbitrary x and y coordinates. This could happen either due to a malicious or malfunctioning program, or even due to the auto-centering feature. This patch also moves the 'normalization' code out of ClientConnection to Window, where it belongs better. Fixes #4135. Fixes #5052.
This commit is contained in:
parent
345909c009
commit
399908e53c
3 changed files with 33 additions and 15 deletions
|
@ -48,15 +48,6 @@ namespace WindowServer {
|
||||||
|
|
||||||
HashMap<int, NonnullRefPtr<ClientConnection>>* s_connections;
|
HashMap<int, NonnullRefPtr<ClientConnection>>* s_connections;
|
||||||
|
|
||||||
static Gfx::IntRect normalize_window_rect(Gfx::IntRect rect, WindowType window_type)
|
|
||||||
{
|
|
||||||
auto min_size = 1;
|
|
||||||
if (window_type == WindowType::Normal)
|
|
||||||
min_size = 50;
|
|
||||||
Gfx::IntRect normalized_rect = { rect.x(), rect.y(), max(rect.width(), min_size), max(rect.height(), min_size) };
|
|
||||||
return normalized_rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientConnection::for_each_client(Function<void(ClientConnection&)> callback)
|
void ClientConnection::for_each_client(Function<void(ClientConnection&)> callback)
|
||||||
{
|
{
|
||||||
if (!s_connections)
|
if (!s_connections)
|
||||||
|
@ -403,10 +394,10 @@ OwnPtr<Messages::WindowServer::SetWindowRectResponse> ClientConnection::handle(c
|
||||||
if (message.rect().location() != window.rect().location()) {
|
if (message.rect().location() != window.rect().location()) {
|
||||||
window.set_default_positioned(false);
|
window.set_default_positioned(false);
|
||||||
}
|
}
|
||||||
auto normalized_rect = normalize_window_rect(message.rect(), window.type());
|
window.set_rect(message.rect());
|
||||||
window.set_rect(normalized_rect);
|
window.normalize_rect();
|
||||||
window.request_update(normalized_rect);
|
window.request_update(window.rect());
|
||||||
return make<Messages::WindowServer::SetWindowRectResponse>(normalized_rect);
|
return make<Messages::WindowServer::SetWindowRectResponse>(window.rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Messages::WindowServer::GetWindowRectResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowRect& message)
|
OwnPtr<Messages::WindowServer::GetWindowRectResponse> ClientConnection::handle(const Messages::WindowServer::GetWindowRect& message)
|
||||||
|
@ -461,8 +452,8 @@ OwnPtr<Messages::WindowServer::CreateWindowResponse> ClientConnection::handle(co
|
||||||
rect = { WindowManager::the().get_recommended_window_position({ 100, 100 }), message.rect().size() };
|
rect = { WindowManager::the().get_recommended_window_position({ 100, 100 }), message.rect().size() };
|
||||||
window->set_default_positioned(true);
|
window->set_default_positioned(true);
|
||||||
}
|
}
|
||||||
auto normalized_rect = normalize_window_rect(rect, window->type());
|
window->set_rect(rect);
|
||||||
window->set_rect(normalized_rect);
|
window->normalize_rect();
|
||||||
}
|
}
|
||||||
if (window->type() == WindowType::Desktop) {
|
if (window->type() == WindowType::Desktop) {
|
||||||
window->set_rect(WindowManager::the().desktop_rect());
|
window->set_rect(WindowManager::the().desktop_rect());
|
||||||
|
|
|
@ -176,6 +176,32 @@ void Window::set_rect_without_repaint(const Gfx::IntRect& rect)
|
||||||
m_frame.notify_window_rect_changed(old_rect, rect); // recomputes occlusions
|
m_frame.notify_window_rect_changed(old_rect, rect); // recomputes occlusions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::normalize_rect()
|
||||||
|
{
|
||||||
|
auto min_size = 1;
|
||||||
|
// Must be -1 to allow windows just outside the desktop rect.
|
||||||
|
// For example, the windows that make the desktop rect smaller
|
||||||
|
// than the display resolution (e.g. the TaskBar).
|
||||||
|
auto min_visible = -1;
|
||||||
|
auto desktop = WindowManager::the().desktop_rect();
|
||||||
|
auto min_y = 0;
|
||||||
|
if (type() == WindowType::Normal) {
|
||||||
|
min_size = 50;
|
||||||
|
min_visible = 50;
|
||||||
|
// 5 pixels is the amount of frame decoration that can be sacrificed before starting to become an issue.
|
||||||
|
min_y = desktop.top() - 5;
|
||||||
|
}
|
||||||
|
auto new_width = max(width(), min_size);
|
||||||
|
auto new_height = max(height(), min_size);
|
||||||
|
Gfx::IntRect normalized_rect = {
|
||||||
|
clamp(x(), -new_width + min_visible, desktop.width() - min_visible),
|
||||||
|
clamp(y(), min_y, desktop.bottom() - min_visible),
|
||||||
|
new_width,
|
||||||
|
new_height,
|
||||||
|
};
|
||||||
|
set_rect(normalized_rect);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::handle_mouse_event(const MouseEvent& event)
|
void Window::handle_mouse_event(const MouseEvent& event)
|
||||||
{
|
{
|
||||||
set_automatic_cursor_tracking_enabled(event.buttons() != 0);
|
set_automatic_cursor_tracking_enabled(event.buttons() != 0);
|
||||||
|
|
|
@ -158,6 +158,7 @@ public:
|
||||||
void set_rect(const Gfx::IntRect&);
|
void set_rect(const Gfx::IntRect&);
|
||||||
void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
|
void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
|
||||||
void set_rect_without_repaint(const Gfx::IntRect&);
|
void set_rect_without_repaint(const Gfx::IntRect&);
|
||||||
|
void normalize_rect();
|
||||||
|
|
||||||
void set_taskbar_rect(const Gfx::IntRect&);
|
void set_taskbar_rect(const Gfx::IntRect&);
|
||||||
const Gfx::IntRect& taskbar_rect() const { return m_taskbar_rect; }
|
const Gfx::IntRect& taskbar_rect() const { return m_taskbar_rect; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue