File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -318,4 +318,17 @@ public class Turntable.Mpris.Entry : GLib.Object {
318318 this . notify_property (" length" );
319319 }
320320 }
321+
322+ public async bool is_active () {
323+ try {
324+ DesktopBus . Mpris . MediaPlayer2Player bus = yield Bus . get_proxy (
325+ BusType . SESSION ,
326+ this . bus_namespace,
327+ " /org/mpris/MediaPlayer2"
328+ );
329+ return bus. playback_status == " Playing" ;
330+ } catch {
331+ return false ;
332+ }
333+ }
321334}
Original file line number Diff line number Diff line change @@ -60,4 +60,15 @@ public class Turntable.Mpris.Manager : GLib.Object {
6060 remove_player (name);
6161 }
6262 }
63+
64+ public async Entry ? active_player () {
65+ for (int i = 0 ; i < entries. length ; i++ ) {
66+ var entry = entries. index (i);
67+ if (yield entry. is_active ()) {
68+ return entry;
69+ }
70+ }
71+
72+ return null ;
73+ }
6374}
Original file line number Diff line number Diff line change @@ -333,11 +333,27 @@ public class Turntable.Widgets.ControlsOverlay : Adw.Bin {
333333 toggle_controls ();
334334 }
335335
336+ private bool done_initial_active_check = false ;
336337 private void update_store () {
337338 players_store. splice (0 , players_store. n_items, mpris_manager. get_players ());
338339 players_store. sort ((GLib . CompareDataFunc<Mpris . Entry > ) compare_players);
339-
340340 client_dropdown. enable_search = players_store. n_items > 10 ;
341+
342+ if (! done_initial_active_check) {
343+ done_initial_active_check = true ;
344+ if (players_store. n_items > 1 ) {
345+ mpris_manager. active_player. begin ((obj, res) = > {
346+ Mpris . Entry ? active_player = mpris_manager. active_player. end (res);
347+ if (active_player != null ) {
348+ uint pos;
349+ if (players_store. find (active_player, out pos)) {
350+ client_dropdown. selected = pos;
351+ }
352+ }
353+ });
354+ }
355+ }
356+
341357 if (this . last_player == null ) selection_changed (); // if always ensure player
342358 }
343359
You can’t perform that action at this time.
0 commit comments