17 Commits

Author SHA1 Message Date
piotr
0cd48d1631 unhardcode desktop-directories path 2024-02-08 03:12:17 +01:00
piotr
943ca39055 update README.md 2024-02-08 02:51:16 +01:00
piotr
42b279ee02 update README.md 2024-02-08 02:49:57 +01:00
Piotr Miller
42f15ec2cb Merge pull request #116 from nwg-piotr/data
un-hardcode data dir
2024-02-08 02:35:16 +01:00
piotr
936f793be4 update README.md 2024-02-08 02:28:21 +01:00
piotr
b59058c5c2 focus 1st power button on Tab key 2024-02-08 02:23:34 +01:00
piotr
3ea4a7824c bump to 0.4.7 2024-02-08 01:32:37 +01:00
piotr
701d4e62f2 unhardcode data dir again #115 2024-02-08 01:31:22 +01:00
piotr
d4996af84a unhardcode data dir #115 2024-02-08 01:20:03 +01:00
piotr
71ce3b5d75 Merge remote-tracking branch 'origin/main' 2024-02-06 03:40:14 +01:00
piotr
b056b4c436 bump to 0.4.6 2024-02-06 03:39:35 +01:00
Piotr Miller
42b55d41df Merge pull request #113 from nwg-piotr/touch
Don't launch if the window has been scrolled
2024-02-06 03:38:09 +01:00
piotr
ec0ce767d9 get proper adjustment 2024-02-06 03:35:29 +01:00
piotr
ec3caa02d2 add comments #110 2024-02-06 03:33:12 +01:00
piotr
6b39eba14c check if window scrolled #110 2024-02-06 03:21:42 +01:00
piotr
631b651eed bump to 0.4.5 2024-02-05 01:02:34 +01:00
piotr
df644f4196 gotk3 -> 0.6.3 2024-02-05 01:01:30 +01:00
7 changed files with 100 additions and 42 deletions

View File

@@ -9,7 +9,7 @@ get:
go get github.com/fsnotify/fsnotify go get github.com/fsnotify/fsnotify
build: build:
go build -o bin/nwg-drawer . go build -v -o bin/nwg-drawer .
install: install:
-pkill -f nwg-drawer -pkill -f nwg-drawer

View File

@@ -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 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). 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 Below the grid there is the **power bar** - a row of buttons to lock the screen, exit the compositor, reboot, suspend
the machine off. For each button to appear, you need to provide a corresponding command. See "Command line arguments" and power the machine off. For each button to appear, you need to provide a corresponding command. See "Command line
below. arguments" below. If the power bar is present, pressing **Tab** will move focus to its first button.
<img src="https://github.com/nwg-piotr/nwg-drawer/assets/20579136/8f4eacb4-5395-4350-889b-a9037aa34f08" width=640 alt="screenshot"><br> <img src="https://github.com/nwg-piotr/nwg-drawer/assets/20579136/8f4eacb4-5395-4350-889b-a9037aa34f08" width=640 alt="screenshot"><br>
@@ -27,7 +27,7 @@ To close the window w/o running a program, you may use the `Esc` key, or right-c
### Dependencies ### Dependencies
- go >=1.20 (just to build) - go
- gtk3 - gtk3
- gtk-layer-shell - gtk-layer-shell
- xdg-utils - xdg-utils
@@ -51,7 +51,7 @@ confirmed to work well with the program. Also see **Files** below.
```text ```text
$ nwg-drawer -h $ nwg-drawer -h
Usage of /tmp/go-build3511850078/b001/exe/nwg-drawer: Usage of nwg-drawer:
-c uint -c uint
number of Columns (default 6) number of Columns (default 6)
-d Turn on Debug messages -d Turn on Debug messages

6
go.mod
View File

@@ -1,12 +1,12 @@
module github.com/nwg-piotr/nwg-drawer module github.com/nwg-piotr/nwg-drawer
go 1.21 go 1.22
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-20230802002603-b0c42cd8474f github.com/dlasky/gotk3-layershell v0.0.0-20230802002603-b0c42cd8474f
github.com/fsnotify/fsnotify v1.7.0 github.com/fsnotify/fsnotify v1.7.0
github.com/gotk3/gotk3 v0.6.2 github.com/gotk3/gotk3 v0.6.3
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
) )
@@ -15,5 +15,5 @@ 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.6.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
) )

4
go.sum
View File

