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 Tray from "gi://AstalTray";
|
||||
import { execAsync } from "astal/process"
|
||||
|
@ -224,7 +224,7 @@ function Workspaces() : JSX.Element {
|
|||
<box>
|
||||
{bind(hyprland, "focusedMonitor").as((fm) =>
|
||||
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) => (
|
||||
<button
|
||||
className={bind(hyprland, "focusedWorkspace").as((fw) => ws === fw ? "focused" : "",)}
|
||||
|
@ -255,7 +255,7 @@ function Clients() : JSX.Element {
|
|||
cls
|
||||
.sort((a, b) => a.pid - b.pid)
|
||||
.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 => (
|
||||
<box
|
||||
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 {
|
||||
return (
|
||||
<window
|
||||
css={"font-size: " + scaleFactor + "em;"}
|
||||
className="Bar"
|
||||
gdkmonitor={gdkmonitor}
|
||||
exclusivity={Astal.Exclusivity.EXCLUSIVE}
|
||||
anchor={
|
||||
Astal.WindowAnchor.TOP |
|
||||
Astal.WindowAnchor.LEFT |
|
||||
Astal.WindowAnchor.RIGHT
|
||||
}
|
||||
application={App}
|
||||
>
|
||||
<centerbox className="window-box" >
|
||||
export default function Bar(gdkmonitor: Gdk.Monitor, scaleFactor: number = 1): Widget.Window {
|
||||
return new Widget.Window({
|
||||
gdkmonitor,
|
||||
css: "font-size: " + scaleFactor + "em;",
|
||||
exclusivity: Astal.Exclusivity.EXCLUSIVE,
|
||||
anchor: Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT,
|
||||
application: App,
|
||||
className: "Bar",
|
||||
name: "top-bar",
|
||||
setup: self => self.connect("destroy", () => {
|
||||
print("Detroying bar");
|
||||
App.remove_window(self);
|
||||
}),
|
||||
child: <centerbox className="window-box">
|
||||
<Left />
|
||||
<Center />
|
||||
<Right />
|
||||
</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 Bar from "./Bar"
|
||||
import Hyprland from "gi://AstalHyprland";
|
||||
import NotificationPopups from "./notifications/NotificationPopups"
|
||||
|
||||
const hyprland = Hyprland.get_default();
|
||||
|
||||
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"]) {
|
||||
|
@ -17,14 +18,33 @@ function find_main_monitor(): Hyprland.Monitor {
|
|||
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({
|
||||
css: style,
|
||||
iconTheme: "Papirus",
|
||||
main() {
|
||||
let mainMonitor = find_main_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)
|
||||
switch_to_best_monitor()
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue