Mercurial > hg > xemacs-beta
comparison src/device-tty.c @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 9ee227acff29 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
68 switch (init_tty_for_redisplay | |
69 (d, (char *) string_data (XSTRING (terminal_type)))) | |
70 { | |
71 #if 0 | |
72 case TTY_UNABLE_OPEN_DATABASE: | |
73 suppress_early_backtrace = 1; | |
74 error ("Can't access terminal information database"); | |
75 break; | |
76 #endif | |
77 case TTY_TYPE_UNDEFINED: | |
78 suppress_early_backtrace = 1; | |
79 error ("Terminal type `%s' undefined (or can't access database?)", | |
80 string_data (XSTRING (terminal_type))); | |
81 break; | |
82 case TTY_TYPE_INSUFFICIENT: | |
83 suppress_early_backtrace = 1; | |
84 error ("Terminal type `%s' not powerful enough to run Emacs", | |
85 string_data (XSTRING (terminal_type))); | |
86 break; | |
87 case TTY_SIZE_UNSPECIFIED: | |
88 suppress_early_backtrace = 1; | |
89 error ("Can't determine window size of terminal"); | |
90 break; | |
91 case TTY_INIT_SUCCESS: | |
92 break; | |
93 default: | |
94 abort (); | |
95 } | |
96 | |
97 init_one_device (d); | |
98 | |
99 /* Run part of the elisp side of the TTY device initialization. | |
100 The post-init is run in the tty_after_init_frame() method. */ | |
101 call0 (Qinit_pre_tty_win); | |
102 } | |
103 | |
104 static void | |
105 free_tty_device_struct (struct device *d) | |
106 { | |
107 struct tty_device *td = (struct tty_device *) d->device_data; | |
108 if (td) | |
109 xfree (td); | |
110 } | |
111 | |
112 static void | |
113 tty_delete_device (struct device *d) | |
114 { | |
115 free_tty_device_struct (d); | |
116 } | |
117 | |
118 #ifdef SIGWINCH | |
119 | |
120 static SIGTYPE | |
121 tty_device_size_change_signal (int signo) | |
122 { | |
123 int old_errno = errno; | |
124 asynch_device_change_pending++; | |
125 signal_fake_event (); | |
126 EMACS_REESTABLISH_SIGNAL (SIGWINCH, tty_device_size_change_signal); | |
127 errno = old_errno; | |
128 SIGRETURN; | |
129 } | |
130 | |
131 /* frame_change_signal does nothing but set a flag that it was called. | |
132 When redisplay is called, it will notice that the flag is set and | |
133 call handle_pending_device_size_change to do the actual work. */ | |
134 static void | |
135 tty_asynch_device_change (void) | |
136 { | |
137 Lisp_Object devcons, concons; | |
138 | |
139 DEVICE_LOOP_NO_BREAK (devcons, concons) | |
140 { | |
141 int width, height; | |
142 Lisp_Object tail; | |
143 struct device *d = XDEVICE (XCAR (devcons)); | |
144 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); | |
145 | |
146 if (!DEVICE_TTY_P (d)) | |
147 continue; | |
148 | |
149 get_tty_device_size (d, &width, &height); | |
150 if (width > 0 && height > 0) | |
151 { | |
152 CONSOLE_TTY_DATA (con)->width = width; | |
153 CONSOLE_TTY_DATA (con)->height = height; | |
154 | |
155 for (tail = DEVICE_FRAME_LIST (d); | |
156 !NILP (tail); | |
157 tail = XCDR (tail)) | |
158 { | |
159 struct frame *f = XFRAME (XCAR (tail)); | |
160 | |
161 /* We know the frame is tty because we made sure that the | |
162 device is tty. */ | |
163 change_frame_size (f, height, width, 1); | |
164 } | |
165 } | |
166 } | |
167 } | |
168 | |
169 #endif /* SIGWINCH */ | |
170 | |
171 static int | |
172 tty_device_pixel_width (struct device *d) | |
173 { | |
174 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); | |
175 return CONSOLE_TTY_DATA (con)->width; | |
176 } | |
177 | |
178 static int | |
179 tty_device_pixel_height (struct device *d) | |
180 { | |
181 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); | |
182 return CONSOLE_TTY_DATA (con)->height; | |
183 } | |
184 | |
185 | |
186 /************************************************************************/ | |
187 /* initialization */ | |
188 /************************************************************************/ | |
189 | |
190 void | |
191 syms_of_device_tty (void) | |
192 { | |
193 defsymbol (&Qinit_pre_tty_win, "init-pre-tty-win"); | |
194 defsymbol (&Qinit_post_tty_win, "init-post-tty-win"); | |
195 } | |
196 | |
197 void | |
198 console_type_create_device_tty (void) | |
199 { | |
200 /* device methods */ | |
201 CONSOLE_HAS_METHOD (tty, init_device); | |
202 CONSOLE_HAS_METHOD (tty, delete_device); | |
203 #ifdef SIGWINCH | |
204 CONSOLE_HAS_METHOD (tty, asynch_device_change); | |
205 #endif /* SIGWINCH */ | |
206 CONSOLE_HAS_METHOD (tty, device_pixel_width); | |
207 CONSOLE_HAS_METHOD (tty, device_pixel_height); | |
208 } | |
209 | |
210 void | |
211 init_device_tty (void) | |
212 { | |
213 #ifdef SIGWINCH | |
214 if (initialized && !noninteractive) | |
215 signal (SIGWINCH, tty_device_size_change_signal); | |
216 #endif /* SIGWINCH */ | |
217 } |