Example #1
0
void wWorkspaceSaveState(WMPropList * old_state)
{
	WMPropList *parr, *pstr, *wks_state, *old_wks_state, *foo, *bar;
	int i;

	make_keys();

	old_wks_state = WMGetFromPLDictionary(old_state, dWorkspaces);
	parr = WMCreatePLArray(NULL);
	for (i = 0; i < w_global.workspace.count; i++) {
		pstr = WMCreatePLString(w_global.workspace.array[i]->name);
		wks_state = WMCreatePLDictionary(dName, pstr, NULL);
		WMReleasePropList(pstr);
		if (!wPreferences.flags.noclip) {
			pstr = wClipSaveWorkspaceState(i);
			WMPutInPLDictionary(wks_state, dClip, pstr);
			WMReleasePropList(pstr);
		} else if (old_wks_state != NULL) {
			if ((foo = WMGetFromPLArray(old_wks_state, i)) != NULL) {
				if ((bar = WMGetFromPLDictionary(foo, dClip)) != NULL) {
					WMPutInPLDictionary(wks_state, dClip, bar);
				}
			}
		}
		WMAddToPLArray(parr, wks_state);
		WMReleasePropList(wks_state);
	}
	WMPutInPLDictionary(w_global.session_state, dWorkspaces, parr);
	WMReleasePropList(parr);
}
Example #2
0
/* Will insert the attribute = value; pair in window's list,
 * if it's different from the defaults.
 * Defaults means either defaults database, or attributes saved
 * for the default window "*". This is to let one revert options that are
 * global because they were saved for all windows ("*"). */
static int
insertAttribute(WMPropList *dict, WMPropList *window, WMPropList *attr, WMPropList *value, int flags)
{
	WMPropList *def_win, *def_value = NULL;
	int update = 0, modified = 0;

	if (!(flags & UPDATE_DEFAULTS) && dict) {
		if ((def_win = WMGetFromPLDictionary(dict, AnyWindow)) != NULL)
			def_value = WMGetFromPLDictionary(def_win, attr);
	}

	/* If we could not find defaults in database, fall to hardcoded values.
	 * Also this is true if we save defaults for all windows */
	if (!def_value)
		def_value = ((flags & IS_BOOLEAN) != 0) ? No : EmptyString;

	if (flags & IS_BOOLEAN)
		update = (getBool(value) != getBool(def_value));
	else
		update = !WMIsPropListEqualTo(value, def_value);

	if (update) {
		WMPutInPLDictionary(window, attr, value);
		modified = 1;
	}

	return modified;
}
Example #3
0
/*
 * struct *s;
 * WDMCheckPLDictionary(pl, spec, &s);
 */
