From: Michael D. Lowis Date: Sun, 5 Apr 2020 01:53:28 +0000 (-0400) Subject: changed proportional font in use and updated to withdraw window on quit, create new... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=cb223f9bc7525233e9b6206898769fa37be57ca5;p=projs%2Ftide.git changed proportional font in use and updated to withdraw window on quit, create new window to serve the selection --- diff --git a/config.h b/config.h index 4be04bd..fa013f2 100644 --- a/config.h +++ b/config.h @@ -36,7 +36,7 @@ static char* TagString = "Del Put Get | Font Tabs Eol | x+ w+ !st !term | Find " /* List of font patterns available to the editor */ static char* Fonts[2] = { - "Verdana:size=11", + "Geneva:size=13", #ifdef __MACH__ "Monaco:size=11" #else diff --git a/inc/x11.h b/inc/x11.h index c5a9a0f..4878f97 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -8,9 +8,15 @@ AUTOLIB(fontconfig) #include #include +enum { + RUNNING, + SERVE_SEL, + QUITTING +}; + typedef struct XConf { - Bool running, error; - int fd, screen, width, height, mods; + Bool error; + int state, fd, screen, width, height, mods; Window root; Display* display; Visual* visual; @@ -157,3 +163,4 @@ int x11_sel_get(XConf* x, int selid, void(*cbfn)(char*)); int x11_sel_set(XConf* x, int selid, char* str); void x11_sel_quit(XConf* x, XEvent* e); int x11_sel_ready(XConf* x); +void x11_sel_serve(XConf* x); diff --git a/src/lib/x11.c b/src/lib/x11.c index 4cbc1bf..5220cf2 100644 --- a/src/lib/x11.c +++ b/src/lib/x11.c @@ -35,7 +35,7 @@ int x11_init(XConf* x) x->colormap = wa.colormap; x->screen = DefaultScreen(x->display); x->depth = DefaultDepth(x->display, x->screen); - x->running = True; + x->state = RUNNING; XSetErrorHandler(onerror); ret = 0; } @@ -105,12 +105,13 @@ void x11_process_events(XConf* x) { telem_send("EV_READ_QUEUE(pending: %d)\n", XPending(x->display)); XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents); + for (XEvent e; XPending(x->display);) { XNextEvent(x->display, &e); update_state(x, &e); if (!XFilterEvent(&e, None) && x->eventfns[e.type]) - {; + { telem_send("EV_HANDLE(type: %d)\n", e.type); (x->eventfns[e.type])(x, &e); } @@ -135,7 +136,7 @@ void x11_process_events(XConf* x) void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) { if (redraw) redraw(x); - for (XEvent e; x->running;) + for (XEvent e; x->state != QUITTING;) { XNextEvent(x->display, &e); if (x->eventfns[e.type]) diff --git a/src/lib/x11_gc.c b/src/lib/x11_gc.c index ef492cb..ae7640d 100644 --- a/src/lib/x11_gc.c +++ b/src/lib/x11_gc.c @@ -120,6 +120,7 @@ XftFont* x11_font_load(XConf* x, char* name) FcPatternDestroy(match); } } +// printf("font: '%s'\n", name); return font; } diff --git a/src/lib/x11_sel.c b/src/lib/x11_sel.c index 1c0170b..0b81c9d 100644 --- a/src/lib/x11_sel.c +++ b/src/lib/x11_sel.c @@ -155,7 +155,7 @@ void x11_sel_quit(XConf* x, XEvent* e) xselclear(x, e); if (!Selections[PRIMARY].text && !Selections[CLIPBOARD].text) { - x->running = False; + x->state = QUITTING; } } @@ -165,3 +165,19 @@ int x11_sel_ready(XConf* x) return (Selections[PRIMARY].text || Selections[CLIPBOARD].text); } +void x11_sel_serve(XConf* x) +{ + X.eventfns[SelectionClear] = x11_sel_quit; + X.self = XCreateSimpleWindow(X.display, X.root, 0, 0, 1, 1, 0, 0, 0); + if (Selections[PRIMARY].text) + { + XSetSelectionOwner(x->display, Selections[PRIMARY].atom, x->self, CurrentTime); + + } + if (Selections[CLIPBOARD].text) + { + XSetSelectionOwner(x->display, Selections[CLIPBOARD].atom, x->self, CurrentTime); + } + if (fork()) exit(0); /* fork into background */ +} + diff --git a/src/pick.c b/src/pick.c index 1f8b171..8f0655b 100644 --- a/src/pick.c +++ b/src/pick.c @@ -190,11 +190,11 @@ static void xkeypress(XConf* x, XEvent* e) XLookupString(&(e->xkey), buf, sizeof(buf), &key, 0); if (key == XK_Return) { - x->running = false; + x->state = QUITTING; } else if (key == XK_Escape) { - x->running = false; + x->state = QUITTING; ChoiceIdx = SIZE_MAX; } else if (key == XK_Up) @@ -241,11 +241,11 @@ static void xbtnpress(XConf* x, XEvent* e) } else if (e->xbutton.button == Button2) { - x->running = false; + x->state = QUITTING; } else if (e->xbutton.button == Button3) { - x->running = false; + x->state = QUITTING; ChoiceIdx = SIZE_MAX; } else if (e->xbutton.button == Button4) diff --git a/src/tide.c b/src/tide.c index 8fe3fc9..b31ff65 100644 --- a/src/tide.c +++ b/src/tide.c @@ -294,7 +294,7 @@ static void xupdate(Job* job) { /* redraw if we have changes or if we have input from a job */ x11_process_events(&X); - if (!job) + if (!job && X.state == RUNNING) { xredraw(&X); } @@ -369,12 +369,14 @@ void win_loop(void) XSync(X.display, False); int maxcount = 1000 / Timeout; int count = 0; - while (X.running) + while (X.state != QUITTING) { bool ready = job_poll(Timeout); count += (ready ? -count : 1); if (count < maxcount) + { xupdate(NULL); + } } } @@ -384,17 +386,13 @@ void win_quit(void) if ((win_buf(EDIT)->status != MODIFIED) || (X.now - before) <= (uint64_t)ClickTime) { tide_send("DEL"); - X.eventfns[SelectionClear] = x11_sel_quit; - XUnmapWindow(X.display, X.self); - if (!x11_sel_ready(&X)) - { - X.running = False; - } - else + XWithdrawWindow(X.display, X.self, X.screen); + X.state = QUITTING; + if (x11_sel_ready(&X)) { - if (fork()) exit(0); /* fork into background if we still have selection */ + X.state = SERVE_SEL; + x11_sel_serve(&X); } - } before = X.now; } diff --git a/testdocs/ascii.txt b/testdocs/ascii.txt new file mode 100644 index 0000000..e79402b --- /dev/null +++ b/testdocs/ascii.txt @@ -0,0 +1,5 @@ +ABCDEFGHIJKLMNOPQRSTUVWXYZ +abcdefghijklmnopqrstuvwxyz +0123456789 +`-=[]\;',./ +~!@#$%^&*()_+{}|:"<>?