Some minor changes in mess
This commit is contained in:
parent
d902b63fd4
commit
679676e97f
|
@ -1,2 +1,3 @@
|
||||||
obj/*
|
obj/*
|
||||||
livewp
|
livewp
|
||||||
|
mess/cairo-xcb
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// x-run: ~/scripts/runc.sh % -lX11 -lcairo -lxcb -lm
|
// x-run: ~/scripts/runc.sh % -lX11 -lcairo -lxcb -lm
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
#define EVENT(T, A, B) T *A = (T *)B
|
#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 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) {
|
int main(void) {
|
||||||
xcb_connection_t *connection = xcb_connect(getenv("DISPLAY"), NULL);
|
xcb_connection_t *connection = xcb_connect(getenv("DISPLAY"), NULL);
|
||||||
|
@ -64,8 +66,9 @@ found_visual: {}
|
||||||
xcb_generic_event_t *event;
|
xcb_generic_event_t *event;
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
|
char buffer[8192];
|
||||||
while (running) {
|
while (running) {
|
||||||
while ((event = xcb_poll_for_event(connection))) {
|
while (running && (event = xcb_poll_for_event(connection))) {
|
||||||
switch (event->response_type & ~0x80) {
|
switch (event->response_type & ~0x80) {
|
||||||
case XCB_CONFIGURE_NOTIFY:
|
case XCB_CONFIGURE_NOTIFY:
|
||||||
{
|
{
|
||||||
|
@ -73,33 +76,43 @@ found_visual: {}
|
||||||
if (win_w != evt->width || win_h != evt->height) {
|
if (win_w != evt->width || win_h != evt->height) {
|
||||||
printf("resize %dx%d -> %dx%d\n", win_w, win_h, evt->width, evt->height);
|
printf("resize %dx%d -> %dx%d\n", win_w, win_h, evt->width, evt->height);
|
||||||
cairo_destroy(cr);
|
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);
|
cr = cairo_create(surface);
|
||||||
win_w = evt->width;
|
win_w = evt->width;
|
||||||
win_h = evt->height;
|
win_h = evt->height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case XCB_REPARENT_NOTIFY:
|
||||||
|
printf("reparent\n");
|
||||||
|
break;
|
||||||
|
case XCB_MAP_NOTIFY:
|
||||||
|
printf("map\n");
|
||||||
|
break;
|
||||||
case XCB_FOCUS_IN:
|
case XCB_FOCUS_IN:
|
||||||
printf("focus in\n");
|
|
||||||
break;
|
break;
|
||||||
case XCB_FOCUS_OUT:
|
case XCB_FOCUS_OUT:
|
||||||
printf("focus out\n");
|
|
||||||
break;
|
break;
|
||||||
case XCB_EXPOSE:
|
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;
|
break;
|
||||||
case XCB_DESTROY_NOTIFY:
|
case XCB_DESTROY_NOTIFY:
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
running = false;
|
running = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("event: %d\n", event->response_type);
|
printf("event: %d\n", event->response_type & ~0x80);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(event);
|
free(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snprintf(buffer, 8191, "size: %dx%d", win_w, win_h);
|
||||||
|
set_window_title(connection, wid, buffer);
|
||||||
|
|
||||||
if (running) {
|
if (running) {
|
||||||
render(connection, wid, cr, win_w, win_h);
|
render(connection, wid, cr, win_w, win_h);
|
||||||
usleep(1000000 / 60);
|
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) {
|
void render(xcb_connection_t *connection, int wid, cairo_t *cr, int win_w, int win_h) {
|
||||||
static float t = 0.0;
|
static float t = 0.0;
|
||||||
xcb_clear_area(connection, 0, wid, 0, 0, 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_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_set_line_width(cr, 5);
|
||||||
cairo_fill(cr);
|
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);
|
xcb_flush(connection);
|
||||||
t += 1.0 / 60.0;
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue