[geary] Set the window decoration buttons correctly in GTK >= 3.12
- From: Robert Schroll <rschroll src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Set the window decoration buttons correctly in GTK >= 3.12
- Date: Fri, 20 Mar 2015 20:25:06 +0000 (UTC)
commit 30500a7b3974d7eafd7cd2f3aa3ba76365f07271
Author: Robert Schroll <rschroll gmail com>
Date: Mon Mar 16 19:48:11 2015 -0400
Set the window decoration buttons correctly in GTK >= 3.12
The folder headerbar should get those going to the left side of the
window, and the conversation and new composer headers should get those
going to the right.
https://bugzilla.gnome.org/show_bug.cgi?id=746315
src/client/components/main-toolbar.vala | 39 +++++++++++++++++++-------
src/client/components/pill-toolbar.vala | 17 +++++++++++
src/client/composer/composer-headerbar.vala | 19 +++++++------
3 files changed, 55 insertions(+), 20 deletions(-)
---
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 3cfc30d..dfa5c52 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -11,8 +11,8 @@ public class MainToolbar : Gtk.Box {
public string account { get; set; }
public string folder { get; set; }
public bool show_close_button { get; set; default = false; }
- public bool show_close_button_left { get; private set; }
- public bool show_close_button_right { get; private set; }
+ public bool show_close_button_left { get; private set; default = true; }
+ public bool show_close_button_right { get; private set; default = true; }
public bool search_open { get; set; default = false; }
public int left_pane_width { get; set; }
@@ -150,8 +150,13 @@ public class MainToolbar : Gtk.Box {
pack_start(folder_header, false, false);
pack_start(conversation_header, true, true);
+#if GTK_3_12
+ Gtk.Settings.get_default().notify["gtk-decoration-layout"].connect(set_window_buttons);
+ realize.connect(set_window_buttons);
+#else
get_style_context().changed.connect(set_close_buttons_side);
realize.connect(set_close_buttons_side);
+#endif
}
/// Updates the trash button as trash or delete, and shows or hides the archive button.
@@ -170,6 +175,9 @@ public class MainToolbar : Gtk.Box {
guest_header_binding = bind_property("show-close-button-right", header,
"show-close-button", BindingFlags.SYNC_CREATE);
pack_start(header, true, true);
+#if GTK_3_12
+ header.decoration_layout = conversation_header.decoration_layout;
+#endif
}
public void remove_conversation_header(Gtk.HeaderBar header) {
@@ -178,21 +186,30 @@ public class MainToolbar : Gtk.Box {
header.get_style_context().remove_class("geary-titlebar-right");
GtkUtil.unbind(guest_header_binding);
header.show_close_button = false;
+#if GTK_3_12
+ header.decoration_layout = Gtk.Settings.get_default().gtk_decoration_layout;
+#endif
conversation_header.show();
}
- private void set_close_buttons_side() {
- string layout;
- bool at_end = false;
- get_toplevel().style_get("decoration-button-layout", out layout);
- // Based on logic of close_button_at_end in gtkheaderbar.c: Close button appears
- // at end iff "close" follows a colon in the layout string.
- if (layout != null) {
- int colon_ind = layout.index_of(":");
- at_end = (colon_ind >= 0 && layout.index_of("close", colon_ind) >= 0);
+#if GTK_3_12
+ private void set_window_buttons() {
+ string[] buttons = Gtk.Settings.get_default().gtk_decoration_layout.split(":");
+ if (buttons.length != 2) {
+ warning("gtk_decoration_layout in unexpected format");
+ return;
}
+ show_close_button_left = show_close_button;
+ show_close_button_right = show_close_button;
+ folder_header.decoration_layout = buttons[0] + ":";
+ conversation_header.decoration_layout = ":" + buttons[1];
+ }
+#else
+ private void set_close_buttons_side() {
+ bool at_end = folder_header.close_button_at_end();
show_close_button_left = show_close_button && !at_end;
show_close_button_right = show_close_button && at_end;
}
+#endif
}
diff --git a/src/client/components/pill-toolbar.vala b/src/client/components/pill-toolbar.vala
index 02f888a..559058c 100644
--- a/src/client/components/pill-toolbar.vala
+++ b/src/client/components/pill-toolbar.vala
@@ -129,6 +129,23 @@ public class PillHeaderbar : Gtk.HeaderBar, PillBar {
public PillHeaderbar(Gtk.ActionGroup toolbar_action_group) {
initialize(toolbar_action_group);
}
+
+ public bool close_button_at_end() {
+ string layout;
+ bool at_end = false;
+#if GTK_3_12
+ layout = decoration_layout;
+#else
+ get_toplevel().style_get("decoration-button-layout", out layout);
+#endif
+ // Based on logic of close_button_at_end in gtkheaderbar.c: Close button appears
+ // at end iff "close" follows a colon in the layout string.
+ if (layout != null) {
+ int colon_ind = layout.index_of(":");
+ at_end = (colon_ind >= 0 && layout.index_of("close", colon_ind) >= 0);
+ }
+ return at_end;
+ }
}
/**
diff --git a/src/client/composer/composer-headerbar.vala b/src/client/composer/composer-headerbar.vala
index 5e1a145..7b67dcc 100644
--- a/src/client/composer/composer-headerbar.vala
+++ b/src/client/composer/composer-headerbar.vala
@@ -108,11 +108,20 @@ public class ComposerHeaderbar : PillHeaderbar {
add_end(close_buttons);
add_end(send_button);
#endif
+
+#if GTK_3_12
+ notify["decoration-layout"].connect(set_detach_button_side);
+#else
get_style_context().changed.connect(set_detach_button_side);
+#endif
realize.connect(set_detach_button_side);
notify["state"].connect((s, p) => {
if (state == ComposerWidget.ComposerState.DETACHED) {
+#if GTK_3_12
+ notify["decoration-layout"].disconnect(set_detach_button_side);
+#else
get_style_context().changed.disconnect(set_detach_button_side);
+#endif
detach_start.visible = detach_end.visible = false;
}
});
@@ -124,15 +133,7 @@ public class ComposerHeaderbar : PillHeaderbar {
}
private void set_detach_button_side() {
- string layout;
- bool at_end = false;
- get_toplevel().style_get("decoration-button-layout", out layout);
- // Based on logic of close_button_at_end in gtkheaderbar.c: Close button appears
- // at end iff "close" follows a colon in the layout string.
- if (layout != null) {
- int colon_ind = layout.index_of(":");
- at_end = (colon_ind >= 0 && layout.index_of("close", colon_ind) >= 0);
- }
+ bool at_end = close_button_at_end();
detach_start.visible = !at_end;
detach_end.visible = at_end;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]