DISPLAY_PROTOCOL Variable and separate monitor resolutions (On X11)
Added a DISPLAY_PROTOCOL variable Resolution information has been converted to a Golang function and now lists different monitors separately
This commit is contained in:
parent
2984a7da5f
commit
7ed54ec1a5
@ -5,20 +5,15 @@ echo -e "${C3}Hostname: ${C4}$(cat /etc/hostname)"
|
|||||||
echo -e "${C3}Kernel: ${C4}$(uname -s) $(uname -r)"
|
echo -e "${C3}Kernel: ${C4}$(uname -s) $(uname -r)"
|
||||||
echo -e "${C3}Packages: ${C4}$(get_packages)"
|
echo -e "${C3}Packages: ${C4}$(get_packages)"
|
||||||
echo -e "${C3}Shell: ${C4}${USER_SHELL}"
|
echo -e "${C3}Shell: ${C4}${USER_SHELL}"
|
||||||
if [ ! -z "$CPU_MODEL" ]; then
|
if [ ! -z "$CPU_MODEL" ]; then echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"; fi
|
||||||
echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"
|
if [ ! -z "$GPU_MODEL" ]; then echo -e "${C3}GPU: ${C4}${GPU_MODEL}"; fi
|
||||||
fi
|
if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"; fi
|
||||||
if [ ! -z "$GPU_MODEL" ]; then
|
if [ ! -z "$DISPLAY_PROTOCOL" ]; then
|
||||||
echo -e "${C3}GPU: ${C4}${GPU_MODEL}"
|
echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}"
|
||||||
fi
|
for i in $(seq ${CONNECTED_MONITORS}); do
|
||||||
if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then
|
monitor="MONITOR$i"
|
||||||
echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"
|
echo -e "${C3}Screen $i: ${C4}${!monitor}"
|
||||||
fi
|
done
|
||||||
if xhost >& /dev/null ; then
|
|
||||||
if [ ! -z "$DE_WM" ]; then
|
|
||||||
echo -e "${C3}DE/WM: ${C4}${DE_WM}"
|
|
||||||
fi
|
|
||||||
if command_exists xdpyinfo ; then
|
|
||||||
echo -e "${C3}Screen Resolution: ${C4}$(get_screen_resolution)"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
if [ ! -z "$DE_WM" ]; then echo -e "${C3}DE/WM: ${C4}${DE_WM}"; fi
|
||||||
|
|
||||||
|
@ -9,12 +9,6 @@ command_exists() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_screen_resolution() {
|
|
||||||
if xhost >& /dev/null && command_exists xdpyinfo; then
|
|
||||||
xdpyinfo | grep dimensions | tr -s ' ' | cut -d " " -f3
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_packages() {
|
get_packages() {
|
||||||
ARRAY=()
|
ARRAY=()
|
||||||
if command_exists dpkg; then
|
if command_exists dpkg; then
|
||||||
|
8
main.go
8
main.go
@ -151,6 +151,14 @@ func readConfig() {
|
|||||||
}
|
}
|
||||||
cmd.Env = append(cmd.Env, "DE_WM="+GetDEWM())
|
cmd.Env = append(cmd.Env, "DE_WM="+GetDEWM())
|
||||||
cmd.Env = append(cmd.Env, "USER_SHELL="+GetShell())
|
cmd.Env = append(cmd.Env, "USER_SHELL="+GetShell())
|
||||||
|
cmd.Env = append(cmd.Env, "DISPLAY_PROTOCOL="+GetDisplayProtocol())
|
||||||
|
monitors := getMonitorResolution()
|
||||||
|
if len(monitors) != 0 {
|
||||||
|
cmd.Env = append(cmd.Env, "CONNECTED_MONITORS="+strconv.Itoa(len(monitors)))
|
||||||
|
for i, monitor := range monitors {
|
||||||
|
cmd.Env = append(cmd.Env, "MONITOR"+strconv.Itoa(i+1)+"="+monitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
if getGPUName() != "" {
|
if getGPUName() != "" {
|
||||||
cmd.Env = append(cmd.Env, "GPU_MODEL="+getGPUName())
|
cmd.Env = append(cmd.Env, "GPU_MODEL="+getGPUName())
|
||||||
}
|
}
|
||||||
|
42
utils.go
42
utils.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"github.com/jackmordaunt/ghw"
|
"github.com/jackmordaunt/ghw"
|
||||||
"github.com/mitchellh/go-ps"
|
"github.com/mitchellh/go-ps"
|
||||||
"log"
|
"log"
|
||||||
@ -283,6 +284,47 @@ func GetDEWM() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDisplayProtocol() string {
|
||||||
|
protocol := os.Getenv("XDG_SESSION_TYPE")
|
||||||
|
if protocol == "x11" {
|
||||||
|
return "X11"
|
||||||
|
} else if protocol == "wayland" {
|
||||||
|
return "Wayland"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMonitorResolution() []string {
|
||||||
|
var monitors []string
|
||||||
|
runCommand := func(command string) string {
|
||||||
|
cmd := exec.Command("/bin/bash", "-c", command)
|
||||||
|
workdir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
cmd.Dir = workdir
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
if GetDisplayProtocol() == "X11" {
|
||||||
|
if _, err := os.Stat("/usr/bin/xrandr"); err != nil {
|
||||||
|
return monitors
|
||||||
|
}
|
||||||
|
connections := strings.Split(runCommand("xrandr --query | grep -w \"connected\" | awk '{print $1}'"), "\n")
|
||||||
|
for i, con := range connections {
|
||||||
|
Xaxis := runCommand(fmt.Sprintf("xrandr --current | grep -m%d '*' | tail -n1 | uniq | awk '{print $1}' | cut -d 'x' -f1", i+1))
|
||||||
|
Yaxis := runCommand(fmt.Sprintf("xrandr --current | grep -m%d '*' | tail -n1 | uniq | awk '{print $1}' | cut -d 'x' -f2", i+1))
|
||||||
|
monitors = append(monitors, con+" ("+Xaxis+"x"+Yaxis+")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return monitors
|
||||||
|
}
|
||||||
|
|
||||||
func stripAnsii(str string) string {
|
func stripAnsii(str string) string {
|
||||||
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
||||||
var re = regexp.MustCompile(ansi)
|
var re = regexp.MustCompile(ansi)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user