From: martii Date: Sat, 17 Sep 2016 11:03:14 +0000 (+0200) Subject: - port most code from martiis shellexec for a smoother rendering X-Git-Url: https://git.webhop.me/?a=commitdiff_plain;h=b2828ab645146cce851034375bdee31827196b29;p=shellexec.git - port most code from martiis shellexec for a smoother rendering --- diff --git a/gfx.c b/gfx.c index 5a4b20f..5d881db 100644 --- a/gfx.c +++ b/gfx.c @@ -3,30 +3,29 @@ char circle[] = { - 0,0,0,0,0,1,1,0,0,0,0,0, - 0,0,0,1,1,1,1,1,1,0,0,0, - 0,0,1,1,1,1,1,1,1,1,0,0, - 0,1,1,1,1,1,1,1,1,1,1,0, - 0,1,1,1,1,1,1,1,1,1,1,0, - 1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1,1,1,1,0, - 0,1,1,1,1,1,1,1,1,1,1,0, - 0,0,1,1,1,1,1,1,1,1,0,0, - 0,0,0,1,1,1,1,1,1,0,0,0, - 0,0,0,0,0,1,1,0,0,0,0,0 + 0,2,2,2,2,2,2,2,2,2,2,0, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,2, + 0,2,2,2,2,2,2,2,2,2,2,0 }; //typedef struct { unsigned char width_lo; unsigned char width_hi; unsigned char height_lo; unsigned char height_hi; unsigned char transp; } IconHeader; - void RenderBox(int sx, int sy, int ex, int ey, int rad, int col) { int F,R=rad,ssx=startx+sx,ssy=starty+sy,dxx=ex-sx,dyy=ey-sy,rx,ry,wx,wy,count; - unsigned char *pos=(lbb+(ssx<<2)+fix_screeninfo.line_length*ssy); - unsigned char *pos0, *pos1, *pos2, *pos3, *i; - unsigned char pix[4]={bl[col],gn[col],rd[col],tr[col]}; + uint32_t *pos = lbb + ssx + stride * ssy; + uint32_t *pos0, *pos1, *pos2, *pos3, *i; + uint32_t pix = bgra[col]; if (dxx<0) { @@ -68,10 +67,10 @@ void RenderBox(int sx, int sy, int ex, int ey, int rad, int col) rx=R-ssx; ry=R-ssy; - pos0=pos+((dyy-ry)*fix_screeninfo.line_length); - pos1=pos+(ry*fix_screeninfo.line_length); - pos2=pos+(rx*fix_screeninfo.line_length); - pos3=pos+((dyy-rx)*fix_screeninfo.line_length); + pos0=pos+(dyy-ry)*stride; + pos1=pos+ry*stride; + pos2=pos+rx*stride; + pos3=pos+(dyy-rx)*stride; while (ssx <= ssy) { rx=R-ssx; @@ -79,18 +78,18 @@ void RenderBox(int sx, int sy, int ex, int ey, int rad, int col) wx=rx<<1; wy=ry<<1; - for(i=pos0+(rx<<2); i #include #include +#include +#include #include "shellexec.h" #include "io.h" @@ -25,7 +27,7 @@ static int rc; int InitRC(void) { - rc = open(RC_DEVICE, O_RDONLY); + rc = open(RC_DEVICE, O_RDONLY | O_CLOEXEC); if(rc == -1) { perror("shellexec "); @@ -77,34 +79,34 @@ int RCTranslate(int code) case KEY_OK: rccode = RC_OK; break; - case KEY_0: rccode = RC_0; + case KEY_0: rccode = RC_0; break; - case KEY_1: rccode = RC_1; + case KEY_1: rccode = RC_1; break; - case KEY_2: rccode = RC_2; + case KEY_2: rccode = RC_2; break; - case KEY_3: rccode = RC_3; + case KEY_3: rccode = RC_3; break; - case KEY_4: rccode = RC_4; + case KEY_4: rccode = RC_4; break; - case KEY_5: rccode = RC_5; + case KEY_5: rccode = RC_5; break; - case KEY_6: rccode = RC_6; + case KEY_6: rccode = RC_6; break; - case KEY_7: rccode = RC_7; + case KEY_7: rccode = RC_7; break; - case KEY_8: rccode = RC_8; + case KEY_8: rccode = RC_8; break; - case KEY_9: rccode = RC_9; + case KEY_9: rccode = RC_9; break; case KEY_RED: rccode = RC_RED; @@ -140,25 +142,68 @@ int RCTranslate(int code) case KEY_POWER: rccode = RC_STANDBY; break; - default: rccode = -1; + default: rccode = -1; } return rccode; } -int GetRCCode(void) +void ClearRC(void) { - int rv; + struct pollfd pfd; + pfd.fd = rc; + pfd.events = POLLIN; + pfd.revents = 0; + + do + poll(&pfd, 1, 300); + while(read(rc, &ev, sizeof(ev)) == sizeof(ev)); +} - if(!RCKeyPressed() || (get_instance()>instance)) - { - return -1; +int GetRCCode(int timeout_in_ms) +{ + int rv = -1; + + if (timeout_in_ms) { + struct pollfd pfd; + struct timeval tv; + uint64_t ms_now, ms_final; + + pfd.fd = rc; + pfd.events = POLLIN; + pfd.revents = 0; + + gettimeofday( &tv, NULL ); + ms_now = tv.tv_usec/1000 + tv.tv_sec * 1000; + if (timeout_in_ms > 0) + ms_final = ms_now + timeout_in_ms; + else + ms_final = UINT64_MAX; + while (ms_final > ms_now) { + switch(poll(&pfd, 1, timeout_in_ms)) { + case -1: + perror("GetRCCode: poll() failed"); + case 0: + return -1; + default: + ; + } + if(RCKeyPressed()) { + rv = rccode; + while(RCKeyPressed()); + return RCTranslate(rv); + } + + gettimeofday( &tv, NULL ); + ms_now = tv.tv_usec/1000 + tv.tv_sec * 1000; + if (timeout_in_ms > 0) + timeout_in_ms = (int)(ms_final - ms_now); + } + } else if(RCKeyPressed()) { + rv = rccode; + while(RCKeyPressed()); + return RCTranslate(rv); } - rv=rccode; - while(RCKeyPressed()); - - return RCTranslate(rv); + return rv; } - - diff --git a/io.h b/io.h index 1619ae7..27782bd 100644 --- a/io.h +++ b/io.h @@ -1,12 +1,12 @@ #ifndef __IO_H__ - #define __IO_H__ -#define RC_DEVICE "/dev/input/nevis_ir" +#define RC_DEVICE "/dev/input/nevis_ir" int InitRC(void); int CloseRC(void); int RCKeyPressed(void); -int GetRCCode(void); +int GetRCCode(int); +void ClearRC(void); #endif diff --git a/shellexec.c b/shellexec.c index 35a5c9a..99e2506 100644 --- a/shellexec.c +++ b/shellexec.c @@ -11,24 +11,25 @@ static char CFG_FILE[128]="/var/tuxbox/config/shellexec.conf"; //#define FONT "/usr/share/fonts/md_khmurabi_10.ttf" #define FONT2 "/share/fonts/pakenham.ttf" // if font is not in usual place, we look here: -unsigned char FONT[128]="/share/fonts/neutrino.ttf"; - -// CMCST, CMCS, CMCT, CMC, CMCIT, CMCI, CMHT, CMH -// WHITE, BLUE0, TRANSP, CMS, ORANGE, GREEN, YELLOW, RED - -unsigned char bl[] = { 0x00, 0x00, 0xFF, 0x80, 0xFF, 0x80, 0x00, 0x80, - 0xFF, 0x80, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; -unsigned char gn[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xC0, 0x00, - 0xFF, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, - 0x00, 0x00, 0x00, 0x00}; -unsigned char rd[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, - 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x80, 0x80, - 0x00, 0x00, 0x00, 0x00}; -unsigned char tr[] = { 0xFF, 0xFF, 0xFF, 0xA0, 0xFF, 0x80, 0xFF, 0xFF, - 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x00, 0x00, 0x00, 0x00}; - +char FONT[128]="/share/fonts/neutrino.ttf"; + +// CMCST, CMCS, CMCT, CMC, CMCIT, CMCI, CMHT, CMH +// WHITE, BLUE0, TRANSP, CMS, ORANGE, GREEN, YELLOW, RED + +unsigned char bl[] = { 0x00, 0x00, 0xFF, 0x80, 0xFF, 0x80, 0x00, 0x80, + 0xFF, 0x80, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; +unsigned char gn[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xC0, 0x00, + 0xFF, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00}; +unsigned char rd[] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x80, 0x80, + 0x00, 0x00, 0x00, 0x00}; +unsigned char tr[] = { 0xFF, 0xFF, 0xFF, 0xA0, 0xFF, 0x80, 0xFF, 0xFF, + 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00}; + +uint32_t bgra[20]; void TrimString(char *strg); // OSD stuff @@ -37,7 +38,7 @@ static char spres[][5]={"","_crt","_lcd"}; #define LIST_STEP 10 #define BUFSIZE 4095 -#define SH_VERSION 1.20 +#define SH_VERSION 1.21 typedef struct {int fnum; FILE *fh[16];} FSTRUCT, *PFSTRUCT; static int direct[32]; @@ -46,7 +47,7 @@ static int STYP=1; typedef struct {char *entry; char *message; int headerpos; int type; int underline; int stay; int showalways;} LISTENTRY; typedef LISTENTRY *PLISTENTRY; -typedef PLISTENTRY *LIST; +typedef PLISTENTRY *LIST; typedef struct {int num_headers; int act_header; int max_header; int *headerwait; int *headermed; char **headertxt; char **icon; int *headerlevels; int *lastheaderentrys; int num_entrys; int act_entry; int max_entrys; int num_active; char *menact; char *menactdep; LIST list;} MENU; enum {TYP_MENU, TYP_MENUDON, TYP_MENUDOFF, TYP_MENUFON, TYP_MENUFOFF, TYP_MENUSON, TYP_MENUSOFF, TYP_EXECUTE, TYP_COMMENT, TYP_DEPENDON, TYP_DEPENDOFF, TYP_FILCONTON, TYP_FILCONTOFF, TYP_SHELLRESON, TYP_SHELLRESOFF, TYP_ENDMENU, TYP_INACTIVE}; static char TYPESTR[TYP_ENDMENU+1][13]={"MENU=","MENUDON=","MENUDOFF=","MENUFON=","MENUFOFF=","MENUSON=","MENUSOFF=","ACTION=","COMMENT=","DEPENDON=","DEPENDOFF=","FILCONTON=","FILCONTOFF=","SHELLRESON=","SHELLRESOFF=","ENDMENU"}; @@ -62,16 +63,17 @@ int Get_Menu(int showwait); static void ShowInfo(MENU *m, int knew); -unsigned char *lfb = 0, *lbb = 0; -unsigned char title[256]; -unsigned char VFD[256]=""; +uint32_t *lfb = NULL, *lbb = NULL; +char title[256]; +char VFD[256]=""; char url[256]="time.fu-berlin.de"; char *line_buffer=NULL; -unsigned char *trstr; -int mloop=1, paging=1, mtmo=120, radius=10; +char *trstr; +int paging=1, mtmo=120, radius=10; int ixw=600, iyw=680, xoffs=13, vfd=0; char INST_FILE[]="/tmp/rc.locked"; int instance=0; +int stride; int get_instance(void) { @@ -133,7 +135,7 @@ char *resptr=xstr; } return NULL; } - + void TrimString(char *strg) { char *pt1=strg, *pt2=strg; @@ -196,9 +198,9 @@ char *pt1; TrimString(buffer); } } - TranslateString(buffer); + TranslateString(buffer, size); } - return rv; + return rv; } int ExistFile(char *fname) @@ -300,6 +302,21 @@ int i, res=0; } return res; } +static int mysystem(const char *command) { + if (!command) + return -1; + char *a = (char *) alloca(strlen(command) + 1); + strcpy(a, command); + char *s = a; + while (*s && *s != ' ' && *s != '\t') + s++; + *s = 0; + if (access(a, X_OK)) + chmod(a, 0755); + + return system(command); +} +#define system mysystem void OnMenuClose(char *cmd, char *dep) { @@ -307,7 +324,7 @@ int res=1; if(dep) { - res=!system(dep); + res=!system(dep); res|=ExistFile(dep); } if(cmd && res) @@ -386,7 +403,7 @@ FSTRUCT fstr; ++pt1; } pt2=pt1; - while(*pt2 && ((*pt2=='*') || (*pt2=='&') || (*pt2=='§') || (*pt2=='+') || (*pt2=='-') || (*pt2=='!') || (*pt2=='_'))) + while(*pt2 && ((*pt2=='*') || (*pt2=='&') || (*pt2==0302) || (*pt2==0247) || (*pt2=='+') || (*pt2=='-') || (*pt2=='!') || (*pt2=='_'))) { if(*pt2=='_') { @@ -399,7 +416,7 @@ FSTRUCT fstr; *(pt2-1)=0; pt2=pt1; } - + if(menu.icon[menu.num_headers]) { free(menu.icon[menu.num_headers]); @@ -429,7 +446,7 @@ FSTRUCT fstr; } else { - if(strstr(line_buffer,"FONT=")==line_buffer) + if(strstr(line_buffer,"FONT=")==line_buffer) { strcpy(FONT,strchr(line_buffer,'=')+1); } @@ -443,10 +460,12 @@ FSTRUCT fstr; { sscanf(strchr(line_buffer,'=')+1,"%d",&FSIZE_MED); } +#if 0 if(strstr(line_buffer,"MENUTIMEOUT=")==line_buffer) { sscanf(strchr(line_buffer,'=')+1,"%d",&mtmo); } +#endif if(strstr(line_buffer,"PAGING=")==line_buffer) { sscanf(strchr(line_buffer,'=')+1,"%d",&paging); @@ -473,7 +492,7 @@ FSTRUCT fstr; } } } -//printf("Check_Config: Level: %d -> %s\n",level,line_buffer); + //printf("Check_Config: Level: %d -> %s\n",level,line_buffer); } rv=0; fclose(fstr.fh[fstr.fnum]); @@ -517,9 +536,9 @@ PLISTENTRY entr; switch(mode) { case 0: return 0; - + case 1: - + if((m->list=calloc(LIST_STEP,sizeof(PLISTENTRY)))==NULL) { printf(NOMEM); @@ -538,7 +557,7 @@ PLISTENTRY entr; } m->max_entrys=LIST_STEP; break; - + case -1: if(m->num_headers && m->headertxt) { @@ -583,58 +602,58 @@ time_t tm1,tm2; } time(&tm1); do{ -// usleep(100000L); + //usleep(100000L); first=(paging)?0:(MAX_FUNCS*(int)(m->act_entry/MAX_FUNCS)); last=(paging)?(m->num_entrys-1):(MAX_FUNCS*(int)(m->act_entry/MAX_FUNCS)+MAX_FUNCS-1); if(last>=m->num_entrys) { last=m->num_entrys-1; } - + active=0; for(i=first; i<=last && !active; i++) { active |= ((m->list[i]->type != TYP_COMMENT) && (m->list[i]->type != TYP_INACTIVE)); } - + rccode=-1; if(knew) { ShowInfo(m, knew); } knew=1; - switch(rccode = GetRCCode()) + switch(rccode = GetRCCode(mtmo * 1000)) { case RC_RED: if(active && direct[0]>=0) - { + { m->act_entry=direct[0]; rv=1; mloop=0; } break; - case RC_GREEN: + case RC_GREEN: if(active && direct[1]>=0) - { + { m->act_entry=direct[1]; rv=1; mloop=0; } break; - case RC_YELLOW: + case RC_YELLOW: if(active && direct[2]>=0) - { + { m->act_entry=direct[2]; rv=1; mloop=0; } break; - case RC_BLUE: + case RC_BLUE: if(active && direct[3]>=0) - { + { m->act_entry=direct[3]; rv=1; mloop=0; @@ -643,7 +662,7 @@ time_t tm1,tm2; case RC_1: if(active && direct[4]>=0) - { + { m->act_entry=direct[4]; rv=1; mloop=0; @@ -652,7 +671,7 @@ time_t tm1,tm2; case RC_2: if(active && direct[5]>=0) - { + { m->act_entry=direct[5]; rv=1; mloop=0; @@ -661,7 +680,7 @@ time_t tm1,tm2; case RC_3: if(active && direct[6]>=0) - { + { m->act_entry=direct[6]; rv=1; mloop=0; @@ -670,7 +689,7 @@ time_t tm1,tm2; case RC_4: if(active && direct[7]>=0) - { + { m->act_entry=direct[7]; rv=1; mloop=0; @@ -679,7 +698,7 @@ time_t tm1,tm2; case RC_5: if(active && direct[8]>=0) - { + { m->act_entry=direct[8]; rv=1; mloop=0; @@ -688,7 +707,7 @@ time_t tm1,tm2; case RC_6: if(active && direct[9]>=0) - { + { m->act_entry=direct[9]; rv=1; mloop=0; @@ -697,7 +716,7 @@ time_t tm1,tm2; case RC_7: if(active && direct[10]>=0) - { + { m->act_entry=direct[10]; rv=1; mloop=0; @@ -706,7 +725,7 @@ time_t tm1,tm2; case RC_8: if(active && direct[11]>=0) - { + { m->act_entry=direct[11]; rv=1; mloop=0; @@ -715,7 +734,7 @@ time_t tm1,tm2; case RC_9: if(active && direct[12]>=0) - { + { m->act_entry=direct[12]; rv=1; mloop=0; @@ -724,7 +743,7 @@ time_t tm1,tm2; case RC_0: if(active && direct[13]>=0) - { + { m->act_entry=direct[13]; rv=1; mloop=0; @@ -750,10 +769,10 @@ time_t tm1,tm2; } m->act_entry=i; } -// knew=1; + //knew=1; break; - case RC_DOWN: + case RC_DOWN: case RC_PLUS: if(m->num_active) { @@ -772,7 +791,7 @@ time_t tm1,tm2; } m->act_entry=i; } -// knew=1; + //knew=1; break; case RC_PAGEUP: @@ -811,7 +830,7 @@ time_t tm1,tm2; m->act_entry=i; break; - case RC_OK: + case RC_OK: if(m->num_active) { rv=1; @@ -821,41 +840,35 @@ time_t tm1,tm2; case -1: knew=0; +#if 0 if(mtmo == 0) - break; + break; +#endif time(&tm2); if((tm2-tm1)num_entrys>=m->max_entrys) { if((m->list=realloc(m->list,(m->max_entrys+LIST_STEP)*sizeof(PLISTENTRY)))==NULL) @@ -905,7 +918,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; } m->max_entrys+=LIST_STEP; } - + entr=m->list[m->num_entrys]; entr->underline=entr->stay=entr->showalways=0; @@ -917,7 +930,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; ptr1=strchr(wstr,'='); ptr1++; ptr2=ptr1; - while(*ptr2 && ((*ptr2=='*') || (*ptr2=='&') || (*ptr2=='§') || (*ptr2=='+') || (*ptr2=='-') || (*ptr2=='!') || (*ptr2=='_'))) + while(*ptr2 && ((*ptr2=='*') || (*ptr2=='&') || (*ptr2==0302) || (*ptr2==0247) || (*ptr2=='+') || (*ptr2=='-') || (*ptr2=='!') || (*ptr2=='_'))) { switch(*ptr2) { @@ -926,7 +939,9 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; case '+': entr->showalways=1; break; case '-': entr->showalways=2; break; case '&': entr->stay=1; break; - case '§': entr->stay=2; break; + case 0302: if (*(ptr2 + 1) != 0247) break; // UTF-8 value of paragraph symbol + ptr2++; + case 0247: entr->stay=2; break; } while(*(++ptr2)) { @@ -955,7 +970,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; } } break; - + case TYP_MENU: if((ptr2=strstr(ptr1,",ICON="))!=NULL) { @@ -979,7 +994,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; m->num_entrys++; found=1; break; - + case TYP_DEPENDON: case TYP_DEPENDOFF: case TYP_MENUDON: @@ -1022,7 +1037,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; pfound=ExistFile(ptr3); } if((((i==TYP_DEPENDON)||(i==TYP_MENUDON)||(i==TYP_FILCONTON)||(i==TYP_MENUFON)) && pfound) || (((i==TYP_DEPENDOFF)||(i==TYP_MENUDOFF)||(i==TYP_FILCONTOFF)||(i==TYP_MENUFOFF)) && !pfound)) - { + { entr->type=(ientry=strdup(ptr1); if(ptr4) @@ -1035,7 +1050,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; else { if(entr->showalways) - { + { entr->type=TYP_INACTIVE; entr->entry=strdup(ptr1); entr->headerpos=pos; @@ -1077,7 +1092,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; } pfound=system(ptr3); if((((i==TYP_SHELLRESON)||(i==TYP_MENUSON)) && !pfound) || (((i==TYP_SHELLRESOFF)||(i==TYP_MENUSOFF)) && pfound)) - { + { entr->type=(ientry=strdup(ptr1); if(ptr4) @@ -1090,7 +1105,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; else { if(entr->showalways) - { + { entr->type=TYP_INACTIVE; entr->entry=strdup(ptr1); entr->headerpos=pos; @@ -1100,7 +1115,7 @@ char *ptr1,*ptr2,*ptr3,*ptr4, *wstr; } } break; - } + } if(found && (i != TYP_COMMENT) && (i != TYP_INACTIVE)) { m->num_active++; @@ -1148,13 +1163,13 @@ FSTRUCT fstr; mlevel--; } } -//printf("Get_Menu: loop: %d, mlevel: %d, pos: %d -> %s\n",loop,mlevel,pos,line_buffer); + //printf("Get_Menu: loop: %d, mlevel: %d, pos: %d -> %s\n",loop,mlevel,pos,line_buffer); } if(loop) { return rv; } - + --pos; --mlevel; loop=1; @@ -1185,7 +1200,7 @@ FSTRUCT fstr; } menu.menact=strdup(pt1); } - + } mlevel--; } @@ -1272,24 +1287,24 @@ static void ShowInfo(MENU *m, int knew ) char dstr[BUFSIZE],*lcptr,*lcstr; int dy, my, moffs, mh, toffs, soffs=4, oldx=startx, oldy=starty, sbar=0, nosel; PLISTENTRY pl; - + moffs=iyw/(MAX_FUNCS+1); mh=iyw-moffs; dy=mh/(MAX_FUNCS+1); toffs=dy/2; my=moffs+dy+toffs; - + startx = sx + (((ex-sx) - ixw)/2); starty = sy + (((ey-sy) - iyw)/2); tind=index; - + //frame layout RenderBox(0, 0, ixw, iyw, radius, CMC); // titlebar RenderBox(0, 0, ixw, moffs+5, radius, CMH); - + for(loop=MAX_FUNCS*(index/MAX_FUNCS); loopnum_entrys && !sbar; loop++) { pl=m->list[loop]; @@ -1309,7 +1324,7 @@ static void ShowInfo(MENU *m, int knew ) scrollbar_len = (double)mh / (double)((m->num_entrys/MAX_FUNCS+1)*MAX_FUNCS); scrollbar_ofs = scrollbar_len*(double)((index/MAX_FUNCS)*MAX_FUNCS); scrollbar_cor = scrollbar_len*(double)MAX_FUNCS; - RenderBox(ixw-sbw, moffs + scrollbar_ofs, ixw, moffs + scrollbar_ofs + scrollbar_cor , radius, COL_MENUCONTENT_PLUS_3); + RenderBox(ixw-sbw, moffs + scrollbar_ofs, ixw, moffs + scrollbar_ofs + scrollbar_cor , radius, COL_MENUCONTENT_PLUS_3); } // Title text @@ -1320,9 +1335,9 @@ static void ShowInfo(MENU *m, int knew ) if(m->icon[m->act_header]) { -// PaintIcon(m->icon[m->act_header],xoffs-6,soffs+2,1); + //PaintIcon(m->icon[m->act_header],xoffs-6,soffs+2,1); } - + index /= MAX_FUNCS; dloop=0; ldy=dy; @@ -1352,10 +1367,10 @@ static void ShowInfo(MENU *m, int knew ) if(m->num_active && sbar && (loop==m->act_entry)) { RenderBox(2, my+soffs-dy, ixw-sbw, my+soffs, radius, CMCS); - } + } nosel=(pl->type==TYP_COMMENT) || (pl->type==TYP_INACTIVE); if(!(pl->type==TYP_COMMENT && pl->underline==2)) - { + { RenderString(dstr, 45, my, ixw-sbw-65, LEFT, (pl->type==TYP_COMMENT)?SMALL:MED, (((loop%MAX_FUNCS) == (tind%MAX_FUNCS)) && (sbar) && (!nosel))?CMCST:(nosel)?CMCIT:CMCT); } if(pl->type==TYP_MENU) @@ -1366,7 +1381,7 @@ static void ShowInfo(MENU *m, int knew ) { int cloffs=0,ccenter=0; if(pl->type==TYP_COMMENT) - { + { if(strlen(dstr)==0) { if(pl->underline==2) @@ -1379,7 +1394,7 @@ static void ShowInfo(MENU *m, int knew ) cloffs=dy/3; } } - else + else { if(pl->underline==2) { @@ -1444,7 +1459,8 @@ static void ShowInfo(MENU *m, int knew ) } //copy backbuffer to framebuffer - memcpy(lfb, lbb,fix_screeninfo.line_length*var_screeninfo.yres); + memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + //blit(); if(m->num_active && knew) { @@ -1479,7 +1495,7 @@ static void ShowInfo(MENU *m, int knew ) int Menu_Up(MENU *m) { int llev=m->headerlevels[m->act_header], lmen=m->act_header, lentr=m->lastheaderentrys[m->act_header]; - + if(m->menact) { OnMenuClose(m->menact,m->menactdep); @@ -1495,8 +1511,8 @@ int llev=m->headerlevels[m->act_header], lmen=m->act_header, lentr=m->lastheader m->act_header=lmen; Get_Menu(1); m->act_entry=lentr; - - return 1; + + return 1; } @@ -1524,13 +1540,13 @@ PLISTENTRY pl; printf(NOMEM); return -1; } - + if((trstr=calloc(BUFSIZE+1, sizeof(char)))==NULL) { printf(NOMEM); return -1; } - + spr=Read_Neutrino_Cfg("screen_preset")+1; sprintf(trstr,"screen_StartX%s",spres[spr]); if((sx=Read_Neutrino_Cfg(trstr))<0) @@ -1576,6 +1592,8 @@ PLISTENTRY pl; tr[index]=tr[cindex]; cindex=index; } + for (index = 0; index <= COL_MENUCONTENT_PLUS_3; index++) + bgra[index] = (tr[index] << 24) | (rd[index] << 16) | (gn[index] << 8) | bl[index]; fb = open(FB_DEVICE, O_RDWR); if(fb == -1) @@ -1585,7 +1603,7 @@ PLISTENTRY pl; } InitRC(); -// InitVFD(); + //InitVFD(); //init framebuffer @@ -1599,14 +1617,13 @@ PLISTENTRY pl; perror("shellexec \n"); return -1; } - if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) + if(!(lfb = (uint32_t*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) { perror("shellexec \n"); return -1; } //init fontlibrary - if((error = FT_Init_FreeType(&library))) { printf("shellexec ", error); @@ -1662,7 +1679,7 @@ PLISTENTRY pl; printf("shellexec \n", desc.face_id); use_kerning = FT_HAS_KERNING(face); - desc.flags = FT_LOAD_MONOCHROME; + desc.flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT; if(Read_Neutrino_Cfg("rounded_corners")>0) radius=9; @@ -1670,8 +1687,7 @@ PLISTENTRY pl; radius=0; //init backbuffer - - if(!(lbb = malloc(fix_screeninfo.line_length*var_screeninfo.yres))) + if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)))) { printf("shellexec \n"); FTC_Manager_Done(manager); @@ -1679,15 +1695,15 @@ PLISTENTRY pl; munmap(lfb, fix_screeninfo.smem_len); return -1; } + stride = fix_screeninfo.line_length/sizeof(uint32_t); -// lbb=lfb; - memset(lbb, TRANSP, fix_screeninfo.line_length*var_screeninfo.yres); - memcpy(lfb, lbb, fix_screeninfo.line_length*var_screeninfo.yres); + //lbb=lfb; + memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + //blit(); startx = sx + (((ex-sx) - (fix_screeninfo.line_length-200))/2); starty = sy + (((ey-sy) - (var_screeninfo.yres-150))/2); - - index=0; if(vfd) { @@ -1721,11 +1737,11 @@ PLISTENTRY pl; case -1: mainloop=0; break; - + case 0: mainloop=Menu_Up(&menu); break; - + case 1: pl=menu.list[menu.act_entry]; switch (pl->type) @@ -1746,7 +1762,7 @@ PLISTENTRY pl; Get_Menu(0); menu.act_entry=0; break; - + case TYP_EXECUTE: if((rptr=strxchr(pl->entry,','))!=NULL) { @@ -1773,10 +1789,11 @@ PLISTENTRY pl; } else { - memset(lbb, TRANSP, fix_screeninfo.line_length*var_screeninfo.yres); - memcpy(lfb, lbb, fix_screeninfo.line_length*var_screeninfo.yres); + memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + //blit(); } - + if(*(rptr+strlen(rptr)-1)=='&') { *(rptr+strlen(rptr)-1)=0; @@ -1790,8 +1807,10 @@ PLISTENTRY pl; rptr=tstr; } } + CloseRC(); system(rptr); - + InitRC(); + mainloop= pl->stay==1; if(pl->stay==1) { @@ -1804,26 +1823,27 @@ PLISTENTRY pl; } //cleanup - Clear_List(&menu,-1); FTC_Manager_Done(manager); FT_Done_FreeType(library); -/* if(strlen(url)) +#if 0 + if(strlen(url)) { sprintf(line_buffer,"/sbin/rdate -s %s > /dev/null &",url); system(line_buffer); } -*/ +#endif CloseRC(); -// CloseVFD(); - + //CloseVFD(); + free(line_buffer); free(trstr); // clear Display - memset(lbb, TRANSP,fix_screeninfo.line_length*var_screeninfo.yres); - memcpy(lfb, lbb, fix_screeninfo.line_length*var_screeninfo.yres); + memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + //blit(); munmap(lfb, fix_screeninfo.smem_len); close(fb); @@ -1833,4 +1853,3 @@ PLISTENTRY pl; return 0; } - diff --git a/shellexec.cfg b/shellexec.cfg index 545472c..d651b50 100644 --- a/shellexec.cfg +++ b/shellexec.cfg @@ -1,7 +1,3 @@ -type=2 -name=Flexmenü -desc=Variables Bildschirmmenue -needfb=1 -needlcd=1 -needrc=1 -needoffsets=1 +type=2 +name=Flexmenü +desc=Variables Bildschirmmenü diff --git a/shellexec.h b/shellexec.h index 99e482b..a32f832 100644 --- a/shellexec.h +++ b/shellexec.h @@ -1,8 +1,8 @@ #ifndef __shellexec_H__ - #define __shellexec_H__ - +//#include +#define _FILE_OFFSET_BITS 64 #include #include #include @@ -16,6 +16,7 @@ #include #include #include +#include #include #include FT_FREETYPE_H @@ -115,7 +116,7 @@ enum {SMALL, MED, BIG}; FT_Error error; FT_Library library; FTC_Manager manager; -FTC_SBitCache cache; +FTC_SBitCache cache; FTC_SBit sbit; #if FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 0 FTC_Image_Desc desc; @@ -137,8 +138,9 @@ enum {FILL, GRID}; enum {CMCST, CMCS, CMCT, CMC, CMCIT, CMCI, CMHT, CMH, WHITE, BLUE0, GTRANSP, CMS, ORANGE, GREEN, YELLOW, RED, COL_MENUCONTENT_PLUS_0, COL_MENUCONTENT_PLUS_1, COL_MENUCONTENT_PLUS_2, COL_MENUCONTENT_PLUS_3}; #define TRANSP 0 -extern unsigned char rd[], gn[], bl[], tr[]; -extern unsigned char *lfb, *lbb; +extern uint32_t bgra[]; +extern int stride; +extern uint32_t *lfb, *lbb; extern int FSIZE_BIG; extern int FSIZE_MED; @@ -155,9 +157,11 @@ extern int instance; int get_instance(void); void put_instance(int pval); +#ifndef FB_DEVICE #define FB_DEVICE "/dev/fb/0" +#endif int key_count; unsigned short lastkey; -#endif \ No newline at end of file +#endif diff --git a/starter.c b/starter.c index 0d14e1a..2e15301 100644 --- a/starter.c +++ b/starter.c @@ -50,4 +50,4 @@ void main() fprintf(stderr, "[%s.so] parent, waitpid() returned..\n", SCRIPT); if (WIFEXITED(status)) fprintf(stderr, "[%s.so] child returned with status %d\n", SCRIPT, WEXITSTATUS(status)); -} +} diff --git a/text.c b/text.c index a79a03f..32cd489 100644 --- a/text.c +++ b/text.c @@ -1,90 +1,155 @@ #include "text.h" #include "gfx.h" #include "io.h" +#include "shellexec.h" int FSIZE_BIG=28; int FSIZE_MED=24; int FSIZE_SMALL=20; int TABULATOR=72; -static unsigned sc[8]={'a','o','u','A','O','U','z','d'}, tc[8]={'ä','ö','ü','Ä','Ö','Ü','ß','°'}, su[7]={0xA4,0xB6,0xBC,0x84,0x96,0x9C,0x9F}; +//extern void blit(); -void TranslateString(char *src) -{ -int i,found,quota=0; -char rc,*rptr=src,*tptr=src; +static char *sc = "aouAOUzd", + *su = "\xA4\xB6\xBC\x84\x96\x9C\x9F", + *tc = "\xE4\xF6\xFC\xC4\xD6\xDC\xDF\xB0"; - while(*rptr != '\0') +// from neutrino/src/driver/fontrenderer.cpp +int UTF8ToUnicode(char **textp, const int utf8_encoded) // returns -1 on error +{ + int unicode_value, i; + char *text = *textp; + if (utf8_encoded && ((((unsigned char)(*text)) & 0x80) != 0)) { - if(*rptr=='\'') + int remaining_unicode_length; + if ((((unsigned char)(*text)) & 0xf8) == 0xf0) { - quota^=1; + unicode_value = ((unsigned char)(*text)) & 0x07; + remaining_unicode_length = 3; } - if(!quota && *rptr=='~') + else if ((((unsigned char)(*text)) & 0xf0) == 0xe0) { - ++rptr; - rc=*rptr; - found=0; - for(i=0; i\n", (char*)face_id); + if (result) + printf("shellexec \n", (char*)face_id); return result; } @@ -93,92 +158,155 @@ FT_Error MyFaceRequester(FTC_FaceID face_id, FT_Library library, FT_Pointer requ * RenderChar ******************************************************************************/ -int RenderChar(FT_ULong currentchar, int sx, int sy, int ex, int color) +struct colors_struct { - // unsigned char pix[4]={oldcmap.red[col],oldcmap.green[col],oldcmap.blue[col],oldcmap.transp[col]}; - // unsigned char pix[4]={0x80,0x80,0x80,0x80}; - unsigned char pix[4]={bl[color],gn[color],rd[color],tr[color]}; - int row, pitch, bit, x = 0, y = 0; + uint32_t fgcolor, bgcolor; + uint32_t colors[256]; +}; + +#define COLORS_LRU_SIZE 16 +static struct colors_struct *colors_lru_array[COLORS_LRU_SIZE] = { NULL }; + +static uint32_t *lookup_colors(uint32_t fgcolor, uint32_t bgcolor) +{ + struct colors_struct *cs; + int i = 0, j; + for (i = 0; i < COLORS_LRU_SIZE; i++) + if (colors_lru_array[i] && colors_lru_array[i]->fgcolor == fgcolor && colors_lru_array[i]->bgcolor == bgcolor) { + cs = colors_lru_array[i]; + for (j = i; j > 0; j--) + colors_lru_array[j] = colors_lru_array[j - 1]; + colors_lru_array[0] = cs; + return cs->colors; + } + i--; + cs = colors_lru_array[i]; + if (!cs) + cs = (struct colors_struct *) calloc(1, sizeof(struct colors_struct)); + for (j = i; j > 0; j--) + colors_lru_array[j] = colors_lru_array[j - 1]; + cs->fgcolor = fgcolor; + cs->bgcolor = bgcolor; + + int ro = var_screeninfo.red.offset; + int go = var_screeninfo.green.offset; + int bo = var_screeninfo.blue.offset; + int to = var_screeninfo.transp.offset; + int rm = (1 << var_screeninfo.red.length) - 1; + int gm = (1 << var_screeninfo.green.length) - 1; + int bm = (1 << var_screeninfo.blue.length) - 1; + int tm = (1 << var_screeninfo.transp.length) - 1; + int fgr = ((int)fgcolor >> ro) & rm; + int fgg = ((int)fgcolor >> go) & gm; + int fgb = ((int)fgcolor >> bo) & bm; + int fgt = ((int)fgcolor >> to) & tm; + int deltar = (((int)bgcolor >> ro) & rm) - fgr; + int deltag = (((int)bgcolor >> go) & gm) - fgg; + int deltab = (((int)bgcolor >> bo) & bm) - fgb; + int deltat = (((int)bgcolor >> to) & tm) - fgt; + for (i = 0; i < 256; i++) + cs->colors[255 - i] = + (((fgr + deltar * i / 255) & rm) << ro) | + (((fgg + deltag * i / 255) & gm) << go) | + (((fgb + deltab * i / 255) & bm) << bo) | + (((fgt + deltat * i / 255) & tm) << to); + + colors_lru_array[0] = cs; + return cs->colors; +} + +int RenderChar(FT_ULong currentchar, int _sx, int _sy, int _ex, int color) +{ + int row, pitch; FT_UInt glyphindex; FT_Vector kerning; - FT_Error error; + FT_Error err; - currentchar=currentchar & 0xFF; + if (currentchar == '\r') // display \r in windows edited files + { + if(color != -1) + { + if (_sx + 10 < _ex) + RenderBox(_sx, _sy - 10, _sx + 10, _sy, GRID, color); + else + return -1; + } + return 10; + } - //load char + if (currentchar == '\t') + { + /* simulate horizontal TAB */ + return 15; + } - if(!(glyphindex = FT_Get_Char_Index(face, (int)currentchar))) + //load char + if(!(glyphindex = FT_Get_Char_Index(face, currentchar))) { - // printf("msgbox \n", (int)currentchar); return 0; } - - if((error = FTC_SBitCache_Lookup(cache, &desc, glyphindex, &sbit, NULL))) + if((err = FTC_SBitCache_Lookup(cache, &desc, glyphindex, &sbit, NULL))) { - // printf("msgbox \n", (int)currentchar, error); + printf("shellexec \n", (int)currentchar, err); return 0; } - // no kerning used - /* if(use_kerning) { FT_Get_Kerning(face, prev_glyphindex, glyphindex, ft_kerning_default, &kerning); prev_glyphindex = glyphindex; kerning.x >>= 6; -} -else - */ - kerning.x = 0; - -//render char - -if(color != -1) /* don't render char, return charwidth only */ -{ - if(sx + sbit->xadvance >= ex) return -1; /* limit to maxwidth */ + } else + kerning.x = 0; + //render char + if (color != -1) /* don't render char, return charwidth only */ + { + uint32_t bgcolor = *(lbb + (starty + _sy) * stride + (startx + _sx)); + uint32_t fgcolor = bgra[color]; + uint32_t *colors = lookup_colors(fgcolor, bgcolor); + uint32_t *p = lbb + (startx + _sx + sbit->left + kerning.x) + stride * (starty + _sy - sbit->top); + uint32_t *r = p + (_ex - _sx); /* end of usable box */ for(row = 0; row < sbit->height; row++) { - for(pitch = 0; pitch < sbit->pitch; pitch++) + uint32_t *q = p; + uint8_t *s = sbit->buffer + row * sbit->pitch; + for(pitch = 0; pitch < sbit->width; pitch++) { - for(bit = 7; bit >= 0; bit--) - { - if(pitch*8 + 7-bit >= sbit->width) break; /* render needed bits only */ - - if((sbit->buffer[row * sbit->pitch + pitch]) & 1<left + kerning.x + x)*4 + fix_screeninfo.line_length*(starty + sy - sbit->top + y),pix,4); - - x++; - } + if (*s) + *q = colors[*s]; + q++, s++; + if (q > r) /* we are past _ex */ + break; } - - x = 0; - y++; + p += stride; + r += stride; } + if (_sx + sbit->xadvance >= _ex) + return -1; /* limit to maxwidth */ + } -} - -//return charwidth - -return sbit->xadvance + kerning.x; + //return charwidth + return sbit->xadvance + kerning.x; } /****************************************************************************** * GetStringLen ******************************************************************************/ -int GetStringLen(int sx, unsigned char *string, int size) +int GetStringLen(int _sx, char *string, size_t size) { - int i, found; - int stringlen = 0; - + int i, stringlen = 0; + //reset kerning - + prev_glyphindex = 0; - + //calc len - + switch (size) { case SMALL: desc.width = desc.height = FSIZE_SMALL; break; @@ -187,46 +315,23 @@ int GetStringLen(int sx, unsigned char *string, int size) default: desc.width = desc.height = size; break; } - while(*string != '\0') - { - if(*string != '~') - { - stringlen += RenderChar(*string, -1, -1, -1, -1); - } - else - { + while(*string) { + switch(*string) { + case '~': string++; if(*string=='t') - { stringlen=desc.width+TABULATOR*((int)(stringlen/TABULATOR)+1); + else if(*string=='T' && sscanf(string+1,"%4d",&i)==1) { + string+=5; + stringlen=i-_sx; } - else - { - if(*string=='T') - { - if(sscanf(string+1,"%4d",&i)==1) - { - string+=4; - stringlen=i-sx; - } - } - else - { - found=0; - for(i=0; i maxwidth */ + if ((charwidth = RenderChar(UTF8ToUnicode(&rptr, 1), sx, sy, ex, ((color!=CMCIT) && (color!=CMCST)) ? varcolor : color)) == -1) + return; /* string > maxwidth */ sx += charwidth; } - rptr++; + //rptr++; } } @@ -364,40 +466,39 @@ void ShowMessage(char *mtitle, char *message, int wait) { extern int radius; int ixw=400; - int lx=startx/*, ly=starty*/; + int lx=startx; + //int ly=starty; char *tdptr; - + startx = sx + (((ex-sx) - ixw)/2); -// starty=sy; - - //layout + //starty=sy; - RenderBox(0, 178, ixw, 327, radius, CMH); - RenderBox(2, 180, ixw-4, 323, radius, CMC); - RenderBox(0, 178, ixw, 220, radius, CMH); + //layout + RenderBox(0, 178, ixw, 327, radius, CMH); + RenderBox(2, 180, ixw-4, 323, radius, CMC); + RenderBox(0, 178, ixw, 220, radius, CMH); //message - - tdptr=strdup(mtitle); - remove_tabs(tdptr); - RenderString(tdptr, 2, 213, ixw, CENTER, FSIZE_BIG, CMHT); - free(tdptr); - tdptr=strdup(message); - remove_tabs(tdptr); - RenderString(tdptr, 2, 270, ixw, CENTER, FSIZE_MED, CMCT); - free(tdptr); - - if(wait) - { - RenderBox(ixw/2-25, 286, ixw/2+25, 310, radius, CMCS); - RenderString("OK", ixw/2-25, 305, 50, CENTER, FSIZE_MED, CMCT); - } - memcpy(lfb, lbb, fix_screeninfo.line_length*var_screeninfo.yres); + tdptr=strdup(mtitle); + remove_tabs(tdptr); + RenderString(tdptr, 2, 213, ixw, CENTER, FSIZE_BIG, CMHT); + free(tdptr); + tdptr=strdup(message); + remove_tabs(tdptr); + RenderString(tdptr, 2, 270, ixw, CENTER, FSIZE_MED, CMCT); + free(tdptr); + + if(wait) + { + RenderBox(ixw/2-25, 286, ixw/2+25, 310, radius, CMCS); + RenderString("OK", ixw/2-25, 305, 50, CENTER, FSIZE_MED, CMCT); + } + memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); + //blit(); - while(wait && (GetRCCode() != RC_OK)); - - startx=lx; -// starty=ly; + while(wait && (GetRCCode(-1) != RC_OK)); -} + startx=lx; + //starty=ly; +} diff --git a/text.h b/text.h index a7b2604..ea34e76 100644 --- a/text.h +++ b/text.h @@ -1,5 +1,4 @@ #ifndef __TEXT_H__ - #define __TEXT_H__ #include "shellexec.h" @@ -8,8 +7,8 @@ extern int FSIZE_BIG; extern int FSIZE_MED; extern int FSIZE_SMALL; -void TranslateString(char *src); -int GetStringLen(int sx, unsigned char *string, int size); +void TranslateString(char *src, size_t size); +int GetStringLen(int sx, char *string, size_t size); FT_Error MyFaceRequester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *aface); void RenderString(char *string, int sx, int sy, int maxwidth, int layout, int size, int color); void ShowMessage(char *mtitle, char *message, int wait);