Merge lp:~cimi/unity/unity.use-gtk3-style-context into lp:unity

Proposed by Andrea Cimitan on 2011-07-01
Status: Merged
Merged at revision: 1269
Proposed branch: lp:~cimi/unity/unity.use-gtk3-style-context
Merge into: lp:unity
Diff against target: 453 lines (+119/-188)
6 files modified
plugins/unityshell/src/PanelHomeButton.cpp (+2/-18)
plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp (+43/-101)
plugins/unityshell/src/PanelMenuView.cpp (+26/-7)
plugins/unityshell/src/PanelStyle.cpp (+40/-48)
plugins/unityshell/src/PanelStyle.h (+3/-11)
plugins/unityshell/src/PanelView.cpp (+5/-3)
To merge this branch: bzr merge lp:~cimi/unity/unity.use-gtk3-style-context
Reviewer Review Type Date Requested Status
Neil J. Patel (community) 2011-07-01 Approve on 2011-07-07
Review via email: mp+66622@code.launchpad.net

Description of the change

First WIP of pure gtk+3 rendering

To post a comment you must log in.
Andrea Cimitan (cimi) wrote :

Visually looks perfect, but selecting widgets on the menubar is pretty slow. Need to profile unity and see where the slowdown comes from

Neil J. Patel (njpatel) wrote :

