]> code.delx.au - gnu-emacs/blob - src/frame.c
* menu.h: New file.
[gnu-emacs] / src / frame.c
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) 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. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include <config.h>
21
22 #include <stdio.h>
23 #include <ctype.h>
24 #include "lisp.h"
25 #include "character.h"
26 #ifdef HAVE_X_WINDOWS
27 #include "xterm.h"
28 #endif
29 #ifdef WINDOWSNT
30 #include "w32term.h"
31 #endif
32 #ifdef MAC_OS
33 #include "macterm.h"
34 #endif
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #ifdef HAVE_WINDOW_SYSTEM
46 #include "font.h"
47 #include "fontset.h"
48 #endif
49 #ifdef MSDOS
50 #include "msdos.h"
51 #include "dosfns.h"
52 #endif
53
54
55 #ifdef HAVE_WINDOW_SYSTEM
56
57 /* The name we're using in resource queries. Most often "emacs". */
58
59 Lisp_Object Vx_resource_name;
60
61 /* The application class we're using in resource queries.
62 Normally "Emacs". */
63
64 Lisp_Object Vx_resource_class;
65
66 /* Lower limit value of the frame opacity (alpha transparency). */
67
68 Lisp_Object Vframe_alpha_lower_limit;
69
70 #endif
71
72 Lisp_Object Qframep, Qframe_live_p;
73 Lisp_Object Qicon, Qmodeline;
74 Lisp_Object Qonly;
75 Lisp_Object Qx, Qw32, Qmac, Qpc;
76 Lisp_Object Qvisible;
77 Lisp_Object Qdisplay_type;
78 Lisp_Object Qbackground_mode;
79 Lisp_Object Qnoelisp;
80
81 Lisp_Object Qx_frame_parameter;
82 Lisp_Object Qx_resource_name;
83 Lisp_Object Qterminal;
84 Lisp_Object Qterminal_live_p;
85
86 /* Frame parameters (set or reported). */
87
88 Lisp_Object Qauto_raise, Qauto_lower;
89 Lisp_Object Qborder_color, Qborder_width;
90 Lisp_Object Qcursor_color, Qcursor_type;
91 Lisp_Object Qgeometry; /* Not used */
92 Lisp_Object Qheight, Qwidth;
93 Lisp_Object Qleft, Qright;
94 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
95 Lisp_Object Qinternal_border_width;
96 Lisp_Object Qmouse_color;
97 Lisp_Object Qminibuffer;
98 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
99 Lisp_Object Qvisibility;
100 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
101 Lisp_Object Qscreen_gamma;
102 Lisp_Object Qline_spacing;
103 Lisp_Object Quser_position, Quser_size;
104 Lisp_Object Qwait_for_wm;
105 Lisp_Object Qwindow_id;
106 #ifdef HAVE_X_WINDOWS
107 Lisp_Object Qouter_window_id;
108 #endif
109 Lisp_Object Qparent_id;
110 Lisp_Object Qtitle, Qname;
111 Lisp_Object Qexplicit_name;
112 Lisp_Object Qunsplittable;
113 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
114 Lisp_Object Qleft_fringe, Qright_fringe;
115 Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
116 Lisp_Object Qtty_color_mode;
117 Lisp_Object Qtty, Qtty_type;
118
119 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
120 Lisp_Object Qfont_backend;
121 Lisp_Object Qalpha;
122
123 Lisp_Object Qface_set_after_frame_default;
124
125 Lisp_Object Vterminal_frame;
126 Lisp_Object Vdefault_frame_alist;
127 Lisp_Object Vdefault_frame_scroll_bars;
128 Lisp_Object Vmouse_position_function;
129 Lisp_Object Vmouse_highlight;
130 static Lisp_Object Vdelete_frame_functions, Qdelete_frame_functions;
131
132 int focus_follows_mouse;
133 \f
134 static void
135 set_menu_bar_lines_1 (window, n)
136 Lisp_Object window;
137 int n;
138 {
139 struct window *w = XWINDOW (window);
140
141 XSETFASTINT (w->last_modified, 0);
142 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
143 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
144
145 if (INTEGERP (w->orig_top_line))
146 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
147 if (INTEGERP (w->orig_total_lines))
148 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
149
150 /* Handle just the top child in a vertical split. */
151 if (!NILP (w->vchild))
152 set_menu_bar_lines_1 (w->vchild, n);
153
154 /* Adjust all children in a horizontal split. */
155 for (window = w->hchild; !NILP (window); window = w->next)
156 {
157 w = XWINDOW (window);
158 set_menu_bar_lines_1 (window, n);
159 }
160 }
161
162 void
163 set_menu_bar_lines (f, value, oldval)
164 struct frame *f;
165 Lisp_Object value, oldval;
166 {
167 int nlines;
168 int olines = FRAME_MENU_BAR_LINES (f);
169
170 /* Right now, menu bars don't work properly in minibuf-only frames;
171 most of the commands try to apply themselves to the minibuffer
172 frame itself, and get an error because you can't switch buffers
173 in or split the minibuffer window. */
174 if (FRAME_MINIBUF_ONLY_P (f))
175 return;
176
177 if (INTEGERP (value))
178 nlines = XINT (value);
179 else
180 nlines = 0;
181
182 if (nlines != olines)
183 {
184 windows_or_buffers_changed++;
185 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
186 FRAME_MENU_BAR_LINES (f) = nlines;
187 set_menu_bar_lines_1 (f->root_window, nlines - olines);
188 adjust_glyphs (f);
189 }
190 }
191 \f
192 Lisp_Object Vemacs_iconified;
193 Lisp_Object Vframe_list;
194
195 extern Lisp_Object Vminibuffer_list;
196 extern Lisp_Object get_minibuffer ();
197 extern Lisp_Object Fhandle_switch_frame ();
198 extern Lisp_Object Fredirect_frame_focus ();
199 extern Lisp_Object x_get_focus_frame ();
200 \f
201 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
202 doc: /* Return non-nil if OBJECT is a frame.
203 Value is t for a termcap frame (a character-only terminal),
204 `x' for an Emacs frame that is really an X window,
205 `w32' for an Emacs frame that is a window on MS-Windows display,
206 `mac' for an Emacs frame on a Macintosh display,
207 `pc' for a direct-write MS-DOS frame.
208 See also `frame-live-p'. */)
209 (object)
210 Lisp_Object object;
211 {
212 if (!FRAMEP (object))
213 return Qnil;
214 switch (XFRAME (object)->output_method)
215 {
216 case output_initial: /* The initial frame is like a termcap frame. */
217 case output_termcap:
218 return Qt;
219 case output_x_window:
220 return Qx;
221 case output_w32:
222 return Qw32;
223 case output_msdos_raw:
224 return Qpc;
225 case output_mac:
226 return Qmac;
227 default:
228 abort ();
229 }
230 }
231
232 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
233 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
234 Value is nil if OBJECT is not a live frame. If object is a live
235 frame, the return value indicates what sort of terminal device it is
236 displayed on. See the documentation of `framep' for possible
237 return values. */)
238 (object)
239 Lisp_Object object;
240 {
241 return ((FRAMEP (object)
242 && FRAME_LIVE_P (XFRAME (object)))
243 ? Fframep (object)
244 : Qnil);
245 }
246
247 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
248 doc: /* The name of the window system that FRAME is displaying through.
249 The value is a symbol---for instance, 'x' for X windows.
250 The value is nil if Emacs is using a text-only terminal.
251
252 FRAME defaults to the currently selected frame. */)
253 (frame)
254 Lisp_Object frame;
255 {
256 Lisp_Object type;
257 if (NILP (frame))
258 frame = selected_frame;
259
260 type = Fframep (frame);
261
262 if (NILP (type))
263 wrong_type_argument (Qframep, frame);
264
265 if (EQ (type, Qt))
266 return Qnil;
267 else
268 return type;
269 }
270
271 struct frame *
272 make_frame (mini_p)
273 int mini_p;
274 {
275 Lisp_Object frame;
276 register struct frame *f;
277 register Lisp_Object root_window;
278 register Lisp_Object mini_window;
279
280 f = allocate_frame ();
281 XSETFRAME (frame, f);
282
283 f->desired_matrix = 0;
284 f->current_matrix = 0;
285 f->desired_pool = 0;
286 f->current_pool = 0;
287 f->glyphs_initialized_p = 0;
288 f->decode_mode_spec_buffer = 0;
289 f->visible = 0;
290 f->async_visible = 0;
291 f->output_data.nothing = 0;
292 f->iconified = 0;
293 f->async_iconified = 0;
294 f->wants_modeline = 1;
295 f->auto_raise = 0;
296 f->auto_lower = 0;
297 f->no_split = 0;
298 f->garbaged = 1;
299 f->has_minibuffer = mini_p;
300 f->focus_frame = Qnil;
301 f->explicit_name = 0;
302 f->can_have_scroll_bars = 0;
303 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
304 f->param_alist = Qnil;
305 f->scroll_bars = Qnil;
306 f->condemned_scroll_bars = Qnil;
307 f->face_alist = Qnil;
308 f->face_cache = NULL;
309 f->menu_bar_items = Qnil;
310 f->menu_bar_vector = Qnil;
311 f->menu_bar_items_used = 0;
312 f->buffer_predicate = Qnil;
313 f->buffer_list = Qnil;
314 f->buried_buffer_list = Qnil;
315 f->namebuf = 0;
316 f->title = Qnil;
317 f->menu_bar_window = Qnil;
318 f->tool_bar_window = Qnil;
319 f->tool_bar_items = Qnil;
320 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
321 f->n_tool_bar_items = 0;
322 f->left_fringe_width = f->right_fringe_width = 0;
323 f->fringe_cols = 0;
324 f->scroll_bar_actual_width = 0;
325 f->border_width = 0;
326 f->internal_border_width = 0;
327 f->column_width = 1; /* !FRAME_WINDOW_P value */
328 f->line_height = 1; /* !FRAME_WINDOW_P value */
329 f->x_pixels_diff = f->y_pixels_diff = 0;
330 #ifdef HAVE_WINDOW_SYSTEM
331 f->want_fullscreen = FULLSCREEN_NONE;
332 #endif
333 f->size_hint_flags = 0;
334 f->win_gravity = 0;
335 f->font_driver_list = NULL;
336 f->font_data_list = NULL;
337
338 root_window = make_window ();
339 if (mini_p)
340 {
341 mini_window = make_window ();
342 XWINDOW (root_window)->next = mini_window;
343 XWINDOW (mini_window)->prev = root_window;
344 XWINDOW (mini_window)->mini_p = Qt;
345 XWINDOW (mini_window)->frame = frame;
346 f->minibuffer_window = mini_window;
347 }
348 else
349 {
350 mini_window = Qnil;
351 XWINDOW (root_window)->next = Qnil;
352 f->minibuffer_window = Qnil;
353 }
354
355 XWINDOW (root_window)->frame = frame;
356
357 /* 10 is arbitrary,
358 just so that there is "something there."
359 Correct size will be set up later with change_frame_size. */
360
361 SET_FRAME_COLS (f, 10);
362 FRAME_LINES (f) = 10;
363
364 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
365 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
366
367 if (mini_p)
368 {
369 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
370 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
371 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
372 }
373
374 /* Choose a buffer for the frame's root window. */
375 {
376 Lisp_Object buf;
377
378 XWINDOW (root_window)->buffer = Qt;
379 buf = Fcurrent_buffer ();
380 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
381 a space), try to find another one. */
382 if (SREF (Fbuffer_name (buf), 0) == ' ')
383 buf = Fother_buffer (buf, Qnil, Qnil);
384
385 /* Use set_window_buffer, not Fset_window_buffer, and don't let
386 hooks be run by it. The reason is that the whole frame/window
387 arrangement is not yet fully intialized at this point. Windows
388 don't have the right size, glyph matrices aren't initialized
389 etc. Running Lisp functions at this point surely ends in a
390 SEGV. */
391 set_window_buffer (root_window, buf, 0, 0);
392 f->buffer_list = Fcons (buf, Qnil);
393 }
394
395 if (mini_p)
396 {
397 XWINDOW (mini_window)->buffer = Qt;
398 set_window_buffer (mini_window,
399 (NILP (Vminibuffer_list)
400 ? get_minibuffer (0)
401 : Fcar (Vminibuffer_list)),
402 0, 0);
403 }
404
405 f->root_window = root_window;
406 f->selected_window = root_window;
407 /* Make sure this window seems more recently used than
408 a newly-created, never-selected window. */
409 ++window_select_count;
410 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
411
412 f->default_face_done_p = 0;
413
414 return f;
415 }
416 \f
417 #ifdef HAVE_WINDOW_SYSTEM
418 /* Make a frame using a separate minibuffer window on another frame.
419 MINI_WINDOW is the minibuffer window to use. nil means use the
420 default (the global minibuffer). */
421
422 struct frame *
423 make_frame_without_minibuffer (mini_window, kb, display)
424 register Lisp_Object mini_window;
425 KBOARD *kb;
426 Lisp_Object display;
427 {
428 register struct frame *f;
429 struct gcpro gcpro1;
430
431 if (!NILP (mini_window))
432 CHECK_LIVE_WINDOW (mini_window);
433
434 #ifdef MULTI_KBOARD
435 if (!NILP (mini_window)
436 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
437 error ("Frame and minibuffer must be on the same terminal");
438 #endif
439
440 /* Make a frame containing just a root window. */
441 f = make_frame (0);
442
443 if (NILP (mini_window))
444 {
445 /* Use default-minibuffer-frame if possible. */
446 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
447 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
448 {
449 Lisp_Object frame_dummy;
450
451 XSETFRAME (frame_dummy, f);
452 GCPRO1 (frame_dummy);
453 /* If there's no minibuffer frame to use, create one. */
454 kb->Vdefault_minibuffer_frame =
455 call1 (intern ("make-initial-minibuffer-frame"), display);
456 UNGCPRO;
457 }
458
459 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
460 }
461
462 f->minibuffer_window = mini_window;
463
464 /* Make the chosen minibuffer window display the proper minibuffer,
465 unless it is already showing a minibuffer. */
466 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
467 Fset_window_buffer (mini_window,
468 (NILP (Vminibuffer_list)
469 ? get_minibuffer (0)
470 : Fcar (Vminibuffer_list)), Qnil);
471 return f;
472 }
473
474 /* Make a frame containing only a minibuffer window. */
475
476 struct frame *
477 make_minibuffer_frame ()
478 {
479 /* First make a frame containing just a root window, no minibuffer. */
480
481 register struct frame *f = make_frame (0);
482 register Lisp_Object mini_window;
483 register Lisp_Object frame;
484
485 XSETFRAME (frame, f);
486
487 f->auto_raise = 0;
488 f->auto_lower = 0;
489 f->no_split = 1;
490 f->wants_modeline = 0;
491 f->has_minibuffer = 1;
492
493 /* Now label the root window as also being the minibuffer.
494 Avoid infinite looping on the window chain by marking next pointer
495 as nil. */
496
497 mini_window = f->minibuffer_window = f->root_window;
498 XWINDOW (mini_window)->mini_p = Qt;
499 XWINDOW (mini_window)->next = Qnil;
500 XWINDOW (mini_window)->prev = Qnil;
501 XWINDOW (mini_window)->frame = frame;
502
503 /* Put the proper buffer in that window. */
504
505 Fset_window_buffer (mini_window,
506 (NILP (Vminibuffer_list)
507 ? get_minibuffer (0)
508 : Fcar (Vminibuffer_list)), Qnil);
509 return f;
510 }
511 #endif /* HAVE_WINDOW_SYSTEM */
512 \f
513 /* Construct a frame that refers to a terminal. */
514
515 static int tty_frame_count;
516
517 struct frame *
518 make_initial_frame (void)
519 {
520 struct frame *f;
521 struct terminal *terminal;
522 Lisp_Object frame;
523
524 eassert (initial_kboard);
525
526 /* The first call must initialize Vframe_list. */
527 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
528 Vframe_list = Qnil;
529
530 terminal = init_initial_terminal ();
531
532 f = make_frame (1);
533 XSETFRAME (frame, f);
534
535 Vframe_list = Fcons (frame, Vframe_list);
536
537 tty_frame_count = 1;
538 f->name = build_string ("F1");
539
540 f->visible = 1;
541 f->async_visible = 1;
542
543 f->output_method = terminal->type;
544 f->terminal = terminal;
545 f->terminal->reference_count++;
546 f->output_data.nothing = 0;
547
548 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
550
551 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
552 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
553
554 return f;
555 }
556
557
558 struct frame *
559 make_terminal_frame (struct terminal *terminal)
560 {
561 register struct frame *f;
562 Lisp_Object frame;
563 char name[20];
564
565 if (!terminal->name)
566 error ("Terminal is not live, can't create new frames on it");
567
568 f = make_frame (1);
569
570 XSETFRAME (frame, f);
571 Vframe_list = Fcons (frame, Vframe_list);
572
573 tty_frame_count++;
574 sprintf (name, "F%d", tty_frame_count);
575 f->name = build_string (name);
576
577 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
578 f->async_visible = 1; /* Don't let visible be cleared later. */
579 #ifdef MSDOS
580 f->output_data.x = &the_only_x_display;
581 if (!inhibit_window_system
582 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
583 || XFRAME (selected_frame)->output_method == output_msdos_raw))
584 {
585 f->output_method = output_msdos_raw;
586 /* This initialization of foreground and background pixels is
587 only important for the initial frame created in temacs. If
588 we don't do that, we get black background and foreground in
589 the dumped Emacs because the_only_x_display is a static
590 variable, hence it is born all-zeroes, and zero is the code
591 for the black color. Other frames all inherit their pixels
592 from what's already in the_only_x_display. */
593 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
594 && FRAME_BACKGROUND_PIXEL (f) == 0
595 && FRAME_FOREGROUND_PIXEL (f) == 0)
596 {
597 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
598 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
599 }
600 }
601 else
602 f->output_method = output_termcap;
603 #else
604 {
605 f->output_method = output_termcap;
606 f->terminal = terminal;
607 f->terminal->reference_count++;
608 create_tty_output (f);
609
610 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
611 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
612
613 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
614 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
615
616 /* Set the top frame to the newly created frame. */
617 if (FRAMEP (FRAME_TTY (f)->top_frame)
618 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
619 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
620
621 FRAME_TTY (f)->top_frame = frame;
622 }
623
624 #ifdef CANNOT_DUMP
625 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
626 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
627 #endif
628 #endif /* MSDOS */
629
630 if (!noninteractive)
631 init_frame_faces (f);
632
633 return f;
634 }
635
636 /* Get a suitable value for frame parameter PARAMETER for a newly
637 created frame, based on (1) the user-supplied frame parameter
638 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
639 fails, (3) Vdefault_frame_alist. */
640
641 static Lisp_Object
642 get_future_frame_param (Lisp_Object parameter,
643 Lisp_Object supplied_parms,
644 char *current_value)
645 {
646 Lisp_Object result;
647
648 result = Fassq (parameter, supplied_parms);
649 if (NILP (result))
650 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
651 if (NILP (result) && current_value != NULL)
652 result = build_string (current_value);
653 if (NILP (result))
654 result = Fassq (parameter, Vdefault_frame_alist);
655 if (!NILP (result) && !STRINGP (result))
656 result = XCDR (result);
657 if (NILP (result) || !STRINGP (result))
658 result = Qnil;
659
660 return result;
661 }
662
663 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
664 1, 1, 0,
665 doc: /* Create an additional terminal frame, possibly on another terminal.
666 This function takes one argument, an alist specifying frame parameters.
667
668 You can create multiple frames on a single text-only terminal, but
669 only one of them (the selected terminal frame) is actually displayed.
670
671 In practice, generally you don't need to specify any parameters,
672 except when you want to create a new frame on another terminal.
673 In that case, the `tty' parameter specifies the device file to open,
674 and the `tty-type' parameter specifies the terminal type. Example:
675
676 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
677
678 Note that changing the size of one terminal frame automatically
679 affects all frames on the same terminal device. */)
680 (parms)
681 Lisp_Object parms;
682 {
683 struct frame *f;
684 struct terminal *t = NULL;
685 Lisp_Object frame, tem;
686 struct frame *sf = SELECTED_FRAME ();
687
688 #ifdef MSDOS
689 if (sf->output_method != output_msdos_raw
690 && sf->output_method != output_termcap)
691 abort ();
692 #else /* not MSDOS */
693
694 #if 0
695 /* This can happen for multi-tty when using both terminal frames and
696 Carbon frames. */
697 if (sf->output_method != output_mac)
698 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
699 #else
700 #if 0 /* This should work now! */
701 if (sf->output_method != output_termcap)
702 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
703 #endif
704 #endif
705 #endif /* not MSDOS */
706
707 {
708 Lisp_Object terminal;
709
710 terminal = Fassq (Qterminal, parms);
711 if (!NILP (terminal))
712 {
713 terminal = XCDR (terminal);
714 t = get_terminal (terminal, 1);
715 }
716 }
717
718 if (!t)
719 {
720 char *name = 0, *type = 0;
721 Lisp_Object tty, tty_type;
722
723 tty = get_future_frame_param
724 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
725 ? FRAME_TTY (XFRAME (selected_frame))->name
726 : NULL));
727 if (!NILP (tty))
728 {
729 name = (char *) alloca (SBYTES (tty) + 1);
730 strncpy (name, SDATA (tty), SBYTES (tty));
731 name[SBYTES (tty)] = 0;
732 }
733
734 tty_type = get_future_frame_param
735 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
736 ? FRAME_TTY (XFRAME (selected_frame))->type
737 : NULL));
738 if (!NILP (tty_type))
739 {
740 type = (char *) alloca (SBYTES (tty_type) + 1);
741 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
742 type[SBYTES (tty_type)] = 0;
743 }
744
745 t = init_tty (name, type, 0); /* Errors are not fatal. */
746 }
747
748 f = make_terminal_frame (t);
749
750 {
751 int width, height;
752 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
753 change_frame_size (f, height, width, 0, 0, 0);
754 }
755
756 adjust_glyphs (f);
757 calculate_costs (f);
758 XSETFRAME (frame, f);
759 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
760 Fmodify_frame_parameters (frame, parms);
761 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
762 build_string (t->display_info.tty->type)),
763 Qnil));
764 if (t->display_info.tty->name != NULL)
765 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
766 build_string (t->display_info.tty->name)),
767 Qnil));
768 else
769 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
770
771 /* Make the frame face alist be frame-specific, so that each
772 frame could change its face definitions independently. */
773 f->face_alist = Fcopy_alist (sf->face_alist);
774 /* Simple Fcopy_alist isn't enough, because we need the contents of
775 the vectors which are the CDRs of associations in face_alist to
776 be copied as well. */
777 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
778 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
779 return frame;
780 }
781
782 \f
783 /* Perform the switch to frame FRAME.
784
785 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
786 FRAME1 as frame.
787
788 If TRACK is non-zero and the frame that currently has the focus
789 redirects its focus to the selected frame, redirect that focused
790 frame's focus to FRAME instead.
791
792 FOR_DELETION non-zero means that the selected frame is being
793 deleted, which includes the possibility that the frame's terminal
794 is dead. */
795
796 Lisp_Object
797 do_switch_frame (frame, track, for_deletion)
798 Lisp_Object frame;
799 int track, for_deletion;
800 {
801 struct frame *sf = SELECTED_FRAME ();
802
803 /* If FRAME is a switch-frame event, extract the frame we should
804 switch to. */
805 if (CONSP (frame)
806 && EQ (XCAR (frame), Qswitch_frame)
807 && CONSP (XCDR (frame)))
808 frame = XCAR (XCDR (frame));
809
810 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
811 a switch-frame event to arrive after a frame is no longer live,
812 especially when deleting the initial frame during startup. */
813 CHECK_FRAME (frame);
814 if (! FRAME_LIVE_P (XFRAME (frame)))
815 return Qnil;
816
817 if (sf == XFRAME (frame))
818 return frame;
819
820 /* This is too greedy; it causes inappropriate focus redirection
821 that's hard to get rid of. */
822 #if 0
823 /* If a frame's focus has been redirected toward the currently
824 selected frame, we should change the redirection to point to the
825 newly selected frame. This means that if the focus is redirected
826 from a minibufferless frame to a surrogate minibuffer frame, we
827 can use `other-window' to switch between all the frames using
828 that minibuffer frame, and the focus redirection will follow us
829 around. */
830 if (track)
831 {
832 Lisp_Object tail;
833
834 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
835 {
836 Lisp_Object focus;
837
838 if (!FRAMEP (XCAR (tail)))
839 abort ();
840
841 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
842
843 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
844 Fredirect_frame_focus (XCAR (tail), frame);
845 }
846 }
847 #else /* ! 0 */
848 /* Instead, apply it only to the frame we're pointing to. */
849 #ifdef HAVE_WINDOW_SYSTEM
850 if (track && FRAME_WINDOW_P (XFRAME (frame)))
851 {
852 Lisp_Object focus, xfocus;
853
854 xfocus = x_get_focus_frame (XFRAME (frame));
855 if (FRAMEP (xfocus))
856 {
857 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
858 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
859 Fredirect_frame_focus (xfocus, frame);
860 }
861 }
862 #endif /* HAVE_X_WINDOWS */
863 #endif /* ! 0 */
864
865 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
866 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
867
868 if (FRAME_TERMCAP_P (XFRAME (frame)))
869 {
870 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
871 /* Mark previously displayed frame as now obscured. */
872 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
873 XFRAME (frame)->async_visible = 1;
874 FRAME_TTY (XFRAME (frame))->top_frame = frame;
875 }
876
877 selected_frame = frame;
878 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
879 last_nonminibuf_frame = XFRAME (selected_frame);
880
881 Fselect_window (XFRAME (frame)->selected_window, Qnil);
882
883 /* We want to make sure that the next event generates a frame-switch
884 event to the appropriate frame. This seems kludgy to me, but
885 before you take it out, make sure that evaluating something like
886 (select-window (frame-root-window (new-frame))) doesn't end up
887 with your typing being interpreted in the new frame instead of
888 the one you're actually typing in. */
889 internal_last_event_frame = Qnil;
890
891 return frame;
892 }
893
894 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
895 doc: /* Select the frame FRAME.
896 Subsequent editing commands apply to its selected window.
897 The selection of FRAME lasts until the next time the user does
898 something to select a different frame, or until the next time this
899 function is called. If you are using a window system, the previously
900 selected frame may be restored as the selected frame after return to
901 the command loop, because it still may have the window system's input
902 focus. On a text-only terminal, the next redisplay will display FRAME.
903
904 This function returns FRAME, or nil if FRAME has been deleted. */)
905 (frame)
906 Lisp_Object frame;
907 {
908 return do_switch_frame (frame, 1, 0);
909 }
910
911
912 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
913 doc: /* Handle a switch-frame event EVENT.
914 Switch-frame events are usually bound to this function.
915 A switch-frame event tells Emacs that the window manager has requested
916 that the user's events be directed to the frame mentioned in the event.
917 This function selects the selected window of the frame of EVENT.
918
919 If EVENT is frame object, handle it as if it were a switch-frame event
920 to that frame. */)
921 (event)
922 Lisp_Object event;
923 {
924 /* Preserve prefix arg that the command loop just cleared. */
925 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
926 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
927 return do_switch_frame (event, 0, 0);
928 }
929
930 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
931 doc: /* Return the frame that is now selected. */)
932 ()
933 {
934 return selected_frame;
935 }
936 \f
937 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
938 doc: /* Return the frame object that window WINDOW is on. */)
939 (window)
940 Lisp_Object window;
941 {
942 CHECK_LIVE_WINDOW (window);
943 return XWINDOW (window)->frame;
944 }
945
946 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
947 doc: /* Returns the topmost, leftmost window of FRAME.
948 If omitted, FRAME defaults to the currently selected frame. */)
949 (frame)
950 Lisp_Object frame;
951 {
952 Lisp_Object w;
953
954 if (NILP (frame))
955 w = SELECTED_FRAME ()->root_window;
956 else
957 {
958 CHECK_LIVE_FRAME (frame);
959 w = XFRAME (frame)->root_window;
960 }
961 while (NILP (XWINDOW (w)->buffer))
962 {
963 if (! NILP (XWINDOW (w)->hchild))
964 w = XWINDOW (w)->hchild;
965 else if (! NILP (XWINDOW (w)->vchild))
966 w = XWINDOW (w)->vchild;
967 else
968 abort ();
969 }
970 return w;
971 }
972
973 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
974 Sactive_minibuffer_window, 0, 0, 0,
975 doc: /* Return the currently active minibuffer window, or nil if none. */)
976 ()
977 {
978 return minibuf_level ? minibuf_window : Qnil;
979 }
980
981 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
982 doc: /* Returns the root-window of FRAME.
983 If omitted, FRAME defaults to the currently selected frame. */)
984 (frame)
985 Lisp_Object frame;
986 {
987 Lisp_Object window;
988
989 if (NILP (frame))
990 window = SELECTED_FRAME ()->root_window;
991 else
992 {
993 CHECK_LIVE_FRAME (frame);
994 window = XFRAME (frame)->root_window;
995 }
996
997 return window;
998 }
999
1000 DEFUN ("frame-selected-window", Fframe_selected_window,
1001 Sframe_selected_window, 0, 1, 0,
1002 doc: /* Return the selected window of frame object FRAME.
1003 If omitted, FRAME defaults to the currently selected frame. */)
1004 (frame)
1005 Lisp_Object frame;
1006 {
1007 Lisp_Object window;
1008
1009 if (NILP (frame))
1010 window = SELECTED_FRAME ()->selected_window;
1011 else
1012 {
1013 CHECK_LIVE_FRAME (frame);
1014 window = XFRAME (frame)->selected_window;
1015 }
1016
1017 return window;
1018 }
1019
1020 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1021 Sset_frame_selected_window, 2, 2, 0,
1022 doc: /* Set the selected window of frame object FRAME to WINDOW.
1023 Return WINDOW.
1024 If FRAME is nil, the selected frame is used.
1025 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1026 (frame, window)
1027 Lisp_Object frame, window;
1028 {
1029 if (NILP (frame))
1030 frame = selected_frame;
1031
1032 CHECK_LIVE_FRAME (frame);
1033 CHECK_LIVE_WINDOW (window);
1034
1035 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1036 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1037
1038 if (EQ (frame, selected_frame))
1039 return Fselect_window (window, Qnil);
1040
1041 return XFRAME (frame)->selected_window = window;
1042 }
1043
1044 \f
1045 DEFUN ("frame-list", Fframe_list, Sframe_list,
1046 0, 0, 0,
1047 doc: /* Return a list of all frames. */)
1048 ()
1049 {
1050 Lisp_Object frames;
1051 frames = Fcopy_sequence (Vframe_list);
1052 #ifdef HAVE_WINDOW_SYSTEM
1053 if (FRAMEP (tip_frame))
1054 frames = Fdelq (tip_frame, frames);
1055 #endif
1056 return frames;
1057 }
1058
1059 /* Return the next frame in the frame list after FRAME.
1060 If MINIBUF is nil, exclude minibuffer-only frames.
1061 If MINIBUF is a window, include only its own frame
1062 and any frame now using that window as the minibuffer.
1063 If MINIBUF is `visible', include all visible frames.
1064 If MINIBUF is 0, include all visible and iconified frames.
1065 Otherwise, include all frames. */
1066
1067 static Lisp_Object
1068 next_frame (frame, minibuf)
1069 Lisp_Object frame;
1070 Lisp_Object minibuf;
1071 {
1072 Lisp_Object tail;
1073 int passed = 0;
1074
1075 /* There must always be at least one frame in Vframe_list. */
1076 if (! CONSP (Vframe_list))
1077 abort ();
1078
1079 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1080 forever. Forestall that. */
1081 CHECK_LIVE_FRAME (frame);
1082
1083 while (1)
1084 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1085 {
1086 Lisp_Object f;
1087
1088 f = XCAR (tail);
1089
1090 if (passed
1091 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1092 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1093 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1094 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1095 {
1096 /* Decide whether this frame is eligible to be returned. */
1097
1098 /* If we've looped all the way around without finding any
1099 eligible frames, return the original frame. */
1100 if (EQ (f, frame))
1101 return f;
1102
1103 /* Let minibuf decide if this frame is acceptable. */
1104 if (NILP (minibuf))
1105 {
1106 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1107 return f;
1108 }
1109 else if (EQ (minibuf, Qvisible))
1110 {
1111 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1112 if (FRAME_VISIBLE_P (XFRAME (f)))
1113 return f;
1114 }
1115 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1116 {
1117 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1118 if (FRAME_VISIBLE_P (XFRAME (f))
1119 || FRAME_ICONIFIED_P (XFRAME (f)))
1120 return f;
1121 }
1122 else if (WINDOWP (minibuf))
1123 {
1124 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1125 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1126 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1127 FRAME_FOCUS_FRAME (XFRAME (f))))
1128 return f;
1129 }
1130 else
1131 return f;
1132 }
1133
1134 if (EQ (frame, f))
1135 passed++;
1136 }
1137 }
1138
1139 /* Return the previous frame in the frame list before FRAME.
1140 If MINIBUF is nil, exclude minibuffer-only frames.
1141 If MINIBUF is a window, include only its own frame
1142 and any frame now using that window as the minibuffer.
1143 If MINIBUF is `visible', include all visible frames.
1144 If MINIBUF is 0, include all visible and iconified frames.
1145 Otherwise, include all frames. */
1146
1147 static Lisp_Object
1148 prev_frame (frame, minibuf)
1149 Lisp_Object frame;
1150 Lisp_Object minibuf;
1151 {
1152 Lisp_Object tail;
1153 Lisp_Object prev;
1154
1155 /* There must always be at least one frame in Vframe_list. */
1156 if (! CONSP (Vframe_list))
1157 abort ();
1158
1159 prev = Qnil;
1160 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1161 {
1162 Lisp_Object f;
1163
1164 f = XCAR (tail);
1165 if (!FRAMEP (f))
1166 abort ();
1167
1168 if (EQ (frame, f) && !NILP (prev))
1169 return prev;
1170
1171 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1172 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1173 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1174 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1175 {
1176 /* Decide whether this frame is eligible to be returned,
1177 according to minibuf. */
1178 if (NILP (minibuf))
1179 {
1180 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1181 prev = f;
1182 }
1183 else if (WINDOWP (minibuf))
1184 {
1185 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1186 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1187 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1188 FRAME_FOCUS_FRAME (XFRAME (f))))
1189 prev = f;
1190 }
1191 else if (EQ (minibuf, Qvisible))
1192 {
1193 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1194 if (FRAME_VISIBLE_P (XFRAME (f)))
1195 prev = f;
1196 }
1197 else if (XFASTINT (minibuf) == 0)
1198 {
1199 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1200 if (FRAME_VISIBLE_P (XFRAME (f))
1201 || FRAME_ICONIFIED_P (XFRAME (f)))
1202 prev = f;
1203 }
1204 else
1205 prev = f;
1206 }
1207 }
1208
1209 /* We've scanned the entire list. */
1210 if (NILP (prev))
1211 /* We went through the whole frame list without finding a single
1212 acceptable frame. Return the original frame. */
1213 return frame;
1214 else
1215 /* There were no acceptable frames in the list before FRAME; otherwise,
1216 we would have returned directly from the loop. Since PREV is the last
1217 acceptable frame in the list, return it. */
1218 return prev;
1219 }
1220
1221
1222 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1223 doc: /* Return the next frame in the frame list after FRAME.
1224 It considers only frames on the same terminal as FRAME.
1225 By default, skip minibuffer-only frames.
1226 If omitted, FRAME defaults to the selected frame.
1227 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1228 If MINIFRAME is a window, include only its own frame
1229 and any frame now using that window as the minibuffer.
1230 If MINIFRAME is `visible', include all visible frames.
1231 If MINIFRAME is 0, include all visible and iconified frames.
1232 Otherwise, include all frames. */)
1233 (frame, miniframe)
1234 Lisp_Object frame, miniframe;
1235 {
1236 if (NILP (frame))
1237 frame = selected_frame;
1238
1239 CHECK_LIVE_FRAME (frame);
1240 return next_frame (frame, miniframe);
1241 }
1242
1243 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1244 doc: /* Return the previous frame in the frame list before FRAME.
1245 It considers only frames on the same terminal as FRAME.
1246 By default, skip minibuffer-only frames.
1247 If omitted, FRAME defaults to the selected frame.
1248 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1249 If MINIFRAME is a window, include only its own frame
1250 and any frame now using that window as the minibuffer.
1251 If MINIFRAME is `visible', include all visible frames.
1252 If MINIFRAME is 0, include all visible and iconified frames.
1253 Otherwise, include all frames. */)
1254 (frame, miniframe)
1255 Lisp_Object frame, miniframe;
1256 {
1257 if (NILP (frame))
1258 frame = selected_frame;
1259 CHECK_LIVE_FRAME (frame);
1260 return prev_frame (frame, miniframe);
1261 }
1262 \f
1263 /* Return 1 if it is ok to delete frame F;
1264 0 if all frames aside from F are invisible.
1265 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1266
1267 int
1268 other_visible_frames (f)
1269 FRAME_PTR f;
1270 {
1271 /* We know the selected frame is visible,
1272 so if F is some other frame, it can't be the sole visible one. */
1273 if (f == SELECTED_FRAME ())
1274 {
1275 Lisp_Object frames;
1276 int count = 0;
1277
1278 for (frames = Vframe_list;
1279 CONSP (frames);
1280 frames = XCDR (frames))
1281 {
1282 Lisp_Object this;
1283
1284 this = XCAR (frames);
1285 /* Verify that the frame's window still exists
1286 and we can still talk to it. And note any recent change
1287 in visibility. */
1288 #ifdef HAVE_WINDOW_SYSTEM
1289 if (FRAME_WINDOW_P (XFRAME (this)))
1290 {
1291 x_sync (XFRAME (this));
1292 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1293 }
1294 #endif
1295
1296 if (FRAME_VISIBLE_P (XFRAME (this))
1297 || FRAME_ICONIFIED_P (XFRAME (this))
1298 /* Allow deleting the terminal frame when at least
1299 one X frame exists! */
1300 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1301 count++;
1302 }
1303 return count > 1;
1304 }
1305 return 1;
1306 }
1307
1308 /* Error handler for `delete-frame-functions'. */
1309 static Lisp_Object
1310 delete_frame_handler (Lisp_Object arg)
1311 {
1312 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1313 return Qnil;
1314 }
1315
1316 extern Lisp_Object Qrun_hook_with_args;
1317
1318 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1319 doc: /* Delete FRAME, permanently eliminating it from use.
1320 If omitted, FRAME defaults to the selected frame.
1321 A frame may not be deleted if its minibuffer is used by other frames.
1322 Normally, you may not delete a frame if all other frames are invisible,
1323 but if the second optional argument FORCE is non-nil, you may do so.
1324
1325 This function runs `delete-frame-functions' before actually deleting the
1326 frame, unless the frame is a tooltip.
1327 The functions are run with one arg, the frame to be deleted.
1328 But FORCE inhibits this too. */)
1329 /* FORCE is non-nil when handling a disconnected terminal. */
1330 (frame, force)
1331 Lisp_Object frame, force;
1332 {
1333 struct frame *f;
1334 struct frame *sf = SELECTED_FRAME ();
1335 struct kboard *kb;
1336
1337 int minibuffer_selected;
1338
1339 if (EQ (frame, Qnil))
1340 {
1341 f = sf;
1342 XSETFRAME (frame, f);
1343 }
1344 else
1345 {
1346 CHECK_FRAME (frame);
1347 f = XFRAME (frame);
1348 }
1349
1350 if (! FRAME_LIVE_P (f))
1351 return Qnil;
1352
1353 if (NILP (force) && !other_visible_frames (f))
1354 error ("Attempt to delete the sole visible or iconified frame");
1355
1356 #if 0
1357 /* This is a nice idea, but x_connection_closed needs to be able
1358 to delete the last frame, if it is gone. */
1359 if (NILP (XCDR (Vframe_list)))
1360 error ("Attempt to delete the only frame");
1361 #endif
1362
1363 /* Does this frame have a minibuffer, and is it the surrogate
1364 minibuffer for any other frame? */
1365 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1366 {
1367 Lisp_Object frames;
1368
1369 for (frames = Vframe_list;
1370 CONSP (frames);
1371 frames = XCDR (frames))
1372 {
1373 Lisp_Object this;
1374 this = XCAR (frames);
1375
1376 if (! EQ (this, frame)
1377 && EQ (frame,
1378 WINDOW_FRAME (XWINDOW
1379 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1380 {
1381 /* If we MUST delete this frame, delete the other first. */
1382 if (!NILP (force))
1383 Fdelete_frame (this, force);
1384 else
1385 error ("Attempt to delete a surrogate minibuffer frame");
1386 }
1387 }
1388 }
1389
1390 /* Run `delete-frame-functions'
1391 unless FORCE is `noelisp' or frame is a tooltip.
1392 FORCE is set to `noelisp' when handling a disconnect from the terminal,
1393 so we don't dare call Lisp code. */
1394 if (NILP (Vrun_hooks) || !NILP (Fframe_parameter (frame, intern ("tooltip"))))
1395 ;
1396 if (EQ (force, Qnoelisp))
1397 pending_funcalls
1398 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1399 pending_funcalls);
1400 else
1401 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1402
1403 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1404 if (! FRAME_LIVE_P (f))
1405 return Qnil;
1406
1407 /* At this point, we are committed to deleting the frame.
1408 There is no more chance for errors to prevent it. */
1409
1410 minibuffer_selected = EQ (minibuf_window, selected_window);
1411
1412 /* Don't let the frame remain selected. */
1413 if (f == sf)
1414 {
1415 Lisp_Object tail, frame1;
1416
1417 /* Look for another visible frame on the same terminal. */
1418 frame1 = next_frame (frame, Qvisible);
1419
1420 /* If there is none, find *some* other frame. */
1421 if (NILP (frame1) || EQ (frame1, frame))
1422 {
1423 FOR_EACH_FRAME (tail, frame1)
1424 {
1425 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1426 break;
1427 }
1428 }
1429
1430 do_switch_frame (frame1, 0, 1);
1431 sf = SELECTED_FRAME ();
1432 }
1433
1434 /* Don't allow minibuf_window to remain on a deleted frame. */
1435 if (EQ (f->minibuffer_window, minibuf_window))
1436 {
1437 Fset_window_buffer (sf->minibuffer_window,
1438 XWINDOW (minibuf_window)->buffer, Qnil);
1439 minibuf_window = sf->minibuffer_window;
1440
1441 /* If the dying minibuffer window was selected,
1442 select the new one. */
1443 if (minibuffer_selected)
1444 Fselect_window (minibuf_window, Qnil);
1445 }
1446
1447 /* Don't let echo_area_window to remain on a deleted frame. */
1448 if (EQ (f->minibuffer_window, echo_area_window))
1449 echo_area_window = sf->minibuffer_window;
1450
1451 /* Clear any X selections for this frame. */
1452 #ifdef HAVE_X_WINDOWS
1453 if (FRAME_X_P (f))
1454 x_clear_frame_selections (f);
1455 #endif
1456 #ifdef MAC_OS
1457 if (FRAME_MAC_P (f))
1458 x_clear_frame_selections (f);
1459 #endif
1460
1461 /* Free glyphs.
1462 This function must be called before the window tree of the
1463 frame is deleted because windows contain dynamically allocated
1464 memory. */
1465 free_glyphs (f);
1466
1467 #ifdef HAVE_WINDOW_SYSTEM
1468 /* Give chance to each font driver to free a frame specific data. */
1469 font_update_drivers (f, Qnil);
1470 #endif
1471
1472 /* Mark all the windows that used to be on FRAME as deleted, and then
1473 remove the reference to them. */
1474 delete_all_subwindows (XWINDOW (f->root_window));
1475 f->root_window = Qnil;
1476
1477 Vframe_list = Fdelq (frame, Vframe_list);
1478 FRAME_SET_VISIBLE (f, 0);
1479
1480 xfree (f->namebuf);
1481 xfree (f->decode_mode_spec_buffer);
1482 xfree (FRAME_INSERT_COST (f));
1483 xfree (FRAME_DELETEN_COST (f));
1484 xfree (FRAME_INSERTN_COST (f));
1485 xfree (FRAME_DELETE_COST (f));
1486 xfree (FRAME_MESSAGE_BUF (f));
1487
1488 /* Since some events are handled at the interrupt level, we may get
1489 an event for f at any time; if we zero out the frame's terminal
1490 now, then we may trip up the event-handling code. Instead, we'll
1491 promise that the terminal of the frame must be valid until we
1492 have called the window-system-dependent frame destruction
1493 routine. */
1494
1495 if (FRAME_TERMINAL (f)->delete_frame_hook)
1496 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1497
1498 {
1499 struct terminal *terminal = FRAME_TERMINAL (f);
1500 f->output_data.nothing = 0;
1501 f->terminal = 0; /* Now the frame is dead. */
1502
1503 /* If needed, delete the terminal that this frame was on.
1504 (This must be done after the frame is killed.) */
1505 terminal->reference_count--;
1506 if (terminal->reference_count == 0)
1507 {
1508 Lisp_Object tmp;
1509 XSETTERMINAL (tmp, terminal);
1510
1511 kb = NULL;
1512 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1513 }
1514 #ifdef MULTI_KBOARD
1515 else
1516 kb = terminal->kboard;
1517 #endif
1518 }
1519
1520 /* If we've deleted the last_nonminibuf_frame, then try to find
1521 another one. */
1522 if (f == last_nonminibuf_frame)
1523 {
1524 Lisp_Object frames;
1525
1526 last_nonminibuf_frame = 0;
1527
1528 for (frames = Vframe_list;
1529 CONSP (frames);
1530 frames = XCDR (frames))
1531 {
1532 f = XFRAME (XCAR (frames));
1533 if (!FRAME_MINIBUF_ONLY_P (f))
1534 {
1535 last_nonminibuf_frame = f;
1536 break;
1537 }
1538 }
1539 }
1540
1541 /* If there's no other frame on the same kboard, get out of
1542 single-kboard state if we're in it for this kboard. */
1543 if (kb != NULL)
1544 {
1545 Lisp_Object frames;
1546 /* Some frame we found on the same kboard, or nil if there are none. */
1547 Lisp_Object frame_on_same_kboard;
1548
1549 frame_on_same_kboard = Qnil;
1550
1551 for (frames = Vframe_list;
1552 CONSP (frames);
1553 frames = XCDR (frames))
1554 {
1555 Lisp_Object this;
1556 struct frame *f1;
1557
1558 this = XCAR (frames);
1559 if (!FRAMEP (this))
1560 abort ();
1561 f1 = XFRAME (this);
1562
1563 if (kb == FRAME_KBOARD (f1))
1564 frame_on_same_kboard = this;
1565 }
1566
1567 if (NILP (frame_on_same_kboard))
1568 not_single_kboard_state (kb);
1569 }
1570
1571
1572 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1573 find another one. Prefer minibuffer-only frames, but also notice
1574 frames with other windows. */
1575 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1576 {
1577 Lisp_Object frames;
1578
1579 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1580 Lisp_Object frame_with_minibuf;
1581 /* Some frame we found on the same kboard, or nil if there are none. */
1582 Lisp_Object frame_on_same_kboard;
1583
1584 frame_on_same_kboard = Qnil;
1585 frame_with_minibuf = Qnil;
1586
1587 for (frames = Vframe_list;
1588 CONSP (frames);
1589 frames = XCDR (frames))
1590 {
1591 Lisp_Object this;
1592 struct frame *f1;
1593
1594 this = XCAR (frames);
1595 if (!FRAMEP (this))
1596 abort ();
1597 f1 = XFRAME (this);
1598
1599 /* Consider only frames on the same kboard
1600 and only those with minibuffers. */
1601 if (kb == FRAME_KBOARD (f1)
1602 && FRAME_HAS_MINIBUF_P (f1))
1603 {
1604 frame_with_minibuf = this;
1605 if (FRAME_MINIBUF_ONLY_P (f1))
1606 break;
1607 }
1608
1609 if (kb == FRAME_KBOARD (f1))
1610 frame_on_same_kboard = this;
1611 }
1612
1613 if (!NILP (frame_on_same_kboard))
1614 {
1615 /* We know that there must be some frame with a minibuffer out
1616 there. If this were not true, all of the frames present
1617 would have to be minibufferless, which implies that at some
1618 point their minibuffer frames must have been deleted, but
1619 that is prohibited at the top; you can't delete surrogate
1620 minibuffer frames. */
1621 if (NILP (frame_with_minibuf))
1622 abort ();
1623
1624 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1625 }
1626 else
1627 /* No frames left on this kboard--say no minibuffer either. */
1628 kb->Vdefault_minibuffer_frame = Qnil;
1629 }
1630
1631 /* Cause frame titles to update--necessary if we now have just one frame. */
1632 update_mode_lines = 1;
1633
1634 return Qnil;
1635 }
1636 \f
1637 /* Return mouse position in character cell units. */
1638
1639 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1640 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1641 The position is given in character cells, where (0, 0) is the
1642 upper-left corner of the frame, X is the horizontal offset, and Y is
1643 the vertical offset.
1644 If Emacs is running on a mouseless terminal or hasn't been programmed
1645 to read the mouse position, it returns the selected frame for FRAME
1646 and nil for X and Y.
1647 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1648 passing the normal return value to that function as an argument,
1649 and returns whatever that function returns. */)
1650 ()
1651 {
1652 FRAME_PTR f;
1653 Lisp_Object lispy_dummy;
1654 enum scroll_bar_part party_dummy;
1655 Lisp_Object x, y, retval;
1656 int col, row;
1657 unsigned long long_dummy;
1658 struct gcpro gcpro1;
1659
1660 f = SELECTED_FRAME ();
1661 x = y = Qnil;
1662
1663 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1664 /* It's okay for the hook to refrain from storing anything. */
1665 if (FRAME_TERMINAL (f)->mouse_position_hook)
1666 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1667 &lispy_dummy, &party_dummy,
1668 &x, &y,
1669 &long_dummy);
1670 if (! NILP (x))
1671 {
1672 col = XINT (x);
1673 row = XINT (y);
1674 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1675 XSETINT (x, col);
1676 XSETINT (y, row);
1677 }
1678 #endif
1679 XSETFRAME (lispy_dummy, f);
1680 retval = Fcons (lispy_dummy, Fcons (x, y));
1681 GCPRO1 (retval);
1682 if (!NILP (Vmouse_position_function))
1683 retval = call1 (Vmouse_position_function, retval);
1684 RETURN_UNGCPRO (retval);
1685 }
1686
1687 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1688 Smouse_pixel_position, 0, 0, 0,
1689 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1690 The position is given in pixel units, where (0, 0) is the
1691 upper-left corner of the frame, X is the horizontal offset, and Y is
1692 the vertical offset.
1693 If Emacs is running on a mouseless terminal or hasn't been programmed
1694 to read the mouse position, it returns the selected frame for FRAME
1695 and nil for X and Y. */)
1696 ()
1697 {
1698 FRAME_PTR f;
1699 Lisp_Object lispy_dummy;
1700 enum scroll_bar_part party_dummy;
1701 Lisp_Object x, y;
1702 unsigned long long_dummy;
1703
1704 f = SELECTED_FRAME ();
1705 x = y = Qnil;
1706
1707 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1708 /* It's okay for the hook to refrain from storing anything. */
1709 if (FRAME_TERMINAL (f)->mouse_position_hook)
1710 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1711 &lispy_dummy, &party_dummy,
1712 &x, &y,
1713 &long_dummy);
1714 #endif
1715 XSETFRAME (lispy_dummy, f);
1716 return Fcons (lispy_dummy, Fcons (x, y));
1717 }
1718
1719 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1720 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1721 Coordinates are relative to the frame, not a window,
1722 so the coordinates of the top left character in the frame
1723 may be nonzero due to left-hand scroll bars or the menu bar.
1724
1725 The position is given in character cells, where (0, 0) is the
1726 upper-left corner of the frame, X is the horizontal offset, and Y is
1727 the vertical offset.
1728
1729 This function is a no-op for an X frame that is not visible.
1730 If you have just created a frame, you must wait for it to become visible
1731 before calling this function on it, like this.
1732 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1733 (frame, x, y)
1734 Lisp_Object frame, x, y;
1735 {
1736 CHECK_LIVE_FRAME (frame);
1737 CHECK_NUMBER (x);
1738 CHECK_NUMBER (y);
1739
1740 /* I think this should be done with a hook. */
1741 #ifdef HAVE_WINDOW_SYSTEM
1742 if (FRAME_WINDOW_P (XFRAME (frame)))
1743 /* Warping the mouse will cause enternotify and focus events. */
1744 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1745 #else
1746 #if defined (MSDOS) && defined (HAVE_MOUSE)
1747 if (FRAME_MSDOS_P (XFRAME (frame)))
1748 {
1749 Fselect_frame (frame);
1750 mouse_moveto (XINT (x), XINT (y));
1751 }
1752 #else
1753 #ifdef HAVE_GPM
1754 {
1755 Fselect_frame (frame);
1756 term_mouse_moveto (XINT (x), XINT (y));
1757 }
1758 #endif
1759 #endif
1760 #endif
1761
1762 return Qnil;
1763 }
1764
1765 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1766 Sset_mouse_pixel_position, 3, 3, 0,
1767 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1768 The position is given in pixels, where (0, 0) is the upper-left corner
1769 of the frame, X is the horizontal offset, and Y is the vertical offset.
1770
1771 Note, this is a no-op for an X frame that is not visible.
1772 If you have just created a frame, you must wait for it to become visible
1773 before calling this function on it, like this.
1774 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1775 (frame, x, y)
1776 Lisp_Object frame, x, y;
1777 {
1778 CHECK_LIVE_FRAME (frame);
1779 CHECK_NUMBER (x);
1780 CHECK_NUMBER (y);
1781
1782 /* I think this should be done with a hook. */
1783 #ifdef HAVE_WINDOW_SYSTEM
1784 if (FRAME_WINDOW_P (XFRAME (frame)))
1785 /* Warping the mouse will cause enternotify and focus events. */
1786 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1787 #else
1788 #if defined (MSDOS) && defined (HAVE_MOUSE)
1789 if (FRAME_MSDOS_P (XFRAME (frame)))
1790 {
1791 Fselect_frame (frame);
1792 mouse_moveto (XINT (x), XINT (y));
1793 }
1794 #else
1795 #ifdef HAVE_GPM
1796 {
1797 Fselect_frame (frame);
1798 term_mouse_moveto (XINT (x), XINT (y));
1799 }
1800 #endif
1801 #endif
1802 #endif
1803
1804 return Qnil;
1805 }
1806 \f
1807 static void make_frame_visible_1 P_ ((Lisp_Object));
1808
1809 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1810 0, 1, "",
1811 doc: /* Make the frame FRAME visible (assuming it is an X window).
1812 If omitted, FRAME defaults to the currently selected frame. */)
1813 (frame)
1814 Lisp_Object frame;
1815 {
1816 if (NILP (frame))
1817 frame = selected_frame;
1818
1819 CHECK_LIVE_FRAME (frame);
1820
1821 /* I think this should be done with a hook. */
1822 #ifdef HAVE_WINDOW_SYSTEM
1823 if (FRAME_WINDOW_P (XFRAME (frame)))
1824 {
1825 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1826 x_make_frame_visible (XFRAME (frame));
1827 }
1828 #endif
1829
1830 make_frame_visible_1 (XFRAME (frame)->root_window);
1831
1832 /* Make menu bar update for the Buffers and Frames menus. */
1833 windows_or_buffers_changed++;
1834
1835 return frame;
1836 }
1837
1838 /* Update the display_time slot of the buffers shown in WINDOW
1839 and all its descendents. */
1840
1841 static void
1842 make_frame_visible_1 (window)
1843 Lisp_Object window;
1844 {
1845 struct window *w;
1846
1847 for (;!NILP (window); window = w->next)
1848 {
1849 w = XWINDOW (window);
1850
1851 if (!NILP (w->buffer))
1852 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1853
1854 if (!NILP (w->vchild))
1855 make_frame_visible_1 (w->vchild);
1856 if (!NILP (w->hchild))
1857 make_frame_visible_1 (w->hchild);
1858 }
1859 }
1860
1861 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1862 0, 2, "",
1863 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1864 If omitted, FRAME defaults to the currently selected frame.
1865 Normally you may not make FRAME invisible if all other frames are invisible,
1866 but if the second optional argument FORCE is non-nil, you may do so. */)
1867 (frame, force)
1868 Lisp_Object frame, force;
1869 {
1870 if (NILP (frame))
1871 frame = selected_frame;
1872
1873 CHECK_LIVE_FRAME (frame);
1874
1875 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1876 error ("Attempt to make invisible the sole visible or iconified frame");
1877
1878 #if 0 /* This isn't logically necessary, and it can do GC. */
1879 /* Don't let the frame remain selected. */
1880 if (EQ (frame, selected_frame))
1881 do_switch_frame (next_frame (frame, Qt), 0, 0)
1882 #endif
1883
1884 /* Don't allow minibuf_window to remain on a deleted frame. */
1885 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1886 {
1887 struct frame *sf = XFRAME (selected_frame);
1888 Fset_window_buffer (sf->minibuffer_window,
1889 XWINDOW (minibuf_window)->buffer, Qnil);
1890 minibuf_window = sf->minibuffer_window;
1891 }
1892
1893 /* I think this should be done with a hook. */
1894 #ifdef HAVE_WINDOW_SYSTEM
1895 if (FRAME_WINDOW_P (XFRAME (frame)))
1896 x_make_frame_invisible (XFRAME (frame));
1897 #endif
1898
1899 /* Make menu bar update for the Buffers and Frames menus. */
1900 windows_or_buffers_changed++;
1901
1902 return Qnil;
1903 }
1904
1905 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1906 0, 1, "",
1907 doc: /* Make the frame FRAME into an icon.
1908 If omitted, FRAME defaults to the currently selected frame. */)
1909 (frame)
1910 Lisp_Object frame;
1911 {
1912 if (NILP (frame))
1913 frame = selected_frame;
1914
1915 CHECK_LIVE_FRAME (frame);
1916
1917 #if 0 /* This isn't logically necessary, and it can do GC. */
1918 /* Don't let the frame remain selected. */
1919 if (EQ (frame, selected_frame))
1920 Fhandle_switch_frame (next_frame (frame, Qt));
1921 #endif
1922
1923 /* Don't allow minibuf_window to remain on a deleted frame. */
1924 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1925 {
1926 struct frame *sf = XFRAME (selected_frame);
1927 Fset_window_buffer (sf->minibuffer_window,
1928 XWINDOW (minibuf_window)->buffer, Qnil);
1929 minibuf_window = sf->minibuffer_window;
1930 }
1931
1932 /* I think this should be done with a hook. */
1933 #ifdef HAVE_WINDOW_SYSTEM
1934 if (FRAME_WINDOW_P (XFRAME (frame)))
1935 x_iconify_frame (XFRAME (frame));
1936 #endif
1937
1938 /* Make menu bar update for the Buffers and Frames menus. */
1939 windows_or_buffers_changed++;
1940
1941 return Qnil;
1942 }
1943
1944 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1945 1, 1, 0,
1946 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1947 A frame that is not \"visible\" is not updated and, if it works through
1948 a window system, it may not show at all.
1949 Return the symbol `icon' if frame is visible only as an icon.
1950
1951 On a text-only terminal, all frames are considered visible, whether
1952 they are currently being displayed or not, and this function returns t
1953 for all frames. */)
1954 (frame)
1955 Lisp_Object frame;
1956 {
1957 CHECK_LIVE_FRAME (frame);
1958
1959 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1960
1961 if (FRAME_VISIBLE_P (XFRAME (frame)))
1962 return Qt;
1963 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1964 return Qicon;
1965 return Qnil;
1966 }
1967
1968 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1969 0, 0, 0,
1970 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1971 ()
1972 {
1973 Lisp_Object tail, frame;
1974 struct frame *f;
1975 Lisp_Object value;
1976
1977 value = Qnil;
1978 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1979 {
1980 frame = XCAR (tail);
1981 if (!FRAMEP (frame))
1982 continue;
1983 f = XFRAME (frame);
1984 if (FRAME_VISIBLE_P (f))
1985 value = Fcons (frame, value);
1986 }
1987 return value;
1988 }
1989
1990
1991 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1992 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1993 If FRAME is invisible or iconified, make it visible.
1994 If you don't specify a frame, the selected frame is used.
1995 If Emacs is displaying on an ordinary terminal or some other device which
1996 doesn't support multiple overlapping frames, this function does nothing. */)
1997 (frame)
1998 Lisp_Object frame;
1999 {
2000 struct frame *f;
2001 if (NILP (frame))
2002 frame = selected_frame;
2003
2004 CHECK_LIVE_FRAME (frame);
2005
2006 f = XFRAME (frame);
2007
2008 /* Do like the documentation says. */
2009 Fmake_frame_visible (frame);
2010
2011 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2012 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2013
2014 return Qnil;
2015 }
2016
2017 /* Should we have a corresponding function called Flower_Power? */
2018 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2019 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2020 If you don't specify a frame, the selected frame is used.
2021 If Emacs is displaying on an ordinary terminal or some other device which
2022 doesn't support multiple overlapping frames, this function does nothing. */)
2023 (frame)
2024 Lisp_Object frame;
2025 {
2026 struct frame *f;
2027
2028 if (NILP (frame))
2029 frame = selected_frame;
2030
2031 CHECK_LIVE_FRAME (frame);
2032
2033 f = XFRAME (frame);
2034
2035 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2036 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2037
2038 return Qnil;
2039 }
2040
2041 \f
2042 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2043 1, 2, 0,
2044 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2045 In other words, switch-frame events caused by events in FRAME will
2046 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2047 FOCUS-FRAME after reading an event typed at FRAME.
2048
2049 If FOCUS-FRAME is omitted or nil, any existing redirection is
2050 cancelled, and the frame again receives its own keystrokes.
2051
2052 Focus redirection is useful for temporarily redirecting keystrokes to
2053 a surrogate minibuffer frame when a frame doesn't have its own
2054 minibuffer window.
2055
2056 A frame's focus redirection can be changed by `select-frame'. If frame
2057 FOO is selected, and then a different frame BAR is selected, any
2058 frames redirecting their focus to FOO are shifted to redirect their
2059 focus to BAR. This allows focus redirection to work properly when the
2060 user switches from one frame to another using `select-window'.
2061
2062 This means that a frame whose focus is redirected to itself is treated
2063 differently from a frame whose focus is redirected to nil; the former
2064 is affected by `select-frame', while the latter is not.
2065
2066 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2067 (frame, focus_frame)
2068 Lisp_Object frame, focus_frame;
2069 {
2070 struct frame *f;
2071
2072 /* Note that we don't check for a live frame here. It's reasonable
2073 to redirect the focus of a frame you're about to delete, if you
2074 know what other frame should receive those keystrokes. */
2075 CHECK_FRAME (frame);
2076
2077 if (! NILP (focus_frame))
2078 CHECK_LIVE_FRAME (focus_frame);
2079
2080 f = XFRAME (frame);
2081
2082 f->focus_frame = focus_frame;
2083
2084 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2085 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2086
2087 return Qnil;
2088 }
2089
2090
2091 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2092 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2093 This returns nil if FRAME's focus is not redirected.
2094 See `redirect-frame-focus'. */)
2095 (frame)
2096 Lisp_Object frame;
2097 {
2098 CHECK_LIVE_FRAME (frame);
2099
2100 return FRAME_FOCUS_FRAME (XFRAME (frame));
2101 }
2102
2103
2104 \f
2105 /* Return the value of frame parameter PROP in frame FRAME. */
2106
2107 Lisp_Object
2108 get_frame_param (frame, prop)
2109 register struct frame *frame;
2110 Lisp_Object prop;
2111 {
2112 register Lisp_Object tem;
2113
2114 tem = Fassq (prop, frame->param_alist);
2115 if (EQ (tem, Qnil))
2116 return tem;
2117 return Fcdr (tem);
2118 }
2119
2120 /* Return the buffer-predicate of the selected frame. */
2121
2122 Lisp_Object
2123 frame_buffer_predicate (frame)
2124 Lisp_Object frame;
2125 {
2126 return XFRAME (frame)->buffer_predicate;
2127 }
2128
2129 /* Return the buffer-list of the selected frame. */
2130
2131 Lisp_Object
2132 frame_buffer_list (frame)
2133 Lisp_Object frame;
2134 {
2135 return XFRAME (frame)->buffer_list;
2136 }
2137
2138 /* Set the buffer-list of the selected frame. */
2139
2140 void
2141 set_frame_buffer_list (frame, list)
2142 Lisp_Object frame, list;
2143 {
2144 XFRAME (frame)->buffer_list = list;
2145 }
2146
2147 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2148
2149 void
2150 frames_discard_buffer (buffer)
2151 Lisp_Object buffer;
2152 {
2153 Lisp_Object frame, tail;
2154
2155 FOR_EACH_FRAME (tail, frame)
2156 {
2157 XFRAME (frame)->buffer_list
2158 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2159 XFRAME (frame)->buried_buffer_list
2160 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2161 }
2162 }
2163
2164 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2165 If the alist already has an element for PROP, we change it. */
2166
2167 void
2168 store_in_alist (alistptr, prop, val)
2169 Lisp_Object *alistptr, val;
2170 Lisp_Object prop;
2171 {
2172 register Lisp_Object tem;
2173
2174 tem = Fassq (prop, *alistptr);
2175 if (EQ (tem, Qnil))
2176 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2177 else
2178 Fsetcdr (tem, val);
2179 }
2180
2181 static int
2182 frame_name_fnn_p (str, len)
2183 char *str;
2184 EMACS_INT len;
2185 {
2186 if (len > 1 && str[0] == 'F')
2187 {
2188 char *end_ptr;
2189
2190 strtol (str + 1, &end_ptr, 10);
2191
2192 if (end_ptr == str + len)
2193 return 1;
2194 }
2195 return 0;
2196 }
2197
2198 /* Set the name of the terminal frame. Also used by MSDOS frames.
2199 Modeled after x_set_name which is used for WINDOW frames. */
2200
2201 static void
2202 set_term_frame_name (f, name)
2203 struct frame *f;
2204 Lisp_Object name;
2205 {
2206 f->explicit_name = ! NILP (name);
2207
2208 /* If NAME is nil, set the name to F<num>. */
2209 if (NILP (name))
2210 {
2211 char namebuf[20];
2212
2213 /* Check for no change needed in this very common case
2214 before we do any consing. */
2215 if (frame_name_fnn_p (SDATA (f->name),
2216 SBYTES (f->name)))
2217 return;
2218
2219 tty_frame_count++;
2220 sprintf (namebuf, "F%d", tty_frame_count);
2221 name = build_string (namebuf);
2222 }
2223 else
2224 {
2225 CHECK_STRING (name);
2226
2227 /* Don't change the name if it's already NAME. */
2228 if (! NILP (Fstring_equal (name, f->name)))
2229 return;
2230
2231 /* Don't allow the user to set the frame name to F<num>, so it
2232 doesn't clash with the names we generate for terminal frames. */
2233 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2234 error ("Frame names of the form F<num> are usurped by Emacs");
2235 }
2236
2237 f->name = name;
2238 update_mode_lines = 1;
2239 }
2240
2241 void
2242 store_frame_param (f, prop, val)
2243 struct frame *f;
2244 Lisp_Object prop, val;
2245 {
2246 register Lisp_Object old_alist_elt;
2247
2248 /* The buffer-list parameters are stored in a special place and not
2249 in the alist. */
2250 if (EQ (prop, Qbuffer_list))
2251 {
2252 f->buffer_list = val;
2253 return;
2254 }
2255 if (EQ (prop, Qburied_buffer_list))
2256 {
2257 f->buried_buffer_list = val;
2258 return;
2259 }
2260
2261 /* If PROP is a symbol which is supposed to have frame-local values,
2262 and it is set up based on this frame, switch to the global
2263 binding. That way, we can create or alter the frame-local binding
2264 without messing up the symbol's status. */
2265 if (SYMBOLP (prop))
2266 {
2267 Lisp_Object valcontents;
2268 valcontents = SYMBOL_VALUE (prop);
2269 if ((BUFFER_LOCAL_VALUEP (valcontents))
2270 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2271 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2272 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2273 swap_in_global_binding (prop);
2274 }
2275
2276 #ifndef WINDOWSNT
2277 /* The tty color needed to be set before the frame's parameter
2278 alist was updated with the new value. This is not true any more,
2279 but we still do this test early on. */
2280 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2281 && f == FRAME_TTY (f)->previous_frame)
2282 /* Force redisplay of this tty. */
2283 FRAME_TTY (f)->previous_frame = NULL;
2284 #endif
2285
2286 /* Update the frame parameter alist. */
2287 old_alist_elt = Fassq (prop, f->param_alist);
2288 if (EQ (old_alist_elt, Qnil))
2289 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2290 else
2291 Fsetcdr (old_alist_elt, val);
2292
2293 /* Update some other special parameters in their special places
2294 in addition to the alist. */
2295
2296 if (EQ (prop, Qbuffer_predicate))
2297 f->buffer_predicate = val;
2298
2299 if (! FRAME_WINDOW_P (f))
2300 {
2301 if (EQ (prop, Qmenu_bar_lines))
2302 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2303 else if (EQ (prop, Qname))
2304 set_term_frame_name (f, val);
2305 }
2306
2307 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2308 {
2309 if (! MINI_WINDOW_P (XWINDOW (val)))
2310 error ("Surrogate minibuffer windows must be minibuffer windows");
2311
2312 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2313 && !EQ (val, f->minibuffer_window))
2314 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2315
2316 /* Install the chosen minibuffer window, with proper buffer. */
2317 f->minibuffer_window = val;
2318 }
2319 }
2320
2321 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2322 doc: /* Return the parameters-alist of frame FRAME.
2323 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2324 The meaningful PARMs depend on the kind of frame.
2325 If FRAME is omitted, return information on the currently selected frame. */)
2326 (frame)
2327 Lisp_Object frame;
2328 {
2329 Lisp_Object alist;
2330 FRAME_PTR f;
2331 int height, width;
2332 struct gcpro gcpro1;
2333
2334 if (NILP (frame))
2335 frame = selected_frame;
2336
2337 CHECK_FRAME (frame);
2338 f = XFRAME (frame);
2339
2340 if (!FRAME_LIVE_P (f))
2341 return Qnil;
2342
2343 alist = Fcopy_alist (f->param_alist);
2344 GCPRO1 (alist);
2345
2346 if (!FRAME_WINDOW_P (f))
2347 {
2348 int fg = FRAME_FOREGROUND_PIXEL (f);
2349 int bg = FRAME_BACKGROUND_PIXEL (f);
2350 Lisp_Object elt;
2351
2352 /* If the frame's parameter alist says the colors are
2353 unspecified and reversed, take the frame's background pixel
2354 for foreground and vice versa. */
2355 elt = Fassq (Qforeground_color, alist);
2356 if (CONSP (elt) && STRINGP (XCDR (elt)))
2357 {
2358 if (strncmp (SDATA (XCDR (elt)),
2359 unspecified_bg,
2360 SCHARS (XCDR (elt))) == 0)
2361 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2362 else if (strncmp (SDATA (XCDR (elt)),
2363 unspecified_fg,
2364 SCHARS (XCDR (elt))) == 0)
2365 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2366 }
2367 else
2368 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2369 elt = Fassq (Qbackground_color, alist);
2370 if (CONSP (elt) && STRINGP (XCDR (elt)))
2371 {
2372 if (strncmp (SDATA (XCDR (elt)),
2373 unspecified_fg,
2374 SCHARS (XCDR (elt))) == 0)
2375 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2376 else if (strncmp (SDATA (XCDR (elt)),
2377 unspecified_bg,
2378 SCHARS (XCDR (elt))) == 0)
2379 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2380 }
2381 else
2382 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2383 store_in_alist (&alist, intern ("font"),
2384 build_string (FRAME_MSDOS_P (f)
2385 ? "ms-dos"
2386 : FRAME_W32_P (f) ? "w32term"
2387 :"tty"));
2388 }
2389 store_in_alist (&alist, Qname, f->name);
2390 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2391 store_in_alist (&alist, Qheight, make_number (height));
2392 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2393 store_in_alist (&alist, Qwidth, make_number (width));
2394 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2395 store_in_alist (&alist, Qminibuffer,
2396 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2397 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2398 : FRAME_MINIBUF_WINDOW (f)));
2399 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2400 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2401 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2402
2403 /* I think this should be done with a hook. */
2404 #ifdef HAVE_WINDOW_SYSTEM
2405 if (FRAME_WINDOW_P (f))
2406 x_report_frame_params (f, &alist);
2407 else
2408 #endif
2409 {
2410 /* This ought to be correct in f->param_alist for an X frame. */
2411 Lisp_Object lines;
2412 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2413 store_in_alist (&alist, Qmenu_bar_lines, lines);
2414 }
2415
2416 UNGCPRO;
2417 return alist;
2418 }
2419
2420
2421 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2422 doc: /* Return FRAME's value for parameter PARAMETER.
2423 If FRAME is nil, describe the currently selected frame. */)
2424 (frame, parameter)
2425 Lisp_Object frame, parameter;
2426 {
2427 struct frame *f;
2428 Lisp_Object value;
2429
2430 if (NILP (frame))
2431 frame = selected_frame;
2432 else
2433 CHECK_FRAME (frame);
2434 CHECK_SYMBOL (parameter);
2435
2436 f = XFRAME (frame);
2437 value = Qnil;
2438
2439 if (FRAME_LIVE_P (f))
2440 {
2441 /* Avoid consing in frequent cases. */
2442 if (EQ (parameter, Qname))
2443 value = f->name;
2444 #ifdef HAVE_X_WINDOWS
2445 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2446 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2447 #endif /* HAVE_X_WINDOWS */
2448 else if (EQ (parameter, Qbackground_color)
2449 || EQ (parameter, Qforeground_color))
2450 {
2451 value = Fassq (parameter, f->param_alist);
2452 if (CONSP (value))
2453 {
2454 value = XCDR (value);
2455 /* Fframe_parameters puts the actual fg/bg color names,
2456 even if f->param_alist says otherwise. This is
2457 important when param_alist's notion of colors is
2458 "unspecified". We need to do the same here. */
2459 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2460 {
2461 const char *color_name;
2462 EMACS_INT csz;
2463
2464 if (EQ (parameter, Qbackground_color))
2465 {
2466 color_name = SDATA (value);
2467 csz = SCHARS (value);
2468 if (strncmp (color_name, unspecified_bg, csz) == 0)
2469 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2470 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2471 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2472 }
2473 else if (EQ (parameter, Qforeground_color))
2474 {
2475 color_name = SDATA (value);
2476 csz = SCHARS (value);
2477 if (strncmp (color_name, unspecified_fg, csz) == 0)
2478 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2479 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2480 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2481 }
2482 }
2483 }
2484 else
2485 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2486 }
2487 else if (EQ (parameter, Qdisplay_type)
2488 || EQ (parameter, Qbackground_mode))
2489 value = Fcdr (Fassq (parameter, f->param_alist));
2490 else
2491 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2492 }
2493
2494 return value;
2495 }
2496
2497
2498 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2499 Smodify_frame_parameters, 2, 2, 0,
2500 doc: /* Modify the parameters of frame FRAME according to ALIST.
2501 If FRAME is nil, it defaults to the selected frame.
2502 ALIST is an alist of parameters to change and their new values.
2503 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2504 The meaningful PARMs depend on the kind of frame.
2505 Undefined PARMs are ignored, but stored in the frame's parameter list
2506 so that `frame-parameters' will return them.
2507
2508 The value of frame parameter FOO can also be accessed
2509 as a frame-local binding for the variable FOO, if you have
2510 enabled such bindings for that variable with `make-variable-frame-local'. */)
2511 (frame, alist)
2512 Lisp_Object frame, alist;
2513 {
2514 FRAME_PTR f;
2515 register Lisp_Object tail, prop, val;
2516
2517 if (EQ (frame, Qnil))
2518 frame = selected_frame;
2519 CHECK_LIVE_FRAME (frame);
2520 f = XFRAME (frame);
2521
2522 /* I think this should be done with a hook. */
2523 #ifdef HAVE_WINDOW_SYSTEM
2524 if (FRAME_WINDOW_P (f))
2525 x_set_frame_parameters (f, alist);
2526 else
2527 #endif
2528 #ifdef MSDOS
2529 if (FRAME_MSDOS_P (f))
2530 IT_set_frame_parameters (f, alist);
2531 else
2532 #endif
2533
2534 {
2535 int length = XINT (Flength (alist));
2536 int i;
2537 Lisp_Object *parms
2538 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2539 Lisp_Object *values
2540 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2541
2542 /* Extract parm names and values into those vectors. */
2543
2544 i = 0;
2545 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2546 {
2547 Lisp_Object elt;
2548
2549 elt = XCAR (tail);
2550 parms[i] = Fcar (elt);
2551 values[i] = Fcdr (elt);
2552 i++;
2553 }
2554
2555 /* Now process them in reverse of specified order. */
2556 for (i--; i >= 0; i--)
2557 {
2558 prop = parms[i];
2559 val = values[i];
2560 store_frame_param (f, prop, val);
2561
2562 /* Changing the background color might change the background
2563 mode, so that we have to load new defface specs.
2564 Call frame-set-background-mode to do that. */
2565 if (EQ (prop, Qbackground_color))
2566 call1 (Qframe_set_background_mode, frame);
2567 }
2568 }
2569 return Qnil;
2570 }
2571 \f
2572 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2573 0, 1, 0,
2574 doc: /* Height in pixels of a line in the font in frame FRAME.
2575 If FRAME is omitted, the selected frame is used.
2576 For a terminal frame, the value is always 1. */)
2577 (frame)
2578 Lisp_Object frame;
2579 {
2580 struct frame *f;
2581
2582 if (NILP (frame))
2583 frame = selected_frame;
2584 CHECK_FRAME (frame);
2585 f = XFRAME (frame);
2586
2587 #ifdef HAVE_WINDOW_SYSTEM
2588 if (FRAME_WINDOW_P (f))
2589 return make_number (x_char_height (f));
2590 else
2591 #endif
2592 return make_number (1);
2593 }
2594
2595
2596 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2597 0, 1, 0,
2598 doc: /* Width in pixels of characters in the font in frame FRAME.
2599 If FRAME is omitted, the selected frame is used.
2600 On a graphical screen, the width is the standard width of the default font.
2601 For a terminal screen, the value is always 1. */)
2602 (frame)
2603 Lisp_Object frame;
2604 {
2605 struct frame *f;
2606
2607 if (NILP (frame))
2608 frame = selected_frame;
2609 CHECK_FRAME (frame);
2610 f = XFRAME (frame);
2611
2612 #ifdef HAVE_WINDOW_SYSTEM
2613 if (FRAME_WINDOW_P (f))
2614 return make_number (x_char_width (f));
2615 else
2616 #endif
2617 return make_number (1);
2618 }
2619
2620 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2621 Sframe_pixel_height, 0, 1, 0,
2622 doc: /* Return a FRAME's height in pixels.
2623 This counts only the height available for text lines,
2624 not menu bars on window-system Emacs frames.
2625 For a terminal frame, the result really gives the height in characters.
2626 If FRAME is omitted, the selected frame is used. */)
2627 (frame)
2628 Lisp_Object frame;
2629 {
2630 struct frame *f;
2631
2632 if (NILP (frame))
2633 frame = selected_frame;
2634 CHECK_FRAME (frame);
2635 f = XFRAME (frame);
2636
2637 #ifdef HAVE_WINDOW_SYSTEM
2638 if (FRAME_WINDOW_P (f))
2639 return make_number (x_pixel_height (f));
2640 else
2641 #endif
2642 return make_number (FRAME_LINES (f));
2643 }
2644
2645 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2646 Sframe_pixel_width, 0, 1, 0,
2647 doc: /* Return FRAME's width in pixels.
2648 For a terminal frame, the result really gives the width in characters.
2649 If FRAME is omitted, the selected frame is used. */)
2650 (frame)
2651 Lisp_Object frame;
2652 {
2653 struct frame *f;
2654
2655 if (NILP (frame))
2656 frame = selected_frame;
2657 CHECK_FRAME (frame);
2658 f = XFRAME (frame);
2659
2660 #ifdef HAVE_WINDOW_SYSTEM
2661 if (FRAME_WINDOW_P (f))
2662 return make_number (x_pixel_width (f));
2663 else
2664 #endif
2665 return make_number (FRAME_COLS (f));
2666 }
2667 \f
2668 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2669 doc: /* Specify that the frame FRAME has LINES lines.
2670 Optional third arg non-nil means that redisplay should use LINES lines
2671 but that the idea of the actual height of the frame should not be changed. */)
2672 (frame, lines, pretend)
2673 Lisp_Object frame, lines, pretend;
2674 {
2675 register struct frame *f;
2676
2677 CHECK_NUMBER (lines);
2678 if (NILP (frame))
2679 frame = selected_frame;
2680 CHECK_LIVE_FRAME (frame);
2681 f = XFRAME (frame);
2682
2683 /* I think this should be done with a hook. */
2684 #ifdef HAVE_WINDOW_SYSTEM
2685 if (FRAME_WINDOW_P (f))
2686 {
2687 if (XINT (lines) != FRAME_LINES (f))
2688 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2689 do_pending_window_change (0);
2690 }
2691 else
2692 #endif
2693 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2694 return Qnil;
2695 }
2696
2697 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2698 doc: /* Specify that the frame FRAME has COLS columns.
2699 Optional third arg non-nil means that redisplay should use COLS columns
2700 but that the idea of the actual width of the frame should not be changed. */)
2701 (frame, cols, pretend)
2702 Lisp_Object frame, cols, pretend;
2703 {
2704 register struct frame *f;
2705 CHECK_NUMBER (cols);
2706 if (NILP (frame))
2707 frame = selected_frame;
2708 CHECK_LIVE_FRAME (frame);
2709 f = XFRAME (frame);
2710
2711 /* I think this should be done with a hook. */
2712 #ifdef HAVE_WINDOW_SYSTEM
2713 if (FRAME_WINDOW_P (f))
2714 {
2715 if (XINT (cols) != FRAME_COLS (f))
2716 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2717 do_pending_window_change (0);
2718 }
2719 else
2720 #endif
2721 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2722 return Qnil;
2723 }
2724
2725 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2726 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2727 (frame, cols, rows)
2728 Lisp_Object frame, cols, rows;
2729 {
2730 register struct frame *f;
2731
2732 CHECK_LIVE_FRAME (frame);
2733 CHECK_NUMBER (cols);
2734 CHECK_NUMBER (rows);
2735 f = XFRAME (frame);
2736
2737 /* I think this should be done with a hook. */
2738 #ifdef HAVE_WINDOW_SYSTEM
2739 if (FRAME_WINDOW_P (f))
2740 {
2741 if (XINT (rows) != FRAME_LINES (f)
2742 || XINT (cols) != FRAME_COLS (f)
2743 || f->new_text_lines || f->new_text_cols)
2744 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2745 do_pending_window_change (0);
2746 }
2747 else
2748 #endif
2749 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2750
2751 return Qnil;
2752 }
2753
2754 DEFUN ("set-frame-position", Fset_frame_position,
2755 Sset_frame_position, 3, 3, 0,
2756 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2757 This is actually the position of the upper left corner of the frame.
2758 Negative values for XOFFSET or YOFFSET are interpreted relative to
2759 the rightmost or bottommost possible position (that stays within the screen). */)
2760 (frame, xoffset, yoffset)
2761 Lisp_Object frame, xoffset, yoffset;
2762 {
2763 register struct frame *f;
2764
2765 CHECK_LIVE_FRAME (frame);
2766 CHECK_NUMBER (xoffset);
2767 CHECK_NUMBER (yoffset);
2768 f = XFRAME (frame);
2769
2770 /* I think this should be done with a hook. */
2771 #ifdef HAVE_WINDOW_SYSTEM
2772 if (FRAME_WINDOW_P (f))
2773 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2774 #endif
2775
2776 return Qt;
2777 }
2778
2779 \f
2780 /***********************************************************************
2781 Frame Parameters
2782 ***********************************************************************/
2783
2784 /* Connect the frame-parameter names for X frames
2785 to the ways of passing the parameter values to the window system.
2786
2787 The name of a parameter, as a Lisp symbol,
2788 has an `x-frame-parameter' property which is an integer in Lisp
2789 that is an index in this table. */
2790
2791 struct frame_parm_table {
2792 char *name;
2793 Lisp_Object *variable;
2794 };
2795
2796 static struct frame_parm_table frame_parms[] =
2797 {
2798 {"auto-raise", &Qauto_raise},
2799 {"auto-lower", &Qauto_lower},
2800 {"background-color", 0},
2801 {"border-color", &Qborder_color},
2802 {"border-width", &Qborder_width},
2803 {"cursor-color", &Qcursor_color},
2804 {"cursor-type", &Qcursor_type},
2805 {"font", 0},
2806 {"foreground-color", 0},
2807 {"icon-name", &Qicon_name},
2808 {"icon-type", &Qicon_type},
2809 {"internal-border-width", &Qinternal_border_width},
2810 {"menu-bar-lines", &Qmenu_bar_lines},
2811 {"mouse-color", &Qmouse_color},
2812 {"name", &Qname},
2813 {"scroll-bar-width", &Qscroll_bar_width},
2814 {"title", &Qtitle},
2815 {"unsplittable", &Qunsplittable},
2816 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2817 {"visibility", &Qvisibility},
2818 {"tool-bar-lines", &Qtool_bar_lines},
2819 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2820 {"scroll-bar-background", &Qscroll_bar_background},
2821 {"screen-gamma", &Qscreen_gamma},
2822 {"line-spacing", &Qline_spacing},
2823 {"left-fringe", &Qleft_fringe},
2824 {"right-fringe", &Qright_fringe},
2825 {"wait-for-wm", &Qwait_for_wm},
2826 {"fullscreen", &Qfullscreen},
2827 {"font-backend", &Qfont_backend},
2828 {"alpha", &Qalpha}
2829 };
2830
2831 #ifdef HAVE_WINDOW_SYSTEM
2832
2833 extern Lisp_Object Qbox;
2834 extern Lisp_Object Qtop;
2835
2836 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2837 wanted positions of the WM window (not Emacs window).
2838 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2839 window (FRAME_X_WINDOW).
2840 */
2841
2842 void
2843 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2844 struct frame *f;
2845 int *width;
2846 int *height;
2847 int *top_pos;
2848 int *left_pos;
2849 {
2850 int newwidth = FRAME_COLS (f);
2851 int newheight = FRAME_LINES (f);
2852
2853 *top_pos = f->top_pos;
2854 *left_pos = f->left_pos;
2855
2856 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2857 {
2858 int ph;
2859
2860 ph = FRAME_X_DISPLAY_INFO (f)->height;
2861 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2862 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2863 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2864 *top_pos = 0;
2865 }
2866
2867 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2868 {
2869 int pw;
2870
2871 pw = FRAME_X_DISPLAY_INFO (f)->width;
2872 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2873 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2874 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2875 *left_pos = 0;
2876 }
2877
2878 *width = newwidth;
2879 *height = newheight;
2880 }
2881
2882
2883 /* Change the parameters of frame F as specified by ALIST.
2884 If a parameter is not specially recognized, do nothing special;
2885 otherwise call the `x_set_...' function for that parameter.
2886 Except for certain geometry properties, always call store_frame_param
2887 to store the new value in the parameter alist. */
2888
2889 void
2890 x_set_frame_parameters (f, alist)
2891 FRAME_PTR f;
2892 Lisp_Object alist;
2893 {
2894 Lisp_Object tail;
2895
2896 /* If both of these parameters are present, it's more efficient to
2897 set them both at once. So we wait until we've looked at the
2898 entire list before we set them. */
2899 int width, height;
2900
2901 /* Same here. */
2902 Lisp_Object left, top;
2903
2904 /* Same with these. */
2905 Lisp_Object icon_left, icon_top;
2906
2907 /* Record in these vectors all the parms specified. */
2908 Lisp_Object *parms;
2909 Lisp_Object *values;
2910 int i, p;
2911 int left_no_change = 0, top_no_change = 0;
2912 int icon_left_no_change = 0, icon_top_no_change = 0;
2913 int fullscreen_is_being_set = 0;
2914
2915 struct gcpro gcpro1, gcpro2;
2916
2917 i = 0;
2918 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2919 i++;
2920
2921 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2922 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2923
2924 /* Extract parm names and values into those vectors. */
2925
2926 i = 0;
2927 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2928 {
2929 Lisp_Object elt;
2930
2931 elt = XCAR (tail);
2932 parms[i] = Fcar (elt);
2933 values[i] = Fcdr (elt);
2934 i++;
2935 }
2936 /* TAIL and ALIST are not used again below here. */
2937 alist = tail = Qnil;
2938
2939 GCPRO2 (*parms, *values);
2940 gcpro1.nvars = i;
2941 gcpro2.nvars = i;
2942
2943 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2944 because their values appear in VALUES and strings are not valid. */
2945 top = left = Qunbound;
2946 icon_left = icon_top = Qunbound;
2947
2948 /* Provide default values for HEIGHT and WIDTH. */
2949 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2950 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2951
2952 /* Process foreground_color and background_color before anything else.
2953 They are independent of other properties, but other properties (e.g.,
2954 cursor_color) are dependent upon them. */
2955 /* Process default font as well, since fringe widths depends on it. */
2956 /* Also, process fullscreen, width and height depend upon that */
2957 for (p = 0; p < i; p++)
2958 {
2959 Lisp_Object prop, val;
2960
2961 prop = parms[p];
2962 val = values[p];
2963 if (EQ (prop, Qforeground_color)
2964 || EQ (prop, Qbackground_color)
2965 || EQ (prop, Qfont)
2966 || EQ (prop, Qfullscreen))
2967 {
2968 register Lisp_Object param_index, old_value;
2969
2970 old_value = get_frame_param (f, prop);
2971 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2972
2973 if (NILP (Fequal (val, old_value)))
2974 {
2975 store_frame_param (f, prop, val);
2976
2977 param_index = Fget (prop, Qx_frame_parameter);
2978 if (NATNUMP (param_index)
2979 && (XFASTINT (param_index)
2980 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2981 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2982 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2983 }
2984 }
2985 }
2986
2987 /* Now process them in reverse of specified order. */
2988 for (i--; i >= 0; i--)
2989 {
2990 Lisp_Object prop, val;
2991
2992 prop = parms[i];
2993 val = values[i];
2994
2995 if (EQ (prop, Qwidth) && NATNUMP (val))
2996 width = XFASTINT (val);
2997 else if (EQ (prop, Qheight) && NATNUMP (val))
2998 height = XFASTINT (val);
2999 else if (EQ (prop, Qtop))
3000 top = val;
3001 else if (EQ (prop, Qleft))
3002 left = val;
3003 else if (EQ (prop, Qicon_top))
3004 icon_top = val;
3005 else if (EQ (prop, Qicon_left))
3006 icon_left = val;
3007 else if (EQ (prop, Qforeground_color)
3008 || EQ (prop, Qbackground_color)
3009 || EQ (prop, Qfont)
3010 || EQ (prop, Qfullscreen))
3011 /* Processed above. */
3012 continue;
3013 else
3014 {
3015 register Lisp_Object param_index, old_value;
3016
3017 old_value = get_frame_param (f, prop);
3018
3019 store_frame_param (f, prop, val);
3020
3021 param_index = Fget (prop, Qx_frame_parameter);
3022 if (NATNUMP (param_index)
3023 && (XFASTINT (param_index)
3024 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3025 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3026 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3027 }
3028 }
3029
3030 /* Don't die if just one of these was set. */
3031 if (EQ (left, Qunbound))
3032 {
3033 left_no_change = 1;
3034 if (f->left_pos < 0)
3035 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3036 else
3037 XSETINT (left, f->left_pos);
3038 }
3039 if (EQ (top, Qunbound))
3040 {
3041 top_no_change = 1;
3042 if (f->top_pos < 0)
3043 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3044 else
3045 XSETINT (top, f->top_pos);
3046 }
3047
3048 /* If one of the icon positions was not set, preserve or default it. */
3049 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3050 {
3051 icon_left_no_change = 1;
3052 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3053 if (NILP (icon_left))
3054 XSETINT (icon_left, 0);
3055 }
3056 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3057 {
3058 icon_top_no_change = 1;
3059 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3060 if (NILP (icon_top))
3061 XSETINT (icon_top, 0);
3062 }
3063
3064 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3065 {
3066 /* If the frame is visible already and the fullscreen parameter is
3067 being set, it is too late to set WM manager hints to specify
3068 size and position.
3069 Here we first get the width, height and position that applies to
3070 fullscreen. We then move the frame to the appropriate
3071 position. Resize of the frame is taken care of in the code after
3072 this if-statement. */
3073 int new_left, new_top;
3074
3075 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
3076 if (new_top != f->top_pos || new_left != f->left_pos)
3077 x_set_offset (f, new_left, new_top, 1);
3078 }
3079
3080 /* Don't set these parameters unless they've been explicitly
3081 specified. The window might be mapped or resized while we're in
3082 this function, and we don't want to override that unless the lisp
3083 code has asked for it.
3084
3085 Don't set these parameters unless they actually differ from the
3086 window's current parameters; the window may not actually exist
3087 yet. */
3088 {
3089 Lisp_Object frame;
3090
3091 check_frame_size (f, &height, &width);
3092
3093 XSETFRAME (frame, f);
3094
3095 if (width != FRAME_COLS (f)
3096 || height != FRAME_LINES (f)
3097 || f->new_text_lines || f->new_text_cols)
3098 Fset_frame_size (frame, make_number (width), make_number (height));
3099
3100 if ((!NILP (left) || !NILP (top))
3101 && ! (left_no_change && top_no_change)
3102 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3103 && NUMBERP (top) && XINT (top) == f->top_pos))
3104 {
3105 int leftpos = 0;
3106 int toppos = 0;
3107
3108 /* Record the signs. */
3109 f->size_hint_flags &= ~ (XNegative | YNegative);
3110 if (EQ (left, Qminus))
3111 f->size_hint_flags |= XNegative;
3112 else if (INTEGERP (left))
3113 {
3114 leftpos = XINT (left);
3115 if (leftpos < 0)
3116 f->size_hint_flags |= XNegative;
3117 }
3118 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3119 && CONSP (XCDR (left))
3120 && INTEGERP (XCAR (XCDR (left))))
3121 {
3122 leftpos = - XINT (XCAR (XCDR (left)));
3123 f->size_hint_flags |= XNegative;
3124 }
3125 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3126 && CONSP (XCDR (left))
3127 && INTEGERP (XCAR (XCDR (left))))
3128 {
3129 leftpos = XINT (XCAR (XCDR (left)));
3130 }
3131
3132 if (EQ (top, Qminus))
3133 f->size_hint_flags |= YNegative;
3134 else if (INTEGERP (top))
3135 {
3136 toppos = XINT (top);
3137 if (toppos < 0)
3138 f->size_hint_flags |= YNegative;
3139 }
3140 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3141 && CONSP (XCDR (top))
3142 && INTEGERP (XCAR (XCDR (top))))
3143 {
3144 toppos = - XINT (XCAR (XCDR (top)));
3145 f->size_hint_flags |= YNegative;
3146 }
3147 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3148 && CONSP (XCDR (top))
3149 && INTEGERP (XCAR (XCDR (top))))
3150 {
3151 toppos = XINT (XCAR (XCDR (top)));
3152 }
3153
3154
3155 /* Store the numeric value of the position. */
3156 f->top_pos = toppos;
3157 f->left_pos = leftpos;
3158
3159 f->win_gravity = NorthWestGravity;
3160
3161 /* Actually set that position, and convert to absolute. */
3162 x_set_offset (f, leftpos, toppos, -1);
3163 }
3164
3165 if ((!NILP (icon_left) || !NILP (icon_top))
3166 && ! (icon_left_no_change && icon_top_no_change))
3167 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3168 }
3169
3170 UNGCPRO;
3171 }
3172
3173
3174 /* Insert a description of internally-recorded parameters of frame X
3175 into the parameter alist *ALISTPTR that is to be given to the user.
3176 Only parameters that are specific to the X window system
3177 and whose values are not correctly recorded in the frame's
3178 param_alist need to be considered here. */
3179
3180 void
3181 x_report_frame_params (f, alistptr)
3182 struct frame *f;
3183 Lisp_Object *alistptr;
3184 {
3185 char buf[16];
3186 Lisp_Object tem;
3187
3188 /* Represent negative positions (off the top or left screen edge)
3189 in a way that Fmodify_frame_parameters will understand correctly. */
3190 XSETINT (tem, f->left_pos);
3191 if (f->left_pos >= 0)
3192 store_in_alist (alistptr, Qleft, tem);
3193 else
3194 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3195
3196 XSETINT (tem, f->top_pos);
3197 if (f->top_pos >= 0)
3198 store_in_alist (alistptr, Qtop, tem);
3199 else
3200 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3201
3202 store_in_alist (alistptr, Qborder_width,
3203 make_number (f->border_width));
3204 store_in_alist (alistptr, Qinternal_border_width,
3205 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3206 store_in_alist (alistptr, Qleft_fringe,
3207 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3208 store_in_alist (alistptr, Qright_fringe,
3209 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3210 store_in_alist (alistptr, Qscroll_bar_width,
3211 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3212 ? make_number (0)
3213 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3214 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3215 /* nil means "use default width"
3216 for non-toolkit scroll bar.
3217 ruler-mode.el depends on this. */
3218 : Qnil));
3219 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3220 store_in_alist (alistptr, Qwindow_id,
3221 build_string (buf));
3222 #ifdef HAVE_X_WINDOWS
3223 #ifdef USE_X_TOOLKIT
3224 /* Tooltip frame may not have this widget. */
3225 if (FRAME_X_OUTPUT (f)->widget)
3226 #endif
3227 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3228 store_in_alist (alistptr, Qouter_window_id,
3229 build_string (buf));
3230 #endif
3231 store_in_alist (alistptr, Qicon_name, f->icon_name);
3232 FRAME_SAMPLE_VISIBILITY (f);
3233 store_in_alist (alistptr, Qvisibility,
3234 (FRAME_VISIBLE_P (f) ? Qt
3235 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3236 store_in_alist (alistptr, Qdisplay,
3237 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3238
3239 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3240 tem = Qnil;
3241 else
3242 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3243 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3244 store_in_alist (alistptr, Qparent_id, tem);
3245 }
3246
3247
3248 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3249 the previous value of that parameter, NEW_VALUE is the new value. */
3250
3251 void
3252 x_set_fullscreen (f, new_value, old_value)
3253 struct frame *f;
3254 Lisp_Object new_value, old_value;
3255 {
3256 if (NILP (new_value))
3257 f->want_fullscreen = FULLSCREEN_NONE;
3258 else if (EQ (new_value, Qfullboth))
3259 f->want_fullscreen = FULLSCREEN_BOTH;
3260 else if (EQ (new_value, Qfullwidth))
3261 f->want_fullscreen = FULLSCREEN_WIDTH;
3262 else if (EQ (new_value, Qfullheight))
3263 f->want_fullscreen = FULLSCREEN_HEIGHT;
3264
3265 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3266 FRAME_TERMINAL (f)->fullscreen_hook (f);
3267 }
3268
3269
3270 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3271 the previous value of that parameter, NEW_VALUE is the new value. */
3272
3273 void
3274 x_set_line_spacing (f, new_value, old_value)
3275 struct frame *f;
3276 Lisp_Object new_value, old_value;
3277 {
3278 if (NILP (new_value))
3279 f->extra_line_spacing = 0;
3280 else if (NATNUMP (new_value))
3281 f->extra_line_spacing = XFASTINT (new_value);
3282 else
3283 signal_error ("Invalid line-spacing", new_value);
3284 if (FRAME_VISIBLE_P (f))
3285 redraw_frame (f);
3286 }
3287
3288
3289 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3290 the previous value of that parameter, NEW_VALUE is the new value. */
3291
3292 void
3293 x_set_screen_gamma (f, new_value, old_value)
3294 struct frame *f;
3295 Lisp_Object new_value, old_value;
3296 {
3297 Lisp_Object bgcolor;
3298
3299 if (NILP (new_value))
3300 f->gamma = 0;
3301 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3302 /* The value 0.4545 is the normal viewing gamma. */
3303 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3304 else
3305 signal_error ("Invalid screen-gamma", new_value);
3306
3307 /* Apply the new gamma value to the frame background. */
3308 bgcolor = Fassq (Qbackground_color, f->param_alist);
3309 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3310 {
3311 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3312 if (NATNUMP (index)
3313 && (XFASTINT (index)
3314 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3315 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3316 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3317 (f, bgcolor, Qnil);
3318 }
3319
3320 Fclear_face_cache (Qnil);
3321 }
3322
3323
3324 void
3325 x_set_font (f, arg, oldval)
3326 struct frame *f;
3327 Lisp_Object arg, oldval;
3328 {
3329 Lisp_Object frame;
3330 int fontset = -1;
3331 Lisp_Object font_object;
3332
3333 /* Set the frame parameter back to the old value because we mail
3334 fail to use ARG as the new parameter value. */
3335 store_frame_param (f, Qfont, oldval);
3336
3337 /* ARG is a fontset name, a font name, or a font object.
3338 In the last case, this function never fail. */
3339 if (STRINGP (arg))
3340 {
3341 fontset = fs_query_fontset (arg, 0);
3342 if (fontset < 0)
3343 {
3344 font_object = font_open_by_name (f, SDATA (arg));
3345 if (NILP (font_object))
3346 error ("Font `%s' is not defined", SDATA (arg));
3347 arg = AREF (font_object, FONT_NAME_INDEX);
3348 }
3349 else if (fontset > 0)
3350 {
3351 Lisp_Object ascii_font = fontset_ascii (fontset);
3352
3353 font_object = font_open_by_name (f, SDATA (ascii_font));
3354 if (NILP (font_object))
3355 error ("Font `%s' is not defined", SDATA (arg));
3356 arg = fontset_name (fontset);
3357 }
3358 else
3359 error ("The default fontset can't be used for a frame font");
3360 }
3361 else if (FONT_OBJECT_P (arg))
3362 {
3363 font_object = arg;
3364 /* This is store the XLFD font name in the frame parameter for
3365 backward compatiblity. We should store the font-object
3366 itself in the future. */
3367 arg = AREF (font_object, FONT_NAME_INDEX);
3368 }
3369 else
3370 signal_error ("Invalid font", arg);
3371
3372 if (! NILP (Fequal (font_object, oldval)))
3373 return;
3374 x_new_font (f, font_object, fontset);
3375 store_frame_param (f, Qfont, arg);
3376 /* Recalculate toolbar height. */
3377 f->n_tool_bar_rows = 0;
3378 /* Ensure we redraw it. */
3379 clear_current_matrices (f);
3380
3381 recompute_basic_faces (f);
3382
3383 do_pending_window_change (0);
3384
3385 /* We used to call face-set-after-frame-default here, but it leads to
3386 recursive calls (since that function can set the `default' face's
3387 font which in turns changes the frame's `font' parameter).
3388 Also I don't know what this call is meant to do, but it seems the
3389 wrong way to do it anyway (it does a lot more work than what seems
3390 reasonable in response to a change to `font'). */
3391 }
3392
3393
3394 void
3395 x_set_font_backend (f, new_value, old_value)
3396 struct frame *f;
3397 Lisp_Object new_value, old_value;
3398 {
3399 if (! NILP (new_value)
3400 && !CONSP (new_value))
3401 {
3402 char *p0, *p1;
3403
3404 CHECK_STRING (new_value);
3405 p0 = p1 = SDATA (new_value);
3406 new_value = Qnil;
3407 while (*p0)
3408 {
3409 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3410 if (p0 < p1)
3411 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3412 new_value);
3413 if (*p1)
3414 {
3415 int c;
3416
3417 while ((c = *++p1) && isspace (c));
3418 }
3419 p0 = p1;
3420 }
3421 new_value = Fnreverse (new_value);
3422 }
3423
3424 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3425 return;
3426
3427 if (FRAME_FONT (f))
3428 free_all_realized_faces (Qnil);
3429
3430 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3431 if (NILP (new_value))
3432 {
3433 if (NILP (old_value))
3434 error ("No font backend available");
3435 font_update_drivers (f, old_value);
3436 error ("None of specified font backends are available");
3437 }
3438 store_frame_param (f, Qfont_backend, new_value);
3439
3440 if (FRAME_FONT (f))
3441 {
3442 Lisp_Object frame;
3443
3444 XSETFRAME (frame, f);
3445 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3446 ++face_change_count;
3447 ++windows_or_buffers_changed;
3448 }
3449 }
3450
3451
3452 void
3453 x_set_fringe_width (f, new_value, old_value)
3454 struct frame *f;
3455 Lisp_Object new_value, old_value;
3456 {
3457 compute_fringe_widths (f, 1);
3458 }
3459
3460 void
3461 x_set_border_width (f, arg, oldval)
3462 struct frame *f;
3463 Lisp_Object arg, oldval;
3464 {
3465 CHECK_NUMBER (arg);
3466
3467 if (XINT (arg) == f->border_width)
3468 return;
3469
3470 if (FRAME_X_WINDOW (f) != 0)
3471 error ("Cannot change the border width of a frame");
3472
3473 f->border_width = XINT (arg);
3474 }
3475
3476 void
3477 x_set_internal_border_width (f, arg, oldval)
3478 struct frame *f;
3479 Lisp_Object arg, oldval;
3480 {
3481 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3482
3483 CHECK_NUMBER (arg);
3484 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3485 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3486 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3487
3488 #ifdef USE_X_TOOLKIT
3489 if (FRAME_X_OUTPUT (f)->edit_widget)
3490 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3491 #endif
3492
3493 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3494 return;
3495
3496 if (FRAME_X_WINDOW (f) != 0)
3497 {
3498 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3499 SET_FRAME_GARBAGED (f);
3500 do_pending_window_change (0);
3501 }
3502 else
3503 SET_FRAME_GARBAGED (f);
3504 }
3505
3506 void
3507 x_set_visibility (f, value, oldval)
3508 struct frame *f;
3509 Lisp_Object value, oldval;
3510 {
3511 Lisp_Object frame;
3512 XSETFRAME (frame, f);
3513
3514 if (NILP (value))
3515 Fmake_frame_invisible (frame, Qt);
3516 else if (EQ (value, Qicon))
3517 Ficonify_frame (frame);
3518 else
3519 Fmake_frame_visible (frame);
3520 }
3521
3522 void
3523 x_set_autoraise (f, arg, oldval)
3524 struct frame *f;
3525 Lisp_Object arg, oldval;
3526 {
3527 f->auto_raise = !EQ (Qnil, arg);
3528 }
3529
3530 void
3531 x_set_autolower (f, arg, oldval)
3532 struct frame *f;
3533 Lisp_Object arg, oldval;
3534 {
3535 f->auto_lower = !EQ (Qnil, arg);
3536 }
3537
3538 void
3539 x_set_unsplittable (f, arg, oldval)
3540 struct frame *f;
3541 Lisp_Object arg, oldval;
3542 {
3543 f->no_split = !NILP (arg);
3544 }
3545
3546 void
3547 x_set_vertical_scroll_bars (f, arg, oldval)
3548 struct frame *f;
3549 Lisp_Object arg, oldval;
3550 {
3551 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3552 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3553 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3554 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3555 {
3556 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3557 = (NILP (arg)
3558 ? vertical_scroll_bar_none
3559 : EQ (Qleft, arg)
3560 ? vertical_scroll_bar_left
3561 : EQ (Qright, arg)
3562 ? vertical_scroll_bar_right
3563 : EQ (Qleft, Vdefault_frame_scroll_bars)
3564 ? vertical_scroll_bar_left
3565 : EQ (Qright, Vdefault_frame_scroll_bars)
3566 ? vertical_scroll_bar_right
3567 : vertical_scroll_bar_none);
3568
3569 /* We set this parameter before creating the X window for the
3570 frame, so we can get the geometry right from the start.
3571 However, if the window hasn't been created yet, we shouldn't
3572 call x_set_window_size. */
3573 if (FRAME_X_WINDOW (f))
3574 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3575 do_pending_window_change (0);
3576 }
3577 }
3578
3579 void
3580 x_set_scroll_bar_width (f, arg, oldval)
3581 struct frame *f;
3582 Lisp_Object arg, oldval;
3583 {
3584 int wid = FRAME_COLUMN_WIDTH (f);
3585
3586 if (NILP (arg))
3587 {
3588 x_set_scroll_bar_default_width (f);
3589
3590 if (FRAME_X_WINDOW (f))
3591 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3592 do_pending_window_change (0);
3593 }
3594 else if (INTEGERP (arg) && XINT (arg) > 0
3595 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3596 {
3597 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3598 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3599
3600 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3601 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3602 if (FRAME_X_WINDOW (f))
3603 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3604 do_pending_window_change (0);
3605 }
3606
3607 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3608 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3609 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3610 }
3611
3612
3613
3614 /* Return non-nil if frame F wants a bitmap icon. */
3615
3616 Lisp_Object
3617 x_icon_type (f)
3618 FRAME_PTR f;
3619 {
3620 Lisp_Object tem;
3621
3622 tem = assq_no_quit (Qicon_type, f->param_alist);
3623 if (CONSP (tem))
3624 return XCDR (tem);
3625 else
3626 return Qnil;
3627 }
3628
3629 void
3630 x_set_alpha (f, arg, oldval)
3631 struct frame *f;
3632 Lisp_Object arg, oldval;
3633 {
3634 double alpha = 1.0;
3635 double newval[2];
3636 int i, ialpha;
3637 Lisp_Object item;
3638
3639 for (i = 0; i < 2; i++)
3640 {
3641 newval[i] = 1.0;
3642 if (CONSP (arg))
3643 {
3644 item = CAR (arg);
3645 arg = CDR (arg);
3646 }
3647 else
3648 item = arg;
3649
3650 if (! NILP (item))
3651 {
3652 if (FLOATP (item))
3653 {
3654 alpha = XFLOAT_DATA (item);
3655 if (alpha < 0.0 || 1.0 < alpha)
3656 args_out_of_range (make_float (0.0), make_float (1.0));
3657 }
3658 else if (INTEGERP (item))
3659 {
3660 ialpha = XINT (item);
3661 if (ialpha < 0 || 100 < ialpha)
3662 args_out_of_range (make_number (0), make_number (100));
3663 else
3664 alpha = ialpha / 100.0;
3665 }
3666 else
3667 wrong_type_argument (Qnumberp, item);
3668 }
3669 newval[i] = alpha;
3670 }
3671
3672 for (i = 0; i < 2; i++)
3673 f->alpha[i] = newval[i];
3674
3675 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
3676 BLOCK_INPUT;
3677 x_set_frame_alpha (f);
3678 UNBLOCK_INPUT;
3679 #endif
3680
3681 return;
3682 }
3683
3684 \f
3685 /* Subroutines of creating an X frame. */
3686
3687 /* Make sure that Vx_resource_name is set to a reasonable value.
3688 Fix it up, or set it to `emacs' if it is too hopeless. */
3689
3690 void
3691 validate_x_resource_name ()
3692 {
3693 int len = 0;
3694 /* Number of valid characters in the resource name. */
3695 int good_count = 0;
3696 /* Number of invalid characters in the resource name. */
3697 int bad_count = 0;
3698 Lisp_Object new;
3699 int i;
3700
3701 if (!STRINGP (Vx_resource_class))
3702 Vx_resource_class = build_string (EMACS_CLASS);
3703
3704 if (STRINGP (Vx_resource_name))
3705 {
3706 unsigned char *p = SDATA (Vx_resource_name);
3707 int i;
3708
3709 len = SBYTES (Vx_resource_name);
3710
3711 /* Only letters, digits, - and _ are valid in resource names.
3712 Count the valid characters and count the invalid ones. */
3713 for (i = 0; i < len; i++)
3714 {
3715 int c = p[i];
3716 if (! ((c >= 'a' && c <= 'z')
3717 || (c >= 'A' && c <= 'Z')
3718 || (c >= '0' && c <= '9')
3719 || c == '-' || c == '_'))
3720 bad_count++;
3721 else
3722 good_count++;
3723 }
3724 }
3725 else
3726 /* Not a string => completely invalid. */
3727 bad_count = 5, good_count = 0;
3728
3729 /* If name is valid already, return. */
3730 if (bad_count == 0)
3731 return;
3732
3733 /* If name is entirely invalid, or nearly so, use `emacs'. */
3734 if (good_count == 0
3735 || (good_count == 1 && bad_count > 0))
3736 {
3737 Vx_resource_name = build_string ("emacs");
3738 return;
3739 }
3740
3741 /* Name is partly valid. Copy it and replace the invalid characters
3742 with underscores. */
3743
3744 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3745
3746 for (i = 0; i < len; i++)
3747 {
3748 int c = SREF (new, i);
3749 if (! ((c >= 'a' && c <= 'z')
3750 || (c >= 'A' && c <= 'Z')
3751 || (c >= '0' && c <= '9')
3752 || c == '-' || c == '_'))
3753 SSET (new, i, '_');
3754 }
3755 }
3756
3757
3758 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3759 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3760
3761
3762 /* Get specified attribute from resource database RDB.
3763 See Fx_get_resource below for other parameters. */
3764
3765 static Lisp_Object
3766 xrdb_get_resource (rdb, attribute, class, component, subclass)
3767 XrmDatabase rdb;
3768 Lisp_Object attribute, class, component, subclass;
3769 {
3770 register char *value;
3771 char *name_key;
3772 char *class_key;
3773
3774 CHECK_STRING (attribute);
3775 CHECK_STRING (class);
3776
3777 if (!NILP (component))
3778 CHECK_STRING (component);
3779 if (!NILP (subclass))
3780 CHECK_STRING (subclass);
3781 if (NILP (component) != NILP (subclass))
3782 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3783
3784 validate_x_resource_name ();
3785
3786 /* Allocate space for the components, the dots which separate them,
3787 and the final '\0'. Make them big enough for the worst case. */
3788 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3789 + (STRINGP (component)
3790 ? SBYTES (component) : 0)
3791 + SBYTES (attribute)
3792 + 3);
3793
3794 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3795 + SBYTES (class)
3796 + (STRINGP (subclass)
3797 ? SBYTES (subclass) : 0)
3798 + 3);
3799
3800 /* Start with emacs.FRAMENAME for the name (the specific one)
3801 and with `Emacs' for the class key (the general one). */
3802 strcpy (name_key, SDATA (Vx_resource_name));
3803 strcpy (class_key, SDATA (Vx_resource_class));
3804
3805 strcat (class_key, ".");
3806 strcat (class_key, SDATA (class));
3807
3808 if (!NILP (component))
3809 {
3810 strcat (class_key, ".");
3811 strcat (class_key, SDATA (subclass));
3812
3813 strcat (name_key, ".");
3814 strcat (name_key, SDATA (component));
3815 }
3816
3817 strcat (name_key, ".");
3818 strcat (name_key, SDATA (attribute));
3819
3820 value = x_get_string_resource (rdb, name_key, class_key);
3821
3822 if (value != (char *) 0)
3823 return build_string (value);
3824 else
3825 return Qnil;
3826 }
3827
3828
3829 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3830 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3831 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3832 class, where INSTANCE is the name under which Emacs was invoked, or
3833 the name specified by the `-name' or `-rn' command-line arguments.
3834
3835 The optional arguments COMPONENT and SUBCLASS add to the key and the
3836 class, respectively. You must specify both of them or neither.
3837 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3838 and the class is `Emacs.CLASS.SUBCLASS'. */)
3839 (attribute, class, component, subclass)
3840 Lisp_Object attribute, class, component, subclass;
3841 {
3842 #ifdef HAVE_X_WINDOWS
3843 check_x ();
3844 #endif
3845
3846 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3847 attribute, class, component, subclass);
3848 }
3849
3850 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3851
3852 Lisp_Object
3853 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3854 Display_Info *dpyinfo;
3855 Lisp_Object attribute, class, component, subclass;
3856 {
3857 return xrdb_get_resource (dpyinfo->xrdb,
3858 attribute, class, component, subclass);
3859 }
3860
3861 /* Used when C code wants a resource value. */
3862
3863 char *
3864 x_get_resource_string (attribute, class)
3865 char *attribute, *class;
3866 {
3867 char *name_key;
3868 char *class_key;
3869 struct frame *sf = SELECTED_FRAME ();
3870
3871 /* Allocate space for the components, the dots which separate them,
3872 and the final '\0'. */
3873 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3874 + strlen (attribute) + 2);
3875 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3876 + strlen (class) + 2);
3877
3878 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3879 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3880
3881 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3882 name_key, class_key);
3883 }
3884
3885
3886 /* Return the value of parameter PARAM.
3887
3888 First search ALIST, then Vdefault_frame_alist, then the X defaults
3889 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3890
3891 Convert the resource to the type specified by desired_type.
3892
3893 If no default is specified, return Qunbound. If you call
3894 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3895 and don't let it get stored in any Lisp-visible variables! */
3896
3897 Lisp_Object
3898 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3899 Display_Info *dpyinfo;
3900 Lisp_Object alist, param;
3901 char *attribute;
3902 char *class;
3903 enum resource_types type;
3904 {
3905 register Lisp_Object tem;
3906
3907 tem = Fassq (param, alist);
3908
3909 if (!NILP (tem))
3910 {
3911 /* If we find this parm in ALIST, clear it out
3912 so that it won't be "left over" at the end. */
3913 #ifndef WINDOWSNT /* w32fns.c has not yet been changed to cope with this. */
3914 Lisp_Object tail;
3915 XSETCAR (tem, Qnil);
3916 /* In case the parameter appears more than once in the alist,
3917 clear it out. */
3918 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3919 if (CONSP (XCAR (tail))
3920 && EQ (XCAR (XCAR (tail)), param))
3921 XSETCAR (XCAR (tail), Qnil);
3922 #endif
3923 }
3924 else
3925 tem = Fassq (param, Vdefault_frame_alist);
3926
3927 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3928 look in the X resources. */
3929 if (EQ (tem, Qnil))
3930 {
3931 if (attribute)
3932 {
3933 tem = display_x_get_resource (dpyinfo,
3934 build_string (attribute),
3935 build_string (class),
3936 Qnil, Qnil);
3937
3938 if (NILP (tem))
3939 return Qunbound;
3940
3941 switch (type)
3942 {
3943 case RES_TYPE_NUMBER:
3944 return make_number (atoi (SDATA (tem)));
3945
3946 case RES_TYPE_FLOAT:
3947 return make_float (atof (SDATA (tem)));
3948
3949 case RES_TYPE_BOOLEAN:
3950 tem = Fdowncase (tem);
3951 if (!strcmp (SDATA (tem), "on")
3952 || !strcmp (SDATA (tem), "true"))
3953 return Qt;
3954 else
3955 return Qnil;
3956
3957 case RES_TYPE_STRING:
3958 return tem;
3959
3960 case RES_TYPE_SYMBOL:
3961 /* As a special case, we map the values `true' and `on'
3962 to Qt, and `false' and `off' to Qnil. */
3963 {
3964 Lisp_Object lower;
3965 lower = Fdowncase (tem);
3966 if (!strcmp (SDATA (lower), "on")
3967 || !strcmp (SDATA (lower), "true"))
3968 return Qt;
3969 else if (!strcmp (SDATA (lower), "off")
3970 || !strcmp (SDATA (lower), "false"))
3971 return Qnil;
3972 else
3973 return Fintern (tem, Qnil);
3974 }
3975
3976 default:
3977 abort ();
3978 }
3979 }
3980 else
3981 return Qunbound;
3982 }
3983 return Fcdr (tem);
3984 }
3985
3986 Lisp_Object
3987 x_frame_get_arg (f, alist, param, attribute, class, type)
3988 struct frame *f;
3989 Lisp_Object alist, param;
3990 char *attribute;
3991 char *class;
3992 enum resource_types type;
3993 {
3994 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3995 alist, param, attribute, class, type);
3996 }
3997
3998 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3999
4000 Lisp_Object
4001 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
4002 struct frame *f;
4003 Lisp_Object alist, param;
4004 char *attribute;
4005 char *class;
4006 enum resource_types type;
4007 {
4008 Lisp_Object value;
4009
4010 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
4011 attribute, class, type);
4012 if (! NILP (value) && ! EQ (value, Qunbound))
4013 store_frame_param (f, param, value);
4014
4015 return value;
4016 }
4017
4018
4019 /* Record in frame F the specified or default value according to ALIST
4020 of the parameter named PROP (a Lisp symbol).
4021 If no value is specified for PROP, look for an X default for XPROP
4022 on the frame named NAME.
4023 If that is not found either, use the value DEFLT. */
4024
4025 Lisp_Object
4026 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
4027 struct frame *f;
4028 Lisp_Object alist;
4029 Lisp_Object prop;
4030 Lisp_Object deflt;
4031 char *xprop;
4032 char *xclass;
4033 enum resource_types type;
4034 {
4035 Lisp_Object tem;
4036
4037 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4038 if (EQ (tem, Qunbound))
4039 tem = deflt;
4040 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
4041 return tem;
4042 }
4043
4044
4045
4046 \f
4047 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4048 doc: /* Parse an X-style geometry string STRING.
4049 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4050 The properties returned may include `top', `left', `height', and `width'.
4051 The value of `left' or `top' may be an integer,
4052 or a list (+ N) meaning N pixels relative to top/left corner,
4053 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
4054 (string)
4055 Lisp_Object string;
4056 {
4057 int geometry, x, y;
4058 unsigned int width, height;
4059 Lisp_Object result;
4060
4061 CHECK_STRING (string);
4062
4063 geometry = XParseGeometry ((char *) SDATA (string),
4064 &x, &y, &width, &height);
4065
4066 #if 0
4067 if (!!(geometry & XValue) != !!(geometry & YValue))
4068 error ("Must specify both x and y position, or neither");
4069 #endif
4070
4071 result = Qnil;
4072 if (geometry & XValue)
4073 {
4074 Lisp_Object element;
4075
4076 if (x >= 0 && (geometry & XNegative))
4077 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
4078 else if (x < 0 && ! (geometry & XNegative))
4079 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
4080 else
4081 element = Fcons (Qleft, make_number (x));
4082 result = Fcons (element, result);
4083 }
4084
4085 if (geometry & YValue)
4086 {
4087 Lisp_Object element;
4088
4089 if (y >= 0 && (geometry & YNegative))
4090 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
4091 else if (y < 0 && ! (geometry & YNegative))
4092 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
4093 else
4094 element = Fcons (Qtop, make_number (y));
4095 result = Fcons (element, result);
4096 }
4097
4098 if (geometry & WidthValue)
4099 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4100 if (geometry & HeightValue)
4101 result = Fcons (Fcons (Qheight, make_number (height)), result);
4102
4103 return result;
4104 }
4105
4106 /* Calculate the desired size and position of frame F.
4107 Return the flags saying which aspects were specified.
4108
4109 Also set the win_gravity and size_hint_flags of F.
4110
4111 Adjust height for toolbar if TOOLBAR_P is 1.
4112
4113 This function does not make the coordinates positive. */
4114
4115 #define DEFAULT_ROWS 40
4116 #define DEFAULT_COLS 80
4117
4118 int
4119 x_figure_window_size (f, parms, toolbar_p)
4120 struct frame *f;
4121 Lisp_Object parms;
4122 int toolbar_p;
4123 {
4124 register Lisp_Object tem0, tem1, tem2;
4125 long window_prompting = 0;
4126 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4127
4128 /* Default values if we fall through.
4129 Actually, if that happens we should get
4130 window manager prompting. */
4131 SET_FRAME_COLS (f, DEFAULT_COLS);
4132 FRAME_LINES (f) = DEFAULT_ROWS;
4133 /* Window managers expect that if program-specified
4134 positions are not (0,0), they're intentional, not defaults. */
4135 f->top_pos = 0;
4136 f->left_pos = 0;
4137
4138 /* Ensure that old new_text_cols and new_text_lines will not override the
4139 values set here. */
4140 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4141 f->new_text_cols = f->new_text_lines = 0;
4142
4143 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4144 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4145 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4146 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4147 {
4148 if (!EQ (tem0, Qunbound))
4149 {
4150 CHECK_NUMBER (tem0);
4151 FRAME_LINES (f) = XINT (tem0);
4152 }
4153 if (!EQ (tem1, Qunbound))
4154 {
4155 CHECK_NUMBER (tem1);
4156 SET_FRAME_COLS (f, XINT (tem1));
4157 }
4158 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4159 window_prompting |= USSize;
4160 else
4161 window_prompting |= PSize;
4162 }
4163
4164 f->scroll_bar_actual_width
4165 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4166
4167 /* This used to be done _before_ calling x_figure_window_size, but
4168 since the height is reset here, this was really a no-op. I
4169 assume that moving it here does what Gerd intended (although he
4170 no longer can remember what that was... ++KFS, 2003-03-25. */
4171
4172 /* Add the tool-bar height to the initial frame height so that the
4173 user gets a text display area of the size he specified with -g or
4174 via .Xdefaults. Later changes of the tool-bar height don't
4175 change the frame size. This is done so that users can create
4176 tall Emacs frames without having to guess how tall the tool-bar
4177 will get. */
4178 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4179 {
4180 int margin, relief, bar_height;
4181
4182 relief = (tool_bar_button_relief >= 0
4183 ? tool_bar_button_relief
4184 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4185
4186 if (INTEGERP (Vtool_bar_button_margin)
4187 && XINT (Vtool_bar_button_margin) > 0)
4188 margin = XFASTINT (Vtool_bar_button_margin);
4189 else if (CONSP (Vtool_bar_button_margin)
4190 && INTEGERP (XCDR (Vtool_bar_button_margin))
4191 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4192 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4193 else
4194 margin = 0;
4195
4196 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4197 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4198 }
4199
4200 compute_fringe_widths (f, 0);
4201
4202 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4203 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4204
4205 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4206 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4207 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4208 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4209 {
4210 if (EQ (tem0, Qminus))
4211 {
4212 f->top_pos = 0;
4213 window_prompting |= YNegative;
4214 }
4215 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4216 && CONSP (XCDR (tem0))
4217 && INTEGERP (XCAR (XCDR (tem0))))
4218 {
4219 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4220 window_prompting |= YNegative;
4221 }
4222 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4223 && CONSP (XCDR (tem0))
4224 && INTEGERP (XCAR (XCDR (tem0))))
4225 {
4226 f->top_pos = XINT (XCAR (XCDR (tem0)));
4227 }
4228 else if (EQ (tem0, Qunbound))
4229 f->top_pos = 0;
4230 else
4231 {
4232 CHECK_NUMBER (tem0);
4233 f->top_pos = XINT (tem0);
4234 if (f->top_pos < 0)
4235 window_prompting |= YNegative;
4236 }
4237
4238 if (EQ (tem1, Qminus))
4239 {
4240 f->left_pos = 0;
4241 window_prompting |= XNegative;
4242 }
4243 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4244 && CONSP (XCDR (tem1))
4245 && INTEGERP (XCAR (XCDR (tem1))))
4246 {
4247 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4248 window_prompting |= XNegative;
4249 }
4250 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4251 && CONSP (XCDR (tem1))
4252 && INTEGERP (XCAR (XCDR (tem1))))
4253 {
4254 f->left_pos = XINT (XCAR (XCDR (tem1)));
4255 }
4256 else if (EQ (tem1, Qunbound))
4257 f->left_pos = 0;
4258 else
4259 {
4260 CHECK_NUMBER (tem1);
4261 f->left_pos = XINT (tem1);
4262 if (f->left_pos < 0)
4263 window_prompting |= XNegative;
4264 }
4265
4266 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4267 window_prompting |= USPosition;
4268 else
4269 window_prompting |= PPosition;
4270 }
4271
4272 if (f->want_fullscreen != FULLSCREEN_NONE)
4273 {
4274 int left, top;
4275 int width, height;
4276
4277 /* It takes both for some WM:s to place it where we want */
4278 window_prompting |= USPosition | PPosition;
4279 x_fullscreen_adjust (f, &width, &height, &top, &left);
4280 FRAME_COLS (f) = width;
4281 FRAME_LINES (f) = height;
4282 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4283 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4284 f->left_pos = left;
4285 f->top_pos = top;
4286 }
4287
4288 if (window_prompting & XNegative)
4289 {
4290 if (window_prompting & YNegative)
4291 f->win_gravity = SouthEastGravity;
4292 else
4293 f->win_gravity = NorthEastGravity;
4294 }
4295 else
4296 {
4297 if (window_prompting & YNegative)
4298 f->win_gravity = SouthWestGravity;
4299 else
4300 f->win_gravity = NorthWestGravity;
4301 }
4302
4303 f->size_hint_flags = window_prompting;
4304
4305 return window_prompting;
4306 }
4307
4308
4309
4310 #endif /* HAVE_WINDOW_SYSTEM */
4311
4312
4313 \f
4314 /***********************************************************************
4315 Initialization
4316 ***********************************************************************/
4317
4318 void
4319 syms_of_frame ()
4320 {
4321 Qframep = intern ("framep");
4322 staticpro (&Qframep);
4323 Qframe_live_p = intern ("frame-live-p");
4324 staticpro (&Qframe_live_p);
4325 Qexplicit_name = intern ("explicit-name");
4326 staticpro (&Qexplicit_name);
4327 Qheight = intern ("height");
4328 staticpro (&Qheight);
4329 Qicon = intern ("icon");
4330 staticpro (&Qicon);
4331 Qminibuffer = intern ("minibuffer");
4332 staticpro (&Qminibuffer);
4333 Qmodeline = intern ("modeline");
4334 staticpro (&Qmodeline);
4335 Qonly = intern ("only");
4336 staticpro (&Qonly);
4337 Qwidth = intern ("width");
4338 staticpro (&Qwidth);
4339 Qgeometry = intern ("geometry");
4340 staticpro (&Qgeometry);
4341 Qicon_left = intern ("icon-left");
4342 staticpro (&Qicon_left);
4343 Qicon_top = intern ("icon-top");
4344 staticpro (&Qicon_top);
4345 Qleft = intern ("left");
4346 staticpro (&Qleft);
4347 Qright = intern ("right");
4348 staticpro (&Qright);
4349 Quser_position = intern ("user-position");
4350 staticpro (&Quser_position);
4351 Quser_size = intern ("user-size");
4352 staticpro (&Quser_size);
4353 Qwindow_id = intern ("window-id");
4354 staticpro (&Qwindow_id);
4355 #ifdef HAVE_X_WINDOWS
4356 Qouter_window_id = intern ("outer-window-id");
4357 staticpro (&Qouter_window_id);
4358 #endif
4359 Qparent_id = intern ("parent-id");
4360 staticpro (&Qparent_id);
4361 Qx = intern ("x");
4362 staticpro (&Qx);
4363 Qw32 = intern ("w32");
4364 staticpro (&Qw32);
4365 Qpc = intern ("pc");
4366 staticpro (&Qpc);
4367 Qmac = intern ("mac");
4368 staticpro (&Qmac);
4369 Qvisible = intern ("visible");
4370 staticpro (&Qvisible);
4371 Qbuffer_predicate = intern ("buffer-predicate");
4372 staticpro (&Qbuffer_predicate);
4373 Qbuffer_list = intern ("buffer-list");
4374 staticpro (&Qbuffer_list);
4375 Qburied_buffer_list = intern ("buried-buffer-list");
4376 staticpro (&Qburied_buffer_list);
4377 Qdisplay_type = intern ("display-type");
4378 staticpro (&Qdisplay_type);
4379 Qbackground_mode = intern ("background-mode");
4380 staticpro (&Qbackground_mode);
4381 Qnoelisp = intern ("noelisp");
4382 staticpro (&Qnoelisp);
4383 Qtty_color_mode = intern ("tty-color-mode");
4384 staticpro (&Qtty_color_mode);
4385 Qtty = intern ("tty");
4386 staticpro (&Qtty);
4387 Qtty_type = intern ("tty-type");
4388 staticpro (&Qtty_type);
4389
4390 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4391 staticpro (&Qface_set_after_frame_default);
4392
4393 Qfullwidth = intern ("fullwidth");
4394 staticpro (&Qfullwidth);
4395 Qfullheight = intern ("fullheight");
4396 staticpro (&Qfullheight);
4397 Qfullboth = intern ("fullboth");
4398 staticpro (&Qfullboth);
4399 Qx_resource_name = intern ("x-resource-name");
4400 staticpro (&Qx_resource_name);
4401
4402 Qx_frame_parameter = intern ("x-frame-parameter");
4403 staticpro (&Qx_frame_parameter);
4404
4405 Qterminal = intern ("terminal");
4406 staticpro (&Qterminal);
4407 Qterminal_live_p = intern ("terminal-live-p");
4408 staticpro (&Qterminal_live_p);
4409
4410 {
4411 int i;
4412
4413 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4414 {
4415 Lisp_Object v = intern (frame_parms[i].name);
4416 if (frame_parms[i].variable)
4417 {
4418 *frame_parms[i].variable = v;
4419 staticpro (frame_parms[i].variable);
4420 }
4421 Fput (v, Qx_frame_parameter, make_number (i));
4422 }
4423 }
4424
4425 #ifdef HAVE_WINDOW_SYSTEM
4426 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4427 doc: /* The name Emacs uses to look up X resources.
4428 `x-get-resource' uses this as the first component of the instance name
4429 when requesting resource values.
4430 Emacs initially sets `x-resource-name' to the name under which Emacs
4431 was invoked, or to the value specified with the `-name' or `-rn'
4432 switches, if present.
4433
4434 It may be useful to bind this variable locally around a call
4435 to `x-get-resource'. See also the variable `x-resource-class'. */);
4436 Vx_resource_name = Qnil;
4437
4438 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4439 doc: /* The class Emacs uses to look up X resources.
4440 `x-get-resource' uses this as the first component of the instance class
4441 when requesting resource values.
4442
4443 Emacs initially sets `x-resource-class' to "Emacs".
4444
4445 Setting this variable permanently is not a reasonable thing to do,
4446 but binding this variable locally around a call to `x-get-resource'
4447 is a reasonable practice. See also the variable `x-resource-name'. */);
4448 Vx_resource_class = build_string (EMACS_CLASS);
4449
4450 DEFVAR_LISP ("frame-alpha-lower-limit", &Vframe_alpha_lower_limit,
4451 doc: /* The lower limit of the frame opacity (alpha transparency).
4452 The value should range from 0 (invisible) to 100 (completely opaque).
4453 You can also use a floating number between 0.0 and 1.0.
4454 The default is 20. */);
4455 Vframe_alpha_lower_limit = make_number (20);
4456 #endif
4457
4458 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4459 doc: /* Alist of default values for frame creation.
4460 These may be set in your init file, like this:
4461 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4462 These override values given in window system configuration data,
4463 including X Windows' defaults database.
4464 For values specific to the first Emacs frame, see `initial-frame-alist'.
4465 For window-system specific values, see `window-system-default-frame-alist'.
4466 For values specific to the separate minibuffer frame, see
4467 `minibuffer-frame-alist'.
4468 The `menu-bar-lines' element of the list controls whether new frames
4469 have menu bars; `menu-bar-mode' works by altering this element.
4470 Setting this variable does not affect existing frames, only new ones. */);
4471 Vdefault_frame_alist = Qnil;
4472
4473 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4474 doc: /* Default position of scroll bars on this window-system. */);
4475 #ifdef HAVE_WINDOW_SYSTEM
4476 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4477 /* MS-Windows has scroll bars on the right by default. */
4478 Vdefault_frame_scroll_bars = Qright;
4479 #else
4480 Vdefault_frame_scroll_bars = Qleft;
4481 #endif
4482 #else
4483 Vdefault_frame_scroll_bars = Qnil;
4484 #endif
4485
4486 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4487 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4488
4489 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4490 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
4491 Vemacs_iconified = Qnil;
4492
4493 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4494 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4495 `mouse-position' calls this function, passing its usual return value as
4496 argument, and returns whatever this function returns.
4497 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4498 which need to do mouse handling at the Lisp level. */);
4499 Vmouse_position_function = Qnil;
4500
4501 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4502 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4503 If the value is an integer, highlighting is only shown after moving the
4504 mouse, while keyboard input turns off the highlight even when the mouse
4505 is over the clickable text. However, the mouse shape still indicates
4506 when the mouse is over clickable text. */);
4507 Vmouse_highlight = Qt;
4508
4509 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4510 doc: /* Functions to be run before deleting a frame.
4511 The functions are run with one arg, the frame to be deleted.
4512 See `delete-frame'.
4513
4514 Note that functions in this list may be called just before the frame is
4515 actually deleted, or some time later (or even both when an earlier function
4516 in `delete-frame-functions' (indirectly) calls `delete-frame'
4517 recursively). */);
4518 Vdelete_frame_functions = Qnil;
4519 Qdelete_frame_functions = intern ("delete-frame-functions");
4520 staticpro (&Qdelete_frame_functions);
4521
4522 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4523 doc: /* Minibufferless frames use this frame's minibuffer.
4524
4525 Emacs cannot create minibufferless frames unless this is set to an
4526 appropriate surrogate.
4527
4528 Emacs consults this variable only when creating minibufferless
4529 frames; once the frame is created, it sticks with its assigned
4530 minibuffer, no matter what this variable is set to. This means that
4531 this variable doesn't necessarily say anything meaningful about the
4532 current set of frames, or where the minibuffer is currently being
4533 displayed.
4534
4535 This variable is local to the current terminal and cannot be buffer-local. */);
4536
4537 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse,
4538 doc: /* Non-nil if window system changes focus when you move the mouse.
4539 You should set this variable to tell Emacs how your window manager
4540 handles focus, since there is no way in general for Emacs to find out
4541 automatically. */);
4542 #ifdef HAVE_WINDOW_SYSTEM
4543 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4544 focus_follows_mouse = 0;
4545 #else
4546 focus_follows_mouse = 1;
4547 #endif
4548 #else
4549 focus_follows_mouse = 0;
4550 #endif
4551
4552 staticpro (&Vframe_list);
4553
4554 defsubr (&Sactive_minibuffer_window);
4555 defsubr (&Sframep);
4556 defsubr (&Sframe_live_p);
4557 defsubr (&Swindow_system);
4558 defsubr (&Smake_terminal_frame);
4559 defsubr (&Shandle_switch_frame);
4560 defsubr (&Sselect_frame);
4561 defsubr (&Sselected_frame);
4562 defsubr (&Swindow_frame);
4563 defsubr (&Sframe_root_window);
4564 defsubr (&Sframe_first_window);
4565 defsubr (&Sframe_selected_window);
4566 defsubr (&Sset_frame_selected_window);
4567 defsubr (&Sframe_list);
4568 defsubr (&Snext_frame);
4569 defsubr (&Sprevious_frame);
4570 defsubr (&Sdelete_frame);
4571 defsubr (&Smouse_position);
4572 defsubr (&Smouse_pixel_position);
4573 defsubr (&Sset_mouse_position);
4574 defsubr (&Sset_mouse_pixel_position);
4575 #if 0
4576 defsubr (&Sframe_configuration);
4577 defsubr (&Srestore_frame_configuration);
4578 #endif
4579 defsubr (&Smake_frame_visible);
4580 defsubr (&Smake_frame_invisible);
4581 defsubr (&Siconify_frame);
4582 defsubr (&Sframe_visible_p);
4583 defsubr (&Svisible_frame_list);
4584 defsubr (&Sraise_frame);
4585 defsubr (&Slower_frame);
4586 defsubr (&Sredirect_frame_focus);
4587 defsubr (&Sframe_focus);
4588 defsubr (&Sframe_parameters);
4589 defsubr (&Sframe_parameter);
4590 defsubr (&Smodify_frame_parameters);
4591 defsubr (&Sframe_char_height);
4592 defsubr (&Sframe_char_width);
4593 defsubr (&Sframe_pixel_height);
4594 defsubr (&Sframe_pixel_width);
4595 defsubr (&Sset_frame_height);
4596 defsubr (&Sset_frame_width);
4597 defsubr (&Sset_frame_size);
4598 defsubr (&Sset_frame_position);
4599
4600 #ifdef HAVE_WINDOW_SYSTEM
4601 defsubr (&Sx_get_resource);
4602 defsubr (&Sx_parse_geometry);
4603 #endif
4604
4605 }
4606
4607 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4608 (do not change this comment) */