Upgrade clang-tidy for Linux jobs

This commit is contained in:
Chris Thrasher 2024-05-20 21:27:29 -06:00
parent 7234fc149b
commit 9f71ad3b24
5 changed files with 147 additions and 169 deletions

View File

@ -343,12 +343,12 @@ jobs:
matrix: matrix:
platform: platform:
- { name: Windows, os: windows-2022, flags: -GNinja } - { name: Windows, os: windows-2022, flags: -GNinja }
- { name: Linux, os: ubuntu-22.04 } - { name: Linux, os: ubuntu-24.04 }
- { name: Linux DRM, os: ubuntu-22.04, flags: -DSFML_USE_DRM=TRUE } - { name: Linux DRM, os: ubuntu-24.04, flags: -DSFML_USE_DRM=TRUE }
- { name: Linux OpenGL ES, os: ubuntu-22.04, flags: -DSFML_OPENGL_ES=ON } - { name: Linux OpenGL ES, os: ubuntu-24.04, flags: -DSFML_OPENGL_ES=ON }
- { name: macOS, os: macos-12 } - { name: macOS, os: macos-12 }
- { name: iOS, os: macos-12, flags: -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64 } - { 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: steps:
- name: Checkout Code - name: Checkout Code
@ -367,7 +367,7 @@ jobs:
- name: Install Linux Dependencies - name: Install Linux Dependencies
if: runner.os == 'Linux' 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 - name: Install macOS Dependencies
if: runner.os == 'macOS' if: runner.os == 'macOS'

View File

@ -56,8 +56,46 @@
extern int main(int argc, char* argv[]); 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) int getAndroidApiLevel(ANativeActivity* activity)
@ -78,82 +116,20 @@ int getAndroidApiLevel(ANativeActivity* activity)
return sdkInt; return sdkInt;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ActivityStates* retrieveStates(ANativeActivity* activity) sf::priv::ActivityStates* retrieveStates(ANativeActivity* activity)
{ {
assert(activity != nullptr && "Activity cannot be null"); assert(activity != nullptr && "Activity cannot be null");
// Hide the ugly cast we find in each callback function // Hide the ugly cast we find in each callback function
return static_cast<ActivityStates*>(activity->instance); return static_cast<sf::priv::ActivityStates*>(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) void goToFullscreenMode(ANativeActivity* activity)
{ {
// Get the current Android API level. // Get the current Android API level.
int apiLevel = sf::priv::getAndroidApiLevel(activity); const int apiLevel = getAndroidApiLevel(activity);
// Hide the status bar // Hide the status bar
ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_FULLSCREEN, AWINDOW_FLAG_FULLSCREEN); ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_FULLSCREEN, AWINDOW_FLAG_FULLSCREEN);
@ -179,28 +155,28 @@ void goToFullscreenMode(ANativeActivity* activity)
// API Level 14 // API Level 14
if (apiLevel >= 14) if (apiLevel >= 14)
{ {
jfieldID fieldSystemUiFlagLowProfile = lJNIEnv->GetStaticFieldID(classView, jfieldID fieldSystemUiFlagLowProfile = lJNIEnv->GetStaticFieldID(classView,
"SYSTEM_UI_FLAG_HIDE_NAVIGATION", "SYSTEM_UI_FLAG_HIDE_NAVIGATION",
"I"); "I");
jint systemUiFlagLowProfile = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagLowProfile); const jint systemUiFlagLowProfile = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagLowProfile);
flags |= systemUiFlagLowProfile; flags |= systemUiFlagLowProfile;
} }
// API Level 16 // API Level 16
if (apiLevel >= 16) if (apiLevel >= 16)
{ {
jfieldID fieldSystemUiFlagFullscreen = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I"); jfieldID fieldSystemUiFlagFullscreen = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
jint systemUiFlagFullscreen = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagFullscreen); const jint systemUiFlagFullscreen = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagFullscreen);
flags |= systemUiFlagFullscreen; flags |= systemUiFlagFullscreen;
} }
// API Level 19 // API Level 19
if (apiLevel >= 19) if (apiLevel >= 19)
{ {
jfieldID fieldSystemUiFlagImmersiveSticky = lJNIEnv->GetStaticFieldID(classView, jfieldID fieldSystemUiFlagImmersiveSticky = lJNIEnv->GetStaticFieldID(classView,
"SYSTEM_UI_FLAG_IMMERSIVE_STICKY", "SYSTEM_UI_FLAG_IMMERSIVE_STICKY",
"I"); "I");
jint systemUiFlagImmersiveSticky = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagImmersiveSticky); const jint systemUiFlagImmersiveSticky = lJNIEnv->GetStaticIntField(classView, fieldSystemUiFlagImmersiveSticky);
flags |= systemUiFlagImmersiveSticky; flags |= systemUiFlagImmersiveSticky;
} }
@ -209,7 +185,6 @@ void goToFullscreenMode(ANativeActivity* activity)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void getScreenSizeInPixels(ANativeActivity* activity, int* width, int* height) void getScreenSizeInPixels(ANativeActivity* activity, int* width, int* height)
{ {
// Perform the following Java code: // Perform the following Java code:
@ -248,18 +223,11 @@ void getScreenSizeInPixels(ANativeActivity* activity, int* width, int* height)
*height = lJNIEnv->GetIntField(objectDisplayMetrics, fieldHeightPixels); *height = lJNIEnv->GetIntField(objectDisplayMetrics, fieldHeightPixels);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static void onStart(ANativeActivity* /* activity */) void onResume(ANativeActivity* activity)
{
}
////////////////////////////////////////////////////////////
static void onResume(ANativeActivity* activity)
{ {
// Retrieve our activity states from the activity instance // 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); const std::lock_guard lock(states->mutex);
if (states->fullscreen) if (states->fullscreen)
@ -269,30 +237,27 @@ static void onResume(ANativeActivity* activity)
states->forwardEvent(sf::Event::MouseEntered{}); states->forwardEvent(sf::Event::MouseEntered{});
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static void onPause(ANativeActivity* activity) void onPause(ANativeActivity* activity)
{ {
// Retrieve our activity states from the activity instance // 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); const std::lock_guard lock(states->mutex);
// Send an event to warn people the activity has been paused // Send an event to warn people the activity has been paused
states->forwardEvent(sf::Event::MouseLeft{}); 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 // 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 // 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 // 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); const std::lock_guard lock(states->mutex);
// Update the activity states // 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); const std::lock_guard lock(states->mutex);
// Update the activity states // 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 // 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 // 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 // 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 // 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 // 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); const std::lock_guard lock(states->mutex);
// Make sure the window still exists before we access the dimensions on it // 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; *outLen = 0;
return nullptr; 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
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -87,7 +87,7 @@ void setVirtualKeyboardVisible(bool visible)
const std::lock_guard lock(states.mutex); const std::lock_guard lock(states.mutex);
// Initializes JNI // Initializes JNI
jint lFlags = 0; const jint lFlags = 0;
JavaVM* lJavaVM = states.activity->vm; JavaVM* lJavaVM = states.activity->vm;
JNIEnv* lJNIEnv = states.activity->env; JNIEnv* lJNIEnv = states.activity->env;
@ -97,7 +97,7 @@ void setVirtualKeyboardVisible(bool visible)
lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.name = "NativeThread";
lJavaVMAttachArgs.group = nullptr; lJavaVMAttachArgs.group = nullptr;
jint lResult = lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); const jint lResult = lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
if (lResult == JNI_ERR) if (lResult == JNI_ERR)
err() << "Failed to initialize JNI, couldn't switch the keyboard visibility" << std::endl; err() << "Failed to initialize JNI, couldn't switch the keyboard visibility" << std::endl;

View File

@ -100,7 +100,7 @@ bool SensorImpl::open(Sensor::Type sensor)
return false; return false;
// Get the minimum delay allowed between events // 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) // Set the event rate (not to consume too much battery)
ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, static_cast<std::int32_t>(minimumDelay.asMicroseconds())); ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, static_cast<std::int32_t>(minimumDelay.asMicroseconds()));
@ -151,7 +151,7 @@ const ASensor* SensorImpl::getDefaultSensor(Sensor::Type sensor)
ASENSOR_TYPE_LINEAR_ACCELERATION, ASENSOR_TYPE_LINEAR_ACCELERATION,
ASENSOR_TYPE_ORIENTATION}; ASENSOR_TYPE_ORIENTATION};
int type = types[sensor]; const int type = types[sensor];
// Retrieve the default sensor matching this type // Retrieve the default sensor matching this type
return ASensorManager_getDefaultSensor(sensorManager, type); return ASensorManager_getDefaultSensor(sensorManager, type);

View File

@ -232,7 +232,7 @@ void WindowImplAndroid::forwardEvent(const Event& event)
{ {
if (WindowImplAndroid::singleInstance != nullptr) if (WindowImplAndroid::singleInstance != nullptr)
{ {
ActivityStates& states = getActivity(); const ActivityStates& states = getActivity();
if (event.is<Event::FocusGained>()) if (event.is<Event::FocusGained>())
{ {
@ -267,12 +267,12 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
int handled = 0; int handled = 0;
std::int32_t type = AInputEvent_getType(inputEvent); const std::int32_t type = AInputEvent_getType(inputEvent);
if (type == AINPUT_EVENT_TYPE_KEY) if (type == AINPUT_EVENT_TYPE_KEY)
{ {
std::int32_t action = AKeyEvent_getAction(inputEvent); const std::int32_t action = AKeyEvent_getAction(inputEvent);
std::int32_t key = AKeyEvent_getKeyCode(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) && if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) &&
key != AKEYCODE_VOLUME_UP && key != AKEYCODE_VOLUME_DOWN) 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) 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) 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 // Retrieve everything we need to create this MotionEvent in Java
std::int64_t downTime = AMotionEvent_getDownTime(inputEvent); const std::int64_t downTime = AMotionEvent_getDownTime(inputEvent);
std::int64_t eventTime = AMotionEvent_getEventTime(inputEvent); const std::int64_t eventTime = AMotionEvent_getEventTime(inputEvent);
std::int32_t action = AMotionEvent_getAction(inputEvent); const std::int32_t action = AMotionEvent_getAction(inputEvent);
float x = AMotionEvent_getX(inputEvent, 0); const float x = AMotionEvent_getX(inputEvent, 0);
float y = AMotionEvent_getY(inputEvent, 0); const float y = AMotionEvent_getY(inputEvent, 0);
float pressure = AMotionEvent_getPressure(inputEvent, 0); const float pressure = AMotionEvent_getPressure(inputEvent, 0);
float size = AMotionEvent_getSize(inputEvent, 0); const float size = AMotionEvent_getSize(inputEvent, 0);
std::int32_t metaState = AMotionEvent_getMetaState(inputEvent); const std::int32_t metaState = AMotionEvent_getMetaState(inputEvent);
float xPrecision = AMotionEvent_getXPrecision(inputEvent); const float xPrecision = AMotionEvent_getXPrecision(inputEvent);
float yPrecision = AMotionEvent_getYPrecision(inputEvent); const float yPrecision = AMotionEvent_getYPrecision(inputEvent);
std::int32_t deviceId = AInputEvent_getDeviceId(inputEvent); const std::int32_t deviceId = AInputEvent_getDeviceId(inputEvent);
std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(inputEvent); const std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(inputEvent);
// Create the MotionEvent object in Java through its static constructor obtain() // Create the MotionEvent object in Java through its static constructor obtain()
jclass classMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent"); jclass classMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent");
@ -385,8 +385,8 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityState
edgeFlags); edgeFlags);
// Call its getAxisValue() method to get the delta value of our wheel move event // Call its getAxisValue() method to get the delta value of our wheel move event
jmethodID methodGetAxisValue = lJNIEnv->GetMethodID(classMotionEvent, "getAxisValue", "(I)F"); jmethodID methodGetAxisValue = lJNIEnv->GetMethodID(classMotionEvent, "getAxisValue", "(I)F");
jfloat delta = lJNIEnv->CallFloatMethod(objectMotionEvent, methodGetAxisValue, 0x00000001); const jfloat delta = lJNIEnv->CallFloatMethod(objectMotionEvent, methodGetAxisValue, 0x00000001);
lJNIEnv->DeleteLocalRef(classMotionEvent); lJNIEnv->DeleteLocalRef(classMotionEvent);
lJNIEnv->DeleteLocalRef(objectMotionEvent); lJNIEnv->DeleteLocalRef(objectMotionEvent);
@ -408,10 +408,10 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityState
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates& /* states */) 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); const std::int32_t key = AKeyEvent_getKeyCode(inputEvent);
std::int32_t metakey = AKeyEvent_getMetaState(inputEvent); const std::int32_t metakey = AKeyEvent_getMetaState(inputEvent);
Event::KeyChanged keyChanged; Event::KeyChanged keyChanged;
keyChanged.code = androidKeyToSF(key); keyChanged.code = androidKeyToSF(key);
@ -448,7 +448,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates&
{ {
const Event event(Event::TextEntered{static_cast<std::uint32_t>(unicode)}); const Event event(Event::TextEntered{static_cast<std::uint32_t>(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) for (std::int32_t i = 0; i < repeats; ++i)
forwardEvent(event); forwardEvent(event);
return 1; return 1;
@ -462,7 +462,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates&
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityStates& states) int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityStates& states)
{ {
std::int32_t device = AInputEvent_getSource(inputEvent); const std::int32_t device = AInputEvent_getSource(inputEvent);
Event event; Event event;
@ -471,11 +471,11 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityState
else if (static_cast<std::uint32_t>(device) & AINPUT_SOURCE_TOUCHSCREEN) else if (static_cast<std::uint32_t>(device) & AINPUT_SOURCE_TOUCHSCREEN)
event = Event::TouchMoved{}; 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) 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<int>(AMotionEvent_getX(inputEvent, p)); int x = static_cast<int>(AMotionEvent_getX(inputEvent, p));
int y = static_cast<int>(AMotionEvent_getY(inputEvent, p)); int y = static_cast<int>(AMotionEvent_getY(inputEvent, p));
@ -507,12 +507,12 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* inputEvent, ActivityState
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* inputEvent, ActivityStates& states) int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* inputEvent, ActivityStates& states)
{ {
std::int32_t device = AInputEvent_getSource(inputEvent); const std::int32_t device = AInputEvent_getSource(inputEvent);
std::int32_t action = AMotionEvent_getAction(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; const 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 std::int32_t id = AMotionEvent_getPointerId(inputEvent, index);
const auto button = static_cast<Mouse::Button>(id); const auto button = static_cast<Mouse::Button>(id);
int x = static_cast<int>(AMotionEvent_getX(inputEvent, index)); int x = static_cast<int>(AMotionEvent_getX(inputEvent, index));
int y = static_cast<int>(AMotionEvent_getY(inputEvent, index)); int y = static_cast<int>(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; err() << "Failed to initialize JNI, couldn't get the Unicode value" << std::endl;
// Retrieve key data from the input event // Retrieve key data from the input event
jlong downTime = AKeyEvent_getDownTime(event); const jlong downTime = AKeyEvent_getDownTime(event);
jlong eventTime = AKeyEvent_getEventTime(event); const jlong eventTime = AKeyEvent_getEventTime(event);
jint action = AKeyEvent_getAction(event); const jint action = AKeyEvent_getAction(event);
jint code = AKeyEvent_getKeyCode(event); const jint code = AKeyEvent_getKeyCode(event);
jint repeat = AKeyEvent_getRepeatCount(event); // not sure! const jint repeat = AKeyEvent_getRepeatCount(event); // not sure!
jint metaState = AKeyEvent_getMetaState(event); const jint metaState = AKeyEvent_getMetaState(event);
jint deviceId = AInputEvent_getDeviceId(event); const jint deviceId = AInputEvent_getDeviceId(event);
jint scancode = AKeyEvent_getScanCode(event); const jint scancode = AKeyEvent_getScanCode(event);
jint flags = AKeyEvent_getFlags(event); const jint flags = AKeyEvent_getFlags(event);
jint source = AInputEvent_getSource(event); const jint source = AInputEvent_getSource(event);
// Construct a KeyEvent object from the event data // Construct a KeyEvent object from the event data
jclass classKeyEvent = lJNIEnv->FindClass("android/view/KeyEvent"); 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 // Call its getUnicodeChar() method to get the Unicode value
jmethodID methodGetUnicode = lJNIEnv->GetMethodID(classKeyEvent, "getUnicodeChar", "(I)I"); 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(classKeyEvent);
lJNIEnv->DeleteLocalRef(objectKeyEvent); lJNIEnv->DeleteLocalRef(objectKeyEvent);