add linux watch
This commit is contained in:
parent
121cfb6864
commit
9249ad092e
|
@ -18,6 +18,7 @@ pub fn build(b: *std.build.Builder) void {
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
exe.addIncludeDir("/usr/include/");
|
exe.addIncludeDir("/usr/include/");
|
||||||
exe.linkSystemLibrary("X11");
|
exe.linkSystemLibrary("X11");
|
||||||
|
exe.linkSystemLibrary("Xfixes");
|
||||||
}
|
}
|
||||||
if (std.builtin.os.tag == .windows) {
|
if (std.builtin.os.tag == .windows) {
|
||||||
// exe.linkLibC();
|
// exe.linkLibC();
|
||||||
|
|
38
src/main.zig
38
src/main.zig
|
@ -2,6 +2,7 @@ const std = @import("std");
|
||||||
const c = @cImport({
|
const c = @cImport({
|
||||||
@cInclude("limits.h");
|
@cInclude("limits.h");
|
||||||
@cInclude("X11/Xlib.h");
|
@cInclude("X11/Xlib.h");
|
||||||
|
@cInclude("X11/extensions/Xfixes.h");
|
||||||
});
|
});
|
||||||
|
|
||||||
fn printSelection(display: *c.Display, window: c.Window, bufname: [*c]const u8, fmtname: [*c]const u8, writer: anytype) !bool {
|
fn printSelection(display: *c.Display, window: c.Window, bufname: [*c]const u8, fmtname: [*c]const u8, writer: anytype) !bool {
|
||||||
|
@ -45,6 +46,31 @@ fn printSelection(display: *c.Display, window: c.Window, bufname: [*c]const u8,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn watch(display: *c.Display, window: c.Window, bufname: [*c]const u8, writer: anytype) !void {
|
||||||
|
var event_base: c_int = undefined;
|
||||||
|
var error_base: c_int = undefined;
|
||||||
|
var event: c.XEvent = undefined;
|
||||||
|
var bufid = c.XInternAtom(display, bufname, c.False);
|
||||||
|
|
||||||
|
_ = c.XFixesQueryExtension(display, &event_base, &error_base);
|
||||||
|
_ = c.XFixesSelectSelectionInput(display, c.XDefaultRootWindow(display), bufid, c.XFixesSetSelectionOwnerNotifyMask);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
_ = c.XNextEvent(display, &event);
|
||||||
|
|
||||||
|
// _ = try writer.print("{d} == {d} + {d}. {d} == {d}", .{ event.type, event_base, c.XFixesSelectionNotify, event.xselection.selection, bufid });
|
||||||
|
// _ = std.debug.print("{}", .{event.xselection});
|
||||||
|
|
||||||
|
if (event.type == event_base + c.XFixesSelectionNotify and
|
||||||
|
event.xselection.property == bufid)
|
||||||
|
{
|
||||||
|
_ = try writer.print("y", .{});
|
||||||
|
if (!try printSelection(display, window, bufname, "UTF8_STRING", writer))
|
||||||
|
_ = try printSelection(display, window, bufname, "STRING", writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() !u8 {
|
pub fn main() !u8 {
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
var display: *c.Display = c.XOpenDisplay(null).?;
|
var display: *c.Display = c.XOpenDisplay(null).?;
|
||||||
|
@ -53,6 +79,18 @@ pub fn main() !u8 {
|
||||||
var color = c.XBlackPixel(display, default_screen);
|
var color = c.XBlackPixel(display, default_screen);
|
||||||
var window = c.XCreateSimpleWindow(display, c.XDefaultRootWindow(display), 0, 0, 1, 1, 0, color, color);
|
var window = c.XCreateSimpleWindow(display, c.XDefaultRootWindow(display), 0, 0, 1, 1, 0, color, color);
|
||||||
defer _ = c.XDestroyWindow(display, window);
|
defer _ = c.XDestroyWindow(display, window);
|
||||||
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
defer _ = gpa.deinit();
|
||||||
|
const allocator = &gpa.allocator;
|
||||||
|
var args = std.process.args();
|
||||||
|
defer args.deinit();
|
||||||
|
while (args.next(allocator)) |arg_or_err| {
|
||||||
|
const arg = try arg_or_err;
|
||||||
|
defer allocator.free(arg);
|
||||||
|
if (std.mem.eql(u8, arg, "-w")) {
|
||||||
|
try watch(display, window, "CLIPBOARD", stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
var result = (try printSelection(display, window, "CLIPBOARD", "UTF8_STRING", stdout)) or
|
var result = (try printSelection(display, window, "CLIPBOARD", "UTF8_STRING", stdout)) or
|
||||||
(try printSelection(display, window, "CLIPBOARD", "STRING", stdout));
|
(try printSelection(display, window, "CLIPBOARD", "STRING", stdout));
|
||||||
if (result)
|
if (result)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user