Merge lp:~aacid/unity-2d/unity-2d_belongsToDifferentScreen_api into lp:unity-2d

Proposed by Albert Astals Cid
Status: Merged
Approved by: Michał Sawicz
Approved revision: 945
Merged at revision: 952
Proposed branch: lp:~aacid/unity-2d/unity-2d_belongsToDifferentScreen_api
Merge into: lp:unity-2d
Diff against target: 235 lines (+105/-2)
4 files modified
libunity-2d-private/src/application.cpp (+92/-2)
libunity-2d-private/src/application.h (+5/-0)
libunity-2d-private/src/launcheritem.cpp (+6/-0)
libunity-2d-private/src/launcheritem.h (+2/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/unity-2d_belongsToDifferentScreen_api
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
Review via email: mp+95366@code.launchpad.net

Description of the change

Add the belongsToDifferentScreen API to launcherItem and Application in particular

To post a comment you must log in.
945. By Albert Astals Cid

More verbose comment

Revision history for this message
Michał Sawicz (saviq) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/application.cpp'
2--- libunity-2d-private/src/application.cpp 2012-02-16 11:24:19 +0000
3+++ libunity-2d-private/src/application.cpp 2012-03-05 11:32:17 +0000
4@@ -35,8 +35,7 @@
5 #include "bamf-indicator.h"
6
7 #include "dbusmenuimporter.h"
8-
9-#include <X11/X.h>
10+#include "gobjectcallback.h"
11
12 #include <gio/gio.h>
13
14@@ -46,7 +45,9 @@
15
16 // Qt
17 #include <Qt>
18+#include <QApplication>
19 #include <QDebug>
20+#include <QDesktopWidget>
21 #include <QAction>
22 #include <QDBusInterface>
23 #include <QDBusReply>
24@@ -56,12 +57,16 @@
25 #include <QScopedPointer>
26 #include <QX11Info>
27
28+#include <X11/X.h>
29+
30 extern "C" {
31 #include <gdk/gdk.h>
32 #include <gdk/gdkx.h>
33 #include <libsn/sn.h>
34 }
35
36+GOBJECT_CALLBACK0(geometryChangedCB, "onWindowGeometryChanged")
37+
38 const char* SHORTCUT_NICK_PROPERTY = "nick";
39
40 Application::Application()
41@@ -78,6 +83,16 @@
42 m_launching_timer.setSingleShot(true);
43 m_launching_timer.setInterval(8000);
44 QObject::connect(&m_launching_timer, SIGNAL(timeout()), this, SLOT(onLaunchingTimeouted()));
45+
46+ // Accumulate geometry changes during 50 msec
47+ // This is done because geometry-changed happens VERY often and doing the calculation
48+ // all the time just drags down your CPU for no reason
49+ // Instead what we do is send the windowGeometryChanged 50 msec after a geometry-changed
50+ // ignoring the geometry-changed that happen in that period, so at most we do
51+ // the calculation each 50ms instead of every single pixel move
52+ m_geometryChangedTimer.setSingleShot(true);
53+ m_geometryChangedTimer.setInterval(50);
54+ connect(&m_geometryChangedTimer, SIGNAL(timeout()), this, SIGNAL(windowGeometryChanged()));
55 }
56
57 Application::Application(const Application& other)
58@@ -91,6 +106,7 @@
59
60 Application::~Application()
61 {
62+ disconnectWindowSignals();
63 }
64
65 bool
66@@ -526,6 +542,34 @@
67 WnckWindow* window = wnck_window_get(xids->at(i));
68 g_signal_connect(G_OBJECT(window), "workspace-changed",
69 G_CALLBACK(Application::onWindowWorkspaceChanged), this);
70+ g_signal_connect(G_OBJECT(window), "geometry-changed", G_CALLBACK(geometryChangedCB), this);
71+ }
72+}
73+
74+void
75+Application::disconnectWindowSignals()
76+{
77+ if (m_application == NULL || m_application->running() == false) {
78+ return;
79+ }
80+
81+ QScopedPointer<BamfUintList> xids(m_application->xids());
82+ int size = xids->size();
83+ if (size < 1) {
84+ return;
85+ }
86+
87+ for (int i = 0; i < size; ++i) {
88+ WnckWindow *window = wnck_window_get(xids->at(i));
89+ if (window == NULL) {
90+ wnck_screen_force_update(wnck_screen_get_default());
91+ window = wnck_window_get(xids->at(i));
92+ if (window == NULL) {
93+ continue;
94+ }
95+ }
96+
97+ g_signal_handlers_disconnect_by_func(window, gpointer(geometryChangedCB), this);
98 }
99 }
100
101@@ -537,6 +581,7 @@
102 WnckWindow* wnck_window = wnck_window_get(window->xid());
103 g_signal_connect(G_OBJECT(wnck_window), "workspace-changed",
104 G_CALLBACK(Application::onWindowWorkspaceChanged), this);
105+ g_signal_connect(G_OBJECT(wnck_window), "geometry-changed", G_CALLBACK(geometryChangedCB), this);
106 }
107 }
108
109@@ -986,6 +1031,44 @@
110 return false;
111 }
112
113+bool
114+Application::belongsToDifferentScreen(int screen)
115+{
116+ if (!m_application) {
117+ return false;
118+ }
119+
120+ if (QApplication::desktop()->screenCount() == 1) {
121+ return false;
122+ }
123+
124+ QScopedPointer<BamfUintList> xids(m_application->xids());
125+ for (int i = 0; i < xids->size(); i++) {
126+ /* When geting the wnck window, it's possible we get a NULL
127+ return value because wnck hasn't updated its internal list yet,
128+ so we need to force it once to be sure */
129+ WnckWindow *window = wnck_window_get(xids->at(i));
130+ if (window == NULL) {
131+ wnck_screen_force_update(wnck_screen_get_default());
132+ window = wnck_window_get(xids->at(i));
133+ if (window == NULL) {
134+ continue;
135+ }
136+ }
137+
138+ // Check the window screen
139+ int x, y, width, height;
140+ wnck_window_get_geometry(window, &x, &y, &width, &height);
141+ const QRect windowRect(x, y, width, height);
142+ const QPoint pos = windowRect.center();
143+ if (QApplication::desktop()->screenNumber(pos) == screen) {
144+ return false;
145+ }
146+ }
147+
148+ return true;
149+}
150+
151 void
152 Application::onIndicatorMenuUpdated()
153 {
154@@ -1110,6 +1193,13 @@
155 }
156
157 void
158+Application::onWindowGeometryChanged()
159+{
160+ if (!m_geometryChangedTimer.isActive())
161+ m_geometryChangedTimer.start();
162+}
163+
164+void
165 Application::onDragEnter(DeclarativeDragDropEvent* event)
166 {
167 QList<QUrl> urls = validateUrisForLaunch(event->mimeData());
168
169=== modified file 'libunity-2d-private/src/application.h'
170--- libunity-2d-private/src/application.h 2012-02-16 11:24:19 +0000
171+++ libunity-2d-private/src/application.h 2012-03-05 11:32:17 +0000
172@@ -105,7 +105,9 @@
173
174 Q_INVOKABLE virtual void createMenuActions();
175 Q_INVOKABLE virtual bool belongsToDifferentWorkspace();
176+ Q_INVOKABLE virtual bool belongsToDifferentScreen(int screen);
177 Q_INVOKABLE void connectWindowSignals();
178+ void disconnectWindowSignals();
179
180 void updateOverlaysState(const QString& sender, const QMap<QString, QVariant>& properties);
181
182@@ -151,6 +153,8 @@
183 void onDragEnter(DeclarativeDragDropEvent*);
184 void onDrop(DeclarativeDragDropEvent*);
185
186+ void onWindowGeometryChanged();
187+
188 private:
189 QPointer<BamfApplication> m_application;
190 QFileSystemWatcher *m_desktopFileWatcher;
191@@ -188,6 +192,7 @@
192 QDBusServiceWatcher* m_dynamicQuicklistServiceWatcher;
193 void setDynamicQuicklistImporter(const QString& service);
194 IndicatorDesktopShortcutsPointer m_staticShortcuts;
195+ QTimer m_geometryChangedTimer;
196 };
197
198 Q_DECLARE_METATYPE(Application*)
199
200=== modified file 'libunity-2d-private/src/launcheritem.cpp'
201--- libunity-2d-private/src/launcheritem.cpp 2012-02-06 12:07:47 +0000
202+++ libunity-2d-private/src/launcheritem.cpp 2012-03-05 11:32:17 +0000
203@@ -93,6 +93,12 @@
204 }
205
206 bool
207+LauncherItem::belongsToDifferentScreen(int)
208+{
209+ return false;
210+}
211+
212+bool
213 LauncherItem::progressBarVisible() const
214 {
215 return false;
216
217=== modified file 'libunity-2d-private/src/launcheritem.h'
218--- libunity-2d-private/src/launcheritem.h 2012-02-06 12:07:47 +0000
219+++ libunity-2d-private/src/launcheritem.h 2012-03-05 11:32:17 +0000
220@@ -80,6 +80,7 @@
221 Q_INVOKABLE virtual void createMenuActions() = 0;
222 Q_INVOKABLE virtual void launchNewInstance();
223 Q_INVOKABLE virtual bool belongsToDifferentWorkspace();
224+ Q_INVOKABLE virtual bool belongsToDifferentScreen(int screen);
225
226 protected:
227 LauncherContextualMenu* m_menu;
228@@ -102,6 +103,7 @@
229 void emblemVisibleChanged(bool);
230 void emblemChanged(QString);
231 void windowWorkspaceChanged();
232+ void windowGeometryChanged();
233
234 public Q_SLOTS:
235 /* Default implementation of drag’n’drop handling, should be overridden in

Subscribers

People subscribed via source and target branches