summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qclipboard_x11.cpp
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-09-15 17:46:01 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-09-16 08:50:25 (GMT)
commitf5c2e6374b9f6c39a2e535f7282c7d7160591ba6 (patch)
tree6a1eb38c59b5901281a69954724aa462e206b390 /src/gui/kernel/qclipboard_x11.cpp
parentb8ff02a67ebd8246253823b53cfed98eef400547 (diff)
downloadQt-f5c2e6374b9f6c39a2e535f7282c7d7160591ba6.zip
Qt-f5c2e6374b9f6c39a2e535f7282c7d7160591ba6.tar.gz
Qt-f5c2e6374b9f6c39a2e535f7282c7d7160591ba6.tar.bz2
Implemented the SAVE_TARGET in QClipboard on X11
Added support for the simpliest SAVE_TARGET mechanizm allowing us to work nicely with clipboard managers, so that when Qt application that owns the clipboard exits we delegate the content to the clipboard manager if there is one. The current implementation doesn't specify which targets to give to the manager, so it will try to fetch as much as possible. Also, right now we do not support the TARGET_SIZES target, meaning that the manager doesn't know how much data it is going to fetch, so it will try to fetch everything even if it can take a lot of time. Reviewed-by: Bradley T. Hughes
Diffstat (limited to 'src/gui/kernel/qclipboard_x11.cpp')
-rw-r--r--src/gui/kernel/qclipboard_x11.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/gui/kernel/qclipboard_x11.cpp b/src/gui/kernel/qclipboard_x11.cpp
index b2f682b..5495bfe 100644
--- a/src/gui/kernel/qclipboard_x11.cpp
+++ b/src/gui/kernel/qclipboard_x11.cpp
@@ -787,6 +787,7 @@ static Atom send_targets_selection(QClipboardData *d, Window window, Atom proper
types.append(ATOM(TARGETS));
types.append(ATOM(MULTIPLE));
types.append(ATOM(TIMESTAMP));
+ types.append(ATOM(SAVE_TARGETS));
XChangeProperty(X11->display, window, property, XA_ATOM, 32,
PropModeReplace, (uchar *) types.data(), types.size());
@@ -911,8 +912,30 @@ bool QClipboard::event(QEvent *e)
XEvent *xevent = (XEvent *)(((QClipboardEvent *)e)->data());
Display *dpy = X11->display;
- if (!xevent)
+ if (!xevent) {
+ // That means application exits and we need to give clipboard
+ // content to the clipboard manager.
+ // First we check if there is a clipboard manager.
+ if (XGetSelectionOwner(X11->display, ATOM(CLIPBOARD_MANAGER)) == XNone)
+ return true;
+
+ Window ownerId = owner->internalWinId();
+ Q_ASSERT(ownerId);
+ // we delete the property so the manager saves all TARGETS.
+ XDeleteProperty(X11->display, ownerId, ATOM(_QT_SELECTION));
+ XConvertSelection(X11->display, ATOM(CLIPBOARD_MANAGER), ATOM(SAVE_TARGETS),
+ ATOM(_QT_SELECTION), ownerId, X11->time);
+ XSync(dpy, false);
+
+ XEvent event;
+ // waiting until the clipboard manager fetches the content.
+ if (!X11->clipboardWaitForEvent(ownerId, SelectionNotify, &event, 10000)) {
+ qWarning("QClipboard: Unable to receive an event from the "
+ "clipboard manager in a reasonable time");
+ }
+
return true;
+ }
switch (xevent->type) {