I'm developing a openGL application for X windows and am currently looking at 
different ways to "fullscreen" a window.   Resizing is not so much the 
challenge as removing the window decoration.

FVWM is actually not a problem, since it responds to "motif hints" which are 
used in common libraries with openGL.  However, it also responds to EWMH hints, 
and I am wondering if anyone here has any experience using these.

I've attached the code I am currently using, the relevant function is 
fullscreenEWMH (about 45 lines).  Again, this works on fvwm, but returns an X 
"Bad Request" error anyway.  This may be an Xlib, and not a fvwm issue. On 
metacity, it functions erratically, which is why I am trying to determine the 
most proper method.   The metacity-devel mailing list unfortunately seems to be 
abandoned.  I'm also inquiring with the XDG people.

Sorry if this seems slightly off topic, I'm just hoping somebody here might 
have a simple quick answer about FULLSCREEN using "extended window manager 
hints".

-- 
MK <[email protected]>
/* window.c
 Some window managers (eg. metacity) really don't like glutFullScreen (Motif 
hints) and may even crash the app.
 Hopefully they are EWMH compliant! */


int checkEWMH(void) {
        Display *disp = XOpenDisplay(NULL);
        int form, retv = 0;
        unsigned long len, len2, i, j, remain;
        Window *list = NULL;
        char *name;
        Atom *actions;
        Atom act, prop, type;

        if (!disp) return 0;
        if (!(list = winlist(disp,&len))) return 0;

        prop = XInternAtom(disp,"_NET_WM_ALLOWED_ACTIONS",False);
        act = XInternAtom(disp,"_NET_WM_ACTION_FULLSCREEN",False);

        for (i=0;i<len;i++) {
                name = winame(disp,list[i]);
                if (!strcmp(name,GAMENAME)) {
                        XFree(name);
                        if 
(XGetWindowProperty(disp,list[i],prop,0,1024,False,XA_ATOM,
                                        &type,&form,&len2,&remain,(unsigned 
char**)&actions) != Success) {
                                XFree(list);
                                return 0;
                        }
                        for (j=0;j<len2;j++) 
                                if (act == actions[j]) retv = 1;
                        XFree(actions);
                        break;
                }
                XFree(name);
        }
        XFree(list);
        return retv;
}


void fullscreenEWMH(void) {             /* prototype matches glutFullScreen() */
        Window *list = NULL;
        Display *disp = XOpenDisplay(NULL);
        XEvent event;
        unsigned long len, i;
        //long mask = SubstructureNotifyMask;
        //long mask = StructureNotifyMask | ResizeRedirectMask;
        long mask = SubstructureRedirectMask | SubstructureNotifyMask;
        //long mask = PropertyChangeMask;
        char *name;
        Status r;

        if (!disp) return;
        if (!(list = winlist(disp,&len))) return;

        for (i=0;i<len;i++) {
                name = winame(disp,list[i]);
                if (!strcmp(name,GAMENAME)) {
                        XFree(name);
                        break;
                }
                XFree(name);
        }
        if (i == len) {
                XFree(list);
                return;
        }

        event.xclient.type = ClientMessage;
        event.xclient.serial = 0;
        event.xclient.send_event = True;
        event.xclient.display = disp;
        event.xclient.window = list[i];
        event.xclient.message_type = XInternAtom(disp,"_NET_WM_STATE",False);
        event.xclient.format = 32;
        event.xclient.data.l[0] = 1;  /* set (2 is toggle) */
        event.xclient.data.l[1] = 
XInternAtom(disp,"_NET_WM_STATE_FULLSCREEN",False);
        event.xclient.data.l[2] = 0;
        event.xclient.data.l[3] = 0;
        event.xclient.data.l[4] = 0;

        if ((r = XSendEvent(disp,XDefaultRootWindow(disp),False,mask,&event)) 
!= Success) 
                fprintf(stderr, "Couldn't get fullscreen...X error: %d\n", r);
        XFree(list);
}


Window *winlist (Display *disp, unsigned long *len) {
        Atom prop = XInternAtom(disp,"_NET_CLIENT_LIST",False), type;
        int form;
        unsigned long remain;
        unsigned char *list;

        if 
(XGetWindowProperty(disp,XDefaultRootWindow(disp),prop,0,1024,False,XA_WINDOW,&type,&form,len,&remain,&list)
 != Success)
                return NULL;
        
        return (Window*)list;
}


char *winame (Display *disp, Window win) {
        Atom prop = XInternAtom(disp,"WM_NAME",False), type;
        int form;
        unsigned long remain, len;
        unsigned char *list;

        if 
(XGetWindowProperty(disp,win,prop,0,1024,False,XA_STRING,&type,&form,&len,&remain,&list)
 != Success) return NULL;

        return (char*)list;
}

Reply via email to