mirror of
https://github.com/patchzyy/wiicompiled
synced 2026-10-21 22:04:15 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d7fe7450c |
@@ -7,7 +7,6 @@
|
||||
#include "memory.h"
|
||||
#include "runtime_product.h"
|
||||
|
||||
#include <SDL3/SDL_clipboard.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
|
||||
#include <atomic>
|
||||
@@ -28,32 +27,11 @@ constexpr uint32_t kPageStateActive = 4;
|
||||
constexpr uint32_t kVtableGetTypeInfoOffset = 0x60;
|
||||
constexpr int kBackspace = -1;
|
||||
constexpr size_t kMaxPendingKeys = 32;
|
||||
constexpr size_t kFriendCodeDigits = 12;
|
||||
|
||||
std::mutex g_pendingMutex;
|
||||
std::vector<int> g_pending;
|
||||
std::atomic_bool g_pageFocused{false};
|
||||
|
||||
bool IsPaste(const SDL_KeyboardEvent& key) {
|
||||
return !key.repeat && key.key == SDLK_V && (key.mod & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) != 0 &&
|
||||
(key.mod & SDL_KMOD_ALT) == 0;
|
||||
}
|
||||
|
||||
void AppendClipboardDigits(std::vector<int>& keys) {
|
||||
char* text = SDL_GetClipboardText();
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
size_t digits = 0;
|
||||
for (const char* c = text; *c && digits < kFriendCodeDigits; ++c) {
|
||||
if (*c >= '0' && *c <= '9') {
|
||||
keys.push_back(*c - '0');
|
||||
++digits;
|
||||
}
|
||||
}
|
||||
SDL_free(text);
|
||||
}
|
||||
|
||||
std::optional<int> KeyValue(const SDL_KeyboardEvent& key) {
|
||||
if ((key.mod & (SDL_KMOD_CTRL | SDL_KMOD_ALT | SDL_KMOD_GUI)) != 0) {
|
||||
return std::nullopt;
|
||||
@@ -120,27 +98,16 @@ void HandleEvents(const AuroraEvent* events) noexcept {
|
||||
if (!events || !g_pageFocused.load(std::memory_order_acquire) || InputBindings::InputBlocked()) {
|
||||
return;
|
||||
}
|
||||
std::vector<int> keys;
|
||||
std::lock_guard lock(g_pendingMutex);
|
||||
for (const AuroraEvent* ev = events; ev->type != AURORA_NONE; ++ev) {
|
||||
if (ev->type != AURORA_SDL_EVENT || ev->sdl.type != SDL_EVENT_KEY_DOWN) {
|
||||
continue;
|
||||
}
|
||||
if (IsPaste(ev->sdl.key)) {
|
||||
AppendClipboardDigits(keys);
|
||||
} else if (const std::optional<int> key = KeyValue(ev->sdl.key)) {
|
||||
keys.push_back(*key);
|
||||
const std::optional<int> key = KeyValue(ev->sdl.key);
|
||||
if (key && g_pending.size() < kMaxPendingKeys) {
|
||||
g_pending.push_back(*key);
|
||||
}
|
||||
}
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard lock(g_pendingMutex);
|
||||
for (const int key : keys) {
|
||||
if (g_pending.size() >= kMaxPendingKeys) {
|
||||
break;
|
||||
}
|
||||
g_pending.push_back(key);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace FriendCodeKeyboard
|
||||
|
||||
Reference in New Issue
Block a user