Mercurial > vim
comparison src/gui_gtk_x11.c @ 28582:278a14b00896 v8.2.4815
patch 8.2.4815: cannot build with older GTK version
Commit: https://github.com/vim/vim/commit/d42b83942e6741de2bb630ee17a2e9fcc03d6b43
Author: Ernie Rael <errael@raelity.com>
Date: Sat Apr 23 19:52:23 2022 +0100
patch 8.2.4815: cannot build with older GTK version
Problem: Cannot build with older GTK version.
Solution: Use gtk_window_get_size() instead of gdk_window_get_width() and
gdk_window_get_height(). (Ernie Rael, closes #10257)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 23 Apr 2022 21:00:03 +0200 |
parents | bae90eec6d14 |
children | 198a2caa8ac2 |
comparison
equal
deleted
inserted
replaced
28581:668a94bb0e5e | 28582:278a14b00896 |
---|---|
394 static int using_gnome = 0; | 394 static int using_gnome = 0; |
395 #else | 395 #else |
396 # define using_gnome 0 | 396 # define using_gnome 0 |
397 #endif | 397 #endif |
398 | 398 |
399 // Comment out the following line to ignore code for resize history tracking. | |
400 #define TRACK_RESIZE_HISTORY | |
401 #ifdef TRACK_RESIZE_HISTORY | |
399 /* | 402 /* |
400 * Keep a short term resize history so that stale gtk responses can be | 403 * Keep a short term resize history so that stale gtk responses can be |
401 * discarded. | 404 * discarded. |
402 * When a gtk_window_resize() request is sent to gtk, the width/height of | 405 * When a gtk_window_resize() request is sent to gtk, the width/height of |
403 * the request is saved. Recent stale requests are kept around in a list. | 406 * the request is saved. Recent stale requests are kept around in a list. |
404 * See https://github.com/vim/vim/issues/10123 | 407 * See https://github.com/vim/vim/issues/10123 |
405 */ | 408 */ |
406 #if 0 // Change to 1 to enable ch_log() calls for debugging. | 409 # if 0 // Change to 1 to enable ch_log() calls for debugging. |
407 # ifdef FEAT_JOB_CHANNEL | 410 # ifdef FEAT_JOB_CHANNEL |
408 # define ENABLE_RESIZE_HISTORY_LOG | 411 # define ENABLE_RESIZE_HISTORY_LOG |
412 # endif | |
409 # endif | 413 # endif |
410 #endif | |
411 | 414 |
412 /* | 415 /* |
413 * History item of a resize request. | 416 * History item of a resize request. |
414 * Width and height are of gui.mainwin. | 417 * Width and height are of gui.mainwin. |
415 */ | 418 */ |
416 typedef struct resize_history { | 419 typedef struct resize_history { |
417 int used; // If true, can't match for discard. Only matches once. | 420 int used; // If true, can't match for discard. Only matches once. |
418 int width; | 421 int width; |
419 int height; | 422 int height; |
420 #ifdef ENABLE_RESIZE_HISTORY_LOG | 423 # ifdef ENABLE_RESIZE_HISTORY_LOG |
421 int seq; // for ch_log messages | 424 int seq; // for ch_log messages |
422 #endif | 425 # endif |
423 struct resize_history *next; | 426 struct resize_history *next; |
424 } resize_hist_T; | 427 } resize_hist_T; |
425 | 428 |
426 // never NULL during execution | 429 // never NULL during execution |
427 static resize_hist_T *latest_resize_hist; | 430 static resize_hist_T *latest_resize_hist; |
446 | 449 |
447 // previous hist item becomes head of list | 450 // previous hist item becomes head of list |
448 prev_hist->next = old_resize_hists; | 451 prev_hist->next = old_resize_hists; |
449 old_resize_hists = prev_hist; | 452 old_resize_hists = prev_hist; |
450 | 453 |
451 #ifdef ENABLE_RESIZE_HISTORY_LOG | 454 # ifdef ENABLE_RESIZE_HISTORY_LOG |
452 new_hist->seq = prev_hist->seq + 1; | 455 new_hist->seq = prev_hist->seq + 1; |
453 ch_log(NULL, "gui_gtk: New resize seq %d (%d, %d) [%d, %d]", | 456 ch_log(NULL, "gui_gtk: New resize seq %d (%d, %d) [%d, %d]", |
454 new_hist->seq, width, height, (int)Columns, (int)Rows); | 457 new_hist->seq, width, height, (int)Columns, (int)Rows); |
455 #endif | 458 # endif |
456 } | 459 } |
457 | 460 |
458 /* | 461 /* |
459 * Free everything on the stale resize history list. | 462 * Free everything on the stale resize history list. |
460 * This list is empty when there are no outstanding resize requests. | 463 * This list is empty when there are no outstanding resize requests. |
461 */ | 464 */ |
462 static void | 465 static void |
463 clear_resize_hists() | 466 clear_resize_hists() |
464 { | 467 { |
465 #ifdef ENABLE_RESIZE_HISTORY_LOG | 468 # ifdef ENABLE_RESIZE_HISTORY_LOG |
466 int i = 0; | 469 int i = 0; |
467 #endif | 470 # endif |
468 | 471 |
469 if (latest_resize_hist) | 472 if (latest_resize_hist) |
470 latest_resize_hist->used = TRUE; | 473 latest_resize_hist->used = TRUE; |
471 while (old_resize_hists != NULL) | 474 while (old_resize_hists != NULL) |
472 { | 475 { |
473 resize_hist_T *next_hist = old_resize_hists->next; | 476 resize_hist_T *next_hist = old_resize_hists->next; |
474 | 477 |
475 vim_free(old_resize_hists); | 478 vim_free(old_resize_hists); |
476 old_resize_hists = next_hist; | 479 old_resize_hists = next_hist; |
477 #ifdef ENABLE_RESIZE_HISTORY_LOG | 480 # ifdef ENABLE_RESIZE_HISTORY_LOG |
478 i++; | 481 i++; |
479 #endif | 482 # endif |
480 } | 483 } |
481 #ifdef ENABLE_RESIZE_HISTORY_LOG | 484 # ifdef ENABLE_RESIZE_HISTORY_LOG |
482 ch_log(NULL, "gui_gtk: free %d hists", i); | 485 ch_log(NULL, "gui_gtk: free %d hists", i); |
483 #endif | 486 # endif |
484 } | 487 } |
485 | 488 |
486 // true if hist item is unused and matches w,h | 489 // true if hist item is unused and matches w,h |
487 #define MATCH_WIDTH_HEIGHT(hist, w, h) \ | 490 # define MATCH_WIDTH_HEIGHT(hist, w, h) \ |
488 (!hist->used && hist->width == w && hist->height == h) | 491 (!hist->used && hist->width == w && hist->height == h) |
489 | 492 |
490 /* | 493 /* |
491 * Search the resize hist list. | 494 * Search the resize hist list. |
492 * Return true if the specified width,height match an item in the list that | 495 * Return true if the specified width,height match an item in the list that |
499 resize_hist_T *hist = old_resize_hists; | 502 resize_hist_T *hist = old_resize_hists; |
500 | 503 |
501 for (hist = old_resize_hists; hist != NULL; hist = hist->next) | 504 for (hist = old_resize_hists; hist != NULL; hist = hist->next) |
502 if (MATCH_WIDTH_HEIGHT(hist, width, height)) | 505 if (MATCH_WIDTH_HEIGHT(hist, width, height)) |
503 { | 506 { |
504 #ifdef ENABLE_RESIZE_HISTORY_LOG | 507 # ifdef ENABLE_RESIZE_HISTORY_LOG |
505 ch_log(NULL, "gui_gtk: discard seq %d, cur seq %d", | 508 ch_log(NULL, "gui_gtk: discard seq %d, cur seq %d", |
506 hist->seq, latest_resize_hist->seq); | 509 hist->seq, latest_resize_hist->seq); |
507 #endif | 510 # endif |
508 hist->used = TRUE; | 511 hist->used = TRUE; |
509 return TRUE; | 512 return TRUE; |
510 } | 513 } |
511 return FALSE; | 514 return FALSE; |
512 } | 515 } |
513 | 516 |
514 #if defined(EXITFREE) | 517 # if defined(EXITFREE) |
515 static void | 518 static void |
516 free_all_resize_hist() | 519 free_all_resize_hist() |
517 { | 520 { |
518 clear_resize_hists(); | 521 clear_resize_hists(); |
519 vim_free(latest_resize_hist); | 522 vim_free(latest_resize_hist); |
520 } | 523 } |
524 # endif | |
521 #endif | 525 #endif |
522 | 526 |
523 /* | 527 /* |
524 * GTK doesn't set the GDK_BUTTON1_MASK state when dragging a touch. Add this | 528 * GTK doesn't set the GDK_BUTTON1_MASK state when dragging a touch. Add this |
525 * state when dragging. | 529 * state when dragging. |
715 { | 719 { |
716 vim_free(gui_argv); | 720 vim_free(gui_argv); |
717 #if defined(USE_GNOME_SESSION) | 721 #if defined(USE_GNOME_SESSION) |
718 vim_free(abs_restart_command); | 722 vim_free(abs_restart_command); |
719 #endif | 723 #endif |
724 #ifdef TRACK_RESIZE_HISTORY | |
720 free_all_resize_hist(); | 725 free_all_resize_hist(); |
726 #endif | |
721 } | 727 } |
722 #endif | 728 #endif |
723 | 729 |
724 #if !GTK_CHECK_VERSION(3,0,0) | 730 #if !GTK_CHECK_VERSION(3,0,0) |
725 /* | 731 /* |
4129 static gint | 4135 static gint |
4130 form_configure_event(GtkWidget *widget UNUSED, | 4136 form_configure_event(GtkWidget *widget UNUSED, |
4131 GdkEventConfigure *event, | 4137 GdkEventConfigure *event, |
4132 gpointer data UNUSED) | 4138 gpointer data UNUSED) |
4133 { | 4139 { |
4134 int usable_height = event->height; | 4140 int usable_height = event->height; |
4135 // Resize requests are made for gui.mainwin, | 4141 #ifdef TRACK_RESIZE_HISTORY |
4136 // get it's dimensions for searching if this event | 4142 // Resize requests are made for gui.mainwin; |
4143 // get its dimensions for searching if this event | |
4137 // is a response to a vim request. | 4144 // is a response to a vim request. |
4138 GdkWindow *win = gtk_widget_get_window(gui.mainwin); | 4145 int w, h; |
4139 int w = gdk_window_get_width(win); | 4146 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); |
4140 int h = gdk_window_get_height(win); | 4147 |
4141 | 4148 # ifdef ENABLE_RESIZE_HISTORY_LOG |
4142 #ifdef ENABLE_RESIZE_HISTORY_LOG | |
4143 ch_log(NULL, "gui_gtk: form_configure_event: (%d, %d) [%d, %d]", | 4149 ch_log(NULL, "gui_gtk: form_configure_event: (%d, %d) [%d, %d]", |
4144 w, h, (int)Columns, (int)Rows); | 4150 w, h, (int)Columns, (int)Rows); |
4145 #endif | 4151 # endif |
4146 | 4152 |
4147 // Look through history of recent vim resize reqeusts. | 4153 // Look through history of recent vim resize requests. |
4148 // If this event matches: | 4154 // If this event matches: |
4149 // - "latest resize hist" We're caught up; | 4155 // - "latest resize hist" We're caught up; |
4150 // clear the history and process this event. | 4156 // clear the history and process this event. |
4151 // If history is, old to new, 100, 99, 100, 99. If this event is | 4157 // If history is, old to new, 100, 99, 100, 99. If this event is |
4152 // 99 for the stale, it is matched against the current. History | 4158 // 99 for the stale, it is matched against the current. History |
4153 // is cleared, we my bounce, but no worse than before. | 4159 // is cleared, we may bounce, but no worse than before. |
4154 // - "older/stale hist" If match an unused event in history, | 4160 // - "older/stale hist" If match an unused event in history, |
4155 // then discard this event, and mark the matching event as used. | 4161 // then discard this event, and mark the matching event as used. |
4156 // - "no match" Figure it's a user resize event, clear history. | 4162 // - "no match" Figure it's a user resize event, clear history. |
4157 // NOTE: clear history is default, then all incoming events are processed | 4163 // NOTE: clear history is default, then all incoming events are processed |
4158 | 4164 |
4159 if (!MATCH_WIDTH_HEIGHT(latest_resize_hist, w, h) | 4165 if (!MATCH_WIDTH_HEIGHT(latest_resize_hist, w, h) |
4160 && match_stale_width_height(w, h)) | 4166 && match_stale_width_height(w, h)) |
4161 // discard stale event | 4167 // discard stale event |
4162 return TRUE; | 4168 return TRUE; |
4163 clear_resize_hists(); | 4169 clear_resize_hists(); |
4170 #endif | |
4164 | 4171 |
4165 #if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) | 4172 #if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) |
4166 // As of 3.22.2, GdkWindows have started distributing configure events to | 4173 // As of 3.22.2, GdkWindows have started distributing configure events to |
4167 // their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). | 4174 // their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). |
4168 // | 4175 // |
4481 * We connect this signal deferred finally after anything is in place, | 4488 * We connect this signal deferred finally after anything is in place, |
4482 * since this is intended to handle resizements coming from the window | 4489 * since this is intended to handle resizements coming from the window |
4483 * manager upon us and should not interfere with what VIM is requesting | 4490 * manager upon us and should not interfere with what VIM is requesting |
4484 * upon startup. | 4491 * upon startup. |
4485 */ | 4492 */ |
4493 #ifdef TRACK_RESIZE_HISTORY | |
4486 latest_resize_hist = ALLOC_CLEAR_ONE(resize_hist_T); | 4494 latest_resize_hist = ALLOC_CLEAR_ONE(resize_hist_T); |
4495 #endif | |
4487 g_signal_connect(G_OBJECT(gui.formwin), "configure-event", | 4496 g_signal_connect(G_OBJECT(gui.formwin), "configure-event", |
4488 G_CALLBACK(form_configure_event), NULL); | 4497 G_CALLBACK(form_configure_event), NULL); |
4489 | 4498 |
4490 #ifdef FEAT_DND | 4499 #ifdef FEAT_DND |
4491 // Set up for receiving DND items. | 4500 // Set up for receiving DND items. |
4669 // the window. So let's do it the other way around and resize the | 4678 // the window. So let's do it the other way around and resize the |
4670 // main window instead. | 4679 // main window instead. |
4671 width += get_menu_tool_width(); | 4680 width += get_menu_tool_width(); |
4672 height += get_menu_tool_height(); | 4681 height += get_menu_tool_height(); |
4673 | 4682 |
4683 #ifdef TRACK_RESIZE_HISTORY | |
4674 alloc_resize_hist(width, height); // track the resize request | 4684 alloc_resize_hist(width, height); // track the resize request |
4685 #endif | |
4675 if (gtk_socket_id == 0) | 4686 if (gtk_socket_id == 0) |
4676 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); | 4687 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
4677 else | 4688 else |
4678 update_window_manager_hints(width, height); | 4689 update_window_manager_hints(width, height); |
4679 | 4690 |