ref: 775f1994df1adb260d180f948b46678205c55fa5
parent: d6091e427901a3f7c6789e7a34ae0cf351ee0c2a
author: halfwit <michaelmisch1985@gmail.com>
date: Thu Oct 15 04:10:54 PDT 2020
Get everything working over normal open/close/read for now, then flag in stdio later
--- a/keyboard.c
+++ b/keyboard.c
@@ -55,14 +55,16 @@
static wchar_t
x9devKeybdRead(void)
{
+ static char s[3];
+ static int n = 0;
wchar_t rune;
- if (c9read(x9di.ctx, &x9di.keybd->tag, x9di.keybd->f, x9di.keybd->wroff, 1) != 1)
+ if(read(x9di.kfd, s+n, 1) != 1)
return 0;
- rune = x9di.keybd->rdbuf[0];
- /* TODO: Handle longer runes
- if ((rune & 0x80) != 0x00) {
+ rune = s[0];
+
+ if (n > 0 || (rune & 0x80) != 0x00) {
if (mbtowc(&rune, s, n + 1) == -1) {
if (++n == 3)
n = 0;
@@ -70,7 +72,7 @@
}
n = 0;
}
- */
+
if (rune == Kdown)
rune = 0x99;
else if (rune & KF)
--- a/libdraw/init.c
+++ b/libdraw/init.c
@@ -1,16 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include "draw.h"
-#include "../c9/c9.h"
Display *_display;
_Font *font;
Image *screen;
-C9ctx *ctx;
+enum{
+ DISP_BUFSIZE = 8000, /* Play with this some, see if changes much */
+};
+
static char deffontname[] = "*default*";
Screen *_screen;
@@ -34,10 +37,10 @@
int
geninitdraw(char *devdir, void(*error)(Display*, char*), char *label, char *windir, int ref)
{
- C9tag ftag, ltag, wtag;
int fd, n;
char *fontname;
- char path[256]; /* Maxpath */
+ char path[256];
+ char buf[128];
Subfont *df;
_display = initdisplay(devdir, windir, error);
@@ -56,13 +59,10 @@
return -1;
}
- sprintf(path, "/env/font");
- c9walk(ctx, &ftag, 1, fd, &path);
- c9open(ctx, &ftag, fd, O_RDONLY);
+ fd = open("/env/font", O_RDONLY);
if(fd >= 0){
- c9read(ctx, &ftag, fd, 0, 128);
- //fontname = buf;
- }
+ read(fd, buf, sizeof(buf));
+ fontname = buf;
}
/*
@@ -88,11 +88,11 @@
*/
if(label != nil){
snprintf(buf, sizeof buf, "%s/label", _display->windir);
- fd = open(buf, OREAD);
+ fd = open(buf, O_RDONLY);
if(fd >= 0){
read(fd, _display->oldlabel, (sizeof _display->oldlabel)-1);
close(fd);
- fd = create(buf, OWRITE, 0666);
+ fd = open(buf, O_CREAT|O_WRONLY, 0666);
if(fd >= 0){
write(fd, label, strlen(label));
close(fd);
@@ -131,7 +131,7 @@
obuf[0] = 0;
retry:
- fd = open(winname, OREAD);
+ fd = open(winname, O_RDONLY);
if(fd<0 || (n=read(fd, buf, sizeof buf-1))<=0){
if((image=d->image) == nil){
*winp = nil;
@@ -222,7 +222,7 @@
return nil;
sprintf(buf, "%s/draw/new", dev);
- ctlfd = open(buf, ORDWR|OCEXEC);
+ ctlfd = open(buf, O_RDWR);
if(ctlfd < 0){
Error1:
free(t);
@@ -240,18 +240,18 @@
isnew = 0;
if(n < NINFO) /* this will do for now, we need something better here */
isnew = 1;
- sprint(buf, "%s/draw/%d/data", dev, atoi(info+0*12));
- datafd = open(buf, ORDWR|OCEXEC);
+ sprintf(buf, "%s/draw/%d/data", dev, atoi(info+0*12));
+ datafd = open(buf, O_RDWR);
if(datafd < 0)
goto Error2;
- sprint(buf, "%s/draw/%d/refresh", dev, atoi(info+0*12));
- reffd = open(buf, OREAD|OCEXEC);
+ sprintf(buf, "%s/draw/%d/refresh", dev, atoi(info+0*12));
+ reffd = open(buf, O_RDWR);
if(reffd < 0){
Error3:
close(datafd);
goto Error2;
}
- disp = mallocz(sizeof(Display), 1);
+ disp = calloc(sizeof(Display), 1);
if(disp == nil){
Error4:
close(reffd);
@@ -265,7 +265,7 @@
goto Error4;
}
if(n >= NINFO){
- image = mallocz(sizeof(Image), 1);
+ image = calloc(sizeof(Image), 1);
if(image == nil)
goto Error5;
image->display = disp;
@@ -284,12 +284,7 @@
}
disp->_isnewdisplay = isnew;
- disp->bufsize = iounit(datafd);
- if(disp->bufsize <= 0)
- disp->bufsize = 8000;
- if(disp->bufsize < 512){
- goto Error5;
- }
+ disp->bufsize = DISP_BUFSIZE;
disp->buf = malloc(disp->bufsize+5); /* +5 for flush message */
if(disp->buf == nil)
goto Error5;
@@ -348,8 +343,8 @@
if(disp == _display)
_display = nil;
if(disp->oldlabel[0]){
- snprint(buf, sizeof buf, "%s/label", disp->windir);
- fd = open(buf, OWRITE);
+ snprintf(buf, sizeof buf, "%s/label", disp->windir);
+ fd = open(buf, O_WRONLY);
if(fd >= 0){
write(fd, disp->oldlabel, strlen(disp->oldlabel));
close(fd);
@@ -402,9 +397,8 @@
if(d != nil && d->error != nil)
(*d->error)(d, s);
else{
- errstr(err, sizeof err);
- fprint(2, "draw: %s: %s\n", s, err);
- exits(s);
+ fprintf(stderr, "draw: %s: %s\n", s, err);
+ exit(1);
}
}
--- a/libdraw/meson.build
+++ b/libdraw/meson.build
@@ -7,5 +7,4 @@
libdraw = static_library(
'libdraw',
libdraw_src,
- link_with: libc9,
)
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,3 @@
-subdir('libc9')
subdir('libdraw')
srcs = [
@@ -20,7 +19,6 @@
include_directories: inc,
dependencies: common_dep,
link_with: [
- libc9,
libdraw,
libxserver_mi,
libxserver_main,
--- a/mouse.c
+++ b/mouse.c
@@ -51,22 +51,22 @@
x9devMouseRead(int *x, int *y, int *b)
{
int n;
+ char buf[1+4*12];
- /* Magic numbers here are the size of a message from /dev/mouse and its offsets */
- if((n = c9read(x9di.ctx, &x9di.mouse->tag, x9di.mouse->f, x9di.mouse->wroff, 1 + 4 * 12)) <= 0)
+ if((n = read(x9di.mfd, buf, 1 + 4 * 12)) < = 0)
return 0;
if (n != 1 + 4 * 12)
FatalError("Bad mouse event");
- if (x9di.mouse->rdbuf[0] == 'r') {
+ if (buf == 'r') {
x9devResize();
return 0;
}
- *x = atoi(x9di.mouse->rdbuf + 1 + 0 * 12) - screen->r.min.x;
- *y = atoi(x9di.mouse->rdbuf + 1 + 1 * 12) - screen->r.min.y;
- *b = atoi(x9di.mouse->rdbuf + 1 + 2 * 12);
+ *x = atoi(buf + 1 + 0 * 12) - screen->r.min.x;
+ *y = atoi(buf + 1 + 1 * 12) - screen->r.min.y;
+ *b = atoi(buf + 1 + 2 * 12);
return 1;
}
--- a/x9dev.c
+++ b/x9dev.c
@@ -31,124 +31,10 @@
extern x9devInfo x9di;
int debug = 0;
-/*
- * 9p functions, used in draw and here
- */
-static int
-wrsend(C9aux *a)
-{
- uint32_t n;
- int w;
-
- for (n = 0; n < a->wroff; n += w) {
- if ((w = write(a->f, a->wrbuf+n, a->wroff-n)) <= 0) {
- if (errno == EINTR)
- continue;
- if (errno != EPIPE) /* remote end closed */
- perror("write");
- return -1;
- }
- }
- a->wroff = 0;
-
- return 0;
-}
-
-static uint8_t *
-ctxbegin(C9ctx *ctx, uint32_t size)
-{
- /* Should return a buffer to store 'size' bytes. Nil means no memory. */
- uint8_t *b;
- C9aux *a;
-
- a = ctx->aux;
- if (a->wroff + size > sizeof(a->wrbuf)) {
- if (wrsend(a) != 0 || a->wroff + size > sizeof(a->wrbuf))
- return NULL;
- }
- b = a->wrbuf + a->wroff;
- a->wroff += size;
-
- return b;
-}
-
-static int
-ctxend(C9ctx *ctx)
-{
- /*
- * Marks the end of a message. Callback may decide if any accumulated
- * messages should be sent to the server/client.
- */
- (void)ctx;
- return 0;
-}
-
-static uint8_t *
-ctxread(C9ctx *ctx, uint32_t size, int *err)
-{
- /*
- * Should return a pointer to the data (exactly 'size' bytes) read.
- * Set 'err' to non-zero and return NULL in case of error.
- * 'err' set to zero (no error) should be used to return from c9process
- * early (timeout on read to do non-blocking operations, for example).
- */
- uint32_t n;
- int r;
- C9aux *a;
-
- a = ctx->aux;
- *err = 0;
- for (n = 0; n < size; n += r) {
- if ((r = read(a->f, a->rdbuf+n, size-n)) <= 0) {
- if (errno == EINTR)
- continue;
- close(a->f);
- return NULL;
- }
- }
-
- return a->rdbuf;
-}
-
-__attribute__ ((format (printf, 1, 2)))
-static void
-ctxerror(const char *fmt, ...)
-{
-
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
- fprintf(stderr, "\n");
- va_end(ap);
-}
-
-
-static void
-x9r(C9ctx *ctx, C9r *r)
-{
- C9aux *a;
-
- /* Callback called every time a new R-message is received. */
- a = ctx->aux;
- switch (r->type) {
- case Rread:
- break;
- case Ropen:
- break;
- case Rerror:
- break;
- default:
- break;
- }
-}
-
void
x9devInfoInit(void)
{
- C9tag *cons;
- C9fid cfd;
- C9aux *c;
+ int fd;
char path[256]; /* Plan9 Maxpath */
c = calloc(1, sizeof(*c));
@@ -173,17 +59,15 @@
x9di.ctx = c->ctx;
sprintf(path, "%s/mouse", _display->devdir);
- c9walk(x9di.ctx, &x9di.mouse->tag, 1, x9di.mouse->f, &path);
- c9open(x9di.ctx, &x9di.mouse->tag, x9di.mouse->f, O_RDWR|O_NONBLOCK);
+ x9di.mfd = open(path, O_RDWR|O_NONBLOCK);
sprintf(path, "%s/cons", _display->devdir);
- c9walk(x9di.ctx, &x9di.keybd->tag, 1, x9di.keybd->f, &path);
- c9open(x9di.ctx, &x9di.keybd->tag, x9di.keybd->f, O_RDONLY|O_NONBLOCK);
+ x9di.kfd = open(path, O_RDONLY|O_NONBLOCK);
sprintf(path, "%s/consctl", _display->devdir);
- c9walk(x9di.ctx, &cons, 1, cfd, &path);
- c9open(x9di.ctx, &cons, cfd, O_WRONLY);
- c9write(x9di.ctx, &cons, cfd, 0, "rawon", 5);
+ fd = open(path, O_WRONLY);
+ write(fd, "rawon", 5);
+ close(fd);
}
void
--- a/x9dev.h
+++ b/x9dev.h
@@ -51,7 +51,6 @@
#include "xserver-properties.h"
#include "mi.h" /* miEnqueue mieqProcessInputEvents */
-#include "c9/c9.h"
#include "libdraw/draw.h"
#define Msize 8192
@@ -66,18 +65,7 @@
#define x9devRecolorCursor (void *) NoopDDA
#define x9devSetCursorPosition (void *) NoopDDA
-typedef struct C9aux C9aux;
-struct C9aux {
- C9ctx *ctx;
- C9tag *tag;
- int f;
- int flags;
- uint8_t rdbuf[Msize];
- uint8_t wrbuf[Msize];
- uint32_t wroff;
-};
-
typedef struct x9devInfo x9devInfo;
struct x9devInfo
{
@@ -87,9 +75,8 @@
int height;
int dpi;
int bpl;
- C9ctx *ctx;
- C9aux *mouse;
- C9aux *keybd;
+ int mfd;
+ int kfd;
};
static PixmapFormatRec formats[] = {