From 2f1c8d35e6a824544714c7eed274f88121322618 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 5 Apr 2014 00:35:58 -0400 Subject: initial commit --- Makefile | 17 +++++++++++++++++ main.c | 24 ++++++++++++++++++++++++ runes.c | 31 +++++++++++++++++++++++++++++++ runes.h | 20 ++++++++++++++++++++ test.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xlib.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xlib.h | 17 +++++++++++++++++ 7 files changed, 222 insertions(+) create mode 100644 Makefile create mode 100644 main.c create mode 100644 runes.c create mode 100644 runes.h create mode 100644 test.c create mode 100644 xlib.c create mode 100644 xlib.h 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 diff --git a/main.c b/main.c new file mode 100644 index 0000000..f366283 --- /dev/null +++ b/main.c @@ -0,0 +1,24 @@ +#include + +#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; +} diff --git a/runes.c b/runes.c new file mode 100644 index 0000000..2e4d1ba --- /dev/null +++ b/runes.c @@ -0,0 +1,31 @@ +#include +#include + +#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); +} diff --git a/runes.h b/runes.h new file mode 100644 index 0000000..1c7b273 --- /dev/null +++ b/runes.h @@ -0,0 +1,20 @@ +#ifndef _RUNES_H +#define _RUNES_H + +#include + +#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 diff --git a/test.c b/test.c new file mode 100644 index 0000000..01677c8 --- /dev/null +++ b/test.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +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; +} diff --git a/xlib.c b/xlib.c new file mode 100644 index 0000000..76b3b55 --- /dev/null +++ b/xlib.c @@ -0,0 +1,57 @@ +#include +#include +#include + +#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); +} diff --git a/xlib.h b/xlib.h new file mode 100644 index 0000000..083bfb6 --- /dev/null +++ b/xlib.h @@ -0,0 +1,17 @@ +#ifndef _RUNES_XLIB_H +#define _RUNES_XLIB_H + +#include + +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 -- cgit v1.2.3-54-g00ecf