Skip to content

Commit 886a069

Browse files
authored
feat: Move mouse focus position config to gnome extension options
1 parent aaf86e4 commit 886a069

File tree

6 files changed

+82
-50
lines changed

6 files changed

+82
-50
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
@@ -43,6 +43,11 @@
4343
<summary>Move cursor to active window when navigating with keyboard shortcuts or touchpad gestures</summary>
4444
</key>
4545

46+
<key type="u" name="mouse-cursor-focus-location">
47+
<default>0</default>
48+
<summary>The location the mouse cursor focuses when selecting a window</summary>
49+
</key>
50+
4651
<!-- Tiling Options -->
4752
<key type="u" name="column-size">
4853
<default>64</default>

src/config.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ export interface FloatRule {
8383
title?: string;
8484
};
8585

86-
export enum DefaultPointerPosition {
87-
TopLeft = "TOP_LEFT",
88-
TopRight = "TOP_RIGHT",
89-
BottomLeft = "BOTTOM_LEFT",
90-
BottomRight = "BOTTOM_RIGHT",
91-
Center = "CENTER",
92-
};
93-
9486
export class Config {
9587
/** List of windows that should float, regardless of their WM hints */
9688
float: Array<FloatRule> = [];
@@ -104,9 +96,6 @@ export class Config {
10496
/** Logs window details on focus of window */
10597
log_on_focus: boolean = false;
10698

107-
/** Specify default pointer position when you're switching windows */
108-
default_pointer_position: DefaultPointerPosition = DefaultPointerPosition.TopLeft;
109-
11099
/** Add a floating exception which matches by wm_class */
111100
add_app_exception(wmclass: string) {
112101
for (const r of this.float) {
@@ -179,7 +168,6 @@ export class Config {
179168
let c = conf.value;
180169
this.float = c.float;
181170
this.log_on_focus = c.log_on_focus;
182-
this.default_pointer_position = c.default_pointer_position;
183171
} else {
184172
log(`error loading conf: ${conf.why}`)
185173
}

src/focus.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import * as Geom from 'geom';
66
import type { ShellWindow } from 'window';
77
import type { Ext } from './extension';
88

9+
export enum FocusPosition {
10+
TopLeft = "Top Left",
11+
TopRight = "Top Right",
12+
BottomLeft = "Bottom Left",
13+
BottomRight = "Bottom Right",
14+
Center = "Center",
15+
}
16+
917
export class FocusSelector {
1018
select(
1119
ext: Ext,

src/prefs.ts

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { Settings } = imports.gi.Gio;
1010

1111
import * as settings from 'settings';
1212
import * as log from 'log';
13+
import * as focus from 'focus';
1314

1415
interface AppWidgets {
1516
fullscreen_launcher: any,
@@ -20,6 +21,8 @@ interface AppWidgets {
2021
smart_gaps: any,
2122
snap_to_grid: any,
2223
window_titles: any,
24+
mouse_cursor_focus_position: any,
25+
log_level: any,
2326
}
2427

2528
// @ts-ignore
@@ -66,6 +69,12 @@ function settings_dialog_new(): Gtk.Container {
6669
}
6770
});
6871

72+
app.log_level.set_active(ext.log_level());
73+
app.log_level.connect("changed", () => {
74+
let active_id = app.log_level.get_active_id();
75+
ext.set_log_level(active_id);
76+
});
77+
6978
app.show_skip_taskbar.set_active(ext.show_skiptaskbar());
7079
app.show_skip_taskbar.connect('state-set', (_widget: any, state: boolean) => {
7180
ext.set_show_skiptaskbar(state);
@@ -78,6 +87,12 @@ function settings_dialog_new(): Gtk.Container {
7887
Settings.sync();
7988
});
8089

90+
app.mouse_cursor_focus_position.set_active(ext.mouse_cursor_focus_location());
91+
app.mouse_cursor_focus_position.connect("changed", () => {
92+
let active_id = app.mouse_cursor_focus_position.get_active_id();
93+
ext.set_mouse_cursor_focus_location(active_id);
94+
});
95+
8196
app.fullscreen_launcher.set_active(ext.fullscreen_launcher())
8297
app.fullscreen_launcher.connect('state-set', (_widget: any, state: boolean) => {
8398
ext.set_fullscreen_launcher(state)
@@ -128,7 +143,7 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
128143
xalign: 0.0
129144
})
130145

131-
const [inner_gap, outer_gap] = gaps_section(grid, 7);
146+
const [inner_gap, outer_gap] = gaps_section(grid, 8);
132147

133148
const settings = {
134149
inner_gap,
@@ -138,7 +153,19 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
138153
snap_to_grid: new Gtk.Switch({ halign: Gtk.Align.END }),
139154
window_titles: new Gtk.Switch({ halign: Gtk.Align.END }),
140155
show_skip_taskbar: new Gtk.Switch({ halign: Gtk.Align.END }),
141-
mouse_cursor_follows_active_window: new Gtk.Switch({ halign: Gtk.Align.END })
156+
mouse_cursor_follows_active_window: new Gtk.Switch({ halign: Gtk.Align.END }),
157+
mouse_cursor_focus_position: build_combo(
158+
grid,
159+
6,
160+
focus.FocusPosition,
161+
'Mouse Cursor Focus Position',
162+
),
163+
log_level: build_combo(
164+
grid,
165+
7,
166+
log.LOG_LEVELS,
167+
'Log Level',
168+
)
142169
}
143170

144171
grid.attach(win_label, 0, 0, 1, 1)
@@ -159,8 +186,6 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
159186
grid.attach(mouse_cursor_follows_active_window_label, 0, 5, 1, 1)
160187
grid.attach(settings.mouse_cursor_follows_active_window, 1, 5, 1, 1)
161188

162-
logging_combo(grid, 6)
163-
164189
return [settings, grid]
165190
}
166191

@@ -199,35 +224,29 @@ function number_entry(): Gtk.Widget {
199224
return new Gtk.Entry({ input_purpose: Gtk.InputPurpose.NUMBER });
200225
}
201226

202-
function logging_combo(grid: any, top_index: number) {
203-
let log_label = new Gtk.Label({
204-
label: `Log Level`,
227+
function build_combo(
228+
grid: any,
229+
top_index: number,
230+
iter_enum: any,
231+
label: string,
232+
) {
233+
let label_ = new Gtk.Label({
234+
label: label,
205235
halign: Gtk.Align.START
206236
});
207237

208-
grid.attach(log_label, 0, top_index, 1, 1);
238+
grid.attach(label_, 0, top_index, 1, 1);
209239

210-
let log_combo = new Gtk.ComboBoxText();
240+
let combo = new Gtk.ComboBoxText();
211241

212-
for (const key in log.LOG_LEVELS) {
213-
// since log level loop will contain key and level,
214-
// then cherry-pick the number, key will be the text value
215-
if (typeof log.LOG_LEVELS[key] === 'number') {
216-
log_combo.append(`${log.LOG_LEVELS[key]}`, key);
242+
for (const [index, key] of Object.keys(iter_enum).entries()) {
243+
if (typeof iter_enum[key] == 'string') {
244+
combo.append(`${index}`, iter_enum[key]);
217245
}
218246
}
219247

220-
let current_log_level = log.log_level();
221-
222-
log_combo.set_active_id(`${current_log_level}`);
223-
log_combo.connect("changed", () => {
224-
let activeId = log_combo.get_active_id();
225-
226-
let settings = ExtensionUtils.getSettings();
227-
settings.set_uint('log-level', activeId);
228-
});
229-
230-
grid.attach(log_combo, 1, top_index, 1, 1);
248+
grid.attach(combo, 1, top_index, 1, 1);
249+
return combo
231250
}
232251

233252
// @ts-ignore

src/settings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const DEFAULT_RGBA_COLOR = "rgba(251, 184, 108, 1)"; //pop-orange
6464
const LOG_LEVEL = "log-level";
6565
const SHOW_SKIPTASKBAR = "show-skip-taskbar";
6666
const MOUSE_CURSOR_FOLLOWS_ACTIVE_WINDOW = "mouse-cursor-follows-active-window"
67+
const MOUSE_CURSOR_FOCUS_LOCATION = "mouse-cursor-focus-location";
6768

6869
export class ExtensionSettings {
6970
ext: Settings = settings_new_schema(Me.metadata["settings-schema"]);
@@ -167,6 +168,10 @@ export class ExtensionSettings {
167168
return this.ext.get_boolean(MOUSE_CURSOR_FOLLOWS_ACTIVE_WINDOW);
168169
}
169170

171+
mouse_cursor_focus_location(): number {
172+
return this.ext.get_uint(MOUSE_CURSOR_FOCUS_LOCATION);
173+
}
174+
170175
// Setters
171176

172177
set_active_hint(set: boolean) {
@@ -238,4 +243,8 @@ export class ExtensionSettings {
238243
set_mouse_cursor_follows_active_window(set: boolean) {
239244
this.ext.set_boolean(MOUSE_CURSOR_FOLLOWS_ACTIVE_WINDOW, set);
240245
}
246+
247+
set_mouse_cursor_focus_location(set: number) {
248+
this.ext.set_uint(MOUSE_CURSOR_FOCUS_LOCATION, set);
249+
}
241250
}

src/window.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-ignore
22
const Me = imports.misc.extensionUtils.getCurrentExtension();
33

4-
import * as Config from 'config';
54
import * as lib from 'lib';
65
import * as log from 'log';
76
import * as once_cell from 'once_cell';
@@ -13,8 +12,8 @@ import type { Entity } from './ecs';
1312
import type { Ext } from './extension';
1413
import type { Rectangle } from './rectangle';
1514
import * as scheduler from 'scheduler';
15+
import * as focus from 'focus';
1616

17-
const { DefaultPointerPosition } = Config;
1817
const { Gdk, Meta, Shell, St, GLib } = imports.gi;
1918

2019
const { OnceCell } = once_cell;
@@ -124,7 +123,7 @@ export class ShellWindow {
124123
}
125124

126125
activate(move_mouse: boolean = true): void {
127-
activate(this.ext, move_mouse, this.ext.conf.default_pointer_position, this.meta);
126+
activate(this.ext, move_mouse, this.meta);
128127
}
129128

130129
actor_exists(): boolean {
@@ -380,7 +379,8 @@ export class ShellWindow {
380379
let br = other.rect().clone();
381380

382381
other.move(ext, ar);
383-
this.move(ext, br, () => place_pointer_on(this.ext.conf.default_pointer_position, this.meta));
382+
this.move(ext, br, () => place_pointer_on(this.ext, this.meta)
383+
);
384384
}
385385

386386
title(): string {
@@ -661,7 +661,7 @@ export class ShellWindow {
661661
}
662662

663663
/// Activates a window, and moves the mouse point.
664-
export function activate(ext: Ext, move_mouse: boolean, default_pointer_position: Config.DefaultPointerPosition, win: Meta.Window) {
664+
export function activate(ext: Ext, move_mouse: boolean, win: Meta.Window) {
665665
try {
666666
if (win.is_override_redirect()) return
667667

@@ -681,7 +681,7 @@ export function activate(ext: Ext, move_mouse: boolean, default_pointer_position
681681
&& pointer_in_work_area()
682682

683683
if (pointer_placement_permitted) {
684-
place_pointer_on(default_pointer_position, win)
684+
place_pointer_on(ext, win)
685685
}
686686
} catch (error) {
687687
log.error(`failed to activate window: ${error}`)
@@ -698,29 +698,32 @@ function pointer_in_work_area(): boolean {
698698
return mon ? cursor.intersects(mon) : false
699699
}
700700

701-
export function place_pointer_on(default_pointer_position: Config.DefaultPointerPosition, win: Meta.Window) {
701+
function place_pointer_on(ext: Ext, win: Meta.Window) {
702702
const rect = win.get_frame_rect();
703703
let x = rect.x;
704704
let y = rect.y;
705705

706-
switch (default_pointer_position) {
707-
case DefaultPointerPosition.TopLeft:
706+
let key = Object.keys(focus.FocusPosition)[ext.settings.mouse_cursor_focus_location()]
707+
let pointer_position_ = focus.FocusPosition[key as keyof typeof focus.FocusPosition]
708+
709+
switch (pointer_position_) {
710+
case focus.FocusPosition.TopLeft:
708711
x += 8;
709712
y += 8;
710713
break;
711-
case DefaultPointerPosition.BottomLeft:
714+
case focus.FocusPosition.BottomLeft:
712715
x += 8;
713716
y += (rect.height - 16);
714717
break;
715-
case DefaultPointerPosition.TopRight:
718+
case focus.FocusPosition.TopRight:
716719
x += (rect.width - 16);
717720
y += 8;
718721
break;
719-
case DefaultPointerPosition.BottomRight:
722+
case focus.FocusPosition.BottomRight:
720723
x += (rect.width - 16);
721724
y += (rect.height - 16);
722725
break;
723-
case DefaultPointerPosition.Center:
726+
case focus.FocusPosition.Center:
724727
x += (rect.width / 2) + 8;
725728
y += (rect.height / 2) + 8;
726729
break;

0 commit comments

Comments
 (0)