aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--Makefile.in31
-rw-r--r--XWindow.c628
-rwxr-xr-xconfigure5
-rw-r--r--configure.in5
-rw-r--r--drv.c16
-rw-r--r--drv_T6963.c43
-rw-r--r--drv_X11.c561
-rw-r--r--drv_generic_graphic.c19
-rw-r--r--lcd4linux.conf.sample31
10 files changed, 660 insertions, 682 deletions
diff --git a/Makefile.am b/Makefile.am
index d5aad06..9432318 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,8 +71,7 @@ drv_MatrixOrbital.c \
MilfordInstruments.c \
PalmPilot.c \
Raster.c \
-SIN.c \
-XWindow.c \
+drv_X11.c \
Text.c \
font_6x8.h
diff --git a/Makefile.in b/Makefile.in
index d5be94b..342b375 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -115,7 +115,7 @@ lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h deb
#liblcd4linux_la_SOURCES =
-EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h BeckmannEgle.c drv_Crystalfontz.c drv_Cwlinux.c drv_HD44780.c drv_M50530.c drv_T6963.c drv_USBLCD.c drv_MatrixOrbital.c MilfordInstruments.c PalmPilot.c Raster.c SIN.c XWindow.c Text.c font_6x8.h
+EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h BeckmannEgle.c drv_Crystalfontz.c drv_Cwlinux.c drv_HD44780.c drv_M50530.c drv_T6963.c drv_USBLCD.c drv_MatrixOrbital.c MilfordInstruments.c PalmPilot.c Raster.c drv_X11.c Text.c font_6x8.h
EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm curses.m4 AUTHORS CREDITS FAQ NEWS TODO README README.Rows README.Tokens README.Drivers README.Plugins README.KDE plugin_sample.c
@@ -163,21 +163,20 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP_ENV = --best
DEP_FILES = .deps/BeckmannEgle.P .deps/MilfordInstruments.P \
-.deps/PalmPilot.P .deps/Raster.P .deps/SIN.P .deps/Text.P \
-.deps/XWindow.P .deps/cfg.P .deps/debug.P .deps/drv.P \
-.deps/drv_Crystalfontz.P .deps/drv_Cwlinux.P .deps/drv_HD44780.P \
-.deps/drv_M50530.P .deps/drv_MatrixOrbital.P .deps/drv_T6963.P \
-.deps/drv_USBLCD.P .deps/drv_generic_graphic.P \
-.deps/drv_generic_parport.P .deps/drv_generic_serial.P \
-.deps/drv_generic_text.P .deps/evaluator.P .deps/hash.P .deps/layout.P \
-.deps/lcd4linux.P .deps/lock.P .deps/pid.P .deps/plugin
/* $Id$
 * $URL$
 *
 * plugin for external processes
 *
 * Copyright (C) 2004 Michael Reinelt <michael@reinelt.co.at>
 * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 *
 * based on the old 'exec' client which is
 * Copyright (C) 2001 Leopold T�tsch <lt@toetsch.at>
 *
 *
 * This file is part of LCD4Linux.
 *
 * LCD4Linux is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * LCD4Linux is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/* 
 * exported functions:
 *
 * int plugin_init_exec (void)
 *  adds functions to start external pocesses
 *
 */


#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include "debug.h"
#include "plugin.h"
#include "hash.h"
#include "cfg.h"
#include "thread.h"
#include "qprintf.h"


#define NUM_THREADS 16
#define SHM_SIZE 4096

typedef struct {
    int delay;
    int mutex;
    pid_t pid;
    int shmid;
    char *cmd;
    char *key;
    char *ret;
} EXEC_THREAD;

static EXEC_THREAD Thread[NUM_THREADS];
static int max_thread = -1;

static HASH EXEC;


/* x^0 + x^5 + x^12 */
#define CRCPOLY 0x8408

static unsigned short CRC(const char *s)
{
    int i;
    unsigned short crc;

    /* seed value */
    crc = 0xffff;

    while (*s != '\0') {
	crc ^= *s++;
	for (i = 0; i < 8; i++)
	    crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY : 0);
    }
    return crc;
}


