nixos-configs/modules/ags/gtk4/widget/subclasses/overlay.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-01-01 13:38:44 -05:00
import { register } from 'astal';
import { Gtk } from 'astal/gtk4';
2025-01-01 13:38:44 -05:00
import astalify, { childType, type AstalifyProps, type ConstructProps } from '../astalify';
2025-01-01 13:38:44 -05:00
export type OverlayProps = ConstructProps<
2025-01-13 10:51:02 -05:00
OverlayClass,
Gtk.Overlay.ConstructorProps & AstalifyProps
2025-01-01 13:38:44 -05:00
>;
@register({ GTypeName: 'Overlay' })
2025-01-13 10:51:02 -05:00
export class OverlayClass extends astalify(Gtk.Overlay) {
constructor({ cssName = 'overlay', ...props }: OverlayProps = {}) {
super({ cssName, ...props });
2025-01-13 10:51:02 -05:00
}
2025-01-01 13:38:44 -05:00
2025-01-13 10:51:02 -05:00
getChildren(self: OverlayClass) {
2025-01-01 13:38:44 -05:00
const children: Gtk.Widget[] = [];
let ch = self.get_first_child();
while (ch !== null) {
children.push(ch);
ch = ch.get_next_sibling();
}
return children.filter((child) => child !== self.child);
}
2025-01-13 10:51:02 -05:00
setChildren(self: OverlayClass, children: Gtk.Widget[]) {
for (const child of children) {
2025-01-14 10:12:20 -05:00
const types = childType in child ?
(child[childType] as string).split(/\s+/) :
2025-01-01 13:38:44 -05:00
[];
if (types.includes('overlay')) {
self.add_overlay(child);
}
else {
self.set_child(child);
}
self.set_measure_overlay(child, types.includes('measure'));
self.set_clip_overlay(child, types.includes('clip'));
}
}
}
2025-01-13 10:51:02 -05:00
export const Overlay = (props?: OverlayProps) => new OverlayClass(props);