diff --git a/unix/gtkcompat.h b/unix/gtkcompat.h index 43a3181c..c0341c34 100644 --- a/unix/gtkcompat.h +++ b/unix/gtkcompat.h @@ -177,6 +177,10 @@ #endif /* 2.24 */ +#if !GTK_CHECK_VERSION(3,0,0) +#define GDK_IS_X11_WINDOW(window) (1) +#endif + #if GTK_CHECK_VERSION(3,0,0) #define STANDARD_OK_LABEL "_OK" #define STANDARD_OPEN_LABEL "_Open" diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 119c428c..737163f2 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -24,6 +24,7 @@ #include #include #include +#include "x11misc.h" #endif #ifdef TESTMODE @@ -1776,9 +1777,12 @@ static void filefont_clicked(GtkButton *button, gpointer data) GdkFont *font = gdk_font_load(fontname); if (font) { XFontStruct *xfs = GDK_FONT_XFONT(font); - Display *disp = GDK_FONT_XDISPLAY(font); + Display *disp = get_x11_display(); Atom fontprop = XInternAtom(disp, "FONT", False); unsigned long ret; + + assert(disp); /* this is GTK1! */ + gdk_font_ref(font); if (XGetFontProperty(xfs, fontprop, &ret)) { char *name = XGetAtomName(disp, (Atom)ret); diff --git a/unix/gtkfont.c b/unix/gtkfont.c index bb4c709a..4dd7919c 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -31,6 +31,7 @@ #include #include #include +#include "x11misc.h" #endif /* @@ -177,6 +178,11 @@ typedef struct x11font_individual { struct x11font { struct unifont u; + /* + * Copy of the X display handle, so we don't have to keep + * extracting it from GDK. + */ + Display *disp; /* * Individual physical X fonts. We store a number of these, for * automatically guessed bold and wide variants. @@ -308,9 +314,9 @@ static char *xlfd_recompose(const struct xlfd_decomposed *dec) #undef ARG_INT } -static char *x11_guess_derived_font_name(XFontStruct *xfs, int bold, int wide) +static char *x11_guess_derived_font_name(Display *disp, XFontStruct *xfs, + int bold, int wide) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); Atom fontprop = XInternAtom(disp, "FONT", False); unsigned long ret; if (XGetFontProperty(xfs, fontprop, &ret)) { @@ -428,12 +434,15 @@ static unifont *x11font_create(GtkWidget *widget, const char *name, { struct x11font *xfont; XFontStruct *xfs; - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + Display *disp; Atom charset_registry, charset_encoding, spacing; unsigned long registry_ret, encoding_ret, spacing_ret; int pubcs, realcs, sixteen_bit, variable; int i; + if ((disp = get_x11_display()) == NULL) + return NULL; + xfs = XLoadQueryFont(disp, name); if (!xfs) return NULL; @@ -508,6 +517,7 @@ static unifont *x11font_create(GtkWidget *widget, const char *name, #else #error No drawtype available at all #endif + xfont->disp = disp; xfont->real_charset = realcs; xfont->sixteen_bit = sixteen_bit; xfont->variable = variable; @@ -534,8 +544,8 @@ static unifont *x11font_create(GtkWidget *widget, const char *name, static void x11font_destroy(unifont *font) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); struct x11font *xfont = (struct x11font *)font; + Display *disp = xfont->disp; int i; for (i = 0; i < lenof(xfont->fonts); i++) { @@ -561,9 +571,9 @@ static void x11font_destroy(unifont *font) static void x11_alloc_subfont(struct x11font *xfont, int sfid) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + Display *disp = xfont->disp; char *derived_name = x11_guess_derived_font_name - (xfont->fonts[0].xfs, sfid & 1, !!(sfid & 2)); + (disp, xfont->fonts[0].xfs, sfid & 1, !!(sfid & 2)); xfont->fonts[sfid].xfs = XLoadQueryFont(disp, derived_name); xfont->fonts[sfid].allocated = TRUE; sfree(derived_name); @@ -618,27 +628,25 @@ static int x11font_width_8(unifont_drawctx *ctx, x11font_individual *xfi, } #ifdef DRAW_TEXT_GDK -static void x11font_gdk_setup(unifont_drawctx *ctx, x11font_individual *xfi) +static void x11font_gdk_setup(unifont_drawctx *ctx, x11font_individual *xfi, + Display *disp) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); XSetFont(disp, GDK_GC_XGC(ctx->u.gdk.gc), xfi->xfs->fid); } -static void x11font_gdk_draw_16(unifont_drawctx *ctx, - x11font_individual *xfi, int x, int y, +static void x11font_gdk_draw_16(unifont_drawctx *ctx, x11font_individual *xfi, + Display *disp, int x, int y, const void *vstring, int start, int length) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); const XChar2b *string = (const XChar2b *)vstring; XDrawString16(disp, GDK_DRAWABLE_XID(ctx->u.gdk.target), GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length); } -static void x11font_gdk_draw_8(unifont_drawctx *ctx, - x11font_individual *xfi, int x, int y, +static void x11font_gdk_draw_8(unifont_drawctx *ctx, x11font_individual *xfi, + Display *disp, int x, int y, const void *vstring, int start, int length) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); const char *string = (const char *)vstring; XDrawString(disp, GDK_DRAWABLE_XID(ctx->u.gdk.target), GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length); @@ -646,10 +654,10 @@ static void x11font_gdk_draw_8(unifont_drawctx *ctx, #endif #ifdef DRAW_TEXT_CAIRO -static void x11font_cairo_setup(unifont_drawctx *ctx, x11font_individual *xfi) +static void x11font_cairo_setup( + unifont_drawctx *ctx, x11font_individual *xfi, Display *disp) { if (xfi->pixmap == None) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); XGCValues gcvals; GdkWindow *widgetwin = gtk_widget_get_window(ctx->u.cairo.widget); int widgetscr = GDK_SCREEN_XNUMBER(gdk_window_get_screen(widgetwin)); @@ -693,12 +701,12 @@ static void x11font_cairo_setup(unifont_drawctx *ctx, x11font_individual *xfi) } } -static void x11font_cairo_cache_glyph(x11font_individual *xfi, int glyphindex) +static void x11font_cairo_cache_glyph( + Display *disp, x11font_individual *xfi, int glyphindex) { XImage *image; int x, y; unsigned char *bitmap; - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); const XCharStruct *xcs = x11_char_struct(xfi->xfs, glyphindex >> 8, glyphindex & 0xFF); @@ -752,11 +760,10 @@ static void x11font_cairo_draw_glyph(unifont_drawctx *ctx, } } -static void x11font_cairo_draw_16(unifont_drawctx *ctx, - x11font_individual *xfi, int x, int y, - const void *vstring, int start, int length) +static void x11font_cairo_draw_16( + unifont_drawctx *ctx, x11font_individual *xfi, Display *disp, + int x, int y, const void *vstring, int start, int length) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); const XChar2b *string = (const XChar2b *)vstring + start; int i; for (i = 0; i < length; i++) { @@ -768,7 +775,7 @@ static void x11font_cairo_draw_16(unifont_drawctx *ctx, XDrawImageString16(disp, xfi->pixmap, xfi->gc, xfi->pixoriginx, xfi->pixoriginy, string+i, 1); - x11font_cairo_cache_glyph(xfi, glyphindex); + x11font_cairo_cache_glyph(disp, xfi, glyphindex); } x11font_cairo_draw_glyph(ctx, xfi, x, y, glyphindex); x += XTextWidth16(xfi->xfs, string+i, 1); @@ -776,11 +783,10 @@ static void x11font_cairo_draw_16(unifont_drawctx *ctx, } } -static void x11font_cairo_draw_8(unifont_drawctx *ctx, - x11font_individual *xfi, int x, int y, - const void *vstring, int start, int length) +static void x11font_cairo_draw_8( + unifont_drawctx *ctx, x11font_individual *xfi, Display *disp, + int x, int y, const void *vstring, int start, int length) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); const char *string = (const char *)vstring + start; int i; for (i = 0; i < length; i++) { @@ -791,7 +797,7 @@ static void x11font_cairo_draw_8(unifont_drawctx *ctx, XDrawImageString(disp, xfi->pixmap, xfi->gc, xfi->pixoriginx, xfi->pixoriginy, string+i, 1); - x11font_cairo_cache_glyph(xfi, glyphindex); + x11font_cairo_cache_glyph(disp, xfi, glyphindex); } x11font_cairo_draw_glyph(ctx, xfi, x, y, glyphindex); x += XTextWidth(xfi->xfs, string+i, 1); @@ -803,9 +809,10 @@ static void x11font_cairo_draw_8(unifont_drawctx *ctx, struct x11font_drawfuncs { int (*width)(unifont_drawctx *ctx, x11font_individual *xfi, const void *vstring, int start, int length); - void (*setup)(unifont_drawctx *ctx, x11font_individual *xfi); - void (*draw)(unifont_drawctx *ctx, x11font_individual *xfi, int x, int y, - const void *vstring, int start, int length); + void (*setup)(unifont_drawctx *ctx, x11font_individual *xfi, + Display *disp); + void (*draw)(unifont_drawctx *ctx, x11font_individual *xfi, Display *disp, + int x, int y, const void *vstring, int start, int length); }; /* @@ -843,12 +850,11 @@ static const struct x11font_drawfuncs x11font_drawfuncs[2*DRAWTYPE_NTYPES] = { #endif }; -static void x11font_really_draw_text(const struct x11font_drawfuncs *dfns, - unifont_drawctx *ctx, - x11font_individual *xfi, int x, int y, - const void *string, int nchars, - int shadowoffset, - int fontvariable, int cellwidth) +static void x11font_really_draw_text( + const struct x11font_drawfuncs *dfns, unifont_drawctx *ctx, + x11font_individual *xfi, Display *disp, + int x, int y, const void *string, int nchars, + int shadowoffset, int fontvariable, int cellwidth) { int start = 0, step, nsteps, centre; @@ -869,16 +875,17 @@ static void x11font_really_draw_text(const struct x11font_drawfuncs *dfns, centre = FALSE; } - dfns->setup(ctx, xfi); + dfns->setup(ctx, xfi, disp); while (nsteps-- > 0) { int X = x; if (centre) X += (cellwidth - dfns->width(ctx, xfi, string, start, step)) / 2; - dfns->draw(ctx, xfi, X, y, string, start, step); + dfns->draw(ctx, xfi, disp, X, y, string, start, step); if (shadowoffset) - dfns->draw(ctx, xfi, X + shadowoffset, y, string, start, step); + dfns->draw(ctx, xfi, disp, X + shadowoffset, y, + string, start, step); x += cellwidth; start += step; @@ -935,7 +942,7 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, } x11font_really_draw_text(x11font_drawfuncs + index + 1, ctx, - &xfont->fonts[sfid], x, y, + &xfont->fonts[sfid], xfont->disp, x, y, xcs, len, shadowoffset, xfont->variable, cellwidth * mult); sfree(xcs); @@ -948,7 +955,7 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, int sblen = wc_to_mb(xfont->real_charset, 0, string, len, sbstring, len+1, ".", NULL, NULL); x11font_really_draw_text(x11font_drawfuncs + index + 0, ctx, - &xfont->fonts[sfid], x, y, + &xfont->fonts[sfid], xfont->disp, x, y, sbstring, sblen, shadowoffset, xfont->variable, cellwidth * mult); sfree(sbstring); @@ -972,11 +979,14 @@ static void x11font_draw_combining(unifont_drawctx *ctx, unifont *font, static void x11font_enum_fonts(GtkWidget *widget, fontsel_add_entry callback, void *callback_ctx) { - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + Display *disp; char **fontnames; char *tmp = NULL; int nnames, i, max, tmpsize; + if ((disp = get_x11_display()) == NULL) + return; + max = 32768; while (1) { fontnames = XListFonts(disp, "*", max, &nnames); @@ -1145,10 +1155,13 @@ static char *x11font_canonify_fontname(GtkWidget *widget, const char *name, * selector treats them as worthwhile in their own right. */ XFontStruct *xfs; - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + Display *disp; Atom fontprop, fontprop2; unsigned long ret; + if ((disp = get_x11_display()) == NULL) + return NULL; + xfs = XLoadQueryFont(disp, name); if (!xfs) @@ -1191,7 +1204,7 @@ static char *x11font_scale_fontname(GtkWidget *widget, const char *name, static char *x11font_size_increment(unifont *font, int increment) { struct x11font *xfont = (struct x11font *)font; - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + Display *disp = xfont->disp; Atom fontprop = XInternAtom(disp, "FONT", False); char *returned_name = NULL; unsigned long ret; diff --git a/unix/gtkmain.c b/unix/gtkmain.c index 67581604..8136676e 100644 --- a/unix/gtkmain.c +++ b/unix/gtkmain.c @@ -41,6 +41,7 @@ #include #include #include +#include "x11misc.h" #endif static char *progname, **gtkargvstart; @@ -54,8 +55,10 @@ static const char *app_name = "pterm"; char *x_get_default(const char *key) { #ifndef NOT_X_WINDOWS - return XGetDefault(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - app_name, key); + Display *disp; + if ((disp = get_x11_display()) == NULL) + return NULL; + return XGetDefault(disp, app_name, key); #else return NULL; #endif diff --git a/unix/gtkmisc.c b/unix/gtkmisc.c index 23f26d07..e9fcaa75 100644 --- a/unix/gtkmisc.c +++ b/unix/gtkmisc.c @@ -15,6 +15,11 @@ #include "putty.h" #include "gtkcompat.h" +#ifndef NOT_X_WINDOWS +#include +#include +#endif + void get_label_text_dimensions(const char *text, int *width, int *height) { /* @@ -206,3 +211,14 @@ char *buildinfo_gtk_version(void) return dupprintf("%d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); } + +#ifndef NOT_X_WINDOWS +Display *get_x11_display(void) +{ +#if GTK_CHECK_VERSION(3,0,0) + if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) + return NULL; +#endif + return GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); +} +#endif diff --git a/unix/gtkwin.c b/unix/gtkwin.c index b058db27..640b4b15 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -97,6 +97,9 @@ struct gui_data { GtkWidget *menu, *specialsmenu, *specialsitem1, *specialsitem2, *restartitem; GtkWidget *sessionsmenu; +#ifndef NOT_X_WINDOWS + Display *disp; +#endif #ifndef NO_BACKING_PIXMAPS /* * Server-side pixmap which we use to cache the terminal window's @@ -2854,31 +2857,36 @@ void frontend_request_paste(void *frontend, int clipboard) */ /* Store the data in a cut-buffer. */ -static void store_cutbuffer(char * ptr, int len) +static void store_cutbuffer(struct gui_data *inst, char *ptr, int len) { #ifndef NOT_X_WINDOWS - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); - /* ICCCM says we must rotate the buffers before storing to buffer 0. */ - XRotateBuffers(disp, 1); - XStoreBytes(disp, ptr, len); + if (inst->disp) { + /* ICCCM says we must rotate the buffers before storing to buffer 0. */ + XRotateBuffers(inst->disp, 1); + XStoreBytes(inst->disp, ptr, len); + } #endif } /* Retrieve data from a cut-buffer. * Returned data needs to be freed with XFree(). */ -static char *retrieve_cutbuffer(int *nbytes) +static char *retrieve_cutbuffer(struct gui_data *inst, int *nbytes) { #ifndef NOT_X_WINDOWS - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); - char * ptr; - ptr = XFetchBytes(disp, nbytes); + char *ptr; + if (!inst->disp) { + *nbytes = 0; + return NULL; + } + ptr = XFetchBytes(inst->disp, nbytes); if (*nbytes <= 0 && ptr != 0) { XFree(ptr); ptr = 0; } return ptr; #else + *nbytes = 0; return NULL; #endif } @@ -2907,7 +2915,6 @@ void write_clip(void *frontend, int clipboard, #ifndef NOT_X_WINDOWS XTextProperty tp; char *list[1]; - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); #endif state->pasteout_data_utf8 = snewn(len*6, char); @@ -2931,8 +2938,8 @@ void write_clip(void *frontend, int clipboard, */ #ifndef NOT_X_WINDOWS list[0] = state->pasteout_data_utf8; - if (Xutf8TextListToTextProperty(disp, list, 1, - XCompoundTextStyle, &tp) == 0) { + if (inst->disp && Xutf8TextListToTextProperty( + inst->disp, list, 1, XCompoundTextStyle, &tp) == 0) { state->pasteout_data_ctext = snewn(tp.nitems+1, char); memcpy(state->pasteout_data_ctext, tp.value, tp.nitems); state->pasteout_data_ctext_len = tp.nitems; @@ -2966,7 +2973,7 @@ void write_clip(void *frontend, int clipboard, /* The legacy X cut buffers go with PRIMARY, not any other clipboard */ if (state->atom == GDK_SELECTION_PRIMARY) - store_cutbuffer(state->pasteout_data, state->pasteout_data_len); + store_cutbuffer(inst, state->pasteout_data, state->pasteout_data_len); if (gtk_selection_owner_set(inst->area, state->atom, inst->input_event_time)) { @@ -3131,7 +3138,7 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata, */ if (seldata_length <= 0) { #ifndef NOT_X_WINDOWS - text = retrieve_cutbuffer(&length); + text = retrieve_cutbuffer(inst, &length); if (length == 0) return; /* Xterm is rumoured to expect Latin-1, though I havn't checked the @@ -3149,13 +3156,13 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata, #ifndef NOT_X_WINDOWS XTextProperty tp; int ret, count; - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); tp.value = (unsigned char *)seldata_data; tp.encoding = (Atom) seldata_type; tp.format = gtk_selection_data_get_format(seldata); tp.nitems = seldata_length; - ret = Xutf8TextPropertyToTextList(disp, &tp, &list, &count); + ret = inst->disp == NULL ? -1 : + Xutf8TextPropertyToTextList(inst->disp, &tp, &list, &count); if (ret == 0 && count == 1) { text = list[0]; length = strlen(list[0]); @@ -3220,32 +3227,33 @@ void init_clipboard(struct gui_data *inst) * Ensure that all the cut buffers exist - according to the ICCCM, * we must do this before we start using cut buffers. */ - unsigned char empty[] = ""; - Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER1, XA_STRING, 8, PropModeAppend, empty, 0); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER2, XA_STRING, 8, PropModeAppend, empty, 0); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER3, XA_STRING, 8, PropModeAppend, empty, 0); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER4, XA_STRING, 8, PropModeAppend, empty, 0); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER5, XA_STRING, 8, PropModeAppend, empty, 0); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0); - x11_ignore_error(disp, BadMatch); - XChangeProperty(disp, GDK_ROOT_WINDOW(), - XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0); + if (inst->disp) { + unsigned char empty[] = ""; + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER0, + XA_STRING, 8, PropModeAppend, empty, 0); + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER1, + XA_STRING, 8, PropModeAppend, empty, 0); + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER2, + XA_STRING, 8, PropModeAppend, empty, 0); + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER3, + XA_STRING, 8, PropModeAppend, empty, 0); + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER4, + XA_STRING, 8, PropModeAppend, empty, 0); + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER5, + XA_STRING, 8, PropModeAppend, empty, 0); + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER6, + XA_STRING, 8, PropModeAppend, empty, 0); + x11_ignore_error(inst->disp, BadMatch); + XChangeProperty(inst->disp, GDK_ROOT_WINDOW(), XA_CUT_BUFFER7, + XA_STRING, 8, PropModeAppend, empty, 0); + } #endif inst->clipstates[CLIP_PRIMARY].atom = GDK_SELECTION_PRIMARY; @@ -4060,10 +4068,14 @@ const char *get_x_display(void *frontend) } #ifndef NOT_X_WINDOWS -long get_windowid(void *frontend) +int get_windowid(void *frontend, long *id) { struct gui_data *inst = (struct gui_data *)frontend; - return (long)GDK_WINDOW_XID(gtk_widget_get_window(inst->area)); + GdkWindow *window = gtk_widget_get_window(inst->area); + if (!GDK_IS_X11_WINDOW(window)) + return FALSE; + *id = GDK_WINDOW_XID(window); + return TRUE; } #endif @@ -4992,6 +5004,7 @@ void new_session_window(Conf *conf, const char *geometry_string) #endif #ifndef NOT_X_WINDOWS + inst->disp = get_x11_display(); if (geometry_string) { int flags, x, y; unsigned int w, h; @@ -5046,13 +5059,11 @@ void new_session_window(Conf *conf, const char *geometry_string) GdkWindow *gdkwin; gtk_widget_realize(GTK_WIDGET(inst->window)); gdkwin = gtk_widget_get_window(GTK_WIDGET(inst->window)); - if (gdk_window_ensure_native(gdkwin)) { - Display *disp = - GDK_DISPLAY_XDISPLAY(gdk_window_get_display(gdkwin)); + if (inst->disp && gdk_window_ensure_native(gdkwin)) { XClassHint *xch = XAllocClassHint(); xch->res_name = (char *)winclass; xch->res_class = (char *)winclass; - XSetClassHint(disp, GDK_WINDOW_XID(gdkwin), xch); + XSetClassHint(inst->disp, GDK_WINDOW_XID(gdkwin), xch); XFree(xch); } #endif diff --git a/unix/unix.h b/unix/unix.h index e6609aa9..a6dcaca0 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -195,7 +195,7 @@ void app_menu_action(void *frontend, enum MenuAction); /* Things pty.c needs from pterm.c */ const char *get_x_display(void *frontend); int font_dimension(void *frontend, int which);/* 0 for width, 1 for height */ -long get_windowid(void *frontend); +int get_windowid(void *frontend, long *id); /* Things gtkdlg.c needs from pterm.c */ #ifdef MAY_REFER_TO_GTK_IN_HEADERS diff --git a/unix/uxpty.c b/unix/uxpty.c index 4387ad8f..a6069ce6 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -742,6 +742,7 @@ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf, int slavefd; pid_t pid, pgrp; #ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */ + int got_windowid; long windowid; #endif Pty pty; @@ -794,7 +795,7 @@ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf, #endif #ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */ - windowid = get_windowid(pty->frontend); + got_windowid = get_windowid(pty->frontend, &windowid); #endif /* @@ -909,7 +910,7 @@ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf, */ } #ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */ - { + if (got_windowid) { char *windowid_env_var = dupprintf("WINDOWID=%ld", windowid); putenv(windowid_env_var); /* We mustn't free windowid_env_var, as putenv links it into the diff --git a/unix/x11misc.h b/unix/x11misc.h index 0ad14764..159d4226 100644 --- a/unix/x11misc.h +++ b/unix/x11misc.h @@ -12,4 +12,9 @@ */ void x11_ignore_error(Display *disp, unsigned char errcode); +/* + * gtkmisc.c + */ +Display *get_x11_display(void); + #endif