Merge lp:~victored/granite/thin-paned-gtk-3-13 into lp:~elementary-pantheon/granite/granite

Proposed by Victor Martinez
Status: Rejected
Rejected by: Victor Martinez
Proposed branch: lp:~victored/granite/thin-paned-gtk-3-13
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 168 lines (+46/-19)
2 files modified
lib/Widgets/ThinPaned.vala (+44/-18)
lib/style-classes.vala (+2/-1)
To merge this branch: bzr merge lp:~victored/granite/thin-paned-gtk-3-13
Reviewer Review Type Date Requested Status
Victor Martinez (community) Disapprove
Review via email: mp+224047@code.launchpad.net

Commit message

Disable ThinPaned's features with Gtk 3.13, to make it act like a normal GtkPaned.

The style class "thin-paned" will also be present in ThinPaned with Gtk 3.13+

Description of the change

GTK+ 3.13 supports defining overlay pane separator handles from the theme, and ThinPaned will be deprecated in favor of that.

As it seems we're still unsure whether we will be shipping GTK+ 3.12 or 3.14 in Freya, I've added a runtime check to ThinPaned to make the same Granite binary work with both versions.

Basically what this does is disabling ThinPaned's overlay GdkWindow, handle-drawing code, and event handling, so it doesn't override the behavior provided by GtkPaned in GTK+ 3.13.

Notice that ThinPaned adds the style class "thin-paned" with GTK+ 3.13, which can be used as follows:

/* this will match the entire GtkPaned widget */
.thin-paned {
    -GtkPaned-handle-size: 1px;
    border-width: 0;

    /*
     the handle's margins are applied to the entire paned and not the
     pane-separator class, as that one is only used for drawing purposes
    */

    /* additional invisible pixels to add above pane separator for vertically-stacked panes */
    margin-top: 3px;

    /* additional invisible pixels to add below pane separator for vertically-stacked panes */
    margin-bottom: 2px;

    /* additional invisible pixels to add on left side of the pane separator for horizontally-stacked panes */
    margin-left: 2px; /* avoid conflicting with scrollbar */

    /* additional invisible pixels to add on right side of the pane separator for horizontally-stacked panes */
    margin-right: 4px;

    /* optionally, we could simply use 'margin' */
    margin: 3px;
}

/* theme pane separator */
.thin-paned.pane-separator {
   background-color: black;
   border-width: 0;
}

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

This branch is no longer relevant, as it seems we'll simply wait for the release of GTK+ 3.14.

Let's do a clean deprecation when the time comes.

review: Disapprove

Unmerged revisions

742. By Victor Martinez

Add runtime check for GTK+ 3.13 or newer, and make ThinPaned behave as a normal GtkPaned with a style class called "thin-paned".

