-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwidget-util.ts
34 lines (32 loc) · 928 Bytes
/
widget-util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Layout, Widget } from 'wibox';
import { Index } from 'awesomewm.4.3.ts.d';
import { table } from 'gears';
export function widgetData<
T extends Widget,
D extends Partial<Omit<T, 'children'>> & { children?: R[] },
R
>(data: D): { [k in string | Index]: unknown } & D {
if (data.children) {
const children = data.children;
data.children = undefined;
return table.join(children, data);
} else {
return data;
}
}
export function setupWidget<T extends Widget, R>(
widget: T,
): (data: Partial<Omit<T, 'children'>> & { layout?: Layout; children?: R[] }) => T {
return (data) => {
widget.setup(widgetData(data));
return widget;
};
}
export function mkWidget<
T extends Widget,
D extends Partial<Omit<T, 'children'>> &
({ children?: R[]; widget: T } | { children?: R[]; layout: Layout }),
R
>(data: D): { [k in string | Index]: unknown } & D {
return widgetData(data);
}