11import { registerGObjectClass } from '@/utils/gjs' ;
22import { Clutter , Mtk , Meta , St } from '@gi.ext' ;
33import Layout from '../layout/Layout' ;
4- import { buildRectangle } from '@utils/ui' ;
4+ import { buildRectangle , isPointInsideRect } from '@utils/ui' ;
55import * as Main from 'resource:///org/gnome/shell/ui/main.js' ;
66import { logger } from '@utils/logger' ;
77import GlobalState from '@utils/globalState' ;
@@ -12,7 +12,7 @@ import LayoutWidget from '@components/layout/LayoutWidget';
1212import SignalHandling from '@utils/signalHandling' ;
1313import SuggestionsTilePreview from '@components/windowsSuggestions/suggestionsTilePreview' ;
1414import TilingShellWindowManager from '@components/windowManager/tilingShellWindowManager' ;
15- import { unmaximizeWindow } from '@utils/gnomesupport' ;
15+ import { getEventCoords , unmaximizeWindow } from '@utils/gnomesupport' ;
1616import TouchEventHelper from '@utils/touch' ;
1717
1818const debug = logger ( 'TilingLayoutWithSuggestions' ) ;
@@ -49,7 +49,7 @@ export default class TilingLayoutWithSuggestions extends LayoutWidget<Suggestion
4949 this . _showing = false ;
5050 this . _oldPreviews = [ ] ;
5151 this . connect ( 'destroy' , ( ) => this . _signals . disconnect ( ) ) ;
52- this . _touchHelper = new TouchEventHelper ( this ) ;
52+ this . _touchHelper = new TouchEventHelper ( ) ;
5353 }
5454
5555 protected override buildTile (
@@ -83,14 +83,21 @@ export default class TilingLayoutWithSuggestions extends LayoutWidget<Suggestion
8383 this . _recursivelyShowPopup ( nontiledWindows , monitorIndex ) ;
8484
8585 this . _signals . disconnect ( ) ;
86+ this . _signals . connect ( this , 'key-focus-out' , ( ) => this . close ( ) ) ;
8687 this . _signals . connect (
8788 this ,
8889 'touch-event' ,
8990 ( _ , event : Clutter . Event ) => {
90- return this . _touchHelper . convertTapToButtonPress ( event ) ;
91+ // if a window clone is touched, it will stop propagating the event
92+ // then if this is called it is not a window clone that was pressed
93+ if ( event . type ( ) === Clutter . EventType . TOUCH_END ) {
94+ this . close ( ) ;
95+ return Clutter . EVENT_STOP ;
96+ }
97+
98+ return Clutter . EVENT_PROPAGATE ;
9199 } ,
92100 ) ;
93- this . _signals . connect ( this , 'key-focus-out' , ( ) => this . close ( ) ) ;
94101 this . _signals . connect ( this , 'button-press-event' , ( ) => {
95102 // if a window clone is pressed by a button, it will stop propagating the event
96103 // then if this is called it is not a window clone that was pressed
@@ -259,6 +266,34 @@ export default class TilingLayoutWithSuggestions extends LayoutWidget<Suggestion
259266
260267 // when the clone is selected by the user
261268 winClone . connect ( 'button-press-event' , onSuggestionPress ) ;
269+ winClone . connect (
270+ 'touch-event' ,
271+ ( act : Clutter . Actor , event : Clutter . Event ) => {
272+ const cl = winClone . get_window_clone ( ) ?? winClone ;
273+ const [ x , y ] = cl . get_transformed_position ( ) ;
274+ const allocation = cl . get_allocation_box ( ) ;
275+ const actorPos = buildRectangle ( {
276+ x,
277+ y,
278+ width : allocation . x2 - allocation . x1 ,
279+ height : allocation . y2 - allocation . y1 ,
280+ } ) ;
281+ const eventCoords = getEventCoords ( event ) ;
282+ if ( event . type ( ) === Clutter . EventType . TOUCH_END ) {
283+ if (
284+ isPointInsideRect (
285+ { x : eventCoords [ 0 ] , y : eventCoords [ 1 ] } ,
286+ actorPos ,
287+ )
288+ )
289+ return onSuggestionPress ( ) ;
290+
291+ // if the touch ended outside the window, then user wanted to cancel the touch
292+ return Clutter . EVENT_STOP ;
293+ }
294+ return Clutter . EVENT_PROPAGATE ;
295+ } ,
296+ ) ;
262297
263298 return winClone ;
264299 } ) ;
0 commit comments