diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-03-18 22:28:57 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-03-18 22:28:57 +0100 |
commit | a555e6fcb6ec97b5ab30b20a340b228f4d820f14 (patch) | |
tree | 08774815296acda9ddb18e315bb5083fefc267a4 /src | |
parent | 108cf0153c5770e343aec9e2390acdaa4a0b149a (diff) | |
download | vim-git-a555e6fcb6ec97b5ab30b20a340b228f4d820f14.tar.gz |
patch 8.2.2622: GTK: error when starting up and -geometry is givenv8.2.2622
Problem: GTK: error when starting up and -geometry is given. (Dominique
Pellé)
Solution: Use another function to get the monitor if the window has not been
created yet. (closes #7978)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui_beval.c | 2 | ||||
-rw-r--r-- | src/gui_gtk_x11.c | 137 | ||||
-rw-r--r-- | src/gui_xim.c | 2 | ||||
-rw-r--r-- | src/proto/gui_gtk_x11.pro | 4 | ||||
-rw-r--r-- | src/version.c | 2 |
5 files changed, 85 insertions, 62 deletions
diff --git a/src/gui_beval.c b/src/gui_beval.c index 57122ffa9..10478c677 100644 --- a/src/gui_beval.c +++ b/src/gui_beval.c @@ -920,7 +920,7 @@ drawBalloon(BalloonEval *beval) screen = gtk_widget_get_screen(beval->target); gtk_window_set_screen(GTK_WINDOW(beval->balloonShell), screen); # endif - gui_gtk_get_screen_geom_of_win(beval->target, + gui_gtk_get_screen_geom_of_win(beval->target, 0, 0, &screen_x, &screen_y, &screen_w, &screen_h); # if !GTK_CHECK_VERSION(3,0,0) gtk_widget_ensure_style(beval->balloonShell); diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index ec81d4efd..3fdff4d3f 100644 --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -4155,6 +4155,80 @@ mainwin_destroy_cb(GObject *object UNUSED, gpointer data UNUSED) #endif } + void +gui_gtk_get_screen_geom_of_win( + GtkWidget *wid, + int point_x, // x position of window if not initialized + int point_y, // y position of window if not initialized + int *screen_x, + int *screen_y, + int *width, + int *height) +{ + GdkRectangle geometry; + GdkWindow *win = gtk_widget_get_window(wid); +#if GTK_CHECK_VERSION(3,22,0) + GdkDisplay *dpy = gtk_widget_get_display(wid); + GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); + + gdk_monitor_get_geometry(monitor, &geometry); +#else + GdkScreen* screen; + int monitor; + + if (wid != NULL && gtk_widget_has_screen(wid)) + screen = gtk_widget_get_screen(wid); + else + screen = gdk_screen_get_default(); + if (win == NULL) + monitor = gdk_screen_get_monitor_at_point(screen, point_x, point_y); + else + monitor = gdk_screen_get_monitor_at_window(screen, win); + gdk_screen_get_monitor_geometry(screen, monitor, &geometry); +#endif + *screen_x = geometry.x; + *screen_y = geometry.y; + *width = geometry.width; + *height = geometry.height; +} + +/* + * The screen size is used to make sure the initial window doesn't get bigger + * than the screen. This subtracts some room for menubar, toolbar and window + * decorations. + */ + static void +gui_gtk_get_screen_dimensions( + int point_x, + int point_y, + int *screen_w, + int *screen_h) +{ + int x, y; + + gui_gtk_get_screen_geom_of_win(gui.mainwin, point_x, point_y, + &x, &y, screen_w, screen_h); + + // Subtract 'guiheadroom' from the height to allow some room for the + // window manager (task list and window title bar). + *screen_h -= p_ghr; + + /* + * FIXME: dirty trick: Because the gui_get_base_height() doesn't include + * the toolbar and menubar for GTK, we subtract them from the screen + * height, so that the window size can be made to fit on the screen. + * This should be completely changed later. + */ + *screen_w -= get_menu_tool_width(); + *screen_h -= get_menu_tool_height(); +} + + void +gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) +{ + gui_gtk_get_screen_dimensions(0, 0, screen_w, screen_h); +} + /* * Bit of a hack to ensure we start GtkPlug windows with the correct window @@ -4250,7 +4324,12 @@ gui_mch_open(void) if (mask & (XValue | YValue)) { int ww, hh; + +#ifdef FEAT_GUI_GTK + gui_gtk_get_screen_dimensions(x, y, &ww, &hh); +#else gui_mch_get_screen_dimensions(&ww, &hh); +#endif hh += p_ghr + get_menu_tool_height(); ww += get_menu_tool_width(); if (mask & XNegative) @@ -4538,64 +4617,6 @@ gui_mch_set_shellsize(int width, int height, gui_mch_update(); } - void -gui_gtk_get_screen_geom_of_win( - GtkWidget *wid, - int *screen_x, - int *screen_y, - int *width, - int *height) -{ - GdkRectangle geometry; - GdkWindow *win = gtk_widget_get_window(wid); -#if GTK_CHECK_VERSION(3,22,0) - GdkDisplay *dpy = gtk_widget_get_display(wid); - GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); - - gdk_monitor_get_geometry(monitor, &geometry); -#else - GdkScreen* screen; - int monitor; - - if (wid != NULL && gtk_widget_has_screen(wid)) - screen = gtk_widget_get_screen(wid); - else - screen = gdk_screen_get_default(); - monitor = gdk_screen_get_monitor_at_window(screen, win); - gdk_screen_get_monitor_geometry(screen, monitor, &geometry); -#endif - *screen_x = geometry.x; - *screen_y = geometry.y; - *width = geometry.width; - *height = geometry.height; -} - -/* - * The screen size is used to make sure the initial window doesn't get bigger - * than the screen. This subtracts some room for menubar, toolbar and window - * decorations. - */ - void -gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) -{ - int x, y; - - gui_gtk_get_screen_geom_of_win(gui.mainwin, &x, &y, screen_w, screen_h); - - // Subtract 'guiheadroom' from the height to allow some room for the - // window manager (task list and window title bar). - *screen_h -= p_ghr; - - /* - * FIXME: dirty trick: Because the gui_get_base_height() doesn't include - * the toolbar and menubar for GTK, we subtract them from the screen - * height, so that the window size can be made to fit on the screen. - * This should be completely changed later. - */ - *screen_w -= get_menu_tool_width(); - *screen_h -= get_menu_tool_height(); -} - #if defined(FEAT_TITLE) || defined(PROTO) void gui_mch_settitle(char_u *title, char_u *icon UNUSED) diff --git a/src/gui_xim.c b/src/gui_xim.c index ee9230133..2dd6fd915 100644 --- a/src/gui_xim.c +++ b/src/gui_xim.c @@ -207,7 +207,7 @@ im_preedit_window_set_position(void) if (preedit_window == NULL) return; - gui_gtk_get_screen_geom_of_win(gui.drawarea, + gui_gtk_get_screen_geom_of_win(gui.drawarea, 0, 0, &screen_x, &screen_y, &screen_width, &screen_height); gdk_window_get_origin(gtk_widget_get_window(gui.drawarea), &x, &y); gtk_window_get_size(GTK_WINDOW(preedit_window), &width, &height); diff --git a/src/proto/gui_gtk_x11.pro b/src/proto/gui_gtk_x11.pro index 3f2604480..1d0a78b09 100644 --- a/src/proto/gui_gtk_x11.pro +++ b/src/proto/gui_gtk_x11.pro @@ -18,6 +18,8 @@ void gui_gtk_set_dnd_targets(void); int gui_mch_init(void); void gui_mch_forked(void); void gui_mch_new_colors(void); +void gui_gtk_get_screen_geom_of_win(GtkWidget *wid, int point_x, int point_y, int *screen_x, int *screen_y, int *width, int *height); +void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h); int gui_mch_open(void); void gui_mch_exit(int rc); int gui_mch_get_winpos(int *x, int *y); @@ -26,8 +28,6 @@ int gui_mch_maximized(void); void gui_mch_unmaximize(void); void gui_mch_newfont(void); void gui_mch_set_shellsize(int width, int height, int min_width, int min_height, int base_width, int base_height, int direction); -void gui_gtk_get_screen_geom_of_win(GtkWidget *wid, int *screen_x, int *screen_y, int *width, int *height); -void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h); void gui_mch_settitle(char_u *title, char_u *icon); void gui_mch_enable_menu(int showit); void gui_mch_show_toolbar(int showit); diff --git a/src/version.c b/src/version.c index 842d138f9..a650c813a 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2622, +/**/ 2621, /**/ 2620, |