[hackers] [surf] Fix WM_CLASS and WM_WINDOW_ROLE properties || Quentin Rameau

From: <git_AT_suckless.org>
Date: Sun, 22 Nov 2015 12:02:51 +0100 (CET)

commit 3e017b1a89c1e0d8cb706638d0223afcf834e70d
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Sun Nov 22 11:53:19 2015 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Sun Nov 22 11:53:19 2015 +0100

    Fix WM_CLASS and WM_WINDOW_ROLE properties
    
    Instead of forcing class and instance names, which is what GTK does by
    default anyway, allow the user to set the instance name, but keep the
    general class as “Surf”.
    Is we won't support a “-name” parameter and don't implement a parsing of
    RESOURCE_NAME env variable, let's fallback on the third behaviour, use
    the name of the calling executable.
    That would let the user do things like 'ln -s ./surf ./surf-other;
    ./surf-other' and set different parameters for the two instances (in dwm
    for example).
    Try to generate a unique WM_WINDOW_ROLE (within the surf process)
    composed of “Surf” and the view ID.

diff --git a/surf.c b/surf.c
index bacf78f..8f85f7b 100644
--- a/surf.c
+++ b/surf.c
_AT_@ -948,6 +948,7 @@ showview(WebKitWebView *v, Client *c)
 GtkWidget *
 createwindow(Client *c)
 {
+ char *wmstr;
         GtkWidget *w;
 
         if (embed) {
_AT_@ -955,19 +956,14 @@ createwindow(Client *c)
         } else {
                 w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
- /* TA: 20091214: Despite what the GNOME docs say, the ICCCM
- * is always correct, so we should still call this function.
- * But when doing so, we *must* differentiate between a
- * WM_CLASS and a resource on the window. By convention, the
- * window class (WM_CLASS) is capped, while the resource is in
- * lowercase. Both these values come as a pair.
- */
- gtk_window_set_wmclass(GTK_WINDOW(w), "surf", "Surf");
+ wmstr = g_path_get_basename(argv0);
+ gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf");
+ g_free(wmstr);
 
- /* TA: 20091214: And set the role here as well -- so that
- * sessions can pick this up.
- */
- gtk_window_set_role(GTK_WINDOW(w), "Surf");
+ wmstr = g_strdup_printf("%s[%lu]", "Surf",
+ webkit_web_view_get_page_id(c->view));
+ gtk_window_set_role(GTK_WINDOW(w), wmstr);
+ g_free(wmstr);
 
                 gtk_window_set_default_size(GTK_WINDOW(w), 800, 600);
         }
Received on Sun Nov 22 2015 - 12:02:51 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 22 2015 - 12:12:13 CET