@@ -35,6 +35,8 @@ const wom = global.workspace_manager;
35
35
36
36
const Movement = movement . Movement ;
37
37
38
+ const GLib : GLib = imports . gi . GLib ;
39
+
38
40
const { Gio, Meta, St } = imports . gi ;
39
41
const { GlobalEvent, WindowEvent } = Events ;
40
42
const { cursor_rect, is_move_op } = Lib ;
@@ -136,6 +138,8 @@ export class Ext extends Ecs.System<ExtEvent> {
136
138
/** Record of misc. global objects and their attached signals */
137
139
private signals : Map < GObject . Object , Array < SignalID > > = new Map ( ) ;
138
140
141
+ /** Used to debounce on_focus triggers */
142
+ private focus_trigger : null | SignalID = null ;
139
143
140
144
// Entity-component associations
141
145
@@ -283,7 +287,7 @@ export class Ext extends Ecs.System<ExtEvent> {
283
287
}
284
288
}
285
289
}
286
-
290
+
287
291
if ( win . is_maximized ( ) ) {
288
292
this . size_changed_block ( ) ;
289
293
win . meta . unmaximize ( Meta . MaximizeFlags . BOTH ) ;
@@ -584,8 +588,16 @@ export class Ext extends Ecs.System<ExtEvent> {
584
588
585
589
this . size_signals_unblock ( win ) ;
586
590
587
- this . prev_focused = this . last_focused ;
588
- this . last_focused = win . entity ;
591
+ // Keep the last-focused window from being shifted too quickly. 300ms debounce
592
+ if ( this . focus_trigger === null ) {
593
+ this . focus_trigger = GLib . timeout_add ( GLib . PRIORITY_DEFAULT , 300 , ( ) => {
594
+ this . focus_trigger = null ;
595
+ return false ;
596
+ } ) ;
597
+
598
+ this . prev_focused = this . last_focused ;
599
+ this . last_focused = win . entity ;
600
+ }
589
601
590
602
function activate_in_stack ( ext : Ext , stack : node . NodeStack , win : Window . ShellWindow ) {
591
603
ext . auto_tiler ?. forest . stacks . get ( stack . idx ) ?. activate ( win . entity ) ;
@@ -1496,36 +1508,36 @@ export class Ext extends Ecs.System<ExtEvent> {
1496
1508
}
1497
1509
1498
1510
auto_tile_on ( ) {
1499
- const original = this . active_workspace ( ) ;
1500
-
1501
- let tiler = new auto_tiler . AutoTiler (
1502
- new Forest . Forest ( )
1503
- . connect_on_attach ( ( entity : Entity , window : Entity ) => {
1504
- tiler . attached . insert ( window , entity ) ;
1505
- } ) ,
1506
- this . register_storage ( )
1507
- ) ;
1511
+ const original = this . active_workspace ( ) ;
1512
+
1513
+ let tiler = new auto_tiler . AutoTiler (
1514
+ new Forest . Forest ( )
1515
+ . connect_on_attach ( ( entity : Entity , window : Entity ) => {
1516
+ tiler . attached . insert ( window , entity ) ;
1517
+ } ) ,
1518
+ this . register_storage ( )
1519
+ ) ;
1508
1520
1509
- this . auto_tiler = tiler ;
1521
+ this . auto_tiler = tiler ;
1510
1522
1511
- this . settings . set_tile_by_default ( true ) ;
1512
- this . tiling_toggle_switch . setToggleState ( true ) ;
1513
- this . button . icon . gicon = this . button_gio_icon_auto_on ; // type: Gio.Icon
1523
+ this . settings . set_tile_by_default ( true ) ;
1524
+ this . tiling_toggle_switch . setToggleState ( true ) ;
1525
+ this . button . icon . gicon = this . button_gio_icon_auto_on ; // type: Gio.Icon
1514
1526
1515
- for ( const window of this . windows . values ( ) ) {
1516
- if ( window . is_tilable ( this ) ) {
1517
- let actor = window . meta . get_compositor_private ( ) ;
1518
- if ( actor ) {
1519
- if ( ! window . meta . minimized ) {
1520
- tiler . auto_tile ( this , window , false ) ;
1521
- }
1527
+ for ( const window of this . windows . values ( ) ) {
1528
+ if ( window . is_tilable ( this ) ) {
1529
+ let actor = window . meta . get_compositor_private ( ) ;
1530
+ if ( actor ) {
1531
+ if ( ! window . meta . minimized ) {
1532
+ tiler . auto_tile ( this , window , false ) ;
1522
1533
}
1523
1534
}
1524
1535
}
1525
-
1526
- this . register_fn ( ( ) => this . switch_to_workspace ( original ) ) ;
1527
1536
}
1528
1537
1538
+ this . register_fn ( ( ) => this . switch_to_workspace ( original ) ) ;
1539
+ }
1540
+
1529
1541
unset_grab_op ( ) {
1530
1542
if ( this . grab_op !== null ) {
1531
1543
let window = this . windows . get ( this . grab_op . entity ) ;
0 commit comments