Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Hidden Panic
Hidden Panic [message #22222] Thu, 25 June 2009 16:31 Go to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I have come across a problem with the Panic message box on X11, basically the same problem I had with Prompts. If there is a window with TopMost set on it in front of the Painc window it is impossible to read or click on.

Clearly the best solution would be to stop it crashing, but the modification below is a decent second best:

static void sPanicMessageBox(const char *title, const char *text)
{
	GuiLock __; 
	Ctrl::ReleaseCtrlCapture();
	XDisplay *display = XOpenDisplay(NULL);
	if(!display)
		return;
	int screen = DefaultScreen(display);
	int x = (DisplayWidth(display, screen) - 600) / 2;
	int y = (DisplayHeight(display, screen) - 120) / 2;
	Window win = XCreateSimpleWindow(display, RootWindow(display, screen),
	                                 x, y, 600, 120, 4,
	                                 BlackPixel(display, screen),
	                                 WhitePixel(display, screen));
	XSizeHints size_hints;
	size_hints.flags = PPosition|PSize|PMinSize;
	size_hints.x = x;
	size_hints.y = x;
	size_hints.width = 600;
	size_hints.height = 120;
	size_hints.min_width = 600;
	size_hints.min_height = 120;
	char *h[1];
	char hh[1];
	*hh = 0;
	h[0] = hh;
	XSetStandardProperties(display, win, title, title, None, h, 0, &size_hints);
	XSelectInput(display, win, ExposureMask|KeyPressMask|ButtonPressMask|StructureNotifyMask);
	XGCValues values;
	GC gc = XCreateGC(display, win, 0, &values);
	// New section
	unsigned long wina[1];
	wina[0] = XAtom("_NET_WM_STATE_ABOVE");
	XChangeProperty(display, win, XAtom("_NET_WM_STATE"), XAtom("ATOM"), 32,
	                PropModeReplace, (const unsigned char *)&wina, 1);
	XMapWindow(display, win);
	XSetInputFocus(display, win, RevertToParent, CurrentTime);
	// End section
	XRaiseWindow(display, win);
	XFontStruct *font_info = XQueryFont(display, XGContextFromGC(gc));
	for(;;) {
		XEvent e;
		XNextEvent(display, &e);
		switch(e.type) {
		case ButtonPress:
			XFreeFont(display, font_info);
			XFreeGC(display, gc);
			XCloseDisplay(display);
		#ifdef _DEBUG
			__BREAK__;
		#endif
			return;
		case Expose:
			int y = 20;
			const char *b = text;
			for(;;) {
				const char *e = strchr(b, '\n');
				if(!e) break;
				XDrawString(display, win, gc, 20, y, b, e - b);
				y += font_info->max_bounds.ascent + font_info->max_bounds.descent;
				b = e + 1;
			}
			XDrawString(display, win, gc, 20, y, b, strlen(b));
			break;
		}
	}
}

This ensures the window is both topmost and raised to the front of the stack. Could this be committed please?
Re: Hidden Panic [message #22223 is a reply to message #22222] Thu, 25 June 2009 18:53 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sure.

Mirek
Previous Topic: PromptYesNo = 1|0 not IDYES|IDNO ?
Next Topic: vectormap
Goto Forum:
  


Current Time: Thu Mar 28 13:43:13 CET 2024

Total time taken to generate the page: 0.00915 seconds