Merge lp:~victored/granite/decorated-window-api-fixes into lp:~elementary-pantheon/granite/granite

Proposed by Victor Martinez
Status: Merged
Approved by: xapantu
Approved revision: 265
Merged at revision: 295
Proposed branch: lp:~victored/granite/decorated-window-api-fixes
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 217 lines (+67/-63)
1 file modified
lib/Widgets/DecoratedWindow.vala (+67/-63)
To merge this branch: bzr merge lp:~victored/granite/decorated-window-api-fixes
Reviewer Review Type Date Requested Status
xapantu (community) Approve
Review via email: mp+112688@code.launchpad.net

Description of the change

Modify DecoratedWindow to use the GtkWindow API as much as possible.

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

Looks fine, using more Gtk apis can only work better :) Thanks :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/DecoratedWindow.vala'
2--- lib/Widgets/DecoratedWindow.vala 2012-06-13 22:35:33 +0000
3+++ lib/Widgets/DecoratedWindow.vala 2012-06-29 03:00:32 +0000
4@@ -27,7 +27,7 @@
5
6 public class DecoratedWindow : CompositedWindow {
7
8- const string DECORATED_WINDOW_FALLBACK_STYLESHEET = """
9+ static const string DECORATED_WINDOW_FALLBACK_STYLESHEET = """
10 .decorated-window {
11 border-style:solid;
12 border-color:alpha (#000, 0.35);
13@@ -38,7 +38,7 @@
14 """;
15
16 // Currently not overridable
17- const string DECORATED_WINDOW_STYLESHEET = """
18+ static const string DECORATED_WINDOW_STYLESHEET = """
19 .decorated-window { border-width:1px; }
20 """;
21
22@@ -55,34 +55,13 @@
23
24 ref_window.get_style_context ().add_class (STYLE_CLASS_DECORATED_WINDOW);
25
26- ref_window.get_style_context ().add_provider (normal_style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
27- ref_window.get_style_context ().add_provider (fallback_style, Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);
28- }
29-
30- bool _show_close_button = true;
31- public bool show_close_button {
32- get {
33- return _show_close_button;
34- }
35- set {
36- _show_close_button = value;
37- w = -1; h = -1; // get it to redraw the buffer
38- Gtk.Allocation alloc;
39- this.get_allocation (out alloc);
40- this.size_allocate (alloc);
41-
42- this.queue_draw ();
43- }
44- }
45-
46- /**
47- * Whether to hide or destroy the window when the close button is clicked.
48- * By default, the window is destroyed. You can change that by changing this
49- * property to 'true'.
50- *
51- * Default: false;
52- */
53- public bool hide_on_close { get; set; default = false; }
54+ ref_window.get_style_context ().add_provider (normal_style,
55+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
56+ ref_window.get_style_context ().add_provider (fallback_style,
57+ Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);
58+ }
59+
60+ public bool show_title { get; set; default = true; }
61
62 protected Gtk.Box box { get; private set; }
63 protected Gtk.Window draw_ref { get; private set; }
64@@ -104,55 +83,70 @@
65
66 private Gtk.Label _title;
67
68- public new string title {
69- get { return _title.label; }
70- set { _title.label = value; }
71- }
72-
73 public DecoratedWindow (string title = "", string? window_style = null, string? content_style = null) {
74- this.resizable = true;
75+ this.resizable = false;
76 this.has_resize_grip = false;
77 this.window_position = Gtk.WindowPosition.CENTER_ON_PARENT;
78
79- this._title = new Gtk.Label (title);
80- this._title.margin_top = 5;
81+ this.close_img = get_close_pixbuf ();
82+
83+ this._title = new Gtk.Label (null);
84+ this._title.halign = Gtk.Align.CENTER;
85+ this._title.hexpand = false;
86+ this._title.ellipsize = Pango.EllipsizeMode.MIDDLE;
87+ this._title.single_line_mode = true;
88+ this._title.margin = 6;
89+ this._title.margin_left = this._title.margin_right = 6 + this.close_img.get_width () / 3;
90 var attr = new Pango.AttrList ();
91 attr.insert (new Pango.AttrFontDesc (Pango.FontDescription.from_string ("bold")));
92 this._title.attributes = attr;
93
94+ this.notify["title"].connect ( () => {
95+ this._title.label = this.title;
96+ });
97+
98+ this.notify["show-title"].connect ( () => {
99+ this._title.visible = this.show_title;
100+ });
101+
102+ this.notify["deletable"].connect ( () => {
103+ w = -1; h = -1; // get it to redraw the buffer
104+ this.queue_resize ();
105+ this.queue_draw ();
106+ });
107+
108+ this.title = title;
109+ this.deletable = true;
110+
111 this.box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
112+ this.box.margin = SHADOW_BLUR + 1; // SHADOW_BLUR + border_width
113+
114 this.draw_ref = new Gtk.Window ();
115
116 // set theming
117- set_default_theming (draw_ref);
118+ set_default_theming (this.draw_ref);
119
120 // extra theming
121 if (window_style != null && window_style != "")
122- draw_ref.get_style_context ().add_class (window_style);
123+ this.draw_ref.get_style_context ().add_class (window_style);
124
125 if (content_style != null && content_style != "")
126- box.get_style_context ().add_class (content_style);
127-
128- close_img = get_close_pixbuf ();
129-
130- this.size_allocate.connect (on_size_allocate);
131- this.draw.connect (draw_widget);
132+ this.box.get_style_context ().add_class (content_style);
133+
134+ this.box.pack_start (this._title, false);
135+ base.add (this.box);
136
137 this.add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK);
138-
139 this.motion_notify_event.connect (on_motion_notify);
140 this.button_press_event.connect (on_button_press);
141-
142- box.pack_start (_title, false);
143-
144- box.margin = SHADOW_BLUR + 1; // SHADOW_BLUR + border_width
145-
146- base.add (this.box);
147+ this.delete_event.connect_after (on_delete_event);
148+ this.size_allocate.connect (on_size_allocate);
149+ this.draw.connect (draw_widget);
150 }
151
152
153 public new void add (Gtk.Widget w) {
154- this.box.pack_start (w);
155+ this.box.pack_start (w, true, true);
156 }
157
158 public new void remove (Gtk.Widget w) {
159@@ -185,17 +179,19 @@
160 this.buffer.context.fill ();
161 this.buffer.exponential_blur (SHADOW_BLUR / 2);
162
163- draw_ref.get_style_context ().render_activity (this.buffer.context, x, y, width, height);
164+ draw_ref.get_style_context ().render_activity (this.buffer.context,
165+ x, y, width, height);
166
167- if (this.show_close_button) {
168- Gdk.cairo_set_source_pixbuf (this.buffer.context, close_img, SHADOW_BLUR / 2 + CLOSE_BUTTON_X,
169+ if (this.deletable) {
170+ Gdk.cairo_set_source_pixbuf (this.buffer.context, close_img,
171+ SHADOW_BLUR / 2 + CLOSE_BUTTON_X,
172 SHADOW_BLUR / 2 + CLOSE_BUTTON_Y);
173 this.buffer.context.paint ();
174 }
175 }
176
177 private bool on_motion_notify (Gdk.EventMotion e) {
178- if (show_close_button && coords_over_close_button (e.x, e.y))
179+ if (coords_over_close_button (e.x, e.y))
180 this.get_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.HAND1));
181 else
182 this.get_window ().set_cursor (null);
183@@ -205,10 +201,10 @@
184
185 private bool on_button_press (Gdk.EventButton e) {
186 if (coords_over_close_button (e.x, e.y)) {
187- if (hide_on_close)
188- this.hide ();
189- else
190- this.destroy ();
191+ var event = new Gdk.Event (Gdk.EventType.DELETE);
192+ event.any.window = e.window;
193+ event.any.send_event = e.send_event;
194+ this.delete_event (event.any);
195 }
196 else {
197 this.begin_move_drag ((int)e.button, (int)e.x_root, (int)e.y_root, e.time);
198@@ -218,10 +214,18 @@
199 }
200
201 private bool coords_over_close_button (double x, double y) {
202- return x > (SHADOW_BLUR / 2 + CLOSE_BUTTON_X) &&
203+ return this.deletable &&
204+ x > (SHADOW_BLUR / 2 + CLOSE_BUTTON_X) &&
205 x < (close_img.get_width () + SHADOW_BLUR / 2 + CLOSE_BUTTON_X) &&
206 y > (SHADOW_BLUR / 2 + CLOSE_BUTTON_Y) &&
207 y < (close_img.get_height () + SHADOW_BLUR / 2 + CLOSE_BUTTON_Y);
208 }
209+
210+ private bool on_delete_event (Gdk.EventAny event) {
211+ if (this.deletable)
212+ this.destroy ();
213+
214+ return false;
215+ }
216 }
217 }

Subscribers

People subscribed via source and target branches