Added monitor switch files.
This commit is contained in:
1
monitor-switch/10-monitor-hotplug.rules
Normal file
1
monitor-switch/10-monitor-hotplug.rules
Normal file
@@ -0,0 +1 @@
|
||||
ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/usr/bin/touch /tmp/monitor-hotplug-changed"
|
||||
6
monitor-switch/monitor-hotplug.path
Normal file
6
monitor-switch/monitor-hotplug.path
Normal file
@@ -0,0 +1,6 @@
|
||||
[Path]
|
||||
PathModified=/tmp/monitor-hotplug-changed
|
||||
Unit=monitor-hotplug.service
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
9
monitor-switch/monitor-hotplug.service
Normal file
9
monitor-switch/monitor-hotplug.service
Normal file
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Update Monitor outputs
|
||||
|
||||
[Service]
|
||||
Environment=DISPLAY=:0
|
||||
Environment=XAUTHORITY=/home/nnm/.Xauthority
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/scala -nc -save /usr/local/bin/update-output.scala
|
||||
User=nnm
|
||||
27
monitor-switch/update-output.scala
Executable file
27
monitor-switch/update-output.scala
Executable file
@@ -0,0 +1,27 @@
|
||||
import scala.sys.process._
|
||||
|
||||
val eDP1 = List("--output", "eDP1", "--primary", "--auto", "--pos", "0x0", "--rotate", "normal")
|
||||
|
||||
val interfaceMapOn = Map[String, Seq[String]](
|
||||
"DP1" -> List("--output", "DP1", "--auto", "--right-of", "eDP1", "--rotate", "normal"),
|
||||
"HDMI2" -> List("--output", "HDMI2", "--auto", "--left-of", "eDP1", "--rotate", "normal")
|
||||
)
|
||||
|
||||
val interfaceMapOff = Map[String, Seq[String]](
|
||||
"DP1" -> List("--output", "DP1", "--off"),
|
||||
"DP2" -> List("--output", "DP2", "--off"),
|
||||
"HDMI1" -> List("--output", "HDMI1", "--off"),
|
||||
"HDMI2" -> List("--output", "HDMI2", "--off")
|
||||
)
|
||||
|
||||
val interfacesOn = ("/usr/bin/xrandr" #| Seq("grep", "-w", "connected") #| Seq("tr", "-s", "' '") #| Seq("cut", "-d", " ", "-f", "1")).!!.trim.split("\n")
|
||||
val interfacesOff = ("/usr/bin/xrandr" #| Seq("grep", "-w", "disconnected") #| Seq("tr", "-s", "' '") #| Seq("cut", "-d", " ", "-f", "1")).!!.trim.split("\n")
|
||||
var execCmd = "/usr/bin/xrandr" :: eDP1 ++
|
||||
interfacesOn.flatMap(i => interfaceMapOn.getOrElse(i.toUpperCase, List.empty)) ++
|
||||
interfacesOff.flatMap(i => interfaceMapOff.getOrElse(i.toUpperCase, List.empty))
|
||||
|
||||
println(s"Enabled interfaces: ${interfacesOn.mkString(" ")}")
|
||||
println(s"Disabled interfaces: ${interfacesOff.mkString(" ")}")
|
||||
println(s"Executing command line: $execCmd")
|
||||
|
||||
execCmd.!
|
||||
Reference in New Issue
Block a user