diff --git a/docs/changelog.rst b/docs/changelog.rst index 97560dfc3..310402963 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,10 @@ Changelog neighboring windows in the current layout, and move them around, similar to window movement in vim (:iss:`916`) +- Add a new :option:`kitty --start-as` command line flag to start kitty + fullscreen/maximized/minimized. This obsoletes the ``--start-in-fullscreen`` + flag introduced in the previous release (:iss:`935`) + - Linux: Ensure that the python embedded in the kitty binary build uses UTF-8 mode to process command-line arguments (:iss:`924`) @@ -23,7 +27,7 @@ Changelog 0.12.1 [2018-09-08] ------------------------------ -- Add a new :option:`kitty --start-in-fullscreen` command line flag to start +- Add a new ``--start-in-fullscreen`` command line flag to start kitty in full screen mode (:iss:`856`) - macOS: Fix a character that cannot be rendered in any font causing diff --git a/kitty/boss.py b/kitty/boss.py index 0e8867375..84147ee9a 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -19,10 +19,11 @@ from .constants import ( ) from .fast_data_types import ( ChildMonitor, background_opacity_of, change_background_opacity, - create_os_window, current_os_window, destroy_global_data, - get_clipboard_string, glfw_post_empty_event, global_font_size, - mark_os_window_for_close, os_window_font_size, patch_global_colors, - set_clipboard_string, set_in_sequence_mode, toggle_fullscreen + change_os_window_state, create_os_window, current_os_window, + destroy_global_data, get_clipboard_string, glfw_post_empty_event, + global_font_size, mark_os_window_for_close, os_window_font_size, + patch_global_colors, set_clipboard_string, set_in_sequence_mode, + toggle_fullscreen ) from .keys import get_shortcut, shortcut_matches from .layout import set_draw_minimal_borders @@ -103,8 +104,11 @@ class Boss: if new_os_window_trigger is not None: self.keymap.pop(new_os_window_trigger, None) self.add_os_window(startup_session, os_window_id=os_window_id) - if args.start_in_fullscreen: - self.toggle_fullscreen() + if args.start_as != 'normal': + if args.start_as == 'fullscreen': + self.toggle_fullscreen() + else: + change_os_window_state(args.start_as) def add_os_window(self, startup_session, os_window_id=None, wclass=None, wname=None, opts_for_size=None, startup_id=None): if os_window_id is None: diff --git a/kitty/cli.py b/kitty/cli.py index dd861f181..3fe201487 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -546,9 +546,11 @@ specify this address. This option will be ignored, unless you set option as it is read automatically from the environment. ---start-in-fullscreen -type=bool-set -Make the initial kitty window fullscreen on startup +--start-as +type=choices +default=normal +choices=normal,fullscreen,maximized,minimized +Control how the initial kitty window is created. # Debugging options diff --git a/kitty/glfw.c b/kitty/glfw.c index 881b90574..7ed7156ef 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -693,7 +693,7 @@ static PyObject* toggle_fullscreen(PYNOARG) { GLFWmonitor *monitor; OSWindow *w = current_os_window(); - if (!w) Py_RETURN_NONE; + if (!w || !w->handle) Py_RETURN_NONE; if ((monitor = glfwGetWindowMonitor(w->handle)) == NULL) { // make fullscreen monitor = current_monitor(w->handle); @@ -716,6 +716,18 @@ toggle_fullscreen(PYNOARG) { } } +static PyObject* +change_os_window_state(PyObject *self UNUSED, PyObject *args) { + char *state; + if (!PyArg_ParseTuple(args, "s", &state)) return NULL; + OSWindow *w = current_os_window(); + if (!w || !w->handle) Py_RETURN_NONE; + if (strcmp(state, "maximized") == 0) glfwMaximizeWindow(w->handle); + else if (strcmp(state, "minimized") == 0) glfwIconifyWindow(w->handle); + else { PyErr_SetString(PyExc_ValueError, "Unknown window state"); return NULL; } + Py_RETURN_NONE; +} + void ring_audio_bell(OSWindow *w) { static double last_bell_at = -1; @@ -924,6 +936,7 @@ static PyMethodDef module_methods[] = { METHODB(get_content_scale_for_window, METH_NOARGS), METHODB(set_clipboard_string, METH_VARARGS), METHODB(toggle_fullscreen, METH_NOARGS), + METHODB(change_os_window_state, METH_VARARGS), METHODB(glfw_window_hint, METH_VARARGS), METHODB(os_window_should_close, METH_VARARGS), METHODB(os_window_swap_buffers, METH_VARARGS),