Skip to content

Instantly share code, notes, and snippets.

@hoelzro
Last active December 28, 2019 16:42
Show Gist options
  • Select an option

  • Save hoelzro/78a2464b80051ca93b437363b69e5f62 to your computer and use it in GitHub Desktop.

Select an option

Save hoelzro/78a2464b80051ca93b437363b69e5f62 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xmu/Atoms.h>
#define die(fmt, args...)\
fprintf(stderr, fmt "\n", ##args);\
exit(1)
int
main(void)
{
Display *dsp;
Window selection;
dsp = XOpenDisplay(NULL);
if(!dsp) {
die("Couldn't connect to X");
}
selection = XGetSelectionOwner(dsp, XA_PRIMARY);
if(selection == None) {
fprintf(stderr, "no selection owner\n");
} else {
printf("0x%x\n", selection);
}
XCloseDisplay(dsp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment