Merge lp:~gerboland/unity-2d/keymonitor-shutdown-fixes into lp:unity-2d

Proposed by Gerry Boland
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 770
Merged at revision: 792
Proposed branch: lp:~gerboland/unity-2d/keymonitor-shutdown-fixes
Merge into: lp:unity-2d
Diff against target: 108 lines (+22/-11)
2 files modified
libunity-2d-private/src/keymonitor.cpp (+17/-7)
libunity-2d-private/src/keymonitor.h (+5/-4)
To merge this branch: bzr merge lp:~gerboland/unity-2d/keymonitor-shutdown-fixes
Reviewer Review Type Date Requested Status
Olivier Tilloy (community) Approve
Michał Sawicz Pending
Review via email: mp+80722@code.launchpad.net

Description of the change

Rewrite KeyMonitor XEvent handler to use QSocketNotifier instead of separate thread. This singleton will now be deconstructed properly on application quit. Also free X11 objects when they're unnecessary.

To post a comment you must log in.
Revision history for this message
Alberto Mardegan (mardy) wrote :

I tested this, but I don't see an improvement on session logout time.

Revision history for this message
Gerry Boland (gerboland) wrote :

No unfortunately it doesn't help with logout-time, I suspect the communication between gnome-session and Launcher at logout is incomplete.

But without this patch QCoreApplication::quit() does not quit the Launcher as the QtConcurrent thread does not halt. So this is a step in right direction, as otherwise the process needs to be killed.

This also keeps code consistency with GEIS gesture handler.

Revision history for this message
Olivier Tilloy (osomon) wrote :

The code looks good and clean, and it fixes the unit test that was hanging.

I have a tiny remark style-wise, which you may safely ignore if you feel like it: the x11FileDescriptor variable is referred to only once, so you can remove it and invoke directly ConnectionNumber(m_display) when instantiating the QSocketNotifier. Other than that, it all looks perfect to me.

As to bug #859596 I can’t really tell whether that fixes it, but it should considering comment #8.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libunity-2d-private/src/keymonitor.cpp'
--- libunity-2d-private/src/keymonitor.cpp 2011-09-23 12:45:33 +0000
+++ libunity-2d-private/src/keymonitor.cpp 2011-10-28 22:27:24 +0000
@@ -21,7 +21,7 @@
21#include "keymonitor.h"21#include "keymonitor.h"
2222
23// Qt23// Qt
24#include <QtConcurrentRun>24#include <QSocketNotifier>
25#include <QDebug>25#include <QDebug>
2626
27// X1127// X11
@@ -38,19 +38,17 @@
3838
3939
40KeyMonitor::KeyMonitor(QObject* parent)40KeyMonitor::KeyMonitor(QObject* parent)
41: QObject(parent), m_stop(false)41: QObject(parent)
42{42{
43 if (this->registerEvents()) {43 if (this->registerEvents()) {
44 getModifiers();44 getModifiers();
45 m_future = QtConcurrent::run(this, &KeyMonitor::run);
46 }45 }
47}46}
4847
49KeyMonitor::~KeyMonitor()48KeyMonitor::~KeyMonitor()
50{49{
51 /* let the running thread know that it should stop */
52 m_stop = true;
53 m_eventList.clear();50 m_eventList.clear();
51 XCloseDisplay(m_display);
54}52}
5553
56KeyMonitor* KeyMonitor::instance()54KeyMonitor* KeyMonitor::instance()
@@ -74,6 +72,8 @@
74 m_modList.append(xmodmap->modifiermap[i]);72 m_modList.append(xmodmap->modifiermap[i]);
75 }73 }
76 }74 }
75
76 XFreeModifiermap(xmodmap);
77}77}
7878
79bool KeyMonitor::registerEvents()79bool KeyMonitor::registerEvents()
@@ -82,6 +82,7 @@
82 Window window;82 Window window;
8383
84 XDeviceInfo *devices;84 XDeviceInfo *devices;
85 int x11FileDescriptor;
85 int num_devices;86 int num_devices;
86 int i, j;87 int i, j;
8788
@@ -116,8 +117,11 @@
116 }117 }
117 }118 }
118 }119 }
120 XCloseDevice(m_display, device);
119 }121 }
120122
123 XFreeDeviceList(devices);
124
121 if (m_eventList.size() == 0) {125 if (m_eventList.size() == 0) {
122 UQ_WARNING << "No input devices found.";126 UQ_WARNING << "No input devices found.";
123 return false;127 return false;
@@ -128,15 +132,21 @@
128 return false;132 return false;
129 }133 }
130134
135 /* Dispatch XEvents when there is activity on the X11 file descriptor */
136 x11FileDescriptor = ConnectionNumber(m_display);
137 QSocketNotifier* socketNotifier = new QSocketNotifier(x11FileDescriptor, QSocketNotifier::Read, this);
138 connect(socketNotifier, SIGNAL(activated(int)), this, SLOT(x11EventDispatch()));
139
131 return true;140 return true;
132}141}
133142
134143
135void KeyMonitor::run()144void KeyMonitor::x11EventDispatch()
136{145{
137 XEvent event;146 XEvent event;
138147
139 while(!m_stop && !XNextEvent(m_display, &event)) {148 while (XPending(m_display) > 0) {
149 XNextEvent(m_display, &event);
140 if (event.type == key_press_type) {150 if (event.type == key_press_type) {
141 XDeviceKeyEvent *keyEvent = (XDeviceKeyEvent *) &event;151 XDeviceKeyEvent *keyEvent = (XDeviceKeyEvent *) &event;
142 if (!m_modList.contains((KeyCode) keyEvent->keycode)) {152 if (!m_modList.contains((KeyCode) keyEvent->keycode)) {
143153
=== modified file 'libunity-2d-private/src/keymonitor.h'
--- libunity-2d-private/src/keymonitor.h 2011-09-19 19:06:54 +0000
+++ libunity-2d-private/src/keymonitor.h 2011-10-28 22:27:24 +0000
@@ -51,11 +51,12 @@
5151
52 void getModifiers();52 void getModifiers();
53 bool registerEvents();53 bool registerEvents();
54 void run();54
5555private Q_SLOTS:
56 void x11EventDispatch();
57
58private:
56 Display *m_display;59 Display *m_display;
57 QFuture<void> m_future;
58 bool m_stop;
59 QVector<XEventClass> m_eventList;60 QVector<XEventClass> m_eventList;
60 QVector<KeyCode> m_modList;61 QVector<KeyCode> m_modList;
61};62};

Subscribers

People subscribed via source and target branches