nixos-configs/nixosModules/ags/v2/widgets/bar/items/current-client.tsx

63 lines
1.7 KiB
TypeScript
Raw Normal View History

import { bind, Variable } from 'astal';
2024-09-27 16:35:32 -04:00
import AstalApps from 'gi://AstalApps?version=0.1';
const Applications = AstalApps.Apps.new();
import AstalHyprland from 'gi://AstalHyprland?version=0.1';
const Hyprland = AstalHyprland.get_default();
import Separator from '../../misc/separator';
export default () => {
const focusedIcon = Variable<string>('');
const focusedTitle = Variable<string>('');
let lastFocused: string | undefined;
const updateVars = (
client: AstalHyprland.Client | null | undefined = Hyprland.get_focused_client(),
) => {
lastFocused = client?.get_address();
const app = Applications.query(
client?.get_class() ?? '',
false,
)[0];
focusedIcon.set(app.iconName ?? '');
focusedTitle.set(client?.get_title() ?? '');
const id = client?.connect('notify::title', (c) => {
if (c.get_address() !== lastFocused) {
c.disconnect(id);
}
focusedTitle.set(c.get_title());
});
};
updateVars();
Hyprland.connect('notify::focused-client', () => updateVars());
Hyprland.connect('client-removed', () => updateVars());
Hyprland.connect('client-added', () => {
updateVars(Hyprland.get_client(JSON.parse(Hyprland.message('j/activewindow')).address));
});
2024-09-27 16:35:32 -04:00
return (
<box
className="bar-item current-window"
visible={bind(focusedTitle).as((title) => title !== '')}
2024-09-27 16:35:32 -04:00
>
<icon
css="font-size: 32px;"
icon={bind(focusedIcon)}
2024-09-27 16:35:32 -04:00
/>
<Separator size={8} />
2024-09-27 16:35:32 -04:00
<label
label={bind(focusedTitle)}
truncate
/>
2024-09-27 16:35:32 -04:00
</box>
);
};