--- rxvt-unicode/src/xdefaults.C 2008/02/16 15:56:41 1.136 +++ rxvt-unicode/src/xdefaults.C 2014/05/02 20:34:24 1.175 @@ -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 { @@ -93,6 +97,7 @@ SWCH ("C", Opt_console, 0, "intercept console messages"), SWCH ("iconic", Opt_iconic, 0, "start iconic"), SWCH ("ic", Opt_iconic, 0, NULL), /* short form */ + STRG (Rs_chdir, "chdir", "cd", "string", "start shell in this directory"), BOOL (Rs_reverseVideo, "reverseVideo", "rv", Opt_reverseVideo, 0, "reverse video"), BOOL (Rs_loginShell, "loginShell", "ls", Opt_loginShell, 0, "login shell"), BOOL (Rs_jumpScroll, "jumpScroll", "j", Opt_jumpScroll, 0, "jump scrolling"), @@ -108,11 +113,12 @@ BOOL (Rs_scrollTtyOutput, NULL, "si", Opt_scrollTtyOutput, Optflag_Reverse, "scroll-on-tty-output inhibit"), BOOL (Rs_scrollTtyKeypress, "scrollTtyKeypress", "sk", Opt_scrollTtyKeypress, 0, "scroll-on-keypress"), BOOL (Rs_scrollWithBuffer, "scrollWithBuffer", "sw", Opt_scrollWithBuffer, 0, "scroll-with-buffer"), -#if ENABLE_TRANSPARENCY +#if BG_IMAGE_FROM_ROOT BOOL (Rs_transparent, "inheritPixmap", "ip", Opt_transparent, 0, "inherit parent pixmap"), 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"), @@ -178,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"), @@ -187,10 +194,13 @@ 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"), #endif +#if ENABLE_EWMH + STRG (Rs_iconfile, "iconFile", "icon", "file", "path to application icon image"), +#endif /* fonts: command-line option = resource name */ STRG (Rs_font, "font", "fn", "fontname", "normal text font"), #if ENABLE_STYLES @@ -199,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"), @@ -214,10 +224,11 @@ STRG (Rs_embed, NULL, "embed", "windowid", "window id to embed terminal in"), #endif #if XFT - STRG (Rs_depth, "depth", "depth", "number", "depth of visual to request"), BOOL (Rs_buffered, "buffered", NULL, Opt_buffered, 0, NULL), #endif #if ENABLE_FRILLS + STRG (Rs_depth, "depth", "depth", "number", "depth of visual to request"), + STRG (Rs_visual, "visual", "visual", "number", "visual id to request"), RSTRG (Rs_transient_for, "transient-for", "windowid"), BOOL (Rs_override_redirect, "override-redirect", "override-redirect", Opt_override_redirect, 0, "set override-redirect on the terminal window"), STRG (Rs_pty_fd, NULL, "pty-fd", "fileno", "file descriptor of pty to use"), @@ -228,6 +239,7 @@ STRG (Rs_int_bwidth, "internalBorder", "b", "number", "internal border in pixels"), BOOL (Rs_borderLess, "borderLess", "bl", Opt_borderLess, 0, "borderless window"), STRG (Rs_lineSpace, "lineSpace", "lsp", "number", "number of extra pixels between rows"), + STRG (Rs_letterSpace, "letterSpace", "letsp", "number", "letter spacing adjustment"), #endif #ifdef BUILTIN_GLYPHS BOOL (Rs_skipBuiltinGlyphs, "skipBuiltinGlyphs", "sbg", Opt_skipBuiltinGlyphs, 0, "do not use internal glyphs"), @@ -258,16 +270,20 @@ STRG (Rs_perl_ext_2, "perl-ext", "pe", "string", "colon-separated list of perl extensions to enable for this instance"), #endif #if ISO_14755 + 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"), +#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 @@ -320,8 +336,8 @@ "transparent," "tint," #endif -#if HAVE_AFTERIMAGE - "afterimage," +#if HAVE_PIXBUF + "pixbuf," #endif #if defined(USE_XIM) "XIM," @@ -371,7 +387,7 @@ #endif "\nUsage: "; /* Usage */ -#define INDENT 18 +#define INDENT 28 const char rxvt_term::resval_undef [] = ""; const char rxvt_term::resval_on [] = "on"; @@ -379,8 +395,8 @@ /*{{{ usage: */ /*----------------------------------------------------------------------*/ -static void -rxvt_usage (int type) +void +rxvt_term::rxvt_usage (int type) { unsigned int i, col; @@ -391,18 +407,18 @@ 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; if (optList[i].arg) len = strlen (optList[i].arg) + 1; -#ifdef DEBUG_STRICT + assert (optList[i].opt != NULL); -#endif - 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) { /* assume regular width */ @@ -411,6 +427,7 @@ } rxvt_log (" [-%s%s", (optList_isBool (i) ? "/+" : ""), optList[i].opt); + if (optList[i].arg) rxvt_log (" %s]", optList[i].arg); else @@ -421,12 +438,10 @@ 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) { -#ifdef DEBUG_STRICT assert (optList[i].opt != NULL); -#endif rxvt_log (" %s%s %-*s%s%s\n", (optList_isBool (i) ? "-/+" : "-"), optList[i].opt, (INDENT - strlen (optList[i].opt) @@ -435,6 +450,12 @@ (optList_isBool (i) ? "turn on/off " : ""), optList[i].desc); } + +#if ENABLE_PERL + rxvt_perl.init (this); + rxvt_perl.usage (this, 1); +#endif + rxvt_log ("\n --help to list long-options"); break; @@ -442,30 +463,30 @@ 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 */ + (INDENT + 2 - 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"); + +#if ENABLE_PERL + rxvt_perl.init (this); + rxvt_perl.usage (this, 2); #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; @@ -506,13 +527,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; @@ -520,14 +542,14 @@ 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 */ if (optList[entry].doff != -1) { - if (flag && i+1 == argc) + if (flag && i + 1 == argc) rxvt_fatal ("option '%s' requires an argument, aborting.\n", argv [i]); rs[optList[entry].doff] = flag ? argv[++i] : resval_undef; @@ -545,31 +567,60 @@ #ifndef NO_RESOURCES else if (!strcmp (opt, "xrm")) { - if (i+1 < argc) + if (i + 1 < argc) XrmPutLineResource (&option_db, argv[++i]); } #endif #ifdef KEYSYM_RESOURCE else if (!strncmp (opt, "keysym.", sizeof ("keysym.") - 1)) { - if (i+1 < argc) + 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 + else if (!strcmp (opt, "e")) { + if (i + 1 < argc) + return (const char **)argv + i + 1; + + rxvt_warn ("option '-e' requires an argument, aborting.\n"); bad_option = 1; - rxvt_warn ("\"%s\": unknown or malformed option.\n", opt); + } + else + { +#if ENABLE_PERL + rxvt_perl.init (this); + + if (int flags = rxvt_perl.parse_resource (this, opt, true, longopt, flag, argv [i + 1])) + { + if (flags & rxvt_perl.RESOURCE_ARG) + { + if (i + 1 == argc) + { + rxvt_warn ("option '%s' requires an argument.\n", argv [i]); + bad_option = 1; + } + else + ++i; + } + } + else +#endif + { + rxvt_warn ("\"%s\": unknown or malformed option.\n", opt); + bad_option = 1; + } } } if (bad_option) rxvt_usage (0); + + return 0; } /*}}} */ @@ -584,22 +635,22 @@ * "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) { + rxvt_term *term = (rxvt_term *)closure; int last; for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */ ; last--; - GET_R->parse_keysym (XrmQuarkToString (quarks[last]), (char *)value->addr);//D//TODO + term->bind_action (XrmQuarkToString (quarks[last]), (char *)value->addr); return False; } @@ -644,7 +695,7 @@ }; int -rxvt_term::parse_keysym (const char *str, const char *arg) +rxvt_term::bind_action (const char *str, const char *arg) { int sym; unsigned int state = 0; @@ -664,7 +715,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) { @@ -674,7 +725,7 @@ } } - if (i >= sizeof (keysym_vocabulary) / sizeof (keysym_vocabulary_t)) + if (i >= ecb_array_length (keysym_vocabulary)) return -1; if (*str == '-') @@ -689,9 +740,13 @@ 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; } @@ -744,7 +799,7 @@ /* * 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; @@ -774,11 +829,18 @@ } } } +#endif /* NO_RESOURCES */ +} +void +rxvt_term::extract_keysym_resources () +{ +#ifndef NO_RESOURCES /* * [R5 or later]: enumerate the resource database */ # ifdef KEYSYM_RESOURCE + XrmDatabase database = XrmGetDatabase (dpy); XrmName name_prefix[3]; XrmClass class_prefix[3]; @@ -790,15 +852,12 @@ class_prefix[2] = NULLQUARK; /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ XrmEnumerateDatabase (database, name_prefix, class_prefix, - XrmEnumOneLevel, rxvt_define_key, NULL); + XrmEnumOneLevel, rxvt_define_key, (XPointer)this); # 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); + XrmEnumOneLevel, rxvt_define_key, (XPointer)this); # endif # endif