/** * gcc -o xclipowner xclipowner.c -L/usr/X11R6/lib -lX11 */ /** * Copyright (c) 2004 Billy Biggs . * * 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. */ #include #include #include #include #include /** * Prints the name of the Window. I think this can be better, using * _NET_WM_NAME and the visible ones as appropriate. Ideally we should * follow some window manager's algorithm. ?? */ static void print_name( char *name, Display *dpy, Window win, Window root ) { XTextProperty nameprop; char *wname; if( XGetWMName( dpy, win, &nameprop ) ) { sprintf( name, "%s", nameprop.value ); XFree( nameprop.value ); } else if( XFetchName( dpy, win, &wname ) ) { sprintf( name, "%s", wname ); XFree( wname ); } else if( win == root ) { sprintf( name, "Root" ); } else { sprintf( name, " " ); } } int main( int argc, char **argv ) { Display *d = XOpenDisplay( 0 ); char name[ 4096 ]; Window w; Atom primary; Atom secondary; Atom clipboard; if( !d ) { fprintf( stderr, "Cannot open DISPLAY %s\n", getenv("DISPLAY") ); return 1; } primary = XInternAtom( d, "PRIMARY", False ); w = XGetSelectionOwner( d, primary ); if( !w ) { fprintf( stderr, "PRIMARY has no owner.\n" ); } else { print_name( name, d, w, DefaultRootWindow( d ) ); fprintf( stderr, "PRIMARY owner is 0x%x (%s)\n", (unsigned int) w, name ); } secondary = XInternAtom( d, "SECONDARY", False ); w = XGetSelectionOwner( d, secondary ); if( !w ) { fprintf( stderr, "SECONDARY has no owner.\n" ); } else { print_name( name, d, w, DefaultRootWindow( d ) ); fprintf( stderr, "SECONDARY owner is 0x%x (%s)\n", (unsigned int) w, name ); } clipboard = XInternAtom( d, "CLIPBOARD", False ); w = XGetSelectionOwner( d, clipboard ); if( !w ) { fprintf( stderr, "CLIPBOARD has no owner.\n" ); } else { print_name( name, d, w, DefaultRootWindow( d ) ); fprintf( stderr, "CLIPBOARD owner is 0x%x (%s)\n", (unsigned int) w, name ); } XCloseDisplay(d); return 0; }