From af08a7a3b15ea4d8cb10d52465f52ba9633e5ec2 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 7 Mar 2017 22:57:42 +0000 Subject: [PATCH] Replace deprecated gtk_window_set_wmclass with raw Xlib. Calling gtk_widget_realize to enforce the existence of an underlying GdkWindow, followed by gdk_window_ensure_native to enforce an underlying X window in turn, allows me to get hold of an X window id on which I can call the Xlib function for setting WM_CLASS, still before the window is mapped. With this change, plus Colin's preceding patches, the whole code base _actually_ compiles and links against GTK 3.22 without any deprecation warnings. (My claim in commit 8ce237234 that it previously did appears to have been completely wrong - my guess is that I'd forgotten to 'make clean' before testing against 3.22 and so some source files had already been compiled against earlier GTK headers.) --- unix/gtkwin.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 4bafbdbd..85c9af0c 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -4387,9 +4387,34 @@ struct gui_data *new_session_window(Conf *conf, const char *geometry_string) gtk_widget_set_name(GTK_WIDGET(inst->window), "top-level"); { const char *winclass = conf_get_str(inst->conf, CONF_winclass); - if (*winclass) + if (*winclass) { +#if GTK_CHECK_VERSION(3,22,0) +#ifndef NOT_X_WINDOWS + 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)); + XClassHint *xch = XAllocClassHint(); + xch->res_name = (char *)winclass; + xch->res_class = (char *)winclass; + XSetClassHint(disp, GDK_WINDOW_XID(gdkwin), xch); + XFree(xch); + } +#endif + /* + * If we do have NOT_X_WINDOWS set, then we don't have any + * function in GTK 3.22 equivalent to the above. But then, + * surely in that situation the deprecated + * gtk_window_set_wmclass wouldn't have done anything + * meaningful in previous GTKs either. + */ +#else gtk_window_set_wmclass(GTK_WINDOW(inst->window), winclass, winclass); +#endif + } } /*