EventFdDesc * EventFdRegister(int fd, EventFdHandler * handler) { nfds++; pfds = EREALLOC(EventFdDesc, pfds, nfds); pfds[nfds - 1].fd = fd; pfds[nfds - 1].handler = handler; return pfds + (nfds - 1); }
int newRef() { // Increase space for the iorefs if (iorefs==NULL) { iorefs = (void**)(EMALLOC(sizeof(void*))); numrefs=1; } else { iorefs = (void**)(EREALLOC(iorefs, sizeof(void*)*(numrefs+1))); numrefs++; } return numrefs-1; }
static int EventsFetch(XEvent ** evq_p, int *evq_n) { int i, n, count; XEvent *evq = *evq_p, *ev; int qsz = *evq_n; /* Fetch the entire event queue */ for (i = count = 0; (n = XPending(disp)) > 0;) { count += n; if (count > qsz) { qsz = count; evq = EREALLOC(XEvent, evq, qsz); } ev = evq + i; for (; i < count; i++, ev++) { XNextEvent(disp, ev); #if USE_XI2 if (ev->type == GenericEvent) { if (ev->xcookie.extension == major_op_xi) EventFetchXI2(ev); continue; } #endif /* USE_XI2 */ /* Map some event types to E internals */ if (ev->type == event_base_shape + ShapeNotify) ev->type = EX_EVENT_SHAPE_NOTIFY; #if USE_XRANDR else if (ev->type == event_base_randr + RRScreenChangeNotify) ev->type = EX_EVENT_SCREEN_CHANGE_NOTIFY; #endif #if USE_COMPOSITE else if (ev->type == event_base_damage + XDamageNotify) ev->type = EX_EVENT_DAMAGE_NOTIFY; #endif #if USE_XSCREENSAVER else if (ev->type == event_base_saver + ScreenSaverNotify) ev->type = EX_EVENT_SAVER_NOTIFY; #endif } } EventsCompress(evq, count); *evq_p = evq; *evq_n = qsz; return count; }
static void quickhash_increase_hashtab_size(Hash * hash) { Int i; if (hash->hashtab_size > 40960) hash->hashtab_size += 40960; else hash->hashtab_size = hash->hashtab_size * 2 + MALLOC_DELTA; printf ("quick hash increase size: %d\n", hash->hashtab_size); hash->links = EREALLOC(hash->links, Int, hash->hashtab_size); hash->hashtab = EREALLOC(hash->hashtab, Int, hash->hashtab_size); memset(hash->links, -1, sizeof(Long)*hash->hashtab_size); memset(hash->hashtab, -1, sizeof(Long)*hash->hashtab_size); printf ("rehashing... "); fflush (stdout); for (i = 0; i < hash->keys->len; i++) quickhash_insert_key(hash, i); printf ("done.\n"); fflush (stdout); }
void EventCallbackRegister(Win win, EventCallbackFunc * func, void *prm) { EventCallbackItem *eci; if (!win) return; #if 0 Eprintf("EventCallbackRegister: %p %#lx: func=%p prm=%p\n", win, win->xwin, func, prm); #endif win->cbl.num++; win->cbl.lst = EREALLOC(EventCallbackItem, win->cbl.lst, win->cbl.num); eci = win->cbl.lst + win->cbl.num - 1; eci->func = func; eci->prm = prm; }
int newLock(int sem) { pthread_mutex_t m; pthread_mutex_init(&m, NULL); Mutex* newm = EMALLOC(sizeof(Mutex)); newm->m_id = m; // Increase space for the mutexes if (ms==NULL) { ms = (Mutex**)EMALLOC(sizeof(Mutex*)); mutexes=1; } else { ms = (Mutex**)(EREALLOC(ms, sizeof(Mutex*)*(mutexes+1))); mutexes++; } ms[mutexes-1] = newm; return mutexes-1; }
int EShapePropagate(Win win) { Win xch; unsigned int num_rects; int k, rn; int x, y, w, h; XRectangle *rects, *rectsn, *rl; if (!win || win->w <= 0 || win->h <= 0) return 0; #if DEBUG_SHAPE_PROPAGATE Eprintf("EShapePropagate %#lx %d,%d %dx%d\n", win->xwin, win->x, win->y, win->w, win->h); #endif num_rects = 0; rects = NULL; /* go through all child windows and create/inset spans */ for (xch = win_first; xch; xch = xch->next) { if (xch->parent != win) continue; #if DEBUG_SHAPE_PROPAGATE > 1 Eprintf("%#lx(%d): %4d,%4d %4dx%4d\n", xch->xwin, xch->mapped, xch->x, xch->y, xch->w, xch->h); #endif if (!xch->mapped) continue; x = xch->x; y = xch->y; w = xch->w; h = xch->h; if (x >= win->w || y >= win->h || x + w < 0 || y + h < 0) continue; rn = xch->num_rect; if (rn > 0) { rl = xch->rects; rectsn = EREALLOC(XRectangle, rects, num_rects + rn); if (!rectsn) goto bail_out; rects = rectsn; /* go through all clip rects in thsi window's shape */ for (k = 0; k < rn; k++) { /* for each clip rect, add it to the rect list */ rects[num_rects + k].x = x + rl[k].x; rects[num_rects + k].y = y + rl[k].y; rects[num_rects + k].width = rl[k].width; rects[num_rects + k].height = rl[k].height; #if DEBUG_SHAPE_PROPAGATE > 1 Eprintf(" - %d: %4d,%4d %4dx%4d\n", k, rects[num_rects + k].x, rects[num_rects + k].y, rects[num_rects + k].width, rects[num_rects + k].height); #endif } num_rects += rn; } else if (rn == 0) { /* Unshaped */ rectsn = EREALLOC(XRectangle, rects, num_rects + 1); if (!rectsn) goto bail_out; rects = rectsn; rects[num_rects].x = x; rects[num_rects].y = y; rects[num_rects].width = w; rects[num_rects].height = h; num_rects++; } } #if DEBUG_SHAPE_PROPAGATE EShapeShow("EShapePropagate", win->xwin, rects, num_rects); #endif /* set the rects as the shape mask */ if (rects) { EShapeCombineRectangles(win, ShapeBounding, 0, 0, rects, num_rects, ShapeSet, Unsorted); Efree(rects); } else { /* Empty shape */ EShapeCombineRectangles(win, ShapeBounding, 0, 0, NULL, 0, ShapeSet, Unsorted); } return win->num_rect; bail_out: Efree(rects); EShapeCombineMask(win, ShapeBounding, 0, 0, None, ShapeSet); return 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(); }
void WarpFocus(int delta) { WarpFocusWin *fw = warpFocusWindow; EWin *const *lst; EWin *ewin; int i, num; WarplistItem *wl; /* Remember invoking keycode (ugly hack) */ if (!fw || !EoIsShown(fw)) { warpFocusKey = Mode.events.last_keycode; warpFocusState = Mode.events.last_keystate; } if (!warplist) { warplist_num = 0; /* Not necessary but silences clang */ lst = EwinListFocusGet(&num); for (i = 0; i < num; i++) { ewin = lst[i]; if ( /* Either visible or iconified */ ((EwinIsOnScreen(ewin)) || (ewin->state.iconified) || (Conf.warplist.showalldesks)) && /* Exclude windows that explicitely say so */ (!ewin->props.skip_focuslist) && (!ewin->props.skip_ext_task) && /* Keep shaded windows if conf say so */ ((!ewin->state.shaded) || (Conf.warplist.showshaded)) && /* Keep sticky windows if conf say so */ ((!EoIsSticky(ewin)) || (Conf.warplist.showsticky)) && /* Keep iconified windows if conf say so */ ((!ewin->state.iconified) || (Conf.warplist.showiconified))) { warplist_num++; warplist = EREALLOC(WarplistItem, warplist, warplist_num); wl = warplist + warplist_num - 1; wl->ewin = ewin; } } /* Hmmm. Hack... */ if (warplist_num >= 2 && warplist[1].ewin == GetFocusEwin()) { warplist[1].ewin = warplist[0].ewin; warplist[0].ewin = GetFocusEwin(); } warpFocusIndex = 0; } if (!warplist) return; warpFocusIndex = (warpFocusIndex + warplist_num + delta) % warplist_num; ewin = warplist[warpFocusIndex].ewin; if (!EwinFindByPtr(ewin)) ewin = NULL; if (!ewin) return; WarpFocusShow(); if (!EwinIsOnScreen(ewin)) return; if (Conf.warplist.show_shape) WarpShapeDraw(ewin); if (Conf.focus.raise_on_next) EwinRaise(ewin); if (Conf.focus.warp_on_next) EwinWarpTo(ewin, 0); if (Conf.warplist.warpfocused) FocusToEWin(ewin, FOCUS_SET); }