Skip to content

Commit dfa299d

Browse files
committed
allow canceling the touch
1 parent 307c988 commit dfa299d

File tree

7 files changed

+49
-60
lines changed

7 files changed

+49
-60
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,6 @@ running Vagrant:
313313

314314
If you are running on a NTFS file system then you have to move out the key:
315315
```
316-
mv /path/to/gnome46/virtualbox/private_key $HOME/.ssh/vagrant_key
317-
ln -sr $HOME/.ssh/vagrant_key /path/to/gnome46/virtualbox/private_key
316+
mv /path/to/box/virtualbox/private_key $HOME/.ssh/vagrant_key
317+
ln -sr $HOME/.ssh/vagrant_key /path/to/box/virtualbox/private_key
318318
```

esbuild.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function convertImports(text) {
8484
// drop import of ExtensionPreferences class
8585
text = text.replaceAll('import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";', "");
8686

87-
// replace import of Config
87+
// replace import of Config in preferences
8888
text = text.replaceAll('import * as Config from "resource:///org/gnome/Shell/Extensions/js/misc/config.js";', "const Config = imports.misc.config;");
8989

9090
// replace import of translation related code

src/components/windowsSuggestions/suggestedWindowPreview.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
GLib,
1212
} from '@gi.ext';
1313
import { logger } from '@utils/logger';
14-
import TouchEventHelper from '@utils/touch';
1514

1615
const WINDOW_OVERLAY_FADE_TIME = 200;
1716

@@ -41,7 +40,6 @@ export default class SuggestedWindowPreview extends Shell.WindowPreview {
4140
private _stackAbove: Clutter.Actor | null;
4241
private _destroyed: boolean;
4342
private _idleHideOverlayId: number;
44-
private _touchHelper: TouchEventHelper;
4543

4644
constructor(metaWindow: Meta.Window) {
4745
super({
@@ -155,8 +153,6 @@ export default class SuggestedWindowPreview extends Shell.WindowPreview {
155153
this._title.ensure_style();
156154
this._icon.ensure_style();
157155
});
158-
159-
this._touchHelper = new TouchEventHelper(this);
160156
}
161157

162158
public get_window_clone(): Clutter.Actor | undefined {
@@ -355,11 +351,4 @@ export default class SuggestedWindowPreview extends Shell.WindowPreview {
355351

356352
this.hideOverlay(true);
357353
}
358-
359-
vfunc_touch_event(event: Clutter.Event): boolean {
360-
if (this._touchHelper.convertTapToButtonPress(event))
361-
return super.vfunc_touch_event(event);
362-
363-
return false;
364-
}
365354
}

src/components/windowsSuggestions/suggestionsTilePreview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class SuggestionsTilePreview extends TilePreview {
9797
this._scrollView.get_vscroll_bar().opacity = 0;
9898
}
9999

100-
this._touchHelper = new TouchEventHelper(this);
100+
this._touchHelper = new TouchEventHelper();
101101
}
102102

103103
set blur(value: boolean) {

src/components/windowsSuggestions/tilingLayoutWithSuggestions.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { registerGObjectClass } from '@/utils/gjs';
22
import { Clutter, Mtk, Meta, St } from '@gi.ext';
33
import Layout from '../layout/Layout';
4-
import { buildRectangle } from '@utils/ui';
4+
import { buildRectangle, isPointInsideRect } from '@utils/ui';
55
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
66
import { logger } from '@utils/logger';
77
import GlobalState from '@utils/globalState';
@@ -12,7 +12,7 @@ import LayoutWidget from '@components/layout/LayoutWidget';
1212
import SignalHandling from '@utils/signalHandling';
1313
import SuggestionsTilePreview from '@components/windowsSuggestions/suggestionsTilePreview';
1414
import TilingShellWindowManager from '@components/windowManager/tilingShellWindowManager';
15-
import { unmaximizeWindow } from '@utils/gnomesupport';
15+
import { getEventCoords, unmaximizeWindow } from '@utils/gnomesupport';
1616
import TouchEventHelper from '@utils/touch';
1717

1818
const 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
});

src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ import { Extension } from '@polyfill';
5353
import OverriddenAltTab from '@components/altTab/overriddenAltTab';
5454
import { LayoutSwitcherPopup } from '@components/layoutSwitcher/layoutSwitcher';
5555
import { unmaximizeWindow } from '@utils/gnomesupport';
56-
// @ts-expect-error "Module exists"
57-
import * as Config from 'resource:///org/gnome/Shell/Extensions/js/misc/config.js';
56+
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
5857

5958
const debug = logger('extension');
6059

src/utils/touch.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,21 @@
11
import { Clutter, St } from '@gi.ext';
2+
import { getEventCoords } from './gnomesupport';
23

34
export default class TouchEventHelper {
45
private readonly TOUCH_SCROLL_THRESHOLD = 10;
56

67
private _touchStartY: number | null = null;
7-
private _touchMoved: boolean = false;
88
private _scrollStartY: number = 0;
99
private _isDragging: boolean = false;
1010

11-
private _actor: Clutter.Actor;
12-
13-
constructor(actor: Clutter.Actor) {
14-
this._actor = actor;
15-
}
16-
17-
convertTapToButtonPress(event: Clutter.Event): boolean {
18-
const eventType = event.type();
19-
const [, y] = event.get_coords();
20-
21-
switch (eventType) {
22-
case Clutter.EventType.TOUCH_BEGIN:
23-
this._touchStartY = y;
24-
this._isDragging = false;
25-
return Clutter.EVENT_PROPAGATE;
26-
case Clutter.EventType.TOUCH_UPDATE:
27-
if (this._touchStartY !== null) {
28-
const deltaY = Math.abs(y - this._touchStartY);
29-
if (deltaY > this.TOUCH_SCROLL_THRESHOLD)
30-
this._isDragging = true;
31-
}
32-
return Clutter.EVENT_PROPAGATE;
33-
34-
case Clutter.EventType.TOUCH_END: {
35-
const wasTap = !this._isDragging;
36-
this._touchStartY = null;
37-
this._isDragging = false;
38-
39-
if (wasTap) this._actor.emit('button-press-event', event);
40-
return Clutter.EVENT_STOP;
41-
}
42-
default:
43-
return Clutter.EVENT_PROPAGATE;
44-
}
45-
}
46-
4711
convertPanToScroll(
4812
event: Clutter.Event,
4913
scrollView: St.ScrollView,
5014
): boolean {
15+
if (!scrollView.vadjustment) return Clutter.EVENT_PROPAGATE;
16+
5117
const eventType = event.type();
52-
const [, y] = event.get_coords();
18+
const [, y] = getEventCoords(event);
5319

5420
switch (eventType) {
5521
case Clutter.EventType.TOUCH_BEGIN:

0 commit comments

Comments
 (0)