Merge lp:~shippo/plank/fix-1248689 into lp:~shippo/plank/test

Proposed by Peter Feichtinger
Status: Merged
Approved by: Peter Feichtinger
Approved revision: 1592
Merged at revision: 1593
Proposed branch: lp:~shippo/plank/fix-1248689
Merge into: lp:~shippo/plank/test
Diff against target: 284 lines (+127/-39)
4 files modified
lib/Items/ApplicationDockItem.vala (+43/-23)
lib/Items/DefaultApplicationDockItemProvider.vala (+4/-0)
lib/Services/WindowControl.vala (+79/-16)
lib/libplank.symbols (+1/-0)
To merge this branch: bzr merge lp:~shippo/plank/fix-1248689
Reviewer Review Type Date Requested Status
Peter Feichtinger Approve
Review via email: mp+319849@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Peter Feichtinger (shippo) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Items/ApplicationDockItem.vala'
2--- lib/Items/ApplicationDockItem.vala 2017-02-09 12:53:29 +0000
3+++ lib/Items/ApplicationDockItem.vala 2017-03-14 17:22:36 +0000
4@@ -276,27 +276,45 @@
5 app_window_removed ();
6 }
7
8- void update_indicator ()
9+ public void update_indicator ()
10 {
11- //FIXME Do not be silly if the application is running
12- // we must indicate it, same goes for the opposite.
13-
14- var is_running = is_running ();
15-
16- if (!is_running) {
17+ switch (get_window_count ()) {
18+ case 0:
19 if (Indicator != IndicatorState.NONE)
20 Indicator = IndicatorState.NONE;
21- return;
22- }
23-
24- var window_count = App.get_windows ().length ();
25-
26- if (window_count <= 1) {
27+ break;
28+ case 1:
29 if (Indicator != IndicatorState.SINGLE)
30 Indicator = IndicatorState.SINGLE;
31- } else {
32+ break;
33+ default:
34 if (Indicator != IndicatorState.SINGLE_PLUS)
35 Indicator = IndicatorState.SINGLE_PLUS;
36+ break;
37+ }
38+ }
39+
40+ uint get_window_count () {
41+ if (App == null)
42+ return 0;
43+
44+ if (get_dock ().prefs.CurrentWorkspaceOnly) {
45+ unowned Wnck.Workspace? active_workspace = Wnck.Screen.get_default ().get_active_workspace ();
46+ return WindowControl.count_windows_on_workspace (App, active_workspace);
47+ } else {
48+ return App.get_windows ().length ();
49+ }
50+ }
51+
52+ GLib.List<unowned Bamf.View>? get_windows () {
53+ if (App == null)
54+ return null;
55+
56+ if (get_dock ().prefs.CurrentWorkspaceOnly) {
57+ unowned Wnck.Workspace? active_workspace = Wnck.Screen.get_default ().get_active_workspace ();
58+ return WindowControl.get_windows_on_workspace (App, active_workspace);
59+ } else {
60+ return App.get_windows ();
61 }
62 }
63
64@@ -321,13 +339,13 @@
65 {
66 if (!is_window ())
67 if (button == PopupButton.MIDDLE
68- || (button == PopupButton.LEFT && (App == null || App.get_windows ().length () == 0
69- || (mod & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK))) {
70+ || (button == PopupButton.LEFT && (get_window_count () == 0
71+ || (mod & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK))) {
72 launch ();
73 return AnimationType.BOUNCE;
74 }
75
76- if (button == PopupButton.LEFT && App != null && App.get_windows ().length () > 0) {
77+ if (button == PopupButton.LEFT && get_window_count () > 0) {
78 WindowControl.smart_focus (App, event_time);
79 return AnimationType.DARKEN;
80 }
81@@ -340,7 +358,7 @@
82 */
83 protected override AnimationType on_scrolled (Gdk.ScrollDirection direction, Gdk.ModifierType mod, uint32 event_time)
84 {
85- if (App == null || App.get_windows ().length () == 0)
86+ if (get_window_count () == 0)
87 return AnimationType.NONE;
88
89 if (GLib.get_monotonic_time () - LastScrolled < ITEM_SCROLL_DURATION * 1000)
90@@ -348,10 +366,14 @@
91
92 LastScrolled = GLib.get_monotonic_time ();
93
94+ unowned Wnck.Workspace? active_workspace = null;
95+ if (get_dock ().prefs.CurrentWorkspaceOnly)
96+ active_workspace = Wnck.Screen.get_default ().get_active_workspace ();
97+
98 if (direction == Gdk.ScrollDirection.UP || direction == Gdk.ScrollDirection.LEFT)
99- WindowControl.focus_previous (App, event_time);
100+ WindowControl.focus_previous (App, event_time, active_workspace);
101 else
102- WindowControl.focus_next (App, event_time);
103+ WindowControl.focus_next (App, event_time, active_workspace);
104
105 return AnimationType.DARKEN;
106 }
107@@ -397,9 +419,7 @@
108 {
109 var items = new Gee.ArrayList<Gtk.MenuItem> ();
110
111- GLib.List<unowned Bamf.View>? windows = null;
112- if (App != null)
113- windows = App.get_windows ();
114+ GLib.List<unowned Bamf.View>? windows = get_windows ();
115
116 var window_count = 0U;
117 if (windows != null)
118
119=== modified file 'lib/Items/DefaultApplicationDockItemProvider.vala'
120--- lib/Items/DefaultApplicationDockItemProvider.vala 2016-02-22 10:55:51 +0000
121+++ lib/Items/DefaultApplicationDockItemProvider.vala 2017-03-14 17:22:36 +0000
122@@ -68,6 +68,10 @@
123 unowned TransientDockItem? transient = (item as TransientDockItem);
124 item.IsAttached = (transient == null || transient.App == null || active_workspace == null
125 || WindowControl.has_window_on_workspace (transient.App, active_workspace));
126+
127+ unowned ApplicationDockItem? app = (item as ApplicationDockItem);
128+ if (item.IsAttached && app != null)
129+ app.update_indicator ();
130 }
131 } else {
132 foreach (var item in internal_elements)
133
134=== modified file 'lib/Services/WindowControl.vala'
135--- lib/Services/WindowControl.vala 2016-11-05 19:48:09 +0000
136+++ lib/Services/WindowControl.vala 2017-03-14 17:22:36 +0000
137@@ -171,6 +171,20 @@
138 return false;
139 }
140
141+ static bool is_on_workspace (Wnck.Window? window, Wnck.Workspace workspace) {
142+ if (window == null)
143+ return false;
144+
145+ var is_virtual = workspace.is_virtual ();
146+
147+ if (!is_virtual && window.is_on_workspace (workspace))
148+ return true;
149+ else if (is_virtual && window.is_in_viewport (workspace))
150+ return true;
151+
152+ return false;
153+ }
154+
155 public static bool has_window_on_workspace (Bamf.Application app, Wnck.Workspace workspace)
156 {
157 Wnck.Screen.get_default ();
158@@ -178,23 +192,48 @@
159
160 warn_if_fail (xids != null);
161
162- var is_virtual = workspace.is_virtual ();
163-
164- for (var i = 0; xids != null && i < xids.length; i++) {
165- unowned Wnck.Window window = Wnck.Window.@get (xids.index (i));
166- if (window == null)
167- continue;
168-
169- if (!is_virtual) {
170- if (window.is_on_workspace (workspace))
171- return true;
172- } else {
173- if (window.is_in_viewport (workspace))
174- return true;
175+ for (var i = 0; xids != null && i < xids.length; i++) {
176+ unowned Wnck.Window window = Wnck.Window.@get (xids.index (i));
177+ if (is_on_workspace (window, workspace))
178+ return true;
179+ }
180+
181+ return false;
182+ }
183+
184+ public static int count_windows_on_workspace (Bamf.Application app, Wnck.Workspace workspace)
185+ {
186+ Wnck.Screen.get_default ();
187+ Array<uint32>? xids = app.get_xids ();
188+
189+ warn_if_fail (xids != null);
190+
191+ int count = 0;
192+
193+ for (var i = 0; xids != null && i < xids.length; i++) {
194+ unowned Wnck.Window window = Wnck.Window.@get (xids.index (i));
195+ if (is_on_workspace (window, workspace))
196+ count++;
197+ }
198+
199+ return count;
200+ }
201+
202+ public static GLib.List<unowned Bamf.View> get_windows_on_workspace (Bamf.Application app, Wnck.Workspace workspace)
203+ {
204+ Wnck.Screen.get_default ();
205+ GLib.List<unowned Bamf.View> windows = app.get_windows ();
206+
207+ var result = new GLib.List<unowned Bamf.View> ();
208+ foreach (var view in windows) {
209+ if (view is Bamf.Window) {
210+ unowned Wnck.Window window = Wnck.Window.@get ((view as Bamf.Window).get_xid ());
211+ if (is_on_workspace (window, workspace))
212+ result.append (view);
213 }
214 }
215
216- return false;
217+ return result;
218 }
219
220 public static void update_icon_regions (Bamf.Application app, Gdk.Rectangle rect)
221@@ -262,7 +301,7 @@
222 return i;
223 }
224
225- public static void focus_previous (Bamf.Application app, uint32 event_time)
226+ public static void focus_previous (Bamf.Application app, uint32 event_time, Wnck.Workspace? workspace = null)
227 {
228 Wnck.Screen.get_default ();
229 Array<uint32>? xids = app.get_xids ();
230@@ -278,10 +317,22 @@
231 if (i < 0)
232 i = (int) xids.length - 1;
233
234+ // Look for window on workspace if specified
235+ if (workspace != null) {
236+ var start = i;
237+ do {
238+ unowned Wnck.Window window = Wnck.Window.@get (xids.index (i));
239+ if (is_on_workspace (window, workspace))
240+ break;
241+
242+ i = (i == 0 ? (int) xids.length - 1 : i - 1);
243+ } while (i != start);
244+ }
245+
246 focus_window_by_xid (xids.index (i), event_time);
247 }
248
249- public static void focus_next (Bamf.Application app, uint32 event_time)
250+ public static void focus_next (Bamf.Application app, uint32 event_time, Wnck.Workspace? workspace = null)
251 {
252 Wnck.Screen.get_default ();
253 Array<uint32>? xids = app.get_xids ();
254@@ -297,6 +348,18 @@
255 if (i == xids.length)
256 i = 0;
257
258+ // Look for window on workspace if specified
259+ if (workspace != null) {
260+ var start = i;
261+ do {
262+ unowned Wnck.Window window = Wnck.Window.@get (xids.index (i));
263+ if (is_on_workspace (window, workspace))
264+ break;
265+
266+ i = (i + 1) % (int) xids.length;
267+ } while (i != start);
268+ }
269+
270 focus_window_by_xid (xids.index (i), event_time);
271 }
272
273
274=== modified file 'lib/libplank.symbols'
275--- lib/libplank.symbols 2017-02-09 12:53:29 +0000
276+++ lib/libplank.symbols 2017-03-14 17:22:36 +0000
277@@ -57,6 +57,7 @@
278 plank_application_dock_item_set_urgent
279 plank_application_dock_item_unity_reset
280 plank_application_dock_item_unity_update
281+plank_application_dock_item_update_indicator
282 plank_check_version
283 plank_color_add_hue
284 plank_color_brighten_val

Subscribers

People subscribed via source and target branches

to all changes: