Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
touch ups
Browse files Browse the repository at this point in the history
  • Loading branch information
Aylur committed Mar 3, 2024
1 parent c9a914a commit 8adf29d
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 93 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nix/hm-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ in {
xdg.configFile."astal".source = cfg.configDir;
})
(mkIf (cfg.package != null) (let
path = "share/astal/types";
path = "share/io.Aylur.Astal/types";
pkg = cfg.package.override {
extraPackages = cfg.extraPackages;
buildTypes = true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"eslint": "^8.42.0"
},
"scripts": {
"test": "eslint ."
"lint": "eslint ."
}
}
10 changes: 7 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import { timeout, readFileAsync } from './utils.js';
import { loadInterfaceXML } from './utils.js';
import { registerGObject } from './utils.js';

import S from './service.js';
import V from './variable.js';
Expand Down Expand Up @@ -36,9 +37,12 @@ export interface Config {

export class App extends Gtk.Application {
static {
S.register(this, {
'window-toggled': ['string', 'boolean'],
'config-parsed': [],
registerGObject(this, {
typename: 'Astal',
signals: {
'window-toggled': ['string', 'boolean'],
'config-parsed': [],
},
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/widgets/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Box<Child extends Gtk.Widget, Attr> extends Gtk.Box {
properties: {
'vertical': ['boolean', 'rw'],
'children': ['jsobject', 'rw'],
'child': ['jsobject', 'rw'],
},
});
}
Expand All @@ -47,7 +48,7 @@ export class Box<Child extends Gtk.Widget, Attr> extends Gtk.Box {
get child() { return this.children[0] as Child; }
set child(child: Child) { this.children = [child]; }

get children() {
get children(): Child[] {
const children = [];
let widget = this.get_first_child();
while (widget) {
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/button.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { register, type BaseProps, type Widget } from './widget.js';
import Gtk from 'gi://Gtk?version=4.0';

type Event<Self> = (self: Self) => unknown

export type ButtonProps<
Child extends Gtk.Widget = Gtk.Widget,
Attr = unknown,
Self = Button<Child, Attr>,
> = BaseProps<Self, Gtk.Button.ConstructorProperties & {
child?: Child
on_clicked?: (self: Self) => boolean
on_clicked?: Event<Self>
}, Attr>;

export function newButton<
Expand Down Expand Up @@ -40,5 +42,5 @@ export class Button<Child extends Gtk.Widget, Attr> extends Gtk.Button {
set child(child: Child) { super.child = child; }

get on_clicked() { return this._get('on-clicked') || (() => false); }
set on_clicked(callback: (self: this) => void) { this._set('on-clicked', callback); }
set on_clicked(callback: Event<this>) { this._set('on-clicked', callback); }
}
17 changes: 14 additions & 3 deletions src/widgets/calendar.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { register, type BaseProps, type Widget } from './widget.js';
import Gtk from 'gi://Gtk?version=4.0';

type Event<Self> = (self: Self) => void

export type CalendarProps<
Attr = unknown,
Self = Calendar<Attr>,
> = BaseProps<Self, Gtk.Calendar.ConstructorProperties, Attr>;
> = BaseProps<Self, Gtk.Calendar.ConstructorProperties & {
on_day_selected?: Event<Self>
}, Attr>;

export function newCalendar<Attr = unknown>(props?: CalendarProps<Attr>) {
return new Calendar(props);
export function newCalendar<
Attr = unknown
>(...props: ConstructorParameters<typeof Calendar<Attr>>) {
return new Calendar(...props);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -17,6 +23,7 @@ export class Calendar<Attr> extends Gtk.Calendar {
register(this, {
properties: {
'date': ['jsobject', 'r'],
'on-day-selected': ['jsobject', 'rw'],
},
});
}
Expand All @@ -26,7 +33,11 @@ export class Calendar<Attr> extends Gtk.Calendar {
this.connect('notify::day', () => this.notify('date'));
this.connect('notify::month', () => this.notify('date'));
this.connect('notify::year', () => this.notify('date'));
this.connect('day-selected', this.on_day_selected.bind(this));
}

get date() { return this.get_date(); }

get on_day_selected() { return this._get('on-day-selected') || (() => false); }
set on_day_selected(callback: Event<this>) { this._set('on-day-selected', callback); }
}
6 changes: 4 additions & 2 deletions src/widgets/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export type EntryProps<
on_change?: EventHandler<Self>
}, Attr>

export function newEntry<Attr = unknown>(props?: EntryProps<Attr>) {
return new Entry(props);
export function newEntry<
Attr = unknown
>(...props: ConstructorParameters<typeof Entry<Attr>>) {
return new Entry(...props);
}

export interface Entry<Attr> extends Widget<Attr> { }
Expand Down
13 changes: 1 addition & 12 deletions src/widgets/menubutton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export type MenuButtonProps<
Self = MenuButton<Child, Attr>,
> = BaseProps<Self, Gtk.MenuButton.ConstructorProperties & {
child?: Child
on_activate?: (self: Self) => boolean
}, Attr>;

export function newMenuButton<
Expand All @@ -20,25 +19,15 @@ export function newMenuButton<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface MenuButton<Child, Attr> extends Widget<Attr> { }
export class MenuButton<Child extends Gtk.Widget, Attr> extends Gtk.MenuButton {
static {
register(this, {
properties: {
'on-activate': ['jsobject', 'rw'],
},
});
}
static { register(this); }

constructor(props: MenuButtonProps<Child, Attr> = {}, child?: Child) {
if (child)
props.child = child;

super(props as Gtk.MenuButton.ConstructorProperties);
this.connect('activate', this.on_activate.bind(this));
}

get child() { return super.child as Child; }
set child(child: Child) { super.child = child; }

get on_activate() { return this._get('on-activate') || (() => false); }
set on_activate(callback: (self: this) => void) { this._set('on-activate', callback); }
}
6 changes: 4 additions & 2 deletions src/widgets/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { register, type BaseProps, type Widget } from './widget.js';
import Gtk from 'gi://Gtk?version=4.0';
import Gdk from 'gi://Gdk?version=4.0';

type Event<Self> = (self: Self) => void | unknown

const POSITION = {
'left': Gtk.PositionType.LEFT,
'right': Gtk.PositionType.RIGHT,
Expand All @@ -17,7 +19,7 @@ export type PopoverProps<
Self = Popover<Child, Attr>,
> = BaseProps<Self, Gtk.Popover.ConstructorProperties & {
child?: Child
on_closed?: (self: Self) => boolean
on_closed?: Event<Self>
xoffset?: number
yoffset?: number
popover_position?: Position
Expand Down Expand Up @@ -63,7 +65,7 @@ export class Popover<Child extends Gtk.Widget, Attr> extends Gtk.Popover {
set child(child: Child) { super.child = child; }

get on_closed() { return this._get('on-closed') || (() => false); }
set on_closed(callback: (self: this) => void) { this._set('on-closed', callback); }
set on_closed(callback: Event<this>) { this._set('on-closed', callback); }

get yoffset() { return this.get_offset()[1]; }
set yoffset(y: number) { this.set_offset(this.xoffset, y); }
Expand Down
11 changes: 5 additions & 6 deletions src/widgets/separator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export type SeparatorProps<
vertical?: boolean
}, Attr>;

export function newSeparator<Attr = unknown>(props?: SeparatorProps<Attr>) {
return new Separator(props);
export function newSeparator<
Attr = unknown
>(...props: ConstructorParameters<typeof Separator<Attr>>) {
return new Separator(...props);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -28,10 +30,7 @@ export class Separator<Attr> extends Gtk.Separator {
this.connect('notify::orientation', () => this.notify('vertical'));
}

get vertical() {
return this.orientation === Gtk.Orientation.VERTICAL;
}

get vertical() { return this.orientation === Gtk.Orientation.VERTICAL; }
set vertical(v: boolean) {
this.orientation = Gtk.Orientation[v ? 'VERTICAL' : 'HORIZONTAL'];
}
Expand Down
10 changes: 2 additions & 8 deletions src/widgets/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,7 @@ export class Slider<Attr> extends Gtk.Scale {
}

get vertical() { return this.orientation === Gtk.Orientation.VERTICAL; }
set vertical(vertical) {
if (this.vertical === vertical)
return;

this.orientation = vertical
? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL;

this.notify('vertical');
set vertical(v: boolean) {
this.orientation = Gtk.Orientation[v ? 'VERTICAL' : 'HORIZONTAL'];
}
}
14 changes: 9 additions & 5 deletions src/widgets/switch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { register, type BaseProps, type Widget } from './widget.js';
import Gtk from 'gi://Gtk?version=4.0';

type Event<Self> = (self: Self) => void | boolean

export type SwitchProps<
Attr = unknown,
Self = Switch<Attr>,
> = BaseProps<Self, Gtk.Switch.ConstructorProperties & {
on_activate?: (self: Self) => boolean
on_activate?: Event<Self>
}, Attr>;

export function newSwitch<Attr = unknown>(props?: SwitchProps<Attr>) {
return new Switch(props);
export function newSwitch<
Attr = unknown
>(...props: ConstructorParameters<typeof Switch<Attr>>) {
return new Switch(...props);
}

export interface Switch<Attr> extends Widget<Attr> { }
Expand All @@ -24,9 +28,9 @@ export class Switch<Attr> extends Gtk.Switch {

constructor(props: SwitchProps<Attr> = {}) {
super(props as Gtk.Switch.ConstructorProperties);
this.connect('activate', this.on_activate.bind(this));
this.connect('notify::active', this.on_activate.bind(this));
}

get on_activate() { return this._get('on-activate') || (() => false); }
set on_activate(callback: (self: this) => void) { this._set('on-activate', callback); }
set on_activate(callback: Event<this>) { this._set('on-activate', callback); }
}
6 changes: 4 additions & 2 deletions src/widgets/togglebutton.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { register, type BaseProps, type Widget } from './widget.js';
import Gtk from 'gi://Gtk?version=4.0';

type Event<Self> = (self: Self) => boolean | unknown

export type ToggleButtonProps<
Child extends Gtk.Widget = Gtk.Widget,
Attr = unknown,
Self = ToggleButton<Child, Attr>,
> = BaseProps<Self, Gtk.ToggleButton.ConstructorProperties & {
child?: Child
on_toggled?: (self: Self) => boolean
on_toggled?: Event<Self>
}, Attr>;

export function newToggleButton<
Expand Down Expand Up @@ -40,5 +42,5 @@ export class ToggleButton<Child extends Gtk.Widget, Attr> extends Gtk.ToggleButt
set child(child: Child) { super.child = child; }

get on_toggled() { return this._get('on-toggled') || (() => false); }
set on_toggled(callback: (self: this) => void) { this._set('on-toggled', callback); }
set on_toggled(callback: Event<this>) { this._set('on-toggled', callback); }
}
Loading

0 comments on commit 8adf29d

Please sign in to comment.