Skip to content

Commit 05e9d9c

Browse files
committed
feat: hide client icon when collpased option and set window gravity (#88)
Reviewed-on: https://codeberg.org/GeopJr/Turntable/pulls/88
1 parent e14b40d commit 05e9d9c

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

data/dev.geopjr.Turntable.gschema.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<key name="now-playing" type="b">
6161
<default>false</default>
6262
</key>
63+
<key name="hide-client-icon-collapsed" type="b">
64+
<default>true</default>
65+
</key>
6366
<key name="component-more-controls" type="b">
6467
<default>false</default>
6568
</key>

meson.build

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,24 @@ scrobbling = false
7979
libsoup_dep = dependency('libsoup-3.0', required: false)
8080
json_glib_dep = dependency('json-glib-1.0', version: '>=1.4.4', required: false)
8181
libsecret_dep = dependency('libsecret-1', required: false)
82+
gtk_dep = dependency('gtk4', version: '>=4.18.0', required: true)
8283

8384
if get_option('scrobbling') and libsoup_dep.found () and json_glib_dep.found () and libsecret_dep.found ()
8485
scrobbling = true
8586
add_project_arguments(['--define=SCROBBLING'], language: 'vala')
8687
endif
8788

89+
if gtk_dep.version().version_compare('>=4.20.0')
90+
add_project_arguments(['--define=GTK_4_20'], language: 'vala')
91+
endif
92+
8893
sources = files()
8994
subdir('src')
9095

9196
final_deps = [
9297
dependency('glib-2.0', version: '>=2.76.0'),
93-
dependency('gtk4', version: '>=4.13.4', required: true),
94-
dependency('libadwaita-1', version: '>=1.5', required: true),
98+
gtk_dep,
99+
dependency('libadwaita-1', version: '>=1.7', required: true),
95100
dependency('gio-unix-2.0', required: true),
96101
dependency('glycin-2', required: true),
97102
dependency('glycin-gtk4-2', required: true),

src/Utils/Settings.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Turntable.Utils.Settings : GLib.Settings {
1414
public bool now_playing { get; set; }
1515
public bool offline_scrobbling { get; set; }
1616
public bool collapsed_controls { get; set; }
17+
public bool hide_client_icon_collapsed { get; set; }
1718
public string cover_size { get; set; }
1819
public string text_size { get; set; }
1920
public string cover_scaling { get; set; }
@@ -37,6 +38,7 @@ public class Turntable.Utils.Settings : GLib.Settings {
3738
"component-tonearm",
3839
"component-center-text",
3940
"now-playing",
41+
"hide-client-icon-collapsed",
4042
"component-more-controls",
4143
"offline-scrobbling",
4244
"collapsed-controls",

src/Views/Window.vala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
44
GLib.SimpleAction progressscale_style_action;
55
GLib.SimpleAction component_progressbin_action;
66
GLib.SimpleAction component_extract_colors_action;
7+
GLib.SimpleAction hide_client_icon_collapsed_action;
78
GLib.SimpleAction window_style_action;
89
GLib.SimpleAction client_icon_style_action;
910
GLib.SimpleAction component_cover_fit_action;
@@ -29,10 +30,15 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
2930
} else {
3031
controls_overlay.remove_css_class ("collapsed");
3132
}
33+
update_client_icon_revealed ();
3234
}
3335
}
3436
}
3537

38+
private void update_client_icon_revealed () {
39+
this.prog.client_icon_revealed = !settings.hide_client_icon_collapsed || !this.collapsed;
40+
}
41+
3642
~Window () {
3743
update_player (null);
3844
debug ("Destroying: %s", uuid);
@@ -419,6 +425,12 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
419425
this.icon_name = Build.DOMAIN;
420426
this.title = Build.NAME;
421427

428+
#if GTK_4_20
429+
// Somehow this worked for a bit but then
430+
// vala realized this is not in the vapi?
431+
// this.gravity = Gtk.WindowGravity.CENTER;
432+
this.set_property ("gravity", 4);
433+
#endif
422434
setup_window_size ();
423435
this.height_request = -1;
424436
this.width_request = -1;
@@ -524,6 +536,10 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
524536
component_extract_colors_action.change_state.connect (on_change_component_extract_colors);
525537
this.add_action (component_extract_colors_action);
526538

539+
hide_client_icon_collapsed_action = new GLib.SimpleAction.stateful ("hide-client-icon-collapsed", null, settings.hide_client_icon_collapsed);
540+
hide_client_icon_collapsed_action.change_state.connect (on_change_hide_client_icon_collapsed);
541+
this.add_action (hide_client_icon_collapsed_action);
542+
527543
meta_dim_action = new GLib.SimpleAction.stateful ("meta-dim", null, settings.meta_dim);
528544
meta_dim_action.change_state.connect (on_change_meta_dim);
529545
this.add_action (meta_dim_action);
@@ -571,6 +587,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
571587
settings.notify["orientation-horizontal"].connect (update_orientation_from_settings);
572588
settings.notify["component-progressbin"].connect (update_progressbin_from_settings);
573589
settings.notify["component-extract-colors"].connect (update_extract_colors_from_settings);
590+
settings.notify["hide-client-icon-collapsed"].connect (update_hide_client_icon_collapsed_from_settings);
574591
settings.notify["window-style"].connect (update_window_from_settings);
575592
settings.notify["client-icon-style"].connect (update_client_icon_style_from_settings);
576593
settings.notify["component-tonearm"].connect (update_component_tonearm_from_settings);
@@ -671,6 +688,7 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
671688
update_progressscale_from_settings ();
672689
update_progressbin_from_settings ();
673690
update_extract_colors_from_settings ();
691+
update_hide_client_icon_collapsed_from_settings ();
674692
update_window_from_settings ();
675693
update_client_icon_style_from_settings ();
676694
update_component_tonearm_from_settings ();
@@ -737,6 +755,11 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
737755
component_extract_colors_action.set_state (this.prog.extract_colors_enabled);
738756
}
739757

