1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 16:05:07 +00:00

LibGUI+WindowServer: Create and broadcast an event when a window moves

LibWeb's Window object will need to know the OS-level position and size
of the GUI::Window for e.g. screenX, screenY, outerWidth, outerHeight.
It will also need to know about changes to that data.
This commit is contained in:
Timothy Flynn 2022-11-01 14:23:22 -04:00 committed by Linus Groh
parent 6b41da0b9e
commit f7e747b68e
7 changed files with 47 additions and 0 deletions

View file

@ -102,6 +102,12 @@ void ConnectionToWindowServer::window_resized(i32 window_id, Gfx::IntRect const&
} }
} }
void ConnectionToWindowServer::window_moved(i32 window_id, Gfx::IntRect const& new_rect)
{
if (auto* window = Window::from_window_id(window_id))
Core::EventLoop::current().post_event(*window, make<MoveEvent>(new_rect.location()));
}
void ConnectionToWindowServer::window_activated(i32 window_id) void ConnectionToWindowServer::window_activated(i32 window_id)
{ {
if (auto* window = Window::from_window_id(window_id)) if (auto* window = Window::from_window_id(window_id))

View file

@ -41,6 +41,7 @@ private:
virtual void window_input_left(i32) override; virtual void window_input_left(i32) override;
virtual void window_close_request(i32) override; virtual void window_close_request(i32) override;
virtual void window_resized(i32, Gfx::IntRect const&) override; virtual void window_resized(i32, Gfx::IntRect const&) override;
virtual void window_moved(i32, Gfx::IntRect const&) override;
virtual void menu_item_activated(i32, u32) override; virtual void menu_item_activated(i32, u32) override;
virtual void menu_item_entered(i32, u32) override; virtual void menu_item_entered(i32, u32) override;
virtual void menu_item_left(i32, u32) override; virtual void menu_item_left(i32, u32) override;

View file

@ -28,6 +28,7 @@ public:
Paint, Paint,
MultiPaint, MultiPaint,
Resize, Resize,
Move,
MouseMove, MouseMove,
MouseDown, MouseDown,
MouseDoubleClick, MouseDoubleClick,
@ -310,6 +311,20 @@ private:
Gfx::IntSize m_size; Gfx::IntSize m_size;
}; };
class MoveEvent final : public Event {
public:
explicit MoveEvent(Gfx::IntPoint const& size)
: Event(Event::Move)
, m_position(size)
{
}
Gfx::IntPoint const& position() const { return m_position; }
private:
Gfx::IntPoint m_position;
};
class ContextMenuEvent final : public Event { class ContextMenuEvent final : public Event {
public: public:
explicit ContextMenuEvent(Gfx::IntPoint const& position, Gfx::IntPoint const& screen_position) explicit ContextMenuEvent(Gfx::IntPoint const& position, Gfx::IntPoint const& screen_position)

View file

@ -35,6 +35,7 @@ public:
WindowInputLeft, WindowInputLeft,
WindowCloseRequest, WindowCloseRequest,
WindowResized, WindowResized,
WindowMoved,
}; };
Event() = default; Event() = default;
@ -157,4 +158,18 @@ private:
Gfx::IntRect m_rect; Gfx::IntRect m_rect;
}; };
class MoveEvent final : public Event {
public:
MoveEvent(Gfx::IntRect const& rect)
: Event(Event::WindowMoved)
, m_rect(rect)
{
}
Gfx::IntRect const& rect() const { return m_rect; }
private:
Gfx::IntRect m_rect;
};
} }

View file

@ -408,6 +408,7 @@ void Window::set_maximized(bool maximized)
set_rect(m_floating_rect); set_rect(m_floating_rect);
m_frame.did_set_maximized({}, maximized); m_frame.did_set_maximized({}, maximized);
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect)); Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
Core::EventLoop::current().post_event(*this, make<MoveEvent>(m_rect));
set_default_positioned(false); set_default_positioned(false);
WindowManager::the().notify_minimization_state_changed(*this); WindowManager::the().notify_minimization_state_changed(*this);
@ -486,6 +487,9 @@ void Window::event(Core::Event& event)
case Event::WindowResized: case Event::WindowResized:
m_client->async_window_resized(m_window_id, static_cast<ResizeEvent const&>(event).rect()); m_client->async_window_resized(m_window_id, static_cast<ResizeEvent const&>(event).rect());
break; break;
case Event::WindowMoved:
m_client->async_window_moved(m_window_id, static_cast<MoveEvent const&>(event).rect());
break;
default: default:
break; break;
} }
@ -826,6 +830,7 @@ void Window::set_fullscreen(bool fullscreen)
} }
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(new_window_rect)); Core::EventLoop::current().post_event(*this, make<ResizeEvent>(new_window_rect));
Core::EventLoop::current().post_event(*this, make<MoveEvent>(new_window_rect));
set_rect(new_window_rect); set_rect(new_window_rect);
} }
@ -896,6 +901,7 @@ bool Window::set_untiled()
set_rect(m_floating_rect); set_rect(m_floating_rect);
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect)); Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
Core::EventLoop::current().post_event(*this, make<MoveEvent>(m_rect));
return true; return true;
} }
@ -917,6 +923,7 @@ void Window::set_tiled(WindowTileType tile_type)
set_rect(WindowManager::the().tiled_window_rect(*this, tile_type)); set_rect(WindowManager::the().tiled_window_rect(*this, tile_type));
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect)); Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
Core::EventLoop::current().post_event(*this, make<MoveEvent>(m_rect));
} }
void Window::detach_client(Badge<ConnectionFromClient>) void Window::detach_client(Badge<ConnectionFromClient>)

View file

@ -23,6 +23,7 @@ endpoint WindowClient
window_input_preempted(i32 window_id, i32 preemptor) =| window_input_preempted(i32 window_id, i32 preemptor) =|
window_close_request(i32 window_id) =| window_close_request(i32 window_id) =|
window_resized(i32 window_id, Gfx::IntRect new_rect) =| window_resized(i32 window_id, Gfx::IntRect new_rect) =|
window_moved(i32 window_id, Gfx::IntRect new_rect) =|
menu_item_activated(i32 menu_id, u32 identifier) =| menu_item_activated(i32 menu_id, u32 identifier) =|
menu_item_entered(i32 menu_id, u32 identifier) =| menu_item_entered(i32 menu_id, u32 identifier) =|

View file

@ -742,6 +742,7 @@ bool WindowManager::process_ongoing_window_move(MouseEvent& event)
if (!m_move_window->is_tiled()) if (!m_move_window->is_tiled())
m_move_window->set_floating_rect(m_move_window->rect()); m_move_window->set_floating_rect(m_move_window->rect());
Core::EventLoop::current().post_event(*m_move_window, make<MoveEvent>(m_move_window->rect()));
m_move_window->invalidate(true, true); m_move_window->invalidate(true, true);
if (m_move_window->is_resizable()) { if (m_move_window->is_resizable()) {
process_event_for_doubleclick(*m_move_window, event); process_event_for_doubleclick(*m_move_window, event);
@ -816,6 +817,7 @@ bool WindowManager::process_ongoing_window_move(MouseEvent& event)
m_geometry_overlay->window_rect_changed(); m_geometry_overlay->window_rect_changed();
} }
} }
Core::EventLoop::current().post_event(*m_move_window, make<MoveEvent>(m_move_window->rect()));
return true; return true;
} }