@@ -39,10 +39,11 @@ const dir_keys = [{ keyval: Clutter.KEY_Left, label: '←',
3939 { keyval : Clutter . KEY_Up , label : '↑' , extraClassName : 'non-alpha-key' } ,
4040 { keyval : Clutter . KEY_Down , label : '↓' , extraClassName : 'non-alpha-key' } ,
4141 { keyval : Clutter . KEY_Right , label : '→' , extraClassName : 'non-alpha-key' } ] ;
42+ const layout_key = { action : 'next-layout' , icon : 'input-keyboard-symbolic' , extraClassName : 'non-alpha-key' } ;
4243
4344const defaultKeysPre = [
44- [ [ escape_key ] , [ tab_key ] , [ { width : 1.5 , level : 1 , extraClassName : 'shift-key-lowercase' , icon : 'keyboard-shift-filled-symbolic' } ] , [ _123_key ] ] ,
45- [ [ escape_key ] , [ tab_key ] , [ { width : 1.5 , level : 0 , extraClassName : 'shift-key-uppercase' , icon : 'keyboard-shift-filled-symbolic' } ] , [ _123_key ] ] ,
45+ [ [ escape_key ] , [ tab_key ] , [ { width : 1.5 , level : 1 , extraClassName : 'shift-key-lowercase' , icon : 'keyboard-shift-filled-symbolic' } ] , [ layout_key , _123_key ] ] ,
46+ [ [ escape_key ] , [ tab_key ] , [ { width : 1.5 , level : 0 , extraClassName : 'shift-key-uppercase' , icon : 'keyboard-shift-filled-symbolic' } ] , [ layout_key , _123_key ] ] ,
4647 [ [ escape_key ] , [ tab_key ] , [ { label : '=/<' , width : 1.5 , level : 3 , extraClassName : 'non-alpha-key' } ] , [ abc_key ] ] ,
4748 [ [ escape_key ] , [ tab_key ] , [ { label : '?123' , width : 1.5 , level : 2 , extraClassName : 'non-alpha-key' } ] , [ abc_key ] ] ,
4849] ;
@@ -251,6 +252,13 @@ var Key = GObject.registerClass({
251252 this . _longPress = false ;
252253 }
253254
255+ updateKey ( label , icon = null ) {
256+ this . key = label || "" ;
257+ this . keyButton . destroy ( ) ;
258+ this . keyButton = this . _makeKey ( this . key , icon ) ;
259+ this . add_child ( this . keyButton ) ;
260+ }
261+
254262 _onDestroy ( ) {
255263 if ( this . _boxPointer ) {
256264 this . _boxPointer . destroy ( ) ;
@@ -384,9 +392,14 @@ var Key = GObject.registerClass({
384392 } ) ;
385393
386394 if ( icon ) {
387- let child = new St . Icon ( { icon_name : icon } ) ;
388- button . set_child ( child ) ;
389- this . _icon = child ;
395+ if ( icon instanceof Clutter . Actor ) {
396+ button . set_child ( icon ) ;
397+ this . _icon = icon ;
398+ } else {
399+ let child = new St . Icon ( { icon_name : icon } ) ;
400+ button . set_child ( child ) ;
401+ this . _icon = child ;
402+ }
390403 } else {
391404 let label = GLib . markup_escape_text ( key , - 1 ) ;
392405 button . set_label ( label ) ;
@@ -468,6 +481,29 @@ var Key = GObject.registerClass({
468481 }
469482} ) ;
470483
484+ var ActiveGroupKey = GObject . registerClass ( { } , class ActiveGroupKey extends Key {
485+ _init ( controller ) {
486+ this . _controller = controller ;
487+ let [ shortName , icon ] = this . _controller . getCurrentGroupLabelIcon ( ) ;
488+
489+ super . _init ( shortName , [ ] , icon ) ;
490+ this . _groupChangedId = this . _controller . connect ( 'active-group' , this . _onGroupChanged . bind ( this ) ) ;
491+ this . connect ( 'destroy' , this . _onDestroy . bind ( this ) ) ;
492+ }
493+
494+ _onGroupChanged ( id ) {
495+ let [ shortName , icon ] = this . _controller . getCurrentGroupLabelIcon ( ) ;
496+ this . updateKey ( shortName , icon ) ;
497+ }
498+
499+ _onDestroy ( ) {
500+ if ( this . _groupChangedId > 0 ) {
501+ this . _controller . disconnect ( this . _groupChangedId ) ;
502+ this . _groupChangedId = 0 ;
503+ }
504+ }
505+ } ) ;
506+
471507var KeyboardModel = class {
472508 constructor ( groupName ) {
473509 let names = [ groupName ] ;
@@ -1006,7 +1042,11 @@ class Keyboard extends St.BoxLayout {
10061042 let action = key . action ;
10071043 let icon = key . icon ;
10081044
1009- extraButton = new Key ( key . label || '' , [ ] , icon ) ;
1045+ if ( action === 'next-layout' ) {
1046+ extraButton = new ActiveGroupKey ( this . _keyboardController ) ;
1047+ } else {
1048+ extraButton = new Key ( key . label || '' , [ ] , icon ) ;
1049+ }
10101050
10111051 // extraButton.keyButton.add_style_class_name('default-key');
10121052 if ( key . extraClassName != null )
@@ -1030,6 +1070,8 @@ class Keyboard extends St.BoxLayout {
10301070 this . _keyboardController . keyvalRelease ( keyval ) ;
10311071 else if ( action == 'hide' )
10321072 this . close ( ) ;
1073+ else if ( action == 'next-layout' )
1074+ this . _keyboardController . activateNextGroup ( ) ;
10331075 } ) ;
10341076
10351077 if ( switchToLevel == 0 ) {
@@ -1458,6 +1500,27 @@ var KeyboardController = class {
14581500
14591501 getIbusInputActive ( ) {
14601502 return this . _currentSource . type === "ibus" ;
1503+
1504+ activateNextGroup ( ) {
1505+ let new_index = this . _inputSourceManager . currentSource . index + 1 ;
1506+ if ( new_index == this . _inputSourceManager . numInputSources ) {
1507+ new_index = 0 ;
1508+ }
1509+
1510+ this . _inputSourceManager . activateInputSourceIndex ( new_index ) ;
1511+ }
1512+
1513+ getCurrentGroupLabelIcon ( ) {
1514+ let actor = null ;
1515+
1516+ if ( this . _inputSourceManager . showFlags ) {
1517+ actor = this . _inputSourceManager . createFlagIcon ( this . _currentSource , null , 16 ) ;
1518+ }
1519+
1520+ if ( actor == null ) {
1521+ return [ this . _currentSource . shortName , null ] ;
1522+ }
1523+ return [ null , actor ] ;
14611524 }
14621525
14631526 commitString ( string , fromKey ) {
0 commit comments