From a45b0cae857f6cb63662788e1116608b6a301e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sun, 21 Apr 2019 15:16:01 +0200 Subject: [PATCH] Setting up code for multiple targets. --- src/main.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index 040b7d7..2ff23cf 100644 --- a/src/main.c +++ b/src/main.c @@ -51,7 +51,7 @@ void get_selection(Atom property) { incr = XInternAtom(display, "INCR", 0); if(type == incr) { - // TODO: increment size of buffer + // TODO: prepare for multiple messages return; } @@ -93,7 +93,7 @@ void send_reject(XSelectionRequestEvent *sre) { NoEventMask, (XEvent*)&reply_se); } -void send_selection(XSelectionRequestEvent *sre, Atom utf8) +void send_selection(XSelectionRequestEvent *sre, Atom target) { XSelectionEvent reply_se; @@ -106,7 +106,7 @@ void send_selection(XSelectionRequestEvent *sre, Atom utf8) #endif XChangeProperty(display, sre->requestor, sre->property, - utf8, 8, PropModeReplace, (unsigned char*)data, data_size); + target, 8, PropModeReplace, (unsigned char*)data, data_size); reply_se.type = SelectionNotify; reply_se.requestor = sre->requestor; @@ -122,7 +122,9 @@ void send_selection(XSelectionRequestEvent *sre, Atom utf8) int main() { Window root, owner; int screen; - Atom selection, utf8, clip_property; + Atom selection, clip_property; + // target atoms + Atom utf8_target, text_target, string_target; data = NULL; data_size = 0; @@ -143,7 +145,9 @@ int main() { // create atoms for selections selection = XInternAtom(display, "CLIPBOARD", 0); - utf8 = XInternAtom(display, "UTF8_STRING", 0); + utf8_target = XInternAtom(display, "UTF8_STRING", 0); + text_target = XInternAtom(display, "TEXT", 0); + string_target = XInternAtom(display, "STRING", 0); clip_property = XInternAtom(display, "TINYCLIP", 0); // check if there is currently someone using the clipboard @@ -154,7 +158,7 @@ int main() { #ifdef DEBUG printf("Current owner: 0x%1X\n", (unsigned int)owner); #endif - XConvertSelection(display, selection, utf8, + XConvertSelection(display, selection, utf8_target, clip_property, clip_win, CurrentTime); } else @@ -178,7 +182,7 @@ int main() { { case SelectionClear: // if someone else took the clipboard, regain ownership - XConvertSelection(display, selection, utf8, + XConvertSelection(display, selection, utf8_target, clip_property, clip_win, CurrentTime); break; case SelectionNotify: @@ -197,10 +201,10 @@ int main() { printf("New selection request:\n" " requestor: 0x%1x\n", (unsigned int)sre->requestor); #endif - if(sre->target != utf8 || sre->property == None) + if(sre->target != utf8_target || sre->property == None) send_reject(sre); else - send_selection(sre, utf8); + send_selection(sre, utf8_target); break; case ClientMessage: break;