static void exec_thread(void *data)
{
    EXEC_THREAD *Thread = (EXEC_THREAD *) data;
    FILE *pipe;
    char buffer[SHM_SIZE];
    int len;

    /* use a safe path */
    putenv("PATH=/usr/local/bin:/usr/bin:/bin");

    /* forever... */
    while (1) {
	pipe = popen(Thread->cmd, "r");
	if (pipe == NULL) {
	    error("exec error: could not run pipe '%s': %s", Thread->cmd, strerror(errno));
	    len = 0;
	} else {
	    len = fread(buffer, 1, SHM_SIZE - 1, pipe);
	    if (len <= 0) {
		error("exec error: could not read from pipe '%s': %s", Thread->cmd, strerror(errno));
		len = 0;
	    }
	    pclose(pipe);
	}

	/* force trailing zero */
	buffer[len] = '\0';

	/* remove trailing CR/LF */
	while (len > 0 && (buffer[len - 1] == '\n' || buffer[len - 1] == '\r')) {
	    buffer[--len] = '\0';
	}

	/* lock shared memory */
	mutex_lock(Thread->mutex);
	/* write data */
	strncpy(Thread->ret, buffer, SHM_SIZE);
	/* unlock shared memory */
	mutex_unlock(Thread->mutex);
	usleep(Thread->delay);
    }
}


static void destroy_exec_thread(const int n)
{
    thread_destroy(Thread[n].pid);

    if (Thread[n].mutex != 0)
	mutex_destroy(Thread[n].mutex);
    if (Thread[n].cmd)
	free(Thread[n].cmd);
    if (Thread[n].key)
	free(Thread[n].key);
    if (Thread[n].ret)
	shm_destroy(Thread[n].shmid, Thread[n].ret);

    Thread[n].delay = 0;
    Thread[n].mutex = 0;
    Thread[n].pid = 0;
    Thread[n].shmid = 0;
    Thread[n].cmd = NULL;
    Thread[n].key = NULL;
    Thread[n].ret = NULL;
}


static int create_exec_thread(const char *cmd, const char *key, const int delay)
{
    char name[10];

    if (max_thread >= NUM_THREADS) {
	error("cannot create exec thread <%s>: thread buffer full!", cmd);
	return -1;
    }

    max_thread++;
    Thread[max_thread].delay = delay;
    Thread[max_thread].mutex = mutex_create();
    Thread[max_thread].pid = -1;
    Thread[max_thread].cmd = strdup(cmd);
    Thread[max_thread].key = strdup(key);
    Thread[max_thread].ret = NULL;

    /* create communication buffer */
    Thread[max_thread].shmid = shm_create((void **) &Thread[max_thread].ret, SHM_SIZE);

    /* catch error */
    if (Thread[max_thread].shmid < 0) {
	error("cannot create exec thread <%s>: shared memory allocation failed!", cmd);
	destroy_exec_thread(max_thread--);
	return -1;
    }

    /* create thread */
    qprintf(name, sizeof(name), "exec-%s", key);
    Thread[max_thread].pid = thread_create(name, exec_thread, &Thread[max_thread]);

    /* catch error */
    if (Thread[max_thread].pid < 0) {
	error("cannot create exec thread <%s>: fork failed?!", cmd);
	destroy_exec_thread(max_thread--);
	return -1;
    }

    return 0;
}


