Skip to content

Commit 3692dd4

Browse files
author
Szymon Mikler
authored
feat(preferences): Option to disable stacking with mouse
1 parent afa7510 commit 3692dd4

File tree

6 files changed

+47
-15
lines changed

6 files changed

+47
-15
lines changed

schemas/org.gnome.shell.extensions.pop-shell.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
<summary>Tile launched windows by default</summary>
7575
</key>
7676

77+
<key type="b" name="stacking-with-mouse">
78+
<default>true</default>
79+
<summary>Allow for stacking windows as a result of dragging a window with mouse</summary>
80+
</key>
81+
7782
<!-- Focus Shifting -->
7883
<key type="as" name="focus-left">
7984
<default><![CDATA[['<Super>Left','<Super>KP_Left','<Super>h']]]></default>

src/auto_tiler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export class AutoTiler {
408408
? fork.area
409409
: attach_to.meta.get_frame_rect()
410410

411-
let placement: null | MoveBy = cursor_placement(attach_area, cursor)
411+
let placement: null | MoveBy = cursor_placement(ext, attach_area, cursor)
412412
const stack = ext.auto_tiler?.find_stack(attach_to.entity)
413413

414414
const matching_stack = win.stack !== null && win.stack === attach_to.stack
@@ -733,11 +733,11 @@ export class AutoTiler {
733733
*
734734
* A null indicates that the window should be stacked
735735
*/
736-
export function cursor_placement(area: Rectangular, cursor: Rectangular): null | MoveByCursor {
736+
export function cursor_placement(ext: Ext, area: Rectangular, cursor: Rectangular): null | MoveByCursor {
737737
const { LEFT, RIGHT, TOP, BOTTOM } = geom.Side
738738
const { HORIZONTAL, VERTICAL } = lib.Orientation
739739

740-
const [, side] = geom.nearest_side([cursor.x, cursor.y], area)
740+
const [, side] = geom.nearest_side(ext, [cursor.x, cursor.y], area)
741741

742742
let res: null | [lib.Orientation, boolean] = side === LEFT
743743
? [HORIZONTAL, true]

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ export class Ext extends Ecs.System<ExtEvent> {
14691469

14701470
const result = monitor_attachment
14711471
? null
1472-
: auto_tiler.cursor_placement(area, cursor)
1472+
: auto_tiler.cursor_placement(this, area, cursor)
14731473

14741474
if (!result) {
14751475
this.overlay.x = area.x

src/geom.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type {Ext} from 'extension';
2+
13
export enum Side {
24
LEFT,
35
TOP,
@@ -70,7 +72,7 @@ export function leftward_distance(win_a: Meta.Window, win_b: Meta.Window) {
7072
return directional_distance(win_a.get_frame_rect(), win_b.get_frame_rect(), east, west);
7173
}
7274

73-
export function nearest_side(origin: [number, number], rect: Rectangular): [number, Side] {
75+
export function nearest_side(ext: Ext, origin: [number, number], rect: Rectangular): [number, Side] {
7476
const left = west(rect), top = north(rect), right = east(rect), bottom = south(rect), ctr = center(rect)
7577

7678
const left_distance = distance(origin, left),
@@ -85,7 +87,7 @@ export function nearest_side(origin: [number, number], rect: Rectangular): [numb
8587

8688
if (top_distance < nearest[0]) nearest = [top_distance, Side.TOP]
8789
if (bottom_distance < nearest[0]) nearest = [bottom_distance, Side.BOTTOM]
88-
if (center_distance < nearest[0]) nearest = [center_distance, Side.CENTER]
90+
if (ext.settings.stacking_with_mouse() && center_distance < nearest[0]) nearest = [center_distance, Side.CENTER]
8991

9092
return nearest
9193
}
@@ -95,4 +97,4 @@ export function shortest_side(origin: [number, number], rect: Rectangular): numb
9597
shortest = Math.min(shortest, distance(origin, north(rect)))
9698
shortest = Math.min(shortest, distance(origin, east(rect)))
9799
return Math.min(shortest, distance(origin, south(rect)))
98-
}
100+
}

src/prefs.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as focus from 'focus';
1414

1515
interface AppWidgets {
1616
fullscreen_launcher: any,
17+
stacking_with_mouse: any,
1718
inner_gap: any,
1819
mouse_cursor_follows_active_window: any,
1920
outer_gap: any,
@@ -97,7 +98,13 @@ function settings_dialog_new(): Gtk.Container {
9798
app.fullscreen_launcher.connect('state-set', (_widget: any, state: boolean) => {
9899
ext.set_fullscreen_launcher(state)
99100
Settings.sync()
100-
})
101+
});
102+
103+
app.stacking_with_mouse.set_active(ext.stacking_with_mouse())
104+
app.stacking_with_mouse.connect('state-set', (_widget: any, state: boolean) => {
105+
ext.set_stacking_with_mouse(state)
106+
Settings.sync()
107+
});
101108

102109
return grid;
103110
}
@@ -143,26 +150,32 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
143150
xalign: 0.0
144151
})
145152

146-
const [inner_gap, outer_gap] = gaps_section(grid, 8);
153+
const stacking_with_mouse = new Gtk.Label({
154+
label: "Allow stacking with mouse",
155+
xalign: 0.0
156+
})
157+
158+
const [inner_gap, outer_gap] = gaps_section(grid, 9);
147159

148160
const settings = {
149161
inner_gap,
150162
outer_gap,
151163
fullscreen_launcher: new Gtk.Switch({ halign: Gtk.Align.END }),
164+
stacking_with_mouse: new Gtk.Switch({ halign: Gtk.Align.END }),
152165
smart_gaps: new Gtk.Switch({ halign: Gtk.Align.END }),
153166
snap_to_grid: new Gtk.Switch({ halign: Gtk.Align.END }),
154167
window_titles: new Gtk.Switch({ halign: Gtk.Align.END }),
155168
show_skip_taskbar: new Gtk.Switch({ halign: Gtk.Align.END }),
156169
mouse_cursor_follows_active_window: new Gtk.Switch({ halign: Gtk.Align.END }),
157170
mouse_cursor_focus_position: build_combo(
158171
grid,
159-
6,
172+
7,
160173
focus.FocusPosition,
161174
'Mouse Cursor Focus Position',
162175
),
163176
log_level: build_combo(
164177
grid,
165-
7,
178+
8,
166179
log.LOG_LEVELS,
167180
'Log Level',
168181
)
@@ -180,11 +193,14 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
180193
grid.attach(fullscreen_launcher_label, 0, 3, 1, 1)
181194
grid.attach(settings.fullscreen_launcher, 1, 3, 1, 1)
182195

183-
grid.attach(show_skip_taskbar_label, 0, 4, 1, 1)
184-
grid.attach(settings.show_skip_taskbar, 1, 4, 1, 1)
196+
grid.attach(stacking_with_mouse, 0, 4, 1, 1)
197+
grid.attach(settings.stacking_with_mouse, 1, 4, 1, 1)
198+
199+
grid.attach(show_skip_taskbar_label, 0, 5, 1, 1)
200+
grid.attach(settings.show_skip_taskbar, 1, 5, 1, 1)
185201

186-
grid.attach(mouse_cursor_follows_active_window_label, 0, 5, 1, 1)
187-
grid.attach(settings.mouse_cursor_follows_active_window, 1, 5, 1, 1)
202+
grid.attach(mouse_cursor_follows_active_window_label, 0, 6, 1, 1)
203+
grid.attach(settings.mouse_cursor_follows_active_window, 1, 6, 1, 1)
188204

189205
return [settings, grid]
190206
}

src/settings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function settings_new_schema(schema: string): Settings {
4949

5050
const ACTIVE_HINT = "active-hint";
5151
const ACTIVE_HINT_BORDER_RADIUS = "active-hint-border-radius";
52+
const STACKING_WITH_MOUSE = "stacking-with-mouse";
5253
const COLUMN_SIZE = "column-size";
5354
const EDGE_TILING = "edge-tiling";
5455
const FULLSCREEN_LAUNCHER = "fullscreen-launcher"
@@ -82,6 +83,10 @@ export class ExtensionSettings {
8283
return this.ext.get_uint(ACTIVE_HINT_BORDER_RADIUS);
8384
}
8485

86+
stacking_with_mouse(): boolean {
87+
return this.ext.get_boolean(STACKING_WITH_MOUSE);
88+
}
89+
8590
column_size(): number {
8691
return this.ext.get_uint(COLUMN_SIZE);
8792
}
@@ -182,6 +187,10 @@ export class ExtensionSettings {
182187
this.ext.set_uint(ACTIVE_HINT_BORDER_RADIUS, set);
183188
}
184189

190+
set_stacking_with_mouse(set: boolean) {
191+
this.ext.set_boolean(STACKING_WITH_MOUSE, set);
192+
}
193+
185194
set_column_size(size: number) {
186195
this.ext.set_uint(COLUMN_SIZE, size);
187196
}

0 commit comments

Comments
 (0)