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