From f6464ee178c288a742b839af47154ebb5d7557e8 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sat, 6 Jan 2018 00:00:41 +0100 Subject: [PATCH] save/restore window position --- ...ithub.artemanufrij.playmymusic.appdata.xml | 3 ++- ...ithub.artemanufrij.playmymusic.gschema.xml | 10 ++++++++++ src/MainWindow.vala | 19 ++++++++++++++++--- src/Settings.vala | 2 ++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/data/com.github.artemanufrij.playmymusic.appdata.xml b/data/com.github.artemanufrij.playmymusic.appdata.xml index 0addffe..fb93bae 100644 --- a/data/com.github.artemanufrij.playmymusic.appdata.xml +++ b/data/com.github.artemanufrij.playmymusic.appdata.xml @@ -58,11 +58,12 @@ - +

New:

  • Show song title from online radio in audio indicator
  • +
  • Save/restore window position

Improved:

    diff --git a/schemas/com.github.artemanufrij.playmymusic.gschema.xml b/schemas/com.github.artemanufrij.playmymusic.gschema.xml index db53f1c..1e43c80 100644 --- a/schemas/com.github.artemanufrij.playmymusic.gschema.xml +++ b/schemas/com.github.artemanufrij.playmymusic.gschema.xml @@ -15,6 +15,16 @@ The saved height of the window. The saved height of the window. + + -1 + The saved x-position of the window. + The saved x-position of the window. + + + -1 + The saved y-position of the window. + The saved y-position of the window. + 0 Last Artist ID. diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 4080235..21268d9 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -224,6 +224,7 @@ namespace PlayMyMusic { return false; }); this.delete_event.connect (() => { + save_settings (); if (settings.play_in_background && library_manager.player.get_state () == Gst.State.PLAYING) { this.hide_on_delete (); return true; @@ -231,7 +232,6 @@ namespace PlayMyMusic { return false; }); this.destroy.connect (() => { - save_settings (); library_manager.player.stop (); }); @@ -254,8 +254,6 @@ namespace PlayMyMusic { public MainWindow () { load_settings (); - this.window_position = Gtk.WindowPosition.CENTER; - Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.use_dark_theme; build_ui (); load_content_from_database.begin ((obj, res) => { @@ -866,6 +864,14 @@ namespace PlayMyMusic { } else { this.set_default_size (settings.window_width, settings.window_height); } + + if (settings.window_x < 0 && settings.window_y < 0 ) { + this.window_position = Gtk.WindowPosition.CENTER; + } else { + this.move (settings.window_x, settings.window_y); + } + + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.use_dark_theme; } private void save_settings () { @@ -898,6 +904,13 @@ namespace PlayMyMusic { settings.track_progress = 0; settings.track_source = ""; } + + if (!settings.window_maximized) { + int x, y; + this.get_position (out x, out y); + settings.window_x = x; + settings.window_y = y; + } } } } diff --git a/src/Settings.vala b/src/Settings.vala index 56e1836..a79cfef 100644 --- a/src/Settings.vala +++ b/src/Settings.vala @@ -42,6 +42,8 @@ namespace PlayMyMusic { } public int window_width { get; set; } public int window_height { get; set; } + public int window_x { get; set; } + public int window_y { get; set; } public bool window_maximized { get; set; } public bool shuffle_mode { get; set; } public RepeatMode repeat_mode { get; set; }