Skip to content

Commit 9c86a7d

Browse files
authored
Resize window according to toggle state (#96)
* Hide/show sliders depending on global switch - have a nice animation and window resize doing so * Remove resizing capabilities to allow resize according to toggle state * avoid unclosable window * Make the linter happy
1 parent 9ddb8cd commit 9c86a7d

File tree

3 files changed

+24
-39
lines changed

3 files changed

+24
-39
lines changed

data/com.github.elfenware.badger.gschema.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,5 @@
7777
path="/com/github/elfenware/badger/state/"
7878
id="com.github.elfenware.badger.state"
7979
gettext-domain="com.github.elfenware.badger">
80-
<key name="window-width" type="i">
81-
<default>180</default>
82-
<summary>The saved width of the window.</summary>
83-
<description>The saved width of the window.</description>
84-
</key>
85-
<key name="window-height" type="i">
86-
<default>200</default>
87-
<summary>The saved height of the window.</summary>
88-
<description>The saved height of the window.</description>
89-
</key>
9080
</schema>
9181
</schemalist>

src/MainGrid.vala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,9 @@ public class Badger.MainGrid : Gtk.Box {
182182
/**************************************************/
183183

184184
// If the "all" flag is false, the switch is off, hide the scales
185-
Gtk.Revealer revealer = new Gtk.Revealer ();
185+
this.revealer = new Gtk.Revealer ();
186186
revealer.set_transition_type (Gtk.RevealerTransitionType.SLIDE_DOWN);
187-
settings.bind ("all", revealer, "reveal_child", SettingsBindFlags.DEFAULT);
188-
189187
revealer.set_child (scale_box);
190188
append (revealer);
191-
192189
}
193190
}

src/MainWindow.vala

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public class Badger.MainWindow : Gtk.Window {
3333

3434
construct {
3535
Intl.setlocale ();
36-
settings = new GLib.Settings ("com.github.elfenware.badger.state");
36+
settings = new GLib.Settings ("com.github.elfenware.badger.timers");
37+
38+
// We cannot resize window if it is allowed to change
39+
set_size_request (12, 12);
40+
set_resizable (false);
3741

38-
set_default_size (
39-
settings.get_int ("window-width"),
40-
settings.get_int ("window-height")
41-
);
4242

43-
set_title (_("Badger"));
44-
Gtk.Label title_widget = new Gtk.Label (_("Badger"));
43+
set_title ("Badger");
44+
Gtk.Label title_widget = new Gtk.Label (this.get_title ());
4545
title_widget.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL);
4646

4747
this.headerbar = new Gtk.HeaderBar ();
@@ -59,33 +59,31 @@ public class Badger.MainWindow : Gtk.Window {
5959

6060
set_child (handle);
6161

62-
var global_switch = new GLib.Settings ("com.github.elfenware.badger.timers");
62+
// Avoid showing the window without content despite toggle off.
63+
main.revealer.reveal_child = settings.get_boolean ("all");
6364

64-
// Resize window when content gets hidden
65-
global_switch.notify["all"].connect (() => {
66-
if (global_switch.get_boolean ("all") == false) {
67-
this.height_request = 0;
68-
this.default_height = 0;
69-
print ("eugh");
70-
}
71-
});
65+
// Resize window accordingly to state of global switch
66+
settings.changed["all"].connect ( on_toggle_changed);
7267

73-
// save state
68+
// Avoid a bug whence reopened windows cannot be closed
7469
close_request.connect (e => {
7570
return before_destroy ();
7671
});
7772
}
7873

74+
private void on_toggle_changed () {
75+
debug ("\nToggle changed!");
76+
main.revealer.reveal_child = settings.get_boolean ("all");
7977

80-
// save state
81-
private bool before_destroy () {
82-
int width, height;
83-
84-
get_default_size (out width, out height);
85-
86-
settings.set_int ("window-width", width);
87-
settings.set_int ("window-height", height);
78+
if (!settings.get_boolean ("all")) {
79+
debug ("\nToggle is off! Resizing window");
80+
set_size_request (12, 12);
81+
queue_resize ();
82+
}
83+
}
8884

85+
// Avoid a bug whence reopened windows cannot be closed
86+
private bool before_destroy () {
8987
hide ();
9088
return true;
9189
}

0 commit comments

Comments
 (0)