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 (
"flag"
"fmt"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
"github.com/expr-lang/expr"
"os"
"os/signal"
"path"
@@ -14,6 +12,9 @@ import (
"syscall"
"time"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
"github.com/expr-lang/expr"
"github.com/allan-simon/go-singleinstance"
log "github.com/sirupsen/logrus"
@@ -112,10 +113,10 @@ var desktopEntries []desktopEntry
// UI elements
var (
win *gtk.Window
resultWindow *gtk.ScrolledWindow
fileSearchResults []string
searchEntry *gtk.SearchEntry
win *gtk.Window
resultWindow *gtk.ScrolledWindow
fileSearchResults []string
//searchEntry *gtk.SearchEntry
phrase string
fileSearchResultFlowBox *gtk.FlowBox
userDirsMap map[string]string
@@ -472,10 +473,11 @@ func main() {
//key := &gdk.EventKey{Event: event}
key := event.AsKey()
if key.Keyval() == gdk.KEY_Escape {
s := searchEntry.Text()
//s := searchEntry.Text()
s := ""
if s != "" {
searchEntry.GrabFocus()
searchEntry.SetText("")
//searchEntry.GrabFocus()
//searchEntry.SetText("")
} else {
if !*resident {
gtk.MainQuit()
@@ -491,7 +493,8 @@ func main() {
}
} else if key.Keyval() == gdk.KEY_Return {
s := searchEntry.Text()
//s := searchEntry.Text()
s := ""
if s != "" {
// Check if the search box content is an arithmetic expression. If so, display the result
// and copy to the clipboard with wl-copy.
@@ -515,9 +518,9 @@ func main() {
return false
default:
if !searchEntry.IsFocus() {
searchEntry.GrabFocusWithoutSelecting()
}
//if !searchEntry.IsFocus() {
// searchEntry.GrabFocusWithoutSelecting()
//}
}
return false
})
@@ -537,12 +540,12 @@ func main() {
outerVBox := gtk.NewBox(gtk.OrientationVertical, 0)
win.Add(outerVBox)
searchBoxWrapper := gtk.NewBox(gtk.OrientationHorizontal, 0)
outerVBox.PackStart(searchBoxWrapper, false, false, 10)
//searchBoxWrapper := gtk.NewBox(gtk.OrientationHorizontal, 0)
//outerVBox.PackStart(searchBoxWrapper, false, false, 10)
searchEntry = setUpSearchEntry()
searchEntry.SetMaxWidthChars(30)
searchBoxWrapper.PackStart(searchEntry, true, false, 0)
//searchEntry = setUpSearchEntry()
//searchEntry.SetMaxWidthChars(30)
//searchBoxWrapper.PackStart(searchEntry, true, false, 0)
if !*noCats {
categoriesWrapper = gtk.NewBox(gtk.OrientationHorizontal, 0)
@@ -771,7 +774,7 @@ func restoreStateAndHide() {
}
// clear search
searchEntry.SetText("")
//searchEntry.SetText("")
// One day or another we'll add SetFilterFunction here; it was impossible on the gotk3 library
appFlowBox = setUpAppsFlowBox(nil, "")
@@ -786,5 +789,5 @@ func restoreStateAndHide() {
}
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"
"errors"
"fmt"
"github.com/joshuarubin/go-sway"
log "github.com/sirupsen/logrus"
"io"
"io/fs"
"net"
@@ -20,6 +18,9 @@ import (
"syscall"
"time"
"github.com/joshuarubin/go-sway"
log "github.com/sirupsen/logrus"
"github.com/diamondburned/gotk4/pkg/gdk/v3"
"github.com/diamondburned/gotk4/pkg/gdkpixbuf/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v3"
@@ -250,35 +251,36 @@ func dataDir() string {
func getAppDirs() []string {
var dirs []string
log.Info("App dirs::")
home := os.Getenv("HOME")
xdgDataHome := os.Getenv("XDG_DATA_HOME")
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"}
//xdgDataHome := os.Getenv("XDG_DATA_HOME")
//xdgDataDirs := os.Getenv("XDG_DATA_DIRS")
for _, d := range flatpakDirs {
if pathExists(d) && !isIn(dirs, d) {
dirs = append(dirs, d)
custom := os.Getenv("CUSTOM_DATA_DIRS")
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
for _, d := range dirs {
if pathExists(d) {
confirmedDirs = append(confirmedDirs, d)
}
}
log.Infof("App dirs: %v", dirs)
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
// if the drawer runs in resident mode
go func() {
restoreStateAndHide()
_ = cmd.Wait()
gtk.MainQuit()
}()
}
@@ -633,7 +638,6 @@ func launch(command string, terminal bool, terminate bool) {
if *resident {
restoreStateAndHide()
} else {
gtk.MainQuit()
}
}
}

View File

@@ -2,11 +2,12 @@ package main
import (
"fmt"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
"io/fs"
"path/filepath"
"strings"
"github.com/diamondburned/gotk4-layer-shell/pkg/gtklayershell"
log "github.com/sirupsen/logrus"
"github.com/diamondburned/gotk4/pkg/gdk/v3"
@@ -115,7 +116,7 @@ func setUpCategoriesButtonBox() *gtk.EventBox {
button := gtk.NewButtonWithLabel("All")
button.SetObjectProperty("name", "category-button")
button.Connect("clicked", func(item *gtk.Button) {
searchEntry.SetText("")
//searchEntry.SetText("")
appFlowBox = setUpAppsFlowBox(nil, "")
for _, btn := range catButtons {
btn.SetImagePosition(gtk.PosLeft)
@@ -135,7 +136,7 @@ func setUpCategoriesButtonBox() *gtk.EventBox {
name := cat.Name
b := *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
appFlowBox = setUpAppsFlowBox(lists[name], "")
for _, btn := range catButtons {