Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Change MainWindow to be a Gtk.Window instead of Gtk.Dialog #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/style/window.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
.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);
}

.main-window .titlebar .title {
color: #fff;
font-size: 12px;
text-shadow: none;
icon-shadow: none;
-gtk-icon-shadow: none;
}

.main-window .titlebar image {
Expand Down
133 changes: 69 additions & 64 deletions src/Windows/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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…"));
Expand All @@ -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 () {
Expand All @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
content.pack_start (slide, false, false, 0);
content.add (slide);

}

private void setup_style () {
Expand All @@ -227,12 +231,13 @@ 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");
headerbar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

this.get_style_context ().add_class ("main-window");
this.get_style_context ().add_class ("main-window");
}

private void connect_signals () {
Expand All @@ -243,45 +248,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;
}
}
}