From d4996af84acf42184a8dee45b32e2613b14b1aad Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 8 Feb 2024 01:20:03 +0100 Subject: [PATCH 1/5] unhardcode data dir #115 --- go.mod | 4 ++-- go.sum | 2 ++ main.go | 55 ++++++++++++++++++++++++++++++------------------------- tools.go | 20 ++++++++++++++++++-- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index 088fc75..dfd246f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/nwg-piotr/nwg-drawer -go 1.21 +go 1.22 require ( github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37 @@ -15,5 +15,5 @@ require ( github.com/joshuarubin/lifecycle v1.1.4 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/sys v0.17.0 // indirect ) diff --git a/go.sum b/go.sum index d36fb20..f5411c6 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,8 @@ golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/main.go b/main.go index 97fa488..67f325d 100644 --- a/main.go +++ b/main.go @@ -234,7 +234,7 @@ func main() { // Otherwise the command may behave in two ways: // 1. kill the running non-residennt instance and exit; // 2. die if a resident instance found. - lockFilePath := path.Join(dataDir(), "nwg-drawer.lock") + lockFilePath := path.Join(dataHome(), "nwg-drawer.lock") lockFile, err := singleinstance.CreateLockFile(lockFilePath) if err != nil { pid, err := readTextFile(lockFilePath) @@ -579,32 +579,37 @@ func main() { } // Power Button Bar - if *pbExit != "" || *pbLock != "" || *pbPoweroff != "" || *pbReboot != "" || *pbSleep != "" { - powerBarWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) - outerVBox.PackStart(powerBarWrapper, false, false, 0) - powerButtonsWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) - powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 12) + dDir := dataDir() + if dDir != "" { + if *pbExit != "" || *pbLock != "" || *pbPoweroff != "" || *pbReboot != "" || *pbSleep != "" { + powerBarWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) + outerVBox.PackStart(powerBarWrapper, false, false, 0) + powerButtonsWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) + powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 12) - if *pbLock != "" { - btn := powerButton("/usr/share/nwg-drawer/img/lock.svg", *pbLock) - powerButtonsWrapper.PackStart(btn, true, false, 0) - } - if *pbExit != "" { - btn := powerButton("/usr/share/nwg-drawer/img/exit.svg", *pbExit) - powerButtonsWrapper.PackStart(btn, true, false, 0) - } - if *pbReboot != "" { - btn := powerButton("/usr/share/nwg-drawer/img/reboot.svg", *pbReboot) - powerButtonsWrapper.PackStart(btn, true, false, 0) - } - if *pbSleep != "" { - btn := powerButton("/usr/share/nwg-drawer/img/sleep.svg", *pbSleep) - powerButtonsWrapper.PackStart(btn, true, false, 0) - } - if *pbPoweroff != "" { - btn := powerButton("/usr/share/nwg-drawer/img/poweroff.svg", *pbPoweroff) - powerButtonsWrapper.PackStart(btn, true, false, 0) + if *pbLock != "" { + btn := powerButton(filepath.Join(dDir, "img/lock.svg"), *pbLock) + powerButtonsWrapper.PackStart(btn, true, false, 0) + } + if *pbExit != "" { + btn := powerButton(filepath.Join(dDir, "img/exit.svg"), *pbExit) + powerButtonsWrapper.PackStart(btn, true, false, 0) + } + if *pbReboot != "" { + btn := powerButton(filepath.Join(dDir, "img/reboot.svg"), *pbReboot) + powerButtonsWrapper.PackStart(btn, true, false, 0) + } + if *pbSleep != "" { + btn := powerButton(filepath.Join(dDir, "img/sleep.svg"), *pbSleep) + powerButtonsWrapper.PackStart(btn, true, false, 0) + } + if *pbPoweroff != "" { + btn := powerButton(filepath.Join(dDir, "img/poweroff.svg"), *pbPoweroff) + powerButtonsWrapper.PackStart(btn, true, false, 0) + } } + } else { + log.Warn("Couldn't find data dir, power bar icons unavailable") } statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) diff --git a/tools.go b/tools.go index 98c71b7..4a8ea33 100644 --- a/tools.go +++ b/tools.go @@ -173,7 +173,7 @@ func configHome() string { return path.Join(os.Getenv("HOME"), ".config") } -func dataDir() string { +func dataHome() string { var dir string if xdgData := os.Getenv("XDG_DATA_HOME"); xdgData != "" { dir = path.Join(xdgData, "nwg-drawer") @@ -181,7 +181,7 @@ func dataDir() string { dir = path.Join(home, ".local/share/nwg-drawer") } - log.Infof("Data dir: %s", dir) + log.Infof("Data home: %s", dir) createDir(dir) return dir @@ -233,6 +233,22 @@ func copyFile(src, dst string) error { return os.Chmod(dst, srcinfo.Mode()) } +func dataDir() string { + xdgDataDirs := os.Getenv("XDG_DATA_DIRS") + if xdgDataDirs == "" { + xdgDataDirs = "/usr/local/share/:/usr/share/" + } + for _, d := range strings.Split(xdgDataDirs, ":") { + p := filepath.Join(d, "nwg-drawer") + if pathExists(p) { + log.Infof("Data dir: %v", p) + return p + } + } + log.Warnf("Data dir not found") + return "" +} + func getAppDirs() []string { var dirs []string From 701d4e62f22e15a60582ccf5f1cb0d8ff9ad3d39 Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 8 Feb 2024 01:31:22 +0100 Subject: [PATCH 2/5] unhardcode data dir again #115 --- main.go | 17 +++++++++-------- tools.go | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 67f325d..0233935 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ const version = "0.4.6" var ( appDirs []string configDirectory string + dataDirectory string pinnedFile string pinned []string id2entry map[string]desktopEntry @@ -266,6 +267,7 @@ func main() { // ENVIRONMENT configDirectory = configDir() + dataDirectory = dataDir() // Placing the drawer config files in the nwg-panel config directory was a mistake. // Let's move them to their own location. @@ -291,7 +293,7 @@ func main() { // Copy default style sheet if not found if !pathExists(filepath.Join(configDirectory, "drawer.css")) { - err := copyFile("/usr/share/nwg-drawer/drawer.css", filepath.Join(configDirectory, "drawer.css")) + err := copyFile(filepath.Join(dataDirectory, "drawer.css"), filepath.Join(configDirectory, "drawer.css")) if err != nil { log.Errorf("Failed copying 'drawer.css' file: %s", err) } @@ -579,8 +581,7 @@ func main() { } // Power Button Bar - dDir := dataDir() - if dDir != "" { + if dataDirectory != "" { if *pbExit != "" || *pbLock != "" || *pbPoweroff != "" || *pbReboot != "" || *pbSleep != "" { powerBarWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) outerVBox.PackStart(powerBarWrapper, false, false, 0) @@ -588,23 +589,23 @@ func main() { powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 12) if *pbLock != "" { - btn := powerButton(filepath.Join(dDir, "img/lock.svg"), *pbLock) + btn := powerButton(filepath.Join(dataDirectory, "img/lock.svg"), *pbLock) powerButtonsWrapper.PackStart(btn, true, false, 0) } if *pbExit != "" { - btn := powerButton(filepath.Join(dDir, "img/exit.svg"), *pbExit) + btn := powerButton(filepath.Join(dataDirectory, "img/exit.svg"), *pbExit) powerButtonsWrapper.PackStart(btn, true, false, 0) } if *pbReboot != "" { - btn := powerButton(filepath.Join(dDir, "img/reboot.svg"), *pbReboot) + btn := powerButton(filepath.Join(dataDirectory, "img/reboot.svg"), *pbReboot) powerButtonsWrapper.PackStart(btn, true, false, 0) } if *pbSleep != "" { - btn := powerButton(filepath.Join(dDir, "img/sleep.svg"), *pbSleep) + btn := powerButton(filepath.Join(dataDirectory, "img/sleep.svg"), *pbSleep) powerButtonsWrapper.PackStart(btn, true, false, 0) } if *pbPoweroff != "" { - btn := powerButton(filepath.Join(dDir, "img/poweroff.svg"), *pbPoweroff) + btn := powerButton(filepath.Join(dataDirectory, "img/poweroff.svg"), *pbPoweroff) powerButtonsWrapper.PackStart(btn, true, false, 0) } } diff --git a/tools.go b/tools.go index 4a8ea33..5a01266 100644 --- a/tools.go +++ b/tools.go @@ -197,7 +197,7 @@ func createDir(dir string) { } func copyFile(src, dst string) error { - log.Infof("Copying file: %s", dst) + log.Infof("Copying: '%s' => '%s'", src, dst) var err error var srcfd *os.File From 3ea4a7824ce1403c860d1e0e0df73279c67c7c17 Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 8 Feb 2024 01:32:37 +0100 Subject: [PATCH 3/5] bump to 0.4.7 --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 0233935..5fc7c50 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( "github.com/gotk3/gotk3/gtk" ) -const version = "0.4.6" +const version = "0.4.7" var ( appDirs []string From b59058c5c21eb4b5f12000d65673264b2c2d2c5f Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 8 Feb 2024 02:23:34 +0100 Subject: [PATCH 4/5] focus 1st power button on Tab key --- main.go | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 5fc7c50..f392bbf 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ var ( exclusions []string hyprlandMonitors []monitor beenScrolled bool + firstPowerBtn *gtk.Button ) var categoryNames = [...]string{ @@ -462,6 +463,10 @@ func main() { } } return true + } else if key.KeyVal() == gdk.KEY_Tab { + if firstPowerBtn != nil { + firstPowerBtn.ToWidget().GrabFocus() + } } return false }) @@ -588,25 +593,30 @@ func main() { powerButtonsWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 12) - if *pbLock != "" { - btn := powerButton(filepath.Join(dataDirectory, "img/lock.svg"), *pbLock) - powerButtonsWrapper.PackStart(btn, true, false, 0) - } - if *pbExit != "" { - btn := powerButton(filepath.Join(dataDirectory, "img/exit.svg"), *pbExit) - powerButtonsWrapper.PackStart(btn, true, false, 0) - } - if *pbReboot != "" { - btn := powerButton(filepath.Join(dataDirectory, "img/reboot.svg"), *pbReboot) - powerButtonsWrapper.PackStart(btn, true, false, 0) + if *pbPoweroff != "" { + btn := powerButton(filepath.Join(dataDirectory, "img/poweroff.svg"), *pbPoweroff) + powerButtonsWrapper.PackEnd(btn, true, false, 0) + firstPowerBtn = btn } if *pbSleep != "" { btn := powerButton(filepath.Join(dataDirectory, "img/sleep.svg"), *pbSleep) - powerButtonsWrapper.PackStart(btn, true, false, 0) + powerButtonsWrapper.PackEnd(btn, true, false, 0) + firstPowerBtn = btn } - if *pbPoweroff != "" { - btn := powerButton(filepath.Join(dataDirectory, "img/poweroff.svg"), *pbPoweroff) - powerButtonsWrapper.PackStart(btn, true, false, 0) + if *pbReboot != "" { + btn := powerButton(filepath.Join(dataDirectory, "img/reboot.svg"), *pbReboot) + powerButtonsWrapper.PackEnd(btn, true, false, 0) + firstPowerBtn = btn + } + if *pbExit != "" { + btn := powerButton(filepath.Join(dataDirectory, "img/exit.svg"), *pbExit) + powerButtonsWrapper.PackEnd(btn, true, false, 0) + firstPowerBtn = btn + } + if *pbLock != "" { + btn := powerButton(filepath.Join(dataDirectory, "img/lock.svg"), *pbLock) + powerButtonsWrapper.PackEnd(btn, true, false, 0) + firstPowerBtn = btn } } } else { From 936f793be44564c58f95f48e370177bdd0de3ec7 Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 8 Feb 2024 02:28:21 +0100 Subject: [PATCH 5/5] update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f9c58f2..80702a5 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ and for files in XDG user directories. The grid view may also be filtered by cat You may pin applications by right-clicking them. Pinned items will appear above the application grid. Right-click a pinned item to unpin it. The pinned items cache is shared with [nwg-menu](https://github.com/nwg-piotr/nwg-menu). -Below the grid there is the power bar - a row of buttons to lock the screen, exit the compositor, reboot, suspend and power -the machine off. For each button to appear, you need to provide a corresponding command. See "Command line arguments" -below. +Below the grid there is the **power bar** - a row of buttons to lock the screen, exit the compositor, reboot, suspend +and power the machine off. For each button to appear, you need to provide a corresponding command. See "Command line +arguments" below. If the power bar is present, pressing **Tab** will move focus to its first button. screenshot