Merge lp:~kbailey4444/wingpanel/dodge-maximize into lp:~elementary-pantheon/wingpanel/trunk-0.3.x

Proposed by Keith Bailey
Status: Rejected
Rejected by: xapantu
Proposed branch: lp:~kbailey4444/wingpanel/dodge-maximize
Merge into: lp:~elementary-pantheon/wingpanel/trunk-0.3.x
Diff against target: 372 lines (+242/-9)
4 files modified
org.pantheon.desktop.wingpanel.gschema.xml (+15/-0)
src/Services/Settings.vala (+3/-0)
src/Widgets/BasePanel.vala (+208/-8)
src/Widgets/Panel.vala (+16/-1)
To merge this branch: bzr merge lp:~kbailey4444/wingpanel/dodge-maximize
Reviewer Review Type Date Requested Status
elementary Pantheon team Pending
Review via email: mp+262278@code.launchpad.net

Description of the change

Closes Bug #1079575 . Gives wingpanel the option to behave like plank's "Hide when focused window is maximized" mode. The panel will hide if the active window is maximized. The panel will show when the mouse hovers over the top of the screen. Here is a video of it in action. https://www.youtube.com/watch?v=Y08u_bcJL-U

To post a comment you must log in.
Revision history for this message
Keith Bailey (kbailey4444) wrote :

When might this be reviewed? I understand you've probably been busy with other code.

Revision history for this message
xapantu (xapantu) wrote :

Hi,

Unfortunately most development happens in this branch https://code.launchpad.net/~wingpanel-devs/wingpanel/wingpanel-rewrite-x11 (which is a rewrite of the existing wingpanel featuring new-from-scratch indicators)

So, while your code actually looks good, we are not going to merge it because it targets a branch which is not developped anymore. We don't want to do it because it would require too many efforts and will probably never be released.

Please check out the daily ppa (unstable, of course, be warned) if you want to implement it there ;)

Revision history for this message
Keith Bailey (kbailey4444) wrote :

Ok, thanks. I'll look into implementing it there.

On Mon, Sep 7, 2015 at 1:57 PM, xapantu <email address hidden> wrote:

> The proposal to merge lp:~kbailey4444/wingpanel/dodge-maximize into
> lp:wingpanel has been updated.
>
> Status: Needs review => Rejected
>
> For more details, see:
>
> https://code.launchpad.net/~kbailey4444/wingpanel/dodge-maximize/+merge/262278
> --
> You are the owner of lp:~kbailey4444/wingpanel/dodge-maximize.
>

Unmerged revisions

224. By Keith Bailey

fixed hover delays not updating.

223. By Keith Bailey

Now shows on hover like plank. Has show and hide delay settings for when the mouse enters or leaves.

222. By Keith Bailey

The panel now hides when the active window is maximized. Does not show when hovered like plank does.

221. By Keith Bailey

