Skip to content

Commit 2e244fc

Browse files
krkkAtkinsSJ
authored andcommitted
WindowServer+LibGUI: Change cursor icon if DragEnter event was accepted
1 parent e5674d9 commit 2e244fc

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

Userland/Libraries/LibGUI/Application.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ void Application::set_drag_hovered_widget_impl(Widget* widget, Gfx::IntPoint con
295295
m_drag_hovered_widget->dispatch_event(enter_event, m_drag_hovered_widget->window());
296296
if (enter_event.is_accepted())
297297
set_pending_drop_widget(m_drag_hovered_widget);
298+
ConnectionToWindowServer::the().async_set_accepts_drag(enter_event.is_accepted());
298299
}
299300
}
300301

Userland/Services/WindowServer/ConnectionFromClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,13 @@ Messages::WindowServer::StartDragResponse ConnectionFromClient::start_drag(Strin
824824
return true;
825825
}
826826

827+
void ConnectionFromClient::set_accepts_drag(bool accepts)
828+
{
829+
auto& wm = WindowManager::the();
830+
VERIFY(wm.dnd_client());
831+
wm.set_accepts_drag(accepts);
832+
}
833+
827834
Messages::WindowServer::SetSystemThemeResponse ConnectionFromClient::set_system_theme(String const& theme_path, String const& theme_name, bool keep_desktop_background)
828835
{
829836
bool success = WindowManager::the().update_theme(theme_path, theme_name, keep_desktop_background);

Userland/Services/WindowServer/ConnectionFromClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class ConnectionFromClient final
142142
virtual void dismiss_menu(i32) override;
143143
virtual void set_window_icon_bitmap(i32, Gfx::ShareableBitmap const&) override;
144144
virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap<String, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;
145+
virtual void set_accepts_drag(bool) override;
145146
virtual Messages::WindowServer::SetSystemThemeResponse set_system_theme(String const&, String const&, bool keep_desktop_background) override;
146147
virtual Messages::WindowServer::GetSystemThemeResponse get_system_theme() override;
147148
virtual Messages::WindowServer::SetSystemThemeOverrideResponse set_system_theme_override(Core::AnonymousBuffer const&) override;

Userland/Services/WindowServer/WindowManager.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,13 @@ bool WindowManager::process_ongoing_drag(MouseEvent& event)
10161016
m_dnd_overlay->cursor_moved();
10171017

10181018
// We didn't let go of the drag yet, see if we should send some drag move events..
1019-
for_each_visible_window_from_front_to_back([&](Window& window) {
1020-
if (!window.rect().contains(event.position()))
1021-
return IterationDecision::Continue;
1019+
if (auto* window = current_window_stack().window_at(event.position(), WindowStack::IncludeWindowFrame::No)) {
10221020
event.set_drag(true);
10231021
event.set_mime_data(*m_dnd_mime_data);
1024-
deliver_mouse_event(window, event, false);
1025-
return IterationDecision::Break;
1026-
});
1022+
deliver_mouse_event(*window, event, false);
1023+
} else {
1024+
set_accepts_drag(false);
1025+
}
10271026
}
10281027

10291028
if (!(event.type() == Event::MouseUp && event.button() == MouseButton::Primary))
@@ -1918,8 +1917,11 @@ ConnectionFromClient const* WindowManager::active_client() const
19181917

19191918
Cursor const& WindowManager::active_cursor() const
19201919
{
1921-
if (m_dnd_client)
1920+
if (m_dnd_client) {
1921+
if (m_dnd_accepts_drag)
1922+
return *m_drag_copy_cursor;
19221923
return *m_drag_cursor;
1924+
}
19231925

19241926
if (m_move_window)
19251927
return *m_move_cursor;
@@ -2061,6 +2063,14 @@ void WindowManager::end_dnd_drag()
20612063
m_dnd_client = nullptr;
20622064
m_dnd_text = {};
20632065
m_dnd_overlay = nullptr;
2066+
m_dnd_accepts_drag = false;
2067+
}
2068+
2069+
void WindowManager::set_accepts_drag(bool accepts)
2070+
{
2071+
VERIFY(m_dnd_client);
2072+
m_dnd_accepts_drag = accepts;
2073+
Compositor::the().invalidate_cursor();
20642074
}
20652075

20662076
void WindowManager::invalidate_after_theme_or_font_change()

Userland/Services/WindowServer/WindowManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class WindowManager : public Core::Object {
9696
void start_dnd_drag(ConnectionFromClient&, String const& text, Gfx::Bitmap const*, Core::MimeData const&);
9797
void end_dnd_drag();
9898

99+
void set_accepts_drag(bool);
100+
99101
Window* active_window()
100102
{
101103
VERIFY(m_current_window_stack);
@@ -480,6 +482,7 @@ class WindowManager : public Core::Object {
480482
OwnPtr<DndOverlay> m_dnd_overlay;
481483
WeakPtr<ConnectionFromClient> m_dnd_client;
482484
String m_dnd_text;
485+
bool m_dnd_accepts_drag { false };
483486

484487
RefPtr<Core::MimeData> m_dnd_mime_data;
485488

Userland/Services/WindowServer/WindowServer.ipc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ endpoint WindowServer
123123
set_window_custom_cursor(i32 window_id, Gfx::ShareableBitmap cursor) =|
124124

125125
start_drag([UTF8] String text, HashMap<String,ByteBuffer> mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started)
126+
set_accepts_drag(bool accepts) =|
126127

127128
set_system_theme(String theme_path, [UTF8] String theme_name, bool keep_desktop_background) => (bool success)
128129
get_system_theme() => ([UTF8] String theme_name)

0 commit comments

Comments
 (0)