comparison src/gui_gtk_x11.c @ 24162:cb8b9bf76082 v8.2.2622

patch 8.2.2622: GTK: error when starting up and -geometry is given Commit: https://github.com/vim/vim/commit/a555e6fcb6ec97b5ab30b20a340b228f4d820f14 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 18 22:28:57 2021 +0100 patch 8.2.2622: GTK: error when starting up and -geometry is given 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 18 Mar 2021 22:30:04 +0100
parents b78b8c804af0
children 74f869d4bd54
comparison
equal deleted inserted replaced
24161:2766741b201d 24162:cb8b9bf76082
4153 #ifdef USE_GRESOURCE 4153 #ifdef USE_GRESOURCE
4154 gui_gtk_unregister_resource(); 4154 gui_gtk_unregister_resource();
4155 #endif 4155 #endif
4156 } 4156 }
4157 4157
4158 void
4159 gui_gtk_get_screen_geom_of_win(
4160 GtkWidget *wid,
4161 int point_x, // x position of window if not initialized
4162 int point_y, // y position of window if not initialized
4163 int *screen_x,
4164 int *screen_y,
4165 int *width,
4166 int *height)
4167 {
4168 GdkRectangle geometry;
4169 GdkWindow *win = gtk_widget_get_window(wid);
4170 #if GTK_CHECK_VERSION(3,22,0)
4171 GdkDisplay *dpy = gtk_widget_get_display(wid);
4172 GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
4173
4174 gdk_monitor_get_geometry(monitor, &geometry);
4175 #else
4176 GdkScreen* screen;
4177 int monitor;
4178
4179 if (wid != NULL && gtk_widget_has_screen(wid))
4180 screen = gtk_widget_get_screen(wid);
4181 else
4182 screen = gdk_screen_get_default();
4183 if (win == NULL)
4184 monitor = gdk_screen_get_monitor_at_point(screen, point_x, point_y);
4185 else
4186 monitor = gdk_screen_get_monitor_at_window(screen, win);
4187 gdk_screen_get_monitor_geometry(screen, monitor, &geometry);
4188 #endif
4189 *screen_x = geometry.x;
4190 *screen_y = geometry.y;
4191 *width = geometry.width;
4192 *height = geometry.height;
4193 }
4194
4195 /*
4196 * The screen size is used to make sure the initial window doesn't get bigger
4197 * than the screen. This subtracts some room for menubar, toolbar and window
4198 * decorations.
4199 */
4200 static void
4201 gui_gtk_get_screen_dimensions(
4202 int point_x,
4203 int point_y,
4204 int *screen_w,
4205 int *screen_h)
4206 {
4207 int x, y;
4208
4209 gui_gtk_get_screen_geom_of_win(gui.mainwin, point_x, point_y,
4210 &x, &y, screen_w, screen_h);
4211
4212 // Subtract 'guiheadroom' from the height to allow some room for the
4213 // window manager (task list and window title bar).
4214 *screen_h -= p_ghr;
4215
4216 /*
4217 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include
4218 * the toolbar and menubar for GTK, we subtract them from the screen
4219 * height, so that the window size can be made to fit on the screen.
4220 * This should be completely changed later.
4221 */
4222 *screen_w -= get_menu_tool_width();
4223 *screen_h -= get_menu_tool_height();
4224 }
4225
4226 void
4227 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
4228 {
4229 gui_gtk_get_screen_dimensions(0, 0, screen_w, screen_h);
4230 }
4231
4158 4232
4159 /* 4233 /*
4160 * Bit of a hack to ensure we start GtkPlug windows with the correct window 4234 * Bit of a hack to ensure we start GtkPlug windows with the correct window
4161 * hints (and thus the required size from -geom), but that after that we 4235 * hints (and thus the required size from -geom), but that after that we
4162 * put the hints back to normal (the actual minimum size) so we may 4236 * put the hints back to normal (the actual minimum size) so we may
4248 pixel_height += get_menu_tool_height(); 4322 pixel_height += get_menu_tool_height();
4249 4323
4250 if (mask & (XValue | YValue)) 4324 if (mask & (XValue | YValue))
4251 { 4325 {
4252 int ww, hh; 4326 int ww, hh;
4327
4328 #ifdef FEAT_GUI_GTK
4329 gui_gtk_get_screen_dimensions(x, y, &ww, &hh);
4330 #else
4253 gui_mch_get_screen_dimensions(&ww, &hh); 4331 gui_mch_get_screen_dimensions(&ww, &hh);
4332 #endif
4254 hh += p_ghr + get_menu_tool_height(); 4333 hh += p_ghr + get_menu_tool_height();
4255 ww += get_menu_tool_width(); 4334 ww += get_menu_tool_width();
4256 if (mask & XNegative) 4335 if (mask & XNegative)
4257 x += ww - pixel_width; 4336 x += ww - pixel_width;
4258 if (mask & YNegative) 4337 if (mask & YNegative)
4534 * 4613 *
4535 * This is a bit of a hack, since Vim is a terminal application with a GUI 4614 * This is a bit of a hack, since Vim is a terminal application with a GUI
4536 * on top, while the GUI expects to be the boss. 4615 * on top, while the GUI expects to be the boss.
4537 */ 4616 */
4538 gui_mch_update(); 4617 gui_mch_update();
4539 }
4540
4541 void
4542 gui_gtk_get_screen_geom_of_win(
4543 GtkWidget *wid,
4544 int *screen_x,
4545 int *screen_y,
4546 int *width,
4547 int *height)
4548 {
4549 GdkRectangle geometry;
4550 GdkWindow *win = gtk_widget_get_window(wid);
4551 #if GTK_CHECK_VERSION(3,22,0)
4552 GdkDisplay *dpy = gtk_widget_get_display(wid);
4553 GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
4554
4555 gdk_monitor_get_geometry(monitor, &geometry);
4556 #else
4557 GdkScreen* screen;
4558 int monitor;
4559
4560 if (wid != NULL && gtk_widget_has_screen(wid))
4561 screen = gtk_widget_get_screen(wid);
4562 else
4563 screen = gdk_screen_get_default();
4564 monitor = gdk_screen_get_monitor_at_window(screen, win);
4565 gdk_screen_get_monitor_geometry(screen, monitor, &geometry);
4566 #endif
4567 *screen_x = geometry.x;
4568 *screen_y = geometry.y;
4569 *width = geometry.width;
4570 *height = geometry.height;
4571 }
4572
4573 /*
4574 * The screen size is used to make sure the initial window doesn't get bigger
4575 * than the screen. This subtracts some room for menubar, toolbar and window
4576 * decorations.
4577 */
4578 void
4579 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
4580 {
4581 int x, y;
4582
4583 gui_gtk_get_screen_geom_of_win(gui.mainwin, &x, &y, screen_w, screen_h);
4584
4585 // Subtract 'guiheadroom' from the height to allow some room for the
4586 // window manager (task list and window title bar).
4587 *screen_h -= p_ghr;
4588
4589 /*
4590 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include
4591 * the toolbar and menubar for GTK, we subtract them from the screen
4592 * height, so that the window size can be made to fit on the screen.
4593 * This should be completely changed later.
4594 */
4595 *screen_w -= get_menu_tool_width();
4596 *screen_h -= get_menu_tool_height();
4597 } 4618 }
4598 4619
4599 #if defined(FEAT_TITLE) || defined(PROTO) 4620 #if defined(FEAT_TITLE) || defined(PROTO)
4600 void 4621 void
4601 gui_mch_settitle(char_u *title, char_u *icon UNUSED) 4622 gui_mch_settitle(char_u *title, char_u *icon UNUSED)