Added dodge maximize to settings and gschema

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'org.pantheon.desktop.wingpanel.gschema.xml'
--- org.pantheon.desktop.wingpanel.gschema.xml 2014-07-24 16:03:50 +0000
+++ org.pantheon.desktop.wingpanel.gschema.xml 2015-06-17 22:29:30 +0000
@@ -25,5 +25,20 @@
25 <summary>Automatically update background alpha.</summary>25 <summary>Automatically update background alpha.</summary>
26 <description>Automatically update the background alpha to zero if it will be readable, else 0.8.</description>26 <description>Automatically update the background alpha to zero if it will be readable, else 0.8.</description>
27 </key>27 </key>
28 <key type="b" name="dodge-maximized">
29 <default>false</default>
30 <summary>Whether to hide the panel when there is an active maximized window.</summary>
31 <description>Whether to hide the panel when there is an active maximized window.</description>
32 </key>
33 <key type="i" name="hover-show-delay">
34 <default>500</default>
35 <summary>The number of milliseconds after mouse enter to show the panel.</summary>
36 <description>The number of milliseconds after mouse enter to show the panel. Only relevant if dodge-maximized is enabled. If the mouse is not inside the panel after the delay, the panel will not be shown.</description>
37 </key>
38 <key type="i" name="hover-hide-delay">
39 <default>500</default>
40 <summary>The number of milliseconds after mouse leave to hide the panel.</summary>
41 <description>The number of milliseconds after mouse leave to hide the panel. Only relevant if dodge-maximized is enabled. If the mouse is not outside the panel after the delay, the panel will not be hidden.</description>
42 </key>
28 </schema>43 </schema>
29</schemalist>44</schemalist>
3045
=== modified file 'src/Services/Settings.vala'
--- src/Services/Settings.vala 2014-07-24 16:03:50 +0000
+++ src/Services/Settings.vala 2015-06-17 22:29:30 +0000
@@ -25,6 +25,9 @@
25 public string default_launcher { get; set; }25 public string default_launcher { get; set; }
26 public double background_alpha { get; set; }26 public double background_alpha { get; set; }
27 public bool auto_adjust_alpha { get; set; }27 public bool auto_adjust_alpha { get; set; }
28 public bool dodge_maximized {get; set; }
29 public int hover_show_delay {get; set; }
30 public int hover_hide_delay {get; set; }
2831
29 public Settings () {32 public Settings () {
30 base ("org.pantheon.desktop.wingpanel");33 base ("org.pantheon.desktop.wingpanel");
3134
=== modified file 'src/Widgets/BasePanel.vala'
--- src/Widgets/BasePanel.vala 2015-01-15 10:45:40 +0000
+++ src/Widgets/BasePanel.vala 2015-06-17 22:29:30 +0000
@@ -43,7 +43,6 @@
43 private int panel_width;43 private int panel_width;
44 private int panel_displacement = -40;44 private int panel_displacement = -40;
45 private int monitor_num;45 private int monitor_num;
46 private uint animation_timer = 0;
4746
48 private double legible_alpha_value = -1.0;47 private double legible_alpha_value = -1.0;
49 private double panel_alpha = 0.0;48 private double panel_alpha = 0.0;
@@ -52,6 +51,11 @@
52 private int fade_duration;51 private int fade_duration;
53 private int64 start_time;52 private int64 start_time;
5453
54 private bool hiding = false;
55 private bool showing = false;
56 private bool first_run = true;
57 private bool struts_set = false;
58
55 private Settings? gala_settings = null;59 private Settings? gala_settings = null;
56 private enum Duration {60 private enum Duration {
57 DEFAULT,61 DEFAULT,
@@ -113,6 +117,11 @@
113 gala_settings.changed.connect (get_duration_values);117 gala_settings.changed.connect (get_duration_values);
114 }118 }
115119
120 wnck_screen.active_window_changed.connect (active_window_changed);
121 add_events(Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK);
122 enter_notify_event.connect(mouse_entered);
123 leave_notify_event.connect(mouse_left);
124
116 get_duration_values ();125 get_duration_values ();
117126
118 update_panel_alpha (Duration.DEFAULT);127 update_panel_alpha (Duration.DEFAULT);
@@ -166,6 +175,144 @@
166 }175 }
167 }176 }
168177
178 private void active_window_changed (Wnck.Window? prev_active_window) {
179 unowned Wnck.Window? active_window = wnck_screen.get_active_window();
180 if (settings.dodge_maximized)
181 update_visibility_active_change (active_window);
182
183 if (prev_active_window != null)
184 prev_active_window.state_changed.disconnect (active_window_state_changed);
185 if (active_window != null)
186 active_window.state_changed.connect (active_window_state_changed);
187 }
188
189 private void active_window_state_changed (Wnck.Window? window,
190 Wnck.WindowState changed_mask, Wnck.WindowState new_state) {
191 if (settings.dodge_maximized)
192 update_visibility_active_change (window);
193 }
194
195 private void update_visibility_active_change (Wnck.Window? active_window) {
196 if (should_hide_active_change (active_window)) {
197 disable_struts ();
198 start_hide ();
199 } else {
200 set_struts ();
201 start_show ();
202 }
203 }
204
205 private bool should_hide_active_change (Wnck.Window? active_window) {
206 unowned Wnck.Workspace active_workspace = wnck_screen.get_active_workspace ();
207
208 return ((active_window != null) && !active_window.is_minimized () && right_type (active_window)
209 && active_window.is_visible_on_workspace (active_workspace)
210 && (active_window.get_window_type () == Wnck.WindowType.DIALOG) ?
211 would_intersect_shown_panel (active_window) :
212 (in_panel_x_range (active_window) && is_maximized_at_all (active_window)));
213 }
214
215 private bool would_intersect_shown_panel (Wnck.Window? window) {
216 Gdk.Rectangle shown_panel_rect = Gdk.Rectangle ();
217 shown_panel_rect.x = panel_x;
218 shown_panel_rect.y = panel_y;
219 shown_panel_rect.width = panel_width;
220 shown_panel_rect.height = panel_height;
221
222 int xp, yp, widthp, heightp;
223 window.get_geometry (out xp, out yp, out widthp, out heightp);
224
225 Gdk.Rectangle window_rect = Gdk.Rectangle ();
226 window_rect.x = xp;
227 window_rect.width = widthp;
228 if (struts_set && is_maximized_at_all (window)) {
229 window_rect.y = yp - panel_height;
230 window_rect.height = heightp + panel_height;
231 } else {
232 window_rect.y = yp;
233 window_rect.height = heightp;
234 }
235
236 return window_rect.intersect (shown_panel_rect, null);
237 }
238
239 private bool in_panel_x_range (Wnck.Window? window) {
240 int xp, yp, widthp, heightp;
241 window.get_geometry (out xp, out yp, out widthp, out heightp);
242 if (xp > panel_x)
243 return (panel_x + panel_width > xp);
244 else if (xp < panel_x)
245 return (xp + widthp > panel_x);
246 else
247 return (xp + widthp > 0 && panel_x + panel_width > 0);
248 }
249
250 private bool right_type (Wnck.Window? active_window) {
251 unowned Wnck.WindowType type = active_window.get_window_type ();
252 return (type == Wnck.WindowType.NORMAL || type == Wnck.WindowType.DIALOG
253 || type == Wnck.WindowType.TOOLBAR || type == Wnck.WindowType.UTILITY);
254 }
255
256 private bool is_maximized_at_all (Wnck.Window window) {
257 return (window.is_maximized_horizontally ()
258 || window.is_maximized_vertically ());
259 }
260
261 private bool mouse_entered (Gdk.EventCrossing event) {
262 if (settings.dodge_maximized) {
263 // if enter from hidden
264 if (event.y == panel_height-1) {
265 uint interval = settings.hover_show_delay < 0 ? 0 : settings.hover_show_delay;
266 Timeout.add (interval, entered_callback);
267 } else
268 start_show ();
269 }
270 return true;
271 }
272
273 private bool entered_callback () {
274 Gdk.DeviceManager device_manager = get_display ().get_device_manager ();
275 Gdk.Device device = device_manager.get_client_pointer ();
276 int mouse_x, mouse_y;
277 get_window ().get_device_position (device, out mouse_x, out mouse_y, null);
278
279 if (mouse_y == panel_height-1)
280 start_show ();
281 return false;
282 }
283
284 private bool mouse_left (Gdk.EventCrossing event) {
285 int mouse_x = (int) Math.ceil (event.x);
286 int mouse_y = (int) Math.ceil (event.y);
287
288 if (settings.dodge_maximized)
289 update_visibility_hover (mouse_x, mouse_y);
290 return true;
291 }
292
293 protected void update_visibility_hover (int mouse_x, int mouse_y) {
294 if (!hovered (mouse_x, mouse_y) && should_hide_active_change (wnck_screen.get_active_window ())) {
295 uint interval = settings.hover_hide_delay < 0 ? 0 : settings.hover_hide_delay;
296 Timeout.add (interval, left_callback);
297 }
298 }
299
300 private bool left_callback () {
301 Gdk.DeviceManager device_manager = get_display ().get_device_manager ();
302 Gdk.Device device = device_manager.get_client_pointer ();
303 int mouse_x, mouse_y;
304 get_window ().get_device_position (device, out mouse_x, out mouse_y, null);
305
306 if (!hovered (mouse_x, mouse_y) && should_hide_active_change (wnck_screen.get_active_window ()))
307 start_hide ();
308 return false;
309 }
310
311 private bool hovered (int mouse_x, int mouse_y) {
312 return (mouse_x >= 0 && mouse_x < panel_width
313 && mouse_y < panel_height && mouse_y >= 0);
314 }
315
169 private void window_geometry_changed_open (Wnck.Window window) {316 private void window_geometry_changed_open (Wnck.Window window) {
170 if (window_fills_workarea (window)) {317 if (window_fills_workarea (window)) {
171 update_panel_alpha (Duration.OPEN);318 update_panel_alpha (Duration.OPEN);
@@ -210,8 +357,9 @@
210 int window_x, window_y, window_width, window_height;357 int window_x, window_y, window_width, window_height;
211 window.get_geometry (out window_x, out window_y, out window_width, out window_height);358 window.get_geometry (out window_x, out window_y, out window_width, out window_height);
212359
360 // window y might be less (further up) than workarea y right after set_struts
213 if (window.is_maximized_vertically () && !window.is_minimized ()361 if (window.is_maximized_vertically () && !window.is_minimized ()
214 && window_y == monitor_workarea_y362 && window_y <= monitor_workarea_y
215 && (window_x == monitor_workarea_x363 && (window_x == monitor_workarea_x
216 || window_x == monitor_workarea.x + monitor_workarea_width / 2)364 || window_x == monitor_workarea.x + monitor_workarea_width / 2)
217 && (window_width == monitor_workarea_width365 && (window_width == monitor_workarea_width
@@ -247,9 +395,10 @@
247 cr.fill ();395 cr.fill ();
248396
249 // Slide in397 // Slide in
250 if (animation_timer == 0) {398 if (first_run) {
399 first_run = false;
251 panel_displacement = -panel_height;400 panel_displacement = -panel_height;
252 animation_timer = Timeout.add (300 / panel_height, animation_callback);401 start_show ();
253 }402 }
254403
255 var child = get_child ();404 var child = get_child ();
@@ -319,17 +468,41 @@
319468
320 return false;469 return false;
321 }470 }
322471
323 private bool animation_callback () {472 private void start_show () {
324 if (panel_displacement >= 0 )473 showing = true;
474 hiding = false;
475 Timeout.add (300 / panel_height, show_animation);
476 }
477
478 private void start_hide () {
479 hiding = true;
480 showing = false;
481 Timeout.add (300 / panel_height, hide_animation);
482 }
483
484 private bool show_animation () {
485 if (!showing || (panel_displacement >= 0)) {
486 showing = false;
325 return false;487 return false;
326488 }
327 panel_displacement += 1;489 panel_displacement += 1;
328 move (panel_x, panel_y + panel_displacement);490 move (panel_x, panel_y + panel_displacement);
329 shadow.move (panel_x, panel_y + panel_height + panel_displacement);491 shadow.move (panel_x, panel_y + panel_height + panel_displacement);
330 return true;492 return true;
331 }493 }
332494
495 private bool hide_animation () {
496 if (!hiding || panel_displacement <= -panel_height+1) {
497 hiding = false;
498 return false;
499 }
500 panel_displacement -= 1;
501 move (panel_x, panel_y + panel_displacement);
502 shadow.move (panel_x, panel_y + panel_height + panel_displacement);
503 return true;
504 }
505
333 private bool active_workspace_has_maximized_window () {506 private bool active_workspace_has_maximized_window () {
334 int scale_factor = this.get_scale_factor ();507 int scale_factor = this.get_scale_factor ();
335 var workspace = wnck_screen.get_active_workspace ();508 var workspace = wnck_screen.get_active_workspace ();
@@ -400,6 +573,33 @@
400 32, X.PropMode.Replace, (uchar[]) struts, struts.length);573 32, X.PropMode.Replace, (uchar[]) struts, struts.length);
401 display.change_property (xid, display.intern_atom ("_NET_WM_STRUT", false), X.XA_CARDINAL,574 display.change_property (xid, display.intern_atom ("_NET_WM_STRUT", false), X.XA_CARDINAL,
402 32, X.PropMode.Replace, (uchar[]) first_struts, first_struts.length);575 32, X.PropMode.Replace, (uchar[]) first_struts, first_struts.length);
576 struts_set = true;
577 }
578
579 private void disable_struts () {
580 if (!get_realized ())
581 return;
582
583 // Since uchar is 8 bits in vala but the struts are 32 bits
584 // we have to allocate 4 times as much and do bit-masking
585 var struts = new ulong[Struts.N_VALUES];
586
587 struts[Struts.TOP] = 0;
588 struts[Struts.TOP_START] = 0;
589 struts[Struts.TOP_END] = 0;
590
591 var first_struts = new ulong[Struts.BOTTOM + 1];
592 for (var i = 0; i < first_struts.length; i++)
593 first_struts[i] = struts[i];
594
595 unowned X.Display display = Gdk.X11Display.get_xdisplay (get_display ());
596 var xid = Gdk.X11Window.get_xid (get_window ());
597
598 display.change_property (xid, display.intern_atom ("_NET_WM_STRUT_PARTIAL", false), X.XA_CARDINAL,
599 32, X.PropMode.Replace, (uchar[]) struts, struts.length);
600 display.change_property (xid, display.intern_atom ("_NET_WM_STRUT", false), X.XA_CARDINAL,
601 32, X.PropMode.Replace, (uchar[]) first_struts, first_struts.length);
602 struts_set = false;
403 }603 }
404604
405 private void panel_resize (bool redraw) {605 private void panel_resize (bool redraw) {
406606
=== modified file 'src/Widgets/Panel.vala'
--- src/Widgets/Panel.vala 2015-03-06 05:47:18 +0000
+++ src/Widgets/Panel.vala 2015-06-17 22:29:30 +0000
@@ -26,6 +26,7 @@
26 private MenuBar left_menubar;26 private MenuBar left_menubar;
27 private MenuBar center_menubar;27 private MenuBar center_menubar;
28 private Gtk.Box container;28 private Gtk.Box container;
29 private AppsButton apps_button;
2930
30 public Panel (Gtk.Application app, Services.Settings settings, IndicatorLoader indicator_loader) {31 public Panel (Gtk.Application app, Services.Settings settings, IndicatorLoader indicator_loader) {
31 base (settings);32 base (settings);
@@ -42,6 +43,9 @@
42 style_context.add_class (StyleClass.PANEL);43 style_context.add_class (StyleClass.PANEL);
43 style_context.add_class (Gtk.STYLE_CLASS_MENUBAR);44 style_context.add_class (Gtk.STYLE_CLASS_MENUBAR);
4445
46 apps_button = new AppsButton (settings);
47 apps_button.state_flags_changed.connect (apps_button_state_changed);
48
45 // Add default widgets49 // Add default widgets
46 add_defaults (settings);50 add_defaults (settings);
4751
@@ -87,6 +91,17 @@
87 critical ("Indicator entry '%s' has no parent. Not removing from panel.", entry.get_entry_name ());91 critical ("Indicator entry '%s' has no parent. Not removing from panel.", entry.get_entry_name ());
88 }92 }
8993
94 private void apps_button_state_changed () {
95 Gdk.DeviceManager device_manager = this.get_display ().get_device_manager ();
96 Gdk.Device device = device_manager.get_client_pointer ();
97 int mouse_x, mouse_y;
98 this.get_window ().get_device_position (device, out mouse_x, out mouse_y, null);
99
100 if (!apps_button.active && settings.dodge_maximized) {
101 update_visibility_hover (mouse_x, mouse_y);
102 }
103 }
104
90 private void add_defaults (Services.Settings settings) {105 private void add_defaults (Services.Settings settings) {
91 left_menubar = new MenuBar ();106 left_menubar = new MenuBar ();
92 center_menubar = new MenuBar ();107 center_menubar = new MenuBar ();
@@ -94,7 +109,7 @@
94109
95 right_menubar.halign = Gtk.Align.END;110 right_menubar.halign = Gtk.Align.END;
96111
97 left_menubar.append (new Widgets.AppsButton (settings));112 left_menubar.append (apps_button);
98113
99 container.pack_start (left_menubar);114 container.pack_start (left_menubar);
100 container.pack_end (right_menubar);115 container.pack_end (right_menubar);

Subscribers

People subscribed via source and target branches