return (ret > 0);
}
+void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) {
+ Job *job = calloc(1, sizeof(job));
+ job->fd = fd;
+ job->readfn = readfn;
+ job->writefn = writefn;
+ job->data = data;
+ job->next = JobList;
+ JobList = job;
+}
+
void job_create(char** cmd, jobfn_t readfn, jobfn_t writefn, void* data) {
int fd = -1, pid = -1;
- if (job_execute(cmd, &fd, &pid) > 0) {
- Job *job = calloc(1, sizeof(job));
- job->fd = fd;
- job->pid = pid;
- job->readfn = readfn;
- job->writefn = writefn;
- job->data = data;
- job->next = JobList;
- JobList = job;
- }
+ if (job_execute(cmd, &fd, &pid) > 0)
+ job_spawn(fd, readfn, writefn, data);
}
void job_start(char** cmd, char* data, size_t ndata, View* dest) {
buf_save(&(view->buffer));
}
+static void xupdate(Job* job) {
+ bool pending = job_poll(ConnectionNumber(X.display), Timeout);
+ int nevents = XEventsQueued(X.display, QueuedAfterFlush);
+ if (pending || nevents) {
+ for (XEvent e; XPending(X.display);) {
+ XNextEvent(X.display, &e);
+ if (!XFilterEvent(&e, None) && EventHandlers[e.type])
+ (EventHandlers[e.type])(&e);
+ }
+ onredraw(X.width, X.height);
+ XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
+ }
+ XFlush(X.display);
+}
+
void win_loop(void) {
+#if 0
+ XMapWindow(X.display, X.self);
+ job_spawn(ConnectionNumber(X.display), xupdate, 0, 0);
+ while (1) job_poll(-1, Timeout);
+#else
XMapWindow(X.display, X.self);
while (Running) {
bool pending = job_poll(ConnectionNumber(X.display), Timeout);
job_start((char*[]){ "xcpd", NULL }, text, len, NULL);
while (job_poll(-1, 100));
}
+#endif
}
+
+
void win_settext(WinRegion id, char* text) {
View* view = win_view(id);
view->buffer.gapstart = view->buffer.bufstart;
Row* row = view_getrow(view, y);
draw_glyphs(Regions[i].x, Regions[i].y + ((y+1) * fheight), row->cols, row->rlen, row->len);
}
+
+ /* place the cursor on screen */
+ if (Regions[i].csrx != SIZE_MAX && Regions[i].csry != SIZE_MAX) {
+ x11_draw_rect(
+ Regions[i].clrcsr.fg,
+ Regions[i].x + (Regions[i].csrx * fwidth),
+ Regions[i].y + (Regions[i].csry * fheight),
+ 1, fheight);
+ }
+
}
/* draw the scroll region */
x11_draw_rect(clr_scroll.bg, 0, Regions[SCROLL].y - 2, Regions[SCROLL].width, thumbreg);
x11_draw_rect(clr_scroll.fg, 0, thumboff, Regions[SCROLL].width, thumbsz);
- /* place the cursor on screen */
- if (Regions[Focused].csrx != SIZE_MAX && Regions[Focused].csry != SIZE_MAX) {
- x11_draw_rect(
- Regions[Focused].clrcsr.fg,
- Regions[Focused].x + (Regions[Focused].csrx * fwidth),
- Regions[Focused].y + (Regions[Focused].csry * fheight),
- 1, fheight);
- }
}
static void oninput(int mods, Rune key) {