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