Skip to content

Commit

Permalink
save/restore window position
Browse files Browse the repository at this point in the history
  • Loading branch information
artemanufrij committed Jan 5, 2018
1 parent d4de4c2 commit f6464ee
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion data/com.github.artemanufrij.playmymusic.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@
</screenshot>
</screenshots>
<releases>
<release version="0.4.2" date="2018-01-02">
<release version="0.4.2" date="2018-01-07">
<description>
<p>New:</p>
<ul>
<li>Show song title from online radio in audio indicator</li>
<li>Save/restore window position</li>
</ul>
<p>Improved:</p>
<ul>
Expand Down
10 changes: 10 additions & 0 deletions schemas/com.github.artemanufrij.playmymusic.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
<summary>The saved height of the window.</summary>
<description>The saved height of the window.</description>
</key>
<key name="window-x" type="i">
<default>-1</default>
<summary>The saved x-position of the window.</summary>
<description>The saved x-position of the window.</description>
</key>
<key name="window-y" type="i">
<default>-1</default>
<summary>The saved y-position of the window.</summary>
<description>The saved y-position of the window.</description>
</key>
<key name="last-artist-id" type="i">
<default>0</default>
<summary>Last Artist ID.</summary>
Expand Down
19 changes: 16 additions & 3 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ 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;
}
return false;
});
this.destroy.connect (() => {
save_settings ();
library_manager.player.stop ();
});

Expand All @@ -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) => {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
}
}
}
}
2 changes: 2 additions & 0 deletions src/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit f6464ee

Please sign in to comment.