refactor(ags): finish typechecking existing code
This commit is contained in:
parent
6ab95385ee
commit
63c5d0b72f
4 changed files with 77 additions and 38 deletions
|
@ -21,7 +21,6 @@ exec(`sassc ${scss} ${css}`);
|
||||||
Setup();
|
Setup();
|
||||||
|
|
||||||
|
|
||||||
// TODO: get rid of 'properties' and 'binds' prop
|
|
||||||
export default {
|
export default {
|
||||||
style: css,
|
style: css,
|
||||||
notificationPopupTimeout: 5000,
|
notificationPopupTimeout: 5000,
|
||||||
|
|
|
@ -80,6 +80,7 @@ const ModKey = (key) => {
|
||||||
const button = EventBox({
|
const button = EventBox({
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
class_name: 'key',
|
class_name: 'key',
|
||||||
|
|
||||||
on_primary_click_release: (self) => {
|
on_primary_click_release: (self) => {
|
||||||
console.log('mod toggled');
|
console.log('mod toggled');
|
||||||
|
|
||||||
|
@ -89,6 +90,7 @@ const ModKey = (key) => {
|
||||||
self.child.toggleClassName('active', !Mod.value);
|
self.child.toggleClassName('active', !Mod.value);
|
||||||
Mod.value = !Mod.value;
|
Mod.value = !Mod.value;
|
||||||
},
|
},
|
||||||
|
|
||||||
setup: (self) => {
|
setup: (self) => {
|
||||||
self.hook(NormalClick, () => {
|
self.hook(NormalClick, () => {
|
||||||
Mod.value = false;
|
Mod.value = false;
|
||||||
|
|
|
@ -21,7 +21,7 @@ export default () => Box({
|
||||||
Icon({
|
Icon({
|
||||||
size: 26,
|
size: 26,
|
||||||
class_name: 'slider-label',
|
class_name: 'slider-label',
|
||||||
binds: [['icon', SpeakerIcon, 'value']],
|
icon: SpeakerIcon.bind(),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Slider({
|
Slider({
|
||||||
|
@ -62,7 +62,7 @@ export default () => Box({
|
||||||
children: [
|
children: [
|
||||||
Icon({
|
Icon({
|
||||||
class_name: 'slider-label',
|
class_name: 'slider-label',
|
||||||
binds: [['icon', Brightness, 'screen-icon']],
|
icon: Brightness.bind('screenIcon'),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Slider({
|
Slider({
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import App from 'resource:///com/github/Aylur/ags/app.js';
|
import App from 'resource:///com/github/Aylur/ags/app.js';
|
||||||
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
||||||
import Service from 'resource:///com/github/Aylur/ags/service.js';
|
import Service from 'resource:///com/github/Aylur/ags/service.js';
|
||||||
|
|
||||||
import { subprocess } from 'resource:///com/github/Aylur/ags/utils.js';
|
import { subprocess } from 'resource:///com/github/Aylur/ags/utils.js';
|
||||||
import GUdev from 'gi://GUdev';
|
|
||||||
|
const { GUdev } = imports.gi;
|
||||||
|
|
||||||
const UDEV_POINTERS = [
|
const UDEV_POINTERS = [
|
||||||
'ID_INPUT_MOUSE',
|
'ID_INPUT_MOUSE',
|
||||||
|
@ -34,8 +36,10 @@ class Pointers extends Service {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type typeof imports.gi.Gio.Subprocess */
|
||||||
#process;
|
#process;
|
||||||
#lastLine = '';
|
#lastLine = '';
|
||||||
|
/** @type Array<string> */
|
||||||
#pointers = [];
|
#pointers = [];
|
||||||
#udevClient = GUdev.Client.new(['input']);
|
#udevClient = GUdev.Client.new(['input']);
|
||||||
|
|
||||||
|
@ -60,7 +64,12 @@ class Pointers extends Service {
|
||||||
// FIXME: logitech mouse screws everything up on disconnect
|
// FIXME: logitech mouse screws everything up on disconnect
|
||||||
#initUdevConnection() {
|
#initUdevConnection() {
|
||||||
this.#getDevices();
|
this.#getDevices();
|
||||||
this.#udevClient.connect('uevent', (_, action) => {
|
this.#udevClient.connect('uevent',
|
||||||
|
/**
|
||||||
|
* @param {typeof imports.gi.GUdev.Client} _
|
||||||
|
* @param {string} action
|
||||||
|
*/
|
||||||
|
(_, action) => {
|
||||||
if (action === 'add' || action === 'remove') {
|
if (action === 'add' || action === 'remove') {
|
||||||
this.#getDevices();
|
this.#getDevices();
|
||||||
if (this.#process) {
|
if (this.#process) {
|
||||||
|
@ -73,8 +82,12 @@ class Pointers extends Service {
|
||||||
|
|
||||||
#getDevices() {
|
#getDevices() {
|
||||||
this.#pointers = [];
|
this.#pointers = [];
|
||||||
this.#udevClient.query_by_subsystem('input').forEach((dev) => {
|
this.#udevClient.query_by_subsystem('input').forEach(
|
||||||
const isPointer = UDEV_POINTERS.some((p) => dev.has_property(p));
|
/** @param {typeof imports.gi.GUdev.Device} dev */
|
||||||
|
(dev) => {
|
||||||
|
const isPointer = UDEV_POINTERS.some(
|
||||||
|
(p) => dev.has_property(p),
|
||||||
|
);
|
||||||
|
|
||||||
if (isPointer) {
|
if (isPointer) {
|
||||||
const hasEventFile = dev.has_property('DEVNAME') &&
|
const hasEventFile = dev.has_property('DEVNAME') &&
|
||||||
|
@ -85,7 +98,8 @@ class Pointers extends Service {
|
||||||
this.#pointers.push(dev.get_property('DEVNAME'));
|
this.#pointers.push(dev.get_property('DEVNAME'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
this.emit('device-fetched', true);
|
this.emit('device-fetched', true);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +137,6 @@ class Pointers extends Service {
|
||||||
this.emit('new-line', output);
|
this.emit('new-line', output);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(err) => logError(err),
|
|
||||||
);
|
);
|
||||||
this.emit('proc-started', true);
|
this.emit('proc-started', true);
|
||||||
}
|
}
|
||||||
|
@ -139,8 +152,11 @@ class Pointers extends Service {
|
||||||
#initAppConnection() {
|
#initAppConnection() {
|
||||||
App.connect('window-toggled', () => {
|
App.connect('window-toggled', () => {
|
||||||
const anyVisibleAndClosable = Array.from(App.windows).some((w) => {
|
const anyVisibleAndClosable = Array.from(App.windows).some((w) => {
|
||||||
|
// @ts-expect-error
|
||||||
const closable = w[1].attribute?.close_on_unfocus &&
|
const closable = w[1].attribute?.close_on_unfocus &&
|
||||||
|
// @ts-expect-error
|
||||||
!(w[1].attribute?.close_on_unfocus === 'none' ||
|
!(w[1].attribute?.close_on_unfocus === 'none' ||
|
||||||
|
// @ts-expect-error
|
||||||
w[1].attribute?.close_on_unfocus === 'stay');
|
w[1].attribute?.close_on_unfocus === 'stay');
|
||||||
|
|
||||||
return w[1].visible && closable;
|
return w[1].visible && closable;
|
||||||
|
@ -156,9 +172,12 @@ class Pointers extends Service {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param {string} clickStage */
|
||||||
static detectClickedOutside(clickStage) {
|
static detectClickedOutside(clickStage) {
|
||||||
const toClose = Array.from(App.windows).some((w) => {
|
const toClose = Array.from(App.windows).some((w) => {
|
||||||
|
// @ts-expect-error
|
||||||
const closable = (w[1].attribute?.close_on_unfocus &&
|
const closable = (w[1].attribute?.close_on_unfocus &&
|
||||||
|
// @ts-expect-error
|
||||||
w[1].attribute?.close_on_unfocus === clickStage);
|
w[1].attribute?.close_on_unfocus === clickStage);
|
||||||
|
|
||||||
return w[1].visible && closable;
|
return w[1].visible && closable;
|
||||||
|
@ -168,22 +187,31 @@ class Pointers extends Service {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hyprland.sendMessage('j/layers').then((layers) => {
|
Hyprland.sendMessage('j/layers').then((response) => {
|
||||||
layers = JSON.parse(layers);
|
// /** @type import('types/service/hyprland').Layer */
|
||||||
|
const layers = JSON.parse(response);
|
||||||
|
|
||||||
Hyprland.sendMessage('j/cursorpos').then((pos) => {
|
Hyprland.sendMessage('j/cursorpos').then((res) => {
|
||||||
pos = JSON.parse(pos);
|
const pos = JSON.parse(res);
|
||||||
|
|
||||||
Object.values(layers).forEach((key) => {
|
Object.values(layers).forEach((key) => {
|
||||||
const bar = key.levels['3']
|
const bar = key.levels['3'].find(
|
||||||
.find((n) => n.namespace === 'bar');
|
/** @param {{ namespace: string }} n */
|
||||||
|
(n) => n.namespace === 'bar',
|
||||||
|
);
|
||||||
|
|
||||||
const widgets = key.levels['3'].filter((n) => {
|
const widgets = key.levels['3'].filter(
|
||||||
|
/** @param {{ namespace: string }} n */
|
||||||
|
(n) => {
|
||||||
const window = App.getWindow(n.namespace);
|
const window = App.getWindow(n.namespace);
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
return window?.attribute?.close_on_unfocus &&
|
return window?.attribute?.close_on_unfocus &&
|
||||||
window?.attribute?.close_on_unfocus === clickStage;
|
// @ts-expect-error
|
||||||
});
|
window?.attribute
|
||||||
|
?.close_on_unfocus === clickStage;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (pos.x > bar?.x && pos.x < bar?.x + bar?.w &&
|
if (pos.x > bar?.x && pos.x < bar?.x + bar?.w &&
|
||||||
pos.y > bar?.y && pos.y < bar?.y + bar?.h) {
|
pos.y > bar?.y && pos.y < bar?.y + bar?.h) {
|
||||||
|
@ -192,12 +220,22 @@ class Pointers extends Service {
|
||||||
// TODO: make this configurable
|
// TODO: make this configurable
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
widgets.forEach((w) => {
|
widgets.forEach(
|
||||||
|
/** @param {{
|
||||||
|
* namespace: string
|
||||||
|
* x: number
|
||||||
|
* y: number
|
||||||
|
* h: number
|
||||||
|
* w: number
|
||||||
|
* }} w
|
||||||
|
*/
|
||||||
|
(w) => {
|
||||||
if (!(pos.x > w.x && pos.x < w.x + w.w &&
|
if (!(pos.x > w.x && pos.x < w.x + w.w &&
|
||||||
pos.y > w.y && pos.y < w.y + w.h)) {
|
pos.y > w.y && pos.y < w.y + w.h)) {
|
||||||
App.closeWindow(w.namespace);
|
App.closeWindow(w.namespace);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(print);
|
}).catch(print);
|
||||||
|
|
Loading…
Reference in a new issue