Skip to content

Commit a594cd2

Browse files
committed
fix: some corrections to translations and how the keybindings directions are represented
1 parent 86bc333 commit a594cd2

File tree

6 files changed

+430
-403
lines changed

6 files changed

+430
-403
lines changed

src/components/tilingsystem/tilingLayout.ts

+81-76
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Meta from 'gi://Meta';
22
import { registerGObjectClass } from '@/utils/gjs';
33
import Mtk from 'gi://Mtk';
44
import Clutter from 'gi://Clutter';
5+
import St from 'gi://St';
56
import TilePreview, {
67
TilePreviewConstructorProperties,
78
} from '../tilepreview/tilePreview';
@@ -11,11 +12,13 @@ import Tile from '../layout/Tile';
1112
import {
1213
buildRectangle,
1314
buildTileGaps,
15+
isPointInsideRect,
1416
squaredEuclideanDistance,
1517
} from '@utils/ui';
1618
import TileUtils from '@components/layout/TileUtils';
1719
import { logger } from '@utils/shell';
1820
import GlobalState from '@utils/globalState';
21+
import { KeyBindingsDirection } from '@keybindings';
1922

2023
const debug = logger('TilingLayout');
2124

@@ -372,102 +375,104 @@ export default class TilingLayout extends LayoutWidget<DynamicTilePreview> {
372375
public findNearestTile(
373376
source: Mtk.Rectangle,
374377
): { rect: Mtk.Rectangle; tile: Tile } | undefined {
375-
let previewFound: DynamicTilePreview | undefined;
376-
let bestDistance = -1;
377-
378-
const sourceCenter = {
378+
const sourceCoords = {
379379
x: source.x + source.width / 2,
380-
y: source.x + source.height / 2,
380+
y: source.y + source.height / 2,
381381
};
382382

383-
for (let i = 0; i < this._previews.length; i++) {
384-
const preview = this._previews[i];
385-
386-
const previewCenter = {
387-
x: preview.innerX + preview.innerWidth / 2,
388-
y: preview.innerY + preview.innerHeight / 2,
389-
};
390-
391-
const euclideanDistance = squaredEuclideanDistance(
392-
previewCenter,
393-
sourceCenter,
394-
);
383+
// uncomment to show debugging
384+
/* global.windowGroup
385+
.get_children()
386+
.filter((c) => c.get_name() === 'debug-kb')[0]
387+
?.destroy();
388+
const debugWidget = new St.Widget({
389+
x: sourceCoords.x - 8,
390+
y: sourceCoords.y - 8,
391+
height: 16,
392+
width: 16,
393+
style: 'border: 2px solid red; border-radius: 8px;',
394+
name: 'debug-kb',
395+
});
396+
global.windowGroup.add_child(debugWidget);*/
395397

396-
if (!previewFound || euclideanDistance < bestDistance) {
397-
previewFound = preview;
398-
bestDistance = euclideanDistance;
398+
for (let i = 0; i < this._previews.length; i++) {
399+
const previewFound = this._previews[i];
400+
if (isPointInsideRect(sourceCoords, previewFound.rect)) {
401+
return {
402+
rect: buildRectangle({
403+
x: previewFound.innerX,
404+
y: previewFound.innerY,
405+
width: previewFound.innerWidth,
406+
height: previewFound.innerHeight,
407+
}),
408+
tile: previewFound.tile,
409+
};
399410
}
400411
}
401412

402-
if (!previewFound) return undefined;
403-
404-
return {
405-
rect: buildRectangle({
406-
x: previewFound.innerX,
407-
y: previewFound.innerY,
408-
width: previewFound.innerWidth,
409-
height: previewFound.innerHeight,
410-
}),
411-
tile: previewFound.tile,
412-
};
413+
return undefined;
413414
}
414415

415416
public findNearestTileDirection(
416417
source: Mtk.Rectangle,
417-
direction: Meta.DisplayDirection,
418+
direction: KeyBindingsDirection,
418419
): { rect: Mtk.Rectangle; tile: Tile } | undefined {
419-
const sourceCenter = {
420+
if (direction === KeyBindingsDirection.CENTER) return undefined;
421+
422+
const sourceCoords = {
420423
x: source.x + source.width / 2,
421-
y: source.x + source.height / 2,
424+
y: source.y + source.height / 2,
422425
};
423426

424-
const filtered = this._previews.filter((preview) => {
425-
switch (direction) {
426-
case Meta.DisplayDirection.RIGHT:
427-
return preview.x >= source.x + source.width;
428-
case Meta.DisplayDirection.LEFT:
429-
return preview.x + preview.width <= source.x;
430-
case Meta.DisplayDirection.DOWN:
431-
return preview.y >= source.y + source.height;
432-
case Meta.DisplayDirection.UP:
433-
return preview.y + preview.height <= source.y;
434-
default:
435-
return false;
436-
}
437-
});
438-
439-
let previewFound: DynamicTilePreview | undefined;
440-
let bestDistance = -1;
441-
for (let i = 0; i < filtered.length; i++) {
442-
const preview = filtered[i];
443-
444-
const previewCenter = {
445-
x: preview.innerX + preview.innerWidth / 2,
446-
y: preview.innerY + preview.innerHeight / 2,
447-
};
427+
// enlarge the side of the direction and search a tile that contains that point
428+
const enlarge = 64;
429+
430+
switch (direction) {
431+
case KeyBindingsDirection.RIGHT:
432+
sourceCoords.x = source.x + source.width + enlarge;
433+
break;
434+
case KeyBindingsDirection.LEFT:
435+
sourceCoords.x = source.x - enlarge;
436+
break;
437+
case KeyBindingsDirection.DOWN:
438+
sourceCoords.y = source.y + source.height + enlarge;
439+
break;
440+
case KeyBindingsDirection.UP:
441+
sourceCoords.y = source.y - enlarge;
442+
break;
443+
}
448444

449-
const euclideanDistance = squaredEuclideanDistance(
450-
previewCenter,
451-
sourceCenter,
452-
);
445+
// uncomment to show debugging
446+
/* global.windowGroup
447+
.get_children()
448+
.filter((c) => c.get_name() === 'debug-kb')[0]
449+
?.destroy();
450+
const debugWidget = new St.Widget({
451+
x: sourceCoords.x - 8,
452+
y: sourceCoords.y - 8,
453+
height: 16,
454+
width: 16,
455+
style: 'border: 2px solid red; border-radius: 8px;',
456+
name: 'debug-kb',
457+
});
458+
global.windowGroup.add_child(debugWidget);*/
453459

454-
if (!previewFound || euclideanDistance < bestDistance) {
455-
previewFound = preview;
456-
bestDistance = euclideanDistance;
460+
for (let i = 0; i < this._previews.length; i++) {
461+
const previewFound = this._previews[i];
462+
if (isPointInsideRect(sourceCoords, previewFound.rect)) {
463+
return {
464+
rect: buildRectangle({
465+
x: previewFound.innerX,
466+
y: previewFound.innerY,
467+
width: previewFound.innerWidth,
468+
height: previewFound.innerHeight,
469+
}),
470+
tile: previewFound.tile,
471+
};
457472
}
458473
}
459474

460-
if (!previewFound) return undefined;
461-
462-
return {
463-
rect: buildRectangle({
464-
x: previewFound.innerX,
465-
y: previewFound.innerY,
466-
width: previewFound.innerWidth,
467-
height: previewFound.innerHeight,
468-
}),
469-
tile: previewFound.tile,
470-
};
475+
return undefined;
471476
}
472477

473478
public getRightmostTile(): { rect: Mtk.Rectangle; tile: Tile } {

src/components/tilingsystem/tilingManager.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Monitor } from 'resource:///org/gnome/shell/ui/layout.js';
2626
import ExtendedWindow from './extendedWindow';
2727
import EdgeTilingManager from './edgeTilingManager';
2828
import TouchPointer from './touchPointer';
29+
import { KeyBindingsDirection } from '@keybindings';
2930

3031
const MINIMUM_DISTANCE_TO_RESTORE_ORIGINAL_SIZE = 90;
3132

@@ -190,27 +191,27 @@ export class TilingManager {
190191

191192
public onKeyboardMoveWindow(
192193
window: Meta.Window,
193-
direction: Meta.DisplayDirection | undefined, // direction is undefined -> move to the center of the screen
194+
direction: KeyBindingsDirection,
194195
force: boolean,
195196
spanFlag: boolean,
196197
): boolean {
197198
let destination: { rect: Mtk.Rectangle; tile: Tile } | undefined;
198-
if (window.get_maximized()) {
199-
if (spanFlag) return false;
199+
if (spanFlag && window.get_maximized()) return false;
200200

201+
if (window.get_maximized()) {
201202
switch (direction) {
202-
case undefined:
203+
case KeyBindingsDirection.CENTER:
203204
window.unmaximize(Meta.MaximizeFlags.BOTH);
204205
break;
205-
case Meta.DisplayDirection.DOWN:
206+
case KeyBindingsDirection.DOWN:
206207
window.unmaximize(Meta.MaximizeFlags.BOTH);
207208
return true;
208-
case Meta.DisplayDirection.UP:
209+
case KeyBindingsDirection.UP:
209210
return false;
210-
case Meta.DisplayDirection.LEFT:
211+
case KeyBindingsDirection.LEFT:
211212
destination = this._tilingLayout.getLeftmostTile();
212213
break;
213-
case Meta.DisplayDirection.RIGHT:
214+
case KeyBindingsDirection.RIGHT:
214215
destination = this._tilingLayout.getRightmostTile();
215216
break;
216217
}
@@ -220,7 +221,7 @@ export class TilingManager {
220221
const windowRectCopy = window.get_frame_rect().copy();
221222
if (!destination) {
222223
// if the window is not tiled, find the nearest tile in any direction
223-
if (!direction) {
224+
if (direction === KeyBindingsDirection.CENTER) {
224225
// direction is undefined -> move to the center of the screen
225226
const rect = buildRectangle({
226227
x:
@@ -255,7 +256,7 @@ export class TilingManager {
255256

256257
// handle maximize of window
257258
if (
258-
direction === Meta.DisplayDirection.UP &&
259+
direction === KeyBindingsDirection.UP &&
259260
window.can_maximize()
260261
) {
261262
window.maximize(Meta.MaximizeFlags.BOTH);
@@ -275,14 +276,14 @@ export class TilingManager {
275276
);
276277
}
277278

279+
if (window.get_maximized()) window.unmaximize(Meta.MaximizeFlags.BOTH);
280+
281+
this._easeWindowRect(window, destination.rect, false, force);
282+
278283
// ensure the assigned tile is a COPY
279284
(window as ExtendedWindow).assignedTile = new Tile({
280285
...destination.tile,
281286
});
282-
283-
if (window.get_maximized()) window.unmaximize(Meta.MaximizeFlags.BOTH);
284-
285-
this._easeWindowRect(window, destination.rect, false, force);
286287
return true;
287288
}
288289

0 commit comments

Comments
 (0)