GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/eventsmanager.cpp Lines: 9 235 3.8 %
Date: 2021-03-17 Branches: 2 119 1.7 %

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

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