Initial git import
[sxemacs] / src / ui / TTY / 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 SXEmacs
7
8 SXEmacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 SXEmacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
20
21
22 /* Synched up with: Not in FSF. */
23
24 /* Written by Ben Wing.
25    Multi-frame support added by Hrvoje Niksic. */
26
27 #include <config.h>
28 #include "lisp.h"
29
30 #include "console-tty.h"
31 #include "ui/frame.h"
32
33 #include "events/events.h"
34 \f
35 /* Default properties to use when creating frames.  */
36 Lisp_Object Vdefault_tty_frame_plist;
37
38 static void tty_raise_frame(struct frame *);
39 \f
40 static void tty_init_frame_1(struct frame *f, Lisp_Object props)
41 {
42         struct device *d = XDEVICE(FRAME_DEVICE(f));
43         struct console *c = XCONSOLE(DEVICE_CONSOLE(d));
44
45         ++CONSOLE_TTY_DATA(c)->frame_count;
46         f->order_count = CONSOLE_TTY_DATA(c)->frame_count;
47         f->height = CONSOLE_TTY_DATA(c)->height;
48         f->width = CONSOLE_TTY_DATA(c)->width;
49 }
50
51 static void tty_init_frame_3(struct frame *f)
52 {
53         tty_raise_frame(f);
54 }
55
56 static void tty_select_frame_if_unhidden(Lisp_Object frame)
57 {
58         if (FRAME_REPAINT_P(XFRAME(frame)))
59                 select_frame_1(frame);
60 }
61
62 static void tty_schedule_frame_select(struct frame *f)
63 {
64         Lisp_Object frame;
65
66         XSETFRAME(frame, f);
67         enqueue_magic_eval_event(tty_select_frame_if_unhidden, frame);
68 }
69
70 static void
71 tty_after_init_frame(struct frame *f, int first_on_device, int first_on_console)
72 {
73         if (first_on_console)
74                 call1(Qinit_post_tty_win, FRAME_CONSOLE(f));
75 }
76
77 /* Change from withdrawn state to mapped state. */
78 static void tty_make_frame_visible(struct frame *f)
79 {
80         if (!FRAME_VISIBLE_P(f)) {
81                 f->visible = -1;
82         }
83 }
84
85 /* Change from mapped state to withdrawn state. */
86 static void tty_make_frame_invisible(struct frame *f)
87 {
88         f->visible = 0;
89 }
90
91 static void tty_make_frame_hidden(struct frame *f)
92 {
93         f->visible = -1;
94 }
95
96 static void tty_make_frame_unhidden(struct frame *f)
97 {
98         if (!FRAME_REPAINT_P(f)) {
99                 SET_FRAME_CLEAR(f);
100                 f->visible = 1;
101         }
102 }
103
104 static int tty_frame_visible_p(struct frame *f)
105 {
106         return FRAME_VISIBLE_P(f);
107 }
108
109 static void tty_raise_frame_no_select(struct frame *f)
110 {
111         LIST_LOOP_2(frame, DEVICE_FRAME_LIST(XDEVICE(FRAME_DEVICE(f)))) {
112                 struct frame *o = XFRAME(frame);
113                 if (o != f && FRAME_REPAINT_P(o)) {
114                         tty_make_frame_hidden(o);
115                         break;
116                 }
117         }
118         tty_make_frame_unhidden(f);
119 }
120
121 static void tty_raise_frame(struct frame *f)
122 {
123         tty_raise_frame_no_select(f);
124         tty_schedule_frame_select(f);
125 }
126
127 static void tty_lower_frame(struct frame *f)
128 {
129         Lisp_Object frame_list = DEVICE_FRAME_LIST(XDEVICE(FRAME_DEVICE(f)));
130         Lisp_Object tail, new;
131
132         if (!FRAME_REPAINT_P(f))
133                 return;
134
135         LIST_LOOP(tail, frame_list) {
136                 if (f == XFRAME(XCAR(tail)))
137                         break;
138         }
139
140         /* To lower this frame, another frame has to be raised.  Return if
141            there is no other frame. */
142         if (NILP(tail) && EQ(frame_list, tail))
143                 return;
144
145         tty_make_frame_hidden(f);
146         if (CONSP(XCDR(tail)))
147                 new = XCAR(XCDR(tail));
148         else
149                 new = XCAR(frame_list);
150         tty_make_frame_unhidden(XFRAME(new));
151         tty_schedule_frame_select(XFRAME(new));
152 }
153
154 static void tty_delete_frame(struct frame *f)
155 {
156         struct device *d = XDEVICE(FRAME_DEVICE(f));
157
158         if (!NILP(DEVICE_SELECTED_FRAME(d)))
159                 tty_raise_frame(XFRAME(DEVICE_SELECTED_FRAME(d)));
160 }
161 \f
162 /************************************************************************/
163 /*                            initialization                            */
164 /************************************************************************/
165
166 void console_type_create_frame_tty(void)
167 {
168         CONSOLE_HAS_METHOD(tty, init_frame_1);
169         CONSOLE_HAS_METHOD(tty, init_frame_3);
170         CONSOLE_HAS_METHOD(tty, after_init_frame);
171         CONSOLE_HAS_METHOD(tty, make_frame_visible);
172         CONSOLE_HAS_METHOD(tty, make_frame_invisible);
173         CONSOLE_HAS_METHOD(tty, frame_visible_p);
174         CONSOLE_HAS_METHOD(tty, raise_frame);
175         CONSOLE_HAS_METHOD(tty, lower_frame);
176         CONSOLE_HAS_METHOD(tty, delete_frame);
177 }
178
179 void vars_of_frame_tty(void)
180 {
181         DEFVAR_LISP("default-tty-frame-plist", &Vdefault_tty_frame_plist        /*
182 Plist of default frame-creation properties for tty frames.
183 These are in addition to and override what is specified in
184 `default-frame-plist', but are overridden by the arguments to the
185 particular call to `make-frame'.
186                                                                                  */ );
187         Vdefault_tty_frame_plist = Qnil;
188
189         tty_console_methods->device_specific_frame_props =
190             &Vdefault_tty_frame_plist;
191
192         /* Tty frames are now supported.  Advertise a feature to indicate this. */
193         Fprovide(intern("tty-frames"));
194 }