Add a shortcut to toggle maximized window state

This commit is contained in:
Kovid Goyal 2019-05-29 16:41:34 +05:30
parent 1ae32b5742
commit 2920638a3d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 32 additions and 1 deletions

View File

@ -10,6 +10,8 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- 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`)

View File

@ -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`

View File

@ -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()

View File

@ -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=_('''

View File

@ -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),