@@ -4,110 +4,143 @@ const Cinnamon = imports.gi.Cinnamon;
44const St = imports . gi . St ;
55const Clutter = imports . gi . Clutter ;
66const Main = imports . ui . main ;
7+ const PopupMenu = imports . ui . popupMenu ;
78
89const RecordPlayer = class {
910 constructor ( metadata , desklet ) {
1011 this . _metadata = metadata ;
1112 this . _desklet = desklet ;
1213 this . _settings = new Cinnamon . AppletSettings ( metadata . uuid , metadata . uuid ) ;
1314
14- // Settings: playing (bool), speed (33 or 45)
15+ // Bind color + control settings
16+ this . _settings . bindProperty ( '' , 'fontColor' , 'fontColor' ,
17+ ( ) => this . _applyColors ( ) , true , false ) ;
18+ this . _settings . bindProperty ( '' , 'playerColor' , 'playerColor' ,
19+ ( ) => this . _applyColors ( ) , true , false ) ;
20+ this . _settings . bindProperty ( '' , 'recordColor' , 'recordColor' ,
21+ ( ) => this . _applyColors ( ) , true , false ) ;
22+ this . _settings . bindProperty ( '' , 'labelColor' , 'labelColor' ,
23+ ( ) => this . _applyColors ( ) , true , false ) ;
1524 this . _settings . bindProperty ( '' , 'playing' , 'playing' ,
1625 ( ) => this . _onSettingsChanged ( ) , true , false ) ;
1726 this . _settings . bindProperty ( '' , 'speed' , 'speed' ,
1827 ( ) => this . _onSettingsChanged ( ) , true , 33 ) ;
28+
29+ this . _settings . setDefault ( 'fontColor' , '#b4afa5' ) ;
30+ this . _settings . setDefault ( 'playerColor' , '#5a4a3a' ) ;
31+ this . _settings . setDefault ( 'recordColor' , '#111111' ) ;
32+ this . _settings . setDefault ( 'labelColor' , '#c4b089' ) ;
1933 this . _settings . setDefault ( 'playing' , true ) ;
2034 this . _settings . setDefault ( 'speed' , 33 ) ;
2135
22- this . _elapsed = 0 ;
23- this . _startTime = 0 ;
2436 this . _angle = 0 ;
37+ this . _startTime = 0 ;
2538 this . _rate = 0 ;
2639
2740 this . _initLayout ( ) ;
41+ this . _applyColors ( ) ;
2842 this . _onSettingsChanged ( ) ;
2943 }
3044
3145 _initLayout ( ) {
32- this . _layout = new St . Bin ( {
33- style_class : 'vinyl-desklet-bin' ,
34- reactive : true ,
46+ // Container bin — acts as our positioning canvas
47+ this . _canvas = new St . Bin ( {
48+ style_class : 'vinyl-canvas' ,
49+ width : 200 ,
50+ height : 200 ,
3551 } ) ;
3652
37- this . _desklet . layout = new St . BoxLayout ( { style_class : 'vinyl-desklet-panel' } ) ;
38-
39- // Turntable platter (outer ring)
40- this . _platter = new St . Bin ( {
41- style_class : 'vinyl-platter' ,
42- x_expand : true ,
43- y_expand : true ,
44- } ) ;
53+ // Platter (circular via CSS border-radius)
54+ this . _platter = new St . Bin ( { style_class : 'vinyl-platter' } ) ;
55+ this . _platter . set_position ( 18 , 18 ) ;
56+ this . _platter . set_size ( 164 , 164 ) ;
57+ this . _canvas . add_child ( this . _platter ) ;
4558
4659 // Record
47- this . _record = new St . Bin ( {
48- style_class : 'vinyl-record' ,
49- } ) ;
60+ this . _record = new St . Bin ( { style_class : 'vinyl-record' } ) ;
61+ this . _record . set_position ( 28 , 28 ) ;
62+ this . _record . set_size ( 144 , 144 ) ;
63+ this . _canvas . add_child ( this . _record ) ;
5064
51- // Label
52- this . _label = new St . Bin ( {
53- style_class : 'vinyl-label' ,
54- } ) ;
65+ // Center label
66+ this . _label = new St . Bin ( { style_class : 'vinyl-label' } ) ;
67+ this . _label . set_position ( 70 , 70 ) ;
68+ this . _label . set_size ( 60 , 60 ) ;
69+ this . _canvas . add_child ( this . _label ) ;
5570
5671 // Spindle
57- this . _spindle = new St . Bin ( {
58- style_class : 'vinyl-spindle' ,
59- } ) ;
72+ this . _spindle = new St . Bin ( { style_class : 'vinyl-spindle' } ) ;
73+ this . _spindle . set_position ( 95 , 95 ) ;
74+ this . _spindle . set_size ( 10 , 10 ) ;
75+ this . _canvas . add_child ( this . _spindle ) ;
6076
61- // Tonearm group
62- this . _armGroup = new St . Group ( ) ;
77+ // Tonearm
6378 this . _armBase = new St . Bin ( { style_class : 'arm-base' } ) ;
64- this . _armBody = new St . Bin ( { style_class : 'arm-body' } ) ;
79+ this . _armBase . set_position ( 150 , 22 ) ;
80+ this . _armBase . set_size ( 12 , 12 ) ;
81+ this . _canvas . add_child ( this . _armBase ) ;
6582
66- this . _armGroup . add_child ( this . _armBase ) ;
67- this . _armGroup . add_child ( this . _armBody ) ;
68-
69- // Popup menu for controls
83+ this . _armBody = new St . Bin ( { style_class : 'arm-body' } ) ;
84+ this . _armBody . set_position ( 156 , 28 ) ;
85+ this . _armBody . set_size ( 80 , 4 ) ;
86+ this . _canvas . add_child ( this . _armBody ) ;
87+ // Rotate arm ~35deg from vertical
88+ this . _armBody . rotation_angle_z = 35 ;
89+ this . _armBody . set_pivot_point ( 0 , 0.5 ) ;
90+
91+ // Title text (bottom)
92+ this . _title = new St . Label ( { style_class : 'vinyl-title' , text : 'Vinyl Player' } ) ;
93+ this . _title . set_position ( 50 , 182 ) ;
94+ this . _canvas . add_child ( this . _title ) ;
95+
96+ // Click to toggle play
97+ this . _canvas . reactive = true ;
98+ this . _canvas . connect ( 'button-press-event' , ( ) => this . _togglePlay ( ) ) ;
99+
100+ // Popup menu
70101 this . _menuManager = new Desklet . DeskletManager ( this ) ;
71- this . _popupManager = new Cinnamon . PopupMenu . PopupMenuManager ( this . _layout ) ;
72- this . _popupMenu = new Cinnamon . PopupMenu . PopupMenu ( this . _layout , 0 ) ;
102+ this . _popupManager = new PopupMenu . PopupMenuManager ( this ) ;
103+ this . _popupMenu = new PopupMenu . PopupMenu ( this . _canvas , 0 ) ;
73104
74105 const playItem = new PopupMenu . PopupMenuItem ( 'Play / Pause' ) ;
75106 playItem . connect ( 'activated' , ( ) => this . _togglePlay ( ) ) ;
76107 this . _popupMenu . addMenuItem ( playItem ) ;
77108
78- const separator = new PopupMenu . PopupSeparatorMenuItem ( ) ;
79- this . _popupMenu . addMenuItem ( separator ) ;
80-
81- const speed33 = new PopupMenu . PopupMenuItem ( '33 RPM' ) ;
82- speed33 . connect ( 'activated' , ( ) => this . _setSpeed ( 33 ) ) ;
83- this . _popupMenu . addMenuItem ( speed33 ) ;
109+ const sep = new PopupMenu . PopupSeparatorMenuItem ( ) ;
110+ this . _popupMenu . addMenuItem ( sep ) ;
84111
85- const speed45 = new PopupMenu . PopupMenuItem ( '45 RPM' ) ;
86- speed45 . connect ( 'activated' , ( ) => this . _setSpeed ( 45 ) ) ;
87- this . _popupMenu . addMenuItem ( speed45 ) ;
112+ const s33 = new PopupMenu . PopupMenuItem ( '33 RPM' ) ;
113+ s33 . connect ( 'activated' , ( ) => this . _setSpeed ( 33 ) ) ;
114+ this . _popupMenu . addMenuItem ( s33 ) ;
88115
89- this . _popupManager . setMenu ( this . _popupMenu ) ;
116+ const s45 = new PopupMenu . PopupMenuItem ( '45 RPM' ) ;
117+ s45 . connect ( 'activated' , ( ) => this . _setSpeed ( 45 ) ) ;
118+ this . _popupMenu . addMenuItem ( s45 ) ;
90119
91- // Layout: record on top of platter
92- this . _desklet . layout . add_child ( this . _platter ) ;
93- this . _desklet . layout . add_child ( this . _record ) ;
94- this . _desklet . layout . add_child ( this . _label ) ;
95- this . _desklet . layout . add_child ( this . _spindle ) ;
96- this . _desklet . layout . add_child ( this . _armGroup ) ;
120+ this . _popupManager . addMenu ( this . _popupMenu ) ;
97121
98- // Header
99- this . _desklet . header . add_child ( this . _desklet . layout ) ;
122+ this . _desklet . header . add_child ( this . _canvas ) ;
123+ }
100124
101- // Click to toggle
102- this . _desklet . header . actor . connect ( 'button-press-event' , ( actor , event ) => {
103- this . _togglePlay ( ) ;
104- return Clutter . EVENT_STOP ;
105- } ) ;
125+ _applyColors ( ) {
126+ if ( ! this . _canvas ) return ;
127+ const fc = this . _settings . get_property ( 'fontColor' ) ;
128+ const pc = this . _settings . get_property ( 'playerColor' ) ;
129+ const rc = this . _settings . get_property ( 'recordColor' ) ;
130+ const lc = this . _settings . get_property ( 'labelColor' ) ;
131+ // Inject CSS custom properties
132+ const css = `color: ${ fc } ;
133+ --vinyl-platter-base: ${ pc } ;
134+ --vinyl-record: ${ rc } ;
135+ --vinyl-label: ${ lc } ;` ;
136+ this . _canvas . set_style ( css ) ;
137+ // Also directly set title color
138+ if ( this . _title )
139+ this . _title . set_style ( `color: ${ fc } ;` ) ;
106140 }
107141
108142 _togglePlay ( ) {
109- const playing = this . _settings . get_property ( 'playing' ) ;
110- this . _settings . setProperty ( 'playing' , ! playing ) ;
143+ this . _settings . setProperty ( 'playing' , ! this . _settings . get_property ( 'playing' ) ) ;
111144 }
112145
113146 _setSpeed ( rpm ) {
@@ -125,23 +158,13 @@ const RecordPlayer = class {
125158 onUpdate ( ) {
126159 if ( ! this . _rate ) return ;
127160
128- const playing = this . _settings . get_property ( 'playing' ) ;
129161 const speed = this . _settings . get_property ( 'speed' ) ;
130- const msPerRev = ( speed === 45 ) ? 60000 / 45 : 60000 / 33 ;
131-
162+ const msPerRev = speed === 45 ? 60000 / 45 : 60000 / 33 ;
132163 const elapsed = Date . now ( ) - this . _startTime ;
133- const revs = elapsed / msPerRev ;
134- this . _angle = ( revs * 360 ) % 360 ;
135-
136- // Apply rotation via CSS transform using clutter transform
137- const transform = new Clutter . Transform ( ) ;
138- transform . rotate ( Z_AXIS , this . _angle * Math . PI / 180 ) ;
139- this . _record . set_transform ( transform ) ;
140- this . _label . set_transform ( transform . clone ( ) ) ;
141- }
164+ this . _angle = ( ( elapsed / msPerRev ) * 360 ) % 360 ;
142165
143- onLookupStyle ( ) {
144- this . _desklet . set_style ( 'vinyl-desklet' ) ;
166+ this . _record . rotation_angle_z = this . _angle ;
167+ this . _label . rotation_angle_z = this . _angle ;
145168 }
146169} ;
147170
0 commit comments