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 >
C/C++ Source or Header  |  1997-06-24  |  6KB  |  237 lines

  1. #include "enlightenment.h"
  2.  
  3. /* this just cleans up after dead child processes.... */
  4. void Reap()
  5. {
  6.    int status;
  7.    
  8.    while (wait3(&status, WNOHANG, 0)>0);
  9. }
  10.  
  11. void X_Connect(void)
  12. {
  13.    XWindowAttributes xwa;
  14.    
  15.    disp=XOpenDisplay(NULL); /* open the display connection */
  16.    if (disp==NULL) /* if we couldn't open the connection.. error */
  17.      {
  18.     fprintf(stderr,"Enlightenment: cannot connect to Display \n");
  19.     exit(1); /* bad error.. we have to exit */
  20.      }
  21.    /* now get some imperative info about the display */
  22.    screen=DefaultScreen(disp); /* the screen number */
  23.    root=DefaultRootWindow(disp); /* the root window id */
  24.    visual=DefaultVisual(disp,screen); /* the visual type */
  25.    depth=DefaultDepth(disp,screen); /* the depth of the screen in bpp */
  26.    scr_width=DisplayWidth(disp,screen); /* the width of the screen */
  27.    scr_height=DisplayHeight(disp,screen); /* height of the screen */
  28.    XSelectInput(disp,root,SubstructureNotifyMask|ButtonPressMask|
  29.         ButtonReleaseMask|EnterWindowMask|LeaveWindowMask|
  30.         ButtonMotionMask|PropertyChangeMask|SubstructureRedirectMask|
  31.         KeyPressMask|KeyReleaseMask|PointerMotionMask);
  32.    if (!debug_mode) UnmapClients(1);
  33.    /* set up an apporpriate event mask */
  34.    if (XGetWindowAttributes(disp,root,&xwa))
  35.      {
  36.     if (xwa.colormap) root_cmap=xwa.colormap;
  37.     else root_cmap=0;
  38.      }
  39.    else root_cmap=0;
  40.    XSetErrorHandler((XErrorHandler)handleError);
  41. }
  42.  
  43. Image *LoadImage(ImlibData *d, char *file, ImColor *icl)
  44. {
  45.    Image *im;
  46.    char ss[10240];
  47.    
  48.    if (!file) return NULL;
  49.    if (!d) return NULL;
  50.    if (file[0]!='/') 
  51.      {
  52.     if (Theme_Path[0])
  53.          sprintf(ss,"%s/%s",Theme_Path,file);
  54.     if (!exists(ss))
  55.       {
  56.          sprintf(ss,".enlightenment/%s",file);
  57.          if (!exists(ss))
  58.            {
  59.           sprintf(ss,"%s/.enlightenment/%s",getenv("HOME"),file);
  60.           if (!exists(ss))
  61.             {
  62.                sprintf(ss,"./%s",file);
  63.             }
  64.            }
  65.       }
  66.      }
  67.    else strcpy(ss,file);                           
  68.    im=ImlibLoadImage(d,ss,icl);
  69.    if (!im)
  70.      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);
  71.    return im;
  72. }
  73.  
  74. int 
  75. main(int argc, char **argv)
  76. {
  77.    char s[1024];
  78.    XEvent event;
  79.    listhead *l;
  80.    struct sigaction sa;
  81.    int i,j;
  82.    unsigned char buf[16];
  83.    FILE *f;
  84.    
  85.    nodel=0;
  86.    srand(time(NULL));
  87.    debug_mode=0;
  88.    Theme_Tar_Ball[0]=0;
  89.    Theme_Name[0]=0;
  90.    Theme_Path[0]=0;
  91.    
  92.    for (j=1;j<argc;j++)
  93.      {
  94.     if (!strcmp("-debug",argv[j])) debug_mode=1;
  95.     if ((!strcmp("-theme",argv[j]))&&((argc-j)>1)) 
  96.       {
  97.          strcpy(Theme_Tar_Ball,argv[j+1]);
  98.          strcpy(Theme_Name,Theme_Tar_Ball);
  99.          j++;
  100.       }
  101.      }
  102.    if (!Theme_Tar_Ball[0])
  103.      {
  104.     if (!isdir("./.enlightenment"))
  105.       {
  106.          sprintf(s,"%s/.enlightenment",getenv("HOME"));
  107.          if (!isdir(s))
  108.            {
  109.           strcpy(Theme_Tar_Ball,"DEFAULT");
  110.           strcpy(Theme_Name,"DEFAULT");
  111.            }
  112.       }
  113.      }
  114.    if (Theme_Tar_Ball[0])
  115.      {
  116.     i=getpid();
  117.     if (!exists(Theme_Tar_Ball))
  118.       {
  119.          sprintf(s,"%s%s",THEMES_DIR,Theme_Tar_Ball);
  120.          strcpy(Theme_Tar_Ball,s);
  121.       }
  122.     if (exists(Theme_Tar_Ball))
  123.       {
  124.          if (isfile(Theme_Tar_Ball))
  125.            {
  126.           sprintf(Theme_Path,"/tmp/enlightenment_theme_%i",i);
  127.           md(Theme_Path);
  128.           f=fopen(Theme_Tar_Ball,"r");
  129.           fread(&buf[0],1,1,f);
  130.           fread(&buf[1],1,1,f);
  131.           if ((buf[0]==31)&&(buf[1]==139))
  132.             {
  133.                /*gzipped tarball*/
  134.                sprintf(s,"gzip -d -c < %s | tar -x -C %s",Theme_Tar_Ball,Theme_Path);
  135.             }
  136.           else
  137.             {
  138.                /*vanilla tarball*/
  139.                sprintf(s,"tar -x -C %s < %s",Theme_Path,Theme_Tar_Ball);
  140.             }
  141.           system(s);
  142.           fclose (f);
  143.            }
  144.          else if (isdir(Theme_Tar_Ball))
  145.            {
  146.           nodel=1;
  147.           strcpy(Theme_Path,Theme_Tar_Ball);
  148.           Theme_Tar_Ball[0]=0;
  149.            }
  150.          else
  151.            {
  152.           Theme_Path[0]=0;
  153.           Theme_Tar_Ball[0]=0;
  154.            }
  155.       }
  156.     else
  157.       {
  158.          Theme_Path[0]=0;
  159.          Theme_Tar_Ball[0]=0;
  160.       }
  161.      }
  162.    
  163.    sa.sa_handler = Reap;
  164.    sa.sa_flags = 0;
  165.    sigemptyset (&sa.sa_mask);
  166.  
  167.    argv1 = (void *)malloc(strlen(argv[0])+1);
  168.    strcpy(argv1, argv[0]);
  169.    
  170.    sigaction(SIGCHLD, &sa, (struct sigaction *)0);
  171.    /* when child processes die.. clean up after them */
  172.    
  173.    sa.sa_handler = SIG_IGN;
  174.    sa.sa_flags = 0;
  175.    sigemptyset(&sa.sa_mask);
  176.    sigaction(SIGALRM, &sa, (struct sigaction *)0);
  177.    
  178.    X_Connect(); /* connect to the display nominated */
  179.    imd=ImlibInit(disp); /* Inititalise Imlib..... */
  180.    if (!imd) /* uh oh.. problems... imlib had a bad day... */
  181.      { 
  182.     fprintf(stderr,"FATAL.... cannot initialise Imlib!!! Outa here!\n");
  183.     Alert("FATAL ERROR!\n Cannot initialise Imlib!\n Quitting.\n");
  184.     exit(1);
  185.      }
  186.    depth=imd->x.depth; 
  187.    visual=imd->x.visual;
  188.    l=ListInit(); /* initialise the window list */
  189.    global_l=l;
  190.    InitConfig();
  191.    LoadConfig("MAIN");
  192.    Kill_StatusWin();
  193.    SetRoot();
  194.    MapClients(l);
  195.    newicon.ewin=NULL;
  196.    while(1) /* loop continuously and reacting to events */
  197.      {
  198.     if (global_killewin)
  199.       {
  200.          ListDelWinID(l,global_killewin->frame_win);
  201.          global_killewin=NULL;
  202.       }
  203.     if ((ifb.on)&&(!raisewin)&&(!newicon.ewin))
  204.       {
  205.          struct sigaction sa;
  206.          struct itimerval tv1,tv2;
  207.          
  208.          sa.sa_handler = InfoBox;
  209.          sa.sa_flags = 0;
  210.          sigemptyset (&sa.sa_mask);
  211.          tv1.it_value.tv_sec=0;
  212.          tv1.it_value.tv_usec=ifb.timeout*1000;
  213.          tv2.it_value.tv_sec=0;
  214.          tv2.it_value.tv_usec=ifb.timeout*1000;
  215.          tv1.it_interval.tv_sec=0;
  216.          tv1.it_interval.tv_usec=0;
  217.          tv2.it_interval.tv_sec=0;
  218.          tv2.it_interval.tv_usec=0;
  219.          setitimer(ITIMER_REAL,&tv1,&tv2);
  220.          sigaction(SIGALRM,&sa,(struct sigaction *)0);
  221.       }
  222.     ifb.nodo=0;
  223.     XNextEvent(disp,&event); /* Get the next event to the display */
  224.     ifb.nodo=1;
  225.     XGrabServer(disp); /* grab the server.. dont let clients play around */
  226.     handleEvent(&event,l);
  227.     XSync(disp,0x00);
  228.     XUngrabServer(disp);
  229.      }
  230.    if ((Theme_Path[0])&&(!nodel))
  231.      {
  232.     sprintf(s,"rm -rf %s",Theme_Path);
  233.     system(s); 
  234.      }
  235. }
  236.  
  237.