Пример #1
0
WMMaskedEvents* WMMaskEvents(WMView* view) {
  W_MaskedEvents *mask;
  unsigned int i;
  Bool changed = False;

  mask = wmalloc(sizeof(W_MaskedEvents));
  mask->view = view;
  mask->procs = WMCreateArray(0);
  mask->data = WMCreateArray(0);

  for (i = 0; i < WMGetArrayItemCount(W_GetViewEventHandlers(view)); i++) {
    W_EventHandler *h = (W_EventHandler*) WMGetFromArray(W_GetViewEventHandlers(view), i);
    if (h->eventMask == (ButtonPressMask|ButtonReleaseMask|
                        EnterWindowMask|LeaveWindowMask|ButtonMotionMask)) {
      WMAddToArray(mask->procs, h->proc);
      WMAddToArray(mask->data, h->clientData);

      /* we change only the first handler to our one, because they seem
         to be processed upside-down and we want the dnd-handler to be processed
         first. */
      if (changed == False) {
        h->proc = W_MaskedEventHandler;
        h->clientData = (void*) mask;
        changed = True;
      } else {
        WMDeleteEventHandler(view, h->eventMask, h->proc, h->clientData);
      }
    }
  }

  return mask;
}
Пример #2
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);
}
Пример #3
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;
}
Пример #4
0
void WMAddSplitViewSubview(WMSplitView * sPtr, WMView * subview)
{
	int wasMapped, count;
	W_SplitViewSubview *p;

	CHECK_CLASS(sPtr, WC_SplitView);

	p = (W_SplitViewSubview *) wmalloc(sizeof(W_SplitViewSubview));
	if (!p)
		return;

	wasMapped = subview->flags.mapped;
	if (wasMapped)
		W_UnmapView(subview);

	count = _GetSubviewsCount();
	p->view = subview;
	getConstraints(sPtr, count, &(p->minSize), &(p->maxSize));
	if (sPtr->flags.vertical)
		p->size = subview->size.width;
	else
		p->size = subview->size.height;

	WMAddToArray(sPtr->subviews, p);
	reparentView(sPtr, subview, 0);

	/*
	   We should have something like that...

	   WMSetViewNotifySizeChanges(subview, True);
	   WMAddNotificationObserver(handleSubviewResized, sPtr,
	   WMViewSizeDidChangeNotification,
	   subview);
	   WMSetViewNotifyMoveChanges(subview, True);
	   WMAddNotificationObserver(handleSubviewResized, sPtr,
	   WMViewMoveDidChangeNotification,
	   subview);
	 */
	if (wasMapped) {
		W_MapView(subview);

		sPtr->flags.adjustOnPaint = 1;
		paintSplitView(sPtr);
	} else {
		handleViewResized(sPtr, NULL);
	}
}
Пример #5
0
/*
 * This function will check if pl is string or array of strings.
 * It always returns WMArray. In case of string, new array will be
 * created and that string will be added to it.
 * def is ignored here.
 */
