Remix.run Logo
marginalia_nu 3 days ago

Actually, typing this out led me to find a fix for the multiscreen workspace issue I was having. Basically the solution is to first assign the workspaces to monitors, and then bind the hotkeys to switch both workspaces at once, with the final binding being the one you land at.

If someone wants to steal my homework, this is what I did

  # use `hyprctl monitors` to get your monitors' names, replace DP-3 and HDMI-A-1 as appropriate

  workspace = 1, monitor:DP-3, default:true
  workspace = 2, monitor:HDMI-A-1, default:true
  workspace = 3, monitor:DP-3
  workspace = 4, monitor:HDMI-A-1
  workspace = 5, monitor:DP-3
  workspace = 6, monitor:HDMI-A-1
  workspace = 7, monitor:DP-3
  workspace = 8, monitor:HDMI-A-1

  unbind = SUPER, code:10
  unbind = SUPER, code:11
  unbind = SUPER, code:12
  unbind = SUPER, code:13
  unbind = SUPER, code:14
  unbind = SUPER, code:15
  unbind = SUPER, code:16
  unbind = SUPER, code:17

  bindd = SUPER, code:10, Switch to workspace 1, workspace, 2
  bindd = SUPER, code:10, Switch to workspace 1, workspace, 1
  bindd = SUPER, code:11, Switch to workspace 2, workspace, 1
  bindd = SUPER, code:11, Switch to workspace 2, workspace, 2
  bindd = SUPER, code:12, Switch to workspace 3, workspace, 4
  bindd = SUPER, code:12, Switch to workspace 3, workspace, 3
  bindd = SUPER, code:13, Switch to workspace 4, workspace, 3
  bindd = SUPER, code:13, Switch to workspace 4, workspace, 4
  bindd = SUPER, code:14, Switch to workspace 5, workspace, 6
  bindd = SUPER, code:14, Switch to workspace 5, workspace, 5
  bindd = SUPER, code:15, Switch to workspace 6, workspace, 5
  bindd = SUPER, code:15, Switch to workspace 6, workspace, 6
  bindd = SUPER, code:16, Switch to workspace 7, workspace, 8
  bindd = SUPER, code:16, Switch to workspace 7, workspace, 7
  bindd = SUPER, code:17, Switch to workspace 8, workspace, 7
  bindd = SUPER, code:17, Switch to workspace 8, workspace, 8
tincholio 2 days ago | parent | next [-]

I've been experimenting with this (it's in Babashka, which is for scripting Clojure, but you can do it with just bash, if your bash-fu is stronger than mine :D ):

    #!/bin/env bb
    
    (ns switch
      (:require [clojure.java.shell :as sh]
                [babashka.process :refer [pipeline pb shell process]]
                [clojure.string :as str]))
    
    (def workspace-ids
      (-> (pipeline (pb "hyprctl workspaces")
                    (pb "grep 'workspace ID'")
                    (pb "awk '{print $3}'"))
          last
          :out
          slurp
          (str/split #"\n")
          (->> (reduce (fn[acc e]
                         (try (let [ee (Integer/parseInt e)]
                                (conj acc ee))
                              (catch Exception e acc))) [])
               (filter #(and (pos? %)
                             (not= 10 %))))))
    
    
    
    (doseq [w workspace-ids]
      (-> (process (str "hyprctl dispatch moveworkspacetomonitor " w " 1"))
          deref
          :exit
          println))
    
    (process "hyprctl dispatch workspace 8")

It basically just moves all workspaces with positive IDs (so not the special workspace) to the external monitor, which seems to have a consistent ID of 1.
evertedsphere 3 days ago | parent | prev [-]

the ideal solution takes into account which screen you were on and leaves you on it

i used to have a setup like this on i3, using i3-msg to query the state