From 5e55b7a978248a2f740bfb0d6570517e3e5f260a Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 8 Aug 2015 18:22:05 +0100 Subject: [PATCH] Switch to using gtk_window_parse_geometry in GTK 2. On GTK versions where it's available, this is a much nicer way of handling the -geometry command-line option, since not only do we get all the faffing about with gravity for free, it also automatically sets the user-position WM hints. --- unix/gtkwin.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 12c47710..3df71b00 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -84,7 +84,11 @@ 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]; GdkColormap *colmap; @@ -2830,25 +2834,30 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch, SECOND_PASS_ONLY; conf_set_str(conf, CONF_line_codepage, val); -#ifndef NOT_X_WINDOWS } else if (!strcmp(p, "-geometry")) { - int flags, x, y; - unsigned int w, h; EXPECTS_ARG; SECOND_PASS_ONLY; - flags = XParseGeometry(val, &x, &y, &w, &h); - if (flags & WidthValue) - conf_set_int(conf, CONF_width, w); - if (flags & HeightValue) - conf_set_int(conf, CONF_height, h); +#if GTK_CHECK_VERSION(2,0,0) + inst->geometry = val; +#else + /* On GTK 1, we have to do this using raw Xlib */ + { + int flags, x, y; + unsigned int w, h; + flags = XParseGeometry(val, &x, &y, &w, &h); + if (flags & WidthValue) + conf_set_int(conf, CONF_width, w); + if (flags & HeightValue) + conf_set_int(conf, CONF_height, h); - if (flags & (XValue | YValue)) { - inst->xpos = x; - inst->ypos = y; - inst->gotpos = TRUE; - inst->gravity = ((flags & XNegative ? 1 : 0) | - (flags & YNegative ? 2 : 0)); + if (flags & (XValue | YValue)) { + inst->xpos = x; + inst->ypos = y; + inst->gotpos = TRUE; + inst->gravity = ((flags & XNegative ? 1 : 0) | + (flags & YNegative ? 2 : 0)); + } } #endif @@ -3839,6 +3848,11 @@ int pt_main(int argc, char **argv) gtk_widget_hide(inst->sbar); gtk_widget_show(GTK_WIDGET(inst->hbox)); +#if GTK_CHECK_VERSION(2,0,0) + if (inst->geometry) { + gtk_window_parse_geometry(GTK_WINDOW(inst->window), inst->geometry); + } +#else if (inst->gotpos) { int x = inst->xpos, y = inst->ypos; GtkRequisition req; @@ -3848,6 +3862,7 @@ int pt_main(int argc, char **argv) gtk_window_set_position(GTK_WINDOW(inst->window), GTK_WIN_POS_NONE); gtk_widget_set_uposition(GTK_WIDGET(inst->window), x, y); } +#endif g_signal_connect(G_OBJECT(inst->window), "destroy", G_CALLBACK(destroy), inst);