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 */
47 Lisp_Object Qinit_pre_tty_win, Qinit_post_tty_win;
51 allocate_tty_device_struct (struct device *d)
53 d->device_data = xnew_and_zero (struct tty_device);
57 tty_init_device (struct device *d, Lisp_Object props)
59 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
60 Lisp_Object terminal_type = CONSOLE_TTY_DATA (con)->terminal_type;
62 DEVICE_INFD (d) = CONSOLE_TTY_DATA (con)->infd;
63 DEVICE_OUTFD (d) = CONSOLE_TTY_DATA (con)->outfd;
65 allocate_tty_device_struct (d);
68 switch (init_tty_for_redisplay (d, (char *) XSTRING_DATA (terminal_type)))
71 case TTY_UNABLE_OPEN_DATABASE:
72 suppress_early_error_handler_backtrace = 1;
73 error ("Can't access terminal information database");
76 case TTY_TYPE_UNDEFINED:
77 suppress_early_error_handler_backtrace = 1;
78 error ("Terminal type `%s' undefined (or can't access database?)",
79 XSTRING_DATA (terminal_type));
81 case TTY_TYPE_INSUFFICIENT:
82 suppress_early_error_handler_backtrace = 1;
83 error ("Terminal type `%s' not powerful enough to run Emacs",
84 XSTRING_DATA (terminal_type));
86 case TTY_SIZE_UNSPECIFIED:
87 suppress_early_error_handler_backtrace = 1;
88 error ("Can't determine window size of terminal");
90 case TTY_INIT_SUCCESS:
98 /* Run part of the elisp side of the TTY device initialization.
99 The post-init is run in the tty_after_init_frame() method. */
100 call0 (Qinit_pre_tty_win);
104 free_tty_device_struct (struct device *d)
106 struct tty_device *td = (struct tty_device *) d->device_data;
112 tty_delete_device (struct device *d)
114 free_tty_device_struct (d);
120 tty_device_size_change_signal (int signo)
122 int old_errno = errno;
123 asynch_device_change_pending++;
124 #ifdef HAVE_UNIXOID_EVENT_LOOP
125 signal_fake_event ();
127 EMACS_REESTABLISH_SIGNAL (SIGWINCH, tty_device_size_change_signal);
132 /* frame_change_signal does nothing but set a flag that it was called.
133 When redisplay is called, it will notice that the flag is set and
134 call handle_pending_device_size_change to do the actual work. */
136 tty_asynch_device_change (void)
138 Lisp_Object devcons, concons;
140 DEVICE_LOOP_NO_BREAK (devcons, concons)
144 struct device *d = XDEVICE (XCAR (devcons));
145 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
147 if (!DEVICE_TTY_P (d))
150 get_tty_device_size (d, &width, &height);
151 if (width > 0 && height > 0
152 && (CONSOLE_TTY_DATA (con)->width != width
153 || CONSOLE_TTY_DATA (con)->height != height))
155 CONSOLE_TTY_DATA (con)->width = width;
156 CONSOLE_TTY_DATA (con)->height = height;
159 /* We need to tell GPM how big our screen is now
160 ** I am pretty sure the GPM library will get incredibly confused
161 ** if you try to connect to more than one mouse-capable device,
162 ** so I don't think it will cause any more damage in that case.
167 for (tail = DEVICE_FRAME_LIST (d);
171 struct frame *f = XFRAME (XCAR (tail));
173 /* We know the frame is tty because we made sure that the
175 change_frame_size (f, height, width, 1);
181 #endif /* SIGWINCH */
184 tty_device_system_metrics (struct device *d,
185 enum device_metrics m)
187 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
191 return Fcons (make_int (CONSOLE_TTY_DATA (con)->width),
192 make_int (CONSOLE_TTY_DATA (con)->height));
193 default: /* No such device metric property for TTY devices */
198 /************************************************************************/
200 /************************************************************************/
203 syms_of_device_tty (void)
205 defsymbol (&Qinit_pre_tty_win, "init-pre-tty-win");
206 defsymbol (&Qinit_post_tty_win, "init-post-tty-win");
210 console_type_create_device_tty (void)
213 CONSOLE_HAS_METHOD (tty, init_device);
214 CONSOLE_HAS_METHOD (tty, delete_device);
216 CONSOLE_HAS_METHOD (tty, asynch_device_change);
217 #endif /* SIGWINCH */
218 CONSOLE_HAS_METHOD (tty, device_system_metrics);
222 init_device_tty (void)
225 if (initialized && !noninteractive)
226 signal (SIGWINCH, tty_device_size_change_signal);
227 #endif /* SIGWINCH */