Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <errno.h>
/* compile -lX11 */
Atom *actionlist (Display *disp, Window win, unsigned long *len);
char *atomtype (Atom x);
int getprop (Display *disp, char *name, Window win);
void makeRequest(Display *disp, Window win, char *req);
Window *winlist (Display *disp, unsigned long *len);
char *winame (Display *disp, Window win);
int main(int argc, char *argv[]) {
int i,j;
unsigned long len, l2;
Display *disp = XOpenDisplay(NULL);
Window *list;
Atom *actions, act;
char *name, *props[] = {
/* these are NOT defined in any header */
"_NET_SUPPORTED",
"_NET_CLIENT_LIST",
"WM_NAME"
};
if (!disp) {
puts("no display!");
return -1;
}
for (i=0;i<3;i++) getprop(disp,props[i],XDefaultRootWindow(disp));
list = (Window*)winlist(disp,&len);
act = XInternAtom(disp,"_NET_WM_ACTION_FULLSCREEN",False);
for (i=0;i<(int)len;i++) {
name = winame(disp,list[i]);
printf("\n%s:\n",name);
if (argc == 2 && !strcmp(name,argv[1])) {
makeRequest(disp,list[i],"_NET_WM_STATE_FULLSCREEN");
printf("Tried\n"); fflush(stdout);
}
free(name);
getprop(disp,"_NET_WM_ALLOWED_ACTIONS",list[i]);
actions = actionlist(disp,list[i],&l2);
for (j=0;j<l2;j++) if (actions[j] == act) puts("\t***Fullscreen Available***");
XFree(actions);
}
XFree(list);
XCloseDisplay(disp);
return 0;
}
Atom *actionlist (Display *disp, Window win, unsigned long *len) {
Atom prop = XInternAtom(disp,"_NET_WM_ALLOWED_ACTIONS",False), type;
int form;
unsigned long remain;
unsigned char *list;
errno = 0;
if (XGetWindowProperty(disp,win,prop,0,1024,False,XA_ATOM,&type,&form,len,&remain,&list) != Success) {
perror("actionlist() -- GetWinProp");
return 0;
}
return (Atom*)list;
}
char *atomtype (Atom x) {
char *type = malloc(32);
switch (x) {
case XA_PRIMARY:
strcpy(type,"XA_PRIMARY");
break;
case XA_SECONDARY:
strcpy(type,"XA_SECONDARY");
break;
case XA_ARC:
strcpy(type,"XA_ARC");
break;
case XA_ATOM:
strcpy(type,"XA_ATOM");
break;
case XA_CARDINAL:
strcpy(type,"XA_CARDINAL");
break;
case XA_INTEGER:
strcpy(type,"XA_INTEGER");
break;
case XA_STRING:
strcpy(type,"XA_STRING");
break;
case XA_WINDOW:
strcpy(type,"XA_WINDOW");
break;
case XA_WM_HINTS:
strcpy(type,"XA_WM_HINTS");
break;
default:
sprintf(type,"unlisted (%lu), see Xatom.h",x);
break;
}
return type;
}
int getprop (Display *disp, char *name, Window win) {
Atom prop = XInternAtom(disp,name,False), type;
int form, r = 0;
unsigned long len, remain;
unsigned char *list;
char *tname;
errno = 0;
if (XGetWindowProperty(disp,win,prop,0,1024,False,AnyPropertyType,&type,&form,&len,&remain,&list) != Success) {
perror("GetWinProp");
return 0;
}
if (type == None) printf("%s is not available.\n",name);
else {
tname = atomtype(type);
printf ("%s (type %s, %lu %d-bit items) remaining: %lu\n",name,tname,len,form,remain);
XFree(tname);
r = 1;
}
XFree(list);
return r;
}
void makeRequest(Display *disp, Window win, char *req) {
XEvent event;
Status r;
long mask = SubstructureRedirectMask | SubstructureNotifyMask;
//long mask = SubstructureNotifyMask;
//long mask = StructureNotifyMask | ResizeRedirectMask;
//long mask = SubstructureRedirectMask;
//long mask = PropertyChangeMask;
event.xclient.type = ClientMessage;
event.xclient.serial = 0;
event.xclient.send_event = True;
event.xclient.display = disp;
event.xclient.window = win;
event.xclient.message_type = XInternAtom(disp,"_NET_WM_STATE",False);
event.xclient.format = 32;
event.xclient.data.l[0] = 1;
event.xclient.data.l[1] = XInternAtom(disp,req,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) printf("makeRequest error: %d\n",r);
}
Window *winlist (Display *disp, unsigned long *len) {
Atom prop = XInternAtom(disp,"_NET_CLIENT_LIST",False), type;
int form;
unsigned long remain;
unsigned char *list;
errno = 0;
if (XGetWindowProperty(disp,XDefaultRootWindow(disp),prop,0,1024,False,XA_WINDOW,&type,&form,len,&remain,&list) != Success) {
perror("winlist() -- GetWinProp");
return 0;
}
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;
errno = 0;
if (XGetWindowProperty(disp,win,prop,0,1024,False,XA_STRING,&type,&form,&len,&remain,&list) != Success) {
perror("winlist() -- GetWinProp");
return NULL;
}
//printf("%s %d\n",(char*)list, len); fflush(stdout);
return (char*)list;
}
Compile that: