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