#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include "config.h"
struct XConf X;
static Bool Has_Error = False;
void x11_mkwin(XConf* x, int width, int height, int evmask) {
/* create the main window */
x->width = width, x->height = height;
- x->self = XCreateSimpleWindow(
- x->display, x->root, 0, 0, x->width, x->height, 0, x->depth, -1);
+ XSetWindowAttributes attr;
+ attr.background_pixel = Palette[EditBg];
+ attr.bit_gravity = NorthWestGravity;
+ attr.backing_store = WhenMapped;
+ attr.event_mask = evmask
+ | FocusChangeMask
+ | ExposureMask
+ | VisibilityChangeMask
+ | StructureNotifyMask
+ ;
+ x->self = XCreateWindow(
+ x->display, x->root, 0, 0, x->width, x->height, 0, x->depth, InputOutput, x->visual,
+ CWBackPixel | CWBitGravity | CWBackingStore | CWEventMask,
+ &attr);
/* register interest in the delete window message */
Atom wmDeleteMessage = XInternAtom(x->display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(x->display, x->self, &wmDeleteMessage, 1);
- /* setup window attributes and events */
- XSetWindowAttributes swa;
- swa.bit_gravity = NorthWestGravity;
- swa.do_not_propagate_mask = 0; /* do not hide any events from child windows */
- XChangeWindowAttributes(x->display, x->self,
- CWBackPixel|CWBorderPixel|CWBitGravity|CWEventMask|CWColormap,
- &swa);
- XSelectInput(x->display, x->self, evmask);
}
void x11_mkdialog(XConf* x, int width, int height, int evmask) {
}
void x11_process_events(XConf* x, void (*redrawfn)(XConf*)) {
- int nqueued, nevents;
+ int nevents;
/* reap zombie background processes */
for (int status; waitpid(-1, &status, WNOHANG) > 0;);
/* process the entire event queue */
- do {
- nqueued = XEventsQueued(x->display, QueuedAfterFlush);
+
+ while (XEventsQueued(x->display, QueuedAfterFlush))
+ {
XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents);
for (XEvent e; XPending(x->display);) {
XNextEvent(x->display, &e);
if (!XFilterEvent(&e, None) && x->eventfns[e.type])
(x->eventfns[e.type])(x, &e);
}
- if (nqueued) redrawfn(x);
- XFlush(x->display);
- } while ((nqueued = XEventsQueued(x->display, QueuedAfterFlush)) > 0);
+ }
+ (void)redrawfn;
}
void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) {
Divider = draw_hrule(x, &csr);
draw_view(x, &Regions[EDIT], x->font, editrows, &csr, EditBg, EditFg, EditSel, SyncMouse);
draw_scroll(x, &csr, win_view(EDIT), Divider);
- draw_rect(x, WinBdr, 0, x->height-1, x->width, 1);
- draw_rect(x, WinBdr, x->width-1, 0, 1, x->height);
XCopyArea(x->display, x->pixmap, x->self, x->gc, 0, 0, x->width, x->height, 0, 0);
SyncMouse = false;
if (Divider < olddiv && Focused == TAGS) {
exit(EXIT_FAILURE);
}
x11_mkwin(&X, 640, 480, 0
- | FocusChangeMask
| KeyPressMask
| ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| PropertyChangeMask
- | ExposureMask
- | VisibilityChangeMask
- | StructureNotifyMask
);
x11_init_gc(&X);
x11_sel_init(&X);
tide_send("ADD");
job_spawn(ConnectionNumber(X.display), xupdate, 0, 0);
XSync(X.display, False);
+ int maxcount = 1000 / Timeout;
+ int count = 0;
while (X.running) {
- if (!job_poll(Timeout))
+ bool ready = job_poll(Timeout);
+ count += (ready ? -count : 1);
+ if (count < maxcount)
xupdate(NULL);
}
}