12 #include <X11/extensions/shape.h>
15 /* local subsystem functions */
17 /* local subsystem globals */
18 static Display *dd = NULL;
19 static char *title = NULL, *str1 = NULL, *str2 = NULL;
21 static XFontStruct *fs = NULL;
23 static Window win = 0, b1 = 0, b2 = 0;
24 static int ww = 320, hh = 240, wx = 20, wy = 20;
26 EAPI unsigned long e_alert_composite_win = 0;
28 /* externally accessible functions */
30 e_alert_init(const char *disp)
34 XSetWindowAttributes att;
36 dd = XOpenDisplay(disp);
38 font = XLoadFont(dd, "fixed");
39 fs = XQueryFont(dd, font);
41 /* dont i18n this - i dont want gettext doing anything as this is called
43 title = "Enlightenment Error";
44 str1 = "(F1) Recover";
47 wid = DisplayWidth(dd, DefaultScreen(dd));
48 hih = DisplayHeight(dd, DefaultScreen(dd));
49 att.background_pixel = WhitePixel(dd, DefaultScreen(dd));
50 att.border_pixel = BlackPixel(dd, DefaultScreen(dd));
51 att.override_redirect = True;
52 mask = CWBackPixel | CWBorderPixel | CWOverrideRedirect;
57 win = XCreateWindow(dd, DefaultRootWindow(dd),
59 CopyFromParent, InputOutput,
60 CopyFromParent, mask, &att);
62 b1 = XCreateWindow(dd, win, -100, -100, 1, 1, 0, CopyFromParent,
63 InputOutput, CopyFromParent, mask, &att);
64 b2 = XCreateWindow(dd, win, -100, -100, 1, 1, 0, CopyFromParent,
65 InputOutput, CopyFromParent, mask, &att);
69 gc = XCreateGC(dd, win, 0, &gcv);
70 XSetForeground(dd, gc, att.border_pixel);
71 XSelectInput(dd, win, KeyPressMask | KeyReleaseMask | ExposureMask);
77 e_alert_shutdown(void)
81 XDestroyWindow(dd, win);
97 e_alert_show(const char *text)
115 fh = fs->ascent + fs->descent;
116 mh = ((ww - 20) / 2) - 20;
120 XMoveResizeWindow(dd, b1, w, hh - 15 - fh, mh + 10, fh + 10);
121 XSelectInput(dd, b1, ButtonPressMask | ButtonReleaseMask | ExposureMask);
123 XMoveResizeWindow(dd, b2, w, hh - 15 - fh, mh + 10, fh + 10);
124 XSelectInput(dd, b2, ButtonPressMask | ButtonReleaseMask | ExposureMask);
126 if (e_alert_composite_win)
135 XShapeCombineRectangles(dd, e_alert_composite_win, ShapeInput,
136 0, 0, &rect, 1, ShapeSet, Unsorted);
138 XReparentWindow(dd, win, e_alert_composite_win, wx, wy);
141 XGrabPointer(dd, win, True, ButtonPressMask | ButtonReleaseMask,
142 GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
143 XGrabKeyboard(dd, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
144 XSetInputFocus(dd, win, RevertToPointerRoot, CurrentTime);
154 key = XKeysymToKeycode(dd, XStringToKeysym("F1"));
155 if (key == ev.xkey.keycode)
160 key = XKeysymToKeycode(dd, XStringToKeysym("F2"));
161 if (key == ev.xkey.keycode)
168 if (ev.xbutton.window == b1)
170 else if (ev.xbutton.window == b2)
174 while (XCheckTypedWindowEvent(dd, ev.xexpose.window, Expose, &ev));
177 XDrawRectangle(dd, win, gc, 0, 0, ww - 1, hh - 1);
179 XDrawRectangle(dd, win, gc, 2, 2, ww - 4 - 1, fh + 4 - 1);
181 fw = XTextWidth(fs, title, strlen(title));
182 XDrawString(dd, win, gc, 2 + 2 + ((ww - 4 - 4 - fw) / 2) , 2 + 2 + fs->ascent, title, strlen(title));
189 line[j++] = text[i++];
190 if (line[j - 1] == '\n')
194 XDrawString(dd, win, gc, 4, k + fs->ascent, line, strlen(line));
198 fw = XTextWidth(fs, str1, strlen(str1));
199 XDrawRectangle(dd, b1, gc, 0, 0, mh - 1, fh + 10 - 1);
200 XDrawString(dd, b1, gc, 5 + ((mh - fw) / 2), 5 + fs->ascent, str1, strlen(str1));
202 fw = XTextWidth(fs, str2, strlen(str2));
203 XDrawRectangle(dd, b2, gc, 0, 0, mh - 1, fh + 10 - 1);
204 XDrawString(dd, b2, gc, 5 + ((mh - fw) / 2), 5 + fs->ascent, str2, strlen(str2));
213 XDestroyWindow(dd, win);
229 /* local subsystem functions */