GTK: stop using gtk_window_parse_geometry.

This function, which parses the X11-style '-geometry WxH+X+Y' option
argument and automatically loads the result into the window, is also
being deprecated.

Fortunately we already had a fallback option for GTK1 (which didn't
have gtk_window_parse_geometry in the first place), calling the Xlib
geometry-parsing function and manually loading the results into GTK.
The method of loading into GTK is not the same between the two
versions, but the basic strategy is still viable.

For the sake of maintaining and testing fewer ifdef branches, I've
removed the use of gtk_window_parse_geometry _completely_, even in
GTK2 which did have it. GTK2 now uses the same strategy that I've
switched to for GTK3.
This commit is contained in:
Simon Tatham 2016-04-04 11:27:01 +01:00
Родитель 4ba7ff006a
Коммит 8fd67a9c46
1 изменённых файлов: 26 добавлений и 14 удалений

Просмотреть файл

@ -94,11 +94,7 @@ struct gui_data {
GtkIMContext *imc;
#endif
unifont *fonts[4]; /* normal, bold, wide, widebold */
#if GTK_CHECK_VERSION(2,0,0)
const char *geometry;
#else
int xpos, ypos, gotpos, gravity;
#endif
GdkCursor *rawcursor, *textcursor, *blankcursor, *waitcursor, *currcursor;
GdkColor cols[NALLCOLOURS];
#if !GTK_CHECK_VERSION(3,0,0)
@ -341,6 +337,8 @@ void move_window(void *frontend, int x, int y)
* though.
*/
#if GTK_CHECK_VERSION(2,0,0)
/* in case we reset this at startup due to a geometry string */
gtk_window_set_gravity(GTK_WINDOW(inst->window), GDK_GRAVITY_NORTH_EAST);
gtk_window_move(GTK_WINDOW(inst->window), x, y);
#else
gdk_window_move(gtk_widget_get_window(inst->window), x, y);
@ -3669,10 +3667,14 @@ static void compute_geom_hints(struct gui_data *inst, GdkGeometry *geom)
void set_geom_hints(struct gui_data *inst)
{
GdkGeometry geom;
gint flags = GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE | GDK_HINT_RESIZE_INC;
compute_geom_hints(inst, &geom);
gtk_window_set_geometry_hints
(GTK_WINDOW(inst->window), NULL, &geom,
GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE | GDK_HINT_RESIZE_INC);
#if GTK_CHECK_VERSION(2,0,0)
if (inst->gotpos)
flags |= GDK_HINT_USER_POS;
#endif
gtk_window_set_geometry_hints(GTK_WINDOW(inst->window),
NULL, &geom, flags);
}
#if GTK_CHECK_VERSION(2,0,0)
@ -4153,11 +4155,8 @@ struct gui_data *new_session_window(Conf *conf, const char *geometry_string)
inst->cumulative_scroll = 0.0;
#endif
#ifndef NOT_X_WINDOWS
if (geometry_string) {
#if GTK_CHECK_VERSION(2,0,0)
inst->geometry = geometry_string;
#else
/* On GTK 1, we have to do this using raw Xlib */
int flags, x, y;
unsigned int w, h;
flags = XParseGeometry(geometry_string, &x, &y, &w, &h);
@ -4173,8 +4172,8 @@ struct gui_data *new_session_window(Conf *conf, const char *geometry_string)
inst->gravity = ((flags & XNegative ? 1 : 0) |
(flags & YNegative ? 2 : 0));
}
#endif
}
#endif
if (!compound_text_atom)
compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
@ -4254,8 +4253,21 @@ struct gui_data *new_session_window(Conf *conf, const char *geometry_string)
#endif
#if GTK_CHECK_VERSION(2,0,0)
if (inst->geometry) {
gtk_window_parse_geometry(GTK_WINDOW(inst->window), inst->geometry);
if (inst->gotpos) {
static const GdkGravity gravities[] = {
GDK_GRAVITY_NORTH_WEST,
GDK_GRAVITY_NORTH_EAST,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_SOUTH_EAST,
};
int x = inst->xpos, y = inst->ypos;
int wp, hp;
compute_whole_window_size(inst, inst->width, inst->height, &wp, &hp);
if (inst->gravity & 1) x += (gdk_screen_width() - wp);
if (inst->gravity & 2) y += (gdk_screen_height() - hp);
gtk_window_set_gravity(GTK_WINDOW(inst->window),
gravities[inst->gravity & 3]);
gtk_window_move(GTK_WINDOW(inst->window), x, y);
}
#else
if (inst->gotpos) {