Question

I'm writing a small window manager, that add a basic decoration around a window, but actually i have several question about adding/remove decoration of a window.

First Question

Actually the decoration is added during MapNotify event, but it seems to be not a good idea, because it add decoration also to a menu opened by an application everytime the mapnotify is fired with a new window, but i want only to add decoration to main window. Maybe i have to check if the current window is a child of another window ? Actually my code just create the decoration window with a specific name, so at every MapNotify request i give the decoration window a dummy name (Parent) to distinguish it from all other windows in that way if the MapNotify event is launched on a decoration window, at least it doesn't add another decoration. But i don't understand if MapNotify is launched not only for parent window but also for childrend probably the risk is that i add more than one decoration window. The actual code is the following:

void map_notify_handler(XEvent local_event, Display* display, ScreenInfos infos){
    printf("Map Notify\n");
    XWindowAttributes win_attr;
    char *child_name;
    XGetWindowAttributes(display, local_event.xmap.window, &win_attr);
    XFetchName(display, local_event.xmap.window, &child_name);
    printf("Attributes: W: %d - H: %d - Name: %s\n", win_attr.width, win_attr.height, child_name);
    if(child_name!=NULL){
      if(strcmp(child_name, "Parent")){
        Window new_win = draw_window_with_name(display, RootWindow(display, infos.screen_num), "Parent", infos.screen_num, 
                           win_attr.x, win_attr.y, win_attr.width, win_attr.height+DECORATION_HEIGHT, 0, 
                           BlackPixel(display, infos.screen_num));
        XMapWindow(display, new_win);
        XReparentWindow(display,local_event.xmap.window, new_win,0, DECORATION_HEIGHT);
        XSelectInput(display, local_event.xmap.window, SubstructureNotifyMask);
        put_text(display, new_win, child_name, "9x15", 10, 10, BlackPixel(display,infos.screen_num), WhitePixel(display, infos.screen_num));
      }
    }
    XFree(child_name);
}

So how to avoid adding of decoration on every window except the main application window (or the popup windows, there is a way to distinguish the type of window? How can i figure it out?)

Second Question

WHen i exit a program the window that is destroyed is just the application window not the parent decoration, how to destroy the current window and also the decoration?

I tried with the following:

void destroy_notify_handler(XEvent local_event, Display *display){
    Window window = local_event.xdestroywindow.event;
    XDestroyWindow(display, window);
}

But i receive the following error:

Error occurred: BadWindow (invalid Window parameter)

I use event instead of window because it seems that it contains the parent window (i read it from there: http://tronche.com/gui/x/xlib/events/window-state-change/destroy.html) But even if i use window i have the same problem.

Or maybe i have to destroy the parent window earlier? Maybe during UnMapNotify? But how to understand if the event is launched just because the window is going to be closed or for some other reasons?

Thanks for the help :)

Était-ce utile?

La solution

Read EWMH spec and you'll find answers to all questions.

  1. Check "override redirect" window flag
  2. You are trying to destroy window which is already destroyed. Instead of using event.xdestroywindow.event window id just delete your decoration window.
  3. Don't forget to add client window to save set if you are writing reparenting WM. That way if you kill wm application windows are not destroyed but reparented back to root window
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top