コード例 #1
0
ファイル: getstyle.c プロジェクト: awmaker/awmaker
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;
}
コード例 #2
0
ファイル: main.c プロジェクト: awmaker/awmaker
int main(int argc, char **argv)
{
	Display *dpy;
	WMScreen *scr;
	char *path;
	int i;
	char *display_name = "";

	wsetabort(wAbort);

	memset(DeadHandlers, 0, sizeof(DeadHandlers));

	WMInitializeApplication("WPrefs", &argc, argv);

	WMSetResourcePath(RESOURCE_PATH);
	path = WMPathForResourceOfType("WPrefs.tiff", NULL);
	if (!path) {
		/* maybe it is run directly from the source directory */
		WMSetResourcePath(".");
		path = WMPathForResourceOfType("WPrefs.tiff", NULL);
		if (!path) {
			WMSetResourcePath("..");
		}
	}
	if (path) {
		wfree(path);
	}

	if (argc > 1) {
		for (i = 1; i < argc; i++) {
			if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
				printf("WPrefs (Window Maker) %s\n", VERSION);
				exit(0);
			} else if (strcmp(argv[i], "-display") == 0) {
				i++;
				if (i >= argc) {
					wwarning(_("too few arguments for %s"), argv[i - 1]);
					exit(0);
				}
				display_name = argv[i];
			} else {
				print_help(argv[0]);
				exit(0);
			}
		}
	}

	setlocale(LC_ALL, "");

#ifdef I18N
	if (getenv("NLSPATH"))
		bindtextdomain("WPrefs", getenv("NLSPATH"));
	else
		bindtextdomain("WPrefs", LOCALEDIR);
	bind_textdomain_codeset("WPrefs", "UTF-8");
	textdomain("WPrefs");

	if (!XSupportsLocale()) {
		wwarning(_("X server does not support locale"));
	}
	if (XSetLocaleModifiers("") == NULL) {
		wwarning(_("cannot set locale modifiers"));
	}
#endif

	dpy = XOpenDisplay(display_name);
	if (!dpy) {
		wfatal(_("could not open display %s"), XDisplayName(display_name));
		exit(0);
	}
#if 0
	XSynchronize(dpy, 1);
