1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-04-27 15:52:09 -05:00

Replace deprecated GDK_DISPLAY() with modern facilities.

We still don't actually support more than one X display active at
once, so it's sufficient to replace every call to that macro with
GDK_DISPLAY_XDISPLAY(gdk_display_get_default()).
This commit is contained in:
Simon Tatham 2015-08-16 09:23:32 +01:00
parent 5319c659ad
commit 1b3b993467
3 changed files with 51 additions and 31 deletions

View File

@ -76,6 +76,12 @@
#define gtk_widget_get_realized(w) GTK_WIDGET_REALIZED(w) #define gtk_widget_get_realized(w) GTK_WIDGET_REALIZED(w)
#define gtk_widget_get_state(w) GTK_WIDGET_STATE(w) #define gtk_widget_get_state(w) GTK_WIDGET_STATE(w)
/* This is a bit of a bodge because it relies on us only calling this
* macro as GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), so under
* GTK1 it makes sense to omit the contained function call and just
* return the GDK default display. */
#define GDK_DISPLAY_XDISPLAY(x) GDK_DISPLAY()
#define GDK_KEY_Alt_L GDK_Alt_L #define GDK_KEY_Alt_L GDK_Alt_L
#define GDK_KEY_Alt_R GDK_Alt_R #define GDK_KEY_Alt_R GDK_Alt_R
#define GDK_KEY_BackSpace GDK_BackSpace #define GDK_KEY_BackSpace GDK_BackSpace

View File