@@ -14,6 +14,8 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT
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=
github.com/gotk3/gotk3 v0.6.3 h1:+Ke4WkM1TQUNOlM2TZH6szqknqo+zNbX3BZWVXjSHYw=
github.com/gotk3/gotk3 v0.6.3/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/joshuarubin/go-sway v1.2.0 h1:t3eqW504//uj9PDwFf0+IVfkD+WoOGaDX5gYIe0BHyM= github.com/joshuarubin/go-sway v1.2.0 h1:t3eqW504//uj9PDwFf0+IVfkD+WoOGaDX5gYIe0BHyM=
github.com/joshuarubin/go-sway v1.2.0/go.mod h1:qcDd6f25vJ0++wICwA1BainIcRC67p2Mb4lsrZ0k3/k= github.com/joshuarubin/go-sway v1.2.0/go.mod h1:qcDd6f25vJ0++wICwA1BainIcRC67p2Mb4lsrZ0k3/k=
github.com/joshuarubin/lifecycle v1.0.0/go.mod h1:sRy++ATvR9Ee21tkRdFkQeywAWvDsue66V70K0Dnl54= github.com/joshuarubin/lifecycle v1.0.0/go.mod h1:sRy++ATvR9Ee21tkRdFkQeywAWvDsue66V70K0Dnl54=
@@ -46,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.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= 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.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/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=

83
main.go
View File

