Remove the function used to init glfw key events
Instead use C99 struct initializers. Much less error prone.
This commit is contained in:
parent
027c5a57f1
commit
abc1e3f289
@ -983,8 +983,7 @@ is_ascii_control_char(char x) {
|
|||||||
const bool process_text = !window->ns.textInputFilterCallback || window->ns.textInputFilterCallback(key, mods, keycode, flags) != 1;
|
const bool process_text = !window->ns.textInputFilterCallback || window->ns.textInputFilterCallback(key, mods, keycode, flags) != 1;
|
||||||
[self unmarkText];
|
[self unmarkText];
|
||||||
_glfw.ns.text[0] = 0;
|
_glfw.ns.text[0] = 0;
|
||||||
GLFWkeyevent glfw_keyevent;
|
GLFWkeyevent glfw_keyevent = {.key = key, .native_key = keycode, .action = GLFW_PRESS, .mods = mods};
|
||||||
_glfwInitializeKeyEvent(&glfw_keyevent, key, keycode, GLFW_PRESS, mods);
|
|
||||||
if (!_glfw.ns.unicodeData) {
|
if (!_glfw.ns.unicodeData) {
|
||||||
// Using the cocoa API for key handling is disabled, as there is no
|
// Using the cocoa API for key handling is disabled, as there is no
|
||||||
// reliable way to handle dead keys using it. Only use it if the
|
// reliable way to handle dead keys using it. Only use it if the
|
||||||
@ -1092,8 +1091,7 @@ is_ascii_control_char(char x) {
|
|||||||
action = GLFW_PRESS;
|
action = GLFW_PRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWkeyevent glfw_keyevent;
|
GLFWkeyevent glfw_keyevent = {.key = key, .native_key = [event keyCode], .action = action, .mods = mods};
|
||||||
_glfwInitializeKeyEvent(&glfw_keyevent, key, [event keyCode], action, mods);
|
|
||||||
_glfwInputKeyboard(window, &glfw_keyevent);
|
_glfwInputKeyboard(window, &glfw_keyevent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1102,8 +1100,7 @@ is_ascii_control_char(char x) {
|
|||||||
const int key = translateKey([event keyCode], true);
|
const int key = translateKey([event keyCode], true);
|
||||||
const int mods = translateFlags([event modifierFlags]);
|
const int mods = translateFlags([event modifierFlags]);
|
||||||
|
|
||||||
GLFWkeyevent glfw_keyevent;
|
GLFWkeyevent glfw_keyevent = {.key = key, .native_key = [event keyCode], .action = GLFW_RELEASE, .mods = mods};
|
||||||
_glfwInitializeKeyEvent(&glfw_keyevent, key, [event keyCode], GLFW_RELEASE, mods);
|
|
||||||
_glfwInputKeyboard(window, &glfw_keyevent);
|
_glfwInputKeyboard(window, &glfw_keyevent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
glfw/ibus_glfw.c
vendored
3
glfw/ibus_glfw.c
vendored
@ -110,8 +110,7 @@ static inline void
|
|||||||
send_text(const char *text, int ime_state) {
|
send_text(const char *text, int ime_state) {
|
||||||
_GLFWwindow *w = _glfwFocusedWindow();
|
_GLFWwindow *w = _glfwFocusedWindow();
|
||||||
if (w && w->callbacks.keyboard) {
|
if (w && w->callbacks.keyboard) {
|
||||||
GLFWkeyevent fake_ev;
|
GLFWkeyevent fake_ev = {.action = GLFW_PRESS};
|
||||||
_glfwInitializeKeyEvent(&fake_ev, 0, 0, GLFW_PRESS, 0);
|
|
||||||
fake_ev.text = text;
|
fake_ev.text = text;
|
||||||
fake_ev.ime_state = ime_state;
|
fake_ev.ime_state = ime_state;
|
||||||
w->callbacks.keyboard((GLFWwindow*) w, &fake_ev);
|
w->callbacks.keyboard((GLFWwindow*) w, &fake_ev);
|
||||||
|
|||||||
10
glfw/input.c
vendored
10
glfw/input.c
vendored
@ -273,16 +273,6 @@ static bool parseMapping(_GLFWmapping* mapping, const char* string)
|
|||||||
////// GLFW event API //////
|
////// GLFW event API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void _glfwInitializeKeyEvent(GLFWkeyevent *ev, int key, int native_key, int action, int mods)
|
|
||||||
{
|
|
||||||
ev->key = key;
|
|
||||||
ev->native_key = native_key;
|
|
||||||
ev->action = action;
|
|
||||||
ev->mods = mods;
|
|
||||||
ev->text = NULL;
|
|
||||||
ev->ime_state = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_key_action(_GLFWwindow *window, uint32_t key, int val, int idx) {
|
set_key_action(_GLFWwindow *window, uint32_t key, int val, int idx) {
|
||||||
const unsigned sz = arraysz(window->activated_keys);
|
const unsigned sz = arraysz(window->activated_keys);
|
||||||
|
|||||||
1
glfw/internal.h
vendored
1
glfw/internal.h
vendored
@ -776,7 +776,6 @@ void _glfwInputWindowDamage(_GLFWwindow* window);
|
|||||||
void _glfwInputWindowCloseRequest(_GLFWwindow* window);
|
void _glfwInputWindowCloseRequest(_GLFWwindow* window);
|
||||||
void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor);
|
void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor);
|
||||||
|
|
||||||
void _glfwInitializeKeyEvent(GLFWkeyevent *ev, int key, int native_key, int action, int mods);
|
|
||||||
void _glfwInputKeyboard(_GLFWwindow *window, GLFWkeyevent *ev);
|
void _glfwInputKeyboard(_GLFWwindow *window, GLFWkeyevent *ev);
|
||||||
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags, int mods);
|
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags, int mods);
|
||||||
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
|
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
|
||||||
|
|||||||
3
glfw/window.c
vendored
3
glfw/window.c
vendored
@ -57,8 +57,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, bool focused)
|
|||||||
if (window->activated_keys[i].key > 0 && window->activated_keys[i].action == GLFW_PRESS)
|
if (window->activated_keys[i].key > 0 && window->activated_keys[i].action == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
const int native_key = _glfwPlatformGetNativeKeyForKey(window->activated_keys[i].key);
|
const int native_key = _glfwPlatformGetNativeKeyForKey(window->activated_keys[i].key);
|
||||||
GLFWkeyevent ev;
|
GLFWkeyevent ev = {.key = window->activated_keys[i].key, .native_key = native_key, .action = GLFW_RELEASE};
|
||||||
_glfwInitializeKeyEvent(&ev, window->activated_keys[i].key, native_key, GLFW_RELEASE, 0);
|
|
||||||
_glfwInputKeyboard(window, &ev);
|
_glfwInputKeyboard(window, &ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
glfw/xkb_glfw.c
vendored
6
glfw/xkb_glfw.c
vendored
@ -557,8 +557,7 @@ glfw_xkb_key_from_ime(_GLFWIBUSKeyEvent *ev, bool handled_by_ime, bool failed) {
|
|||||||
_GLFWwindow *window = _glfwWindowForId(ev->window_id);
|
_GLFWwindow *window = _glfwWindowForId(ev->window_id);
|
||||||
if (failed && window && window->callbacks.keyboard) {
|
if (failed && window && window->callbacks.keyboard) {
|
||||||
// notify application to remove any existing pre-edit text
|
// notify application to remove any existing pre-edit text
|
||||||
GLFWkeyevent fake_ev;
|
GLFWkeyevent fake_ev = {.action = GLFW_PRESS};
|
||||||
_glfwInitializeKeyEvent(&fake_ev, 0, 0, GLFW_PRESS, 0);
|
|
||||||
fake_ev.ime_state = 1;
|
fake_ev.ime_state = 1;
|
||||||
window->callbacks.keyboard((GLFWwindow*) window, &fake_ev);
|
window->callbacks.keyboard((GLFWwindow*) window, &fake_ev);
|
||||||
}
|
}
|
||||||
@ -591,8 +590,7 @@ glfw_xkb_handle_key_event(_GLFWwindow *window, _GLFWXKBData *xkb, xkb_keycode_t
|
|||||||
const xkb_keysym_t *syms, *clean_syms, *default_syms;
|
const xkb_keysym_t *syms, *clean_syms, *default_syms;
|
||||||
xkb_keysym_t xkb_sym;
|
xkb_keysym_t xkb_sym;
|
||||||
xkb_keycode_t code_for_sym = xkb_keycode, ibus_keycode = xkb_keycode;
|
xkb_keycode_t code_for_sym = xkb_keycode, ibus_keycode = xkb_keycode;
|
||||||
GLFWkeyevent glfw_ev;
|
GLFWkeyevent glfw_ev = {.action = GLFW_PRESS};
|
||||||
_glfwInitializeKeyEvent(&glfw_ev, 0, 0, GLFW_PRESS, 0); // init with default values
|
|
||||||
#ifdef _GLFW_WAYLAND
|
#ifdef _GLFW_WAYLAND
|
||||||
code_for_sym += 8;
|
code_for_sym += 8;
|
||||||
#else
|
#else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user