diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-04-05 00:35:58 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-04-05 00:35:58 -0400 |
commit | 2f1c8d35e6a824544714c7eed274f88121322618 (patch) | |
tree | 7cd0eafb9b436a9aca5a428fe8473d0230bafe7e | |
download | runes-2f1c8d35e6a824544714c7eed274f88121322618.tar.gz runes-2f1c8d35e6a824544714c7eed274f88121322618.zip |
initial commit
-rw-r--r-- | Makefile | 17 | ||||
-rw-r--r-- | main.c | 24 | ||||
-rw-r--r-- | runes.c | 31 | ||||
-rw-r--r-- | runes.h | 20 | ||||
-rw-r--r-- | test.c | 56 | ||||
-rw-r--r-- | xlib.c | 57 | ||||
-rw-r--r-- | xlib.h | 17 |
7 files changed, 222 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c385821 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +OUT = runes +OBJ = runes.o xlib.o main.o +CFLAGS ?= -g +LDFLAGS ?= -g + +build: $(OUT) + +$(OUT): $(OBJ) + $(CC) $(shell pkg-config --libs cairo-xlib) $(LDFLAGS) -o $@ $^ + +%.o: %.c + $(CC) $(shell pkg-config --cflags cairo-xlib) $(CFLAGS) -c -o $@ $^ + +clean: + rm -f $(OUT) $(OBJ) + +.PHONY: build clean @@ -0,0 +1,24 @@ +#include <unistd.h> + +#include "runes.h" + +int main (int argc, char *argv[]) +{ + RunesTerm *t; + + t = runes_term_create(); + + cairo_select_font_face(t->cr, "7x14", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(t->cr, 14.0); + cairo_set_source_rgb(t->cr, 0.0, 0.0, 1.0); + cairo_move_to(t->cr, 10.0, 50.0); + cairo_show_text(t->cr, "Hello, world"); + + runes_term_flush(t); + + sleep(2); + + runes_term_destroy(t); + + return 0; +} @@ -0,0 +1,31 @@ +#include <cairo.h> +#include <stdlib.h> + +#include "runes.h" + +RunesTerm *runes_term_create() +{ + RunesTerm *t; + + t = malloc(sizeof(RunesTerm)); + + t->w = runes_window_create(); + t->surface = runes_surface_create(t->w); + t->cr = cairo_create(t->surface); + + return t; +} + +void runes_term_flush(RunesTerm *t) +{ + runes_window_flush(t->w); +} + +void runes_term_destroy(RunesTerm *t) +{ + cairo_destroy(t->cr); + cairo_surface_destroy(t->surface); + runes_window_destroy(t->w); + + free(t); +} @@ -0,0 +1,20 @@ +#ifndef _RUNES_H +#define _RUNES_H + +#include <cairo.h> + +#include "xlib.h" + +typedef struct { + RunesWindow *w; + /* RunesBuffer *buf; */ + + cairo_surface_t *surface; + cairo_t *cr; +} RunesTerm; + +RunesTerm *runes_term_create(); +void runes_term_flush(RunesTerm *t); +void runes_term_destroy(RunesTerm *t); + +#endif @@ -0,0 +1,56 @@ +#include <cairo.h> +#include <cairo-xlib.h> +#include <X11/Xlib.h> +#include <unistd.h> + +int main (int argc, char *argv[]) +{ + Display *dpy; + unsigned long white; + Window w; + Visual *vis; + GC gc; + + cairo_surface_t *surface; + cairo_t *cr; + + dpy = XOpenDisplay(NULL); + white = WhitePixel(dpy, DefaultScreen(dpy)); + w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 240, 80, 0, white, white); + vis = DefaultVisual(dpy, DefaultScreen(dpy)); + + XSelectInput(dpy, w, StructureNotifyMask); + XMapWindow(dpy, w); + gc = XCreateGC(dpy, w, 0, NULL); + XSetForeground(dpy, gc, white); + + for (;;) { + XEvent e; + + XNextEvent(dpy, &e); + if (e.type == MapNotify) { + break; + } + } + + surface = cairo_xlib_surface_create(dpy, w, vis, 240, 80); + cr = cairo_create(surface); + + cairo_select_font_face(cr, "7x14", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(cr, 14.0); + cairo_set_source_rgb(cr, 0.0, 0.0, 1.0); + cairo_move_to(cr, 10.0, 50.0); + cairo_show_text(cr, "Hello, world"); + + XFlush(dpy); + + sleep(2); + + cairo_destroy(cr); + cairo_surface_destroy(surface); + + XDestroyWindow(dpy, w); + XCloseDisplay(dpy); + + return 0; +} @@ -0,0 +1,57 @@ +#include <cairo-xlib.h> +#include <stdlib.h> +#include <X11/Xlib.h> + +#include "xlib.h" + +RunesWindow *runes_window_create() +{ + RunesWindow *w; + unsigned long white; + + w = malloc(sizeof(RunesWindow)); + + w->dpy = XOpenDisplay(NULL); + white = WhitePixel(w->dpy, DefaultScreen(w->dpy)); + w->w = XCreateSimpleWindow( + w->dpy, DefaultRootWindow(w->dpy), + 0, 0, 240, 80, 0, white, white + ); + + XSelectInput(w->dpy, w->w, StructureNotifyMask); + XMapWindow(w->dpy, w->w); + w->gc = XCreateGC(w->dpy, w->w, 0, NULL); + XSetForeground(w->dpy, w->gc, white); + + for (;;) { + XEvent e; + + XNextEvent(w->dpy, &e); + if (e.type == MapNotify) { + break; + } + } + + return w; +} + +cairo_surface_t *runes_surface_create(RunesWindow *w) +{ + Visual *vis; + + vis = DefaultVisual(w->dpy, DefaultScreen(w->dpy)); + return cairo_xlib_surface_create(w->dpy, w->w, vis, 240, 80); +} + +void runes_window_flush(RunesWindow *w) +{ + XFlush(w->dpy); +} + +void runes_window_destroy(RunesWindow *w) +{ + XDestroyWindow(w->dpy, w->w); + XCloseDisplay(w->dpy); + + free(w); +} @@ -0,0 +1,17 @@ +#ifndef _RUNES_XLIB_H +#define _RUNES_XLIB_H + +#include <X11/Xlib.h> + +typedef struct { + Display *dpy; + Window w; + GC gc; +} RunesWindow; + +RunesWindow *runes_window_create(); +cairo_surface_t *runes_surface_create(RunesWindow *w); +void runes_window_flush(RunesWindow *w); +void runes_window_destroy(RunesWindow *w); + +#endif |