mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
LibGUI+WindowServer: Start fleshing out drag&drop functionality
This patch enables basic drag&drop between applications. You initiate a drag by creating a GDragOperation object and calling exec() on it. This creates a nested event loop in the calling program that only returns once the drag operation has ended. On the receiving side, you get a call to GWidget::drop_event() with a GDropEvent containing information about the dropped data. The only data passed right now is a piece of text that's also used to visually indicate that a drag is happening (by showing the text in a little box that follows the mouse cursor around.) There are things to fix here, but we're off to a nice start. :^)
This commit is contained in:
parent
e09a02ad3f
commit
a7f414bba7
19 changed files with 318 additions and 3 deletions
53
Libraries/LibGUI/GDragOperation.cpp
Normal file
53
Libraries/LibGUI/GDragOperation.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <LibGUI/GDragOperation.h>
|
||||
#include <LibGUI/GWindowServerConnection.h>
|
||||
|
||||
static GDragOperation* s_current_drag_operation;
|
||||
|
||||
GDragOperation::GDragOperation(CObject* parent)
|
||||
: CObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
GDragOperation::~GDragOperation()
|
||||
{
|
||||
}
|
||||
|
||||
GDragOperation::Outcome GDragOperation::exec()
|
||||
{
|
||||
ASSERT(!s_current_drag_operation);
|
||||
ASSERT(!m_event_loop);
|
||||
|
||||
auto response = GWindowServerConnection::the().send_sync<WindowServer::StartDrag>(m_text, -1, Size());
|
||||
if (!response->started()) {
|
||||
m_outcome = Outcome::Cancelled;
|
||||
return m_outcome;
|
||||
}
|
||||
|
||||
s_current_drag_operation = this;
|
||||
m_event_loop = make<CEventLoop>();
|
||||
auto result = m_event_loop->exec();
|
||||
m_event_loop = nullptr;
|
||||
dbgprintf("%s: event loop returned with result %d\n", class_name(), result);
|
||||
remove_from_parent();
|
||||
s_current_drag_operation = nullptr;
|
||||
return m_outcome;
|
||||
}
|
||||
|
||||
void GDragOperation::done(Outcome outcome)
|
||||
{
|
||||
ASSERT(m_outcome == Outcome::None);
|
||||
m_outcome = outcome;
|
||||
m_event_loop->quit(0);
|
||||
}
|
||||
|
||||
void GDragOperation::notify_accepted(Badge<GWindowServerConnection>)
|
||||
{
|
||||
ASSERT(s_current_drag_operation);
|
||||
s_current_drag_operation->done(Outcome::Accepted);
|
||||
}
|
||||
|
||||
void GDragOperation::notify_cancelled(Badge<GWindowServerConnection>)
|
||||
{
|
||||
ASSERT(s_current_drag_operation);
|
||||
s_current_drag_operation->done(Outcome::Cancelled);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue