2024-11-15 22:07:59 -05:00
|
|
|
import { bind, Variable } from 'astal';
|
|
|
|
|
|
|
|
import AstalApps from 'gi://AstalApps';
|
|
|
|
import AstalHyprland from 'gi://AstalHyprland';
|
|
|
|
|
|
|
|
import { hyprMessage } from '../../../lib';
|
|
|
|
|
|
|
|
|
|
|
|
export default () => {
|
2024-11-20 23:38:41 -05:00
|
|
|
const applications = AstalApps.Apps.new();
|
|
|
|
const hyprland = AstalHyprland.get_default();
|
|
|
|
|
2024-11-15 22:07:59 -05:00
|
|
|
const visibleIcon = Variable<boolean>(false);
|
|
|
|
const focusedIcon = Variable<string>('');
|
|
|
|
|
|
|
|
let lastFocused: string | undefined;
|
|
|
|
|
|
|
|
const updateVars = (
|
2024-11-20 23:38:41 -05:00
|
|
|
client: AstalHyprland.Client | null = hyprland.get_focused_client(),
|
2024-11-15 22:07:59 -05:00
|
|
|
) => {
|
|
|
|
lastFocused = client?.get_address();
|
2024-11-20 23:38:41 -05:00
|
|
|
const app = applications.fuzzy_query(
|
2024-11-15 22:07:59 -05:00
|
|
|
client?.get_class() ?? '',
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
const icon = app?.iconName;
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
visibleIcon.set(true);
|
|
|
|
focusedIcon.set(icon);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
visibleIcon.set(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
const id = client?.connect('notify::title', (c) => {
|
|
|
|
if (c.get_address() !== lastFocused) {
|
|
|
|
c.disconnect(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
updateVars();
|
2024-11-20 23:38:41 -05:00
|
|
|
hyprland.connect('notify::focused-client', () => updateVars());
|
|
|
|
hyprland.connect('client-removed', () => updateVars());
|
|
|
|
hyprland.connect('client-added', async() => {
|
2024-11-15 22:07:59 -05:00
|
|
|
try {
|
2024-11-20 23:38:41 -05:00
|
|
|
updateVars(hyprland.get_client(JSON.parse(await hyprMessage('j/activewindow')).address));
|
2024-11-15 22:07:59 -05:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<box
|
|
|
|
className="bar-item current-window"
|
|
|
|
visible={bind(visibleIcon)}
|
|
|
|
>
|
|
|
|
<icon
|
|
|
|
css="font-size: 32px;"
|
|
|
|
icon={bind(focusedIcon)}
|
|
|
|
/>
|
|
|
|
</box>
|
|
|
|
);
|
|
|
|
};
|