0
|
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
|
|
39 #include "syssignal.h" /* for SIGWINCH */
|
|
40
|
|
41 #include <errno.h>
|
|
42
|
|
43 Lisp_Object Qinit_pre_tty_win, Qinit_post_tty_win;
|
|
44
|
|
45
|
|
46 static void
|
|
47 allocate_tty_device_struct (struct device *d)
|
|
48 {
|
|
49 d->device_data =
|
|
50 (struct tty_device *) xmalloc (sizeof (struct tty_device));
|
|
51
|
|
52 /* zero out all slots. */
|
|
53 memset (d->device_data, 0, sizeof (struct tty_device));
|
|
54 }
|
|
55
|
|
56 static void
|
|
57 tty_init_device (struct device *d, Lisp_Object props)
|
|
58 {
|
|
59 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
60 Lisp_Object terminal_type = CONSOLE_TTY_DATA (con)->terminal_type;
|
|
61
|
|
62 DEVICE_INFD (d) = CONSOLE_TTY_DATA (con)->infd;
|
|
63 DEVICE_OUTFD (d) = CONSOLE_TTY_DATA (con)->outfd;
|
|
64
|
|
65 allocate_tty_device_struct (d);
|
|
66 init_baud_rate (d);
|
|
67
|
14
|
68 switch (init_tty_for_redisplay (d, (char *) XSTRING_DATA (terminal_type)))
|
0
|
69 {
|
|
70 #if 0
|
|
71 case TTY_UNABLE_OPEN_DATABASE:
|
|
72 suppress_early_backtrace = 1;
|
|
73 error ("Can't access terminal information database");
|
|
74 break;
|
|
75 #endif
|
|
76 case TTY_TYPE_UNDEFINED:
|
|
77 suppress_early_backtrace = 1;
|
|
78 error ("Terminal type `%s' undefined (or can't access database?)",
|
14
|
79 XSTRING_DATA (terminal_type));
|
0
|
80 break;
|
|
81 case TTY_TYPE_INSUFFICIENT:
|
|
82 suppress_early_backtrace = 1;
|
|
83 error ("Terminal type `%s' not powerful enough to run Emacs",
|
14
|
84 XSTRING_DATA (terminal_type));
|
0
|
85 break;
|
|
86 case TTY_SIZE_UNSPECIFIED:
|
|
87 suppress_early_backtrace = 1;
|
|
88 error ("Can't determine window size of terminal");
|
|
89 break;
|
|
90 case TTY_INIT_SUCCESS:
|
|
91 break;
|
|
92 default:
|
|
93 abort ();
|
|
94 }
|
|
95
|
|
96 init_one_device (d);
|
|
97
|
|
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);
|
|
101 }
|
|
102
|
|
103 static void
|
|
104 free_tty_device_struct (struct device *d)
|
|
105 {
|
|
106 struct tty_device *td = (struct tty_device *) d->device_data;
|
|
107 if (td)
|
|
108 xfree (td);
|
|
109 }
|
|
110
|
|
111 static void
|
|
112 tty_delete_device (struct device *d)
|
|
113 {
|
|
114 free_tty_device_struct (d);
|
|
115 }
|
|
116
|
|
117 #ifdef SIGWINCH
|
|
118
|
|
119 static SIGTYPE
|
|
120 tty_device_size_change_signal (int signo)
|
|
121 {
|
|
122 int old_errno = errno;
|
|
123 asynch_device_change_pending++;
|
|
124 signal_fake_event ();
|
|
125 EMACS_REESTABLISH_SIGNAL (SIGWINCH, tty_device_size_change_signal);
|
|
126 errno = old_errno;
|
|
127 SIGRETURN;
|
|
128 }
|
|
129
|
|
130 /* frame_change_signal does nothing but set a flag that it was called.
|
|
131 When redisplay is called, it will notice that the flag is set and
|
|
132 call handle_pending_device_size_change to do the actual work. */
|
|
133 static void
|
|
134 tty_asynch_device_change (void)
|
|
135 {
|
|
136 Lisp_Object devcons, concons;
|
|
137
|
|
138 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
139 {
|
|
140 int width, height;
|
|
141 Lisp_Object tail;
|
|
142 struct device *d = XDEVICE (XCAR (devcons));
|
|
143 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
144
|
|
145 if (!DEVICE_TTY_P (d))
|
|
146 continue;
|
|
147
|
|
148 get_tty_device_size (d, &width, &height);
|
|
149 if (width > 0 && height > 0)
|
|
150 {
|
|
151 CONSOLE_TTY_DATA (con)->width = width;
|
|
152 CONSOLE_TTY_DATA (con)->height = height;
|
|
153
|
|
154 for (tail = DEVICE_FRAME_LIST (d);
|
|
155 !NILP (tail);
|
|
156 tail = XCDR (tail))
|
|
157 {
|
|
158 struct frame *f = XFRAME (XCAR (tail));
|
|
159
|
|
160 /* We know the frame is tty because we made sure that the
|
|
161 device is tty. */
|
|
162 change_frame_size (f, height, width, 1);
|
|
163 }
|
|
164 }
|
|
165 }
|
|
166 }
|
|
167
|
|
168 #endif /* SIGWINCH */
|
|
169
|
|
170 static int
|
|
171 tty_device_pixel_width (struct device *d)
|
|
172 {
|
|
173 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
174 return CONSOLE_TTY_DATA (con)->width;
|
|
175 }
|
|
176
|
|
177 static int
|
|
178 tty_device_pixel_height (struct device *d)
|
|
179 {
|
|
180 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
181 return CONSOLE_TTY_DATA (con)->height;
|
|
182 }
|
|
183
|
|
184
|
|
185 /************************************************************************/
|
|
186 /* initialization */
|
|
187 /************************************************************************/
|
|
188
|
|
189 void
|
|
190 syms_of_device_tty (void)
|
|
191 {
|
|
192 defsymbol (&Qinit_pre_tty_win, "init-pre-tty-win");
|
|
193 defsymbol (&Qinit_post_tty_win, "init-post-tty-win");
|
|
194 }
|
|
195
|
|
196 void
|
|
197 console_type_create_device_tty (void)
|
|
198 {
|
|
199 /* device methods */
|
|
200 CONSOLE_HAS_METHOD (tty, init_device);
|
|
201 CONSOLE_HAS_METHOD (tty, delete_device);
|
|
202 #ifdef SIGWINCH
|
|
203 CONSOLE_HAS_METHOD (tty, asynch_device_change);
|
|
204 #endif /* SIGWINCH */
|
|
205 CONSOLE_HAS_METHOD (tty, device_pixel_width);
|
|
206 CONSOLE_HAS_METHOD (tty, device_pixel_height);
|
|
207 }
|
|
208
|
|
209 void
|
|
210 init_device_tty (void)
|
|
211 {
|
|
212 #ifdef SIGWINCH
|
|
213 if (initialized && !noninteractive)
|
|
214 signal (SIGWINCH, tty_device_size_change_signal);
|
|
215 #endif /* SIGWINCH */
|
|
216 }
|