GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/eventsmanager.cpp Lines: 9 290 3.1 %
Date: 2017-11-29 Branches: 2 129 1.6 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "eventsmanager.h"
22
23
#include "configuration.h"
24
#include "client.h"
25
#ifndef DYECMD
26
#include "game.h"
27
#endif  // DYECMD
28
#ifdef USE_MUMBLE
29
#include "mumblemanager.h"
30
#endif  // USE_MUMBLE
31
#include "sdlshared.h"
32
#include "settings.h"
33
34
#include "gui/windowmanager.h"
35
36
#include "being/localplayer.h"
37
38
#include "input/inputmanager.h"
39
40
#ifdef USE_SDL2
41
#include "render/graphics.h"
42
#else  // USE_SDL2
43
#include "logger.h"
44
#endif  // USE_SDL2
45
46
#include "utils/process.h"
47
#include "utils/sdlhelper.h"
48
#ifdef USE_X11
49
#include "utils/x11logger.h"
50
#endif  // USE_X11
51
52
#include "debug.h"
53
54
2
EventsManager eventsManager;
55
56
2
EventsManager::EventsManager() :
57
    ConfigListener(),
58
4
    mLogInput(false)
59
{
60
}
61
62
2
EventsManager::~EventsManager()
63
{
64
    CHECKLISTENERS
65
2
}
66
67
void EventsManager::init()
68
{
69
    mLogInput = config.getBoolValue("logInput");
70
    config.addListener("logInput", this);
71
}
72
73
void EventsManager::enableEvents()
74
{
75
    // disable unused SDL events
76
#ifndef USE_SDL2
77
    SDL_EventState(SDL_VIDEOEXPOSE, SDL_IGNORE);
78
#endif  // USE_SDL2
79
80
    SDL_EventState(SDL_SYSWMEVENT, mLogInput ? SDL_ENABLE : SDL_IGNORE);
81
    SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
82
}
83
84
362
void EventsManager::shutdown()
85
{
86
362
    config.removeListeners(this);
87
362
}
88
89
bool EventsManager::handleCommonEvents(const SDL_Event &event) const
90
{
91
    BLOCK_START("EventsManager::handleCommonEvents")
92
    if (mLogInput)
93
        logEvent(event);
94
95
    switch (event.type)
96
    {
97
        case SDL_QUIT:
98
            client->setState(State::EXIT);
99
            logger->log1("force exit");
100
            BLOCK_END("EventsManager::handleCommonEvents")
101
            return true;
102
#ifdef USE_SDL2
103
        case SDL_WINDOWEVENT:
104
            handleSDL2WindowEvent(event);
105
            BLOCK_END("EventsManager::handleCommonEvents")
106
            return true;
107
#else  // USE_SDL2
108
        case SDL_VIDEORESIZE:
109
            WindowManager::resizeVideo(event.resize.w,
110
                event.resize.h,
111
                false);
112
            BLOCK_END("EventsManager::handleCommonEvents")
113
            return true;
114
        case SDL_ACTIVEEVENT:
115
            handleActive(event);
116
            BLOCK_END("EventsManager::handleCommonEvents")
117
            return true;
118
#ifdef ANDROID
119
        case SDL_KEYBOARDSHOW:
120
            WindowManager::updateScreenKeyboard(event.user.code);
121
            BLOCK_END("EventsManager::handleCommonEvents")
122
            return true;
123
        case SDL_ACCELEROMETER:
124
            break;
125
#endif  // ANDROID
126
#endif  // USE_SDL2
127
        default:
128
            break;
129
    }
130
131
    if (inputManager.handleEvent(event))
132
    {
133
        BLOCK_END("EventsManager::handleCommonEvents")
134
        return true;
135
    }
136
137
    BLOCK_END("EventsManager::handleCommonEvents")
138
    return false;
139
}
140
141
bool EventsManager::handleEvents() const
142
{
143
    BLOCK_START("EventsManager::handleEvents")
144
#ifndef DYECMD
145
    if (Game::instance() != nullptr)
146
    {
147
        // Let the game handle the events while it is active
148
        Game::instance()->handleInput();
149
    }
150
    else
151
#endif  // DYECMD
152
    {
153
        SDL_Event event;
154
        // Handle SDL events
155
        while (SDL::PollEvent(&event))
156
        {
157
            if (!handleCommonEvents(event))
158
            {
159
                switch (event.type)
160
                {
161
#ifdef ANDROID
162
#ifndef USE_SDL2
163
                    case SDL_ACTIVEEVENT:
164
                        if ((event.active.state & SDL_APPACTIVE)
165
                            && !event.active.gain)
166
                        {
167
                            client->setState(State::EXIT);
168
                            logger->log1("exit on lost focus");
169
                        }
170
                        break;
171
172
#endif  // USE_SDL2
173
#endif  // ANDROID
174
                    default:
175
                        break;
176
                }
177
            }
178
179
#ifdef USE_MUMBLE
180
            if (localPlayer && mumbleManager)
181
            {
182
                mumbleManager->setPos(localPlayer->getTileX(),
183
                    localPlayer->getTileY(), localPlayer->getDirection());
184
            }
185
#endif  // USE_MUMBLE
186
        }
187
        if (client->getState() == State::EXIT)
188
        {
189
            BLOCK_END("EventsManager::handleEvents")
190
            return true;
191
        }
192
    }
193
    BLOCK_END("EventsManager::handleEvents")
194
    return false;
195
}
196
197
void EventsManager::handleGameEvents() const
198
{
199
    BLOCK_START("EventsManager::handleGameEvents")
200
#ifndef DYECMD
201
    Game *const game = Game::instance();
202
203
    // Events
204
    SDL_Event event;
205
    while (SDL::PollEvent(&event))
206
    {
207
        if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
208
            game->updateHistory(event);
209
        game->checkKeys();
210
211
        if (handleCommonEvents(event))
212
            break;
213
    }  // End while
214
#endif  // DYECMD
215
216
    BLOCK_END("EventsManager::handleGameEvents")
217
}
218
219
void EventsManager::optionChanged(const std::string &name)
220
{
221
    if (name == "logInput")
222
        mLogInput = config.getBoolValue("logInput");
223
}
224
225
void EventsManager::logEvent(const SDL_Event &event)
226
{
227
    switch (event.type)
228
    {
229
#ifdef USE_SDL2
230
#define winEventLog(name, name2) \
231
    case name: \
232
        str = name2; \
233
        break
234
235
        case SDL_MOUSEMOTION:
236
            logger->log("event: SDL_MOUSEMOTION: %u, %d,%d, %d,%d",
237
                event.motion.state,
238
                event.motion.x,
239
                event.motion.y,
240
                event.motion.xrel,
241
                event.motion.yrel);
242
            break;
243
        case SDL_FINGERDOWN:
244
        {
245
            const SDL_TouchFingerEvent &touch = event.tfinger;
246
            const int w = mainGraphics->mWidth;
247
            const int h = mainGraphics->mHeight;
248
            logger->log("event: SDL_FINGERDOWN: %u,%u (%f,%f) (%f,%f) %f",
249
                CAST_U32(touch.touchId),
250
                CAST_U32(touch.fingerId),
251
                touch.x * w, touch.y * w,
252
                touch.dx * w, touch.dy * h,
253
                touch.pressure);
254
            break;
255
        }
256
        case SDL_FINGERUP:
257
        {
258
            const SDL_TouchFingerEvent &touch = event.tfinger;
259
            const int w = mainGraphics->mWidth;
260
            const int h = mainGraphics->mHeight;
261
            logger->log("event: SDL_FINGERUP: %u,%u (%f,%f) (%f,%f) %f",
262
                CAST_U32(touch.touchId),
263
                CAST_U32(touch.fingerId),
264
                touch.x * w, touch.y * w,
265
                touch.dx * w, touch.dy * h,
266
                touch.pressure);
267
            break;
268
        }
269
        case SDL_FINGERMOTION:
270
        {
271
            const SDL_TouchFingerEvent &touch = event.tfinger;
272
            const int w = mainGraphics->mWidth;
273
            const int h = mainGraphics->mHeight;
274
            logger->log("event: SDL_FINGERMOTION: %u,%u (%f,%f) (%f,%f) %f",
275
                CAST_U32(touch.touchId),
276
                CAST_U32(touch.fingerId),
277
                touch.x * w, touch.y * h,
278
                touch.dx * w, touch.dy * h,
279
                touch.pressure);
280
            break;
281
        }
282
        case SDL_MULTIGESTURE:
283
        {
284
            const SDL_MultiGestureEvent &gesture = event.mgesture;
285
            const int w = mainGraphics->mWidth;
286
            const int h = mainGraphics->mHeight;
287
            logger->log("event: SDL_MULTIGESTURE: %u %f,%f (%f,%f) %d",
288
                CAST_U32(gesture.touchId),
289
                gesture.dTheta, gesture.dDist,
290
                gesture.x * w, gesture.y * h,
291
                CAST_S32(gesture.numFingers));
292
            break;
293
        }
294
        case SDL_KEYDOWN:
295
            logger->log("event: SDL_KEYDOWN: %s(%d) %s(%d) %d,%d,%u",
296
                SDL_GetScancodeName(event.key.keysym.scancode),
297
                event.key.keysym.scancode,
298
                SDL_GetKeyName(event.key.keysym.sym),
299
                event.key.keysym.sym,
300
                event.key.state,
301
                event.key.repeat,
302
                CAST_U32(event.key.keysym.mod));
303
            break;
304
        case SDL_KEYUP:
305
            logger->log("event: SDL_KEYUP: %s(%d) %s(%d) %d,%d,%u",
306
                SDL_GetScancodeName(event.key.keysym.scancode),
307
                event.key.keysym.scancode,
308
                SDL_GetKeyName(event.key.keysym.sym),
309
                event.key.keysym.sym,
310
                event.key.state,
311
                event.key.repeat,
312
                CAST_U32(event.key.keysym.mod));
313
            break;
314
        case SDL_WINDOWEVENT:
315
        {
316
            const int data1 = event.window.data1;
317
            const int data2 = event.window.data2;
318
            std::string str;
319
            switch (event.window.event)
320
            {
321
                winEventLog(SDL_WINDOWEVENT_NONE, "SDL_WINDOWEVENT_NONE");
322
                winEventLog(SDL_WINDOWEVENT_SHOWN, "SDL_WINDOWEVENT_SHOWN");
323
                winEventLog(SDL_WINDOWEVENT_HIDDEN, "SDL_WINDOWEVENT_HIDDEN");
324
                winEventLog(SDL_WINDOWEVENT_EXPOSED,
325
                    "SDL_WINDOWEVENT_EXPOSED");
326
                winEventLog(SDL_WINDOWEVENT_MOVED, "SDL_WINDOWEVENT_MOVED");
327
                winEventLog(SDL_WINDOWEVENT_RESIZED,
328
                    "SDL_WINDOWEVENT_RESIZED");
329
                winEventLog(SDL_WINDOWEVENT_SIZE_CHANGED,
330
                    "SDL_WINDOWEVENT_SIZE_CHANGED");
331
                winEventLog(SDL_WINDOWEVENT_MINIMIZED,
332
                    "SDL_WINDOWEVENT_MINIMIZED");
333
                winEventLog(SDL_WINDOWEVENT_MAXIMIZED,
334
                    "SDL_WINDOWEVENT_MAXIMIZED");
335
                winEventLog(SDL_WINDOWEVENT_RESTORED,
336
                    "SDL_WINDOWEVENT_RESTORED");
337
                winEventLog(SDL_WINDOWEVENT_ENTER, "SDL_WINDOWEVENT_ENTER");
338
                winEventLog(SDL_WINDOWEVENT_LEAVE, "SDL_WINDOWEVENT_LEAVE");
339
                winEventLog(SDL_WINDOWEVENT_FOCUS_GAINED,
340
                    "SDL_WINDOWEVENT_FOCUS_GAINED");
341
                winEventLog(SDL_WINDOWEVENT_FOCUS_LOST,
342
                    "SDL_WINDOWEVENT_FOCUS_LOST");
343
                winEventLog(SDL_WINDOWEVENT_CLOSE, "SDL_WINDOWEVENT_CLOSE");
344
#if SDL_VERSION_ATLEAST(2, 0, 5)
345
                winEventLog(SDL_WINDOWEVENT_TAKE_FOCUS,
346
                    "SDL_WINDOWEVENT_TAKE_FOCUS");
347
                winEventLog(SDL_WINDOWEVENT_HIT_TEST,
348
                    "SDL_WINDOWEVENT_HIT_TEST");
349
#endif  // SDL_VERSION_ATLEAST(2, 0, 5)
350
                default:
351
                    str = strprintf("unknown: %d",
352
                        event.window.event);
353
                    break;
354
            }
355
            logger->log("event: SDL_WINDOWEVENT: %s: %d,%d",
356
                str.c_str(), data1, data2);
357
            break;
358
        }
359
        case SDL_TEXTINPUT:
360
        {
361
            const char *const text = event.text.text;
362
            logger->log("event: SDL_TEXTINPUT: %s", text);
363
            const size_t sz = strlen(event.text.text);
364
            for (size_t f = 0; f < sz; f ++)
365
                logger->log("dec: %d", text[f]);
366
            break;
367
        }
368
        case SDL_APP_TERMINATING:
369
            logger->log("SDL_APP_TERMINATING");
370
            break;
371
        case SDL_APP_LOWMEMORY:
372
            logger->log("SDL_APP_LOWMEMORY");
373
            break;
374
        case SDL_APP_WILLENTERBACKGROUND:
375
            logger->log("SDL_APP_WILLENTERBACKGROUND");
376
            break;
377
        case SDL_APP_WILLENTERFOREGROUND:
378
            logger->log("SDL_APP_WILLENTERFOREGROUND");
379
            break;
380
        case SDL_APP_DIDENTERFOREGROUND:
381
            logger->log("SDL_APP_DIDENTERFOREGROUND");
382
            break;
383
        case SDL_APP_DIDENTERBACKGROUND:
384
            logger->log("SDL_APP_DIDENTERBACKGROUND");
385
            break;
386
        case SDL_MOUSEWHEEL:
387
#if SDL_VERSION_ATLEAST(2, 0, 4)
388
            logger->log("event: SDL_MOUSEWHEEL: %u,%u, %d,%d, %u",
389
                event.wheel.windowID,
390
                event.wheel.which,
391
                event.wheel.x,
392
                event.wheel.y,
393
                event.wheel.direction);
394
#else  // SDL_VERSION_ATLEAST(2, 0, 4)
395
396
            logger->log("event: SDL_MOUSEWHEEL: %u,%u, %d,%d",
397
                event.wheel.windowID,
398
                event.wheel.which,
399
                event.wheel.x,
400
                event.wheel.y);
401
#endif  // SDL_VERSION_ATLEAST(2, 0, 4)
402
            break;
403
#if SDL_VERSION_ATLEAST(2, 0, 4)
404
        case SDL_AUDIODEVICEADDED:
405
            logger->log("event: SDL_AUDIODEVICEADDED: %u,%u",
406
                event.adevice.which,
407
                event.adevice.iscapture);
408
            break;
409
        case SDL_KEYMAPCHANGED:
410
            logger->log("event: SDL_KEYMAPCHANGED");
411
            break;
412
#endif  // SDL_VERSION_ATLEAST(2, 0, 4)
413
        case SDL_MOUSEBUTTONDOWN:
414
            logger->log("event: SDL_MOUSEBUTTONDOWN: %u,%u,%u, %d,%d",
415
                event.button.which,
416
                CAST_U32(event.button.button),
417
                CAST_U32(event.button.state),
418
                event.button.x,
419
                event.button.y);
420
            break;
421
        case SDL_MOUSEBUTTONUP:
422
            logger->log("event: SDL_MOUSEBUTTONUP: %u,%u,%u, %d,%d",
423
                event.button.which,
424
                CAST_U32(event.button.button),
425
                CAST_U32(event.button.state),
426
                event.button.x,
427
                event.button.y);
428
            break;
429
        case SDL_JOYDEVICEADDED:
430
            logger->log("event: SDL_JOYDEVICEADDED: %d",
431
                event.jdevice.which);
432
            break;
433
        case SDL_JOYDEVICEREMOVED:
434
            logger->log("event: SDL_JOYDEVICEREMOVED: %d",
435
                event.jdevice.which);
436
            break;
437
#else  // USE_SDL2
438
439
        case SDL_MOUSEMOTION:
440
            logger->log("event: SDL_MOUSEMOTION: %u,%d,%d",
441
                event.motion.state, event.motion.x, event.motion.y);
442
            break;
443
        case SDL_KEYDOWN:
444
            logger->log("event: SDL_KEYDOWN: %s(%d),%d,%d,%d",
445
                SDL_GetKeyName(event.key.keysym.sym),
446
                event.key.keysym.sym,
447
                event.key.keysym.scancode,
448
                event.key.state,
449
                event.key.keysym.unicode);
450
            break;
451
        case SDL_KEYUP:
452
            logger->log("event: SDL_KEYUP: %s(%d),%d,%d,%d",
453
                SDL_GetKeyName(event.key.keysym.sym),
454
                event.key.keysym.sym,
455
                event.key.keysym.scancode,
456
                event.key.state,
457
                event.key.keysym.unicode);
458
            break;
459
        case SDL_VIDEORESIZE:
460
            logger->log("event: SDL_VIDEORESIZE");
461
            break;
462
        case SDL_VIDEOEXPOSE:
463
            logger->log("event: SDL_VIDEOEXPOSE");
464
            break;
465
        case SDL_ACTIVEEVENT:
466
            logger->log("event: SDL_ACTIVEEVENT: %d %d",
467
                event.active.state, event.active.gain);
468
            break;
469
        case SDL_MOUSEBUTTONDOWN:
470
            logger->log("event: SDL_MOUSEBUTTONDOWN: %d,%d, %d,%d",
471
                event.button.button,
472
                event.button.state,
473
                event.button.x,
474
                event.button.y);
475
            break;
476
        case SDL_MOUSEBUTTONUP:
477
            logger->log("event: SDL_MOUSEBUTTONUP: %d,%d,%d,%d",
478
                event.button.button,
479
                event.button.state,
480
                event.button.x,
481
                event.button.y);
482
            break;
483
#endif  // USE_SDL2
484
485
        case SDL_JOYAXISMOTION:
486
            logger->log("event: SDL_JOYAXISMOTION: %d,%d,%d",
487
                event.jaxis.which, event.jaxis.axis, event.jaxis.value);
488
            break;
489
        case SDL_JOYBALLMOTION:
490
            logger->log("event: SDL_JOYBALLMOTION: %d,%d,%d,%d",
491
                event.jball.which, event.jball.ball,
492
                event.jball.xrel, event.jball.yrel);
493
            break;
494
        case SDL_JOYHATMOTION:
495
            logger->log("event: SDL_JOYHATMOTION: %d,%d,%d", event.jhat.which,
496
                event.jhat.hat, event.jhat.value);
497
            break;
498
        case SDL_JOYBUTTONDOWN:
499
            logger->log("event: SDL_JOYBUTTONDOWN: %d,%d,%d",
500
                event.jbutton.which, event.jbutton.button,
501
                event.jbutton.state);
502
            break;
503
        case SDL_JOYBUTTONUP:
504
            logger->log("event: SDL_JOYBUTTONUP: %d,%d,%d",
505
                event.jbutton.which, event.jbutton.button,
506
                event.jbutton.state);
507
            break;
508
        case SDL_QUIT:
509
            logger->log("event: SDL_QUIT");
510
            break;
511
        case SDL_SYSWMEVENT:
512
        {
513
#ifdef USE_X11
514
            const bool res = X11Logger::logEvent(event);
515
            if (res == false)
516
                logger->assertLog("event: SDL_SYSWMEVENT: not supported:");
517
#else  // USE_X11
518
519
            logger->assertLog("event: SDL_SYSWMEVENT: not supported:");
520
#endif  // USE_X11
521
522
            break;
523
        }
524
        case SDL_USEREVENT:
525
            logger->log("event: SDL_USEREVENT: %d",
526
                event.user.code);
527
            break;
528
#ifdef ANDROID
529
#ifndef USE_SDL2
530
        case SDL_ACCELEROMETER:
531
            logger->log("event: SDL_ACCELEROMETER");
532
            break;
533
#endif  // USE_SDL2
534
#endif  // ANDROID
535
536
        default:
537
            logger->assertLog("event: other: %u",
538
                CAST_U32(event.type));
539
            break;
540
    };
541
}
542
543
#ifdef USE_SDL2
544
void EventsManager::handleSDL2WindowEvent(const SDL_Event &event)
545
{
546
#ifndef DYECMD
547
    int fpsLimit = 0;
548
#endif  // DYECMD
549
550
    const int eventType = event.window.event;
551
    const bool inGame = (client->getState() == State::GAME);
552
    switch (eventType)
553
    {
554
        case SDL_WINDOWEVENT_RESIZED:
555
            WindowManager::resizeVideo(event.window.data1,
556
                event.window.data2,
557
                false);
558
            break;
559
        case SDL_WINDOWEVENT_ENTER:
560
            settings.mouseFocused = true;
561
            break;
562
        case SDL_WINDOWEVENT_LEAVE:
563
            settings.mouseFocused = false;
564
            break;
565
        case SDL_WINDOWEVENT_FOCUS_GAINED:
566
            settings.inputFocused = KeyboardFocus::Focused;
567
            break;
568
#if SDL_VERSION_ATLEAST(2, 0, 5)
569
        case SDL_WINDOWEVENT_TAKE_FOCUS:
570
            settings.inputFocused = KeyboardFocus::Focused2;
571
            break;
572
#endif  // SDL_VERSION_ATLEAST(2, 0, 5)
573
574
        case SDL_WINDOWEVENT_FOCUS_LOST:
575
            settings.inputFocused = KeyboardFocus::Unfocused;
576
            break;
577
        case SDL_WINDOWEVENT_MINIMIZED:
578
            WindowManager::setIsMinimized(true);
579
#ifndef DYECMD
580
            fpsLimit = config.getIntValue("altfpslimit");
581
            if (localPlayer)
582
                localPlayer->setHalfAway(true);
583
#endif  // DYECMD
584
585
            setPriority(false);
586
            break;
587
        case SDL_WINDOWEVENT_RESTORED:
588
        case SDL_WINDOWEVENT_MAXIMIZED:
589
            WindowManager::setIsMinimized(false);
590
#ifndef DYECMD
591
            fpsLimit = config.getIntValue("fpslimit");
592
            if (localPlayer)
593
                localPlayer->setHalfAway(false);
594
#endif  // DYECMD
595
596
            setPriority(true);
597
            break;
598
        default:
599
            break;
600
    }
601
602
    if (!inGame)
603
        return;
604
605
#ifndef DYECMD
606
    if (eventType == SDL_WINDOWEVENT_MINIMIZED
607
        || eventType == SDL_WINDOWEVENT_RESTORED
608
        || eventType == SDL_WINDOWEVENT_MAXIMIZED)
609
    {
610
        if (localPlayer)
611
        {
612
            localPlayer->updateStatus();
613
            localPlayer->updateName();
614
        }
615
        Game::instance()->updateFrameRate(fpsLimit);
616
    }
617
#endif  // DYECMD
618

6
}
619
#else  // USE_SDL2
620
621
void EventsManager::handleActive(const SDL_Event &event)
622
{
623
#ifndef DYECMD
624
    int fpsLimit = 0;
625
    const bool inGame = (client->getState() == State::GAME);
626
#endif  // DYECMD
627
628
    if ((event.active.state & SDL_APPACTIVE) != 0)
629
    {
630
        if (event.active.gain != 0u)
631
        {   // window restore
632
            WindowManager::setIsMinimized(false);
633
#ifndef DYECMD
634
            if (localPlayer != nullptr)
635
            {
636
                if (!settings.awayMode)
637
                    fpsLimit = config.getIntValue("fpslimit");
638
                localPlayer->setHalfAway(false);
639
            }
640
#endif  // DYECMD
641
642
            setPriority(true);
643
        }
644
        else
645
        {   // window minimization
646
#ifdef ANDROID
647
            client->setState(State::EXIT);
648
#else  // ANDROID
649
            WindowManager::setIsMinimized(true);
650
#ifndef DYECMD
651
            if (localPlayer != nullptr && !settings.awayMode)
652
            {
653
                fpsLimit = config.getIntValue("altfpslimit");
654
                localPlayer->setHalfAway(true);
655
            }
656
#endif  // DYECMD
657
658
            setPriority(false);
659
#endif  // ANDROID
660
        }
661
#ifndef DYECMD
662
        if (inGame && (localPlayer != nullptr))
663
            localPlayer->updateStatus();
664
#endif  // DYECMD
665
    }
666
#ifndef DYECMD
667
    if (inGame && (localPlayer != nullptr))
668
        localPlayer->updateName();
669
#endif  // DYECMD
670
671
    if ((event.active.state & SDL_APPINPUTFOCUS) != 0)
672
    {
673
        settings.inputFocused = (event.active.gain != 0u) ?
674
            KeyboardFocus::Focused : KeyboardFocus::Unfocused;
675
    }
676
    if ((event.active.state & SDL_APPMOUSEFOCUS) != 0)
677
        settings.mouseFocused = (event.active.gain != 0u);
678
#ifndef DYECMD
679
    if (inGame)
680
        Game::instance()->updateFrameRate(fpsLimit);
681
#endif  // DYECMD
682
}
683
#endif  // USE_SDL2