fix(ags): update current-client and fix network hover
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-11-24 17:16:22 -05:00
parent 386a4cfde4
commit a1df7028f1
3 changed files with 35 additions and 46 deletions

View file

@ -16,16 +16,17 @@ export default () => {
const focusedIcon = Variable<string>(''); const focusedIcon = Variable<string>('');
const focusedTitle = Variable<string>(''); const focusedTitle = Variable<string>('');
let lastFocusedAddress: string | null; // FIXME: readd this once client titles are fixed
// let lastFocusedAddress: string | null;
const updateVars = ( const updateVars = (
client: AstalHyprland.Client | null = hyprland.get_focused_client(), client: AstalHyprland.Client | null = hyprland.get_focused_client(),
) => { ) => {
lastFocusedAddress = client ? client.get_address() : null; // lastFocusedAddress = client ? client.address : null;
const app = applications.fuzzy_query( const app = applications.fuzzy_query(
client?.get_class() ?? '', client?.class ?? '',
)[0]; )[0];
const icon = app?.iconName; const icon = app?.iconName;
@ -38,21 +39,21 @@ export default () => {
visibleIcon.set(false); visibleIcon.set(false);
} }
focusedTitle.set(client?.get_title() ?? ''); focusedTitle.set(client?.title ?? '');
const id = client?.connect('notify::title', (c) => { /* const id = client?.connect('notify::title', (c) => {
if (c.get_address() !== lastFocusedAddress) { if (c.get_address() !== lastFocusedAddress) {
c.disconnect(id); c.disconnect(id);
} }
console.log(c.get_title());
focusedTitle.set(c.get_title()); focusedTitle.set(c.get_title());
}); });*/
}; };
updateVars(); updateVars();
hyprland.connect('notify::focused-client', () => updateVars()); // hyprland.connect('notify::focused-client', () => updateVars());
hyprland.connect('client-removed', () => updateVars()); hyprland.connect('event', async() => {
hyprland.connect('client-added', async() => {
try { try {
updateVars(hyprland.get_client(JSON.parse(await hyprMessage('j/activewindow')).address)); updateVars(JSON.parse(await hyprMessage('j/activewindow')));
} }
catch (e) { catch (e) {
console.log(e); console.log(e);
@ -85,6 +86,7 @@ export default () => {
<label <label
label={bind(focusedTitle)} label={bind(focusedTitle)}
truncate truncate
maxWidthChars={45}
/> />
</box> </box>
</box> </box>

View file

@ -5,6 +5,7 @@ import AstalApps from 'gi://AstalApps';
import AstalHyprland from 'gi://AstalHyprland'; import AstalHyprland from 'gi://AstalHyprland';
import Separator from '../../misc/separator'; import Separator from '../../misc/separator';
import { hyprMessage } from '../../../lib'; import { hyprMessage } from '../../../lib';
@ -15,16 +16,18 @@ export default () => {
const visibleIcon = Variable<boolean>(false); const visibleIcon = Variable<boolean>(false);
const focusedIcon = Variable<string>(''); const focusedIcon = Variable<string>('');
let lastFocusedAddress: string | null; // FIXME: readd this once client titles are fixed
// let lastFocusedAddress: string | null;
const updateVars = ( const updateVars = (
client: AstalHyprland.Client | null = hyprland.get_focused_client(), client: AstalHyprland.Client | null = hyprland.get_focused_client(),
) => { ) => {
lastFocusedAddress = client ? client.get_address() : null; // lastFocusedAddress = client ? client.address : null;
const app = client ? const app = applications.fuzzy_query(
applications.fuzzy_query(client.get_class())[0] : client?.class ?? '',
null; )[0];
const icon = app?.iconName; const icon = app?.iconName;
@ -35,20 +38,13 @@ export default () => {
else { else {
visibleIcon.set(false); visibleIcon.set(false);
} }
const id = client?.connect('notify::title', (c) => {
if (c.get_address() !== lastFocusedAddress) {
c.disconnect(id);
}
});
}; };
updateVars(); updateVars();
hyprland.connect('notify::focused-client', () => updateVars()); // hyprland.connect('notify::focused-client', () => updateVars());
hyprland.connect('client-removed', () => updateVars()); hyprland.connect('event', async() => {
hyprland.connect('client-added', async() => {
try { try {
updateVars(hyprland.get_client(JSON.parse(await hyprMessage('j/activewindow')).address)); updateVars(JSON.parse(await hyprMessage('j/activewindow')));
} }
catch (e) { catch (e) {
console.log(e); console.log(e);

View file

@ -14,8 +14,8 @@ export default () => {
className="bar-item network" className="bar-item network"
cursor="pointer" cursor="pointer"
onEnterNotifyEvent={() => Hovered.set(true)} onHover={() => Hovered.set(true)}
onLeaveNotifyEvent={() => Hovered.set(false)} onHoverLost={() => Hovered.set(false)}
> >
{bind(network, 'primary').as((primary) => { {bind(network, 'primary').as((primary) => {
if (primary === AstalNetwork.Primary.UNKNOWN) { if (primary === AstalNetwork.Primary.UNKNOWN) {
@ -24,16 +24,10 @@ export default () => {
else if (primary === AstalNetwork.Primary.WIFI) { else if (primary === AstalNetwork.Primary.WIFI) {
const Wifi = network.get_wifi(); const Wifi = network.get_wifi();
if (!Wifi) { return; } if (!Wifi || Wifi.accessPoints.length === 0) { return; }
return ( return (
<box> <box>
{/* Make sure the AP is there before binding to it */}
{bind(Wifi, 'accessPoints').as((aps) => {
if (aps.length === 0) { return; }
return (
<>
<icon icon={bind(Wifi, 'iconName')} /> <icon icon={bind(Wifi, 'iconName')} />
<revealer <revealer
@ -44,9 +38,6 @@ export default () => {
<label label={bind(ap, 'ssid')} /> <label label={bind(ap, 'ssid')} />
))} ))}
</revealer> </revealer>
</>
);
})}
</box> </box>
); );
} }