I'm developing a openGL application for X windows and am currently looking at
different ways to "fullscreen" a window, particularly EWMH which should cover a
number of popular window managers including ones which do not respond to Motif
hints.
I've attached the code I am currently using, the relevant function is
fullscreenEWMH (about 45 lines). This works on fvwm, but returns an Xlib "Bad
Request" (on XSendEvent() using ClientMessage) anyway. It does the same thing
in metacity, except that it will only work when issued from an external process
(ie, it does not work within the application itself).
If anyone can provide me with some info/docs/advice/examples, I'm willing to
prepare a brief sort of on-line tutorial on using EWMH, since as is now, the
only material I could find was source code from other applications.
--
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;
}
_______________________________________________
xdg mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xdg