From 1b780dd648c21e2e2d81c1102bfc5fddf03fb5d9 Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Tue, 24 Feb 2004 05:55:04 +0000 Subject: [lcd4linux @ 2004-02-24 05:54:57 by reinelt] X11 driver ported --- XWindow.c | 628 -------------------------------------------------------------- 1 file changed, 628 deletions(-) delete mode 100644 XWindow.c (limited to 'XWindow.c') diff --git a/XWindow.c b/XWindow.c deleted file mode 100644 index c7ead72..0000000 --- a/XWindow.c +++ /dev/null @@ -1,628 +0,0 @@ -/* $Id: XWindow.c,v 1.40 2004/01/30 20:57:55 reinelt Exp $ - * - * X11 Driver for LCD4Linux - * - * Copyright 2000 Herbert Rosmanith - * - * 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: XWindow.c,v $ - * Revision 1.40 2004/01/30 20:57:55 reinelt - * HD44780 patch from Martin Hejl - * dmalloc integrated - * - * Revision 1.39 2004/01/29 04:40:02 reinelt - * every .c file includes "config.h" now - * - * Revision 1.38 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.37 2004/01/06 22:33:14 reinelt - * Copyright statements cleaned up - * - * Revision 1.36 2003/10/22 04:32:25 reinelt - * fixed icon bug found by Rob van Nieuwkerk - * - * Revision 1.35 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.34 2003/09/10 14:01:53 reinelt - * icons nearly finished\! - * - * Revision 1.33 2003/09/09 06:54:43 reinelt - * new function 'cfg_number()' - * - * Revision 1.32 2003/07/24 04:48:09 reinelt - * 'soft clear' needed for virtual rows - * - * Revision 1.31 2003/04/12 16:23:10 reinelt - * small glitch in XWindow.c (thanks to Moe Wibble) - * - * Revision 1.30 2003/02/22 07:53:10 reinelt - * cfg_get(key,defval) - * - * Revision 1.29 2003/02/18 06:13:44 reinelt - * X11 driver fixes and cleanup - * - * Revision 1.28 2003/02/17 06:06:12 reinelt - * small bug in X11 driver: omit pixel gap between cahracters - * - * Revision 1.27 2002/08/19 04:41:20 reinelt - * introduced bar.c, moved bar stuff from display.h to bar.h - * - * Revision 1.26 2001/08/05 17:13:29 reinelt - * - * cleaned up inlude of sys/time.h and time.h - * - * Revision 1.25 2001/03/16 16:40:17 ltoetsch - * implemented time bar - * - * Revision 1.24 2001/03/01 11:08:16 reinelt - * - * reworked configure to allow selection of drivers - * - * Revision 1.23 2001/02/26 00:33:37 herp - * fixed X11 signal handler - * - * Revision 1.22 2001/02/13 09:00:13 reinelt - * - * prepared framework for GPO's (general purpose outputs) - * - * Revision 1.21 2000/08/10 18:42:20 reinelt - * - * fixed some bugs with the new syslog code - * - * Revision 1.20 2000/08/10 09:44:09 reinelt - * - * new debugging scheme: error(), info(), debug() - * uses syslog if in daemon mode - * - * Revision 1.19 2000/08/09 09:50:29 reinelt - * - * opened 0.98 development - * removed driver-specific signal-handlers - * added 'quit'-function to driver structure - * added global signal-handler - * - * Revision 1.18 2000/05/02 23:07:48 herp - * Crystalfontz initial coding - * - * Revision 1.17 2000/04/05 05:58:36 reinelt - * - * fixed bug in XWindow.c: union semun isn't defined with glibc-2.1 - * - * Revision 1.16 2000/04/03 23:53:23 herp - * fixed a bug that caused pixel-errors ("fliegendreck") under high load - * - * Revision 1.15 2000/04/03 04:01:31 reinelt - * - * if 'gap' is specified as -1, a gap of (pixelsize+pixelgap) is selected automatically - * - * Revision 1.14 2000/04/02 22:07:10 herp - * fixded a bug that occasionally caused Xlib errors - * - * Revision 1.13 2000/04/01 22:40:42 herp - * geometric correction (too many pixelgaps) - * lcd4linux main should return int, not void - * - * Revision 1.12 2000/04/01 19:33:45 herp - * - * colors in format \#RRGGBB in config-file now understood - * - * Revision 1.11 2000/04/01 16:22:38 reinelt - * - * bug that caused a segfault in processor.c fixed (thanks to herp) - * - * Revision 1.10 2000/03/31 01:42:11 herp - * - * semaphore bug fixed - * - * Revision 1.9 2000/03/30 16:46:57 reinelt - * - * configure now handles '--with-x' and '--without-x' correct - * - * Revision 1.8 2000/03/28 08:48:33 reinelt - * - * README.X11 added - * - * Revision 1.7 2000/03/28 07:22:15 reinelt - * - * version 0.95 released - * X11 driver up and running - * minor bugs fixed - * - */ - -/* - * - * exported fuctions: - * - * struct LCD XWindow[] - * - */ - - -/* - * Mon Feb 26 02:07:52 MET 2001 fixed sighandler - * Tue Apr 4 02:37:38 MET 2000 fixed a bug that caused pixelerrors under h/load - * Sun Apr 2 22:07:10 MET 2000 fixed a bug that occasionally caused Xlib error - * Sun Apr 2 01:32:48 MET 2000 geometric correction (too many pixelgaps) - * Sat Apr 1 22:18:04 MET 2000 colors in format \#RRGGBB in config-file - * Fri Mar 31 01:42:11 MET 2000 semaphore bug fixed - * Sun Mar 26 15:28:23 MET 2000 various rewrites - * Sat Mar 25 23:58:19 MET 2000 use generic pixmap driver - * Thu Mar 23 01:05:07 MET 2000 multithreading, synchronization - * Tue Mar 21 22:22:03 MET 2000 initial coding - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "debug.h" -#include "cfg.h" -#include "display.h" -#include "bar.h" -#include "icon.h" -#include "pixmap.h" - -#ifdef WITH_DMALLOC -#include -#endif - - -/* glibc 2.1 requires defining semun ourselves */ -#ifdef _SEM_SEMUN_UNDEFINED -union semun { - int val; - struct semid_ds *buf; - unsigned short int *array; - struct seminfo *__buf; -}; -#endif - - -static LCD Lcd; -static Display *dp; -static int sc; -static Window w,rw; -static Visual *vi; -static int dd; -static Colormap cm; -static GC gc,gcb,gch; -static XColor co[3]; -static Pixmap pmback; - -static unsigned char *LCDpixmap2; -static char *rgbfg,*rgbbg,*rgbhg; -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 rows=-1,cols=-1; /*rows+cols without background*/ -static int xres=-1,yres=-1; /*xres+yres (same as self->...)*/ -static int icons; /* number of user-defined icons */ -static int dimx,dimy; /*total window dimension in pixel*/ -static int boxw,boxh; /*box width, box height*/ -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*/ - - -static void acquire_lock() -{ - struct sembuf sembuf; - sembuf.sem_num=0; - sembuf.sem_op=-1; - sembuf.sem_flg=0; - semop(semid,&sembuf,1); /* get mutex */ -} - - -static void release_lock() -{ - struct sembuf sembuf; - sembuf.sem_num=0; - sembuf.sem_op=1; - sembuf.sem_flg=0; - semop(semid,&sembuf,1); /* free mutex */ -} - - -static void semcleanup() -{ - union semun arg; - if (semid>-1) semctl(semid,0,IPC_RMID,arg); -} - - -static void shmcleanup() -{ - if (shmid>-1) shmctl(shmid,IPC_RMID,NULL); -} - - -static void quit_updater() -{ - int i; - if (async_updater_pid>1) { - i=async_updater_pid; - async_updater_pid=1; - kill(i,9); - waitpid(i,&i,0); - } -} - - -static void sig_updater(int sig) -{ - kill(ppid,sig); - exit(0); -} - - -static void init_signals() -{ - unsigned int ignsig=(1<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; - - rgbfg=cfg_get(NULL, "foreground", "#000000"); - rgbbg=cfg_get(NULL, "background", "#80d000"); - rgbhg=cfg_get(NULL, "halfground", "#70c000"); - if (*rgbfg=='\\') rgbfg++; - if (*rgbbg=='\\') rgbbg++; - if (*rgbhg=='\\') rgbhg++; - - if (pix_init(rows,cols,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(rows, cols, xres, yres, 8, icons, pix_icon); - } - - if (init_x(rows,cols,xres,yres)==-1) return -1; - init_signals(); - if (init_shm(rows*cols*xres*yres,&LCDpixmap2)==-1) return -1; - memset(LCDpixmap2,0xff,rows*yres*cols*xres); - if (init_thread(rows*cols*xres*yres)==-1) return -1; - Self->rows=rows; - Self->cols=cols; - Self->xres=xres; - Self->yres=yres; - Self->icons=icons; - Lcd=*Self; - - pix_clear(); - return 0; -} - - -int xlcdclear(int full) -{ - icon_clear(); - pix_clear(); - return 0; -} - - -int xlcdput(int row,int col, char *text) -{ - return pix_put(row,col,text); -} - - -int xlcdbar(int type, int row, int col, int max, int len1, int len2) -{ - return pix_bar(type,row,col,max,len1,len2); -} - - -int xlcdicon (int num, int seq, int row, int col) -{ - return icon_draw (num, seq, row, col); -} - - -int xlcdflush() { - int dirty; - int row,col; - - acquire_lock(); - dirty=0; - for(row=0;rowy1) continue; - for(col=0;colx1) continue; - p=row*cols*xres+col; - XFillRectangle(dp,w,LCDpixmap2[p]?gc:gch,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(); - } - } -} - - -LCD XWindow[] = { - { name: "X11", - rows: 0, - cols: 0, - xres: 0, - yres: 0, - bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 | BAR_V2 | BAR_T, - icons: 0, - gpos: 0, - init: xlcdinit, - clear: xlcdclear, - put: xlcdput, - bar: xlcdbar, - icon: xlcdicon, - gpo: NULL, - flush: xlcdflush, - quit: xlcdquit - }, - { NULL } -}; -- cgit v1.2.3