things/img/scrall/main.c

80 lines
2.1 KiB
C

// x-run: make run
#include <raylib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include "screenshot.h"
#include "windowtree.h"
int main(int argc, char **argv) {
(void)argc;
(void)argv;
xcb_connection_t *xcb = xcb_connect(NULL, NULL);
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(xcb)).data;
printf("root: 0x%08x\n", screen->root);
size_t n_windows;
struct window_info *windows = get_windows_list(xcb, &n_windows);
SetConfigFlags(FLAG_WINDOW_TRANSPARENT | FLAG_WINDOW_RESIZABLE);
InitWindow(0, 0, "img/scrall");
Font font = LoadFontEx("/usr/share/fonts/Unifont/Unifont.ttf", 16, 0, 8192);
struct window_display {
Vector2 offset;
Texture2D texture;
} *windows_snaps = calloc(n_windows, sizeof(struct window_display));
for (size_t i = 0; i < n_windows; i++) {
Image screenshot = get_screenshot(xcb, windows[i].wid);
if (screenshot.data) {
windows_snaps[i].texture = LoadTextureFromImage(screenshot);
ExportImage(screenshot, TextFormat("screen_%08x.png", windows[i].wid));
UnloadImage(screenshot);
} else {
windows_snaps[i].texture.id = -1;
}
windows_snaps[i].offset.x = windows[i].rect.x;
windows_snaps[i].offset.y = windows[i].rect.y;
}
for (int frame = 0; !WindowShouldClose(); frame++) {
BeginDrawing();
ClearBackground(Fade(BLACK, 0.9));
BeginBlendMode(BLEND_ALPHA);
for (size_t i = 0; i < n_windows; i++) {
if (windows_snaps[i].texture.id != (unsigned int)-1 && ((frame / 10) % n_windows) == i) {
DrawTextureV(windows_snaps[i].texture, windows_snaps[i].offset, WHITE);
}
}
for (size_t i = 0; i < n_windows; i++) {
DrawTextEx(font,
TextFormat("0x%08x %dx%d+%d+%d %s\n",
windows[i].wid,
windows[i].rect.width,
windows[i].rect.height,
windows[i].rect.x,
windows[i].rect.y,
windows[i].title),
(Vector2) { 8, 8 + 18 * i }, 16, 0,
windows_snaps[i].texture.id == (unsigned int)-1 ? RED :WHITE);
}
EndBlendMode();
EndDrawing();
}
UnloadFont(font);
}