Sends UTF-8 of clipboard.

This commit is contained in:
Nicolás Ortega Froysa 2019-04-17 15:20:47 +02:00
parent 4405557a32
commit 25a68d31cc

View File

@ -44,7 +44,7 @@ void get_selection(Display *display, Window window, Atom property) {
incr = XInternAtom(display, "INCR", 0); incr = XInternAtom(display, "INCR", 0);
if(type == incr) if(type == incr)
{ {
// increment size of buffer // TODO: increment size of buffer
return; return;
} }
@ -64,24 +64,54 @@ void get_selection(Display *display, Window window, Atom property) {
XDeleteProperty(display, window, property); XDeleteProperty(display, window, property);
} }
/*void send_selection(Display *display, XSelectionRequestEvent *sre, Atom utf8) { void send_reject(Display *display, XSelectionRequestEvent *sre) {
XSelectionEvent se; XSelectionEvent reply_se;
time_t now_tm;
char *now;
now_tm = time(NULL);
now = ctime(&now_tm);
#ifdef DEBUG #ifdef DEBUG
char *an = XGetAtomName(display, sre->property); char *target_name;
printf("Sending CLIPBOARD to window 0x%1x, property '%s'\n", sre->requestor, an); target_name = XGetAtomName(display, sre->target);
if(an) printf("Denying request for type `%s'\n", target_name);
XFree(an); if(target_name)
XFree(target_name);
#endif #endif
XChangeProperty(display, sre->requestor, sre->property, utf8, 8, PropModeReplace, data, data_size); reply_se.type = SelectionNotify;
reply_se.requestor = sre->requestor;
reply_se.selection = sre->selection;
reply_se.target = sre->target;
reply_se.property = None;
reply_se.time = sre->time;
}*/ XSendEvent(display, sre->requestor, 1,
NoEventMask, (XEvent*)&reply_se);
}
void send_selection(Display *display,
XSelectionRequestEvent *sre, Atom utf8)
{
XSelectionEvent reply_se;
#ifdef DEBUG
char *target_name = XGetAtomName(display, sre->property);
printf("Sending CLIPBOARD to window 0x%1x, property '%s'\n",
(unsigned int)sre->requestor, target_name);
if(target_name)
XFree(target_name);
#endif
XChangeProperty(display, sre->requestor, sre->property,
utf8, 8, PropModeReplace, (unsigned char*)data, data_size);
reply_se.type = SelectionNotify;
reply_se.requestor = sre->requestor;
reply_se.selection = sre->selection;
reply_se.target = sre->target;
reply_se.property = sre->property;
reply_se.time = sre->time;
XSendEvent(display, sre->requestor, 1,
NoEventMask, (XEvent*)&reply_se);
}
int main() { int main() {
Display *display; Display *display;
@ -134,7 +164,7 @@ int main() {
while(run) while(run)
{ {
XNextEvent(display, &event); XNextEvent(display, &event);
/*XSelectionRequestEvent *sre;*/ XSelectionRequestEvent *sre;
XSelectionEvent *se; XSelectionEvent *se;
switch(event.type) switch(event.type)
{ {
@ -154,11 +184,15 @@ int main() {
break; break;
case SelectionRequest: case SelectionRequest:
// respond to request for clipboard // respond to request for clipboard
/*sre = (XSelectionRequestEvent*) &event.xselectionrequest;*/ sre = (XSelectionRequestEvent*) &event.xselectionrequest;
#ifdef DEBUG #ifdef DEBUG
/*printf("New selection request:\n" printf("New selection request:\n"
" requestor: 0x%1x\n", (unsigned int)sre->requestor);*/ " requestor: 0x%1x\n", (unsigned int)sre->requestor);
#endif #endif
if(sre->target != utf8 || sre->property == None)
send_reject(display, sre);
else
send_selection(display, sre, utf8);
break; break;
} }
} }