Merge lp:~victored/wingpanel/lp-1380392 into lp:~elementary-pantheon/wingpanel/trunk-0.3.x

Proposed by Victor Martinez
Status: Merged
Approved by: Danielle Foré
Approved revision: 201
Merged at revision: 206
Proposed branch: lp:~victored/wingpanel/lp-1380392
Merge into: lp:~elementary-pantheon/wingpanel/trunk-0.3.x
Diff against target: 104 lines (+41/-32)
1 file modified
src/Indicator/IndicatorObjectEntry.vala (+41/-32)
To merge this branch: bzr merge lp:~victored/wingpanel/lp-1380392
Reviewer Review Type Date Requested Status
PerfectCarl (community) Needs Fixing
elementary Pantheon team Pending
Review via email: mp+247739@code.launchpad.net

Commit message

Update menu arrow placement after indicator geometry changes. Fixes lp:1380392

Description of the change

Update menu arrow placement after indicator geometry changes. Fixes lp:1380392

To post a comment you must log in.
Revision history for this message
PerfectCarl (name-is-carl) wrote :

1) I tried the test mentioned in the bug report:
  - disable the network
  - click on the indicator
  - re-enable the network
  - click on the indicator

The arrow is not redrawn properly.

2) Also I tried with my ido branch (granted not production ready).
When ido update the main menu margins, the window is not moved properly and is displayed out of the screen.

https://code.launchpad.net/~elementary-apps/+junk/os-patch-ido-trusty
http://i.imgur.com/iE4JtNU.png

This is not related to the bug but I would love this to be fixed: it would fix the asymmetrical margins on indicator once and for all.

review: Needs Fixing
Revision history for this message
PerfectCarl (name-is-carl) wrote :
Revision history for this message
Victor Martinez (victored) wrote :

Thanks for the review Carl.

Addressing your concerns:

1) Without this branch, if you click on the network indicator, disable the network, and then re-enable it, the arrow is permanently pointing to the wrong indicator until wingpanel is restarted. This branch addresses that issue. When the menu shrinks the arrow is properly updated and points in the correct direction.

If by properly you mean that the arrow might be misaligned while the menu resizes, that is correct, and it's actually caused by (2). I'm not addressing that in this branch.

2) Wingpanel only controls the drawing of a popover background beneath a transparent menu background. The positioning of the menus is controlled by GtkMenuBar, and it's glitchy. Since there's no clean way to override that, we'd have to write our own menubar implementation and control Gtk.Menu.popup ourselves in order to override the default positioning. This bug is still reproduceable even if you removed all the popover-related modifications performed by the panel. I might implement that at some point, although this fix makes the situation more bearable.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Indicator/IndicatorObjectEntry.vala'
2--- src/Indicator/IndicatorObjectEntry.vala 2015-01-22 06:06:22 +0000
3+++ src/Indicator/IndicatorObjectEntry.vala 2015-01-27 16:35:31 +0000
4@@ -33,11 +33,13 @@
5 private Granite.Drawing.BufferSurface buffer;
6 private int w = -1;
7 private int h = -1;
8- private int arrow_height = 10;
9- private int arrow_width = 20;
10- private double x = 10.5;
11- private double y = 10.5;
12- private int radius = 5;
13+ private int icon_origin_x = -1;
14+ private int menu_origin_x = -1;
15+ private const int arrow_height = 10;
16+ private const int arrow_width = 20;
17+ private const double x = 10.5;
18+ private const double y = 10.5;
19+ private const int radius = 5;
20
21 private const string MENU_STYLESHEET = """
22 .menu {
23@@ -158,12 +160,22 @@
24 }
25
26 private bool entry_menu_parent_draw_callback (Cairo.Context ctx) {
27- var new_w = entry.menu.get_parent ().get_allocated_width ();
28- var new_h = entry.menu.get_parent ().get_allocated_height ();
29-
30- if (new_w != w || new_h != h) {
31- w = new_w;
32- h = new_h;
33+ Gtk.Allocation alloc;
34+ entry.menu.get_parent ().get_allocation (out alloc);
35+
36+ // Get x coordinate where indicator icon starts in panel
37+ int icon_x;
38+ this.get_window ().get_origin (out icon_x, null);
39+
40+ // Get x coordinate where menu starts relative to screen area
41+ int menu_x;
42+ entry.menu.get_window ().get_origin (out menu_x, null);
43+
44+ if (alloc.width != w || alloc.height != h || icon_origin_x != icon_x || menu_origin_x != menu_x) {
45+ w = alloc.width;
46+ h = alloc.height;
47+ icon_origin_x = icon_x;
48+ menu_origin_x = menu_x;
49
50 buffer = new Granite.Drawing.BufferSurface (w, h);
51 cairo_popover (w, h);
52@@ -200,34 +212,31 @@
53 return false;
54 }
55
56- private void cairo_popover (int w, int h) {
57- w = w - 20;
58- h = h - 20;
59+ private void cairo_popover (int menu_width, int menu_height) {
60+ menu_width -= 20;
61+ menu_height -= 20;
62+
63+ Gtk.Allocation panel_icon_alloc;
64+ get_allocation (out panel_icon_alloc);
65
66 // Get some nice pos for the arrow
67- var offs = 30;
68- int p_x;
69- int w_x;
70- Gtk.Allocation alloc;
71- this.get_window ().get_origin (out p_x, null);
72- this.get_allocation (out alloc);
73-
74- entry.menu.get_window ().get_origin (out w_x, null);
75-
76- offs = (p_x + alloc.x) - w_x + this.get_allocated_width () / 4;
77- if (offs + 50 > (w + 20))
78- offs = (w + 20) - 15 - arrow_width;
79- if (offs < 17)
80- offs = 17;
81+ int arrow_offset = icon_origin_x + panel_icon_alloc.x;
82+ arrow_offset += panel_icon_alloc.width / 4 - menu_origin_x;
83+
84+ if (arrow_offset + 50 > menu_width + 20)
85+ arrow_offset = menu_width + 20 - 15 - arrow_width;
86+
87+ if (arrow_offset < 17)
88+ arrow_offset = 17;
89
90 buffer.context.arc (x + radius, y + arrow_height + radius, radius, Math.PI, Math.PI * 1.5);
91- buffer.context.line_to (offs, y + arrow_height);
92+ buffer.context.line_to (arrow_offset, y + arrow_height);
93 buffer.context.rel_line_to (arrow_width / 2.0, -arrow_height);
94 buffer.context.rel_line_to (arrow_width / 2.0, arrow_height);
95- buffer.context.arc (x + w - radius, y + arrow_height + radius, radius, Math.PI * 1.5, Math.PI * 2.0);
96+ buffer.context.arc (x + menu_width - radius, y + arrow_height + radius, radius, Math.PI * 1.5, Math.PI * 2.0);
97
98- buffer.context.arc (x + w - radius, y + h - radius, radius, 0, Math.PI * 0.5);
99- buffer.context.arc (x + radius, y + h - radius, radius, Math.PI * 0.5, Math.PI);
100+ buffer.context.arc (x + menu_width - radius, y + menu_height - radius, radius, 0, Math.PI * 0.5);
101+ buffer.context.arc (x + radius, y + menu_height - radius, radius, Math.PI * 0.5, Math.PI);
102
103 buffer.context.close_path ();
104 }

Subscribers

People subscribed via source and target branches