diff --git a/kitty/data-types.c b/kitty/data-types.c index 1658ba115..664858a2c 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -98,6 +98,7 @@ extern bool init_freetype_library(PyObject*); extern bool init_fontconfig_library(PyObject*); extern bool init_glfw(PyObject *m); extern bool init_sprites(PyObject *module); +extern bool init_state(PyObject *module); extern bool init_shaders(PyObject *module); extern bool init_shaders_debug(PyObject *module); #ifdef __APPLE__ @@ -124,6 +125,7 @@ PyInit_fast_data_types(void) { if (!init_Screen(m)) return NULL; if (!init_glfw(m)) return NULL; if (!init_sprites(m)) return NULL; + if (!init_state(m)) return NULL; if (PySys_GetObject("debug_gl") == Py_True) { if (!init_shaders_debug(m)) return NULL; } else { diff --git a/kitty/main.py b/kitty/main.py index 96e6e3a0c..30bcb7214 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -23,7 +23,7 @@ from .fast_data_types import ( GLFW_STENCIL_BITS, Window, change_wcwidth, check_for_extensions, clear_buffers, glewInit, glfw_init, glfw_init_hint_string, glfw_set_error_callback, glfw_swap_interval, glfw_terminate, - glfw_window_hint + glfw_window_hint, set_options ) from .layout import all_layouts from .utils import color_as_int, detach, safe_print @@ -154,6 +154,7 @@ def setup_opengl(opts): def run_app(opts, args): + set_options(opts) setup_opengl(opts) load_cached_values() if 'window-size' in cached_values and opts.remember_window_size: diff --git a/kitty/state.c b/kitty/state.c new file mode 100644 index 000000000..2b24c3ff2 --- /dev/null +++ b/kitty/state.c @@ -0,0 +1,48 @@ +/* + * state.c + * Copyright (C) 2017 Kovid Goyal + * + * Distributed under terms of the GPL3 license. + */ + +#include "data-types.h" + +#define PYWRAP0(name) static PyObject* py##name(PyObject UNUSED *self) +#define PYWRAP1(name) static PyObject* py##name(PyObject UNUSED *self, PyObject *args) +#define PYWRAP2(name) static PyObject* py##name(PyObject UNUSED *self, PyObject *args, PyObject *kw) +#define PA(fmt, ...) if(!PyArg_ParseTuple(args, fmt, __VA_ARGS__)) return NULL; + +typedef struct { + double visual_bell_duration; +} Options; + +typedef struct { + Options opts; +} GlobalState; + +static GlobalState global_state = {{0}}; + + +// Python API {{{ +PYWRAP1(set_options) { +#define S(name, convert) { PyObject *ret = PyObject_GetAttrString(args, #name); if (ret == NULL) return NULL; global_state.opts.name = convert(ret); Py_DECREF(ret); } + S(visual_bell_duration, PyFloat_AsDouble); +#undef S + Py_RETURN_NONE; +} + +#define M(name, arg_type) {#name, (PyCFunction)name, arg_type, NULL} +#define MW(name, arg_type) {#name, (PyCFunction)py##name, arg_type, NULL} +static PyMethodDef module_methods[] = { + MW(set_options, METH_O), + + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + + +bool +init_state(PyObject *module) { + if (PyModule_AddFunctions(module, module_methods) != 0) return false; + return true; +} +// }}}