diff --git a/modules/ags/gtk4/widget/bar.tsx b/modules/ags/gtk4/widget/bar.tsx index 0f31673c..72077b0f 100644 --- a/modules/ags/gtk4/widget/bar.tsx +++ b/modules/ags/gtk4/widget/bar.tsx @@ -1,7 +1,7 @@ import { App, Astal, Gtk } from 'astal/gtk4'; import { Variable } from 'astal'; -import { Box, Button, CenterBox } from './subclasses'; +import { Box, Button, Calendar, CenterBox, Label, MenuButton, Popover, Window } from './subclasses'; const { EXCLUSIVE } = Astal.Exclusivity; const { TOP, LEFT, RIGHT } = Astal.WindowAnchor; @@ -21,7 +21,7 @@ export default () => { ) as Box; return ( - { {styledBox} - - + + ); }; diff --git a/modules/ags/gtk4/widget/subclasses/astalify.ts b/modules/ags/gtk4/widget/subclasses/astalify.ts index ad53556e..0aa5a92e 100644 --- a/modules/ags/gtk4/widget/subclasses/astalify.ts +++ b/modules/ags/gtk4/widget/subclasses/astalify.ts @@ -20,8 +20,8 @@ export const filter = (children: any[]) => { new Gtk.Label({ visible: true, label: String(ch) })); }; +export const type = Symbol('child type'); const dummyBuilder = new Gtk.Builder(); -const type = Symbol('child type'); interface EventController { onFocusEnter?: (self: Self) => void diff --git a/modules/ags/gtk4/widget/subclasses/calendar.ts b/modules/ags/gtk4/widget/subclasses/calendar.ts new file mode 100644 index 00000000..dd7877e7 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/calendar.ts @@ -0,0 +1,26 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +type CalendarSignals = Record<`on${string}`, unknown[]> & { + onDaySelected: [] + onNextMonth: [] + onNextYear: [] + onPrevMonth: [] + onPrevYear: [] + +}; +export type CalendarProps = ConstructProps< + Calendar, + Gtk.Calendar.ConstructorProps & { css: string }, + CalendarSignals +>; + +@register({ GTypeName: 'Calendar' }) +export class Calendar extends astalify(Gtk.Calendar) { + constructor(props?: CalendarProps) { super(props as any); } +} diff --git a/modules/ags/gtk4/widget/subclasses/entry.ts b/modules/ags/gtk4/widget/subclasses/entry.ts new file mode 100644 index 00000000..8a60467f --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/entry.ts @@ -0,0 +1,24 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +type EntrySignals = Record<`on${string}`, unknown[]> & { + onActivate: [] + onNotifyText: [] +}; +export type EntryProps = ConstructProps< + Entry, + Gtk.Entry.ConstructorProps & { css: string }, + EntrySignals +>; + +@register({ GTypeName: 'Entry' }) +export class Entry extends astalify(Gtk.Entry) { + constructor(props?: EntryProps) { super(props as any); } + + getChildren() { return []; } +} diff --git a/modules/ags/gtk4/widget/subclasses/image.ts b/modules/ags/gtk4/widget/subclasses/image.ts new file mode 100644 index 00000000..14d05382 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/image.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +export type ImageProps = ConstructProps< + Image, + Gtk.Image.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Image' }) +export class Image extends astalify(Gtk.Image) { + constructor(props?: ImageProps) { super(props as any); } + + getChildren() { return []; } +} diff --git a/modules/ags/gtk4/widget/subclasses/index.ts b/modules/ags/gtk4/widget/subclasses/index.ts index 9e97c5fc..c537722a 100644 --- a/modules/ags/gtk4/widget/subclasses/index.ts +++ b/modules/ags/gtk4/widget/subclasses/index.ts @@ -1,3 +1,16 @@ export * from './box'; export * from './button'; +export * from './calendar'; export * from './centerbox'; +export * from './entry'; +export * from './image'; +export * from './label'; +export * from './levelbar'; +export * from './menubutton'; +export * from './overlay'; +export * from './popover'; +export * from './revealer'; +export * from './slider'; +export * from './stack'; +export * from './switch'; +export * from './window'; diff --git a/modules/ags/gtk4/widget/subclasses/label.ts b/modules/ags/gtk4/widget/subclasses/label.ts new file mode 100644 index 00000000..b85d83a1 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/label.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +export type LabelProps = ConstructProps< + Label, + Gtk.Label.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Label' }) +export class Label extends astalify(Gtk.Label) { + constructor(props?: LabelProps) { super(props as any); } + + getChildren() { return []; } + + setChildren(self: Label, children: any[]) { self.label = String(children); } +} diff --git a/modules/ags/gtk4/widget/subclasses/levelbar.ts b/modules/ags/gtk4/widget/subclasses/levelbar.ts new file mode 100644 index 00000000..06f45c88 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/levelbar.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +export type LevelBarProps = ConstructProps< + LevelBar, + Gtk.LevelBar.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'LevelBar' }) +export class LevelBar extends astalify(Gtk.LevelBar) { + constructor(props?: LevelBarProps) { super(props as any); } + + getChildren() { return []; } +} diff --git a/modules/ags/gtk4/widget/subclasses/menubutton.ts b/modules/ags/gtk4/widget/subclasses/menubutton.ts new file mode 100644 index 00000000..8adb62e3 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/menubutton.ts @@ -0,0 +1,32 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify, { filter } from './astalify'; + + +export type MenuButtonProps = ConstructProps< + MenuButton, + Gtk.MenuButton.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'MenuButton' }) +export class MenuButton extends astalify(Gtk.MenuButton) { + constructor(props?: MenuButtonProps) { super(props as any); } + + getChildren(self: MenuButton) { + return [self.popover, self.child]; + } + + setChildren(self: MenuButton, children: any[]) { + for (const child of filter(children)) { + if (child instanceof Gtk.Popover) { + self.set_popover(child); + } + else { + self.set_child(child); + } + } + } +} diff --git a/modules/ags/gtk4/widget/subclasses/overlay.ts b/modules/ags/gtk4/widget/subclasses/overlay.ts new file mode 100644 index 00000000..6d794d72 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/overlay.ts @@ -0,0 +1,47 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify, { filter, type } from './astalify'; + + +export type OverlayProps = ConstructProps< + Overlay, + Gtk.Overlay.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Overlay' }) +export class Overlay extends astalify(Gtk.Overlay) { + constructor(props?: OverlayProps) { super(props as any); } + + getChildren(self: Overlay) { + 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); + } + + setChildren(self: Overlay, children: any[]) { + for (const child of filter(children)) { + const types = type in child ? + (child[type] as string).split(/\s+/) : + []; + + 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')); + } + } +} diff --git a/modules/ags/gtk4/widget/subclasses/popover.ts b/modules/ags/gtk4/widget/subclasses/popover.ts new file mode 100644 index 00000000..4b22d361 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/popover.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +export type PopoverProps = ConstructProps< + Popover, + Gtk.Popover.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Popover' }) +export class Popover extends astalify(Gtk.Popover) { + constructor(props?: PopoverProps) { super(props as any); } +} diff --git a/modules/ags/gtk4/widget/subclasses/revealer.ts b/modules/ags/gtk4/widget/subclasses/revealer.ts new file mode 100644 index 00000000..2f2da691 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/revealer.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +export type RevealerProps = ConstructProps< + Revealer, + Gtk.Revealer.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Revealer' }) +export class Revealer extends astalify(Gtk.Revealer) { + constructor(props?: RevealerProps) { super(props as any); } +} diff --git a/modules/ags/gtk4/widget/subclasses/slider.ts b/modules/ags/gtk4/widget/subclasses/slider.ts new file mode 100644 index 00000000..fddb47b6 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/slider.ts @@ -0,0 +1,23 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Astal, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +type SliderSignals = Record<`on${string}`, unknown[]> & { + onClicked: [] +}; +export type SliderProps = ConstructProps< + Slider, + Astal.Slider.ConstructorProps & { css: string }, + SliderSignals +>; + +@register({ GTypeName: 'Slider' }) +export class Slider extends astalify(Astal.Slider) { + constructor(props?: SliderProps) { super(props as any); } + + getChildren() { return []; } +} diff --git a/modules/ags/gtk4/widget/subclasses/stack.ts b/modules/ags/gtk4/widget/subclasses/stack.ts new file mode 100644 index 00000000..a65823ca --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/stack.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify, { filter } from './astalify'; + + +export type StackProps = ConstructProps< + Stack, + Gtk.Stack.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Stack' }) +export class Stack extends astalify(Gtk.Stack) { + constructor(props?: StackProps) { super(props as any); } + + setChildren(self: Stack, children: any[]) { + for (const child of filter(children)) { + if (child.name !== '' && child.name !== null) { + self.add_named(child, child.name); + } + else { + self.add_child(child); + } + } + } +} diff --git a/modules/ags/gtk4/widget/subclasses/switch.ts b/modules/ags/gtk4/widget/subclasses/switch.ts new file mode 100644 index 00000000..b2fdc1b2 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/switch.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Gtk, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +export type SwitchProps = ConstructProps< + Switch, + Gtk.Switch.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Switch' }) +export class Switch extends astalify(Gtk.Switch) { + constructor(props?: SwitchProps) { super(props as any); } + + getChildren() { return []; } +} diff --git a/modules/ags/gtk4/widget/subclasses/window.ts b/modules/ags/gtk4/widget/subclasses/window.ts new file mode 100644 index 00000000..eca145b6 --- /dev/null +++ b/modules/ags/gtk4/widget/subclasses/window.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import { register } from 'astal'; +import { Astal, type ConstructProps } from 'astal/gtk4'; + +import astalify from './astalify'; + + +export type WindowProps = ConstructProps< + Window, + Astal.Window.ConstructorProps & { css: string } +>; + +@register({ GTypeName: 'Window' }) +export class Window extends astalify(Astal.Window) { + constructor(props?: WindowProps) { super(props as any); } +}