/* List of font patterns available to the editor */
static char* Fonts[2] = {
- "Verdana:size=11",
+ "Geneva:size=13",
#ifdef __MACH__
"Monaco:size=11"
#else
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>
+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;
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);
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;
}
{
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);
}
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])
FcPatternDestroy(match);
}
}
+// printf("font: '%s'\n", name);
return font;
}
xselclear(x, e);
if (!Selections[PRIMARY].text && !Selections[CLIPBOARD].text)
{
- x->running = False;
+ x->state = QUITTING;
}
}
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 */
+}
+
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)
}
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)
{
/* 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);
}
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);
+ }
}
}
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;
}
--- /dev/null
+ABCDEFGHIJKLMNOPQRSTUVWXYZ
+abcdefghijklmnopqrstuvwxyz
+0123456789
+`-=[]\;',./
+~!@#$%^&*()_+{}|:"<>?