#endif
	scr = WMCreateScreen(dpy, DefaultScreen(dpy));
	if (!scr) {
		wfatal(_("could not initialize application"));
		exit(0);
	}

	xext_xkb_supported = XkbQueryExtension(dpy, NULL, NULL, NULL, NULL, NULL);

	WMPLSetCaseSensitive(False);

	Initialize(scr);

	while (1) {
		XEvent event;

		WMNextEvent(dpy, &event);

		while (DeadChildrenCount-- > 0) {
			int i;

			for (i = 0; i < MAX_DEATHS; i++) {
				if (DeadChildren[i] == DeadHandlers[i].pid) {
					(*DeadHandlers[i].handler) (DeadHandlers[i].data);
					DeadHandlers[i].pid = 0;
				}
			}
		}

		WMHandleEvent(&event);
	}
}
コード例 #3
0
ファイル: winspector.c プロジェクト: cneira/wmaker-crm
static void saveSettings(WMWidget *button, void *client_data)
{
	InspectorPanel *panel = (InspectorPanel *) client_data;
	WWindow *wwin = panel->inspected;
	WDDomain *db = w_global.domain.window_attr;
	WMPropList *dict = NULL;
	WMPropList *winDic, *appDic, *value, *value1, *key = NULL, *key2;
	char *icon_file, *buf1, *buf2;
	int flags = 0, i = 0, different = 0, different2 = 0;

	/* Save will apply the changes and save them */
	applySettings(panel->applyBtn, panel);

	if (WMGetButtonSelected(panel->instRb) != 0) {
		key = WMCreatePLString(wwin->wm_instance);
	} else if (WMGetButtonSelected(panel->clsRb) != 0) {
		key = WMCreatePLString(wwin->wm_class);
	} else if (WMGetButtonSelected(panel->bothRb) != 0) {
		buf1 = StrConcatDot(wwin->wm_instance, wwin->wm_class);
		key = WMCreatePLString(buf1);
		wfree(buf1);
	} else if (WMGetButtonSelected(panel->defaultRb) != 0) {
		key = WMRetainPropList(AnyWindow);
		flags = UPDATE_DEFAULTS;
	}

	if (!key)
		return;

	dict = db->dictionary;
	if (!dict) {
		dict = WMCreatePLDictionary(NULL, NULL);
		if (dict) {
			db->dictionary = dict;
		} else {
			WMReleasePropList(key);
			return;
		}
	}

	if (showIconFor(WMWidgetScreen(button), panel, NULL, NULL, USE_TEXT_FIELD) < 0)
		return;

	WMPLSetCaseSensitive(True);

	winDic = WMCreatePLDictionary(NULL, NULL);
	appDic = WMCreatePLDictionary(NULL, NULL);

	/* Save the icon info */
	/* The flag "Ignore client suplied icon is not selected" */
	buf1 = wmalloc(4);
	snprintf(buf1, 4, "%s", (WMGetButtonSelected(panel->alwChk) != 0) ? "Yes" : "No");
	value1 = WMCreatePLString(buf1);
	different |= insertAttribute(dict, winDic, AAlwaysUserIcon, value1, flags);
	WMReleasePropList(value1);
	wfree(buf1);

	/* The icon filename (if exists) */
	icon_file = WMGetTextFieldText(panel->fileText);
	if (icon_file != NULL) {
		if (icon_file[0] != '\0') {
			value = WMCreatePLString(icon_file);
			different |= insertAttribute(dict, winDic, AIcon, value, flags);
			different2 |= insertAttribute(dict, appDic, AIcon, value, flags);
			WMReleasePropList(value);
		}
		wfree(icon_file);
	}

	i = WMGetPopUpButtonSelectedItem(panel->wsP) - 1;
	if (i >= 0 && i < w_global.workspace.count) {
		value = WMCreatePLString(w_global.workspace.array[i]->name);
		different |= insertAttribute(dict, winDic, AStartWorkspace, value, flags);
		WMReleasePropList(value);
	}

	flags |= IS_BOOLEAN;

	value = (WMGetButtonSelected(panel->attrChk[0]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoTitlebar, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[1]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoResizebar, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[2]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoCloseButton, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[3]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoMiniaturizeButton, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[4]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoBorder, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[5]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AKeepOnTop, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[6]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AKeepOnBottom, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[7]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AOmnipresent, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[8]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AStartMiniaturized, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[9]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AStartMaximized, value, flags);

	value = (WMGetButtonSelected(panel->attrChk[10]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AFullMaximize, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[0]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoKeyBindings, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[1]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoMouseBindings, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[2]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ASkipWindowList, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[3]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ASkipSwitchPanel, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[4]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AUnfocusable, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[5]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AKeepInsideScreen, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[6]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoHideOthers, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[7]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ADontSaveSession, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[8]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AEmulateAppIcon, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[9]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, AFocusAcrossWorkspace, value, flags);

	value = (WMGetButtonSelected(panel->moreChk[10]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoMiniaturizable, value, flags);

#ifdef XKB_BUTTON_HINT
	value = (WMGetButtonSelected(panel->moreChk[11]) != 0) ? Yes : No;
	different |= insertAttribute(dict, winDic, ANoLanguageButton, value, flags);
#endif

	if (wwin->main_window != None && wApplicationOf(wwin->main_window) != NULL) {
		value = (WMGetButtonSelected(panel->appChk[0]) != 0) ? Yes : No;
		different2 |= insertAttribute(dict, appDic, AStartHidden, value, flags);

		value = (WMGetButtonSelected(panel->appChk[1]) != 0) ? Yes : No;
		different2 |= insertAttribute(dict, appDic, ANoAppIcon, value, flags);

		value = (WMGetButtonSelected(panel->appChk[2]) != 0) ? Yes : No;
		different2 |= insertAttribute(dict, appDic, ASharedAppIcon, value, flags);
	}

	if (wwin->fake_group) {
		key2 = WMCreatePLString(wwin->fake_group->identifier);
		if (WMIsPropListEqualTo(key, key2)) {
			WMMergePLDictionaries(winDic, appDic, True);
			different |= different2;
		} else {
			WMRemoveFromPLDictionary(dict, key2);
			if (different2)
				WMPutInPLDictionary(dict, key2, appDic);
		}
		WMReleasePropList(key2);
	} else if (wwin->main_window != wwin->client_win) {
		WApplication *wapp = wApplicationOf(wwin->main_window);

		if (wapp) {
			buf2 = StrConcatDot(wapp->main_window_desc->wm_instance,
					      wapp->main_window_desc->wm_class);
			key2 = WMCreatePLString(buf2);
			wfree(buf2);

			if (WMIsPropListEqualTo(key, key2)) {
				WMMergePLDictionaries(winDic, appDic, True);
				different |= different2;
			} else {
				WMRemoveFromPLDictionary(dict, key2);
				if (different2)
					WMPutInPLDictionary(dict, key2, appDic);
			}
			WMReleasePropList(key2);
		}
	} else {
		WMMergePLDictionaries(winDic, appDic, True);
		different |= different2;
	}
	WMReleasePropList(appDic);

	WMRemoveFromPLDictionary(dict, key);
	if (different)
		WMPutInPLDictionary(dict, key, winDic);

	WMReleasePropList(key);
	WMReleasePropList(winDic);

	UpdateDomainFile(db);

	/* clean up */
	WMPLSetCaseSensitive(False);
}