Merge lp:~townsend/libertine/fix-pasted-xmir-rootless into lp:libertine

Proposed by Christopher Townsend
Status: Merged
Approved by: Larry Price
Approved revision: 441
Merged at revision: 444
Proposed branch: lp:~townsend/libertine/fix-pasted-xmir-rootless
Merge into: lp:libertine
Diff against target: 248 lines (+90/-53)
2 files modified
pasted/pasted.cpp (+77/-48)
pasted/pasted.h (+13/-5)
To merge this branch: bzr merge lp:~townsend/libertine/fix-pasted-xmir-rootless
Reviewer Review Type Date Requested Status
Libertine CI Bot continuous-integration Approve
Larry Price Approve
Review via email: mp+319507@code.launchpad.net

Commit message

Fix pasted to work with rootless Xmir.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:434
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/461/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/850
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/700
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/700
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/700
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/700
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/860
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/852
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/852/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/852
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/852/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/852
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/852/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/852
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/852/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/461/rebuild

review: Approve (continuous-integration)
Revision history for this message
Larry Price (larryprice) wrote :

left some inline presents for you

review: Needs Information
435. By Christopher Townsend

Some cleanup based on review.

436. By Christopher Townsend

Merge lp:libertine.

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:436
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/462/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/851
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/701
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/701
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/701
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/701
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/861
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/853
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/853/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/853
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/853/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/853
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/853/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/853
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/853/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/462/rebuild

review: Approve (continuous-integration)
437. By Christopher Townsend

Another bit of cleanup.

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:437
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/463/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/852
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/702
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/702
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/702
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/702
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/862
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/854
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/854/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/854
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/854/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/854
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/854/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/854
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/854/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/463/rebuild

review: Approve (continuous-integration)
Revision history for this message
Larry Price (larryprice) wrote :

Whoops, guess I'm going to leave this open until ChrisTownsend returns...

This works for internal copy/paste, but does not work between apps. Is that expected for now and can you link the relevant bugs to this one when you get back?

review: Needs Information
438. By Christopher Townsend

Merge lp:libertine.

439. By Christopher Townsend

Merge lp:libertine.

440. By Christopher Townsend

Revert libertine.pot.

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:440
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/479/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/872
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/721
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/721
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/721
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/721
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/882
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/874
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/874/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/874
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/874/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/874
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/874/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/874
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/874/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/479/rebuild

