X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=1474c531dcb4ab9086b7bf718019b0d2527b15af;hb=1132d9e2d65f469dedd9c5b6f356495c7a87b743;hp=1497dd27f1270b92cb1bc8432e0339a75eef65f9;hpb=f211bc2eedaa8ea86dc66ad04ccd08938c73a93c;p=st.git diff --git a/st.c b/st.c index 1497dd2..1474c53 100644 --- a/st.c +++ b/st.c @@ -185,9 +185,9 @@ static char* kmap(KeySym); static void kpress(XEvent *); static void resize(XEvent *); static void focus(XEvent *); -static void brelease(XEvent *e); -static void bpress(XEvent *e); -static void bmotion(XEvent *e); +static void brelease(XEvent *); +static void bpress(XEvent *); +static void bmotion(XEvent *); static void (*handler[LASTEvent])(XEvent *) = { @@ -210,6 +210,13 @@ static int cmdfd; static pid_t pid; static Selection sel; +void +selinit(void) { + sel.mode = 0; + sel.bx = -1; + sel.clip = NULL; +} + static inline int selected(int x, int y) { if ((sel.ey==y && sel.by==y)) { int bx = MIN(sel.bx, sel.ex); @@ -261,12 +268,12 @@ static char *getseltext() { } /* TODO: use X11 clipboard */ -static void clipboard_copy(char *str) { +static void selcopy(char *str) { free(sel.clip); sel.clip = str; } -static void clipboard_paste() { +static void selpaste() { if(sel.clip) ttywrite(sel.clip, strlen(sel.clip)); } @@ -285,10 +292,10 @@ static void brelease(XEvent *e) { if(sel.bx==sel.ex && sel.by==sel.ey) { sel.bx = -1; if(b==2) - clipboard_paste(); + selpaste(); } else { if(b==1) - clipboard_copy(getseltext()); + selcopy(getseltext()); } draw(1); } @@ -1471,6 +1478,7 @@ main(int argc, char *argv[]) { tnew(80, 24); ttynew(); xinit(); + selinit(); run(); return 0; }