fix(agsV2): make current-client accurate
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
32f7efd88d
commit
2bbfad1c23
1 changed files with 37 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
|||
import { bind } from 'astal';
|
||||
import { bind, Variable } from 'astal';
|
||||
|
||||
import AstalApps from 'gi://AstalApps?version=0.1';
|
||||
const Applications = AstalApps.Apps.new();
|
||||
|
@ -10,35 +10,53 @@ import Separator from '../../misc/separator';
|
|||
|
||||
|
||||
export default () => {
|
||||
const focused = bind(Hyprland, 'focusedClient');
|
||||
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));
|
||||
});
|
||||
|
||||
return (
|
||||
<box
|
||||
className="bar-item current-window"
|
||||
visible={focused.as(Boolean)}
|
||||
visible={bind(focusedTitle).as((title) => title !== '')}
|
||||
>
|
||||
<icon
|
||||
css="font-size: 32px;"
|
||||
setup={(self) => {
|
||||
self.hook(Hyprland, 'notify::focused-client', () => {
|
||||
const app = Applications.query(
|
||||
Hyprland.get_focused_client()?.get_class() ?? '',
|
||||
false,
|
||||
)[0];
|
||||
|
||||
self.set_icon(app.iconName ?? '');
|
||||
});
|
||||
}}
|
||||
icon={bind(focusedIcon)}
|
||||
/>
|
||||
|
||||
<Separator size={8} />
|
||||
|
||||
{focused.as((client) => (client && (
|
||||
<label
|
||||
label={bind(client, 'title').as(String)}
|
||||
label={bind(focusedTitle)}
|
||||
truncate
|
||||
/>
|
||||
)))}
|
||||
</box>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue