--- rxvt-unicode/src/xdefaults.C 2014/08/16 10:51:23 1.180 +++ rxvt-unicode/src/xdefaults.C 2019/09/17 20:38:53 1.194 @@ -7,7 +7,7 @@ * - original version * Copyright (c) 1997,1998 mj olesen * Copyright (c) 2003-2006 Marc Lehmann - * Copyright (c) 2007 Emanuele Giaquinta + * Copyright (c) 2007,2015 Emanuele Giaquinta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -101,7 +101,7 @@ SWCH ("dockapp", Opt_dockapp, 0, "start as dockapp"), BOOL (Rs_reverseVideo, "reverseVideo", "rv", Opt_reverseVideo, 0, "reverse video"), BOOL (Rs_loginShell, "loginShell", "ls", Opt_loginShell, 0, "login shell"), - STRG (Rs_multiClickTime, "multiClickTime", "mc", "number", "Maximum time (in ms) between multi-click selections"), + STRG (Rs_multiClickTime, "multiClickTime", "mc", "number", "maximum time (in ms) between multi-click selections"), BOOL (Rs_jumpScroll, "jumpScroll", "j", Opt_jumpScroll, 0, "jump scrolling"), BOOL (Rs_skipScroll, "skipScroll", "ss", Opt_skipScroll, 0, "skip scrolling"), BOOL (Rs_pastableTabs, "pastableTabs", "ptab", Opt_pastableTabs, 0, "tab characters are pastable"), @@ -115,13 +115,6 @@ 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 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"), STRG (Rs_color + Color_fade, "fadeColor", "fadecolor", "color", "target color for off-focus fading"), @@ -196,13 +189,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"), -#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 +#ifdef HAVE_XMU + RSTRG (Rs_pointerShape, "pointerShape", "string"), +#endif /* fonts: command-line option = resource name */ STRG (Rs_font, "font", "fn", "fontname", "normal text font"), #if ENABLE_STYLES @@ -627,10 +619,9 @@ /*}}} */ -#ifndef NO_RESOURCES /*----------------------------------------------------------------------*/ -# ifdef KEYSYM_RESOURCE +#ifdef KEYSYM_RESOURCE static void rxvt_define_key (rxvt_term *term, const char *k, const char *v) { @@ -638,37 +629,6 @@ } /* - * Define key from XrmEnumerateDatabase. - * quarks will be something like - * "rxvt" "keysym" "0xFF01" - * value will be a string - */ -static int -rxvt_keysym_enumerate_helper ( - XrmDatabase *database ecb_unused, - XrmBindingList bindings ecb_unused, - XrmQuarkList quarks, - XrmRepresentation *type ecb_unused, - XrmValue *value, - XPointer closure -) -{ - int last; - - for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */ - ; - - rxvt_term *term = (rxvt_term *)(((void **)closure)[0]); - void (*cb)(rxvt_term *, const char *, const char *) - = (void (*)(rxvt_term *, const char *, const char *)) - (((void **)closure)[1]); - - cb (term, XrmQuarkToString (quarks[last - 1]), (char *)value->addr); - - return False; -} - -/* * look for something like this (XK_Delete) * rxvt*keysym.0xFFFF: "\177" */ @@ -709,19 +669,20 @@ }; int -rxvt_term::bind_action (const char *str, const char *arg) +rxvt_term::parse_keysym (const char *str, unsigned int &state) { int sym; - unsigned int state = 0; const char *key = strrchr (str, '-'); + state = 0; + if (!key) key = str; else key++; // string or key is empty - if (*arg == '\0' || *key == '\0') + if (*key == '\0') return -1; // parse modifiers @@ -756,6 +717,18 @@ return -1; } + return sym; +} + +int +rxvt_term::bind_action (const char *str, const char *arg) +{ + int sym; + unsigned int state; + + if (*arg == '\0' || (sym = parse_keysym (str, state)) == -1) + return -1; + 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_action (sym, state, ws); @@ -764,8 +737,7 @@ return 1; } -# endif /* KEYSYM_RESOURCE */ -#endif /* NO_RESOURCES */ +#endif /* KEYSYM_RESOURCE */ static char * get_res (XrmDatabase database, const char *program, const char *option) @@ -846,47 +818,128 @@ #endif /* NO_RESOURCES */ } +struct rxvt_enumerate_closure +{ + rxvt_term *term; + void (*cb)(rxvt_term *, const char *, const char *); + int specific; // iterate over only a specific subhierarchy +}; + +/* + * Define key from XrmEnumerateDatabase. + * quarks will be something like + * "rxvt" "keysym" "0xFF01" + * value will be a string + */ +static int +rxvt_enumerate_helper ( + XrmDatabase *database ecb_unused, + XrmBindingList bindings ecb_unused, + XrmQuarkList quarks, + XrmRepresentation *type ecb_unused, + XrmValue *value, + XPointer closure +) +{ + const rxvt_enumerate_closure *data = (const rxvt_enumerate_closure *)closure; + + if (*quarks == NULLQUARK) return False; + + // if the quark list starts with a tighly bound quark, we skip it, + // as it is the exactly matched the prefix. Otherwise, it matched because + // it started with "*", in which case we assuime the prefix is part + // of the "*". + if (*bindings == XrmBindTightly) + { + ++quarks, ++bindings; // skip if this is a fixed prefix, rather than a *-match + if (*quarks == NULLQUARK) return False; + } + + // specific, a bit misleadingly named, is used when a specific "subclass" + // is iterated over, e.g. "keysym", and is used to skip one more + // component, as well as all generic prefixes + // this is a bit of a hack, ideally, keysym (the only user) should use its + // own iteration function, but this ought to be less bloated + if (data->specific) + { + if (*bindings != XrmBindTightly) + return False; + + ++quarks, ++bindings; // skip if this is a fixed prefix, rather than a *-match + if (*quarks == NULLQUARK) return False; + } + + char *pattern; + if (quarks[1] == NULLQUARK) + pattern = XrmQuarkToString (quarks[0]); // single component, fats path + else + { + // multiple components, slow path - should be rare, to don't optimize for speed + int size = 0; + + for (int i = 0; quarks[i] != NULLQUARK; ++i) + size += strlen (XrmQuarkToString (quarks[i])) + 1; + + pattern = rxvt_temp_buf (size + 1); + + // now print all components + { + char *cur = pattern; + + for (int i = 0; quarks[i] != NULLQUARK; ++i) + cur += sprintf (cur, ".%s", XrmQuarkToString (quarks[i])); + } + + ++pattern; // skip initial dot + } + + data->cb (data->term, pattern, (char *)value->addr); + + return False; +} + void -rxvt_term::enumerate_keysym_resources (void (*cb)(rxvt_term *, const char *, const char *)) +rxvt_term::enumerate_resources (void (*cb)(rxvt_term *, const char *, const char *), const char *name_p, const char *class_p) { -#ifndef NO_RESOURCES /* * [R5 or later]: enumerate the resource database */ -# ifdef KEYSYM_RESOURCE - void *closure[2] = { - (void *)this, - (void *)cb, - }; + assert (!name_p == !class_p); // both must be specified, or missing + +#ifdef KEYSYM_RESOURCE + rxvt_enumerate_closure closure = { this, cb, name_p ? 1 : 0 }; 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] = name_p ? XrmStringToName (name_p) : NULLQUARK; name_prefix[2] = NULLQUARK; - class_prefix[0] = XrmStringToName (RESCLASS); - class_prefix[1] = XrmStringToName ("Keysym"); + class_prefix[1] = class_p ? XrmStringToName (class_p) : NULLQUARK; class_prefix[2] = NULLQUARK; - /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ - XrmEnumerateDatabase (database, name_prefix, class_prefix, - XrmEnumOneLevel, rxvt_keysym_enumerate_helper, (XPointer)closure); -# ifdef RESFALLBACK + +# ifdef RESFALLBACK 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_keysym_enumerate_helper, (XPointer)closure); -# endif -# endif + XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure); +# endif -#endif /* NO_RESOURCES */ + name_prefix[0] = class_prefix[0] = XrmStringToName (RESCLASS); + XrmEnumerateDatabase (database, name_prefix, class_prefix, + XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure); + + name_prefix[0] = class_prefix[0] = XrmStringToName (rs[Rs_name]); + XrmEnumerateDatabase (database, name_prefix, class_prefix, + XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure); +#endif } void rxvt_term::extract_keysym_resources () { +#ifdef KEYSYM_RESOURCE enumerate_keysym_resources (rxvt_define_key); +#endif } /*----------------------- end-of-file (C source) -----------------------*/