@ -25,6 +25,7 @@
#include "putty.h" #include "putty.h"
#include "gtkfont.h" #include "gtkfont.h"
#include "gtkcompat.h"
#include "tree234.h" #include "tree234.h"
/* /*
@ -218,7 +219,7 @@ static const struct unifont_vtable x11font_vtable = {
static char *x11_guess_derived_font_name(XFontStruct *xfs, int bold, int wide) static char *x11_guess_derived_font_name(XFontStruct *xfs, int bold, int wide)
{ {
Display *disp = GDK_DISPLAY(); Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
Atom fontprop = XInternAtom(disp, "FONT", False); Atom fontprop = XInternAtom(disp, "FONT", False);
unsigned long ret; unsigned long ret;
if (XGetFontProperty(xfs, fontprop, &ret)) { if (XGetFontProperty(xfs, fontprop, &ret)) {
@ -349,7 +350,7 @@ static unifont *x11font_create(GtkWidget *widget, const char *name,
{ {
struct x11font *xfont; struct x11font *xfont;
XFontStruct *xfs; XFontStruct *xfs;
Display *disp = GDK_DISPLAY(); Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
Atom charset_registry, charset_encoding, spacing; Atom charset_registry, charset_encoding, spacing;
unsigned long registry_ret, encoding_ret, spacing_ret; unsigned long registry_ret, encoding_ret, spacing_ret;
int pubcs, realcs, sixteen_bit, variable; int pubcs, realcs, sixteen_bit, variable;
@ -455,7 +456,7 @@ static unifont *x11font_create(GtkWidget *widget, const char *name,
static void x11font_destroy(unifont *font) static void x11font_destroy(unifont *font)
{ {
Display *disp = GDK_DISPLAY(); Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
struct x11font *xfont = (struct x11font *)font; struct x11font *xfont = (struct x11font *)font;
int i; int i;
@ -482,7 +483,7 @@ static void x11font_destroy(unifont *font)
static void x11_alloc_subfont(struct x11font *xfont, int sfid) static void x11_alloc_subfont(struct x11font *xfont, int sfid)
{ {
Display *disp = GDK_DISPLAY(); Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
char *derived_name = x11_guess_derived_font_name char *derived_name = x11_guess_derived_font_name
(xfont->fonts[0].xfs, sfid & 1, !!(sfid & 2)); (xfont->fonts[0].xfs, sfid & 1, !!(sfid & 2));
xfont->fonts[sfid].xfs = XLoadQueryFont(disp, derived_name); xfont->fonts[sfid].xfs = XLoadQueryFont(disp, derived_name);
@ -539,15 +540,17 @@ static int x11font_width_8(unifont_drawctx *ctx, x11font_individual *xfi,
#ifdef DRAW_TEXT_GDK #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)
{ {
XSetFont(GDK_DISPLAY(), GDK_GC_XGC(ctx->u.gdk.gc), xfi->xfs->fid); 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, static void x11font_gdk_draw_16(unifont_drawctx *ctx,
x11font_individual *xfi, int x, int y, x11font_individual *xfi, int x, int y,
const void *vstring, int start, int length) const void *vstring, int start, int length)
{ {
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
const XChar2b *string = (const XChar2b *)vstring; const XChar2b *string = (const XChar2b *)vstring;
XDrawString16(GDK_DISPLAY(), GDK_DRAWABLE_XID(ctx->u.gdk.target), XDrawString16(disp, GDK_DRAWABLE_XID(ctx->u.gdk.target),
GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length); GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length);
} }
@ -555,8 +558,9 @@ static void x11font_gdk_draw_8(unifont_drawctx *ctx,
x11font_individual *xfi, int x, int y, x11font_individual *xfi, int x, int y,
const void *vstring, int start, int length) const void *vstring, int start, int length)
{ {
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
const char *string = (const char *)vstring; const char *string = (const char *)vstring;
XDrawString(GDK_DISPLAY(), GDK_DRAWABLE_XID(ctx->u.gdk.target), XDrawString(disp, GDK_DRAWABLE_XID(ctx->u.gdk.target),
GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length); GDK_GC_XGC(ctx->u.gdk.gc), x, y, string+start, length);
} }
#endif #endif
@ -565,6 +569,7 @@ static void x11font_gdk_draw_8(unifont_drawctx *ctx,
static void x11font_cairo_setup(unifont_drawctx *ctx, x11font_individual *xfi) static void x11font_cairo_setup(unifont_drawctx *ctx, x11font_individual *xfi)
{ {
if (xfi->pixmap == None) { if (xfi->pixmap == None) {
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
XGCValues gcvals; XGCValues gcvals;
GdkWindow *widgetwin = gtk_widget_get_window(ctx->u.cairo.widget); GdkWindow *widgetwin = gtk_widget_get_window(ctx->u.cairo.widget);
int widgetscr = GDK_SCREEN_XNUMBER(gdk_window_get_screen(widgetwin)); int widgetscr = GDK_SCREEN_XNUMBER(gdk_window_get_screen(widgetwin));
@ -597,13 +602,13 @@ static void x11font_cairo_setup(unifont_drawctx *ctx, x11font_individual *xfi)
} }
xfi->pixmap = XCreatePixmap xfi->pixmap = XCreatePixmap
(GDK_DISPLAY(), (disp,
GDK_DRAWABLE_XID(gtk_widget_get_window(ctx->u.cairo.widget)), GDK_DRAWABLE_XID(gtk_widget_get_window(ctx->u.cairo.widget)),
xfi->pixwidth, xfi->pixheight, 1); xfi->pixwidth, xfi->pixheight, 1);
gcvals.foreground = WhitePixel(GDK_DISPLAY(), widgetscr); gcvals.foreground = WhitePixel(disp, widgetscr);
gcvals.background = BlackPixel(GDK_DISPLAY(), widgetscr); gcvals.background = BlackPixel(disp, widgetscr);
gcvals.font = xfi->xfs->fid; gcvals.font = xfi->xfs->fid;
xfi->gc = XCreateGC(GDK_DISPLAY(), xfi->pixmap, xfi->gc = XCreateGC(disp, xfi->pixmap,
GCForeground | GCBackground | GCFont, &gcvals); GCForeground | GCBackground | GCFont, &gcvals);
} }
} }
@ -613,11 +618,12 @@ static void x11font_cairo_cache_glyph(x11font_individual *xfi, int glyphindex)
XImage *image; XImage *image;
int x, y; int x, y;
unsigned char *bitmap; unsigned char *bitmap;
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
bitmap = snewn(xfi->allsize, unsigned char); bitmap = snewn(xfi->allsize, unsigned char);
memset(bitmap, 0, xfi->allsize); memset(bitmap, 0, xfi->allsize);
image = XGetImage(GDK_DISPLAY(), xfi->pixmap, 0, 0, image = XGetImage(disp, xfi->pixmap, 0, 0,
xfi->pixwidth, xfi->pixheight, AllPlanes, XYPixmap); xfi->pixwidth, xfi->pixheight, AllPlanes, XYPixmap);
for (y = 0; y < xfi->pixheight; y++) { for (y = 0; y < xfi->pixheight; y++) {
for (x = 0; x < xfi->pixwidth; x++) { for (x = 0; x < xfi->pixwidth; x++) {
@ -666,6 +672,7 @@ static void x11font_cairo_draw_16(unifont_drawctx *ctx,
x11font_individual *xfi, int x, int y, x11font_individual *xfi, int x, int y,
const void *vstring, int start, int length) const void *vstring, int start, int length)
{ {
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
const XChar2b *string = (const XChar2b *)vstring + start; const XChar2b *string = (const XChar2b *)vstring + start;
int i; int i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
@ -674,7 +681,7 @@ static void x11font_cairo_draw_16(unifont_drawctx *ctx,
(unsigned char)string[i].byte2); (unsigned char)string[i].byte2);
if (glyphindex >= xfi->nglyphs || if (glyphindex >= xfi->nglyphs ||
!xfi->glyphcache[glyphindex].surface) { !xfi->glyphcache[glyphindex].surface) {
XDrawImageString16(GDK_DISPLAY(), xfi->pixmap, xfi->gc, XDrawImageString16(disp, xfi->pixmap, xfi->gc,
xfi->pixoriginx, xfi->pixoriginy, xfi->pixoriginx, xfi->pixoriginy,
string+i, 1); string+i, 1);
x11font_cairo_cache_glyph(xfi, glyphindex); x11font_cairo_cache_glyph(xfi, glyphindex);
@ -689,6 +696,7 @@ static void x11font_cairo_draw_8(unifont_drawctx *ctx,
x11font_individual *xfi, int x, int y, x11font_individual *xfi, int x, int y,
const void *vstring, int start, int length) const void *vstring, int start, int length)
{ {
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
const char *string = (const char *)vstring + start; const char *string = (const char *)vstring + start;
int i; int i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
@ -696,7 +704,7 @@ static void x11font_cairo_draw_8(unifont_drawctx *ctx,
int glyphindex = (unsigned char)string[i]; int glyphindex = (unsigned char)string[i];
if (glyphindex >= xfi->nglyphs || if (glyphindex >= xfi->nglyphs ||
!xfi->glyphcache[glyphindex].surface) { !xfi->glyphcache[glyphindex].surface) {
XDrawImageString(GDK_DISPLAY(), xfi->pixmap, xfi->gc, XDrawImageString(disp, xfi->pixmap, xfi->gc,
xfi->pixoriginx, xfi->pixoriginy, xfi->pixoriginx, xfi->pixoriginy,
string+i, 1); string+i, 1);
x11font_cairo_cache_glyph(xfi, glyphindex); x11font_cairo_cache_glyph(xfi, glyphindex);
@ -866,13 +874,14 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
static void x11font_enum_fonts(GtkWidget *widget, static void x11font_enum_fonts(GtkWidget *widget,
fontsel_add_entry callback, void *callback_ctx) fontsel_add_entry callback, void *callback_ctx)
{ {
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
char **fontnames; char **fontnames;
char *tmp = NULL; char *tmp = NULL;
int nnames, i, max, tmpsize; int nnames, i, max, tmpsize;
max = 32768; max = 32768;
while (1) { while (1) {
fontnames = XListFonts(GDK_DISPLAY(), "*", max, &nnames); fontnames = XListFonts(disp, "*", max, &nnames);
if (nnames >= max) { if (nnames >= max) {
XFreeFontNames(fontnames); XFreeFontNames(fontnames);
max *= 2; max *= 2;
@ -1047,7 +1056,7 @@ static char *x11font_canonify_fontname(GtkWidget *widget, const char *name,
* selector treats them as worthwhile in their own right. * selector treats them as worthwhile in their own right.
*/ */
XFontStruct *xfs; XFontStruct *xfs;
Display *disp = GDK_DISPLAY(); Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
Atom fontprop, fontprop2; Atom fontprop, fontprop2;
unsigned long ret; unsigned long ret;

