Some minor changes in mess

This commit is contained in:
Casey 2024-04-09 15:22:39 +03:00
parent d902b63fd4
commit 679676e97f
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
2 changed files with 40 additions and 8 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
obj/*
livewp
mess/cairo-xcb

View File

@ -1,5 +1,6 @@
// x-run: ~/scripts/runc.sh % -lX11 -lcairo -lxcb -lm
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -14,6 +15,7 @@
#define EVENT(T, A, B) T *A = (T *)B
void render(xcb_connection_t *connection, int wid, cairo_t *cr, int win_w, int win_h);
void set_window_title(xcb_connection_t *connection, xcb_window_t wid, const char *title);
int main(void) {
xcb_connection_t *connection = xcb_connect(getenv("DISPLAY"), NULL);
@ -64,8 +66,9 @@ found_visual: {}
xcb_generic_event_t *event;
bool running = true;
char buffer[8192];
while (running) {
while ((event = xcb_poll_for_event(connection))) {
while (running && (event = xcb_poll_for_event(connection))) {
switch (event->response_type & ~0x80) {
case XCB_CONFIGURE_NOTIFY:
{
@ -73,33 +76,43 @@ found_visual: {}
if (win_w != evt->width || win_h != evt->height) {
printf("resize %dx%d -> %dx%d\n", win_w, win_h, evt->width, evt->height);
cairo_destroy(cr);
surface = cairo_xcb_surface_create(connection, wid, visual, win_w, win_h);
surface = cairo_xcb_surface_create(connection, wid, visual, evt->width, evt->height);
cr = cairo_create(surface);
win_w = evt->width;
win_h = evt->height;
}
}
break;
case XCB_REPARENT_NOTIFY:
printf("reparent\n");
break;
case XCB_MAP_NOTIFY:
printf("map\n");
break;
case XCB_FOCUS_IN:
printf("focus in\n");
break;
case XCB_FOCUS_OUT:
printf("focus out\n");
break;
case XCB_EXPOSE:
printf("expose\n");
{
EVENT(xcb_expose_event_t, evt, event);
printf("expose %dx%d+%d+%d\n", evt->width, evt->height, evt->x, evt->y);
}
break;
case XCB_DESTROY_NOTIFY:
cairo_destroy(cr);
running = false;
break;
default:
printf("event: %d\n", event->response_type);
printf("event: %d\n", event->response_type & ~0x80);
break;
}
free(event);
}
snprintf(buffer, 8191, "size: %dx%d", win_w, win_h);
set_window_title(connection, wid, buffer);
if (running) {
render(connection, wid, cr, win_w, win_h);
usleep(1000000 / 60);
@ -113,9 +126,27 @@ found_visual: {}
void render(xcb_connection_t *connection, int wid, cairo_t *cr, int win_w, int win_h) {
static float t = 0.0;
xcb_clear_area(connection, 0, wid, 0, 0, 0, 0);
cairo_set_source_rgb(cr, 0.0, 0.5 - sin(t) * 0.5, 0.5 - cos(t) * 0.5);
cairo_paint(cr);
cairo_set_source_rgb(cr, sin(t) * 0.5 + 0.5, cos(t) * 0.5 + 0.5, 0);
cairo_rectangle(cr, win_w * 0.5, win_h * 0.5, sin(t) * 0.5 * win_w, cos(t) * 0.5 * win_h);
cairo_fill(cr);
cairo_set_line_width(cr, 5);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
cairo_move_to(cr, win_w * 0.5, win_h * 0.5);
cairo_line_to(cr, (sin(t) * 0.5 + 0.5) * win_w, (cos(t) * 0.5 + 0.5) * win_h);
cairo_stroke(cr);
xcb_flush(connection);
t += 1.0 / 60.0;
}
void set_window_title(xcb_connection_t *connection, xcb_window_t wid, const char *title) {
xcb_change_property(connection,
XCB_PROP_MODE_REPLACE,
wid,
XCB_ATOM_WM_NAME,
XCB_ATOM_STRING,
8,
strlen(title), title);
xcb_flush(connection);
}