X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=st.c;h=a6fb7668355c2146d996c3352d2c810d93a0fc75;hb=73e37f562964c2d1cb6029693d1d79a69a22ff14;hp=13104267ee790c252195172b02385cb42df6c189;hpb=1ab42fd49e68a11bfbbe5990ebdab2d3ca502178;p=st.git diff --git a/st.c b/st.c index 1310426..a6fb766 100644 --- a/st.c +++ b/st.c @@ -32,7 +32,7 @@ #define USAGE \ "st-" VERSION ", (c) 2010 st engineers\n" \ - "usage: st [-t title] [-c class] [-e cmd] [-v]\n" + "usage: st [-t title] [-c class] [-v] [-e cmd]\n" /* Arbitrary sizes */ #define ESC_TITLE_SIZ 256 @@ -152,6 +152,7 @@ typedef struct { int ex, ey; struct {int x, y;} b, e; char *clip; + Atom xtarget; } Selection; #include "config.h" @@ -370,6 +371,9 @@ selinit(void) { sel.mode = 0; sel.bx = -1; sel.clip = NULL; + sel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0); + if(sel.xtarget == None) + sel.xtarget = XA_STRING; } static inline int @@ -388,8 +392,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { if(b) *b = e->xbutton.button; - *x = e->xbutton.x/xw.cw; - *y = e->xbutton.y/xw.ch; + *x = (e->xbutton.x - BORDER)/xw.cw; + *y = (e->xbutton.y - BORDER)/xw.ch; sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; sel.b.y = MIN(sel.by, sel.ey); sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; @@ -399,8 +403,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { void bpress(XEvent *e) { sel.mode = 1; - sel.ex = sel.bx = e->xbutton.x/xw.cw; - sel.ey = sel.by = e->xbutton.y/xw.ch; + sel.ex = sel.bx = (e->xbutton.x - BORDER)/xw.cw; + sel.ey = sel.by = (e->xbutton.y - BORDER)/xw.ch; } void @@ -420,8 +424,8 @@ selcopy(void) { memcpy(ptr, term.line[y][x].c, sl); ptr += sl; } - if(ls) - *ptr = '\n', ptr++; + if(ls && y < sel.e.y) + *ptr++ = '\n'; } *ptr = 0; } @@ -453,7 +457,7 @@ selnotify(XEvent *e) { void selpaste() { - XConvertSelection(xw.dpy, XA_PRIMARY, XA_STRING, XA_PRIMARY, xw.win, CurrentTime); + XConvertSelection(xw.dpy, XA_PRIMARY, sel.xtarget, XA_PRIMARY, xw.win, CurrentTime); } void @@ -474,12 +478,12 @@ selrequest(XEvent *e) { xa_targets = XInternAtom(xw.dpy, "TARGETS", 0); if(xsre->target == xa_targets) { /* respond with the supported type */ - Atom string = XA_STRING; + Atom string = sel.xtarget; XChangeProperty(xsre->display, xsre->requestor, xsre->property, XA_ATOM, 32, PropModeReplace, (unsigned char *) &string, 1); xev.property = xsre->property; - } else if(xsre->target == XA_STRING) { + } else if(xsre->target == sel.xtarget) { XChangeProperty(xsre->display, xsre->requestor, xsre->property, xsre->target, 8, PropModeReplace, (unsigned char *) sel.clip, strlen(sel.clip)); @@ -1794,8 +1798,7 @@ kpress(XEvent *ev) { if(meta && len == 1) ttywrite("\033", 1); ttywrite(buf, len); - } else /* 4. nothing to send */ - fprintf(stderr, "errkey: %d\n", (int)ksym); + } break; } }