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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
import { launchApp } from "lib/utils";
import options from "options";
import * as Gtk from "gi://Gtk?version=3.0";
import { type ButtonProps } from "types/widgets/button";
import { type BoxProps } from "types/widgets/box";
const hyprland = await Service.import("hyprland");
const applications = await Service.import("applications");
const focus = (address: string) => hyprland.messageAsync(`dispatch focuswindow address:${address}`);
const AppButton = ({ icon, pinned = false, term, ...rest }: ButtonProps & { term?: string }): Gtk.Button & ButtonProps => {
const { iconSize } = options.dock;
const buttonBox = Widget.Box({
class_name: 'box',
child: Widget.Icon({
icon,
size: iconSize,
}),
});
const button = Widget.Button({
...rest,
class_name: '',
child: pinned ? buttonBox : Widget.Overlay({
child: buttonBox,
pass_through: false,
overlays: [],
}),
});
return Object.assign(button, {});
};
const createAppButton = ({ app, term, ...params }) => {
return AppButton({
icon: app.icon_name || '',
term,
...params,
});
};
const filterValidClients = (clients: any[]) => {
return clients.filter(client => (
client.mapped &&
[client.class, client.title, client.initialClass].every(prop => typeof prop === 'string' && prop !== '')
));
};
const Taskbar = (): Gtk.Box & BoxProps => {
const addedApps = new Set<string>();
const updateTaskbar = (clients: any[]) => {
const validClients = filterValidClients(clients);
const focusedAddress = hyprland?.active.client?.address;
const running = validClients.filter(client => client.mapped);
const focused = running.find(client => client.address === focusedAddress);
return validClients.map(client => {
if (![client.class, client.title, client.initialClass].every(prop => typeof prop === 'string' && prop !== '')) {
return null;
}
if (addedApps.has(client.title)) {
return null;
}
for (const appName of options.dock.pinnedApps.value) {
if (!appName || typeof appName !== 'string') {
continue;
}
if (client.class.includes(appName) || client.title.includes(appName)
|| client.initialClass.includes(appName)) {
return null;
}
}
const matchingApp = applications?.list.find(app => (
app.match(client.title) || app.match(client.class) || app.match(client.initialClass)
));
if (matchingApp) {
addedApps.add(client.title);
return createAppButton({
app: matchingApp,
term: matchingApp.title,
on_primary_click: () => {
const clickAddress = client.address || focusedAddress;
clickAddress && focus(clickAddress);
},
on_secondary_click: () => launchApp(matchingApp),
});
a
}
return null;
});
};
return Widget.Box({
vertical: false,
})
.bind('children', hyprland, 'clients', updateTaskbar);
};
const PinnedApps = (): Gtk.Box & BoxProps => {
const updatePinnedApps = (pinnedApps: string[]) => {
return pinnedApps
.map(term => ({ app: applications?.query(term)?.[0], term }))
.filter(({ app }) => app)
.map(({ app, term = true }) => createAppButton({
app,
term,
pinned: true,
on_primary_click: () => {
const matchingClients = hyprland?.clients.filter(client => (
typeof client.class === 'string' &&
typeof client.title === 'string' &&
typeof client.initialClass === 'string' &&
(client.class.includes(term) || client.title.includes(term) || client.initialClass.includes(term))
));
if (matchingClients.length > 0) {
const { address } = matchingClients[0];
address && focus(address);
} else {
launchApp(app);
}
},
on_secondary_click: () => launchApp(app),
}));
};
return Widget.Box({
class_name: 'pins',
vertical: false,
homogeneous: true,
})
.bind('children', options.dock.pinnedApps, 'value', updatePinnedApps);
};
const Dock = (): Gtk.Box & BoxProps => Widget.Box({
class_name: 'dock',
vertical: false,
children: [PinnedApps(), Taskbar()],
});
export default Dock;
|