Bool WDMCheckPLDictionary(WMPropList * pl, void *def, void *target)
{
	WDMDictionarySpec *spec = (WDMDictionarySpec *) def;
	WDMDictionaryStruct *fields = spec->fields;
	void **data = (void **)target;
	WMPropList *key = NULL, *value = NULL;
	Bool plok;

	WDMDebug("WDMCheckPLDictionary(%p, %p, %p)\n", (void *)pl, def, target);

	plok = pl && WMIsPLDictionary(pl);
	*data = (void *)wmalloc(spec->size);
	memset(*data, 0, spec->size);
	while (fields->key) {
		key = WMCreatePLString(fields->key);
		value = plok ? WMGetFromPLDictionary(pl, key) : NULL;

		(*fields->checker) (value, fields->data, (void *)((unsigned char *)*data + fields->offset));

		WMReleasePropList(key);
		key = NULL;
		fields++;
	}
	return True;
}
Example #4
0
/* This function save the application icon and store the path in the Dictionary */
static void wApplicationSaveIconPathFor(const char *iconPath, const char *wm_instance, const char *wm_class)
{
	WMPropList *dict = w_global.domain.window_attr->dictionary;
	WMPropList *adict, *key, *iconk;
	WMPropList *val;
	char *tmp;

	tmp = get_name_for_instance_class(wm_instance, wm_class);
	key = WMCreatePLString(tmp);
	wfree(tmp);

	adict = WMGetFromPLDictionary(dict, key);
	iconk = WMCreatePLString("Icon");

	if (adict) {
		val = WMGetFromPLDictionary(adict, iconk);
	} else {
		/* no dictionary for app, so create one */
		adict = WMCreatePLDictionary(NULL, NULL);
		WMPutInPLDictionary(dict, key, adict);
		WMReleasePropList(adict);
		val = NULL;
	}

	if (!val) {
		val = WMCreatePLString(iconPath);
		WMPutInPLDictionary(adict, iconk, val);
		WMReleasePropList(val);
	} else {
		val = NULL;
	}

	WMReleasePropList(key);
	WMReleasePropList(iconk);

	if (val && !wPreferences.flags.noupdates)
		UpdateDomainFile(w_global.domain.window_attr);
}
Example #5
0
int main(int argc, char **argv)
{
	char path[PATH_MAX];
	WMPropList *key, *value, *dict;
	int 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;

	if (argc != 2)
		print_help(0, 1);

	key = WMCreatePLString(argv[1]);

	snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));

	dict = WMReadPropListFromFile(path);
	if (dict == NULL)
		return 1;	/* bad domain */

	value = WMGetFromPLDictionary(dict, key);
	if (value == NULL)
		return 2;	/* bad key */

	printf("%s\n", WMGetPropListDescription(value, True));
	return 0;
}
Example #6
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);
            }
        }
    }

}
Example #7
0
int main(int argc, char **argv)
{
	WMPropList *prop, *style, *key, *val;
	char *path;
	int i, ch, theme_too = 0, make_pack = 0;
	char *style_file = NULL;

	struct option longopts[] = {
		{ "pack",		no_argument,	NULL,	'p' },
		{ "theme-options",	no_argument,	NULL,	't' },
		{ "version",		no_argument,	NULL,	'v' },
		{ "help",		no_argument,	NULL,	'h' },
		{ NULL,			0,		NULL,	0 }
	};

	prog_name = argv[0];
	while ((ch = getopt_long(argc, argv, "ptvh", 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 'p':
				make_pack = 1;
				theme_too = 1;
				break;
			case 't':
				theme_too = 1;
			case 0:
				break;
			default:
				print_help(0, 1);
				/* NOTREACHED */
		}

	/* At most one non-option ARGV-element is accepted (the theme name) */
	if (argc - optind > 1)
		print_help(0, 1);

	if (argc - optind == 1)
		style_file = argv[argc - 1];

	if (make_pack && !style_file) {
		printf("%s: you must supply a name for the theme pack\n", prog_name);
		return 1;
	}

	WMPLSetCaseSensitive(False);

	path = wdefaultspathfordomain("WindowMaker");

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

	/* get global value */
	path = wglobaldefaultspathfordomain("WindowMaker");

	val = WMReadPropListFromFile(path);
	if (val) {
		WMMergePLDictionaries(val, prop, True);
		WMReleasePropList(prop);
		prop = val;
	}

	style = WMCreatePLDictionary(NULL, NULL);

	for (i = 0; options[i] != NULL; i++) {
		key = WMCreatePLString(options[i]);

		val = WMGetFromPLDictionary(prop, key);
		if (val) {
			WMRetainPropList(val);
			if (isFontOption(options[i])) {
				char *newfont, *oldfont;

				oldfont = WMGetFromPLString(val);
				newfont = convertFont(oldfont, False);
				/* newfont is a reference to old if conversion is not needed */
				if (newfont != oldfont) {
					WMReleasePropList(val);
					val = WMCreatePLString(newfont);
					wfree(newfont);
				}
			}
			WMPutInPLDictionary(style, key, val);
			WMReleasePropList(val);
		}
		WMReleasePropList(key);
	}

	val = WMGetFromPLDictionary(prop, WMCreatePLString("PixmapPath"));
	if (val)
		PixmapPath = val;

	if (theme_too) {
		for (i = 0; theme_options[i] != NULL; i++) {
			key = WMCreatePLString(theme_options[i]);

			val = WMGetFromPLDictionary(prop, key);
			if (val)
				WMPutInPLDictionary(style, key, val);
		}
	}

	if (make_pack) {
		char *path;

		makeThemePack(style, style_file);

		path = wmalloc(strlen(ThemePath) + 32);
		strcpy(path, ThemePath);
		strcat(path, "/style");
		WMWritePropListToFile(style, path);
		wfree(path);
	} else {
		if (style_file) {
			WMWritePropListToFile(style, style_file);
		} else {
			puts(WMGetPropListDescription(style, True));
		}
	}
	return 0;
}
Example #8
0
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);
}
Example #9
0
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);
	}
}
Example #10
0
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;
}
Example #11
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);
}