XEmacs 21.2.28 "Hermes".
[chise/xemacs-chise.git.1] / src / frame-tty.c
1 /* TTY frame functions.
2    Copyright (C) 1995  Free Software Foundation, Inc.
3    Copyright (C) 1995, 1996 Ben Wing.
4    Copyright (C) 1997  Free Software Foundation, Inc.
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 /* Written by Ben Wing.
26    Multi-frame support added by Hrvoje Niksic. */
27
28 #include <config.h>
29 #include "lisp.h"
30
31 #include "console-tty.h"
32 #include "frame.h"
33
34 #include "events.h"
35
36 \f
37 /* Default properties to use when creating frames.  */
38 Lisp_Object Vdefault_tty_frame_plist;
39
40 static void tty_raise_frame (struct frame *);
41
42 \f
43 static void
44 tty_init_frame_1 (struct frame *f, Lisp_Object props)
45 {
46   struct device *d = XDEVICE (FRAME_DEVICE (f));
47   struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
48
49   ++CONSOLE_TTY_DATA (c)->frame_count;
50   f->order_count = CONSOLE_TTY_DATA (c)->frame_count;
51   f->height = CONSOLE_TTY_DATA (c)->height;
52   f->width = CONSOLE_TTY_DATA (c)->width;
53 }
54
55 static void
56 tty_init_frame_3 (struct frame *f)
57 {
58   tty_raise_frame (f);
59 }
60
61 static void
62 tty_select_frame_if_unhidden (Lisp_Object frame)
63 {
64   if (FRAME_REPAINT_P (XFRAME (frame)))
65     select_frame_1 (frame);
66 }
67
68 static void
69 tty_schedule_frame_select (struct frame *f)
70 {
71   Lisp_Object frame;
72
73   XSETFRAME (frame, f);
74   enqueue_magic_eval_event (tty_select_frame_if_unhidden, frame);
75 }
76
77 static void
78 tty_after_init_frame (struct frame *f, int first_on_device,
79                       int first_on_console)
80 {
81   if (first_on_console)
82     call1 (Qinit_post_tty_win, FRAME_CONSOLE (f));
83 }
84
85 /* Change from withdrawn state to mapped state. */
86 static void
87 tty_make_frame_visible (struct frame *f)
88 {
89   if (!FRAME_VISIBLE_P(f))
90     {
91       f->visible = -1;
92     }
93 }
94
95 /* Change from mapped state to withdrawn state. */
96 static void
97 tty_make_frame_invisible (struct frame *f)
98 {
99   f->visible = 0;
100 }
101
102 static void
103 tty_make_frame_hidden (struct frame *f)
104 {
105   f->visible = -1;
106 }
107
108 static void
109 tty_make_frame_unhidden (struct frame *f)
110 {
111   if (!FRAME_REPAINT_P(f))
112     {
113       SET_FRAME_CLEAR(f);
114       f->visible = 1;
115     }
116 }
117
118 static int
119 tty_frame_visible_p (struct frame *f)
120 {
121   return FRAME_VISIBLE_P (f);
122 }
123
124 static void
125 tty_raise_frame_no_select (struct frame *f)
126 {
127   Lisp_Object frame;
128   LIST_LOOP_2 (frame, DEVICE_FRAME_LIST (XDEVICE (FRAME_DEVICE (f))))
129     {
130       struct frame *o = XFRAME (frame);
131       if (o != f && FRAME_REPAINT_P (o))
132         {
133            tty_make_frame_hidden (o);
134            break;
135         }
136     }
137   tty_make_frame_unhidden (f);
138 }
139
140 static void
141 tty_raise_frame (struct frame *f)
142 {
143   tty_raise_frame_no_select (f);
144   tty_schedule_frame_select (f);
145 }
146
147 static void
148 tty_lower_frame (struct frame *f)
149 {
150   Lisp_Object frame_list = DEVICE_FRAME_LIST (XDEVICE (FRAME_DEVICE (f)));
151   Lisp_Object tail, new;
152
153   if (!FRAME_REPAINT_P (f))
154     return;
155
156   LIST_LOOP (tail, frame_list)
157     {
158       if (f == XFRAME (XCAR (tail)))
159         break;
160     }
161
162   /* To lower this frame, another frame has to be raised.  Return if
163      there is no other frame. */
164   if (NILP (tail) && EQ(frame_list, tail))
165     return;
166
167   tty_make_frame_hidden (f);
168   if (CONSP (XCDR (tail)))
169     new = XCAR (XCDR (tail));
170   else
171     new = XCAR (frame_list);
172   tty_make_frame_unhidden (XFRAME (new));
173   tty_schedule_frame_select (XFRAME (new));
174 }
175
176 static void
177 tty_delete_frame (struct frame *f)
178 {
179   struct device *d = XDEVICE (FRAME_DEVICE (f));
180
181   if (!NILP (DEVICE_SELECTED_FRAME (d)))
182     tty_raise_frame (XFRAME (DEVICE_SELECTED_FRAME (d)));
183 }
184 \f
185 /************************************************************************/
186 /*                            initialization                            */
187 /************************************************************************/
188
189 void
190 console_type_create_frame_tty (void)
191 {
192   CONSOLE_HAS_METHOD (tty, init_frame_1);
193   CONSOLE_HAS_METHOD (tty, init_frame_3);
194   CONSOLE_HAS_METHOD (tty, after_init_frame);
195   CONSOLE_HAS_METHOD (tty, make_frame_visible);
196   CONSOLE_HAS_METHOD (tty, make_frame_invisible);
197   CONSOLE_HAS_METHOD (tty, frame_visible_p);
198   CONSOLE_HAS_METHOD (tty, raise_frame);
199   CONSOLE_HAS_METHOD (tty, lower_frame);
200   CONSOLE_HAS_METHOD (tty, delete_frame);
201 }
202
203 void
204 vars_of_frame_tty (void)
205 {
206   DEFVAR_LISP ("default-tty-frame-plist", &Vdefault_tty_frame_plist /*
207 Plist of default frame-creation properties for tty frames.
208 These are in addition to and override what is specified in
209 `default-frame-plist', but are overridden by the arguments to the
210 particular call to `make-frame'.
211 */ );
212   Vdefault_tty_frame_plist = Qnil;
213
214   tty_console_methods->device_specific_frame_props =
215     &Vdefault_tty_frame_plist;
216
217   /* Tty frames are now supported.  Advertise a feature to indicate this. */
218   Fprovide (intern ("tty-frames"));
219 }