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; GtkIMContext *imc;
#endif #endif
unifont *fonts[4]; /* normal, bold, wide, widebold */ unifont *fonts[4]; /* normal, bold, wide, widebold */
#if GTK_CHECK_VERSION(2,0,0)
const char *geometry;
#else
int xpos, ypos, gotpos, gravity; int xpos, ypos, gotpos, gravity;
#endif
GdkCursor *rawcursor, *textcursor, *blankcursor, *waitcursor, *currcursor; GdkCursor *rawcursor, *textcursor, *blankcursor, *waitcursor, *currcursor;
GdkColor cols[NALLCOLOURS]; GdkColor cols[NALLCOLOURS];
#if !GTK_CHECK_VERSION(3,0,0) #if !GTK_CHECK_VERSION(3,0,0)
@ -341,6 +337,8 @@ void move_window(void *frontend, int x, int y)
* though. * though.
*/ */
#if GTK_CHECK_VERSION(2,0,0) #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); gtk_window_move(GTK_WINDOW(inst->window), x, y);
#else #else
gdk_window_move(gtk_widget_get_window(inst->window), x, y); 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) void set_geom_hints(struct gui_data *inst)
{ {
GdkGeometry geom; GdkGeometry geom;
gint flags = GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE | GDK_HINT_RESIZE_INC;
compute_geom_hints(inst, &geom); compute_geom_hints(inst, &geom);
gtk_window_set_geometry_hints #if GTK_CHECK_VERSION(2,0,0)
(GTK_WINDOW(inst->window), NULL, &geom, if (inst->gotpos)
GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE | GDK_HINT_RESIZE_INC); 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) #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; inst->cumulative_scroll = 0.0;
#endif #endif
#ifndef NOT_X_WINDOWS
if (geometry_string) { 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; int flags, x, y;
unsigned int w, h; unsigned int w, h;
flags = XParseGeometry(geometry_string, &x, &y, &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) | inst->gravity = ((flags & XNegative ? 1 : 0) |
(flags & YNegative ? 2 : 0)); (flags & YNegative ? 2 : 0));
} }
#endif
} }
#endif
if (!compound_text_atom) if (!compound_text_atom)
compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE); 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 #endif
#if GTK_CHECK_VERSION(2,0,0) #if GTK_CHECK_VERSION(2,0,0)
if (inst->geometry) { if (inst->gotpos) {
gtk_window_parse_geometry(GTK_WINDOW(inst->window), inst->geometry); 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 #else
if (inst->gotpos) { if (inst->gotpos) {