758+
private void update_hide_client_icon_collapsed_from_settings () {
759+
update_client_icon_revealed ();
760+
hide_client_icon_collapsed_action.set_state (settings.hide_client_icon_collapsed);
761+
}
762+
740763
private void update_orientation_from_settings () {
741764
this.orientation = settings.orientation_horizontal ? Gtk.Orientation.HORIZONTAL : Gtk.Orientation.VERTICAL;
742765
toggle_orientation_action.set_state (settings.orientation_horizontal);
@@ -926,6 +949,11 @@ public class Turntable.Views.Window : Adw.ApplicationWindow {
926949
settings.component_extract_colors = value.get_boolean ();
927950
}
928951

952+
private void on_change_hide_client_icon_collapsed (GLib.SimpleAction action, GLib.Variant? value) {
953+
if (value == null) return;
954+
settings.hide_client_icon_collapsed = value.get_boolean ();
955+
}
956+
929957
private void on_change_window_style (GLib.SimpleAction action, GLib.Variant? value) {
930958
if (value == null) return;
931959
settings.window_style = value.get_string ();

src/Widgets/ControlsOverlay.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
145145
component_submenu_model.append (_("Fit Art on Cover"), "win.component-cover-fit");
146146
// translators: whether to extract the colors of the cover and use them in UI elements (like Amberol or Material You)
147147
component_submenu_model.append (_("Extract Cover Colors"), "win.component-extract-colors");
148+
// translators: whether to hide the client icon when the controls are collapsed
149+
component_submenu_model.append (_("Hide Client Icon when Collapsed"), "win.hide-client-icon-collapsed");
148150
// translators: whether to show the shuffle and loop buttons
149151
component_submenu_model.append (_("More Player Controls"), "win.component-more-controls");
150152
// translators: whether to show a turntable tonearm in turntable styled cover art; tonearm is the 'arm' part of the turntable,

src/Widgets/ProgressBin.vala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class Turntable.Widgets.ProgressBin : Adw.Bin {
44
Adw.TimedAnimation animation;
55
Gtk.Overlay overlay;
66
Gtk.Image client_icon_widget;
7+
Adw.TimedAnimation client_icon_animation;
78

89
~ProgressBin () {
910
debug ("Destroying");
@@ -58,6 +59,19 @@ public class Turntable.Widgets.ProgressBin : Adw.Bin {
5859
_client_icon = client_icon_widget.icon_name = name;
5960
}
6061

62+
private bool _client_icon_revealed = true;
63+
public bool client_icon_revealed {
64+
get { return _client_icon_revealed; }
65+
set {
66+
if (value != _client_icon_revealed) {
67+
_client_icon_revealed = value;
68+
client_icon_animation.value_from = client_icon_animation.value;
69+
client_icon_animation.value_to = value ? 1 : 0;
70+
client_icon_animation.play ();
71+
}
72+
}
73+
}
74+
6175
public Gtk.Widget content {
6276
set {
6377
overlay.child = value;
@@ -229,6 +243,10 @@ public class Turntable.Widgets.ProgressBin : Adw.Bin {
229243
can_target = false
230244
};
231245

246+
client_icon_animation = new Adw.TimedAnimation (this, 0.0, 1.0, 250, new Adw.PropertyAnimationTarget (client_icon_widget, "opacity")) {
247+
easing = Adw.Easing.LINEAR
248+
};
249+
232250
overlay.add_overlay (client_icon_widget);
233251
this.child = overlay;
234252
}

0 commit comments

Comments
 (0)