selk | Keyboard-only rectangle selector for X |
| download: https://git.y1.nz/archives/selk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
draw.h
1 /* Originally retrieved from https://codeberg.org/NRK/selx */
2 /* Adapted by Emma Weaver on 26-04-20. */
3
4 //////////////// macros
5
6 #define DIFF(A, B) ((A) > (B) ? (A) - (B) : (B) - (A))
7 #define SIZE_T ptrdiff_t
8 #define SIZEOF(...) ((SIZE_T)sizeof(__VA_ARGS__))
9 #define ARRLEN(...) (SIZEOF(__VA_ARGS__) / SIZEOF(0[__VA_ARGS__]))
10 #define ARREND(V) ((V) + ARRLEN(V))
11 #define CLAMP(lo, md, hi) ((md) < (lo) ? (lo) : ((md) > (hi) ? (hi) : (md)))
12
13 #define TRUE 1
14 #define FALSE 0
15 #define WINDOW_COUNT 4
16
17 #define LOG(...) printf(__VA_ARGS__)
18
19 #define fatal(message) { fprintf(stderr, message); exit(1); }
20
21 //////////////// types
22
23 typedef enum { MODE_P1, MODE_P2, MODE_BOTH } Mode;
24 enum { STATUS_CONTINUE, STATUS_DONE };
25 enum {
26 KEY_UP_MASK = 1 << 0,
27 KEY_DOWN_MASK = 1 << 1,
28 KEY_RIGHT_MASK = 1 << 2,
29 KEY_LEFT_MASK = 1 << 3,
30
31 KEY_UP2_MASK = 1 << 4,
32 KEY_DOWN2_MASK = 1 << 5,
33 KEY_LEFT2_MASK = 1 << 6,
34 KEY_RIGHT2_MASK = 1 << 7,
35
36 KEY_FAST_MASK = 1 << 8,
37 KEY_SLOW_MASK = 1 << 9
38 };
39
40 typedef struct { int x, y; } Point;
41 typedef struct { int x, y, w, h; } Rect;
42
43 typedef struct {
44 Display * display;
45 struct {
46 Window window;
47 int x, y, w, h;
48 } root;
49 Window window[WINDOW_COUNT];
50 } X11;
51
52 typedef struct {
53 int keys_down_mask;
54 int frames_moving;
55
56 Point start, end;
57 Mode mode;
58
59 union {
60 Window window;
61 int monitor;
62 } target;
63
64 const char * color_name;
65 const int border_width;
66 } DrawContext;
67
68 ///////////////////////////////// functions
69
70 void set_up(DrawContext * ctx, X11 * x11);
71 void clean_up(DrawContext * ctx, X11 * x11);
72 void select_monitor(DrawContext * ctx, X11 * x11);
73 void select_window(DrawContext * ctx, X11 * x11, XEvent event);
74 int is_fast(DrawContext * ctx);
75
76 Rect get_rectangle(DrawContext * ctx, X11 * x11);
77 void draw(DrawContext * ctx, X11 * x11);
78 void run_draw_loop(DrawContext * ctx, X11 * x11);
79
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.