@@ -21,17 +21,20 @@ import (
"github.com/gotk3/gotk3/gtk" "github.com/gotk3/gotk3/gtk"
) )
const version = "0.4.4" const version = "0.4.7"
var ( var (
appDirs []string appDirs []string
configDirectory string configDirectory string
dataDirectory string
pinnedFile string pinnedFile string
pinned []string pinned []string
id2entry map[string]desktopEntry id2entry map[string]desktopEntry
preferredApps map[string]interface{} preferredApps map[string]interface{}
exclusions []string exclusions []string
hyprlandMonitors []monitor hyprlandMonitors []monitor
beenScrolled bool
firstPowerBtn *gtk.Button
) )
var categoryNames = [...]string{ var categoryNames = [...]string{
@@ -233,7 +236,7 @@ func main() {
// Otherwise the command may behave in two ways: // Otherwise the command may behave in two ways:
// 1. kill the running non-residennt instance and exit; // 1. kill the running non-residennt instance and exit;
// 2. die if a resident instance found. // 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) lockFile, err := singleinstance.CreateLockFile(lockFilePath)
if err != nil { if err != nil {
pid, err := readTextFile(lockFilePath) pid, err := readTextFile(lockFilePath)
@@ -265,6 +268,7 @@ func main() {
// ENVIRONMENT // ENVIRONMENT
configDirectory = configDir() configDirectory = configDir()
dataDirectory = dataDir()
// Placing the drawer config files in the nwg-panel config directory was a mistake. // Placing the drawer config files in the nwg-panel config directory was a mistake.
// Let's move them to their own location. // Let's move them to their own location.
@@ -290,7 +294,7 @@ func main() {
// Copy default style sheet if not found // Copy default style sheet if not found
if !pathExists(filepath.Join(configDirectory, "drawer.css")) { 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 { if err != nil {
log.Errorf("Failed copying 'drawer.css' file: %s", err) log.Errorf("Failed copying 'drawer.css' file: %s", err)
} }
@@ -459,6 +463,10 @@ func main() {
} }
} }
return true return true
} else if key.KeyVal() == gdk.KEY_Tab {
if firstPowerBtn != nil {
firstPowerBtn.ToWidget().GrabFocus()
}
} }
return false return false
}) })
@@ -518,6 +526,18 @@ func main() {
resultWindow.SetEvents(int(gdk.ALL_EVENTS_MASK)) resultWindow.SetEvents(int(gdk.ALL_EVENTS_MASK))
resultWindow.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) resultWindow.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
// On touch screen we don't want the button-release-event to launch the app if the user just wanted to scroll the
// window. Let's forbid doing so if the content has been scrolled. We will reset the value on button-press-event.
// Resolves https://github.com/nwg-piotr/nwg-drawer/issues/110
vAdj := resultWindow.GetVAdjustment()
vAdj.Connect("value-changed", func() {
beenScrolled = true
})
hAdj := resultWindow.GetHAdjustment()
hAdj.Connect("value-changed", func() {
beenScrolled = true
})
resultWindow.Connect("button-release-event", func(_ *gtk.ScrolledWindow, event *gdk.Event) bool { resultWindow.Connect("button-release-event", func(_ *gtk.ScrolledWindow, event *gdk.Event) bool {
btnEvent := gdk.EventButtonNewFromEvent(event) btnEvent := gdk.EventButtonNewFromEvent(event)
if btnEvent.Button() == 3 { if btnEvent.Button() == 3 {
@@ -566,32 +586,41 @@ func main() {
} }
// Power Button Bar // Power Button Bar
if *pbExit != "" || *pbLock != "" || *pbPoweroff != "" || *pbReboot != "" || *pbSleep != "" { if dataDirectory != "" {
powerBarWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) if *pbExit != "" || *pbLock != "" || *pbPoweroff != "" || *pbReboot != "" || *pbSleep != "" {
outerVBox.PackStart(powerBarWrapper, false, false, 0) powerBarWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
powerButtonsWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) outerVBox.PackStart(powerBarWrapper, false, false, 0)
powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 12) powerButtonsWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
powerBarWrapper.PackStart(powerButtonsWrapper, true, false, 12)
if *pbLock != "" { if *pbPoweroff != "" {
btn := powerButton("/usr/share/nwg-drawer/img/lock.svg", *pbLock) btn := powerButton(filepath.Join(dataDirectory, "img/poweroff.svg"), *pbPoweroff)
powerButtonsWrapper.PackStart(btn, true, false, 0) powerButtonsWrapper.PackEnd(btn, true, false, 0)
} firstPowerBtn = btn
if *pbExit != "" { }
btn := powerButton("/usr/share/nwg-drawer/img/exit.svg", *pbExit) if *pbSleep != "" {
powerButtonsWrapper.PackStart(btn, true, false, 0) btn := powerButton(filepath.Join(dataDirectory, "img/sleep.svg"), *pbSleep)
} powerButtonsWrapper.PackEnd(btn, true, false, 0)
if *pbReboot != "" { firstPowerBtn = btn
btn := powerButton("/usr/share/nwg-drawer/img/reboot.svg", *pbReboot) }
powerButtonsWrapper.PackStart(btn, true, false, 0) if *pbReboot != "" {
} btn := powerButton(filepath.Join(dataDirectory, "img/reboot.svg"), *pbReboot)
if *pbSleep != "" { powerButtonsWrapper.PackEnd(btn, true, false, 0)
btn := powerButton("/usr/share/nwg-drawer/img/sleep.svg", *pbSleep) firstPowerBtn = btn
powerButtonsWrapper.PackStart(btn, true, false, 0) }
} if *pbExit != "" {
if *pbPoweroff != "" { btn := powerButton(filepath.Join(dataDirectory, "img/exit.svg"), *pbExit)
btn := powerButton("/usr/share/nwg-drawer/img/poweroff.svg", *pbPoweroff) powerButtonsWrapper.PackEnd(btn, true, false, 0)
powerButtonsWrapper.PackStart(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 {
log.Warn("Couldn't find data dir, power bar icons unavailable")
} }
statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)

View File

@@ -173,7 +173,7 @@ func configHome() string {
return path.Join(os.Getenv("HOME"), ".config") return path.Join(os.Getenv("HOME"), ".config")
} }
func dataDir() string { func dataHome() string {
var dir string var dir string
if xdgData := os.Getenv("XDG_DATA_HOME"); xdgData != "" { if xdgData := os.Getenv("XDG_DATA_HOME"); xdgData != "" {
dir = path.Join(xdgData, "nwg-drawer") dir = path.Join(xdgData, "nwg-drawer")
@@ -181,7 +181,7 @@ func dataDir() string {
dir = path.Join(home, ".local/share/nwg-drawer") dir = path.Join(home, ".local/share/nwg-drawer")
} }
log.Infof("Data dir: %s", dir) log.Infof("Data home: %s", dir)
createDir(dir) createDir(dir)
return dir return dir
@@ -197,7 +197,7 @@ func createDir(dir string) {
} }
func copyFile(src, dst string) error { func copyFile(src, dst string) error {
log.Infof("Copying file: %s", dst) log.Infof("Copying: '%s' => '%s'", src, dst)
var err error var err error
var srcfd *os.File var srcfd *os.File
@@ -233,6 +233,22 @@ func copyFile(src, dst string) error {
return os.Chmod(dst, srcinfo.Mode()) 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 { func getAppDirs() []string {
var dirs []string var dirs []string
@@ -321,9 +337,10 @@ func listDesktopFiles() []string {
func setUpCategories() { func setUpCategories() {
var other category var other category
dDir := dataDir()
for _, cName := range categoryNames { for _, cName := range categoryNames {
fileName := fmt.Sprintf("%s.directory", cName) fileName := fmt.Sprintf("%s.directory", cName)
fp := filepath.Join("/usr/share/nwg-drawer/desktop-directories", fileName) fp := filepath.Join(dDir, "desktop-directories", fileName)
lines, err := loadTextFile(fp) lines, err := loadTextFile(fp)
if err == nil { if err == nil {
var cat category var cat category

View File

@@ -264,11 +264,19 @@ func flowBoxButton(entry desktopEntry) *gtk.Button {
r := substring(desc, 0, 117) r := substring(desc, 0, 117)
desc = fmt.Sprintf("%s…", string(r)) desc = fmt.Sprintf("%s…", string(r))
} }
button.Connect("button-press-event", func() {
// if not scrolled from now on, we will allow launching apps on button-release-event
beenScrolled = false
})
button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool { button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool {
btnEvent := gdk.EventButtonNewFromEvent(e) btnEvent := gdk.EventButtonNewFromEvent(e)
if btnEvent.Button() == 1 { if btnEvent.Button() == 1 {
launch(exec, terminal) if !beenScrolled {
return true launch(exec, terminal)
return true
}
} else if btnEvent.Button() == 3 { } else if btnEvent.Button() == 3 {
pinItem(ID) pinItem(ID)
return true return true