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

LibGUI: Add Widget override cursor concept

We got ourselves into a mess by making widgets override the window
cursor whenever they wanted a custom cursor. This patch introduces a
better solution to that issue: per-widget override cursors.

Each widget now has an override cursor that overrides the window
cursor when that widget is hovered.
This commit is contained in:
Andreas Kling 2020-09-11 14:17:35 +02:00
parent b4f307f982
commit cf429a788c
4 changed files with 48 additions and 8 deletions

View file

@ -228,23 +228,20 @@ void Window::set_window_type(WindowType window_type)
void Window::set_cursor(Gfx::StandardCursor cursor)
{
if (!is_visible())
if (m_cursor == cursor)
return;
if (!m_custom_cursor && m_cursor == cursor)
return;
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowCursor>(m_window_id, (u32)cursor);
m_cursor = cursor;
m_custom_cursor = nullptr;
update_cursor();
}
void Window::set_cursor(const Gfx::Bitmap& cursor)
{
if (!is_visible())
return;
if (&cursor == m_custom_cursor.ptr())
if (m_custom_cursor == &cursor)
return;
m_cursor = Gfx::StandardCursor::None;
m_custom_cursor = &cursor;
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowCustomCursor>(m_window_id, m_custom_cursor->to_shareable_bitmap(WindowServerConnection::the().server_pid()));
update_cursor();
}
void Window::handle_drop_event(DropEvent& event)
@ -871,4 +868,24 @@ void Window::set_progress(int progress)
ASSERT(m_window_id);
WindowServerConnection::the().post_message(Messages::WindowServer::SetWindowProgress(m_window_id, progress));
}
void Window::update_cursor()
{
Gfx::StandardCursor new_cursor;
if (m_hovered_widget && m_hovered_widget->override_cursor() != Gfx::StandardCursor::None)
new_cursor = m_hovered_widget->override_cursor();
else
new_cursor = m_cursor;
if (m_effective_cursor == new_cursor)
return;
m_effective_cursor = new_cursor;
if (m_custom_cursor)
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowCustomCursor>(m_window_id, m_custom_cursor->to_shareable_bitmap(WindowServerConnection::the().server_pid()));
else
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowCursor>(m_window_id, (u32)m_effective_cursor);
}
}