5 Commits
0.6.0 ... main

Author SHA1 Message Date
85320215be remove search bar 2025-08-06 03:41:42 +02:00
f35903bfb7 allow for CUSTOM_DATA_DIRS variable 2025-08-05 03:58:33 +02:00
c8f8e27a65 only serach in custom director.
hide&wait for the program to exit.
2024-12-20 04:17:36 +01:00
Piotr Miller
4110554466 Merge pull request #141 from msmafra/patch-1
Update main.go
2024-12-14 00:56:03 +01:00
Marcelo dos Santos Mafra
7d1242d6ce Update main.go
Very little misspell
2024-12-13 16:37:34 -03:00
4 changed files with 64 additions and 45 deletions

43
main.go
View File

@@ -3,8 +3,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
"github.com/expr-lang/expr"
"os" "os"
"os/signal" "os/signal"
"path" "path"
@@ -14,6 +12,9 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
"github.com/expr-lang/expr"
"github.com/allan-simon/go-singleinstance" "github.com/allan-simon/go-singleinstance"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -112,10 +113,10 @@ var desktopEntries []desktopEntry
// UI elements // UI elements
var ( var (
win *gtk.Window win *gtk.Window
resultWindow *gtk.ScrolledWindow resultWindow *gtk.ScrolledWindow
fileSearchResults []string fileSearchResults []string
searchEntry *gtk.SearchEntry //searchEntry *gtk.SearchEntry
phrase string phrase string
fileSearchResultFlowBox *gtk.FlowBox fileSearchResultFlowBox *gtk.FlowBox
userDirsMap map[string]string userDirsMap map[string]string
@@ -472,10 +473,11 @@ func main() {
//key := &gdk.EventKey{Event: event} //key := &gdk.EventKey{Event: event}
key := event.AsKey() key := event.AsKey()
if key.Keyval() == gdk.KEY_Escape { if key.Keyval() == gdk.KEY_Escape {
s := searchEntry.Text() //s := searchEntry.Text()
s := ""
if s != "" { if s != "" {
searchEntry.GrabFocus() //searchEntry.GrabFocus()
searchEntry.SetText("") //searchEntry.SetText("")
} else { } else {
if !*resident { if !*resident {
gtk.MainQuit() gtk.MainQuit()
@@ -491,7 +493,8 @@ func main() {
} }
} else if key.Keyval() == gdk.KEY_Return { } else if key.Keyval() == gdk.KEY_Return {
s := searchEntry.Text() //s := searchEntry.Text()
s := ""
if s != "" { if s != "" {
// Check if the search box content is an arithmetic expression. If so, display the result // Check if the search box content is an arithmetic expression. If so, display the result
// and copy to the clipboard with wl-copy. // and copy to the clipboard with wl-copy.
@@ -515,9 +518,9 @@ func main() {
return false return false
default: default:
if !searchEntry.IsFocus() { //if !searchEntry.IsFocus() {
searchEntry.GrabFocusWithoutSelecting() // searchEntry.GrabFocusWithoutSelecting()
} //}
} }
return false return false
}) })
@@ -537,12 +540,12 @@ func main() {
outerVBox := gtk.NewBox(gtk.OrientationVertical, 0) outerVBox := gtk.NewBox(gtk.OrientationVertical, 0)
win.Add(outerVBox) win.Add(outerVBox)
searchBoxWrapper := gtk.NewBox(gtk.OrientationHorizontal, 0) //searchBoxWrapper := gtk.NewBox(gtk.OrientationHorizontal, 0)
outerVBox.PackStart(searchBoxWrapper, false, false, 10) //outerVBox.PackStart(searchBoxWrapper, false, false, 10)
searchEntry = setUpSearchEntry() //searchEntry = setUpSearchEntry()
searchEntry.SetMaxWidthChars(30) //searchEntry.SetMaxWidthChars(30)
searchBoxWrapper.PackStart(searchEntry, true, false, 0) //searchBoxWrapper.PackStart(searchEntry, true, false, 0)
if !*noCats { if !*noCats {
categoriesWrapper = gtk.NewBox(gtk.OrientationHorizontal, 0) categoriesWrapper = gtk.NewBox(gtk.OrientationHorizontal, 0)
@@ -771,7 +774,7 @@ func restoreStateAndHide() {
} }
// clear search // clear search
searchEntry.SetText("") //searchEntry.SetText("")
// One day or another we'll add SetFilterFunction here; it was impossible on the gotk3 library // One day or another we'll add SetFilterFunction here; it was impossible on the gotk3 library
appFlowBox = setUpAppsFlowBox(nil, "") appFlowBox = setUpAppsFlowBox(nil, "")
@@ -786,5 +789,5 @@ func restoreStateAndHide() {
} }
t := time.Now() t := time.Now()
log.Debugf(fmt.Sprintf("UI hidden and restored in the backgroud in %v ms", t.Sub(timeStart1).Milliseconds())) log.Debugf(fmt.Sprintf("UI hidden and restored in the background in %v ms", t.Sub(timeStart1).Milliseconds()))
} }

11
run_forever.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
# Infinite loop to run the command
while true; do
echo "Starting nwg-drawer..."
bin/nwg-drawer -nocats -nofs -ovl -d
done &
# Return immediately after starting the loop
echo "The loop is running in the background."

View File

@@ -5,8 +5,6 @@ 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" "net"
@@ -20,6 +18,9 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/joshuarubin/go-sway"
log "github.com/sirupsen/logrus"
"github.com/diamondburned/gotk4/pkg/gdk/v3" "github.com/diamondburned/gotk4/pkg/gdk/v3"
"github.com/diamondburned/gotk4/pkg/gdkpixbuf/v2" "github.com/diamondburned/gotk4/pkg/gdkpixbuf/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v3" "github.com/diamondburned/gotk4/pkg/gtk/v3"
@@ -250,35 +251,36 @@ func dataDir() string {
func getAppDirs() []string { func getAppDirs() []string {
var dirs []string var dirs []string
log.Info("App dirs::")
home := os.Getenv("HOME") home := os.Getenv("HOME")
xdgDataHome := os.Getenv("XDG_DATA_HOME") //xdgDataHome := os.Getenv("XDG_DATA_HOME")
xdgDataDirs := os.Getenv("XDG_DATA_DIRS") //xdgDataDirs := os.Getenv("XDG_DATA_DIRS")
if xdgDataDirs == "" {
xdgDataDirs = "/usr/local/share/:/usr/share/"
}
if xdgDataHome != "" {
dirs = append(dirs, filepath.Join(xdgDataHome, "applications"))
} else if home != "" {
dirs = append(dirs, filepath.Join(home, ".local/share/applications"))
}
for _, d := range strings.Split(xdgDataDirs, ":") {
dirs = append(dirs, filepath.Join(d, "applications"))
}
flatpakDirs := []string{filepath.Join(home, ".local/share/flatpak/exports/share/applications"),
"/var/lib/flatpak/exports/share/applications"}
for _, d := range flatpakDirs { custom := os.Getenv("CUSTOM_DATA_DIRS")
if pathExists(d) && !isIn(dirs, d) {
dirs = append(dirs, d) if home != "" {
if custom == "" {
dirs = append(dirs, filepath.Join(home, "/my_applications"))
} else {
dirs = append(dirs, filepath.Join(home, custom))
} }
}
}
log.Infof("App dirs: %v", dirs)
var confirmedDirs []string var confirmedDirs []string
for _, d := range dirs { for _, d := range dirs {
if pathExists(d) { if pathExists(d) {
confirmedDirs = append(confirmedDirs, d) confirmedDirs = append(confirmedDirs, d)
} }
} }
log.Infof("App dirs: %v", dirs)
return confirmedDirs return confirmedDirs
} }
@@ -625,7 +627,10 @@ func launch(command string, terminal bool, terminate bool) {
// Collect the exit code of the child process to prevent zombies // Collect the exit code of the child process to prevent zombies
// if the drawer runs in resident mode // if the drawer runs in resident mode
go func() { go func() {
restoreStateAndHide()
_ = cmd.Wait() _ = cmd.Wait()
gtk.MainQuit()
}() }()
} }
@@ -633,7 +638,6 @@ func launch(command string, terminal bool, terminate bool) {
if *resident { if *resident {
restoreStateAndHide() restoreStateAndHide()
} else { } else {
gtk.MainQuit()
} }
} }
} }

View File

@@ -2,11 +2,12 @@ package main
import ( import (
"fmt" "fmt"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
"io/fs" "io/fs"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/diamondburned/gotk4/pkg/gdk/v3" "github.com/diamondburned/gotk4/pkg/gdk/v3"
@@ -115,7 +116,7 @@ func setUpCategoriesButtonBox() *gtk.EventBox {
button := gtk.NewButtonWithLabel("All") button := gtk.NewButtonWithLabel("All")
button.SetObjectProperty("name", "category-button") button.SetObjectProperty("name", "category-button")
button.Connect("clicked", func(item *gtk.Button) { button.Connect("clicked", func(item *gtk.Button) {
searchEntry.SetText("") //searchEntry.SetText("")
appFlowBox = setUpAppsFlowBox(nil, "") appFlowBox = setUpAppsFlowBox(nil, "")
for _, btn := range catButtons { for _, btn := range catButtons {
btn.SetImagePosition(gtk.PosLeft) btn.SetImagePosition(gtk.PosLeft)
@@ -135,7 +136,7 @@ func setUpCategoriesButtonBox() *gtk.EventBox {
name := cat.Name name := cat.Name
b := *button b := *button
button.Connect("clicked", func(item *gtk.Button) { button.Connect("clicked", func(item *gtk.Button) {
searchEntry.SetText("") //searchEntry.SetText("")
// One day or another we'll add SetFilterFunction here; it was impossible on the gotk3 library // One day or another we'll add SetFilterFunction here; it was impossible on the gotk3 library
appFlowBox = setUpAppsFlowBox(lists[name], "") appFlowBox = setUpAppsFlowBox(lists[name], "")
for _, btn := range catButtons { for _, btn := range catButtons {