@@ -8,6 +8,7 @@ const Signals = imports.signals;
8
8
const KeyboardManager = imports . ui . keyboardManager ;
9
9
const IBus = imports . gi . IBus ;
10
10
const IBusManager = imports . misc . ibusManager ;
11
+ const SignalManager = imports . misc . signalManager ;
11
12
12
13
const PANEL_EDIT_MODE_KEY = "panel-edit-mode" ;
13
14
@@ -31,31 +32,28 @@ class LayoutMenuItem extends PopupMenu.PopupBaseMenuItem {
31
32
}
32
33
}
33
34
34
- class CinnamonKeyboardApplet extends Applet . IconApplet {
35
+ class CinnamonKeyboardApplet extends Applet . Applet {
35
36
constructor ( metadata , orientation , panel_height , instance_id ) {
36
37
super ( orientation , panel_height , instance_id ) ;
37
38
38
- this . _panel_icon_box = new St . Bin ( ) ; // https://developer.gnome.org/st/stable/StBin.htm
39
+ this . _panel_icon_box = new St . Bin ( ) ;
39
40
40
- this . _panel_icon_box . set_fill ( true , true ) ;
41
+ this . _panel_icon_box . set_fill ( true , false ) ;
41
42
this . _panel_icon_box . set_alignment ( St . Align . MIDDLE , St . Align . MIDDLE ) ;
42
43
44
+ this . _signalManager = new SignalManager . SignalManager ( null ) ;
45
+ this . _signalManager . connect ( this . panel , "icon-size-changed" , ( ) => this . _syncGroup ( ) ) ;
46
+
43
47
this . actor . add ( this . _panel_icon_box , {
44
48
y_align : St . Align . MIDDLE ,
45
49
y_fill : false
46
50
} ) ;
47
51
48
52
this . setAllowedLayout ( Applet . AllowedLayout . BOTH ) ;
49
53
50
- this . _layoutItems = new Map ( ) ;
51
- this . _layoutIcons = new Map ( ) ;
52
-
53
54
this . _selectedLayout = null ;
54
55
this . _layoutItems = new Map ( ) ;
55
56
56
- this . _maxSeenWidth = this . _maxSeenHeight = 0 ;
57
- this . show_flags = this . use_upper = this . use_variants = false ;
58
- this . _bus_watch_id = 0
59
57
60
58
try {
61
59
this . metadata = metadata ;
@@ -67,11 +65,9 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
67
65
68
66
this . actor . add_style_class_name ( 'panel-status-button' ) ;
69
67
70
- this . desktop_settings = new Gio . Settings ( { schema_id : "org.cinnamon.desktop.interface" } ) ;
71
-
72
68
const _syncConfig = ( ) => this . _syncConfig ( ) ;
73
69
74
- global . settings . connect ( 'changed::' + PANEL_EDIT_MODE_KEY , ( ) => this . _onPanelEditModeChanged ( ) ) ;
70
+ this . _signalManager . connect ( global . settings , 'changed::' + PANEL_EDIT_MODE_KEY , ( ) => this . _onPanelEditModeChanged ( ) ) ;
75
71
76
72
this . _layoutSection = new PopupMenu . PopupMenuSection ( ) ;
77
73
this . menu . addMenuItem ( this . _layoutSection ) ;
@@ -82,17 +78,17 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
82
78
this . menu . addMenuItem ( new PopupMenu . PopupSeparatorMenuItem ( ) ) ;
83
79
this . menu . addAction ( _ ( "Show Keyboard Layout" ) , ( ) => {
84
80
Main . overview . hide ( ) ;
85
- Util . spawn ( [ 'gkbd-keyboard-display' , '-g' , String ( this . _manager . currentSource . index + 1 ) ] ) ;
81
+ Util . spawn ( [ 'gkbd-keyboard-display' , '-g' , String ( this . _inputSourcesManager . currentSource . index + 1 ) ] ) ;
86
82
} ) ;
87
83
this . menu . addAction ( _ ( "Show Character Table" ) , ( ) => {
88
84
Main . overview . hide ( ) ;
89
85
Util . spawn ( [ 'gucharmap' ] ) ;
90
86
} ) ;
91
87
this . menu . addSettingsAction ( _ ( "Keyboard Settings" ) , 'keyboard' ) ;
92
88
93
- this . _manager = KeyboardManager . getInputSourceManager ( ) ;
94
- this . _manager . connect ( "sources-changed" , this . _onSourcesChanged . bind ( this ) ) ;
95
- this . _manager . connect ( "current-source-changed" , this . _onCurrentSourceChanged . bind ( this ) ) ;
89
+ this . _inputSourcesManager = KeyboardManager . getInputSourceManager ( ) ;
90
+ this . _signalManager . connect ( this . _inputSourcesManager , "sources-changed" , this . _onSourcesChanged . bind ( this ) ) ;
91
+ this . _signalManager . connect ( this . _inputSourcesManager , "current-source-changed" , this . _onCurrentSourceChanged . bind ( this ) ) ;
96
92
this . _syncConfig ( ) ;
97
93
this . _syncGroup ( ) ;
98
94
}
@@ -124,33 +120,23 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
124
120
if ( global . settings . get_boolean ( PANEL_EDIT_MODE_KEY ) ) {
125
121
this . _onPanelEditModeChanged ( ) ;
126
122
}
127
- this . connect ( 'orientation-changed' , ( ) => this . on_orientation_changed ( ) ) ;
128
-
129
- if ( this . _bus_watch_id === 0 ) {
130
- const on_ibus = ( is_active ) => {
131
- this . actor . visible = ! is_active ;
132
- } ;
133
- this . _bus_watch_id = Gio . DBus . session . watch_name (
134
- "org.fcitx.Fcitx" , Gio . BusNameWatcherFlags . NONE ,
135
- ( ) => on_ibus ( true ) , ( ) => on_ibus ( false )
136
- ) ;
137
- }
123
+
124
+ this . _signalManager . connect ( this , 'orientation-changed' , ( ) => this . on_orientation_changed ( ) ) ;
138
125
}
139
126
140
127
on_orientation_changed ( ) {
141
- this . _maxSeenWidth = this . _maxSeenHeight = 0 ;
142
128
this . _syncGroup ( ) ;
143
129
}
144
130
145
131
_onButtonPressEvent ( actor , event ) {
146
132
// Cycle to the next layout
147
133
if ( event . get_button ( ) === 2 ) {
148
- let new_index = this . _manager . currentSource . index + 1 ;
149
- if ( new_index == this . _manager . numInputSources ) {
134
+ let new_index = this . _inputSourcesManager . currentSource . index + 1 ;
135
+ if ( new_index == this . _inputSourcesManager . numInputSources ) {
150
136
new_index = 0 ;
151
137
}
152
138
153
- this . _manager . activateInputSourceIndex ( new_index ) ;
139
+ this . _inputSourcesManager . activateInputSourceIndex ( new_index ) ;
154
140
}
155
141
156
142
return Applet . Applet . prototype . _onButtonPressEvent . call ( this , actor , event ) ;
@@ -160,17 +146,6 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
160
146
this . menu . toggle ( ) ;
161
147
}
162
148
163
- _setLayoutItems ( items ) {
164
- this . _selectedLayout = null ;
165
-
166
- this . _layoutItems . forEach ( ( v , k , m ) => v . destroy ( ) ) ;
167
- this . _layoutItems = items || new Map ( ) ;
168
- }
169
-
170
- _setLayoutIcons ( icons ) {
171
- this . _layoutIcons = icons || new Map ( ) ;
172
- }
173
-
174
149
_createFlagIcon ( source , actorClass , size ) {
175
150
let actor = null ;
176
151
let name = source . flagName ;
@@ -181,45 +156,34 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
181
156
style_class : actorClass ,
182
157
file : file ,
183
158
subscript : source . dupeId > 0 ? String ( source . dupeId ) : null ,
184
- width : size ,
185
159
height : size ,
186
160
} ) ;
187
161
}
188
162
189
163
return actor ;
190
164
}
191
165
192
- _setMargin ( actor , left , right ) {
193
- actor . set_style ( `margin-left: ${ left } px; margin-right: ${ right } px;` ) ;
194
- }
195
-
196
166
_syncConfig ( ) {
197
- this . _maxSeenWidth = this . _maxSeenHeight = 0 ;
198
-
199
167
this . _layoutItems . forEach ( ( v , k , m ) => v . destroy ( ) ) ;
200
- // this.menu.removeAll();
201
-
202
168
this . _layoutItems = new Map ( )
203
169
204
170
this . _selectedLayout = null ;
205
171
206
- if ( ! this . _manager . multipleSources ) {
172
+ if ( ! this . _inputSourcesManager . multipleSources ) {
207
173
this . menu . close ( ) ;
208
174
this . actor . hide ( ) ;
209
175
return ;
210
176
}
211
177
212
- this . show_flags = this . desktop_settings . get_boolean ( "keyboard-layout-show-flags" ) ;
213
178
this . actor . show ( ) ;
214
179
215
- for ( const sourceId of Object . keys ( this . _manager . inputSources ) ) {
216
- const source = this . _manager . inputSources [ sourceId ] ;
180
+ for ( const sourceId of Object . keys ( this . _inputSourcesManager . inputSources ) ) {
181
+ const source = this . _inputSourcesManager . inputSources [ sourceId ] ;
217
182
218
183
let actor = null ;
219
- const iconSize = this . getPanelIconSize ( St . IconType . FULLCOLOR ) ;
220
184
221
- if ( this . show_flags ) {
222
- actor = this . _createFlagIcon ( source , POPUP_MENU_ICON_STYLE_CLASS , iconSize ) ;
185
+ if ( this . _inputSourcesManager . showFlags ) {
186
+ actor = this . _createFlagIcon ( source , POPUP_MENU_ICON_STYLE_CLASS , 22 * global . ui_scale ) ;
223
187
}
224
188
225
189
if ( actor == null ) {
@@ -237,9 +201,9 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
237
201
}
238
202
239
203
_syncGroup ( ) {
240
- const selected = this . _manager . currentSource ;
204
+ const selected = this . _inputSourcesManager . currentSource ;
241
205
242
- if ( ! this . _manager . multipleSources ) {
206
+ if ( ! this . _inputSourcesManager . multipleSources ) {
243
207
this . actor . hide ( ) ;
244
208
return ;
245
209
}
@@ -256,9 +220,9 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
256
220
this . set_applet_tooltip ( selected . displayName ) ;
257
221
258
222
let actor = null ;
259
- const iconSize = this . getPanelIconSize ( St . IconType . FULLCOLOR ) ;
223
+ const iconSize = this . getPanelIconSize ( St . IconType . SYMBOLIC ) ;
260
224
261
- if ( this . show_flags ) {
225
+ if ( this . _inputSourcesManager . showFlags ) {
262
226
actor = this . _createFlagIcon ( selected , APPLET_ICON_STYLE_CLASS , iconSize ) ;
263
227
}
264
228
@@ -272,40 +236,6 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
272
236
this . _panel_icon_box . set_child ( actor ) ;
273
237
274
238
this . _updatePropertySection ( selected . properties ) ;
275
- // const _applet_label_box = this._applet_label.get_parent();
276
- // this._setMargin(_applet_label_box, 0, 0);
277
- // this._setMargin(this._applet_icon_box, 0, 0);
278
-
279
- // const {name, actor, isFlagIcon} = this._layoutIcons.get(selected);
280
- // if (isFlagIcon) {
281
- // this._applet_icon = actor;
282
- // this._applet_icon_box.set_child(actor);
283
- // this._applet_icon_box.show();
284
- // this._setStyle();
285
- // this.set_applet_label("");
286
- // } else {
287
- // this.set_applet_label(name);
288
- // this._applet_icon_box.hide();
289
- // }
290
-
291
- // const box = isFlagIcon ? this._applet_icon_box : _applet_label_box;
292
- // const width = this.actor.get_width();
293
- // const height = this.actor.get_height();
294
- // if (width >= this._maxSeenWidth) {
295
- // this._maxSeenWidth = width;
296
- // }
297
- // if (height >= this._maxSeenHeight) {
298
- // this._maxSeenHeight = height;
299
- // } else {
300
- // this.actor.set_height(this._maxSeenHeight);
301
- // }
302
- // const addedWidth = this._maxSeenWidth - width;
303
- // const leftOffset = parseInt(addedWidth / 2);
304
- // const rightOffset = addedWidth - leftOffset;
305
- // this._setMargin(box, leftOffset, rightOffset);
306
- // if (isFlagIcon) {
307
- // this._setStyle();
308
- // }
309
239
}
310
240
311
241
_setPanelIBusLabel ( label ) {
@@ -345,7 +275,7 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
345
275
text = prop . get_symbol ( ) . get_text ( ) ;
346
276
else
347
277
text = prop . get_label ( ) . get_text ( ) ;
348
- let currentSource = this . _manager . currentSource ;
278
+ let currentSource = this . _inputSourcesManager . currentSource ;
349
279
if ( currentSource ) {
350
280
let indicatorLabel = this . _layoutItems . get ( currentSource ) ;
351
281
if ( text && text . length > 0 && text . length < 3 )
@@ -428,15 +358,8 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
428
358
}
429
359
}
430
360
431
-
432
361
on_applet_removed_from_panel ( ) {
433
- if ( this . _bus_watch_id > 0 ) {
434
- Gio . DBus . session . unwatch_name ( this . _bus_watch_id ) ;
435
- this . _bus_watch_id = 0 ;
436
- }
437
-
438
- // TODO disconnect ISM signals.
439
-
362
+ this . _signalManager . disconnectAllSignals ( ) ;
440
363
Main . systrayManager . unregisterTrayIconReplacement ( this . metadata . uuid ) ;
441
364
}
442
365
} ;
0 commit comments