428
+ − 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.
+ − 5
+ − 6 This file is part of XEmacs.
+ − 7
+ − 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
+ − 11 later version.
+ − 12
+ − 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
+ − 16 for more details.
+ − 17
+ − 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. */
+ − 22
+ − 23 /* Synched up with: Not in FSF. */
+ − 24
+ − 25 /* Authors: Ben Wing and Chuck Thompson. */
+ − 26
+ − 27 #include <config.h>
+ − 28 #include "lisp.h"
+ − 29
+ − 30 #include "console-tty.h"
+ − 31 #include "console-stream.h"
+ − 32 #include "events.h"
+ − 33 #include "faces.h"
+ − 34 #include "frame.h"
+ − 35 #include "lstream.h"
+ − 36 #include "redisplay.h"
+ − 37 #include "sysdep.h"
+ − 38
558
+ − 39 #include "sysfile.h"
428
+ − 40 #include "syssignal.h" /* for SIGWINCH */
+ − 41
+ − 42 Lisp_Object Qinit_pre_tty_win, Qinit_post_tty_win;
+ − 43
+ − 44
+ − 45 static void
+ − 46 allocate_tty_device_struct (struct device *d)
+ − 47 {
+ − 48 d->device_data = xnew_and_zero (struct tty_device);
+ − 49 }
+ − 50
+ − 51 static void
+ − 52 tty_init_device (struct device *d, Lisp_Object props)
+ − 53 {
+ − 54 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
+ − 55 Lisp_Object terminal_type = CONSOLE_TTY_DATA (con)->terminal_type;
+ − 56
+ − 57 DEVICE_INFD (d) = CONSOLE_TTY_DATA (con)->infd;
+ − 58 DEVICE_OUTFD (d) = CONSOLE_TTY_DATA (con)->outfd;
+ − 59
+ − 60 allocate_tty_device_struct (d);
+ − 61 init_baud_rate (d);
+ − 62
+ − 63 switch (init_tty_for_redisplay (d, (char *) XSTRING_DATA (terminal_type)))
+ − 64 {
+ − 65 #if 0
+ − 66 case TTY_UNABLE_OPEN_DATABASE:
+ − 67 suppress_early_error_handler_backtrace = 1;
563
+ − 68 signal_error (Qio_error, "Can't access terminal information database", Qunbound);
428
+ − 69 break;
+ − 70 #endif
+ − 71 case TTY_TYPE_UNDEFINED:
+ − 72 suppress_early_error_handler_backtrace = 1;
563
+ − 73 signal_error (Qio_error, "Terminal type undefined (or can't access database?)",
+ − 74 terminal_type);
428
+ − 75 break;
+ − 76 case TTY_TYPE_INSUFFICIENT:
+ − 77 suppress_early_error_handler_backtrace = 1;
563
+ − 78 signal_error (Qio_error, "Terminal type not powerful enough to run Emacs",
+ − 79 terminal_type);
428
+ − 80 break;
+ − 81 case TTY_SIZE_UNSPECIFIED:
+ − 82 suppress_early_error_handler_backtrace = 1;
563
+ − 83 signal_error (Qio_error, "Can't determine window size of terminal", Qunbound);
428
+ − 84 break;
+ − 85 case TTY_INIT_SUCCESS:
+ − 86 break;
+ − 87 default:
+ − 88 abort ();
+ − 89 }
+ − 90
+ − 91 init_one_device (d);
+ − 92
+ − 93 /* Run part of the elisp side of the TTY device initialization.
+ − 94 The post-init is run in the tty_after_init_frame() method. */
+ − 95 call0 (Qinit_pre_tty_win);
+ − 96 }
+ − 97
+ − 98 static void
+ − 99 free_tty_device_struct (struct device *d)
+ − 100 {
+ − 101 struct tty_device *td = (struct tty_device *) d->device_data;
+ − 102 if (td)
+ − 103 xfree (td);
+ − 104 }
+ − 105
+ − 106 static void
+ − 107 tty_delete_device (struct device *d)
+ − 108 {
+ − 109 free_tty_device_struct (d);
+ − 110 }
+ − 111
+ − 112 #ifdef SIGWINCH
+ − 113
+ − 114 static SIGTYPE
+ − 115 tty_device_size_change_signal (int signo)
+ − 116 {
+ − 117 int old_errno = errno;
+ − 118 asynch_device_change_pending++;
+ − 119 #ifdef HAVE_UNIXOID_EVENT_LOOP
+ − 120 signal_fake_event ();
+ − 121 #endif
+ − 122 EMACS_REESTABLISH_SIGNAL (SIGWINCH, tty_device_size_change_signal);
+ − 123 errno = old_errno;
+ − 124 SIGRETURN;
+ − 125 }
+ − 126
+ − 127 /* frame_change_signal does nothing but set a flag that it was called.
+ − 128 When redisplay is called, it will notice that the flag is set and
+ − 129 call handle_pending_device_size_change to do the actual work. */
+ − 130 static void
+ − 131 tty_asynch_device_change (void)
+ − 132 {
+ − 133 Lisp_Object devcons, concons;
+ − 134
+ − 135 DEVICE_LOOP_NO_BREAK (devcons, concons)
+ − 136 {
+ − 137 int width, height;
+ − 138 Lisp_Object tail;
+ − 139 struct device *d = XDEVICE (XCAR (devcons));
+ − 140 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
+ − 141
+ − 142 if (!DEVICE_TTY_P (d))
+ − 143 continue;
+ − 144
+ − 145 get_tty_device_size (d, &width, &height);
+ − 146 if (width > 0 && height > 0
+ − 147 && (CONSOLE_TTY_DATA (con)->width != width
+ − 148 || CONSOLE_TTY_DATA (con)->height != height))
+ − 149 {
+ − 150 CONSOLE_TTY_DATA (con)->width = width;
+ − 151 CONSOLE_TTY_DATA (con)->height = height;
+ − 152
+ − 153 for (tail = DEVICE_FRAME_LIST (d);
+ − 154 !NILP (tail);
+ − 155 tail = XCDR (tail))
+ − 156 {
+ − 157 struct frame *f = XFRAME (XCAR (tail));
+ − 158
+ − 159 /* We know the frame is tty because we made sure that the
+ − 160 device is tty. */
+ − 161 change_frame_size (f, height, width, 1);
+ − 162 }
+ − 163 }
+ − 164 }
+ − 165 }
+ − 166
+ − 167 #endif /* SIGWINCH */
+ − 168
+ − 169 static Lisp_Object
+ − 170 tty_device_system_metrics (struct device *d,
+ − 171 enum device_metrics m)
+ − 172 {
+ − 173 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
+ − 174 switch (m)
+ − 175 {
+ − 176 case DM_size_device:
+ − 177 return Fcons (make_int (CONSOLE_TTY_DATA (con)->width),
+ − 178 make_int (CONSOLE_TTY_DATA (con)->height));
+ − 179 default: /* No such device metric property for TTY devices */
+ − 180 return Qunbound;
+ − 181 }
+ − 182 }
+ − 183
+ − 184 /************************************************************************/
+ − 185 /* initialization */
+ − 186 /************************************************************************/
+ − 187
+ − 188 void
+ − 189 syms_of_device_tty (void)
+ − 190 {
563
+ − 191 DEFSYMBOL (Qinit_pre_tty_win);
+ − 192 DEFSYMBOL (Qinit_post_tty_win);
428
+ − 193 }
+ − 194
+ − 195 void
+ − 196 console_type_create_device_tty (void)
+ − 197 {
+ − 198 /* device methods */
+ − 199 CONSOLE_HAS_METHOD (tty, init_device);
+ − 200 CONSOLE_HAS_METHOD (tty, delete_device);
+ − 201 #ifdef SIGWINCH
+ − 202 CONSOLE_HAS_METHOD (tty, asynch_device_change);
+ − 203 #endif /* SIGWINCH */
+ − 204 CONSOLE_HAS_METHOD (tty, device_system_metrics);
+ − 205 }
+ − 206
+ − 207 void
+ − 208 init_device_tty (void)
+ − 209 {
+ − 210 #ifdef SIGWINCH
+ − 211 if (initialized && !noninteractive)
613
+ − 212 EMACS_SIGNAL (SIGWINCH, tty_device_size_change_signal);
428
+ − 213 #endif /* SIGWINCH */
+ − 214 }