From 4d336f64a298976fa0563955ef8040431a0eeec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nh=C3=A2n?= Date: Wed, 4 Oct 2023 17:54:01 +0700 Subject: [PATCH] fix bug when walking against a KDE panel --- states.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/states.go b/states.go index 3d2e248..76d0233 100644 --- a/states.go +++ b/states.go @@ -133,7 +133,9 @@ func (s *StateDrag) Update(sm *StateMachine) { } s.PreviousMousePos = mousePos } -func (s *StateDrag) EndAnimHook(sm *StateMachine) {} +func (s *StateDrag) EndAnimHook(sm *StateMachine) { + syncWinPos(sm) +} type StateRClick struct{} @@ -217,7 +219,24 @@ func (s *StateWalk) Update(sm *StateMachine) { } } func (s *StateWalk) EndAnimHook(sm *StateMachine) { + // On KDE, our window isn't allowed to walk over a vertical taskbar + // ("panel" in KDE parlance), so when gura walks agains a taskbar, the + // in-game position (sm.x) will get out of sync with the actual window + // position. Therefore, we must run a sync: + syncWinPos(sm) + if randBool(StopChance) { sm.SetState(&StateIdle{}) } } + +// Sometimes the sm.x/y doesn't match the window's actual position on screen. +// Run this at the end of States that might end up in that situation. +func syncWinPos(sm *StateMachine) { + actualX, actualY := ebiten.WindowPosition() + if actualX != sm.x || actualY != sm.y { + //fmt.Printf("ingame: %d,%d - actual: %d,%d\n", sm.x, sm.y, actualX, actualY) + sm.x = actualX + sm.y = actualY + } +}