hlfw.ca

x9dev

Download patch

ref: 3f65e3d01f0359cab8fde1841a1de965e1fcd037
parent: c26e66f3a96dd2a66f46fae46eb960daae553a92
author: halfwit <michaelmisch1985@gmail.com>
date: Sat Oct 10 04:58:12 PDT 2020

Start working on draw-specific code

--- a/keyboard.c
+++ b/keyboard.c
@@ -25,6 +25,8 @@
 #endif
 
 #include "x9dev.h"
+#include "keymap.h"
+
 #define KF      0xF000
 #define Kdown   0x80
 
@@ -53,17 +55,15 @@
 static wchar_t
 x9devKeybdRead(void)
 {
-    static char s[3];
-    static int  n = 0;
     wchar_t rune;
 
-    if (x9read(x9di.ctx, x9di.keybd, 1) != 1)
+    if (c9read(x9di.ctx, &x9di.keybd->tag, 0, x9di->keybd->wroff, 1) != 1)
         return 0;
 
-    rune = s[0];
-    if (n > 0 || (rune & 0x80) != 0x00) {
+    rune = x9di.keybd->rdbuf[0];
+    /* TODO: Handle longer runes
+    if ((rune & 0x80) != 0x00) {
         if (mbtowc(&rune, s, n + 1) == -1) {
-            /* incomplete rune; wait until next char */
             if (++n == 3)
                 n = 0;
             return 0;
@@ -70,6 +70,7 @@
         }
         n = 0;
     }
+    */
     if (rune == Kdown)
         rune = 0x99;
     else if (rune & KF)
@@ -133,7 +134,6 @@
 int  
 x9devKeybdProc(DeviceIntPtr pDev, int what)
 {
-
     switch (what) {
     case DEVICE_INIT:
         x9devInitModmap();
--- /dev/null
+++ b/libdraw/bytesperline.c
@@ -1,0 +1,33 @@
+/* From 9front */
+#include <stdlib.h>
+#include "draw.h"
+
+static int
+unitsperline(Rectangle r, int d, int bitsperunit)
+{
+	ulong l, t;
+
+	if(d <= 0 || d > 32)	/* being called wrong.  d is image depth. */
+		abort();
+
+	if(r.min.x >= 0){
+		l = (r.max.x*d+bitsperunit-1)/bitsperunit;
+		l -= (r.min.x*d)/bitsperunit;
+	}else{			/* make positive before divide */
+		t = (-r.min.x*d+bitsperunit-1)/bitsperunit;
+		l = t+(r.max.x*d+bitsperunit-1)/bitsperunit;
+	}
+	return l;
+}
+
+int
+wordsperline(Rectangle r, int d)
+{
+	return unitsperline(r, d, 8*sizeof(ulong));
+}
+
+int
+bytesperline(Rectangle r, int d)
+{
+	return unitsperline(r, d, 8);
+}
\ No newline at end of file
--- a/libdraw/draw.h
+++ b/libdraw/draw.h
@@ -171,7 +171,7 @@
 struct Screen
 {
 	Display	*display;	/* display holding data */
-	int	id;		/* id of system-held Screen */
+	int		id;			/* id of system-held Screen */
 	Image	*image;		/* unused; for reference only */
 	Image	*fill;		/* color to paint behind windows */
 };
@@ -196,7 +196,7 @@
 	Image		*transparent;
 	Image		*image;
 	uchar		*buf;
-	int		bufsize;
+	int			bufsize;
 	uchar		*bufp;
 	Font		*defaultfont;
 	Subfont		*defaultsubfont;
@@ -208,14 +208,14 @@
 struct Image
 {
 	Display		*display;	/* display holding data */
-	int		id;		/* id of system-held Image */
-	Rectangle	r;		/* rectangle in data area, local coords */
+	int			id;			/* id of system-held Image */
+	Rectangle	r;			/* rectangle in data area, local coords */
 	Rectangle 	clipr;		/* clipping region */
-	int		depth;		/* number of bits per pixel */
+	int			depth;		/* number of bits per pixel */
 	ulong		chan;
-	int		repl;		/* flag: data replicates to tile clipr */
+	int			repl;		/* flag: data replicates to tile clipr */
 	Screen		*screen;	/* 0 if not a window */
-	Image		*next;	/* next in list of windows */
+	Image		*next;		/* next in list of windows */
 };
 
 struct RGB
@@ -240,10 +240,10 @@
 struct	Fontchar
 {
 	int		x;		/* left edge of bits */
-	uchar		top;		/* first non-zero scan-line */
-	uchar		bottom;		/* last non-zero scan-line + 1 */
-	char		left;		/* offset of baseline */
-	uchar		width;		/* width of baseline */
+	uchar	top;	/* first non-zero scan-line */
+	uchar	bottom;	/* last non-zero scan-line + 1 */
+	char	left;	/* offset of baseline */
+	uchar	width;	/* width of baseline */
 };
 
 struct	Subfont
@@ -250,10 +250,10 @@
 {
 	char		*name;
 	short		n;		/* number of chars in font */
-	uchar		height;		/* height of image */
-	char		ascent;		/* top of image to baseline */
-	Fontchar 	*info;		/* n+1 character descriptors */
-	Image		*bits;		/* of font */
+	uchar		height;	/* height of image */
+	char		ascent;	/* top of image to baseline */
+	Fontchar 	*info;	/* n+1 character descriptors */
+	Image		*bits;	/* of font */
 	int		ref;
 };
 
@@ -276,18 +276,18 @@
 
 struct Cachefont
 {
-	Rune		min;	/* lowest rune value to be taken from subfont */
-	Rune		max;	/* highest rune value+1 to be taken from subfont */
-	int		offset;	/* position in subfont of character at min */
-	char		*name;			/* stored in font */
-	char		*subfontname;		/* to access subfont */
+	Rune	min;			/* lowest rune value to be taken from subfont */
+	Rune	max;			/* highest rune value+1 to be taken from subfont */
+	int		offset;			/* position in subfont of character at min */
+	char	*name;			/* stored in font */
+	char	*subfontname;	/* to access subfont */
 };
 
 struct Cacheinfo
 {
 	ushort		x;		/* left edge of bits */
-	uchar		width;		/* width of baseline */
-	char		left;		/* offset of baseline */
+	uchar		width;	/* width of baseline */
+	char		left;	/* offset of baseline */
 	Rune		value;	/* value of character at this slot in cache */
 	ushort		age;
 };
@@ -296,7 +296,7 @@
 {
 	ulong		age;	/* for replacement */
 	Cachefont	*cf;	/* font info that owns us */
-	Subfont		*f;	/* attached subfont */
+	Subfont		*f;		/* attached subfont */
 };
 
 struct Font
--- a/mouse.c
+++ b/mouse.c
@@ -52,7 +52,7 @@
     int n;
 
     /* Magic numbers here are the size of a message from /dev/mouse and its offsets */
-    if((n = x9read(x9di.ctx, x9di.mouse, 1 + 4 * 12)) <= 0)
+    if((n = c9read(x9di.ctx, &x9di.mouse.tag, 0, x9di.mouse->wroff, 1 + 4 * 12)) <= 0)
         return 0;
 
     if (n != 1 + 4 * 12)
@@ -63,8 +63,8 @@
         return 0;
     }
 
-    *x = atoi(x9di.mouse->rdbuf + 1 + 0 * 12) - x9di.screen->r.x;
-    *y = atoi(x9di.mouse->rdbuf + 1 + 1 * 12) - x9di.screen->r.y;
+    *x = atoi(x9di.mouse->rdbuf + 1 + 0 * 12) - screen->r.x;
+    *y = atoi(x9di.mouse->rdbuf + 1 + 1 * 12) - screen->r.y;
     *b = atoi(x9di.mouse->rdbuf + 1 + 2 * 12);
 
     return 1;
@@ -106,7 +106,6 @@
 
     return 1;
 }
