comparison src/xfns.c @ 11917:2314b62ca4ab

(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.
author Karl Heuer <kwzh@gnu.org>
date Thu, 25 May 1995 16:00:51 +0000
parents 54186a96c5b2
children f3fb1e5dfde1
comparison
equal deleted inserted replaced
11916:03675a551746 11917:2314b62ca4ab
1787 } 1787 }
1788 } 1788 }
1789 1789
1790 /* Subroutines of creating an X frame. */ 1790 /* Subroutines of creating an X frame. */
1791 1791
1792 /* Make sure that Vx_resource_name is set to a reasonable value. */ 1792 /* Make sure that Vx_resource_name is set to a reasonable value.
1793 Fix it up, or set it to `emacs' if it is too hopeless. */
1794
1793 static void 1795 static void
1794 validate_x_resource_name () 1796 validate_x_resource_name ()
1795 { 1797 {
1796 int len; 1798 int len;
1797 /* Number of valid characters in the resource name. */ 1799 /* Number of valid characters in the resource name. */
1832 1834
1833 /* If name is entirely invalid, or nearly so, use `emacs'. */ 1835 /* If name is entirely invalid, or nearly so, use `emacs'. */
1834 if (good_count == 0 1836 if (good_count == 0
1835 || (good_count == 1 && bad_count > 0)) 1837 || (good_count == 1 && bad_count > 0))
1836 { 1838 {
1837 Vx_resource_name = make_string ("emacs", 5); 1839 Vx_resource_name = build_string ("emacs");
1838 return; 1840 return;
1839 } 1841 }
1840 1842
1841 /* Name is partly valid. Copy it and replace the invalid characters 1843 /* Name is partly valid. Copy it and replace the invalid characters
1842 with underscores. */ 1844 with underscores. */
1871 Lisp_Object attribute, class, component, subclass; 1873 Lisp_Object attribute, class, component, subclass;
1872 { 1874 {
1873 register char *value; 1875 register char *value;
1874 char *name_key; 1876 char *name_key;
1875 char *class_key; 1877 char *class_key;
1876 Lisp_Object resname;
1877 1878
1878 check_x (); 1879 check_x ();
1879 1880
1880 CHECK_STRING (attribute, 0); 1881 CHECK_STRING (attribute, 0);
1881 CHECK_STRING (class, 0); 1882 CHECK_STRING (class, 0);
1886 CHECK_STRING (subclass, 2); 1887 CHECK_STRING (subclass, 2);
1887 if (NILP (component) != NILP (subclass)) 1888 if (NILP (component) != NILP (subclass))
1888 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither"); 1889 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
1889 1890
1890 validate_x_resource_name (); 1891 validate_x_resource_name ();
1891 resname = Vx_resource_name; 1892
1892 1893 /* Allocate space for the components, the dots which separate them,
1893 if (NILP (component)) 1894 and the final '\0'. Make them big enough for the worst case. */
1894 { 1895 name_key = (char *) alloca (XSTRING (Vx_resource_name)->size
1895 /* Allocate space for the components, the dots which separate them, 1896 + (STRINGP (component)
1896 and the final '\0'. */ 1897 ? XSTRING (component)->size : 0)
1897 name_key = (char *) alloca (XSTRING (resname)->size 1898 + XSTRING (attribute)->size
1898 + XSTRING (attribute)->size 1899 + 3);
1899 + 2); 1900
1900 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1) 1901 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
1901 + XSTRING (class)->size 1902 + XSTRING (class)->size
1902 + 2); 1903 + (STRINGP (subclass)
1903 1904 ? XSTRING (subclass)->size : 0)
1904 sprintf (name_key, "%s.%s", 1905 + 3);
1905 XSTRING (resname)->data, 1906
1906 XSTRING (attribute)->data); 1907 /* Start with emacs.FRAMENAME for the name (the specific one)
1907 sprintf (class_key, "%s.%s", 1908 and with `Emacs' for the class key (the general one). */
1908 EMACS_CLASS, 1909 strcpy (name_key, XSTRING (Vx_resource_name)->data);
1909 XSTRING (class)->data); 1910 strcpy (class_key, EMACS_CLASS);
1910 } 1911
1911 else 1912 strcat (class_key, ".");
1912 { 1913 strcat (class_key, XSTRING (class)->data);
1913 name_key = (char *) alloca (XSTRING (resname)->size 1914
1914 + XSTRING (component)->size 1915 if (!NILP (component))
1915 + XSTRING (attribute)->size 1916 {
1916 + 3); 1917 strcat (class_key, ".");
1917 1918 strcat (class_key, XSTRING (subclass)->data);
1918 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1) 1919
1919 + XSTRING (class)->size 1920 strcat (name_key, ".");
1920 + XSTRING (subclass)->size 1921 strcat (name_key, XSTRING (component)->data);
1921 + 3); 1922 }
1922 1923
1923 sprintf (name_key, "%s.%s.%s", 1924 strcat (name_key, ".");
1924 XSTRING (resname)->data, 1925 strcat (name_key, XSTRING (attribute)->data);
1925 XSTRING (component)->data,
1926 XSTRING (attribute)->data);
1927 sprintf (class_key, "%s.%s.%s",
1928 EMACS_CLASS,
1929 XSTRING (class)->data,
1930 XSTRING (subclass)->data);
1931 }
1932 1926
1933 value = x_get_string_resource (check_x_display_info (Qnil)->xrdb, 1927 value = x_get_string_resource (check_x_display_info (Qnil)->xrdb,
1934 name_key, class_key); 1928 name_key, class_key);
1935 1929
1936 if (value != (char *) 0) 1930 if (value != (char *) 0)
2360 Arg al [25]; 2354 Arg al [25];
2361 int ac; 2355 int ac;
2362 2356
2363 BLOCK_INPUT; 2357 BLOCK_INPUT;
2364 2358
2359 /* Use the resource name as the top-level widget name
2360 for looking up resources. Make a non-Lisp copy
2361 for the window manager, so GC relocation won't bother it.
2362
2363 Elsewhere we specify the window name for the window manager. */
2364
2365 { 2365 {
2366 char *str 2366 char *str = (char *) XSTRING (Vx_resource_name)->data;
2367 = (STRINGP (f->name) ? (char *)XSTRING (f->name)->data : "emacs"); 2367 f->namebuf = (char *) xmalloc (strlen (str) + 1);
2368 f->namebuf = (char *) xrealloc (f->namebuf, strlen (str) + 1);
2369 strcpy (f->namebuf, str); 2368 strcpy (f->namebuf, str);
2370 } 2369 }
2371 2370
2372 ac = 0; 2371 ac = 0;
2373 XtSetArg (al[ac], XtNallowShellResize, 1); ac++; 2372 XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
2470 XtRealizeWidget (shell_widget); 2469 XtRealizeWidget (shell_widget);
2471 2470
2472 FRAME_X_WINDOW (f) = XtWindow (frame_widget); 2471 FRAME_X_WINDOW (f) = XtWindow (frame_widget);
2473 2472
2474 validate_x_resource_name (); 2473 validate_x_resource_name ();
2474
2475 class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data; 2475 class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data;
2476 class_hints.res_class = EMACS_CLASS; 2476 class_hints.res_class = EMACS_CLASS;
2477 XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints); 2477 XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints);
2478 2478
2479 f->display.x->wm_hints.input = True; 2479 f->display.x->wm_hints.input = True;
2563 InputOutput, /* class */ 2563 InputOutput, /* class */
2564 FRAME_X_DISPLAY_INFO (f)->visual, 2564 FRAME_X_DISPLAY_INFO (f)->visual,
2565 attribute_mask, &attributes); 2565 attribute_mask, &attributes);
2566 2566
2567 validate_x_resource_name (); 2567 validate_x_resource_name ();
2568
2568 class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data; 2569 class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data;
2569 class_hints.res_class = EMACS_CLASS; 2570 class_hints.res_class = EMACS_CLASS;
2570 XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints); 2571 XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints);
2571 2572
2572 /* The menubar is part of the ordinary display; 2573 /* The menubar is part of the ordinary display;
2754 Lisp_Object parent; 2755 Lisp_Object parent;
2755 struct kboard *kb; 2756 struct kboard *kb;
2756 2757
2757 check_x (); 2758 check_x ();
2758 2759
2760 /* Use this general default value to start with
2761 until we know if this frame has a specified name. */
2762 Vx_resource_name = Vinvocation_name;
2763
2759 display = x_get_arg (parms, Qdisplay, 0, 0, 0); 2764 display = x_get_arg (parms, Qdisplay, 0, 0, 0);
2760 if (EQ (display, Qunbound)) 2765 if (EQ (display, Qunbound))
2761 display = Qnil; 2766 display = Qnil;
2762 dpyinfo = check_x_display_info (display); 2767 dpyinfo = check_x_display_info (display);
2763 #ifdef MULTI_KBOARD 2768 #ifdef MULTI_KBOARD
2769 name = x_get_arg (parms, Qname, "title", "Title", string); 2774 name = x_get_arg (parms, Qname, "title", "Title", string);
2770 if (!STRINGP (name) 2775 if (!STRINGP (name)
2771 && ! EQ (name, Qunbound) 2776 && ! EQ (name, Qunbound)
2772 && ! NILP (name)) 2777 && ! NILP (name))
2773 error ("Invalid frame name--not a string or nil"); 2778 error ("Invalid frame name--not a string or nil");
2779
2780 if (STRINGP (name))
2781 Vx_resource_name = name;
2774 2782
2775 /* See if parent window is specified. */ 2783 /* See if parent window is specified. */
2776 parent = x_get_arg (parms, Qparent_id, NULL, NULL, number); 2784 parent = x_get_arg (parms, Qparent_id, NULL, NULL, number);
2777 if (EQ (parent, Qunbound)) 2785 if (EQ (parent, Qunbound))
2778 parent = Qnil; 2786 parent = Qnil;
4557 tem = Fstring_equal (XCONS (XCONS (names)->car)->car, name); 4565 tem = Fstring_equal (XCONS (XCONS (names)->car)->car, name);
4558 if (!NILP (tem)) 4566 if (!NILP (tem))
4559 return dpyinfo; 4567 return dpyinfo;
4560 } 4568 }
4561 4569
4570 /* Use this general default value to start with. */
4571 Vx_resource_name = Vinvocation_name;
4572
4562 validate_x_resource_name (); 4573 validate_x_resource_name ();
4563 4574
4564 dpyinfo = x_term_init (name, (unsigned char *)0, 4575 dpyinfo = x_term_init (name, (unsigned char *)0,
4565 XSTRING (Vx_resource_name)->data); 4576 (char *) XSTRING (Vx_resource_name)->data);
4566 4577
4567 if (dpyinfo == 0) 4578 if (dpyinfo == 0)
4568 error ("X server %s not responding", XSTRING (name)->data); 4579 error ("X server %s not responding", XSTRING (name)->data);
4569 4580
4570 x_in_use = 1; 4581 x_in_use = 1;
4593 if (! NILP (xrm_string)) 4604 if (! NILP (xrm_string))
4594 xrm_option = (unsigned char *) XSTRING (xrm_string)->data; 4605 xrm_option = (unsigned char *) XSTRING (xrm_string)->data;
4595 else 4606 else
4596 xrm_option = (unsigned char *) 0; 4607 xrm_option = (unsigned char *) 0;
4597 4608
4609 /* Use this general default value to start with. */
4610 Vx_resource_name = Vinvocation_name;
4611
4598 validate_x_resource_name (); 4612 validate_x_resource_name ();
4599 4613
4600 /* This is what opens the connection and sets x_current_display. 4614 /* This is what opens the connection and sets x_current_display.
4601 This also initializes many symbols, such as those used for input. */ 4615 This also initializes many symbols, such as those used for input. */
4602 dpyinfo = x_term_init (display, xrm_option, 4616 dpyinfo = x_term_init (display, xrm_option,
4603 XSTRING (Vx_resource_name)->data); 4617 (char *) XSTRING (Vx_resource_name)->data);
4604 4618
4605 if (dpyinfo == 0) 4619 if (dpyinfo == 0)
4606 { 4620 {
4607 if (!NILP (must_succeed)) 4621 if (!NILP (must_succeed))
4608 fatal ("X server %s not responding.\n\ 4622 fatal ("X server %s not responding.\n\