1 /* TTY device functions.
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4 Copyright (C) 1996 Ben Wing.
6 This file is part of XEmacs.
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Synched up with: Not in FSF. */
25 /* Authors: Ben Wing and Chuck Thompson. */
30 #include "console-tty.h"
31 #include "console-stream.h"
36 #include "redisplay.h"
39 #include "syssignal.h" /* for SIGWINCH */
43 Lisp_Object Qinit_pre_tty_win, Qinit_post_tty_win;
47 allocate_tty_device_struct (struct device *d)
49 d->device_data = xnew_and_zero (struct tty_device);
53 tty_init_device (struct device *d, Lisp_Object props)
55 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
56 Lisp_Object terminal_type = CONSOLE_TTY_DATA (con)->terminal_type;
58 DEVICE_INFD (d) = CONSOLE_TTY_DATA (con)->infd;
59 DEVICE_OUTFD (d) = CONSOLE_TTY_DATA (con)->outfd;
61 allocate_tty_device_struct (d);
64 switch (init_tty_for_redisplay (d, (char *) XSTRING_DATA (terminal_type)))
67 case TTY_UNABLE_OPEN_DATABASE:
68 suppress_early_error_handler_backtrace = 1;
69 error ("Can't access terminal information database");
72 case TTY_TYPE_UNDEFINED:
73 suppress_early_error_handler_backtrace = 1;
74 error ("Terminal type `%s' undefined (or can't access database?)",
75 XSTRING_DATA (terminal_type));
77 case TTY_TYPE_INSUFFICIENT:
78 suppress_early_error_handler_backtrace = 1;
79 error ("Terminal type `%s' not powerful enough to run Emacs",
80 XSTRING_DATA (terminal_type));
82 case TTY_SIZE_UNSPECIFIED:
83 suppress_early_error_handler_backtrace = 1;
84 error ("Can't determine window size of terminal");
86 case TTY_INIT_SUCCESS:
94 /* Run part of the elisp side of the TTY device initialization.
95 The post-init is run in the tty_after_init_frame() method. */
96 call0 (Qinit_pre_tty_win);
100 free_tty_device_struct (struct device *d)
102 struct tty_device *td = (struct tty_device *) d->device_data;
108 tty_delete_device (struct device *d)
110 free_tty_device_struct (d);
116 tty_device_size_change_signal (int signo)
118 int old_errno = errno;
119 asynch_device_change_pending++;
120 #ifdef HAVE_UNIXOID_EVENT_LOOP
121 signal_fake_event ();
123 EMACS_REESTABLISH_SIGNAL (SIGWINCH, tty_device_size_change_signal);
128 /* frame_change_signal does nothing but set a flag that it was called.
129 When redisplay is called, it will notice that the flag is set and
130 call handle_pending_device_size_change to do the actual work. */
132 tty_asynch_device_change (void)
134 Lisp_Object devcons, concons;
136 DEVICE_LOOP_NO_BREAK (devcons, concons)
140 struct device *d = XDEVICE (XCAR (devcons));
141 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
143 if (!DEVICE_TTY_P (d))
146 get_tty_device_size (d, &width, &height);
147 if (width > 0 && height > 0
148 && (CONSOLE_TTY_DATA (con)->width != width
149 || CONSOLE_TTY_DATA (con)->height != height))
151 CONSOLE_TTY_DATA (con)->width = width;
152 CONSOLE_TTY_DATA (con)->height = height;
154 for (tail = DEVICE_FRAME_LIST (d);
158 struct frame *f = XFRAME (XCAR (tail));
160 /* We know the frame is tty because we made sure that the
162 change_frame_size (f, height, width, 1);
168 #endif /* SIGWINCH */
171 tty_device_system_metrics (struct device *d,
172 enum device_metrics m)
174 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
178 return Fcons (make_int (CONSOLE_TTY_DATA (con)->width),
179 make_int (CONSOLE_TTY_DATA (con)->height));
180 default: /* No such device metric property for TTY devices */
185 /************************************************************************/
187 /************************************************************************/
190 syms_of_device_tty (void)
192 defsymbol (&Qinit_pre_tty_win, "init-pre-tty-win");
193 defsymbol (&Qinit_post_tty_win, "init-post-tty-win");
197 console_type_create_device_tty (void)
200 CONSOLE_HAS_METHOD (tty, init_device);
201 CONSOLE_HAS_METHOD (tty, delete_device);
203 CONSOLE_HAS_METHOD (tty, asynch_device_change);
204 #endif /* SIGWINCH */
205 CONSOLE_HAS_METHOD (tty, device_system_metrics);
209 init_device_tty (void)
212 if (initialized && !noninteractive)
213 signal (SIGWINCH, tty_device_size_change_signal);
214 #endif /* SIGWINCH */