WindowServer+LibGUI: Change cursor icon if DragEnter event was accepted
This commit is contained in:
parent
e5674d9666
commit
2e244fc85b
Notes:
sideshowbarker
2024-07-17 07:35:36 +09:00
Author: https://github.com/krkk Commit: https://github.com/SerenityOS/serenity/commit/2e244fc85b Pull-request: https://github.com/SerenityOS/serenity/pull/14957
6 changed files with 30 additions and 7 deletions
|
@ -295,6 +295,7 @@ void Application::set_drag_hovered_widget_impl(Widget* widget, Gfx::IntPoint con
|
|||
m_drag_hovered_widget->dispatch_event(enter_event, m_drag_hovered_widget->window());
|
||||
if (enter_event.is_accepted())
|
||||
set_pending_drop_widget(m_drag_hovered_widget);
|
||||
ConnectionToWindowServer::the().async_set_accepts_drag(enter_event.is_accepted());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -824,6 +824,13 @@ Messages::WindowServer::StartDragResponse ConnectionFromClient::start_drag(Strin
|
|||
return true;
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_accepts_drag(bool accepts)
|
||||
{
|
||||
auto& wm = WindowManager::the();
|
||||
VERIFY(wm.dnd_client());
|
||||
wm.set_accepts_drag(accepts);
|
||||
}
|
||||
|
||||
Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(String const& theme_path, String const& theme_name, bool keep_desktop_background)
|
||||
{
|
||||
bool success = WindowManager::the().update_theme(theme_path, theme_name, keep_desktop_background);
|
||||
|
|
|
@ -142,6 +142,7 @@ private:
|
|||
virtual void dismiss_menu(i32) override;
|
||||
virtual void set_window_icon_bitmap(i32, Gfx::ShareableBitmap const&) override;
|
||||
virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap<String, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
|
||||
virtual void set_accepts_drag(bool) override;
|
||||
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(String const&, String const&, bool keep_desktop_background) override;
|
||||
virtual Messages::WindowServer::GetSystemThemeResponse get_system_theme() override;
|
||||
virtual Messages::WindowServer::SetSystemThemeOverrideResponse set_system_theme_override(Core::AnonymousBuffer const&) override;
|
||||
|
|
|
@ -1016,14 +1016,13 @@ bool WindowManager::process_ongoing_drag(MouseEvent& event)
|
|||
m_dnd_overlay->cursor_moved();
|
||||
|
||||
// We didn't let go of the drag yet, see if we should send some drag move events..
|
||||
for_each_visible_window_from_front_to_back([&](Window& window) {
|
||||
if (!window.rect().contains(event.position()))
|
||||
return IterationDecision::Continue;
|
||||
if (auto* window = current_window_stack().window_at(event.position(), WindowStack::IncludeWindowFrame::No)) {
|
||||
event.set_drag(true);
|
||||
event.set_mime_data(*m_dnd_mime_data);
|
||||
deliver_mouse_event(window, event, false);
|
||||
return IterationDecision::Break;
|
||||
});
|
||||
deliver_mouse_event(*window, event, false);
|
||||
} else {
|
||||
set_accepts_drag(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(event.type() == Event::MouseUp && event.button() == MouseButton::Primary))
|
||||
|
@ -1918,8 +1917,11 @@ ConnectionFromClient const* WindowManager::active_client() const
|
|||
|
||||
Cursor const& WindowManager::active_cursor() const
|
||||
{
|
||||
if (m_dnd_client)
|
||||
if (m_dnd_client) {
|
||||
if (m_dnd_accepts_drag)
|
||||
return *m_drag_copy_cursor;
|
||||
return *m_drag_cursor;
|
||||
}
|
||||
|
||||
if (m_move_window)
|
||||
return *m_move_cursor;
|
||||
|
@ -2061,6 +2063,14 @@ void WindowManager::end_dnd_drag()
|
|||
m_dnd_client = nullptr;
|
||||
m_dnd_text = {};
|
||||
m_dnd_overlay = nullptr;
|
||||
m_dnd_accepts_drag = false;
|
||||
}
|
||||
|
||||
void WindowManager::set_accepts_drag(bool accepts)
|
||||
{
|
||||
VERIFY(m_dnd_client);
|
||||
m_dnd_accepts_drag = accepts;
|
||||
Compositor::the().invalidate_cursor();
|
||||
}
|
||||
|
||||
void WindowManager::invalidate_after_theme_or_font_change()
|
||||
|
|
|
@ -96,6 +96,8 @@ public:
|
|||
void start_dnd_drag(ConnectionFromClient&, String const& text, Gfx::Bitmap const*, Core::MimeData const&);
|
||||
void end_dnd_drag();
|
||||
|
||||
void set_accepts_drag(bool);
|
||||
|
||||
Window* active_window()
|
||||
{
|
||||
VERIFY(m_current_window_stack);
|
||||
|
@ -480,6 +482,7 @@ private:
|
|||
OwnPtr<DndOverlay> m_dnd_overlay;
|
||||
WeakPtr<ConnectionFromClient> m_dnd_client;
|
||||
String m_dnd_text;
|
||||
bool m_dnd_accepts_drag { false };
|
||||
|
||||
RefPtr<Core::MimeData> m_dnd_mime_data;
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ endpoint WindowServer
|
|||
set_window_custom_cursor(i32 window_id, Gfx::ShareableBitmap cursor) =|
|
||||
|
||||
start_drag([UTF8] String text, HashMap<String,ByteBuffer> mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started)
|
||||
set_accepts_drag(bool accepts) =|
|
||||
|
||||
set_system_theme(String theme_path, [UTF8] String theme_name, bool keep_desktop_background) => (bool success)
|
||||
get_system_theme() => ([UTF8] String theme_name)
|
||||
|
|
Loading…
Add table
Reference in a new issue