<commit_before>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <cstdlib>
#include <GL/gl.h>
#include <GL/glext.h>
#include "ApplicationLinux.h"
#include "core/Engine.h"
#include "events/Event.h"
#include "input/Input.h"
#include "input/linux/InputLinux.h"
#include "WindowLinux.h"

namespace ouzel
{
    ApplicationLinux::ApplicationLinux(int aArgc, char* aArgv[]):
        Application(aArgc, aArgv)
    {
    }

    int ApplicationLinux::run()
    {
        ouzelMain(args);

        if (!sharedEngine)
        {
            return EXIT_FAILURE;
        }

        sharedEngine->begin();

        if (sharedEngine->getRenderer()->getDriver() == graphics::Renderer::Driver::EMPTY)
        {
            for (;;)
            {
                executeAll();

                if (!sharedEngine->draw())
                {
                    sharedEngine->exit();
                    break;
                }
            }
        }
        else
        {
            XEvent event;

            WindowLinux* windowLinux = static_cast<WindowLinux*>(sharedEngine->getWindow());

            while (active)
            {
                executeAll();

                if (sharedEngine->draw())
                {
                    while (sharedEngine->isActive())
                    {
                        // XNextEvent will block if there is no event pending, so don't call it if engine is running
                        if (sharedEngine->isRunning() && !XPending(windowLinux->getDisplay()))
                        {
                            break;
                        }

                        XNextEvent(windowLinux->getDisplay(), &event);

                        switch (event.type)
                        {
                            case ClientMessage:
                            {
                                if (static_cast<Atom>(event.xclient.data.l[0]) == windowLinux->getDeleteMessage())
                                {
                                    sharedEngine->exit();
                                }
                                break;
                            }
                            case FocusIn:
                                sharedEngine->resume();
                                break;
                            case FocusOut:
                                sharedEngine->pause();
                                break;
                            case KeyPress: // keyboard
                            case KeyRelease:
                            {
                                KeySym keySym = XkbKeycodeToKeysym(windowLinux->getDisplay(), event.xkey.keycode, 0, event.xkey.state & ShiftMask ? 1 : 0);

                                if (event.type == KeyPress)
                                {
                                    sharedEngine->getInput()->keyDown(input::InputLinux::convertKeyCode(keySym),<commit_msg>Fix Linux exit<commit_after>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <cstdlib>
#include <GL/gl.h>
#include <GL/glext.h>
#include "ApplicationLinux.h"
#include "core/Engine.h"
#include "events/Event.h"
#include "input/Input.h"
#include "input/linux/InputLinux.h"
#include "WindowLinux.h"

namespace ouzel
{
    ApplicationLinux::ApplicationLinux(int aArgc, char* aArgv[]):
        Application(aArgc, aArgv)
    {
    }

    int ApplicationLinux::run()
    {
        ouzelMain(args);

        if (!sharedEngine)
        {
            return EXIT_FAILURE;
        }

        sharedEngine->begin();

        if (sharedEngine->getRenderer()->getDriver() == graphics::Renderer::Driver::EMPTY)
        {
            for (;;)
            {
                executeAll();

                if (!sharedEngine->draw())
                {
                    break;
                }
            }
        }
        else
        {
            XEvent event;

            WindowLinux* windowLinux = static_cast<WindowLinux*>(sharedEngine->getWindow());

            while (active)
            {
                executeAll();

                if (sharedEngine->draw())
                {
                    while (sharedEngine->isActive())
                    {
                        // XNextEvent will block if there is no event pending, so don't call it if engine is running
                        if (sharedEngine->isRunning() && !XPending(windowLinux->getDisplay()))
                        {
                            break;
                        }

                        XNextEvent(windowLinux->getDisplay(), &event);

                        switch (event.type)
                        {
                            case ClientMessage:
                            {
                                if (static_cast<Atom>(event.xclient.data.l[0]) == windowLinux->getDeleteMessage())
                                {
                                    exit();
                                }
                                break;
                            }
                            case FocusIn:
                                sharedEngine->resume();
                                break;
                            case FocusOut:
                                sharedEngine->pause();
                                break;
                            case KeyPress: // keyboard
                            case KeyRelease:
                            {
                                KeySym keySym = XkbKeycodeToKeysym(windowLinux->getDisplay(), event.xkey.keycode, 0, event.xkey.state & ShiftMask ? 1 : 0);

                                if (event.type == KeyPress)
                                {
                                    sharedEngine->getInput()->keyDown(input::InputLinux::convertKeyCode(keySym),
{'fraction_non_alphanumeric': 0.09759889445500086, 'fraction_numerical': 0.0027638624978407324, 'mean_word_length': 0.98559670781893, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5985315', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1300, 'n_words': 254}