Skip to content

Commit

Permalink
fix bug when walking against a KDE panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanb committed Oct 4, 2023
1 parent a060156 commit 4d336f6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion states.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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
}
}

0 comments on commit 4d336f6

Please sign in to comment.