Fix conversion of background_image option to C
Should handle None and not rely on the python object's lifetime. Also some miscellaneous cleanups.
This commit is contained in:
parent
1bc5d7038d
commit
ee53edd96d
@ -848,7 +848,7 @@ default as it has a performance cost)
|
||||
'''))
|
||||
|
||||
|
||||
def startup_session(x):
|
||||
def config_or_absolute_path(x):
|
||||
if x.lower() == 'none':
|
||||
return
|
||||
x = os.path.expanduser(x)
|
||||
@ -858,8 +858,8 @@ def startup_session(x):
|
||||
return x
|
||||
|
||||
|
||||
o('background_image', 'none', option_type=startup_session, long_text=_('''
|
||||
Path to a background image. Must be PNG.'''))
|
||||
o('background_image', 'none', option_type=config_or_absolute_path, long_text=_('''
|
||||
Path to a background image. Must be in PNG format.'''))
|
||||
|
||||
o('background_image_layout', 'tiling', option_type=choices('tiling', 'scaled', 'mirror_tiled'), long_text=_('''
|
||||
Whether to tile or scale the background image.'''))
|
||||
@ -995,7 +995,7 @@ The default is to check every 24 hrs, set to zero to disable.
|
||||
'''))
|
||||
|
||||
|
||||
o('startup_session', 'none', option_type=startup_session, long_text=_('''
|
||||
o('startup_session', 'none', option_type=config_or_absolute_path, long_text=_('''
|
||||
Path to a session file to use for all kitty instances. Can be overridden
|
||||
by using the :option:`kitty --session` command line option for individual
|
||||
instances. See :ref:`sessions` in the kitty documentation for details. Note
|
||||
|
||||
@ -332,7 +332,7 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa
|
||||
return changed;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
draw_bg(int program, OSWindow *w) {
|
||||
if (w->bvao_idx == 0) {
|
||||
const GLfloat screenrect[4][2] = {
|
||||
@ -345,7 +345,7 @@ draw_bg(int program, OSWindow *w) {
|
||||
bind_vertex_array(w->bvao_idx);
|
||||
glGenBuffers(1, &w->vbo_idx);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, w->vbo_idx);
|
||||
glBufferData(GL_ARRAY_BUFFER, 4*2*sizeof(float), screenrect, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(screenrect), screenrect, GL_STATIC_DRAW);
|
||||
}
|
||||
bind_vertex_array(w->bvao_idx);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, w->vbo_idx);
|
||||
|
||||
@ -82,7 +82,7 @@ add_os_window() {
|
||||
ans->gvao_idx = create_graphics_vao();
|
||||
ans->background_opacity = OPT(background_opacity);
|
||||
|
||||
bool wants_bg = OPT(background_image) != NULL;
|
||||
bool wants_bg = OPT(background_image) && OPT(background_image)[0] != 0;
|
||||
if (wants_bg) {
|
||||
bool has_bg;
|
||||
has_bg = global_state.bgimage != NULL;
|
||||
@ -450,7 +450,8 @@ window_title_in(PyObject *title_in) {
|
||||
return ALL;
|
||||
}
|
||||
|
||||
static BackgroundImageLayout bglayout(PyObject *layout_name) {
|
||||
static BackgroundImageLayout
|
||||
bglayout(PyObject *layout_name) {
|
||||
const char *name = PyUnicode_AsUTF8(layout_name);
|
||||
switch(name[0]) {
|
||||
case 't': return TILING;
|
||||
@ -461,6 +462,18 @@ static BackgroundImageLayout bglayout(PyObject *layout_name) {
|
||||
return TILING;
|
||||
}
|
||||
|
||||
static void
|
||||
background_image(PyObject *src) {
|
||||
if (OPT(background_image)) free(OPT(background_image));
|
||||
OPT(background_image) = NULL;
|
||||
if (src == Py_None || !PyUnicode_Check(src)) return;
|
||||
Py_ssize_t sz;
|
||||
const char *s = PyUnicode_AsUTF8AndSize(src, &sz);
|
||||
OPT(background_image) = calloc(sz + 1, 1);
|
||||
if (OPT(background_image)) memcpy(OPT(background_image), s, sz);
|
||||
}
|
||||
|
||||
|
||||
static MouseShape
|
||||
pointer_shape(PyObject *shape_name) {
|
||||
const char *name = PyUnicode_AsUTF8(shape_name);
|
||||
@ -532,7 +545,6 @@ PYWRAP1(set_options) {
|
||||
S(background_image_opacity, PyFloat_AsFloat);
|
||||
S(background_image_scale, PyFloat_AsFloat);
|
||||
S(background_image_layout, bglayout);
|
||||
S(background_image, (char*)PyUnicode_AsUTF8);
|
||||
S(background_image_linear, PyObject_IsTrue);
|
||||
S(dim_opacity, PyFloat_AsFloat);
|
||||
S(dynamic_background_opacity, PyObject_IsTrue);
|
||||
@ -601,6 +613,8 @@ PYWRAP1(set_options) {
|
||||
GA(sequence_map); set_special_keys(ret);
|
||||
Py_DECREF(ret); if (PyErr_Occurred()) return NULL;
|
||||
|
||||
GA(background_image); background_image(ret); Py_CLEAR(ret);
|
||||
|
||||
#define read_adjust(name) { \
|
||||
PyObject *al = PyObject_GetAttrString(opts, #name); \
|
||||
if (PyFloat_Check(al)) { \
|
||||
@ -945,6 +959,7 @@ finalize(void) {
|
||||
}
|
||||
if (detached_windows.windows) free(detached_windows.windows);
|
||||
detached_windows.capacity = 0;
|
||||
if (OPT(background_image)) free(OPT(background_image));
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user