commit 1f86a7bb32b059c0d115ecd196f3aa3beb06b53f
parent df78d9fed344b55967accac4a73f7485986f4a0d
Author: kocotian <kocotian@kocotian.pl>
Date: Fri, 15 Jan 2021 15:07:50 +0100
[v0.2.1] README, basic fwin example
Diffstat:
4 files changed, 139 insertions(+), 79 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,4 +1,10 @@
================
+- v0.2.1:
+* extended README
+* basic fwin example
+* examples directory
+
+================
- v0.2:
* some basic user input
diff --git a/README b/README
@@ -1,2 +1,10 @@
-fwin - framebuffer window system
-================================
+=== fwin - framebuffer window system =================================
+
+FWin is a simple Framebuffer-based Window System.
+Basic (this) FWin setup contains:
+
+* FLib - simple library for drawing things in framebuffer. Like Xlib.
+* FWin Server - simple server that manage framebuffer device, windows,
+ something like X server + WM. FWin Server is built on top of FLib.
+
+For copyright and license details see files LICENSE and AUTHORS.
diff --git a/examples/basic_hello_world.c b/examples/basic_hello_world.c
@@ -0,0 +1,69 @@
+/* See AUTHORS file for copying details
+ and LICENSE file for license details. */
+
+#define _XOPEN_SOURCE 700
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <flib.h>
+#include "getch.h"
+
+int
+main(void)
+{
+ FbDrawable fbdev, buffer;
+ /* fbdev is actual framebuffer device, buffer is only temporary
+ buffer for making operations and its content is copied to fbdev.
+ Why? If we will make operations on fbdev directly, screen will
+ be flashing and this will be just epilepsy moment. It will consume
+ more ram, but this will just look normal. */
+
+ /* Opening fbdev */
+ if ((fbdev.fbdesc = fbopen(DEFAULT_FRAMEBUFFER)) < 0)
+ exit(fbdev.fbdesc);
+
+ /* Getting resolution from fbdev */
+ fbdev.res[0] = getres(fbdev.fbdesc);
+ fbdev.res[1] = getvres(fbdev.fbdesc);
+
+ /* Calculating length - x * y * rgba (4) */
+ fbdev.len = GETX(fbdev.res[1]) * GETY(fbdev.res[1]) * 4;
+
+ /* Mapping fbdev into memory */
+ if ((fbdev.mappoint = fbmap(fbdev.fbdesc, fbdev.len)) == MAP_FAILED)
+ exit((int64_t)fbdev.mappoint);
+
+ /* Setting up temporary buffer - no file, so descriptor is -1 */
+ buffer.fbdesc = -1;
+
+ /* Resolution will be the same as in fbdev */
+ buffer.res[0] = fbdev.res[0];
+ buffer.res[1] = fbdev.res[1];
+
+ /* Length too */
+ buffer.len = fbdev.len;
+
+ /* Allocating memory via malloc - just length */
+ buffer.mappoint = malloc(buffer.len);
+
+ /* Setting random seed */
+ srand(getpid());
+
+ /* Filling buffer with #1d2021 */
+ fbfill(&buffer, 0xff1d2021);
+
+ /* And printing "Hello, world!" */
+ fbputs(&buffer, XY(8, 8), "Hello, world!", 0xffebdbb2, 0xff1d2021);
+
+ /* Copying the buffer content to actual fbdev */
+ drwcpyraw(&fbdev, &buffer);
+
+ /* Freeing temporary buffer memory */
+ free(buffer.mappoint);
+
+ /* Unmapping and closing fbdev */
+ fbunmap(&fbdev.mappoint, fbdev.len);
+ fbclose(fbdev.fbdesc);
+}
diff --git a/fwin.c b/fwin.c
@@ -5,7 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
+#include <unistd.h>
#include <flib.h>
#include "getch.h"
@@ -13,80 +13,57 @@
int
main(void)
{
- int fbdesc;
- int64_t res, vres, len;
- char *mappoint;
-
- FbDrawable screen, framebuf, terminal, tux;
-
- if ((fbdesc = fbopen(DEFAULT_FRAMEBUFFER)) < 0)
- exit(fbdesc);
-
- res = getres(fbdesc);
- vres = getvres(fbdesc);
- len = GETX(vres) * GETY(vres) * 4;
-
- if ((mappoint = fbmap(fbdesc, len)) == MAP_FAILED)
- exit((int64_t)mappoint);
-
- screen.fbdesc = fbdesc;
- screen.mappoint = mappoint;
- screen.len = len;
- screen.res[0] = getres(fbdesc);
- screen.res[1] = getvres(fbdesc);
-
- framebuf.fbdesc = -1;
- framebuf.mappoint = malloc(len);
- framebuf.len = len;
- framebuf.res[0] = getres(fbdesc);
- framebuf.res[1] = getvres(fbdesc);
-
- terminal.fbdesc = -1;
- terminal.len = 514 * 130 * 4;
- terminal.mappoint = malloc(len);
- terminal.res[0] = terminal.res[1] = XY(514, 130);
-
- tux.fbdesc = open("tux.raw", O_RDONLY);
- tux.len = 128 * 128 * 4;
- tux.mappoint = mmap(NULL, 65536 /* hardcoded */,
- PROT_READ, MAP_SHARED,
- tux.fbdesc, 0);
- close(tux.fbdesc);
- tux.res[0] = tux.res[1] = XY(128, 128);
-
- int sel = 0;
- PositionXY xy[] = {
- XY(59, 91),
- XY(285, 181),
- };
-
- while (1) {
- fbfill(&framebuf, 0x1d2021);
- fbdrawrect(&framebuf, 0, XY(GETX(res), 24), 1, 0xeeeeee);
- fbputs(&framebuf, XY(8, 8), "Welcome to the Framebuffer Window System alpha!", 0x222222, 0xeeeeee);
-
- fbdrawrect(&terminal, XY(0, 0), XY(514, 130), 0, 0xd79921);
- fbputs(&terminal, XY(9, 9), "simple window", 0xebdbb2, 0x000000);
-
- drwcpyat(&framebuf, &terminal, xy[0]);
- drwcpyat(&framebuf, &tux, xy[1]);
- drwcpyraw(&screen, &framebuf);
- switch (getch(0)) {
- case 'h': xy[sel] = XY(GETX(xy[sel]) - 1, GETY(xy[sel])); break;
- case 'l': xy[sel] = XY(GETX(xy[sel]) + 1, GETY(xy[sel])); break;
- case 'k': xy[sel] = XY(GETX(xy[sel]), GETY(xy[sel]) - 1); break;
- case 'j': xy[sel] = XY(GETX(xy[sel]), GETY(xy[sel]) + 1); break;
- case 'J': sel = sel ? 0 : 1; break;
- case 'K': sel = sel ? 0 : 1; break;
- case 'q': goto done; break;
- }
- }
- done:
-
- free(terminal.mappoint);
- free(framebuf.mappoint);
-
- fbunmap(&tux.mappoint, tux.len);
- fbunmap(&mappoint, len);
- fbclose(fbdesc);
+ FbDrawable fbdev, buffer;
+ /* fbdev is actual framebuffer device, buffer is only temporary
+ buffer for making operations and its content is copied to fbdev.
+ Why? If we will make operations on fbdev directly, screen will
+ be flashing and this will be just epilepsy moment. It will consume
+ more ram, but this will just look normal. */
+
+ /* Opening fbdev */
+ if ((fbdev.fbdesc = fbopen(DEFAULT_FRAMEBUFFER)) < 0)
+ exit(fbdev.fbdesc);
+
+ /* Getting resolution from fbdev */
+ fbdev.res[0] = getres(fbdev.fbdesc);
+ fbdev.res[1] = getvres(fbdev.fbdesc);
+
+ /* Calculating length - x * y * rgba (4) */
+ fbdev.len = GETX(fbdev.res[1]) * GETY(fbdev.res[1]) * 4;
+
+ /* Mapping fbdev into memory */
+ if ((fbdev.mappoint = fbmap(fbdev.fbdesc, fbdev.len)) == MAP_FAILED)
+ exit((int64_t)fbdev.mappoint);
+
+ /* Setting up temporary buffer - no file, so descriptor is -1 */
+ buffer.fbdesc = -1;
+
+ /* Resolution will be the same as in fbdev */
+ buffer.res[0] = fbdev.res[0];
+ buffer.res[1] = fbdev.res[1];
+
+ /* Length too */
+ buffer.len = fbdev.len;
+
+ /* Allocating memory via malloc - just length */
+ buffer.mappoint = malloc(buffer.len);
+
+ /* Setting random seed */
+ srand(getpid());
+
+ /* Filling buffer with #1d2021 */
+ fbfill(&buffer, 0xff1d2021);
+
+ /* And printing "Hello, world!" */
+ fbputs(&buffer, XY(8, 8), "Hello, world!", 0xffebdbb2, 0xff1d2021);
+
+ /* Copying the buffer content to actual fbdev */
+ drwcpyraw(&fbdev, &buffer);
+
+ /* Freeing temporary buffer memory */
+ free(buffer.mappoint);
+
+ /* Unmapping and closing fbdev */
+ fbunmap(&fbdev.mappoint, fbdev.len);
+ fbclose(fbdev.fbdesc);
}