Skip to content

Commit

Permalink
version 12.2: customize quarter tiling, snap assistant below pointer,…
Browse files Browse the repository at this point in the history
… snap assistant threshold handles scaling factor, tiling buttons with maximized windows
  • Loading branch information
domferr committed Aug 5, 2024
1 parent 7efca34 commit ab2a08e
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ You can resize adjacent tiled windows together!

Move window through the tiles using keyboard shortcuts (<kbd>SUPER</kbd>+<kbd>←</kbd>/<kbd>↑</kbd>/<kbd>↓</kbd>/<kbd>→</kbd>). They can be customized from the preferences!

[Screencast from 2024-06-18 23-06-56.webm](https://github.com/domferr/tilingshell/assets/14203981/11c966b7-c140-4ecb-b8af-b514ec186ad6)
[Tile with Keyboard Video](https://github.com/user-attachments/assets/6f8dedbb-2733-41d8-8a94-0fa62dffb915)

> It can be enabled/disabled from the preferences
Expand Down
2 changes: 1 addition & 1 deletion resources/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"46"
],
"version": 99,
"version-name": "12.1",
"version-name": "12.2",
"url": "https://github.com/domferr/tilingshell",
"settings-schema": "org.gnome.shell.extensions.tilingshell",
"donations": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@
<summary>Add snap assistant and auto-tile buttons to window menu</summary>
<description>Add snap assistant and auto-tile buttons in the menu that shows up when you right click on a window title.</description>
</key>
<key name="snap-assistant-threshold" type="u">
<key name="snap-assistant-threshold" type="i">
<default>54</default>
<summary>Snap Assistant threshold</summary>
<description>Snap Assistant's threshold to enlarge, shrink, open and close it.</description>
</key>
<key name="quarter-tiling-threshold" type="u">
<default>40</default>
<summary>Quarter tiling threshold</summary>
<description>Threshold to trigger quarter tiling.</description>
</key>

<!-- keybindings -->
<key type="as" name="move-window-right">
Expand Down
4 changes: 2 additions & 2 deletions src/components/editor/editorDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Layout from '@/components/layout/Layout';
import Tile from '@/components/layout/Tile';
import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import { enableScalingFactorSupport, getScalingFactor } from '@utils/ui';
import { enableScalingFactorSupport, getMonitorScalingFactor } from '@utils/ui';

@registerGObjectClass
export default class EditorDialog extends ModalDialog.ModalDialog {
Expand All @@ -36,7 +36,7 @@ export default class EditorDialog extends ModalDialog.ModalDialog {

if (params.enableScaling) {
const monitor = Main.layoutManager.findMonitorForActor(this);
const scalingFactor = getScalingFactor(
const scalingFactor = getMonitorScalingFactor(
monitor?.index || Main.layoutManager.primaryIndex,
);
enableScalingFactorSupport(this, scalingFactor);
Expand Down
4 changes: 2 additions & 2 deletions src/components/editor/layoutEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
buildTileGaps,
enableScalingFactorSupport,
getEventCoords,
getScalingFactor,
getMonitorScalingFactor,
getWindowsOfMonitor,
} from '@/utils/ui';
import Layout from '../layout/Layout';
Expand Down Expand Up @@ -47,7 +47,7 @@ export default class LayoutEditor extends St.Widget {
);

if (enableScaling) {
const scalingFactor = getScalingFactor(monitor.index);
const scalingFactor = getMonitorScalingFactor(monitor.index);
enableScalingFactorSupport(this, scalingFactor);
}

Expand Down
67 changes: 35 additions & 32 deletions src/components/snapassist/snapAssist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import {
buildBlurEffect,
buildMargin,
enableScalingFactorSupport,
getMonitorScalingFactor,
getScalingFactorOf,
} from '@utils/ui';

export const SNAP_ASSIST_SIGNAL = 'snap-assist';
export const SNAP_ASSIST_ANIMATION_TIME = 180;
// distance from top when the snap assistant is enlarged
const ENLARGED_VERTICAL_DISTANCE = 24;
const GAPS = 4;

@registerGObjectClass
Expand Down Expand Up @@ -59,8 +58,9 @@ class SnapAssistContent extends St.BoxLayout {
private _bottomPadding: number;
private _blur: boolean;
private _snapAssistantThreshold: number;
private _monitorIndex: number;

constructor(container: St.Widget) {
constructor(container: St.Widget, monitorIndex: number) {
super({
name: 'snap_assist_content',
xAlign: Clutter.ActorAlign.CENTER,
Expand All @@ -78,7 +78,9 @@ class SnapAssistContent extends St.BoxLayout {
this._showing = true;
this._bottomPadding = 0;
this._blur = false;
this._snapAssistantThreshold = 54;
this._monitorIndex = monitorIndex;
this._snapAssistantThreshold =
54 * getMonitorScalingFactor(this._monitorIndex);

Settings.bind(
Settings.SETTING_ENABLE_BLUR_SNAP_ASSISTANT,
Expand Down Expand Up @@ -126,7 +128,8 @@ class SnapAssistContent extends St.BoxLayout {
}

private set snapAssistantThreshold(value: number) {
this._snapAssistantThreshold = value;
this._snapAssistantThreshold =
value * getMonitorScalingFactor(this._monitorIndex);
}

get showing(): boolean {
Expand Down Expand Up @@ -182,7 +185,12 @@ class SnapAssistContent extends St.BoxLayout {

private get _desiredY(): number {
return this._isEnlarged
? ENLARGED_VERTICAL_DISTANCE
? Math.max(
0,
this._snapAssistantThreshold -
this.height / 2 +
this._bottomPadding,
)
: -this.height + this._bottomPadding;
}

Expand Down Expand Up @@ -276,41 +284,35 @@ class SnapAssistContent extends St.BoxLayout {
}
}

const size = this._isEnlarged ? this.height : this._bottomPadding;
const height =
this.height + (this._isEnlarged ? 0 : this._snapAssistantThreshold);
const minY = this._container.y;
const maxY = this._container.y + this._desiredY + height;
const minX = this._container.x + this.x - this._snapAssistantThreshold;
const maxX =
this._container.x +
this.x +
this.width +
this._snapAssistantThreshold;

const isNear =
this.isBetween(
this._container.x + this.x - this._snapAssistantThreshold,
currPointerPos.x,
this._container.x +
this.x +
this.width +
this._snapAssistantThreshold,
) &&
this.isBetween(
this._container.y - this._snapAssistantThreshold,
currPointerPos.y,
this._container.y +
size +
(this._isEnlarged ? this.y : this._snapAssistantThreshold),
);
this.isBetween(minX, currPointerPos.x, maxX) &&
this.isBetween(minY, currPointerPos.y, maxY);

// uncomment to show activation area debugging
/* global.windowGroup
.get_children()
.filter((c) => c.get_name() === 'debug')[0]
?.destroy();
const debug = new St.Widget({
x: this._container.x + this.x - this._snapAssistantThreshold,
y: this._container.y - this._snapAssistantThreshold,
height:
size +
this._snapAssistantThreshold +
(this._isEnlarged ? this.y : this._snapAssistantThreshold),
width: this.width + this._snapAssistantThreshold * 2,
style: 'border: 2px solid red; border-radius: 16px;',
x: minX,
y: minY,
height: maxY - minY,
width: maxX - minX,
style: 'border: 2px solid red; border-radius: 8px;',
name: 'debug',
});
global.windowGroup.add_child(debug);*/
global.windowGroup.add_child(debug); */

if (this._showing && this._isEnlarged === isNear) return;

Expand Down Expand Up @@ -367,6 +369,7 @@ export default class SnapAssist extends St.Widget {
constructor(
parent: Clutter.Actor,
workArea: Mtk.Rectangle,
monitorIndex: number,
scalingFactor?: number,
) {
super();
Expand All @@ -375,7 +378,7 @@ export default class SnapAssist extends St.Widget {
this.set_clip(0, 0, workArea.width, workArea.height);
if (scalingFactor) enableScalingFactorSupport(this, scalingFactor);

this._content = new SnapAssistContent(this);
this._content = new SnapAssistContent(this, monitorIndex);
}

public set workArea(newWorkArea: Mtk.Rectangle) {
Expand Down
43 changes: 39 additions & 4 deletions src/components/tilingsystem/edgeTilingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@ import {
clampPointInsideRect,
} from '@utils/ui';
import Mtk from 'gi://Mtk';
import GObject from 'gi://GObject';
import Settings from '@settings/settings';
import { registerGObjectClass } from '@utils/gjs';

const EDGE_TILING_OFFSET = 16;
const TOP_EDGE_TILING_OFFSET = 8;
const QUARTER_PERCENTAGE = 0.5;
const ACTIVATION_PERCENTAGE = 0.4;

export default class EdgeTilingManager {
@registerGObjectClass
export default class EdgeTilingManager extends GObject.Object {
static metaInfo: GObject.MetaInfo<unknown, unknown, unknown> = {
GTypeName: 'EdgeTilingManager',
Properties: {
quarterActivationPercentage: GObject.ParamSpec.uint(
'quarterActivationPercentage',
'quarterActivationPercentage',
'Threshold to trigger quarter tiling',
GObject.ParamFlags.READWRITE,
1,
50,
40,
),
},
};
private _workArea: Mtk.Rectangle;
private _quarterActivationPercentage: number;

// activation zones
private _topLeft: Mtk.Rectangle;
Expand All @@ -27,6 +44,7 @@ export default class EdgeTilingManager {
private _activeEdgeTile: Mtk.Rectangle | null;

constructor(initialWorkArea: Mtk.Rectangle) {
super();
this._workArea = buildRectangle();
this._topLeft = buildRectangle();
this._topRight = buildRectangle();
Expand All @@ -37,6 +55,18 @@ export default class EdgeTilingManager {
this._rightCenter = buildRectangle();
this._activeEdgeTile = null;
this.workarea = initialWorkArea;
this._quarterActivationPercentage =
Settings.get_quarter_tiling_threshold();
Settings.bind(
Settings.SETTING_QUARTER_TILING_THRESHOLD,
this,
'quarterActivationPercentage',
);
}

private set quarterActivationPercentage(value: number) {
this._quarterActivationPercentage = value / 100;
this._updateActivationZones();
}

public set workarea(newWorkArea: Mtk.Rectangle) {
Expand All @@ -45,8 +75,13 @@ export default class EdgeTilingManager {
this._workArea.width = newWorkArea.width;
this._workArea.height = newWorkArea.height;

const width = this._workArea.width * ACTIVATION_PERCENTAGE;
const height = this._workArea.height * ACTIVATION_PERCENTAGE;
this._updateActivationZones();
}

private _updateActivationZones() {
const width = this._workArea.width * this._quarterActivationPercentage;
const height =
this._workArea.height * this._quarterActivationPercentage;

this._topLeft.x = this._workArea.x;
this._topLeft.y = this._workArea.y;
Expand Down
30 changes: 15 additions & 15 deletions src/components/tilingsystem/tilingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
buildMargin,
buildRectangle,
buildTileGaps,
getScalingFactor,
getMonitorScalingFactor,
getScalingFactorOf,
isPointInsideRect,
} from '@/utils/ui';
Expand Down Expand Up @@ -83,7 +83,7 @@ export class TilingManager {
this._edgeTilingManager = new EdgeTilingManager(this._workArea);

const monitorScalingFactor = this._enableScaling
? getScalingFactor(monitor.index)
? getMonitorScalingFactor(monitor.index)
: undefined;
// build the tiling layout
this._tilingLayout = new TilingLayout(
Expand All @@ -103,6 +103,7 @@ export class TilingManager {
this._snapAssist = new SnapAssist(
Main.uiGroup,
this._workArea,
this._monitor.index,
monitorScalingFactor,
);
}
Expand Down Expand Up @@ -775,24 +776,23 @@ export class TilingManager {
// abort if there is an invalid selection
if (destinationRect.width <= 0 || destinationRect.height <= 0) return;

if (window.get_maximized()) return;
const rememberOriginalSize = !window.get_maximized();
if (window.get_maximized()) window.unmaximize(Meta.MaximizeFlags.BOTH);

if (!(window as ExtendedWindow).assignedTile) {
if (rememberOriginalSize && !(window as ExtendedWindow).assignedTile) {
(window as ExtendedWindow).originalSize = window
.get_frame_rect()
.copy();
}
(window as ExtendedWindow).assignedTile = new Tile({
...TileUtils.build_tile(
buildRectangle({
x: scaledRect.x,
y: scaledRect.y,
width: scaledRect.width,
height: scaledRect.height,
}),
this._workArea,
),
});
(window as ExtendedWindow).assignedTile = TileUtils.build_tile(
buildRectangle({
x: scaledRect.x,
y: scaledRect.y,
width: scaledRect.width,
height: scaledRect.height,
}),
this._workArea,
);
this._easeWindowRect(window, destinationRect);
}
}
4 changes: 2 additions & 2 deletions src/components/window_menu/overriddenWindowMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { registerGObjectClass } from '@utils/gjs';
import Tile from '@components/layout/Tile';
import {
enableScalingFactorSupport,
getScalingFactor,
getMonitorScalingFactor,
getWindows,
} from '@utils/ui';
import ExtendedWindow from '@components/tilingsystem/extendedWindow';
Expand Down Expand Up @@ -132,7 +132,7 @@ export default class OverriddenWindowMenu extends GObject.Object {

const enableScaling =
window.get_monitor() === Main.layoutManager.primaryIndex;
const scalingFactor = getScalingFactor(window.get_monitor());
const scalingFactor = getMonitorScalingFactor(window.get_monitor());
const gaps = Settings.get_inner_gaps(1).top > 0 ? 2 : 0;

if (vacantTiles.length > 0) {
Expand Down
Loading

0 comments on commit ab2a08e

Please sign in to comment.