API to create initially hidden windows

This commit is contained in:
Kovid Goyal 2017-11-18 05:53:18 +05:30
parent 3e511d217b
commit ef7dcbf365
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 32 additions and 5 deletions

View File

@ -78,10 +78,10 @@ class Boss:
startup_session = create_session(opts, args) startup_session = create_session(opts, args)
self.add_os_window(startup_session, os_window_id=os_window_id) self.add_os_window(startup_session, os_window_id=os_window_id)
def add_os_window(self, startup_session, os_window_id=None, wclass=None, size=None): def add_os_window(self, startup_session, os_window_id=None, wclass=None, size=None, visible=True):
if os_window_id is None: if os_window_id is None:
w, h = initial_window_size(self.opts) if size is None else size w, h = initial_window_size(self.opts) if size is None else size
os_window_id = create_os_window(w, h, wclass or self.args.cls) os_window_id = create_os_window(w, h, wclass or self.args.cls, visible)
tm = TabManager(os_window_id, self.opts, self.args, startup_session) tm = TabManager(os_window_id, self.opts, self.args, startup_session)
self.os_window_map[os_window_id] = tm self.os_window_map[os_window_id] = tm
return os_window_id return os_window_id

View File

@ -211,10 +211,10 @@ make_os_window_context_current(OSWindow *w) {
static PyObject* static PyObject*
create_os_window(PyObject UNUSED *self, PyObject *args) { create_os_window(PyObject UNUSED *self, PyObject *args) {
int width, height; int width, height, visible = 1;
char *title; char *title;
PyObject *load_programs = NULL; PyObject *load_programs = NULL;
if (!PyArg_ParseTuple(args, "iis|O", &width, &height, &title, &load_programs)) return NULL; if (!PyArg_ParseTuple(args, "iis|pO", &width, &height, &title, &visible, &load_programs)) return NULL;
bool is_first_window = standard_cursor == NULL; bool is_first_window = standard_cursor == NULL;
if (is_first_window) { if (is_first_window) {
@ -241,6 +241,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
PyErr_SetString(PyExc_ValueError, "Too many windows"); PyErr_SetString(PyExc_ValueError, "Too many windows");
return NULL; return NULL;
} }
glfwWindowHint(GLFW_VISIBLE, visible ? GLFW_TRUE : GLFW_FALSE);
GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, global_state.num_os_windows ? global_state.os_windows[0].handle : NULL); GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, global_state.num_os_windows ? global_state.os_windows[0].handle : NULL);
if (glfw_window == NULL) { if (glfw_window == NULL) {
fprintf(stderr, "Failed to create a window at size: %dx%d, using a standard size instead.\n", width, height); fprintf(stderr, "Failed to create a window at size: %dx%d, using a standard size instead.\n", width, height);
@ -282,6 +283,21 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
return PyLong_FromUnsignedLongLong(w->id); return PyLong_FromUnsignedLongLong(w->id);
} }
static PyObject*
show_window(PyObject UNUSED *self, PyObject *args) {
id_type os_window_id;
int yes = 1;
if (!PyArg_ParseTuple(args, "K|p", &os_window_id, &yes)) return NULL;
for (size_t i = 0; i < global_state.num_os_windows; i++) {
OSWindow *w = global_state.os_windows + i;
if (w->id == os_window_id) {
if (yes) glfwShowWindow(w->handle); else glfwHideWindow(w->handle);
break;
}
}
Py_RETURN_NONE;
}
void void
destroy_os_window(OSWindow *w) { destroy_os_window(OSWindow *w) {
if (w->handle) { if (w->handle) {
@ -356,6 +372,14 @@ glfw_get_key_name(PyObject UNUSED *self, PyObject *args) {
return Py_BuildValue("s", glfwGetKeyName(key, scancode)); return Py_BuildValue("s", glfwGetKeyName(key, scancode));
} }
PyObject*
glfw_window_hint(PyObject UNUSED *self, PyObject *args) {
int key, val;
if (!PyArg_ParseTuple(args, "ii", &key, &val)) return NULL;
glfwWindowHint(key, val);
Py_RETURN_NONE;
}
PyObject* PyObject*
glfw_init_hint_string(PyObject UNUSED *self, PyObject *args) { glfw_init_hint_string(PyObject UNUSED *self, PyObject *args) {
int hint_id; int hint_id;
@ -544,6 +568,8 @@ static PyMethodDef module_methods[] = {
METHODB(get_content_scale_for_window, METH_NOARGS), METHODB(get_content_scale_for_window, METH_NOARGS),
METHODB(set_clipboard_string, METH_VARARGS), METHODB(set_clipboard_string, METH_VARARGS),
METHODB(toggle_fullscreen, METH_NOARGS), METHODB(toggle_fullscreen, METH_NOARGS),
METHODB(show_window, METH_VARARGS),
METHODB(glfw_window_hint, METH_VARARGS),
{"glfw_init", (PyCFunction)glfw_init, METH_NOARGS, ""}, {"glfw_init", (PyCFunction)glfw_init, METH_NOARGS, ""},
{"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""}, {"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""},
{"glfw_wait_events", (PyCFunction)glfw_wait_events, METH_VARARGS, ""}, {"glfw_wait_events", (PyCFunction)glfw_wait_events, METH_VARARGS, ""},
@ -568,6 +594,7 @@ init_glfw(PyObject *m) {
ADDC(GLFW_RELEASE); ADDC(GLFW_RELEASE);
ADDC(GLFW_PRESS); ADDC(GLFW_PRESS);
ADDC(GLFW_REPEAT); ADDC(GLFW_REPEAT);
ADDC(GLFW_TRUE); ADDC(GLFW_FALSE);
// --- Keys -------------------------------------------------------------------- // --- Keys --------------------------------------------------------------------

View File

@ -41,7 +41,7 @@ def run_app(opts, args):
set_options(opts, iswayland, args.debug_gl) set_options(opts, iswayland, args.debug_gl)
load_cached_values() load_cached_values()
w, h = initial_window_size(opts) w, h = initial_window_size(opts)
window_id = create_os_window(w, h, args.cls, load_all_shaders) window_id = create_os_window(w, h, args.cls, True, load_all_shaders)
startup_ctx = init_startup_notification(window_id) startup_ctx = init_startup_notification(window_id)
if isosx: if isosx:
from .fast_data_types import cocoa_create_global_menu, cocoa_init from .fast_data_types import cocoa_create_global_menu, cocoa_init