Skip to content

Commit c80fbe9

Browse files
authored
Merge pull request kran27#7 from DashTheDev/main
Add Window Position Saving
2 parents be3600a + 0eba582 commit c80fbe9

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.vs/
2-
out/
2+
.vscode/
3+
out/
4+
build/
5+
releases/

spotifyamp.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ bool MainWindow::Load() {
369369
InitThreading();
370370
RegisterForGlobalHotkeys();
371371

372+
LoadPosition(0, 0);
373+
372374
bool compact = PrefReadBool(false, "compact");
373375
compact_ = !compact;
374376
SetCompact(compact);
@@ -845,8 +847,6 @@ void MainWindow::Paint() {
845847

846848
void MainWindow::SetDoubleSize(bool v) {
847849
PlatformWindow::SetDoubleSize(v);
848-
eq_window_->SetDoubleSize(v);
849-
PrefWriteInt(v, "double_size");
850850
SetVisualizer(24, 43, 76, 16);
851851
}
852852

@@ -980,7 +980,12 @@ void MainWindow::Perform(int cmd) {
980980
if (const char *s = PlatformReadClipboard())
981981
TspPlayerPlayContext(tsp_, s, NULL, 0);
982982
break;
983-
case CMD_DOUBLE_SIZE: SetDoubleSize(!double_size()); break;
983+
case CMD_DOUBLE_SIZE: {
984+
bool is_double_size(!double_size());
985+
PrefWriteInt(is_double_size, "double_size");
986+
SetDoubleSize(is_double_size);
987+
eq_window_->SetDoubleSize(is_double_size);
988+
} break;
984989
case CMD_ALWAYS_ON_TOP: SetAlwaysOnTop(!always_on_top()); break;
985990
case CMD_COMPACT: SetCompact(!compact_); break;
986991
case CMD_LOGIN: ShowLoginDialog(); break;
@@ -1514,6 +1519,7 @@ void MainWindow::GlobalHotkey(int id) {
15141519
// PLAYLIST WINDOW
15151520
///////////////////////////////////////////////////////////
15161521
PlaylistWindow::PlaylistWindow(MainWindow *main_window) {
1522+
id_ = 1;
15171523
main_window_ = main_window;
15181524
hover_button_ = -1;
15191525
Resize(WND_MAIN_W, WND_MAIN_H * 3);
@@ -1524,6 +1530,7 @@ PlaylistWindow::~PlaylistWindow() {
15241530
}
15251531

15261532
void PlaylistWindow::Load() {
1533+
LoadPosition(main_window.screen_rect()->left, main_window.screen_rect()->bottom);
15271534
SetCompact(PrefReadBool(false, "pl.compact"));
15281535
font_size_ = PrefReadInt(10, "pl.font_size");
15291536
row_height_ = 13;
@@ -1997,6 +2004,7 @@ void PlaylistWindow::Perform(int cmd) {
19972004
// EQUALIZER WINDOW
19982005
///////////////////////////////////////////////////////////
19992006
EqWindow::EqWindow(MainWindow *main_window) {
2007+
id_ = 2;
20002008
main_window_ = main_window;
20012009
hover_button_ = -1;
20022010
hover_eq_ = -1;
@@ -2014,6 +2022,8 @@ void EqWindow::Load() {
20142022
gain_mode_ = PrefReadInt(0, "eq.gain_mode");
20152023
CopyToTsp();
20162024

2025+
LoadPosition(main_window.screen_rect()->right, main_window.screen_rect()->top);
2026+
SetDoubleSize(PrefReadBool(false, "double_size"));
20172027
SetCompact(PrefReadBool(false, "eq.compact"));
20182028
}
20192029

@@ -2375,6 +2385,7 @@ void EqWindow::ShowPresets() {
23752385

23762386

23772387
GenWindow::GenWindow() {
2388+
id_ = 3;
23782389
hover_button_ = -1;
23792390
left_button_down_ = false;
23802391
Resize(275, 116*2+29);
@@ -2528,6 +2539,7 @@ void GenWindow::Paint() {
25282539
///////////////////////////////////////////////////////////
25292540

25302541
CoverArtWindow::CoverArtWindow(MainWindow *main_window) {
2542+
id_ = 4;
25312543
main_window_ = main_window;
25322544
image_needs_load_ = false;
25332545
bitmap_ = NULL;
@@ -2596,6 +2608,7 @@ void CoverArtWindow::SetImage(const char* image) {
25962608
#include <vector>
25972609

25982610
void CoverArtWindow::Load() {
2611+
LoadPosition(main_window.screen_rect()->right, main_window.screen_rect()->bottom);
25992612
if (image_ == "") { return; }
26002613

26012614
PlatformDeleteBitmap(bitmap_);
@@ -2680,12 +2693,9 @@ PlatformWindow *InitSpotamp(int argc, char **argv) {
26802693
if (!main_window.Load())
26812694
return NULL;
26822695

2683-
playlist_window.Move(main_window.screen_rect()->left, main_window.screen_rect()->bottom);
2684-
eq_window.Move(main_window.screen_rect()->right, main_window.screen_rect()->top);
2685-
coverart_window.Move(main_window.screen_rect()->right, main_window.screen_rect()->bottom);
2686-
26872696
eq_window.Load();
26882697
playlist_window.Load();
2698+
coverart_window.Load();
26892699

26902700
InitVisualizer();
26912701

spotifyamp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ class CoverArtWindow : public GenWindow {
294294
explicit CoverArtWindow(MainWindow* main_window);
295295
virtual ~CoverArtWindow();
296296

297+
void Load();
297298
virtual void Paint();
298299
virtual void OnClose();
299300

@@ -302,7 +303,6 @@ class CoverArtWindow : public GenWindow {
302303
void GotImagePart(TspImageDownloadResult* part);
303304

304305
private:
305-
void Load();
306306

307307
MainWindow* main_window_;
308308
std::string image_;

window.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ void PlatformWindowBase<PlatformWindow>::Create(PlatformWindow *owner_window) {
174174
}
175175

176176

177+
template<>
178+
const char *PlatformWindowBase<PlatformWindow>::GetPositionKey(const char *side) {
179+
static char leftKey[12];
180+
snprintf(leftKey, sizeof(leftKey), "window_%d_%s", id_, side);
181+
return leftKey;
182+
}
183+
184+
185+
template<>
186+
void PlatformWindowBase<PlatformWindow>::SavePosition() {
187+
PrefWriteInt(screen_rect_.left, GetPositionKey("l"));
188+
PrefWriteInt(screen_rect_.top, GetPositionKey("t"));
189+
}
190+
191+
192+
template<>
193+
void PlatformWindowBase<PlatformWindow>::LoadPosition(int def_left, int def_top) {
194+
int left(PrefReadInt(def_left, GetPositionKey("l")));
195+
int top(PrefReadInt(def_top, GetPositionKey("t")));
196+
Move(left, top);
197+
}
198+
199+
177200
template<>
178201
void PlatformWindowBase<PlatformWindow>::SetDoubleSize(bool v) {
179202
if (v != double_size_) {

window.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class PlatformWindowBase {
1717

1818
void Create(T *owner_window);
1919

20+
void SavePosition();
21+
void LoadPosition(int def_left, int def_top);
22+
2023
// Double all pixels
2124
void SetDoubleSize(bool v);
2225
bool double_size() const { return double_size_; }
@@ -30,6 +33,8 @@ class PlatformWindowBase {
3033
void SetVisible(bool visible);
3134
bool visible() const { return visible_; }
3235

36+
virtual void Move(int l, int t) {}
37+
3338
// Resize window. If you're in doublesize mode, these still return the normal sized size.
3439
void Resize(int w, int h);
3540
int width() const { return width_; }
@@ -48,6 +53,7 @@ class PlatformWindowBase {
4853
T *self() { return static_cast<T*>(this); }
4954
Point HandleMouseDragOrSize(int dx, int dy, bool snap);
5055

56+
int id_;
5157
bool double_size_;
5258
bool always_on_top_;
5359
bool active_window_;
@@ -57,6 +63,8 @@ class PlatformWindowBase {
5763
int width_, height_;
5864
Rect screen_rect_;
5965
T *next_, *owner_;
66+
private:
67+
const char *GetPositionKey(const char *side);
6068
};
6169

6270
#if defined(WITH_SDL)

window_win32.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ void PlatformWindow::MoveAllWindows() {
248248
r->left, r->top,
249249
r->right - r->left, r->bottom - r->top, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
250250
w->need_move_ = false;
251+
w->SavePosition();
251252
}
252253
}
253254
EndDeferWindowPos(dp);

0 commit comments

Comments
 (0)