diff --git a/main.go b/main.go index a3a6b1e..2fff258 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "syscall" + "time" log "github.com/sirupsen/logrus" @@ -21,7 +22,7 @@ import ( "github.com/gotk3/gotk3/gtk" ) -const version = "0.3.1" +const version = "0.3.2" type WindowState int @@ -46,6 +47,7 @@ var ( currentWsNum, targetWsNum int64 win *gtk.Window windowStateChannel chan WindowState = make(chan WindowState, 1) + detectorEnteredAt int64 ) // Flags @@ -65,6 +67,7 @@ var marginTop = flag.Int("mt", 0, "Margin Top") var marginLeft = flag.Int("ml", 0, "Margin Left") var marginRight = flag.Int("mr", 0, "Margin Right") var marginBottom = flag.Int("mb", 0, "Margin Bottom") +var hotspotDelay = flag.Int64("hd", 20, "Hotspot Delay [ms]; the smaller, the faster mouse pointer needs to enter hotspot for the dock to appear; set 0 to disable") var noWs = flag.Bool("nows", false, "don't show the workspace switcher") var noLauncher = flag.Bool("nolauncher", false, "don't show the launcher button") var resident = flag.Bool("r", false, "Leave the program resident, but w/o hotspot") @@ -255,23 +258,57 @@ func buildMainBox(tasks []task, vbox *gtk.Box) { func setupHotSpot(monitor gdk.Monitor, dockWindow *gtk.Window) gtk.Window { w, h := dockWindow.GetSize() - win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) layershell.InitForWindow(win) layershell.SetMonitor(win, &monitor) - box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) + var box *gtk.Box + if *position == "bottom" || *position == "top" { + box, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) + } else { + box, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) + } win.Add(box) - win.Connect("enter-notify-event", func() { + detectorBox, _ := gtk.EventBoxNew() + _ = detectorBox.SetProperty("name", "detector-box") + + if *position == "bottom" { + box.PackStart(detectorBox, false, false, 0) + } else { + box.PackEnd(detectorBox, false, false, 0) + } + + detectorBox.Connect("enter-notify-event", func() { + detectorEnteredAt = time.Now().UnixNano() / 1000000 + }) + + hotspotBox, _ := gtk.EventBoxNew() + _ = hotspotBox.SetProperty("name", "hotspot-box") + + if *position == "bottom" { + box.PackStart(hotspotBox, false, false, 0) + } else { + box.PackEnd(hotspotBox, false, false, 0) + } + + hotspotBox.Connect("enter-notify-event", func() { + hotspotEnteredAt := time.Now().UnixNano() / 1000000 + delay := hotspotEnteredAt - detectorEnteredAt layershell.SetMonitor(dockWindow, &monitor) - dockWindow.Hide() - dockWindow.Show() + if delay <= *hotspotDelay || *hotspotDelay == 0 { + log.Debugf("Delay %v < %v ms, let's show the window!", delay, *hotspotDelay) + dockWindow.Hide() + dockWindow.Show() + } else { + log.Debugf("Delay %v > %v ms, don't show the window :/", delay, *hotspotDelay) + } }) if *position == "bottom" || *position == "top" { - win.SetSizeRequest(w, 10) + detectorBox.SetSizeRequest(w, h/3) + hotspotBox.SetSizeRequest(w, 2) if *position == "bottom" { layershell.SetAnchor(win, layershell.LAYER_SHELL_EDGE_BOTTOM, true) } else { @@ -283,7 +320,8 @@ func setupHotSpot(monitor gdk.Monitor, dockWindow *gtk.Window) gtk.Window { } if *position == "left" { - win.SetSizeRequest(10, h) + detectorBox.SetSizeRequest(w/3, h) + hotspotBox.SetSizeRequest(2, h) layershell.SetAnchor(win, layershell.LAYER_SHELL_EDGE_LEFT, true) layershell.SetAnchor(win, layershell.LAYER_SHELL_EDGE_TOP, *full) @@ -370,7 +408,7 @@ func main() { if *autohide || *resident { log.Info("Running instance found, terminating...") } else { - syscall.Kill(i, syscall.SIGUSR1) + _ = syscall.Kill(i, syscall.SIGUSR1) log.Info("Sending SIGUSR1 to running instance and bye, bye!") } } @@ -524,7 +562,7 @@ func main() { }) outerBox, _ := gtk.BoxNew(outerOrientation, 0) - outerBox.SetProperty("name", "box") + _ = outerBox.SetProperty("name", "box") win.Add(outerBox) alignmentBox, _ := gtk.BoxNew(innerOrientation, 0)