mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-09 21:55:29 +02:00
Start working on central object to track state
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
48
kitty/state.c
Normal file
48
kitty/state.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* state.c
|
||||
* Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
// }}}
|
||||
Reference in New Issue
Block a user