From 96bae751e415a59374570e1bd9c8995e23df5ba4 Mon Sep 17 00:00:00 2001 From: Cong Date: Tue, 9 Feb 2016 22:09:38 +1100 Subject: [PATCH] Prevent bogus mouse clicks on title bar (#169) --- src/cdogs/events.c | 10 +++++++++- src/cdogs/net_server.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cdogs/events.c b/src/cdogs/events.c index af74734dd..86998e7e5 100644 --- a/src/cdogs/events.c +++ b/src/cdogs/events.c @@ -1,7 +1,7 @@ /* C-Dogs SDL A port of the legendary (and fun) action/arcade cdogs. - Copyright (c) 2013-2015, Cong Xu + Copyright (c) 2013-2016, Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -72,6 +72,10 @@ void EventPoll(EventHandlers *handlers, Uint32 ticks) JoyPrePoll(&handlers->joysticks); SDL_free(handlers->DropFile); handlers->DropFile = NULL; + // Don't process mouse events if focus just regained this cycle + // This is to prevent bogus click events outside the window, e.g. in the + // title bar + bool regainedFocus = false; while (SDL_PollEvent(&e)) { switch (e.type) @@ -140,18 +144,22 @@ void EventPoll(EventHandlers *handlers, Uint32 ticks) break; case SDL_MOUSEBUTTONDOWN: + if (regainedFocus) break; MouseOnButtonDown(&handlers->mouse, e.button.button); break; case SDL_MOUSEBUTTONUP: + if (regainedFocus) break; MouseOnButtonUp(&handlers->mouse, e.button.button); break; case SDL_MOUSEWHEEL: + if (regainedFocus) break; MouseOnWheel(&handlers->mouse, e.wheel.x, e.wheel.y); break; case SDL_WINDOWEVENT: switch (e.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: + regainedFocus = true; MusicSetPlaying(&gSoundDevice, true); break; case SDL_WINDOWEVENT_FOCUS_LOST: diff --git a/src/cdogs/net_server.c b/src/cdogs/net_server.c index 58539ea34..f12a4e585 100644 --- a/src/cdogs/net_server.c +++ b/src/cdogs/net_server.c @@ -418,7 +418,7 @@ void NetServerSendGameStartMessages(NetServer *n, const int peerId) aa.TileItemFlags = a->tileItem.flags; aa.FullPos.x = a->Pos.x; aa.FullPos.y = a->Pos.y; - LOG(LM_NET, LL_DEBUG, "send add player UID(%d) playerUID(%d)", + LOG(LM_NET, LL_DEBUG, "send add actor UID(%d) playerUID(%d)", (int)aa.UID, (int)aa.PlayerUID); NetServerSendMsg(n, peerId, GAME_EVENT_ACTOR_ADD, &aa); CA_FOREACH_END()