@@ -3,6 +3,12 @@ import { onPrimaryClick, onSecondaryClick, onMiddleClick, onScroll } from 'src/l
3
3
import { bind , Variable } from 'astal' ;
4
4
import { Astal } from 'astal/gtk3' ;
5
5
import AstalMpris from 'gi://AstalMpris?version=0.1' ;
6
+ import { NextTrack , PreviousTrack } from 'src/components/menus/media/components/controls/Tracks.js' ;
7
+ import { PlayPause } from 'src/components/menus/media/components/controls/PlayPause.js' ;
8
+ import { Gtk } from 'astal/gtk3' ;
9
+ import { Binding } from 'astal' ;
10
+ import { mediaArtUrl } from 'src/services/media' ;
11
+
6
12
import { BarBoxChild } from 'src/components/bar/types.js' ;
7
13
import { activePlayer , mediaTitle , mediaAlbum , mediaArtist } from 'src/services/media' ;
8
14
import options from 'src/configuration' ;
@@ -16,6 +22,8 @@ const {
16
22
truncation_size,
17
23
show_label,
18
24
show_active_only,
25
+ use_image_controls_mode,
26
+ disable_media_label,
19
27
rightClick,
20
28
middleClick,
21
29
scrollUp,
@@ -29,6 +37,15 @@ Variable.derive([bind(show_active_only), bind(mprisService, 'players')], (showAc
29
37
isVis . set ( ! showActive || players ?. length > 0 ) ;
30
38
} ) ;
31
39
40
+ const MediaImage = ( ) : Astal . Box => {
41
+ const getBackground = ( ) : Binding < string > => {
42
+ return Variable . derive ( [ bind ( mediaArtUrl ) ] , ( artUrl ) => {
43
+ return `background-image: url('${ artUrl } ');` ;
44
+ } ) ( ) ;
45
+ } ;
46
+ return < box className = "media-image" css = { getBackground ( ) } halign = { Gtk . Align . CENTER } hexpand vertical /> ;
47
+ } ;
48
+
32
49
const Media = ( ) : BarBoxChild => {
33
50
activePlayer . set ( mprisService . get_players ( ) [ 0 ] ) ;
34
51
@@ -72,20 +89,46 @@ const Media = (): BarBoxChild => {
72
89
componentClassName . drop ( ) ;
73
90
} }
74
91
>
92
+ { /* My custom media indicatior */ }
93
+ < box
94
+ visible = { bind ( use_image_controls_mode ) . as ( ( useImageControlsMode ) => useImageControlsMode ) }
95
+ className = { 'media-indicator-current-player' }
96
+ >
97
+ < MediaImage />
98
+ < box className = { 'media-indicator-current-controls' } halign = { Gtk . Align . CENTER } >
99
+ < PreviousTrack />
100
+ < PlayPause />
101
+ < NextTrack />
102
+ </ box >
103
+ </ box >
104
+ { /* Old media indicator */ }
75
105
< label
76
106
className = { 'bar-button-icon media txt-icon bar' }
77
107
label = { bind ( songIcon ) . as ( ( icn ) => icn || '' ) }
108
+ visible = { bind ( use_image_controls_mode ) . as ( ( useImageControlsMode ) => ! useImageControlsMode ) }
109
+ />
110
+ < label
111
+ className = { 'bar-button-label media' }
112
+ label = { mediaLabel ( ) }
113
+ visible = { bind (
114
+ Variable . derive (
115
+ [ bind ( use_image_controls_mode ) , bind ( disable_media_label ) ] ,
116
+ ( useImageControlsMode , disableMediaLabel ) =>
117
+ ! useImageControlsMode || ! disableMediaLabel ,
118
+ ) ,
119
+ ) }
78
120
/>
79
- < label className = { 'bar-button-label media' } label = { mediaLabel ( ) } />
80
121
</ box >
81
122
) ;
82
123
83
124
return {
84
125
component,
85
126
isVis : bind ( isVis ) ,
127
+ isBox : true ,
86
128
boxClass : 'media' ,
87
129
props : {
88
- setup : ( self : Astal . Button ) : void => {
130
+ tooltipText : bind ( mediaLabel ) ,
131
+ setup : ( self : Astal . Box ) : void => {
89
132
let disconnectFunctions : ( ( ) => void ) [ ] = [ ] ;
90
133
91
134
Variable . derive (
@@ -102,11 +145,14 @@ const Media = (): BarBoxChild => {
102
145
103
146
const throttledHandler = throttledScrollHandler ( options . bar . scrollSpeed . get ( ) ) ;
104
147
105
- disconnectFunctions . push (
106
- onPrimaryClick ( self , ( clicked , event ) => {
107
- openDropdownMenu ( clicked , event , 'mediamenu' ) ;
108
- } ) ,
109
- ) ;
148
+ // NOTE: As part of my "controls experiment," I decided to remove the primary click handler
149
+ // as it causes problems when clicked on the buttons.
150
+ //
151
+ // disconnectFunctions.push(
152
+ // onPrimaryClick(self, (clicked, event) => {
153
+ // openDropdownMenu(clicked, event, 'mediamenu');
154
+ // }),
155
+ // );
110
156
111
157
disconnectFunctions . push (
112
158
onSecondaryClick ( self , ( clicked , event ) => {
0 commit comments