Exemplo n.º 1
0
void WMFreeMaskedEvents(WMMaskedEvents* maskev) {
  W_MaskedEvents* mask = (W_MaskedEvents*)maskev;
  WMFreeArray(mask->procs);
  WMFreeArray(mask->data);
  wfree(mask);
  return;
}
Exemplo n.º 2
0
Bool
W_CheckIdleHandlers(void)
{
    IdleHandler *handler;
    WMArray *handlerCopy;
    WMArrayIterator iter;

    if (!idleHandler || WMGetArrayItemCount(idleHandler)==0) {
        W_FlushIdleNotificationQueue();
        /* make sure an observer in queue didn't added an idle handler */
        return (idleHandler!=NULL && WMGetArrayItemCount(idleHandler)>0);
    }

    handlerCopy = WMDuplicateArray(idleHandler);

    WM_ITERATE_ARRAY(handlerCopy, handler, iter) {
        /* check if the handler still exist or was removed by a callback */
        if (WMGetFirstInArray(idleHandler, handler) == WANotFound)
            continue;

        (*handler->callback)(handler->clientData);
        WMDeleteIdleHandler(handler);
    }

    WMFreeArray(handlerCopy);

    W_FlushIdleNotificationQueue();

    /* this is not necesarrily False, because one handler can re-add itself */
    return (WMGetArrayItemCount(idleHandler)>0);
}
Exemplo n.º 3
0
static void makeShortcutCommand(WMenu * menu, WMenuEntry * entry)
{
	WWindow *wwin = (WWindow *) entry->clientdata;
	WScreen *scr = wwin->screen_ptr;
	int index = entry->order - wlengthof(menu_options_entries);

	/* Parameter not used, but tell the compiler that it is ok */
	(void) menu;

	if (scr->shortcutWindows[index]) {
		WMFreeArray(scr->shortcutWindows[index]);
		scr->shortcutWindows[index] = NULL;
	}

	if (wwin->flags.selected && scr->selected_windows) {
		scr->shortcutWindows[index] = WMDuplicateArray(scr->selected_windows);
		/*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
		   WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
	} else {
		scr->shortcutWindows[index] = WMCreateArray(4);
		WMAddToArray(scr->shortcutWindows[index], wwin);
	}

	wSelectWindow(wwin, !wwin->flags.selected);
	XFlush(dpy);
	wusleep(3000);
	wSelectWindow(wwin, !wwin->flags.selected);
	XFlush(dpy);
}
Exemplo n.º 4
0
/*
 * WMArray *array;
 * WDMCheckPLArray(pl, spec, &array);
 */
Bool WDMCheckPLArray(WMPropList * pl, void *def, void *target)
{
	WMArray **array_target = (WMArray **) target;
	WDMArraySpec *spec = (WDMArraySpec *) def;
	void *entry = NULL;
	int i, count;

	WDMDebug("WDMCheckPLArray(%p, %p, %p)\n", (void *)pl, def, target);
	if (!pl || !WMIsPLArray(pl))
		return False;

	count = WMGetPropListItemCount(pl);
	*array_target = WMCreateArrayWithDestructor(count, spec->destructor);

	for (i = 0; i < count; ++i) {
		if (!(*spec->checker) (WMGetFromPLArray(pl, i), spec->data, &entry)) {
			WMFreeArray(*array_target);
			*array_target = NULL;
			return False;
		}
		if (spec->addnull == True || entry != NULL) {
			WMAddToArray(*array_target, entry);
		}
	}

	return True;
}
Exemplo n.º 5
0
static void destroySplitView(WMSplitView * sPtr)
{
	WMFreeArray(sPtr->subviews);

	WMRemoveNotificationObserver(sPtr);

	wfree(sPtr);
}
Exemplo n.º 6
0
static void destroyNode(void *data)
{
	WMTreeNode *aNode = (WMTreeNode *) data;

	if (aNode->destructor) {
		(*aNode->destructor) (aNode->data);
	}
	if (aNode->leaves) {
		WMFreeArray(aNode->leaves);
	}
	wfree(aNode);
}
Exemplo n.º 7
0
static void releasePropListByCount(WMPropList * plist, int count)
{
	WMPropList *key, *value;
	WMHashEnumerator e;
	int i;

	plist->retainCount -= count;

	switch (plist->type) {
	case WPLString:
		if (plist->retainCount < 1) {
			wfree(plist->d.string);
			wfree(plist);
		}
		break;
	case WPLData:
		if (plist->retainCount < 1) {
			WMReleaseData(plist->d.data);
			wfree(plist);
		}
		break;
	case WPLArray:
		for (i = 0; i < WMGetArrayItemCount(plist->d.array); i++) {
			releasePropListByCount(WMGetFromArray(plist->d.array, i), count);
		}
		if (plist->retainCount < 1) {
			WMFreeArray(plist->d.array);
			wfree(plist);
		}
		break;
	case WPLDictionary:
		e = WMEnumerateHashTable(plist->d.dict);
		while (WMNextHashEnumeratorItemAndKey(&e, (void **)&value, (void **)&key)) {
			releasePropListByCount(key, count);
			releasePropListByCount(value, count);
		}
		if (plist->retainCount < 1) {
			WMFreeHashTable(plist->d.dict);
			wfree(plist);
		}
		break;
	default:
		wwarning(_("Used proplist functions on non-WMPropLists objects"));
		wassertr(False);
		break;
	}
}
Exemplo n.º 8
0
/*
 * This functions will handle input events on all registered file descriptors.
 * Input:
 *    - waitForInput - True if we want the function to wait until an event
 *                     appears on a file descriptor we watch, False if we
 *                     want the function to immediately return if there is
 *                     no data available on the file descriptors we watch.
 *    - inputfd      - Extra input file descriptor to watch for input.
 *                     This is only used when called from wevent.c to watch
 *                     on ConnectionNumber(dpy) to avoid blocking of X events
 *                     if we wait for input from other file handlers.
 * Output:
 *    if waitForInput is False, the function will return False if there are no
 *                     input handlers registered, or if there is no data
 *                     available on the registered ones, and will return True
 *                     if there is at least one input handler that has data
 *                     available.
 *    if waitForInput is True, the function will return False if there are no
 *                     input handlers registered, else it will block until an
 *                     event appears on one of the file descriptors it watches
 *                     and then it will return True.
 *
 * If the retured value is True, the input handlers for the corresponding file
 * descriptors are also called.
 *
 * Parametersshould be passed like this:
 * - from wevent.c:
 *   waitForInput - apropriate value passed by the function who called us
 *   inputfd = ConnectionNumber(dpy)
 * - from wutil.c:
 *   waitForInput - apropriate value passed by the function who called us
 *   inputfd = -1
 *
 */
Bool
W_HandleInputEvents(Bool waitForInput, int inputfd)
{
#if defined(HAVE_POLL) && defined(HAVE_POLL_H) && !defined(HAVE_SELECT)
    struct poll fd *fds;
    InputHandler *handler;
    int count, timeout, nfds, i, extrafd;

    extrafd = (inputfd < 0) ? 0 : 1;

    if (inputHandler)
        nfds = WMGetArrayItemCount(inputHandler);
    else
        nfds = 0;

    if (!extrafd && nfds==0) {
        W_FlushASAPNotificationQueue();
        return False;
    }

    fds = wmalloc((nfds+extrafd) * sizeof(struct pollfd));
    if (extrafd) {
        /* put this to the end of array to avoid using ranges from 1 to nfds+1 */
        fds[nfds].fd = inputfd;
        fds[nfds].events = POLLIN;
    }

    /* use WM_ITERATE_ARRAY() here */
    for (i = 0; i<nfds; i++) {
        handler = WMGetFromArray(inputHandler, i);
        fds[i].fd = handler->fd;
        fds[i].events = 0;
        if (handler->mask & WIReadMask)
            fds[i].events |= POLLIN;

        if (handler->mask & WIWriteMask)
            fds[i].events |= POLLOUT;

#if 0 /* FIXME */
        if (handler->mask & WIExceptMask)
            FD_SET(handler->fd, &eset);
#endif
    }

    /*
     * Setup the timeout to the estimated time until the
     * next timer expires.
     */
    if (!waitForInput) {
        timeout = 0;
    } else if (timerPending()) {
        struct timeval tv;
        delayUntilNextTimerEvent(&tv);
        timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000;
    } else {
        timeout = -1;
    }

    count = poll(fds, nfds+extrafd, timeout);

    if (count>0 && nfds>0) {
        WMArray *handlerCopy = WMDuplicateArray(inputHandler);
        int mask;

        /* use WM_ITERATE_ARRAY() here */
        for (i=0; i<nfds; i++) {
            handler = WMGetFromArray(handlerCopy, i);
            /* check if the handler still exist or was removed by a callback */
            if (WMGetFirstInArray(inputHandler, handler) == WANotFound)
                continue;

            mask = 0;

            if ((handler->mask & WIReadMask) &&
                (fds[i].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI)))
                mask |= WIReadMask;

            if ((handler->mask & WIWriteMask) &&
                (fds[i].revents & (POLLOUT | POLLWRBAND)))
                mask |= WIWriteMask;

            if ((handler->mask & WIExceptMask) &&
                (fds[i].revents & (POLLHUP | POLLNVAL | POLLERR)))
                mask |= WIExceptMask;

            if (mask!=0 && handler->callback) {
                (*handler->callback)(handler->fd, mask,
                                     handler->clientData);
            }
        }

        WMFreeArray(handlerCopy);
    }

    wfree(fds);

    W_FlushASAPNotificationQueue();

    return (count > 0);
#else
#ifdef HAVE_SELECT
    struct timeval timeout;
    struct timeval *timeoutPtr;
    fd_set rset, wset, eset;
    int maxfd, nfds, i;
    int count;
    InputHandler *handler;

    if (inputHandler)
        nfds = WMGetArrayItemCount(inputHandler);
    else
        nfds = 0;

    if (inputfd<0 && nfds==0) {
        W_FlushASAPNotificationQueue();
        return False;
    }

    FD_ZERO(&rset);
    FD_ZERO(&wset);
    FD_ZERO(&eset);

    if (inputfd < 0) {
        maxfd = 0;
    } else {
        FD_SET(inputfd, &rset);
        maxfd = inputfd;
    }

    /* use WM_ITERATE_ARRAY() here */
    for (i=0; i<nfds; i++) {
        handler = WMGetFromArray(inputHandler, i);
        if (handler->mask & WIReadMask)
            FD_SET(handler->fd, &rset);

        if (handler->mask & WIWriteMask)
            FD_SET(handler->fd, &wset);

        if (handler->mask & WIExceptMask)
            FD_SET(handler->fd, &eset);

        if (maxfd < handler->fd)
            maxfd = handler->fd;
    }

    /*
     * Setup the timeout to the estimated time until the
     * next timer expires.
     */
    if (!waitForInput) {
        SET_ZERO(timeout);
        timeoutPtr = &timeout;
    } else if (timerPending()) {
        delayUntilNextTimerEvent(&timeout);
        timeoutPtr = &timeout;
    } else {
        timeoutPtr = (struct timeval*)0;
    }

    count = select(1 + maxfd, &rset, &wset, &eset, timeoutPtr);

    if (count>0 && nfds>0) {
        WMArray *handlerCopy = WMDuplicateArray(inputHandler);
        int mask;

        /* use WM_ITERATE_ARRAY() here */
        for (i=0; i<nfds; i++) {
            handler = WMGetFromArray(handlerCopy, i);
            /* check if the handler still exist or was removed by a callback */
            if (WMGetFirstInArray(inputHandler, handler) == WANotFound)
                continue;

            mask = 0;

            if ((handler->mask & WIReadMask) && FD_ISSET(handler->fd, &rset))
                mask |= WIReadMask;

            if ((handler->mask & WIWriteMask) && FD_ISSET(handler->fd, &wset))
                mask |= WIWriteMask;

            if ((handler->mask & WIExceptMask) && FD_ISSET(handler->fd, &eset))
                mask |= WIExceptMask;

            if (mask!=0 && handler->callback) {
                (*handler->callback)(handler->fd, mask,
                                     handler->clientData);
            }
        }

        WMFreeArray(handlerCopy);
    }

    W_FlushASAPNotificationQueue();

    return (count > 0);
#else /* not HAVE_SELECT, not HAVE_POLL */
# error   Neither select nor poll. You lose.
#endif /* HAVE_SELECT */
#endif /* HAVE_POLL */
}
Exemplo n.º 9
0
WMArray *WMGetBrowserPaths(WMBrowser * bPtr)
{
	int column, i, k, size, selNo;
	char *path;
	size_t slen;
	WMListItem *item, *lastItem;
	WMArray *paths, *items;

	column = bPtr->usedColumnCount - 1;

	if (column < 0) {
		paths = WMCreateArrayWithDestructor(1, wfree);
		WMAddToArray(paths, wstrdup(bPtr->pathSeparator));
		return paths;
	}

	items = WMGetListSelectedItems(bPtr->columns[column]);
	selNo = WMGetArrayItemCount(items);
	paths = WMCreateArrayWithDestructor(selNo, wfree);

	if (selNo <= 1) {
		WMAddToArray(paths, WMGetBrowserPath(bPtr));
		return paths;
	}

	/* calculate size of buffer */
	size = 0;
	for (i = 0; i < column; i++) {
		item = WMGetListSelectedItem(bPtr->columns[i]);
		if (!item)
			break;
		size += strlen(item->text);
	}

	size += (column + 1) * strlen(bPtr->pathSeparator) + 1;

	for (k = 0; k < selNo; k++) {
		/* get the path */
		lastItem = WMGetFromArray(items, k);
		slen = size + (lastItem != NULL ? strlen(lastItem->text) : 0);
		path = wmalloc(slen);
		/* ignore first `/' */
		for (i = 0; i <= column; i++) {
			if (wstrlcat(path, bPtr->pathSeparator, slen) >= slen) {
				wfree(path);
				WMFreeArray(paths);
				return NULL;
			}
			if (i == column) {
				item = lastItem;
			} else {
				item = WMGetListSelectedItem(bPtr->columns[i]);
			}
			if (!item)
				break;
			if (wstrlcat(path, item->text, slen) >= slen) {
				wfree(path);
				return NULL;
			}
		}
		WMAddToArray(paths, path);
	}

	return paths;
}
Exemplo n.º 10
0
static void destroyView(W_View * view)
{
	W_View *ptr;

	if (view->flags.alreadyDead)
		return;
	view->flags.alreadyDead = 1;

	/* delete the balloon text for the view, if there's any */
	WMSetBalloonTextForView(NULL, view);

	if (view->nextFocusChain)
		view->nextFocusChain->prevFocusChain = view->prevFocusChain;
	if (view->prevFocusChain)
		view->prevFocusChain->nextFocusChain = view->nextFocusChain;

	/* Do not leave focus in a inexisting control */
	if (W_FocusedViewOfToplevel(W_TopLevelOfView(view)) == view)
		W_SetFocusOfTopLevel(W_TopLevelOfView(view), NULL);

	if (view->flags.topLevel) {
		W_FocusInfo *info = view->screen->focusInfo;
		/* remove focus information associated to this toplevel */

		if (info) {
			if (info->toplevel == view) {
				view->screen->focusInfo = info->next;
				wfree(info);
			} else {
				while (info->next) {
					if (info->next->toplevel == view)
						break;
					info = info->next;
				}
				if (info->next) {
					W_FocusInfo *next = info->next->next;
					wfree(info->next);
					info->next = next;
				}
				/* else the toplevel did not have any focused subview */
			}
		}
	}

	/* destroy children recursively */
	while (view->childrenList != NULL) {
		ptr = view->childrenList;
		ptr->flags.parentDying = 1;

		W_DestroyView(ptr);

		if (ptr == view->childrenList) {
			view->childrenList = ptr->nextSister;
			ptr->parent = NULL;
		}
	}

	W_CallDestroyHandlers(view);

	if (view->flags.realized) {
		XDeleteContext(view->screen->display, view->window, ViewContext);

		/* if parent is being destroyed, it will die naturaly */
		if (!view->flags.parentDying || view->flags.topLevel)
			XDestroyWindow(view->screen->display, view->window);
	}

	/* remove self from parent's children list */
	unparentView(view);

	/* the array has a wfree() destructor that will be called automatically */
	WMFreeArray(view->eventHandlers);
	view->eventHandlers = NULL;

	WMRemoveNotificationObserver(view);

	W_FreeViewXdndPart(view);

	if (view->backColor)
		WMReleaseColor(view->backColor);

	wfree(view);
}
Exemplo n.º 11
0
static void destroyBox(Box * bPtr)
{
	WMFreeArray(bPtr->subviews);
	wfree(bPtr);
}