WindowServer+LibGUI: Allow changing a window's base size and increment

Previously it was only possible to change these window attributes when
creating a new window. This patch adds an IPC message that allows you
to change them at runtime.
This commit is contained in:
Andreas Kling 2020-02-24 19:23:57 +01:00
parent d0f5b43c2e
commit ab6f694905
5 changed files with 38 additions and 2 deletions

View file

@ -670,4 +670,22 @@ Action* Window::action_for_key_event(const KeyEvent& event)
return found_action;
}
void Window::set_base_size(const Gfx::Size& base_size)
{
if (m_base_size == base_size)
return;
m_base_size = base_size;
if (m_window_id)
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement>(m_window_id, m_base_size, m_size_increment);
}
void Window::set_size_increment(const Gfx::Size& size_increment)
{
if (m_size_increment == size_increment)
return;
m_size_increment = size_increment;
if (m_window_id)
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement>(m_window_id, m_base_size, m_size_increment);
}
}

View file

@ -148,9 +148,9 @@ public:
Gfx::Bitmap* back_bitmap() { return m_back_bitmap.ptr(); }
Gfx::Size size_increment() const { return m_size_increment; }
void set_size_increment(const Gfx::Size& increment) { m_size_increment = increment; }
void set_size_increment(const Gfx::Size&);
Gfx::Size base_size() const { return m_base_size; }
void set_base_size(const Gfx::Size& size) { m_base_size = size; }
void set_base_size(const Gfx::Size&);
void set_override_cursor(StandardCursor);

View file

@ -714,4 +714,19 @@ void ClientConnection::deboost()
perror("deboost: set_process_boost");
}
OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement& message)
{
auto it = m_windows.find(message.window_id());
if (it == m_windows.end()) {
did_misbehave("SetWindowBaseSizeAndSizeIncrementResponse: Bad window ID");
return nullptr;
}
auto& window = *it->value;
window.set_base_size(message.base_size());
window.set_size_increment(message.size_increment());
return make<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse>();
}
}

View file

@ -116,6 +116,7 @@ private:
virtual OwnPtr<Messages::WindowServer::StartDragResponse> handle(const Messages::WindowServer::StartDrag&) override;
virtual OwnPtr<Messages::WindowServer::SetSystemMenuResponse> handle(const Messages::WindowServer::SetSystemMenu&) override;
virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override;
virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override;
HashMap<int, NonnullRefPtr<Window>> m_windows;
HashMap<int, NonnullOwnPtr<MenuBar>> m_menubars;

View file

@ -83,4 +83,6 @@ endpoint WindowServer = 2
StartDrag(String text, String data_type, String data, i32 bitmap_id, Gfx::Size bitmap_size) => (bool started)
SetSystemTheme(String theme_path, String theme_name) => (bool success)
SetWindowBaseSizeAndSizeIncrement(i32 window_id, Gfx::Size base_size, Gfx::Size size_increment) => ()
}