_NET_WM_STATE_FULLSCREEN



Hi.  I am trying to use EWMH to fullscreen windows under a number of
wm's claiming compliance.

I've attached the code I'm currently using for this.  The relevant
function is fullscreenEWMH(), about 40 lines.  The other 3 functions are
internal or for checking compliance.

Anyway, so far this works on fvwm and problematically on metacity -- it
will work when called on a window from a separate process, but not if
included in application code.   I've had a few suggestions from the
metacity-devel list (which appears abandoned) and xdg suggesting
setting the 4th element of the Xevent.data array to 1 or 2; this does
not help.  I'm also uncertain as to what event mask to use.

I'd also like to find out why XSendEvent always returns 1
('BadRequest'), regardless of whether the request works or not.

Thanks in advance.

-- 
MK <halfcountplus intergate com>
/* 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;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]