Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to hyprlandctl #102

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var (
pinnedItemsChanged chan interface{} = make(chan interface{}, 1)
)

func defaultStringIfBlank(s, fallback string) string {
func defaultTermIfBlank(s, fallback string) string {
s = strings.TrimSpace(s)
// 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.
Expand All @@ -114,14 +114,19 @@ func defaultStringIfBlank(s, fallback string) string {
return s
}

func defaultBoolIfBlank(s string, fallback bool) bool {
func defaultStringIfBlank(s, fallback string) string {
s = strings.TrimSpace(s)
// 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.
if s != "sway" {
if s == "" {
return fallback
}
return true
return s
}

func validateWm() {
if !(*wm == "sway" || *wm == "hyprland") && *wm != "" {
*wm = ""
log.Warn("nwg-drawer support only `swaymsg` or `hyprland`.")
}
}

// Flags
Expand All @@ -143,8 +148,8 @@ var columnsNumber = flag.Uint("c", 6, "number of Columns")
var itemSpacing = flag.Uint("spacing", 20, "icon spacing")
var lang = flag.String("lang", "", "force lang, e.g. \"en\", \"pl\"")
var fileManager = flag.String("fm", "thunar", "File Manager")
var term = flag.String("term", defaultStringIfBlank(os.Getenv("TERM"), "foot"), "Terminal emulator")
var swaymsg = flag.Bool("swaymsg", defaultBoolIfBlank(os.Getenv("XDG_CURRENT_DESKTOP"), false), "Use swaymsg (sway only)")
var term = flag.String("term", defaultTermIfBlank(os.Getenv("TERM"), "foot"), "Terminal emulator")
var wm = flag.String("wm", defaultStringIfBlank(os.Getenv("XDG_CURRENT_DESKTOP"), ""), "Use swaymsg or hyprlandctl")
var nameLimit = flag.Int("fslen", 80, "File Search name LENgth Limit")
var noCats = flag.Bool("nocats", false, "Disable filtering by category")
var noFS = flag.Bool("nofs", false, "Disable file search")
Expand All @@ -164,6 +169,8 @@ func main() {
os.Exit(0)
}

validateWm()

// Gentle SIGTERM handler thanks to reiki4040 https://gist.github.com/reiki4040/be3705f307d3cd136e85
// v0.2: we also need to support SIGUSR from now on
showWindowChannel := make(chan interface{}, 1)
Expand Down
6 changes: 5 additions & 1 deletion tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,14 @@ func launch(command string, terminal bool) {
args = []string{elements[cmdIdx]}
}
cmd = exec.Command(prefixCommand, args...)
} else if *swaymsg {
} else if *wm == "sway" {
prefixCommand = "swaymsg"
args = []string{"exec", elements[cmdIdx]}
cmd = exec.Command(prefixCommand, args...)
} else if *wm == "hyprland" {
prefixCommand = "hyprlandctl"
args = []string{"dispatch", "exec", elements[cmdIdx]}
cmd = exec.Command(prefixCommand, args...)
}

// set env variables
Expand Down