diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef3548170..7a7094bd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -343,12 +343,12 @@ jobs: matrix: platform: - { name: Windows, os: windows-2022, flags: -GNinja } - - { name: Linux, os: ubuntu-22.04 } - - { name: Linux DRM, os: ubuntu-22.04, flags: -DSFML_USE_DRM=TRUE } - - { name: Linux OpenGL ES, os: ubuntu-22.04, flags: -DSFML_OPENGL_ES=ON } + - { name: Linux, os: ubuntu-24.04 } + - { name: Linux DRM, os: ubuntu-24.04, flags: -DSFML_USE_DRM=TRUE } + - { name: Linux OpenGL ES, os: ubuntu-24.04, flags: -DSFML_OPENGL_ES=ON } - { name: macOS, os: macos-12 } - { name: iOS, os: macos-12, flags: -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64 } - - { name: Android, os: ubuntu-22.04, flags: -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DCMAKE_ANDROID_STL_TYPE=c++_shared } + - { name: Android, os: ubuntu-24.04, flags: -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DCMAKE_ANDROID_STL_TYPE=c++_shared } steps: - name: Checkout Code @@ -367,7 +367,7 @@ jobs: - name: Install Linux Dependencies if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev libdrm-dev libgbm-dev + run: sudo apt-get update && sudo apt-get install libfreetype-dev libxrandr-dev libxcursor-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev libdrm-dev libgbm-dev - name: Install macOS Dependencies if: runner.os == 'macOS' diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 630ad9fff..4279c8f12 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -56,8 +56,46 @@ extern int main(int argc, char* argv[]); -namespace sf::priv +namespace { +//////////////////////////////////////////////////////////// +void initializeMain(sf::priv::ActivityStates& states) +{ + // Protect from concurrent access + const std::lock_guard lock(states.mutex); + + // Prepare and share the looper to be read later + ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); + states.looper = looper; + + /** + * Acquire increments a reference counter on the looper. This keeps android + * from collecting it before the activity thread has a chance to detach its + * input queue. + */ + ALooper_acquire(states.looper); + ALooper_wake(states.looper); + + // Get the default configuration + states.config = AConfiguration_new(); + AConfiguration_fromAssetManager(states.config, states.activity->assetManager); +} + +//////////////////////////////////////////////////////////// +void terminateMain(sf::priv::ActivityStates& states) +{ + // Protect from concurrent access + const std::lock_guard lock(states.mutex); + + // The main thread has finished, we must explicitly ask the activity to finish + states.mainOver = true; + ANativeActivity_finish(states.activity); +} + +//////////////////////////////////////////////////////////// +void onStart(ANativeActivity* /* activity */) +{ +} //////////////////////////////////////////////////////////// int getAndroidApiLevel(ANativeActivity* activity) @@ -78,82 +116,20 @@ int getAndroidApiLevel(ANativeActivity* activity) return sdkInt; } - //////////////////////////////////////////////////////////// -ActivityStates* retrieveStates(ANativeActivity* activity) +sf::priv::ActivityStates* retrieveStates(ANativeActivity* activity) { assert(activity != nullptr && "Activity cannot be null"); // Hide the ugly cast we find in each callback function - return static_cast(activity->instance); + return static_cast(activity->instance); } - -//////////////////////////////////////////////////////////// -static void initializeMain(ActivityStates* states) -{ - // Protect from concurrent access - const std::lock_guard lock(states->mutex); - - // Prepare and share the looper to be read later - ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); - states->looper = looper; - - /** - * Acquire increments a reference counter on the looper. This keeps android - * from collecting it before the activity thread has a chance to detach its - * input queue. - */ - ALooper_acquire(states->looper); - ALooper_wake(states->looper); - - // Get the default configuration - states->config = AConfiguration_new(); - AConfiguration_fromAssetManager(states->config, states->activity->assetManager); -} - - -//////////////////////////////////////////////////////////// -static void terminateMain(ActivityStates* states) -{ - // Protect from concurrent access - const std::lock_guard lock(states->mutex); - - // The main thread has finished, we must explicitly ask the activity to finish - states->mainOver = true; - ANativeActivity_finish(states->activity); -} - - -//////////////////////////////////////////////////////////// -void* main(ActivityStates* states) -{ - // Initialize the thread before giving the hand - initializeMain(states); - - sleep(seconds(0.5)); - ::main(0, nullptr); - - // Terminate properly the main thread and wait until it's done - terminateMain(states); - - { - const std::lock_guard lock(states->mutex); - - states->terminated = true; - } - - return nullptr; -} - -} // namespace sf::priv - - //////////////////////////////////////////////////////////// void goToFullscreenMode(ANativeActivity* activity) { // Get the current Android API level. - int apiLevel = sf::priv::getAndroidApiLevel(activity); + const int apiLevel = getAndroidApiLevel(activity); // Hide the status bar ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_FULLSCREEN, AWINDOW_FLAG_FULLSCREEN); @@ -179,28 +155,28 @@ void goToFullscreenMode(ANativeActivity* activity) // API Level 14 if (apiLevel >= 14) { - jfieldID fieldSystemUiFlagLowProfile = lJNIEnv->GetStaticFieldID(classView, + jfieldID fieldSystemUiFlagLowProfile = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I"); - jint systemUiFlagLowProfile = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagLowProfile); + const jint systemUiFlagLowProfile = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagLowProfile); flags |= systemUiFlagLowProfile; } // API Level 16 if (apiLevel >= 16) { - jfieldID fieldSystemUiFlagFullscreen = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I"); - jint systemUiFlagFullscreen = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagFullscreen); + jfieldID fieldSystemUiFlagFullscreen = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I"); + const jint systemUiFlagFullscreen = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagFullscreen); flags |= systemUiFlagFullscreen; } // API Level 19 if (apiLevel >= 19) { - jfieldID fieldSystemUiFlagImmersiveSticky = lJNIEnv->GetStaticFieldID(classView, + jfieldID fieldSystemUiFlagImmersiveSticky = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY", "I"); - jint systemUiFlagImmersiveSticky = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagImmersiveSticky); + const jint systemUiFlagImmersiveSticky = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagImmersiveSticky); flags |= systemUiFlagImmersiveSticky; } @@ -209,7 +185,6 @@ void goToFullscreenMode(ANativeActivity* activity) } //////////////////////////////////////////////////////////// - void getScreenSizeInPixels(ANativeActivity* activity, int* width, int* height) { // Perform the following Java code: @@ -248,18 +223,11 @@ void getScreenSizeInPixels(ANativeActivity* activity, int* width, int* height) *height = lJNIEnv->GetIntField(objectDisplayMetrics, fieldHeightPixels); } - //////////////////////////////////////////////////////////// -static void onStart(ANativeActivity* /* activity */) -{ -} - - -//////////////////////////////////////////////////////////// -static void onResume(ANativeActivity* activity) +void onResume(ANativeActivity* activity) { // Retrieve our activity states from the activity instance - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); const std::lock_guard lock(states->mutex); if (states->fullscreen) @@ -269,30 +237,27 @@ static void onResume(ANativeActivity* activity) states->forwardEvent(sf::Event::MouseEntered{}); } - //////////////////////////////////////////////////////////// -static void onPause(ANativeActivity* activity) +void onPause(ANativeActivity* activity) { // Retrieve our activity states from the activity instance - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); const std::lock_guard lock(states->mutex); // Send an event to warn people the activity has been paused states->forwardEvent(sf::Event::MouseLeft{}); } - //////////////////////////////////////////////////////////// -static void onStop(ANativeActivity* /* activity */) +void onStop(ANativeActivity* /* activity */) { } - //////////////////////////////////////////////////////////// -static void onDestroy(ANativeActivity* activity) +void onDestroy(ANativeActivity* activity) { // Retrieve our activity states from the activity instance - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); // Send an event to warn people the activity is being destroyed { @@ -328,11 +293,10 @@ static void onDestroy(ANativeActivity* activity) // The application should now terminate } - //////////////////////////////////////////////////////////// -static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) +void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) { - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); const std::lock_guard lock(states->mutex); // Update the activity states @@ -351,11 +315,10 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind } } - //////////////////////////////////////////////////////////// -static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* /* window */) +void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* /* window */) { - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); const std::lock_guard lock(states->mutex); // Update the activity states @@ -374,24 +337,21 @@ static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* /* } } - //////////////////////////////////////////////////////////// -static void onNativeWindowRedrawNeeded(ANativeActivity* /* activity */, ANativeWindow* /* window */) +void onNativeWindowRedrawNeeded(ANativeActivity* /* activity */, ANativeWindow* /* window */) { } - //////////////////////////////////////////////////////////// -static void onNativeWindowResized(ANativeActivity* /* activity */, ANativeWindow* /* window */) +void onNativeWindowResized(ANativeActivity* /* activity */, ANativeWindow* /* window */) { } - //////////////////////////////////////////////////////////// -static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) +void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) { // Retrieve our activity states from the activity instance - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); // Attach the input queue { @@ -402,12 +362,11 @@ static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) } } - //////////////////////////////////////////////////////////// -static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) +void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) { // Retrieve our activity states from the activity instance - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); // Detach the input queue { @@ -420,18 +379,16 @@ static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) } } - //////////////////////////////////////////////////////////// -static void onWindowFocusChanged(ANativeActivity* /* activity */, int /* focused */) +void onWindowFocusChanged(ANativeActivity* /* activity */, int /* focused */) { } - //////////////////////////////////////////////////////////// -static void onContentRectChanged(ANativeActivity* activity, const ARect* /* rect */) +void onContentRectChanged(ANativeActivity* activity, const ARect* /* rect */) { // Retrieve our activity states from the activity instance - sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); + sf::priv::ActivityStates* states = retrieveStates(activity); const std::lock_guard lock(states->mutex); // Make sure the window still exists before we access the dimensions on it @@ -444,26 +401,47 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* /* rect } } - //////////////////////////////////////////////////////////// -static void onConfigurationChanged(ANativeActivity* /* activity */) +void onConfigurationChanged(ANativeActivity* /* activity */) { } - //////////////////////////////////////////////////////////// -static void* onSaveInstanceState(ANativeActivity* /* activity */, std::size_t* outLen) +void* onSaveInstanceState(ANativeActivity* /* activity */, std::size_t* outLen) { *outLen = 0; - return nullptr; } - //////////////////////////////////////////////////////////// -static void onLowMemory(ANativeActivity* /* activity */) +void onLowMemory(ANativeActivity* /* activity */) { } +} // namespace + + +namespace sf::priv +{ +//////////////////////////////////////////////////////////// +void* main(ActivityStates* states) +{ + // Initialize the thread before giving the hand + initializeMain(*states); + + sleep(seconds(0.5)); + ::main(0, nullptr); + + // Terminate properly the main thread and wait until it's done + terminateMain(*states); + + { + const std::lock_guard lock(states->mutex); + states->terminated = true; + } + + return nullptr; +} +} // namespace sf::priv //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Android/InputImpl.cpp b/src/SFML/Window/Android/InputImpl.cpp index 8f8cea373..d9772ad01 100644 --- a/src/SFML/Window/Android/InputImpl.cpp +++ b/src/SFML/Window/Android/InputImpl.cpp @@ -87,7 +87,7 @@ void setVirtualKeyboardVisible(bool visible) const std::lock_guard lock(states.mutex); // Initializes JNI - jint lFlags = 0; + const jint lFlags = 0; JavaVM* lJavaVM = states.activity->vm; JNIEnv* lJNIEnv = states.activity->env; @@ -97,7 +97,7 @@ void setVirtualKeyboardVisible(bool visible) lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.group = nullptr; - jint lResult = lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); + const jint lResult = lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); if (lResult == JNI_ERR) err() << "Failed to initialize JNI, couldn't switch the keyboard visibility" << std::endl; diff --git a/src/SFML/Window/Android/SensorImpl.cpp b/src/SFML/Window/Android/SensorImpl.cpp index ef8f5940f..cb79771f9 100644 --- a/src/SFML/Window/Android/SensorImpl.cpp +++ b/src/SFML/Window/Android/SensorImpl.cpp @@ -100,7 +100,7 @@ bool SensorImpl::open(Sensor::Type sensor) return false; // Get the minimum delay allowed between events - Time minimumDelay = microseconds(ASensor_getMinDelay(m_sensor)); + const Time minimumDelay = microseconds(ASensor_getMinDelay(m_sensor)); // Set the event rate (not to consume too much battery) ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, static_cast(minimumDelay.asMicroseconds())); @@ -151,7 +151,7 @@ const ASensor* SensorImpl::getDefaultSensor(Sensor::Type sensor) ASENSOR_TYPE_LINEAR_ACCELERATION, ASENSOR_TYPE_ORIENTATION}; - int type = types[sensor]; + const int type = types[sensor]; // Retrieve the default sensor matching this type return ASensorManager_getDefaultSensor(sensorManager, type); diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 41e553208..b49010c75 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -232,7 +232,7 @@ void WindowImplAndroid::forwardEvent(const Event& event) { if (WindowImplAndroid::singleInstance != nullptr) { - ActivityStates& states = getActivity(); + const ActivityStates& states = getActivity(); if (event.is()) { @@ -267,12 +267,12 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat int handled = 0; - std::int32_t type = AInputEvent_getType(inputEvent); + const std::int32_t type = AInputEvent_getType(inputEvent); if (type == AINPUT_EVENT_TYPE_KEY) { - std::int32_t action = AKeyEvent_getAction(inputEvent); - std::int32_t key = AKeyEvent_getKeyCode(inputEvent); + const std::int32_t action = AKeyEvent_getAction(inputEvent); + const std::int32_t key = AKeyEvent_getKeyCode(inputEvent); if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) && key != AKEYCODE_VOLUME_UP && key != AKEYCODE_VOLUME_DOWN) @@ -282,7 +282,7 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat } else if (type == AINPUT_EVENT_TYPE_MOTION) { - std::int32_t action = AMotionEvent_getAction(inputEvent); + const std::int32_t action = AMotionEvent_getAction(inputEvent); switch (action & AMOTION_EVENT_ACTION_MASK) { @@ -348,18 +348,18 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityState } // Retrieve everything we need to create this MotionEvent in Java - std::int64_t downTime = AMotionEvent_getDownTime(inputEvent); - std::int64_t eventTime = AMotionEvent_getEventTime(inputEvent); - std::int32_t action = AMotionEvent_getAction(inputEvent); - float x = AMotionEvent_getX(inputEvent, 0); - float y = AMotionEvent_getY(inputEvent, 0); - float pressure = AMotionEvent_getPressure(inputEvent, 0); - float size = AMotionEvent_getSize(inputEvent, 0); - std::int32_t metaState = AMotionEvent_getMetaState(inputEvent); - float xPrecision = AMotionEvent_getXPrecision(inputEvent); - float yPrecision = AMotionEvent_getYPrecision(inputEvent); - std::int32_t deviceId = AInputEvent_getDeviceId(inputEvent); - std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(inputEvent); + const std::int64_t downTime = AMotionEvent_getDownTime(inputEvent); + const std::int64_t eventTime = AMotionEvent_getEventTime(inputEvent); + const std::int32_t action = AMotionEvent_getAction(inputEvent); + const float x = AMotionEvent_getX(inputEvent, 0); + const float y = AMotionEvent_getY(inputEvent, 0); + const float pressure = AMotionEvent_getPressure(inputEvent, 0); + const float size = AMotionEvent_getSize(inputEvent, 0); + const std::int32_t metaState = AMotionEvent_getMetaState(inputEvent); + const float xPrecision = AMotionEvent_getXPrecision(inputEvent); + const float yPrecision = AMotionEvent_getYPrecision(inputEvent); + const std::int32_t deviceId = AInputEvent_getDeviceId(inputEvent); + const std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(inputEvent); // Create the MotionEvent object in Java through its static constructor obtain() jclass classMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent"); @@ -385,8 +385,8 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityState edgeFlags); // Call its getAxisValue() method to get the delta value of our wheel move event - jmethodID methodGetAxisValue = lJNIEnv->GetMethodID(classMotionEvent, "getAxisValue", "(I)F"); - jfloat delta = lJNIEnv->CallFloatMethod(objectMotionEvent, methodGetAxisValue, 0x00000001); + jmethodID methodGetAxisValue = lJNIEnv->GetMethodID(classMotionEvent, "getAxisValue", "(I)F"); + const jfloat delta = lJNIEnv->CallFloatMethod(objectMotionEvent, methodGetAxisValue, 0x00000001); lJNIEnv->DeleteLocalRef(classMotionEvent); lJNIEnv->DeleteLocalRef(objectMotionEvent); @@ -408,10 +408,10 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityState //////////////////////////////////////////////////////////// int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates& /* states */) { - std::int32_t action = AKeyEvent_getAction(inputEvent); + const std::int32_t action = AKeyEvent_getAction(inputEvent); - std::int32_t key = AKeyEvent_getKeyCode(inputEvent); - std::int32_t metakey = AKeyEvent_getMetaState(inputEvent); + const std::int32_t key = AKeyEvent_getKeyCode(inputEvent); + const std::int32_t metakey = AKeyEvent_getMetaState(inputEvent); Event::KeyChanged keyChanged; keyChanged.code = androidKeyToSF(key); @@ -448,7 +448,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates& { const Event event(Event::TextEntered{static_cast(unicode)}); - std::int32_t repeats = AKeyEvent_getRepeatCount(inputEvent); + const std::int32_t repeats = AKeyEvent_getRepeatCount(inputEvent); for (std::int32_t i = 0; i < repeats; ++i) forwardEvent(event); return 1; @@ -462,7 +462,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates& //////////////////////////////////////////////////////////// int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityStates& states) { - std::int32_t device = AInputEvent_getSource(inputEvent); + const std::int32_t device = AInputEvent_getSource(inputEvent); Event event; @@ -471,11 +471,11 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityState else if (static_cast(device) & AINPUT_SOURCE_TOUCHSCREEN) event = Event::TouchMoved{}; - std::size_t pointerCount = AMotionEvent_getPointerCount(inputEvent); + const std::size_t pointerCount = AMotionEvent_getPointerCount(inputEvent); for (std::size_t p = 0; p < pointerCount; ++p) { - std::int32_t id = AMotionEvent_getPointerId(inputEvent, p); + const std::int32_t id = AMotionEvent_getPointerId(inputEvent, p); int x = static_cast(AMotionEvent_getX(inputEvent, p)); int y = static_cast(AMotionEvent_getY(inputEvent, p)); @@ -507,12 +507,12 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityState //////////////////////////////////////////////////////////// int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* inputEvent, ActivityStates& states) { - std::int32_t device = AInputEvent_getSource(inputEvent); - std::int32_t action = AMotionEvent_getAction(inputEvent); + const std::int32_t device = AInputEvent_getSource(inputEvent); + const std::int32_t action = AMotionEvent_getAction(inputEvent); - std::size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; - std::int32_t id = AMotionEvent_getPointerId(inputEvent, index); - const auto button = static_cast(id); + const std::size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + const std::int32_t id = AMotionEvent_getPointerId(inputEvent, index); + const auto button = static_cast(id); int x = static_cast(AMotionEvent_getX(inputEvent, index)); int y = static_cast(AMotionEvent_getY(inputEvent, index)); @@ -708,16 +708,16 @@ int WindowImplAndroid::getUnicode(AInputEvent* event) err() << "Failed to initialize JNI, couldn't get the Unicode value" << std::endl; // Retrieve key data from the input event - jlong downTime = AKeyEvent_getDownTime(event); - jlong eventTime = AKeyEvent_getEventTime(event); - jint action = AKeyEvent_getAction(event); - jint code = AKeyEvent_getKeyCode(event); - jint repeat = AKeyEvent_getRepeatCount(event); // not sure! - jint metaState = AKeyEvent_getMetaState(event); - jint deviceId = AInputEvent_getDeviceId(event); - jint scancode = AKeyEvent_getScanCode(event); - jint flags = AKeyEvent_getFlags(event); - jint source = AInputEvent_getSource(event); + const jlong downTime = AKeyEvent_getDownTime(event); + const jlong eventTime = AKeyEvent_getEventTime(event); + const jint action = AKeyEvent_getAction(event); + const jint code = AKeyEvent_getKeyCode(event); + const jint repeat = AKeyEvent_getRepeatCount(event); // not sure! + const jint metaState = AKeyEvent_getMetaState(event); + const jint deviceId = AInputEvent_getDeviceId(event); + const jint scancode = AKeyEvent_getScanCode(event); + const jint flags = AKeyEvent_getFlags(event); + const jint source = AInputEvent_getSource(event); // Construct a KeyEvent object from the event data jclass classKeyEvent = lJNIEnv->FindClass("android/view/KeyEvent"); @@ -737,7 +737,7 @@ int WindowImplAndroid::getUnicode(AInputEvent* event) // Call its getUnicodeChar() method to get the Unicode value jmethodID methodGetUnicode = lJNIEnv->GetMethodID(classKeyEvent, "getUnicodeChar", "(I)I"); - int unicode = lJNIEnv->CallIntMethod(objectKeyEvent, methodGetUnicode, metaState); + const int unicode = lJNIEnv->CallIntMethod(objectKeyEvent, methodGetUnicode, metaState); lJNIEnv->DeleteLocalRef(classKeyEvent); lJNIEnv->DeleteLocalRef(objectKeyEvent);