feat(ags): add anims to current-client
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-11-21 10:32:18 -05:00
parent 4604dcb6fd
commit 2a6b0a1bb2
3 changed files with 52 additions and 32 deletions

View file

@ -26,7 +26,7 @@ export default () => (
<box hexpand halign={Gtk.Align.START}> <box hexpand halign={Gtk.Align.START}>
<CurrentIcon /> <CurrentIcon />
<Separator size={8} /> {/* <Separator size={8} />*/}
<SysTray /> <SysTray />

View file

@ -1,4 +1,5 @@
import { bind, Variable } from 'astal'; import { bind, Variable } from 'astal';
import { Gtk } from 'astal/gtk3';
import AstalApps from 'gi://AstalApps'; import AstalApps from 'gi://AstalApps';
import AstalHyprland from 'gi://AstalHyprland'; import AstalHyprland from 'gi://AstalHyprland';
@ -15,12 +16,14 @@ export default () => {
const focusedIcon = Variable<string>(''); const focusedIcon = Variable<string>('');
const focusedTitle = Variable<string>(''); const focusedTitle = Variable<string>('');
let lastFocused: string | undefined; let lastFocusedAddress: string | null;
const updateVars = ( const updateVars = (
client: AstalHyprland.Client | null = hyprland.get_focused_client(), client: AstalHyprland.Client | null = hyprland.get_focused_client(),
) => { ) => {
lastFocused = client?.get_address(); lastFocusedAddress = client ? client.get_address() : null;
const app = applications.fuzzy_query( const app = applications.fuzzy_query(
client?.get_class() ?? '', client?.get_class() ?? '',
)[0]; )[0];
@ -37,7 +40,7 @@ export default () => {
focusedTitle.set(client?.get_title() ?? ''); focusedTitle.set(client?.get_title() ?? '');
const id = client?.connect('notify::title', (c) => { const id = client?.connect('notify::title', (c) => {
if (c.get_address() !== lastFocused) { if (c.get_address() !== lastFocusedAddress) {
c.disconnect(id); c.disconnect(id);
} }
focusedTitle.set(c.get_title()); focusedTitle.set(c.get_title());
@ -57,22 +60,30 @@ export default () => {
}); });
return ( return (
<box <revealer
className="bar-item current-window" transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
visible={bind(focusedTitle).as((title) => title !== '')} revealChild={bind(focusedTitle).as((title) => title !== '')}
> >
<icon <box className="bar-item current-window">
css="font-size: 32px;" <revealer
icon={bind(focusedIcon)} transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
visible={bind(visibleIcon)} revealChild={bind(visibleIcon)}
/> >
<box>
<icon
css="font-size: 32px;"
icon={bind(focusedIcon)}
/>
<Separator size={8} /> <Separator size={8} />
</box>
</revealer>
<label <label
label={bind(focusedTitle)} label={bind(focusedTitle)}
truncate truncate
/> />
</box> </box>
</revealer>
); );
}; };

View file

@ -1,8 +1,10 @@
import { bind, Variable } from 'astal'; import { bind, Variable } from 'astal';
import { Gtk } from 'astal/gtk3';
import AstalApps from 'gi://AstalApps'; import AstalApps from 'gi://AstalApps';
import AstalHyprland from 'gi://AstalHyprland'; import AstalHyprland from 'gi://AstalHyprland';
import Separator from '../../misc/separator';
import { hyprMessage } from '../../../lib'; import { hyprMessage } from '../../../lib';
@ -13,15 +15,16 @@ export default () => {
const visibleIcon = Variable<boolean>(false); const visibleIcon = Variable<boolean>(false);
const focusedIcon = Variable<string>(''); const focusedIcon = Variable<string>('');
let lastFocused: string | undefined; let lastFocusedAddress: string | null;
const updateVars = ( const updateVars = (
client: AstalHyprland.Client | null = hyprland.get_focused_client(), client: AstalHyprland.Client | null = hyprland.get_focused_client(),
) => { ) => {
lastFocused = client?.get_address(); lastFocusedAddress = client ? client.get_address() : null;
const app = applications.fuzzy_query(
client?.get_class() ?? '', const app = client ?
)[0]; applications.fuzzy_query(client.get_class())[0] :
null;
const icon = app?.iconName; const icon = app?.iconName;
@ -34,7 +37,7 @@ export default () => {
} }
const id = client?.connect('notify::title', (c) => { const id = client?.connect('notify::title', (c) => {
if (c.get_address() !== lastFocused) { if (c.get_address() !== lastFocusedAddress) {
c.disconnect(id); c.disconnect(id);
} }
}); });
@ -53,14 +56,20 @@ export default () => {
}); });
return ( return (
<box <revealer
className="bar-item current-window" transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
visible={bind(visibleIcon)} revealChild={bind(visibleIcon)}
> >
<icon <box>
css="font-size: 32px;" <box className="bar-item current-window">
icon={bind(focusedIcon)} <icon
/> css="font-size: 32px;"
</box> icon={bind(focusedIcon)}
/>
</box>
<Separator size={8} />
</box>
</revealer>
); );
}; };