mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-14 12:11:12 +03:00
Make argument handling of create_os_window() to be more robust and match its python signature
This commit is contained in:
parent
1593baa9f9
commit
bea8fd25a7
@ -514,9 +514,9 @@ def create_os_window(
|
||||
wm_class_class: str,
|
||||
window_state: Optional[int] = WINDOW_NORMAL,
|
||||
load_programs: Optional[Callable[[bool], None]] = None,
|
||||
x: Optional[int] = -1,
|
||||
y: Optional[int] = -1,
|
||||
disallow_override_title: Optional[bool] = False,
|
||||
x: Optional[int] = None,
|
||||
y: Optional[int] = None,
|
||||
disallow_override_title: bool = False,
|
||||
) -> int:
|
||||
pass
|
||||
|
||||
|
14
kitty/glfw.c
14
kitty/glfw.c
@ -1040,13 +1040,15 @@ native_window_handle(GLFWwindow *w) {
|
||||
|
||||
static PyObject*
|
||||
create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
|
||||
int x = -1, y = -1, window_state = WINDOW_NORMAL, disallow_override_title = 0;
|
||||
int x = INT_MIN, y = INT_MIN, window_state = WINDOW_NORMAL, disallow_override_title = 0;
|
||||
char *title, *wm_class_class, *wm_class_name;
|
||||
PyObject *optional_window_state = NULL, *load_programs = NULL, *get_window_size, *pre_show_callback;
|
||||
PyObject *optional_window_state = NULL, *load_programs = NULL, *get_window_size, *pre_show_callback, *optional_x = NULL, *optional_y = NULL;
|
||||
static const char* kwlist[] = {"get_window_size", "pre_show_callback", "title", "wm_class_name", "wm_class_class", "window_state", "load_programs", "x", "y", "disallow_override_title", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "OOsss|OOiip", (char**)kwlist,
|
||||
&get_window_size, &pre_show_callback, &title, &wm_class_name, &wm_class_class, &optional_window_state, &load_programs, &x, &y, &disallow_override_title)) return NULL;
|
||||
if (optional_window_state && optional_window_state != Py_None) window_state = (int) PyLong_AsLong(optional_window_state);
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "OOsss|OOOOp", (char**)kwlist,
|
||||
&get_window_size, &pre_show_callback, &title, &wm_class_name, &wm_class_class, &optional_window_state, &load_programs, &optional_x, &optional_y, &disallow_override_title)) return NULL;
|
||||
if (optional_window_state && optional_window_state != Py_None) { if (!PyLong_Check(optional_window_state)) { PyErr_SetString(PyExc_TypeError, "window_state must be an int"); return NULL; } window_state = (int) PyLong_AsLong(optional_window_state); }
|
||||
if (optional_x && optional_x != Py_None) { if (!PyLong_Check(optional_x)) { PyErr_SetString(PyExc_TypeError, "x must be an int"); return NULL;} x = (int)PyLong_AsLong(optional_x); }
|
||||
if (optional_y && optional_y != Py_None) { if (!PyLong_Check(optional_y)) { PyErr_SetString(PyExc_TypeError, "y must be an int"); return NULL;} y = (int)PyLong_AsLong(optional_y); }
|
||||
if (window_state < WINDOW_NORMAL || window_state > WINDOW_MINIMIZED) window_state = WINDOW_NORMAL;
|
||||
|
||||
static bool is_first_window = true;
|
||||
@ -1144,7 +1146,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
|
||||
PyObject *pret = PyObject_CallFunction(pre_show_callback, "N", native_window_handle(glfw_window));
|
||||
if (pret == NULL) return NULL;
|
||||
Py_DECREF(pret);
|
||||
if (x != -1 && y != -1) glfwSetWindowPos(glfw_window, x, y);
|
||||
if (x != INT_MIN && y != INT_MIN) glfwSetWindowPos(glfw_window, x, y);
|
||||
#ifndef __APPLE__
|
||||
glfwShowWindow(glfw_window);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user