2024-10-16 23:56:05 -04:00
|
|
|
import { App, Astal, Gdk, Gtk, Widget } from 'astal/gtk3';
|
2024-11-20 00:54:02 -05:00
|
|
|
import { bind, idle, Variable } from 'astal';
|
2024-09-26 11:11:31 -04:00
|
|
|
|
2024-10-22 13:09:39 -04:00
|
|
|
import AstalHyprland from 'gi://AstalHyprland';
|
2024-09-26 11:11:31 -04:00
|
|
|
const Hyprland = AstalHyprland.get_default();
|
|
|
|
|
2024-10-16 12:32:06 -04:00
|
|
|
import { get_hyprland_monitor_desc, get_monitor_desc, hyprMessage } from '../../lib';
|
2024-09-26 11:11:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
const FullscreenState = Variable({
|
|
|
|
monitors: [] as string[],
|
|
|
|
clientAddrs: new Map() as Map<string, string>,
|
|
|
|
});
|
|
|
|
|
2024-10-16 12:32:06 -04:00
|
|
|
Hyprland.connect('event', async() => {
|
2024-09-26 11:11:31 -04:00
|
|
|
const arrayEquals = (a1: unknown[], a2: unknown[]) =>
|
|
|
|
a1.sort().toString() === a2.sort().toString();
|
|
|
|
|
|
|
|
const mapEquals = (m1: Map<string, string>, m2: Map<string, string>) =>
|
|
|
|
m1.size === m2.size &&
|
|
|
|
Array.from(m1.keys()).every((key) => m1.get(key) === m2.get(key));
|
|
|
|
|
2024-10-16 22:33:15 -04:00
|
|
|
try {
|
|
|
|
const newMonitors = JSON.parse(await hyprMessage('j/monitors')) as AstalHyprland.Monitor[];
|
2024-10-11 14:43:42 -04:00
|
|
|
|
2024-10-16 22:33:15 -04:00
|
|
|
const fs = FullscreenState.get();
|
|
|
|
const fsClients = Hyprland.get_clients().filter((c) => {
|
|
|
|
const mon = newMonitors.find((monitor) => monitor.id === c.get_monitor()?.id);
|
2024-09-26 11:11:31 -04:00
|
|
|
|
2024-10-16 22:33:15 -04:00
|
|
|
return c.fullscreenClient !== 0 &&
|
|
|
|
c.workspace.id === mon?.activeWorkspace.id;
|
|
|
|
});
|
2024-09-26 11:11:31 -04:00
|
|
|
|
2024-10-16 22:33:15 -04:00
|
|
|
const monitors = fsClients.map((c) =>
|
|
|
|
get_monitor_desc(c.monitor));
|
2024-09-26 11:11:31 -04:00
|
|
|
|
2024-10-16 22:33:15 -04:00
|
|
|
const clientAddrs = new Map(fsClients.map((c) => [
|
|
|
|
get_monitor_desc(c.monitor),
|
|
|
|
c.address ?? '',
|
|
|
|
]));
|
2024-09-26 11:11:31 -04:00
|
|
|
|
2024-10-16 22:33:15 -04:00
|
|
|
const hasChanged =
|
|
|
|
!arrayEquals(monitors, fs.monitors) ||
|
|
|
|
!mapEquals(clientAddrs, fs.clientAddrs);
|
2024-09-26 11:11:31 -04:00
|
|
|
|
2024-10-16 22:33:15 -04:00
|
|
|
if (hasChanged) {
|
|
|
|
FullscreenState.set({
|
|
|
|
monitors,
|
|
|
|
clientAddrs,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(e);
|
2024-09-26 11:11:31 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-09-26 15:55:32 -04:00
|
|
|
export default ({
|
|
|
|
anchor,
|
|
|
|
gdkmonitor = Gdk.Display.get_default()?.get_monitor(0) as Gdk.Monitor,
|
|
|
|
child,
|
|
|
|
...rest
|
2024-09-27 21:14:58 -04:00
|
|
|
}: {
|
|
|
|
anchor: Astal.WindowAnchor
|
|
|
|
gdkmonitor?: Gdk.Monitor
|
|
|
|
} & Widget.WindowProps) => {
|
2024-09-26 15:55:32 -04:00
|
|
|
const monitor = get_hyprland_monitor_desc(gdkmonitor);
|
2024-11-20 00:54:02 -05:00
|
|
|
const BarVisible = Variable(false);
|
2024-09-26 15:55:32 -04:00
|
|
|
|
|
|
|
FullscreenState.subscribe((v) => {
|
|
|
|
BarVisible.set(!v.monitors.includes(monitor));
|
|
|
|
});
|
|
|
|
|
|
|
|
const barCloser = (
|
|
|
|
<window
|
|
|
|
name={`bar-${monitor}-closer`}
|
|
|
|
css="all: unset;"
|
|
|
|
visible={false}
|
|
|
|
gdkmonitor={gdkmonitor}
|
|
|
|
layer={Astal.Layer.OVERLAY}
|
|
|
|
anchor={
|
|
|
|
Astal.WindowAnchor.TOP |
|
|
|
|
Astal.WindowAnchor.BOTTOM |
|
|
|
|
Astal.WindowAnchor.LEFT |
|
|
|
|
Astal.WindowAnchor.RIGHT
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<eventbox
|
|
|
|
on_hover={() => {
|
|
|
|
barCloser.visible = false;
|
|
|
|
BarVisible.set(false);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<box css="padding: 1px;" />
|
|
|
|
</eventbox>
|
|
|
|
</window>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Hide bar instantly when out of focus
|
|
|
|
Hyprland.connect('notify::focused-workspace', () => {
|
|
|
|
const addr = FullscreenState.get().clientAddrs.get(monitor);
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
const client = Hyprland.get_client(addr);
|
|
|
|
|
|
|
|
if (client?.workspace.id !== Hyprland.get_focused_workspace().get_id()) {
|
|
|
|
BarVisible.set(true);
|
|
|
|
barCloser.visible = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BarVisible.set(false);
|
|
|
|
barCloser.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const buffer = (
|
|
|
|
<box
|
|
|
|
css="min-height: 10px;"
|
|
|
|
visible={bind(BarVisible).as((v) => !v)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const vertical = anchor >= (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT);
|
|
|
|
const isBottomOrLeft = (
|
|
|
|
anchor === (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT | Astal.WindowAnchor.BOTTOM)
|
|
|
|
) || (
|
|
|
|
anchor === (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.TOP | Astal.WindowAnchor.BOTTOM)
|
|
|
|
);
|
|
|
|
|
|
|
|
let transition: Gtk.RevealerTransitionType;
|
|
|
|
|
|
|
|
if (vertical) {
|
|
|
|
transition = isBottomOrLeft ?
|
|
|
|
Gtk.RevealerTransitionType.SLIDE_UP :
|
|
|
|
Gtk.RevealerTransitionType.SLIDE_DOWN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
transition = isBottomOrLeft ?
|
|
|
|
Gtk.RevealerTransitionType.SLIDE_RIGHT :
|
|
|
|
Gtk.RevealerTransitionType.SLIDE_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
const barWrap = (
|
|
|
|
<revealer
|
|
|
|
reveal_child={bind(BarVisible)}
|
|
|
|
transitionType={transition}
|
|
|
|
>
|
|
|
|
{child}
|
|
|
|
</revealer>
|
|
|
|
);
|
|
|
|
|
2024-10-16 23:56:05 -04:00
|
|
|
const win = (
|
2024-09-26 15:55:32 -04:00
|
|
|
<window
|
|
|
|
name={`bar-${monitor}`}
|
2024-10-16 23:56:05 -04:00
|
|
|
namespace={`bar-${monitor}`}
|
2024-09-26 15:55:32 -04:00
|
|
|
layer={Astal.Layer.OVERLAY}
|
|
|
|
gdkmonitor={gdkmonitor}
|
|
|
|
anchor={anchor}
|
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
<eventbox
|
|
|
|
onHover={() => {
|
|
|
|
if (!BarVisible.get()) {
|
|
|
|
barCloser.visible = true;
|
|
|
|
BarVisible.set(true);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<box
|
|
|
|
css="min-height: 1px; padding: 1px;"
|
2024-09-26 23:55:06 -04:00
|
|
|
hexpand
|
|
|
|
halign={Gtk.Align.FILL}
|
2024-09-26 15:55:32 -04:00
|
|
|
vertical={vertical}
|
|
|
|
>
|
|
|
|
{isBottomOrLeft ?
|
|
|
|
[buffer, barWrap] :
|
|
|
|
[barWrap, buffer]}
|
|
|
|
</box>
|
|
|
|
</eventbox>
|
|
|
|
</window>
|
2024-10-16 23:56:05 -04:00
|
|
|
) as Widget.Window;
|
|
|
|
|
|
|
|
App.add_window(win);
|
|
|
|
|
2024-11-20 00:54:02 -05:00
|
|
|
idle(() => {
|
|
|
|
BarVisible.set(true);
|
|
|
|
});
|
|
|
|
|
2024-10-16 23:56:05 -04:00
|
|
|
return win;
|
2024-09-26 15:55:32 -04:00
|
|
|
};
|