void bpress(XEvent *e) { struct timespec now; MouseShortcut *ms; if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { mousereport(e); return; } for (ms = mshortcuts; ms < mshortcuts + mshortcutslen; ms++) { if (e->xbutton.button == ms->b && match(ms->mask, e->xbutton.state)) { ttysend(ms->s, strlen(ms->s)); return; } } if (e->xbutton.button == Button1) { clock_gettime(CLOCK_MONOTONIC, &now); /* Clear previous selection, logically and visually. */ selclear_(NULL); sel.mode = SEL_EMPTY; sel.type = SEL_REGULAR; sel.oe.x = sel.ob.x = x2col(e->xbutton.x); sel.oe.y = sel.ob.y = y2row(e->xbutton.y); /* * If the user clicks below predefined timeouts specific * snapping behaviour is exposed. */ if (TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) { sel.snap = SNAP_LINE; } else if (TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) { sel.snap = SNAP_WORD; } else { sel.snap = 0; } selnormalize(); if (sel.snap != 0) sel.mode = SEL_READY; tsetdirt(sel.nb.y, sel.ne.y); sel.tclick2 = sel.tclick1; sel.tclick1 = now; } }
void selnotify(XEvent *e) { ulong nitems, ofs, rem; int format; uchar *data, *last, *repl; Atom type, incratom, property; incratom = XInternAtom(xw.dpy, "INCR", 0); ofs = 0; if (e->type == SelectionNotify) { property = e->xselection.property; } else if(e->type == PropertyNotify) { property = e->xproperty.atom; } else { return; } if (property == None) return; do { if (XGetWindowProperty(xw.dpy, xw.win, property, ofs, BUFSIZ/4, False, AnyPropertyType, &type, &format, &nitems, &rem, &data)) { fprintf(stderr, "Clipboard allocation failed\n"); return; } if (e->type == PropertyNotify && nitems == 0 && rem == 0) { /* * If there is some PropertyNotify with no data, then * this is the signal of the selection owner that all * data has been transferred. We won't need to receive * PropertyNotify events anymore. */ MODBIT(xw.attrs.event_mask, 0, PropertyChangeMask); XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); } if (type == incratom) { /* * Activate the PropertyNotify events so we receive * when the selection owner does send us the next * chunk of data. */ MODBIT(xw.attrs.event_mask, 1, PropertyChangeMask); XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); /* * Deleting the property is the transfer start signal. */ XDeleteProperty(xw.dpy, xw.win, (int)property); continue; } /* * As seen in getsel: * Line endings are inconsistent in the terminal and GUI world * copy and pasting. When receiving some selection data, * replace all '\n' with '\r'. * FIXME: Fix the computer world. */ repl = data; last = data + nitems * format / 8; while ((repl = memchr(repl, '\n', last - repl))) { *repl++ = '\r'; } if (IS_SET(MODE_BRCKTPASTE) && ofs == 0) ttywrite("\033[200~", 6); ttysend((char *)data, nitems * format / 8); if (IS_SET(MODE_BRCKTPASTE) && rem == 0) ttywrite("\033[201~", 6); XFree(data); /* number of 32-bit chunks returned */ ofs += nitems * format / 32; } while (rem > 0); /* * Deleting the property again tells the selection owner to send the * next data chunk in the property. */ XDeleteProperty(xw.dpy, xw.win, (int)property); }
int main (int argc, char const * argv []) { static char const * optv [] = { "f:l:s:t:qv", "", "Serial Line Rate Tester", "f f\tsend file (f)", "l f\tserial port is (f) [" SERIAL_PORT "]", "s n\tport speed [ 115200 ]", "t n\ttransmit for (n) seconds [ 15 ]", "q\tquiet mode", "v\tverbose mode", (char const *) (0) }; int fd; signed c; optind = 1; char const *line = SERIAL_PORT; struct _file_ file = { -1, NULL }; speed_t speed = B115200; size_t time = 15; size_t chunk_size = 256; struct termios termios; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'f': file.name = optarg; if (!strcmp (file.name, "-")) file.file = STDIN_FILENO; else { file.file = open (file.name, O_BINARY | O_RDONLY); if (file.file == - 1) { error (1, errno, "could not open %s", file.name); } } break; case 'l': line = optarg; break; case 's': if (baudrate (uintspec (optarg, 0, UINT_MAX), & speed)) { error (1, 0, "could not set baud rate"); } break; case 't': time = uintspec (optarg, 0, SIZE_MAX); break; default: break; } } argc -= optind; argv += optind; fd = open (line, O_RDWR | O_NONBLOCK | O_NOCTTY); if (fd == - 1) { error (1, errno, "could not open %s", line); } if (fcntl(fd, F_SETFL, 0) == -1) { error (1, errno, "failed to set tty flags"); } if (tcgetattr (fd, & termios) == - 1) { error (1, errno, "could not get tty attributes"); } cfmakeraw (& termios); termios.c_cflag = CS8 | CREAD | CLOCAL; if (cfsetspeed (& termios, speed) == - 1) { error (1, errno, "could not set tty speed"); } if (tcsetattr (fd, TCSANOW, & termios) == - 1) { error (1, errno, "could not set tty attributes"); } ttysend (file.file, fd, time, chunk_size); close (fd); return (0); }