mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
Make live resize code a little cleaner
This commit is contained in:
@@ -807,16 +807,22 @@ process_pending_resizes(double now) {
|
|||||||
global_state.has_pending_resizes = false;
|
global_state.has_pending_resizes = false;
|
||||||
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
||||||
OSWindow *w = global_state.os_windows + i;
|
OSWindow *w = global_state.os_windows + i;
|
||||||
if (w->has_pending_resizes) {
|
if (w->live_resize.in_progress) {
|
||||||
if (w->has_live_resize_information) {
|
bool update_viewport = false;
|
||||||
if (!w->live_resize_in_progress) update_os_window_viewport(w, true);
|
if (w->live_resize.from_os_notification) {
|
||||||
|
if (w->live_resize.os_says_resize_complete || (now - w->live_resize.last_resize_event_at) > 1) update_viewport = true;
|
||||||
} else {
|
} else {
|
||||||
if (now - w->last_resize_event_at >= RESIZE_DEBOUNCE_TIME) update_os_window_viewport(w, true);
|
if (now - w->live_resize.last_resize_event_at >= RESIZE_DEBOUNCE_TIME) update_viewport = true;
|
||||||
else {
|
else {
|
||||||
global_state.has_pending_resizes = true;
|
global_state.has_pending_resizes = true;
|
||||||
set_maximum_wait(RESIZE_DEBOUNCE_TIME - now + w->last_resize_event_at);
|
set_maximum_wait(RESIZE_DEBOUNCE_TIME - now + w->live_resize.last_resize_event_at);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (update_viewport) {
|
||||||
|
static const LiveResizeInfo empty = {0};
|
||||||
|
update_os_window_viewport(w, true);
|
||||||
|
w->live_resize = empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
kitty/glfw.c
20
kitty/glfw.c
@@ -44,7 +44,6 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) {
|
|||||||
bool dpi_changed = (xr != 0.0 && xr != window->viewport_x_ratio) || (yr != 0.0 && yr != window->viewport_y_ratio) || (xdpi != window->logical_dpi_x) || (ydpi != window->logical_dpi_y);
|
bool dpi_changed = (xr != 0.0 && xr != window->viewport_x_ratio) || (yr != 0.0 && yr != window->viewport_y_ratio) || (xdpi != window->logical_dpi_x) || (ydpi != window->logical_dpi_y);
|
||||||
|
|
||||||
window->viewport_size_dirty = true;
|
window->viewport_size_dirty = true;
|
||||||
window->has_pending_resizes = false;
|
|
||||||
window->viewport_width = MAX(window->viewport_width, 100);
|
window->viewport_width = MAX(window->viewport_width, 100);
|
||||||
window->viewport_height = MAX(window->viewport_height, 100);
|
window->viewport_height = MAX(window->viewport_height, 100);
|
||||||
window->window_width = MAX(w, 100);
|
window->window_width = MAX(w, 100);
|
||||||
@@ -131,9 +130,13 @@ window_iconify_callback(GLFWwindow *window, int iconified UNUSED) {
|
|||||||
static void
|
static void
|
||||||
live_resize_callback(GLFWwindow *w, bool started) {
|
live_resize_callback(GLFWwindow *w, bool started) {
|
||||||
if (!set_callback_window(w)) return;
|
if (!set_callback_window(w)) return;
|
||||||
global_state.callback_os_window->has_live_resize_information = true;
|
global_state.callback_os_window->live_resize.from_os_notification = true;
|
||||||
global_state.callback_os_window->live_resize_in_progress = started;
|
global_state.callback_os_window->live_resize.in_progress = true;
|
||||||
if (!started) request_tick_callback();
|
global_state.has_pending_resizes = true;
|
||||||
|
if (!started) {
|
||||||
|
global_state.callback_os_window->live_resize.os_says_resize_complete = true;
|
||||||
|
request_tick_callback();
|
||||||
|
}
|
||||||
global_state.callback_os_window = NULL;
|
global_state.callback_os_window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,8 +145,9 @@ framebuffer_size_callback(GLFWwindow *w, int width, int height) {
|
|||||||
if (!set_callback_window(w)) return;
|
if (!set_callback_window(w)) return;
|
||||||
if (width >= min_width && height >= min_height) {
|
if (width >= min_width && height >= min_height) {
|
||||||
OSWindow *window = global_state.callback_os_window;
|
OSWindow *window = global_state.callback_os_window;
|
||||||
window->has_pending_resizes = true; global_state.has_pending_resizes = true;
|
global_state.has_pending_resizes = true;
|
||||||
window->last_resize_event_at = monotonic();
|
window->live_resize.in_progress = true;
|
||||||
|
window->live_resize.last_resize_event_at = monotonic();
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// On cocoa request_tick_callback() does not work while the window
|
// On cocoa request_tick_callback() does not work while the window
|
||||||
// is being resized, because that happens in a sub-loop. With semi-transparent
|
// is being resized, because that happens in a sub-loop. With semi-transparent
|
||||||
@@ -166,8 +170,8 @@ dpi_change_callback(GLFWwindow *w, float x_scale UNUSED, float y_scale UNUSED) {
|
|||||||
// Ensure update_os_window_viewport() is called in the near future, it will
|
// Ensure update_os_window_viewport() is called in the near future, it will
|
||||||
// take care of DPI changes.
|
// take care of DPI changes.
|
||||||
OSWindow *window = global_state.callback_os_window;
|
OSWindow *window = global_state.callback_os_window;
|
||||||
window->has_pending_resizes = true; global_state.has_pending_resizes = true;
|
window->live_resize.in_progress = true; global_state.has_pending_resizes = true;
|
||||||
window->last_resize_event_at = monotonic();
|
window->live_resize.last_resize_event_at = monotonic();
|
||||||
global_state.callback_os_window = NULL;
|
global_state.callback_os_window = NULL;
|
||||||
request_tick_callback();
|
request_tick_callback();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,14 @@ typedef struct {
|
|||||||
|
|
||||||
enum RENDER_STATE { RENDER_FRAME_NOT_REQUESTED, RENDER_FRAME_REQUESTED, RENDER_FRAME_READY };
|
enum RENDER_STATE { RENDER_FRAME_NOT_REQUESTED, RENDER_FRAME_REQUESTED, RENDER_FRAME_READY };
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
double last_resize_event_at;
|
||||||
|
bool in_progress;
|
||||||
|
bool from_os_notification;
|
||||||
|
bool os_says_resize_complete;
|
||||||
|
} LiveResizeInfo;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *handle;
|
void *handle;
|
||||||
id_type id;
|
id_type id;
|
||||||
@@ -125,8 +133,7 @@ typedef struct {
|
|||||||
PyObject *window_title;
|
PyObject *window_title;
|
||||||
bool is_key_pressed[MAX_KEY_COUNT];
|
bool is_key_pressed[MAX_KEY_COUNT];
|
||||||
bool viewport_size_dirty;
|
bool viewport_size_dirty;
|
||||||
double last_resize_event_at;
|
LiveResizeInfo live_resize;
|
||||||
bool has_live_resize_information, live_resize_in_progress;
|
|
||||||
bool has_pending_resizes, is_semi_transparent, shown_once, is_damaged;
|
bool has_pending_resizes, is_semi_transparent, shown_once, is_damaged;
|
||||||
uint32_t offscreen_texture_id;
|
uint32_t offscreen_texture_id;
|
||||||
unsigned int clear_count;
|
unsigned int clear_count;
|
||||||
|
|||||||
Reference in New Issue
Block a user