Skip to content

Commit a555e6f

Browse files
committed
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)
1 parent 108cf01 commit a555e6f

5 files changed

Lines changed: 85 additions & 62 deletions

File tree

src/gui_beval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ drawBalloon(BalloonEval *beval)
920920
screen = gtk_widget_get_screen(beval->target);
921921
gtk_window_set_screen(GTK_WINDOW(beval->balloonShell), screen);
922922
# endif
923-
gui_gtk_get_screen_geom_of_win(beval->target,
923+
gui_gtk_get_screen_geom_of_win(beval->target, 0, 0,
924924
&screen_x, &screen_y, &screen_w, &screen_h);
925925
# if !GTK_CHECK_VERSION(3,0,0)
926926
gtk_widget_ensure_style(beval->balloonShell);

src/gui_gtk_x11.c

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4155,6 +4155,80 @@ mainwin_destroy_cb(GObject *object UNUSED, gpointer data UNUSED)
41554155
#endif
41564156
}
41574157

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+
41584232

41594233
/*
41604234
* Bit of a hack to ensure we start GtkPlug windows with the correct window
@@ -4250,7 +4324,12 @@ gui_mch_open(void)
42504324
if (mask & (XValue | YValue))
42514325
{
42524326
int ww, hh;
4327+
4328+
#ifdef FEAT_GUI_GTK
4329+
gui_gtk_get_screen_dimensions(x, y, &ww, &hh);
4330+
#else
42534331
gui_mch_get_screen_dimensions(&ww, &hh);
4332+
#endif
42544333
hh += p_ghr + get_menu_tool_height();
42554334
ww += get_menu_tool_width();
42564335
if (mask & XNegative)
@@ -4538,64 +4617,6 @@ gui_mch_set_shellsize(int width, int height,
45384617
gui_mch_update();
45394618
}
45404619

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-
}
4598-
45994620
#if defined(FEAT_TITLE) || defined(PROTO)
46004621
void
46014622
gui_mch_settitle(char_u *title, char_u *icon UNUSED)

src/gui_xim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ im_preedit_window_set_position(void)
207207
if (preedit_window == NULL)
208208
return;
209209

210-
gui_gtk_get_screen_geom_of_win(gui.drawarea,
210+
gui_gtk_get_screen_geom_of_win(gui.drawarea, 0, 0,
211211
&screen_x, &screen_y, &screen_width, &screen_height);
212212
gdk_window_get_origin(gtk_widget_get_window(gui.drawarea), &x, &y);
213213
gtk_window_get_size(GTK_WINDOW(preedit_window), &width, &height);

src/proto/gui_gtk_x11.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ void gui_gtk_set_dnd_targets(void);
1818
int gui_mch_init(void);
1919
void gui_mch_forked(void);
2020
void gui_mch_new_colors(void);
21+
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);
22+
void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h);
2123
int gui_mch_open(void);
2224
void gui_mch_exit(int rc);
2325
int gui_mch_get_winpos(int *x, int *y);
@@ -26,8 +28,6 @@ int gui_mch_maximized(void);
2628
void gui_mch_unmaximize(void);
2729
void gui_mch_newfont(void);
2830
void gui_mch_set_shellsize(int width, int height, int min_width, int min_height, int base_width, int base_height, int direction);
29-
void gui_gtk_get_screen_geom_of_win(GtkWidget *wid, int *screen_x, int *screen_y, int *width, int *height);
30-
void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h);
3131
void gui_mch_settitle(char_u *title, char_u *icon);
3232
void gui_mch_enable_menu(int showit);
3333
void gui_mch_show_toolbar(int showit);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2622,
753755
/**/
754756
2621,
755757
/**/

0 commit comments

Comments
 (0)