Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
remember last window size
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Sep 20, 2023
1 parent c4db25a commit 5fed880
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions data/com.vixalien.decibels.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="decibels">
<schema id="com.vixalien.decibels" path="/com/vixalien/decibels/">
<key name="last-window-size" type="(ii)">
<default>(-1,-1)</default>
<summary>Last width &amp; height of window</summary>
<description>The saved last size of the window (to be restored)</description>
</key>
</schema>
</schemalist>
4 changes: 3 additions & 1 deletion src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Gtk from "gi://Gtk?version=4.0";

import { Window } from "./window.js";

export const Settings = new Gio.Settings({ schema: pkg.name });

export class Application extends Adw.Application {
private window?: Window;

Expand All @@ -25,7 +27,7 @@ export class Application extends Adw.Application {

this.add_action(quit_action);
this.set_accels_for_action("app.quit", ["<Control>q"]);

this.set_accels_for_action("win.open-file", ["<Control>o"]);

const show_about_action = new Gio.SimpleAction({ name: "about" });
Expand Down
20 changes: 20 additions & 0 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { APEmptyState } from "./empty.js";
import { APErrorState } from "./error.js";
import { APPlayerState } from "./player.js";
import { MPRIS } from "./mpris.js";
import { Settings } from "./application.js";

Gio._promisify(Gtk.FileDialog.prototype, "open", "open_finish");

Expand Down Expand Up @@ -76,6 +77,14 @@ export class Window extends Adw.ApplicationWindow {
constructor(params?: Partial<Adw.ApplicationWindow.ConstructorProperties>) {
super(params);

const window_size = Settings.get_value("last-window-size");

const width = window_size.get_child_value(0).get_int32();
const height = window_size.get_child_value(1).get_int32();

if (width > 0) this.default_width = width;
if (height > 0) this.default_height = height;

this.stream = new APMediaStream();

this.insert_action_group("player", this.stream.get_action_group());
Expand Down Expand Up @@ -176,4 +185,15 @@ export class Window extends Adw.ApplicationWindow {

this._error.show_error(title, error);
}

vfunc_close_request() {
const window_size = GLib.Variant.new("(ii)", [
this.get_width(),
this.get_height(),
]);

Settings.set_value("last-window-size", window_size);

return super.vfunc_close_request();
}
}

0 comments on commit 5fed880

Please sign in to comment.