linux x11 clipboard improvements
This commit is contained in:
parent
58a334190d
commit
71b18c4064
|
@ -166,6 +166,7 @@ struct Linux_Vars{
|
||||||
String clipboard_outgoing;
|
String clipboard_outgoing;
|
||||||
b32 new_clipboard;
|
b32 new_clipboard;
|
||||||
|
|
||||||
|
Atom atom_TARGETS;
|
||||||
Atom atom_CLIPBOARD;
|
Atom atom_CLIPBOARD;
|
||||||
Atom atom_UTF8_STRING;
|
Atom atom_UTF8_STRING;
|
||||||
Atom atom__NET_WM_STATE;
|
Atom atom__NET_WM_STATE;
|
||||||
|
@ -2272,15 +2273,43 @@ LinuxHandleX11Events(void)
|
||||||
response.time = request.time;
|
response.time = request.time;
|
||||||
response.property = None;
|
response.property = None;
|
||||||
|
|
||||||
//TODO(inso): handle TARGETS negotiation instead of requiring UTF8_STRING
|
|
||||||
if (
|
if (
|
||||||
linuxvars.clipboard_outgoing.size &&
|
linuxvars.clipboard_outgoing.size &&
|
||||||
request.target == linuxvars.atom_UTF8_STRING &&
|
|
||||||
request.selection == linuxvars.atom_CLIPBOARD &&
|
request.selection == linuxvars.atom_CLIPBOARD &&
|
||||||
request.property != None &&
|
request.property != None &&
|
||||||
request.display &&
|
request.display &&
|
||||||
request.requestor
|
request.requestor
|
||||||
){
|
){
|
||||||
|
Atom atoms[] = {
|
||||||
|
XA_STRING,
|
||||||
|
linuxvars.atom_UTF8_STRING
|
||||||
|
};
|
||||||
|
|
||||||
|
if(request.target == linuxvars.atom_TARGETS){
|
||||||
|
|
||||||
|
XChangeProperty(
|
||||||
|
request.display,
|
||||||
|
request.requestor,
|
||||||
|
request.property,
|
||||||
|
XA_ATOM,
|
||||||
|
32,
|
||||||
|
PropModeReplace,
|
||||||
|
(u8*)atoms,
|
||||||
|
ArrayCount(atoms)
|
||||||
|
);
|
||||||
|
|
||||||
|
response.property = request.property;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
b32 found = false;
|
||||||
|
for(int i = 0; i < ArrayCount(atoms); ++i){
|
||||||
|
if(request.target == atoms[i]){
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(found){
|
||||||
XChangeProperty(
|
XChangeProperty(
|
||||||
request.display,
|
request.display,
|
||||||
request.requestor,
|
request.requestor,
|
||||||
|
@ -2288,12 +2317,14 @@ LinuxHandleX11Events(void)
|
||||||
request.target,
|
request.target,
|
||||||
8,
|
8,
|
||||||
PropModeReplace,
|
PropModeReplace,
|
||||||
(unsigned char*)linuxvars.clipboard_outgoing.str,
|
(u8*)linuxvars.clipboard_outgoing.str,
|
||||||
linuxvars.clipboard_outgoing.size
|
linuxvars.clipboard_outgoing.size
|
||||||
);
|
);
|
||||||
|
|
||||||
response.property = request.property;
|
response.property = request.property;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XSendEvent(request.display, request.requestor, True, 0, (XEvent*)&response);
|
XSendEvent(request.display, request.requestor, True, 0, (XEvent*)&response);
|
||||||
|
|
||||||
|
@ -2339,6 +2370,7 @@ LinuxHandleX11Events(void)
|
||||||
should_step = 1;
|
should_step = 1;
|
||||||
linuxvars.new_clipboard = 1;
|
linuxvars.new_clipboard = 1;
|
||||||
XFree(data);
|
XFree(data);
|
||||||
|
XDeleteProperty(linuxvars.XDisplay, linuxvars.XWindow, linuxvars.atom_CLIPBOARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
|
@ -2585,6 +2617,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
#define LOAD_ATOM(x) linuxvars.atom_##x = XInternAtom(linuxvars.XDisplay, #x, False);
|
#define LOAD_ATOM(x) linuxvars.atom_##x = XInternAtom(linuxvars.XDisplay, #x, False);
|
||||||
|
|
||||||
|
LOAD_ATOM(TARGETS);
|
||||||
LOAD_ATOM(CLIPBOARD);
|
LOAD_ATOM(CLIPBOARD);
|
||||||
LOAD_ATOM(UTF8_STRING);
|
LOAD_ATOM(UTF8_STRING);
|
||||||
LOAD_ATOM(_NET_WM_STATE);
|
LOAD_ATOM(_NET_WM_STATE);
|
||||||
|
@ -2619,6 +2652,8 @@ main(int argc, char **argv)
|
||||||
linuxvars.atom_CLIPBOARD,
|
linuxvars.atom_CLIPBOARD,
|
||||||
XFixesSetSelectionOwnerNotifyMask
|
XFixesSetSelectionOwnerNotifyMask
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
fputs("Your X server doesn't support XFIXES, mention this fact if you report any clipboard-related issues.\n", stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Init_Input_Result input_result =
|
Init_Input_Result input_result =
|
||||||
|
|
Loading…
Reference in New Issue