Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually unset XdndProxy ("Stop deleting dragged items, browser panel, pretty please") #304

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions panel/browser-panel-internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class QCefWidgetInternal : public QCefWidget {

void Resize();

#ifdef __linux__
private:
bool needsDeleteXdndProxy = true;
void unsetToplevelXdndProxy();
#endif

public slots:
void Init();
};
72 changes: 72 additions & 0 deletions panel/browser-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,74 @@ void QCefWidgetInternal::closeBrowser()
}
}

#ifdef __linux__
static bool XWindowHasAtom(Display *display, Window w, Atom a)
{
Atom type;
int format;
unsigned long nItems;
unsigned long bytesAfter;
unsigned char *data = NULL;

if (XGetWindowProperty(display, w, a, 0, LONG_MAX, False,
AnyPropertyType, &type, &format, &nItems,
&bytesAfter, &data) != Success)
return false;

if (data)
XFree(data);

return type != None;
}

void QCefWidgetInternal::unsetToplevelXdndProxy()
{
if (!cefBrowser)
return;

CefWindowHandle browserHandle =
cefBrowser->GetHost()->GetWindowHandle();
Display *xDisplay = cef_get_xdisplay();
Window toplevel, root, parent, *children;
unsigned int nChildren;
bool found = false;

toplevel = browserHandle;

// Find the toplevel
Atom netWmPidAtom = XInternAtom(xDisplay, "_NET_WM_PID", False);
do {
if (XQueryTree(xDisplay, toplevel, &root, &parent, &children,
&nChildren) == 0)
return;
jp9000 marked this conversation as resolved.
Show resolved Hide resolved

if (children)
XFree(children);

if (root == parent ||
!XWindowHasAtom(xDisplay, parent, netWmPidAtom)) {
found = true;
break;
}
toplevel = parent;
} while (true);

if (!found)
return;

// Check if the XdndProxy property is set
Atom xDndProxyAtom = XInternAtom(xDisplay, "XdndProxy", False);
if (needsDeleteXdndProxy &&
!XWindowHasAtom(xDisplay, toplevel, xDndProxyAtom)) {
QueueCEFTask([this]() { unsetToplevelXdndProxy(); });
return;
}

XDeleteProperty(xDisplay, toplevel, xDndProxyAtom);
needsDeleteXdndProxy = false;
}
#endif

void QCefWidgetInternal::Init()
{
#ifndef __APPLE__
Expand Down Expand Up @@ -281,6 +349,10 @@ void QCefWidgetInternal::Init()
CefRefPtr<CefDictionaryValue>(),
#endif
rqc);

#ifdef __linux__
QueueCEFTask([this]() { unsetToplevelXdndProxy(); });
#endif
});

if (success) {
Expand Down