Setting up code for multiple targets.

This commit is contained in:
Nicolás Ortega Froysa 2019-04-21 15:16:01 +02:00
parent 2f8199586d
commit a45b0cae85

View File

@ -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;