2024-10-03 09:03:52 -04:00
|
|
|
import { bind, Variable } from 'astal';
|
2024-11-21 10:32:18 -05:00
|
|
|
import { Gtk } from 'astal/gtk3';
|
2024-09-27 16:35:32 -04:00
|
|
|
|
2024-10-22 13:09:39 -04:00
|
|
|
import AstalApps from 'gi://AstalApps';
|
|
|
|
import AstalHyprland from 'gi://AstalHyprland';
|
2024-09-27 16:35:32 -04:00
|
|
|
|
|
|
|
import Separator from '../../misc/separator';
|
2024-10-16 12:32:06 -04:00
|
|
|
import { hyprMessage } from '../../../lib';
|
2024-09-27 16:35:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
export default () => {
|
2024-11-20 23:38:41 -05:00
|
|
|
const applications = AstalApps.Apps.new();
|
|
|
|
const hyprland = AstalHyprland.get_default();
|
|
|
|
|
2024-10-21 15:49:26 -04:00
|
|
|
const visibleIcon = Variable<boolean>(false);
|
2024-10-03 09:03:52 -04:00
|
|
|
const focusedIcon = Variable<string>('');
|
|
|
|
const focusedTitle = Variable<string>('');
|
|
|
|
|
2024-11-21 10:32:18 -05:00
|
|
|
let lastFocusedAddress: string | null;
|
|
|
|
|
2024-10-03 09:03:52 -04:00
|
|
|
|
|
|
|
const updateVars = (
|
2024-11-20 23:38:41 -05:00
|
|
|
client: AstalHyprland.Client | null = hyprland.get_focused_client(),
|
2024-10-03 09:03:52 -04:00
|
|
|
) => {
|
2024-11-21 10:32:18 -05:00
|
|
|
lastFocusedAddress = client ? client.get_address() : null;
|
|
|
|
|
2024-11-20 23:38:41 -05:00
|
|
|
const app = applications.fuzzy_query(
|
2024-10-03 09:03:52 -04:00
|
|
|
client?.get_class() ?? '',
|
|
|
|
)[0];
|
|
|
|
|
2024-10-21 15:49:26 -04:00
|
|
|
const icon = app?.iconName;
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
visibleIcon.set(true);
|
|
|
|
focusedIcon.set(icon);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
visibleIcon.set(false);
|
|
|
|
}
|
|
|
|
|
2024-10-03 09:03:52 -04:00
|
|
|
focusedTitle.set(client?.get_title() ?? '');
|
|
|
|
const id = client?.connect('notify::title', (c) => {
|
2024-11-21 10:32:18 -05:00
|
|
|
if (c.get_address() !== lastFocusedAddress) {
|
2024-10-03 09:03:52 -04:00
|
|
|
c.disconnect(id);
|
|
|
|
}
|
|
|
|
focusedTitle.set(c.get_title());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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-10-16 22:33:15 -04:00
|
|
|
try {
|
2024-11-20 23:38:41 -05:00
|
|
|
updateVars(hyprland.get_client(JSON.parse(await hyprMessage('j/activewindow')).address));
|
2024-10-16 22:33:15 -04:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
2024-10-03 09:03:52 -04:00
|
|
|
});
|
2024-09-27 16:35:32 -04:00
|
|
|
|
|
|
|
return (
|
2024-11-21 10:32:18 -05:00
|
|
|
<revealer
|
|
|
|
transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
|
|
|
|
revealChild={bind(focusedTitle).as((title) => title !== '')}
|
2024-09-27 16:35:32 -04:00
|
|
|
>
|
2024-11-21 10:32:18 -05:00
|
|
|
<box className="bar-item current-window">
|
|
|
|
<revealer
|
|
|
|
transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
|
|
|
|
revealChild={bind(visibleIcon)}
|
|
|
|
>
|
|
|
|
<box>
|
|
|
|
<icon
|
|
|
|
css="font-size: 32px;"
|
|
|
|
icon={bind(focusedIcon)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Separator size={8} />
|
|
|
|
</box>
|
|
|
|
</revealer>
|
|
|
|
|
|
|
|
<label
|
|
|
|
label={bind(focusedTitle)}
|
|
|
|
truncate
|
|
|
|
/>
|
|
|
|
</box>
|
|
|
|
</revealer>
|
2024-09-27 16:35:32 -04:00
|
|
|
);
|
|
|
|
};
|