X.height,
0, X.depth,
Config->palette[0]);
+
+ /* register interest in the delete window message */
+ Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
+ XSetWMProtocols(X.display, X.window, &wmDeleteMessage, 1);
+
+ /* setup window attributes and events */
XSetWindowAttributes swa;
swa.backing_store = WhenMapped;
swa.bit_gravity = NorthWestGravity;
| KeyPressMask
| ExposureMask
| FocusChangeMask);
+
/* set input methods */
if ((X.xim = XOpenIM(X.display, 0, 0, 0)))
X.xic = XCreateIC(X.xim, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNClientWindow, X.window, XNFocusWindow, X.window, NULL);
+
/* initialize pixmap and drawing context */
X.pixmap = XCreatePixmap(X.display, X.window, width, height, X.depth);
X.xft = XftDrawCreate(X.display, X.pixmap, X.visual, X.colormap);
+
/* initialize the graphics context */
XGCValues gcv;
gcv.foreground = WhitePixel(X.display, X.screen);
XPeekEvent(X.display,&e);
while (XPending(X.display)) {
XNextEvent(X.display, &e);
- if (!XFilterEvent(&e, None))
+ if (!XFilterEvent(&e, None)) {
switch (e.type) {
case FocusIn: if (X.xic) XSetICFocus(X.xic); break;
case FocusOut: if (X.xic) XUnsetICFocus(X.xic); break;
case ButtonRelease: handle_mouse(&e); break;
case ButtonPress: handle_mouse(&e); break;
case MotionNotify: handle_mouse(&e); break;
+ case ClientMessage: {
+ Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
+ if (e.xclient.data.l[0] == wmDeleteMessage)
+ Config->shutdown();
+ }
+ break;
case ConfigureNotify: // Resize the window
if (e.xconfigure.width != X.width || e.xconfigure.height != X.height) {
X.width = e.xconfigure.width;
}
break;
}
+ }
}
if (Running) {
/* redraw the window */
.redraw = redraw,
.handle_key = key_handler,
.handle_mouse = mouse_handler,
+ .shutdown = quit,
.palette = COLOR_PALETTE
};
static uint64_t before = 0;
uint64_t now = getmillis();
if (!getbuf(EDIT)->modified || (now-before) <= 250) {
- exit(0);
+ x11_deinit();
} else {
view_append(getview(TAGS),
"File is modified. Repeat action twice in < 250ms to quit.");