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