X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=1474c531dcb4ab9086b7bf718019b0d2527b15af;hb=1132d9e2d65f469dedd9c5b6f356495c7a87b743;hp=4a898767fecc3d1f2dde3480402e98b505111289;hpb=ee858b4805aec3e12bff48cf27433ebcd3f6ac34;p=st.git diff --git a/st.c b/st.c index 4a89876..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,7 +210,12 @@ static int cmdfd; static pid_t pid; static Selection sel; -/* TODO: use X11 clipboard */ +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)) { @@ -262,17 +267,18 @@ static char *getseltext() { return str; } -static void clipboard_copy(char *str) { +/* TODO: use X11 clipboard */ +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)); } -// TODO: doubleclick to select word +/* TODO: doubleclick to select word */ static void brelease(XEvent *e) { int b; sel.mode = 0; @@ -286,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); } @@ -1214,9 +1220,14 @@ xinit(void) { xw.bufw = xw.w - 2*BORDER; xw.bufh = xw.h - 2*BORDER; xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr)); - xw.hasfocus = 1; /* gc */ dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL); + + /* event mask */ + XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask + | StructureNotifyMask | FocusChangeMask | PointerMotionMask + | ButtonPressMask | ButtonReleaseMask); + XMapWindow(xw.dis, xw.win); xhints(); XStoreName(xw.dis, xw.win, "st"); @@ -1435,12 +1446,6 @@ run(void) { XEvent ev; fd_set rfd; int xfd = XConnectionNumber(xw.dis); - long mask = ExposureMask | KeyPressMask | StructureNotifyMask - | FocusChangeMask | PointerMotionMask | ButtonPressMask - | ButtonReleaseMask; - - XSelectInput(xw.dis, xw.win, mask); - XResizeWindow(xw.dis, xw.win, xw.w, xw.h); /* XXX: fix resize bug in wmii (?) */ for(;;) { FD_ZERO(&rfd); @@ -1473,6 +1478,7 @@ main(int argc, char *argv[]) { tnew(80, 24); ttynew(); xinit(); + selinit(); run(); return 0; }