# HG changeset patch # User Karl Heuer # Date 801417651 0 # Node ID 2314b62ca4ab3b39f3b54564622e5d979d1f0238 # Parent 03675a5517469396a8aa5b447bd948adfbcc658d (Fx_get_resource): Major rewrite to make it clearer. (validate_x_resource_name): Use build_string, not make_string. (Fx_create_frame): Initially use Vinvocation_name as resource name. Switch to frame name if frame name is explicit. (x_display_info_for_name, Fx_open_connection): Add casts. Initially use Vinvocation_name as resource name. [USE_X_TOOLKIT] (x_window): Use Vx_resource_name for widget names. diff -r 03675a551746 -r 2314b62ca4ab src/xfns.c --- a/src/xfns.c Thu May 25 15:53:35 1995 +0000 +++ b/src/xfns.c Thu May 25 16:00:51 1995 +0000 @@ -1789,7 +1789,9 @@ /* Subroutines of creating an X frame. */ -/* Make sure that Vx_resource_name is set to a reasonable value. */ +/* Make sure that Vx_resource_name is set to a reasonable value. + Fix it up, or set it to `emacs' if it is too hopeless. */ + static void validate_x_resource_name () { @@ -1834,7 +1836,7 @@ if (good_count == 0 || (good_count == 1 && bad_count > 0)) { - Vx_resource_name = make_string ("emacs", 5); + Vx_resource_name = build_string ("emacs"); return; } @@ -1873,7 +1875,6 @@ register char *value; char *name_key; char *class_key; - Lisp_Object resname; check_x (); @@ -1888,47 +1889,40 @@ error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither"); validate_x_resource_name (); - resname = Vx_resource_name; - - if (NILP (component)) + + /* Allocate space for the components, the dots which separate them, + and the final '\0'. Make them big enough for the worst case. */ + name_key = (char *) alloca (XSTRING (Vx_resource_name)->size + + (STRINGP (component) + ? XSTRING (component)->size : 0) + + XSTRING (attribute)->size + + 3); + + class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1) + + XSTRING (class)->size + + (STRINGP (subclass) + ? XSTRING (subclass)->size : 0) + + 3); + + /* Start with emacs.FRAMENAME for the name (the specific one) + and with `Emacs' for the class key (the general one). */ + strcpy (name_key, XSTRING (Vx_resource_name)->data); + strcpy (class_key, EMACS_CLASS); + + strcat (class_key, "."); + strcat (class_key, XSTRING (class)->data); + + if (!NILP (component)) { - /* Allocate space for the components, the dots which separate them, - and the final '\0'. */ - name_key = (char *) alloca (XSTRING (resname)->size - + XSTRING (attribute)->size - + 2); - class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1) - + XSTRING (class)->size - + 2); - - sprintf (name_key, "%s.%s", - XSTRING (resname)->data, - XSTRING (attribute)->data); - sprintf (class_key, "%s.%s", - EMACS_CLASS, - XSTRING (class)->data); + strcat (class_key, "."); + strcat (class_key, XSTRING (subclass)->data); + + strcat (name_key, "."); + strcat (name_key, XSTRING (component)->data); } - else - { - name_key = (char *) alloca (XSTRING (resname)->size - + XSTRING (component)->size - + XSTRING (attribute)->size - + 3); - - class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1) - + XSTRING (class)->size - + XSTRING (subclass)->size - + 3); - - sprintf (name_key, "%s.%s.%s", - XSTRING (resname)->data, - XSTRING (component)->data, - XSTRING (attribute)->data); - sprintf (class_key, "%s.%s.%s", - EMACS_CLASS, - XSTRING (class)->data, - XSTRING (subclass)->data); - } + + strcat (name_key, "."); + strcat (name_key, XSTRING (attribute)->data); value = x_get_string_resource (check_x_display_info (Qnil)->xrdb, name_key, class_key); @@ -2362,10 +2356,15 @@ BLOCK_INPUT; + /* Use the resource name as the top-level widget name + for looking up resources. Make a non-Lisp copy + for the window manager, so GC relocation won't bother it. + + Elsewhere we specify the window name for the window manager. */ + { - char *str - = (STRINGP (f->name) ? (char *)XSTRING (f->name)->data : "emacs"); - f->namebuf = (char *) xrealloc (f->namebuf, strlen (str) + 1); + char *str = (char *) XSTRING (Vx_resource_name)->data; + f->namebuf = (char *) xmalloc (strlen (str) + 1); strcpy (f->namebuf, str); } @@ -2472,6 +2471,7 @@ FRAME_X_WINDOW (f) = XtWindow (frame_widget); validate_x_resource_name (); + class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data; class_hints.res_class = EMACS_CLASS; XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints); @@ -2565,6 +2565,7 @@ attribute_mask, &attributes); validate_x_resource_name (); + class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data; class_hints.res_class = EMACS_CLASS; XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints); @@ -2756,6 +2757,10 @@ check_x (); + /* Use this general default value to start with + until we know if this frame has a specified name. */ + Vx_resource_name = Vinvocation_name; + display = x_get_arg (parms, Qdisplay, 0, 0, 0); if (EQ (display, Qunbound)) display = Qnil; @@ -2772,6 +2777,9 @@ && ! NILP (name)) error ("Invalid frame name--not a string or nil"); + if (STRINGP (name)) + Vx_resource_name = name; + /* See if parent window is specified. */ parent = x_get_arg (parms, Qparent_id, NULL, NULL, number); if (EQ (parent, Qunbound)) @@ -4559,10 +4567,13 @@ return dpyinfo; } + /* Use this general default value to start with. */ + Vx_resource_name = Vinvocation_name; + validate_x_resource_name (); dpyinfo = x_term_init (name, (unsigned char *)0, - XSTRING (Vx_resource_name)->data); + (char *) XSTRING (Vx_resource_name)->data); if (dpyinfo == 0) error ("X server %s not responding", XSTRING (name)->data); @@ -4595,12 +4606,15 @@ else xrm_option = (unsigned char *) 0; + /* Use this general default value to start with. */ + Vx_resource_name = Vinvocation_name; + validate_x_resource_name (); /* This is what opens the connection and sets x_current_display. This also initializes many symbols, such as those used for input. */ dpyinfo = x_term_init (display, xrm_option, - XSTRING (Vx_resource_name)->data); + (char *) XSTRING (Vx_resource_name)->data); if (dpyinfo == 0) {