Skip to content

Commit c53220a

Browse files
committed
feat: allow resizing (#65)
This was a quite a lot more work than what you'd believe. Things like the tonearm expected a static position that changed based on the cover size. Lot's of it was re-written to be more dynamic. At the same time I did use the tonearm circle to hide the not-so-aligned arm but since I revisited the code with a clear mind, the maths were re-done and it now rotates from the correct origin point. That also allowed me to show the tonearm from the other side which makes it more realistic. The turntable cover style wasn't calculated properly after all the attempts at fixing those fitting bugs. I now made it calculate the record vs art size dynamically which looks much better. Some other styles and widgets had to change to better fit a more 'freeform' window size, like for example the fade/shadow style. The progress background would have an offset so it's started at the start of the fading but now that doesn't look that good when it's not at the edge so the offset was removed. It also used the window's border radius for styling but now it had to be backed-in since it's not always at the edge. fix: #37
1 parent b784b5b commit c53220a

File tree

9 files changed

+149
-117
lines changed

9 files changed

+149
-117
lines changed

data/dev.geopjr.Turntable.gschema.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,20 @@
4646
<key name="scrobbler-allowlist" type="as">
4747
<default>[]</default>
4848
</key>
49-
<key name="component-center-text" type="b">
49+
<key name="component-center-text" type="b">
5050
<default>false</default>
5151
</key>
52-
<key name="now-playing" type="b">
52+
<key name="now-playing" type="b">
53+
<default>false</default>
54+
</key>
55+
56+
<key name="window-w" type="i">
57+
<default>0</default>
58+
</key>
59+
<key name="window-h" type="i">
60+
<default>0</default>
61+
</key>
62+
<key name="window-maximized" type="b">
5363
<default>false</default>
5464
</key>
5565
</schema>

data/style.css

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ button.large {
88
}
99

1010
.card-like {
11-
margin-top: 16px;
12-
margin-left: 16px;
11+
margin: 16px;
1312
}
1413

15-
.card-like.horizontal {
16-
margin-right: 0px;
17-
margin-bottom: 16px;
14+
.transparent .fade {
15+
border-radius: 0;
1816
}
1917

20-
.card-like:dir(rtl) {
21-
margin-right: 16px;
18+
.fade.horizontal:dir(ltr) {
19+
border-top-left-radius: 15px;
20+
border-bottom-left-radius: 15px;
2221
}
2322

24-
.card-like.horizontal:dir(rtl) {
25-
margin-left: 0px;
23+
.fade.horizontal:dir(rtl) {
24+
border-top-right-radius: 15px;
25+
border-bottom-right-radius: 15px;
2626
}
2727

28-
.card-like.vertical {
29-
margin-right: 16px;
30-
margin-bottom: 0px;
28+
.fade.vertical {
29+
border-top-left-radius: 15px;
30+
border-top-right-radius: 15px;
3131
}
3232

3333
.bigger-label {

src/Application.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ namespace Turntable {
209209
// translators: Application metainfo for the app "Tuba". <https://github.com/GeopJr/Tuba>
210210
about.add_other_app ("dev.geopjr.Tuba", _("Tuba"), _("Browse the Fediverse"));
211211

212+
this.active_window.resizable = false;
212213
about.present (this.active_window);
214+
about.closed.connect (((Views.Window) this.active_window).make_resizable);
213215

214216
GLib.Idle.add (() => {
215217
var style = Utils.Celebrate.get_celebration_css_class (new GLib.DateTime.now ());

src/Views/Window.vala

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
8585
}
8686

8787
update_orientation ();
88-
update_offset ();
88+
// update_offset ();
8989
}
9090
}
9191
}
@@ -215,6 +215,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
215215
set {
216216
if (this.length == 0) {
217217
_position = 0;
218+
tonearm.progress =
218219
prog.progress = 0;
219220
} else {
220221
#if SCROBBLING
@@ -223,6 +224,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
223224
}
224225
#endif
225226
_position = value;
227+
tonearm.progress =
226228
prog.progress = (double)value / (double)this.length;
227229
}
228230
}
@@ -234,6 +236,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
234236
set {
235237
_length = value;
236238

239+
tonearm.progress =
237240
prog.progress = value == 0 ? 0 : (double)this.position / (double)value;
238241
#if SCROBBLING
239242
if (value > 0) {
@@ -271,17 +274,6 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
271274
}
272275

273276
private void update_orientation () {
274-
switch (this.orientation) {
275-
case Gtk.Orientation.VERTICAL:
276-
this.default_width = 0;
277-
this.default_height = this.cover_size == Size.SMALL ? 300 : 400;
278-
break;
279-
default:
280-
this.default_width = 534;
281-
this.default_height = 0;
282-
break;
283-
}
284-
285277
art_pic.orientation =
286278
main_box.orientation =
287279
prog.orientation = this.orientation;
@@ -310,31 +302,59 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
310302
if (value != art_pic.style ) {
311303
art_pic.style = value;
312304
art_pic.turntable_playing = this.playing;
313-
update_offset ();
305+
// update_offset ();
314306
}
315307
}
316308
}
317309

318-
private void update_offset () {
319-
switch (this.cover_style) {
320-
case Widgets.Cover.Style.SHADOW:
321-
prog.offset = art_pic.size - (int32) (Widgets.Cover.FADE_WIDTH / 2);
322-
break;
323-
default:
324-
prog.offset = 0;
325-
break;
326-
}
327-
}
310+
// private void update_offset () {
311+
// switch (this.cover_style) {
312+
// case Widgets.Cover.Style.SHADOW:
313+
// prog.offset = art_pic.size - (int32) (Widgets.Cover.FADE_WIDTH / 2);
314+
// break;
315+
// default:
316+
// prog.offset = 0;
317+
// break;
318+
// }
319+
// }
328320

329321
private void update_extracted_colors () {
330322
prog.extracted_colors = art_pic.extracted_colors;
331323
}
332324

325+
private inline void setup_window_size () {
326+
this.default_width = settings.get_int ("window-w");
327+
this.default_height = settings.get_int ("window-h");
328+
this.maximized = settings.get_boolean ("window-maximized");
329+
330+
this.notify["default-width"].connect (on_window_size_changed);
331+
this.notify["default-height"].connect (on_window_size_changed);
332+
this.notify["maximized"].connect (on_window_size_changed);
333+
}
334+
335+
uint window_settings_timeout = 0;
336+
private void on_window_size_changed () {
337+
// non_art_box.visible = settings.orientation_horizontal ? this.default_width > 452 : this.default_height > 423;
338+
if (window_settings_timeout > 0) GLib.Source.remove (window_settings_timeout);
339+
window_settings_timeout = GLib.Timeout.add (2 * 1000, update_window_size_settings, Priority.LOW);
340+
}
341+
342+
private bool update_window_size_settings () {
343+
settings.set_int ("window-h", this.default_height);
344+
settings.set_int ("window-w", this.default_width);
345+
settings.set_boolean ("window-maximized", this.maximized);
346+
347+
window_settings_timeout = 0;
348+
return GLib.Source.REMOVE;
349+
}
350+
333351
Mpris.Entry? player = null;
334352
Widgets.Marquee artist_label;
335353
Widgets.Marquee title_label;
336354
Widgets.Marquee album_label;
337355
Widgets.Cover art_pic;
356+
Widgets.Tonearm tonearm;
357+
Gtk.Box non_art_box;
338358
Widgets.ProgressBin prog;
339359
Gtk.Box main_box;
340360
Gtk.Button button_play;
@@ -344,31 +364,37 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
344364
construct {
345365
this.uuid = GLib.Uuid.string_random ();
346366
this.icon_name = Build.DOMAIN;
347-
this.resizable = false;
348367
this.title = Build.NAME;
349368

350-
this.default_width = 0;
351-
this.default_height = 0;
369+
setup_window_size ();
352370
this.height_request = -1;
353371
this.width_request = -1;
354372

355-
main_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
373+
main_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
374+
valign = CENTER,
375+
halign = CENTER
376+
};
356377
art_pic = new Widgets.Cover () {
357378
valign = Gtk.Align.START,
358379
halign = Gtk.Align.START
359380
};
360381
art_pic.notify["extracted-colors"].connect (update_extracted_colors);
361382
controls_overlay = new Widgets.ControlsOverlay (art_pic);
362-
main_box.append (controls_overlay);
363383

364-
var box2 = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
384+
tonearm = new Widgets.Tonearm () {
385+
halign = CENTER,
386+
child = controls_overlay
387+
};
388+
main_box.append (tonearm);
389+
390+
non_art_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
365391
hexpand = true,
366392
margin_top = 16,
367393
margin_bottom = 16,
368394
margin_end = 16,
369395
margin_start = 16
370396
};
371-
main_box.append (box2);
397+
main_box.append (non_art_box);
372398

373399

374400
title_label = new Widgets.Marquee () {
@@ -382,9 +408,9 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
382408
xalign = 0.0f
383409
};
384410

385-
box2.append (title_label);
386-
box2.append (artist_label);
387-
box2.append (album_label);
411+
non_art_box.append (title_label);
412+
non_art_box.append (artist_label);
413+
non_art_box.append (album_label);
388414

389415
prog = new Widgets.ProgressBin () {
390416
content = main_box
@@ -396,7 +422,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
396422
halign = Gtk.Align.CENTER,
397423
valign = Gtk.Align.CENTER,
398424
};
399-
box2.append (box3);
425+
non_art_box.append (box3);
400426

401427
button_prev = new Gtk.Button.from_icon_name (is_rtl ? "skip-forward-large-symbolic" : "skip-backward-large-symbolic") {
402428
css_classes = {"circular"},
@@ -520,8 +546,18 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
520546
account_manager.accounts_changed.connect (update_scrobble_status);
521547
#endif
522548

523-
box2.state_flags_changed.connect (on_state_flags_changed);
549+
non_art_box.state_flags_changed.connect (on_state_flags_changed);
524550
art_pic.map.connect (on_mapped);
551+
552+
Gtk.GestureClick click_gesture = new Gtk.GestureClick () {
553+
button = Gdk.BUTTON_PRIMARY
554+
};
555+
click_gesture.pressed.connect (on_click);
556+
prog.add_controller (click_gesture);
557+
}
558+
559+
private void on_click () {
560+
if (controls_overlay.hide_overlay ()) this.focus_widget = null;
525561
}
526562

527563
private void play_next () {
@@ -537,7 +573,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
537573
}
538574

539575
private void on_mapped () {
540-
update_offset ();
576+
// update_offset ();
541577
art_pic.turntable_playing = this.playing;
542578
}
543579

@@ -639,7 +675,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
639675
}
640676

641677
private void update_component_tonearm_from_settings () {
642-
this.prog.tonearm_enabled = settings.component_tonearm;
678+
this.tonearm.enabled = settings.component_tonearm;
643679
component_tonearm_action.set_state (settings.component_tonearm);
644680
}
645681

@@ -663,10 +699,19 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
663699

664700
#if SCROBBLING
665701
private void open_scrobbling_setup () {
666-
(new Views.ScrobblerSetup ()).present (this);
702+
this.resizable = false;
703+
704+
var dlg = new Views.ScrobblerSetup ();
705+
dlg.present (this);
706+
dlg.closed.connect (make_resizable);
667707
}
668708
#endif
669709

710+
// hack to force present dialogs as windows
711+
public void make_resizable () {
712+
this.resizable = true;
713+
}
714+
670715
GLib.Binding[] player_bindings = {};
671716
private void update_player (Mpris.Entry? new_player) {
672717
debug ("[%s] Player Changed", uuid);

src/Widgets/ControlsOverlay.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
2020
this.css_classes = { "card", "circular-art", "card-like" };
2121
break;
2222
case SHADOW:
23-
this.css_classes = {};
23+
this.css_classes = { "fade" };
2424
this.overlay.child.valign =
2525
this.overlay.child.halign =
2626
this.valign =

src/Widgets/Cover.vala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ public class Turntable.Widgets.Cover : Gtk.Widget {
4343
Graphene.Rect record_center_inner;
4444

4545
private void update_record_rects () {
46+
int new_size = (int) (this.size * 0.666666666666);
4647
record_center_inner = Graphene.Rect () {
4748
origin = Graphene.Point () {
4849
x = 0,
4950
y = 0
5051
},
5152
size = Graphene.Size () {
52-
width = 128 * this.scale_factor,
53-
height = 128 * this.scale_factor
53+
width = new_size * this.scale_factor,
54+
height = new_size * this.scale_factor
5455
}
5556
};
5657

@@ -408,6 +409,7 @@ public class Turntable.Widgets.Cover : Gtk.Widget {
408409
set {
409410
if (_size != value) {
410411
_size = value;
412+
update_record_rects ();
411413
this.queue_resize ();
412414
}
413415
}
@@ -636,9 +638,7 @@ public class Turntable.Widgets.Cover : Gtk.Widget {
636638
x = - translation_point.x,
637639
y = - translation_point.y
638640
});
639-
}
640-
641-
if (this.style == Style.SHADOW) {
641+
} else if (this.style == Style.SHADOW) {
642642
snapshot.push_mask (Gsk.MaskMode.INVERTED_ALPHA);
643643

644644
if (this.orientation == Gtk.Orientation.HORIZONTAL) {

src/Widgets/Marquee.vala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ public class Turntable.Widgets.Marquee : Gtk.Widget {
112112
out int minimum_baseline,
113113
out int natural_baseline
114114
) {
115+
label.measure (orientation, for_size, out minimum, out natural, out minimum_baseline, out natural_baseline);
116+
115117
if (orientation == Gtk.Orientation.HORIZONTAL) {
116118
minimum = 0;
117-
natural = this.width_pixels;
119+
natural = int.min (308, natural);
118120
minimum_baseline = -1;
119121
natural_baseline = -1;
120-
} else {
121-
label.measure (orientation, for_size, out minimum, out natural, out minimum_baseline, out natural_baseline);
122122
}
123123
}
124124

0 commit comments

Comments
 (0)