Separated event handling from positioning logic to allow easier customization.