aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKaroly Lorentey2004-07-04 04:48:55 +0000
committerKaroly Lorentey2004-07-04 04:48:55 +0000
commitb6660415b3094d37b27e8d303f2c57c4c2a60700 (patch)
tree715ac1a52f92c0e5d6d25bd089ba9c048b012339 /src
parent91b726f0f87d0adcec194642256375f4302c52a8 (diff)
downloademacs-b6660415b3094d37b27e8d303f2c57c4c2a60700.tar.gz
emacs-b6660415b3094d37b27e8d303f2c57c4c2a60700.zip
Implemented display ids for multiple emacsclients on the same tty. Plus assorted bugfixes.
* lisp/frame.el (make-frame-on-display): Update doc. (make-frame): Handle display-id parameter. Update doc. (frames-on-display-list): Update for display ids. (framep-on-display): Ditto. (suspend-frame): Use display-name, not frame-tty-name. (selected-display): New function. * lisp/server.el (server-delete-client): Use delete-display, not delete-tty. (server-tty-live-p, server-handle-delete-tty): Removed. (server-handle-delete-frame): Delete tty clients, if needed. (server-process-filter): Set the display parameter, and use it when appropriate. (server-handle-suspend-tty): Use the display parameter. (server-start, server-unload-hook): Removed obsolete delete-tty hook. * lisp/talk.el (talk): Always use talk-add-display. (talk-add-tty-frame, talk-handle-delete-tty): Removed. (talk-handle-delete-frame): New function. (talk-add-display): Open a new frame only if parameter was not a frame. * src/dispextern.h (get_display, Fdisplay_tty_type): New prototypes. (Fframe_tty_type): Removed. * src/dispnew.c (init_display): Use Fdisplay_tty_type, not Fframe_tty_type. * src/frame.c (Qdisplay_id, Qdisplay_live_p): New symbols. (make_terminal_frame): Get display as a parameter. (Fmake_terminal_frame): Get/create display here; pass it to make_terminal_frame. (Fframe_display): New function. (Fdelete_frame): Stop if the hook deleted the frame. (syms_of_frame): Register new stuff. * src/frame.h (Qdisplay_id, Qdisplay_live_p, make_terminal_frame): Updated prototypes. * src/keyboard.c (interrupt_signal): Updated comment. * src/term.c (Vdelete_tty_after_functions): Removed variable. (Qframe_tty_name, Qframe_tty_type): Removed. (next_display_id): New var. (tty_ring_bell): Don't do anything on suspended frames. (Ftty_display_color_p, Ftty_display_color_cells): Doc update. (get_display): New function. (get_tty_display): Use it. (get_named_tty_display): Ignore suspended displays. (Fframe_tty_name): Renamed to Fdisplay_name. Handle all kinds of displays. (Fframe_tty_type): Renamed to Fdisplay_tty_type. (init_initial_display): Set display name. (term_init): Allow more displays on the same device. Set display name. (Fdelete_tty): Removed. (delete_tty): Don't run hooks. (create_display): Set display id. (delete_display): Free display name. (Fdelete_display, Fdisplay_live_p, Fdisplay_list): New functions. (Fsuspend_tty): Call hook with display id. Doc update. (Fresume_tty): Refuse to resume when there is already an active display on the same device. Call hook with display id. Doc update. (syms_of_term): Reflect above changes. * src/termhooks.h (struct display): Added `id' and `name' members. (DISPLAY_ACTIVE_P): New macro. * src/xfns.c (check_x_display_info): Handle display ids. (Fx_create_frame): Try to get display from `display-id' parameter. * src/xterm.c (x_term_init): Set display name. (x_delete_display): Handle the case when `font_table' is NULL. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-207
Diffstat (limited to 'src')
-rw-r--r--src/dispextern.h3
-rw-r--r--src/dispnew.c2
-rw-r--r--src/frame.c150
-rw-r--r--src/frame.h3
-rw-r--r--src/keyboard.c2
-rw-r--r--src/term.c421
-rw-r--r--src/termhooks.h13
-rw-r--r--src/xfns.c15
-rw-r--r--src/xterm.c10
9 files changed, 362 insertions, 257 deletions
diff --git a/src/dispextern.h b/src/dispextern.h
index f48cdbbe273..c438ad0f9dd 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2859,8 +2859,9 @@ extern int per_line_cost P_ ((char *));
2859extern void calculate_costs P_ ((struct frame *)); 2859extern void calculate_costs P_ ((struct frame *));
2860extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object)); 2860extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object));
2861extern void tty_setup_colors P_ ((struct tty_display_info *, int)); 2861extern void tty_setup_colors P_ ((struct tty_display_info *, int));
2862extern struct display *get_display P_ ((Lisp_Object display));
2862extern struct display *get_named_tty_display P_ ((char *)); 2863extern struct display *get_named_tty_display P_ ((char *));
2863extern Lisp_Object Fframe_tty_type P_ ((Lisp_Object)); 2864EXFUN (Fdisplay_tty_type, 1);
2864extern struct display *init_initial_display P_ ((void)); 2865extern struct display *init_initial_display P_ ((void));
2865extern struct display *term_init P_ ((char *, char *, int)); 2866extern struct display *term_init P_ ((char *, char *, int));
2866extern void delete_tty P_ ((struct display *)); 2867extern void delete_tty P_ ((struct display *));
diff --git a/src/dispnew.c b/src/dispnew.c
index 8d64a954619..b519dfa0752 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6757,7 +6757,7 @@ For types not defined in VMS, use define emacs_term \"TYPE\".\n\
6757 /* Update frame parameters to reflect the new type. */ 6757 /* Update frame parameters to reflect the new type. */
6758 Fmodify_frame_parameters 6758 Fmodify_frame_parameters
6759 (selected_frame, Fcons (Fcons (Qtty_type, 6759 (selected_frame, Fcons (Fcons (Qtty_type,
6760 Fframe_tty_type (selected_frame)), Qnil)); 6760 Fdisplay_tty_type (selected_frame)), Qnil));
6761 } 6761 }
6762 6762
6763 { 6763 {
diff --git a/src/frame.c b/src/frame.c
index 7917b9ecdd6..41ee5a64bd5 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -76,6 +76,8 @@ Lisp_Object Qinhibit_default_face_x_resources;
76 76
77Lisp_Object Qx_frame_parameter; 77Lisp_Object Qx_frame_parameter;
78Lisp_Object Qx_resource_name; 78Lisp_Object Qx_resource_name;
79Lisp_Object Qdisplay_id;
80Lisp_Object Qdisplay_live_p;
79 81
80/* Frame parameters (set or reported). */ 82/* Frame parameters (set or reported). */
81 83
@@ -558,19 +560,12 @@ make_initial_frame (void)
558 560
559 561
560struct frame * 562struct frame *
561make_terminal_frame (tty_name, tty_type) 563make_terminal_frame (struct display *display)
562 char *tty_name;
563 char *tty_type;
564{ 564{
565 register struct frame *f; 565 register struct frame *f;
566 struct display *display;
567 Lisp_Object frame; 566 Lisp_Object frame;
568 char name[20]; 567 char name[20];
569 568
570 /* Open the display before creating the new frame, because
571 create_tty_display might throw an error. */
572 display = term_init (tty_name, tty_type, 0); /* Errors are not fatal. */
573
574 f = make_frame (1); 569 f = make_frame (1);
575 570
576 XSETFRAME (frame, f); 571 XSETFRAME (frame, f);
@@ -673,6 +668,7 @@ affects all frames on the same terminal device. */)
673 Lisp_Object parms; 668 Lisp_Object parms;
674{ 669{
675 struct frame *f; 670 struct frame *f;
671 struct display *d = NULL;
676 Lisp_Object frame, tem; 672 Lisp_Object frame, tem;
677 struct frame *sf = SELECTED_FRAME (); 673 struct frame *sf = SELECTED_FRAME ();
678 674
@@ -692,53 +688,70 @@ affects all frames on the same terminal device. */)
692#endif 688#endif
693#endif 689#endif
694#endif /* not MSDOS */ 690#endif /* not MSDOS */
691
692 {
693 Lisp_Object display_device;
695 694
696 { 695 display_device = Fassq (Qdisplay_id, parms);
697 Lisp_Object tty, tty_type; 696 if (!NILP (display_device))
698 char *name = 0, *type = 0;
699
700 tty = Fassq (Qtty, parms);
701 if (EQ (tty, Qnil))
702 tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
703 if (EQ (tty, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
704 && FRAME_TTY (XFRAME (selected_frame))->name)
705 tty = build_string (FRAME_TTY (XFRAME (selected_frame))->name);
706 if (EQ (tty, Qnil))
707 tty = Fassq (Qtty, Vdefault_frame_alist);
708 if (! EQ (tty, Qnil) && ! STRINGP (tty))
709 tty = XCDR (tty);
710 if (EQ (tty, Qnil) || !STRINGP (tty))
711 tty = Qnil;
712
713 tty_type = Fassq (Qtty_type, parms);
714 if (EQ (tty_type, Qnil))
715 tty_type = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
716 if (EQ (tty_type, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
717 && FRAME_TTY (XFRAME (selected_frame))->type)
718 tty_type = build_string (FRAME_TTY (XFRAME (selected_frame))->type);
719 if (EQ (tty_type, Qnil))
720 tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
721 if (! EQ (tty_type, Qnil) && ! STRINGP (tty_type))
722 tty_type = XCDR (tty_type);
723 if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
724 tty_type = Qnil;
725
726 if (! EQ (tty, Qnil))
727 {
728 name = (char *) alloca (SBYTES (tty) + 1);
729 strncpy (name, SDATA (tty), SBYTES (tty));
730 name[SBYTES (tty)] = 0;
731 }
732
733 if (! EQ (tty_type, Qnil))
734 { 697 {
735 type = (char *) alloca (SBYTES (tty_type) + 1); 698 display_device = XCDR (display_device);
736 strncpy (type, SDATA (tty_type), SBYTES (tty_type)); 699 CHECK_NUMBER (display_device);
737 type[SBYTES (tty_type)] = 0; 700 d = get_display (XINT (display_device));
701 if (!d)
702 wrong_type_argument (Qdisplay_live_p, display_device);
738 } 703 }
739
740 f = make_terminal_frame (name, type);
741 } 704 }
705
706 if (!d)
707 {
708 Lisp_Object tty, tty_type;
709 char *name = 0, *type = 0;
710
711 tty = Fassq (Qtty, parms);
712 if (EQ (tty, Qnil))
713 tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
714 if (EQ (tty, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
715 && FRAME_TTY (XFRAME (selected_frame))->name)
716 tty = build_string (FRAME_TTY (XFRAME (selected_frame))->name);
717 if (EQ (tty, Qnil))
718 tty = Fassq (Qtty, Vdefault_frame_alist);
719 if (! EQ (tty, Qnil) && ! STRINGP (tty))
720 tty = XCDR (tty);
721 if (EQ (tty, Qnil) || !STRINGP (tty))
722 tty = Qnil;
723
724 tty_type = Fassq (Qtty_type, parms);
725 if (EQ (tty_type, Qnil))
726 tty_type = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
727 if (EQ (tty_type, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
728 && FRAME_TTY (XFRAME (selected_frame))->type)
729 tty_type = build_string (FRAME_TTY (XFRAME (selected_frame))->type);
730 if (EQ (tty_type, Qnil))
731 tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
732 if (! EQ (tty_type, Qnil) && ! STRINGP (tty_type))
733 tty_type = XCDR (tty_type);
734 if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
735 tty_type = Qnil;
736
737 if (! EQ (tty, Qnil))
738 {
739 name = (char *) alloca (SBYTES (tty) + 1);
740 strncpy (name, SDATA (tty), SBYTES (tty));
741 name[SBYTES (tty)] = 0;
742 }
743
744 if (! EQ (tty_type, Qnil))
745 {
746 type = (char *) alloca (SBYTES (tty_type) + 1);
747 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
748 type[SBYTES (tty_type)] = 0;
749 }
750
751 d = term_init (name, type, 0); /* Errors are not fatal. */
752 }
753
754 f = make_terminal_frame (d);
742 755
743 { 756 {
744 int width, height; 757 int width, height;
@@ -1046,6 +1059,31 @@ If FRAME is the selected frame, this makes WINDOW the selected window. */)
1046 return XFRAME (frame)->selected_window = window; 1059 return XFRAME (frame)->selected_window = window;
1047} 1060}
1048 1061
1062
1063DEFUN ("frame-display", Fframe_display, Sframe_display, 0, 1, 0,
1064 doc: /* Return the display device that FRAME is displayed on.
1065If FRAME is nil, the selected frame is used.
1066
1067The display device is represented by its integer identifier. */)
1068 (frame)
1069 Lisp_Object frame;
1070{
1071 struct display *d;
1072
1073 if (NILP (frame))
1074 frame = selected_frame;
1075
1076 CHECK_LIVE_FRAME (frame);
1077
1078 d = get_display (frame);
1079
1080 if (!d)
1081 return Qnil;
1082 else
1083 return make_number (d->id);
1084}
1085
1086
1049DEFUN ("frame-list", Fframe_list, Sframe_list, 1087DEFUN ("frame-list", Fframe_list, Sframe_list,
1050 0, 0, 0, 1088 0, 0, 0,
1051 doc: /* Return a list of all frames. */) 1089 doc: /* Return a list of all frames. */)
@@ -1387,6 +1425,10 @@ The functions are run with one arg, the frame to be deleted. */)
1387 Frun_hook_with_args (2, args); 1425 Frun_hook_with_args (2, args);
1388 } 1426 }
1389 1427
1428 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1429 if (! FRAME_LIVE_P (f))
1430 return Qnil;
1431
1390 minibuffer_selected = EQ (minibuf_window, selected_window); 1432 minibuffer_selected = EQ (minibuf_window, selected_window);
1391 1433
1392 /* Don't let the frame remain selected. */ 1434 /* Don't let the frame remain selected. */
@@ -4154,6 +4196,11 @@ syms_of_frame ()
4154 Qx_frame_parameter = intern ("x-frame-parameter"); 4196 Qx_frame_parameter = intern ("x-frame-parameter");
4155 staticpro (&Qx_frame_parameter); 4197 staticpro (&Qx_frame_parameter);
4156 4198
4199 Qdisplay_id = intern ("display-id");
4200 staticpro (&Qdisplay_id);
4201 Qdisplay_live_p = intern ("display-live-p");
4202 staticpro (&Qdisplay_live_p);
4203
4157 { 4204 {
4158 int i; 4205 int i;
4159 4206
@@ -4286,6 +4333,7 @@ This variable is local to the current terminal and cannot be buffer-local. */);
4286 defsubr (&Sframe_first_window); 4333 defsubr (&Sframe_first_window);
4287 defsubr (&Sframe_selected_window); 4334 defsubr (&Sframe_selected_window);
4288 defsubr (&Sset_frame_selected_window); 4335 defsubr (&Sset_frame_selected_window);
4336 defsubr (&Sframe_display);
4289 defsubr (&Sframe_list); 4337 defsubr (&Sframe_list);
4290 defsubr (&Snext_frame); 4338 defsubr (&Snext_frame);
4291 defsubr (&Sprevious_frame); 4339 defsubr (&Sprevious_frame);
diff --git a/src/frame.h b/src/frame.h
index 2d87913309f..044aa6e90f0 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -775,11 +775,12 @@ typedef struct frame *FRAME_PTR;
775 775
776extern Lisp_Object Qframep, Qframe_live_p; 776extern Lisp_Object Qframep, Qframe_live_p;
777extern Lisp_Object Qtty, Qtty_type; 777extern Lisp_Object Qtty, Qtty_type;
778extern Lisp_Object Qdisplay_id, Qdisplay_live_p;
778 779
779extern struct frame *last_nonminibuf_frame; 780extern struct frame *last_nonminibuf_frame;
780 781
781extern struct frame *make_initial_frame P_ ((void)); 782extern struct frame *make_initial_frame P_ ((void));
782extern struct frame *make_terminal_frame P_ ((char *, char *)); 783extern struct frame *make_terminal_frame P_ ((struct display *));
783extern struct frame *make_frame P_ ((int)); 784extern struct frame *make_frame P_ ((int));
784#ifdef HAVE_WINDOW_SYSTEM 785#ifdef HAVE_WINDOW_SYSTEM
785extern struct frame *make_minibuffer_frame P_ ((void)); 786extern struct frame *make_minibuffer_frame P_ ((void));
diff --git a/src/keyboard.c b/src/keyboard.c
index e9c9edbd239..0ac88f80805 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -10317,7 +10317,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10317 signal (SIGQUIT, interrupt_signal); 10317 signal (SIGQUIT, interrupt_signal);
10318#endif /* USG */ 10318#endif /* USG */
10319 10319
10320 /* See if we have a display on our controlling terminal. */ 10320 /* See if we have an active display on our controlling terminal. */
10321 display = get_named_tty_display (NULL); 10321 display = get_named_tty_display (NULL);
10322 if (!display) 10322 if (!display)
10323 { 10323 {
diff --git a/src/term.c b/src/term.c
index ae659e422ff..1628de01045 100644
--- a/src/term.c
+++ b/src/term.c
@@ -85,6 +85,8 @@ static void turn_off_face P_ ((struct frame *, int face_id));
85static void tty_show_cursor P_ ((struct tty_display_info *)); 85static void tty_show_cursor P_ ((struct tty_display_info *));
86static void tty_hide_cursor P_ ((struct tty_display_info *)); 86static void tty_hide_cursor P_ ((struct tty_display_info *));
87 87
88static struct display *get_tty_display (Lisp_Object display);
89
88void delete_initial_display P_ ((struct display *)); 90void delete_initial_display P_ ((struct display *));
89void create_tty_output P_ ((struct frame *)); 91void create_tty_output P_ ((struct frame *));
90void delete_tty_output P_ ((struct frame *)); 92void delete_tty_output P_ ((struct frame *));
@@ -117,9 +119,6 @@ extern Lisp_Object Qspace, QCalign_to, QCwidth;
117 119
118Lisp_Object Vring_bell_function; 120Lisp_Object Vring_bell_function;
119 121
120/* Functions to call after deleting a tty. */
121Lisp_Object Vdelete_tty_after_functions;
122
123/* Functions to call after suspending a tty. */ 122/* Functions to call after suspending a tty. */
124Lisp_Object Vsuspend_tty_functions; 123Lisp_Object Vsuspend_tty_functions;
125 124
@@ -141,9 +140,6 @@ struct tty_display_info *tty_list;
141 else. */ 140 else. */
142int no_redraw_on_reenter; 141int no_redraw_on_reenter;
143 142
144Lisp_Object Qframe_tty_name, Qframe_tty_type;
145
146
147 143
148/* Meaning of bits in no_color_video. Each bit set means that the 144/* Meaning of bits in no_color_video. Each bit set means that the
149 corresponding attribute cannot be combined with colors. */ 145 corresponding attribute cannot be combined with colors. */
@@ -175,6 +171,9 @@ int max_frame_lines;
175 should not open a frame on stdout. */ 171 should not open a frame on stdout. */
176static int no_controlling_tty; 172static int no_controlling_tty;
177 173
174/* The first unallocated display id. */
175static int next_display_id;
176
178/* Provided for lisp packages. */ 177/* Provided for lisp packages. */
179 178
180static int system_uses_terminfo; 179static int system_uses_terminfo;
@@ -228,10 +227,13 @@ tty_ring_bell (struct frame *f)
228{ 227{
229 struct tty_display_info *tty = FRAME_TTY (f); 228 struct tty_display_info *tty = FRAME_TTY (f);
230 229
231 OUTPUT (tty, (tty->TS_visible_bell && visible_bell 230 if (tty->output)
232 ? tty->TS_visible_bell 231 {
233 : tty->TS_bell)); 232 OUTPUT (tty, (tty->TS_visible_bell && visible_bell
234 fflush (tty->output); 233 ? tty->TS_visible_bell
234 : tty->TS_bell));
235 fflush (tty->output);
236 }
235} 237}
236 238
237/* Set up termcap modes for Emacs. */ 239/* Set up termcap modes for Emacs. */
@@ -1925,58 +1927,11 @@ tty_capable_p (tty, caps, fg, bg)
1925 return 1; 1927 return 1;
1926} 1928}
1927 1929
1928/* Return the tty display object specified by DISPLAY. DISPLAY may be
1929 a frame, a string, or nil for the display device of the current
1930 frame. */
1931
1932static struct display *
1933get_tty_display (Lisp_Object display)
1934{
1935 struct display *d;
1936
1937 if (NILP (display))
1938 display = selected_frame;
1939
1940 if (! FRAMEP (display) && ! STRINGP (display))
1941 return 0;
1942
1943 /* The initial frame does not support colors. */
1944 if (FRAMEP (display) && FRAME_INITIAL_P (XFRAME (display)))
1945 return 0;
1946
1947 if (FRAMEP (display))
1948 {
1949 if (! FRAME_TERMCAP_P (XFRAME (display)))
1950#if 0 /* XXX We need a predicate as the first argument; find one. */
1951 wrong_type_argument ("Not a termcap frame", display);
1952#else /* Until we fix the wrong_type_argument call above, simply throw
1953 a dumb error. */
1954 error ("DISPLAY is not a termcap frame");
1955#endif
1956
1957 d = FRAME_DISPLAY (XFRAME (display));
1958 }
1959 else if (STRINGP (display))
1960 {
1961 char *name = (char *) alloca (SBYTES (display) + 1);
1962 strncpy (name, SDATA (display), SBYTES (display));
1963 name[SBYTES (display)] = 0;
1964
1965 d = get_named_tty_display (name);
1966
1967 if (!d)
1968 error ("There is no tty display on %s", name);
1969 }
1970
1971 return d;
1972}
1973
1974
1975/* Return non-zero if the terminal is capable to display colors. */ 1930/* Return non-zero if the terminal is capable to display colors. */
1976 1931
1977DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p, 1932DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
1978 0, 1, 0, 1933 0, 1, 0,
1979 doc: /* Return non-nil if TTY can display colors on DISPLAY. */) 1934 doc: /* Return non-nil if the tty device that DISPLAY uses can display colors. */)
1980 (display) 1935 (display)
1981 Lisp_Object display; 1936 Lisp_Object display;
1982{ 1937{
@@ -1990,7 +1945,7 @@ DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
1990/* Return the number of supported colors. */ 1945/* Return the number of supported colors. */
1991DEFUN ("tty-display-color-cells", Ftty_display_color_cells, 1946DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
1992 Stty_display_color_cells, 0, 1, 0, 1947 Stty_display_color_cells, 0, 1, 0,
1993 doc: /* Return the number of colors supported by TTY on DISPLAY. */) 1948 doc: /* Return the number of colors supported by the tty device that DISPLAY uses. */)
1994 (display) 1949 (display)
1995 Lisp_Object display; 1950 Lisp_Object display;
1996{ 1951{
@@ -2140,8 +2095,62 @@ set_tty_color_mode (f, val)
2140 2095
2141 2096
2142 2097
2143/* Return the termcap display with the given name. If NAME is null, 2098/* Return the display object specified by DISPLAY. DISPLAY may be a
2144 return the display corresponding to our controlling terminal. 2099 display id, a frame, or nil for the display device of the current
2100 frame. */
2101
2102struct display *
2103get_display (Lisp_Object display)
2104{
2105 if (NILP (display))
2106 display = selected_frame;
2107
2108 if (! INTEGERP (display) && ! FRAMEP (display))
2109 return NULL;
2110
2111 if (INTEGERP (display))
2112 {
2113 struct display *d;
2114
2115 for (d = display_list; d; d = d->next_display)
2116 {
2117 if (d->id == XINT (display))
2118 return d;
2119 }
2120 return NULL;
2121 }
2122 else if (FRAMEP (display))
2123 {
2124 return FRAME_DISPLAY (XFRAME (display));
2125 }
2126 return NULL;
2127}
2128
2129/* Return the tty display object specified by DISPLAY. */
2130
2131static struct display *
2132get_tty_display (Lisp_Object display)
2133{
2134 struct display *d = get_display (display);
2135
2136 if (d && d->type != output_termcap)
2137 {
2138#if 0 /* XXX We need a predicate as the first argument; find one. */
2139 wrong_type_argument ("Not a termcap display", display);
2140#else /* Until we fix the wrong_type_argument call above, simply throw
2141 a dumb error. */
2142 error ("DISPLAY is not a termcap display");
2143#endif
2144 }
2145
2146 return d;
2147}
2148
2149/* Return the active termcap display that uses the tty device with the
2150 given name. If NAME is NULL, return the display corresponding to
2151 our controlling terminal.
2152
2153 This function ignores suspended displays.
2145 2154
2146 Returns NULL if the named terminal device is not opened. */ 2155 Returns NULL if the named terminal device is not opened. */
2147 2156
@@ -2155,7 +2164,8 @@ get_named_tty_display (name)
2155 if (d->type == output_termcap 2164 if (d->type == output_termcap
2156 && ((d->display_info.tty->name == 0 && name == 0) 2165 && ((d->display_info.tty->name == 0 && name == 0)
2157 || (name && d->display_info.tty->name 2166 || (name && d->display_info.tty->name
2158 && !strcmp (d->display_info.tty->name, name)))) 2167 && !strcmp (d->display_info.tty->name, name)))
2168 && DISPLAY_ACTIVE_P (d))
2159 return d; 2169 return d;
2160 }; 2170 };
2161 2171
@@ -2164,54 +2174,41 @@ get_named_tty_display (name)
2164 2174
2165 2175
2166 2176
2167DEFUN ("frame-tty-name", Fframe_tty_name, Sframe_tty_name, 0, 1, 0, 2177DEFUN ("display-name", Fdisplay_name, Sdisplay_name, 0, 1, 0,
2168 doc: /* Return the name of the TTY device that FRAME is displayed on. */) 2178 doc: /* Return the name of the device that DISPLAY uses.
2169 (frame) 2179It is not guaranteed that the returned value is unique among opened displays.
2170 Lisp_Object frame;
2171{
2172 struct frame *f;
2173 2180
2174 if (NILP (frame)) 2181DISPLAY can be a display, a frame, or nil (meaning the selected
2175 { 2182frame's display). */)
2176 f = XFRAME (selected_frame); 2183 (display)
2177 } 2184 Lisp_Object display;
2178 else 2185{
2179 { 2186 struct display *d = get_display (display);
2180 CHECK_LIVE_FRAME (frame);
2181 f = XFRAME (frame);
2182 }
2183 2187
2184 if (f->output_method != output_termcap) 2188 if (!d)
2185 wrong_type_argument (Qframe_tty_name, frame); 2189 wrong_type_argument (Qdisplay_live_p, display);
2186 2190
2187 if (FRAME_TTY (f)->name) 2191 if (d->name)
2188 return build_string (FRAME_TTY (f)->name); 2192 return build_string (d->name);
2189 else 2193 else
2190 return Qnil; 2194 return Qnil;
2191} 2195}
2192 2196
2193DEFUN ("frame-tty-type", Fframe_tty_type, Sframe_tty_type, 0, 1, 0,
2194 doc: /* Return the type of the TTY device that FRAME is displayed on. */)
2195 (frame)
2196 Lisp_Object frame;
2197{
2198 struct frame *f;
2199
2200 if (NILP (frame))
2201 {
2202 f = XFRAME (selected_frame);
2203 }
2204 else
2205 {
2206 CHECK_LIVE_FRAME (frame);
2207 f = XFRAME (frame);
2208 }
2209 2197
2210 if (f->output_method != output_termcap) 2198DEFUN ("display-tty-type", Fdisplay_tty_type, Sdisplay_tty_type, 0, 1, 0,
2211 wrong_type_argument (Qframe_tty_type, frame); 2199 doc: /* Return the type of the TTY device that DISPLAY uses. */)
2200 (display)
2201 Lisp_Object display;
2202{
2203 struct display *d = get_display (display);
2212 2204
2213 if (FRAME_TTY (f)->type) 2205 if (!d)
2214 return build_string (FRAME_TTY (f)->type); 2206 wrong_type_argument (Qdisplay_live_p, display);
2207 if (d->type != output_termcap)
2208 error ("Display %d is not a termcap display", d->id);
2209
2210 if (d->display_info.tty->type)
2211 return build_string (d->display_info.tty->type);
2215 else 2212 else
2216 return Qnil; 2213 return Qnil;
2217} 2214}
@@ -2232,7 +2229,8 @@ init_initial_display (void)
2232 2229
2233 initial_display = create_display (); 2230 initial_display = create_display ();
2234 initial_display->type = output_initial; 2231 initial_display->type = output_initial;
2235 2232 initial_display->name = xstrdup ("initial_display");
2233
2236 initial_display->delete_display_hook = &delete_initial_display; 2234 initial_display->delete_display_hook = &delete_initial_display;
2237 /* All other hooks are NULL. */ 2235 /* All other hooks are NULL. */
2238 2236
@@ -2311,18 +2309,15 @@ term_init (char *name, char *terminal_type, int must_succeed)
2311 maybe_fatal (must_succeed, 0, 0, 2309 maybe_fatal (must_succeed, 0, 0,
2312 "Unknown terminal type", 2310 "Unknown terminal type",
2313 "Unknown terminal type"); 2311 "Unknown terminal type");
2314 2312
2313 /* If we already have an active display on the given device, use that.
2314 If all displays are suspended, create a new one instead. */
2315 /* XXX Perhaps this should be made explicit by having term_init
2316 always create a new display and separating display and frame
2317 creation on Lisp level. */
2315 display = get_named_tty_display (name); 2318 display = get_named_tty_display (name);
2316 if (display) 2319 if (display)
2317 { 2320 return display;
2318 /* XXX We would be able to support multiple emacsclients from
2319 the same terminal if display devices were Lisp objects.
2320 (Lisp code must know the difference between two separate
2321 displays on the same terminal device.) -- lorentey */
2322 if (! display->display_info.tty->input)
2323 error ("%s already has a suspended frame on it, can't open it twice", name);
2324 return display;
2325 }
2326 2321
2327 display = create_display (); 2322 display = create_display ();
2328 tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info)); 2323 tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info));
@@ -2410,6 +2405,7 @@ term_init (char *name, char *terminal_type, int must_succeed)
2410 2405
2411 file = fdopen (fd, "w+"); 2406 file = fdopen (fd, "w+");
2412 tty->name = xstrdup (name); 2407 tty->name = xstrdup (name);
2408 display->name = xstrdup (name);
2413 tty->input = file; 2409 tty->input = file;
2414 tty->output = file; 2410 tty->output = file;
2415 } 2411 }
@@ -2422,6 +2418,7 @@ term_init (char *name, char *terminal_type, int must_succeed)
2422 error ("There is no controlling terminal any more"); 2418 error ("There is no controlling terminal any more");
2423 } 2419 }
2424 tty->name = 0; 2420 tty->name = 0;
2421 display->name = xstrdup (ttyname (0));
2425 tty->input = stdin; 2422 tty->input = stdin;
2426 tty->output = stdout; 2423 tty->output = stdout;
2427 } 2424 }
@@ -2907,37 +2904,6 @@ fatal (str, arg1, arg2)
2907 2904
2908 2905
2909 2906
2910DEFUN ("delete-tty", Fdelete_tty, Sdelete_tty, 0, 1, 0,
2911 doc: /* Delete all frames on the terminal named TTY, and close the device.
2912If omitted, TTY defaults to the controlling terminal.
2913
2914This function runs `delete-tty-after-functions' after closing the
2915tty. The functions are run with one arg, the frame to be deleted. */)
2916 (tty)
2917 Lisp_Object tty;
2918{
2919 struct display *d;
2920 char *name = 0;
2921
2922 CHECK_STRING (tty);
2923
2924 if (SBYTES (tty) > 0)
2925 {
2926 name = (char *) alloca (SBYTES (tty) + 1);
2927 strncpy (name, SDATA (tty), SBYTES (tty));
2928 name[SBYTES (tty)] = 0;
2929 }
2930
2931 d = get_named_tty_display (name);
2932
2933 if (! d)
2934 error ("No such terminal device: %s", name);
2935
2936 delete_tty (d);
2937
2938 return Qnil;
2939}
2940
2941static int deleting_tty = 0; 2907static int deleting_tty = 0;
2942 2908
2943 2909
@@ -3038,21 +3004,6 @@ delete_tty (struct display *display)
3038 bzero (tty, sizeof (struct tty_display_info)); 3004 bzero (tty, sizeof (struct tty_display_info));
3039 xfree (tty); 3005 xfree (tty);
3040 deleting_tty = 0; 3006 deleting_tty = 0;
3041
3042 /* Run `delete-tty-after-functions'. */
3043 if (!NILP (Vrun_hooks))
3044 {
3045 Lisp_Object args[2];
3046 args[0] = intern ("delete-tty-after-functions");
3047 if (tty_name)
3048 {
3049 args[1] = build_string (tty_name);
3050 xfree (tty_name);
3051 }
3052 else
3053 args[1] = Qnil;
3054 Frun_hook_with_args (2, args);
3055 }
3056} 3007}
3057 3008
3058 3009
@@ -3118,6 +3069,8 @@ create_display (void)
3118 display->next_display = display_list; 3069 display->next_display = display_list;
3119 display_list = display; 3070 display_list = display;
3120 3071
3072 display->id = next_display_id++;
3073
3121 display->keyboard_coding = 3074 display->keyboard_coding =
3122 (struct coding_system *) xmalloc (sizeof (struct coding_system)); 3075 (struct coding_system *) xmalloc (sizeof (struct coding_system));
3123 display->terminal_coding = 3076 display->terminal_coding =
@@ -3157,26 +3110,114 @@ delete_display (struct display *display)
3157 xfree (display->keyboard_coding); 3110 xfree (display->keyboard_coding);
3158 if (display->terminal_coding) 3111 if (display->terminal_coding)
3159 xfree (display->terminal_coding); 3112 xfree (display->terminal_coding);
3160 3113 if (display->name)
3114 xfree (display->name);
3115
3161 bzero (display, sizeof (struct display)); 3116 bzero (display, sizeof (struct display));
3162 xfree (display); 3117 xfree (display);
3163} 3118}
3164 3119
3120DEFUN ("delete-display", Fdelete_display, Sdelete_display, 0, 2, 0,
3121 doc: /* Delete DISPLAY by deleting all frames on it and closing the device.
3122DISPLAY may be a display id, a frame, or nil for the display
3123device of the current frame.
3124
3125Normally, you may not delete a display if all other displays are suspended,
3126but if the second argument FORCE is non-nil, you may do so. */)
3127 (display, force)
3128 Lisp_Object display, force;
3129{
3130 struct display *d, *p;
3131
3132 d = get_display (display);
3133
3134 if (!d)
3135 return Qnil;
3136
3137 p = display_list;
3138 while (p && (p == d || !DISPLAY_ACTIVE_P (p)))
3139 p = p->next_display;
3140
3141 if (NILP (force) && !p)
3142 error ("Attempt to delete the sole active display");
3143
3144 if (d->delete_display_hook)
3145 (*d->delete_display_hook) (d);
3146 else
3147 delete_display (d);
3148
3149 return Qnil;
3150}
3151
3152DEFUN ("display-live-p", Fdisplay_live_p, Sdisplay_live_p, 1, 1, 0,
3153 doc: /* Return non-nil if OBJECT is a display which has not been deleted.
3154Value is nil if OBJECT is not a live display.
3155If object is a live display, the return value indicates what sort of
3156output device it uses. See the documentation of `framep' for possible
3157return values.
3158
3159Displays are represented by their integer identifiers. */)
3160 (object)
3161 Lisp_Object object;
3162{
3163 struct display *d;
3164
3165 if (!INTEGERP (object))
3166 return Qnil;
3167
3168 d = get_display (object);
3169
3170 if (!d)
3171 return Qnil;
3172
3173 switch (d->type)
3174 {
3175 case output_initial: /* The initial frame is like a termcap frame. */
3176 case output_termcap:
3177 return Qt;
3178 case output_x_window:
3179 return Qx;
3180 case output_w32:
3181 return Qw32;
3182 case output_msdos_raw:
3183 return Qpc;
3184 case output_mac:
3185 return Qmac;
3186 default:
3187 abort ();
3188 }
3189}
3190
3191DEFUN ("display-list", Fdisplay_list, Sdisplay_list, 0, 0, 0,
3192 doc: /* Return a list of all displays.
3193Displays are represented by their integer identifiers. */)
3194 ()
3195{
3196 Lisp_Object displays = Qnil;
3197 struct display *d;
3198
3199 for (d = display_list; d; d = d->next_display)
3200 displays = Fcons (make_number (d->id), displays);
3201
3202 return displays;
3203}
3204
3205
3165 3206
3166 3207
3167DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0, 3208DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0,
3168 doc: /* Suspend the terminal device TTY. 3209 doc: /* Suspend the terminal device TTY.
3169The terminal is restored to its default state, and Emacs closes all 3210The terminal is restored to its default state, and Emacs ceases all
3170access to the terminal device. Frames that use the device are not 3211access to the terminal device. Frames that use the device are not
3171deleted, but input is not read from them and if they change, their 3212deleted, but input is not read from them and if they change, their
3172display is not updated. 3213display is not updated.
3173 3214
3174TTY may a string (a device name), a frame, or nil for the display 3215TTY may be a display id, a frame, or nil for the display device of the
3175device of the currently selected frame. 3216currently selected frame.
3176 3217
3177This function runs `suspend-tty-functions' after suspending the 3218This function runs `suspend-tty-functions' after suspending the
3178device. The functions are run with one arg, the name of the terminal 3219device. The functions are run with one arg, the id of the suspended
3179device. 3220display device.
3180 3221
3181`suspend-tty' does nothing if it is called on an already suspended 3222`suspend-tty' does nothing if it is called on an already suspended
3182device. 3223device.
@@ -3215,12 +3256,7 @@ it. */)
3215 { 3256 {
3216 Lisp_Object args[2]; 3257 Lisp_Object args[2];
3217 args[0] = intern ("suspend-tty-functions"); 3258 args[0] = intern ("suspend-tty-functions");
3218 if (d->display_info.tty->name) 3259 args[1] = make_number (d->id);
3219 {
3220 args[1] = build_string (d->display_info.tty->name);
3221 }
3222 else
3223 args[1] = Qnil;
3224 Frun_hook_with_args (2, args); 3260 Frun_hook_with_args (2, args);
3225 } 3261 }
3226 } 3262 }
@@ -3231,17 +3267,21 @@ it. */)
3231 3267
3232DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0, 3268DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0,
3233 doc: /* Resume the previously suspended terminal device TTY. 3269 doc: /* Resume the previously suspended terminal device TTY.
3234The terminal is opened and reinitialized. Frames that used the 3270The terminal is opened and reinitialized. Frames that are on the
3235suspended device are revived. 3271suspended display are revived.
3272
3273It is an error to resume a display while another display is active on
3274the same device.
3236 3275
3237This function runs `resume-tty-functions' after resuming the device. 3276This function runs `resume-tty-functions' after resuming the device.
3238The functions are run with one arg, the name of the terminal device. 3277The functions are run with one arg, the id of the resumed display
3278device.
3239 3279
3240`resume-tty' does nothing if it is called on a device that is not 3280`resume-tty' does nothing if it is called on a device that is not
3241suspended. 3281suspended.
3242 3282
3243TTY may a string (a device name), a frame, or nil for the display 3283TTY may be a display id, a frame, or nil for the display device of the
3244device of the currently selected frame. */) 3284currently selected frame. */)
3245 (tty) 3285 (tty)
3246 Lisp_Object tty; 3286 Lisp_Object tty;
3247{ 3287{
@@ -3253,6 +3293,9 @@ device of the currently selected frame. */)
3253 3293
3254 if (!d->display_info.tty->input) 3294 if (!d->display_info.tty->input)
3255 { 3295 {
3296 if (get_named_tty_display (d->display_info.tty->name))
3297 error ("Cannot resume display while another display is active on the same device");
3298
3256 fd = emacs_open (d->display_info.tty->name, O_RDWR | O_NOCTTY, 0); 3299 fd = emacs_open (d->display_info.tty->name, O_RDWR | O_NOCTTY, 0);
3257 3300
3258 /* XXX What if open fails? */ 3301 /* XXX What if open fails? */
@@ -3274,12 +3317,7 @@ device of the currently selected frame. */)
3274 { 3317 {
3275 Lisp_Object args[2]; 3318 Lisp_Object args[2];
3276 args[0] = intern ("resume-tty-functions"); 3319 args[0] = intern ("resume-tty-functions");
3277 if (d->display_info.tty->name) 3320 args[1] = make_number (d->id);
3278 {
3279 args[1] = build_string (d->display_info.tty->name);
3280 }
3281 else
3282 args[1] = Qnil;
3283 Frun_hook_with_args (2, args); 3321 Frun_hook_with_args (2, args);
3284 } 3322 }
3285 } 3323 }
@@ -3305,13 +3343,6 @@ This variable can be used by terminal emulator packages. */);
3305The function should accept no arguments. */); 3343The function should accept no arguments. */);
3306 Vring_bell_function = Qnil; 3344 Vring_bell_function = Qnil;
3307 3345
3308 DEFVAR_LISP ("delete-tty-after-functions", &Vdelete_tty_after_functions,
3309 doc: /* Functions to be run after deleting a tty.
3310The functions are run with one argument, the name of the tty to be deleted.
3311See `delete-tty'. */);
3312 Vdelete_tty_after_functions = Qnil;
3313
3314
3315 DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions, 3346 DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions,
3316 doc: /* Functions to be run after suspending a tty. 3347 doc: /* Functions to be run after suspending a tty.
3317The functions are run with one argument, the name of the tty to be suspended. 3348The functions are run with one argument, the name of the tty to be suspended.
@@ -3325,17 +3356,13 @@ The functions are run with one argument, the name of the tty that was revived.
3325See `resume-tty'. */); 3356See `resume-tty'. */);
3326 Vresume_tty_functions = Qnil; 3357 Vresume_tty_functions = Qnil;
3327 3358
3328 Qframe_tty_name = intern ("frame-tty-name");
3329 staticpro (&Qframe_tty_name);
3330
3331 Qframe_tty_type = intern ("frame-tty-type");
3332 staticpro (&Qframe_tty_type);
3333
3334 defsubr (&Stty_display_color_p); 3359 defsubr (&Stty_display_color_p);
3335 defsubr (&Stty_display_color_cells); 3360 defsubr (&Stty_display_color_cells);
3336 defsubr (&Sframe_tty_name); 3361 defsubr (&Sdisplay_name);
3337 defsubr (&Sframe_tty_type); 3362 defsubr (&Sdisplay_tty_type);
3338 defsubr (&Sdelete_tty); 3363 defsubr (&Sdelete_display);
3364 defsubr (&Sdisplay_live_p);
3365 defsubr (&Sdisplay_list);
3339 defsubr (&Ssuspend_tty); 3366 defsubr (&Ssuspend_tty);
3340 defsubr (&Sresume_tty); 3367 defsubr (&Sresume_tty);
3341 3368
diff --git a/src/termhooks.h b/src/termhooks.h
index 227ec21372e..9aedede55bf 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -282,12 +282,18 @@ struct display
282 /* Chain of all displays. */ 282 /* Chain of all displays. */
283 struct display *next_display; 283 struct display *next_display;
284 284
285 /* Unique id for this display. */
286 int id;
287
285 /* The number of frames that are on this display. */ 288 /* The number of frames that are on this display. */
286 int reference_count; 289 int reference_count;
287 290
288 /* The type of the display. */ 291 /* The type of the display. */
289 enum output_method type; 292 enum output_method type;
290 293
294 /* The name of the display device. Do not use this to identify the display. */
295 char *name;
296
291 /* Display-type dependent data shared amongst all frames on this display. */ 297 /* Display-type dependent data shared amongst all frames on this display. */
292 union display_info 298 union display_info
293 { 299 {
@@ -518,8 +524,8 @@ struct display
518 /* Called after the last frame on this display is deleted, or when 524 /* Called after the last frame on this display is deleted, or when
519 the display device was closed (hangup). 525 the display device was closed (hangup).
520 526
521 If this is NULL, then the generic delete_display() is called 527 If this is NULL, then the generic delete_display is called
522 instead. 528 instead. Otherwise the hook must call delete_display itself.
523 529
524 The hook must check for and close any live frames that are still 530 The hook must check for and close any live frames that are still
525 on the display. Fdelete_frame ensures that there are no live 531 on the display. Fdelete_frame ensures that there are no live
@@ -563,6 +569,9 @@ extern struct display *display_list;
563#define FRAME_WINDOW_P(f) (0) 569#define FRAME_WINDOW_P(f) (0)
564#endif 570#endif
565 571
572/* Return true if the display is not suspended. */
573#define DISPLAY_ACTIVE_P(d) ((d)->type != output_termcap || (d)->display_info.tty->input)
574
566extern struct display *create_display P_ ((void)); 575extern struct display *create_display P_ ((void));
567extern void delete_display P_ ((struct display *)); 576extern void delete_display P_ ((struct display *));
568 577
diff --git a/src/xfns.c b/src/xfns.c
index 56593453b2c..dbb7548650c 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -257,6 +257,17 @@ check_x_display_info (frame)
257 else 257 else
258 error ("X windows are not in use or not initialized"); 258 error ("X windows are not in use or not initialized");
259 } 259 }
260 else if (INTEGERP (frame))
261 {
262 struct display *d = get_display (XINT (frame));
263
264 if (!d)
265 wrong_type_argument (Qdisplay_live_p, frame);
266 if (d->type != output_x_window)
267 error ("Display %d is not an X display", XINT (frame));
268
269 dpyinfo = d->display_info.x;
270 }
260 else if (STRINGP (frame)) 271 else if (STRINGP (frame))
261 dpyinfo = x_display_info_for_name (frame); 272 dpyinfo = x_display_info_for_name (frame);
262 else 273 else
@@ -2849,7 +2860,9 @@ This function is an internal primitive--use `make-frame' instead. */)
2849 until we know if this frame has a specified name. */ 2860 until we know if this frame has a specified name. */
2850 Vx_resource_name = Vinvocation_name; 2861 Vx_resource_name = Vinvocation_name;
2851 2862
2852 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING); 2863 display = x_get_arg (dpyinfo, parms, Qdisplay_id, 0, 0, RES_TYPE_NUMBER);
2864 if (NILP (display))
2865 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
2853 if (EQ (display, Qunbound)) 2866 if (EQ (display, Qunbound))
2854 display = Qnil; 2867 display = Qnil;
2855 dpyinfo = check_x_display_info (display); 2868 dpyinfo = check_x_display_info (display);
diff --git a/src/xterm.c b/src/xterm.c
index c17146bde1d..c8b5921a3b5 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10336,6 +10336,11 @@ x_term_init (display_name, xrm_option, resource_name)
10336 10336
10337 dpyinfo->display = dpy; 10337 dpyinfo->display = dpy;
10338 10338
10339 /* Set the name of the display. */
10340 display->name = (char *) xmalloc (SBYTES (display_name) + 1);
10341 strncpy (display->name, SDATA (display_name), SBYTES (display_name));
10342 display->name[SBYTES (display_name)] = 0;
10343
10339#if 0 10344#if 0
10340 XSetAfterFunction (x_current_display, x_trace_wire); 10345 XSetAfterFunction (x_current_display, x_trace_wire);
10341#endif /* ! 0 */ 10346#endif /* ! 0 */
@@ -10709,10 +10714,11 @@ x_delete_display (dpyinfo)
10709 xfree (dpyinfo->font_table[i].name); 10714 xfree (dpyinfo->font_table[i].name);
10710 } 10715 }
10711 10716
10712 if (dpyinfo->font_table->font_encoder) 10717 if (dpyinfo->font_table && dpyinfo->font_table->font_encoder)
10713 xfree (dpyinfo->font_table->font_encoder); 10718 xfree (dpyinfo->font_table->font_encoder);
10714 10719
10715 xfree (dpyinfo->font_table); 10720 if (dpyinfo->font_table)
10721 xfree (dpyinfo->font_table);
10716 xfree (dpyinfo->x_id_name); 10722 xfree (dpyinfo->x_id_name);
10717 xfree (dpyinfo->color_cells); 10723 xfree (dpyinfo->color_cells);
10718 xfree (dpyinfo); 10724 xfree (dpyinfo);