diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5417b3893..3a8869c45 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,8 @@ version 0.5.0 [future] - Add an option to have window focus follow mouse +- Add a keyboard shortcut (ctrl+shift+f11) to toggle fullscreen mode + - macOS: Fix handling of option key. It now behaves just like the alt key on Linux. There is an option to make it type unicode characters instead. diff --git a/kitty/boss.py b/kitty/boss.py index dac4758fb..44be2a550 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -109,6 +109,9 @@ class Boss: for window in tab: self.close_window(window) + def toggle_fullscreen(self): + self.glfw_window.toggle_fullscreen() + def start(self): if not getattr(self, 'io_thread_started', False): self.child_monitor.start() diff --git a/kitty/glfw.c b/kitty/glfw.c index 7762e1ce6..8204f7d9f 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -36,12 +36,18 @@ #define WINDOW_CALLBACK(name, fmt, ...) \ CALLBACK(the_window->name, "O" fmt, the_window, __VA_ARGS__); +typedef struct { + int x, y, w, h; + bool is_set; +} GLFWWindowGeometry; + typedef struct { PyObject_HEAD GLFWwindow *window; PyObject *framebuffer_size_callback, *window_focus_callback; GLFWcursor *standard_cursor, *click_cursor, *arrow_cursor; + GLFWWindowGeometry before_fullscreen; } WindowWrapper; static void update_viewport(GLFWwindow *window) { @@ -429,6 +435,28 @@ current_monitor_dpi(WindowWrapper *self) { return get_physical_dpi(m); } +static PyObject* +toggle_fullscreen(WindowWrapper *self) { + GLFWmonitor *monitor; + if ((monitor = glfwGetWindowMonitor(self->window)) == NULL) { + // make fullscreen + monitor = current_monitor(self->window); + if (monitor == NULL) return NULL; + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + self->before_fullscreen.is_set = true; + glfwGetWindowSize(self->window, &self->before_fullscreen.w, &self->before_fullscreen.h); + glfwGetWindowPos(self->window, &self->before_fullscreen.x, &self->before_fullscreen.y); + glfwSetWindowMonitor(self->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); + Py_RETURN_TRUE; + } else { + // make windowed + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + if (self->before_fullscreen.is_set) glfwSetWindowMonitor(self->window, NULL, self->before_fullscreen.x, self->before_fullscreen.y, self->before_fullscreen.w, self->before_fullscreen.h, mode->refreshRate); + else glfwSetWindowMonitor(self->window, NULL, 0, 0, 600, 400, mode->refreshRate); + Py_RETURN_FALSE; + } +} + void request_window_attention() { #ifdef has_request_attention @@ -477,6 +505,7 @@ static PyMethodDef methods[] = { MND(should_close, METH_NOARGS), MND(get_framebuffer_size, METH_NOARGS), MND(get_window_size, METH_NOARGS), + MND(toggle_fullscreen, METH_NOARGS), MND(current_monitor_dpi, METH_NOARGS), #ifdef __APPLE__ MND(cocoa_window_id, METH_NOARGS), diff --git a/kitty/kitty.conf b/kitty/kitty.conf index c087b7b2a..016009089 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -282,6 +282,7 @@ map ctrl+shift+, move_tab_backward map ctrl+shift+equal increase_font_size map ctrl+shift+minus decrease_font_size map ctrl+shift+backspace restore_font_size +map ctrl+shift+f11 toggle_fullscreen # Sending arbitrary text on shortcut key presses # You can tell kitty to send arbitrary (UTF-8) encoded text to