overdraw

X11 drawable overlay
git clone https://git.sinitax.com/sinitax/overdraw
Log | Files | Refs | LICENSE | sfeed.txt

commit 35ffd0d929b3a94da3a565d3641af3a0cf75c9a8
parent 4145c7ed8951400913687c1c3e5acb594f95f9ba
Author: Louis Burda <quent.burda@gmail.com>
Date:   Tue, 27 Sep 2022 23:40:44 +0200

Small touchups, XClearWindow bug remains

Diffstat:
Moverdraw.c | 30+++++++++---------------------
1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/overdraw.c b/overdraw.c @@ -6,7 +6,7 @@ #include <X11/keysym.h> #include <X11/cursorfont.h> -#include <stdarg.h> +#include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -24,7 +24,6 @@ struct line { struct rgb color; }; -static void die(const char *fmtstr, ...); static void add_line(cairo_path_t *path, struct rgb *color); static void clear_background(void); static void draw_color_mark(void); @@ -48,24 +47,12 @@ static struct line *lines; static int lines_cnt, lines_cap; void -die(const char *fmtstr, ...) -{ - va_list ap; - - va_start(ap, fmtstr); - vfprintf(stderr, fmtstr, ap); - va_end(ap); - - exit(1); -} - -void add_line(cairo_path_t *path, struct rgb *color) { if (lines_cnt == lines_cap) { lines_cap *= 2; lines = realloc(lines, lines_cap * sizeof(struct line)); - if (!lines) exit(1); + if (!lines) err(1, "realloc"); } lines[lines_cnt].path = path; @@ -87,7 +74,7 @@ draw_color_mark(void) c = &colors[color_index]; cairo_save(cr); - cairo_set_source_rgba(cr, c->r, c->g, c->b, 1); + cairo_set_source_rgb(cr, c->r, c->g, c->b); cairo_rectangle(cr, 10, 10, 20, 20); cairo_stroke_preserve(cr); cairo_fill(cr); @@ -102,8 +89,8 @@ draw_lines(void) cairo_save(cr); for (i = 0; i < lines_cnt; i++) { cairo_new_path(cr); - cairo_set_source_rgba(cr, lines[i].color.r, - lines[i].color.g, lines[i].color.b, 1); + cairo_set_source_rgb(cr, lines[i].color.r, + lines[i].color.g, lines[i].color.b); cairo_append_path(cr, lines[i].path); cairo_stroke(cr); } @@ -127,12 +114,12 @@ init(void) win = XCreateWindow(display, root, scr.x, scr.y, scr.width, scr.height, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect, &swa); - if (!win) die("Failed to create window\n"); + if (!win) err(1, "XCreateWindow"); XMapWindow(display, win); image = XGetImage(display, win, scr.x, scr.y, scr.width, scr.height, AllPlanes, ZPixmap); - if (!image) die("Failed to capture screen\n"); + if (!image) err(1, "XGetImage"); gcvals = (XGCValues) { 0 }; gcvals.subwindow_mode = IncludeInferiors; @@ -209,7 +196,7 @@ main(int argc, char *argv[]) break; case MotionNotify: if (!draw) break; - cairo_set_source_rgba(cr, color.r, color.g, color.b, 1); + cairo_set_source_rgb(cr, color.r, color.g, color.b); cairo_line_to(cr, ev.xmotion.x, ev.xmotion.y); cairo_move_to(cr, ev.xmotion.x, ev.xmotion.y); cairo_stroke_preserve(cr); @@ -230,6 +217,7 @@ main(int argc, char *argv[]) clear_background(); draw_color_mark(); draw_lines(); + XFlush(display); break; }