Better monitor handling
This commit is contained in:
parent
a917cf9642
commit
75c8be2bd1
|
@ -1,4 +1,4 @@
|
||||||
import { App, Astal, Gdk, Gtk } from "astal/gtk3";
|
import { App, Astal, Gdk, Gtk, Widget } from "astal/gtk3";
|
||||||
import { GLib, Variable, bind } from "astal";
|
import { GLib, Variable, bind } from "astal";
|
||||||
import Tray from "gi://AstalTray";
|
import Tray from "gi://AstalTray";
|
||||||
import { execAsync } from "astal/process"
|
import { execAsync } from "astal/process"
|
||||||
|
@ -224,7 +224,7 @@ function Workspaces() : JSX.Element {
|
||||||
<box>
|
<box>
|
||||||
{bind(hyprland, "focusedMonitor").as((fm) =>
|
{bind(hyprland, "focusedMonitor").as((fm) =>
|
||||||
wss.sort((a, b) => a.id - b.id)
|
wss.sort((a, b) => a.id - b.id)
|
||||||
.filter(ws => ws && ws.get_monitor().get_id() === fm.get_id())
|
.filter(ws => ws && ws.get_monitor() && ws.get_monitor().get_id() === fm.get_id())
|
||||||
.map((ws) => (
|
.map((ws) => (
|
||||||
<button
|
<button
|
||||||
className={bind(hyprland, "focusedWorkspace").as((fw) => ws === fw ? "focused" : "",)}
|
className={bind(hyprland, "focusedWorkspace").as((fw) => ws === fw ? "focused" : "",)}
|
||||||
|
@ -255,7 +255,7 @@ function Clients() : JSX.Element {
|
||||||
cls
|
cls
|
||||||
.sort((a, b) => a.pid - b.pid)
|
.sort((a, b) => a.pid - b.pid)
|
||||||
.filter(cl => !cl.title.includes("rofi"))
|
.filter(cl => !cl.title.includes("rofi"))
|
||||||
.filter(cl => cl.get_workspace().get_id() === fw.get_id())
|
.filter(cl => fw && cl.get_workspace().get_id() === fw.get_id())
|
||||||
.map(cl => (
|
.map(cl => (
|
||||||
<box
|
<box
|
||||||
className={bind(hyprland, "focusedClient").as(a => a && a.address === cl.address ? "focused" : "unfocused")}
|
className={bind(hyprland, "focusedClient").as(a => a && a.address === cl.address ? "focused" : "unfocused")}
|
||||||
|
@ -279,25 +279,23 @@ function Clients() : JSX.Element {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Bar(gdkmonitor: Gdk.Monitor, scaleFactor: number = 1): JSX.Element {
|
export default function Bar(gdkmonitor: Gdk.Monitor, scaleFactor: number = 1): Widget.Window {
|
||||||
return (
|
return new Widget.Window({
|
||||||
<window
|
gdkmonitor,
|
||||||
css={"font-size: " + scaleFactor + "em;"}
|
css: "font-size: " + scaleFactor + "em;",
|
||||||
className="Bar"
|
exclusivity: Astal.Exclusivity.EXCLUSIVE,
|
||||||
gdkmonitor={gdkmonitor}
|
anchor: Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT,
|
||||||
exclusivity={Astal.Exclusivity.EXCLUSIVE}
|
application: App,
|
||||||
anchor={
|
className: "Bar",
|
||||||
Astal.WindowAnchor.TOP |
|
name: "top-bar",
|
||||||
Astal.WindowAnchor.LEFT |
|
setup: self => self.connect("destroy", () => {
|
||||||
Astal.WindowAnchor.RIGHT
|
print("Detroying bar");
|
||||||
}
|
App.remove_window(self);
|
||||||
application={App}
|
}),
|
||||||
>
|
child: <centerbox className="window-box">
|
||||||
<centerbox className="window-box" >
|
|
||||||
<Left />
|
<Left />
|
||||||
<Center />
|
<Center />
|
||||||
<Right />
|
<Right />
|
||||||
</centerbox>
|
</centerbox>
|
||||||
</window>
|
})
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { App, Gdk } from "astal/gtk3"
|
import { App, Gdk, Widget } 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 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();
|
const hyprland = Hyprland.get_default();
|
||||||
|
|
||||||
|
function find_main_monitor(): Hyprland.Monitor {
|
||||||
let monitors = hyprland.get_monitors()
|
let monitors = hyprland.get_monitors()
|
||||||
for (let i = 0; i < monitors.length; i++) {
|
for (let i = 0; i < monitors.length; i++) {
|
||||||
for (const monitor of ["eDP", "DP", "HDMI-A"]) {
|
for (const monitor of ["eDP", "DP", "HDMI-A"]) {
|
||||||
|
@ -17,14 +18,33 @@ function find_main_monitor(): Hyprland.Monitor {
|
||||||
return monitors[0]
|
return monitors[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function register_windows(monitor: Hyprland.Monitor) {
|
||||||
|
let gtkMonitor = App.get_monitors()[0].get_display().get_monitor_at_point(monitor.get_x(), monitor.get_y())
|
||||||
|
let scale = (monitor.get_width() >= 3000)? 1.2: 1
|
||||||
|
Bar(gtkMonitor, scale)
|
||||||
|
NotificationPopups(gtkMonitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
function switch_to_best_monitor() {
|
||||||
|
let mainMonitor = find_main_monitor()
|
||||||
|
for (var wd of App.get_windows()) {
|
||||||
|
wd.destroy();
|
||||||
|
}
|
||||||
|
register_windows(mainMonitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
hyprland.connect("monitor-added", (_, monitor) => {
|
||||||
|
switch_to_best_monitor()
|
||||||
|
})
|
||||||
|
|
||||||
|
hyprland.connect("monitor-removed", () => {
|
||||||
|
switch_to_best_monitor()
|
||||||
|
})
|
||||||
|
|
||||||
App.start({
|
App.start({
|
||||||
css: style,
|
css: style,
|
||||||
iconTheme: "Papirus",
|
iconTheme: "Papirus",
|
||||||
main() {
|
main() {
|
||||||
let mainMonitor = find_main_monitor()
|
switch_to_best_monitor()
|
||||||
let gtkMonitor = App.get_monitors()[0].get_display().get_monitor_at_point(mainMonitor.get_x(), mainMonitor.get_y())
|
|
||||||
let scale = (mainMonitor.get_width() >= 3000)? 1.2: 1
|
|
||||||
Bar(gtkMonitor, scale)
|
|
||||||
NotificationPopups(gtkMonitor)
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue