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

Detect pointer speed to determine if to show up auto-hidden dock #31

Merged
merged 6 commits into from
Nov 15, 2022
Merged
Changes from all commits
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
58 changes: 48 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"syscall"
"time"

log "github.com/sirupsen/logrus"

Expand All @@ -21,7 +22,7 @@ import (
"github.com/gotk3/gotk3/gtk"
)

const version = "0.3.1"
const version = "0.3.2"

type WindowState int

Expand All @@ -46,6 +47,7 @@ var (
currentWsNum, targetWsNum int64
win *gtk.Window
windowStateChannel chan WindowState = make(chan WindowState, 1)
detectorEnteredAt int64
)

// Flags
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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!")
}
}
Expand Down Expand Up @@ -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)
Expand Down