/* Lifted the code from rxvt. */ static char * get_primary_selection(void) { long nread; unsigned long bytes_after; XTextProperty ct; struct sbuf *s = sbuf_new(0); for (nread = 0, bytes_after = 1; bytes_after > 0; nread += ct.nitems) { if ((XGetWindowProperty(dpy, current_screen()->input_window, rp_selection, (nread / 4), 4096, True, AnyPropertyType, &ct.encoding, &ct.format, &ct.nitems, &bytes_after, &ct.value) != Success)) { XFree(ct.value); sbuf_free(s); return NULL; } if (ct.value == NULL) continue; /* Accumulate the data. FIXME: ct.value may not be NULL terminated. */ sbuf_nconcat (s, ct.value, ct.nitems); XFree(ct.value); } return sbuf_free_struct (s); }
/* Return the name of the keysym. caller must free returned pointer */ char * keysym_to_string (KeySym keysym, unsigned int modifier) { struct sbuf *name; char *tmp; name = sbuf_new (0); if (modifier & RP_SHIFT_MASK) sbuf_concat (name, "S-"); if (modifier & RP_CONTROL_MASK) sbuf_concat (name, "C-"); if (modifier & RP_META_MASK) sbuf_concat (name, "M-"); if (modifier & RP_ALT_MASK) sbuf_concat (name, "A-"); if (modifier & RP_HYPER_MASK) sbuf_concat (name, "H-"); if (modifier & RP_SUPER_MASK) sbuf_concat (name, "s-"); /* On solaris machines (perhaps other machines as well) this call can return NULL. In this case use the "NULL" string. */ tmp = XKeysymToString (keysym); if (tmp == NULL) tmp = "NULL"; sbuf_concat (name, tmp); return sbuf_free_struct (name); }
static char * get_cut_buffer (void) { int nbytes; char *data; PRINT_DEBUG (("trying the cut buffer\n")); data = XFetchBytes (dpy, &nbytes); if (data) { struct sbuf *s = sbuf_new (0); sbuf_nconcat (s, data, nbytes); XFree (data); return sbuf_free_struct (s); } else return NULL; }