@@ -330,7 +330,7 @@ function setPanelsEnabledList(list) {
330330function updatePanelsMeta ( meta , panel_props ) {
331331 let changed = false ;
332332
333- // panelMeta is [panel_id, monitor ]
333+ // panelMeta is [panel_id][monitor, position ]
334334 // Find matching panel ids and update their monitor value if necessary.
335335
336336 for ( let i = 0 ; i < meta . length ; i ++ ) {
@@ -376,6 +376,7 @@ PanelManager.prototype = {
376376 this . panels = [ ] ;
377377 this . panelsMeta = [ ] ; // Properties of panels in format [<monitor index>, <panelPosition>]
378378 this . canAdd = true ; // Whether there is space for more panels to be added
379+ this . monitorCount = global . display . get_n_monitors ( ) ;
379380
380381 let editMode = global . settings . get_boolean ( "panel-edit-mode" ) ;
381382 if ( editMode == true )
@@ -845,7 +846,7 @@ PanelManager.prototype = {
845846
846847 metaList [ ID ] = [ monitorIndex , panelPosition ] ; // Note: metaList [i][0] is the monitor index, metaList [i][1] is the panelPosition
847848
848- if ( monitorIndex < 0 || monitorIndex >= global . display . get_n_monitors ( ) ) {
849+ if ( monitorIndex < 0 || monitorIndex >= this . monitorCount ) {
849850 global . log ( "Monitor " + monitorIndex + " not found. Not creating panel" ) ;
850851 return null ;
851852 }
@@ -857,8 +858,7 @@ PanelManager.prototype = {
857858 } ,
858859
859860 _checkCanAdd : function ( ) {
860- let monitorCount = global . display . get_n_monitors ( ) ;
861- let panelCount = ( monitorCount * 4 ) - this . panelCount ; // max of 4 panels on a monitor, one per edge
861+ let panelCount = ( this . monitorCount * 4 ) - this . panelCount ; // max of 4 panels on a monitor, one per edge
862862
863863 this . canAdd = panelCount > 0 ;
864864 } ,
@@ -1066,12 +1066,13 @@ PanelManager.prototype = {
10661066 } ,
10671067
10681068 _onMonitorsChanged : function ( ) {
1069- let monitorCount = global . display . get_n_monitors ( ) ;
1069+ const oldCount = this . monitorCount ;
1070+ this . monitorCount = global . display . get_n_monitors ( ) ;
10701071 let drawcorner = [ false , false ] ;
10711072
10721073 let panelProperties = getPanelsEnabledList ( )
10731074 // adjust any changes to logical/xinerama monitor relationships
1074- let monitors_changed = updatePanelsMeta ( this . panelsMeta , panelProperties ) ;
1075+ let monitors_changed = updatePanelsMeta ( this . panelsMeta , panelProperties ) || oldCount !== this . monitorCount ;
10751076
10761077 for ( let i = 0 , len = this . panelsMeta . length ; i < len ; i ++ ) {
10771078 if ( ! this . panelsMeta [ i ] ) {
@@ -1080,13 +1081,13 @@ PanelManager.prototype = {
10801081
10811082 if ( ! this . panels [ i ] ) { // If there is a meta but not a panel, i.e. panel could not create due to non-existent monitor, try again
10821083 // - the monitor may just have been reconnected
1083- if ( this . panelsMeta [ i ] [ 0 ] < monitorCount ) // just check that the monitor is there
1084+ if ( this . panelsMeta [ i ] [ 0 ] < this . monitorCount ) // just check that the monitor is there
10841085 {
10851086 let panel = this . _loadPanel ( i , this . panelsMeta [ i ] [ 0 ] , this . panelsMeta [ i ] [ 1 ] , drawcorner ) ;
10861087 if ( panel )
10871088 AppletManager . loadAppletsOnPanel ( panel ) ;
10881089 }
1089- } else if ( this . panelsMeta [ i ] [ 0 ] >= monitorCount ) { // Monitor of the panel went missing. Meta is [monitor,panel] array
1090+ } else if ( this . panelsMeta [ i ] [ 0 ] >= this . monitorCount ) { // Monitor of the panel went missing. Meta is [monitor,panel] array
10901091 if ( this . panels [ i ] ) {
10911092 this . panels [ i ] . destroy ( false ) ; // destroy panel, but don't remove icon size settings
10921093 delete this . panels [ i ] ;
@@ -1166,23 +1167,22 @@ PanelManager.prototype = {
11661167 * shows the dummy panels
11671168 */
11681169 _showDummyPanels : function ( callback ) {
1169- let monitorCount = global . display . get_n_monitors ( ) ;
11701170 this . dummyCallback = callback ;
11711171 this . dummyPanels = [ ] ;
11721172
1173- while ( this . dummyPanels . push ( [ true , true , true , true ] ) < monitorCount ) ; // 4 possible panels per monitor
1173+ while ( this . dummyPanels . push ( [ true , true , true , true ] ) < this . monitorCount ) ; // 4 possible panels per monitor
11741174
11751175 for ( let i = 0 , len = this . panelsMeta . length ; i < len ; i ++ ) {
11761176 if ( ! this . panelsMeta [ i ] ) {
11771177 continue ;
11781178 }
1179- if ( this . panelsMeta [ i ] [ 0 ] >= monitorCount ) // Monitor does not exist
1179+ if ( this . panelsMeta [ i ] [ 0 ] >= this . monitorCount ) // Monitor does not exist
11801180 continue ;
11811181 // there is an existing panel showing
11821182 this . dummyPanels [ this . panelsMeta [ i ] [ 0 ] ] [ this . panelsMeta [ i ] [ 1 ] ] = false ;
11831183 }
11841184
1185- for ( let i = 0 ; i < monitorCount ; i ++ ) {
1185+ for ( let i = 0 ; i < this . monitorCount ; i ++ ) {
11861186 for ( let j = 0 ; j < 4 ; j ++ ) {
11871187 if ( this . dummyPanels [ i ] && this . dummyPanels [ i ] [ j ] == true ) { // no panel there at the moment, so show a dummy
11881188 this . dummyPanels [ i ] [ j ] = new PanelDummy ( i , j , callback ) ;
0 commit comments