Skip to content

Commit 0d68dee

Browse files
committed
feat: toggle controls (#85)
Reviewed-on: https://codeberg.org/GeopJr/Turntable/pulls/85
1 parent 276a6e0 commit 0d68dee

File tree

9 files changed

+75
-9
lines changed

9 files changed

+75
-9
lines changed

data/dev.geopjr.Turntable.gresource.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<file preprocess="xml-stripblanks" alias="playlist-repeat-song-symbolic.svg">icons/hicolor/symbolic/actions/playlist-repeat-song-symbolic.svg</file>
2626
<file preprocess="xml-stripblanks" alias="playlist-consecutive-symbolic.svg">icons/hicolor/symbolic/actions/playlist-consecutive-symbolic.svg</file>
2727
<file preprocess="xml-stripblanks" alias="background-app-ghost-symbolic.svg">icons/hicolor/symbolic/actions/background-app-ghost-symbolic.svg</file>
28+
<file preprocess="xml-stripblanks" alias="dock-right-symbolic.svg">icons/hicolor/symbolic/actions/dock-right-symbolic.svg</file>
29+
<file preprocess="xml-stripblanks" alias="dock-left-symbolic.svg">icons/hicolor/symbolic/actions/dock-left-symbolic.svg</file>
30+
<file preprocess="xml-stripblanks" alias="dock-bottom-symbolic.svg">icons/hicolor/symbolic/actions/dock-bottom-symbolic.svg</file>
2831
<file preprocess="xml-stripblanks" alias="settings-symbolic.svg">icons/hicolor/symbolic/actions/settings-symbolic.svg</file>
2932
<file preprocess="xml-stripblanks" alias="network-server-symbolic.svg">icons/hicolor/symbolic/actions/network-server-symbolic.svg</file>
3033
<file preprocess="xml-stripblanks" alias="listenbrainz.svg">icons/hicolor/scalable/actions/listenbrainz.svg</file>

data/dev.geopjr.Turntable.gschema.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
<default>[]</default>
7171
</key>
7272

73+
<key name="collapsed-controls" type="b">
74+
<default>false</default>
75+
</key>
7376
<key name="window-w" type="i">
7477
<default>0</default>
7578
</key>
Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Loading

data/style.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ button.large {
1111
margin: 16px;
1212
}
1313

14-
.card-like.vertical {
14+
.card-like.vertical:not(.collapsed) {
1515
margin-bottom: 0;
1616
}
1717

18-
.card-like.horizontal:dir(ltr):not(.circular-art) {
18+
.card-like.horizontal:dir(ltr):not(.circular-art):not(.collapsed) {
1919
margin-right: 0;
2020
}
2121

22-
.card-like.horizontal:dir(rtl):not(.circular-art) {
22+
.card-like.horizontal:dir(rtl):not(.circular-art):not(.collapsed) {
2323
margin-left: 0;
2424
}
2525

src/Utils/Settings.vala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Turntable.Utils.Settings : GLib.Settings {
1313
public bool mbid_required { get; set; }
1414
public bool now_playing { get; set; }
1515
public bool offline_scrobbling { get; set; }
16+
public bool collapsed_controls { get; set; }
1617
public string cover_size { get; set; }
1718
public string text_size { get; set; }
1819
public string cover_scaling { get; set; }
@@ -37,8 +38,9 @@ public class Turntable.Utils.Settings : GLib.Settings {
3738
"component-center-text",
3839
"now-playing",
3940
"component-more-controls",
40-
"client-icon-style",
41-
"offline-scrobbling"
41+
"offline-scrobbling",
42+
"collapsed-controls",
43+
"client-icon-style"
4244
};
4345

4446
public Settings () {

src/Views/Window.vala

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
1616
GLib.SimpleAction component_more_controls_action;
1717
public string uuid { get; private set; }
1818

19+
private bool _collapsed = false;
20+
public bool collapsed {
21+
get { return _collapsed; }
22+
set {
23+
if (_collapsed != value) {
24+
settings.collapsed_controls =
25+
_collapsed = value;
26+
non_art_revealer.reveal_child = !value;
27+
if (value) {
28+
controls_overlay.add_css_class ("collapsed");
29+
} else {
30+
controls_overlay.remove_css_class ("collapsed");
31+
}
32+
}
33+
}
34+
}
35+
1936
~Window () {
2037
update_player (null);
2138
debug ("Destroying: %s", uuid);
@@ -301,6 +318,10 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
301318
artist_label.force_width =
302319
title_label.force_width = this.orientation == HORIZONTAL;
303320

321+
non_art_revealer.transition_type = this.orientation == HORIZONTAL
322+
? (Gtk.Widget.get_default_direction () == Gtk.TextDirection.RTL ? Gtk.RevealerTransitionType.SLIDE_LEFT : Gtk.RevealerTransitionType.SLIDE_RIGHT)
323+
: Gtk.RevealerTransitionType.SLIDE_DOWN;
324+
controls_overlay.update_toggle_controls_icon ();
304325
update_album_artist_title ();
305326
}
306327

@@ -386,7 +407,8 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
386407
Widgets.Marquee album_label;
387408
Widgets.Cover art_pic;
388409
Widgets.Tonearm tonearm;
389-
Gtk.Box non_art_box;
410+
// Gtk.Box non_art_box;
411+
Gtk.Revealer non_art_revealer;
390412
Widgets.ProgressBin prog;
391413
Gtk.Box main_box;
392414
Widgets.ControlsOverlay controls_overlay;
@@ -413,22 +435,26 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
413435
};
414436
art_pic.notify["extracted-colors"].connect (update_extracted_colors);
415437
controls_overlay = new Widgets.ControlsOverlay (art_pic);
438+
controls_overlay.toggle_controls.connect (toggle_controls);
416439

417440
tonearm = new Widgets.Tonearm () {
418441
halign = CENTER,
419442
child = controls_overlay
420443
};
421444
main_box.append (tonearm);
422445

423-
non_art_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
446+
Gtk.Box non_art_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
424447
hexpand = true,
425448
margin_top = 16,
426449
margin_bottom = 16,
427450
margin_end = 16,
428451
margin_start = 16
429452
};
430-
main_box.append (non_art_box);
431-
453+
non_art_revealer = new Gtk.Revealer () {
454+
child = non_art_box,
455+
reveal_child = !settings.collapsed_controls
456+
};
457+
main_box.append (non_art_revealer);
432458

433459
title_label = new Widgets.Marquee () {
434460
css_classes = {"title-2"},
@@ -655,6 +681,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
655681
update_cover_scaling_from_settings ();
656682
update_component_center_text_from_settings ();
657683
update_component_more_controls_from_settings ();
684+
this.collapsed = settings.collapsed_controls;
658685
}
659686

660687
private void update_cover_scaling_from_settings () {
@@ -928,4 +955,8 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
928955
if (value == null) return;
929956
settings.component_cover_fit = value.get_boolean ();
930957
}
958+
959+
private void toggle_controls () {
960+
this.collapsed = !this.collapsed;
961+
}
931962
}

src/Widgets/ControlsOverlay.vala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
2+
public signal void toggle_controls ();
23
public signal void player_changed (Mpris.Entry? new_player);
34
public Mpris.Entry? last_player { get; set; default = null; }
45

@@ -73,6 +74,7 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
7374
GLib.ListStore players_store;
7475
Gtk.DropDown client_dropdown;
7576
Gtk.MenuButton menu_button;
77+
Gtk.Button toggle_controls_button;
7678
#if SCROBBLING
7779
ScrobbleButton scrobble_button;
7880
#endif
@@ -262,6 +264,15 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
262264
on_accounts_changed ();
263265
#endif
264266

267+
toggle_controls_button = new Gtk.Button () {
268+
css_classes = {"circular", "osd", "min34px"},
269+
icon_name = "dock-right-symbolic",
270+
// translators: tooltip for button that hides/shows all the media controls and labels
271+
tooltip_text = _("Toggle Controls")
272+
};
273+
toggle_controls_button.clicked.connect (on_toggle_controls_button);
274+
sub_box.append (toggle_controls_button);
275+
265276
menu_button = new Gtk.MenuButton () {
266277
icon_name = "menu-large-symbolic",
267278
primary = true,
@@ -289,6 +300,12 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
289300
update_style (cover.style, cover.orientation);
290301
}
291302

303+
public void update_toggle_controls_icon () {
304+
toggle_controls_button.icon_name = settings.orientation_horizontal
305+
? (Gtk.Widget.get_default_direction () == Gtk.TextDirection.RTL ? "dock-left-symbolic" : "dock-right-symbolic")
306+
: "dock-bottom-symbolic";
307+
}
308+
292309
private void on_state_flags_changed () {
293310
bool should_reveal_child = (
294311
this.get_state_flags ()
@@ -312,6 +329,10 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
312329
return true;
313330
}
314331

332+
private void on_toggle_controls_button () {
333+
toggle_controls ();
334+
}
335+
315336
private void update_store () {
316337
players_store.splice (0, players_store.n_items, mpris_manager.get_players ());
317338
players_store.sort ((GLib.CompareDataFunc<Mpris.Entry>) compare_players);

0 commit comments

Comments
 (0)