Skip to content

Commit 787c8ea

Browse files
committed
refactor(dock): simplify code by removing unnecessary checks and improving type usage
1 parent 5d9a04a commit 787c8ea

2 files changed

Lines changed: 27 additions & 86 deletions

File tree

src/modules/dock.ts

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ const HOT_AREA_REVEAL_DURATION = 1500;
2020
/** Height (in pixels) of the invisible strip at the screen bottom that triggers dock reveal. */
2121
const HOT_AREA_STRIP_HEIGHT = 1;
2222

23-
const HOT_AREA_ALLOWED_MODES = Shell.ActionMode.ALL ?? [
24-
Shell.ActionMode.NORMAL,
25-
Shell.ActionMode.OVERVIEW,
26-
Shell.ActionMode.POPUP,
27-
Shell.ActionMode.FULLSCREEN,
28-
].reduce((mask, mode) => mask | (typeof mode === 'number' ? mode : 0), 0);
29-
3023
/** Window types considered when checking whether a window overlaps the dock. */
3124
const OVERLAP_WINDOW_TYPES: Meta.WindowType[] = [
3225
Meta.WindowType.NORMAL,
@@ -40,18 +33,10 @@ const OVERLAP_WINDOW_TYPES: Meta.WindowType[] = [
4033
];
4134

4235
enum OverlapStatus {
43-
UNDEFINED = -1,
4436
CLEAR = 0,
4537
BLOCKED = 1,
4638
}
4739

48-
type MonitorGeometry = {
49-
x: number;
50-
y: number;
51-
width: number;
52-
height: number;
53-
};
54-
5540
type ManagedDockBinding = {
5641
monitorIndex: number;
5742
container: St.Bin;
@@ -78,16 +63,16 @@ const DockHotArea = GObject.registerClass({
7863
private _pressureBarrier: any;
7964
private _horizontalBarrier: Meta.Barrier | null = null;
8065
private _triggerAllowed = true;
81-
private _monitor: MonitorGeometry;
66+
private _monitor: DashBounds;
8267

83-
_init(monitor: MonitorGeometry) {
68+
_init(monitor: DashBounds) {
8469
super._init({ reactive: true, visible: true, name: 'aurora-dock-hot-area' });
8570
this._monitor = monitor;
8671

8772
this._pressureBarrier = new Layout.PressureBarrier(
8873
HOT_AREA_TRIGGER_SPEED,
8974
HOT_AREA_TRIGGER_TIMEOUT,
90-
HOT_AREA_ALLOWED_MODES || Shell.ActionMode.NORMAL
75+
Shell.ActionMode.ALL
9176
);
9277

9378
this._pressureBarrier.connectObject('trigger', () => {
@@ -111,15 +96,11 @@ const DockHotArea = GObject.registerClass({
11196
);
11297
}
11398

114-
setGeometry(monitor: MonitorGeometry): void {
99+
setGeometry(monitor: DashBounds): void {
115100
this._monitor = monitor;
116101
this._rebuildBarrier(monitor.width);
117102
}
118103

119-
setBarrierSize(size: number): void {
120-
this._rebuildBarrier(size);
121-
}
122-
123104
override destroy(): void {
124105
global.display.disconnectObject(this);
125106
this._destroyBarrier();
@@ -171,26 +152,19 @@ const DockHotArea = GObject.registerClass({
171152
* CLEAR and BLOCKED so the Dock module can show/hide the dash accordingly.
172153
*/
173154
const DockIntellihide = GObject.registerClass({
174-
Properties: {
175-
'monitor-index': GObject.ParamSpec.int(
176-
'monitor-index', 'Monitor Index',
177-
'Monitor tracked for dock overlap checks',
178-
GObject.ParamFlags.READWRITE, -1, 32,
179-
Main.layoutManager.primaryIndex
180-
),
181-
},
182155
Signals: { 'status-changed': {} },
183156
}, class DockIntellihide extends GObject.Object {
184157
private declare _monitorIndex: number;
185158
private declare _tracker: Shell.WindowTracker | null;
186159
private _targetBox: DashBounds | null = null;
187-
private _status: OverlapStatus = OverlapStatus.UNDEFINED;
160+
private _status: OverlapStatus = OverlapStatus.CLEAR;
188161
private _focusActor: any = null;
189162
private _focusActorId = 0;
190163
private _destroyed = false;
191164

192-
_init(params: { 'monitor-index'?: number } = {}) {
193-
super._init(params);
165+
_init(monitorIndex: number) {
166+
super._init();
167+
this._monitorIndex = monitorIndex;
194168
this._tracker = Shell.WindowTracker.get_default() ?? null;
195169

196170
global.display.connectObject(
@@ -211,16 +185,6 @@ const DockIntellihide = GObject.registerClass({
211185
);
212186
}
213187

214-
get monitorIndex(): number {
215-
return this._monitorIndex;
216-
}
217-
218-
set monitorIndex(index: number) {
219-
if (typeof index !== 'number' || this._monitorIndex === index) return;
220-
this._monitorIndex = index;
221-
this._checkOverlap();
222-
}
223-
224188
get status(): OverlapStatus {
225189
return this._status;
226190
}
@@ -243,7 +207,6 @@ const DockIntellihide = GObject.registerClass({
243207
Main.overview.disconnectObject(this);
244208
this.disconnectObject?.(this);
245209

246-
// GObject.Object has no destroy(); use run_dispose() instead
247210
(this as unknown as { run_dispose?: () => void }).run_dispose?.();
248211
}
249212

@@ -368,7 +331,6 @@ export class Dock extends Module {
368331
global.display.connectObject('workareas-changed', () => this._refreshWorkAreas(), this);
369332
Main.sessionMode.connectObject('updated', () => this._refreshBindingsLayout(), this);
370333

371-
// Hide the dock while the overview or app grid is visible
372334
Main.overview.connectObject(
373335
'showing', () => this._setOverviewVisible(true),
374336
'hidden', () => this._setOverviewVisible(false),
@@ -388,7 +350,7 @@ export class Dock extends Module {
388350
private _rebuildBindings(): void {
389351
this._clearBindings();
390352

391-
const monitors: MonitorGeometry[] = Main.layoutManager.monitors ?? [];
353+
const monitors: DashBounds[] = Main.layoutManager.monitors ?? [];
392354
monitors.forEach((monitor, index) => {
393355
if (this._hasDefinedBottom(monitors, index)) {
394356
const binding = this._createBinding(monitor, index);
@@ -399,7 +361,7 @@ export class Dock extends Module {
399361
this._refreshWorkAreas();
400362
}
401363

402-
private _createBinding(monitor: MonitorGeometry, monitorIndex: number): ManagedDockBinding | null {
364+
private _createBinding(monitor: DashBounds, monitorIndex: number): ManagedDockBinding | null {
403365
const container = new St.Bin({
404366
name: `aurora-dock-container-${monitorIndex}`,
405367
reactive: false,
@@ -416,7 +378,7 @@ export class Dock extends Module {
416378
container.set_child(dash);
417379
dash.attachToContainer(container);
418380

419-
const intellihide = new DockIntellihide({ 'monitor-index': monitorIndex });
381+
const intellihide = new DockIntellihide(monitorIndex);
420382
dash.setTargetBoxListener((box) => intellihide.updateTargetBox(box));
421383

422384
const binding: ManagedDockBinding = {
@@ -447,8 +409,8 @@ export class Dock extends Module {
447409
return binding;
448410
}
449411

450-
private _createHotArea(binding: ManagedDockBinding, monitor: MonitorGeometry): InstanceType<typeof DockHotArea> | null {
451-
if (!isValidMonitor(monitor)) return null;
412+
private _createHotArea(binding: ManagedDockBinding, monitor: DashBounds): InstanceType<typeof DockHotArea> | null {
413+
if (monitor.width <= 0 || monitor.height <= 0) return null;
452414

453415
const hotArea = new DockHotArea(monitor);
454416
Main.layoutManager.addChrome(hotArea, {
@@ -459,7 +421,6 @@ export class Dock extends Module {
459421

460422
hotArea.set_size(monitor.width, HOT_AREA_STRIP_HEIGHT);
461423
hotArea.set_position(monitor.x, monitor.y + monitor.height - HOT_AREA_STRIP_HEIGHT);
462-
hotArea.setBarrierSize(monitor.width);
463424

464425
hotArea.connectObject('triggered', () => this._revealDockFromHotArea(binding), this);
465426

@@ -533,7 +494,7 @@ export class Dock extends Module {
533494
* Returns true if no other monitor sits directly below this one.
534495
* Used to avoid placing a dock between vertically stacked monitors.
535496
*/
536-
private _hasDefinedBottom(monitors: MonitorGeometry[], index: number): boolean {
497+
private _hasDefinedBottom(monitors: DashBounds[], index: number): boolean {
537498
const monitor = monitors[index];
538499
if (!monitor) return false;
539500

@@ -571,9 +532,6 @@ export class Dock extends Module {
571532
binding.autoHideReleaseId = 0;
572533
binding.hotAreaActive = false;
573534

574-
// If no window overlaps the dock, keep it visible instead of
575-
// unconditionally releasing auto-hide (which would cause the
576-
// dock to disappear even with no overlapping windows).
577535
if (binding.intellihide.status === OverlapStatus.CLEAR) {
578536
binding.dash.blockAutoHide(true);
579537
binding.dash.show(true);
@@ -593,7 +551,6 @@ export class Dock extends Module {
593551
}
594552
}
595553

596-
/** Hide all dock containers during overview/app grid, restore on close. */
597554
private _setOverviewVisible(overviewShowing: boolean): void {
598555
this._bindings.forEach((binding) => {
599556
if (overviewShowing) {
@@ -603,18 +560,9 @@ export class Dock extends Module {
603560
binding.dash.hide(false);
604561
binding.container.hide();
605562
} else {
606-
// Re-apply work area so the container is at the correct position
607-
// and size before making anything visible again.
608563
this._updateWorkArea(binding);
609-
// Let intellihide decide whether to show the dash
610564
binding.intellihide.emit('status-changed');
611565
}
612566
});
613567
}
614568
}
615-
616-
// -- Utilities --
617-
618-
function isValidMonitor(m: MonitorGeometry): boolean {
619-
return Number.isFinite(m.x) && Number.isFinite(m.y) && m.width > 0 && m.height > 0;
620-
}

src/ui/dash.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,7 @@ export class AuroraDash extends Dash {
141141

142142
/** Force the dash to re-render its icon list. */
143143
refresh(): void {
144-
const dash = this as unknown as { _redisplay?: () => void; _queueRedisplay?: () => void };
145-
if (typeof dash._redisplay === 'function') {
146-
dash._redisplay();
147-
} else {
148-
dash._queueRedisplay?.();
149-
}
144+
(this as any)._redisplay();
150145
}
151146

152147
setTargetBoxListener(listener: TargetBoxListener | null): void {
@@ -160,14 +155,13 @@ export class AuroraDash extends Dash {
160155
this._container?.disconnectObject?.(this);
161156
this._container = container;
162157

163-
const containerObj = container as unknown as {
164-
connectObject?: (signal: string, handler: () => void, scope?: object) => void;
165-
};
166-
167-
containerObj.connectObject?.('notify::allocation', () => this._queueTargetBoxUpdate(), this);
168-
containerObj.connectObject?.('destroy', () => {
169-
if (this._container === container) this._container = null;
170-
}, this);
158+
(container as any).connectObject?.(
159+
'notify::allocation', () => this._queueTargetBoxUpdate(),
160+
'destroy', () => {
161+
if (this._container === container) this._container = null;
162+
},
163+
this
164+
);
171165

172166
this._queueTargetBoxUpdate();
173167
}
@@ -521,14 +515,13 @@ export class AuroraDash extends Dash {
521515
if (!this.visible || this.translation_y !== 0) return;
522516

523517
const [stageX, stageY] = (this as any).get_transformed_position?.() ?? [0, 0];
524-
525-
const dashBounds: DashBounds = { x: stageX, y: stageY, ...size };
518+
const p = TARGET_BOX_PADDING;
526519

527520
const padded: DashBounds = {
528-
x: dashBounds.x - TARGET_BOX_PADDING,
529-
y: dashBounds.y - TARGET_BOX_PADDING,
530-
width: dashBounds.width + TARGET_BOX_PADDING * 2,
531-
height: dashBounds.height + TARGET_BOX_PADDING * 2,
521+
x: stageX - p,
522+
y: stageY - p,
523+
width: size.width + p * 2,
524+
height: size.height + p * 2,
532525
};
533526

534527
if (!boundsEqual(this._targetBox, padded)) {

0 commit comments

Comments
 (0)