View File

@ -153,7 +153,8 @@ static void exit_callback(void *vinst);
char *x_get_default(const char *key) char *x_get_default(const char *key)
{ {
#ifndef NOT_X_WINDOWS #ifndef NOT_X_WINDOWS
return XGetDefault(GDK_DISPLAY(), app_name, key); return XGetDefault(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
app_name, key);
#else #else
return NULL; return NULL;
#endif #endif
@ -1868,21 +1869,22 @@ void init_cutbuffers()
{ {
#ifndef NOT_X_WINDOWS #ifndef NOT_X_WINDOWS
unsigned char empty[] = ""; unsigned char empty[] = "";
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER1, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER1, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER2, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER2, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER3, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER3, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER4, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER4, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER5, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER5, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), XChangeProperty(disp, GDK_ROOT_WINDOW(),
XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0); XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0);
#endif #endif
} }
@ -1891,9 +1893,10 @@ void init_cutbuffers()
void store_cutbuffer(char * ptr, int len) void store_cutbuffer(char * ptr, int len)
{ {
#ifndef NOT_X_WINDOWS #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. */ /* ICCCM says we must rotate the buffers before storing to buffer 0. */
XRotateBuffers(GDK_DISPLAY(), 1); XRotateBuffers(disp, 1);
XStoreBytes(GDK_DISPLAY(), ptr, len); XStoreBytes(disp, ptr, len);
#endif #endif
} }
@ -1903,8 +1906,9 @@ void store_cutbuffer(char * ptr, int len)
char * retrieve_cutbuffer(int * nbytes) char * retrieve_cutbuffer(int * nbytes)
{ {
#ifndef NOT_X_WINDOWS #ifndef NOT_X_WINDOWS
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
char * ptr; char * ptr;
ptr = XFetchBytes(GDK_DISPLAY(), nbytes); ptr = XFetchBytes(disp, nbytes);
if (*nbytes <= 0 && ptr != 0) { if (*nbytes <= 0 && ptr != 0) {
XFree(ptr); XFree(ptr);
ptr = 0; ptr = 0;
@ -1935,6 +1939,7 @@ void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_des
#ifndef NOT_X_WINDOWS #ifndef NOT_X_WINDOWS
XTextProperty tp; XTextProperty tp;
char *list[1]; char *list[1];
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
#endif #endif
inst->pasteout_data_utf8 = snewn(len*6, char); inst->pasteout_data_utf8 = snewn(len*6, char);
@ -1958,7 +1963,7 @@ void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_des
*/ */
#ifndef NOT_X_WINDOWS #ifndef NOT_X_WINDOWS
list[0] = inst->pasteout_data_utf8; list[0] = inst->pasteout_data_utf8;
if (Xutf8TextListToTextProperty(GDK_DISPLAY(), list, 1, if (Xutf8TextListToTextProperty(disp, list, 1,
XCompoundTextStyle, &tp) == 0) { XCompoundTextStyle, &tp) == 0) {
inst->pasteout_data_ctext = snewn(tp.nitems+1, char); inst->pasteout_data_ctext = snewn(tp.nitems+1, char);
memcpy(inst->pasteout_data_ctext, tp.value, tp.nitems); memcpy(inst->pasteout_data_ctext, tp.value, tp.nitems);
@ -2157,13 +2162,13 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
#ifndef NOT_X_WINDOWS #ifndef NOT_X_WINDOWS
XTextProperty tp; XTextProperty tp;
int ret, count; int ret, count;
Display *disp = GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
tp.value = (unsigned char *)seldata_data; tp.value = (unsigned char *)seldata_data;
tp.encoding = (Atom) seldata_type; tp.encoding = (Atom) seldata_type;
tp.format = gtk_selection_data_get_format(seldata); tp.format = gtk_selection_data_get_format(seldata);
tp.nitems = seldata_length; tp.nitems = seldata_length;
ret = Xutf8TextPropertyToTextList(GDK_DISPLAY(), &tp, ret = Xutf8TextPropertyToTextList(disp, &tp, &list, &count);
&list, &count);
if (ret == 0 && count == 1) { if (ret == 0 && count == 1) {
text = list[0]; text = list[0];
length = strlen(list[0]); length = strlen(list[0]);