static void xupdate(Job* job) {
(void)job;
- int nevents;
+ int nevents, nqueued;
/* process events from the queue */
- XEventsQueued(X.display, QueuedAfterFlush);
+ nqueued = XEventsQueued(X.display, QueuedAfterFlush);
XGetMotionEvents(X.display, X.self, CurrentTime, CurrentTime, &nevents);
for (XEvent e; XPending(X.display);) {
XNextEvent(X.display, &e);
(X.eventfns[e.type])(&X, &e);
for (int status; waitpid(-1, &status, WNOHANG) > 0;);
}
- /* force update the title */
- win_title(NULL);
- /* determine the size of the regions */
- size_t maxtagrows = ((X.height/4) / X.tagfont->height);
- size_t tagrows = view_limitrows(win_view(TAGS), maxtagrows);
- size_t tagregsz = (tagrows * X.tagfont->height) + 7;
- size_t editrows = (X.height - tagregsz) / X.font->height ;
- /* draw the regions to the window */
- drawcsr csr = { .w = X.width, .h = X.height };
- csr.x += ScrollWidth + 1;
- draw_statbox();
- draw_view(&Regions[TAGS], X.tagfont, tagrows, &csr, TagsBg, TagsFg, TagsSel);
- draw_hrule(&csr);
- draw_view(&Regions[EDIT], X.font, editrows, &csr, EditBg, EditFg, EditSel);
- draw_scroll(&csr);
- XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
+ if (nqueued || !job) {
+ /* force update the title */
+ win_title(NULL);
+ /* determine the size of the regions */
+ size_t maxtagrows = ((X.height/4) / X.tagfont->height);
+ size_t tagrows = view_limitrows(win_view(TAGS), maxtagrows);
+ size_t tagregsz = (tagrows * X.tagfont->height) + 7;
+ size_t editrows = (X.height - tagregsz) / X.font->height ;
+ /* draw the regions to the window */
+ drawcsr csr = { .w = X.width, .h = X.height };
+ csr.x += ScrollWidth + 1;
+ draw_statbox();
+ draw_view(&Regions[TAGS], X.tagfont, tagrows, &csr, TagsBg, TagsFg, TagsSel);
+ draw_hrule(&csr);
+ draw_view(&Regions[EDIT], X.font, editrows, &csr, EditBg, EditFg, EditSel);
+ draw_scroll(&csr);
+ XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
+ }
XFlush(X.display);
}
}
void win_title(char* path) {
+ static char prevtitle[4096] = {0};
char title[4096] = {0};
if (!path) path = win_view(EDIT)->buffer.path;
if (!path) path = "*scratch*";
(DosLineFeed ? 'C' : 'N'),
(ExpandTabs ? 'S' : 'T'),
path);
- XStoreName(X.display, X.self, title);
+ if (strcmp(prevtitle, title))
+ XStoreName(X.display, X.self, title);
+ memcpy(prevtitle, title, sizeof(title));
}
void win_font(char* font) {
- if (font) {
- font_load(font);
- } else {
- font_load(Fonts[++FontSel % nelem(Fonts)]);
- }
+ font_load(font ? font : Fonts[++FontSel % nelem(Fonts)]);
}
void win_prop_set(char* xname, char* ename, char* value) {
}
void win_update(int ms) {
- job_poll(ms);
+ if (job_poll(ms))
+ xupdate(NULL);
}
void win_loop(void) {