goto finish;
usec_t end = usec_add(now(CLOCK_MONOTONIC), 100 * USEC_PER_MSEC);
- char buf[256];
+ char buf[STRLEN("\x1B]11;rgb:0/0/0\x07")]; /* shortest possible reply */
size_t buf_full = 0;
BackgroundColorContext context = {};
- for (;;) {
+ for (bool first = true;; first = false) {
if (buf_full == 0) {
usec_t n = now(CLOCK_MONOTONIC);
goto finish;
}
- ssize_t l = read(STDIN_FILENO, buf, sizeof(buf));
+ /* On the first try, read multiple characters, i.e. the shortest valid
+ * reply. Afterwards read byte-wise, since we don't want to read too much, and
+ * unnecessarily drop too many characters from the input queue. */
+ ssize_t l = read(STDIN_FILENO, buf, first ? sizeof(buf) : 1);
if (l < 0) {
r = -errno;
goto finish;