about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig13
-rw-r--r--src/x11.zig14
-rw-r--r--src/xfixes.zig18
3 files changed, 45 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..c5a23cc
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,13 @@
+const x11 = @import("x11.zig");
+
+pub fn main() anyerror!void {
+    const display = x11.openDisplay(null) orelse return error.SystemResources;
+    defer _ = x11.closeDisplay(display);
+
+    const root = x11.getDefaultRootWindow(display);
+    x11.getSelection(display, root, "PRIMARY");
+    x11.getSelection(display, root, "CLIPBOARD");
+
+    var event: x11.Event = undefined;
+    _ = x11.nextEvent(display, &event);
+}
diff --git a/src/x11.zig b/src/x11.zig
new file mode 100644
index 0000000..faea858
--- /dev/null
+++ b/src/x11.zig
@@ -0,0 +1,14 @@
+const xlib = @cImport({ @cInclude("X11/Xlib.h"); });
+pub const Atom = xlib.Atom;
+pub const Display = xlib.Display;
+pub const Event = xlib.XEvent;
+pub const False = xlib.False;
+pub const Window = xlib.Window;
+pub const closeDisplay = xlib.XCloseDisplay;
+pub const getAtom = xlib.XInternAtom;
+pub const getDefaultRootWindow = xlib.XDefaultRootWindow;
+pub const nextEvent = xlib.XNextEvent;
+pub const openDisplay = xlib.XOpenDisplay;
+
+const xfixes = @import("xfixes.zig");
+pub const getSelection = xfixes.getSelection;
diff --git a/src/xfixes.zig b/src/xfixes.zig
new file mode 100644
index 0000000..9eb8afc
--- /dev/null
+++ b/src/xfixes.zig
@@ -0,0 +1,18 @@
+const x11 = @import("x11.zig");
+const Atom = x11.Atom;
+const Display = x11.Display;
+const False = x11.False;
+const Window = x11.Window;
+const getAtom = x11.getAtom;
+
+const xfixes = @cImport({ @cInclude("X11/extensions/Xfixes.h"); });
+const SET_SELECTION_OWNER = xfixes.XFixesSetSelectionOwnerNotifyMask;
+
+extern fn XFixesSelectSelectionInput(display: *Display, window: Window,
+                                     selection: Atom, event_mask: c_ulong) void;
+
+pub fn getSelection(display: *Display, window: Window,
+                    selection: [*c]const u8) void {
+    const atom = getAtom(display, selection, False);
+    XFixesSelectSelectionInput(display, window, atom, SET_SELECTION_OWNER);
+}