Skip to content

Commit 510ae86

Browse files
committed
feat: Use the display aspect ratio instead of 16:9 while previewing layouts
1 parent c12f6ee commit 510ae86

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { St } from '@gi.ext';
2+
import { getScalingFactorOf } from '@utils/ui';
3+
export default class LayoutUtils {
4+
static calc_size(
5+
widget: St.Widget,
6+
monitorIndex: number,
7+
smallEdgeSize: number,
8+
): [number, number] {
9+
const monitorGeometry =
10+
global.display.get_monitor_geometry(monitorIndex);
11+
12+
const aspectRatio = monitorGeometry.width / monitorGeometry.height;
13+
const [, scalingFactor] = getScalingFactorOf(widget);
14+
15+
if (aspectRatio === 1) {
16+
return [
17+
smallEdgeSize * scalingFactor,
18+
smallEdgeSize * scalingFactor,
19+
];
20+
}
21+
22+
return [
23+
(aspectRatio > 1.0
24+
? Math.round(smallEdgeSize * aspectRatio)
25+
: smallEdgeSize) * scalingFactor,
26+
(aspectRatio < 1.0
27+
? Math.round(smallEdgeSize / aspectRatio)
28+
: smallEdgeSize) * scalingFactor,
29+
];
30+
}
31+
}

src/components/snapassist/snapAssist.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GObject, St, Clutter, Mtk, Meta, Gio } from '@gi.ext';
33
import SnapAssistTile from './snapAssistTile';
44
import SnapAssistLayout from './snapAssistLayout';
55
import Layout from '../layout/Layout';
6+
import LayoutUtils from '../layout/LayoutUtils';
67
import Tile from '../layout/Tile';
78
import Settings from '@settings/settings';
89
import GlobalState from '@utils/globalState';
@@ -19,9 +20,9 @@ import { logger } from '@utils/logger';
1920
export const SNAP_ASSIST_SIGNAL = 'snap-assist';
2021

2122
const GAPS = 4;
22-
// 16:9 ratio and then rounded to int
23-
const SNAP_ASSIST_LAYOUT_WIDTH = 120;
24-
const SNAP_ASSIST_LAYOUT_HEIGHT = 68;
23+
// The size of the smallest size of the monitor
24+
// Will result into a size of 120x68 if the monitor is 16:9
25+
const SNAP_ASSIST_LAYOUT_SIZE = 68;
2526

2627
const debug = logger('SnapAssist');
2728

@@ -209,7 +210,7 @@ class SnapAssistContent extends St.BoxLayout {
209210
? Math.max(
210211
0,
211212
this._snapAssistantThreshold -
212-
this.height / 2 +
213+
46 * getMonitorScalingFactor(this._monitorIndex) +
213214
this._padding,
214215
)
215216
: -this.height + this._padding;
@@ -237,12 +238,13 @@ class SnapAssistContent extends St.BoxLayout {
237238
this._snapAssistLayouts.forEach((lay) => lay.destroy());
238239
this.remove_all_children();
239240

240-
const [, scalingFactor] = getScalingFactorOf(this);
241-
242241
const layoutGaps = buildMarginOf(GAPS);
242+
const [width, height] = LayoutUtils.calc_size(
243+
this,
244+
this._monitorIndex,
245+
SNAP_ASSIST_LAYOUT_SIZE,
246+
);
243247

244-
const width = SNAP_ASSIST_LAYOUT_WIDTH * scalingFactor;
245-
const height = SNAP_ASSIST_LAYOUT_HEIGHT * scalingFactor;
246248
// build the layouts inside the snap assistant. Place a spacer between each layout
247249
this._snapAssistLayouts = layouts.map((lay, ind) => {
248250
const saLay = new SnapAssistLayout(

src/indicator/defaultMenu.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Monitor } from 'resource:///org/gnome/shell/ui/layout.js';
2121
import Layout from '@components/layout/Layout';
2222
import { _ } from '../translations';
2323
import { openPrefs } from '@polyfill';
24+
import LayoutUtils from '@components/layout/LayoutUtils';
2425

2526
const debug = logger('DefaultMenu');
2627

@@ -76,8 +77,11 @@ class LayoutsRow extends St.BoxLayout {
7677
const selectedIndex = layouts.findIndex((lay) => lay.id === selectedId);
7778
const hasGaps = Settings.get_inner_gaps(1).top > 0;
7879

79-
const layoutHeight: number = 36;
80-
const layoutWidth: number = 64; // 16:9 ratio. -> (16*layoutHeight) / 9 and then rounded to int
80+
const [layoutWidth, layoutHeight] = LayoutUtils.calc_size(
81+
this,
82+
this._monitor.index,
83+
36,
84+
);
8185

8286
this._layoutsButtons = layouts.map((lay, ind) => {
8387
const btn = new LayoutButton(

0 commit comments

Comments
 (0)