diff options
| author | kj_sh604 | 2026-06-05 16:07:29 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-06-05 16:07:29 -0400 |
| commit | 7a57444251630da7e7a2ecf069bca0a331db8cf6 (patch) | |
| tree | 13248b73da26f445de649b9950c94b7d90d5fdc6 /src | |
| parent | d6fb89a1de50cc8a7364fc798205d44fa988d477 (diff) | |
refactor: src/screenshot.zig
Diffstat (limited to 'src')
| -rw-r--r-- | src/screenshot.zig | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/src/screenshot.zig b/src/screenshot.zig deleted file mode 100644 index 6f74429..0000000 --- a/src/screenshot.zig +++ /dev/null @@ -1,59 +0,0 @@ -const build_options = @import("build_options"); -const c = @import("c.zig").c; - -const std = @import("std"); - -extern fn XDestroyImage(ximage: *c.XImage) c_int; - -const ShmInfo = if (build_options.use_xshm) c.XShmSegmentInfo else struct {}; - -pub const Screenshot = struct { - image: *c.XImage, - shm: ShmInfo = .{}, - - pub fn capture(display: *c.Display, window: c.Window) !Screenshot { - var attrs: c.XWindowAttributes = undefined; - _ = c.XGetWindowAttributes(display, window, &attrs); - - if (build_options.use_xshm) { - const screen = c.XDefaultScreen(display); - - var ss = Screenshot{ .image = undefined, .shm = undefined }; - - ss.image = c.XShmCreateImage( - display, - c.XDefaultVisual(display, @intCast(screen)), - @intCast(c.XDefaultDepthOfScreen(c.XScreenOfDisplay(display, @intCast(screen)))), - c.ZPixmap, - null, - &ss.shm, - @intCast(attrs.width), - @intCast(attrs.height), - ) orelse return error.ScreenshotFailed; - - ss.shm.shmid = c.shmget(c.IPC_PRIVATE, @intCast(ss.image.*.bytes_per_line * ss.image.*.height), c.IPC_CREAT | 0o777); - ss.shm.shmaddr = @ptrCast(c.shmat(ss.shm.shmid, null, 0)); - ss.image.*.data = @ptrCast(ss.shm.shmaddr); - ss.shm.readOnly = c.False; - - _ = c.XShmAttach(display, &ss.shm); - _ = c.XShmGetImage(display, window, ss.image, 0, 0, c.AllPlanes); - - return ss; - } else { - const image = c.XGetImage(display, window, 0, 0, @intCast(attrs.width), @intCast(attrs.height), c.AllPlanes, c.ZPixmap); - if (image == null) return error.ScreenshotFailed; - return .{ .image = image.? }; - } - } - - pub fn deinit(self: *Screenshot) void { - if (build_options.use_xshm) { - _ = XDestroyImage(self.image); - _ = c.shmdt(self.shm.shmaddr); - _ = c.shmctl(self.shm.shmid, c.IPC_RMID, null); - } else { - _ = XDestroyImage(self.image); - } - } -};
\ No newline at end of file |
