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 GObject from 'types/@girs/gobject-2.0/gobject-2.0';
import { Widget as agsWidget } from 'types/widgets/widget';
export type AgsWidget = agsWidget<unknown> & Widget;
@ -72,6 +73,32 @@ export type PlayerButtonType = {
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
import { CursorBox, CursorBoxProps } from 'ts/misc/cursorbox';
export type CursorBox = CursorBox;
@ -89,8 +116,8 @@ WindowProps<Child> & {
transition?: RevealerProps<Widget>['transition']
transition_duration?: number
bezier?: string
on_open?(self: AgsWindow<Widget, unknown>): void
on_close?(self: AgsWindow<Widget, unknown>): void
on_open?(self: PopupWindow<Child, Attr>): void
on_close?(self: PopupWindow<Child, Attr>): void
blur?: boolean
close_on_unfocus?: CloseType
attribute?: Attr;
@ -113,17 +140,27 @@ export type CenterBoxPropsGeneric = CenterBoxProps<
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>;
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>;
import AgsOverlay, { OverlayProps } from 'types/widgets/overlay.ts';
import AgsOverlay, { OverlayProps } from 'types/widgets/overlay';
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>;
import AgsStack from 'types/widgets/stack.ts';
import AgsStack from 'types/widgets/stack';
export type StackGeneric = AgsStack<unknown & Widget, unknown>;
import AgsWindow from 'types/widgets/window';
export type WindowGeneric = AgsWindow<unknown & Widget, unknown>;

View file

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

View file

@ -13,8 +13,6 @@ import CursorBox from '../misc/cursorbox.ts';
// Types
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';
type NotificationWidget = {
notif: NotifObj
@ -22,8 +20,9 @@ type NotificationWidget = {
command?(): void
};
import {
EventBoxGeneric,
CursorBox as CBox,
EventBoxGeneric,
NotifGesture,
} from 'global-types';
@ -38,7 +37,7 @@ const getDragState = (box: EventBoxGeneric) => (box
?.get_parent()
?.get_parent()
?.get_parent()
?.get_parent() as AgsEventBox<Widget, { dragging: boolean }>)
?.get_parent() as NotifGesture)
?.attribute.dragging;

View file

@ -9,7 +9,7 @@ import CursorBox from '../misc/cursorbox.ts';
// Types
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) => {
@ -53,7 +53,7 @@ const NotificationList = () => Box({
}, 'notified')
.hook(Notifications, (box, id) => {
const notif = (box.children as BoxGeneric[])
const notif = (box.children as NotifGesture[])
.find((ch) => ch.attribute.id === id);
if (notif?.sensitive) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,24 +3,7 @@ import { Box, Icon, ProgressBar } from 'resource:///com/github/Aylur/ags/widget.
const Y_POS = 80;
// Types
import AgsBox from 'types/widgets/box';
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
}
};
import { ConnectFunc, OSD, ProgressBarGeneric } from 'global-types';
export default ({ stack, icon, info }: OSD) => {
@ -58,7 +41,7 @@ export default ({ stack, icon, info }: 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);
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 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
const OSDList = [] as Array<(stack: AgsStack) => AgsBox>;
const OSDList = [] as Array<(stack: StackGeneric) => BoxGeneric>;
import * as Modules from './osds.ts';
for (const osd in Modules) {
@ -24,7 +25,9 @@ const OSDs = () => {
transition: 'over_up_down',
transition_duration,
attribute: { popup: () => {/**/} },
attribute: { popup: (osd: BoxGeneric) => {
console.log(osd);
} },
});
// Send reference of stack to all items
@ -35,7 +38,7 @@ const OSDs = () => {
timeout(1000, () => {
let count = 0;
stack.attribute.popup = (osd: AgsBox) => {
stack.attribute.popup = (osd: BoxGeneric) => {
++count;
stack.set_visible_child(osd);
App.openWindow('osd');

View file

@ -17,10 +17,10 @@ globalThis.showSpeaker = () => {
};
// 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,
icon: { icon: SpeakerIcon.bind() },
info: {
@ -35,12 +35,12 @@ export const SpeakerOSD = (stack: AgsStack) => OSD({
Audio.speaker.volume / AUDIO_MAX :
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,
icon: { icon: Brightness.bind('screenIcon') },
info: {
@ -53,7 +53,7 @@ export const ScreenBrightnessOSD = (stack: AgsStack) => OSD({
},
});
export const KbdBrightnessOSD = (stack: AgsStack) => OSD({
export const KbdBrightnessOSD = (stack: OSDStack) => OSD({
stack,
icon: 'keyboard-brightness-symbolic',
info: {
@ -72,7 +72,7 @@ export const KbdBrightnessOSD = (stack: AgsStack) => OSD({
},
});
export const MicOSD = (stack: AgsStack) => OSD({
export const MicOSD = (stack: OSDStack) => OSD({
stack,
icon: { icon: MicIcon.bind() },
info: {
@ -85,12 +85,12 @@ export const MicOSD = (stack: AgsStack) => OSD({
}
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,
icon: { icon: Brightness.bind('capsIcon') },
info: {