Bool WDMCheckPLStringOrArray(WMPropList * pl, void *def, void *target)
{
	char *text;
	WMArray **array_target = (WMArray **) target;
	static WDMArraySpec array_of_strings = { WDMCheckPLString, NULL, wfree, False };

	if (pl && WMIsPLString(pl)) {
		if (WDMCheckPLString(pl, NULL, &text) && text) {
			*array_target = WMCreateArrayWithDestructor(1, wfree);

			WMAddToArray(*array_target, text);

			return True;
		}
	}
	return WDMCheckPLArray(pl, &array_of_strings, target);
}
Пример #6
0
void WMAddBoxSubviewAtEnd(WMBox * bPtr, WMView * view, Bool expand, Bool fill, int minSize, int maxSize, int space)
{
	SubviewItem *subView;

	subView = wmalloc(sizeof(SubviewItem));
	subView->view = view;
	subView->minSize = minSize;
	subView->maxSize = maxSize;
	subView->expand = expand;
	subView->fill = fill;
	subView->space = space;
	subView->end = 1;

	WMAddToArray(bPtr->subviews, subView);

	rearrange(bPtr);
}
Пример #7
0
WMHandlerID
WMAddInputHandler(int fd, int condition, WMInputProc *proc, void *clientData)
{
    InputHandler *handler;

    handler = wmalloc(sizeof(InputHandler));

    handler->fd = fd;
    handler->mask = condition;
    handler->callback = proc;
    handler->clientData = clientData;

    if (!inputHandler)
        inputHandler = WMCreateArrayWithDestructor(16, wfree);
    WMAddToArray(inputHandler, handler);

    return handler;
}
Пример #8
0
WMTreeNode *WMInsertNodeInTree(WMTreeNode * parent, int index, WMTreeNode * aNode)
{
	wassertrv(parent != NULL, NULL);
	wassertrv(aNode != NULL, NULL);

	aNode->parent = parent;
	updateNodeDepth(aNode, parent->depth + 1);
	if (!parent->leaves) {
		parent->leaves = WMCreateArrayWithDestructor(1, destroyNode);
	}
	if (index < 0) {
		WMAddToArray(parent->leaves, aNode);
	} else {
		WMInsertInArray(parent->leaves, index, aNode);
	}

	return aNode;
}
Пример #9
0
WMHandlerID
WMAddIdleHandler(WMCallback *callback, void *cdata)
{
    IdleHandler *handler;

    handler = malloc(sizeof(IdleHandler));
    if (!handler)
        return NULL;

    handler->callback = callback;
    handler->clientData = cdata;
    /* add handler at end of queue */
    if (!idleHandler) {
        idleHandler = WMCreateArrayWithDestructor(16, wfree);
    }
    WMAddToArray(idleHandler, handler);

    return handler;
}
Пример #10
0
WMTreeNode *WMInsertItemInTree(WMTreeNode * parent, int index, void *item)
{
	WMTreeNode *aNode;

	wassertrv(parent != NULL, NULL);

	aNode = WMCreateTreeNodeWithDestructor(item, parent->destructor);
	aNode->parent = parent;
	aNode->depth = parent->depth + 1;
	if (!parent->leaves) {
		parent->leaves = WMCreateArrayWithDestructor(1, destroyNode);
	}
	if (index < 0) {
		WMAddToArray(parent->leaves, aNode);
	} else {
		WMInsertInArray(parent->leaves, index, aNode);
	}

	return aNode;
}
Пример #11
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;
}
Пример #12
0
int main(int argc, char **argv)
{
	struct stat st;
	int i;
	int *previousDepth;

	prog_name = argv[0];
	plMenuNodes = WMCreateArray(8); /* grows on demand */
	menu = (WMTreeNode *)NULL;
	parse = NULL;
	validateFilename = NULL;

	/* assemblePLMenuFunc passes this around */
	previousDepth = (int *)wmalloc(sizeof(int));
	*previousDepth = -1;

	/* currently this is used only by the xdg parser, but it might be useful
	 * in the future localizing other menus, so it won't hurt to have it here.
	 */
	parse_locale(NULL, &env_lang, &env_ctry, &env_enc, &env_mod);
	terminal = find_terminal_emulator();

	for (i = 1; i < argc; i++)
	{
		if (strncmp(argv[i], "-parser", 7) == 0 &&
		    (argv[i][7] == '=' ||
		     argv[i][7] == ':' || /* for legacy compatibility */
		     argv[i][7] == '\0')) {
			const char *name;

			if (argv[i][7] == '\0') {
				if (++i > argc) {
					fprintf(stderr, "%s: Missing parser name after \"-parser\"\n", prog_name);
					return 2;
				}
				name = argv[i];
			} else {
				name = argv[i] + 8;
			}

			if (strcmp(name, "xdg") == 0) {
				parse = &parse_xdg;
			} else if (strcmp(name, "wmconfig") == 0) {
				parse = &parse_wmconfig;
				validateFilename = &wmconfig_validate_file;
			} else {
				fprintf(stderr, "%s: Unknown parser \"%s\"\n", prog_name, name);
				return 2;
			}
			continue;
		}

		if (strcmp(argv[i], "--version") == 0) {
			printf("%s (Window Maker %s)\n", prog_name, VERSION);
			return 0;
		}

		if (strcmp(argv[i], "-h") == 0 ||
		    strcmp(argv[i], "-help") == 0 ||
		    strcmp(argv[i], "--help") == 0) {
			print_help();
			return 0;
		}

		if (parse == NULL) {
			fprintf(stderr, "%s: argument \"%s\" with no valid parser\n", prog_name, argv[i]);
			return 2;
		}

#if DEBUG
		fprintf(stderr, "%s: Using parser \"%s\" to process \"%s\"\n",
		        prog_name, get_parser_name(), argv[i]);
#endif

		if (stat(argv[i], &st) == -1) {
			fprintf(stderr, "%s: unable to stat \"%s\", %s\n",
			        prog_name, argv[i], strerror(errno));
			return 1;
		} else if (S_ISREG(st.st_mode)) {
			parse(argv[i], addWMMenuEntryCallback);
		} else if (S_ISDIR(st.st_mode)) {
			nftw(argv[i], dirParseFunc, 16, FTW_PHYS);
		} else {
			fprintf(stderr, "%s: \"%s\" is not a file or directory\n", prog_name, argv[i]);
			return 1;
		}
	}

	if (!menu) {
		fprintf(stderr, "%s: parsers failed to create a valid menu\n", prog_name);
		return 1;
	}

	WMSortTree(menu, menuSortFunc);
	WMTreeWalk(menu, assemblePLMenuFunc, previousDepth, True);

	i = WMGetArrayItemCount(plMenuNodes);
	if (i > 2) { /* more than one submenu unprocessed is almost certainly an error */
		fprintf(stderr, "%s: unprocessed levels on the stack. fishy.\n", prog_name);
		return 3;
	} else if (i > 1 ) { /* possibly the top-level attachment is not yet done */
		WMPropList *first, *next;

		next = WMPopFromArray(plMenuNodes);
		first = WMPopFromArray(plMenuNodes);
		WMAddToPLArray(first, next);
		WMAddToArray(plMenuNodes, first);
	}

	puts(WMGetPropListDescription((WMPropList *)WMGetFromArray(plMenuNodes, 0), True));

	return 0;
}
Пример #13
0
/* creates the proplist menu out of the abstract menu representation in `menu'.
 */
