Full Code of cdown/clipnotify for AI

master 25ba143c7da8 cached
4 files
4.6 KB
1.2k tokens
2 symbols
1 requests
Download .txt
Repository: cdown/clipnotify
Branch: master
Commit: 25ba143c7da8
Files: 4
Total size: 4.6 KB

Directory structure:
gitextract_ocwvpy70/

├── LICENSE
├── Makefile
├── README.md
└── clipnotify.c

================================================
FILE CONTENTS
================================================

================================================
FILE: LICENSE
================================================
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.


================================================
FILE: Makefile
================================================
PREFIX ?= /usr/local

x11_bsd_flags = -I/usr/X11R6/include -L/usr/X11R6/lib

all:
	${CC} ${CFLAGS} ${LDFLAGS} clipnotify.c -o clipnotify $(x11_bsd_flags) -lX11 -lXfixes

install: all
	mkdir -p ${DESTDIR}${PREFIX}/bin
	cp -f clipnotify ${DESTDIR}${PREFIX}/bin
	chmod 755 ${DESTDIR}${PREFIX}/bin/clipnotify

uninstall:
	rm -f ${DESTDIR}${PREFIX}/bin/clipnotify

clean:
	rm -f *.o *~ clipnotify


================================================
FILE: README.md
================================================
clipnotify is a simple program that, using the
[XFIXES](https://cgit.freedesktop.org/xorg/proto/fixesproto/plain/fixesproto.txt)
extension to X11, waits until a new selection is available and then exits.

It was primarily designed for [clipmenu](https://github.com/cdown/clipmenu), to
avoid polling for new selections.

Here's how it's intended to be used:

    while read; do
        [an event happened, do something with the selection]
    done < <(clipnotify -l)

Or:

    while clipnotify; do
        [an event happened, do something with the selection]
    done

clipnotify doesn't try to print anything about the contents of the selection,
it just exits when it changes. This is intentional -- X11's selection API is
verging on the insane, and there are plenty of others who have already lost
their sanity to bring us xclip/xsel/etc. Use one of those tools to complement
clipnotify.

You can choose a particular selection with `-s`, and loop instead of exiting
with `-l`. See `clipmenu -h` for more information.


================================================
FILE: clipnotify.c
================================================
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

static enum selections {
    NONE = 0,
    SELECTION_CLIPBOARD = (1 << 0),
    SELECTION_PRIMARY = (1 << 1),
    SELECTION_SECONDARY = (1 << 2)
} selections = NONE;

static int loop;

int main(int argc, char *argv[]) {
    static const char *usage =
        "%s: Notify by exiting on clipboard events.\n\n"
        "  -l    Instead of exiting, print a newline when a new selection is available.\n"
        "  -s    The selection to use. Available selections:\n"
        "        clipboard, primary, secondary\n"
        "        The default is to monitor clipboard and primary.\n";
    Display *disp;
    Window root;
    Atom clip;
    XEvent evt;
    int opt;

    while ((opt = getopt(argc, argv, "hs:l")) != -1) {
        switch (opt) {
            case 'h':
                printf(usage, argv[0]);
                return EXIT_SUCCESS;
            case 'l':
                loop = 1;
                break;
            case 's': {
                char *token = strtok(optarg, ",");
                while (token != NULL) {
                    if (strcmp(token, "clipboard") == 0) {
                        selections |= SELECTION_CLIPBOARD;
                    } else if (strcmp(token, "primary") == 0) {
                        selections |= SELECTION_PRIMARY;
                    } else if (strcmp(token, "secondary") == 0) {
                        selections |= SELECTION_SECONDARY;
                    } else {
                        fprintf(stderr, "Unknown selection '%s'\n", token);
                        return EXIT_FAILURE;
                    }
                    token = strtok(NULL, ",");
                }
                break;
            }
            default:
                fprintf(stderr, usage, argv[0]);
                return EXIT_FAILURE;
        }
    }

    disp = XOpenDisplay(NULL);
    if (!disp) {
        fprintf(stderr, "Can't open X display\n");
        return EXIT_FAILURE;
    }

    root = DefaultRootWindow(disp);

    clip = XInternAtom(disp, "CLIPBOARD", False);

    /* <= 1.0.2 backwards compatibility */
    if (!selections)
        selections = SELECTION_CLIPBOARD | SELECTION_PRIMARY;

    if (selections & SELECTION_CLIPBOARD)
        XFixesSelectSelectionInput(disp, root, clip,
                                   XFixesSetSelectionOwnerNotifyMask);
    if (selections & SELECTION_PRIMARY)
        XFixesSelectSelectionInput(disp, root, XA_PRIMARY,
                                   XFixesSetSelectionOwnerNotifyMask);
    if (selections & SELECTION_SECONDARY)
        XFixesSelectSelectionInput(disp, root, XA_SECONDARY,
                                   XFixesSetSelectionOwnerNotifyMask);

    if (loop) {
        (void)setvbuf(stdout, NULL, _IONBF, 0);
        do {
            XNextEvent(disp, &evt);
            printf("\n");
        } while (1);
    } else {
        XNextEvent(disp, &evt);
    }
    XCloseDisplay(disp);
}
Download .txt
gitextract_ocwvpy70/

├── LICENSE
├── Makefile
├── README.md
└── clipnotify.c
Download .txt
SYMBOL INDEX (2 symbols across 1 files)

FILE: clipnotify.c
  type selections (line 9) | enum selections {
  function main (line 18) | int main(int argc, char *argv[]) {
Condensed preview — 4 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (5K chars).
[
  {
    "path": "LICENSE",
    "chars": 280,
    "preview": "This is free and unencumbered software released into the public domain.\n\nAnyone is free to copy, modify, publish, use, c"
  },
  {
    "path": "Makefile",
    "chars": 392,
    "preview": "PREFIX ?= /usr/local\n\nx11_bsd_flags = -I/usr/X11R6/include -L/usr/X11R6/lib\n\nall:\n\t${CC} ${CFLAGS} ${LDFLAGS} clipnotify"
  },
  {
    "path": "README.md",
    "chars": 1018,
    "preview": "clipnotify is a simple program that, using the\n[XFIXES](https://cgit.freedesktop.org/xorg/proto/fixesproto/plain/fixespr"
  },
  {
    "path": "clipnotify.c",
    "chars": 3047,
    "preview": "#include <X11/Xatom.h>\n#include <X11/Xlib.h>\n#include <X11/extensions/Xfixes.h>\n#include <stdio.h>\n#include <stdlib.h>\n#"
  }
]

About this extraction

This page contains the full source code of the cdown/clipnotify GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 4 files (4.6 KB), approximately 1.2k tokens, and a symbol index with 2 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!