static int do_exec(const char *cmd, const char *key, int delay)
{
    int i, age;

    age = hash_age(&EXEC, key);

    if (age < 0) {
	hash_put(&EXEC, key, "");
	/* first-time call: create thread */
	if (delay < 10) {
	    error("exec(%s): delay %d is too short! using 10 msec", cmd, delay);
	    delay = 10;
	}
	if (create_exec_thread(cmd, key, 1000 * delay)) {
	    return -1;
	}
	return 0;
    }

    /* reread every 10 msec only */
    if (age > 0 && age <= 10)
	return 0;

    /* find thread */
    for (i = 0; i <= max_thread; i++) {
	if (strcmp(key, Thread[i].key) == 0) {
	    /* lock shared memory */
	    mutex_lock(Thread[i].mutex);
	    /* copy data */
	    hash_put(&EXEC, key, Thread[i].ret);
	    /* unlock shared memory */
	    mutex_unlock(Thread[i].mutex);
	    return 0;
	}
    }

    error("internal error: could not find thread exec-%s", key);
    re
@@ -21096,8 +21096,9 @@ if test "$X11" = "yes"; then
echo "$as_me: error: X11 headers or libraries not available: X11 driver disabled" >&2;}
{ (exit 1); exit 1; }; }
else
-# DRIVERS="$DRIVERS XWindow.lo"
-# DRIVERS="$DRIVERS XWindow.o"
+ GRAPHIC="yes"
+# DRIVERS="$DRIVERS drv_X11.lo"
+ DRIVERS="$DRIVERS drv_X11.o"
DRVLIBS="$DRVLIBS -L$ac_x_libraries -lX11"
cat >>confdefs.h <<\_ACEOF
diff --git a/configure.in b/configure.in
index 8ea41cf..ef4ec57 100644
--- a/configure.in
+++ b/configure.in
@@ -246,8 +246,9 @@ if test "$X11" = "yes"; then
if test "$no_x" = "yes"; then
AC_MSG_ERROR(X11 headers or libraries not available: X11 driver disabled)
else
-# DRIVERS="$DRIVERS XWindow.lo"
-# DRIVERS="$DRIVERS XWindow.o"
+ GRAPHIC="yes"
+# DRIVERS="$DRIVERS drv_X11.lo"
+ DRIVERS="$DRIVERS drv_X11.o"
DRVLIBS="$DRVLIBS -L$ac_x_libraries -lX11"
AC_DEFINE(WITH_X11,1,[X11 driver])
fi
diff --git a/drv.c b/drv.c
index 38d35b2..75605f5 100644
--- a/drv.c
+++ b/drv.c
@@ -1,4 +1,4 @@
-/* $Id: drv.c,v 1.8 2004/02/15 21:43:43 reinelt Exp $
+/* $Id: drv.c,v 1.9 2004/02/24 05:55:04 reinelt Exp $
*
* new framework for display drivers
*
@@ -23,6 +23,10 @@
*
*
* $Log: drv.c,v $
+ * Revision 1.9 2004/02/24 05:55:04 reinelt
+ *
+ * X11 driver ported
+ *
* Revision 1.8 2004/02/15 21:43:43 reinelt
* T6963 driver nearly finished
* framework for graphic displays done
@@ -115,7 +119,7 @@ extern DRIVER drv_MatrixOrbital;
extern DRIVER drv_MilfordInstruments;
extern DRIVER drv_PalmPilot;
extern DRIVER drv_Raster;
-extern DRIVER drv_XWindow;
+extern DRIVER drv_X11;
extern DRIVER drv_Text;
// output file for Raster driver
@@ -163,9 +167,11 @@ DRIVER *Driver[] = {
#if defined (WITH_PNG) || defined(WITH_PPM)
&Raster,
#endif
- #ifdef WITH_X11
- &XWindow,
- #endif
+ */
+#ifdef WITH_X11
+ &drv_X11,
+#endif
+ /* Fixme
#ifdef WITH_TEXT
&Text,
#endif
diff --git a/drv_T6963.c b/drv_T6963.c
index e581e81..e18c281 100644
--- a/drv_T6963.c
+++ b/drv_T6963.c
@@ -1,4 +1,4 @@
-/* $Id: drv_T6963.c,v 1.3 2004/02/22 17:35:41 reinelt Exp $
+/* $Id: drv_T6963.c,v 1.4 2004/02/24 05:55:04 reinelt Exp $
*
* new style driver for T6963-based displays
*
@@ -23,6 +23,10 @@
*
*
* $Log: drv_T6963.c,v $
+ * Revision 1.4 2004/02/24 05:55:04 reinelt
+ *
+ * X11 driver ported
+ *
* Revision 1.3 2004/02/22 17:35:41 reinelt
* some fixes for generic graphic driver and T6963
* removed ^M from plugin_imon (Nico, are you editing under Windows?)
@@ -69,6 +73,10 @@
#include "drv_generic_graphic.h"
#include "drv_generic_parport.h"
+#ifdef WITH_DMALLOC
+#include <dmalloc.h>
+#endif
+
static char Name[]="T6963";
static int Model;
@@ -377,8 +385,27 @@ static int drv_T6_start (char *section)
return -1;
}
- TROWS=DROWS/8; // text rows, assume 6x8 font
- TCOLS=DCOLS/6; // text cols, assume 6x8 font
+ s=cfg_get(section, "Font", "6x8");
+ if (s==NULL || *s=='\0') {
+ error ("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
+ return -1;
+ }
+
+ XRES = -1;
+ YRES = -1;
+ if (sscanf(s, "%dx%d", &XRES, &YRES)!=2 || XRES<1 || YRES<1) {
+ error ("%s: bad Font '%s' from %s", Name, s, cfg_source());
+ return -1;
+ }
+
+ // Fixme: provider other fonts someday...
+ if (XRES!=6 && YRES!=8) {
+ error ("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source());
+ return -1;
+ }
+
+ TROWS=DROWS/YRES; // text rows
+ TCOLS=DCOLS/XRES; // text cols
Buffer1=malloc(DCOLS*TROWS);
if (Buffer1==NULL) {
@@ -527,6 +554,16 @@ int drv_T6_quit (void) {
drv_generic_parport_close();
drv_generic_graphic_quit();
+ if (Buffer1) {
+ free (Buffer1);
+ Buffer1=NULL;
+ }
+
+ if (Buffer2) {
+ free (Buffer2);
+ Buffer2=NULL;
+ }
+
return (0);
}
diff --git a/drv_X11.c b/drv_X11.c
new file mode 100644
index 0000000..e146df4
--- /dev/null
+++ b/drv_X11.c
@@ -0,0 +1,561 @@
+/* $Id: drv_X11.c,v 1.1 2004/02/24 05:55:04 reinelt Exp $
+ *
+ * new style X11 Driver for LCD4Linux
+ *
+ * Copyright 1999-2004 Michael Reinelt <reinelt@eunet.at>
+ * Copyright 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
+ *
+ * based on the old XWindow.c which is
+ * Copyright 2000 Herbert Rosmanith <herp@wildsau.idv.uni-linz.ac.at>
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: drv_X11.c,v $
+ * Revision 1.1 2004/02/24 05:55:04 reinelt
+ *
+ * X11 driver ported
+ *
+ */
+
+/*
+ *
+ * exported fuctions:
+ *
+ * struct DRIVER drv_X11
+ *
+ */
+
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include "debug.h"
+#include "cfg.h"
+#include "timer.h"
+#include "udelay.h"
+#include "plugin.h"
+#include "widget.h"
+#include "widget_text.h"
+#include "widget_icon.h"
+#include "widget_bar.h"
+#include "drv.h"
+#include "drv_generic_graphic.h"
+
+#ifdef WITH_DMALLOC
+#include <dmalloc.h>
+#endif
+
+static char Name[]="X11";
+
+static char *fg_col,*bg_col,*hg_col;
+
+static int pixel = -1; // pointsize in pixel
+static int pgap = 0; // gap between points
+static int rgap = 0; // row gap between lines
+static int cgap = 0; // column gap between characters
+static int border = 0; // window border
+
+static int dimx, dimy; // total window dimension in pixel
+
+static unsigned char *drv_X11_FB=NULL;
+
+static Display *dp;
+static int sc, dd;
+static Window w, rw;
+static Visual *vi;
+static GC fg_gc, bg_gc, hg_gc;
+static Colormap cm;
+static XColor fg_xc, bg_xc, hg_xc;
+static Pixmap pm;
+
+
+#if 0
+static LCD Lcd;
+
+static unsigned char *LCDpixmap2;
+static int DROWS=-1,DCOLS=-1; /*DROWS+DCOLS without background*/
+static int XRES=-1,YRES=-1; /*XRES+YRES (same as self->...)*/
+static int icons; /* number of user-defined icons */
+static int async_update(); /*PROTO*/
+static pid_t async_updater_pid=1;
+static int semid=-1;
+static int shmid=-1;
+static int ppid; /*parent pid*/
+
+#endif
+
+// ****************************************
+// *** hardware dependant functions ***
+// ****************************************
+
+static void drv_X11_blit(int row, int col, int height, int width)
+{
+ int r, c;
+ int dirty = 0;
+
+ for (r=row; r<row+height && r<DROWS; r++) {
+ int y = border + (r/YRES)*rgap + r*(pixel+pgap);
+ for (c=col; c<col+width && c<DCOLS; c++) {
+ int x = border + (c/XRES)*cgap + c*(pixel+pgap);
+ unsigned char p = drv_generic_graphic_FB[r*LCOLS+c];
+ if (drv_X11_FB[r*DCOLS+c] != p) {
+ XFillRectangle( dp, w, p? fg_gc:hg_gc, x, y, pixel, pixel);
+ drv_X11_FB[r*DCOLS+c] = p;
+ dirty=1;
+ }
+ }
+ }
+ if (dirty) {
+ XSync(dp, False);
+ }
+}
+
+
+static void drv_X11_expose(int x, int y, int width, int height)
+{
+ /*
+ * theory of operation:
+ * instead of the old, fully-featured but complicated update
+ * region calculation, we do an update of the whole display,
+ * but check before every pixel if the pixel region is inside
+ * the update region.
+ */
+
+ int r, c;
+ int x0, y0;
+ int x1, y1;
+
+ x0 = x-pixel;
+ x1 = x+pixel+width;
+ y0 = y-pixel;
+ y1 = y+pixel+height;
+
+ for (r=0; r<DROWS; r++) {
+ int yc = border + (r/YRES)*rgap + r*(pixel+pgap);
+ if (yc<y0 || yc>y1) continue;
+ for (c=0; c<DCOLS; c++) {
+ int xc = border + (c/XRES)*cgap + c*(pixel+pgap);
+ if (xc<x0 || xc>x1) continue;
+ XFillRectangle( dp, w, drv_generic_graphic_FB[r*LCOLS+c]? fg_gc:hg_gc, xc, yc, pixel, pixel);
+ }
+ }
+ XSync(dp, False);
+}
+
+
+static void drv_X11_timer (void *notused)
+{
+ XEvent ev;
+
+ if (XCheckWindowEvent(dp, w, ExposureMask, &ev)==0) return;
+ if (ev.type==Expose) {
+ drv_X11_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height);
+ }
+}
+
+
+static int drv_X11_start (char *section)
+{
+ char *s;
+ XSetWindowAttributes wa;
+ XSizeHints sh;
+ XColor dummy;
+ XEvent ev;
+
+
+ // read display size from config
+ if (sscanf(s=cfg_get(section, "Size", "120x32"), "%dx%d", &DCOLS, &DROWS)!=2 || DCOLS<1 || DROWS<1) {
+ error ("%s: bad Size '%s' from %s", Name, s, cfg_source());
+ return -1;
+ }
+
+ if (sscanf(s=cfg_get(section, "font", "5x8"), "%dx%d", &XRES, &YRES)!=2 || XRES<1|| YRES<1) {
+ error ("%s: bad font '%s' from %s", Name, s, cfg_source());
+ return -1;
+ }
+
+ if (sscanf(s=cfg_get(section, "pixel", "4+1"), "%d+%d", &pixel, &pgap)!=2 || pixel<1 || pgap<0) {
+ error ("%s: bad pixel '%s' from %s", Name, s, cfg_source());
+ return -1;
+ }
+
+ if (sscanf(s=cfg_get(section, "gap", "-1x-1"), "%dx%d", &cgap, &rgap)!=2 || cgap<-1 || rgap<-1) {
+ error ("%s: bad gap '%s' from %s", Name, s, cfg_source());
+ return -1;
+ }
+ if (rgap<0) rgap=pixel+pgap;
+ if (cgap<0) cgap=pixel+pgap;
+
+ if (cfg_number(section, "border", 0, 0, 1000000, &border)<0) return -1;
+
+ fg_col=cfg_get(section, "foreground", "#000000");
+ bg_col=cfg_get(section, "background", "#80d000");
+ hg_col=cfg_get(section, "halfground", "#70c000");
+ if (*fg_col=='\\') fg_col++;
+ if (*bg_col=='\\') bg_col++;
+ if (*hg_col=='\\') hg_col++;
+
+
+ drv_X11_FB = malloc(DCOLS*DROWS);
+ if (drv_X11_FB==NULL) {
+ error ("%s: framebuffer could not be allocated: malloc() failed", Name);
+ return -1;
+ }
+
+ // init with 255 so all 'halfground' pixels will be drawn
+ memset(drv_X11_FB, 255, DCOLS*DROWS*sizeof(*drv_X11_FB));
+
+ if ((dp=XOpenDisplay(NULL))==NULL) {
+ error ("%s: can't open display", Name);
+ return -1;
+ }
+
+ sc = DefaultScreen(dp);
+ fg_gc = DefaultGC(dp, sc);
+ vi = DefaultVisual(dp, sc);
+ dd = DefaultDepth(dp, sc);
+ rw = DefaultRootWindow(dp);
+ cm = DefaultColormap(dp, sc);
+
+ if (XAllocNamedColor(dp, cm, fg_col, &fg_xc, &dummy) == False) {
+ error ("%s: can't alloc foreground color '%s'", Name, fg_col);
+ return -1;
+ }
+
+ if (XAllocNamedColor(dp, cm, bg_col, &bg_xc, &dummy)==False) {
+ error ("%s: can't alloc background color '%s'", Name, bg_col);
+ return -1;
+ }
+
+ if (XAllocNamedColor(dp, cm, hg_col, &hg_xc, &dummy)==False) {
+ error ("%s: can't alloc halfground color '%s'", Name, hg_col);
+ return -1;
+ }
+
+ dimx = DCOLS*pixel + (DCOLS-1)*pgap + (DCOLS/XRES-1)*cgap;
+ dimy = DROWS*pixel + (DROWS-1)*pgap + (DROWS/YRES-1)*rgap;
+
+ wa.event_mask=ExposureMask;
+
+ w = XCreateWindow(dp, rw, 0, 0, dimx+2*border, dimy+2*border, 0, 0, InputOutput, vi, CWEventMask, &wa);
+
+ pm = XCreatePixmap(dp, w, dimx, dimy, dd);
+
+ sh.min_width = sh.max_width = dimx+2*border;
+ sh.min_height = sh.max_height = dimy+2*border;
+ sh.flags = PPosition|PSize|PMinSize|PMaxSize;
+
+ XSetWMProperties(dp, w, NULL, NULL, NULL, 0, &sh, NULL, NULL);
+
+
+ XSetForeground(dp, fg_gc, fg_xc.pixel);
+ XSetBackground(dp, fg_gc, bg_xc.pixel);
+
+ bg_gc = XCreateGC(dp, w, 0, NULL);
+ XSetForeground(dp, bg_gc, bg_xc.pixel);
+ XSetBackground(dp, bg_gc, fg_xc.pixel);
+
+ hg_gc = XCreateGC(dp, w, 0, NULL);
+ XSetForeground(dp, hg_gc, hg_xc.pixel);
+ XSetBackground(dp, hg_gc, fg_xc.pixel);
+
+ XFillRectangle(dp, pm, bg_gc, 0, 0, dimx+2*border, dimy+2*border);
+ XSetWindowBackground(dp, w, bg_xc.pixel);
+ XClearWindow(dp, w);
+
+ XStoreName(dp, w, "LCD4Linux");
+ XMapWindow(dp, w);
+
+ XFlush(dp);
+
+ while(1) {
+ XNextEvent(dp,&ev);
+ if (ev.type==Expose && ev.xexpose.count==0)
+ break;
+ }
+
+ // regularly process X events
+ // Fixme: make 20msec configurable
+ timer_add (drv_X11_timer, NULL, 20, 0);
+
+ return 0;
+}
+
+
+#if 0
+static int init_x(int rows,int cols,int XRES,int YRES)
+{
+ return 0;
+}
+
+
+int xlcdinit(LCD *Self)
+{
+ char *s;
+
+ if (sscanf(s=cfg_get(NULL, "size", "20x4"),"%dx%d",&DCOLS,&DROWS)!=2
+ || DROWS<1 || DCOLS<1) {
+ error ("X11: bad size '%s'",s);
+ return -1;
+ }
+ if (sscanf(s=cfg_get(NULL, "font", "5x8"),"%dx%d",&XRES,&YRES)!=2
+ || XRES<5 || YRES>10) {
+ error ("X11: bad font '%s'",s);
+ return -1;
+ }
+ if (sscanf(s=cfg_get(NULL, "pixel", "4+1"),"%d+%d",&pixel,&pgap)!=2
+ || pixel<1 || pgap<0) {
+ error ("X11: bad pixel '%s'",s);
+ return -1;
+ }
+ if (sscanf(s=cfg_get(NULL, "gap", "-1x-1"),"%dx%d",&cgap,&rgap)!=2
+ || cgap<-1 || rgap<-1) {
+ error ("X11: bad gap '%s'",s);
+ return -1;
+ }
+ if (rgap<0) rgap=pixel+pgap;
+ if (cgap<0) cgap=pixel+pgap;
+
+ if (cfg_number(NULL, "border", 0, 0, 1000000, &border)<0) return -1;
+
+ fg_col=cfg_get(NULL, "foreground", "#000000");
+ bg_col=cfg_get(NULL, "background", "#80d000");
+ hg_col=cfg_get(NULL, "halfground", "#70c000");
+ if (*fg_col=='\\') fg_col++;
+ if (*bg_col=='\\') bg_col++;
+ if (*hg_col=='\\') hg_col++;
+
+ if (pix_init(DROWS,DCOLS,XRES,YRES)==-1) return -1;
+
+ if (cfg_number(NULL, "Icons", 0, 0, 8, &icons) < 0) return -1;
+ if (icons>0) {
+ info ("allocating %d icons", icons);
+ icon_init(DROWS, DCOLS, XRES, YRES, 8, icons, pix_icon);
+ }
+
+ if (init_x(DROWS,DCOLS,XRES,YRES)==-1) return -1;
+ init_signals();
+ if (init_shm(DROWS*DCOLS*XRES*YRES,&LCDpixmap2)==-1) return -1;
+ memset(LCDpixmap2,0xff,DROWS*YRES*DCOLS*XRES);
+ if (init_thread(DROWS*DCOLS*XRES*YRES)==-1) return -1;
+ Self->DROWS=DROWS;
+ Self->DCOLS=DCOLS;
+ Self->XRES=XRES;
+ Self->YRES=YRES;
+ Self->icons=icons;
+ Lcd=*Self;
+
+ pix_clear();
+ return 0;
+}
+
+
+int xlcdflush() {
+ int dirty;
+ int row,col;
+
+ acquire_lock();
+ dirty=0;
+ for(row=0;row<DROWS*YRES;row++) {
+ int y=border+(row/YRES)*rgap+row*(pixel+pgap);
+ for(col=0;col<DCOLS*XRES;col++) {
+ int x=border+(col/XRES)*cgap+col*(pixel+pgap);
+ int p=row*DCOLS*XRES+col;
+ if (LCDpixmap[p]^LCDpixmap2[p]) {
+ XFillRectangle(dp,w,LCDpixmap[p]?fg_gc:hg_gc,x,y,pixel,pixel);
+ LCDpixmap2[p]=LCDpixmap[p];
+ dirty=1;
+ }
+ }
+ }
+ if (dirty) XSync(dp,False);
+ release_lock();
+ return 0;
+}
+
+
+/*
+ * this one should only be called from the updater-thread
+ * no user serviceable parts inside
+ */
+
+static void update(int x,int y,int width,int height)
+{
+ /*
+ * theory of operation:
+ * instead of the old, fully-featured but complicated update
+ * region calculation, we do an update of the whole display,
+ * but check before every pixel if the pixel region is inside
+ * the update region.
+ */
+
+ int x0, y0;
+ int x1, y1;
+ int row, col;
+ int dirty;
+
+ x0=x-pixel;
+ y0=y-pixel;
+ x1=x+pixel+width;
+ y1=y+pixel+height;
+
+ dirty=0;
+ for(row=0; row<DROWS; row++) {
+ int y = border + (row/YRES)*rgap + row*(pixel+pgap);
+ if (y<y0 || y>y1) continue;
+ for(col=0; col<DCOLS; col++) {
+ int x = border + (col/XRES)*cgap + col*(pixel+pgap);
+ int p;
+ if (x<x0 || x>x1) continue;
+ p=row*DCOLS*XRES+col;
+ XFillRectangle(dp,w,LCDpixmap2[p]?fg_gc:hg_gc,x,y,pixel,pixel);
+ dirty=1;
+ }
+ }
+ if (dirty) XSync(dp,False);
+}
+
+
+static int async_update()
+{
+ XSetWindowAttributes wa;
+ XEvent ev;
+
+ if ((dp=XOpenDisplay(NULL))==NULL)
+ return -1;
+ wa.event_mask=ExposureMask;
+ XChangeWindowAttributes(dp,w,CWEventMask,&wa);
+ for(;;) {
+ XWindowEvent(dp,w,ExposureMask,&ev);
+ if (ev.type==Expose) {
+ acquire_lock();
+ update(ev.xexpose.x,ev.xexpose.y,
+ ev.xexpose.width,ev.xexpose.height);
+ release_lock();
+ }
+ }
+}
+#endif
+
+
+// ****************************************
+// *** plugins ***
+// ****************************************
+
+// none at the moment...
+
+
+// ****************************************
+// *** widget callbacks ***
+// ****************************************
+
+
+// using drv_generic_graphic_draw(W)
+// using drv_generic_graphic_icon_draw(W)
+// using drv_generic_graphic_bar_draw(W)
+
+
+// ****************************************
+// *** exported functions ***
+// ****************************************
+
+
+// list models
+int drv_X11_list (void)
+{
+ printf ("any");
+ return 0;
+}
+
+
+// initialize driver & display
+int drv_X11_init (char *section)
+{
+ WIDGET_CLASS wc;
+ int ret;
+
+ // real worker functions
+ drv_generic_graphic_real_blit = drv_X11_blit;
+
+ // start display
+ if ((ret=drv_X11_start (section))!=0)
+ return ret;
+
+ // initialize generic graphic driver
+ if ((ret=drv_generic_graphic_init(section, Name))!=0)
+ return ret;
+
+ // initially expose window
+ drv_X11_expose (0, 0, dimx+2*border, dimy+2*border);
+
+ // register text widget
+ wc=Widget_Text;
+ wc.draw=drv_generic_graphic_draw;
+ widget_register(&wc);
+
+ // register icon widget
+ wc=Widget_Icon;
+ wc.draw=drv_generic_graphic_icon_draw;
+ widget_register(&wc);
+
+ // register bar widget
+ wc=Widget_Bar;
+ wc.draw=drv_generic_graphic_bar_draw;
+ widget_register(&wc);
+
+ // register plugins
+ // none at the moment...
+
+
+ return 0;
+}
+
+
+// close driver & display
+int drv_X11_quit (void) {
+
+ info("%s: shutting down.", Name);
+ drv_generic_graphic_quit();
+
+ if (drv_X11_FB) {
+ free (drv_X11_FB);
+ drv_X11_FB=NULL;
+ }
+
+ return (0);
+}
+
+
+DRIVER drv_X11 = {
+ name: Name,
+ list: drv_X11_list,
+ init: drv_X11_init,
+ quit: drv_X11_quit,
+};
+
+
diff --git a/drv_generic_graphic.c b/drv_generic_graphic.c
index 1b01cf4..6d9c7b7 100644
--- a/drv_generic_graphic.c
+++ b/drv_generic_graphic.c
@@ -23,6 +23,10 @@
*
*
* $Log: drv_generic_graphic.c,v $
+ * Revision 1.4 2004/02/24 05:55:04 reinelt
+ *
+ * X11 driver ported
+ *
* Revision 1.3 2004/02/22 17:35:41 reinelt
* some fixes for generic graphic driver and T6963
* removed ^M from plugin_imon (Nico, are you editing under Windows?)
@@ -272,24 +276,9 @@ int drv_generic_graphic_bar_draw (WIDGET *W)
int drv_generic_graphic_init (char *section, char *driver)
{
- char *font;
-
Section=section;
Driver=driver;
- font=cfg_get(section, "Font", "6x8");
- if (font==NULL || *font=='\0') {
- error ("%s: no '%s.Font' entry from %s", Driver, section, cfg_source());
- return -1;
- }
-
- XRES = -1;
- YRES = -1;
- if (sscanf(font, "%dx%d", &XRES, &YRES)!=2 || XRES<1 || YRES<1) {
- error ("%s: bad Font '%s' from %s", Driver, font, cfg_source());
- return -1;
- }
-
// init layout framebuffer
LROWS = 0;
LCOLS = 0;
diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample
index 4ca8bd6..85981d7 100644
--- a/lcd4linux.conf.sample
+++ b/lcd4linux.conf.sample
@@ -82,6 +82,18 @@ Display T6963-240x64 {
}
+Display XWindow {
+ Driver 'X11'
+ Size '120x32'
+ Font '6x8'
+ Pixel '4+1'
+ Gap '-1x-1'
+ Border 20
+ Foreground '#000000'
+ Background '#80d000'
+ Halfground '#70c000'
+}
+
Widget OS {
class 'Text'
expression '*** '.uname('sysname').' '.uname('release').' ***'
@@ -334,14 +346,14 @@ Layout Default {
Col1 'Load'
Col11 'LoadBar'
}
- Row5 {
- Col1 'Disk'
- Col11 'DiskBar'
- }
- Row6 {
- Col1 'Eth0'
- Col11 'Eth0Bar'
- }
+# Row5 {
+# Col1 'Disk'
+# Col11 'DiskBar'
+# }
+# Row6 {
+# Col1 'Eth0'
+# Col11 'Eth0Bar'
+# }
}
Layout L24x8 {
@@ -395,7 +407,8 @@ Layout Test {
#Display 'CF632'
#Display 'CF633'
#Display 'USBLCD'
-Display 'T6963-240x64'
+#Display 'T6963-240x64'
+Display 'XWindow'
Layout 'Default'
#Layout 'L16x2'