This commit is contained in:
parent
bf3b856ac2
commit
259b077345
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Emil Lerch
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
49
xclipget.c
Normal file
49
xclipget.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
// gcc -o xclipget xclipget.c -lX11
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
Bool PrintSelection(Display *display, Window window, const char *bufname, const char *fmtname)
|
||||||
|
{
|
||||||
|
char *result;
|
||||||
|
unsigned long ressize, restail;
|
||||||
|
int resbits;
|
||||||
|
Atom bufid = XInternAtom(display, bufname, False),
|
||||||
|
fmtid = XInternAtom(display, fmtname, False),
|
||||||
|
propid = XInternAtom(display, "XSEL_DATA", False),
|
||||||
|
incrid = XInternAtom(display, "INCR", False);
|
||||||
|
XEvent event;
|
||||||
|
|
||||||
|
XConvertSelection(display, bufid, fmtid, propid, window, CurrentTime);
|
||||||
|
do {
|
||||||
|
XNextEvent(display, &event);
|
||||||
|
} while (event.type != SelectionNotify || event.xselection.selection != bufid);
|
||||||
|
|
||||||
|
if (event.xselection.property)
|
||||||
|
{
|
||||||
|
XGetWindowProperty(display, window, propid, 0, LONG_MAX/4, False, AnyPropertyType,
|
||||||
|
&fmtid, &resbits, &ressize, &restail, (unsigned char**)&result);
|
||||||
|
|
||||||
|
if (fmtid == incrid)
|
||||||
|
printf("Buffer is too large and INCR reading is not implemented yet.\n");
|
||||||
|
else
|
||||||
|
printf("%.*s", (int)ressize, result);
|
||||||
|
|
||||||
|
XFree(result);
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
else // request failed, e.g. owner can't convert to the target format
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Display *display = XOpenDisplay(NULL);
|
||||||
|
unsigned long color = BlackPixel(display, DefaultScreen(display));
|
||||||
|
Window window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0,0, 1,1, 0, color, color);
|
||||||
|
Bool result = PrintSelection(display, window, "CLIPBOARD", "UTF8_STRING") ||
|
||||||
|
PrintSelection(display, window, "CLIPBOARD", "STRING");
|
||||||
|
XDestroyWindow(display, window);
|
||||||
|
XCloseDisplay(display);
|
||||||
|
return !result;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user