static void assemblePLMenuFunc(WMTreeNode *aNode, void *data)
{
	WMMenuEntry *wm;
	WMPropList *pl;
	int pDepth, cDepth;

	wm = (WMMenuEntry *)WMGetDataForTreeNode(aNode);
	cDepth = WMGetTreeNodeDepth(aNode);
	pDepth = *(int *)data;

	if (pDepth > cDepth) {				/* just ascended out of a/several submenu(s) */
		WMPropList *last, *but;			/* merge the tail up to the current position */
		int i;
		for (i = pDepth - cDepth; i > 0; i--) {
			last = WMPopFromArray(plMenuNodes);
			but = WMPopFromArray(plMenuNodes);
			WMAddToPLArray(but, last);
			WMAddToArray(plMenuNodes, but);
		}
	}

	if (!wm->CmdLine) {				/* new submenu */
		WMAddToArray(plMenuNodes, WMCreatePLArray(WMCreatePLString(wm->Name), NULL));
	} else {					/* new menu item */
		pl = WMPopFromArray(plMenuNodes);
		if (wm->Flags & F_RESTART_OTHER) {	/* RESTART, somewm */
			char buf[1024];
			memset(buf, 0, sizeof(buf));
			snprintf(buf, sizeof(buf), "%s %s", _("Restart"), wm->Name);
			WMAddToPLArray(pl, WMCreatePLArray(
				WMCreatePLString(buf),
				WMCreatePLString("RESTART"),
				WMCreatePLString(wm->CmdLine),
				NULL)
			);
		} else if (wm->Flags & F_RESTART_SELF) {/* RESTART */
			WMAddToPLArray(pl, WMCreatePLArray(
				WMCreatePLString(_("Restart Window Maker")),
				WMCreatePLString("RESTART"),
				NULL)
			);
		} else if (wm->Flags & F_QUIT) {	/* EXIT */
			WMAddToPLArray(pl, WMCreatePLArray(
				WMCreatePLString(_("Exit Window Maker")),
				WMCreatePLString("EXIT"),
				NULL)
			);
		} else {				/* plain simple command */
			char buf[1024];

			memset(buf, 0, sizeof(buf));
			if (wm->Flags & F_TERMINAL)	/* XXX: quoting! */
				snprintf(buf, sizeof(buf), "%s -e \"%s\"", terminal, wm->CmdLine);
			else
				snprintf(buf, sizeof(buf), "%s", wm->CmdLine);

			WMAddToPLArray(pl, WMCreatePLArray(
				WMCreatePLString(wm->Name),
				WMCreatePLString("SHEXEC"),
				WMCreatePLString(buf),
				NULL)
			);
		}
		WMAddToArray(plMenuNodes, pl);
	}

	*(int *)data = cDepth;
	return;
}