-
 
 int  
 x9devMouseProc(DeviceIntPtr pDevice, int what)
--- a/screen.c
+++ b/screen.c
@@ -28,8 +28,7 @@
 
 static void
 x9devRefreshScreen(int x1, int y1, int x2, int y2)
-{
-    /*
+{ 
     Rectangle r;
     uchar *p;
     int n;
@@ -53,7 +52,6 @@
 
 End:
     flushimage(display, 1);
-    */
 }
 
 
@@ -60,13 +58,11 @@
 static void
 x9devResize(void)
 {
-    /* 
     if (getwindow(display, Refnone) < 0)
         FatalError("can't reattach to window");
 
     draw(screen, screen->r, display->white, nil, ZP);
     x9devRefreshScreen(0, 0, x9di.width, x9di.height);
-    */
 }
 
 static void
--- a/x9dev.c
+++ b/x9dev.c
@@ -24,13 +24,12 @@
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
 #endif
+
 #include "x9dev.h"
 
-
 static void
 x9devInfoInit(void)
 {
-    /* 
     if(initdraw(NULL, 0, "x9dev") < 0)
         FatalError("can't open display");
 
@@ -43,6 +42,7 @@
     if (x9di.fb == nil)
         FatalError("couldn't allocate framebuffer");
 
+/*
     snprint(buf, sizeof buf, "%s/mouse", display->devdir);
     x9di.mouseFd = c9open(buf, O_RDWR | O_NONBLOCK);
     if(x9di.mouseFd < 0)
@@ -59,7 +59,7 @@
         FatalError("can't open consctl");
     if(c9write(x9di.consctlFd, "rawon", 5) != 5)
         FatalError("can't set rawon");
-    */
+*/
 }
 
 void
--- a/x9dev.h
+++ b/x9dev.h
@@ -51,9 +51,8 @@
 #include "xserver-properties.h"
 #include "mi.h" /* miEnqueue mieqProcessInputEvents */
 
-/* Our local includes */
-#include "keymap.h"
 #include "c9/c9.h"
+#include "libdraw/draw.h"
 
 #define Msize 8192
 #define NUMFORMATS (sizeof(formats)/sizeof((formats)[0]))
@@ -70,10 +69,10 @@
 
 typedef struct x9file x9file;
 struct x9file {
-	uint8_t     rdbuf[Msize];
-	uint8_t     wrbuf[Msize];
-	uint32_t    wroff;
-    C9tag       *tag;
+    C9tag    tag;
+	uint8_t  rdbuf[Msize];
+	uint8_t  wrbuf[Msize];
+	uint32_t wroff;
 };
 
 typedef struct x9devInfo x9devInfo;
@@ -105,6 +104,7 @@
 DeviceIntPtr x9devMouse;
 DeviceIntPtr x9devKeybd;
 x9devInfo x9di;
+Screen *screen;
 
 Bool x9checkmod(unsigned int, DeviceIntPtr);
 Bool x9devScreenInit(ScreenPtr, int, char **);