Commit | Line | Data |
---|---|---|
ff11dfa1 | 1 | /* Generic frame functions. |
beb0bc36 | 2 | Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000 Free Software Foundation. |
dc6f92b8 JB |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
1113d9db | 8 | the Free Software Foundation; either version 2, or (at your option) |
dc6f92b8 JB |
9 | any later version. |
10 | ||
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
dc6f92b8 | 20 | |
18160b98 | 21 | #include <config.h> |
565620a5 RS |
22 | |
23 | #include <stdio.h> | |
cc38027b | 24 | #include "lisp.h" |
71025e5e | 25 | #include "charset.h" |
6d55d620 | 26 | #ifdef HAVE_X_WINDOWS |
dfcf069d | 27 | #include "xterm.h" |
71025e5e | 28 | #endif |
8f23f280 AI |
29 | #ifdef WINDOWSNT |
30 | #include "w32term.h" | |
31 | #endif | |
1a578e9b AC |
32 | #ifdef macintosh |
33 | #include "macterm.h" | |
34 | #endif | |
2538fae4 AI |
35 | #include "buffer.h" |
36 | /* These help us bind and responding to switch-frame events. */ | |
37 | #include "commands.h" | |
38 | #include "keyboard.h" | |
cc38027b | 39 | #include "frame.h" |
a1dfb88a KH |
40 | #ifdef HAVE_WINDOW_SYSTEM |
41 | #include "fontset.h" | |
42 | #endif | |
bc1ed486 | 43 | #include "termhooks.h" |
dfcf069d | 44 | #include "dispextern.h" |
f769f1b2 | 45 | #include "window.h" |
87485d6f MW |
46 | #ifdef MSDOS |
47 | #include "msdos.h" | |
4aec4b29 | 48 | #include "dosfns.h" |
87485d6f | 49 | #endif |
e5d77022 | 50 | |
fd0c2bd1 | 51 | Lisp_Object Qframep; |
dbc4e1c1 | 52 | Lisp_Object Qframe_live_p; |
fd0c2bd1 JB |
53 | Lisp_Object Qheight; |
54 | Lisp_Object Qicon; | |
bc93c097 | 55 | Lisp_Object Qminibuffer; |
fd0c2bd1 JB |
56 | Lisp_Object Qmodeline; |
57 | Lisp_Object Qname; | |
fd0c2bd1 JB |
58 | Lisp_Object Qonly; |
59 | Lisp_Object Qunsplittable; | |
fa8fdbf9 | 60 | Lisp_Object Qmenu_bar_lines; |
9ea173e8 | 61 | Lisp_Object Qtool_bar_lines; |
fd0c2bd1 JB |
62 | Lisp_Object Qwidth; |
63 | Lisp_Object Qx; | |
fbd6baed | 64 | Lisp_Object Qw32; |
4ec0d3c1 | 65 | Lisp_Object Qw32_console; |
bb221971 | 66 | Lisp_Object Qpc; |
574a1a90 | 67 | Lisp_Object Qmac; |
f7af3f7b | 68 | Lisp_Object Qvisible; |
329ca574 | 69 | Lisp_Object Qbuffer_predicate; |
fa54c6ae | 70 | Lisp_Object Qbuffer_list; |
61eaa912 | 71 | Lisp_Object Qtitle; |
8b60f7bc | 72 | Lisp_Object Qdisplay_type; |
6345f6aa | 73 | Lisp_Object Qbackground_mode; |
3df1fda2 | 74 | Lisp_Object Qinhibit_default_face_x_resources; |
dc6f92b8 | 75 | |
a249de79 | 76 | Lisp_Object Vterminal_frame; |
a1aaa23f | 77 | Lisp_Object Vdefault_frame_alist; |
beb0bc36 | 78 | Lisp_Object Vmouse_position_function; |
a249de79 RS |
79 | \f |
80 | static void | |
81 | set_menu_bar_lines_1 (window, n) | |
82 | Lisp_Object window; | |
83 | int n; | |
84 | { | |
85 | struct window *w = XWINDOW (window); | |
86 | ||
57aeea1e | 87 | XSETFASTINT (w->last_modified, 0); |
a249de79 RS |
88 | XSETFASTINT (w->top, XFASTINT (w->top) + n); |
89 | XSETFASTINT (w->height, XFASTINT (w->height) - n); | |
4336c705 GM |
90 | |
91 | if (INTEGERP (w->orig_top)) | |
92 | XSETFASTINT (w->orig_top, XFASTINT (w->orig_top) + n); | |
93 | if (INTEGERP (w->orig_height)) | |
94 | XSETFASTINT (w->orig_height, XFASTINT (w->orig_height) - n); | |
a249de79 RS |
95 | |
96 | /* Handle just the top child in a vertical split. */ | |
97 | if (!NILP (w->vchild)) | |
98 | set_menu_bar_lines_1 (w->vchild, n); | |
99 | ||
100 | /* Adjust all children in a horizontal split. */ | |
101 | for (window = w->hchild; !NILP (window); window = w->next) | |
102 | { | |
103 | w = XWINDOW (window); | |
104 | set_menu_bar_lines_1 (window, n); | |
105 | } | |
106 | } | |
107 | ||
e48f782c | 108 | void |
a249de79 RS |
109 | set_menu_bar_lines (f, value, oldval) |
110 | struct frame *f; | |
111 | Lisp_Object value, oldval; | |
112 | { | |
113 | int nlines; | |
114 | int olines = FRAME_MENU_BAR_LINES (f); | |
115 | ||
116 | /* Right now, menu bars don't work properly in minibuf-only frames; | |
117 | most of the commands try to apply themselves to the minibuffer | |
e3678b64 | 118 | frame itself, and get an error because you can't switch buffers |
a249de79 RS |
119 | in or split the minibuffer window. */ |
120 | if (FRAME_MINIBUF_ONLY_P (f)) | |
121 | return; | |
122 | ||
123 | if (INTEGERP (value)) | |
124 | nlines = XINT (value); | |
125 | else | |
126 | nlines = 0; | |
127 | ||
57aeea1e RS |
128 | if (nlines != olines) |
129 | { | |
130 | windows_or_buffers_changed++; | |
131 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; | |
132 | FRAME_MENU_BAR_LINES (f) = nlines; | |
133 | set_menu_bar_lines_1 (f->root_window, nlines - olines); | |
18082e2d | 134 | adjust_glyphs (f); |
57aeea1e | 135 | } |
a249de79 RS |
136 | } |
137 | \f | |
a249de79 RS |
138 | Lisp_Object Vemacs_iconified; |
139 | Lisp_Object Vframe_list; | |
a249de79 | 140 | |
2d764c78 EZ |
141 | struct x_output tty_display; |
142 | ||
dc6f92b8 JB |
143 | extern Lisp_Object Vminibuffer_list; |
144 | extern Lisp_Object get_minibuffer (); | |
84386599 RS |
145 | extern Lisp_Object Fhandle_switch_frame (); |
146 | extern Lisp_Object Fredirect_frame_focus (); | |
a54d3a73 | 147 | extern Lisp_Object x_get_focus_frame (); |
dc6f92b8 | 148 | \f |
ff11dfa1 JB |
149 | DEFUN ("framep", Fframep, Sframep, 1, 1, 0, |
150 | "Return non-nil if OBJECT is a frame.\n\ | |
151 | Value is t for a termcap frame (a character-only terminal),\n\ | |
87485d6f | 152 | `x' for an Emacs frame that is really an X window,\n\ |
2d764c78 EZ |
153 | `w32' for an Emacs frame that is a window on MS-Windows display,\n\ |
154 | `mac' for an Emacs frame on a Macintosh display,\n\ | |
87485d6f | 155 | `pc' for a direct-write MS-DOS frame.\n\ |
e6b27a8f | 156 | See also `frame-live-p'.") |
f9898cc6 JB |
157 | (object) |
158 | Lisp_Object object; | |
dc6f92b8 | 159 | { |
e35d291d | 160 | if (!FRAMEP (object)) |
dc6f92b8 | 161 | return Qnil; |
ff11dfa1 | 162 | switch (XFRAME (object)->output_method) |
dc6f92b8 JB |
163 | { |
164 | case output_termcap: | |
165 | return Qt; | |
166 | case output_x_window: | |
fd0c2bd1 | 167 | return Qx; |
fbd6baed GV |
168 | case output_w32: |
169 | return Qw32; | |
4ec0d3c1 AI |
170 | case output_w32_console: |
171 | return Qw32_console; | |
bb221971 RS |
172 | case output_msdos_raw: |
173 | return Qpc; | |
574a1a90 RS |
174 | case output_mac: |
175 | return Qmac; | |
dc6f92b8 JB |
176 | default: |
177 | abort (); | |
178 | } | |
179 | } | |
180 | ||
dbc4e1c1 | 181 | DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0, |
ff11dfa1 JB |
182 | "Return non-nil if OBJECT is a frame which has not been deleted.\n\ |
183 | Value is nil if OBJECT is not a live frame. If object is a live\n\ | |
184 | frame, the return value indicates what sort of output device it is\n\ | |
185 | displayed on. Value is t for a termcap frame (a character-only\n\ | |
186 | terminal), `x' for an Emacs frame being displayed in an X window.") | |
f9898cc6 JB |
187 | (object) |
188 | Lisp_Object object; | |
189 | { | |
ff11dfa1 JB |
190 | return ((FRAMEP (object) |
191 | && FRAME_LIVE_P (XFRAME (object))) | |
192 | ? Fframep (object) | |
f9898cc6 JB |
193 | : Qnil); |
194 | } | |
195 | ||
ff11dfa1 JB |
196 | struct frame * |
197 | make_frame (mini_p) | |
dc6f92b8 JB |
198 | int mini_p; |
199 | { | |
ff11dfa1 JB |
200 | Lisp_Object frame; |
201 | register struct frame *f; | |
dc6f92b8 JB |
202 | register Lisp_Object root_window; |
203 | register Lisp_Object mini_window; | |
36af7d69 KH |
204 | register struct Lisp_Vector *vec; |
205 | int i; | |
206 | ||
207 | vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct frame)); | |
208 | for (i = 0; i < VECSIZE (struct frame); i++) | |
209 | XSETFASTINT (vec->contents[i], 0); | |
210 | vec->size = VECSIZE (struct frame); | |
211 | f = (struct frame *)vec; | |
212 | XSETFRAME (frame, f); | |
ff11dfa1 | 213 | |
18082e2d GM |
214 | f->desired_matrix = 0; |
215 | f->current_matrix = 0; | |
216 | f->desired_pool = 0; | |
217 | f->current_pool = 0; | |
218 | f->glyphs_initialized_p = 0; | |
219 | f->decode_mode_spec_buffer = 0; | |
ff11dfa1 | 220 | f->visible = 0; |
323405de | 221 | f->async_visible = 0; |
7556890b | 222 | f->output_data.nothing = 0; |
ff11dfa1 | 223 | f->iconified = 0; |
323405de | 224 | f->async_iconified = 0; |
ff11dfa1 JB |
225 | f->wants_modeline = 1; |
226 | f->auto_raise = 0; | |
227 | f->auto_lower = 0; | |
228 | f->no_split = 0; | |
10689a01 | 229 | f->garbaged = 1; |
ff11dfa1 | 230 | f->has_minibuffer = mini_p; |
a42e9724 | 231 | f->focus_frame = Qnil; |
804518aa | 232 | f->explicit_name = 0; |
fd2777e0 | 233 | f->can_have_scroll_bars = 0; |
3a43d2dd | 234 | f->vertical_scroll_bar_type = vertical_scroll_bar_none; |
ff11dfa1 | 235 | f->param_alist = Qnil; |
fd2777e0 JB |
236 | f->scroll_bars = Qnil; |
237 | f->condemned_scroll_bars = Qnil; | |
306cc902 | 238 | f->face_alist = Qnil; |
18082e2d | 239 | f->face_cache = NULL; |
9dd935ee | 240 | f->menu_bar_items = Qnil; |
c8b8e7e3 RS |
241 | f->menu_bar_vector = Qnil; |
242 | f->menu_bar_items_used = 0; | |
329ca574 | 243 | f->buffer_predicate = Qnil; |
fa54c6ae | 244 | f->buffer_list = Qnil; |
b4f0ee5d KH |
245 | #ifdef MULTI_KBOARD |
246 | f->kboard = initial_kboard; | |
247 | #endif | |
aec6e486 | 248 | f->namebuf = 0; |
2b1c9cfb | 249 | f->title = Qnil; |
18082e2d | 250 | f->menu_bar_window = Qnil; |
9ea173e8 | 251 | f->tool_bar_window = Qnil; |
61752261 | 252 | f->tool_bar_items = Qnil; |
9ea173e8 | 253 | f->desired_tool_bar_string = f->current_tool_bar_string = Qnil; |
61752261 | 254 | f->n_tool_bar_items = 0; |
dc6f92b8 | 255 | |
cc38027b | 256 | root_window = make_window (); |
dc6f92b8 JB |
257 | if (mini_p) |
258 | { | |
cc38027b | 259 | mini_window = make_window (); |
dc6f92b8 JB |
260 | XWINDOW (root_window)->next = mini_window; |
261 | XWINDOW (mini_window)->prev = root_window; | |
262 | XWINDOW (mini_window)->mini_p = Qt; | |
ff11dfa1 JB |
263 | XWINDOW (mini_window)->frame = frame; |
264 | f->minibuffer_window = mini_window; | |
dc6f92b8 JB |
265 | } |
266 | else | |
267 | { | |
268 | mini_window = Qnil; | |
269 | XWINDOW (root_window)->next = Qnil; | |
ff11dfa1 | 270 | f->minibuffer_window = Qnil; |
dc6f92b8 JB |
271 | } |
272 | ||
ff11dfa1 | 273 | XWINDOW (root_window)->frame = frame; |
dc6f92b8 JB |
274 | |
275 | /* 10 is arbitrary, | |
276 | just so that there is "something there." | |
ff11dfa1 | 277 | Correct size will be set up later with change_frame_size. */ |
dc6f92b8 | 278 | |
3a43d2dd | 279 | SET_FRAME_WIDTH (f, 10); |
ff11dfa1 | 280 | f->height = 10; |
dc6f92b8 | 281 | |
f4e93c40 KH |
282 | XSETFASTINT (XWINDOW (root_window)->width, 10); |
283 | XSETFASTINT (XWINDOW (root_window)->height, (mini_p ? 9 : 10)); | |
dc6f92b8 JB |
284 | |
285 | if (mini_p) | |
286 | { | |
f4e93c40 KH |
287 | XSETFASTINT (XWINDOW (mini_window)->width, 10); |
288 | XSETFASTINT (XWINDOW (mini_window)->top, 9); | |
289 | XSETFASTINT (XWINDOW (mini_window)->height, 1); | |
dc6f92b8 JB |
290 | } |
291 | ||
ff11dfa1 | 292 | /* Choose a buffer for the frame's root window. */ |
5bce042c JB |
293 | { |
294 | Lisp_Object buf; | |
295 | ||
296 | XWINDOW (root_window)->buffer = Qt; | |
297 | buf = Fcurrent_buffer (); | |
298 | /* If buf is a 'hidden' buffer (i.e. one whose name starts with | |
299 | a space), try to find another one. */ | |
300 | if (XSTRING (Fbuffer_name (buf))->data[0] == ' ') | |
98ce1622 | 301 | buf = Fother_buffer (buf, Qnil, Qnil); |
fa54c6ae | 302 | |
18082e2d GM |
303 | /* Use set_window_buffer, not Fset_window_buffer, and don't let |
304 | hooks be run by it. The reason is that the whole frame/window | |
305 | arrangement is not yet fully intialized at this point. Windows | |
306 | don't have the right size, glyph matrices aren't initialized | |
307 | etc. Running Lisp functions at this point surely ends in a | |
308 | SEGV. */ | |
309 | set_window_buffer (root_window, buf, 0); | |
fa54c6ae | 310 | f->buffer_list = Fcons (buf, Qnil); |
5bce042c JB |
311 | } |
312 | ||
dc6f92b8 JB |
313 | if (mini_p) |
314 | { | |
315 | XWINDOW (mini_window)->buffer = Qt; | |
18082e2d GM |
316 | set_window_buffer (mini_window, |
317 | (NILP (Vminibuffer_list) | |
318 | ? get_minibuffer (0) | |
319 | : Fcar (Vminibuffer_list)), | |
320 | 0); | |
dc6f92b8 JB |
321 | } |
322 | ||
ff11dfa1 JB |
323 | f->root_window = root_window; |
324 | f->selected_window = root_window; | |
d5e7c279 JB |
325 | /* Make sure this window seems more recently used than |
326 | a newly-created, never-selected window. */ | |
f4e93c40 | 327 | XSETFASTINT (XWINDOW (f->selected_window)->use_time, ++window_select_count); |
dc6f92b8 | 328 | |
ff11dfa1 | 329 | return f; |
dc6f92b8 JB |
330 | } |
331 | \f | |
bba88bb1 | 332 | #ifdef HAVE_WINDOW_SYSTEM |
ff11dfa1 | 333 | /* Make a frame using a separate minibuffer window on another frame. |
dc6f92b8 JB |
334 | MINI_WINDOW is the minibuffer window to use. nil means use the |
335 | default (the global minibuffer). */ | |
336 | ||
ff11dfa1 | 337 | struct frame * |
b0660239 | 338 | make_frame_without_minibuffer (mini_window, kb, display) |
dc6f92b8 | 339 | register Lisp_Object mini_window; |
662ac59a | 340 | KBOARD *kb; |
b0660239 | 341 | Lisp_Object display; |
dc6f92b8 | 342 | { |
ff11dfa1 | 343 | register struct frame *f; |
363b873b | 344 | struct gcpro gcpro1; |
dc6f92b8 | 345 | |
b0660239 KH |
346 | if (!NILP (mini_window)) |
347 | CHECK_LIVE_WINDOW (mini_window, 0); | |
dc6f92b8 | 348 | |
662ac59a | 349 | #ifdef MULTI_KBOARD |
b0660239 KH |
350 | if (!NILP (mini_window) |
351 | && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb) | |
662ac59a KH |
352 | error ("frame and minibuffer must be on the same display"); |
353 | #endif | |
354 | ||
ff11dfa1 JB |
355 | /* Make a frame containing just a root window. */ |
356 | f = make_frame (0); | |
dc6f92b8 | 357 | |
b0660239 KH |
358 | if (NILP (mini_window)) |
359 | { | |
360 | /* Use default-minibuffer-frame if possible. */ | |
361 | if (!FRAMEP (kb->Vdefault_minibuffer_frame) | |
362 | || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame))) | |
363 | { | |
363b873b RS |
364 | Lisp_Object frame_dummy; |
365 | ||
366 | XSETFRAME (frame_dummy, f); | |
367 | GCPRO1 (frame_dummy); | |
b0660239 | 368 | /* If there's no minibuffer frame to use, create one. */ |
363b873b RS |
369 | kb->Vdefault_minibuffer_frame = |
370 | call1 (intern ("make-initial-minibuffer-frame"), display); | |
371 | UNGCPRO; | |
b0660239 | 372 | } |
363b873b | 373 | |
b0660239 KH |
374 | mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window; |
375 | } | |
a2812a26 | 376 | |
ff11dfa1 | 377 | f->minibuffer_window = mini_window; |
a2812a26 RS |
378 | |
379 | /* Make the chosen minibuffer window display the proper minibuffer, | |
380 | unless it is already showing a minibuffer. */ | |
381 | if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list))) | |
382 | Fset_window_buffer (mini_window, | |
383 | (NILP (Vminibuffer_list) | |
384 | ? get_minibuffer (0) | |
385 | : Fcar (Vminibuffer_list))); | |
ff11dfa1 | 386 | return f; |
dc6f92b8 JB |
387 | } |
388 | ||
ff11dfa1 | 389 | /* Make a frame containing only a minibuffer window. */ |
dc6f92b8 | 390 | |
ff11dfa1 JB |
391 | struct frame * |
392 | make_minibuffer_frame () | |
dc6f92b8 | 393 | { |
ff11dfa1 | 394 | /* First make a frame containing just a root window, no minibuffer. */ |
dc6f92b8 | 395 | |
ff11dfa1 | 396 | register struct frame *f = make_frame (0); |
dc6f92b8 | 397 | register Lisp_Object mini_window; |
ff11dfa1 | 398 | register Lisp_Object frame; |
dc6f92b8 | 399 | |
2d80a27a | 400 | XSETFRAME (frame, f); |
dc6f92b8 | 401 | |
804518aa | 402 | f->auto_raise = 0; |
ff11dfa1 JB |
403 | f->auto_lower = 0; |
404 | f->no_split = 1; | |
405 | f->wants_modeline = 0; | |
406 | f->has_minibuffer = 1; | |
dc6f92b8 JB |
407 | |
408 | /* Now label the root window as also being the minibuffer. | |
409 | Avoid infinite looping on the window chain by marking next pointer | |
410 | as nil. */ | |
411 | ||
ff11dfa1 | 412 | mini_window = f->minibuffer_window = f->root_window; |
dc6f92b8 JB |
413 | XWINDOW (mini_window)->mini_p = Qt; |
414 | XWINDOW (mini_window)->next = Qnil; | |
804518aa | 415 | XWINDOW (mini_window)->prev = Qnil; |
ff11dfa1 | 416 | XWINDOW (mini_window)->frame = frame; |
dc6f92b8 JB |
417 | |
418 | /* Put the proper buffer in that window. */ | |
419 | ||
420 | Fset_window_buffer (mini_window, | |
265a9e55 | 421 | (NILP (Vminibuffer_list) |
dc6f92b8 JB |
422 | ? get_minibuffer (0) |
423 | : Fcar (Vminibuffer_list))); | |
ff11dfa1 | 424 | return f; |
dc6f92b8 | 425 | } |
bba88bb1 | 426 | #endif /* HAVE_WINDOW_SYSTEM */ |
dc6f92b8 | 427 | \f |
ff11dfa1 | 428 | /* Construct a frame that refers to the terminal (stdin and stdout). */ |
dc6f92b8 | 429 | |
bb1513c9 RS |
430 | static int terminal_frame_count; |
431 | ||
ff11dfa1 JB |
432 | struct frame * |
433 | make_terminal_frame () | |
dc6f92b8 | 434 | { |
ff11dfa1 | 435 | register struct frame *f; |
d063751a | 436 | Lisp_Object frame; |
bb1513c9 RS |
437 | char name[20]; |
438 | ||
b4f0ee5d KH |
439 | #ifdef MULTI_KBOARD |
440 | if (!initial_kboard) | |
441 | { | |
442 | initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); | |
443 | init_kboard (initial_kboard); | |
a1b658dd KH |
444 | initial_kboard->next_kboard = all_kboards; |
445 | all_kboards = initial_kboard; | |
b4f0ee5d KH |
446 | } |
447 | #endif | |
448 | ||
bb1513c9 RS |
449 | /* The first call must initialize Vframe_list. */ |
450 | if (! (NILP (Vframe_list) || CONSP (Vframe_list))) | |
451 | Vframe_list = Qnil; | |
ff11dfa1 | 452 | |
ff11dfa1 | 453 | f = make_frame (1); |
d063751a | 454 | |
2d80a27a | 455 | XSETFRAME (frame, f); |
d063751a RS |
456 | Vframe_list = Fcons (frame, Vframe_list); |
457 | ||
bb1513c9 | 458 | terminal_frame_count++; |
0303e8da RS |
459 | sprintf (name, "F%d", terminal_frame_count); |
460 | f->name = build_string (name); | |
bb1513c9 | 461 | |
bb1513c9 RS |
462 | f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */ |
463 | f->async_visible = 1; /* Don't let visible be cleared later. */ | |
bb221971 RS |
464 | #ifdef MSDOS |
465 | f->output_data.x = &the_only_x_display; | |
2d764c78 EZ |
466 | if (!inhibit_window_system |
467 | && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)) | |
468 | || XFRAME (selected_frame)->output_method == output_msdos_raw)) | |
65606f5e EZ |
469 | { |
470 | f->output_method = output_msdos_raw; | |
471 | /* This initialization of foreground and background pixels is | |
472 | only important for the initial frame created in temacs. If | |
473 | we don't do that, we get black background and foreground in | |
474 | the dumped Emacs because the_only_x_display is a static | |
475 | variable, hence it is born all-zeroes, and zero is the code | |
476 | for the black color. Other frames all inherit their pixels | |
477 | from what's already in the_only_x_display. */ | |
478 | if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))) | |
479 | && f->output_data.x->background_pixel == 0 | |
480 | && f->output_data.x->foreground_pixel == 0) | |
481 | { | |
482 | f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR; | |
483 | f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR; | |
484 | } | |
485 | } | |
2d764c78 EZ |
486 | else |
487 | f->output_method = output_termcap; | |
488 | #else | |
4ec0d3c1 AI |
489 | #ifdef WINDOWSNT |
490 | f->output_method = output_w32_console; | |
491 | f->output_data.x = &tty_display; | |
492 | #else | |
574a1a90 | 493 | #ifdef macintosh |
1a578e9b AC |
494 | make_mac_terminal_frame (f); |
495 | #else | |
2d764c78 | 496 | f->output_data.x = &tty_display; |
1a578e9b | 497 | #endif /* macintosh */ |
4ec0d3c1 | 498 | #endif /* WINDOWSNT */ |
2d764c78 | 499 | #endif /* MSDOS */ |
574a1a90 | 500 | |
1a6d3623 EZ |
501 | if (!noninteractive) |
502 | init_frame_faces (f); | |
1a578e9b | 503 | |
ff11dfa1 | 504 | return f; |
dc6f92b8 | 505 | } |
bb1513c9 RS |
506 | |
507 | DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame, | |
4bc7e3ad RS |
508 | 1, 1, 0, "Create an additional terminal frame.\n\ |
509 | You can create multiple frames on a text-only terminal in this way.\n\ | |
510 | Only the selected terminal frame is actually displayed.\n\ | |
511 | This function takes one argument, an alist specifying frame parameters.\n\ | |
512 | In practice, generally you don't need to specify any parameters.\n\ | |
513 | Note that changing the size of one terminal frame automatically affects all.") | |
bb1513c9 RS |
514 | (parms) |
515 | Lisp_Object parms; | |
516 | { | |
517 | struct frame *f; | |
574a1a90 | 518 | Lisp_Object frame, tem; |
8d2666fe | 519 | struct frame *sf = SELECTED_FRAME (); |
bb1513c9 | 520 | |
541580aa | 521 | #ifdef MSDOS |
2d764c78 EZ |
522 | if (sf->output_method != output_msdos_raw |
523 | && sf->output_method != output_termcap) | |
bb221971 | 524 | abort (); |
574a1a90 RS |
525 | #else /* not MSDOS */ |
526 | ||
527 | #ifdef macintosh | |
8d2666fe | 528 | if (sf->output_method != output_mac) |
574a1a90 | 529 | error ("Not running on a Macintosh screen; cannot make a new Macintosh frame"); |
bb221971 | 530 | #else |
8d2666fe | 531 | if (sf->output_method != output_termcap) |
bb1513c9 | 532 | error ("Not using an ASCII terminal now; cannot make a new ASCII frame"); |
bb221971 | 533 | #endif |
574a1a90 | 534 | #endif /* not MSDOS */ |
bb1513c9 RS |
535 | |
536 | f = make_terminal_frame (); | |
574a1a90 | 537 | |
8d2666fe GM |
538 | change_frame_size (f, FRAME_HEIGHT (sf), |
539 | FRAME_WIDTH (sf), 0, 0, 0); | |
18082e2d | 540 | adjust_glyphs (f); |
bb1513c9 RS |
541 | calculate_costs (f); |
542 | XSETFRAME (frame, f); | |
8adfc1ec | 543 | Fmodify_frame_parameters (frame, Vdefault_frame_alist); |
bb1513c9 | 544 | Fmodify_frame_parameters (frame, parms); |
87f1940e EZ |
545 | |
546 | /* Make the frame face alist be frame-specific, so that each | |
547 | frame could change its face definitions independently. */ | |
8d2666fe | 548 | f->face_alist = Fcopy_alist (sf->face_alist); |
87f1940e EZ |
549 | /* Simple Fcopy_alist isn't enough, because we need the contents of |
550 | the vectors which are the CDRs of associations in face_alist to | |
551 | be copied as well. */ | |
552 | for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem)) | |
553 | XCDR (XCAR (tem)) = Fcopy_sequence (XCDR (XCAR (tem))); | |
bb1513c9 RS |
554 | return frame; |
555 | } | |
dc6f92b8 | 556 | \f |
61f94483 | 557 | Lisp_Object |
0aed85f4 | 558 | do_switch_frame (frame, no_enter, track) |
ff11dfa1 | 559 | Lisp_Object frame, no_enter; |
0aed85f4 | 560 | int track; |
dc6f92b8 | 561 | { |
8d2666fe GM |
562 | struct frame *sf = SELECTED_FRAME (); |
563 | ||
2f0b07e0 JB |
564 | /* If FRAME is a switch-frame event, extract the frame we should |
565 | switch to. */ | |
566 | if (CONSP (frame) | |
7539e11f KR |
567 | && EQ (XCAR (frame), Qswitch_frame) |
568 | && CONSP (XCDR (frame))) | |
569 | frame = XCAR (XCDR (frame)); | |
2f0b07e0 | 570 | |
09907c3a KH |
571 | /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for |
572 | a switch-frame event to arrive after a frame is no longer live, | |
573 | especially when deleting the initial frame during startup. */ | |
574 | CHECK_FRAME (frame, 0); | |
575 | if (! FRAME_LIVE_P (XFRAME (frame))) | |
576 | return Qnil; | |
dc6f92b8 | 577 | |
8d2666fe | 578 | if (sf == XFRAME (frame)) |
ff11dfa1 | 579 | return frame; |
dc6f92b8 | 580 | |
0aed85f4 KH |
581 | /* This is too greedy; it causes inappropriate focus redirection |
582 | that's hard to get rid of. */ | |
583 | #if 0 | |
a42e9724 JB |
584 | /* If a frame's focus has been redirected toward the currently |
585 | selected frame, we should change the redirection to point to the | |
586 | newly selected frame. This means that if the focus is redirected | |
587 | from a minibufferless frame to a surrogate minibuffer frame, we | |
588 | can use `other-window' to switch between all the frames using | |
589 | that minibuffer frame, and the focus redirection will follow us | |
590 | around. */ | |
0aed85f4 KH |
591 | if (track) |
592 | { | |
593 | Lisp_Object tail; | |
a42e9724 | 594 | |
7539e11f | 595 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
0aed85f4 KH |
596 | { |
597 | Lisp_Object focus; | |
a42e9724 | 598 | |
7539e11f | 599 | if (!FRAMEP (XCAR (tail))) |
0aed85f4 | 600 | abort (); |
a42e9724 | 601 | |
7539e11f | 602 | focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail))); |
a42e9724 | 603 | |
8d2666fe | 604 | if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ()) |
7539e11f | 605 | Fredirect_frame_focus (XCAR (tail), frame); |
0aed85f4 KH |
606 | } |
607 | } | |
608 | #else /* ! 0 */ | |
609 | /* Instead, apply it only to the frame we're pointing to. */ | |
032d78fe GV |
610 | #ifdef HAVE_WINDOW_SYSTEM |
611 | if (track && (FRAME_WINDOW_P (XFRAME (frame)))) | |
0aed85f4 KH |
612 | { |
613 | Lisp_Object focus, xfocus; | |
614 | ||
d7266360 | 615 | xfocus = x_get_focus_frame (XFRAME (frame)); |
0aed85f4 KH |
616 | if (FRAMEP (xfocus)) |
617 | { | |
618 | focus = FRAME_FOCUS_FRAME (XFRAME (xfocus)); | |
8d2666fe | 619 | if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ()) |
0aed85f4 KH |
620 | Fredirect_frame_focus (xfocus, frame); |
621 | } | |
622 | } | |
623 | #endif /* HAVE_X_WINDOWS */ | |
624 | #endif /* ! 0 */ | |
a42e9724 | 625 | |
8d2666fe GM |
626 | selected_frame = frame; |
627 | if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) | |
628 | last_nonminibuf_frame = XFRAME (selected_frame); | |
d5e7c279 | 629 | |
ff11dfa1 | 630 | Fselect_window (XFRAME (frame)->selected_window); |
dc6f92b8 | 631 | |
074577b8 | 632 | /* We want to make sure that the next event generates a frame-switch |
eb8c3be9 | 633 | event to the appropriate frame. This seems kludgy to me, but |
074577b8 JB |
634 | before you take it out, make sure that evaluating something like |
635 | (select-window (frame-root-window (new-frame))) doesn't end up | |
636 | with your typing being interpreted in the new frame instead of | |
637 | the one you're actually typing in. */ | |
ef352596 | 638 | internal_last_event_frame = Qnil; |
074577b8 | 639 | |
ff11dfa1 | 640 | return frame; |
dc6f92b8 JB |
641 | } |
642 | ||
0aed85f4 KH |
643 | DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e", |
644 | "Select the frame FRAME.\n\ | |
645 | Subsequent editing commands apply to its selected window.\n\ | |
646 | The selection of FRAME lasts until the next time the user does\n\ | |
647 | something to select a different frame, or until the next time this\n\ | |
648 | function is called.") | |
649 | (frame, no_enter) | |
650 | Lisp_Object frame, no_enter; | |
651 | { | |
652 | return do_switch_frame (frame, no_enter, 1); | |
653 | } | |
654 | ||
655 | ||
656 | DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e", | |
657 | "Handle a switch-frame event EVENT.\n\ | |
658 | Switch-frame events are usually bound to this function.\n\ | |
659 | A switch-frame event tells Emacs that the window manager has requested\n\ | |
660 | that the user's events be directed to the frame mentioned in the event.\n\ | |
661 | This function selects the selected window of the frame of EVENT.\n\ | |
662 | \n\ | |
663 | If EVENT is frame object, handle it as if it were a switch-frame event\n\ | |
664 | to that frame.") | |
735eeca3 EN |
665 | (event, no_enter) |
666 | Lisp_Object event, no_enter; | |
0aed85f4 | 667 | { |
6951cd71 KH |
668 | /* Preserve prefix arg that the command loop just cleared. */ |
669 | current_kboard->Vprefix_arg = Vcurrent_prefix_arg; | |
e05169e2 | 670 | call1 (Vrun_hooks, Qmouse_leave_buffer_hook); |
735eeca3 | 671 | return do_switch_frame (event, no_enter, 0); |
0aed85f4 KH |
672 | } |
673 | ||
1c212787 KH |
674 | DEFUN ("ignore-event", Fignore_event, Signore_event, 0, 0, "", |
675 | "Do nothing, but preserve any prefix argument already specified.\n\ | |
676 | This is a suitable binding for iconify-frame and make-frame-visible.") | |
677 | () | |
678 | { | |
679 | current_kboard->Vprefix_arg = Vcurrent_prefix_arg; | |
680 | return Qnil; | |
681 | } | |
0aed85f4 | 682 | |
ff11dfa1 JB |
683 | DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0, |
684 | "Return the frame that is now selected.") | |
dc6f92b8 JB |
685 | () |
686 | { | |
8d2666fe | 687 | return selected_frame; |
dc6f92b8 | 688 | } |
4a7cfafc | 689 | \f |
ff11dfa1 JB |
690 | DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0, |
691 | "Return the frame object that window WINDOW is on.") | |
dc6f92b8 JB |
692 | (window) |
693 | Lisp_Object window; | |
694 | { | |
774910eb | 695 | CHECK_LIVE_WINDOW (window, 0); |
ff11dfa1 | 696 | return XWINDOW (window)->frame; |
dc6f92b8 JB |
697 | } |
698 | ||
ba32f2db KH |
699 | DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0, |
700 | "Returns the topmost, leftmost window of FRAME.\n\ | |
701 | If omitted, FRAME defaults to the currently selected frame.") | |
702 | (frame) | |
703 | Lisp_Object frame; | |
704 | { | |
705 | Lisp_Object w; | |
706 | ||
707 | if (NILP (frame)) | |
8d2666fe | 708 | w = SELECTED_FRAME ()->root_window; |
ba32f2db KH |
709 | else |
710 | { | |
711 | CHECK_LIVE_FRAME (frame, 0); | |
712 | w = XFRAME (frame)->root_window; | |
713 | } | |
714 | while (NILP (XWINDOW (w)->buffer)) | |
715 | { | |
716 | if (! NILP (XWINDOW (w)->hchild)) | |
717 | w = XWINDOW (w)->hchild; | |
718 | else if (! NILP (XWINDOW (w)->vchild)) | |
719 | w = XWINDOW (w)->vchild; | |
720 | else | |
721 | abort (); | |
722 | } | |
723 | return w; | |
724 | } | |
725 | ||
5add3885 RS |
726 | DEFUN ("active-minibuffer-window", Factive_minibuffer_window, |
727 | Sactive_minibuffer_window, 0, 0, 0, | |
728 | "Return the currently active minibuffer window, or nil if none.") | |
729 | () | |
730 | { | |
731 | return minibuf_level ? minibuf_window : Qnil; | |
732 | } | |
733 | ||
ff11dfa1 | 734 | DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0, |
8693ca83 JB |
735 | "Returns the root-window of FRAME.\n\ |
736 | If omitted, FRAME defaults to the currently selected frame.") | |
ff11dfa1 JB |
737 | (frame) |
738 | Lisp_Object frame; | |
dc6f92b8 | 739 | { |
8d2666fe GM |
740 | Lisp_Object window; |
741 | ||
ff11dfa1 | 742 | if (NILP (frame)) |
8d2666fe | 743 | window = SELECTED_FRAME ()->root_window; |
f9898cc6 | 744 | else |
8d2666fe GM |
745 | { |
746 | CHECK_LIVE_FRAME (frame, 0); | |
747 | window = XFRAME (frame)->root_window; | |
748 | } | |
749 | ||
750 | return window; | |
dc6f92b8 JB |
751 | } |
752 | ||
ff11dfa1 JB |
753 | DEFUN ("frame-selected-window", Fframe_selected_window, |
754 | Sframe_selected_window, 0, 1, 0, | |
8693ca83 JB |
755 | "Return the selected window of frame object FRAME.\n\ |
756 | If omitted, FRAME defaults to the currently selected frame.") | |
ff11dfa1 JB |
757 | (frame) |
758 | Lisp_Object frame; | |
dc6f92b8 | 759 | { |
8d2666fe GM |
760 | Lisp_Object window; |
761 | ||
ff11dfa1 | 762 | if (NILP (frame)) |
8d2666fe | 763 | window = SELECTED_FRAME ()->selected_window; |
f9898cc6 | 764 | else |
8d2666fe GM |
765 | { |
766 | CHECK_LIVE_FRAME (frame, 0); | |
767 | window = XFRAME (frame)->selected_window; | |
768 | } | |
dc6f92b8 | 769 | |
8d2666fe | 770 | return window; |
dc6f92b8 JB |
771 | } |
772 | ||
4a7cfafc RS |
773 | DEFUN ("set-frame-selected-window", Fset_frame_selected_window, |
774 | Sset_frame_selected_window, 2, 2, 0, | |
775 | "Set the selected window of frame object FRAME to WINDOW.\n\ | |
776 | If FRAME is nil, the selected frame is used.\n\ | |
777 | If FRAME is the selected frame, this makes WINDOW the selected window.") | |
778 | (frame, window) | |
779 | Lisp_Object frame, window; | |
780 | { | |
781 | if (NILP (frame)) | |
8d2666fe GM |
782 | frame = selected_frame; |
783 | ||
784 | CHECK_LIVE_FRAME (frame, 0); | |
4a7cfafc RS |
785 | CHECK_LIVE_WINDOW (window, 1); |
786 | ||
787 | if (! EQ (frame, WINDOW_FRAME (XWINDOW (window)))) | |
788 | error ("In `set-frame-selected-window', WINDOW is not on FRAME"); | |
789 | ||
8d2666fe | 790 | if (EQ (frame, selected_frame)) |
4a7cfafc RS |
791 | return Fselect_window (window); |
792 | ||
793 | return XFRAME (frame)->selected_window = window; | |
794 | } | |
795 | \f | |
ff11dfa1 | 796 | DEFUN ("frame-list", Fframe_list, Sframe_list, |
dc6f92b8 | 797 | 0, 0, 0, |
ff11dfa1 | 798 | "Return a list of all frames.") |
dc6f92b8 JB |
799 | () |
800 | { | |
ff11dfa1 | 801 | return Fcopy_sequence (Vframe_list); |
dc6f92b8 JB |
802 | } |
803 | ||
ff11dfa1 | 804 | /* Return the next frame in the frame list after FRAME. |
ff11dfa1 | 805 | If MINIBUF is nil, exclude minibuffer-only frames. |
a9986780 RS |
806 | If MINIBUF is a window, include only its own frame |
807 | and any frame now using that window as the minibuffer. | |
f7af3f7b | 808 | If MINIBUF is `visible', include all visible frames. |
a9986780 | 809 | If MINIBUF is 0, include all visible and iconified frames. |
f7af3f7b RS |
810 | Otherwise, include all frames. */ |
811 | ||
dc6f92b8 | 812 | Lisp_Object |
ff11dfa1 JB |
813 | next_frame (frame, minibuf) |
814 | Lisp_Object frame; | |
f9898cc6 | 815 | Lisp_Object minibuf; |
dc6f92b8 JB |
816 | { |
817 | Lisp_Object tail; | |
818 | int passed = 0; | |
819 | ||
ff11dfa1 JB |
820 | /* There must always be at least one frame in Vframe_list. */ |
821 | if (! CONSP (Vframe_list)) | |
f9898cc6 JB |
822 | abort (); |
823 | ||
dbc4e1c1 JB |
824 | /* If this frame is dead, it won't be in Vframe_list, and we'll loop |
825 | forever. Forestall that. */ | |
826 | CHECK_LIVE_FRAME (frame, 0); | |
827 | ||
dc6f92b8 | 828 | while (1) |
7539e11f | 829 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
dc6f92b8 | 830 | { |
ab9f008d | 831 | Lisp_Object f; |
d06a8a56 | 832 | |
7539e11f | 833 | f = XCAR (tail); |
06537cc8 RS |
834 | |
835 | if (passed | |
836 | && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) | |
d5e7c279 | 837 | { |
d06a8a56 JB |
838 | /* Decide whether this frame is eligible to be returned. */ |
839 | ||
840 | /* If we've looped all the way around without finding any | |
841 | eligible frames, return the original frame. */ | |
842 | if (EQ (f, frame)) | |
843 | return f; | |
844 | ||
845 | /* Let minibuf decide if this frame is acceptable. */ | |
846 | if (NILP (minibuf)) | |
847 | { | |
848 | if (! FRAME_MINIBUF_ONLY_P (XFRAME (f))) | |
849 | return f; | |
850 | } | |
f7af3f7b RS |
851 | else if (EQ (minibuf, Qvisible)) |
852 | { | |
853 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | |
854 | if (FRAME_VISIBLE_P (XFRAME (f))) | |
855 | return f; | |
856 | } | |
3780bc22 | 857 | else if (INTEGERP (minibuf) && XINT (minibuf) == 0) |
a9986780 RS |
858 | { |
859 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | |
860 | if (FRAME_VISIBLE_P (XFRAME (f)) | |
861 | || FRAME_ICONIFIED_P (XFRAME (f))) | |
862 | return f; | |
863 | } | |
f7af3f7b | 864 | else if (WINDOWP (minibuf)) |
d06a8a56 | 865 | { |
a9986780 | 866 | if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf) |
551645f8 GM |
867 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f) |
868 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), | |
869 | FRAME_FOCUS_FRAME (XFRAME (f)))) | |
d06a8a56 JB |
870 | return f; |
871 | } | |
872 | else | |
ff11dfa1 | 873 | return f; |
d5e7c279 | 874 | } |
dc6f92b8 | 875 | |
d06a8a56 | 876 | if (EQ (frame, f)) |
dc6f92b8 JB |
877 | passed++; |
878 | } | |
879 | } | |
880 | ||
ff11dfa1 | 881 | /* Return the previous frame in the frame list before FRAME. |
ff11dfa1 | 882 | If MINIBUF is nil, exclude minibuffer-only frames. |
a9986780 RS |
883 | If MINIBUF is a window, include only its own frame |
884 | and any frame now using that window as the minibuffer. | |
f7af3f7b | 885 | If MINIBUF is `visible', include all visible frames. |
a9986780 | 886 | If MINIBUF is 0, include all visible and iconified frames. |
f7af3f7b RS |
887 | Otherwise, include all frames. */ |
888 | ||
dc6f92b8 | 889 | Lisp_Object |
ff11dfa1 JB |
890 | prev_frame (frame, minibuf) |
891 | Lisp_Object frame; | |
f9898cc6 | 892 | Lisp_Object minibuf; |
dc6f92b8 JB |
893 | { |
894 | Lisp_Object tail; | |
895 | Lisp_Object prev; | |
896 | ||
ff11dfa1 JB |
897 | /* There must always be at least one frame in Vframe_list. */ |
898 | if (! CONSP (Vframe_list)) | |
f9898cc6 JB |
899 | abort (); |
900 | ||
dc6f92b8 | 901 | prev = Qnil; |
7539e11f | 902 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
f9898cc6 | 903 | { |
ab9f008d | 904 | Lisp_Object f; |
f9898cc6 | 905 | |
7539e11f | 906 | f = XCAR (tail); |
e35d291d | 907 | if (!FRAMEP (f)) |
d06a8a56 | 908 | abort (); |
f9898cc6 | 909 | |
d06a8a56 JB |
910 | if (EQ (frame, f) && !NILP (prev)) |
911 | return prev; | |
f9898cc6 | 912 | |
06537cc8 | 913 | if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) |
f7af3f7b | 914 | { |
06537cc8 RS |
915 | /* Decide whether this frame is eligible to be returned, |
916 | according to minibuf. */ | |
917 | if (NILP (minibuf)) | |
918 | { | |
919 | if (! FRAME_MINIBUF_ONLY_P (XFRAME (f))) | |
920 | prev = f; | |
921 | } | |
922 | else if (WINDOWP (minibuf)) | |
923 | { | |
924 | if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf) | |
551645f8 GM |
925 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f) |
926 | || EQ (WINDOW_FRAME (XWINDOW (minibuf)), | |
927 | FRAME_FOCUS_FRAME (XFRAME (f)))) | |
06537cc8 RS |
928 | prev = f; |
929 | } | |
930 | else if (EQ (minibuf, Qvisible)) | |
931 | { | |
932 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | |
933 | if (FRAME_VISIBLE_P (XFRAME (f))) | |
934 | prev = f; | |
935 | } | |
936 | else if (XFASTINT (minibuf) == 0) | |
937 | { | |
938 | FRAME_SAMPLE_VISIBILITY (XFRAME (f)); | |
939 | if (FRAME_VISIBLE_P (XFRAME (f)) | |
940 | || FRAME_ICONIFIED_P (XFRAME (f))) | |
941 | prev = f; | |
942 | } | |
943 | else | |
a9986780 RS |
944 | prev = f; |
945 | } | |
f9898cc6 | 946 | } |
d06a8a56 JB |
947 | |
948 | /* We've scanned the entire list. */ | |
949 | if (NILP (prev)) | |
950 | /* We went through the whole frame list without finding a single | |
951 | acceptable frame. Return the original frame. */ | |
952 | return frame; | |
953 | else | |
954 | /* There were no acceptable frames in the list before FRAME; otherwise, | |
955 | we would have returned directly from the loop. Since PREV is the last | |
956 | acceptable frame in the list, return it. */ | |
957 | return prev; | |
dc6f92b8 JB |
958 | } |
959 | ||
ef2c57ac | 960 | |
ff11dfa1 JB |
961 | DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0, |
962 | "Return the next frame in the frame list after FRAME.\n\ | |
06537cc8 | 963 | It considers only frames on the same terminal as FRAME.\n\ |
a42e9724 | 964 | By default, skip minibuffer-only frames.\n\ |
d06a8a56 | 965 | If omitted, FRAME defaults to the selected frame.\n\ |
c08c95c7 | 966 | If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\ |
06537cc8 | 967 | If MINIFRAME is a window, include only its own frame\n\ |
a9986780 | 968 | and any frame now using that window as the minibuffer.\n\ |
f7af3f7b | 969 | If MINIFRAME is `visible', include all visible frames.\n\ |
06537cc8 | 970 | If MINIFRAME is 0, include all visible and iconified frames.\n\ |
f7af3f7b | 971 | Otherwise, include all frames.") |
ff11dfa1 | 972 | (frame, miniframe) |
8693ca83 | 973 | Lisp_Object frame, miniframe; |
dc6f92b8 | 974 | { |
ff11dfa1 | 975 | if (NILP (frame)) |
8d2666fe GM |
976 | frame = selected_frame; |
977 | ||
978 | CHECK_LIVE_FRAME (frame, 0); | |
ff11dfa1 | 979 | return next_frame (frame, miniframe); |
dc6f92b8 | 980 | } |
dbc4e1c1 | 981 | |
ef2c57ac RM |
982 | DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0, |
983 | "Return the previous frame in the frame list before FRAME.\n\ | |
06537cc8 | 984 | It considers only frames on the same terminal as FRAME.\n\ |
ef2c57ac RM |
985 | By default, skip minibuffer-only frames.\n\ |
986 | If omitted, FRAME defaults to the selected frame.\n\ | |
987 | If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\ | |
06537cc8 | 988 | If MINIFRAME is a window, include only its own frame\n\ |
a9986780 | 989 | and any frame now using that window as the minibuffer.\n\ |
f7af3f7b | 990 | If MINIFRAME is `visible', include all visible frames.\n\ |
06537cc8 | 991 | If MINIFRAME is 0, include all visible and iconified frames.\n\ |
f7af3f7b | 992 | Otherwise, include all frames.") |
ef2c57ac RM |
993 | (frame, miniframe) |
994 | Lisp_Object frame, miniframe; | |
995 | { | |
ef2c57ac | 996 | if (NILP (frame)) |
8d2666fe GM |
997 | frame = selected_frame; |
998 | CHECK_LIVE_FRAME (frame, 0); | |
ef2c57ac RM |
999 | return prev_frame (frame, miniframe); |
1000 | } | |
dc6f92b8 | 1001 | \f |
808c0f20 RS |
1002 | /* Return 1 if it is ok to delete frame F; |
1003 | 0 if all frames aside from F are invisible. | |
1004 | (Exception: if F is the terminal frame, and we are using X, return 1.) */ | |
dc6f92b8 | 1005 | |
d56b45eb | 1006 | int |
808c0f20 RS |
1007 | other_visible_frames (f) |
1008 | FRAME_PTR f; | |
1009 | { | |
1010 | /* We know the selected frame is visible, | |
1011 | so if F is some other frame, it can't be the sole visible one. */ | |
8d2666fe | 1012 | if (f == SELECTED_FRAME ()) |
c08c95c7 RS |
1013 | { |
1014 | Lisp_Object frames; | |
1015 | int count = 0; | |
1016 | ||
1017 | for (frames = Vframe_list; | |
1018 | CONSP (frames); | |
7539e11f | 1019 | frames = XCDR (frames)) |
c08c95c7 | 1020 | { |
ab9f008d | 1021 | Lisp_Object this; |
c08c95c7 | 1022 | |
7539e11f | 1023 | this = XCAR (frames); |
808c0f20 RS |
1024 | /* Verify that the frame's window still exists |
1025 | and we can still talk to it. And note any recent change | |
1026 | in visibility. */ | |
032d78fe GV |
1027 | #ifdef HAVE_WINDOW_SYSTEM |
1028 | if (FRAME_WINDOW_P (XFRAME (this))) | |
5e7b7c5b | 1029 | { |
b0509a40 | 1030 | x_sync (XFRAME (this)); |
5e7b7c5b RS |
1031 | FRAME_SAMPLE_VISIBILITY (XFRAME (this)); |
1032 | } | |
1033 | #endif | |
1034 | ||
c08c95c7 RS |
1035 | if (FRAME_VISIBLE_P (XFRAME (this)) |
1036 | || FRAME_ICONIFIED_P (XFRAME (this)) | |
1037 | /* Allow deleting the terminal frame when at least | |
1038 | one X frame exists! */ | |
032d78fe | 1039 | || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f))) |
c08c95c7 RS |
1040 | count++; |
1041 | } | |
808c0f20 | 1042 | return count > 1; |
c08c95c7 | 1043 | } |
808c0f20 RS |
1044 | return 1; |
1045 | } | |
1046 | ||
1047 | DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "", | |
1048 | "Delete FRAME, permanently eliminating it from use.\n\ | |
1049 | If omitted, FRAME defaults to the selected frame.\n\ | |
1050 | A frame may not be deleted if its minibuffer is used by other frames.\n\ | |
1051 | Normally, you may not delete a frame if all other frames are invisible,\n\ | |
0e662342 GM |
1052 | but if the second optional argument FORCE is non-nil, you may do so.\n\ |
1053 | \n\ | |
1054 | This function runs `delete-frame-hook' before actually deleting the\n\ | |
1055 | frame. The hook is called with one argument FRAME.") | |
808c0f20 RS |
1056 | (frame, force) |
1057 | Lisp_Object frame, force; | |
1058 | { | |
1059 | struct frame *f; | |
8d2666fe | 1060 | struct frame *sf = SELECTED_FRAME (); |
99b92e64 | 1061 | int minibuffer_selected; |
808c0f20 RS |
1062 | |
1063 | if (EQ (frame, Qnil)) | |
1064 | { | |
8d2666fe | 1065 | f = sf; |
2d80a27a | 1066 | XSETFRAME (frame, f); |
808c0f20 RS |
1067 | } |
1068 | else | |
1069 | { | |
1070 | CHECK_FRAME (frame, 0); | |
1071 | f = XFRAME (frame); | |
1072 | } | |
1073 | ||
1074 | if (! FRAME_LIVE_P (f)) | |
1075 | return Qnil; | |
1076 | ||
1077 | if (NILP (force) && !other_visible_frames (f)) | |
1078 | error ("Attempt to delete the sole visible or iconified frame"); | |
d5e7c279 | 1079 | |
00c5fd51 RS |
1080 | #if 0 |
1081 | /* This is a nice idea, but x_connection_closed needs to be able | |
1082 | to delete the last frame, if it is gone. */ | |
7539e11f | 1083 | if (NILP (XCDR (Vframe_list))) |
e9687ee8 | 1084 | error ("Attempt to delete the only frame"); |
00c5fd51 | 1085 | #endif |
e9687ee8 | 1086 | |
ff11dfa1 JB |
1087 | /* Does this frame have a minibuffer, and is it the surrogate |
1088 | minibuffer for any other frame? */ | |
fd0c2bd1 | 1089 | if (FRAME_HAS_MINIBUF_P (XFRAME (frame))) |
dc6f92b8 | 1090 | { |
ff11dfa1 | 1091 | Lisp_Object frames; |
1113d9db | 1092 | |
ff11dfa1 JB |
1093 | for (frames = Vframe_list; |
1094 | CONSP (frames); | |
7539e11f | 1095 | frames = XCDR (frames)) |
1113d9db | 1096 | { |
7a8cc307 | 1097 | Lisp_Object this; |
7539e11f | 1098 | this = XCAR (frames); |
1113d9db | 1099 | |
ff11dfa1 JB |
1100 | if (! EQ (this, frame) |
1101 | && EQ (frame, | |
7a8cc307 RS |
1102 | WINDOW_FRAME (XWINDOW |
1103 | (FRAME_MINIBUF_WINDOW (XFRAME (this)))))) | |
ff11dfa1 | 1104 | error ("Attempt to delete a surrogate minibuffer frame"); |
1113d9db | 1105 | } |
dc6f92b8 JB |
1106 | } |
1107 | ||
0e662342 GM |
1108 | /* Run `delete-frame-hook'. */ |
1109 | if (!NILP (Vrun_hooks)) | |
1110 | { | |
1111 | Lisp_Object args[2]; | |
1112 | args[0] = intern ("delete-frame-hook"); | |
1113 | args[1] = frame; | |
1114 | Frun_hook_with_args (2, args); | |
1115 | } | |
1116 | ||
99b92e64 RS |
1117 | minibuffer_selected = EQ (minibuf_window, selected_window); |
1118 | ||
ff11dfa1 | 1119 | /* Don't let the frame remain selected. */ |
8d2666fe | 1120 | if (f == sf) |
06537cc8 RS |
1121 | { |
1122 | Lisp_Object tail, frame1; | |
1123 | ||
1124 | /* Look for another visible frame on the same terminal. */ | |
1125 | frame1 = next_frame (frame, Qvisible); | |
1126 | ||
1127 | /* If there is none, find *some* other frame. */ | |
1128 | if (NILP (frame1) || EQ (frame1, frame)) | |
1129 | { | |
1130 | FOR_EACH_FRAME (tail, frame1) | |
1131 | { | |
1132 | if (! EQ (frame, frame1)) | |
1133 | break; | |
1134 | } | |
1135 | } | |
1136 | ||
1137 | do_switch_frame (frame1, Qnil, 0); | |
79a65b7f | 1138 | sf = SELECTED_FRAME (); |
06537cc8 | 1139 | } |
dc6f92b8 | 1140 | |
ff11dfa1 JB |
1141 | /* Don't allow minibuf_window to remain on a deleted frame. */ |
1142 | if (EQ (f->minibuffer_window, minibuf_window)) | |
dc6f92b8 | 1143 | { |
8d2666fe | 1144 | Fset_window_buffer (sf->minibuffer_window, |
dc6f92b8 | 1145 | XWINDOW (minibuf_window)->buffer); |
8d2666fe | 1146 | minibuf_window = sf->minibuffer_window; |
99b92e64 RS |
1147 | |
1148 | /* If the dying minibuffer window was selected, | |
1149 | select the new one. */ | |
1150 | if (minibuffer_selected) | |
1151 | Fselect_window (minibuf_window); | |
dc6f92b8 JB |
1152 | } |
1153 | ||
130adcb7 EZ |
1154 | /* Don't let echo_area_window to remain on a deleted frame. */ |
1155 | if (EQ (f->minibuffer_window, echo_area_window)) | |
1156 | echo_area_window = sf->minibuffer_window; | |
1157 | ||
bb2a0a65 RS |
1158 | /* Clear any X selections for this frame. */ |
1159 | #ifdef HAVE_X_WINDOWS | |
1160 | if (FRAME_X_P (f)) | |
1161 | x_clear_frame_selections (f); | |
1162 | #endif | |
1163 | ||
18082e2d GM |
1164 | /* Free glyphs. |
1165 | This function must be called before the window tree of the | |
1166 | frame is deleted because windows contain dynamically allocated | |
1167 | memory. */ | |
1168 | free_glyphs (f); | |
1169 | ||
4a88b3b0 JB |
1170 | /* Mark all the windows that used to be on FRAME as deleted, and then |
1171 | remove the reference to them. */ | |
1172 | delete_all_subwindows (XWINDOW (f->root_window)); | |
1173 | f->root_window = Qnil; | |
1174 | ||
ff11dfa1 | 1175 | Vframe_list = Fdelq (frame, Vframe_list); |
a42e9724 | 1176 | FRAME_SET_VISIBLE (f, 0); |
dc6f92b8 | 1177 | |
60a8823e | 1178 | if (f->namebuf) |
18082e2d | 1179 | xfree (f->namebuf); |
d2bee99e | 1180 | if (FRAME_INSERT_COST (f)) |
18082e2d | 1181 | xfree (FRAME_INSERT_COST (f)); |
d2bee99e | 1182 | if (FRAME_DELETEN_COST (f)) |
18082e2d | 1183 | xfree (FRAME_DELETEN_COST (f)); |
d2bee99e | 1184 | if (FRAME_INSERTN_COST (f)) |
18082e2d | 1185 | xfree (FRAME_INSERTN_COST (f)); |
d2bee99e | 1186 | if (FRAME_DELETE_COST (f)) |
18082e2d | 1187 | xfree (FRAME_DELETE_COST (f)); |
25734faf | 1188 | if (FRAME_MESSAGE_BUF (f)) |
18082e2d | 1189 | xfree (FRAME_MESSAGE_BUF (f)); |
d2bee99e | 1190 | |
8678b9cc JB |
1191 | /* Since some events are handled at the interrupt level, we may get |
1192 | an event for f at any time; if we zero out the frame's display | |
1193 | now, then we may trip up the event-handling code. Instead, we'll | |
1194 | promise that the display of the frame must be valid until we have | |
1195 | called the window-system-dependent frame destruction routine. */ | |
dbc4e1c1 JB |
1196 | |
1197 | /* I think this should be done with a hook. */ | |
032d78fe GV |
1198 | #ifdef HAVE_WINDOW_SYSTEM |
1199 | if (FRAME_WINDOW_P (f)) | |
8678b9cc | 1200 | x_destroy_window (f); |
d5e7c279 JB |
1201 | #endif |
1202 | ||
7556890b | 1203 | f->output_data.nothing = 0; |
8678b9cc | 1204 | |
ff11dfa1 | 1205 | /* If we've deleted the last_nonminibuf_frame, then try to find |
d5e7c279 | 1206 | another one. */ |
ff11dfa1 | 1207 | if (f == last_nonminibuf_frame) |
d5e7c279 | 1208 | { |
ff11dfa1 | 1209 | Lisp_Object frames; |
1113d9db | 1210 | |
ff11dfa1 | 1211 | last_nonminibuf_frame = 0; |
d5e7c279 | 1212 | |
ff11dfa1 JB |
1213 | for (frames = Vframe_list; |
1214 | CONSP (frames); | |
7539e11f | 1215 | frames = XCDR (frames)) |
d5e7c279 | 1216 | { |
7539e11f | 1217 | f = XFRAME (XCAR (frames)); |
ff11dfa1 | 1218 | if (!FRAME_MINIBUF_ONLY_P (f)) |
d5e7c279 | 1219 | { |
ff11dfa1 | 1220 | last_nonminibuf_frame = f; |
d5e7c279 JB |
1221 | break; |
1222 | } | |
1223 | } | |
1224 | } | |
dc6f92b8 | 1225 | |
c4c6d073 KH |
1226 | /* If we've deleted this keyboard's default_minibuffer_frame, try to |
1227 | find another one. Prefer minibuffer-only frames, but also notice | |
1228 | frames with other windows. */ | |
c60f3a6a | 1229 | if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame)) |
1113d9db | 1230 | { |
ff11dfa1 | 1231 | Lisp_Object frames; |
1113d9db | 1232 | |
ff11dfa1 | 1233 | /* The last frame we saw with a minibuffer, minibuffer-only or not. */ |
ab9f008d | 1234 | Lisp_Object frame_with_minibuf; |
32fda9ba RS |
1235 | /* Some frame we found on the same kboard, or nil if there are none. */ |
1236 | Lisp_Object frame_on_same_kboard; | |
1113d9db | 1237 | |
32fda9ba | 1238 | frame_on_same_kboard = Qnil; |
ab9f008d | 1239 | frame_with_minibuf = Qnil; |
32fda9ba | 1240 | |
ff11dfa1 JB |
1241 | for (frames = Vframe_list; |
1242 | CONSP (frames); | |
7539e11f | 1243 | frames = XCDR (frames)) |
1113d9db | 1244 | { |
ab9f008d | 1245 | Lisp_Object this; |
c4c6d073 | 1246 | struct frame *f1; |
1113d9db | 1247 | |
7539e11f | 1248 | this = XCAR (frames); |
e35d291d | 1249 | if (!FRAMEP (this)) |
1113d9db | 1250 | abort (); |
c4c6d073 | 1251 | f1 = XFRAME (this); |
1113d9db | 1252 | |
c4c6d073 KH |
1253 | /* Consider only frames on the same kboard |
1254 | and only those with minibuffers. */ | |
1255 | if (FRAME_KBOARD (f) == FRAME_KBOARD (f1) | |
1256 | && FRAME_HAS_MINIBUF_P (f1)) | |
1113d9db | 1257 | { |
ff11dfa1 | 1258 | frame_with_minibuf = this; |
c4c6d073 | 1259 | if (FRAME_MINIBUF_ONLY_P (f1)) |
1113d9db JB |
1260 | break; |
1261 | } | |
32fda9ba RS |
1262 | |
1263 | if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)) | |
1264 | frame_on_same_kboard = this; | |
1113d9db JB |
1265 | } |
1266 | ||
32fda9ba RS |
1267 | if (!NILP (frame_on_same_kboard)) |
1268 | { | |
1269 | /* We know that there must be some frame with a minibuffer out | |
1270 | there. If this were not true, all of the frames present | |
1271 | would have to be minibufferless, which implies that at some | |
1272 | point their minibuffer frames must have been deleted, but | |
1273 | that is prohibited at the top; you can't delete surrogate | |
1274 | minibuffer frames. */ | |
1275 | if (NILP (frame_with_minibuf)) | |
1276 | abort (); | |
1113d9db | 1277 | |
32fda9ba RS |
1278 | FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf; |
1279 | } | |
1280 | else | |
1281 | /* No frames left on this kboard--say no minibuffer either. */ | |
1282 | FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil; | |
1113d9db JB |
1283 | } |
1284 | ||
e681c92a RS |
1285 | /* Cause frame titles to update--necessary if we now have just one frame. */ |
1286 | update_mode_lines = 1; | |
1287 | ||
dc6f92b8 JB |
1288 | return Qnil; |
1289 | } | |
1290 | \f | |
1291 | /* Return mouse position in character cell units. */ | |
1292 | ||
f9898cc6 | 1293 | DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0, |
ff11dfa1 | 1294 | "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\ |
4f90516b JB |
1295 | The position is given in character cells, where (0, 0) is the\n\ |
1296 | upper-left corner.\n\ | |
f9898cc6 | 1297 | If Emacs is running on a mouseless terminal or hasn't been programmed\n\ |
ff11dfa1 | 1298 | to read the mouse position, it returns the selected frame for FRAME\n\ |
beb0bc36 DL |
1299 | and nil for X and Y.\n\ |
1300 | Runs the abnormal hook `mouse-position-function' with the normal return\n\ | |
1301 | value as argument.") | |
f9898cc6 | 1302 | () |
dc6f92b8 | 1303 | { |
ff11dfa1 | 1304 | FRAME_PTR f; |
dbc4e1c1 | 1305 | Lisp_Object lispy_dummy; |
fd2777e0 | 1306 | enum scroll_bar_part party_dummy; |
beb0bc36 | 1307 | Lisp_Object x, y, retval; |
5384466a | 1308 | int col, row; |
dbc4e1c1 | 1309 | unsigned long long_dummy; |
cb2255b3 | 1310 | struct gcpro gcpro1; |
dc6f92b8 | 1311 | |
8d2666fe | 1312 | f = SELECTED_FRAME (); |
c5074d8c RS |
1313 | x = y = Qnil; |
1314 | ||
f443c170 | 1315 | #ifdef HAVE_MOUSE |
c5074d8c | 1316 | /* It's okay for the hook to refrain from storing anything. */ |
f9898cc6 | 1317 | if (mouse_position_hook) |
66e827dc | 1318 | (*mouse_position_hook) (&f, -1, |
dbc4e1c1 JB |
1319 | &lispy_dummy, &party_dummy, |
1320 | &x, &y, | |
1321 | &long_dummy); | |
76db7eb4 KH |
1322 | if (! NILP (x)) |
1323 | { | |
1324 | col = XINT (x); | |
1325 | row = XINT (y); | |
8126c3b4 | 1326 | pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1); |
76db7eb4 KH |
1327 | XSETINT (x, col); |
1328 | XSETINT (y, row); | |
1329 | } | |
f443c170 | 1330 | #endif |
2d80a27a | 1331 | XSETFRAME (lispy_dummy, f); |
beb0bc36 | 1332 | retval = Fcons (lispy_dummy, Fcons (x, y)); |
cb2255b3 | 1333 | GCPRO1 (retval); |
beb0bc36 | 1334 | if (!NILP (Vmouse_position_function)) |
cb2255b3 GM |
1335 | retval = call1 (Vmouse_position_function, retval); |
1336 | RETURN_UNGCPRO (retval); | |
dc6f92b8 JB |
1337 | } |
1338 | ||
152e6c70 RS |
1339 | DEFUN ("mouse-pixel-position", Fmouse_pixel_position, |
1340 | Smouse_pixel_position, 0, 0, 0, | |
1341 | "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\ | |
1342 | The position is given in pixel units, where (0, 0) is the\n\ | |
1343 | upper-left corner.\n\ | |
1344 | If Emacs is running on a mouseless terminal or hasn't been programmed\n\ | |
1345 | to read the mouse position, it returns the selected frame for FRAME\n\ | |
1346 | and nil for X and Y.") | |
1347 | () | |
1348 | { | |
1349 | FRAME_PTR f; | |
1350 | Lisp_Object lispy_dummy; | |
1351 | enum scroll_bar_part party_dummy; | |
1352 | Lisp_Object x, y; | |
152e6c70 RS |
1353 | unsigned long long_dummy; |
1354 | ||
8d2666fe | 1355 | f = SELECTED_FRAME (); |
152e6c70 RS |
1356 | x = y = Qnil; |
1357 | ||
0c5c1cf7 | 1358 | #ifdef HAVE_MOUSE |
152e6c70 RS |
1359 | /* It's okay for the hook to refrain from storing anything. */ |
1360 | if (mouse_position_hook) | |
66e827dc | 1361 | (*mouse_position_hook) (&f, -1, |
152e6c70 RS |
1362 | &lispy_dummy, &party_dummy, |
1363 | &x, &y, | |
1364 | &long_dummy); | |
0c5c1cf7 | 1365 | #endif |
2d80a27a | 1366 | XSETFRAME (lispy_dummy, f); |
152e6c70 RS |
1367 | return Fcons (lispy_dummy, Fcons (x, y)); |
1368 | } | |
1369 | ||
dc6f92b8 | 1370 | DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0, |
1d7cc616 | 1371 | "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\ |
e84ffeec RS |
1372 | Coordinates are relative to the frame, not a window,\n\ |
1373 | so the coordinates of the top left character in the frame\n\ | |
1374 | may be nonzero due to left-hand scroll bars or the menu bar.\n\ | |
1375 | \n\ | |
1376 | This function is a no-op for an X frame that is not visible.\n\ | |
efb57f43 RS |
1377 | If you have just created a frame, you must wait for it to become visible\n\ |
1378 | before calling this function on it, like this.\n\ | |
1379 | (while (not (frame-visible-p frame)) (sleep-for .5))") | |
ff11dfa1 JB |
1380 | (frame, x, y) |
1381 | Lisp_Object frame, x, y; | |
dc6f92b8 | 1382 | { |
ff11dfa1 | 1383 | CHECK_LIVE_FRAME (frame, 0); |
dc6f92b8 JB |
1384 | CHECK_NUMBER (x, 2); |
1385 | CHECK_NUMBER (y, 1); | |
1386 | ||
dbc4e1c1 | 1387 | /* I think this should be done with a hook. */ |
032d78fe GV |
1388 | #ifdef HAVE_WINDOW_SYSTEM |
1389 | if (FRAME_WINDOW_P (XFRAME (frame))) | |
dc6f92b8 | 1390 | /* Warping the mouse will cause enternotify and focus events. */ |
d4d76014 | 1391 | x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y)); |
bb221971 | 1392 | #else |
be625e00 | 1393 | #if defined (MSDOS) && defined (HAVE_MOUSE) |
bb221971 RS |
1394 | if (FRAME_MSDOS_P (XFRAME (frame))) |
1395 | { | |
1396 | Fselect_frame (frame, Qnil); | |
1397 | mouse_moveto (XINT (x), XINT (y)); | |
1398 | } | |
1399 | #endif | |
dc6f92b8 JB |
1400 | #endif |
1401 | ||
1402 | return Qnil; | |
1403 | } | |
152e6c70 RS |
1404 | |
1405 | DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position, | |
1406 | Sset_mouse_pixel_position, 3, 3, 0, | |
1407 | "Move the mouse pointer to pixel position (X,Y) in FRAME.\n\ | |
efb57f43 RS |
1408 | Note, this is a no-op for an X frame that is not visible.\n\ |
1409 | If you have just created a frame, you must wait for it to become visible\n\ | |
1410 | before calling this function on it, like this.\n\ | |
1411 | (while (not (frame-visible-p frame)) (sleep-for .5))") | |
152e6c70 RS |
1412 | (frame, x, y) |
1413 | Lisp_Object frame, x, y; | |
1414 | { | |
1415 | CHECK_LIVE_FRAME (frame, 0); | |
1416 | CHECK_NUMBER (x, 2); | |
1417 | CHECK_NUMBER (y, 1); | |
1418 | ||
1419 | /* I think this should be done with a hook. */ | |
032d78fe GV |
1420 | #ifdef HAVE_WINDOW_SYSTEM |
1421 | if (FRAME_WINDOW_P (XFRAME (frame))) | |
152e6c70 | 1422 | /* Warping the mouse will cause enternotify and focus events. */ |
d4d76014 | 1423 | x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y)); |
bb221971 | 1424 | #else |
be625e00 | 1425 | #if defined (MSDOS) && defined (HAVE_MOUSE) |
bb221971 RS |
1426 | if (FRAME_MSDOS_P (XFRAME (frame))) |
1427 | { | |
1428 | Fselect_frame (frame, Qnil); | |
1429 | mouse_moveto (XINT (x), XINT (y)); | |
1430 | } | |
1431 | #endif | |
152e6c70 RS |
1432 | #endif |
1433 | ||
1434 | return Qnil; | |
1435 | } | |
dc6f92b8 | 1436 | \f |
98ce1622 RS |
1437 | static void make_frame_visible_1 P_ ((Lisp_Object)); |
1438 | ||
ff11dfa1 | 1439 | DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible, |
fc25d15d | 1440 | 0, 1, "", |
ff11dfa1 | 1441 | "Make the frame FRAME visible (assuming it is an X-window).\n\ |
8693ca83 | 1442 | If omitted, FRAME defaults to the currently selected frame.") |
ff11dfa1 JB |
1443 | (frame) |
1444 | Lisp_Object frame; | |
dc6f92b8 | 1445 | { |
1aa66088 | 1446 | if (NILP (frame)) |
8d2666fe | 1447 | frame = selected_frame; |
1aa66088 | 1448 | |
ff11dfa1 | 1449 | CHECK_LIVE_FRAME (frame, 0); |
dc6f92b8 | 1450 | |
dbc4e1c1 | 1451 | /* I think this should be done with a hook. */ |
032d78fe GV |
1452 | #ifdef HAVE_WINDOW_SYSTEM |
1453 | if (FRAME_WINDOW_P (XFRAME (frame))) | |
02ff9dd5 RS |
1454 | { |
1455 | FRAME_SAMPLE_VISIBILITY (XFRAME (frame)); | |
1456 | x_make_frame_visible (XFRAME (frame)); | |
1457 | } | |
fd0c2bd1 | 1458 | #endif |
dc6f92b8 | 1459 | |
98ce1622 RS |
1460 | make_frame_visible_1 (XFRAME (frame)->root_window); |
1461 | ||
565620a5 RS |
1462 | /* Make menu bar update for the Buffers and Frams menus. */ |
1463 | windows_or_buffers_changed++; | |
1464 | ||
ff11dfa1 | 1465 | return frame; |
dc6f92b8 JB |
1466 | } |
1467 | ||
98ce1622 RS |
1468 | /* Update the display_time slot of the buffers shown in WINDOW |
1469 | and all its descendents. */ | |
1470 | ||
1471 | static void | |
1472 | make_frame_visible_1 (window) | |
1473 | Lisp_Object window; | |
1474 | { | |
1475 | struct window *w; | |
1476 | ||
1477 | for (;!NILP (window); window = w->next) | |
1478 | { | |
1479 | w = XWINDOW (window); | |
1480 | ||
1481 | if (!NILP (w->buffer)) | |
1482 | XBUFFER (w->buffer)->display_time = Fcurrent_time (); | |
1483 | ||
1484 | if (!NILP (w->vchild)) | |
1485 | make_frame_visible_1 (w->vchild); | |
1486 | if (!NILP (w->hchild)) | |
1487 | make_frame_visible_1 (w->hchild); | |
1488 | } | |
1489 | } | |
1490 | ||
ff11dfa1 | 1491 | DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible, |
808c0f20 | 1492 | 0, 2, "", |
8693ca83 | 1493 | "Make the frame FRAME invisible (assuming it is an X-window).\n\ |
808c0f20 RS |
1494 | If omitted, FRAME defaults to the currently selected frame.\n\ |
1495 | Normally you may not make FRAME invisible if all other frames are invisible,\n\ | |
1496 | but if the second optional argument FORCE is non-nil, you may do so.") | |
1497 | (frame, force) | |
1498 | Lisp_Object frame, force; | |
dc6f92b8 | 1499 | { |
1aa66088 | 1500 | if (NILP (frame)) |
8d2666fe | 1501 | frame = selected_frame; |
1aa66088 | 1502 | |
ff11dfa1 | 1503 | CHECK_LIVE_FRAME (frame, 0); |
dc6f92b8 | 1504 | |
808c0f20 RS |
1505 | if (NILP (force) && !other_visible_frames (XFRAME (frame))) |
1506 | error ("Attempt to make invisible the sole visible or iconified frame"); | |
1507 | ||
3d378fdf | 1508 | #if 0 /* This isn't logically necessary, and it can do GC. */ |
9c394f17 | 1509 | /* Don't let the frame remain selected. */ |
8d2666fe | 1510 | if (EQ (frame, selected_frame)) |
61f94483 | 1511 | do_switch_frame (next_frame (frame, Qt), Qnil, 0) |
3d378fdf | 1512 | #endif |
9c394f17 RS |
1513 | |
1514 | /* Don't allow minibuf_window to remain on a deleted frame. */ | |
1515 | if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window)) | |
1516 | { | |
8d2666fe GM |
1517 | struct frame *sf = XFRAME (selected_frame); |
1518 | Fset_window_buffer (sf->minibuffer_window, | |
9c394f17 | 1519 | XWINDOW (minibuf_window)->buffer); |
8d2666fe | 1520 | minibuf_window = sf->minibuffer_window; |
9c394f17 RS |
1521 | } |
1522 | ||
dbc4e1c1 | 1523 | /* I think this should be done with a hook. */ |
032d78fe GV |
1524 | #ifdef HAVE_WINDOW_SYSTEM |
1525 | if (FRAME_WINDOW_P (XFRAME (frame))) | |
ff11dfa1 | 1526 | x_make_frame_invisible (XFRAME (frame)); |
fd0c2bd1 | 1527 | #endif |
dc6f92b8 | 1528 | |
565620a5 RS |
1529 | /* Make menu bar update for the Buffers and Frams menus. */ |
1530 | windows_or_buffers_changed++; | |
1531 | ||
dc6f92b8 JB |
1532 | return Qnil; |
1533 | } | |
1534 | ||
ff11dfa1 | 1535 | DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame, |
1aa66088 | 1536 | 0, 1, "", |
8693ca83 JB |
1537 | "Make the frame FRAME into an icon.\n\ |
1538 | If omitted, FRAME defaults to the currently selected frame.") | |
ff11dfa1 JB |
1539 | (frame) |
1540 | Lisp_Object frame; | |
dc6f92b8 | 1541 | { |
1aa66088 | 1542 | if (NILP (frame)) |
8d2666fe | 1543 | frame = selected_frame; |
1aa66088 | 1544 | |
ff11dfa1 | 1545 | CHECK_LIVE_FRAME (frame, 0); |
dc6f92b8 | 1546 | |
3d378fdf | 1547 | #if 0 /* This isn't logically necessary, and it can do GC. */ |
9c394f17 | 1548 | /* Don't let the frame remain selected. */ |
8d2666fe | 1549 | if (EQ (frame, selected_frame)) |
9c394f17 | 1550 | Fhandle_switch_frame (next_frame (frame, Qt), Qnil); |
3d378fdf | 1551 | #endif |
9c394f17 RS |
1552 | |
1553 | /* Don't allow minibuf_window to remain on a deleted frame. */ | |
1554 | if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window)) | |
1555 | { | |
8d2666fe GM |
1556 | struct frame *sf = XFRAME (selected_frame); |
1557 | Fset_window_buffer (sf->minibuffer_window, | |
9c394f17 | 1558 | XWINDOW (minibuf_window)->buffer); |
8d2666fe | 1559 | minibuf_window = sf->minibuffer_window; |
9c394f17 RS |
1560 | } |
1561 | ||
dbc4e1c1 | 1562 | /* I think this should be done with a hook. */ |
032d78fe GV |
1563 | #ifdef HAVE_WINDOW_SYSTEM |
1564 | if (FRAME_WINDOW_P (XFRAME (frame))) | |
ff11dfa1 | 1565 | x_iconify_frame (XFRAME (frame)); |
fd0c2bd1 | 1566 | #endif |
dc6f92b8 | 1567 | |
565620a5 RS |
1568 | /* Make menu bar update for the Buffers and Frams menus. */ |
1569 | windows_or_buffers_changed++; | |
1570 | ||
dc6f92b8 JB |
1571 | return Qnil; |
1572 | } | |
1573 | ||
ff11dfa1 | 1574 | DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p, |
dc6f92b8 | 1575 | 1, 1, 0, |
ff11dfa1 JB |
1576 | "Return t if FRAME is now \"visible\" (actually in use for display).\n\ |
1577 | A frame that is not \"visible\" is not updated and, if it works through\n\ | |
dc6f92b8 | 1578 | a window system, it may not show at all.\n\ |
fd0c2bd1 | 1579 | Return the symbol `icon' if frame is visible only as an icon.") |
ff11dfa1 JB |
1580 | (frame) |
1581 | Lisp_Object frame; | |
dc6f92b8 | 1582 | { |
ff11dfa1 | 1583 | CHECK_LIVE_FRAME (frame, 0); |
dc6f92b8 | 1584 | |
5c044f55 RS |
1585 | FRAME_SAMPLE_VISIBILITY (XFRAME (frame)); |
1586 | ||
a42e9724 | 1587 | if (FRAME_VISIBLE_P (XFRAME (frame))) |
dc6f92b8 | 1588 | return Qt; |
a42e9724 | 1589 | if (FRAME_ICONIFIED_P (XFRAME (frame))) |
fd0c2bd1 | 1590 | return Qicon; |
dc6f92b8 JB |
1591 | return Qnil; |
1592 | } | |
1593 | ||
ff11dfa1 | 1594 | DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list, |
dc6f92b8 | 1595 | 0, 0, 0, |
ff11dfa1 | 1596 | "Return a list of all frames now \"visible\" (being updated).") |
dc6f92b8 JB |
1597 | () |
1598 | { | |
ff11dfa1 JB |
1599 | Lisp_Object tail, frame; |
1600 | struct frame *f; | |
dc6f92b8 JB |
1601 | Lisp_Object value; |
1602 | ||
1603 | value = Qnil; | |
7539e11f | 1604 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
dc6f92b8 | 1605 | { |
7539e11f | 1606 | frame = XCAR (tail); |
e35d291d | 1607 | if (!FRAMEP (frame)) |
dc6f92b8 | 1608 | continue; |
ff11dfa1 | 1609 | f = XFRAME (frame); |
a42e9724 | 1610 | if (FRAME_VISIBLE_P (f)) |
ff11dfa1 | 1611 | value = Fcons (frame, value); |
dc6f92b8 JB |
1612 | } |
1613 | return value; | |
1614 | } | |
d5e7c279 JB |
1615 | |
1616 | ||
e518d5e1 | 1617 | DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "", |
dbc4e1c1 JB |
1618 | "Bring FRAME to the front, so it occludes any frames it overlaps.\n\ |
1619 | If FRAME is invisible, make it visible.\n\ | |
828ac693 | 1620 | If you don't specify a frame, the selected frame is used.\n\ |
dbc4e1c1 JB |
1621 | If Emacs is displaying on an ordinary terminal or some other device which\n\ |
1622 | doesn't support multiple overlapping frames, this function does nothing.") | |
1623 | (frame) | |
1624 | Lisp_Object frame; | |
1625 | { | |
828ac693 | 1626 | if (NILP (frame)) |
8d2666fe | 1627 | frame = selected_frame; |
828ac693 | 1628 | |
dbc4e1c1 | 1629 | CHECK_LIVE_FRAME (frame, 0); |
8a981af5 RS |
1630 | |
1631 | /* Do like the documentation says. */ | |
1632 | Fmake_frame_visible (frame); | |
1633 | ||
dbc4e1c1 JB |
1634 | if (frame_raise_lower_hook) |
1635 | (*frame_raise_lower_hook) (XFRAME (frame), 1); | |
1636 | ||
1637 | return Qnil; | |
1638 | } | |
1639 | ||
b49f5578 | 1640 | /* Should we have a corresponding function called Flower_Power? */ |
e518d5e1 | 1641 | DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "", |
dbc4e1c1 | 1642 | "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\ |
828ac693 | 1643 | If you don't specify a frame, the selected frame is used.\n\ |
dbc4e1c1 JB |
1644 | If Emacs is displaying on an ordinary terminal or some other device which\n\ |
1645 | doesn't support multiple overlapping frames, this function does nothing.") | |
1646 | (frame) | |
1647 | Lisp_Object frame; | |
1648 | { | |
828ac693 | 1649 | if (NILP (frame)) |
8d2666fe | 1650 | frame = selected_frame; |
828ac693 | 1651 | |
dbc4e1c1 JB |
1652 | CHECK_LIVE_FRAME (frame, 0); |
1653 | ||
1654 | if (frame_raise_lower_hook) | |
1655 | (*frame_raise_lower_hook) (XFRAME (frame), 0); | |
1656 | ||
1657 | return Qnil; | |
1658 | } | |
1659 | ||
d5e7c279 | 1660 | \f |
ff11dfa1 | 1661 | DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus, |
d5e7c279 | 1662 | 1, 2, 0, |
ff11dfa1 | 1663 | "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\ |
a42e9724 JB |
1664 | In other words, switch-frame events caused by events in FRAME will\n\ |
1665 | request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\ | |
1666 | FOCUS-FRAME after reading an event typed at FRAME.\n\ | |
d5e7c279 | 1667 | \n\ |
a42e9724 | 1668 | If FOCUS-FRAME is omitted or nil, any existing redirection is\n\ |
ff11dfa1 | 1669 | cancelled, and the frame again receives its own keystrokes.\n\ |
d5e7c279 | 1670 | \n\ |
a42e9724 JB |
1671 | Focus redirection is useful for temporarily redirecting keystrokes to\n\ |
1672 | a surrogate minibuffer frame when a frame doesn't have its own\n\ | |
1673 | minibuffer window.\n\ | |
d5e7c279 | 1674 | \n\ |
a42e9724 JB |
1675 | A frame's focus redirection can be changed by select-frame. If frame\n\ |
1676 | FOO is selected, and then a different frame BAR is selected, any\n\ | |
1677 | frames redirecting their focus to FOO are shifted to redirect their\n\ | |
1678 | focus to BAR. This allows focus redirection to work properly when the\n\ | |
1679 | user switches from one frame to another using `select-window'.\n\ | |
1680 | \n\ | |
1681 | This means that a frame whose focus is redirected to itself is treated\n\ | |
1682 | differently from a frame whose focus is redirected to nil; the former\n\ | |
1683 | is affected by select-frame, while the latter is not.\n\ | |
1684 | \n\ | |
1685 | The redirection lasts until `redirect-frame-focus' is called to change it.") | |
ff11dfa1 JB |
1686 | (frame, focus_frame) |
1687 | Lisp_Object frame, focus_frame; | |
d5e7c279 | 1688 | { |
13144095 JB |
1689 | /* Note that we don't check for a live frame here. It's reasonable |
1690 | to redirect the focus of a frame you're about to delete, if you | |
1691 | know what other frame should receive those keystrokes. */ | |
1692 | CHECK_FRAME (frame, 0); | |
f9898cc6 | 1693 | |
a42e9724 | 1694 | if (! NILP (focus_frame)) |
ff11dfa1 | 1695 | CHECK_LIVE_FRAME (focus_frame, 1); |
d5e7c279 | 1696 | |
ff11dfa1 | 1697 | XFRAME (frame)->focus_frame = focus_frame; |
d5e7c279 | 1698 | |
ff11dfa1 | 1699 | if (frame_rehighlight_hook) |
dc0700f6 | 1700 | (*frame_rehighlight_hook) (XFRAME (frame)); |
d5e7c279 JB |
1701 | |
1702 | return Qnil; | |
1703 | } | |
1704 | ||
1705 | ||
ff11dfa1 JB |
1706 | DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0, |
1707 | "Return the frame to which FRAME's keystrokes are currently being sent.\n\ | |
a42e9724 | 1708 | This returns nil if FRAME's focus is not redirected.\n\ |
ff11dfa1 JB |
1709 | See `redirect-frame-focus'.") |
1710 | (frame) | |
1711 | Lisp_Object frame; | |
d5e7c279 | 1712 | { |
ff11dfa1 | 1713 | CHECK_LIVE_FRAME (frame, 0); |
a42e9724 | 1714 | |
ff11dfa1 | 1715 | return FRAME_FOCUS_FRAME (XFRAME (frame)); |
d5e7c279 JB |
1716 | } |
1717 | ||
1718 | ||
dc6f92b8 | 1719 | \f |
329ca574 RS |
1720 | /* Return the value of frame parameter PROP in frame FRAME. */ |
1721 | ||
dc6f92b8 | 1722 | Lisp_Object |
ff11dfa1 JB |
1723 | get_frame_param (frame, prop) |
1724 | register struct frame *frame; | |
dc6f92b8 JB |
1725 | Lisp_Object prop; |
1726 | { | |
1727 | register Lisp_Object tem; | |
1728 | ||
ff11dfa1 | 1729 | tem = Fassq (prop, frame->param_alist); |
dc6f92b8 JB |
1730 | if (EQ (tem, Qnil)) |
1731 | return tem; | |
1732 | return Fcdr (tem); | |
1733 | } | |
1734 | ||
329ca574 RS |
1735 | /* Return the buffer-predicate of the selected frame. */ |
1736 | ||
1737 | Lisp_Object | |
98ce1622 RS |
1738 | frame_buffer_predicate (frame) |
1739 | Lisp_Object frame; | |
329ca574 | 1740 | { |
98ce1622 | 1741 | return XFRAME (frame)->buffer_predicate; |
329ca574 RS |
1742 | } |
1743 | ||
fa54c6ae RS |
1744 | /* Return the buffer-list of the selected frame. */ |
1745 | ||
1746 | Lisp_Object | |
98ce1622 RS |
1747 | frame_buffer_list (frame) |
1748 | Lisp_Object frame; | |
fa54c6ae | 1749 | { |
98ce1622 | 1750 | return XFRAME (frame)->buffer_list; |
fa54c6ae RS |
1751 | } |
1752 | ||
1753 | /* Set the buffer-list of the selected frame. */ | |
1754 | ||
1755 | void | |
98ce1622 RS |
1756 | set_frame_buffer_list (frame, list) |
1757 | Lisp_Object frame, list; | |
fa54c6ae | 1758 | { |
98ce1622 | 1759 | XFRAME (frame)->buffer_list = list; |
fa54c6ae RS |
1760 | } |
1761 | ||
1762 | /* Discard BUFFER from the buffer-list of each frame. */ | |
1763 | ||
1764 | void | |
1765 | frames_discard_buffer (buffer) | |
1766 | Lisp_Object buffer; | |
1767 | { | |
1768 | Lisp_Object frame, tail; | |
1769 | ||
1770 | FOR_EACH_FRAME (tail, frame) | |
1771 | { | |
1772 | XFRAME (frame)->buffer_list | |
1773 | = Fdelq (buffer, XFRAME (frame)->buffer_list); | |
1774 | } | |
1775 | } | |
1776 | ||
214b3216 RS |
1777 | /* Move BUFFER to the end of the buffer-list of each frame. */ |
1778 | ||
1779 | void | |
1780 | frames_bury_buffer (buffer) | |
1781 | Lisp_Object buffer; | |
1782 | { | |
1783 | Lisp_Object frame, tail; | |
1784 | ||
1785 | FOR_EACH_FRAME (tail, frame) | |
1786 | { | |
835c1b36 GM |
1787 | struct frame *f = XFRAME (frame); |
1788 | Lisp_Object found; | |
1789 | ||
1790 | found = Fmemq (buffer, f->buffer_list); | |
1791 | if (!NILP (found)) | |
1792 | f->buffer_list = nconc2 (Fdelq (buffer, f->buffer_list), | |
1793 | Fcons (buffer, Qnil)); | |
214b3216 RS |
1794 | } |
1795 | } | |
1796 | ||
329ca574 RS |
1797 | /* Modify the alist in *ALISTPTR to associate PROP with VAL. |
1798 | If the alist already has an element for PROP, we change it. */ | |
1799 | ||
dc6f92b8 | 1800 | void |
fd0c2bd1 | 1801 | store_in_alist (alistptr, prop, val) |
dc6f92b8 | 1802 | Lisp_Object *alistptr, val; |
fd0c2bd1 | 1803 | Lisp_Object prop; |
dc6f92b8 JB |
1804 | { |
1805 | register Lisp_Object tem; | |
dc6f92b8 | 1806 | |
dc6f92b8 JB |
1807 | tem = Fassq (prop, *alistptr); |
1808 | if (EQ (tem, Qnil)) | |
1809 | *alistptr = Fcons (Fcons (prop, val), *alistptr); | |
1810 | else | |
1811 | Fsetcdr (tem, val); | |
1812 | } | |
1813 | ||
e5317d61 EZ |
1814 | static int |
1815 | frame_name_fnn_p (str, len) | |
1816 | char *str; | |
1817 | int len; | |
1818 | { | |
1819 | if (len > 1 && str[0] == 'F') | |
1820 | { | |
1821 | char *end_ptr; | |
e5317d61 | 1822 | |
48970f2f EZ |
1823 | strtol (str + 1, &end_ptr, 10); |
1824 | ||
e5317d61 EZ |
1825 | if (end_ptr == str + len) |
1826 | return 1; | |
1827 | } | |
1828 | return 0; | |
1829 | } | |
1830 | ||
1831 | /* Set the name of the terminal frame. Also used by MSDOS frames. | |
1832 | Modeled after x_set_name which is used for WINDOW frames. */ | |
1833 | ||
1834 | void | |
1835 | set_term_frame_name (f, name) | |
1836 | struct frame *f; | |
1837 | Lisp_Object name; | |
1838 | { | |
1839 | f->explicit_name = ! NILP (name); | |
1840 | ||
1841 | /* If NAME is nil, set the name to F<num>. */ | |
1842 | if (NILP (name)) | |
1843 | { | |
1844 | char namebuf[20]; | |
1845 | ||
1846 | /* Check for no change needed in this very common case | |
1847 | before we do any consing. */ | |
e34c5c7d | 1848 | if (frame_name_fnn_p (XSTRING (f->name)->data, |
fc932ac6 | 1849 | STRING_BYTES (XSTRING (f->name)))) |
e5317d61 EZ |
1850 | return; |
1851 | ||
1852 | terminal_frame_count++; | |
1853 | sprintf (namebuf, "F%d", terminal_frame_count); | |
1854 | name = build_string (namebuf); | |
1855 | } | |
1856 | else | |
1857 | { | |
1858 | CHECK_STRING (name, 0); | |
1859 | ||
1860 | /* Don't change the name if it's already NAME. */ | |
1861 | if (! NILP (Fstring_equal (name, f->name))) | |
1862 | return; | |
1863 | ||
1864 | /* Don't allow the user to set the frame name to F<num>, so it | |
1865 | doesn't clash with the names we generate for terminal frames. */ | |
fc932ac6 | 1866 | if (frame_name_fnn_p (XSTRING (name)->data, STRING_BYTES (XSTRING (name)))) |
e5317d61 EZ |
1867 | error ("Frame names of the form F<num> are usurped by Emacs"); |
1868 | } | |
1869 | ||
1870 | f->name = name; | |
1871 | update_mode_lines = 1; | |
1872 | } | |
1873 | ||
dc6f92b8 | 1874 | void |
ff11dfa1 JB |
1875 | store_frame_param (f, prop, val) |
1876 | struct frame *f; | |
dc6f92b8 JB |
1877 | Lisp_Object prop, val; |
1878 | { | |
7eb63b72 | 1879 | register Lisp_Object old_alist_elt; |
dc6f92b8 | 1880 | |
7eb63b72 GM |
1881 | /* The buffer-alist parameter is stored in a special place and is |
1882 | not in the alist. */ | |
fa54c6ae RS |
1883 | if (EQ (prop, Qbuffer_list)) |
1884 | { | |
1885 | f->buffer_list = val; | |
1886 | return; | |
1887 | } | |
1888 | ||
7eb63b72 GM |
1889 | /* If PROP is a symbol which is supposed to have frame-local values, |
1890 | and it is set up based on this frame, switch to the global | |
1891 | binding. That way, we can create or alter the frame-local binding | |
1892 | without messing up the symbol's status. */ | |
1893 | if (SYMBOLP (prop)) | |
1894 | { | |
1895 | Lisp_Object valcontents; | |
1896 | valcontents = XSYMBOL (prop)->value; | |
1897 | if ((BUFFER_LOCAL_VALUEP (valcontents) | |
1898 | || SOME_BUFFER_LOCAL_VALUEP (valcontents)) | |
1899 | && XBUFFER_LOCAL_VALUE (valcontents)->check_frame | |
1900 | && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f) | |
1901 | swap_in_global_binding (prop); | |
1902 | } | |
1903 | ||
1904 | /* Update the frame parameter alist. */ | |
1905 | old_alist_elt = Fassq (prop, f->param_alist); | |
1906 | if (EQ (old_alist_elt, Qnil)) | |
ff11dfa1 | 1907 | f->param_alist = Fcons (Fcons (prop, val), f->param_alist); |
dc6f92b8 | 1908 | else |
7eb63b72 | 1909 | Fsetcdr (old_alist_elt, val); |
bc93c097 | 1910 | |
7eb63b72 GM |
1911 | /* Update some other special parameters in their special places |
1912 | in addition to the alist. */ | |
1913 | ||
329ca574 RS |
1914 | if (EQ (prop, Qbuffer_predicate)) |
1915 | f->buffer_predicate = val; | |
1916 | ||
032d78fe | 1917 | if (! FRAME_WINDOW_P (f)) |
e5317d61 EZ |
1918 | { |
1919 | if (EQ (prop, Qmenu_bar_lines)) | |
1920 | set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f))); | |
1921 | else if (EQ (prop, Qname)) | |
1922 | set_term_frame_name (f, val); | |
1923 | } | |
a249de79 | 1924 | |
e35d291d | 1925 | if (EQ (prop, Qminibuffer) && WINDOWP (val)) |
bc93c097 JB |
1926 | { |
1927 | if (! MINI_WINDOW_P (XWINDOW (val))) | |
1928 | error ("Surrogate minibuffer windows must be minibuffer windows."); | |
1929 | ||
213bac8a | 1930 | if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f)) |
7af7ef38 KH |
1931 | && !EQ (val, f->minibuffer_window)) |
1932 | error ("Can't change the surrogate minibuffer of a frame with its own minibuffer"); | |
bc93c097 JB |
1933 | |
1934 | /* Install the chosen minibuffer window, with proper buffer. */ | |
ff11dfa1 | 1935 | f->minibuffer_window = val; |
bc93c097 | 1936 | } |
dc6f92b8 JB |
1937 | } |
1938 | ||
ff11dfa1 JB |
1939 | DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0, |
1940 | "Return the parameters-alist of frame FRAME.\n\ | |
dc6f92b8 | 1941 | It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\ |
dc6d9681 JB |
1942 | The meaningful PARMs depend on the kind of frame.\n\ |
1943 | If FRAME is omitted, return information on the currently selected frame.") | |
ff11dfa1 JB |
1944 | (frame) |
1945 | Lisp_Object frame; | |
dc6f92b8 JB |
1946 | { |
1947 | Lisp_Object alist; | |
f769f1b2 | 1948 | FRAME_PTR f; |
dd10ec4f | 1949 | int height, width; |
57629833 | 1950 | struct gcpro gcpro1; |
dc6f92b8 | 1951 | |
ff11dfa1 | 1952 | if (EQ (frame, Qnil)) |
8d2666fe GM |
1953 | frame = selected_frame; |
1954 | ||
1955 | CHECK_FRAME (frame, 0); | |
1956 | f = XFRAME (frame); | |
dc6f92b8 | 1957 | |
f769f1b2 | 1958 | if (!FRAME_LIVE_P (f)) |
dc6f92b8 JB |
1959 | return Qnil; |
1960 | ||
ff11dfa1 | 1961 | alist = Fcopy_alist (f->param_alist); |
57629833 GM |
1962 | GCPRO1 (alist); |
1963 | ||
2d764c78 | 1964 | if (!FRAME_WINDOW_P (f)) |
bb221971 | 1965 | { |
4aec4b29 EZ |
1966 | int fg = FRAME_FOREGROUND_PIXEL (f); |
1967 | int bg = FRAME_BACKGROUND_PIXEL (f); | |
e1d0bbc9 EZ |
1968 | Lisp_Object elt; |
1969 | ||
1970 | /* If the frame's parameter alist says the colors are | |
1971 | unspecified and reversed, take the frame's background pixel | |
1972 | for foreground and vice versa. */ | |
1973 | elt = Fassq (Qforeground_color, alist); | |
70de9f06 EZ |
1974 | if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt))) |
1975 | { | |
1976 | if (strncmp (XSTRING (XCDR (elt))->data, | |
1977 | unspecified_bg, | |
1978 | XSTRING (XCDR (elt))->size) == 0) | |
1979 | store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg)); | |
1980 | else if (strncmp (XSTRING (XCDR (elt))->data, | |
1981 | unspecified_fg, | |
1982 | XSTRING (XCDR (elt))->size) == 0) | |
1983 | store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg)); | |
1984 | } | |
e1d0bbc9 EZ |
1985 | else |
1986 | store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg)); | |
1987 | elt = Fassq (Qbackground_color, alist); | |
70de9f06 EZ |
1988 | if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt))) |
1989 | { | |
1990 | if (strncmp (XSTRING (XCDR (elt))->data, | |
1991 | unspecified_fg, | |
1992 | XSTRING (XCDR (elt))->size) == 0) | |
1993 | store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg)); | |
1994 | else if (strncmp (XSTRING (XCDR (elt))->data, | |
1995 | unspecified_bg, | |
1996 | XSTRING (XCDR (elt))->size) == 0) | |
1997 | store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg)); | |
1998 | } | |
e1d0bbc9 EZ |
1999 | else |
2000 | store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg)); | |
2d764c78 EZ |
2001 | store_in_alist (&alist, intern ("font"), |
2002 | build_string (FRAME_MSDOS_P (f) | |
2003 | ? "ms-dos" | |
4ec0d3c1 AI |
2004 | : FRAME_W32_P (f) ? "w32term" |
2005 | : FRAME_W32_CONSOLE_P (f) ? "w32console" | |
2006 | :"tty")); | |
bb221971 | 2007 | } |
fd0c2bd1 | 2008 | store_in_alist (&alist, Qname, f->name); |
dd10ec4f RS |
2009 | height = (FRAME_NEW_HEIGHT (f) ? FRAME_NEW_HEIGHT (f) : FRAME_HEIGHT (f)); |
2010 | store_in_alist (&alist, Qheight, make_number (height)); | |
2011 | width = (FRAME_NEW_WIDTH (f) ? FRAME_NEW_WIDTH (f) : FRAME_WIDTH (f)); | |
2012 | store_in_alist (&alist, Qwidth, make_number (width)); | |
f769f1b2 | 2013 | store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil)); |
fd0c2bd1 | 2014 | store_in_alist (&alist, Qminibuffer, |
39acc701 | 2015 | (! FRAME_HAS_MINIBUF_P (f) ? Qnil |
f769f1b2 KH |
2016 | : FRAME_MINIBUF_ONLY_P (f) ? Qonly |
2017 | : FRAME_MINIBUF_WINDOW (f))); | |
2018 | store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil)); | |
98ce1622 | 2019 | store_in_alist (&alist, Qbuffer_list, |
8d2666fe | 2020 | frame_buffer_list (selected_frame)); |
fd0c2bd1 | 2021 | |
dbc4e1c1 | 2022 | /* I think this should be done with a hook. */ |
032d78fe GV |
2023 | #ifdef HAVE_WINDOW_SYSTEM |
2024 | if (FRAME_WINDOW_P (f)) | |
ff11dfa1 | 2025 | x_report_frame_params (f, &alist); |
b6dd20ed | 2026 | else |
fd0c2bd1 | 2027 | #endif |
16a3738c KH |
2028 | { |
2029 | /* This ought to be correct in f->param_alist for an X frame. */ | |
2030 | Lisp_Object lines; | |
f4e93c40 | 2031 | XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f)); |
16a3738c KH |
2032 | store_in_alist (&alist, Qmenu_bar_lines, lines); |
2033 | } | |
57629833 GM |
2034 | |
2035 | UNGCPRO; | |
dc6f92b8 JB |
2036 | return alist; |
2037 | } | |
2038 | ||
8b60f7bc GM |
2039 | |
2040 | DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0, | |
2041 | "Return FRAME's value for parameter PARAMETER.\n\ | |
2042 | If FRAME is nil, describe the currently selected frame.") | |
2043 | (frame, parameter) | |
2044 | Lisp_Object frame, parameter; | |
2045 | { | |
2046 | struct frame *f; | |
2047 | Lisp_Object value; | |
2048 | ||
2049 | if (NILP (frame)) | |
2050 | frame = selected_frame; | |
2051 | else | |
2052 | CHECK_FRAME (frame, 0); | |
2053 | CHECK_SYMBOL (parameter, 1); | |
2054 | ||
2055 | f = XFRAME (frame); | |
2056 | value = Qnil; | |
2057 | ||
2058 | if (FRAME_LIVE_P (f)) | |
2059 | { | |
67d853e6 GM |
2060 | if (EQ (parameter, Qname)) |
2061 | value = f->name; | |
6345f6aa GM |
2062 | #ifdef HAVE_X_WINDOWS |
2063 | else if (EQ (parameter, Qdisplay) && FRAME_X_P (f)) | |
2064 | value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element); | |
2065 | #endif /* HAVE_X_WINDOWS */ | |
8b60f7bc | 2066 | else |
67d853e6 GM |
2067 | { |
2068 | value = Fassq (parameter, f->param_alist); | |
2069 | if (CONSP (value)) | |
5f65b39d | 2070 | { |
5f65b39d EZ |
2071 | value = XCDR (value); |
2072 | /* Fframe_parameters puts the actual fg/bg color names, | |
2073 | even if f->param_alist says otherwise. This is | |
2074 | important when param_alist's notion of colors is | |
2075 | "unspecified". We need to do the same here. */ | |
2076 | if (STRINGP (value) && !FRAME_WINDOW_P (f)) | |
2077 | { | |
e1d0bbc9 EZ |
2078 | char *color_name; |
2079 | EMACS_INT csz; | |
2080 | ||
2081 | if (EQ (parameter, Qbackground_color)) | |
2082 | { | |
2083 | color_name = XSTRING (value)->data; | |
2084 | csz = XSTRING (value)->size; | |
2085 | if (strncmp (color_name, unspecified_bg, csz) == 0) | |
2086 | value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)); | |
2087 | else if (strncmp (color_name, unspecified_fg, csz) == 0) | |
2088 | value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)); | |
2089 | } | |
2090 | else if (EQ (parameter, Qforeground_color)) | |
2091 | { | |
2092 | color_name = XSTRING (value)->data; | |
2093 | csz = XSTRING (value)->size; | |
2094 | if (strncmp (color_name, unspecified_fg, csz) == 0) | |
2095 | value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)); | |
2096 | else if (strncmp (color_name, unspecified_bg, csz) == 0) | |
2097 | value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)); | |
2098 | } | |
5f65b39d EZ |
2099 | } |
2100 | } | |
6345f6aa GM |
2101 | else if (EQ (parameter, Qdisplay_type) |
2102 | || EQ (parameter, Qbackground_mode)) | |
2103 | /* Avoid consing in frequent cases. */ | |
67d853e6 GM |
2104 | value = Qnil; |
2105 | else | |
2106 | value = Fcdr (Fassq (parameter, Fframe_parameters (frame))); | |
2107 | } | |
8b60f7bc GM |
2108 | } |
2109 | ||
2110 | return value; | |
2111 | } | |
2112 | ||
2113 | ||
ff11dfa1 JB |
2114 | DEFUN ("modify-frame-parameters", Fmodify_frame_parameters, |
2115 | Smodify_frame_parameters, 2, 2, 0, | |
2116 | "Modify the parameters of frame FRAME according to ALIST.\n\ | |
dc6f92b8 JB |
2117 | ALIST is an alist of parameters to change and their new values.\n\ |
2118 | Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\ | |
e80f3932 RS |
2119 | The meaningful PARMs depend on the kind of frame.\n\ |
2120 | Undefined PARMs are ignored, but stored in the frame's parameter list\n\ | |
7eb63b72 GM |
2121 | so that `frame-parameters' will return them.\n\ |
2122 | \n\ | |
2123 | The value of frame parameter FOO can also be accessed\n\ | |
2124 | as a frame-local binding for the variable FOO, if you have\n\ | |
2125 | enabled such bindings for that variable with `make-variable-frame-local'.") | |
ff11dfa1 JB |
2126 | (frame, alist) |
2127 | Lisp_Object frame, alist; | |
dc6f92b8 | 2128 | { |
fd0c2bd1 | 2129 | FRAME_PTR f; |
213bac8a | 2130 | register Lisp_Object tail, prop, val; |
3df1fda2 GM |
2131 | int count = BINDING_STACK_SIZE (); |
2132 | ||
2133 | /* Bind this to t to inhibit initialization of the default face from | |
2134 | X resources in face-set-after-frame-default. If we don't inhibit | |
2135 | this, modifying the `font' frame parameter, for example, while | |
2136 | there is a `default.attributeFont' X resource, won't work, | |
2137 | because `default's font is reset to the value of the X resource | |
2138 | and that resets the `font' frame parameter. */ | |
2139 | specbind (Qinhibit_default_face_x_resources, Qt); | |
dc6f92b8 | 2140 | |
ff11dfa1 | 2141 | if (EQ (frame, Qnil)) |
8d2666fe GM |
2142 | frame = selected_frame; |
2143 | CHECK_LIVE_FRAME (frame, 0); | |
2144 | f = XFRAME (frame); | |
dc6f92b8 | 2145 | |
dbc4e1c1 | 2146 | /* I think this should be done with a hook. */ |
032d78fe GV |
2147 | #ifdef HAVE_WINDOW_SYSTEM |
2148 | if (FRAME_WINDOW_P (f)) | |
fd0c2bd1 | 2149 | x_set_frame_parameters (f, alist); |
329ca574 | 2150 | else |
bb221971 RS |
2151 | #endif |
2152 | #ifdef MSDOS | |
2153 | if (FRAME_MSDOS_P (f)) | |
2154 | IT_set_frame_parameters (f, alist); | |
2155 | else | |
329ca574 | 2156 | #endif |
574a1a90 | 2157 | |
41d44f1f RS |
2158 | { |
2159 | int length = XINT (Flength (alist)); | |
2160 | int i; | |
2161 | Lisp_Object *parms | |
2162 | = (Lisp_Object *) alloca (length * sizeof (Lisp_Object)); | |
2163 | Lisp_Object *values | |
2164 | = (Lisp_Object *) alloca (length * sizeof (Lisp_Object)); | |
2165 | ||
2166 | /* Extract parm names and values into those vectors. */ | |
2167 | ||
2168 | i = 0; | |
2169 | for (tail = alist; CONSP (tail); tail = Fcdr (tail)) | |
2170 | { | |
213bac8a | 2171 | Lisp_Object elt; |
41d44f1f RS |
2172 | |
2173 | elt = Fcar (tail); | |
2174 | parms[i] = Fcar (elt); | |
2175 | values[i] = Fcdr (elt); | |
2176 | i++; | |
2177 | } | |
2178 | ||
2179 | /* Now process them in reverse of specified order. */ | |
2180 | for (i--; i >= 0; i--) | |
2181 | { | |
2182 | prop = parms[i]; | |
2183 | val = values[i]; | |
2184 | store_frame_param (f, prop, val); | |
2185 | } | |
2186 | } | |
dc6f92b8 | 2187 | |
3df1fda2 | 2188 | return unbind_to (count, Qnil); |
dc6f92b8 JB |
2189 | } |
2190 | \f | |
a26a1f95 RS |
2191 | DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height, |
2192 | 0, 1, 0, | |
2193 | "Height in pixels of a line in the font in frame FRAME.\n\ | |
2194 | If FRAME is omitted, the selected frame is used.\n\ | |
2195 | For a terminal frame, the value is always 1.") | |
ff11dfa1 JB |
2196 | (frame) |
2197 | Lisp_Object frame; | |
dc6f92b8 | 2198 | { |
a26a1f95 | 2199 | struct frame *f; |
dc6f92b8 | 2200 | |
a26a1f95 | 2201 | if (NILP (frame)) |
8d2666fe GM |
2202 | frame = selected_frame; |
2203 | CHECK_FRAME (frame, 0); | |
2204 | f = XFRAME (frame); | |
a26a1f95 | 2205 | |
032d78fe GV |
2206 | #ifdef HAVE_WINDOW_SYSTEM |
2207 | if (FRAME_WINDOW_P (f)) | |
a26a1f95 RS |
2208 | return make_number (x_char_height (f)); |
2209 | else | |
dc6d9681 | 2210 | #endif |
a26a1f95 RS |
2211 | return make_number (1); |
2212 | } | |
dc6d9681 | 2213 | |
dc6f92b8 | 2214 | |
a26a1f95 RS |
2215 | DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width, |
2216 | 0, 1, 0, | |
2217 | "Width in pixels of characters in the font in frame FRAME.\n\ | |
2218 | If FRAME is omitted, the selected frame is used.\n\ | |
2219 | The width is the same for all characters, because\n\ | |
2220 | currently Emacs supports only fixed-width fonts.\n\ | |
2221 | For a terminal screen, the value is always 1.") | |
2222 | (frame) | |
2223 | Lisp_Object frame; | |
dc6f92b8 | 2224 | { |
a26a1f95 RS |
2225 | struct frame *f; |
2226 | ||
2227 | if (NILP (frame)) | |
8d2666fe GM |
2228 | frame = selected_frame; |
2229 | CHECK_FRAME (frame, 0); | |
2230 | f = XFRAME (frame); | |
a26a1f95 | 2231 | |
032d78fe GV |
2232 | #ifdef HAVE_WINDOW_SYSTEM |
2233 | if (FRAME_WINDOW_P (f)) | |
a26a1f95 RS |
2234 | return make_number (x_char_width (f)); |
2235 | else | |
2236 | #endif | |
2237 | return make_number (1); | |
dc6f92b8 JB |
2238 | } |
2239 | ||
a26a1f95 RS |
2240 | DEFUN ("frame-pixel-height", Fframe_pixel_height, |
2241 | Sframe_pixel_height, 0, 1, 0, | |
164a14ef | 2242 | "Return a FRAME's height in pixels.\n\ |
07822795 RS |
2243 | This counts only the height available for text lines,\n\ |
2244 | not menu bars on window-system Emacs frames.\n\ | |
164a14ef | 2245 | For a terminal frame, the result really gives the height in characters.\n\ |
a26a1f95 RS |
2246 | If FRAME is omitted, the selected frame is used.") |
2247 | (frame) | |
2248 | Lisp_Object frame; | |
dc6f92b8 | 2249 | { |
a26a1f95 RS |
2250 | struct frame *f; |
2251 | ||
2252 | if (NILP (frame)) | |
8d2666fe GM |
2253 | frame = selected_frame; |
2254 | CHECK_FRAME (frame, 0); | |
2255 | f = XFRAME (frame); | |
a26a1f95 | 2256 | |
032d78fe GV |
2257 | #ifdef HAVE_WINDOW_SYSTEM |
2258 | if (FRAME_WINDOW_P (f)) | |
a26a1f95 RS |
2259 | return make_number (x_pixel_height (f)); |
2260 | else | |
dc6d9681 | 2261 | #endif |
a26a1f95 RS |
2262 | return make_number (FRAME_HEIGHT (f)); |
2263 | } | |
2264 | ||
2265 | DEFUN ("frame-pixel-width", Fframe_pixel_width, | |
2266 | Sframe_pixel_width, 0, 1, 0, | |
2267 | "Return FRAME's width in pixels.\n\ | |
164a14ef | 2268 | For a terminal frame, the result really gives the width in characters.\n\ |
a26a1f95 RS |
2269 | If FRAME is omitted, the selected frame is used.") |
2270 | (frame) | |
2271 | Lisp_Object frame; | |
2272 | { | |
2273 | struct frame *f; | |
2274 | ||
2275 | if (NILP (frame)) | |
8d2666fe GM |
2276 | frame = selected_frame; |
2277 | CHECK_FRAME (frame, 0); | |
2278 | f = XFRAME (frame); | |
dc6f92b8 | 2279 | |
032d78fe GV |
2280 | #ifdef HAVE_WINDOW_SYSTEM |
2281 | if (FRAME_WINDOW_P (f)) | |
a26a1f95 RS |
2282 | return make_number (x_pixel_width (f)); |
2283 | else | |
2284 | #endif | |
2285 | return make_number (FRAME_WIDTH (f)); | |
2286 | } | |
2287 | \f | |
ff11dfa1 JB |
2288 | DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0, |
2289 | "Specify that the frame FRAME has LINES lines.\n\ | |
dc6f92b8 | 2290 | Optional third arg non-nil means that redisplay should use LINES lines\n\ |
ff11dfa1 | 2291 | but that the idea of the actual height of the frame should not be changed.") |
735eeca3 EN |
2292 | (frame, lines, pretend) |
2293 | Lisp_Object frame, lines, pretend; | |
dc6f92b8 | 2294 | { |
ff11dfa1 | 2295 | register struct frame *f; |
dc6f92b8 | 2296 | |
735eeca3 | 2297 | CHECK_NUMBER (lines, 0); |
ff11dfa1 | 2298 | if (NILP (frame)) |
8d2666fe GM |
2299 | frame = selected_frame; |
2300 | CHECK_LIVE_FRAME (frame, 0); | |
2301 | f = XFRAME (frame); | |
dc6f92b8 | 2302 | |
dbc4e1c1 | 2303 | /* I think this should be done with a hook. */ |
032d78fe GV |
2304 | #ifdef HAVE_WINDOW_SYSTEM |
2305 | if (FRAME_WINDOW_P (f)) | |
dc6f92b8 | 2306 | { |
735eeca3 EN |
2307 | if (XINT (lines) != f->height) |
2308 | x_set_window_size (f, 1, f->width, XINT (lines)); | |
32347cf4 | 2309 | do_pending_window_change (0); |
dc6f92b8 JB |
2310 | } |
2311 | else | |
fd0c2bd1 | 2312 | #endif |
32347cf4 | 2313 | change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0); |
dc6f92b8 JB |
2314 | return Qnil; |
2315 | } | |
2316 | ||
ff11dfa1 JB |
2317 | DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0, |
2318 | "Specify that the frame FRAME has COLS columns.\n\ | |
dc6f92b8 | 2319 | Optional third arg non-nil means that redisplay should use COLS columns\n\ |
ff11dfa1 JB |
2320 | but that the idea of the actual width of the frame should not be changed.") |
2321 | (frame, cols, pretend) | |
fd0c2bd1 | 2322 | Lisp_Object frame, cols, pretend; |
dc6f92b8 | 2323 | { |
ff11dfa1 | 2324 | register struct frame *f; |
dc6f92b8 | 2325 | CHECK_NUMBER (cols, 0); |
ff11dfa1 | 2326 | if (NILP (frame)) |
8d2666fe GM |
2327 | frame = selected_frame; |
2328 | CHECK_LIVE_FRAME (frame, 0); | |
2329 | f = XFRAME (frame); | |
dc6f92b8 | 2330 | |
dbc4e1c1 | 2331 | /* I think this should be done with a hook. */ |
032d78fe GV |
2332 | #ifdef HAVE_WINDOW_SYSTEM |
2333 | if (FRAME_WINDOW_P (f)) | |
dc6f92b8 | 2334 | { |
ff11dfa1 | 2335 | if (XINT (cols) != f->width) |
808c0f20 | 2336 | x_set_window_size (f, 1, XINT (cols), f->height); |
32347cf4 | 2337 | do_pending_window_change (0); |
dc6f92b8 JB |
2338 | } |
2339 | else | |
fd0c2bd1 | 2340 | #endif |
32347cf4 | 2341 | change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0); |
dc6f92b8 JB |
2342 | return Qnil; |
2343 | } | |
2344 | ||
ff11dfa1 JB |
2345 | DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0, |
2346 | "Sets size of FRAME to COLS by ROWS, measured in characters.") | |
2347 | (frame, cols, rows) | |
2348 | Lisp_Object frame, cols, rows; | |
dc6f92b8 | 2349 | { |
ff11dfa1 | 2350 | register struct frame *f; |
dc6f92b8 | 2351 | |
ff11dfa1 | 2352 | CHECK_LIVE_FRAME (frame, 0); |
dc6f92b8 JB |
2353 | CHECK_NUMBER (cols, 2); |
2354 | CHECK_NUMBER (rows, 1); | |
ff11dfa1 | 2355 | f = XFRAME (frame); |
dc6f92b8 | 2356 | |
dbc4e1c1 | 2357 | /* I think this should be done with a hook. */ |
032d78fe GV |
2358 | #ifdef HAVE_WINDOW_SYSTEM |
2359 | if (FRAME_WINDOW_P (f)) | |
dc6f92b8 | 2360 | { |
29824ce2 RS |
2361 | if (XINT (rows) != f->height || XINT (cols) != f->width |
2362 | || FRAME_NEW_HEIGHT (f) || FRAME_NEW_WIDTH (f)) | |
808c0f20 | 2363 | x_set_window_size (f, 1, XINT (cols), XINT (rows)); |
32347cf4 | 2364 | do_pending_window_change (0); |
dc6f92b8 JB |
2365 | } |
2366 | else | |
fd0c2bd1 | 2367 | #endif |
32347cf4 | 2368 | change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0); |
dc6f92b8 JB |
2369 | |
2370 | return Qnil; | |
2371 | } | |
2372 | ||
ff11dfa1 JB |
2373 | DEFUN ("set-frame-position", Fset_frame_position, |
2374 | Sset_frame_position, 3, 3, 0, | |
2375 | "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\ | |
60bf8ee4 RS |
2376 | This is actually the position of the upper left corner of the frame.\n\ |
2377 | Negative values for XOFFSET or YOFFSET are interpreted relative to\n\ | |
4524cb1c | 2378 | the rightmost or bottommost possible position (that stays within the screen).") |
ff11dfa1 JB |
2379 | (frame, xoffset, yoffset) |
2380 | Lisp_Object frame, xoffset, yoffset; | |
dc6f92b8 | 2381 | { |
ff11dfa1 | 2382 | register struct frame *f; |
dc6f92b8 | 2383 | |
ff11dfa1 | 2384 | CHECK_LIVE_FRAME (frame, 0); |
dc6f92b8 JB |
2385 | CHECK_NUMBER (xoffset, 1); |
2386 | CHECK_NUMBER (yoffset, 2); | |
ff11dfa1 | 2387 | f = XFRAME (frame); |
dc6f92b8 | 2388 | |
dbc4e1c1 | 2389 | /* I think this should be done with a hook. */ |
032d78fe GV |
2390 | #ifdef HAVE_WINDOW_SYSTEM |
2391 | if (FRAME_WINDOW_P (f)) | |
c7c70761 | 2392 | x_set_offset (f, XINT (xoffset), XINT (yoffset), 1); |
fd0c2bd1 | 2393 | #endif |
dc6f92b8 JB |
2394 | |
2395 | return Qt; | |
2396 | } | |
dc6d9681 | 2397 | |
dc6f92b8 | 2398 | \f |
dfcf069d | 2399 | void |
ff11dfa1 | 2400 | syms_of_frame () |
dc6f92b8 | 2401 | { |
3df1fda2 GM |
2402 | Qframep = intern ("framep"); |
2403 | staticpro (&Qframep); | |
2404 | Qframe_live_p = intern ("frame-live-p"); | |
2405 | staticpro (&Qframe_live_p); | |
2406 | Qheight = intern ("height"); | |
2407 | staticpro (&Qheight); | |
2408 | Qicon = intern ("icon"); | |
2409 | staticpro (&Qicon); | |
2410 | Qminibuffer = intern ("minibuffer"); | |
2411 | staticpro (&Qminibuffer); | |
2412 | Qmodeline = intern ("modeline"); | |
2413 | staticpro (&Qmodeline); | |
2414 | Qname = intern ("name"); | |
2415 | staticpro (&Qname); | |
2416 | Qonly = intern ("only"); | |
2417 | staticpro (&Qonly); | |
2418 | Qunsplittable = intern ("unsplittable"); | |
2419 | staticpro (&Qunsplittable); | |
2420 | Qmenu_bar_lines = intern ("menu-bar-lines"); | |
2421 | staticpro (&Qmenu_bar_lines); | |
2422 | Qtool_bar_lines = intern ("tool-bar-lines"); | |
2423 | staticpro (&Qtool_bar_lines); | |
2424 | Qwidth = intern ("width"); | |
2425 | staticpro (&Qwidth); | |
2426 | Qx = intern ("x"); | |
2427 | staticpro (&Qx); | |
2428 | Qw32 = intern ("w32"); | |
2429 | staticpro (&Qw32); | |
4ec0d3c1 AI |
2430 | Qw32_console = intern ("w32-console"); |
2431 | staticpro (&Qw32_console); | |
3df1fda2 GM |
2432 | Qpc = intern ("pc"); |
2433 | staticpro (&Qpc); | |
2434 | Qmac = intern ("mac"); | |
2435 | staticpro (&Qmac); | |
2436 | Qvisible = intern ("visible"); | |
2437 | staticpro (&Qvisible); | |
2438 | Qbuffer_predicate = intern ("buffer-predicate"); | |
2439 | staticpro (&Qbuffer_predicate); | |
2440 | Qbuffer_list = intern ("buffer-list"); | |
2441 | staticpro (&Qbuffer_list); | |
2442 | Qtitle = intern ("title"); | |
2443 | staticpro (&Qtitle); | |
2444 | Qdisplay_type = intern ("display-type"); | |
2445 | staticpro (&Qdisplay_type); | |
2446 | Qbackground_mode = intern ("background-mode"); | |
2447 | staticpro (&Qbackground_mode); | |
dc6f92b8 | 2448 | |
3df1fda2 GM |
2449 | DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist, |
2450 | "Alist of default values for frame creation.\n\ | |
2451 | These may be set in your init file, like this:\n\ | |
2452 | (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))\n\ | |
2453 | These override values given in window system configuration data,\n\ | |
2454 | including X Windows' defaults database.\n\ | |
2455 | For values specific to the first Emacs frame, see `initial-frame-alist'.\n\ | |
2456 | For values specific to the separate minibuffer frame, see\n\ | |
2457 | `minibuffer-frame-alist'.\n\ | |
2458 | The `menu-bar-lines' element of the list controls whether new frames\n\ | |
2459 | have menu bars; `menu-bar-mode' works by altering this element."); | |
2460 | Vdefault_frame_alist = Qnil; | |
2461 | ||
2462 | Qinhibit_default_face_x_resources | |
2463 | = intern ("inhibit-default-face-x-resources"); | |
2464 | staticpro (&Qinhibit_default_face_x_resources); | |
dc6f92b8 | 2465 | |
ff11dfa1 JB |
2466 | DEFVAR_LISP ("terminal-frame", &Vterminal_frame, |
2467 | "The initial frame-object, which represents Emacs's stdout."); | |
dc6f92b8 JB |
2468 | |
2469 | DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified, | |
ff11dfa1 | 2470 | "Non-nil if all of emacs is iconified and frame updates are not needed."); |
dc6f92b8 JB |
2471 | Vemacs_iconified = Qnil; |
2472 | ||
beb0bc36 DL |
2473 | DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function, |
2474 | "If non-nil, function applied to the normal result of `mouse-position'.\n\ | |
2475 | This abnormal hook exists for the benefit of packages like XTerm-mouse\n\ | |
2476 | which need to do mouse handling at the Lisp level."); | |
2477 | Vmouse_position_function = Qnil; | |
2478 | ||
c60f3a6a | 2479 | DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame, |
ff11dfa1 | 2480 | "Minibufferless frames use this frame's minibuffer.\n\ |
f9898cc6 | 2481 | \n\ |
ff11dfa1 | 2482 | Emacs cannot create minibufferless frames unless this is set to an\n\ |
f9898cc6 JB |
2483 | appropriate surrogate.\n\ |
2484 | \n\ | |
2485 | Emacs consults this variable only when creating minibufferless\n\ | |
ff11dfa1 | 2486 | frames; once the frame is created, it sticks with its assigned\n\ |
f9898cc6 JB |
2487 | minibuffer, no matter what this variable is set to. This means that\n\ |
2488 | this variable doesn't necessarily say anything meaningful about the\n\ | |
ff11dfa1 | 2489 | current set of frames, or where the minibuffer is currently being\n\ |
f9898cc6 | 2490 | displayed."); |
dc6f92b8 | 2491 | |
3df1fda2 GM |
2492 | staticpro (&Vframe_list); |
2493 | ||
5add3885 | 2494 | defsubr (&Sactive_minibuffer_window); |
ff11dfa1 | 2495 | defsubr (&Sframep); |
dbc4e1c1 | 2496 | defsubr (&Sframe_live_p); |
bb1513c9 | 2497 | defsubr (&Smake_terminal_frame); |
0f85737c | 2498 | defsubr (&Shandle_switch_frame); |
1c212787 | 2499 | defsubr (&Signore_event); |
ff11dfa1 JB |
2500 | defsubr (&Sselect_frame); |
2501 | defsubr (&Sselected_frame); | |
2502 | defsubr (&Swindow_frame); | |
2503 | defsubr (&Sframe_root_window); | |
d446a856 | 2504 | defsubr (&Sframe_first_window); |
ff11dfa1 | 2505 | defsubr (&Sframe_selected_window); |
4a7cfafc | 2506 | defsubr (&Sset_frame_selected_window); |
ff11dfa1 JB |
2507 | defsubr (&Sframe_list); |
2508 | defsubr (&Snext_frame); | |
ef2c57ac | 2509 | defsubr (&Sprevious_frame); |
ff11dfa1 | 2510 | defsubr (&Sdelete_frame); |
f9898cc6 | 2511 | defsubr (&Smouse_position); |
152e6c70 | 2512 | defsubr (&Smouse_pixel_position); |
dc6f92b8 | 2513 | defsubr (&Sset_mouse_position); |
152e6c70 | 2514 | defsubr (&Sset_mouse_pixel_position); |
dc6f92b8 | 2515 | #if 0 |
ff11dfa1 JB |
2516 | defsubr (&Sframe_configuration); |
2517 | defsubr (&Srestore_frame_configuration); | |
dc6f92b8 | 2518 | #endif |
ff11dfa1 JB |
2519 | defsubr (&Smake_frame_visible); |
2520 | defsubr (&Smake_frame_invisible); | |
2521 | defsubr (&Siconify_frame); | |
2522 | defsubr (&Sframe_visible_p); | |
2523 | defsubr (&Svisible_frame_list); | |
b49f5578 JB |
2524 | defsubr (&Sraise_frame); |
2525 | defsubr (&Slower_frame); | |
ff11dfa1 JB |
2526 | defsubr (&Sredirect_frame_focus); |
2527 | defsubr (&Sframe_focus); | |
2528 | defsubr (&Sframe_parameters); | |
8b60f7bc | 2529 | defsubr (&Sframe_parameter); |
ff11dfa1 | 2530 | defsubr (&Smodify_frame_parameters); |
a26a1f95 RS |
2531 | defsubr (&Sframe_char_height); |
2532 | defsubr (&Sframe_char_width); | |
2533 | defsubr (&Sframe_pixel_height); | |
2534 | defsubr (&Sframe_pixel_width); | |
ff11dfa1 JB |
2535 | defsubr (&Sset_frame_height); |
2536 | defsubr (&Sset_frame_width); | |
2537 | defsubr (&Sset_frame_size); | |
2538 | defsubr (&Sset_frame_position); | |
dc6f92b8 | 2539 | } |
e5d77022 | 2540 | |
dfcf069d | 2541 | void |
2f0b07e0 JB |
2542 | keys_of_frame () |
2543 | { | |
0f85737c | 2544 | initial_define_lispy_key (global_map, "switch-frame", "handle-switch-frame"); |
d134b17b | 2545 | initial_define_lispy_key (global_map, "delete-frame", "handle-delete-frame"); |
1c212787 KH |
2546 | initial_define_lispy_key (global_map, "iconify-frame", "ignore-event"); |
2547 | initial_define_lispy_key (global_map, "make-frame-visible", "ignore-event"); | |
2f0b07e0 | 2548 | } |