Merge lp:~3v1n0/unity/panel-p-tray into lp:~3v1n0/unity/panel-p-grab-area

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merge reported by: Marco Trevisan (Treviño)
Merged at revision: not available
Proposed branch: lp:~3v1n0/unity/panel-p-tray
Merge into: lp:~3v1n0/unity/panel-p-grab-area
Diff against target: 417 lines (+113/-139)
2 files modified
plugins/unityshell/src/PanelTray.cpp (+92/-115)
plugins/unityshell/src/PanelTray.h (+21/-24)
To merge this branch: bzr merge lp:~3v1n0/unity/panel-p-tray
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Marco Trevisan (Treviño) Pending
Review via email: mp+100125@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Looks fine.

review: Approve

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 2012-03-21 12:31:11 +0000
3+++ plugins/unityshell/src/PanelTray.cpp 2012-04-04 20:17:23 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright (C) 2010 Canonical Ltd
7+ * Copyright (C) 2010-2012 Canonical Ltd
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3 as
11@@ -14,11 +14,14 @@
12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
13 *
14 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
15+ * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
16 */
17
18 #include "PanelTray.h"
19+#include "PanelStyle.h"
20
21 #include <NuxCore/Logger.h>
22+#include <UnityCore/Variant.h>
23
24 namespace
25 {
26@@ -31,137 +34,118 @@
27 {
28
29 PanelTray::PanelTray()
30- : View(NUX_TRACKER_LOCATION),
31- _window(0),
32- _tray(NULL),
33- _last_x(0),
34- _last_y(0),
35- _tray_icon_added_id(0)
36-{
37- _settings = g_settings_new(SETTINGS_NAME.c_str());
38- _whitelist = g_settings_get_strv(_settings, "systray-whitelist");
39-
40- RealInit();
41-}
42-
43-unsigned int
44-PanelTray::xid ()
45-{
46- if (!_window)
47- return 0;
48-
49- return gdk_x11_window_get_xid (gtk_widget_get_window (_window));
50-}
51-
52-void PanelTray::RealInit()
53-{
54- _window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
55- gtk_window_set_type_hint(GTK_WINDOW(_window), GDK_WINDOW_TYPE_HINT_DOCK);
56- gtk_window_set_has_resize_grip(GTK_WINDOW(_window), FALSE);
57- gtk_window_set_keep_above(GTK_WINDOW(_window), TRUE);
58- gtk_window_set_skip_pager_hint(GTK_WINDOW(_window), TRUE);
59- gtk_window_set_skip_taskbar_hint(GTK_WINDOW(_window), TRUE);
60- gtk_window_resize(GTK_WINDOW(_window), 1, 24);
61- gtk_window_move(GTK_WINDOW(_window), -24,-24);
62- gtk_widget_set_name(_window, "UnityPanelApplet");
63-
64- gtk_widget_set_visual(_window, gdk_screen_get_rgba_visual(gdk_screen_get_default()));
65- gtk_widget_realize(_window);
66- gtk_widget_set_app_paintable(_window, TRUE);
67- _tray_expose_id = g_signal_connect(_window, "draw", G_CALLBACK(PanelTray::OnTrayDraw), this);
68+ : View(NUX_TRACKER_LOCATION)
69+ , settings_(g_settings_new(SETTINGS_NAME.c_str()))
70+ , window_(gtk_window_new(GTK_WINDOW_TOPLEVEL))
71+ , whitelist_(g_settings_get_strv(settings_, "systray-whitelist"))
72+{
73+ int panel_height = panel::Style::Instance().panel_height;
74+
75+ whitelist_changed_.Connect(settings_, "changed::systray-whitelist", [&] (GSettings*, gchar*) {
76+ g_strfreev(whitelist_);
77+ whitelist_ = g_settings_get_strv(settings_, "systray-whitelist");
78+ });
79+
80+ auto gtkwindow = glib::object_cast<GtkWindow>(window_);
81+ gtk_window_set_type_hint(gtkwindow, GDK_WINDOW_TYPE_HINT_DOCK);
82+ gtk_window_set_has_resize_grip(gtkwindow, FALSE);
83+ gtk_window_set_keep_above(gtkwindow, TRUE);
84+ gtk_window_set_skip_pager_hint(gtkwindow, TRUE);
85+ gtk_window_set_skip_taskbar_hint(gtkwindow, TRUE);
86+ gtk_window_resize(gtkwindow, 1, panel_height);
87+ gtk_window_move(gtkwindow, -panel_height,-panel_height);
88+ gtk_widget_set_name(window_, "UnityPanelApplet");
89+
90+ gtk_widget_set_visual(window_, gdk_screen_get_rgba_visual(gdk_screen_get_default()));
91+ gtk_widget_realize(window_);
92+ gtk_widget_set_app_paintable(window_, TRUE);
93+ draw_signal_.Connect(window_, "draw", sigc::mem_fun(this, &PanelTray::OnTrayDraw));
94
95 if (!g_getenv("UNITY_PANEL_TRAY_DISABLE"))
96 {
97- _tray = na_tray_new_for_screen(gdk_screen_get_default(),
98+ tray_ = na_tray_new_for_screen(gdk_screen_get_default(),
99 GTK_ORIENTATION_HORIZONTAL,
100 (NaTrayFilterCallback)FilterTrayCallback,
101 this);
102- na_tray_set_icon_size(_tray, 24);
103-
104- _tray_icon_added_id = g_signal_connect(na_tray_get_manager(_tray), "tray_icon_removed",
105- G_CALLBACK(PanelTray::OnTrayIconRemoved), this);
106-
107- gtk_container_add(GTK_CONTAINER(_window), GTK_WIDGET(_tray));
108- gtk_widget_show(GTK_WIDGET(_tray));
109+ na_tray_set_icon_size(tray_, panel_height);
110+
111+ icon_removed_signal_.Connect(na_tray_get_manager(tray_), "tray_icon_removed",
112+ sigc::mem_fun(this, &PanelTray::OnTrayIconRemoved));
113+
114+ gtk_container_add(GTK_CONTAINER(window_.RawPtr()), GTK_WIDGET(tray_.RawPtr()));
115+ gtk_widget_show(GTK_WIDGET(tray_.RawPtr()));
116 }
117
118- SetMinMaxSize(1, 24);
119-
120+ SetMinMaxSize(1, panel_height);
121 }
122
123 PanelTray::~PanelTray()
124 {
125- if (_tray)
126- {
127- g_signal_handler_disconnect(na_tray_get_manager(_tray), _tray_icon_added_id);
128- _tray = NULL;
129- }
130-
131 g_idle_remove_by_data(this);
132-
133- if (_tray_expose_id)
134- g_signal_handler_disconnect(_window, _tray_expose_id);
135-
136- gtk_widget_destroy(_window);
137- g_strfreev(_whitelist);
138- g_object_unref(_settings);
139-}
140-
141-void
142-PanelTray::Draw(nux::GraphicsEngine& gfx_context, bool force_draw)
143-{
144- nux::Geometry geo(GetAbsoluteGeometry());
145+ g_strfreev(whitelist_);
146+
147+ if (gtk_widget_get_realized(window_))
148+ gtk_widget_destroy(window_);
149+}
150+
151+Window PanelTray::xid()
152+{
153+ if (!window_)
154+ return 0;
155+
156+ return gdk_x11_window_get_xid(gtk_widget_get_window(window_));
157+}
158+
159+void PanelTray::Draw(nux::GraphicsEngine& gfx_context, bool force_draw)
160+{
161+ nux::Geometry const& geo = GetAbsoluteGeometry();
162
163 gfx_context.PushClippingRectangle(geo);
164 nux::GetPainter().PaintBackground(gfx_context, geo);
165 gfx_context.PopClippingRectangle();
166
167- if (geo.x != _last_x || geo.y != _last_y)
168+ if (geo != last_geo_)
169 {
170- _last_x = geo.x;
171- _last_y = geo.y;
172-
173- gtk_window_move(GTK_WINDOW(_window), geo.x + PADDING, geo.y);
174+ last_geo_ = geo;
175+ gtk_window_move(GTK_WINDOW(window_.RawPtr()), geo.x + PADDING, geo.y);
176 }
177 }
178
179-void
180-PanelTray::Sync()
181+void PanelTray::Sync()
182 {
183- if (_tray)
184+ if (tray_)
185 {
186- SetMinMaxSize(WidthOfTray() + (PADDING * 2), 24);
187+ SetMinMaxSize(WidthOfTray() + (PADDING * 2), panel::Style::Instance().panel_height);
188 QueueRelayout();
189 QueueDraw();
190
191- if (_children.size())
192- gtk_widget_show(_window);
193+ if (!children_.empty())
194+ gtk_widget_show(window_);
195 else
196- gtk_widget_hide(_window);
197+ gtk_widget_hide(window_);
198 }
199 }
200
201-gboolean
202-PanelTray::FilterTrayCallback(NaTray* tray, NaTrayChild* icon, PanelTray* self)
203+gboolean PanelTray::FilterTrayCallback(NaTray* tray, NaTrayChild* icon, PanelTray* self)
204 {
205- char* title;
206- char* res_name = NULL;
207- char* res_class = NULL;
208- char* name;
209- int i = 0;
210- bool accept = false;
211-
212- title = na_tray_child_get_title(icon);
213+ int i = 0;
214+ bool accept = false;
215+ const char *name = nullptr;
216+
217+ glib::String title(na_tray_child_get_title(icon));
218+
219+ glib::String res_class;
220+ glib::String res_name;
221 na_tray_child_get_wm_class(icon, &res_name, &res_class);
222
223- while ((name = self->_whitelist[i]))
224+ while ((name = self->whitelist_[i]))
225 {
226 if (g_strcmp0(name, "all") == 0)
227 {
228 accept = true;
229 break;
230 }
231- else if (!name || g_strcmp0(name, "") == 0)
232+ else if (!name || name[0] == '\0')
233 {
234 accept = false;
235 break;
236@@ -182,7 +166,7 @@
237 if (na_tray_child_has_alpha(icon))
238 na_tray_child_set_composited(icon, TRUE);
239
240- self->_children.push_back(icon);
241+ self->children_.push_back(icon);
242 g_idle_add((GSourceFunc)IdleSync, self);
243 }
244
245@@ -191,32 +175,26 @@
246 << na_tray_child_get_title(icon) << " "
247 << res_name << " " << res_class;
248
249- g_free(res_name);
250- g_free(res_class);
251- g_free(title);
252-
253 return accept ? TRUE : FALSE;
254 }
255
256-void
257-PanelTray::OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* child, PanelTray* self)
258+void PanelTray::OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* removed)
259 {
260- for (auto it = self->_children.begin(); it != self->_children.end(); ++it)
261+ for (auto child : children_)
262 {
263- if (*it == child)
264+ if (child == removed)
265 {
266- g_idle_add((GSourceFunc)IdleSync, self);
267- self->_children.erase(it);
268+ g_idle_add((GSourceFunc)IdleSync, this);
269+ children_.remove(child);
270 break;
271 }
272 }
273 }
274
275-gboolean
276-PanelTray::IdleSync(PanelTray* self)
277+gboolean PanelTray::IdleSync(PanelTray* self)
278 {
279 int width = self->WidthOfTray();
280- gtk_window_resize(GTK_WINDOW(self->_window), width, 24);
281+ gtk_window_resize(GTK_WINDOW(self->window_.RawPtr()), width, panel::Style::Instance().panel_height);
282 self->Sync();
283 return FALSE;
284 }
285@@ -224,7 +202,7 @@
286 int PanelTray::WidthOfTray()
287 {
288 int width = 0;
289- for (auto child: _children)
290+ for (auto child: children_)
291 {
292 int w = gtk_widget_get_allocated_width(GTK_WIDGET(child));
293 width += w > 24 ? w : 24;
294@@ -232,8 +210,7 @@
295 return width;
296 }
297
298-gboolean
299-PanelTray::OnTrayDraw(GtkWidget* widget, cairo_t* cr, PanelTray* tray)
300+gboolean PanelTray::OnTrayDraw(GtkWidget* widget, cairo_t* cr)
301 {
302 GtkAllocation alloc;
303
304@@ -254,16 +231,16 @@
305 return FALSE;
306 }
307
308-std::string
309-PanelTray::GetName() const
310+std::string PanelTray::GetName() const
311 {
312- return "PanelTray";
313+ return "Tray";
314 }
315
316-void
317-PanelTray::AddProperties(GVariantBuilder* builder)
318+void PanelTray::AddProperties(GVariantBuilder* builder)
319 {
320-
321+ variant::BuilderWrapper(builder)
322+ .add(GetGeometry())
323+ .add("children_count", children_.size());
324 }
325
326 } // namespace unity
327
328=== modified file 'plugins/unityshell/src/PanelTray.h'
329--- plugins/unityshell/src/PanelTray.h 2011-12-14 20:04:23 +0000
330+++ plugins/unityshell/src/PanelTray.h 2012-04-04 20:17:23 +0000
331@@ -1,5 +1,5 @@
332 /*
333- * Copyright (C) 2010 Canonical Ltd
334+ * Copyright (C) 2010-2012 Canonical Ltd
335 *
336 * This program is free software: you can redistribute it and/or modify
337 * it under the terms of the GNU General Public License version 3 as
338@@ -14,18 +14,20 @@
339 * along with this program. If not, see <http://www.gnu.org/licenses/>.
340 *
341 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
342+ * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
343 */
344
345 #ifndef PANEL_TRAY_H
346 #define PANEL_TRAY_H
347
348 #include <Nux/Nux.h>
349+#include <Nux/View.h>
350 #include <gtk/gtk.h>
351-
352 #include <gdk/gdkx.h>
353
354-#include <Nux/View.h>
355 #include "Introspectable.h"
356+#include <UnityCore/GLibWrapper.h>
357+#include <UnityCore/GLibSignal.h>
358
359 #include <unity-misc/na-tray.h>
360 #include <unity-misc/na-tray-child.h>
361@@ -37,40 +39,35 @@
362 class PanelTray : public nux::View, public unity::debug::Introspectable
363 {
364 public:
365- typedef std::vector<NaTrayChild*> TrayChildren;
366 PanelTray();
367 ~PanelTray();
368
369- void Draw(nux::GraphicsEngine& gfx_content, bool force_draw);
370 void Sync();
371-
372- unsigned int xid ();
373-
374-public:
375- char** _whitelist;
376+ Window xid();
377+
378 protected:
379+ void Draw(nux::GraphicsEngine& gfx_content, bool force_draw);
380 std::string GetName() const;
381- void AddProperties(GVariantBuilder* builder);
382+ void AddProperties(GVariantBuilder* builder);
383
384 private:
385 static gboolean FilterTrayCallback(NaTray* tray, NaTrayChild* child, PanelTray* self);
386- static void OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* child, PanelTray* self);
387 static gboolean IdleSync(PanelTray* tray);
388- static gboolean OnTrayDraw(GtkWidget* widget, cairo_t* cr, PanelTray* tray);
389-
390- void RealInit();
391+ void OnTrayIconRemoved(NaTrayManager* manager, NaTrayChild* child);
392+ gboolean OnTrayDraw(GtkWidget* widget, cairo_t* cr);
393+
394 int WidthOfTray();
395
396-private:
397- GSettings* _settings;
398- GtkWidget* _window;
399- NaTray* _tray;
400- TrayChildren _children;
401- int _last_x;
402- int _last_y;
403+ glib::Object<GSettings> settings_;
404+ glib::Object<GtkWidget> window_;
405+ glib::Object<NaTray> tray_;
406+ char** whitelist_;
407
408- gulong _tray_expose_id;
409- gulong _tray_icon_added_id;
410+ glib::Signal<void, GSettings*, gchar*> whitelist_changed_;
411+ glib::Signal<gboolean, GtkWidget*, cairo_t*> draw_signal_;
412+ glib::Signal<void, NaTrayManager*, NaTrayChild*> icon_removed_signal_;
413+ std::list<NaTrayChild*> children_;
414+ nux::Geometry last_geo_;
415 };
416
417 }

Subscribers

People subscribed via source and target branches

to all changes: