refactor(ags): do more types
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-01-29 20:56:56 -05:00
parent 9c64b00243
commit caac0507a1
13 changed files with 95 additions and 71 deletions

View file

@ -1,4 +1,5 @@
import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
import GObject from 'types/@girs/gobject-2.0/gobject-2.0';
import { Widget as agsWidget } from 'types/widgets/widget'; import { Widget as agsWidget } from 'types/widgets/widget';
export type AgsWidget = agsWidget<unknown> & Widget; export type AgsWidget = agsWidget<unknown> & Widget;
@ -72,6 +73,32 @@ export type PlayerButtonType = {
prop: string prop: string
}; };
// For ./ts/notifications/gesture.js
type NotifGestureProps = {
dragging: boolean;
hovered: boolean
ready: boolean
id: number;
slideAway(side: 'Left' | 'Right'): void;
};
export type NotifGesture = AgsEventBox<BoxGeneric, NotifGestureProps>;
// For ./ts/osd/ctor.ts
export type OSDStack = AgsStack<unknown & Widget, {
popup(osd: BoxGeneric): void,
}>;
export type ConnectFunc = (self?: ProgressBarGeneric) => void;
export type OSD = {
stack: OSDStack;
icon: string | IconPropsGeneric;
info: {
mod: GObject.Object;
signal?: string;
logic?(self: ProgressBarGeneric): void;
widget?: Widget;
}
};
// For CursorBox // For CursorBox
import { CursorBox, CursorBoxProps } from 'ts/misc/cursorbox'; import { CursorBox, CursorBoxProps } from 'ts/misc/cursorbox';
export type CursorBox = CursorBox; export type CursorBox = CursorBox;
@ -89,8 +116,8 @@ WindowProps<Child> & {
transition?: RevealerProps<Widget>['transition'] transition?: RevealerProps<Widget>['transition']
transition_duration?: number transition_duration?: number
bezier?: string bezier?: string
on_open?(self: AgsWindow<Widget, unknown>): void on_open?(self: PopupWindow<Child, Attr>): void
on_close?(self: AgsWindow<Widget, unknown>): void on_close?(self: PopupWindow<Child, Attr>): void
blur?: boolean blur?: boolean
close_on_unfocus?: CloseType close_on_unfocus?: CloseType
attribute?: Attr; attribute?: Attr;
@ -113,17 +140,27 @@ export type CenterBoxPropsGeneric = CenterBoxProps<
unknown & Widget, unknown & Widget, unknown & Widget, unknown unknown & Widget, unknown & Widget, unknown & Widget, unknown
>; >;
import AgsEventBox from 'types/widgets/eventbox.ts'; import AgsEventBox from 'types/widgets/eventbox';
export type EventBoxGeneric = AgsEventBox<unknown & Widget, unknown>; export type EventBoxGeneric = AgsEventBox<unknown & Widget, unknown>;
import AgsLabel from 'types/widgets/label.ts'; import AgsIcon, { IconProps } from 'types/widgets/icon';
export type IconGeneric = AgsIcon<unknown>;
export type IconPropsGeneric = IconProps<unknown>;
import AgsLabel from 'types/widgets/label';
export type LabelGeneric = AgsLabel<unknown>; export type LabelGeneric = AgsLabel<unknown>;
import AgsOverlay, { OverlayProps } from 'types/widgets/overlay.ts'; import AgsOverlay, { OverlayProps } from 'types/widgets/overlay';
export type OverlayGeneric = AgsOverlay<unknown & Widget, unknown>; export type OverlayGeneric = AgsOverlay<unknown & Widget, unknown>;
import AgsRevealer, { RevealerProps } from 'types/widgets/revealer.ts'; import AgsProgressBar from 'types/widgets/progressbar';
export type ProgressBarGeneric = AgsProgressBar<unknown & Widget, unknown>;
import AgsRevealer, { RevealerProps } from 'types/widgets/revealer';
export type RevealerGeneric = AgsRevealer<unknown & Widget, unknown>; export type RevealerGeneric = AgsRevealer<unknown & Widget, unknown>;
import AgsStack from 'types/widgets/stack.ts'; import AgsStack from 'types/widgets/stack';
export type StackGeneric = AgsStack<unknown & Widget, unknown>; export type StackGeneric = AgsStack<unknown & Widget, unknown>;
import AgsWindow from 'types/widgets/window';
export type WindowGeneric = AgsWindow<unknown & Widget, unknown>;

View file

@ -134,13 +134,16 @@ class Pointers extends Service {
} }
static detectClickedOutside(clickStage: string) { static detectClickedOutside(clickStage: string) {
const toClose = (Array.from(App.windows) as Array<[string, PopupWindow]>) const toClose = (
.some((w) => { Array.from(App.windows) as Array<[string, PopupWindow]>
const closable = (w[1].close_on_unfocus && ).some((w) => {
w[1].close_on_unfocus === clickStage); const closable = (
w[1].close_on_unfocus &&
w[1].close_on_unfocus === clickStage
);
return w[1].visible && closable; return w[1].visible && closable;
}); });
if (!toClose) { if (!toClose) {
return; return;

View file

@ -13,8 +13,6 @@ import CursorBox from '../misc/cursorbox.ts';
// Types // Types
import { Notification as NotifObj } from 'types/service/notifications.ts'; import { Notification as NotifObj } from 'types/service/notifications.ts';
import AgsEventBox from 'types/widgets/eventbox';
import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
import { Client } from 'types/service/hyprland.ts'; import { Client } from 'types/service/hyprland.ts';
type NotificationWidget = { type NotificationWidget = {
notif: NotifObj notif: NotifObj
@ -22,8 +20,9 @@ type NotificationWidget = {
command?(): void command?(): void
}; };
import { import {
EventBoxGeneric,
CursorBox as CBox, CursorBox as CBox,
EventBoxGeneric,
NotifGesture,
} from 'global-types'; } from 'global-types';
@ -38,7 +37,7 @@ const getDragState = (box: EventBoxGeneric) => (box
?.get_parent() ?.get_parent()
?.get_parent() ?.get_parent()
?.get_parent() ?.get_parent()
?.get_parent() as AgsEventBox<Widget, { dragging: boolean }>) ?.get_parent() as NotifGesture)
?.attribute.dragging; ?.attribute.dragging;

View file

@ -9,7 +9,7 @@ import CursorBox from '../misc/cursorbox.ts';
// Types // Types
import { Notification as NotifObj } from 'resource:///com/github/Aylur/ags/service/notifications.js'; import { Notification as NotifObj } from 'resource:///com/github/Aylur/ags/service/notifications.js';
import { BoxGeneric } from 'global-types'; import { BoxGeneric, NotifGesture } from 'global-types';
const addNotif = (box: BoxGeneric, notif: NotifObj) => { const addNotif = (box: BoxGeneric, notif: NotifObj) => {
@ -53,7 +53,7 @@ const NotificationList = () => Box({
}, 'notified') }, 'notified')
.hook(Notifications, (box, id) => { .hook(Notifications, (box, id) => {
const notif = (box.children as BoxGeneric[]) const notif = (box.children as NotifGesture[])
.find((ch) => ch.attribute.id === id); .find((ch) => ch.attribute.id === id);
if (notif?.sensitive) { if (notif?.sensitive) {

View file

@ -9,7 +9,7 @@ const { Gdk, Gtk } = imports.gi;
const display = Gdk.Display.get_default(); const display = Gdk.Display.get_default();
// Types // Types
import AgsBox from 'types/widgets/box.ts'; import { BoxGeneric } from 'global-types';
const MAX_OFFSET = 200; const MAX_OFFSET = 200;
const OFFSCREEN = 300; const OFFSCREEN = 300;
@ -107,7 +107,7 @@ export default ({
id, id,
slideAway: (side: 'Left' | 'Right') => { slideAway: (side: 'Left' | 'Right') => {
(widget.child as AgsBox) (widget.child as BoxGeneric)
.setCss(side === 'Left' ? slideLeft : slideRight); .setCss(side === 'Left' ? slideLeft : slideRight);
// Make it uninteractable // Make it uninteractable
@ -115,7 +115,7 @@ export default ({
timeout(ANIM_DURATION - 100, () => { timeout(ANIM_DURATION - 100, () => {
// Reduce height after sliding away // Reduce height after sliding away
(widget.child as AgsBox)?.setCss(side === 'Left' ? (widget.child as BoxGeneric)?.setCss(side === 'Left' ?
squeezeLeft : squeezeLeft :
squeezeRight); squeezeRight);
@ -126,7 +126,7 @@ export default ({
HasNotifs.value = Notifications HasNotifs.value = Notifications
.notifications.length > 0; .notifications.length > 0;
(widget.get_parent() as AgsBox)?.remove(widget); (widget.get_parent() as BoxGeneric)?.remove(widget);
}); });
}); });
}, },

View file

@ -10,7 +10,7 @@ import { Notification } from './base.ts';
const DELAY = 2000; const DELAY = 2000;
// Types // Types
import AgsBox from 'types/widgets/box.ts'; import { NotifGesture } from 'global-types';
export default () => Box({ export default () => Box({
@ -45,7 +45,7 @@ export default () => Box({
}; };
const handleDismiss = (id: number, force = false) => { const handleDismiss = (id: number, force = false) => {
const notif = (self.children as Array<AgsBox>) const notif = (self.children as NotifGesture[])
.find((ch) => ch.attribute.id === id); .find((ch) => ch.attribute.id === id);
if (!notif) { if (!notif) {

View file

@ -11,8 +11,7 @@ const HIDDEN_MARGIN = 340;
const ANIM_DURATION = 700; const ANIM_DURATION = 700;
// Types // Types
import AgsWindow from 'types/widgets/window.ts'; import { BoxGeneric } from 'global-types';
import AgsBox from 'types/widgets/box.ts';
const releaseAllKeys = () => { const releaseAllKeys = () => {
@ -24,9 +23,9 @@ const releaseAllKeys = () => {
]).catch(print); ]).catch(print);
}; };
export default (window: AgsWindow) => { export default (window) => {
const gesture = Gtk.GestureDrag.new(window); const gesture = Gtk.GestureDrag.new(window);
const child = window.child as AgsBox; const child = window.child as BoxGeneric;
child.setCss(`margin-bottom: -${HIDDEN_MARGIN}px;`); child.setCss(`margin-bottom: -${HIDDEN_MARGIN}px;`);
@ -94,7 +93,7 @@ export default (window: AgsWindow) => {
return; return;
} }
(window.child as AgsBox).setCss(` (window.child as BoxGeneric).setCss(`
margin-bottom: ${offset - HIDDEN_MARGIN}px; margin-bottom: ${offset - HIDDEN_MARGIN}px;
`); `);
}); });
@ -104,7 +103,7 @@ export default (window: AgsWindow) => {
// End drag // End drag
signals.push( signals.push(
gesture.connect('drag-end', () => { gesture.connect('drag-end', () => {
(window.child as AgsBox).setCss(` (window.child as BoxGeneric).setCss(`
transition: margin-bottom 0.5s ease-in-out; transition: margin-bottom 0.5s ease-in-out;
margin-bottom: -${HIDDEN_MARGIN}px; margin-bottom: -${HIDDEN_MARGIN}px;
`); `);
@ -135,7 +134,7 @@ export default (window: AgsWindow) => {
return; return;
} }
(window.child as AgsBox).setCss(` (window.child as BoxGeneric).setCss(`
margin-bottom: ${offset}px; margin-bottom: ${offset}px;
`); `);
}); });
@ -145,7 +144,7 @@ export default (window: AgsWindow) => {
// End drag // End drag
signals.push( signals.push(
gesture.connect('drag-end', () => { gesture.connect('drag-end', () => {
(window.child as AgsBox).setCss(` (window.child as BoxGeneric).setCss(`
transition: margin-bottom 0.5s ease-in-out; transition: margin-bottom 0.5s ease-in-out;
margin-bottom: 0px; margin-bottom: 0px;
`); `);

View file

@ -16,11 +16,10 @@ const COLOR = 'rgba(0, 0, 0, 0.3)';
const SPACING = 4; const SPACING = 4;
// Types // Types
import AgsWindow from 'types/widgets/window.ts'; import { BoxGeneric, WindowGeneric } from 'global-types';
import AgsBox from 'types/widgets/box.ts';
export default (window: AgsWindow) => Box({ export default (window: WindowGeneric) => Box({
vertical: true, vertical: true,
children: [ children: [
CenterBox({ CenterBox({
@ -99,7 +98,7 @@ export default (window: AgsWindow) => Box({
vertical: true, vertical: true,
children: keyboardJson.keys.map((row, rowIndex) => { children: keyboardJson.keys.map((row, rowIndex) => {
const keys = [] as Array<AgsBox>; const keys = [] as BoxGeneric[];
row.forEach((key, keyIndex) => { row.forEach((key, keyIndex) => {
if (keyIndex < L_KEY_PER_ROW[rowIndex]) { if (keyIndex < L_KEY_PER_ROW[rowIndex]) {
@ -141,7 +140,7 @@ export default (window: AgsWindow) => Box({
vertical: true, vertical: true,
children: keyboardJson.keys.map((row, rowIndex) => { children: keyboardJson.keys.map((row, rowIndex) => {
const keys = [] as Array<AgsBox>; const keys = [] as BoxGeneric[];
row.forEach((key, keyIndex) => { row.forEach((key, keyIndex) => {
if (keyIndex >= L_KEY_PER_ROW[rowIndex]) { if (keyIndex >= L_KEY_PER_ROW[rowIndex]) {

View file

@ -57,7 +57,7 @@ type Key = {
const ModKey = (key: Key) => { const ModKey = (key: Key) => {
let Mod: Var<any>; let Mod: Var<boolean>;
if (key.label === 'Super') { if (key.label === 'Super') {
Mod = Super; Mod = Super;

View file

@ -20,6 +20,7 @@ export default () => {
setup: (self) => { setup: (self) => {
self self
.hook(Tablet, (_, state) => { .hook(Tablet, (_, state) => {
// @ts-expect-error too lazy to do keyboard type
self.attribute.setVisible(state); self.attribute.setVisible(state);
}, 'osk-toggled') }, 'osk-toggled')

View file

@ -3,24 +3,7 @@ import { Box, Icon, ProgressBar } from 'resource:///com/github/Aylur/ags/widget.
const Y_POS = 80; const Y_POS = 80;
// Types // Types
import AgsBox from 'types/widgets/box'; import { ConnectFunc, OSD, ProgressBarGeneric } from 'global-types';
import { IconProps } from 'types/widgets/icon';
import GObject from 'types/@girs/gobject-2.0/gobject-2.0';
import AgsStack from 'types/widgets/stack';
import { Widget } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
import { Connectable } from 'types/widgets/widget';
import AgsProgressBar from 'types/widgets/progressbar';
type ConnectFunc = (self?: AgsProgressBar) => void;
type OSD = {
stack: AgsStack
icon: string | IconProps
info: {
mod: GObject.Object
signal?: string
logic?(self: AgsProgressBar): void
widget?: Widget
}
};
export default ({ stack, icon, info }: OSD) => { export default ({ stack, icon, info }: OSD) => {
@ -58,7 +41,7 @@ export default ({ stack, icon, info }: OSD) => {
connectFunc = () => stack.attribute.popup(osd); connectFunc = () => stack.attribute.popup(osd);
} }
((osd.children[0] as AgsBox).children[1] as Connectable<AgsProgressBar>) (osd.children[0].children[1] as ProgressBarGeneric)
.hook(info.mod, connectFunc, info.signal); .hook(info.mod, connectFunc, info.signal);
return osd; return osd;

View file

@ -4,11 +4,12 @@ import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import { Stack } from 'resource:///com/github/Aylur/ags/widget.js'; import { Stack } from 'resource:///com/github/Aylur/ags/widget.js';
import PopupWindow from '../misc/popup.ts'; import PopupWindow from '../misc/popup.ts';
import AgsBox from 'types/widgets/box.ts';
import AgsStack from 'types/widgets/stack.ts'; // Types
import { BoxGeneric, StackGeneric } from 'global-types';
// Import all the OSDs as an array // Import all the OSDs as an array
const OSDList = [] as Array<(stack: AgsStack) => AgsBox>; const OSDList = [] as Array<(stack: StackGeneric) => BoxGeneric>;
import * as Modules from './osds.ts'; import * as Modules from './osds.ts';
for (const osd in Modules) { for (const osd in Modules) {
@ -24,7 +25,9 @@ const OSDs = () => {
transition: 'over_up_down', transition: 'over_up_down',
transition_duration, transition_duration,
attribute: { popup: () => {/**/} }, attribute: { popup: (osd: BoxGeneric) => {
console.log(osd);
} },
}); });
// Send reference of stack to all items // Send reference of stack to all items
@ -35,7 +38,7 @@ const OSDs = () => {
timeout(1000, () => { timeout(1000, () => {
let count = 0; let count = 0;
stack.attribute.popup = (osd: AgsBox) => { stack.attribute.popup = (osd: BoxGeneric) => {
++count; ++count;
stack.set_visible_child(osd); stack.set_visible_child(osd);
App.openWindow('osd'); App.openWindow('osd');

View file

@ -17,10 +17,10 @@ globalThis.showSpeaker = () => {
}; };
// Types // Types
import AgsStack from 'types/widgets/stack.ts'; import { OSDStack } from 'global-types';
export const SpeakerOSD = (stack: AgsStack) => OSD({ export const SpeakerOSD = (stack: OSDStack) => OSD({
stack, stack,
icon: { icon: SpeakerIcon.bind() }, icon: { icon: SpeakerIcon.bind() },
info: { info: {
@ -35,12 +35,12 @@ export const SpeakerOSD = (stack: AgsStack) => OSD({
Audio.speaker.volume / AUDIO_MAX : Audio.speaker.volume / AUDIO_MAX :
0; 0;
self.sensitive = !Audio.speaker?.stream.is_muted; self.sensitive = !Audio.speaker.stream?.is_muted;
}, },
}, },
}); });
export const ScreenBrightnessOSD = (stack: AgsStack) => OSD({ export const ScreenBrightnessOSD = (stack: OSDStack) => OSD({
stack, stack,
icon: { icon: Brightness.bind('screenIcon') }, icon: { icon: Brightness.bind('screenIcon') },
info: { info: {
@ -53,7 +53,7 @@ export const ScreenBrightnessOSD = (stack: AgsStack) => OSD({
}, },
}); });
export const KbdBrightnessOSD = (stack: AgsStack) => OSD({ export const KbdBrightnessOSD = (stack: OSDStack) => OSD({
stack, stack,
icon: 'keyboard-brightness-symbolic', icon: 'keyboard-brightness-symbolic',
info: { info: {
@ -72,7 +72,7 @@ export const KbdBrightnessOSD = (stack: AgsStack) => OSD({
}, },
}); });
export const MicOSD = (stack: AgsStack) => OSD({ export const MicOSD = (stack: OSDStack) => OSD({
stack, stack,
icon: { icon: MicIcon.bind() }, icon: { icon: MicIcon.bind() },
info: { info: {
@ -85,12 +85,12 @@ export const MicOSD = (stack: AgsStack) => OSD({
} }
self.value = Audio.microphone ? Audio.microphone.volume : 0; self.value = Audio.microphone ? Audio.microphone.volume : 0;
self.sensitive = !Audio.microphone?.stream.is_muted; self.sensitive = !Audio.microphone.stream?.is_muted;
}, },
}, },
}); });
export const CapsLockOSD = (stack: AgsStack) => OSD({ export const CapsLockOSD = (stack: OSDStack) => OSD({
stack, stack,
icon: { icon: Brightness.bind('capsIcon') }, icon: { icon: Brightness.bind('capsIcon') },
info: { info: {