merge branch niri into v3 #1

Merged
nat merged 2 commits from niri into v3 2025-03-17 01:50:49 -07:00
Showing only changes of commit dd8fc68c62 - Show all commits

View File

@ -1,34 +1,41 @@
(import astal *) (import astal *)
(import astal.gtk3 *) (import astal.gtk3 *)
(.require-version gi "AstalHyprland" "0.1") (.require-version gi "AstalNiri" "0.1")
(import gi.repository [AstalHyprland :as Hyprland])
(import gi.repository [AstalNiri :as Niri])
(let [ (let [
hyprland (.get-default Hyprland) Niri (.get-default Niri)
workspace-row (fn [start stop] workspace-row (fn [start stop]
(Widget.Box (Widget.Box
:children (lfor i (range start stop) :children (lfor i (range start stop)
(Widget.Button (Widget.Button
:class-name "workspace" :class-name "workspace"
:attribute (+ i 1) :attribute (+ i 1)
:on-clicked (fn [self] (.message-async hyprland f"dispatch workspace {self.attribute}")) :on-clicked (fn [self] (exec-async f"niri msg action focus-workspace {self.attribute}"))
:setup (fn [self] :setup (fn [self]
(.hook self hyprland "notify::focused-workspace" (fn [self, w] (.toggle-class-name self "focused" (= (.get-id w) self.attribute))))
(.hook self Niri "workspace-activated" (fn [_ w __]
(when w
(.toggle-class-name self "focused" (= (.get-id (. Niri (get-workspace w))) self.attribute)))))
(defn update [#* _] (defn update [#* _]
(let [workspace (.get-workspace hyprland self.attribute)] (let [workspace (.get-workspace Niri self.attribute)]
(when (!= workspace None) (when (!= workspace None)
(.toggle-class-name self "occupied" (< 0 (len (.get-clients workspace))))))) (.toggle-class-name self "occupied" (< 0 (len (lfor window (. Niri (get-windows))
:if (= (.get-workspace-id window) (.get-id workspace))
window)))))))
(.hook self hyprland "notify::workspaces" update) (.hook self Niri "workspaces-changed" update)
(.hook self hyprland "notify::clients" update) (.hook self Niri "window-opened" update)
(.hook self hyprland "client-moved" update) (.hook self Niri "window-changed" update)
(update) (.hook self Niri "window-closed" update)
(when (= (.get-id (.get-focused-workspace hyprland)) self.attribute) (idle update)
(.toggle-class-name self "focused")))))))]
(idle (fn [] (when (= (.get-id (.get-focused-workspace Niri)) self.attribute)
(.toggle-class-name self "focused")))))))))]
(setv workspaces (Widget.Box (setv workspaces (Widget.Box
:class_name "workspaces" :class_name "workspaces"