Merge lp:~tspindler/unity/icon-systray-fix-761409 into lp:unity/3.0

Proposed by Omer Akram
Status: Merged
Merged at revision: 1211
Proposed branch: lp:~tspindler/unity/icon-systray-fix-761409
Merge into: lp:unity/3.0
Diff against target: 157 lines (+55/-9)
2 files modified
src/PanelTray.cpp (+50/-7)
src/PanelTray.h (+5/-2)
To merge this branch: bzr merge lp:~tspindler/unity/icon-systray-fix-761409
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+73568@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Going to remove the commented out code before committing, but nice port of the patch!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/PanelTray.cpp'
--- src/PanelTray.cpp 2011-06-16 12:12:02 +0000
+++ src/PanelTray.cpp 2011-08-31 18:41:23 +0000
@@ -22,7 +22,7 @@
22#define PADDING 322#define PADDING 3
2323
24PanelTray::PanelTray ()24PanelTray::PanelTray ()
25: _n_children (0),25 :_window (0),
26 _tray (NULL),26 _tray (NULL),
27 _last_x (0),27 _last_x (0),
28 _last_y (0),28 _last_y (0),
@@ -30,7 +30,12 @@
30{30{
31 _settings = g_settings_new (SETTINGS_NAME);31 _settings = g_settings_new (SETTINGS_NAME);
32 _whitelist = g_settings_get_strv (_settings, "systray-whitelist");32 _whitelist = g_settings_get_strv (_settings, "systray-whitelist");
33
34 RealInit();
35}
3336
37void PanelTray::RealInit()
38{
34 _window = gtk_window_new (GTK_WINDOW_TOPLEVEL);39 _window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
35 gtk_window_set_type_hint (GTK_WINDOW (_window), GDK_WINDOW_TYPE_HINT_DOCK);40 gtk_window_set_type_hint (GTK_WINDOW (_window), GDK_WINDOW_TYPE_HINT_DOCK);
36 gtk_window_set_has_resize_grip (GTK_WINDOW (_window), FALSE);41 gtk_window_set_has_resize_grip (GTK_WINDOW (_window), FALSE);
@@ -38,6 +43,21 @@
38 gtk_window_set_skip_pager_hint (GTK_WINDOW (_window), TRUE);43 gtk_window_set_skip_pager_hint (GTK_WINDOW (_window), TRUE);
39 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (_window), TRUE);44 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (_window), TRUE);
40 gtk_window_resize (GTK_WINDOW (_window), 1, 24);45 gtk_window_resize (GTK_WINDOW (_window), 1, 24);
46
47 /*
48 GtkStyleContext* style_context = gtk_widget_get_style_context(_window);
49
50 GtkWidgetPath* widget_path = gtk_widget_path_new();
51 guint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW);
52 gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget");
53
54 gtk_style_context_set_path(style_context, widget_path);
55 gtk_style_context_add_class(style_context, "gnome-panel-menu-bar");
56 gtk_style_context_add_class(style_context, "unity-panel");
57
58 gtk_widget_path_free(widget_path);
59 */
60
41 SetMinMaxSize (1, 24);61 SetMinMaxSize (1, 24);
42 gtk_window_move (GTK_WINDOW (_window), 200, 12);62 gtk_window_move (GTK_WINDOW (_window), 200, 12);
43 gtk_widget_set_name (_window, "UnityPanelApplet");63 gtk_widget_set_name (_window, "UnityPanelApplet");
@@ -53,6 +73,8 @@
53 GTK_ORIENTATION_HORIZONTAL,73 GTK_ORIENTATION_HORIZONTAL,
54 (NaTrayFilterCallback)FilterTrayCallback,74 (NaTrayFilterCallback)FilterTrayCallback,
55 this);75 this);
76 /* na_tray_set_icon_size(_tray, 24); */
77
56 _tray_icon_added_id = g_signal_connect (na_tray_get_manager (_tray), "tray_icon_removed",78 _tray_icon_added_id = g_signal_connect (na_tray_get_manager (_tray), "tray_icon_removed",
57 G_CALLBACK (PanelTray::OnTrayIconRemoved), this);79 G_CALLBACK (PanelTray::OnTrayIconRemoved), this);
5880
@@ -104,11 +126,11 @@
104{126{
105 if (_tray)127 if (_tray)
106 {128 {
107 SetMinMaxSize ((_n_children * 24) + (PADDING * 2), 24);129 SetMinMaxSize (WidthOfTray() + (PADDING * 2), 24);
108 QueueRelayout ();130 QueueRelayout ();
109 QueueDraw ();131 QueueDraw ();
110132
111 if (_n_children)133 if (_children.size())
112 gtk_widget_show (_window);134 gtk_widget_show (_window);
113 else135 else
114 gtk_widget_hide (_window);136 gtk_widget_hide (_window);
@@ -156,7 +178,7 @@
156 if (na_tray_child_has_alpha (icon))178 if (na_tray_child_has_alpha (icon))
157 na_tray_child_set_composited (icon, TRUE);179 na_tray_child_set_composited (icon, TRUE);
158180
159 self->_n_children++;181 self->_children.push_back(icon);
160 g_idle_add ((GSourceFunc)IdleSync, self);182 g_idle_add ((GSourceFunc)IdleSync, self);
161 }183 }
162184
@@ -176,18 +198,39 @@
176void198void
177PanelTray::OnTrayIconRemoved (NaTrayManager *manager, NaTrayChild *child, PanelTray *self)199PanelTray::OnTrayIconRemoved (NaTrayManager *manager, NaTrayChild *child, PanelTray *self)
178{200{
179 g_idle_add ((GSourceFunc)IdleSync, self);201 for (std::vector<NaTrayChild*>::iterator it = self->_children.begin(); it != self->_children.end(); ++it)
180 if (self->_n_children > 0)202 {
181 self->_n_children--;203 if (*it == child)
204 {
205 g_idle_add ((GSourceFunc)IdleSync, self);
206 self->_children.erase(it);
207 break;
208 }
209 }
182}210}
183211
184gboolean212gboolean
185PanelTray::IdleSync (PanelTray *self)213PanelTray::IdleSync (PanelTray *self)
186{214{
215 int width = self->WidthOfTray();
216 gtk_window_resize(GTK_WINDOW(self->_window), width, 24);
187 self->Sync ();217 self->Sync ();
188 return FALSE;218 return FALSE;
189}219}
190220
221int PanelTray::WidthOfTray()
222{
223 int width = 0;
224 for (std::vector<NaTrayChild*>::iterator it = this->_children.begin(); it != this->_children.end(); ++it)
225 {
226 GtkAllocation alloc;
227 gtk_widget_get_allocation(GTK_WIDGET(*it), &alloc);
228 int w = alloc.width;
229 width += w > 24 ? w : 24;
230 }
231 return width;
232}
233
191gboolean234gboolean
192PanelTray::OnTrayExpose (GtkWidget *widget, GdkEventExpose *ev, PanelTray *tray)235PanelTray::OnTrayExpose (GtkWidget *widget, GdkEventExpose *ev, PanelTray *tray)
193{236{
194237
=== modified file 'src/PanelTray.h'
--- src/PanelTray.h 2011-06-16 12:12:02 +0000
+++ src/PanelTray.h 2011-08-31 18:41:23 +0000
@@ -35,7 +35,7 @@
35class PanelTray : public PanelIndicatorObjectView35class PanelTray : public PanelIndicatorObjectView
36{36{
37public:37public:
3838 typedef std::vector<NaTrayChild*> TrayChildren;
39 PanelTray ();39 PanelTray ();
40 ~PanelTray ();40 ~PanelTray ();
4141
@@ -50,7 +50,6 @@
50 void OnEntryRemoved (IndicatorObjectEntryProxy *proxy);50 void OnEntryRemoved (IndicatorObjectEntryProxy *proxy);
5151
52public:52public:
53 guint8 _n_children;
54 char **_whitelist;53 char **_whitelist;
55protected:54protected:
56 const gchar * GetName ();55 const gchar * GetName ();
@@ -63,10 +62,14 @@
63 static gboolean IdleSync (PanelTray *tray);62 static gboolean IdleSync (PanelTray *tray);
64 static gboolean OnTrayExpose (GtkWidget *widget, GdkEventExpose *ev, PanelTray *tray);63 static gboolean OnTrayExpose (GtkWidget *widget, GdkEventExpose *ev, PanelTray *tray);
6564
65 void RealInit();
66 int WidthOfTray();
67
66private:68private:
67 GSettings *_settings;69 GSettings *_settings;
68 GtkWidget *_window;70 GtkWidget *_window;
69 NaTray *_tray;71 NaTray *_tray;
72 TrayChildren _children;
70 int _last_x;73 int _last_x;
71 int _last_y;74 int _last_y;
72 75

Subscribers

People subscribed via source and target branches

to all changes: