コード例 #1
0
ファイル: plcheckers.c プロジェクト: bbidulock/wdm
/*
 * 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;
}
コード例 #2
0
ファイル: findfile.c プロジェクト: cneira/wmaker-crm
char *wfindfileinarray(WMPropList *array, const char *file)
{
	int i;
	char *path;
	int len, flen;
	char *fullpath;

	if (!file)
		return NULL;

	if (*file == '/' || *file == '~' || !array) {
		if (access(file, F_OK) < 0) {
			fullpath = wexpandpath(file);
			if (!fullpath)
				return NULL;

			if (access(fullpath, F_OK) < 0) {
				wfree(fullpath);
				return NULL;
			} else {
				return fullpath;
			}
		} else {
			return wstrdup(file);
		}
	}

	flen = strlen(file);
	for (i = 0; i < WMGetPropListItemCount(array); i++) {
		WMPropList *prop;
		char *p;

		prop = WMGetFromPLArray(array, i);
		if (!prop)
			continue;
		p = WMGetFromPLString(prop);

		len = strlen(p);
		path = wmalloc(len + flen + 2);
		path = memcpy(path, p, len);
		path[len] = 0;
		if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
		    wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
			wfree(path);
			return NULL;
		}
		/* expand tilde */
		fullpath = wexpandpath(path);
		wfree(path);
		if (fullpath) {
			/* check if file exists */
			if (access(fullpath, F_OK) == 0) {
				return fullpath;
			}
			wfree(fullpath);
		}
	}
	return NULL;
}
コード例 #3
0
void
hackPaths(WMPropList *style, char *prefix)
{
    WMPropList *keys;
    WMPropList *key;
    WMPropList *value;
    int i;


    keys = WMGetPLDictionaryKeys(style);

    for (i = 0; i < WMGetPropListItemCount(keys); i++) {
        key = WMGetFromPLArray(keys, i);

        value = WMGetFromPLDictionary(style, key);
        if (!value)
            continue;

        if (strcasecmp(WMGetFromPLString(key), "WorkspaceSpecificBack")==0) {
            if (WMIsPLArray(value)) {
                int j;
                WMPropList *texture;

                for (j = 0; j < WMGetPropListItemCount(value); j++) {
                    texture = WMGetFromPLArray(value, j);

                    if (texture && WMIsPLArray(texture)
                        && WMGetPropListItemCount(texture) > 2) {

                        hackPathInTexture(texture, prefix);
                    }
                }
            }
        } else {

            if (WMIsPLArray(value) && WMGetPropListItemCount(value) > 2) {

                hackPathInTexture(value, prefix);
            }
        }
    }

}
コード例 #4
0
static WEditMenu*
buildSubmenu(_Panel *panel, WMPropList *pl)
{
    WMScreen *scr = WMWidgetScreen(panel->parent);
    WEditMenu *menu;
    WEditMenuItem *item;
    char *title;
    WMPropList *tp, *bp;
    int i;

    tp = WMGetFromPLArray(pl, 0);
    title = WMGetFromPLString(tp);

    menu = WCreateEditMenu(scr, title);

    for (i = 1; i < WMGetPropListItemCount(pl); i++) {
        WMPropList *pi;

        pi = WMGetFromPLArray(pl, i);

        tp = WMGetFromPLArray(pi, 0);
        bp = WMGetFromPLArray(pi, 1);

        title = WMGetFromPLString(tp);

        if (!bp || WMIsPLArray(bp)) {	       /* it's a submenu */
            WEditMenu *submenu;

            submenu = buildSubmenu(panel, pi);

            item = WAddMenuItemWithTitle(menu, title);

            WSetEditMenuSubmenu(menu, item, submenu);
        } else {
            ItemData *data;

            item = WAddMenuItemWithTitle(menu, title);

            data = parseCommand(pi);

            if (panel->markerPix[data->type])
                WSetEditMenuItemImage(item, panel->markerPix[data->type]);
            WSetEditMenuItemData(item, data, (WMCallback*)freeItemData);
        }
    }

    WSetEditMenuAcceptsDrop(menu, True);
    WSetEditMenuDelegate(menu, &menuDelegate);

    WMRealizeWidget(menu);

    return menu;
}
コード例 #5
0
static void
showData(_Panel *panel)
{
    WMPropList *array, *val;
    int i;

    array = GetObjectForKey("IconPath");
    if (!array || !WMIsPLArray(array)) {
        if (array)
            wwarning(_("bad value in option IconPath. Using default path list"));
        addPathToList(panel->icoL, -1, "~/pixmaps");
        addPathToList(panel->icoL, -1, "~/GNUstep/Library/Icons");
        addPathToList(panel->icoL, -1, "/usr/include/X11/pixmaps");
        addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Icons");
        addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Pixmaps");
        addPathToList(panel->icoL, -1, "/usr/share/WindowMaker/Icons");
    } else {
        for (i=0; i<WMGetPropListItemCount(array); i++) {
            val = WMGetFromPLArray(array, i);
            addPathToList(panel->icoL, -1, WMGetFromPLString(val));
        }
    }

    array = GetObjectForKey("PixmapPath");
    if (!array || !WMIsPLArray(array)) {
        if (array)
            wwarning(_("bad value in option PixmapPath. Using default path list"));
        addPathToList(panel->pixL, -1, "~/pixmaps");
        addPathToList(panel->pixL, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
        addPathToList(panel->pixL, -1, "/usr/local/share/WindowMaker/Pixmaps");
    } else {
        for (i=0; i<WMGetPropListItemCount(array); i++) {
            val = WMGetFromPLArray(array, i);
            addPathToList(panel->pixL, -1, WMGetFromPLString(val));
        }
    }
}
コード例 #6
0
ファイル: Menu.c プロジェクト: awmaker/awmaker
static WEditMenu *buildSubmenu(_Panel * panel, WMPropList * pl)
{
	WMScreen *scr = WMWidgetScreen(panel->parent);
	WEditMenu *menu;
	WEditMenuItem *item;
	char *title;
	WMPropList *tp, *bp;
	int i;

	tp = WMGetFromPLArray(pl, 0);
	title = WMGetFromPLString(tp);

	menu = WCreateEditMenu(scr, title);

	for (i = 1; i < WMGetPropListItemCount(pl); i++) {
		WMPropList *pi;

		pi = WMGetFromPLArray(pl, i);

		tp = WMGetFromPLArray(pi, 0);
		bp = WMGetFromPLArray(pi, 1);

		title = WMGetFromPLString(tp);

		if (!bp || WMIsPLArray(bp)) {	/* it's a submenu */
			WEditMenu *submenu;

			submenu = buildSubmenu(panel, pi);

			item = WAddMenuItemWithTitle(menu, title);

			WSetEditMenuSubmenu(menu, item, submenu);
		} else {
			ItemData *data;

			data = parseCommand(pi);

			if (data != NULL) {
				item = WAddMenuItemWithTitle(menu, title);
				if (panel->markerPix[data->type])
					WSetEditMenuItemImage(item, panel->markerPix[data->type]);
				WSetEditMenuItemData(item, data, (WMCallback *) freeItemData);
			} else {
				char *buf = wmalloc(1024);
				snprintf(buf, 1024, _("Invalid menu command \"%s\" with label \"%s\" cleared"),
					WMGetFromPLString(WMGetFromPLArray(pi, 1)),
					WMGetFromPLString(WMGetFromPLArray(pi, 0)));
				WMRunAlertPanel(scr, panel->parent, _("Warning"), buf, _("OK"), NULL, NULL);
				wfree(buf);
			}

		}
	}

	WSetEditMenuAcceptsDrop(menu, True);
	WSetEditMenuDelegate(menu, &menuDelegate);

	WMRealizeWidget(menu);

	return menu;
}
コード例 #7
0
ファイル: getstyle.c プロジェクト: awmaker/awmaker
static void makeThemePack(WMPropList * style, const char *themeName)
{
	WMPropList *keys;
	WMPropList *key;
	WMPropList *value;
	int i;
	size_t themeNameLen;
	char *themeDir;
	const char *user_base;

	user_base = wusergnusteppath();
	if (user_base == NULL)
		return;
	themeNameLen = strlen(user_base) + sizeof(THEME_SUBPATH) + strlen(themeName) + sizeof(THEME_EXTDIR) + 1;
	themeDir = wmalloc(themeNameLen);
	snprintf(themeDir, themeNameLen,
	         "%s" THEME_SUBPATH "%s" THEME_EXTDIR,
	         user_base, themeName);
	ThemePath = themeDir;

	if (!wmkdirhier(themeDir)) {
		wwarning("Could not make theme dir %s\n", themeDir);
		return;
	}

	keys = WMGetPLDictionaryKeys(style);

	for (i = 0; i < WMGetPropListItemCount(keys); i++) {
		key = WMGetFromPLArray(keys, i);

		value = WMGetFromPLDictionary(style, key);
		if (value && WMIsPLArray(value) && WMGetPropListItemCount(value) > 2) {
			WMPropList *type;
			char *t;

			type = WMGetFromPLArray(value, 0);
			t = WMGetFromPLString(type);
			if (t == NULL)
				continue;

			if (strcasecmp(t, "tpixmap") == 0 ||
			    strcasecmp(t, "spixmap") == 0 ||
			    strcasecmp(t, "cpixmap") == 0 ||
			    strcasecmp(t, "mpixmap") == 0 ||
			    strcasecmp(t, "tdgradient") == 0 ||
			    strcasecmp(t, "tvgradient") == 0 ||
			    strcasecmp(t, "thgradient") == 0) {

				WMPropList *file;
				char *p;
				char *newPath;

				file = WMGetFromPLArray(value, 1);

				p = strrchr(WMGetFromPLString(file), '/');
				if (p) {
					newPath = wstrdup(p + 1);

					wcopy_file(themeDir, WMGetFromPLString(file), newPath);

					WMDeleteFromPLArray(value, 1);
					WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
					free(newPath);
				} else {
					findCopyFile(themeDir, WMGetFromPLString(file));
				}
			} else if (strcasecmp(t, "bitmap") == 0) {

				WMPropList *file;
				char *p;
				char *newPath;

				file = WMGetFromPLArray(value, 1);

				p = strrchr(WMGetFromPLString(file), '/');
				if (p) {
					newPath = wstrdup(p + 1);

					wcopy_file(themeDir, WMGetFromPLString(file), newPath);

					WMDeleteFromPLArray(value, 1);
					WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
					free(newPath);
				} else {
					findCopyFile(themeDir, WMGetFromPLString(file));
				}

				file = WMGetFromPLArray(value, 2);

				p = strrchr(WMGetFromPLString(file), '/');
				if (p) {
					newPath = wstrdup(p + 1);

					wcopy_file(themeDir, WMGetFromPLString(file), newPath);

					WMDeleteFromPLArray(value, 2);
					WMInsertInPLArray(value, 2, WMCreatePLString(newPath));
					free(newPath);
				} else {
					findCopyFile(themeDir, WMGetFromPLString(file));
				}
			}
		}
	}
	WMReleasePropList(keys);
}
コード例 #8
0
ファイル: workspace.c プロジェクト: jafd/wmaker
void wWorkspaceRestoreState(WScreen *scr)
{
	WMPropList *parr, *pstr, *wks_state, *clip_state;
	int i, j;

	make_keys();

	if (w_global.session_state == NULL)
		return;

	parr = WMGetFromPLDictionary(w_global.session_state, dWorkspaces);

	if (!parr)
		return;

	for (i = 0; i < WMIN(WMGetPropListItemCount(parr), MAX_WORKSPACES); i++) {
		wks_state = WMGetFromPLArray(parr, i);
		if (WMIsPLDictionary(wks_state))
			pstr = WMGetFromPLDictionary(wks_state, dName);
		else
			pstr = wks_state;

		if (i >= w_global.workspace.count)
			wWorkspaceNew(scr);

		if (w_global.workspace.menu) {
			wfree(w_global.workspace.menu->entries[i + MC_WORKSPACE1]->text);
			w_global.workspace.menu->entries[i + MC_WORKSPACE1]->text = wstrdup(WMGetFromPLString(pstr));
			w_global.workspace.menu->flags.realized = 0;
		}

		wfree(w_global.workspace.array[i]->name);
		w_global.workspace.array[i]->name = wstrdup(WMGetFromPLString(pstr));
		if (!wPreferences.flags.noclip) {
			int added_omnipresent_icons = 0;

			clip_state = WMGetFromPLDictionary(wks_state, dClip);
			if (w_global.workspace.array[i]->clip)
				wDockDestroy(w_global.workspace.array[i]->clip);

			w_global.workspace.array[i]->clip = wDockRestoreState(scr, clip_state, WM_CLIP);
			if (i > 0)
				wDockHideIcons(w_global.workspace.array[i]->clip);

			/* We set the global icons here, because scr->workspaces[i]->clip
			 * was not valid in wDockRestoreState().
			 * There we only set icon->omnipresent to know which icons we
			 * need to set here.
			 */
			for (j = 0; j < w_global.workspace.array[i]->clip->max_icons; j++) {
				WAppIcon *aicon = w_global.workspace.array[i]->clip->icon_array[j];
				int k;

				if (!aicon || !aicon->omnipresent)
					continue;
				aicon->omnipresent = 0;
				if (wClipMakeIconOmnipresent(aicon, True) != WO_SUCCESS)
					continue;
				if (i == 0)
					continue;

				/* Move this appicon from workspace i to workspace 0 */
				w_global.workspace.array[i]->clip->icon_array[j] = NULL;
				w_global.workspace.array[i]->clip->icon_count--;

				added_omnipresent_icons++;
				/* If there are too many omnipresent appicons, we are in trouble */
				assert(w_global.workspace.array[0]->clip->icon_count + added_omnipresent_icons
				       <= w_global.workspace.array[0]->clip->max_icons);
				/* Find first free spot on workspace 0 */
				for (k = 0; k < w_global.workspace.array[0]->clip->max_icons; k++)
					if (w_global.workspace.array[0]->clip->icon_array[k] == NULL)
						break;
				w_global.workspace.array[0]->clip->icon_array[k] = aicon;
				aicon->dock = w_global.workspace.array[0]->clip;
			}
			w_global.workspace.array[0]->clip->icon_count += added_omnipresent_icons;
		}

		WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void *)(uintptr_t) i);
	}
}
コード例 #9
0
ファイル: geticonset.c プロジェクト: awmaker/awmaker
int main(int argc, char **argv)
{
	WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
	WMPropList *all_windows, *iconset, *keylist;
	char *path;
	int i, ch;

	struct option longopts[] = {
		{ "version",	no_argument,	NULL,		'v' },
		{ "help",	no_argument,	NULL,		'h' },
		{ NULL,		0,		NULL,		0 }
	};

	prog_name = argv[0];
	while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
		switch(ch) {
			case 'v':
				printf("%s (Window Maker %s)\n", prog_name, VERSION);
				return 0;
				/* NOTREACHED */
			case 'h':
				print_help(1, 0);
				/* NOTREACHED */
			case 0:
				break;
			default:
				print_help(0, 1);
				/* NOTREACHED */
		}

	argc -= optind;
	argv += optind;

	path = wdefaultspathfordomain("WMWindowAttributes");

	all_windows = WMReadPropListFromFile(path);
	if (!all_windows) {
		printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path);
		return 1;
	}

	iconset = WMCreatePLDictionary(NULL, NULL);

	keylist = WMGetPLDictionaryKeys(all_windows);
	icon_key = WMCreatePLString("Icon");

	for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
		WMPropList *icondic;

		window_name = WMGetFromPLArray(keylist, i);
		if (!WMIsPLString(window_name))
			continue;

		window_attrs = WMGetFromPLDictionary(all_windows, window_name);
		if (window_attrs && WMIsPLDictionary(window_attrs)) {
			icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
			if (icon_value) {
				icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
				WMPutInPLDictionary(iconset, window_name, icondic);
			}
		}
	}

	if (argc == 1) {
		WMWritePropListToFile(iconset, argv[0]);
	} else {
		puts(WMGetPropListDescription(iconset, True));
	}
	return 0;
}
コード例 #10
0
int
main(int argc, char **argv)
{
    WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
    WMPropList *all_windows, *iconset, *keylist;
    int i;
    char *path = NULL;

    ProgName = argv[0];


    if (argc < 2) {
        printf("%s: missing argument\n", ProgName);
        printf("Try '%s --help' for more information\n", ProgName);
    }

    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-h")==0
            || strcmp(argv[i], "--help")==0) {
            print_help();
            exit(0);
        } else if (strcmp(argv[i], "--version")==0) {
            puts(PROG_VERSION);
            exit(0);
        } else {
            if (path) {
                printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
                printf("Try '%s --help' for more information\n", ProgName);
                exit(1);
            }
            path = argv[i];
        }
    }

    path = defaultsPathForDomain("WMWindowAttributes");

    all_windows = WMReadPropListFromFile(path);
    if (!all_windows) {
        printf("%s:could not load WindowMaker configuration file \"%s\".\n",
               ProgName, path);
        exit(1);
    }

    iconset = WMReadPropListFromFile(argv[1]);
    if (!iconset) {
        printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
        exit(1);
    }


    keylist = WMGetPLDictionaryKeys(iconset);
    icon_key = WMCreatePLString("Icon");

    for (i=0; i<WMGetPropListItemCount(keylist); i++) {
        window_name = WMGetFromPLArray(keylist, i);
        if (!WMIsPLString(window_name))
            continue;

        icon_value = WMGetFromPLDictionary(iconset, window_name);
        if (!icon_value || !WMIsPLDictionary(icon_value))
            continue;

        window_attrs = WMGetFromPLDictionary(all_windows, window_name);
        if (window_attrs) {
            if (WMIsPLDictionary(window_attrs)) {
                WMMergePLDictionaries(window_attrs, icon_value, True);
            }
        } else {
            WMPutInPLDictionary(all_windows, window_name, icon_value);
        }
    }

    WMWritePropListToFile(all_windows, path, True);

    exit(0);
}
コード例 #11
0
ファイル: wmsetbg.c プロジェクト: cneira/wmaker-crm
static BackgroundTexture *parseTexture(RContext * rc, char *text)
{
	BackgroundTexture *texture = NULL;
	WMPropList *texarray;
	WMPropList *val;
	int count;
	char *tmp;
	char *type;

#define GETSTRORGOTO(val, str, i, label) \
    val = WMGetFromPLArray(texarray, i);\
    if (!WMIsPLString(val)) {\
    wwarning("could not parse texture %s", text);\
    goto label;\
    }\
    str = WMGetFromPLString(val)

	texarray = WMCreatePropListFromDescription(text);
	if (!texarray || !WMIsPLArray(texarray)
	    || (count = WMGetPropListItemCount(texarray)) < 2) {

		wwarning("could not parse texture %s", text);
		if (texarray)
			WMReleasePropList(texarray);
		return NULL;
	}

	texture = wmalloc(sizeof(BackgroundTexture));

	GETSTRORGOTO(val, type, 0, error);

	if (strcasecmp(type, "solid") == 0) {
		XColor color;
		Pixmap pixmap;

		texture->solid = 1;

		GETSTRORGOTO(val, tmp, 1, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}
		XAllocColor(dpy, DefaultColormap(dpy, scr), &color);

		pixmap = XCreatePixmap(dpy, root, 8, 8, DefaultDepth(dpy, scr));
		XSetForeground(dpy, DefaultGC(dpy, scr), color.pixel);
		XFillRectangle(dpy, pixmap, DefaultGC(dpy, scr), 0, 0, 8, 8);

		texture->pixmap = pixmap;
		texture->color = color;
		texture->width = 8;
		texture->height = 8;
	} else if (strcasecmp(type, "vgradient") == 0
		   || strcasecmp(type, "dgradient") == 0 || strcasecmp(type, "hgradient") == 0) {
		XColor color;
		RColor color1, color2;
		RImage *image;
		Pixmap pixmap;
		RGradientStyle gtype;
		int iwidth, iheight;

		GETSTRORGOTO(val, tmp, 1, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}

		color1.red = color.red >> 8;
		color1.green = color.green >> 8;
		color1.blue = color.blue >> 8;

		GETSTRORGOTO(val, tmp, 2, error);

		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
			wwarning("could not parse color %s in texture %s", tmp, text);
			goto error;
		}

		color2.red = color.red >> 8;
		color2.green = color.green >> 8;
		color2.blue = color.blue >> 8;

		switch (type[0]) {
		case 'h':
		case 'H':
			gtype = RHorizontalGradient;
			iwidth = scrWidth;
			iheight = 32;
			break;
		case 'V':
		case 'v':
			gtype = RVerticalGradient;
			iwidth = 32;
			iheight = scrHeight;
			break;
		default:
			gtype = RDiagonalGradient;
			iwidth = scrWidth;
			iheight = scrHeight;
			break;
		}

		image = RRenderGradient(iwidth, iheight, &color1, &color2, gtype);

		if (!image) {
			wwarning("could not render gradient texture:%s", RMessageForError(RErrorCode));
			goto error;
		}

		if (!RConvertImage(rc, image, &pixmap)) {
			wwarning("could not convert texture:%s", RMessageForError(RErrorCode));
			RReleaseImage(image);
			goto error;
		}

		texture->width = image->width;
		texture->height = image->height;
		RReleaseImage(image);

		texture->pixmap = pixmap;
	} else if (strcasecmp(type, "mvgradient") == 0