Run ags on the correct monitor

This commit is contained in:
Thomas Avé 2024-11-28 21:15:30 +01:00
parent cbc805d0dc
commit 1b1a398970
2 changed files with 34 additions and 17 deletions

View File

@ -99,7 +99,7 @@ function Memory(): JSX.Element {
const line = out.split('\n').find(line => line.includes('Mem:')); const line = out.split('\n').find(line => line.includes('Mem:'));
if (!line) return "N/A"; if (!line) return "N/A";
const split = line.split(/\s+/).map(Number); const split = line.split(/\s+/).map(Number);
return ((split[2]-split[5]) / 1000000).toFixed(2) + "GB"; return (split[2] / 1000000).toFixed(2) + "GB";
}); });
return <label return <label
className="item blue" className="item blue"
@ -151,6 +151,7 @@ function Right() : JSX.Element {
} }
function BatteryIcon(): JSX.Element { function BatteryIcon(): JSX.Element {
if (!battery.online) return <box />;
const icon_name = bind(battery, "percentage").as((percentage) => { const icon_name = bind(battery, "percentage").as((percentage) => {
const thresholds = [...Array(11).keys()].map( i => i * 10); const thresholds = [...Array(11).keys()].map( i => i * 10);
const icon = thresholds.find(threshold => threshold >= percentage * 100) const icon = thresholds.find(threshold => threshold >= percentage * 100)
@ -215,19 +216,19 @@ function Workspaces() : JSX.Element {
return ( return (
<box className="workspaces"> <box className="workspaces">
{bind(hyprland, "workspaces").as((wss) => {bind(hyprland, "workspaces").as((wss) =>
wss <box>
.sort((a, b) => a.id - b.id) {bind(hyprland, "focusedMonitor").as((fm) =>
.filter(ws => ws && ws.get_monitor().get_id() === hyprland.get_focused_monitor().get_id()) wss.sort((a, b) => a.id - b.id)
.map((ws) => ( .filter(ws => ws && ws.get_monitor().get_id() === fm.get_id())
<button .map((ws) => (
className={bind(hyprland, "focusedWorkspace").as((fw) => <button
ws === fw ? "focused" : "", className={bind(hyprland, "focusedWorkspace").as((fw) => ws === fw ? "focused" : "",)}
)} onClicked={() => ws.focus()}
onClicked={() => ws.focus()} >
> {`${ws.id}`.slice(-1)}
{`${ws.id}`.slice(-1)} </button>
</button> )))}
)), </box>
)} )}
</box> </box>
); );

View File

@ -1,13 +1,29 @@
import { App } from "astal/gtk3" import { App, Gdk } from "astal/gtk3"
import style from "./style.scss" import style from "./style.scss"
import Bar from "./Bar" import Bar from "./Bar"
import Hyprland from "gi://AstalHyprland";
import NotificationPopups from "./notifications/NotificationPopups" import NotificationPopups from "./notifications/NotificationPopups"
function find_main_monitor(): Hyprland.Monitor {
const hyprland = Hyprland.get_default();
let monitors = hyprland.get_monitors()
for (let i = 0; i < monitors.length; i++) {
for (const monitor of ["eDP", "DP", "HDMI-A"]) {
if (monitors[i].get_name() == monitor + "-" + i) {
return monitors[i]
}
}
}
return monitors[0]
}
App.start({ App.start({
css: style, css: style,
iconTheme: "Papirus", iconTheme: "Papirus",
main() { main() {
App.get_monitors().map(Bar) let mainMonitor = find_main_monitor()
App.get_monitors().map(NotificationPopups) let gtkMonitor = App.get_monitors()[Number(mainMonitor.get_id())]
Bar(gtkMonitor)
NotificationPopups(gtkMonitor)
}, },
}) })