Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
223e16f77c | ||
|
|
55c095c053 | ||
|
|
ee2008348f | ||
|
|
0570f90bec | ||
|
|
a2917d68dd | ||
|
|
b05b0f484a | ||
|
|
b61e665c71 | ||
|
|
8408c669ef | ||
|
|
d66066c3b6 | ||
|
|
dac55cdd0d | ||
|
|
03365d24e5 | ||
|
|
8e58654336 | ||
|
|
33e0032725 | ||
|
|
c05fff189d | ||
|
|
57d130ca51 | ||
|
|
954a6ba9c9 | ||
|
|
67b16ea6a6 | ||
|
|
3a02b16761 | ||
|
|
c67fef6671 | ||
|
|
444617865e | ||
|
|
e3de9cc67b | ||
|
|
1c11329581 | ||
|
|
87ee23afe2 | ||
|
|
808fd032a0 | ||
|
|
1d3f023dc8 | ||
|
|
ccfe7776c6 | ||
|
|
5a7dbefeb0 |
10
go.mod
10
go.mod
@@ -1,11 +1,11 @@
|
|||||||
module github.com/nwg-piotr/nwg-drawer
|
module github.com/nwg-piotr/nwg-drawer
|
||||||
|
|
||||||
go 1.20
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37
|
github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37
|
||||||
github.com/dlasky/gotk3-layershell v0.0.0-20221218201547-1f6674a3f872
|
github.com/dlasky/gotk3-layershell v0.0.0-20230802002603-b0c42cd8474f
|
||||||
github.com/fsnotify/fsnotify v1.6.0
|
github.com/fsnotify/fsnotify v1.7.0
|
||||||
github.com/gotk3/gotk3 v0.6.2
|
github.com/gotk3/gotk3 v0.6.2
|
||||||
github.com/joshuarubin/go-sway v1.2.0
|
github.com/joshuarubin/go-sway v1.2.0
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
@@ -14,6 +14,6 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/joshuarubin/lifecycle v1.1.4 // indirect
|
github.com/joshuarubin/lifecycle v1.1.4 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/sync v0.3.0 // indirect
|
golang.org/x/sync v0.5.0 // indirect
|
||||||
golang.org/x/sys v0.10.0 // indirect
|
golang.org/x/sys v0.14.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
8
go.sum
8
go.sum
@@ -5,8 +5,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dlasky/gotk3-layershell v0.0.0-20221218201547-1f6674a3f872 h1:16qcNl+UgbvudN7wPv+zq4mmDSYJWdLv5jbVhS7+OVI=
|
github.com/dlasky/gotk3-layershell v0.0.0-20221218201547-1f6674a3f872 h1:16qcNl+UgbvudN7wPv+zq4mmDSYJWdLv5jbVhS7+OVI=
|
||||||
github.com/dlasky/gotk3-layershell v0.0.0-20221218201547-1f6674a3f872/go.mod h1:JHLx2Wz4mAPVwn4PFhC69ydwyHP4A3wQvlg7HKVVc1U=
|
github.com/dlasky/gotk3-layershell v0.0.0-20221218201547-1f6674a3f872/go.mod h1:JHLx2Wz4mAPVwn4PFhC69ydwyHP4A3wQvlg7HKVVc1U=
|
||||||
|
github.com/dlasky/gotk3-layershell v0.0.0-20230802002603-b0c42cd8474f h1:qDnUQAD7tVX/gnL6uSgouzfGNA4xXH+B/fd6Ko19GgM=
|
||||||
|
github.com/dlasky/gotk3-layershell v0.0.0-20230802002603-b0c42cd8474f/go.mod h1:JHLx2Wz4mAPVwn4PFhC69ydwyHP4A3wQvlg7HKVVc1U=
|
||||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||||
github.com/gotk3/gotk3 v0.6.1/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
|
github.com/gotk3/gotk3 v0.6.1/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
|
||||||
github.com/gotk3/gotk3 v0.6.2 h1:sx/PjaKfKULJPTPq8p2kn2ZbcNFxpOJqi4VLzMbEOO8=
|
github.com/gotk3/gotk3 v0.6.2 h1:sx/PjaKfKULJPTPq8p2kn2ZbcNFxpOJqi4VLzMbEOO8=
|
||||||
github.com/gotk3/gotk3 v0.6.2/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
|
github.com/gotk3/gotk3 v0.6.2/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
|
||||||
@@ -30,10 +34,14 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
|
|||||||
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||||
|
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
|
||||||
|
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||||
|
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
46
main.go
46
main.go
@@ -21,7 +21,7 @@ import (
|
|||||||
"github.com/gotk3/gotk3/gtk"
|
"github.com/gotk3/gotk3/gtk"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "0.3.9"
|
const version = "0.4.3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
appDirs []string
|
appDirs []string
|
||||||
@@ -31,6 +31,7 @@ var (
|
|||||||
id2entry map[string]desktopEntry
|
id2entry map[string]desktopEntry
|
||||||
preferredApps map[string]interface{}
|
preferredApps map[string]interface{}
|
||||||
exclusions []string
|
exclusions []string
|
||||||
|
hyprlandMonitors []monitor
|
||||||
)
|
)
|
||||||
|
|
||||||
var categoryNames = [...]string{
|
var categoryNames = [...]string{
|
||||||
@@ -66,6 +67,30 @@ type desktopEntry struct {
|
|||||||
NoDisplay bool
|
NoDisplay bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type monitor struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Make string `json:"make"`
|
||||||
|
Model string `json:"model"`
|
||||||
|
Serial string `json:"serial"`
|
||||||
|
Width int `json:"width"`
|
||||||
|
Height int `json:"height"`
|
||||||
|
RefreshRate float64 `json:"refreshRate"`
|
||||||
|
X int `json:"x"`
|
||||||
|
Y int `json:"y"`
|
||||||
|
ActiveWorkspace struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"activeWorkspace"`
|
||||||
|
Reserved []int `json:"reserved"`
|
||||||
|
Scale float64 `json:"scale"`
|
||||||
|
Transform int `json:"transform"`
|
||||||
|
Focused bool `json:"focused"`
|
||||||
|
DpmsStatus bool `json:"dpmsStatus"`
|
||||||
|
Vrr bool `json:"vrr"`
|
||||||
|
}
|
||||||
|
|
||||||
// slices below will hold DesktopID strings
|
// slices below will hold DesktopID strings
|
||||||
var (
|
var (
|
||||||
listUtility []string
|
listUtility []string
|
||||||
@@ -104,7 +129,7 @@ var (
|
|||||||
pinnedItemsChanged chan interface{} = make(chan interface{}, 1)
|
pinnedItemsChanged chan interface{} = make(chan interface{}, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultStringIfBlank(s, fallback string) string {
|
func defaultTermIfBlank(s, fallback string) string {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
// os.Getenv("TERM") returns "linux" instead of empty string, if program has been started
|
// os.Getenv("TERM") returns "linux" instead of empty string, if program has been started
|
||||||
// from a key binding defined in the config file. See #23.
|
// from a key binding defined in the config file. See #23.
|
||||||
@@ -114,9 +139,16 @@ func defaultStringIfBlank(s, fallback string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateWm() {
|
||||||
|
if !(*wm == "sway" || *wm == "hyprland" || *wm == "Hyprland") && *wm != "" {
|
||||||
|
*wm = ""
|
||||||
|
log.Warn("-wm argument supports only 'sway' or 'hyprland' string.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
var cssFileName = flag.String("s", "drawer.css", "Styling: css file name")
|
var cssFileName = flag.String("s", "drawer.css", "Styling: css file name")
|
||||||
var targetOutput = flag.String("o", "", "name of the Output to display the drawer on (sway only)")
|
var targetOutput = flag.String("o", "", "name of the Output to display the drawer on (sway & Hyprland only)")
|
||||||
var displayVersion = flag.Bool("v", false, "display Version information")
|
var displayVersion = flag.Bool("v", false, "display Version information")
|
||||||
var keyboard = flag.Bool("k", false, "set GTK layer shell Keyboard interactivity to 'on-demand' mode")
|
var keyboard = flag.Bool("k", false, "set GTK layer shell Keyboard interactivity to 'on-demand' mode")
|
||||||
var overlay = flag.Bool("ovl", false, "use OVerLay layer")
|
var overlay = flag.Bool("ovl", false, "use OVerLay layer")
|
||||||
@@ -133,7 +165,8 @@ var columnsNumber = flag.Uint("c", 6, "number of Columns")
|
|||||||
var itemSpacing = flag.Uint("spacing", 20, "icon spacing")
|
var itemSpacing = flag.Uint("spacing", 20, "icon spacing")
|
||||||
var lang = flag.String("lang", "", "force lang, e.g. \"en\", \"pl\"")
|
var lang = flag.String("lang", "", "force lang, e.g. \"en\", \"pl\"")
|
||||||
var fileManager = flag.String("fm", "thunar", "File Manager")
|
var fileManager = flag.String("fm", "thunar", "File Manager")
|
||||||
var term = flag.String("term", defaultStringIfBlank(os.Getenv("TERM"), "foot"), "Terminal emulator")
|
var term = flag.String("term", defaultTermIfBlank(os.Getenv("TERM"), "foot"), "Terminal emulator")
|
||||||
|
var wm = flag.String("wm", "", "use swaymsg exec (with 'sway' argument) or hyprctl dispatch exec (with 'hyprland') to launch programs")
|
||||||
var nameLimit = flag.Int("fslen", 80, "File Search name LENgth Limit")
|
var nameLimit = flag.Int("fslen", 80, "File Search name LENgth Limit")
|
||||||
var noCats = flag.Bool("nocats", false, "Disable filtering by category")
|
var noCats = flag.Bool("nocats", false, "Disable filtering by category")
|
||||||
var noFS = flag.Bool("nofs", false, "Disable file search")
|
var noFS = flag.Bool("nofs", false, "Disable file search")
|
||||||
@@ -153,6 +186,8 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validateWm()
|
||||||
|
|
||||||
// Gentle SIGTERM handler thanks to reiki4040 https://gist.github.com/reiki4040/be3705f307d3cd136e85
|
// Gentle SIGTERM handler thanks to reiki4040 https://gist.github.com/reiki4040/be3705f307d3cd136e85
|
||||||
// v0.2: we also need to support SIGUSR from now on
|
// v0.2: we also need to support SIGUSR from now on
|
||||||
showWindowChannel := make(chan interface{}, 1)
|
showWindowChannel := make(chan interface{}, 1)
|
||||||
@@ -362,6 +397,7 @@ func main() {
|
|||||||
if *targetOutput != "" {
|
if *targetOutput != "" {
|
||||||
// We want to assign layershell to a monitor, but we only know the output name!
|
// We want to assign layershell to a monitor, but we only know the output name!
|
||||||
output2mon, err = mapOutputs()
|
output2mon, err = mapOutputs()
|
||||||
|
fmt.Println(">>>", output2mon)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
monitor := output2mon[*targetOutput]
|
monitor := output2mon[*targetOutput]
|
||||||
layershell.SetMonitor(win, monitor)
|
layershell.SetMonitor(win, monitor)
|
||||||
@@ -524,8 +560,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
|
statusLineWrapper.SetProperty("name", "status-line-wrapper")
|
||||||
outerVBox.PackStart(statusLineWrapper, false, false, 10)
|
outerVBox.PackStart(statusLineWrapper, false, false, 10)
|
||||||
statusLabel, _ = gtk.LabelNew(status)
|
statusLabel, _ = gtk.LabelNew(status)
|
||||||
|
statusLabel.SetProperty("name", "status-label")
|
||||||
statusLineWrapper.PackStart(statusLabel, true, false, 0)
|
statusLineWrapper.PackStart(statusLabel, true, false, 0)
|
||||||
|
|
||||||
win.ShowAll()
|
win.ShowAll()
|
||||||
|
|||||||
136
tools.go
136
tools.go
@@ -5,8 +5,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/joshuarubin/go-sway"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -17,11 +20,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/gotk3/gotk3/gdk"
|
"github.com/gotk3/gotk3/gdk"
|
||||||
"github.com/gotk3/gotk3/gtk"
|
"github.com/gotk3/gotk3/gtk"
|
||||||
"github.com/joshuarubin/go-sway"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func wayland() bool {
|
func wayland() bool {
|
||||||
@@ -548,6 +548,14 @@ func savePinned() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func launch(command string, terminal bool) {
|
func launch(command string, terminal bool) {
|
||||||
|
// trim % and everything afterwards
|
||||||
|
if strings.Contains(command, "%") {
|
||||||
|
cutAt := strings.Index(command, "%")
|
||||||
|
if cutAt != -1 {
|
||||||
|
command = command[:cutAt-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
themeToPrepend := ""
|
themeToPrepend := ""
|
||||||
// add "GTK_THEME=<default_gtk_theme>" environment variable
|
// add "GTK_THEME=<default_gtk_theme>" environment variable
|
||||||
if *forceTheme {
|
if *forceTheme {
|
||||||
@@ -557,59 +565,31 @@ func launch(command string, terminal bool) {
|
|||||||
themeToPrepend = th.(string)
|
themeToPrepend = th.(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// trim % and everything afterwards
|
|
||||||
if strings.Contains(command, "%") {
|
|
||||||
cutAt := strings.Index(command, "%")
|
|
||||||
if cutAt != -1 {
|
|
||||||
command = command[:cutAt-1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
elements := strings.Split(command, " ")
|
|
||||||
|
|
||||||
// find prepended env variables, if any
|
|
||||||
envVarsNum := strings.Count(command, "=")
|
|
||||||
var envVars []string
|
|
||||||
|
|
||||||
cmdIdx := -1
|
|
||||||
|
|
||||||
if envVarsNum > 0 {
|
|
||||||
for idx, item := range elements {
|
|
||||||
if strings.Contains(item, "=") {
|
|
||||||
envVars = append(envVars, item)
|
|
||||||
} else if !strings.HasPrefix(item, "-") && cmdIdx == -1 {
|
|
||||||
cmdIdx = idx
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cmdIdx == -1 {
|
|
||||||
cmdIdx = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if themeToPrepend != "" {
|
if themeToPrepend != "" {
|
||||||
envVars = append(envVars, fmt.Sprintf("GTK_THEME=%s", themeToPrepend))
|
command = fmt.Sprintf("GTK_THEME=%q %s", themeToPrepend, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(elements[cmdIdx], elements[1+cmdIdx:]...)
|
var elements = []string{"/usr/bin/env", "-S", command}
|
||||||
|
|
||||||
|
cmd := exec.Command(elements[0], elements[1:]...)
|
||||||
|
|
||||||
if terminal {
|
if terminal {
|
||||||
|
var prefixCommand = *term
|
||||||
var args []string
|
var args []string
|
||||||
if *term != "foot" {
|
if prefixCommand != "foot" {
|
||||||
args = []string{"-e", elements[cmdIdx]}
|
args = []string{"-e", command}
|
||||||
} else {
|
} else {
|
||||||
args = []string{elements[cmdIdx]}
|
args = elements
|
||||||
|
}
|
||||||
|
cmd = exec.Command(prefixCommand, args...)
|
||||||
|
} else if *wm == "sway" {
|
||||||
|
cmd = exec.Command("swaymsg", "exec", strings.Join(elements, " "))
|
||||||
|
} else if *wm == "hyprland" || *wm == "Hyprland" {
|
||||||
|
cmd = exec.Command("hyprctl", "dispatch", "exec", strings.Join(elements, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = exec.Command(*term, args...)
|
msg := fmt.Sprintf("command: %q; args: %q\n", cmd.Args[0], cmd.Args[1:])
|
||||||
}
|
|
||||||
|
|
||||||
// set env variables
|
|
||||||
if len(envVars) > 0 {
|
|
||||||
cmd.Env = os.Environ()
|
|
||||||
cmd.Env = append(cmd.Env, envVars...)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := fmt.Sprintf("env vars: %s; command: '%s'; args: %s\n", envVars, elements[cmdIdx], elements[1+cmdIdx:])
|
|
||||||
log.Info(msg)
|
log.Info(msg)
|
||||||
|
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
@@ -671,6 +651,31 @@ func open(filePath string, xdgOpen bool) {
|
|||||||
func mapOutputs() (map[string]*gdk.Monitor, error) {
|
func mapOutputs() (map[string]*gdk.Monitor, error) {
|
||||||
result := make(map[string]*gdk.Monitor)
|
result := make(map[string]*gdk.Monitor)
|
||||||
|
|
||||||
|
if os.Getenv("HYPRLAND_INSTANCE_SIGNATURE") != "" {
|
||||||
|
err := listHyprlandMonitors()
|
||||||
|
if err == nil {
|
||||||
|
|
||||||
|
display, err := gdk.DisplayGetDefault()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
num := display.GetNMonitors()
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
mon, _ := display.GetMonitor(i)
|
||||||
|
geometry := mon.GetGeometry()
|
||||||
|
// assign output to monitor on the basis of the same x, y coordinates
|
||||||
|
for _, output := range hyprlandMonitors {
|
||||||
|
if int(output.X) == geometry.GetX() && int(output.Y) == geometry.GetY() {
|
||||||
|
result[output.Name] = mon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if os.Getenv("SWAYSOCK") != "" {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@@ -700,6 +705,10 @@ func mapOutputs() (map[string]*gdk.Monitor, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("output assignment only supported on sway and Hyprland")
|
||||||
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -718,3 +727,38 @@ func substring(s string, start int, end int) string {
|
|||||||
}
|
}
|
||||||
return s[startStrIdx:]
|
return s[startStrIdx:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hyprctl(cmd string) ([]byte, error) {
|
||||||
|
his := os.Getenv("HYPRLAND_INSTANCE_SIGNATURE")
|
||||||
|
socketFile := fmt.Sprintf("/tmp/hypr/%s/.socket.sock", his)
|
||||||
|
conn, err := net.Dial("unix", socketFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
message := []byte(cmd)
|
||||||
|
_, err = conn.Write(message)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
reply := make([]byte, 102400)
|
||||||
|
n, err := conn.Read(reply)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
return reply[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func listHyprlandMonitors() error {
|
||||||
|
reply, err := hyprctl("j/monitors")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
err = json.Unmarshal([]byte(reply), &hyprlandMonitors)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user