mirror of
https://github.com/InstanceBrick/nightcap.git
synced 2026-10-17 15:00:47 +02:00
chore(merge): merge upstream komaruworld/mocktail main
This commit is contained in:
commit
a9d8e3185e
6 files changed
+48
-20
No files matched your search
@@ -40,9 +40,10 @@ struct AndroidKeyMapping {
|
||||
// through with an ABI-incompatible numeric value.
|
||||
AndroidKeyMapping MapSdlKeyToAndroid(uint32_t sdl_scancode, uint32_t sdl_key = 0);
|
||||
|
||||
// Mirrors the APK's MotionEvent.getActionButton() - 1 conversion. SDL button
|
||||
// numbers are not numerically compatible with Android button bit values.
|
||||
int32_t MapSdlMouseButtonToAndroid(uint8_t sdl_button);
|
||||
// Translates SDL button numbers to the nativePassMouseButton argument.
|
||||
// The first three are Roblox's zero-based MouseButton1/2/3 indices, not Android
|
||||
// MotionEvent button bits.
|
||||
int32_t MapSdlMouseButtonToRoblox(uint8_t sdl_button);
|
||||
|
||||
int32_t MapSdlGamepadButtonToAndroid(uint8_t sdl_button);
|
||||
int32_t RobloxGamepadType(platform::GamepadFamily family);
|
||||
|
||||
+5
-1
@@ -1650,9 +1650,13 @@ jlong ParseLocalStorageUserIdFromEnv() {
|
||||
if (!value || value[0] == '\0') {
|
||||
return 0;
|
||||
}
|
||||
errno = 0;
|
||||
char* end = nullptr;
|
||||
long long parsed = std::strtoll(value, &end, 10);
|
||||
return end == value ? 0 : static_cast<jlong>(parsed);
|
||||
if (errno == ERANGE || end == value || *end != '\0') {
|
||||
return 0;
|
||||
}
|
||||
return static_cast<jlong>(parsed);
|
||||
}
|
||||
|
||||
jlong CurrentLocalStorageUserLocked() {
|
||||
|
||||
@@ -274,14 +274,15 @@ AndroidKeyMapping MapSdlKeyToAndroid(uint32_t sdl_scancode,
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t MapSdlMouseButtonToAndroid(uint8_t sdl_button) {
|
||||
int32_t MapSdlMouseButtonToRoblox(uint8_t sdl_button) {
|
||||
switch (sdl_button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
return 0;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
return 1;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
return 3;
|
||||
// MouseButton3 is index 2, not BUTTON_TERTIARY (4) minus one.
|
||||
return 2;
|
||||
case SDL_BUTTON_X1:
|
||||
return 7;
|
||||
case SDL_BUTTON_X2:
|
||||
@@ -586,11 +587,11 @@ RobloxInputDispatchResult RobloxInputRouter::HandleMouseButtonLocked(
|
||||
RobloxInputEventKind::kMouseButton,
|
||||
Unsupported("native mouse buttons are unavailable"));
|
||||
}
|
||||
const int32_t android_button = MapSdlMouseButtonToAndroid(event.button);
|
||||
if (android_button < 0) {
|
||||
const int32_t roblox_button = MapSdlMouseButtonToRoblox(event.button);
|
||||
if (roblox_button < 0) {
|
||||
return Result(RobloxInputDispatchState::kIgnoredUnsupported,
|
||||
RobloxInputEventKind::kMouseButton,
|
||||
Unsupported("SDL mouse button has no Android mapping"));
|
||||
Unsupported("SDL mouse button has no Roblox mapping"));
|
||||
}
|
||||
const platform::SurfaceCoordinateTransform transform =
|
||||
CoordinateTransform(snapshot_.viewport);
|
||||
@@ -616,12 +617,12 @@ RobloxInputDispatchResult RobloxInputRouter::HandleMouseButtonLocked(
|
||||
}
|
||||
}
|
||||
Status status = sink_.mouse_button(sink_.context, clamped_x, clamped_y,
|
||||
event.pressed, android_button);
|
||||
event.pressed, roblox_button);
|
||||
if (status.ok()) {
|
||||
const auto active = std::find(active_mouse_buttons_.begin(),
|
||||
active_mouse_buttons_.end(), android_button);
|
||||
active_mouse_buttons_.end(), roblox_button);
|
||||
if (event.pressed && active == active_mouse_buttons_.end()) {
|
||||
active_mouse_buttons_.push_back(android_button);
|
||||
active_mouse_buttons_.push_back(roblox_button);
|
||||
} else if (!event.pressed && active != active_mouse_buttons_.end()) {
|
||||
active_mouse_buttons_.erase(active);
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ TEST_F(RobloxInputNativeAdapterTest, CallsExactExportedJniSignatures) {
|
||||
(std::vector<double>{90.0, 190.0, 4.0, -2.0}));
|
||||
EXPECT_EQ(probe_.calls[1].name, "mouse-button");
|
||||
EXPECT_EQ(probe_.calls[1].arguments,
|
||||
(std::vector<double>{100.0, 200.0, JNI_TRUE, 3.0}));
|
||||
(std::vector<double>{100.0, 200.0, JNI_TRUE, 2.0}));
|
||||
EXPECT_EQ(probe_.calls[2].name, "touch");
|
||||
EXPECT_EQ(probe_.calls[2].arguments,
|
||||
(std::vector<double>{0.0, 320.0, 360.0, 0.0, 1280.0, 720.0}));
|
||||
|
||||
@@ -170,13 +170,13 @@ class RobloxInputRouterTest : public ::testing::Test {
|
||||
RobloxInputRouter router_{Sink(&probe_)};
|
||||
};
|
||||
|
||||
TEST(RobloxInputMappingTest, MapsAndroidMouseButtonsExactlyLikeApk) {
|
||||
EXPECT_EQ(MapSdlMouseButtonToAndroid(SDL_BUTTON_LEFT), 0);
|
||||
EXPECT_EQ(MapSdlMouseButtonToAndroid(SDL_BUTTON_RIGHT), 1);
|
||||
EXPECT_EQ(MapSdlMouseButtonToAndroid(SDL_BUTTON_MIDDLE), 3);
|
||||
EXPECT_EQ(MapSdlMouseButtonToAndroid(SDL_BUTTON_X1), 7);
|
||||
EXPECT_EQ(MapSdlMouseButtonToAndroid(SDL_BUTTON_X2), 15);
|
||||
EXPECT_EQ(MapSdlMouseButtonToAndroid(42), -1);
|
||||
TEST(RobloxInputMappingTest, MapsMouseButtonsForNativeInput) {
|
||||
EXPECT_EQ(MapSdlMouseButtonToRoblox(SDL_BUTTON_LEFT), 0);
|
||||
EXPECT_EQ(MapSdlMouseButtonToRoblox(SDL_BUTTON_RIGHT), 1);
|
||||
EXPECT_EQ(MapSdlMouseButtonToRoblox(SDL_BUTTON_MIDDLE), 2);
|
||||
EXPECT_EQ(MapSdlMouseButtonToRoblox(SDL_BUTTON_X1), 7);
|
||||
EXPECT_EQ(MapSdlMouseButtonToRoblox(SDL_BUTTON_X2), 15);
|
||||
EXPECT_EQ(MapSdlMouseButtonToRoblox(42), -1);
|
||||
}
|
||||
|
||||
TEST(RobloxInputMappingTest, MapsSdlUsbKeysToLinuxAndAndroidCodes) {
|
||||
@@ -239,6 +239,7 @@ TEST_F(RobloxInputRouterTest, RoutesMouseMotionButtonAndVerticalWheel) {
|
||||
EXPECT_FLOAT_EQ(probe_.mouse_wheels[0].delta_y, -2.0f);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(RobloxInputRouterTest, HoldsPointerPositionDuringRelativeMotion) {
|
||||
// Relative-mode motion reports zero absolute coordinates. The pointer stays
|
||||
// where it was captured while the deltas pass through, so a long camera
|
||||
@@ -467,6 +468,25 @@ TEST_F(RobloxInputRouterTest, RawMouseSendsLookDeltasUnscaled) {
|
||||
EXPECT_NEAR(probe_.mouse_moves[0].y,
|
||||
(transform.guest_height() - 1.0F) / 2.0F, 0.01f);
|
||||
}
|
||||
TEST_F(RobloxInputRouterTest, MiddleClickUsesMouseButton3OnPressAndRelease) {
|
||||
ASSERT_TRUE(router_
|
||||
.HandleEvent(Event(platform::MouseButtonEvent{
|
||||
true, SDL_BUTTON_MIDDLE, 1, 100.0f, 80.0f}))
|
||||
.dispatched());
|
||||
EXPECT_EQ(router_.Snapshot().active_mouse_buttons, 1U);
|
||||
ASSERT_TRUE(router_
|
||||
.HandleEvent(Event(platform::MouseButtonEvent{
|
||||
false, SDL_BUTTON_MIDDLE, 1, 100.0f, 80.0f}))
|
||||
.dispatched());
|
||||
|
||||
ASSERT_EQ(probe_.mouse_buttons.size(), 2U);
|
||||
EXPECT_TRUE(probe_.mouse_buttons[0].pressed);
|
||||
EXPECT_EQ(probe_.mouse_buttons[0].button, 2);
|
||||
EXPECT_FALSE(probe_.mouse_buttons[1].pressed);
|
||||
EXPECT_EQ(probe_.mouse_buttons[1].button, 2);
|
||||
EXPECT_EQ(router_.Snapshot().active_mouse_buttons, 0U);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(RobloxInputRouterTest,
|
||||
ScalesMouseCoordinatesAfterDisplayScaleChange) {
|
||||
|
||||
@@ -594,6 +594,7 @@ TEST(RobloxTextDisplayStateTest, AdvancesCaretForTrailingSpace) {
|
||||
EXPECT_TRUE(overlay.Shutdown().ok());
|
||||
}
|
||||
|
||||
|
||||
TEST(RobloxTextDisplayStateTest, KeepsCaretBeforeTrailingSpaceDistinct) {
|
||||
RobloxTextSurfaceOverlay overlay;
|
||||
ASSERT_TRUE(overlay.Initialize({800, 600}).ok());
|
||||
@@ -648,6 +649,7 @@ TEST(RobloxTextDisplayStateTest, ReopensFontsAfterPointSizeChange) {
|
||||
EXPECT_TRUE(overlay.Shutdown().ok());
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
} // namespace runtime
|
||||
} // namespace mocktail
|
||||
Reference in new issue
Block a user