Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XChangeProperty without effect after client exits

Tags:

c

x11

xlib

I am trying to write a simple program that changes the name of a window with a certain window id.

/* See LICENSE file for copyright and license details. */

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>

static void usage(char *);
static void set_title(Display* d, Window w, char* name);

static void
usage(char *name)
{
    fprintf(stderr, "usage: %s <name> <wid>\n", name);
    exit(1);
}

static void
set_title(Display* d, Window w, char* name)
{
    XEvent e;
    XSync(d, False);
    int ret=XChangeProperty(d, w,
        XInternAtom(d, "WM_NAME", False),
        XInternAtom(d, "STRING", False), 8,
        PropModeReplace, (unsigned char*)name, strlen(name)+1);
    if(ret==0)
        return;
    ret=XChangeProperty(d, w,
        XInternAtom(d, "_NET_WM_NAME", False),
        XInternAtom(d, "STRING", False), 8,
        PropModeReplace, (unsigned char*)name, strlen(name)+1);
}

int
main(int argc, char **argv)
{
    Display* d;
    char* name=argv[1];

    if (argc != 3)
        usage(argv[0]);

    d=XOpenDisplay(NULL);

    set_title(d, strtoul(argv[2], NULL, 16), name);

    XFlush(d);
    XCloseDisplay(d);

    return 0;
}

This works fine in a debugger, however, after the program finishes, the window name does not persist (using wname from wmutils (http://wmutils.io)).

Do I have to explicitely wait for an XEvent when I change a property before I can exit? What can I do to change a window property permanently?

like image 618
pranomostro Avatar asked Sep 26 '16 08:09

pranomostro


1 Answers

I am not able to reproduce this. I tried this with the application "Xfburn". Please see this session and let me know if I've misunderstood anything (xchangeproperty.c is your code):

$ gcc -g -O0 -o xchangeproperty xchangeproperty.c -lX11
$ xwininfo -name Xfburn | grep "Window id"
xwininfo: Window id: 0x4600003 "Xfburn"
$ ./wname 0x4600003
Xfburn
$ ./xchangeproperty pranomostro 0x4600003
$ echo $?
0
$ ./wname 0x4600003
pranomostro

I can also see the title on the Window change. This is tested on XUbuntu 16.04 with gcc:

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
like image 159
bleakgadfly Avatar answered Nov 12 '22 14:11

bleakgadfly