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

Subscribers

People subscribed via source and target branches

to all changes: