void IpcPrintf(const char *fmt, ...) { char tmp[FILEPATH_LEN_MAX]; int len; va_list args; if (!ipc_active) return; va_start(args, fmt); len = Evsnprintf(tmp, sizeof(tmp), fmt, args); va_end(args); ipc_bufptr = EREALLOC(char, ipc_bufptr, ipc_bufsiz + len + 1); memcpy(ipc_bufptr + ipc_bufsiz, tmp, len); ipc_bufsiz += len; }
static void ShowAlert(const char *title, const char *ignore, const char *restart, const char *quit, const char *fmt, va_list args) { char text[4096], buf1[64], buf2[64], buf3[64]; Window win, b1 = 0, b2 = 0, b3 = 0, root; Display *dd; int wid, hih, w, h, i, k, mask; XGCValues gcv; GC gc; unsigned int len; XEvent ev; XSetWindowAttributes att; XRectangle rect1, rect2; char colorful; unsigned long cols[5]; XColor xcl; Colormap cmap; int cnum, fh, x, y, ww, hh, bw, bh; char *str1, *str2, *str3, *p; KeyCode keycode; int button; char **missing_charset_list_return, *def_string_return; int missing_charset_count_return; XFontStruct **font_struct_list_return; char **font_name_list_return; #if 0 /* Don't play sound here (maybe if not forked/in signal handler - later) */ SoundPlay(SOUND_ALERT); #endif if (!fmt) return; Evsnprintf(text, sizeof(text), fmt, args); /* * We may get here from obscure places like an X-error or signal handler * and things seem to work properly only if we do a new XOpenDisplay(). */ dd = XOpenDisplay(NULL); if (!dd) { fprintf(stderr, "%s\n", text); fflush(stderr); return; } button = 0; if (!title) title = _("Enlightenment Error"); str1 = AlertButtonText(1, buf1, sizeof(buf1), ignore); str2 = AlertButtonText(2, buf2, sizeof(buf2), restart); str3 = AlertButtonText(3, buf3, sizeof(buf3), quit); cnum = 0; colorful = 0; cols[0] = cols[1] = cols[2] = cols[3] = cols[4] = 0; cmap = DefaultColormap(dd, DefaultScreen(dd)); if (DefaultDepth(dd, DefaultScreen(dd)) > 4) { ExSetColor(&xcl, 220, 220, 220); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 160, 160, 160); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 100, 100, 100); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 0, 0, 0); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; ExSetColor(&xcl, 255, 255, 255); if (!XAllocColor(dd, cmap, &xcl)) goto CN; cols[cnum++] = xcl.pixel; colorful = 1; } CN: if (colorful) att.background_pixel = cols[1]; else att.background_pixel = BlackPixel(dd, DefaultScreen(dd)); if (colorful) att.border_pixel = cols[3]; else att.border_pixel = WhitePixel(dd, DefaultScreen(dd)); att.backing_store = Always; att.save_under = True; att.override_redirect = True; mask = CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder | CWBackingStore; #if USE_COMPOSITE_OVERLAY_WINDOW /* * Intended workings: * Composite extension not enabled (or COW not available?) * - fall back to root * Composite extension enabled * - use COW whether or not compositing is enabled, window mode too */ root = XCompositeGetOverlayWindow(dd, DefaultRootWindow(dd)); if (root == None) #endif { root = DefaultRootWindow(dd); } win = XCreateWindow(dd, root, -100, -100, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); gc = XCreateGC(dd, win, 0, &gcv); if (colorful) XSetForeground(dd, gc, cols[3]); else XSetForeground(dd, gc, att.border_pixel); xfs = XCreateFontSet(dd, "fixed", &missing_charset_list_return, &missing_charset_count_return, &def_string_return); if (!xfs) goto done; if (missing_charset_list_return) XFreeStringList(missing_charset_list_return); k = XFontsOfFontSet(xfs, &font_struct_list_return, &font_name_list_return); fh = 0; for (i = 0; i < k; i++) { h = font_struct_list_return[i]->ascent + font_struct_list_return[i]->descent; if (fh < h) fh = h; } XSelectInput(dd, win, ExposureMask); XMapWindow(dd, win); XGrabServer(dd); XGrabPointer(dd, win, False, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); XGrabKeyboard(dd, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); XSetInputFocus(dd, win, RevertToPointerRoot, CurrentTime); XSync(dd, False); wid = DisplayWidth(dd, DefaultScreen(dd)); hih = DisplayHeight(dd, DefaultScreen(dd)); ww = (wid >= 600) ? 600 : (wid / 40) * 40; hh = (hih >= 440) ? 440 : (hih / 40) * 40; for (i = 40; i < ww; i += 40) { w = i; h = (i * hh) / ww; x = (wid - w) >> 1; y = (hih - h) >> 1; XMoveResizeWindow(dd, win, x, y, w, h); DRAW_BOX_OUT(dd, gc, win, 0, 0, w, h); XSync(dd, False); SleepUs(20000); } x = (wid - ww) >> 1; y = (hih - hh) >> 1; XMoveResizeWindow(dd, win, x, y, ww, hh); XSync(dd, False); bw = 0; if (str1) { ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2); bw = (rect2.width > bw) ? rect2.width : bw; } if (str2) { ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2); bw = (rect2.width > bw) ? rect2.width : bw; } if (str3) { ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2); bw = (rect2.width > bw) ? rect2.width : bw; } bw += 20; bh = fh + 10; #define BX(i) (5 + (((ww - bw - 10) * (i)) / 2)) #define BY (hh - bh - 5) if (str1) { b1 = XCreateWindow(dd, win, BX(0), BY, bw, bh, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); XMapWindow(dd, b1); } if (str2) { b2 = XCreateWindow(dd, win, BX(1), BY, bw, bh, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); XMapWindow(dd, b2); } if (str3) { b3 = XCreateWindow(dd, win, BX(2), BY, bw, bh, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &att); XMapWindow(dd, b3); } XSync(dd, False); button = 0; for (; button == 0;) { XNextEvent(dd, &ev); switch (ev.type) { case KeyPress: keycode = XKeysymToKeycode(dd, XK_F1); if (keycode == ev.xkey.keycode) { DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh); XSync(dd, False); SleepUs(500000); DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh); button = 1; goto do_sync; } keycode = XKeysymToKeycode(dd, XK_F2); if (keycode == ev.xkey.keycode) { DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh); XSync(dd, False); SleepUs(500000); DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh); button = 2; goto do_sync; } keycode = XKeysymToKeycode(dd, XK_F3); if (keycode == ev.xkey.keycode) { DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh); XSync(dd, False); SleepUs(500000); DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh); button = 3; goto do_sync; } break; case ButtonPress: if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh)) break; x = BX(0); if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh); goto do_sync; } x = BX(1); if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh); goto do_sync; } x = BX(2); if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh); goto do_sync; } break; case ButtonRelease: if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh)) break; x = BX(0); if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh); button = 1; goto do_sync; } x = BX(1); if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh); button = 2; goto do_sync; } x = BX(2); if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw) { DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh); button = 3; goto do_sync; } break; case Expose: /* Flush all other Expose events */ while (XCheckTypedWindowEvent(dd, ev.xexpose.window, Expose, &ev)) ; ExTextExtents(xfs, title, strlen(title), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, win, (ww - w) / 2, 5 - rect2.y, title); DRAW_BOX_OUT(dd, gc, win, 0, 0, ww, bh); DRAW_BOX_OUT(dd, gc, win, 0, bh - 1, ww, hh - fh - fh - 30 + 2); DRAW_BOX_OUT(dd, gc, win, 0, hh - fh - 20, ww, fh + 20); k = bh; for (p = text;; p += len + 1) { len = strcspn(p, "\n"); DRAW_STRING(dd, gc, win, 6, 6 + k + fh, p, len); k += fh + 2; if (p[len] == '\0') break; } if (str1) { ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, b1, (bw - w) / 2, 5 - rect2.y, str1); DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh); DRAW_THIN_BOX_IN(dd, gc, win, BX(0) - 2, BY - 2, bw + 4, bh + 4); } if (str2) { ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, b2, (bw - w) / 2, 5 - rect2.y, str2); DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh); DRAW_THIN_BOX_IN(dd, gc, win, BX(1) - 2, BY - 2, bw + 4, bh + 4); } if (str3) { ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2); w = rect2.width; DRAW_HEADER(dd, gc, b3, (bw - w) / 2, 5 - rect2.y, str3); DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh); DRAW_THIN_BOX_IN(dd, gc, win, BX(2) - 2, BY - 2, bw + 4, bh + 4); } do_sync: XSync(dd, False); break; default: break; } } XFreeFontSet(dd, xfs); done: XUngrabServer(dd); XDestroyWindow(dd, win); XFreeGC(dd, gc); if (cnum > 0) XFreeColors(dd, cmap, cols, cnum, 0); XCloseDisplay(dd); switch (button) { default: case 1: break; case 2: SessionExit(EEXIT_RESTART, NULL); break; case 3: SessionExit(EEXIT_EXIT, NULL); break; } }