Exemplo n.º 1
0
int
main(int argc, char **argv)
{
    int                 ch, i, loop;
    struct utsname      ubuf;
    const char         *str, *dstr;

    /* This function runs all the setup for startup, and then
     * proceeds into the primary event loop at the end.
     */

    /* Init state variable struct */
    memset(&Mode, 0, sizeof(EMode));

    Mode.wm.master = 1;
    Mode.wm.pid = getpid();
    Mode.wm.exec_name = argv[0];
    Mode.wm.startup = 1;

    Mode.mode = MODE_NONE;

    EXInit();
    Dpy.screen = -1;

    str = getenv("EDEBUG");
    if (str)
        EDebugInit(str);
    str = getenv("EDEBUG_COREDUMP");
    if (str)
        Mode.wm.coredump = 1;
    str = getenv("EDEBUG_EXIT");
    if (str)
        Mode.debug_exit = atoi(str);

    str = getenv("ECONFNAME");
    if (str)
        EConfNameSet(str);
    str = getenv("ECONFDIR");
    if (str)
        EDirUserSet(str);
    str = getenv("ECACHEDIR");
    if (str)
        EDirUserCacheSet(str);

    srand((unsigned int)time(NULL));

    if (!uname(&ubuf))
        Mode.wm.machine_name = Estrdup(ubuf.nodename);
    if (!Mode.wm.machine_name)
        Mode.wm.machine_name = Estrdup("localhost");

    /* Now we're going to interpret any of the commandline parameters
     * that are passed to it -- Well, at least the ones that we
     * understand.
     */

    Mode.theme.path = NULL;
    dstr = NULL;

    for (loop = 1; loop;)
    {
        ch = EoptGet(argc, argv);
        if (ch <= 0)
            break;
#if 0
        Eprintf("Opt: %c: %d - %s\n", ch, eoptind, eoptarg);
#endif
        switch (ch)
        {
        default:
        case '?':
            printf("e16: Ignoring: ");
            for (i = eoptind; i < argc; i++)
                printf("%s ", argv[i]);
            printf("\n");
            loop = 0;
            break;
        case 'h':
            EoptHelp();
            exit(0);
            break;
        case 'd':
            dstr = eoptarg;
            break;
        case 'f':
            Mode.wm.restart = 1;
            break;
        case 'p':
            EConfNameSet(eoptarg);
            break;
        case 'P':
            EDirUserSet(eoptarg);
            break;
        case 'Q':
            EDirUserCacheSet(eoptarg);
            break;
        case 's':
            Mode.wm.single = 1;
            Dpy.screen = strtoul(eoptarg, NULL, 10);
            break;
        case 'S':
            SetSMID(eoptarg);
            break;
        case 't':
            Mode.theme.path = Estrdup(eoptarg);
            break;
        case 'V':
            printf("%s %s\n", e_wm_name, e_wm_version);
            exit(0);
            break;
        case 'v':
            EDebugSet(EDBUG_TYPE_VERBOSE, 1);
            break;
        case 'w':
            sscanf(eoptarg, "%dx%d", &Mode.wm.win_w, &Mode.wm.win_h);
            Mode.wm.window = 1;
            Mode.wm.single = 1;
            Mode.wm.master = 0;
            break;
#ifdef USE_EXT_INIT_WIN
        case 'X':
            ExtInitWinSet(strtoul(eoptarg, NULL, 0));
            Mode.wm.restart = 1;
            break;
#endif
        case 'm':
            Mode.wm.master = 0;
            Mode.wm.master_screen = strtoul(eoptarg, NULL, 10);
            break;
        }
    }

    SignalsSetup();		/* Install signal handlers */

    EDirsSetup();
    ECheckEprog("epp");
    ECheckEprog("eesh");

    SetupX(dstr);		/* This is where the we fork per screen */
    /* X is now running, and we have forked per screen */

    ESavePrefixSetup();

    /* So far nothing should rely on a selected settings or theme. */
    ConfigurationLoad();		/* Load settings */

    /* Initialise internationalisation */
    LangInit();

    /* The theme path must now be available for config file loading. */
    ThemePathFind();

    /* Set the Environment variables */
    Esetenv("EVERSION", e_wm_version);
    Esetenv("EROOT", EDirRoot());
    Esetenv("EBIN", EDirBin());
    Esetenv("ECONFDIR", EDirUser());
    Esetenv("ECACHEDIR", EDirUserCache());
    Esetenv("ETHEME", Mode.theme.path);

    /* Move elsewhere? */
    EImageInit();
    HintsInit();
    CommsInit();
    SessionInit();
    SnapshotsLoad();

#if USE_DBUS
    DbusInit();
#endif

    if (Mode.wm.window)
        EMapWindow(VROOT);

    ModulesSignal(ESIGNAL_INIT, NULL);

    /* Load the theme */
    ThemeConfigLoad();

    if (Mode.debug_exit)
        return 0;

    /* Do initial configuration */
    ModulesSignal(ESIGNAL_CONFIGURE, NULL);

    /* Set root window cursor */
    ECsrApply(ECSR_ROOT, WinGetXwin(VROOT));

#ifdef USE_EXT_INIT_WIN
    /* Kill the E process owning the "init window" */
    ExtInitWinKill();
#endif

    /* let's make sure we set this up and go to our desk anyways */
    DeskGoto(DesksGetCurrent());
    ESync(ESYNC_MAIN);

#ifdef SIGCONT
    for (i = 0; i < Mode.wm.child_count; i++)
        kill(Mode.wm.children[i], SIGCONT);
#endif

    ModulesSignal(ESIGNAL_START, NULL);
#if ENABLE_DIALOGS
    DialogsInit();
#endif
    EwinsManage();

    RunInitPrograms();
    SnapshotsSpawn();

    if (!Mode.wm.restart)
        StartupWindowsOpen();

    Conf.startup.firsttime = 0;
    Mode.wm.save_ok = Conf.autosave;
    Mode.wm.startup = 0;
    autosave();

    /* The primary event loop */
    EventsMain();

    SessionExit(EEXIT_QUIT, NULL);

    return 0;
}
Exemplo n.º 2
0
static              Window
ExtInitWinMain(void)
{
   int                 i, loop, err;
   Ecore_X_Window      win;
   XGCValues           gcv;
   GC                  gc;
   Pixmap              pmap;
   Atom                a;
   EiwData             eiwd;
   EiwLoopFunc        *eiwc_loop_func;

   if (EDebug(EDBUG_TYPE_SESSION))
      Eprintf("ExtInitWinMain enter\n");

   err = EDisplayOpen(NULL, -1);
   if (err)
      return None;

   EGrabServer();

   EImageInit();

   eiwd.attr.backing_store = NotUseful;
   eiwd.attr.override_redirect = True;
   eiwd.attr.colormap = WinGetCmap(VROOT);
   eiwd.attr.border_pixel = 0;
   eiwd.attr.background_pixel = 0;
   eiwd.attr.save_under = True;
   win = XCreateWindow(disp, WinGetXwin(VROOT),
		       0, 0, WinGetW(VROOT), WinGetH(VROOT),
		       0, CopyFromParent, InputOutput, CopyFromParent,
		       CWOverrideRedirect | CWSaveUnder | CWBackingStore |
		       CWColormap | CWBackPixel | CWBorderPixel, &eiwd.attr);

   pmap = XCreatePixmap(disp, win,
			WinGetW(VROOT), WinGetH(VROOT), WinGetDepth(VROOT));
   gcv.subwindow_mode = IncludeInferiors;
   gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
   XCopyArea(disp, WinGetXwin(VROOT), pmap, gc,
	     0, 0, WinGetW(VROOT), WinGetH(VROOT), 0, 0);
   XSetWindowBackgroundPixmap(disp, win, pmap);
   XMapRaised(disp, win);
   XFreePixmap(disp, pmap);
   XFreeGC(disp, gc);

   a = EInternAtom("ENLIGHTENMENT_RESTART_SCREEN");
   ecore_x_window_prop_window_set(WinGetXwin(VROOT), a, &win, 1);

   XSelectInput(disp, win, StructureNotifyMask);

   EUngrabServer();
   ESync(0);

#if USE_EIWC_WINDOW && USE_EIWC_RENDER
   eiwc_loop_func = _eiw_render_init(win, &eiwd);
   if (!eiwc_loop_func)
      eiwc_loop_func = _eiw_window_init(win, &eiwd);
#elif USE_EIWC_RENDER
   eiwc_loop_func = _eiw_render_init(win, &eiwd);
#elif USE_EIWC_WINDOW
   eiwc_loop_func = _eiw_window_init(win, &eiwd);
#endif
   if (!eiwc_loop_func)
      return None;

   {
      XWindowAttributes   xwa;
      char                s[1024];
      EImage             *im;

      for (i = loop = 1;; i++, loop++)
	{
	   if (i > 12)
	      i = 1;

	   /* If we get unmapped we are done */
	   XGetWindowAttributes(disp, win, &xwa);
	   if (xwa.map_state == IsUnmapped)
	      break;

	   Esnprintf(s, sizeof(s), "pix/wait%i.png", i);
	   if (EDebug(EDBUG_TYPE_SESSION) > 1)
	      Eprintf("ExtInitWinCreate - child %s\n", s);

	   im = ThemeImageLoad(s);
	   if (im)
	     {
		eiwc_loop_func(win, im, &eiwd);
		EImageFree(im);
	     }
	   ESync(0);
	   usleep(50000);

	   /* If we still are here after 5 sec something is wrong. */
	   if (loop > 100)
	      break;
	}
   }

   if (EDebug(EDBUG_TYPE_SESSION))
      Eprintf("ExtInitWinMain exit\n");

   EDisplayClose();

   exit(0);
}