From 04a04c1417087a219ab5816df9aced436b9fa6fb Mon Sep 17 00:00:00 2001 From: Zijia Xiong Date: Thu, 13 Jun 2024 19:09:33 +0100 Subject: [PATCH 1/6] Add -close and -open options. --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.go b/main.go index f392bbf..3579a4a 100644 --- a/main.go +++ b/main.go @@ -155,6 +155,8 @@ var targetOutput = flag.String("o", "", "name of the Output to display the drawe var displayVersion = flag.Bool("v", false, "display Version information") var keyboard = flag.Bool("k", false, "set GTK layer shell Keyboard interactivity to 'on-demand' mode") var overlay = flag.Bool("ovl", false, "use OVerLay layer") +var flagDrawerOpen = flag.Bool("open", false, "open drawer on startup") +var flagDrawerClose = flag.Bool("close", false, "close drawer on startup") var gtkTheme = flag.String("g", "", "GTK theme name") var gtkIconTheme = flag.String("i", "", "GTK icon theme name") var iconSize = flag.Int("is", 64, "Icon Size") @@ -245,8 +247,16 @@ func main() { if err == nil { if *resident { log.Warnf("Resident instance already running (PID %v)", i) + if *flagDrawerClose { + log.Infof("-close is set, ignore showing the running instance") + return + } } else { log.Infof("Showing resident instance (PID %v)", i) + if *flagDrawerOpen { + log.Infof("-open is set, ignore killing the running instance") + return + } err := syscall.Kill(i, syscall.SIGUSR1) if err != nil { return From 3fb70fc0cb1fb9325ef2c308295b59099f174015 Mon Sep 17 00:00:00 2001 From: Zijia Xiong Date: Thu, 13 Jun 2024 23:30:58 +0100 Subject: [PATCH 2/6] Fix bug of -open and -close --- main.go | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 3579a4a..116e19b 100644 --- a/main.go +++ b/main.go @@ -155,8 +155,8 @@ var targetOutput = flag.String("o", "", "name of the Output to display the drawe var displayVersion = flag.Bool("v", false, "display Version information") var keyboard = flag.Bool("k", false, "set GTK layer shell Keyboard interactivity to 'on-demand' mode") var overlay = flag.Bool("ovl", false, "use OVerLay layer") -var flagDrawerOpen = flag.Bool("open", false, "open drawer on startup") -var flagDrawerClose = flag.Bool("close", false, "close drawer on startup") +var flagDrawerOpen = flag.Bool("open", false, "open drawer of existing instance") +var flagDrawerClose = flag.Bool("close", false, "close drawer of existing instance") var gtkTheme = flag.String("g", "", "GTK theme name") var gtkIconTheme = flag.String("i", "", "GTK icon theme name") var iconSize = flag.Int("is", 64, "Icon Size") @@ -203,7 +203,7 @@ func main() { // v0.2: we also need to support SIGUSR from now on showWindowChannel := make(chan interface{}, 1) signalChan := make(chan os.Signal, 1) - signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGUSR1) + signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGINT) go func() { for { @@ -212,7 +212,8 @@ func main() { case syscall.SIGTERM: log.Info("SIGTERM received, bye bye") gtk.MainQuit() - case syscall.SIGUSR1: + break + case syscall.SIGUSR1: // toggle drawer if *resident { // As win.Show() called from inside a goroutine randomly crashes GTK, // let's just set e helper variable here. We'll be checking it with glib.TimeoutAdd. @@ -224,7 +225,23 @@ func main() { restoreStateAndHide() } } else { - log.Info("SIGUSR1 received, and I'm not resident, bye bye") + log.Info("A signal received, and I'm not resident, bye bye") + gtk.MainQuit() + } + case syscall.SIGUSR2: // open drawer + if *resident { + log.Debug("SIGUSR2 received, showing the window") + showWindowChannel <- struct{}{} + } else { + log.Info("A signal received, and I'm not resident, bye bye") + gtk.MainQuit() + } + case syscall.SIGINT: // colse drawer + if *resident { + log.Debug("SIGINT received, hiding the window") + restoreStateAndHide() + } else { + log.Info("A signal received, and I'm not resident, bye bye") gtk.MainQuit() } default: @@ -247,17 +264,18 @@ func main() { if err == nil { if *resident { log.Warnf("Resident instance already running (PID %v)", i) - if *flagDrawerClose { - log.Infof("-close is set, ignore showing the running instance") - return - } } else { - log.Infof("Showing resident instance (PID %v)", i) - if *flagDrawerOpen { - log.Infof("-open is set, ignore killing the running instance") - return - } - err := syscall.Kill(i, syscall.SIGUSR1) + var err error + if *flagDrawerClose { + log.Infof("Closing resident instance (PID %v)", i) + err = syscall.Kill(i, syscall.SIGINT) + } else if *flagDrawerOpen { + log.Infof("Showing resident instance (PID %v)", i) + err = syscall.Kill(i, syscall.SIGUSR2) + } else { + log.Infof("Togging resident instance (PID %v)", i) + err = syscall.Kill(i, syscall.SIGUSR1) + } if err != nil { return } @@ -484,7 +502,7 @@ func main() { win.Connect("key-press-event", func(_ *gtk.Window, event *gdk.Event) bool { key := &gdk.EventKey{Event: event} switch key.KeyVal() { - case gdk.KEY_downarrow, gdk.KEY_Up, gdk.KEY_Down, gdk.KEY_Left, gdk.KEY_Right, gdk.KEY_Tab, + case gdk.KEY_downarrow, gdk.KEY_Up, gdk.KEY_Down, gdk.KEY_Left, gdk.KEY_Right, gdk.KEY_Tab, gdk.KEY_Return, gdk.KEY_Page_Up, gdk.KEY_Page_Down, gdk.KEY_Home, gdk.KEY_End: return false @@ -497,9 +515,9 @@ func main() { }) /* - In case someone REALLY needed to use X11 - for some stupid Zoom meeting or something, this allows - the drawer to behave properly on Openbox, and possibly somewhere else. For sure not on i3. - This feature is not really supported and will stay undocumented. + In case someone REALLY needed to use X11 - for some stupid Zoom meeting or something, this allows + the drawer to behave properly on Openbox, and possibly somewhere else. For sure not on i3. + This feature is not really supported and will stay undocumented. */ if !wayland() { log.Info("Not Wayland, oh really?") From 99765402d7348f469a840913055da0f224ecbdc3 Mon Sep 17 00:00:00 2001 From: Zijia Xiong Date: Fri, 14 Jun 2024 00:48:10 +0100 Subject: [PATCH 3/6] Change usage of SIGINT to SIGRTMIN+3 --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 116e19b..345534d 100644 --- a/main.go +++ b/main.go @@ -203,8 +203,10 @@ func main() { // v0.2: we also need to support SIGUSR from now on showWindowChannel := make(chan interface{}, 1) signalChan := make(chan os.Signal, 1) - signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGINT) - + const ( + SIG25 = syscall.Signal(0x25) // Which is SIGRTMIN+3 on Linux, it's not used by the system + ) + signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2, SIG25) go func() { for { s := <-signalChan @@ -212,7 +214,6 @@ func main() { case syscall.SIGTERM: log.Info("SIGTERM received, bye bye") gtk.MainQuit() - break case syscall.SIGUSR1: // toggle drawer if *resident { // As win.Show() called from inside a goroutine randomly crashes GTK, @@ -236,9 +237,9 @@ func main() { log.Info("A signal received, and I'm not resident, bye bye") gtk.MainQuit() } - case syscall.SIGINT: // colse drawer + case SIG25: // colse drawer if *resident { - log.Debug("SIGINT received, hiding the window") + log.Debug("SIG25 received, hiding the window") restoreStateAndHide() } else { log.Info("A signal received, and I'm not resident, bye bye") @@ -268,7 +269,7 @@ func main() { var err error if *flagDrawerClose { log.Infof("Closing resident instance (PID %v)", i) - err = syscall.Kill(i, syscall.SIGINT) + err = syscall.Kill(i, SIG25) } else if *flagDrawerOpen { log.Infof("Showing resident instance (PID %v)", i) err = syscall.Kill(i, syscall.SIGUSR2) From 69e3b06b39563b0c7842c56d363d7da2118d38af Mon Sep 17 00:00:00 2001 From: RRRRRm Date: Sun, 16 Jun 2024 18:35:01 +0100 Subject: [PATCH 4/6] Update README.md, Add some information about new flags `-open` and `-close` --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d9fe8f..a10d130 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ $ nwg-drawer -h Usage of nwg-drawer: -c uint number of Columns (default 6) + -close + close drawer of existing instance -d Turn on Debug messages -fm string File Manager (default "thunar") @@ -86,6 +88,8 @@ Usage of nwg-drawer: Disable file search -o string name of the Output to display the drawer on (sway & Hyprland only) + -open + open drawer of existing instance -ovl use OVerLay layer -pbexit string @@ -106,7 +110,7 @@ Usage of nwg-drawer: -spacing uint icon spacing (default 20) -term string - Terminal emulator (default "foot") + Terminal emulator (default "xterm-kitty") -v display Version information -wm string use swaymsg exec (with 'sway' argument) or hyprctl dispatch exec (with 'hyprland') to launch programs @@ -137,6 +141,15 @@ this should be a little bit faster. Running a resident instance should speed up use of the drawer significantly. Pay attention to the fact, that you need to `pkill -f nwg-drawer` and reload the compositor to apply any new arguments! +If you want to explicitly specify commands to open and close the resident instance, which can be helpful for touchpad gestures, please use the `-open` and `-close` parameters. Similarly, some signals can also be use: pkill -USR2 nwg-drawer to open and pkill -SIGRTMIN+3 nwg-drawer to close. + +For a MacOS-style three-finger pinch: + +```text +bindgesture pinch:4:inward exec pkill -SIGUSR2 nwg-drawer +bindgesture pinch:4:outward exec pkill -SIGRTMIN+3 nwg-drawer +``` + ## Logging In case you encounter an issue, you may need debug messages. If you use the resident instance, you'll see nothing From 008f31278dd44cc8a3c308f54e1fdb36009ab000 Mon Sep 17 00:00:00 2001 From: Zijia Xiong Date: Sun, 16 Jun 2024 19:01:26 +0100 Subject: [PATCH 5/6] Fix logic about receive signals --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 345534d..a001ae4 100644 --- a/main.go +++ b/main.go @@ -226,7 +226,7 @@ func main() { restoreStateAndHide() } } else { - log.Info("A signal received, and I'm not resident, bye bye") + log.Info("SIGUSR1 received, and I'm not resident, bye bye") gtk.MainQuit() } case syscall.SIGUSR2: // open drawer @@ -234,13 +234,14 @@ func main() { log.Debug("SIGUSR2 received, showing the window") showWindowChannel <- struct{}{} } else { - log.Info("A signal received, and I'm not resident, bye bye") - gtk.MainQuit() + log.Info("SIGUSR2 received, and I'm not resident but I'm still here, doing nothing") } case SIG25: // colse drawer - if *resident { - log.Debug("SIG25 received, hiding the window") - restoreStateAndHide() + if *resident { + log.Debug("SIG25 received, hiding the window") + if win.IsVisible() { + restoreStateAndHide() + } } else { log.Info("A signal received, and I'm not resident, bye bye") gtk.MainQuit() From 6649dcefdb060031a0b2d4b208331ccaefc681ce Mon Sep 17 00:00:00 2001 From: RRRRRm Date: Mon, 17 Jun 2024 00:31:52 +0100 Subject: [PATCH 6/6] Correct the default terminal --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a10d130..aa6a576 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Usage of nwg-drawer: -spacing uint icon spacing (default 20) -term string - Terminal emulator (default "xterm-kitty") + Terminal emulator (default "foot") -v display Version information -wm string use swaymsg exec (with 'sway' argument) or hyprctl dispatch exec (with 'hyprland') to launch programs