feat: enable the window manager to be able to drag across monitors and support keybindings propperly in the extension settings

This commit is contained in:
Lucas Oskorep
2025-05-20 01:20:48 -04:00
parent ed29d0a0a9
commit 57e28ff77a
9 changed files with 304 additions and 173 deletions

View File

@@ -0,0 +1,83 @@
// Gnome imports
import Adw from 'gi://Adw';
import Gtk from 'gi://Gtk';
import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
import { gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import { Logger } from '../utils/logger.js';
/**
* EntryRow class for handling text input including keybindings
*/
export class EntryRow extends Adw.EntryRow {
static {
GObject.registerClass(this);
}
constructor(params: {
title: string,
settings: Gio.Settings,
bind: string,
map?: {
from: (settings: Gio.Settings, bind: string) => string,
to: (settings: Gio.Settings, bind: string, value: string) => void
}
}) {
super({ title: params.title });
const { settings, bind, map } = params;
// When text changes, update settings
this.connect('changed', () => {
const text = this.get_text();
if (typeof text === 'string') {
if (map) {
map.to(settings, bind, text);
} else {
settings.set_string(bind, text);
}
}
});
// Set initial text from settings
const current = map ? map.from(settings, bind) : settings.get_string(bind);
this.set_text(current ?? '');
// Add reset button
this.add_suffix(
new ResetButton({
settings,
bind,
onReset: () => {
this.set_text((map ? map.from(settings, bind) : settings.get_string(bind)) ?? '');
},
})
);
}
}
/**
* Reset button for settings
*/
export class ResetButton extends Gtk.Button {
static {
GObject.registerClass(this);
}
constructor(params: {
settings?: Gio.Settings,
bind: string,
onReset?: () => void
}) {
super({
icon_name: 'edit-clear-symbolic',
tooltip_text: _('Reset'),
valign: Gtk.Align.CENTER,
});
this.connect('clicked', () => {
params.settings?.reset(params.bind);
params.onReset?.();
});
}
}