Awesome work dude, merging now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/PanelHomeButton.cpp'
--- plugins/unityshell/src/PanelHomeButton.cpp 2011-06-21 12:10:09 +0000
+++ plugins/unityshell/src/PanelHomeButton.cpp 2011-07-01 17:47:29 +0000
@@ -133,7 +133,6 @@
133 int width = _button_width;133 int width = _button_width;
134 int height = PANEL_HEIGHT;134 int height = PANEL_HEIGHT;
135 GdkPixbuf *pixbuf;135 GdkPixbuf *pixbuf;
136 GdkPixbuf *overlay;
137136
138 SetMinMaxSize (_button_width, PANEL_HEIGHT);137 SetMinMaxSize (_button_width, PANEL_HEIGHT);
139138
@@ -142,23 +141,8 @@
142 cairo_set_line_width (cr, 1);141 cairo_set_line_width (cr, 1);
143142
144 /* button pressed effect */143 /* button pressed effect */
145 if (_pressed) {144 //FIXME(Cimi) removed the pressed effect
146 if (PanelStyle::GetDefault ()->IsAmbianceOrRadiance () && _opacity == 1.0f) {145
147 /* loads background panel upside-down */
148 overlay = gdk_pixbuf_flip (PanelStyle::GetDefault ()->GetBackground (width - 2, height), FALSE);
149 if (GDK_IS_PIXBUF (overlay)) {
150 gdk_cairo_set_source_pixbuf (cr, overlay, 0, 0);
151 cairo_paint (cr);
152 g_object_unref (overlay);
153 }
154 } else {
155 /* draws an translucent overlay */
156 cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.3f);
157 cairo_rectangle (cr, 0, 0, width-1, height);
158 cairo_fill (cr);
159 }
160 }
161
162 pixbuf = PanelStyle::GetDefault ()->GetHomeButton ();146 pixbuf = PanelStyle::GetDefault ()->GetHomeButton ();
163 if (GDK_IS_PIXBUF (pixbuf))147 if (GDK_IS_PIXBUF (pixbuf))
164 {148 {
165149
=== modified file 'plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp'
--- plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp 2011-06-29 15:40:49 +0000
+++ plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp 2011-07-01 17:47:29 +0000
@@ -147,10 +147,6 @@
147 int text_width = 0;147 int text_width = 0;
148 int text_height = 0;148 int text_height = 0;
149149
150 PanelStyle *style = PanelStyle::GetDefault ();
151 nux::Color textcol = style->GetTextColor ();
152 nux::Color textshadowcol = style->GetTextShadow ();
153
154 if (proxy_->show_now())150 if (proxy_->show_now())
155 {151 {
156 if (!pango_parse_markup (label.c_str(),152 if (!pango_parse_markup (label.c_str(),
@@ -246,25 +242,28 @@
246 {242 {
247 pango_cairo_update_layout (cr, layout);243 pango_cairo_update_layout (cr, layout);
248244
249 // Once for the homies that couldn't be here245 PanelStyle *style = PanelStyle::GetDefault ();
250 cairo_set_source_rgba (cr,246 GtkStyleContext *style_context = style->GetStyleContext ();
251 textshadowcol.red,247
252 textshadowcol.green,248 gtk_style_context_save (style_context);
253 textshadowcol.blue,249
254 1.0f - textshadowcol.red);250 GtkWidgetPath *widget_path = gtk_widget_path_new ();
255 cairo_move_to (cr, x, (int)(((height - text_height)/2)+1));251 gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
256 pango_cairo_show_layout (cr, layout);252 gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_BAR);
257 cairo_stroke (cr);253 gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_ITEM);
258254
259 // Once again for the homies that could255 gtk_style_context_set_path (style_context, widget_path);
260 cairo_set_source_rgba (cr,256 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUBAR);
261 textcol.red,257 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUITEM);
262 textcol.green,258
263 textcol.blue,259 if (proxy_->active())
264 proxy_->label_sensitive() ? 1.0f : 0.5f);260 gtk_style_context_set_state (style_context, GTK_STATE_FLAG_PRELIGHT);
265 cairo_move_to (cr, x, (int)((height - text_height)/2));261
266 pango_cairo_show_layout (cr, layout);262 gtk_render_layout (style_context, cr, x, (int)((height - text_height)/2), layout);
267 cairo_stroke (cr);263
264 gtk_widget_path_free (widget_path);
265
266 gtk_style_context_restore (style_context);
268 }267 }
269268
270 cairo_destroy (cr);269 cairo_destroy (cr);
@@ -362,85 +361,28 @@
362361
363void draw_menu_bg(cairo_t* cr, int width, int height)362void draw_menu_bg(cairo_t* cr, int width, int height)
364{363{
365 int radius = 4;
366 double x = 0;
367 double y = 0;
368 double xos = 0.5;
369 double yos = 0.5;
370 /* FIXME */
371 double mpi = 3.14159265358979323846;
372
373 PanelStyle *style = PanelStyle::GetDefault ();364 PanelStyle *style = PanelStyle::GetDefault ();
374 nux::Color bgtop = style->GetBackgroundTop ();365 GtkStyleContext *style_context = style->GetStyleContext ();
375 nux::Color bgbot = style->GetBackgroundBottom ();366
376 nux::Color line = style->GetLineColor ();367 gtk_style_context_save (style_context);
377368
378 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);369 GtkWidgetPath *widget_path = gtk_widget_path_new ();
379370 gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
380 cairo_set_line_width (cr, 1.0);371 gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_BAR);
381372 gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_ITEM);
382 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.2);373
383374 gtk_style_context_set_path (style_context, widget_path);
384 cairo_move_to (cr, x+xos+radius, y+yos);375 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUBAR);
385 cairo_arc (cr, x+xos+width-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);376 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUITEM);
386 cairo_line_to (cr, x+xos+width-xos*2, y+yos+height-yos*2+2);377 gtk_style_context_set_state (style_context, GTK_STATE_FLAG_PRELIGHT);
387 cairo_line_to (cr, x+xos, y+yos+height-yos*2+2);378
388 cairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);379 // FIXME(Cimi) probably some padding is needed here.
389380 gtk_render_background (style_context, cr, 0, 0, width, height);
390 cairo_pattern_t * pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+2);381 gtk_render_frame (style_context, cr, 0, 0, width, height);
391 cairo_pattern_add_color_stop_rgba (pat, 0.0,382
392 bgtop.red,383 gtk_widget_path_free (widget_path);
393 bgtop.green,384
394 bgtop.blue,385 gtk_style_context_restore (style_context);
395 1.0f - bgbot.red);
396 cairo_pattern_add_color_stop_rgba (pat, 1.0,
397 bgbot.red,
398 bgbot.green,
399 bgbot.blue,
400 1.0f - bgtop.red);
401 cairo_set_source (cr, pat);
402 cairo_fill_preserve (cr);
403 cairo_pattern_destroy (pat);
404
405 pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+2);
406 cairo_pattern_add_color_stop_rgba (pat, 0.0,
407 line.red,
408 line.green,
409 line.blue,
410 1.0f);
411 cairo_pattern_add_color_stop_rgba (pat, 1.0,
412 line.red,
413 line.green,
414 line.blue,
415 1.0f);
416 cairo_set_source (cr, pat);
417 cairo_stroke (cr);
418 cairo_pattern_destroy (pat);
419
420 xos++;
421 yos++;
422
423 /* enlarging the area to not draw the lightborder at bottom, ugly trick :P */
424 cairo_move_to (cr, x+radius+xos, y+yos);
425 cairo_arc (cr, x+xos+width-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
426 cairo_line_to (cr, x+xos+width-xos*2, y+yos+height-yos*2+3);
427 cairo_line_to (cr, x+xos, y+yos+height-yos*2+3);
428 cairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
429
430 pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+3);
431 cairo_pattern_add_color_stop_rgba (pat, 0.0,
432 bgbot.red,
433 bgbot.green,
434 bgbot.blue,
435 1.0f);
436 cairo_pattern_add_color_stop_rgba (pat, 1.0,
437 bgbot.red,
438 bgbot.green,
439 bgbot.blue,
440 1.0f);
441 cairo_set_source (cr, pat);
442 cairo_stroke (cr);
443 cairo_pattern_destroy (pat);
444}386}
445387
446GdkPixbuf* make_pixbuf(int image_type, std::string const& image_data)388GdkPixbuf* make_pixbuf(int image_type, std::string const& image_data)
447389
=== modified file 'plugins/unityshell/src/PanelMenuView.cpp'
--- plugins/unityshell/src/PanelMenuView.cpp 2011-06-21 12:29:49 +0000
+++ plugins/unityshell/src/PanelMenuView.cpp 2011-07-01 17:47:29 +0000
@@ -578,10 +578,26 @@
578578
579 if (label)579 if (label)
580 {580 {
581 nux::Color const& col = PanelStyle::GetDefault ()->GetTextColor();581 PanelStyle *style = PanelStyle::GetDefault ();
582 float red = col.red;582 GtkStyleContext *style_context = style->GetStyleContext ();
583 float green = col.green;583
584 float blue = col.blue;584 gtk_style_context_save (style_context);
585
586 GtkWidgetPath *widget_path = gtk_widget_path_new ();
587 gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
588 gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_BAR);
589 gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_ITEM);
590
591 gtk_style_context_set_path (style_context, widget_path);
592 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUBAR);
593 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUITEM);
594
595 GdkRGBA rgba_text;
596 gtk_style_context_get_color (style_context, GTK_STATE_FLAG_NORMAL, &rgba_text);
597
598 float red = rgba_text.red;
599 float green = rgba_text.green;
600 float blue = rgba_text.blue;
585601
586 pango_cairo_update_layout (cr, layout);602 pango_cairo_update_layout (cr, layout);
587603
@@ -602,9 +618,12 @@
602 {618 {
603 cairo_set_source_rgb (cr, red, green, blue);619 cairo_set_source_rgb (cr, red, green, blue);
604 }620 }
605 cairo_move_to (cr, x, y);621
606 pango_cairo_show_layout (cr, layout);622 gtk_render_layout (style_context, cr, x, y, layout);
607 cairo_stroke (cr);623
624 gtk_widget_path_free (widget_path);
625
626 gtk_style_context_restore (style_context);
608 }627 }
609628
610 cairo_destroy (cr);629 cairo_destroy (cr);
611630
=== modified file 'plugins/unityshell/src/PanelStyle.cpp'
--- plugins/unityshell/src/PanelStyle.cpp 2011-06-20 21:39:32 +0000
+++ plugins/unityshell/src/PanelStyle.cpp 2011-07-01 17:47:29 +0000
@@ -32,11 +32,12 @@
3232
33PanelStyle *_style = NULL;33PanelStyle *_style = NULL;
3434
35nux::Color ColorFromGdkColor(GdkColor const& gc)35nux::Color ColorFromGdkRGBA(GdkRGBA const& color)
36{36{
37 return nux::Color(gc.red / static_cast<float>(0xffff),37 return nux::Color(color.red,
38 gc.green / static_cast<float>(0xffff),38 color.green,
39 gc.blue / static_cast<float>(0xffff));39 color.blue,
40 color.alpha);
40}41}
4142
42}43}
@@ -44,12 +45,17 @@
44PanelStyle::PanelStyle ()45PanelStyle::PanelStyle ()
45: _theme_name (NULL)46: _theme_name (NULL)
46{47{
47 _offscreen = gtk_offscreen_window_new ();48 _style_context = gtk_style_context_new ();
48 gtk_widget_set_name (_offscreen, "UnityPanelWidget");49
49 gtk_widget_set_size_request (_offscreen, 100, 24);50 GtkWidgetPath *widget_path = gtk_widget_path_new ();
50 gtk_style_context_add_class (gtk_widget_get_style_context (_offscreen),51 gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
51 "menubar");52 gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
52 gtk_widget_show_all (_offscreen);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);
5359
54 _gtk_theme_changed_id = g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",60 _gtk_theme_changed_id = g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",
55 G_CALLBACK (PanelStyle::OnStyleChanged), this);61 G_CALLBACK (PanelStyle::OnStyleChanged), this);
@@ -62,8 +68,8 @@
62 if (_gtk_theme_changed_id)68 if (_gtk_theme_changed_id)
63 g_signal_handler_disconnect (gtk_settings_get_default (),69 g_signal_handler_disconnect (gtk_settings_get_default (),
64 _gtk_theme_changed_id);70 _gtk_theme_changed_id);
65 71
66 gtk_widget_destroy (_offscreen);72 g_object_unref (_style_context);
6773
68 if (_style == this)74 if (_style == this)
69 _style = NULL;75 _style = NULL;
@@ -83,7 +89,7 @@
83void89void
84PanelStyle::Refresh ()90PanelStyle::Refresh ()
85{91{
86 GtkStyle* style = NULL;92 GdkRGBA rgba_text;
8793
88 if (_theme_name)94 if (_theme_name)
89 g_free (_theme_name);95 g_free (_theme_name);
@@ -91,40 +97,19 @@
91 _theme_name = NULL;97 _theme_name = NULL;
92 g_object_get (gtk_settings_get_default (), "gtk-theme-name", &_theme_name, NULL);98 g_object_get (gtk_settings_get_default (), "gtk-theme-name", &_theme_name, NULL);
9399
94 style = gtk_widget_get_style (_offscreen);100 gtk_style_context_invalidate (_style_context);
95101
96 _text = ColorFromGdkColor(style->text[0]);102 gtk_style_context_get_color (_style_context, GTK_STATE_FLAG_NORMAL, &rgba_text);
97 _text_shadow = ColorFromGdkColor(style->text[3]);103
98 _line = ColorFromGdkColor(style->dark[0]);104 _text = ColorFromGdkRGBA (rgba_text);
99 _bg_top = ColorFromGdkColor(style->bg[1]);
100 _bg_bottom = ColorFromGdkColor(style->bg[0]);
101105
102 changed.emit ();106 changed.emit ();
103}107}
104108
105nux::Color const& PanelStyle::GetTextColor() const109GtkStyleContext *
106{110PanelStyle::GetStyleContext ()
107 return _text;111{
108}112 return _style_context;
109
110nux::Color const& PanelStyle::GetBackgroundTop() const
111{
112 return _bg_top;
113}
114
115nux::Color const& PanelStyle::GetBackgroundBottom() const
116{
117 return _bg_bottom;
118}
119
120nux::Color const& PanelStyle::GetTextShadow() const
121{
122 return _text_shadow;
123}
124
125nux::Color const& PanelStyle::GetLineColor() const
126{
127 return _line;
128}113}
129114
130void115void
@@ -137,13 +122,20 @@
137 self->Refresh ();122 self->Refresh ();
138}123}
139124
140GdkPixbuf *125nux::NBitmapData *
141PanelStyle::GetBackground (int width, int height)126PanelStyle::GetBackground (int width, int height)
142{127{
143 gtk_widget_set_size_request (_offscreen, width, height);128 nux::CairoGraphics* context = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);
144 gdk_window_process_updates (gtk_widget_get_window (_offscreen), TRUE);129
145 130 cairo_t* cr = context->GetContext ();
146 return gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (_offscreen));131
132 gtk_render_background (_style_context, cr, 0, 0, width, height);
133
134 nux::NBitmapData* bitmap = context->GetBitmap ();
135
136 delete context;
137
138 return bitmap;
147}139}
148140
149nux::BaseTexture *141nux::BaseTexture *
150142
=== modified file 'plugins/unityshell/src/PanelStyle.h'
--- plugins/unityshell/src/PanelStyle.h 2011-05-13 02:38:16 +0000
+++ plugins/unityshell/src/PanelStyle.h 2011-07-01 17:47:29 +0000
@@ -48,13 +48,9 @@
48 PanelStyle ();48 PanelStyle ();
49 ~PanelStyle ();49 ~PanelStyle ();
5050
51 nux::Color const& GetTextColor() const;51 GtkStyleContext * GetStyleContext ();
52 nux::Color const& GetBackgroundTop() const;
53 nux::Color const& GetBackgroundBottom() const;
54 nux::Color const& GetTextShadow() const;
55 nux::Color const& GetLineColor() const;
5652
57 GdkPixbuf * GetBackground (int width, int height);53 nux::NBitmapData * GetBackground (int width, int height);
5854
59 nux::BaseTexture * GetWindowButton (WindowButtonType type, WindowState state);55 nux::BaseTexture * GetWindowButton (WindowButtonType type, WindowState state);
6056
@@ -71,13 +67,9 @@
71 gpointer data);67 gpointer data);
72 nux::BaseTexture * GetWindowButtonForTheme (WindowButtonType type, WindowState state);68 nux::BaseTexture * GetWindowButtonForTheme (WindowButtonType type, WindowState state);
73 private:69 private:
74 GtkWidget *_offscreen;70 GtkStyleContext *_style_context;
75 char *_theme_name;71 char *_theme_name;
76 nux::Color _text;72 nux::Color _text;
77 nux::Color _bg_top;
78 nux::Color _bg_bottom;
79 nux::Color _text_shadow;
80 nux::Color _line;
8173
82 gulong _gtk_theme_changed_id;74 gulong _gtk_theme_changed_id;
83};75};
8476
=== modified file 'plugins/unityshell/src/PanelView.cpp'
--- plugins/unityshell/src/PanelView.cpp 2011-06-22 14:39:34 +0000
+++ plugins/unityshell/src/PanelView.cpp 2011-07-01 17:47:29 +0000
@@ -187,9 +187,11 @@
187 _last_height = geo.height;187 _last_height = geo.height;
188 _is_dirty = false;188 _is_dirty = false;
189189
190 GdkPixbuf *pixbuf = _style->GetBackground (geo.width, geo.height);190 nux::NBitmapData * bitmap = _style->GetBackground (geo.width, geo.height);
191 nux::BaseTexture * texture2D = nux::CreateTexture2DFromPixbuf (pixbuf, true);191 nux::BaseTexture * texture2D = nux::GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
192 g_object_unref (pixbuf);192 texture2D->Update (bitmap);
193 delete bitmap;
194
193 nux::TexCoordXForm texxform;195 nux::TexCoordXForm texxform;
194 texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);196 texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
195 texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);197 texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);