mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
LibGUI+WindowServer: Add resize_aspect_ratio()
When a resize_aspect_ratio is specified, and window will only be resized to a multiple of that ratio. When resize_aspect_ratio is set, windows cannot be tiled.
This commit is contained in:
parent
c68537271c
commit
45ed58865e
8 changed files with 51 additions and 1 deletions
|
@ -107,6 +107,7 @@ void Window::show()
|
||||||
m_opacity_when_windowless,
|
m_opacity_when_windowless,
|
||||||
m_base_size,
|
m_base_size,
|
||||||
m_size_increment,
|
m_size_increment,
|
||||||
|
m_resize_aspect_ratio,
|
||||||
(i32)m_window_type,
|
(i32)m_window_type,
|
||||||
m_title_when_windowless,
|
m_title_when_windowless,
|
||||||
parent_window ? parent_window->window_id() : 0);
|
parent_window ? parent_window->window_id() : 0);
|
||||||
|
@ -837,6 +838,16 @@ void Window::set_size_increment(const Gfx::IntSize& size_increment)
|
||||||
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement>(m_window_id, m_base_size, m_size_increment);
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement>(m_window_id, m_base_size, m_size_increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::set_resize_aspect_ratio(const Optional<Gfx::IntSize>& ratio)
|
||||||
|
{
|
||||||
|
if (m_resize_aspect_ratio == ratio)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_resize_aspect_ratio = ratio;
|
||||||
|
if (is_visible())
|
||||||
|
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowResizeAspectRatio>(m_window_id, m_resize_aspect_ratio);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::did_add_widget(Badge<Widget>, Widget& widget)
|
void Window::did_add_widget(Badge<Widget>, Widget& widget)
|
||||||
{
|
{
|
||||||
if (!m_focused_widget && widget.accepts_focus())
|
if (!m_focused_widget && widget.accepts_focus())
|
||||||
|
|
|
@ -179,6 +179,10 @@ public:
|
||||||
void set_size_increment(const Gfx::IntSize&);
|
void set_size_increment(const Gfx::IntSize&);
|
||||||
Gfx::IntSize base_size() const { return m_base_size; }
|
Gfx::IntSize base_size() const { return m_base_size; }
|
||||||
void set_base_size(const Gfx::IntSize&);
|
void set_base_size(const Gfx::IntSize&);
|
||||||
|
const Optional<Gfx::IntSize>& resize_aspect_ratio() const { return m_resize_aspect_ratio; }
|
||||||
|
void set_resize_aspect_ratio(int width, int height) { set_resize_aspect_ratio(Gfx::IntSize(width, height)); }
|
||||||
|
void set_no_resize_aspect_ratio() { set_resize_aspect_ratio({}); }
|
||||||
|
void set_resize_aspect_ratio(const Optional<Gfx::IntSize>& ratio);
|
||||||
|
|
||||||
void set_override_cursor(StandardCursor);
|
void set_override_cursor(StandardCursor);
|
||||||
void set_override_cursor(const Gfx::Bitmap&);
|
void set_override_cursor(const Gfx::Bitmap&);
|
||||||
|
@ -260,6 +264,7 @@ private:
|
||||||
bool m_double_buffering_enabled { true };
|
bool m_double_buffering_enabled { true };
|
||||||
bool m_modal { false };
|
bool m_modal { false };
|
||||||
bool m_resizable { true };
|
bool m_resizable { true };
|
||||||
|
Optional<Gfx::IntSize> m_resize_aspect_ratio {};
|
||||||
bool m_minimizable { true };
|
bool m_minimizable { true };
|
||||||
bool m_fullscreen { false };
|
bool m_fullscreen { false };
|
||||||
bool m_frameless { false };
|
bool m_frameless { false };
|
||||||
|
|
|
@ -479,6 +479,7 @@ OwnPtr<Messages::WindowServer::CreateWindowResponse> ClientConnection::handle(co
|
||||||
window->set_opacity(message.opacity());
|
window->set_opacity(message.opacity());
|
||||||
window->set_size_increment(message.size_increment());
|
window->set_size_increment(message.size_increment());
|
||||||
window->set_base_size(message.base_size());
|
window->set_base_size(message.base_size());
|
||||||
|
window->set_resize_aspect_ratio(message.resize_aspect_ratio());
|
||||||
window->invalidate();
|
window->invalidate();
|
||||||
if (window->type() == WindowType::MenuApplet)
|
if (window->type() == WindowType::MenuApplet)
|
||||||
AppletManager::the().add_applet(*window);
|
AppletManager::the().add_applet(*window);
|
||||||
|
@ -816,6 +817,20 @@ OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> Client
|
||||||
return make<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse>();
|
return make<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OwnPtr<Messages::WindowServer::SetWindowResizeAspectRatioResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowResizeAspectRatio& message)
|
||||||
|
{
|
||||||
|
auto it = m_windows.find(message.window_id());
|
||||||
|
if (it == m_windows.end()) {
|
||||||
|
did_misbehave("SetWindowResizeAspectRatioResponse: Bad window ID");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& window = *it->value;
|
||||||
|
window.set_resize_aspect_ratio(message.resize_aspect_ratio());
|
||||||
|
|
||||||
|
return make<Messages::WindowServer::SetWindowResizeAspectRatioResponse>();
|
||||||
|
}
|
||||||
|
|
||||||
void ClientConnection::handle(const Messages::WindowServer::EnableDisplayLink&)
|
void ClientConnection::handle(const Messages::WindowServer::EnableDisplayLink&)
|
||||||
{
|
{
|
||||||
if (m_has_display_link)
|
if (m_has_display_link)
|
||||||
|
|
|
@ -138,6 +138,7 @@ private:
|
||||||
virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override;
|
virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override;
|
||||||
virtual OwnPtr<Messages::WindowServer::GetSystemThemeResponse> handle(const Messages::WindowServer::GetSystemTheme&) override;
|
virtual OwnPtr<Messages::WindowServer::GetSystemThemeResponse> handle(const Messages::WindowServer::GetSystemTheme&) override;
|
||||||
virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override;
|
virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override;
|
||||||
|
virtual OwnPtr<Messages::WindowServer::SetWindowResizeAspectRatioResponse> handle(const Messages::WindowServer::SetWindowResizeAspectRatio&) override;
|
||||||
virtual void handle(const Messages::WindowServer::EnableDisplayLink&) override;
|
virtual void handle(const Messages::WindowServer::EnableDisplayLink&) override;
|
||||||
virtual void handle(const Messages::WindowServer::DisableDisplayLink&) override;
|
virtual void handle(const Messages::WindowServer::DisableDisplayLink&) override;
|
||||||
virtual void handle(const Messages::WindowServer::SetWindowProgress&) override;
|
virtual void handle(const Messages::WindowServer::SetWindowProgress&) override;
|
||||||
|
|
|
@ -297,7 +297,7 @@ void Window::set_maximized(bool maximized)
|
||||||
{
|
{
|
||||||
if (m_maximized == maximized)
|
if (m_maximized == maximized)
|
||||||
return;
|
return;
|
||||||
if (maximized && !is_resizable())
|
if (maximized && (!is_resizable() || resize_aspect_ratio().has_value()))
|
||||||
return;
|
return;
|
||||||
set_tiled(WindowTileType::None);
|
set_tiled(WindowTileType::None);
|
||||||
m_maximized = maximized;
|
m_maximized = maximized;
|
||||||
|
@ -616,6 +616,9 @@ void Window::set_tiled(WindowTileType tiled)
|
||||||
if (m_tiled == tiled)
|
if (m_tiled == tiled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (resize_aspect_ratio().has_value())
|
||||||
|
return;
|
||||||
|
|
||||||
m_tiled = tiled;
|
m_tiled = tiled;
|
||||||
if (tiled != WindowTileType::None)
|
if (tiled != WindowTileType::None)
|
||||||
m_untiled_rect = m_rect;
|
m_untiled_rect = m_rect;
|
||||||
|
|
|
@ -207,6 +207,9 @@ public:
|
||||||
Gfx::IntSize size_increment() const { return m_size_increment; }
|
Gfx::IntSize size_increment() const { return m_size_increment; }
|
||||||
void set_size_increment(const Gfx::IntSize& increment) { m_size_increment = increment; }
|
void set_size_increment(const Gfx::IntSize& increment) { m_size_increment = increment; }
|
||||||
|
|
||||||
|
const Optional<Gfx::IntSize>& resize_aspect_ratio() const { return m_resize_aspect_ratio; }
|
||||||
|
void set_resize_aspect_ratio(const Optional<Gfx::IntSize>& ratio) { m_resize_aspect_ratio = ratio; }
|
||||||
|
|
||||||
Gfx::IntSize base_size() const { return m_base_size; }
|
Gfx::IntSize base_size() const { return m_base_size; }
|
||||||
void set_base_size(const Gfx::IntSize& size) { m_base_size = size; }
|
void set_base_size(const Gfx::IntSize& size) { m_base_size = size; }
|
||||||
|
|
||||||
|
@ -314,6 +317,7 @@ private:
|
||||||
bool m_minimizable { false };
|
bool m_minimizable { false };
|
||||||
bool m_frameless { false };
|
bool m_frameless { false };
|
||||||
bool m_resizable { false };
|
bool m_resizable { false };
|
||||||
|
Optional<Gfx::IntSize> m_resize_aspect_ratio {};
|
||||||
bool m_listens_to_wm_events { false };
|
bool m_listens_to_wm_events { false };
|
||||||
bool m_minimized { false };
|
bool m_minimized { false };
|
||||||
bool m_maximized { false };
|
bool m_maximized { false };
|
||||||
|
|
|
@ -643,6 +643,15 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
|
||||||
new_rect.set_height(m_resize_window->base_size().height() + vertical_incs * m_resize_window->size_increment().height());
|
new_rect.set_height(m_resize_window->base_size().height() + vertical_incs * m_resize_window->size_increment().height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_resize_window->resize_aspect_ratio().has_value()) {
|
||||||
|
auto& ratio = m_resize_window->resize_aspect_ratio().value();
|
||||||
|
if (abs(change_w) > abs(change_h)) {
|
||||||
|
new_rect.set_height(new_rect.width() * ratio.height() / ratio.width());
|
||||||
|
} else {
|
||||||
|
new_rect.set_width(new_rect.height() * ratio.width() / ratio.height());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Second, set its position so that the sides of the window
|
// Second, set its position so that the sides of the window
|
||||||
// that end up moving are the same ones as the user is dragging,
|
// that end up moving are the same ones as the user is dragging,
|
||||||
// no matter which part of the logic above caused us to decide
|
// no matter which part of the logic above caused us to decide
|
||||||
|
|
|
@ -43,6 +43,7 @@ endpoint WindowServer = 2
|
||||||
float opacity,
|
float opacity,
|
||||||
Gfx::IntSize base_size,
|
Gfx::IntSize base_size,
|
||||||
Gfx::IntSize size_increment,
|
Gfx::IntSize size_increment,
|
||||||
|
Optional<Gfx::IntSize> resize_aspect_ratio,
|
||||||
i32 type,
|
i32 type,
|
||||||
[UTF8] String title,
|
[UTF8] String title,
|
||||||
i32 parent_window_id) => (i32 window_id)
|
i32 parent_window_id) => (i32 window_id)
|
||||||
|
@ -99,6 +100,7 @@ endpoint WindowServer = 2
|
||||||
GetSystemTheme() => ([UTF8] String theme_name)
|
GetSystemTheme() => ([UTF8] String theme_name)
|
||||||
|
|
||||||
SetWindowBaseSizeAndSizeIncrement(i32 window_id, Gfx::IntSize base_size, Gfx::IntSize size_increment) => ()
|
SetWindowBaseSizeAndSizeIncrement(i32 window_id, Gfx::IntSize base_size, Gfx::IntSize size_increment) => ()
|
||||||
|
SetWindowResizeAspectRatio(i32 window_id, Optional<Gfx::IntSize> resize_aspect_ratio) => ()
|
||||||
|
|
||||||
EnableDisplayLink() =|
|
EnableDisplayLink() =|
|
||||||
DisableDisplayLink() =|
|
DisableDisplayLink() =|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue