about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-06-19 15:23:47 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-06-19 15:40:32 +0700
commit7451d8fce4c50729ab3192c93422fa79c9e4fe85 (patch)
tree5a3e89989103b43aac1e3c934f4897b11f91ae2e /src
parenta9faca40b3929f22ad1e21c071c853af47b0b7bc (diff)
downloadclipbuzz-7451d8fce4c50729ab3192c93422fa79c9e4fe85.tar.gz
Translate from C to Zig 2.0.0
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);
+}