@@ -381,15 +381,20 @@ def _update_switcher_for_player(self, player_name):
381
381
btn .add (new_label )
382
382
new_label .show_all ()
383
383
return False
384
-
384
+
385
385
386
386
class PlayerSmall (CenterBox ):
387
387
def __init__ (self ):
388
- super ().__init__ (orientation = "h" , h_align = "fill" , v_align = "center" )
388
+ super ().__init__ (name = "player-small" , orientation = "h" , h_align = "fill" , v_align = "center" )
389
389
self ._show_artist = False # toggle flag
390
+ self ._display_options = ["cavalcade" , "title" , "artist" ]
391
+ self ._display_index = 0
392
+ self ._current_display = "cavalcade"
390
393
391
394
self .mpris_icon = Button (
392
395
name = "compact-mpris-icon" ,
396
+ h_align = "center" ,
397
+ v_align = "center" ,
393
398
child = Label (name = "compact-mpris-icon-label" , markup = icons .disc )
394
399
)
395
400
# Remove scroll events; instead, add button press events.
@@ -405,10 +410,14 @@ def __init__(self):
405
410
self .mpris_label = Label (
406
411
name = "compact-mpris-label" ,
407
412
label = "Nothing Playing" ,
408
- ellipsization = "end"
413
+ ellipsization = "end" ,
414
+ max_chars_width = 26 ,
415
+ h_align = "center" ,
409
416
)
410
417
self .mpris_button = Button (
411
418
name = "compact-mpris-button" ,
419
+ h_align = "center" ,
420
+ v_align = "center" ,
412
421
child = Label (name = "compact-mpris-button-label" , markup = icons .play )
413
422
)
414
423
self .mpris_button .add_events (Gdk .EventMask .BUTTON_PRESS_MASK )
@@ -426,12 +435,12 @@ def __init__(self):
426
435
v_align = "center" ,
427
436
v_expand = False ,
428
437
children = [
429
- self .mpris_label ,
430
438
self .cavalcade_box ,
439
+ self .mpris_label ,
431
440
]
432
441
)
433
- self .center_stack .set_visible_child (self .cavalcade_box )
434
-
442
+ self .center_stack .set_visible_child (self .cavalcade_box ) # default to cavalcade
443
+
435
444
# Create additional compact view.
436
445
self .mpris_small = CenterBox (
437
446
name = "compact-mpris" ,
@@ -441,16 +450,11 @@ def __init__(self):
441
450
v_align = "center" ,
442
451
v_expand = False ,
443
452
start_children = self .mpris_icon ,
444
- center_children = self .mpris_label ,
453
+ center_children = self .center_stack , # Changed to center_stack to handle stack switching
445
454
end_children = self .mpris_button ,
446
455
)
447
-
448
- self .mpris_small_overlay = Overlay ()
449
- self .mpris_small_overlay .add (self .center_stack )
450
- self .mpris_small_overlay .add_overlay (self .mpris_small )
451
-
452
-
453
- self .add (self .mpris_small_overlay )
456
+
457
+ self .add (self .mpris_small )
454
458
455
459
self .mpris_manager = MprisPlayerManager ()
456
460
self .mpris_player = None
@@ -475,49 +479,57 @@ def _apply_mpris_properties(self):
475
479
self .mpris_label .set_text ("Nothing Playing" )
476
480
self .mpris_button .get_child ().set_markup (icons .stop )
477
481
self .mpris_icon .get_child ().set_markup (icons .disc )
482
+ if self ._current_display != "cavalcade" :
483
+ self .center_stack .set_visible_child (self .mpris_label ) # if was title or artist, keep showing label
484
+ else :
485
+ self .center_stack .set_visible_child (self .cavalcade_box ) # default to cavalcade if no player
478
486
return
479
487
480
488
mp = self .mpris_player
481
489
482
- # Toggle between title and artist.
483
- text = (mp .artist if self ._show_artist and mp .artist
484
- else (mp .title if mp .title and mp .title .strip ()
485
- else "Nothing Playing" ))
486
- self .mpris_label .set_text (text )
487
-
488
490
# Choose icon based on player name.
489
491
player_name = mp .player_name .lower () if hasattr (mp , "player_name" ) and mp .player_name else ""
490
492
icon_markup = get_player_icon_markup_by_name (player_name )
491
493
self .mpris_icon .get_child ().set_markup (icon_markup )
492
494
self .update_play_pause_icon ()
493
495
496
+ if self ._current_display == "title" :
497
+ text = (mp .title if mp .title and mp .title .strip () else "Nothing Playing" )
498
+ self .mpris_label .set_text (text )
499
+ self .center_stack .set_visible_child (self .mpris_label )
500
+ elif self ._current_display == "artist" :
501
+ text = (mp .artist if mp .artist else "Nothing Playing" )
502
+ self .mpris_label .set_text (text )
503
+ self .center_stack .set_visible_child (self .mpris_label )
504
+ else : # default cavalcade
505
+ self .center_stack .set_visible_child (self .cavalcade_box )
506
+
507
+
494
508
def _on_icon_button_press (self , widget , event ):
495
509
from gi .repository import Gdk
496
510
if event .type == Gdk .EventType .BUTTON_PRESS :
497
- if event .button == 3 :
498
- self .center_stack .set_visible_child (self .cavalcade_box )
499
- if event .button == 2 :
500
- self .center_stack .set_visible_child (self .mpris_label )
501
511
players = self .mpris_manager .players
502
512
if not players :
503
513
return True
504
514
515
+ if event .button == 2 : # Middle-click: cycle display
516
+ self ._display_index = (self ._display_index + 1 ) % len (self ._display_options )
517
+ self ._current_display = self ._display_options [self ._display_index ]
518
+ self ._apply_mpris_properties () # Re-apply to update label/cavalcade
519
+ return True
520
+
505
521
# Cambiar de reproductor según el botón presionado.
506
- if event .button == 1 : # Left-click: reproductor anterior
522
+ if event .button == 1 : # Left-click: next player
507
523
self .current_index = (self .current_index + 1 ) % len (players )
508
- elif event .button == 3 : # Right-click: reproductor siguiente
509
- #self.current_index = (self.current_index + 1) % len(players)
510
- self .center_stack .set_visible_child (self .cavalcade_box )
511
- elif event .button == 2 : # Middle-click: toggle entre title y artist
512
- self ._on_icon_clicked (widget )
513
- self .center_stack .set_visible_child (self .mpris_label )
514
- return True
524
+ elif event .button == 3 : # Right-click: previous player
525
+ self .current_index = (self .current_index - 1 ) % len (players )
526
+ if self .current_index < 0 :
527
+ self .current_index = len (players ) - 1
515
528
516
529
mp_new = MprisPlayer (players [self .current_index ])
517
530
self .mpris_player = mp_new
518
- # Conectar el evento "changed" para que se actualice el botón de play/pausa
531
+ # Conectar el evento "changed" para que se actualice
519
532
self .mpris_player .connect ("changed" , self ._on_mpris_changed )
520
- # Se remueve el reinicio de self._show_artist para que la selección (artist/title) persista
521
533
self ._apply_mpris_properties ()
522
534
return True # Se consume el evento
523
535
return True
@@ -545,17 +557,8 @@ def _restore_play_pause_icon(self):
545
557
self .update_play_pause_icon ()
546
558
return False
547
559
548
- def _on_icon_clicked (self , widget ):
549
- if not self .mpris_player :
550
- return
551
- # Toggle between showing title and artist.
552
- self ._show_artist = not self ._show_artist
553
- text = (self .mpris_player .artist if self ._show_artist and self .mpris_player .artist
554
- else (self .mpris_player .title if self .mpris_player .title and self .mpris_player .title .strip ()
555
- else "Nothing Playing" ))
556
- self .mpris_label .set_text (text )
557
-
558
- self .center_stack .set_visible_child (self .mpris_label )
560
+ def _on_icon_clicked (self , widget ): # No longer used, logic moved to _on_icon_button_press
561
+ pass
559
562
560
563
def update_play_pause_icon (self ):
561
564
if self .mpris_player and self .mpris_player .playback_status == "playing" :
@@ -583,10 +586,13 @@ def on_player_appeared(self, manager, player):
583
586
def on_player_vanished (self , manager , player_name ):
584
587
players = self .mpris_manager .players
585
588
if players and self .mpris_player and self .mpris_player .player_name == player_name :
586
- self .current_index = self .current_index % len (players )
587
- new_player = MprisPlayer (players [self .current_index ])
588
- self .mpris_player = new_player
589
- self .mpris_player .connect ("changed" , self ._on_mpris_changed )
589
+ if players : # Check if players is not empty after vanishing
590
+ self .current_index = self .current_index % len (players )
591
+ new_player = MprisPlayer (players [self .current_index ])
592
+ self .mpris_player = new_player
593
+ self .mpris_player .connect ("changed" , self ._on_mpris_changed )
594
+ else :
595
+ self .mpris_player = None # No players left
590
596
elif not players :
591
597
self .mpris_player = None
592
- self ._apply_mpris_properties ()
598
+ self ._apply_mpris_properties ()
0 commit comments