aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-11 16:01:21 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-11 16:01:21 -0400
commit63513dba6880d75ba279ed01960ec9bf2f41208a (patch)
tree25d71bf2336327a5f01f95542cf20293a78c4172
parentdcde26d4fd8a0d359e9afe4144dba0650e4da435 (diff)
downloadrunes-63513dba6880d75ba279ed01960ec9bf2f41208a.tar.gz
runes-63513dba6880d75ba279ed01960ec9bf2f41208a.zip
clean up some stuff with static functions
-rw-r--r--display.c24
-rw-r--r--pty-unix.c59
-rw-r--r--vt100.c172
-rw-r--r--window-xlib.c225
4 files changed, 247 insertions, 233 deletions
diff --git a/display.c b/display.c
index 71124cd..8093f8b 100644
--- a/display.c
+++ b/display.c
@@ -2,6 +2,8 @@
#include "runes.h"
+static void runes_display_get_font_dimensions(RunesTerm *t, double *fontx, double *fonty, double *ascent);
+
void runes_display_init(RunesTerm *t)
{
cairo_font_face_t *font_face;
@@ -36,17 +38,6 @@ void runes_display_init(RunesTerm *t)
runes_pty_backend_set_window_size(t);
}
-static void runes_display_get_font_dimensions(RunesTerm *t, double *fontx, double *fonty, double *ascent)
-{
- cairo_font_extents_t extents;
-
- cairo_font_extents(t->cr, &extents);
-
- *fontx = extents.max_x_advance;
- *fonty = extents.height;
- *ascent = extents.ascent;
-}
-
void runes_display_get_term_size(RunesTerm *t, int *row, int *col, int *xpixel, int *ypixel)
{
double fontx, fonty, ascent;
@@ -200,3 +191,14 @@ void runes_display_reset_bg_color(RunesTerm *t)
{
runes_display_set_bg_color(t, t->colors[0]);
}
+
+static void runes_display_get_font_dimensions(RunesTerm *t, double *fontx, double *fonty, double *ascent)
+{
+ cairo_font_extents_t extents;
+
+ cairo_font_extents(t->cr, &extents);
+
+ *fontx = extents.max_x_advance;
+ *fonty = extents.height;
+ *ascent = extents.ascent;
+}
diff --git a/pty-unix.c b/pty-unix.c
index c02b31f..6934bb6 100644
--- a/pty-unix.c
+++ b/pty-unix.c
@@ -6,6 +6,9 @@
#include "runes.h"
+static void runes_pty_backend_read(uv_work_t *req);
+static void runes_pty_backend_got_data(uv_work_t *req, int status);
+
void runes_pty_backend_init(RunesTerm *t)
{
RunesPtyBackend *pty;
@@ -57,33 +60,6 @@ void runes_pty_backend_set_window_size(RunesTerm *t)
ioctl(t->pty.master, TIOCSWINSZ, &size);
}
-static void runes_read_pty(uv_work_t *req)
-{
- RunesPtyLoopData *data;
-
- data = (RunesPtyLoopData *)req->data;
- data->len = read(data->data.t->pty.master, data->buf, RUNES_PTY_BUFFER_LENGTH);
-}
-
-static void runes_got_pty_data(uv_work_t *req, int status)
-{
- RunesTerm *t;
- RunesPtyLoopData *data;
-
- UNUSED(status);
- data = (RunesPtyLoopData *)req->data;
- t = data->data.t;
-
- if (data->len > 0) {
- runes_handle_pty_read(t, data->buf, data->len);
- uv_queue_work(t->loop, req, runes_read_pty, runes_got_pty_data);
- }
- else {
- runes_handle_pty_close(t);
- free(req);
- }
-}
-
void runes_pty_backend_loop_init(RunesTerm *t)
{
void *data;
@@ -92,7 +68,7 @@ void runes_pty_backend_loop_init(RunesTerm *t)
((RunesLoopData *)data)->req.data = data;
((RunesLoopData *)data)->t = t;
- uv_queue_work(t->loop, data, runes_read_pty, runes_got_pty_data);
+ uv_queue_work(t->loop, data, runes_pty_backend_read, runes_pty_backend_got_data);
}
void runes_pty_backend_write(RunesTerm *t, char *buf, size_t len)
@@ -115,3 +91,30 @@ void runes_pty_backend_cleanup(RunesTerm *t)
pty = &t->pty;
close(pty->master);
}
+
+static void runes_pty_backend_read(uv_work_t *req)
+{
+ RunesPtyLoopData *data;
+
+ data = (RunesPtyLoopData *)req->data;
+ data->len = read(data->data.t->pty.master, data->buf, RUNES_PTY_BUFFER_LENGTH);
+}
+
+static void runes_pty_backend_got_data(uv_work_t *req, int status)
+{
+ RunesTerm *t;
+ RunesPtyLoopData *data;
+
+ UNUSED(status);
+ data = (RunesPtyLoopData *)req->data;
+ t = data->data.t;
+
+ if (data->len > 0) {
+ runes_handle_pty_read(t, data->buf, data->len);
+ uv_queue_work(t->loop, req, runes_pty_backend_read, runes_pty_backend_got_data);
+ }
+ else {
+ runes_handle_pty_close(t);
+ free(req);
+ }
+}
diff --git a/vt100.c b/vt100.c
index 6763be6..10862e8 100644
--- a/vt100.c
+++ b/vt100.c
@@ -12,24 +12,85 @@ static const char *ctrl_chars =
"\030\031\032\033\034\035\036\037"
"\177";
-static void runes_vt100_unhandled_escape_sequence(RunesTerm *t, int *p, char type)
+static char *runes_vt100_handle_ctrl_char(RunesTerm *t, char *buf, size_t len);
+static char *runes_vt100_handle_escape_sequence(RunesTerm *t, char *buf, size_t len);
+static void runes_vt100_unhandled_escape_sequence(RunesTerm *t, int *p, char type);
+
+void runes_vt100_process_string(RunesTerm *t, char *buf, size_t len)
{
- UNUSED(t);
+ int found;
+ size_t prefix;
- fprintf(stderr, "unhandled escape sequence: \\033");
- if (p) {
- fprintf(stderr, "[");
- if (p[0] != -1) {
- fprintf(stderr, "%d", p[0]);
- }
- if (p[1] != -1) {
- fprintf(stderr, ";%d", p[1]);
+ buf[len] = '\0';
+ do {
+ found = 0;
+
+ prefix = strcspn(buf, ctrl_chars);
+ if (prefix) {
+ char tmp = buf[prefix];
+
+ buf[prefix] = '\0';
+ runes_display_show_string(t, buf, strlen(buf));
+ buf[prefix] = tmp;
+ buf += prefix;
+ found = 1;
}
- if (p[2] != -1) {
- fprintf(stderr, ";%d", p[2]);
+
+ prefix = strspn(buf, ctrl_chars);
+ if (prefix) {
+ char *end = buf + prefix;
+
+ while (buf < end) {
+ buf = runes_vt100_handle_ctrl_char(t, buf, strlen(buf));
+ }
+ found = 1;
}
+ } while (found);
+}
+
+static char *runes_vt100_handle_ctrl_char(RunesTerm *t, char *buf, size_t len)
+{
+ switch (buf[0]) {
+ case '\010': /* BS */
+ runes_display_backspace(t);
+ buf++;
+ break;
+ case '\011': { /* TAB */
+ int row, col;
+
+ runes_display_get_position(t, &row, &col);
+ runes_display_move_to(t, row, col - (col % 8) + 8);
+ buf++;
+ break;
}
- fprintf(stderr, "%c\n", type);
+ case '\012': /* LF */
+ case '\013': /* VT */
+ case '\014': { /* FF */
+ int row, col;
+
+ runes_display_get_position(t, &row, &col);
+ runes_display_move_to(t, row + 1, col);
+ buf++;
+ break;
+ }
+ case '\015': { /* CR */
+ int row, col;
+
+ runes_display_get_position(t, &row, &col);
+ runes_display_move_to(t, row, 0);
+ buf++;
+ break;
+ }
+ case '\033':
+ buf = runes_vt100_handle_escape_sequence(t, buf, len);
+ break;
+ default: {
+ buf++;
+ break;
+ }
+ }
+
+ return buf;
}
static char *runes_vt100_handle_escape_sequence(RunesTerm *t, char *buf, size_t len)
@@ -184,79 +245,22 @@ static char *runes_vt100_handle_escape_sequence(RunesTerm *t, char *buf, size_t
return buf;
}
-static char *runes_vt100_handle_ctrl_char(RunesTerm *t, char *buf, size_t len)
-{
- switch (buf[0]) {
- case '\010': /* BS */
- runes_display_backspace(t);
- buf++;
- break;
- case '\011': { /* TAB */
- int row, col;
-
- runes_display_get_position(t, &row, &col);
- runes_display_move_to(t, row, col - (col % 8) + 8);
- buf++;
- break;
- }
- case '\012': /* LF */
- case '\013': /* VT */
- case '\014': { /* FF */
- int row, col;
-
- runes_display_get_position(t, &row, &col);
- runes_display_move_to(t, row + 1, col);
- buf++;
- break;
- }
- case '\015': { /* CR */
- int row, col;
-
- runes_display_get_position(t, &row, &col);
- runes_display_move_to(t, row, 0);
- buf++;
- break;
- }
- case '\033':
- buf = runes_vt100_handle_escape_sequence(t, buf, len);
- break;
- default: {
- buf++;
- break;
- }
- }
-
- return buf;
-}
-
-void runes_vt100_process_string(RunesTerm *t, char *buf, size_t len)
+static void runes_vt100_unhandled_escape_sequence(RunesTerm *t, int *p, char type)
{
- int found;
- size_t prefix;
-
- buf[len] = '\0';
- do {
- found = 0;
-
- prefix = strcspn(buf, ctrl_chars);
- if (prefix) {
- char tmp = buf[prefix];
+ UNUSED(t);
- buf[prefix] = '\0';
- runes_display_show_string(t, buf, strlen(buf));
- buf[prefix] = tmp;
- buf += prefix;
- found = 1;
+ fprintf(stderr, "unhandled escape sequence: \\033");
+ if (p) {
+ fprintf(stderr, "[");
+ if (p[0] != -1) {
+ fprintf(stderr, "%d", p[0]);
}
-
- prefix = strspn(buf, ctrl_chars);
- if (prefix) {
- char *end = buf + prefix;
-
- while (buf < end) {
- buf = runes_vt100_handle_ctrl_char(t, buf, strlen(buf));
- }
- found = 1;
+ if (p[1] != -1) {
+ fprintf(stderr, ";%d", p[1]);
}
- } while (found);
+ if (p[2] != -1) {
+ fprintf(stderr, ";%d", p[2]);
+ }
+ }
+ fprintf(stderr, "%c\n", type);
}
diff --git a/window-xlib.c b/window-xlib.c
index 9204354..076f364 100644
--- a/window-xlib.c
+++ b/window-xlib.c
@@ -18,7 +18,116 @@ static char *atom_names[RUNES_NUM_ATOMS] = {
"WM_PROTOCOLS"
};
-static void runes_get_next_event(uv_work_t *req)
+static void runes_window_backend_get_next_event(uv_work_t *req);
+static void runes_window_backend_process_event(uv_work_t *req, int status);
+static void runes_window_backend_init_wm_properties(RunesWindowBackend *w, int argc, char *argv[]);
+static void runes_window_backend_init_loop(RunesTerm *t);
+
+void runes_window_backend_init(RunesTerm *t, int argc, char *argv[])
+{
+ RunesWindowBackend *w;
+ unsigned long white;
+ XIM im;
+
+ w = &t->w;
+
+ 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;
+ }
+ }
+
+ XSetLocaleModifiers("");
+ im = XOpenIM(w->dpy, NULL, NULL, NULL);
+ w->ic = XCreateIC(
+ im,
+ XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
+ XNClientWindow, w->w,
+ XNFocusWindow, w->w,
+ NULL
+ );
+ if (w->ic == NULL) {
+ fprintf(stderr, "failed\n");
+ exit(1);
+ }
+
+ runes_window_backend_init_wm_properties(w, argc, argv);
+ runes_window_backend_init_loop(t);
+}
+
+cairo_surface_t *runes_window_backend_surface_create(RunesTerm *t)
+{
+ RunesWindowBackend *w;
+ Visual *vis;
+ XWindowAttributes attrs;
+
+ w = &t->w;
+ XGetWindowAttributes(w->dpy, w->w, &attrs);
+ vis = DefaultVisual(w->dpy, DefaultScreen(w->dpy));
+ return cairo_xlib_surface_create(w->dpy, w->w, vis, attrs.width, attrs.height);
+}
+
+void runes_window_backend_flush(RunesTerm *t)
+{
+ cairo_set_source_surface(t->backend_cr, cairo_get_target(t->cr), 0.0, 0.0);
+ cairo_paint(t->backend_cr);
+ runes_display_draw_cursor(t);
+ XFlush(t->w.dpy);
+}
+
+void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel)
+{
+ cairo_surface_t *surface;
+
+ surface = cairo_get_target(t->backend_cr);
+ *xpixel = cairo_xlib_surface_get_width(surface);
+ *ypixel = cairo_xlib_surface_get_height(surface);
+}
+
+void runes_window_backend_request_close(RunesTerm *t)
+{
+ XEvent e;
+
+ e.xclient.type = ClientMessage;
+ e.xclient.window = t->w.w;
+ e.xclient.message_type = t->w.atoms[RUNES_ATOM_WM_PROTOCOLS];
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = t->w.atoms[RUNES_ATOM_WM_DELETE_WINDOW];
+ e.xclient.data.l[1] = CurrentTime;
+
+ XSendEvent(t->w.dpy, t->w.w, False, NoEventMask, &e);
+}
+
+void runes_window_backend_cleanup(RunesTerm *t)
+{
+ RunesWindowBackend *w;
+ XIM im;
+
+ w = &t->w;
+ im = XIMOfIC(w->ic);
+ XDestroyIC(w->ic);
+ XCloseIM(im);
+ XFreeGC(w->dpy, w->gc);
+ XDestroyWindow(w->dpy, w->w);
+ XCloseDisplay(w->dpy);
+}
+
+static void runes_window_backend_get_next_event(uv_work_t *req)
{
RunesXlibLoopData *data;
@@ -26,7 +135,7 @@ static void runes_get_next_event(uv_work_t *req)
XNextEvent(data->data.t->w.dpy, &data->e);
}
-static void runes_process_event(uv_work_t *req, int status)
+static void runes_window_backend_process_event(uv_work_t *req, int status)
{
RunesXlibLoopData *data;
XEvent *e;
@@ -90,7 +199,7 @@ static void runes_process_event(uv_work_t *req, int status)
}
if (!should_close) {
- uv_queue_work(t->loop, req, runes_get_next_event, runes_process_event);
+ uv_queue_work(t->loop, req, runes_window_backend_get_next_event, runes_window_backend_process_event);
}
else {
runes_handle_close_window(t);
@@ -98,7 +207,7 @@ static void runes_process_event(uv_work_t *req, int status)
}
}
-static void runes_init_wm_properties(RunesWindowBackend *w, int argc, char *argv[])
+static void runes_window_backend_init_wm_properties(RunesWindowBackend *w, int argc, char *argv[])
{
pid_t pid;
XClassHint class_hints = { "runes", "runes" };
@@ -124,7 +233,7 @@ static void runes_init_wm_properties(RunesWindowBackend *w, int argc, char *argv
XChangeProperty(w->dpy, w->w, w->atoms[RUNES_ATOM_NET_WM_NAME], w->atoms[RUNES_ATOM_UTF8_STRING], 8, PropModeReplace, (unsigned char *)"runes", 5);
}
-static void runes_window_init_loop(RunesTerm *t)
+static void runes_window_backend_init_loop(RunesTerm *t)
{
RunesWindowBackend *w;
unsigned long mask;
@@ -140,109 +249,5 @@ static void runes_window_init_loop(RunesTerm *t)
((RunesLoopData *)data)->req.data = data;
((RunesLoopData *)data)->t = t;
- uv_queue_work(t->loop, data, runes_get_next_event, runes_process_event);
-}
-
-void runes_window_backend_init(RunesTerm *t, int argc, char *argv[])
-{
- RunesWindowBackend *w;
- unsigned long white;
- XIM im;
-
- w = &t->w;
-
- 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;
- }
- }
-
- XSetLocaleModifiers("");
- im = XOpenIM(w->dpy, NULL, NULL, NULL);
- w->ic = XCreateIC(
- im,
- XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
- XNClientWindow, w->w,
- XNFocusWindow, w->w,
- NULL
- );
- if (w->ic == NULL) {
- fprintf(stderr, "failed\n");
- exit(1);
- }
-
- runes_init_wm_properties(w, argc, argv);
- runes_window_init_loop(t);
-}
-
-cairo_surface_t *runes_window_backend_surface_create(RunesTerm *t)
-{
- RunesWindowBackend *w;
- Visual *vis;
- XWindowAttributes attrs;
-
- w = &t->w;
- XGetWindowAttributes(w->dpy, w->w, &attrs);
- vis = DefaultVisual(w->dpy, DefaultScreen(w->dpy));
- return cairo_xlib_surface_create(w->dpy, w->w, vis, attrs.width, attrs.height);
-}
-
-void runes_window_backend_flush(RunesTerm *t)
-{
- cairo_set_source_surface(t->backend_cr, cairo_get_target(t->cr), 0.0, 0.0);
- cairo_paint(t->backend_cr);
- runes_display_draw_cursor(t);
- XFlush(t->w.dpy);
-}
-
-void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel)
-{
- cairo_surface_t *surface;
-
- surface = cairo_get_target(t->backend_cr);
- *xpixel = cairo_xlib_surface_get_width(surface);
- *ypixel = cairo_xlib_surface_get_height(surface);
-}
-
-void runes_window_backend_request_close(RunesTerm *t)
-{
- XEvent e;
-
- e.xclient.type = ClientMessage;
- e.xclient.window = t->w.w;
- e.xclient.message_type = t->w.atoms[RUNES_ATOM_WM_PROTOCOLS];
- e.xclient.format = 32;
- e.xclient.data.l[0] = t->w.atoms[RUNES_ATOM_WM_DELETE_WINDOW];
- e.xclient.data.l[1] = CurrentTime;
-
- XSendEvent(t->w.dpy, t->w.w, False, NoEventMask, &e);
-}
-
-void runes_window_backend_cleanup(RunesTerm *t)
-{
- RunesWindowBackend *w;
- XIM im;
-
- w = &t->w;
- im = XIMOfIC(w->ic);
- XDestroyIC(w->ic);
- XCloseIM(im);
- XFreeGC(w->dpy, w->gc);
- XDestroyWindow(w->dpy, w->w);
- XCloseDisplay(w->dpy);
+ uv_queue_work(t->loop, data, runes_window_backend_get_next_event, runes_window_backend_process_event);
}