The International Simutrans Forum

 

Author Topic: Fix window focus/unfocus events on SDL2  (Read 1895 times)

0 Members and 1 Guest are viewing this topic.

Offline ArthurDenture

  • Coder/patcher
  • *
  • Posts: 86
Fix window focus/unfocus events on SDL2
« on: October 27, 2013, 08:24:27 PM »
I built the SDL2 backend at head and noticed that every time I moved the mouse out of the Simutrans window, the current open dialog closed.

It turned out that r6702 ("ADD: loading gui themes on runtime") added a new "#define SYSTEM_RELOAD_WINDOWS 3" to simevent.h for a custom reload-theme event, which conflicted with the existing "#define SIM_SYSTEM_UPDATE 3" in simsys.h. SDL1 didn't notice anything b/c that event turns out to seemingly never get fired, but SDL2 was firing that event when the game window was focused or unfocused.

There was a comment on simevent.h warning about the duplicate event definitions, but even better than having to notice the comment is simply to make the code safe by eliminating the duplication. So I got rid of the defines in simsys.h and replaced their usages with the ones from simevent.h. As for the conflicting SIM_SYSTEM_UPDATE event, it was never used for anything, I went ahead and just ripped it out, getting rid of all of the SDL event handling that could have generated it.

Patch is attached.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Fix window focus/unfocus events on SDL2
« Reply #1 on: October 27, 2013, 10:38:28 PM »
Added by prissi in 6867.

Offline Max-Max

  • Coder/patcher
  • *
  • Posts: 670
    • MK Development
  • Languages: SV,EN
Re: Fix window focus/unfocus events on SDL2
« Reply #2 on: October 27, 2013, 11:19:32 PM »
Hmm, shouldn't those defines be an enum? Then it would be more natural to seek out the enum list when adding new messages.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5695
  • Languages: EN, NO
Re: Fix window focus/unfocus events on SDL2
« Reply #3 on: October 28, 2013, 05:09:44 PM »
Hmm, shouldn't those defines be an enum? Then it would be more natural to seek out the enum list when adding new messages.

I thought the same. One thing that may rule out an enum is if some backends need som internal event types.