2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2008 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #include <X11/keysym.h>
36 SessionExit(EEXIT_ERROR, NULL);
40 * This function sets up all of our connections to X
43 SetupX(const char *dstr)
50 dstr = getenv("DISPLAY");
54 /* Open a connection to the diplay nominated by the DISPLAY variable */
55 err = EDisplayOpen(dstr, Dpy.screen);
58 Alert(_("Enlightenment cannot connect to the display nominated by\n"
59 "your shell's DISPLAY environment variable. You may set this\n"
60 "variable to indicate which display name Enlightenment is to\n"
61 "connect to. It may be that you do not have an Xserver already\n"
62 "running to serve that Display connection, or that you do not\n"
63 "have permission to connect to that display. Please make sure\n"
64 "all is correct before trying again. Run an Xserver by running\n"
65 "xdm or startx first, or contact your local system\n"
66 "administrator, or Xserver vendor, or read the X, xdm and\n"
67 "startx manual pages before proceeding.\n"));
71 if (getenv("ESYNCHRONIZE"))
72 XSynchronize(disp, True);
74 Dpy.screens = ScreenCount(disp);
75 Dpy.screen = DefaultScreen(disp);
78 Mode.wm.master_screen < 0 || Mode.wm.master_screen >= Dpy.screens)
79 Mode.wm.master_screen = Dpy.screen;
81 /* Start up on multiple heads, if appropriate */
82 if (Dpy.screens > 1 && !Mode.wm.single && !Mode.wm.restart)
86 for (i = 0; i < Dpy.screens; i++)
96 /* We are the master */
97 Mode.wm.child_count++;
99 EREALLOC(pid_t, Mode.wm.children, Mode.wm.child_count);
100 Mode.wm.children[Mode.wm.child_count - 1] = pid;
105 EDisplayDisconnect();
107 Mode.wm.pid = getpid();
111 kill(getpid(), SIGSTOP);
113 EDisplayOpen(dstr, i);
114 /* Terminate the loop as I am the child process... */
120 Dpy.name = Estrdup(DisplayString(disp));
121 Esetenv("DISPLAY", Dpy.name);
123 Dpy.pixel_black = BlackPixel(disp, Dpy.screen);
124 Dpy.pixel_white = WhitePixel(disp, Dpy.screen);
126 EDisplaySetErrorHandlers(HandleXIOError);
129 RROOT = ERegisterWindow(DefaultRootWindow(disp), NULL);
133 VROOT = ECreateWindow(RROOT, 0, 0, Mode.wm.win_w, Mode.wm.win_h, 0);
135 /* Enable eesh and edox to pick up the virtual root */
136 Esnprintf(buf, sizeof(buf), "%#lx", WinGetXwin(VROOT));
137 Esetenv("ENL_WM_ROOT", buf);
141 /* Running E normally on the root window */
145 /* Initialise event handling */
148 /* select all the root window events to start managing */
149 Dpy.last_error_code = 0;
151 StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask;
152 ESelectInput(VROOT, mask);
154 if (Dpy.last_error_code)
156 AlertX(_("Another Window Manager is already running"),
158 _("Another Window Manager is already running.\n" "\n"
159 "You will have to quit your current Window Manager first before\n"
160 "you can successfully run Enlightenment.\n"));
164 /* warn, if necessary about X version problems */
165 if (ProtocolVersion(disp) != 11)
167 AlertX(_("X server version error"), _("Ignore this error"), "",
168 _("Quit Enlightenment"),
170 "This is not an X11 Xserver. It in fact talks the X%i protocol.\n"
171 "This may mean Enlightenment will either not function, or\n"
172 "function incorrectly. If it is later than X11, then your\n"
173 "server is one the author of Enlightenment neither have\n"
174 "access to, nor have heard of.\n"), ProtocolVersion(disp));
177 /* damn that bloody numlock stuff - ok I'd rather XFree got fixed to not */
178 /* have it as a modifier and everyone have to write specific code to mask */
179 /* it out - but well.... */
180 /* ok under Xfree Numlock and Scollock are lock modifiers and we need */
181 /* to hunt them down to mask them out - EVIL EVIL EVIL hack but needed */
183 XModifierKeymap *mod;
185 unsigned int numlock, scrollock;
188 ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask,
192 numlock = scrollock = 0;
193 mod = XGetModifierMapping(disp);
194 nl = EKeysymToKeycode(XK_Num_Lock);
195 sl = EKeysymToKeycode(XK_Scroll_Lock);
196 if ((mod) && (mod->max_keypermod > 0))
198 for (i = 0; i < (8 * mod->max_keypermod); i++)
200 if ((nl) && (mod->modifiermap[i] == nl))
201 numlock = masks[i / mod->max_keypermod];
202 else if ((sl) && (mod->modifiermap[i] == sl))
203 scrollock = masks[i / mod->max_keypermod];
206 Mode.masks.mod_combos[0] = 0;
207 Mode.masks.mod_combos[1] = LockMask;
210 Mode.masks.mod_combos[2] = numlock;
211 Mode.masks.mod_combos[5] = LockMask | numlock;
215 Mode.masks.mod_combos[3] = scrollock;
216 Mode.masks.mod_combos[6] = LockMask | scrollock;
218 if (numlock && scrollock)
220 Mode.masks.mod_combos[4] = numlock | scrollock;
221 Mode.masks.mod_combos[7] = LockMask | numlock | scrollock;
224 Mode.masks.mod_key_mask =
225 (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask |
226 Mod5Mask) & (~(numlock | scrollock | LockMask));
229 XFreeModifiermap(mod);