ThinPaned behaves as usual with Gtk 3.12 or older.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/ThinPaned.vala'
2--- lib/Widgets/ThinPaned.vala 2014-04-04 03:47:51 +0000
3+++ lib/Widgets/ThinPaned.vala 2014-06-22 17:48:43 +0000
4@@ -52,6 +52,7 @@
5
6 private Gdk.Window overlay_handle;
7 private bool in_resize = false;
8+ private bool use_legacy_gdk_window;
9
10 static construct {
11 install_style_property (new ParamSpecInt (STYLE_PROP_OVERLAY_HANDLE_SIZE,
12@@ -63,17 +64,30 @@
13
14 public ThinPaned (Gtk.Orientation orientation = Gtk.Orientation.HORIZONTAL) {
15 this.orientation = orientation;
16- Utils.set_theming (this, DEFAULT_STYLESHEET, null, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
17- Utils.set_theming (this, FALLBACK_STYLESHEET, null, Gtk.STYLE_PROVIDER_PRIORITY_THEME);
18+
19+ // GtkPaned is already capable of showing an overlay handle since version 3.13,
20+ // so we disable ThinPaned's features at runtime when this version is detected,
21+ // at least until our widget is properly deprecated.
22+ use_legacy_gdk_window = (Gtk.get_minor_version () < 13);
23+
24+ if (use_legacy_gdk_window) {
25+ Utils.set_theming (this, DEFAULT_STYLESHEET, null, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
26+ Utils.set_theming (this, FALLBACK_STYLESHEET, null, Gtk.STYLE_PROVIDER_PRIORITY_THEME);
27+ } else {
28+ get_style_context ().add_class (StyleClass.THIN_PANED);
29+ }
30 }
31
32 public unowned Gdk.Window get_overlay_handle_window () {
33- return overlay_handle;
34+ return use_legacy_gdk_window ? overlay_handle : get_handle_window ();
35 }
36
37 public override void realize () {
38 base.realize ();
39
40+ if (!use_legacy_gdk_window)
41+ return;
42+
43 // Create invisible overlay handle
44 var attributes = Gdk.WindowAttr ();
45
46@@ -105,27 +119,34 @@
47
48 public override void unrealize () {
49 base.unrealize ();
50- overlay_handle.set_user_data (null);
51- overlay_handle.destroy ();
52- overlay_handle = null;
53+
54+ if (use_legacy_gdk_window) {
55+ overlay_handle.set_user_data (null);
56+ overlay_handle.destroy ();
57+ overlay_handle = null;
58+ }
59 }
60
61 public override void map () {
62 base.map ();
63- overlay_handle.show ();
64+
65+ if (use_legacy_gdk_window)
66+ overlay_handle.show ();
67 }
68
69 public override void unmap () {
70 base.unmap ();
71- overlay_handle.hide ();
72+
73+ if (use_legacy_gdk_window)
74+ overlay_handle.hide ();
75 }
76
77 public override bool draw (Cairo.Context ctx) {
78- base.draw (ctx);
79+ bool rv = base.draw (ctx);
80
81 // if the overlay handle is not visible, don't draw a pane separator.
82- if (!overlay_handle.is_visible ())
83- return false;
84+ if (!use_legacy_gdk_window || !overlay_handle.is_visible ())
85+ return rv;
86
87 Gtk.Allocation allocation;
88 get_allocation (out allocation);
89@@ -171,7 +192,9 @@
90
91 public override void size_allocate (Gtk.Allocation allocation) {
92 base.size_allocate (allocation);
93- update_overlay_handle ();
94+
95+ if (use_legacy_gdk_window)
96+ update_overlay_handle ();
97 }
98
99 private void update_overlay_handle () {
100@@ -212,7 +235,7 @@
101 public override void state_flags_changed (Gtk.StateFlags previous_state) {
102 base.state_flags_changed (previous_state);
103
104- if (get_realized ()) {
105+ if (use_legacy_gdk_window && get_realized ()) {
106 var default_handle_cursor = get_handle_window ().get_cursor ();
107 if (overlay_handle.get_cursor () != default_handle_cursor)
108 overlay_handle.set_cursor (default_handle_cursor);
109@@ -220,7 +243,7 @@
110 }
111
112 public override bool motion_notify_event (Gdk.EventMotion event) {
113- if (!in_resize)
114+ if (!use_legacy_gdk_window || !in_resize)
115 return base.motion_notify_event (event);
116
117 var device = event.device ?? Gtk.get_current_event_device ();
118@@ -257,7 +280,8 @@
119 }
120
121 public override bool button_press_event (Gdk.EventButton event) {
122- if (!in_resize && event.button == Gdk.BUTTON_PRIMARY && event.window == overlay_handle) {
123+ if (use_legacy_gdk_window && !in_resize && event.button == Gdk.BUTTON_PRIMARY
124+ && event.window == overlay_handle) {
125 in_resize = true;
126 Gtk.grab_add (this);
127 return true;
128@@ -267,7 +291,7 @@
129 }
130
131 public override bool button_release_event (Gdk.EventButton event) {
132- if (event.window == overlay_handle) {
133+ if (use_legacy_gdk_window && event.window == overlay_handle) {
134 in_resize = false;
135 Gtk.grab_remove (this);
136 return true;
137@@ -277,7 +301,9 @@
138 }
139
140 public override bool grab_broken_event (Gdk.EventGrabBroken event) {
141- in_resize = false;
142+ if (use_legacy_gdk_window)
143+ in_resize = false;
144+
145 return base.grab_broken_event (event);
146 }
147-}
148+}
149\ No newline at end of file
150
151=== modified file 'lib/style-classes.vala'
152--- lib/style-classes.vala 2014-04-18 19:35:30 +0000
153+++ lib/style-classes.vala 2014-06-22 17:48:43 +0000
154@@ -28,6 +28,7 @@
155 public const string POPOVER = "popover";
156 public const string POPOVER_BG = "popover_bg";
157 public const string HELP_BUTTON = "help_button";
158+ public const string THIN_PANED = "thin-paned";
159 public const string THIN_PANE_SEPARATOR = "sidebar-pane-separator";
160 public const string OVERLAY_BAR = "overlay-bar";
161
162@@ -35,4 +36,4 @@
163 public const string H1_TEXT = "h1";
164 public const string H2_TEXT = "h2";
165 public const string H3_TEXT = "h3";
166-}
167+}
168\ No newline at end of file

Subscribers

People subscribed via source and target branches