From 93f6a3a2a0b02da2a0f9f569b2ea6dd589381ae9 Mon Sep 17 00:00:00 2001 From: Marcelo Alexandre Date: Thu, 4 Jul 2019 16:47:58 -0300 Subject: [PATCH 1/3] Change MainWindow to be a Gtk.Window instead of Gtk.Dialog --- src/Windows/MainWindow.vala | 132 +++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/src/Windows/MainWindow.vala b/src/Windows/MainWindow.vala index 87d42c3..0b34af8 100644 --- a/src/Windows/MainWindow.vala +++ b/src/Windows/MainWindow.vala @@ -18,8 +18,8 @@ namespace Tomato.Window { - public class MainWindow : Gtk.Dialog { - private const string COLOR_PRIMARY = """ + public class MainWindow : Gtk.Window { + private const string COLOR_PRIMARY = """ @define-color colorPrimary %s; .main-window.background, @@ -40,11 +40,11 @@ namespace Tomato.Window { private TomatoApp app; - private Gtk.HeaderBar headerbar; + private Gtk.HeaderBar headerbar; private Gtk.MenuButton appmenu; private Gtk.MenuItem preferences; private Widget.Slide slide; - private Gtk.Box content; + private Gtk.Box content; private Gtk.Label countdown_label; private Gtk.Label total_time_label; @@ -56,8 +56,6 @@ namespace Tomato.Window { // constructor public MainWindow (TomatoApp app) { - Object (use_header_bar: 1); - this.app = app; this.title = Constants.APP_NAME; this.set_position (Gtk.WindowPosition.CENTER); @@ -75,28 +73,30 @@ namespace Tomato.Window { stop = new Gtk.Button.with_label (_("Stop")); skip = new Gtk.Button.with_label (_("Skip")); - content = this.get_content_area (); - headerbar = this.get_header_bar () as Gtk.HeaderBar; + content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + headerbar = new Gtk.HeaderBar (); setup_layout (); setup_style (); connect_signals (); + add (content); show_all (); update_progress (); next_status (Gtk.StackTransitionType.NONE); - /** - * Allow moving the window - */ - this.button_press_event.connect ((e) => { - if (e.button == Gdk.BUTTON_PRIMARY) { - this.begin_move_drag ((int) e.button, (int) e.x_root, (int) e.y_root, e.time); - return true; - } - return false; - }); + + /** + * Allow moving the window + */ + this.button_press_event.connect ((e) => { + if (e.button == Gdk.BUTTON_PRIMARY) { + this.begin_move_drag ((int) e.button, (int) e.x_root, (int) e.y_root, e.time); + return true; + } + return false; + }); } public void set_pause (bool topause = true) { @@ -164,6 +164,8 @@ namespace Tomato.Window { } private void setup_headerbar () { + headerbar.show_close_button = true; + appmenu = new Gtk.MenuButton (); preferences = new Gtk.MenuItem.with_label (_("Preferences…")); @@ -176,13 +178,15 @@ namespace Tomato.Window { appmenu.set_image (menu_icon); appmenu.popup = menu; - appmenu.valign = Gtk.Align.CENTER; + appmenu.valign = Gtk.Align.CENTER; + + appmenu.get_style_context ().add_class ("close"); + appmenu.get_style_context ().add_class ("titlebutton"); + appmenu.get_style_context ().remove_class ("image-button"); - appmenu.get_style_context ().add_class ("close"); - appmenu.get_style_context ().add_class ("titlebutton"); - appmenu.get_style_context ().remove_class ("image-button"); + headerbar.pack_end (appmenu); - headerbar.pack_end (appmenu); + set_titlebar (headerbar); } private void setup_stack () { @@ -203,7 +207,7 @@ namespace Tomato.Window { private void setup_layout () { setup_headerbar (); setup_stack (); - content.add (slide); + content.pack_start (slide, false, false, 0); } private void setup_style () { @@ -227,12 +231,12 @@ namespace Tomato.Window { resume.get_style_context ().add_class ("pomodoro-button"); pause.get_style_context ().add_class ("pomodoro-button"); stop.get_style_context ().add_class ("pomodoro-button"); - start.get_style_context ().add_class ("pomodoro-button"); + start.get_style_context ().add_class ("pomodoro-button"); - headerbar.get_style_context ().add_class ("compact"); - headerbar.get_style_context ().add_class ("main-window"); + headerbar.get_style_context ().add_class ("compact"); + headerbar.get_style_context ().add_class ("main-window"); - this.get_style_context ().add_class ("main-window"); + this.get_style_context ().add_class ("main-window"); } private void connect_signals () { @@ -243,45 +247,45 @@ namespace Tomato.Window { skip.clicked.connect (() => {skip_clicked ();}); preferences.activate.connect (() => {preferences_clicked ();}); - this.slide.changed.connect ((s) => { - string color_primary; - - switch (s.get_name ()) { - case "start": - color_primary = "#8ea5af"; - break; - case "pomodoro": - color_primary = "#df4b4b"; - break; - case "break": - color_primary = "#05B560"; - break; - default: - color_primary = "#8ea5af"; - break; - } - - var provider = new Gtk.CssProvider (); - try { - var colored_css = COLOR_PRIMARY.printf (color_primary); - provider.load_from_data (colored_css, colored_css.length); - - Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - } catch (GLib.Error e) { - critical (e.message); - } - }); + this.slide.changed.connect ((s) => { + string color_primary; + + switch (s.get_name ()) { + case "start": + color_primary = "#8ea5af"; + break; + case "pomodoro": + color_primary = "#df4b4b"; + break; + case "break": + color_primary = "#05B560"; + break; + default: + color_primary = "#8ea5af"; + break; + } + + var provider = new Gtk.CssProvider (); + try { + var colored_css = COLOR_PRIMARY.printf (color_primary); + provider.load_from_data (colored_css, colored_css.length); + + Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } catch (GLib.Error e) { + critical (e.message); + } + }); this.delete_event.connect (quit); } - private bool quit () { - if (!paused) { - hide (); - return true; - } - Gtk.main_quit (); - return false; - } + private bool quit () { + if (!paused) { + hide (); + return true; + } + Gtk.main_quit (); + return false; + } } } From 634f9bae109ab6c64c6b48fbc196af5167ed5579 Mon Sep 17 00:00:00 2001 From: Marcelo Alexandre Date: Thu, 4 Jul 2019 16:48:41 -0300 Subject: [PATCH 2/3] Fix deprecation about icon-shadow property --- data/style/window.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/style/window.css b/data/style/window.css index cbbe9ca..4ca47dd 100644 --- a/data/style/window.css +++ b/data/style/window.css @@ -15,7 +15,7 @@ .main-window.background { background-color: @colorPrimary; color: #fff; - icon-shadow: 0 1px 1px shade (@colorPrimary, 0.82); + -gtk-icon-shadow: 0 1px 1px shade (@colorPrimary, 0.82); text-shadow: 0 1px 1px shade (@colorPrimary, 0.82); } @@ -23,7 +23,7 @@ color: #fff; font-size: 12px; text-shadow: none; - icon-shadow: none; + -gtk-icon-shadow: none; } .main-window .titlebar image { From d62529323d9cf3b27d3f344ef9f28da4d5650bbb Mon Sep 17 00:00:00 2001 From: Marcelo Alexandre Date: Thu, 4 Jul 2019 17:08:15 -0300 Subject: [PATCH 3/3] Add Gtk.STYLE_CLASS_FLAT to the header --- src/Windows/MainWindow.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Windows/MainWindow.vala b/src/Windows/MainWindow.vala index 0b34af8..7e5c2a2 100644 --- a/src/Windows/MainWindow.vala +++ b/src/Windows/MainWindow.vala @@ -235,6 +235,7 @@ namespace Tomato.Window { headerbar.get_style_context ().add_class ("compact"); headerbar.get_style_context ().add_class ("main-window"); + headerbar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); this.get_style_context ().add_class ("main-window"); }