diff --git a/docs/changelog.rst b/docs/changelog.rst index 68b6d091d..7d2d61b26 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -10,6 +10,8 @@ To update |kitty|, :doc:`follow the instructions `. - Add an option :opt:`command_on_bell` to run an arbitrary command when a bell occurs (:iss:`1660`) +- Add a shortcut to toggle maximized window state :sc:`toggle_maximized` + - Add support for the underscore key found in some keyboard layouts (:iss:`1639`) diff --git a/docs/index.rst b/docs/index.rst index e935b8e83..c2b0364e8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -187,6 +187,7 @@ Increase font size :sc:`increase_font_size` (also :kbd:`⌘++` Decrease font size :sc:`decrease_font_size` (also :kbd:`⌘+-` on macOS) Restore font size :sc:`reset_font_size` (also :kbd:`⌘+0` on macOS) Toggle fullscreen :sc:`toggle_fullscreen` (also :kbd:`^+⌘+f` on macOS) +Toggle maximized :sc:`toggle_maximized` Input unicode character :sc:`input_unicode_character` Click URL using the keyboard :sc:`open_url` Reset the terminal :sc:`reset_terminal` diff --git a/kitty/boss.py b/kitty/boss.py index 0947495bb..552895367 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -24,7 +24,8 @@ from .fast_data_types import ( change_os_window_state, create_os_window, current_os_window, destroy_global_data, get_clipboard_string, global_font_size, mark_os_window_for_close, os_window_font_size, patch_global_colors, - set_clipboard_string, set_in_sequence_mode, toggle_fullscreen + set_clipboard_string, set_in_sequence_mode, toggle_fullscreen, + toggle_maximized ) from .keys import get_shortcut, shortcut_matches from .layout import set_draw_borders_options @@ -361,6 +362,9 @@ class Boss: def toggle_fullscreen(self): toggle_fullscreen() + def toggle_maximized(self): + toggle_maximized() + def start(self): if not getattr(self, 'io_thread_started', False): self.child_monitor.start() diff --git a/kitty/config_data.py b/kitty/config_data.py index bfa146031..38c3f80b4 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -1157,6 +1157,7 @@ Useful with git, which uses sha1 hashes to identify commits''')) g('shortcuts.misc') # {{{ k('toggle_fullscreen', 'kitty_mod+f11', 'toggle_fullscreen', _('Toggle fullscreen')) +k('toggle_maximized', 'kitty_mod+f10', 'toggle_maximized', _('Toggle maximized')) k('input_unicode_character', 'kitty_mod+u', 'kitten unicode_input', _('Unicode input')) k('edit_config_file', 'kitty_mod+f2', 'edit_config_file', _('Edit config file')) k('kitty_shell', 'kitty_mod+escape', 'kitty_shell window', _('Open the kitty command shell'), long_text=_(''' diff --git a/kitty/glfw.c b/kitty/glfw.c index 10504351b..22797aa2c 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -398,6 +398,20 @@ toggle_fullscreen_for_os_window(OSWindow *w) { return false; } +static bool +toggle_maximized_for_os_window(OSWindow *w) { + bool maximized = false; + if (w && w->handle) { + if (glfwGetWindowAttrib(w->handle, GLFW_MAXIMIZED)) { + glfwRestoreWindow(w->handle); + } else { + glfwMaximizeWindow(w->handle); + maximized = true; + } + } + return maximized; +} + #ifdef __APPLE__ static int @@ -843,6 +857,14 @@ toggle_fullscreen(PYNOARG) { Py_RETURN_FALSE; } +static PyObject* +toggle_maximized(PYNOARG) { + OSWindow *w = current_os_window(); + if (!w) Py_RETURN_NONE; + if (toggle_maximized_for_os_window(w)) { Py_RETURN_TRUE; } + Py_RETURN_FALSE; +} + static PyObject* change_os_window_state(PyObject *self UNUSED, PyObject *args) { char *state; @@ -1112,6 +1134,7 @@ static PyMethodDef module_methods[] = { METHODB(ring_bell, METH_NOARGS), METHODB(set_clipboard_string, METH_VARARGS), METHODB(toggle_fullscreen, METH_NOARGS), + METHODB(toggle_maximized, METH_NOARGS), METHODB(change_os_window_state, METH_VARARGS), METHODB(glfw_window_hint, METH_VARARGS), METHODB(get_primary_selection, METH_NOARGS),