Merge lp:~njpatel/unity/fix-panel-tray into lp:unity

Proposed by Neil J. Patel
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 1465
Proposed branch: lp:~njpatel/unity/fix-panel-tray
Merge into: lp:unity
Diff against target: 176 lines (+56/-13)
2 files modified
plugins/unityshell/src/PanelTray.cpp (+51/-12)
plugins/unityshell/src/PanelTray.h (+5/-1)
To merge this branch: bzr merge lp:~njpatel/unity/fix-panel-tray
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+73374@code.launchpad.net

Description of the change

This fixes:

- RGBA tray icons being broken
- Tray icon window being the wrong size
- Tray icon window blocking mouse input to other indicators
- Tray icon window positioning
- Tray icon mathematics, which were not taking into account icons that we ignored when they were removed

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/PanelTray.cpp'
2--- plugins/unityshell/src/PanelTray.cpp 2011-08-11 05:11:58 +0000
3+++ plugins/unityshell/src/PanelTray.cpp 2011-08-30 13:44:29 +0000
4@@ -32,7 +32,7 @@
5 {
6
7 PanelTray::PanelTray()
8- : _n_children(0),
9+ : _window(0),
10 _tray(NULL),
11 _last_x(0),
12 _last_y(0),
13@@ -41,6 +41,11 @@
14 _settings = g_settings_new(SETTINGS_NAME);
15 _whitelist = g_settings_get_strv(_settings, "systray-whitelist");
16
17+ RealInit();
18+}
19+
20+void PanelTray::RealInit()
21+{
22 _window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
23 gtk_window_set_type_hint(GTK_WINDOW(_window), GDK_WINDOW_TYPE_HINT_DOCK);
24 gtk_window_set_has_resize_grip(GTK_WINDOW(_window), FALSE);
25@@ -48,8 +53,22 @@
26 gtk_window_set_skip_pager_hint(GTK_WINDOW(_window), TRUE);
27 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(_window), TRUE);
28 gtk_window_resize(GTK_WINDOW(_window), 1, 24);
29- SetMinMaxSize(1, 24);
30- gtk_window_move(GTK_WINDOW(_window), 200, 12);
31+
32+ /*
33+ GtkStyleContext* style_context = gtk_widget_get_style_context(_window);
34+
35+ GtkWidgetPath* widget_path = gtk_widget_path_new();
36+ guint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW);
37+ gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget");
38+
39+ gtk_style_context_set_path(style_context, widget_path);
40+ gtk_style_context_add_class(style_context, "gnome-panel-menu-bar");
41+ gtk_style_context_add_class(style_context, "unity-panel");
42+
43+ gtk_widget_path_free(widget_path);
44+ */
45+
46+ gtk_window_move(GTK_WINDOW(_window), -24,-24);
47 gtk_widget_set_name(_window, "UnityPanelApplet");
48
49 gtk_widget_set_visual(_window, gdk_screen_get_rgba_visual(gdk_screen_get_default()));
50@@ -63,6 +82,7 @@
51 GTK_ORIENTATION_HORIZONTAL,
52 (NaTrayFilterCallback)FilterTrayCallback,
53 this);
54+ na_tray_set_icon_size(_tray, 24);
55
56 _tray_icon_added_id = g_signal_connect(na_tray_get_manager(_tray), "tray_icon_removed",
57 G_CALLBACK(PanelTray::OnTrayIconRemoved), this);
58@@ -70,6 +90,9 @@
59 gtk_container_add(GTK_CONTAINER(_window), GTK_WIDGET(_tray));
60 gtk_widget_show(GTK_WIDGET(_tray));
61 }
62+
63+ SetMinMaxSize(1, 24);
64+
65 }
66
67 PanelTray::~PanelTray()
68@@ -115,11 +138,11 @@
69 {
70 if (_tray)
71 {
72- SetMinMaxSize((_n_children * 24) + (PADDING * 2), 24);
73+ SetMinMaxSize(WidthOfTray() + (PADDING * 2), 24);
74 QueueRelayout();
75 QueueDraw();
76
77- if (_n_children)
78+ if (_children.size())
79 gtk_widget_show(_window);
80 else
81 gtk_widget_hide(_window);
82@@ -167,7 +190,7 @@
83 if (na_tray_child_has_alpha(icon))
84 na_tray_child_set_composited(icon, TRUE);
85
86- self->_n_children++;
87+ self->_children.push_back(icon);
88 g_idle_add((GSourceFunc)IdleSync, self);
89 }
90
91@@ -186,18 +209,37 @@
92 void
93 PanelTray::OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* child, PanelTray* self)
94 {
95- g_idle_add((GSourceFunc)IdleSync, self);
96- if (self->_n_children > 0)
97- self->_n_children--;
98+ for (auto it = self->_children.begin(); it != self->_children.end(); ++it)
99+ {
100+ if (*it == child)
101+ {
102+ g_idle_add((GSourceFunc)IdleSync, self);
103+ self->_children.erase(it);
104+ break;
105+ }
106+ }
107 }
108
109 gboolean
110 PanelTray::IdleSync(PanelTray* self)
111 {
112+ int width = self->WidthOfTray();
113+ gtk_window_resize(GTK_WINDOW(self->_window), width, 24);
114 self->Sync();
115 return FALSE;
116 }
117
118+int PanelTray::WidthOfTray()
119+{
120+ int width = 0;
121+ for (auto child: _children)
122+ {
123+ int w = gtk_widget_get_allocated_width(GTK_WIDGET(child));
124+ width += w > 24 ? w : 24;
125+ }
126+ return width;
127+}
128+
129 gboolean
130 PanelTray::OnTrayDraw(GtkWidget* widget, cairo_t* cr, PanelTray* tray)
131 {
132@@ -205,9 +247,6 @@
133
134 gtk_widget_get_allocation(widget, &alloc);
135
136- //gdk_cairo_region (cr, ev->region);
137- cairo_clip(cr);
138-
139 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
140 cairo_paint(cr);
141
142
143=== modified file 'plugins/unityshell/src/PanelTray.h'
144--- plugins/unityshell/src/PanelTray.h 2011-07-21 14:59:25 +0000
145+++ plugins/unityshell/src/PanelTray.h 2011-08-30 13:44:29 +0000
146@@ -39,6 +39,7 @@
147 class PanelTray : public PanelIndicatorObjectView
148 {
149 public:
150+ typedef std::vector<NaTrayChild*> TrayChildren;
151 PanelTray();
152 ~PanelTray();
153
154@@ -49,7 +50,6 @@
155 virtual void OnEntryAdded(unity::indicator::Entry::Ptr const& proxy);
156
157 public:
158- guint8 _n_children;
159 char** _whitelist;
160 protected:
161 const gchar* GetName();
162@@ -61,11 +61,15 @@
163 static void OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* child, PanelTray* self);
164 static gboolean IdleSync(PanelTray* tray);
165 static gboolean OnTrayDraw(GtkWidget* widget, cairo_t* cr, PanelTray* tray);
166+
167+ void RealInit();
168+ int WidthOfTray();
169
170 private:
171 GSettings* _settings;
172 GtkWidget* _window;
173 NaTray* _tray;
174+ TrayChildren _children;
175 int _last_x;
176 int _last_y;
177