tags:

views:

23

answers:

1

Context:

I use glfw under xmonad. Glfw apparently sets the window title after creating the window, thus not allowing xmonad to properly handle it. I want to modify the glfw source so that I can set the window title before creating the window.

Problem:

So I download glfw-2.6, and I look into lib/x11/x11_window.c ; the lines causing the trouble are:

// Create a window
_glfwWin.Win = XCreateWindow(
    _glfwLibrary.Dpy,
    RootWindow( _glfwLibrary.Dpy, _glfwWin.VI->screen ),
    0, 0,                            // Upper left corner
    _glfwWin.Width, _glfwWin.Height, // Width, height
    0,                               // Borderwidth
    _glfwWin.VI->depth,              // Depth
    InputOutput,
    _glfwWin.VI->visual,
    CWBorderPixel | CWColormap | CWEventMask,
    &wa
);

Followed sometime later by:

_glfwPlatformSetWindowTitle( "GLFW Window" );

where

void _glfwPlatformSetWindowTitle( const char *title )
{
    // Set window & icon title
    XStoreName( _glfwLibrary.Dpy, _glfwWin.Win, title );
    XSetIconName( _glfwLibrary.Dpy, _glfwWin.Win, title );
}

Now, if I tr yto move the glfwPlatformSetWindowTitle call before the CreateWindow call, I get a segfault -- as I should, since _glfwWin.win would not be defined.

I don't know how to solve this problem since to set the window title, I need _glfwWin.Win to be initialized, but to initialize it, I need to create the window.

Thus, I ask: in X11, what is the proper way to set the window title before creating the window?

Thanks!

+3  A: 

This is not possible in X11, but also not necessary for stuff to work. There must be a bug somewhere causing the symptoms you're seeing. The window title is just a property on the window, and properties can't exist until there's a window for them to be on.

You say "not allowing xmonad to properly handle it" which implies it isn't coping with changes to the name; window managers absolutely must handle setting the title at any time, including changing the title long after a window is created.

What the spec says (http://www.x.org/docs/ICCCM/icccm.pdf) is: "The window manager will examine the contents of these properties when the window makes the transition from the Withdrawn state and will monitor some properties for changes while the window is in the Iconic or Normal state."

The "transition from the Withdrawn state" is the point where glfw calls XMapWindow(). At that point, the window will remain unmapped but the WM will receive a MapRequest. The WM would then read properties and such and then map the window. All window managers I've ever seen also handle later changes to the property because changing the window title is pretty normal. For example web browsers the page title on every url.

If xmonad doesn't handle changes maybe it at least waits for the map, so maybe you just need to set title before XMapWindow(). Really all setup should be done before MapWindow though only a few properties are required to be before it by the specs. The props that must be before it generally can't be changed without unmapping.

Incidentally, _glfwPlatformSetWindowTitle won't work for anything but Latin-1. The modern way to do it is to set _NET_WM_NAME and _NET_WM_ICON_NAME with XChangeProperty() (setting the old Latin-1 WM_NAME is fine too but only as a fallback).

Havoc P