home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Enlightenment
/
enl_DR-0.10.tar.gz
/
enl_DR-0.10.tar
/
enl
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-24
|
6KB
|
237 lines
#include "enlightenment.h"
/* this just cleans up after dead child processes.... */
void Reap()
{
int status;
while (wait3(&status, WNOHANG, 0)>0);
}
void X_Connect(void)
{
XWindowAttributes xwa;
disp=XOpenDisplay(NULL); /* open the display connection */
if (disp==NULL) /* if we couldn't open the connection.. error */
{
fprintf(stderr,"Enlightenment: cannot connect to Display \n");
exit(1); /* bad error.. we have to exit */
}
/* now get some imperative info about the display */
screen=DefaultScreen(disp); /* the screen number */
root=DefaultRootWindow(disp); /* the root window id */
visual=DefaultVisual(disp,screen); /* the visual type */
depth=DefaultDepth(disp,screen); /* the depth of the screen in bpp */
scr_width=DisplayWidth(disp,screen); /* the width of the screen */
scr_height=DisplayHeight(disp,screen); /* height of the screen */
XSelectInput(disp,root,SubstructureNotifyMask|ButtonPressMask|
ButtonReleaseMask|EnterWindowMask|LeaveWindowMask|
ButtonMotionMask|PropertyChangeMask|SubstructureRedirectMask|
KeyPressMask|KeyReleaseMask|PointerMotionMask);
if (!debug_mode) UnmapClients(1);
/* set up an apporpriate event mask */
if (XGetWindowAttributes(disp,root,&xwa))
{
if (xwa.colormap) root_cmap=xwa.colormap;
else root_cmap=0;
}
else root_cmap=0;
XSetErrorHandler((XErrorHandler)handleError);
}
Image *LoadImage(ImlibData *d, char *file, ImColor *icl)
{
Image *im;
char ss[10240];
if (!file) return NULL;
if (!d) return NULL;
if (file[0]!='/')
{
if (Theme_Path[0])
sprintf(ss,"%s/%s",Theme_Path,file);
if (!exists(ss))
{
sprintf(ss,".enlightenment/%s",file);
if (!exists(ss))
{
sprintf(ss,"%s/.enlightenment/%s",getenv("HOME"),file);
if (!exists(ss))
{
sprintf(ss,"./%s",file);
}
}
}
}
else strcpy(ss,file);
im=ImlibLoadImage(d,ss,icl);
if (!im)
Alert("Holy Carumba! Geez oh crikey!\nI couldn't for the lif of me find %s\nI'll probably run screaming off in a fit of rage now...\n",ss);
return im;
}
int
main(int argc, char **argv)
{
char s[1024];
XEvent event;
listhead *l;
struct sigaction sa;
int i,j;
unsigned char buf[16];
FILE *f;
nodel=0;
srand(time(NULL));
debug_mode=0;
Theme_Tar_Ball[0]=0;
Theme_Name[0]=0;
Theme_Path[0]=0;
for (j=1;j<argc;j++)
{
if (!strcmp("-debug",argv[j])) debug_mode=1;
if ((!strcmp("-theme",argv[j]))&&((argc-j)>1))
{
strcpy(Theme_Tar_Ball,argv[j+1]);
strcpy(Theme_Name,Theme_Tar_Ball);
j++;
}
}
if (!Theme_Tar_Ball[0])
{
if (!isdir("./.enlightenment"))
{
sprintf(s,"%s/.enlightenment",getenv("HOME"));
if (!isdir(s))
{
strcpy(Theme_Tar_Ball,"DEFAULT");
strcpy(Theme_Name,"DEFAULT");
}
}
}
if (Theme_Tar_Ball[0])
{
i=getpid();
if (!exists(Theme_Tar_Ball))
{
sprintf(s,"%s%s",THEMES_DIR,Theme_Tar_Ball);
strcpy(Theme_Tar_Ball,s);
}
if (exists(Theme_Tar_Ball))
{
if (isfile(Theme_Tar_Ball))
{
sprintf(Theme_Path,"/tmp/enlightenment_theme_%i",i);
md(Theme_Path);
f=fopen(Theme_Tar_Ball,"r");
fread(&buf[0],1,1,f);
fread(&buf[1],1,1,f);
if ((buf[0]==31)&&(buf[1]==139))
{
/*gzipped tarball*/
sprintf(s,"gzip -d -c < %s | tar -x -C %s",Theme_Tar_Ball,Theme_Path);
}
else
{
/*vanilla tarball*/
sprintf(s,"tar -x -C %s < %s",Theme_Path,Theme_Tar_Ball);
}
system(s);
fclose (f);
}
else if (isdir(Theme_Tar_Ball))
{
nodel=1;
strcpy(Theme_Path,Theme_Tar_Ball);
Theme_Tar_Ball[0]=0;
}
else
{
Theme_Path[0]=0;
Theme_Tar_Ball[0]=0;
}
}
else
{
Theme_Path[0]=0;
Theme_Tar_Ball[0]=0;
}
}
sa.sa_handler = Reap;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
argv1 = (void *)malloc(strlen(argv[0])+1);
strcpy(argv1, argv[0]);
sigaction(SIGCHLD, &sa, (struct sigaction *)0);
/* when child processes die.. clean up after them */
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGALRM, &sa, (struct sigaction *)0);
X_Connect(); /* connect to the display nominated */
imd=ImlibInit(disp); /* Inititalise Imlib..... */
if (!imd) /* uh oh.. problems... imlib had a bad day... */
{
fprintf(stderr,"FATAL.... cannot initialise Imlib!!! Outa here!\n");
Alert("FATAL ERROR!\n Cannot initialise Imlib!\n Quitting.\n");
exit(1);
}
depth=imd->x.depth;
visual=imd->x.visual;
l=ListInit(); /* initialise the window list */
global_l=l;
InitConfig();
LoadConfig("MAIN");
Kill_StatusWin();
SetRoot();
MapClients(l);
newicon.ewin=NULL;
while(1) /* loop continuously and reacting to events */
{
if (global_killewin)
{
ListDelWinID(l,global_killewin->frame_win);
global_killewin=NULL;
}
if ((ifb.on)&&(!raisewin)&&(!newicon.ewin))
{
struct sigaction sa;
struct itimerval tv1,tv2;
sa.sa_handler = InfoBox;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
tv1.it_value.tv_sec=0;
tv1.it_value.tv_usec=ifb.timeout*1000;
tv2.it_value.tv_sec=0;
tv2.it_value.tv_usec=ifb.timeout*1000;
tv1.it_interval.tv_sec=0;
tv1.it_interval.tv_usec=0;
tv2.it_interval.tv_sec=0;
tv2.it_interval.tv_usec=0;
setitimer(ITIMER_REAL,&tv1,&tv2);
sigaction(SIGALRM,&sa,(struct sigaction *)0);
}
ifb.nodo=0;
XNextEvent(disp,&event); /* Get the next event to the display */
ifb.nodo=1;
XGrabServer(disp); /* grab the server.. dont let clients play around */
handleEvent(&event,l);
XSync(disp,0x00);
XUngrabServer(disp);
}
if ((Theme_Path[0])&&(!nodel))
{
sprintf(s,"rm -rf %s",Theme_Path);
system(s);
}
}