mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-20 07:24:41 +02:00
Move the text input callback to C
This commit is contained in:
29
kitty/keys.c
29
kitty/keys.c
@@ -6,7 +6,8 @@
|
||||
*/
|
||||
|
||||
#include "keys.h"
|
||||
#include "data-types.h"
|
||||
#include "state.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
const uint8_t*
|
||||
key_to_bytes(int glfw_key, bool smkx, bool extended, int mods, int action) {
|
||||
@@ -29,6 +30,32 @@ set_special_key_combo(int glfw_key, int mods) {
|
||||
needs_special_handling[k] = true;
|
||||
}
|
||||
|
||||
static inline Window*
|
||||
active_window() {
|
||||
Tab *t = global_state.tabs + global_state.active_tab;
|
||||
Window *w = t->windows + t->active_window;
|
||||
if (w->render_data.screen) return w;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
on_text_input(unsigned int codepoint, int mods) {
|
||||
Window *w = active_window();
|
||||
static char buf[10];
|
||||
|
||||
if (w != NULL) {
|
||||
Screen *screen = w->render_data.screen;
|
||||
bool handle_event = (
|
||||
mods <= GLFW_MOD_SHIFT ||
|
||||
(!screen->modes.mEXTENDED_KEYBOARD && (mods == GLFW_MOD_ALT || mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT)))
|
||||
) ? true : false; // non text input is handle in on_key_input
|
||||
if (handle_event) {
|
||||
unsigned int sz = encode_utf8(codepoint, buf);
|
||||
if (sz) schedule_write_to_child(w->id, buf, sz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define PYWRAP1(name) static PyObject* py##name(PyObject UNUSED *self, PyObject *args)
|
||||
#define PA(fmt, ...) if(!PyArg_ParseTuple(args, fmt, __VA_ARGS__)) return NULL;
|
||||
#define M(name, arg_type) {#name, (PyCFunction)py##name, arg_type, NULL}
|
||||
|
||||
Reference in New Issue
Block a user