From 7451d8fce4c50729ab3192c93422fa79c9e4fe85 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 19 Jun 2021 15:23:47 +0700 Subject: Translate from C to Zig --- src/main.zig | 13 +++++++++++++ src/x11.zig | 14 ++++++++++++++ src/xfixes.zig | 18 ++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/main.zig create mode 100644 src/x11.zig create mode 100644 src/xfixes.zig (limited to 'src') 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); +} -- cgit 1.4.1