@@ -8,6 +8,7 @@ const Signals = imports.signals;
88const KeyboardManager = imports . ui . keyboardManager ;
99const IBus = imports . gi . IBus ;
1010const IBusManager = imports . misc . ibusManager ;
11+ const SignalManager = imports . misc . signalManager ;
1112
1213const PANEL_EDIT_MODE_KEY = "panel-edit-mode" ;
1314
@@ -31,31 +32,28 @@ class LayoutMenuItem extends PopupMenu.PopupBaseMenuItem {
3132 }
3233}
3334
34- class CinnamonKeyboardApplet extends Applet . IconApplet {
35+ class CinnamonKeyboardApplet extends Applet . Applet {
3536 constructor ( metadata , orientation , panel_height , instance_id ) {
3637 super ( orientation , panel_height , instance_id ) ;
3738
38- this . _panel_icon_box = new St . Bin ( ) ; // https://developer.gnome.org/st/stable/StBin.htm
39+ this . _panel_icon_box = new St . Bin ( ) ;
3940
40- this . _panel_icon_box . set_fill ( true , true ) ;
41+ this . _panel_icon_box . set_fill ( true , false ) ;
4142 this . _panel_icon_box . set_alignment ( St . Align . MIDDLE , St . Align . MIDDLE ) ;
4243
44+ this . _signalManager = new SignalManager . SignalManager ( null ) ;
45+ this . _signalManager . connect ( this . panel , "icon-size-changed" , ( ) => this . _syncGroup ( ) ) ;
46+
4347 this . actor . add ( this . _panel_icon_box , {
4448 y_align : St . Align . MIDDLE ,
4549 y_fill : false
4650 } ) ;
4751
4852 this . setAllowedLayout ( Applet . AllowedLayout . BOTH ) ;
4953
50- this . _layoutItems = new Map ( ) ;
51- this . _layoutIcons = new Map ( ) ;
52-
5354 this . _selectedLayout = null ;
5455 this . _layoutItems = new Map ( ) ;
5556
56- this . _maxSeenWidth = this . _maxSeenHeight = 0 ;
57- this . show_flags = this . use_upper = this . use_variants = false ;
58- this . _bus_watch_id = 0
5957
6058 try {
6159 this . metadata = metadata ;
@@ -67,11 +65,9 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
6765
6866 this . actor . add_style_class_name ( 'panel-status-button' ) ;
6967
70- this . desktop_settings = new Gio . Settings ( { schema_id : "org.cinnamon.desktop.interface" } ) ;
71-
7268 const _syncConfig = ( ) => this . _syncConfig ( ) ;
7369
74- global . settings . connect ( 'changed::' + PANEL_EDIT_MODE_KEY , ( ) => this . _onPanelEditModeChanged ( ) ) ;
70+ this . _signalManager . connect ( global . settings , 'changed::' + PANEL_EDIT_MODE_KEY , ( ) => this . _onPanelEditModeChanged ( ) ) ;
7571
7672 this . _layoutSection = new PopupMenu . PopupMenuSection ( ) ;
7773 this . menu . addMenuItem ( this . _layoutSection ) ;
@@ -82,17 +78,17 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
8278 this . menu . addMenuItem ( new PopupMenu . PopupSeparatorMenuItem ( ) ) ;
8379 this . menu . addAction ( _ ( "Show Keyboard Layout" ) , ( ) => {
8480 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 ) ] ) ;
8682 } ) ;
8783 this . menu . addAction ( _ ( "Show Character Table" ) , ( ) => {
8884 Main . overview . hide ( ) ;
8985 Util . spawn ( [ 'gucharmap' ] ) ;
9086 } ) ;
9187 this . menu . addSettingsAction ( _ ( "Keyboard Settings" ) , 'keyboard' ) ;
9288
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 ) ) ;
9692 this . _syncConfig ( ) ;
9793 this . _syncGroup ( ) ;
9894 }
@@ -124,33 +120,23 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
124120 if ( global . settings . get_boolean ( PANEL_EDIT_MODE_KEY ) ) {
125121 this . _onPanelEditModeChanged ( ) ;
126122 }
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 ( ) ) ;
138125 }
139126
140127 on_orientation_changed ( ) {
141- this . _maxSeenWidth = this . _maxSeenHeight = 0 ;
142128 this . _syncGroup ( ) ;
143129 }
144130
145131 _onButtonPressEvent ( actor , event ) {
146132 // Cycle to the next layout
147133 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 ) {
150136 new_index = 0 ;
151137 }
152138
153- this . _manager . activateInputSourceIndex ( new_index ) ;
139+ this . _inputSourcesManager . activateInputSourceIndex ( new_index ) ;
154140 }
155141
156142 return Applet . Applet . prototype . _onButtonPressEvent . call ( this , actor , event ) ;
@@ -160,17 +146,6 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
160146 this . menu . toggle ( ) ;
161147 }
162148
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-
174149 _createFlagIcon ( source , actorClass , size ) {
175150 let actor = null ;
176151 let name = source . flagName ;
@@ -181,45 +156,34 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
181156 style_class : actorClass ,
182157 file : file ,
183158 subscript : source . dupeId > 0 ? String ( source . dupeId ) : null ,
184- width : size ,
185159 height : size ,
186160 } ) ;
187161 }
188162
189163 return actor ;
190164 }
191165
192- _setMargin ( actor , left , right ) {
193- actor . set_style ( `margin-left: ${ left } px; margin-right: ${ right } px;` ) ;
194- }
195-
196166 _syncConfig ( ) {
197- this . _maxSeenWidth = this . _maxSeenHeight = 0 ;
198-
199167 this . _layoutItems . forEach ( ( v , k , m ) => v . destroy ( ) ) ;
200- // this.menu.removeAll();
201-
202168 this . _layoutItems = new Map ( )
203169
204170 this . _selectedLayout = null ;
205171
206- if ( ! this . _manager . multipleSources ) {
172+ if ( ! this . _inputSourcesManager . multipleSources ) {
207173 this . menu . close ( ) ;
208174 this . actor . hide ( ) ;
209175 return ;
210176 }
211177
212- this . show_flags = this . desktop_settings . get_boolean ( "keyboard-layout-show-flags" ) ;
213178 this . actor . show ( ) ;
214179
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 ] ;
217182
218183 let actor = null ;
219- const iconSize = this . getPanelIconSize ( St . IconType . FULLCOLOR ) ;
220184
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 ) ;
223187 }
224188
225189 if ( actor == null ) {
@@ -237,9 +201,9 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
237201 }
238202
239203 _syncGroup ( ) {
240- const selected = this . _manager . currentSource ;
204+ const selected = this . _inputSourcesManager . currentSource ;
241205
242- if ( ! this . _manager . multipleSources ) {
206+ if ( ! this . _inputSourcesManager . multipleSources ) {
243207 this . actor . hide ( ) ;
244208 return ;
245209 }
@@ -256,9 +220,9 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
256220 this . set_applet_tooltip ( selected . displayName ) ;
257221
258222 let actor = null ;
259- const iconSize = this . getPanelIconSize ( St . IconType . FULLCOLOR ) ;
223+ const iconSize = this . getPanelIconSize ( St . IconType . SYMBOLIC ) ;
260224
261- if ( this . show_flags ) {
225+ if ( this . _inputSourcesManager . showFlags ) {
262226 actor = this . _createFlagIcon ( selected , APPLET_ICON_STYLE_CLASS , iconSize ) ;
263227 }
264228
@@ -272,40 +236,6 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
272236 this . _panel_icon_box . set_child ( actor ) ;
273237
274238 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- // }
309239 }
310240
311241 _setPanelIBusLabel ( label ) {
@@ -345,7 +275,7 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
345275 text = prop . get_symbol ( ) . get_text ( ) ;
346276 else
347277 text = prop . get_label ( ) . get_text ( ) ;
348- let currentSource = this . _manager . currentSource ;
278+ let currentSource = this . _inputSourcesManager . currentSource ;
349279 if ( currentSource ) {
350280 let indicatorLabel = this . _layoutItems . get ( currentSource ) ;
351281 if ( text && text . length > 0 && text . length < 3 )
@@ -428,15 +358,8 @@ class CinnamonKeyboardApplet extends Applet.IconApplet {
428358 }
429359 }
430360
431-
432361 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 ( ) ;
440363 Main . systrayManager . unregisterTrayIconReplacement ( this . metadata . uuid ) ;
441364 }
442365} ;
0 commit comments