diff options
| author | auric <104602845+ihateamongus@users.noreply.github.com> | 2025-09-07 19:26:35 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-07 19:26:35 -0500 |
| commit | 54b41bddc00449b446b0f9dbddb037954cd6a265 (patch) | |
| tree | 2849f3dea2612f11f9f1496c00ad3344ec0df644 /accent.h | |
| parent | 8661540682391f5f6db33a86747028d90dda09ed (diff) | |
| parent | 30b8f7faf8b3d58971672cadf97084d2a897bea9 (diff) | |
Merge pull request #10 from ihateamongus/codex/analyze-oldresources-folder-for-performance-x6iukv
Add glass-style transparency and dynamic tags
Diffstat (limited to 'accent.h')
| -rw-r--r-- | accent.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/accent.h b/accent.h new file mode 100644 index 0000000..8c9c6d4 --- /dev/null +++ b/accent.h @@ -0,0 +1,52 @@ +#ifndef ACCENT_H +#define ACCENT_H +#include <stdint.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <fcntl.h> + +#define SHMNAME "/breathing_color_shm" +#define SHM_MAGIC 0xBEEFCAFEu +#define SHM_VERSION 1u + +typedef struct { + uint32_t magic; + uint32_t version; + volatile uint32_t seq; + char color[8]; +} ColorShm; + +static inline ColorShm * +mapaccent(void) +{ + int fd; + ColorShm *blk; + if ((fd = shm_open(SHMNAME, O_RDONLY, 0)) < 0) + return NULL; + blk = mmap(NULL, sizeof(ColorShm), PROT_READ, MAP_SHARED, fd, 0); + close(fd); + if (blk == MAP_FAILED) + return NULL; + if (blk->magic != SHM_MAGIC || blk->version != SHM_VERSION) { + munmap(blk, sizeof(ColorShm)); + return NULL; + } + return blk; +} + +static inline int +readaccent(ColorShm **blk, char out[8]) +{ + uint32_t s1, s2; + if (!*blk && !(*blk = mapaccent())) + return 0; + do { + s1 = (*blk)->seq; + memcpy(out, (*blk)->color, 8); + s2 = (*blk)->seq; + } while (s1 != s2); + return out[0] == '#'; +} + +#endif /* ACCENT_H */ |
