Skip to content

Commit

Permalink
Prevent bogus mouse clicks on title bar (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 9, 2016
1 parent a717be1 commit 96bae75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/cdogs/events.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/net_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 96bae75

Please sign in to comment.