review: Approve (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:439
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/480/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/873
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/722
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/722
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/722
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/722
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/883
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/875
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/875/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/875
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/875/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/875
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/875/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/875
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/875/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/480/rebuild

review: Approve (continuous-integration)
441. By Christopher Townsend

Add closing the disaply in the XEventWorker dtor.

Revision history for this message
Larry Price (larryprice) wrote :

lgtm

review: Approve
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:441
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/483/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/876
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/723
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/723
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/723
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/723
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/886
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/878
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/878/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/878
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/878/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/878
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/878/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/878
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/878/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/483/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pasted/pasted.cpp'
--- pasted/pasted.cpp 2017-03-20 19:22:25 +0000
+++ pasted/pasted.cpp 2017-03-20 20:42:05 +0000
@@ -36,9 +36,8 @@
36constexpr auto UNITY_FOCUSINFO_METHOD = "isSurfaceFocused";36constexpr auto UNITY_FOCUSINFO_METHOD = "isSurfaceFocused";
3737
3838
39static QString getPersistentSurfaceId()39static QString getPersistentSurfaceId(Display *dpy, const Window& id)
40{40{
41 Display *dpy = XOpenDisplay(NULL);
42 Atom prop = XInternAtom(dpy, MIR_WM_PERSISTENT_ID, 0),41 Atom prop = XInternAtom(dpy, MIR_WM_PERSISTENT_ID, 0),
43 type; // unused42 type; // unused
44 int form, // unused43 int form, // unused
@@ -48,7 +47,7 @@
48 unsigned char *data = nullptr;47 unsigned char *data = nullptr;
49 QString persistentSurfaceId;48 QString persistentSurfaceId;
5049
51 status = XGetWindowProperty(dpy, XDefaultRootWindow(dpy), prop, 0, 1024, 0,50 status = XGetWindowProperty(dpy, id, prop, 0, 1024, 0,
52 XA_STRING, &type, &form, &len, &remain, &data);51 XA_STRING, &type, &form, &len, &remain, &data);
5352
54 if (status)53 if (status)
@@ -60,14 +59,13 @@
60 persistentSurfaceId = (const char *)data;59 persistentSurfaceId = (const char *)data;
61 }60 }
6261
63 XCloseDisplay(dpy);
64 XFree(data);62 XFree(data);
6563
66 return persistentSurfaceId;64 return persistentSurfaceId;
67}65}
6866
6967
70void checkXServer()68Display *checkXServer()
71{69{
72 char *display = getenv("DISPLAY");70 char *display = getenv("DISPLAY");
7371
@@ -84,55 +82,86 @@
84 exit(-1);82 exit(-1);
85 }83 }
8684
87 XCloseDisplay(dpy);85 return dpy;
88
89 return;
90}86}
9187
92} //anonymous namespace88} //anonymous namespace
9389
9490
91XEventWorker::
92XEventWorker(Display *dpy)
93: dpy_(dpy)
94{
95 unityFocus_ = new QDBusInterface(UNITY_FOCUSINFO_SERVICE,
96 UNITY_FOCUSINFO_PATH,
97 UNITY_FOCUSINFO_INTERFACE,
98 QDBusConnection::sessionBus(),
99 this);
100}
101
102
103XEventWorker::
104~XEventWorker()
105{
106 XCloseDisplay(dpy_);
107}
108
109
110bool XEventWorker::
111isSurfaceFocused(const Window& focus_window)
112{
113 surfaceId_ = getPersistentSurfaceId(dpy_, focus_window);
114
115 QDBusReply<bool> isFocused = unityFocus_->call(UNITY_FOCUSINFO_METHOD, surfaceId_);
116
117 return isFocused;
118}
119
120
95void XEventWorker::121void XEventWorker::
96checkForAppFocus()122checkForAppFocus()
97{123{
98 bool hasFocus = false;124 bool hasFocus = false;
125 int focus_state;
126 Window focus_window;
127
128 XGetInputFocus(dpy_, &focus_window, &focus_state);
129
130 if (focus_window > PointerRoot)
131 {
132 if (isSurfaceFocused(focus_window))
133 {
134 focusChanged(surfaceId_);
135 hasFocus = true;
136 }
137 }
138
139 XSelectInput(dpy_, XDefaultRootWindow(dpy_), FocusChangeMask);
140
141 bool focused = false;
99 XEvent event;142 XEvent event;
100143
101 QDBusInterface *unityFocus = new QDBusInterface(UNITY_FOCUSINFO_SERVICE,
102 UNITY_FOCUSINFO_PATH,
103 UNITY_FOCUSINFO_INTERFACE,
104 QDBusConnection::sessionBus(),
105 this);
106
107 QString surfaceId = getPersistentSurfaceId();
108
109 QDBusReply<bool> isFocused = unityFocus->call(UNITY_FOCUSINFO_METHOD, surfaceId);
110
111 if (isFocused == true)
112 {
113 focusChanged();
114 hasFocus = true;
115 }
116
117 Display *dpy = XOpenDisplay(NULL);
118 XSelectInput(dpy, XDefaultRootWindow(dpy), FocusChangeMask);
119
120 while (1)144 while (1)
121 {145 {
122 XNextEvent(dpy, &event);146 XNextEvent(dpy_, &event);
123147
124 isFocused = unityFocus->call(UNITY_FOCUSINFO_METHOD, surfaceId);148 XGetInputFocus(dpy_, &focus_window, &focus_state);
125149
126 if (hasFocus == false && isFocused == true)150 if (focus_window > PointerRoot)
127 {151 {
128 qDebug() << "Surface is focused";152 focused = isSurfaceFocused(focus_window);
129 focusChanged();153
130 hasFocus = true;154 if (hasFocus == false && focused == true)
131 }155 {
132 else if (hasFocus == true && isFocused == false)156 qDebug() << "Surface is focused";
133 {157 focusChanged(surfaceId_);
134 qDebug() << "Surface lost focus";158 hasFocus = true;
135 hasFocus = false;159 }
160 else if (hasFocus == true && focused == false)
161 {
162 qDebug() << "Surface lost focus";
163 hasFocus = false;
164 }
136 }165 }
137 }166 }
138}167}
@@ -253,19 +282,19 @@
253282
254283
255void Pasted::284void Pasted::
256setPersistentSurfaceId()285setPersistentSurfaceId(const QString& surfaceId)
257{286{
258 if (persistentSurfaceId_.isEmpty())287 if (persistentSurfaceId_ != surfaceId)
259 {288 {
260 persistentSurfaceId_ = getPersistentSurfaceId();289 persistentSurfaceId_ = surfaceId;
261 }290 }
262}291}
263292
264293
265void Pasted::294void Pasted::
266appFocused()295appFocused(const QString& surfaceId)
267{296{
268 setPersistentSurfaceId();297 setPersistentSurfaceId(surfaceId);
269 handleContentHubPasteboard();298 handleContentHubPasteboard();
270}299}
271300
@@ -275,12 +304,12 @@
275{304{
276 qSetMessagePattern(QString("%{appname}: %{message}"));305 qSetMessagePattern(QString("%{appname}: %{message}"));
277306
278 checkXServer();307 Display *dpy = checkXServer();
279308
280 Pasted pasted(argc, argv);309 Pasted pasted(argc, argv);
281310
282 QThread t;311 QThread t;
283 XEventWorker worker;312 XEventWorker worker(dpy);
284313
285 worker.moveToThread(&t);314 worker.moveToThread(&t);
286315
287316
=== modified file 'pasted/pasted.h'
--- pasted/pasted.h 2016-09-12 17:59:56 +0000
+++ pasted/pasted.h 2017-03-20 20:42:05 +0000
@@ -39,14 +39,22 @@
39 Q_OBJECT39 Q_OBJECT
4040
41 public:41 public:
42 XEventWorker() = default;42 XEventWorker(Display *dpy);
43 virtual ~XEventWorker() = default;43 virtual ~XEventWorker();
44
45 private:
46 bool isSurfaceFocused(const Window& focus_window);
4447
45 signals:48 signals:
46 void focusChanged();49 void focusChanged(const QString& surfaceId);
4750
48 public slots:51 public slots:
49 void checkForAppFocus();52 void checkForAppFocus();
53
54 private:
55 Display *dpy_;
56 QDBusInterface *unityFocus_;
57 QString surfaceId_;
50};58};
5159
5260
@@ -60,13 +68,13 @@
60 virtual ~Pasted() = default;68 virtual ~Pasted() = default;
6169
62 public slots:70 public slots:
63 void appFocused();71 void appFocused(const QString& surfaceId);
6472
65 private:73 private:
66 void updateLastMimeData(const QMimeData *source);74 void updateLastMimeData(const QMimeData *source);
67 void updateXMimeData(const QMimeData *source);75 void updateXMimeData(const QMimeData *source);
68 void handleContentHubPasteboard();76 void handleContentHubPasteboard();
69 void setPersistentSurfaceId();77 void setPersistentSurfaceId(const QString& surfaceId);
7078
71 static bool compareMimeData(const QMimeData *a, const QMimeData *b);79 static bool compareMimeData(const QMimeData *a, const QMimeData *b);
72 static void copyMimeData(QMimeData& target, const QMimeData *source);80 static void copyMimeData(QMimeData& target, const QMimeData *source);

Subscribers

People subscribed via source and target branches