Пример #1
0
/*
 * This function sets up all of our connections to X
 */
void
SetupX(const char *dstr)
{
   int                 err;
   char                buf[128];
   unsigned int        mask;

   if (!dstr)
      dstr = getenv("DISPLAY");
   if (!dstr)
      dstr = ":0.0";

   /* Open a connection to the diplay nominated by the DISPLAY variable */
   err = EDisplayOpen(dstr, Dpy.screen);
   if (err)
     {
	Alert(_("Enlightenment cannot connect to the display nominated by\n"
		"your shell's DISPLAY environment variable. You may set this\n"
		"variable to indicate which display name Enlightenment is to\n"
		"connect to. It may be that you do not have an Xserver already\n"
		"running to serve that Display connection, or that you do not\n"
		"have permission to connect to that display. Please make sure\n"
		"all is correct before trying again. Run an Xserver by running\n"
		"xdm or startx first, or contact your local system\n"
		"administrator, or Xserver vendor, or read the X, xdm and\n"
		"startx manual pages before proceeding.\n"));
	EExit(1);
     }

   if (getenv("ESYNCHRONIZE"))
      XSynchronize(disp, True);

   Dpy.screens = ScreenCount(disp);
   Dpy.screen = DefaultScreen(disp);

   if (Mode.wm.master ||
       Mode.wm.master_screen < 0 || Mode.wm.master_screen >= Dpy.screens)
      Mode.wm.master_screen = Dpy.screen;

   /* Start up on multiple heads, if appropriate */
   if (Dpy.screens > 1 && !Mode.wm.single && !Mode.wm.restart)
     {
	int                 i;

	for (i = 0; i < Dpy.screens; i++)
	  {
	     pid_t               pid;

	     if (i == Dpy.screen)
		continue;

	     pid = fork();
	     if (pid)
	       {
		  /* We are the master */
		  Mode.wm.child_count++;
		  Mode.wm.children =
		     EREALLOC(pid_t, Mode.wm.children, Mode.wm.child_count);
		  Mode.wm.children[Mode.wm.child_count - 1] = pid;
	       }
	     else
	       {
		  /* We are a slave */
		  EDisplayDisconnect();
		  Mode.wm.master = 0;
		  Mode.wm.pid = getpid();
		  Dpy.screen = i;
		  ExtInitWinSet(NoXID);
#ifdef SIGSTOP
		  kill(getpid(), SIGSTOP);
#endif
		  EDisplayOpen(dstr, i);
		  /* Terminate the loop as I am the child process... */
		  break;
	       }
	  }
     }

   Dpy.name = Estrdup(DisplayString(disp));
   Esetenv("DISPLAY", Dpy.name);

   Dpy.pixel_black = BlackPixel(disp, Dpy.screen);
   Dpy.pixel_white = WhitePixel(disp, Dpy.screen);

   EDisplaySetErrorHandlers(EventShowError, HandleXIOError);

   /* Root defaults */
   RROOT = ERegisterWindow(DefaultRootWindow(disp), NULL);

   if (Mode.wm.window)
     {
	VROOT = ECreateWindow(RROOT, 0, 0, Mode.wm.win_w, Mode.wm.win_h, 0);

	/* Enable eesh and edox to pick up the virtual root */
	Esnprintf(buf, sizeof(buf), "%#x", WinGetXwin(VROOT));
	Esetenv("ENL_WM_ROOT", buf);
     }
   else
     {
	/* Running E normally on the root window */
	VROOT = RROOT;
     }

   Dpy.root_gc = EXCreateGC(WinGetXwin(VROOT), 0, NULL);

   /* Initialise event handling */
   EventsInit();

   /* select all the root window events to start managing */
   Dpy.last_error_code = 0;
   mask =
      StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask;
   ESelectInput(VROOT, mask);
   ESync(0);
   if (Dpy.last_error_code)
     {
	AlertX(_("Another Window Manager is already running"),
	       _("OK"), NULL, NULL,
	       _("Another Window Manager is already running.\n" "\n"
		 "You will have to quit your current Window Manager first before\n"
		 "you can successfully run Enlightenment.\n"));
	EExit(1);
     }

   mask |= ButtonPressMask | ButtonReleaseMask;
   ESelectInput(VROOT, mask);
   ESync(0);
   if (Dpy.last_error_code)
     {
	AlertX(_("Cannot select root window button press events"),
	       _("OK"), NULL, NULL,
	       _("Root window button actions will not work.\n"));
     }

   /* warn, if necessary about X version problems */
   if (ProtocolVersion(disp) != 11)
     {
	AlertX(_("X server version error"), _("Ignore this error"), "",
	       _("Quit Enlightenment"),
	       _("WARNING:\n"
		 "This is not an X11 Xserver. It in fact talks the X%i protocol.\n"
		 "This may mean Enlightenment will either not function, or\n"
		 "function incorrectly. If it is later than X11, then your\n"
		 "server is one the author of Enlightenment neither have\n"
		 "access to, nor have heard of.\n"), ProtocolVersion(disp));
     }

   /* damn that bloody numlock stuff - ok I'd rather XFree got fixed to not */
   /* have it as a modifier and everyone have to write specific code to mask */
   /* it out - but well.... */
   /* ok under Xfree Numlock and Scollock are lock modifiers and we need */
   /* to hunt them down to mask them out - EVIL EVIL EVIL hack but needed */
   {
      XModifierKeymap    *mod;
      EX_KeyCode          nl, sl;
      unsigned int        numlock, scrollock;
      int                 i;

      int                 masks[8] = {
	 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
	 Mod4Mask, Mod5Mask
      };

      numlock = scrollock = 0;
      mod = XGetModifierMapping(disp);
      nl = EKeysymToKeycode(XK_Num_Lock);
      sl = EKeysymToKeycode(XK_Scroll_Lock);
      if ((mod) && (mod->max_keypermod > 0))
	{
	   for (i = 0; i < (8 * mod->max_keypermod); i++)
	     {
		if ((nl) && (mod->modifiermap[i] == nl))
		   numlock = masks[i / mod->max_keypermod];
		else if ((sl) && (mod->modifiermap[i] == sl))
		   scrollock = masks[i / mod->max_keypermod];
	     }
	}
      Mode.masks.mod_combos[0] = 0;
      Mode.masks.mod_combos[1] = LockMask;
      if (numlock)
	{
	   Mode.masks.mod_combos[2] = numlock;
	   Mode.masks.mod_combos[5] = LockMask | numlock;
	}
      if (scrollock)
	{
	   Mode.masks.mod_combos[3] = scrollock;
	   Mode.masks.mod_combos[6] = LockMask | scrollock;
	}
      if (numlock && scrollock)
	{
	   Mode.masks.mod_combos[4] = numlock | scrollock;
	   Mode.masks.mod_combos[7] = LockMask | numlock | scrollock;
	}

      Mode.masks.mod_key_mask =
	 (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask |
	  Mod5Mask) & (~(numlock | scrollock | LockMask));

      if (mod)
	 XFreeModifiermap(mod);
   }

   ScreenInit();
}
Пример #2
0
Файл: main.c Проект: gzorin/e17
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;
   Mode.move.check = 1;

   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;
}