--- rxvt-unicode/src/xdefaults.C 2010/01/06 12:10:44 1.142 +++ rxvt-unicode/src/xdefaults.C 2012/06/04 15:18:53 1.165 @@ -6,7 +6,7 @@ * Copyright (c) 1994 Robert Nation * - original version * Copyright (c) 1997,1998 mj olesen - * Copyright (c) 2003-2006 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * Copyright (c) 2007 Emanuele Giaquinta * * This program is free software; you can redistribute it and/or modify @@ -36,6 +36,7 @@ #define Optflag_Reverse 1 #define Optflag_Boolean 2 #define Optflag_Switch 4 +#define Optflag_Info 8 /* monolithic option/resource structure: */ /* @@ -46,7 +47,10 @@ /* INFO () - descriptive information only */ #define INFO(opt, arg, desc) \ - {0, 0, -1, NULL, (opt), (arg), (desc)} + {0, Optflag_Info, -1, NULL, (opt), (arg), (desc)} + +#define RINFO(kw, arg) \ + {0, Optflag_Info, -1, (kw), NULL, (arg), NULL} /* STRG () - command-line option, with/without resource */ #define STRG(rsp, kw, opt, arg, desc) \ @@ -71,8 +75,8 @@ (optList[i].flag & Optflag_Boolean) #define optList_isReverse(i) \ (optList[i].flag & Optflag_Reverse) -#define optList_size \ - (sizeof (optList) / sizeof (optList[0])) +#define optList_isInfo(i) \ + (optList[i].flag & Optflag_Info) static const struct { @@ -114,6 +118,7 @@ BOOL (Rs_transparent, "transparent", "tr", Opt_transparent, 0, "inherit parent pixmap"), STRG (Rs_color + Color_tint, "tintColor", "tint", "color", "tint color"), STRG (Rs_shade, "shading", "sh", "number", "shade background by number %."), + STRG (Rs_blurradius, "blurRadius", "blr", "HxV", "gaussian blur radii to apply to the root background"), #endif #if OFF_FOCUS_FADING STRG (Rs_fade, "fading", "fade", "number", "fade colors by number % when losing focus"), @@ -179,6 +184,7 @@ #endif #ifdef OPTION_HC STRG (Rs_color + Color_HC, "highlightColor", "hc", "color", "highlight color"), + RSTRG (Rs_color + Color_HTC, "highlightTextColor", "color"), #endif #ifndef NO_CURSORCOLOR STRG (Rs_color + Color_cursor, "cursorColor", "cr", "color", "cursor color"), @@ -188,9 +194,12 @@ STRG (Rs_color + Color_pointer_fg, "pointerColor", "pr", "color", "pointer color"), STRG (Rs_color + Color_pointer_bg, "pointerColor2", "pr2", "color", "pointer bg color"), STRG (Rs_color + Color_border, "borderColor", "bd", "color", "border color"), -#ifdef BG_IMAGE_FROM_FILE +#if BG_IMAGE_FROM_FILE RSTRG (Rs_path, "path", "search path"), STRG (Rs_backgroundPixmap, "backgroundPixmap", "pixmap", "file[;geom]", "background pixmap"), +# if ENABLE_EWMH + STRG (Rs_iconfile, "iconFile", "icon", "file", "path to application icon image"), +# endif #endif /* fonts: command-line option = resource name */ STRG (Rs_font, "font", "fn", "fontname", "normal text font"), @@ -200,7 +209,7 @@ STRG (Rs_boldItalicFont, "boldItalicFont", "fbi", "fontname", "bold italic font"), BOOL (Rs_intensityStyles, "intensityStyles", "is", Opt_intensityStyles, 0, "font styles imply intensity changes"), #endif -#ifdef USE_XIM +#if USE_XIM STRG (Rs_inputMethod, "inputMethod", "im", "name", "name of input method"), STRG (Rs_preeditType, "preeditType", "pt", "style", "input style: style = OverTheSpot|OffTheSpot|Root"), STRG (Rs_imLocale, "imLocale", "imlocale", "string", "locale to use for input method"), @@ -263,17 +272,17 @@ BOOL (Rs_iso14755, "iso14755", NULL, Opt_iso14755, 0, NULL), BOOL (Rs_iso14755_52, "iso14755_52", NULL, Opt_iso14755_52, 0, NULL), #endif -#ifdef HAVE_AFTERIMAGE - STRG (Rs_blendtype, "blendType", "blt", "string", "background image blending type - alpha, tint, etc..."), - STRG (Rs_blurradius, "blurRadius", "blr", "HxV", "gaussian blur radii to apply to the root background"), -# if ENABLE_EWMH - STRG (Rs_iconfile, "iconFile", "icon", "file", "path to application icon image"), -# endif +#ifndef NO_RESOURCES + RINFO ("xrm", "string"), +#endif +#ifdef KEYSYM_RESOURCE + RINFO ("keysym.sym", "keysym"), #endif INFO ("e", "command arg ...", "command to execute") }; #undef INFO +#undef RINFO #undef STRG #undef RSTRG #undef SWCH @@ -326,8 +335,8 @@ "transparent," "tint," #endif -#if HAVE_AFTERIMAGE - "afterimage," +#if HAVE_PIXBUF + "pixbuf," #endif #if defined(USE_XIM) "XIM," @@ -397,7 +406,7 @@ case 0: /* brief listing */ rxvt_log (" [-help] [--help]\n"); - for (col = 1, i = 0; i < optList_size; i++) + for (col = 1, i = 0; i < ecb_array_length (optList); i++) if (optList[i].desc != NULL) { int len = 0; @@ -405,7 +414,7 @@ if (optList[i].arg) len = strlen (optList[i].arg) + 1; assert (optList[i].opt != NULL); - len += 4 + strlen (optList[i].opt) + (optList_isBool (i) ? 2: 0); + len += 4 + strlen (optList[i].opt) + (optList_isBool (i) ? 2 : 0); col += len; if (col > 79) { @@ -425,7 +434,7 @@ case 1: /* full command-line listing */ rxvt_log (" [options] [-e command args]\n\nwhere options include:\n"); - for (i = 0; i < optList_size; i++) + for (i = 0; i < ecb_array_length (optList); i++) if (optList[i].desc != NULL) { assert (optList[i].opt != NULL); @@ -444,30 +453,24 @@ rxvt_log (" [options] [-e command args]\n\n" "where resources (long-options) include:\n"); - for (i = 0; i < optList_size; i++) + for (i = 0; i < ecb_array_length (optList); i++) if (optList[i].kw != NULL) rxvt_log (" %s: %*s%s\n", optList[i].kw, (INDENT - strlen (optList[i].kw)), "", /* XXX */ (optList_isBool (i) ? "boolean" : optList[i].arg)); -#ifdef KEYSYM_RESOURCE - rxvt_log (" " "keysym.sym" ": %*s%s\n", - (INDENT - sizeof ("keysym.sym") + 1), "", /* XXX */ - "keysym"); -#endif rxvt_log ("\n -help to list options"); break; } rxvt_log ("\n\n"); rxvt_exit_failure (); - /* NOTREACHED */ } /*}}} */ /*{{{ get command-line options before getting resources */ -void +const char ** rxvt_term::get_options (int argc, const char *const *argv) { int i, bad_option = 0; @@ -508,13 +511,14 @@ rxvt_usage (0); /* feature: always try to match long-options */ - for (entry = 0; entry < optList_size; entry++) + for (entry = 0; entry < ecb_array_length (optList); entry++) if ((optList[entry].kw && !strcmp (opt, optList[entry].kw)) || (!longopt && optList[entry].opt && !strcmp (opt, optList[entry].opt))) break; - if (entry < optList_size) + if (entry < ecb_array_length (optList) + && !optList_isInfo (entry)) { if (optList_isReverse (entry)) flag = !flag; @@ -522,7 +526,7 @@ if (optList_isString (entry)) { /* - * special cases are handled in main.c:main () to allow + * special cases are handled in init_resources () to allow * X resources to set these values before we settle for * default values */ @@ -556,13 +560,19 @@ { if (i+1 < argc) { - char *res = (char *)malloc (strlen (opt) + strlen (argv[++i]) + 6); + char *res = rxvt_temp_buf (strlen (opt) + strlen (argv[++i]) + 6); sprintf (res, "*.%s: %s\n", opt, argv[i]); XrmPutLineResource (&option_db, res); - free (res); } } #endif + else if (!strcmp (opt, "e")) + { + if (i+1 == argc) + rxvt_fatal ("option '-e' requires an argument, aborting.\n"); + + return (const char **)argv + i + 1; + } else { bad_option = 1; @@ -572,6 +582,8 @@ if (bad_option) rxvt_usage (0); + + return 0; } /*}}} */ @@ -586,14 +598,13 @@ * "rxvt" "keysym" "0xFF01" * value will be a string */ -/* ARGSUSED */ -int -rxvt_define_key (XrmDatabase *database UNUSED, - XrmBindingList bindings UNUSED, +static int +rxvt_define_key (XrmDatabase *database ecb_unused, + XrmBindingList bindings ecb_unused, XrmQuarkList quarks, - XrmRepresentation *type UNUSED, + XrmRepresentation *type ecb_unused, XrmValue *value, - XPointer closure UNUSED) + XPointer closure ecb_unused) { int last; @@ -666,7 +677,7 @@ { unsigned int i; - for (i=0; i < sizeof (keysym_vocabulary) / sizeof (keysym_vocabulary_t); ++i) + for (i = 0; i < ecb_array_length (keysym_vocabulary); ++i) { if (strncmp (str, keysym_vocabulary [i].name, keysym_vocabulary [i].len) == 0) { @@ -676,7 +687,7 @@ } } - if (i >= sizeof (keysym_vocabulary) / sizeof (keysym_vocabulary_t)) + if (i >= ecb_array_length (keysym_vocabulary)) return -1; if (*str == '-') @@ -691,9 +702,12 @@ sym = strtol (str, &end, 16); if (*end) return -1; - } + } - keyboard->register_user_translation (sym, state, arg); + wchar_t *ws = rxvt_mbstowcs (arg); + if (!HOOK_INVOKE ((this, HOOK_REGISTER_COMMAND, DT_INT, sym, DT_INT, state, DT_WCS_LEN, ws, wcslen (ws), DT_END))) + keyboard->register_user_translation (sym, state, ws); + free (ws); return 1; } @@ -746,9 +760,8 @@ /* * Query resources for options that affect us */ - for (int entry = 0; entry < optList_size; entry++) + for (int entry = 0; entry < ecb_array_length (optList); entry++) { - int s; const char *kw = optList[entry].kw; if (kw == NULL || rs[optList[entry].doff] != NULL) @@ -764,10 +777,7 @@ if (optList_isBool (entry)) { - s = strcasecmp (p, "TRUE") == 0 - || strcasecmp (p, "YES") == 0 - || strcasecmp (p, "ON") == 0 - || strcasecmp (p, "1") == 0; + bool s = parse_bool_resource (p); if (optList_isReverse (entry)) s = !s; @@ -776,35 +786,45 @@ } } } +#endif /* NO_RESOURCES */ +} +void +rxvt_term::extract_keysym_resources () +{ +#if !defined NO_RESOURCES && defined KEYSYM_RESOURCE + find_resources ("keysym", "Keysym", XrmEnumOneLevel, rxvt_define_key); +#endif +} + +#if !defined NO_RESOURCES && (defined KEYSYM_RESOURCE || defined BG_IMAGE_FROM_FILE) +void +rxvt_term::find_resources (const char *n_prefix, const char *c_prefix, int mode, + Bool (*proc)(XrmDatabase *, XrmBindingList, XrmQuarkList, XrmRepresentation *, XrmValue *, XPointer)) +{ /* * [R5 or later]: enumerate the resource database */ -# ifdef KEYSYM_RESOURCE + XrmDatabase database = XrmGetDatabase (dpy); XrmName name_prefix[3]; XrmClass class_prefix[3]; name_prefix[0] = XrmStringToName (rs[Rs_name]); - name_prefix[1] = XrmStringToName ("keysym"); + name_prefix[1] = XrmStringToName (n_prefix); name_prefix[2] = NULLQUARK; class_prefix[0] = XrmStringToName (RESCLASS); - class_prefix[1] = XrmStringToName ("Keysym"); + class_prefix[1] = XrmStringToName (c_prefix); class_prefix[2] = NULLQUARK; /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ XrmEnumerateDatabase (database, name_prefix, class_prefix, - XrmEnumOneLevel, rxvt_define_key, NULL); + mode, proc, NULL); # ifdef RESFALLBACK - name_prefix[0] = XrmStringToName (RESFALLBACK); - name_prefix[1] = XrmStringToName ("keysym"); - class_prefix[0] = XrmStringToName (RESFALLBACK); - class_prefix[1] = XrmStringToName ("Keysym"); + name_prefix[0] = class_prefix[0] = XrmStringToName (RESFALLBACK); /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ XrmEnumerateDatabase (database, name_prefix, class_prefix, - XrmEnumOneLevel, rxvt_define_key, NULL); + mode, proc, NULL); # endif -# endif - -#endif /* NO_RESOURCES */ } +#endif /*----------------------- end-of-file (C source) -----------------------*/