Merge from trunk
[bpt/emacs.git] / src / frame.c
1 /* Generic frame functions.
2
3 Copyright (C) 1993-1995, 1997, 1999-2012 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 initialized 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 Lisp_Object frames;
1122
1123 for (frames = Vframe_list; CONSP (frames); frames = XCDR (frames))
1124 {
1125 Lisp_Object this = XCAR (frames);
1126 if (f == XFRAME (this))
1127 continue;
1128
1129 /* Verify that we can still talk to the frame's X window,
1130 and note any recent change in visibility. */
1131 #ifdef HAVE_WINDOW_SYSTEM
1132 if (FRAME_WINDOW_P (XFRAME (this)))
1133 {
1134 x_sync (XFRAME (this));
1135 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1136 }
1137 #endif
1138
1139 if (FRAME_VISIBLE_P (XFRAME (this))
1140 || FRAME_ICONIFIED_P (XFRAME (this))
1141 /* Allow deleting the terminal frame when at least one X
1142 frame exists. */
1143 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1144 return 1;
1145 }
1146 return 0;
1147 }
1148
1149 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1150 unconditionally. x_connection_closed and delete_terminal use
1151 this. Any other value of FORCE implements the semantics
1152 described for Fdelete_frame. */
1153 Lisp_Object
1154 delete_frame (Lisp_Object frame, Lisp_Object force)
1155 /* If we use `register' here, gcc-4.0.2 on amd64 using
1156 -DUSE_LISP_UNION_TYPE complains further down that we're getting the
1157 address of `force'. Go figure. */
1158
1159 {
1160 struct frame *f;
1161 struct frame *sf = SELECTED_FRAME ();
1162 struct kboard *kb;
1163
1164 int minibuffer_selected, tooltip_frame;
1165
1166 if (EQ (frame, Qnil))
1167 {
1168 f = sf;
1169 XSETFRAME (frame, f);
1170 }
1171 else
1172 {
1173 CHECK_FRAME (frame);
1174 f = XFRAME (frame);
1175 }
1176
1177 if (! FRAME_LIVE_P (f))
1178 return Qnil;
1179
1180 if (NILP (force) && !other_visible_frames (f))
1181 error ("Attempt to delete the sole visible or iconified frame");
1182
1183 /* x_connection_closed must have set FORCE to `noelisp' in order
1184 to delete the last frame, if it is gone. */
1185 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1186 error ("Attempt to delete the only frame");
1187
1188 /* Does this frame have a minibuffer, and is it the surrogate
1189 minibuffer for any other frame? */
1190 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1191 {
1192 Lisp_Object frames;
1193
1194 for (frames = Vframe_list;
1195 CONSP (frames);
1196 frames = XCDR (frames))
1197 {
1198 Lisp_Object this;
1199 this = XCAR (frames);
1200
1201 if (! EQ (this, frame)
1202 && EQ (frame,
1203 WINDOW_FRAME (XWINDOW
1204 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1205 {
1206 /* If we MUST delete this frame, delete the other first.
1207 But do this only if FORCE equals `noelisp'. */
1208 if (EQ (force, Qnoelisp))
1209 delete_frame (this, Qnoelisp);
1210 else
1211 error ("Attempt to delete a surrogate minibuffer frame");
1212 }
1213 }
1214 }
1215
1216 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1217
1218 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1219 frame is a tooltip. FORCE is set to `noelisp' when handling
1220 a disconnect from the terminal, so we don't dare call Lisp
1221 code. */
1222 if (NILP (Vrun_hooks) || tooltip_frame)
1223 ;
1224 else if (EQ (force, Qnoelisp))
1225 pending_funcalls
1226 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1227 pending_funcalls);
1228 else
1229 {
1230 #ifdef HAVE_X_WINDOWS
1231 /* Also, save clipboard to the clipboard manager. */
1232 x_clipboard_manager_save_frame (frame);
1233 #endif
1234
1235 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1236 }
1237
1238 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1239 if (! FRAME_LIVE_P (f))
1240 return Qnil;
1241
1242 /* At this point, we are committed to deleting the frame.
1243 There is no more chance for errors to prevent it. */
1244
1245 minibuffer_selected = EQ (minibuf_window, selected_window);
1246
1247 /* Don't let the frame remain selected. */
1248 if (f == sf)
1249 {
1250 Lisp_Object tail, frame1;
1251
1252 /* Look for another visible frame on the same terminal. */
1253 frame1 = next_frame (frame, Qvisible);
1254
1255 /* If there is none, find *some* other frame. */
1256 if (NILP (frame1) || EQ (frame1, frame))
1257 {
1258 FOR_EACH_FRAME (tail, frame1)
1259 {
1260 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1261 break;
1262 }
1263 }
1264 #ifdef NS_IMPL_COCOA
1265 else
1266 /* Under NS, there is no system mechanism for choosing a new
1267 window to get focus -- it is left to application code.
1268 So the portion of THIS application interfacing with NS
1269 needs to know about it. We call Fraise_frame, but the
1270 purpose is really to transfer focus. */
1271 Fraise_frame (frame1);
1272 #endif
1273
1274 do_switch_frame (frame1, 0, 1, Qnil);
1275 sf = SELECTED_FRAME ();
1276 }
1277
1278 /* Don't allow minibuf_window to remain on a deleted frame. */
1279 if (EQ (f->minibuffer_window, minibuf_window))
1280 {
1281 Fset_window_buffer (sf->minibuffer_window,
1282 XWINDOW (minibuf_window)->buffer, Qnil);
1283 minibuf_window = sf->minibuffer_window;
1284
1285 /* If the dying minibuffer window was selected,
1286 select the new one. */
1287 if (minibuffer_selected)
1288 Fselect_window (minibuf_window, Qnil);
1289 }
1290
1291 /* Don't let echo_area_window to remain on a deleted frame. */
1292 if (EQ (f->minibuffer_window, echo_area_window))
1293 echo_area_window = sf->minibuffer_window;
1294
1295 /* Clear any X selections for this frame. */
1296 #ifdef HAVE_X_WINDOWS
1297 if (FRAME_X_P (f))
1298 x_clear_frame_selections (f);
1299 #endif
1300
1301 /* Free glyphs.
1302 This function must be called before the window tree of the
1303 frame is deleted because windows contain dynamically allocated
1304 memory. */
1305 free_glyphs (f);
1306
1307 #ifdef HAVE_WINDOW_SYSTEM
1308 /* Give chance to each font driver to free a frame specific data. */
1309 font_update_drivers (f, Qnil);
1310 #endif
1311
1312 /* Mark all the windows that used to be on FRAME as deleted, and then
1313 remove the reference to them. */
1314 delete_all_child_windows (f->root_window);
1315 f->root_window = Qnil;
1316
1317 Vframe_list = Fdelq (frame, Vframe_list);
1318 FRAME_SET_VISIBLE (f, 0);
1319
1320 /* Allow the vector of menu bar contents to be freed in the next
1321 garbage collection. The frame object itself may not be garbage
1322 collected until much later, because recent_keys and other data
1323 structures can still refer to it. */
1324 f->menu_bar_vector = Qnil;
1325
1326 free_font_driver_list (f);
1327 xfree (f->namebuf);
1328 xfree (f->decode_mode_spec_buffer);
1329 xfree (FRAME_INSERT_COST (f));
1330 xfree (FRAME_DELETEN_COST (f));
1331 xfree (FRAME_INSERTN_COST (f));
1332 xfree (FRAME_DELETE_COST (f));
1333 xfree (FRAME_MESSAGE_BUF (f));
1334
1335 /* Since some events are handled at the interrupt level, we may get
1336 an event for f at any time; if we zero out the frame's terminal
1337 now, then we may trip up the event-handling code. Instead, we'll
1338 promise that the terminal of the frame must be valid until we
1339 have called the window-system-dependent frame destruction
1340 routine. */
1341
1342 if (FRAME_TERMINAL (f)->delete_frame_hook)
1343 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1344
1345 {
1346 struct terminal *terminal = FRAME_TERMINAL (f);
1347 f->output_data.nothing = 0;
1348 f->terminal = 0; /* Now the frame is dead. */
1349
1350 /* If needed, delete the terminal that this frame was on.
1351 (This must be done after the frame is killed.) */
1352 terminal->reference_count--;
1353 #ifdef USE_GTK
1354 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1355 bug.
1356 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1357 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1358 terminal->reference_count = 1;
1359 #endif /* USE_GTK */
1360 if (terminal->reference_count == 0)
1361 {
1362 Lisp_Object tmp;
1363 XSETTERMINAL (tmp, terminal);
1364
1365 kb = NULL;
1366 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1367 }
1368 else
1369 kb = terminal->kboard;
1370 }
1371
1372 /* If we've deleted the last_nonminibuf_frame, then try to find
1373 another one. */
1374 if (f == last_nonminibuf_frame)
1375 {
1376 Lisp_Object frames;
1377
1378 last_nonminibuf_frame = 0;
1379
1380 for (frames = Vframe_list;
1381 CONSP (frames);
1382 frames = XCDR (frames))
1383 {
1384 f = XFRAME (XCAR (frames));
1385 if (!FRAME_MINIBUF_ONLY_P (f))
1386 {
1387 last_nonminibuf_frame = f;
1388 break;
1389 }
1390 }
1391 }
1392
1393 /* If there's no other frame on the same kboard, get out of
1394 single-kboard state if we're in it for this kboard. */
1395 if (kb != NULL)
1396 {
1397 Lisp_Object frames;
1398 /* Some frame we found on the same kboard, or nil if there are none. */
1399 Lisp_Object frame_on_same_kboard;
1400
1401 frame_on_same_kboard = Qnil;
1402
1403 for (frames = Vframe_list;
1404 CONSP (frames);
1405 frames = XCDR (frames))
1406 {
1407 Lisp_Object this;
1408 struct frame *f1;
1409
1410 this = XCAR (frames);
1411 if (!FRAMEP (this))
1412 abort ();
1413 f1 = XFRAME (this);
1414
1415 if (kb == FRAME_KBOARD (f1))
1416 frame_on_same_kboard = this;
1417 }
1418
1419 if (NILP (frame_on_same_kboard))
1420 not_single_kboard_state (kb);
1421 }
1422
1423
1424 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1425 find another one. Prefer minibuffer-only frames, but also notice
1426 frames with other windows. */
1427 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1428 {
1429 Lisp_Object frames;
1430
1431 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1432 Lisp_Object frame_with_minibuf;
1433 /* Some frame we found on the same kboard, or nil if there are none. */
1434 Lisp_Object frame_on_same_kboard;
1435
1436 frame_on_same_kboard = Qnil;
1437 frame_with_minibuf = Qnil;
1438
1439 for (frames = Vframe_list;
1440 CONSP (frames);
1441 frames = XCDR (frames))
1442 {
1443 Lisp_Object this;
1444 struct frame *f1;
1445
1446 this = XCAR (frames);
1447 if (!FRAMEP (this))
1448 abort ();
1449 f1 = XFRAME (this);
1450
1451 /* Consider only frames on the same kboard
1452 and only those with minibuffers. */
1453 if (kb == FRAME_KBOARD (f1)
1454 && FRAME_HAS_MINIBUF_P (f1))
1455 {
1456 frame_with_minibuf = this;
1457 if (FRAME_MINIBUF_ONLY_P (f1))
1458 break;
1459 }
1460
1461 if (kb == FRAME_KBOARD (f1))
1462 frame_on_same_kboard = this;
1463 }
1464
1465 if (!NILP (frame_on_same_kboard))
1466 {
1467 /* We know that there must be some frame with a minibuffer out
1468 there. If this were not true, all of the frames present
1469 would have to be minibufferless, which implies that at some
1470 point their minibuffer frames must have been deleted, but
1471 that is prohibited at the top; you can't delete surrogate
1472 minibuffer frames. */
1473 if (NILP (frame_with_minibuf))
1474 abort ();
1475
1476 KVAR (kb, Vdefault_minibuffer_frame) = frame_with_minibuf;
1477 }
1478 else
1479 /* No frames left on this kboard--say no minibuffer either. */
1480 KVAR (kb, Vdefault_minibuffer_frame) = Qnil;
1481 }
1482
1483 /* Cause frame titles to update--necessary if we now have just one frame. */
1484 if (!tooltip_frame)
1485 update_mode_lines = 1;
1486
1487 return Qnil;
1488 }
1489
1490 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1491 doc: /* Delete FRAME, permanently eliminating it from use.
1492 FRAME defaults to the selected frame.
1493
1494 A frame may not be deleted if its minibuffer is used by other frames.
1495 Normally, you may not delete a frame if all other frames are invisible,
1496 but if the second optional argument FORCE is non-nil, you may do so.
1497
1498 This function runs `delete-frame-functions' before actually
1499 deleting the frame, unless the frame is a tooltip.
1500 The functions are run with one argument, the frame to be deleted. */)
1501 (Lisp_Object frame, Lisp_Object force)
1502 {
1503 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1504 }
1505
1506 \f
1507 /* Return mouse position in character cell units. */
1508
1509 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1510 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1511 The position is given in character cells, where (0, 0) is the
1512 upper-left corner of the frame, X is the horizontal offset, and Y is
1513 the vertical offset.
1514 If Emacs is running on a mouseless terminal or hasn't been programmed
1515 to read the mouse position, it returns the selected frame for FRAME
1516 and nil for X and Y.
1517 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1518 passing the normal return value to that function as an argument,
1519 and returns whatever that function returns. */)
1520 (void)
1521 {
1522 FRAME_PTR f;
1523 Lisp_Object lispy_dummy;
1524 enum scroll_bar_part party_dummy;
1525 Lisp_Object x, y, retval;
1526 int col, row;
1527 Time long_dummy;
1528 struct gcpro gcpro1;
1529
1530 f = SELECTED_FRAME ();
1531 x = y = Qnil;
1532
1533 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1534 /* It's okay for the hook to refrain from storing anything. */
1535 if (FRAME_TERMINAL (f)->mouse_position_hook)
1536 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1537 &lispy_dummy, &party_dummy,
1538 &x, &y,
1539 &long_dummy);
1540 if (! NILP (x))
1541 {
1542 col = XINT (x);
1543 row = XINT (y);
1544 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1545 XSETINT (x, col);
1546 XSETINT (y, row);
1547 }
1548 #endif
1549 XSETFRAME (lispy_dummy, f);
1550 retval = Fcons (lispy_dummy, Fcons (x, y));
1551 GCPRO1 (retval);
1552 if (!NILP (Vmouse_position_function))
1553 retval = call1 (Vmouse_position_function, retval);
1554 RETURN_UNGCPRO (retval);
1555 }
1556
1557 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1558 Smouse_pixel_position, 0, 0, 0,
1559 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1560 The position is given in pixel units, where (0, 0) is the
1561 upper-left corner of the frame, X is the horizontal offset, and Y is
1562 the vertical offset.
1563 If Emacs is running on a mouseless terminal or hasn't been programmed
1564 to read the mouse position, it returns the selected frame for FRAME
1565 and nil for X and Y. */)
1566 (void)
1567 {
1568 FRAME_PTR f;
1569 Lisp_Object lispy_dummy;
1570 enum scroll_bar_part party_dummy;
1571 Lisp_Object x, y;
1572 Time long_dummy;
1573
1574 f = SELECTED_FRAME ();
1575 x = y = Qnil;
1576
1577 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1578 /* It's okay for the hook to refrain from storing anything. */
1579 if (FRAME_TERMINAL (f)->mouse_position_hook)
1580 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1581 &lispy_dummy, &party_dummy,
1582 &x, &y,
1583 &long_dummy);
1584 #endif
1585 XSETFRAME (lispy_dummy, f);
1586 return Fcons (lispy_dummy, Fcons (x, y));
1587 }
1588
1589 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1590 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1591 Coordinates are relative to the frame, not a window,
1592 so the coordinates of the top left character in the frame
1593 may be nonzero due to left-hand scroll bars or the menu bar.
1594
1595 The position is given in character cells, where (0, 0) is the
1596 upper-left corner of the frame, X is the horizontal offset, and Y is
1597 the vertical offset.
1598
1599 This function is a no-op for an X frame that is not visible.
1600 If you have just created a frame, you must wait for it to become visible
1601 before calling this function on it, like this.
1602 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1603 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1604 {
1605 CHECK_LIVE_FRAME (frame);
1606 CHECK_NUMBER (x);
1607 CHECK_NUMBER (y);
1608
1609 /* I think this should be done with a hook. */
1610 #ifdef HAVE_WINDOW_SYSTEM
1611 if (FRAME_WINDOW_P (XFRAME (frame)))
1612 /* Warping the mouse will cause enternotify and focus events. */
1613 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1614 #else
1615 #if defined (MSDOS) && defined (HAVE_MOUSE)
1616 if (FRAME_MSDOS_P (XFRAME (frame)))
1617 {
1618 Fselect_frame (frame, Qnil);
1619 mouse_moveto (XINT (x), XINT (y));
1620 }
1621 #else
1622 #ifdef HAVE_GPM
1623 {
1624 Fselect_frame (frame, Qnil);
1625 term_mouse_moveto (XINT (x), XINT (y));
1626 }
1627 #endif
1628 #endif
1629 #endif
1630
1631 return Qnil;
1632 }
1633
1634 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1635 Sset_mouse_pixel_position, 3, 3, 0,
1636 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1637 The position is given in pixels, where (0, 0) is the upper-left corner
1638 of the frame, X is the horizontal offset, and Y is the vertical offset.
1639
1640 Note, this is a no-op for an X frame that is not visible.
1641 If you have just created a frame, you must wait for it to become visible
1642 before calling this function on it, like this.
1643 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1644 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1645 {
1646 CHECK_LIVE_FRAME (frame);
1647 CHECK_NUMBER (x);
1648 CHECK_NUMBER (y);
1649
1650 /* I think this should be done with a hook. */
1651 #ifdef HAVE_WINDOW_SYSTEM
1652 if (FRAME_WINDOW_P (XFRAME (frame)))
1653 /* Warping the mouse will cause enternotify and focus events. */
1654 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1655 #else
1656 #if defined (MSDOS) && defined (HAVE_MOUSE)
1657 if (FRAME_MSDOS_P (XFRAME (frame)))
1658 {
1659 Fselect_frame (frame, Qnil);
1660 mouse_moveto (XINT (x), XINT (y));
1661 }
1662 #else
1663 #ifdef HAVE_GPM
1664 {
1665 Fselect_frame (frame, Qnil);
1666 term_mouse_moveto (XINT (x), XINT (y));
1667 }
1668 #endif
1669 #endif
1670 #endif
1671
1672 return Qnil;
1673 }
1674 \f
1675 static void make_frame_visible_1 (Lisp_Object);
1676
1677 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1678 0, 1, "",
1679 doc: /* Make the frame FRAME visible (assuming it is an X window).
1680 If omitted, FRAME defaults to the currently selected frame. */)
1681 (Lisp_Object frame)
1682 {
1683 if (NILP (frame))
1684 frame = selected_frame;
1685
1686 CHECK_LIVE_FRAME (frame);
1687
1688 /* I think this should be done with a hook. */
1689 #ifdef HAVE_WINDOW_SYSTEM
1690 if (FRAME_WINDOW_P (XFRAME (frame)))
1691 {
1692 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1693 x_make_frame_visible (XFRAME (frame));
1694 }
1695 #endif
1696
1697 make_frame_visible_1 (XFRAME (frame)->root_window);
1698
1699 /* Make menu bar update for the Buffers and Frames menus. */
1700 windows_or_buffers_changed++;
1701
1702 return frame;
1703 }
1704
1705 /* Update the display_time slot of the buffers shown in WINDOW
1706 and all its descendants. */
1707
1708 static void
1709 make_frame_visible_1 (Lisp_Object window)
1710 {
1711 struct window *w;
1712
1713 for (;!NILP (window); window = w->next)
1714 {
1715 w = XWINDOW (window);
1716
1717 if (!NILP (w->buffer))
1718 BVAR (XBUFFER (w->buffer), display_time) = Fcurrent_time ();
1719
1720 if (!NILP (w->vchild))
1721 make_frame_visible_1 (w->vchild);
1722 if (!NILP (w->hchild))
1723 make_frame_visible_1 (w->hchild);
1724 }
1725 }
1726
1727 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1728 0, 2, "",
1729 doc: /* Make the frame FRAME invisible.
1730 If omitted, FRAME defaults to the currently selected frame.
1731 On graphical displays, invisible frames are not updated and are
1732 usually not displayed at all, even in a window system's \"taskbar\".
1733
1734 Normally you may not make FRAME invisible if all other frames are invisible,
1735 but if the second optional argument FORCE is non-nil, you may do so.
1736
1737 This function has no effect on text-only terminal frames. Such frames
1738 are always considered visible, whether or not they are currently being
1739 displayed in the terminal. */)
1740 (Lisp_Object frame, Lisp_Object force)
1741 {
1742 if (NILP (frame))
1743 frame = selected_frame;
1744
1745 CHECK_LIVE_FRAME (frame);
1746
1747 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1748 error ("Attempt to make invisible the sole visible or iconified frame");
1749
1750 #if 0 /* This isn't logically necessary, and it can do GC. */
1751 /* Don't let the frame remain selected. */
1752 if (EQ (frame, selected_frame))
1753 do_switch_frame (next_frame (frame, Qt), 0, 0, Qnil)
1754 #endif
1755
1756 /* Don't allow minibuf_window to remain on a deleted frame. */
1757 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1758 {
1759 struct frame *sf = XFRAME (selected_frame);
1760 Fset_window_buffer (sf->minibuffer_window,
1761 XWINDOW (minibuf_window)->buffer, Qnil);
1762 minibuf_window = sf->minibuffer_window;
1763 }
1764
1765 /* I think this should be done with a hook. */
1766 #ifdef HAVE_WINDOW_SYSTEM
1767 if (FRAME_WINDOW_P (XFRAME (frame)))
1768 x_make_frame_invisible (XFRAME (frame));
1769 #endif
1770
1771 /* Make menu bar update for the Buffers and Frames menus. */
1772 windows_or_buffers_changed++;
1773
1774 return Qnil;
1775 }
1776
1777 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1778 0, 1, "",
1779 doc: /* Make the frame FRAME into an icon.
1780 If omitted, FRAME defaults to the currently selected frame. */)
1781 (Lisp_Object frame)
1782 {
1783 if (NILP (frame))
1784 frame = selected_frame;
1785
1786 CHECK_LIVE_FRAME (frame);
1787
1788 #if 0 /* This isn't logically necessary, and it can do GC. */
1789 /* Don't let the frame remain selected. */
1790 if (EQ (frame, selected_frame))
1791 Fhandle_switch_frame (next_frame (frame, Qt));
1792 #endif
1793
1794 /* Don't allow minibuf_window to remain on a deleted frame. */
1795 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1796 {
1797 struct frame *sf = XFRAME (selected_frame);
1798 Fset_window_buffer (sf->minibuffer_window,
1799 XWINDOW (minibuf_window)->buffer, Qnil);
1800 minibuf_window = sf->minibuffer_window;
1801 }
1802
1803 /* I think this should be done with a hook. */
1804 #ifdef HAVE_WINDOW_SYSTEM
1805 if (FRAME_WINDOW_P (XFRAME (frame)))
1806 x_iconify_frame (XFRAME (frame));
1807 #endif
1808
1809 /* Make menu bar update for the Buffers and Frames menus. */
1810 windows_or_buffers_changed++;
1811
1812 return Qnil;
1813 }
1814
1815 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1816 1, 1, 0,
1817 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1818 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1819 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1820 On graphical displays, invisible frames are not updated and are
1821 usually not displayed at all, even in a window system's \"taskbar\".
1822
1823 If FRAME is a text-only terminal frame, this always returns t.
1824 Such frames are always considered visible, whether or not they are
1825 currently being displayed on the terminal. */)
1826 (Lisp_Object frame)
1827 {
1828 CHECK_LIVE_FRAME (frame);
1829
1830 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1831
1832 if (FRAME_VISIBLE_P (XFRAME (frame)))
1833 return Qt;
1834 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1835 return Qicon;
1836 return Qnil;
1837 }
1838
1839 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1840 0, 0, 0,
1841 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1842 (void)
1843 {
1844 Lisp_Object tail, frame;
1845 struct frame *f;
1846 Lisp_Object value;
1847
1848 value = Qnil;
1849 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1850 {
1851 frame = XCAR (tail);
1852 if (!FRAMEP (frame))
1853 continue;
1854 f = XFRAME (frame);
1855 if (FRAME_VISIBLE_P (f))
1856 value = Fcons (frame, value);
1857 }
1858 return value;
1859 }
1860
1861
1862 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1863 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1864 If FRAME is invisible or iconified, make it visible.
1865 If you don't specify a frame, the selected frame is used.
1866 If Emacs is displaying on an ordinary terminal or some other device which
1867 doesn't support multiple overlapping frames, this function selects FRAME. */)
1868 (Lisp_Object frame)
1869 {
1870 struct frame *f;
1871 if (NILP (frame))
1872 frame = selected_frame;
1873
1874 CHECK_LIVE_FRAME (frame);
1875
1876 f = XFRAME (frame);
1877
1878 if (FRAME_TERMCAP_P (f))
1879 /* On a text-only terminal select FRAME. */
1880 Fselect_frame (frame, Qnil);
1881 else
1882 /* Do like the documentation says. */
1883 Fmake_frame_visible (frame);
1884
1885 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1886 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1887
1888 return Qnil;
1889 }
1890
1891 /* Should we have a corresponding function called Flower_Power? */
1892 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1893 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1894 If you don't specify a frame, the selected frame is used.
1895 If Emacs is displaying on an ordinary terminal or some other device which
1896 doesn't support multiple overlapping frames, this function does nothing. */)
1897 (Lisp_Object frame)
1898 {
1899 struct frame *f;
1900
1901 if (NILP (frame))
1902 frame = selected_frame;
1903
1904 CHECK_LIVE_FRAME (frame);
1905
1906 f = XFRAME (frame);
1907
1908 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1909 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1910
1911 return Qnil;
1912 }
1913
1914 \f
1915 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1916 1, 2, 0,
1917 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1918 In other words, switch-frame events caused by events in FRAME will
1919 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1920 FOCUS-FRAME after reading an event typed at FRAME.
1921
1922 If FOCUS-FRAME is omitted or nil, any existing redirection is
1923 canceled, and the frame again receives its own keystrokes.
1924
1925 Focus redirection is useful for temporarily redirecting keystrokes to
1926 a surrogate minibuffer frame when a frame doesn't have its own
1927 minibuffer window.
1928
1929 A frame's focus redirection can be changed by `select-frame'. If frame
1930 FOO is selected, and then a different frame BAR is selected, any
1931 frames redirecting their focus to FOO are shifted to redirect their
1932 focus to BAR. This allows focus redirection to work properly when the
1933 user switches from one frame to another using `select-window'.
1934
1935 This means that a frame whose focus is redirected to itself is treated
1936 differently from a frame whose focus is redirected to nil; the former
1937 is affected by `select-frame', while the latter is not.
1938
1939 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1940 (Lisp_Object frame, Lisp_Object focus_frame)
1941 {
1942 struct frame *f;
1943
1944 /* Note that we don't check for a live frame here. It's reasonable
1945 to redirect the focus of a frame you're about to delete, if you
1946 know what other frame should receive those keystrokes. */
1947 CHECK_FRAME (frame);
1948
1949 if (! NILP (focus_frame))
1950 CHECK_LIVE_FRAME (focus_frame);
1951
1952 f = XFRAME (frame);
1953
1954 f->focus_frame = focus_frame;
1955
1956 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1957 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1958
1959 return Qnil;
1960 }
1961
1962
1963 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1964 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1965 This returns nil if FRAME's focus is not redirected.
1966 See `redirect-frame-focus'. */)
1967 (Lisp_Object frame)
1968 {
1969 CHECK_LIVE_FRAME (frame);
1970
1971 return FRAME_FOCUS_FRAME (XFRAME (frame));
1972 }
1973
1974
1975 \f
1976 /* Return the value of frame parameter PROP in frame FRAME. */
1977
1978 #if !HAVE_NS
1979 static
1980 #endif
1981 Lisp_Object
1982 get_frame_param (register struct frame *frame, Lisp_Object prop)
1983 {
1984 register Lisp_Object tem;
1985
1986 tem = Fassq (prop, frame->param_alist);
1987 if (EQ (tem, Qnil))
1988 return tem;
1989 return Fcdr (tem);
1990 }
1991
1992 /* Return the buffer-predicate of the selected frame. */
1993
1994 Lisp_Object
1995 frame_buffer_predicate (Lisp_Object frame)
1996 {
1997 return XFRAME (frame)->buffer_predicate;
1998 }
1999
2000 /* Return the buffer-list of the selected frame. */
2001
2002 static Lisp_Object
2003 frame_buffer_list (Lisp_Object frame)
2004 {
2005 return XFRAME (frame)->buffer_list;
2006 }
2007
2008 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2009
2010 void
2011 frames_discard_buffer (Lisp_Object buffer)
2012 {
2013 Lisp_Object frame, tail;
2014
2015 FOR_EACH_FRAME (tail, frame)
2016 {
2017 XFRAME (frame)->buffer_list
2018 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2019 XFRAME (frame)->buried_buffer_list
2020 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2021 }
2022 }
2023
2024 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2025 If the alist already has an element for PROP, we change it. */
2026
2027 void
2028 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2029 {
2030 register Lisp_Object tem;
2031
2032 tem = Fassq (prop, *alistptr);
2033 if (EQ (tem, Qnil))
2034 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2035 else
2036 Fsetcdr (tem, val);
2037 }
2038
2039 static int
2040 frame_name_fnn_p (char *str, EMACS_INT len)
2041 {
2042 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2043 {
2044 char *p = str + 2;
2045 while ('0' <= *p && *p <= '9')
2046 p++;
2047 if (p == str + len)
2048 return 1;
2049 }
2050 return 0;
2051 }
2052
2053 /* Set the name of the terminal frame. Also used by MSDOS frames.
2054 Modeled after x_set_name which is used for WINDOW frames. */
2055
2056 static void
2057 set_term_frame_name (struct frame *f, Lisp_Object name)
2058 {
2059 f->explicit_name = ! NILP (name);
2060
2061 /* If NAME is nil, set the name to F<num>. */
2062 if (NILP (name))
2063 {
2064 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2065
2066 /* Check for no change needed in this very common case
2067 before we do any consing. */
2068 if (frame_name_fnn_p (SSDATA (f->name),
2069 SBYTES (f->name)))
2070 return;
2071
2072 tty_frame_count++;
2073 sprintf (namebuf, "F%"pMd, tty_frame_count);
2074 name = build_string (namebuf);
2075 }
2076 else
2077 {
2078 CHECK_STRING (name);
2079
2080 /* Don't change the name if it's already NAME. */
2081 if (! NILP (Fstring_equal (name, f->name)))
2082 return;
2083
2084 /* Don't allow the user to set the frame name to F<num>, so it
2085 doesn't clash with the names we generate for terminal frames. */
2086 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2087 error ("Frame names of the form F<num> are usurped by Emacs");
2088 }
2089
2090 f->name = name;
2091 update_mode_lines = 1;
2092 }
2093
2094 void
2095 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2096 {
2097 register Lisp_Object old_alist_elt;
2098
2099 /* The buffer-list parameters are stored in a special place and not
2100 in the alist. All buffers must be live. */
2101 if (EQ (prop, Qbuffer_list))
2102 {
2103 Lisp_Object list = Qnil;
2104 for (; CONSP (val); val = XCDR (val))
2105 if (!NILP (Fbuffer_live_p (XCAR (val))))
2106 list = Fcons (XCAR (val), list);
2107 f->buffer_list = Fnreverse (list);
2108 return;
2109 }
2110 if (EQ (prop, Qburied_buffer_list))
2111 {
2112 Lisp_Object list = Qnil;
2113 for (; CONSP (val); val = XCDR (val))
2114 if (!NILP (Fbuffer_live_p (XCAR (val))))
2115 list = Fcons (XCAR (val), list);
2116 f->buried_buffer_list = Fnreverse (list);
2117 return;
2118 }
2119
2120 /* If PROP is a symbol which is supposed to have frame-local values,
2121 and it is set up based on this frame, switch to the global
2122 binding. That way, we can create or alter the frame-local binding
2123 without messing up the symbol's status. */
2124 if (SYMBOLP (prop))
2125 {
2126 struct Lisp_Symbol *sym = XSYMBOL (prop);
2127 start:
2128 switch (sym->redirect)
2129 {
2130 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2131 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2132 case SYMBOL_LOCALIZED:
2133 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2134 if (blv->frame_local && BLV_FOUND (blv) && XFRAME (blv->where) == f)
2135 swap_in_global_binding (sym);
2136 break;
2137 }
2138 default: abort ();
2139 }
2140 }
2141
2142 /* The tty color needed to be set before the frame's parameter
2143 alist was updated with the new value. This is not true any more,
2144 but we still do this test early on. */
2145 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2146 && f == FRAME_TTY (f)->previous_frame)
2147 /* Force redisplay of this tty. */
2148 FRAME_TTY (f)->previous_frame = NULL;
2149
2150 /* Update the frame parameter alist. */
2151 old_alist_elt = Fassq (prop, f->param_alist);
2152 if (EQ (old_alist_elt, Qnil))
2153 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2154 else
2155 Fsetcdr (old_alist_elt, val);
2156
2157 /* Update some other special parameters in their special places
2158 in addition to the alist. */
2159
2160 if (EQ (prop, Qbuffer_predicate))
2161 f->buffer_predicate = val;
2162
2163 if (! FRAME_WINDOW_P (f))
2164 {
2165 if (EQ (prop, Qmenu_bar_lines))
2166 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2167 else if (EQ (prop, Qname))
2168 set_term_frame_name (f, val);
2169 }
2170
2171 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2172 {
2173 if (! MINI_WINDOW_P (XWINDOW (val)))
2174 error ("Surrogate minibuffer windows must be minibuffer windows");
2175
2176 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2177 && !EQ (val, f->minibuffer_window))
2178 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2179
2180 /* Install the chosen minibuffer window, with proper buffer. */
2181 f->minibuffer_window = val;
2182 }
2183 }
2184
2185 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2186 doc: /* Return the parameters-alist of frame FRAME.
2187 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2188 The meaningful PARMs depend on the kind of frame.
2189 If FRAME is omitted, return information on the currently selected frame. */)
2190 (Lisp_Object frame)
2191 {
2192 Lisp_Object alist;
2193 FRAME_PTR f;
2194 int height, width;
2195 struct gcpro gcpro1;
2196
2197 if (NILP (frame))
2198 frame = selected_frame;
2199
2200 CHECK_FRAME (frame);
2201 f = XFRAME (frame);
2202
2203 if (!FRAME_LIVE_P (f))
2204 return Qnil;
2205
2206 alist = Fcopy_alist (f->param_alist);
2207 GCPRO1 (alist);
2208
2209 if (!FRAME_WINDOW_P (f))
2210 {
2211 int fg = FRAME_FOREGROUND_PIXEL (f);
2212 int bg = FRAME_BACKGROUND_PIXEL (f);
2213 Lisp_Object elt;
2214
2215 /* If the frame's parameter alist says the colors are
2216 unspecified and reversed, take the frame's background pixel
2217 for foreground and vice versa. */
2218 elt = Fassq (Qforeground_color, alist);
2219 if (CONSP (elt) && STRINGP (XCDR (elt)))
2220 {
2221 if (strncmp (SSDATA (XCDR (elt)),
2222 unspecified_bg,
2223 SCHARS (XCDR (elt))) == 0)
2224 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2225 else if (strncmp (SSDATA (XCDR (elt)),
2226 unspecified_fg,
2227 SCHARS (XCDR (elt))) == 0)
2228 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2229 }
2230 else
2231 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2232 elt = Fassq (Qbackground_color, alist);
2233 if (CONSP (elt) && STRINGP (XCDR (elt)))
2234 {
2235 if (strncmp (SSDATA (XCDR (elt)),
2236 unspecified_fg,
2237 SCHARS (XCDR (elt))) == 0)
2238 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2239 else if (strncmp (SSDATA (XCDR (elt)),
2240 unspecified_bg,
2241 SCHARS (XCDR (elt))) == 0)
2242 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2243 }
2244 else
2245 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2246 store_in_alist (&alist, intern ("font"),
2247 build_string (FRAME_MSDOS_P (f)
2248 ? "ms-dos"
2249 : FRAME_W32_P (f) ? "w32term"
2250 :"tty"));
2251 }
2252 store_in_alist (&alist, Qname, f->name);
2253 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2254 store_in_alist (&alist, Qheight, make_number (height));
2255 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2256 store_in_alist (&alist, Qwidth, make_number (width));
2257 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2258 store_in_alist (&alist, Qminibuffer,
2259 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2260 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2261 : FRAME_MINIBUF_WINDOW (f)));
2262 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2263 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2264 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2265
2266 /* I think this should be done with a hook. */
2267 #ifdef HAVE_WINDOW_SYSTEM
2268 if (FRAME_WINDOW_P (f))
2269 x_report_frame_params (f, &alist);
2270 else
2271 #endif
2272 {
2273 /* This ought to be correct in f->param_alist for an X frame. */
2274 Lisp_Object lines;
2275 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2276 store_in_alist (&alist, Qmenu_bar_lines, lines);
2277 }
2278
2279 UNGCPRO;
2280 return alist;
2281 }
2282
2283
2284 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2285 doc: /* Return FRAME's value for parameter PARAMETER.
2286 If FRAME is nil, describe the currently selected frame. */)
2287 (Lisp_Object frame, Lisp_Object parameter)
2288 {
2289 struct frame *f;
2290 Lisp_Object value;
2291
2292 if (NILP (frame))
2293 frame = selected_frame;
2294 else
2295 CHECK_FRAME (frame);
2296 CHECK_SYMBOL (parameter);
2297
2298 f = XFRAME (frame);
2299 value = Qnil;
2300
2301 if (FRAME_LIVE_P (f))
2302 {
2303 /* Avoid consing in frequent cases. */
2304 if (EQ (parameter, Qname))
2305 value = f->name;
2306 #ifdef HAVE_X_WINDOWS
2307 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2308 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2309 #endif /* HAVE_X_WINDOWS */
2310 else if (EQ (parameter, Qbackground_color)
2311 || EQ (parameter, Qforeground_color))
2312 {
2313 value = Fassq (parameter, f->param_alist);
2314 if (CONSP (value))
2315 {
2316 value = XCDR (value);
2317 /* Fframe_parameters puts the actual fg/bg color names,
2318 even if f->param_alist says otherwise. This is
2319 important when param_alist's notion of colors is
2320 "unspecified". We need to do the same here. */
2321 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2322 {
2323 const char *color_name;
2324 EMACS_INT csz;
2325
2326 if (EQ (parameter, Qbackground_color))
2327 {
2328 color_name = SSDATA (value);
2329 csz = SCHARS (value);
2330 if (strncmp (color_name, unspecified_bg, csz) == 0)
2331 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2332 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2333 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2334 }
2335 else if (EQ (parameter, Qforeground_color))
2336 {
2337 color_name = SSDATA (value);
2338 csz = SCHARS (value);
2339 if (strncmp (color_name, unspecified_fg, csz) == 0)
2340 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2341 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2342 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2343 }
2344 }
2345 }
2346 else
2347 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2348 }
2349 else if (EQ (parameter, Qdisplay_type)
2350 || EQ (parameter, Qbackground_mode))
2351 value = Fcdr (Fassq (parameter, f->param_alist));
2352 else
2353 /* FIXME: Avoid this code path at all (as well as code duplication)
2354 by sharing more code with Fframe_parameters. */
2355 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2356 }
2357
2358 return value;
2359 }
2360
2361
2362 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2363 Smodify_frame_parameters, 2, 2, 0,
2364 doc: /* Modify the parameters of frame FRAME according to ALIST.
2365 If FRAME is nil, it defaults to the selected frame.
2366 ALIST is an alist of parameters to change and their new values.
2367 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2368 The meaningful PARMs depend on the kind of frame.
2369 Undefined PARMs are ignored, but stored in the frame's parameter list
2370 so that `frame-parameters' will return them.
2371
2372 The value of frame parameter FOO can also be accessed
2373 as a frame-local binding for the variable FOO, if you have
2374 enabled such bindings for that variable with `make-variable-frame-local'.
2375 Note that this functionality is obsolete as of Emacs 22.2, and its
2376 use is not recommended. Explicitly check for a frame-parameter instead. */)
2377 (Lisp_Object frame, Lisp_Object alist)
2378 {
2379 FRAME_PTR f;
2380 register Lisp_Object tail, prop, val;
2381
2382 if (EQ (frame, Qnil))
2383 frame = selected_frame;
2384 CHECK_LIVE_FRAME (frame);
2385 f = XFRAME (frame);
2386
2387 /* I think this should be done with a hook. */
2388 #ifdef HAVE_WINDOW_SYSTEM
2389 if (FRAME_WINDOW_P (f))
2390 x_set_frame_parameters (f, alist);
2391 else
2392 #endif
2393 #ifdef MSDOS
2394 if (FRAME_MSDOS_P (f))
2395 IT_set_frame_parameters (f, alist);
2396 else
2397 #endif
2398
2399 {
2400 int length = XINT (Flength (alist));
2401 int i;
2402 Lisp_Object *parms
2403 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2404 Lisp_Object *values
2405 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2406
2407 /* Extract parm names and values into those vectors. */
2408
2409 i = 0;
2410 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2411 {
2412 Lisp_Object elt;
2413
2414 elt = XCAR (tail);
2415 parms[i] = Fcar (elt);
2416 values[i] = Fcdr (elt);
2417 i++;
2418 }
2419
2420 /* Now process them in reverse of specified order. */
2421 while (--i >= 0)
2422 {
2423 prop = parms[i];
2424 val = values[i];
2425 store_frame_param (f, prop, val);
2426
2427 if (EQ (prop, Qforeground_color)
2428 || EQ (prop, Qbackground_color))
2429 update_face_from_frame_parameter (f, prop, val);
2430 }
2431 }
2432 return Qnil;
2433 }
2434 \f
2435 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2436 0, 1, 0,
2437 doc: /* Height in pixels of a line in the font in frame FRAME.
2438 If FRAME is omitted, the selected frame is used.
2439 For a terminal frame, the value is always 1. */)
2440 (Lisp_Object frame)
2441 {
2442 struct frame *f;
2443
2444 if (NILP (frame))
2445 frame = selected_frame;
2446 CHECK_FRAME (frame);
2447 f = XFRAME (frame);
2448
2449 #ifdef HAVE_WINDOW_SYSTEM
2450 if (FRAME_WINDOW_P (f))
2451 return make_number (x_char_height (f));
2452 else
2453 #endif
2454 return make_number (1);
2455 }
2456
2457
2458 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2459 0, 1, 0,
2460 doc: /* Width in pixels of characters in the font in frame FRAME.
2461 If FRAME is omitted, the selected frame is used.
2462 On a graphical screen, the width is the standard width of the default font.
2463 For a terminal screen, the value is always 1. */)
2464 (Lisp_Object frame)
2465 {
2466 struct frame *f;
2467
2468 if (NILP (frame))
2469 frame = selected_frame;
2470 CHECK_FRAME (frame);
2471 f = XFRAME (frame);
2472
2473 #ifdef HAVE_WINDOW_SYSTEM
2474 if (FRAME_WINDOW_P (f))
2475 return make_number (x_char_width (f));
2476 else
2477 #endif
2478 return make_number (1);
2479 }
2480
2481 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2482 Sframe_pixel_height, 0, 1, 0,
2483 doc: /* Return a FRAME's height in pixels.
2484 If FRAME is omitted, the selected frame is used. The exact value
2485 of the result depends on the window-system and toolkit in use:
2486
2487 In the Gtk+ version of Emacs, it includes only any window (including
2488 the minibuffer or echo area), mode line, and header line. It does not
2489 include the tool bar or menu bar.
2490
2491 With the Motif or Lucid toolkits, it also includes the tool bar (but
2492 not the menu bar).
2493
2494 In a graphical version with no toolkit, it includes both the tool bar
2495 and menu bar.
2496
2497 For a text-only terminal, it includes the menu bar. In this case, the
2498 result is really in characters rather than pixels (i.e., is identical
2499 to `frame-height'). */)
2500 (Lisp_Object frame)
2501 {
2502 struct frame *f;
2503
2504 if (NILP (frame))
2505 frame = selected_frame;
2506 CHECK_FRAME (frame);
2507 f = XFRAME (frame);
2508
2509 #ifdef HAVE_WINDOW_SYSTEM
2510 if (FRAME_WINDOW_P (f))
2511 return make_number (x_pixel_height (f));
2512 else
2513 #endif
2514 return make_number (FRAME_LINES (f));
2515 }
2516
2517 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2518 Sframe_pixel_width, 0, 1, 0,
2519 doc: /* Return FRAME's width in pixels.
2520 For a terminal frame, the result really gives the width in characters.
2521 If FRAME is omitted, the selected frame is used. */)
2522 (Lisp_Object frame)
2523 {
2524 struct frame *f;
2525
2526 if (NILP (frame))
2527 frame = selected_frame;
2528 CHECK_FRAME (frame);
2529 f = XFRAME (frame);
2530
2531 #ifdef HAVE_WINDOW_SYSTEM
2532 if (FRAME_WINDOW_P (f))
2533 return make_number (x_pixel_width (f));
2534 else
2535 #endif
2536 return make_number (FRAME_COLS (f));
2537 }
2538
2539 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2540 Stool_bar_pixel_width, 0, 1, 0,
2541 doc: /* Return width in pixels of FRAME's tool bar.
2542 The result is greater than zero only when the tool bar is on the left
2543 or right side of FRAME. If FRAME is omitted, the selected frame is
2544 used. */)
2545 (Lisp_Object frame)
2546 {
2547 struct frame *f;
2548
2549 if (NILP (frame))
2550 frame = selected_frame;
2551 CHECK_FRAME (frame);
2552 f = XFRAME (frame);
2553
2554 #ifdef FRAME_TOOLBAR_WIDTH
2555 if (FRAME_WINDOW_P (f))
2556 return make_number (FRAME_TOOLBAR_WIDTH (f));
2557 #endif
2558 return make_number (0);
2559 }
2560 \f
2561 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2562 doc: /* Specify that the frame FRAME has LINES lines.
2563 Optional third arg non-nil means that redisplay should use LINES lines
2564 but that the idea of the actual height of the frame should not be changed. */)
2565 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2566 {
2567 register struct frame *f;
2568
2569 CHECK_NUMBER (lines);
2570 if (NILP (frame))
2571 frame = selected_frame;
2572 CHECK_LIVE_FRAME (frame);
2573 f = XFRAME (frame);
2574
2575 /* I think this should be done with a hook. */
2576 #ifdef HAVE_WINDOW_SYSTEM
2577 if (FRAME_WINDOW_P (f))
2578 {
2579 if (XINT (lines) != FRAME_LINES (f))
2580 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2581 do_pending_window_change (0);
2582 }
2583 else
2584 #endif
2585 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2586 return Qnil;
2587 }
2588
2589 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2590 doc: /* Specify that the frame FRAME has COLS columns.
2591 Optional third arg non-nil means that redisplay should use COLS columns
2592 but that the idea of the actual width of the frame should not be changed. */)
2593 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2594 {
2595 register struct frame *f;
2596 CHECK_NUMBER (cols);
2597 if (NILP (frame))
2598 frame = selected_frame;
2599 CHECK_LIVE_FRAME (frame);
2600 f = XFRAME (frame);
2601
2602 /* I think this should be done with a hook. */
2603 #ifdef HAVE_WINDOW_SYSTEM
2604 if (FRAME_WINDOW_P (f))
2605 {
2606 if (XINT (cols) != FRAME_COLS (f))
2607 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2608 do_pending_window_change (0);
2609 }
2610 else
2611 #endif
2612 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2613 return Qnil;
2614 }
2615
2616 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2617 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2618 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2619 {
2620 register struct frame *f;
2621
2622 CHECK_LIVE_FRAME (frame);
2623 CHECK_NUMBER (cols);
2624 CHECK_NUMBER (rows);
2625 f = XFRAME (frame);
2626
2627 /* I think this should be done with a hook. */
2628 #ifdef HAVE_WINDOW_SYSTEM
2629 if (FRAME_WINDOW_P (f))
2630 {
2631 if (XINT (rows) != FRAME_LINES (f)
2632 || XINT (cols) != FRAME_COLS (f)
2633 || f->new_text_lines || f->new_text_cols)
2634 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2635 do_pending_window_change (0);
2636 }
2637 else
2638 #endif
2639 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2640
2641 return Qnil;
2642 }
2643
2644 DEFUN ("set-frame-position", Fset_frame_position,
2645 Sset_frame_position, 3, 3, 0,
2646 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2647 This is actually the position of the upper left corner of the frame.
2648 Negative values for XOFFSET or YOFFSET are interpreted relative to
2649 the rightmost or bottommost possible position (that stays within the screen). */)
2650 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2651 {
2652 register struct frame *f;
2653
2654 CHECK_LIVE_FRAME (frame);
2655 CHECK_NUMBER (xoffset);
2656 CHECK_NUMBER (yoffset);
2657 f = XFRAME (frame);
2658
2659 /* I think this should be done with a hook. */
2660 #ifdef HAVE_WINDOW_SYSTEM
2661 if (FRAME_WINDOW_P (f))
2662 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2663 #endif
2664
2665 return Qt;
2666 }
2667
2668 \f
2669 /***********************************************************************
2670 Frame Parameters
2671 ***********************************************************************/
2672
2673 /* Connect the frame-parameter names for X frames
2674 to the ways of passing the parameter values to the window system.
2675
2676 The name of a parameter, as a Lisp symbol,
2677 has an `x-frame-parameter' property which is an integer in Lisp
2678 that is an index in this table. */
2679
2680 struct frame_parm_table {
2681 const char *name;
2682 Lisp_Object *variable;
2683 };
2684
2685 static const struct frame_parm_table frame_parms[] =
2686 {
2687 {"auto-raise", &Qauto_raise},
2688 {"auto-lower", &Qauto_lower},
2689 {"background-color", 0},
2690 {"border-color", &Qborder_color},
2691 {"border-width", &Qborder_width},
2692 {"cursor-color", &Qcursor_color},
2693 {"cursor-type", &Qcursor_type},
2694 {"font", 0},
2695 {"foreground-color", 0},
2696 {"icon-name", &Qicon_name},
2697 {"icon-type", &Qicon_type},
2698 {"internal-border-width", &Qinternal_border_width},
2699 {"menu-bar-lines", &Qmenu_bar_lines},
2700 {"mouse-color", &Qmouse_color},
2701 {"name", &Qname},
2702 {"scroll-bar-width", &Qscroll_bar_width},
2703 {"title", &Qtitle},
2704 {"unsplittable", &Qunsplittable},
2705 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2706 {"visibility", &Qvisibility},
2707 {"tool-bar-lines", &Qtool_bar_lines},
2708 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2709 {"scroll-bar-background", &Qscroll_bar_background},
2710 {"screen-gamma", &Qscreen_gamma},
2711 {"line-spacing", &Qline_spacing},
2712 {"left-fringe", &Qleft_fringe},
2713 {"right-fringe", &Qright_fringe},
2714 {"wait-for-wm", &Qwait_for_wm},
2715 {"fullscreen", &Qfullscreen},
2716 {"font-backend", &Qfont_backend},
2717 {"alpha", &Qalpha},
2718 {"sticky", &Qsticky},
2719 {"tool-bar-position", &Qtool_bar_position},
2720 };
2721
2722 #ifdef WINDOWSNT
2723
2724 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2725 wanted positions of the WM window (not Emacs window).
2726 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2727 window (FRAME_X_WINDOW).
2728 */
2729
2730 void
2731 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2732 {
2733 int newwidth = FRAME_COLS (f);
2734 int newheight = FRAME_LINES (f);
2735 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2736
2737 *top_pos = f->top_pos;
2738 *left_pos = f->left_pos;
2739
2740 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2741 {
2742 int ph;
2743
2744 ph = x_display_pixel_height (dpyinfo);
2745 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2746 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2747 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2748 *top_pos = 0;
2749 }
2750
2751 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2752 {
2753 int pw;
2754
2755 pw = x_display_pixel_width (dpyinfo);
2756 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2757 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2758 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2759 *left_pos = 0;
2760 }
2761
2762 *width = newwidth;
2763 *height = newheight;
2764 }
2765
2766 #endif /* WINDOWSNT */
2767
2768 #ifdef HAVE_WINDOW_SYSTEM
2769
2770 /* Change the parameters of frame F as specified by ALIST.
2771 If a parameter is not specially recognized, do nothing special;
2772 otherwise call the `x_set_...' function for that parameter.
2773 Except for certain geometry properties, always call store_frame_param
2774 to store the new value in the parameter alist. */
2775
2776 void
2777 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2778 {
2779 Lisp_Object tail;
2780
2781 /* If both of these parameters are present, it's more efficient to
2782 set them both at once. So we wait until we've looked at the
2783 entire list before we set them. */
2784 int width, height;
2785
2786 /* Same here. */
2787 Lisp_Object left, top;
2788
2789 /* Same with these. */
2790 Lisp_Object icon_left, icon_top;
2791
2792 /* Record in these vectors all the parms specified. */
2793 Lisp_Object *parms;
2794 Lisp_Object *values;
2795 ptrdiff_t i, p;
2796 int left_no_change = 0, top_no_change = 0;
2797 int icon_left_no_change = 0, icon_top_no_change = 0;
2798 int size_changed = 0;
2799 struct gcpro gcpro1, gcpro2;
2800
2801 i = 0;
2802 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2803 i++;
2804
2805 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2806 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2807
2808 /* Extract parm names and values into those vectors. */
2809
2810 i = 0;
2811 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2812 {
2813 Lisp_Object elt;
2814
2815 elt = XCAR (tail);
2816 parms[i] = Fcar (elt);
2817 values[i] = Fcdr (elt);
2818 i++;
2819 }
2820 /* TAIL and ALIST are not used again below here. */
2821 alist = tail = Qnil;
2822
2823 GCPRO2 (*parms, *values);
2824 gcpro1.nvars = i;
2825 gcpro2.nvars = i;
2826
2827 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2828 because their values appear in VALUES and strings are not valid. */
2829 top = left = Qunbound;
2830 icon_left = icon_top = Qunbound;
2831
2832 /* Provide default values for HEIGHT and WIDTH. */
2833 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2834 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2835
2836 /* Process foreground_color and background_color before anything else.
2837 They are independent of other properties, but other properties (e.g.,
2838 cursor_color) are dependent upon them. */
2839 /* Process default font as well, since fringe widths depends on it. */
2840 for (p = 0; p < i; p++)
2841 {
2842 Lisp_Object prop, val;
2843
2844 prop = parms[p];
2845 val = values[p];
2846 if (EQ (prop, Qforeground_color)
2847 || EQ (prop, Qbackground_color)
2848 || EQ (prop, Qfont))
2849 {
2850 register Lisp_Object param_index, old_value;
2851
2852 old_value = get_frame_param (f, prop);
2853 if (NILP (Fequal (val, old_value)))
2854 {
2855 store_frame_param (f, prop, val);
2856
2857 param_index = Fget (prop, Qx_frame_parameter);
2858 if (NATNUMP (param_index)
2859 && (XFASTINT (param_index)
2860 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2861 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2862 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2863 }
2864 }
2865 }
2866
2867 /* Now process them in reverse of specified order. */
2868 while (i-- != 0)
2869 {
2870 Lisp_Object prop, val;
2871
2872 prop = parms[i];
2873 val = values[i];
2874
2875 if (EQ (prop, Qwidth) && NATNUMP (val))
2876 {
2877 size_changed = 1;
2878 width = XFASTINT (val);
2879 }
2880 else if (EQ (prop, Qheight) && NATNUMP (val))
2881 {
2882 size_changed = 1;
2883 height = XFASTINT (val);
2884 }
2885 else if (EQ (prop, Qtop))
2886 top = val;
2887 else if (EQ (prop, Qleft))
2888 left = val;
2889 else if (EQ (prop, Qicon_top))
2890 icon_top = val;
2891 else if (EQ (prop, Qicon_left))
2892 icon_left = val;
2893 else if (EQ (prop, Qforeground_color)
2894 || EQ (prop, Qbackground_color)
2895 || EQ (prop, Qfont))
2896 /* Processed above. */
2897 continue;
2898 else
2899 {
2900 register Lisp_Object param_index, old_value;
2901
2902 old_value = get_frame_param (f, prop);
2903
2904 store_frame_param (f, prop, val);
2905
2906 param_index = Fget (prop, Qx_frame_parameter);
2907 if (NATNUMP (param_index)
2908 && (XFASTINT (param_index)
2909 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2910 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2911 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2912 }
2913 }
2914
2915 /* Don't die if just one of these was set. */
2916 if (EQ (left, Qunbound))
2917 {
2918 left_no_change = 1;
2919 if (f->left_pos < 0)
2920 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2921 else
2922 XSETINT (left, f->left_pos);
2923 }
2924 if (EQ (top, Qunbound))
2925 {
2926 top_no_change = 1;
2927 if (f->top_pos < 0)
2928 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2929 else
2930 XSETINT (top, f->top_pos);
2931 }
2932
2933 /* If one of the icon positions was not set, preserve or default it. */
2934 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
2935 {
2936 icon_left_no_change = 1;
2937 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2938 if (NILP (icon_left))
2939 XSETINT (icon_left, 0);
2940 }
2941 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
2942 {
2943 icon_top_no_change = 1;
2944 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2945 if (NILP (icon_top))
2946 XSETINT (icon_top, 0);
2947 }
2948
2949 /* Don't set these parameters unless they've been explicitly
2950 specified. The window might be mapped or resized while we're in
2951 this function, and we don't want to override that unless the lisp
2952 code has asked for it.
2953
2954 Don't set these parameters unless they actually differ from the
2955 window's current parameters; the window may not actually exist
2956 yet. */
2957 {
2958 Lisp_Object frame;
2959
2960 check_frame_size (f, &height, &width);
2961
2962 XSETFRAME (frame, f);
2963
2964 if (size_changed
2965 && (width != FRAME_COLS (f)
2966 || height != FRAME_LINES (f)
2967 || f->new_text_lines || f->new_text_cols))
2968 Fset_frame_size (frame, make_number (width), make_number (height));
2969
2970 if ((!NILP (left) || !NILP (top))
2971 && ! (left_no_change && top_no_change)
2972 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2973 && NUMBERP (top) && XINT (top) == f->top_pos))
2974 {
2975 int leftpos = 0;
2976 int toppos = 0;
2977
2978 /* Record the signs. */
2979 f->size_hint_flags &= ~ (XNegative | YNegative);
2980 if (EQ (left, Qminus))
2981 f->size_hint_flags |= XNegative;
2982 else if (TYPE_RANGED_INTEGERP (int, left))
2983 {
2984 leftpos = XINT (left);
2985 if (leftpos < 0)
2986 f->size_hint_flags |= XNegative;
2987 }
2988 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2989 && CONSP (XCDR (left))
2990 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
2991 {
2992 leftpos = - XINT (XCAR (XCDR (left)));
2993 f->size_hint_flags |= XNegative;
2994 }
2995 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2996 && CONSP (XCDR (left))
2997 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
2998 {
2999 leftpos = XINT (XCAR (XCDR (left)));
3000 }
3001
3002 if (EQ (top, Qminus))
3003 f->size_hint_flags |= YNegative;
3004 else if (TYPE_RANGED_INTEGERP (int, top))
3005 {
3006 toppos = XINT (top);
3007 if (toppos < 0)
3008 f->size_hint_flags |= YNegative;
3009 }
3010 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3011 && CONSP (XCDR (top))
3012 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3013 {
3014 toppos = - XINT (XCAR (XCDR (top)));
3015 f->size_hint_flags |= YNegative;
3016 }
3017 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3018 && CONSP (XCDR (top))
3019 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3020 {
3021 toppos = XINT (XCAR (XCDR (top)));
3022 }
3023
3024
3025 /* Store the numeric value of the position. */
3026 f->top_pos = toppos;
3027 f->left_pos = leftpos;
3028
3029 f->win_gravity = NorthWestGravity;
3030
3031 /* Actually set that position, and convert to absolute. */
3032 x_set_offset (f, leftpos, toppos, -1);
3033 }
3034
3035 if ((!NILP (icon_left) || !NILP (icon_top))
3036 && ! (icon_left_no_change && icon_top_no_change))
3037 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3038 }
3039
3040 UNGCPRO;
3041 }
3042
3043
3044 /* Insert a description of internally-recorded parameters of frame X
3045 into the parameter alist *ALISTPTR that is to be given to the user.
3046 Only parameters that are specific to the X window system
3047 and whose values are not correctly recorded in the frame's
3048 param_alist need to be considered here. */
3049
3050 void
3051 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3052 {
3053 char buf[16];
3054 Lisp_Object tem;
3055 unsigned long w;
3056
3057 /* Represent negative positions (off the top or left screen edge)
3058 in a way that Fmodify_frame_parameters will understand correctly. */
3059 XSETINT (tem, f->left_pos);
3060 if (f->left_pos >= 0)
3061 store_in_alist (alistptr, Qleft, tem);
3062 else
3063 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3064
3065 XSETINT (tem, f->top_pos);
3066 if (f->top_pos >= 0)
3067 store_in_alist (alistptr, Qtop, tem);
3068 else
3069 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3070
3071 store_in_alist (alistptr, Qborder_width,
3072 make_number (f->border_width));
3073 store_in_alist (alistptr, Qinternal_border_width,
3074 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3075 store_in_alist (alistptr, Qleft_fringe,
3076 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3077 store_in_alist (alistptr, Qright_fringe,
3078 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3079 store_in_alist (alistptr, Qscroll_bar_width,
3080 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3081 ? make_number (0)
3082 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3083 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3084 /* nil means "use default width"
3085 for non-toolkit scroll bar.
3086 ruler-mode.el depends on this. */
3087 : Qnil));
3088 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3089 MS-Windows it returns a value whose type is HANDLE, which is
3090 actually a pointer. Explicit casting avoids compiler
3091 warnings. */
3092 w = (unsigned long) FRAME_X_WINDOW (f);
3093 sprintf (buf, "%lu", w);
3094 store_in_alist (alistptr, Qwindow_id,
3095 build_string (buf));
3096 #ifdef HAVE_X_WINDOWS
3097 #ifdef USE_X_TOOLKIT
3098 /* Tooltip frame may not have this widget. */
3099 if (FRAME_X_OUTPUT (f)->widget)
3100 #endif
3101 {
3102 w = (unsigned long) FRAME_OUTER_WINDOW (f);
3103 sprintf (buf, "%lu", w);
3104 }
3105 store_in_alist (alistptr, Qouter_window_id,
3106 build_string (buf));
3107 #endif
3108 store_in_alist (alistptr, Qicon_name, f->icon_name);
3109 FRAME_SAMPLE_VISIBILITY (f);
3110 store_in_alist (alistptr, Qvisibility,
3111 (FRAME_VISIBLE_P (f) ? Qt
3112 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3113 store_in_alist (alistptr, Qdisplay,
3114 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3115
3116 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3117 tem = Qnil;
3118 else
3119 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3120 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3121 store_in_alist (alistptr, Qparent_id, tem);
3122 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3123 }
3124
3125
3126 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3127 the previous value of that parameter, NEW_VALUE is the new value. */
3128
3129 void
3130 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3131 {
3132 if (NILP (new_value))
3133 f->want_fullscreen = FULLSCREEN_NONE;
3134 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3135 f->want_fullscreen = FULLSCREEN_BOTH;
3136 else if (EQ (new_value, Qfullwidth))
3137 f->want_fullscreen = FULLSCREEN_WIDTH;
3138 else if (EQ (new_value, Qfullheight))
3139 f->want_fullscreen = FULLSCREEN_HEIGHT;
3140 else if (EQ (new_value, Qmaximized))
3141 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3142
3143 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3144 FRAME_TERMINAL (f)->fullscreen_hook (f);
3145 }
3146
3147
3148 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3149 the previous value of that parameter, NEW_VALUE is the new value. */
3150
3151 void
3152 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3153 {
3154 if (NILP (new_value))
3155 f->extra_line_spacing = 0;
3156 else if (NATNUMP (new_value))
3157 f->extra_line_spacing = XFASTINT (new_value);
3158 else
3159 signal_error ("Invalid line-spacing", new_value);
3160 if (FRAME_VISIBLE_P (f))
3161 redraw_frame (f);
3162 }
3163
3164
3165 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3166 the previous value of that parameter, NEW_VALUE is the new value. */
3167
3168 void
3169 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3170 {
3171 Lisp_Object bgcolor;
3172
3173 if (NILP (new_value))
3174 f->gamma = 0;
3175 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3176 /* The value 0.4545 is the normal viewing gamma. */
3177 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3178 else
3179 signal_error ("Invalid screen-gamma", new_value);
3180
3181 /* Apply the new gamma value to the frame background. */
3182 bgcolor = Fassq (Qbackground_color, f->param_alist);
3183 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3184 {
3185 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3186 if (NATNUMP (parm_index)
3187 && (XFASTINT (parm_index)
3188 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3189 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3190 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3191 (f, bgcolor, Qnil);
3192 }
3193
3194 Fclear_face_cache (Qnil);
3195 }
3196
3197
3198 void
3199 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3200 {
3201 Lisp_Object font_object, font_param = Qnil;
3202 int fontset = -1;
3203
3204 /* Set the frame parameter back to the old value because we may
3205 fail to use ARG as the new parameter value. */
3206 store_frame_param (f, Qfont, oldval);
3207
3208 /* ARG is a fontset name, a font name, a cons of fontset name and a
3209 font object, or a font object. In the last case, this function
3210 never fail. */
3211 if (STRINGP (arg))
3212 {
3213 font_param = arg;
3214 fontset = fs_query_fontset (arg, 0);
3215 if (fontset < 0)
3216 {
3217 font_object = font_open_by_name (f, SSDATA (arg));
3218 if (NILP (font_object))
3219 error ("Font `%s' is not defined", SSDATA (arg));
3220 arg = AREF (font_object, FONT_NAME_INDEX);
3221 }
3222 else if (fontset > 0)
3223 {
3224 Lisp_Object ascii_font = fontset_ascii (fontset);
3225
3226 font_object = font_open_by_name (f, SSDATA (ascii_font));
3227 if (NILP (font_object))
3228 error ("Font `%s' is not defined", SDATA (arg));
3229 arg = AREF (font_object, FONT_NAME_INDEX);
3230 }
3231 else
3232 error ("The default fontset can't be used for a frame font");
3233 }
3234 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3235 {
3236 /* This is the case that the ASCII font of F's fontset XCAR
3237 (arg) is changed to the font XCDR (arg) by
3238 `set-fontset-font'. */
3239 fontset = fs_query_fontset (XCAR (arg), 0);
3240 if (fontset < 0)
3241 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3242 font_object = XCDR (arg);
3243 arg = AREF (font_object, FONT_NAME_INDEX);
3244 font_param = Ffont_get (font_object, QCname);
3245 }
3246 else if (FONT_OBJECT_P (arg))
3247 {
3248 font_object = arg;
3249 font_param = Ffont_get (font_object, QCname);
3250 /* This is to store the XLFD font name in the frame parameter for
3251 backward compatibility. We should store the font-object
3252 itself in the future. */
3253 arg = AREF (font_object, FONT_NAME_INDEX);
3254 fontset = FRAME_FONTSET (f);
3255 /* Check if we can use the current fontset. If not, set FONTSET
3256 to -1 to generate a new fontset from FONT-OBJECT. */
3257 if (fontset >= 0)
3258 {
3259 Lisp_Object ascii_font = fontset_ascii (fontset);
3260 Lisp_Object spec = font_spec_from_name (ascii_font);
3261
3262 if (! font_match_p (spec, font_object))
3263 fontset = -1;
3264 }
3265 }
3266 else
3267 signal_error ("Invalid font", arg);
3268
3269 if (! NILP (Fequal (font_object, oldval)))
3270 return;
3271
3272 x_new_font (f, font_object, fontset);
3273 store_frame_param (f, Qfont, arg);
3274 #ifdef HAVE_X_WINDOWS
3275 store_frame_param (f, Qfont_param, font_param);
3276 #endif
3277 /* Recalculate toolbar height. */
3278 f->n_tool_bar_rows = 0;
3279 /* Ensure we redraw it. */
3280 clear_current_matrices (f);
3281
3282 recompute_basic_faces (f);
3283
3284 do_pending_window_change (0);
3285
3286 /* We used to call face-set-after-frame-default here, but it leads to
3287 recursive calls (since that function can set the `default' face's
3288 font which in turns changes the frame's `font' parameter).
3289 Also I don't know what this call is meant to do, but it seems the
3290 wrong way to do it anyway (it does a lot more work than what seems
3291 reasonable in response to a change to `font'). */
3292 }
3293
3294
3295 void
3296 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3297 {
3298 if (! NILP (new_value)
3299 && !CONSP (new_value))
3300 {
3301 char *p0, *p1;
3302
3303 CHECK_STRING (new_value);
3304 p0 = p1 = SSDATA (new_value);
3305 new_value = Qnil;
3306 while (*p0)
3307 {
3308 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3309 if (p0 < p1)
3310 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3311 new_value);
3312 if (*p1)
3313 {
3314 int c;
3315
3316 while ((c = *++p1) && isspace (c));
3317 }
3318 p0 = p1;
3319 }
3320 new_value = Fnreverse (new_value);
3321 }
3322
3323 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3324 return;
3325
3326 if (FRAME_FONT (f))
3327 free_all_realized_faces (Qnil);
3328
3329 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3330 if (NILP (new_value))
3331 {
3332 if (NILP (old_value))
3333 error ("No font backend available");
3334 font_update_drivers (f, old_value);
3335 error ("None of specified font backends are available");
3336 }
3337 store_frame_param (f, Qfont_backend, new_value);
3338
3339 if (FRAME_FONT (f))
3340 {
3341 Lisp_Object frame;
3342
3343 XSETFRAME (frame, f);
3344 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3345 ++face_change_count;
3346 ++windows_or_buffers_changed;
3347 }
3348 }
3349
3350
3351 void
3352 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3353 {
3354 compute_fringe_widths (f, 1);
3355 #ifdef HAVE_X_WINDOWS
3356 /* Must adjust this so window managers report correct number of columns. */
3357 if (FRAME_X_WINDOW (f) != 0)
3358 x_wm_set_size_hint (f, 0, 0);
3359 #endif
3360 }
3361
3362 void
3363 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3364 {
3365 CHECK_NUMBER (arg);
3366
3367 if (XINT (arg) == f->border_width)
3368 return;
3369
3370 if (FRAME_X_WINDOW (f) != 0)
3371 error ("Cannot change the border width of a frame");
3372
3373 f->border_width = XINT (arg);
3374 }
3375
3376 void
3377 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3378 {
3379 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3380
3381 CHECK_NUMBER (arg);
3382 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3383 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3384 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3385
3386 #ifdef USE_X_TOOLKIT
3387 if (FRAME_X_OUTPUT (f)->edit_widget)
3388 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3389 #endif
3390
3391 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3392 return;
3393
3394 if (FRAME_X_WINDOW (f) != 0)
3395 {
3396 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3397 SET_FRAME_GARBAGED (f);
3398 do_pending_window_change (0);
3399 }
3400 else
3401 SET_FRAME_GARBAGED (f);
3402 }
3403
3404 void
3405 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3406 {
3407 Lisp_Object frame;
3408 XSETFRAME (frame, f);
3409
3410 if (NILP (value))
3411 Fmake_frame_invisible (frame, Qt);
3412 else if (EQ (value, Qicon))
3413 Ficonify_frame (frame);
3414 else
3415 Fmake_frame_visible (frame);
3416 }
3417
3418 void
3419 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3420 {
3421 f->auto_raise = !EQ (Qnil, arg);
3422 }
3423
3424 void
3425 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3426 {
3427 f->auto_lower = !EQ (Qnil, arg);
3428 }
3429
3430 void
3431 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3432 {
3433 f->no_split = !NILP (arg);
3434 }
3435
3436 void
3437 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3438 {
3439 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3440 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3441 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3442 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3443 {
3444 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3445 = (NILP (arg)
3446 ? vertical_scroll_bar_none
3447 : EQ (Qleft, arg)
3448 ? vertical_scroll_bar_left
3449 : EQ (Qright, arg)
3450 ? vertical_scroll_bar_right
3451 : EQ (Qleft, Vdefault_frame_scroll_bars)
3452 ? vertical_scroll_bar_left
3453 : EQ (Qright, Vdefault_frame_scroll_bars)
3454 ? vertical_scroll_bar_right
3455 : vertical_scroll_bar_none);
3456
3457 /* We set this parameter before creating the X window for the
3458 frame, so we can get the geometry right from the start.
3459 However, if the window hasn't been created yet, we shouldn't
3460 call x_set_window_size. */
3461 if (FRAME_X_WINDOW (f))
3462 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3463 do_pending_window_change (0);
3464 }
3465 }
3466
3467 void
3468 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3469 {
3470 int wid = FRAME_COLUMN_WIDTH (f);
3471
3472 if (NILP (arg))
3473 {
3474 x_set_scroll_bar_default_width (f);
3475
3476 if (FRAME_X_WINDOW (f))
3477 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3478 do_pending_window_change (0);
3479 }
3480 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3481 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3482 {
3483 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3484 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3485
3486 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3487 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3488 if (FRAME_X_WINDOW (f))
3489 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3490 do_pending_window_change (0);
3491 }
3492
3493 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3494 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3495 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3496 }
3497
3498
3499
3500 /* Return non-nil if frame F wants a bitmap icon. */
3501
3502 Lisp_Object
3503 x_icon_type (FRAME_PTR f)
3504 {
3505 Lisp_Object tem;
3506
3507 tem = assq_no_quit (Qicon_type, f->param_alist);
3508 if (CONSP (tem))
3509 return XCDR (tem);
3510 else
3511 return Qnil;
3512 }
3513
3514 void
3515 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3516 {
3517 double alpha = 1.0;
3518 double newval[2];
3519 int i;
3520 Lisp_Object item;
3521
3522 for (i = 0; i < 2; i++)
3523 {
3524 newval[i] = 1.0;
3525 if (CONSP (arg))
3526 {
3527 item = CAR (arg);
3528 arg = CDR (arg);
3529 }
3530 else
3531 item = arg;
3532
3533 if (NILP (item))
3534 alpha = - 1.0;
3535 else if (FLOATP (item))
3536 {
3537 alpha = XFLOAT_DATA (item);
3538 if (alpha < 0.0 || 1.0 < alpha)
3539 args_out_of_range (make_float (0.0), make_float (1.0));
3540 }
3541 else if (INTEGERP (item))
3542 {
3543 EMACS_INT ialpha = XINT (item);
3544 if (ialpha < 0 || 100 < ialpha)
3545 args_out_of_range (make_number (0), make_number (100));
3546 else
3547 alpha = ialpha / 100.0;
3548 }
3549 else
3550 wrong_type_argument (Qnumberp, item);
3551 newval[i] = alpha;
3552 }
3553
3554 for (i = 0; i < 2; i++)
3555 f->alpha[i] = newval[i];
3556
3557 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3558 BLOCK_INPUT;
3559 x_set_frame_alpha (f);
3560 UNBLOCK_INPUT;
3561 #endif
3562
3563 return;
3564 }
3565
3566 \f
3567 /* Subroutines of creating an X frame. */
3568
3569 /* Make sure that Vx_resource_name is set to a reasonable value.
3570 Fix it up, or set it to `emacs' if it is too hopeless. */
3571
3572 void
3573 validate_x_resource_name (void)
3574 {
3575 ptrdiff_t len = 0;
3576 /* Number of valid characters in the resource name. */
3577 ptrdiff_t good_count = 0;
3578 /* Number of invalid characters in the resource name. */
3579 ptrdiff_t bad_count = 0;
3580 Lisp_Object new;
3581 ptrdiff_t i;
3582
3583 if (!STRINGP (Vx_resource_class))
3584 Vx_resource_class = build_string (EMACS_CLASS);
3585
3586 if (STRINGP (Vx_resource_name))
3587 {
3588 unsigned char *p = SDATA (Vx_resource_name);
3589
3590 len = SBYTES (Vx_resource_name);
3591
3592 /* Only letters, digits, - and _ are valid in resource names.
3593 Count the valid characters and count the invalid ones. */
3594 for (i = 0; i < len; i++)
3595 {
3596 int c = p[i];
3597 if (! ((c >= 'a' && c <= 'z')
3598 || (c >= 'A' && c <= 'Z')
3599 || (c >= '0' && c <= '9')
3600 || c == '-' || c == '_'))
3601 bad_count++;
3602 else
3603 good_count++;
3604 }
3605 }
3606 else
3607 /* Not a string => completely invalid. */
3608 bad_count = 5, good_count = 0;
3609
3610 /* If name is valid already, return. */
3611 if (bad_count == 0)
3612 return;
3613
3614 /* If name is entirely invalid, or nearly so, or is so implausibly
3615 large that alloca might not work, use `emacs'. */
3616 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3617 {
3618 Vx_resource_name = build_string ("emacs");
3619 return;
3620 }
3621
3622 /* Name is partly valid. Copy it and replace the invalid characters
3623 with underscores. */
3624
3625 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3626
3627 for (i = 0; i < len; i++)
3628 {
3629 int c = SREF (new, i);
3630 if (! ((c >= 'a' && c <= 'z')
3631 || (c >= 'A' && c <= 'Z')
3632 || (c >= '0' && c <= '9')
3633 || c == '-' || c == '_'))
3634 SSET (new, i, '_');
3635 }
3636 }
3637
3638
3639 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3640 extern Display_Info *check_x_display_info (Lisp_Object);
3641
3642
3643 /* Get specified attribute from resource database RDB.
3644 See Fx_get_resource below for other parameters. */
3645
3646 static Lisp_Object
3647 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3648 {
3649 register char *value;
3650 char *name_key;
3651 char *class_key;
3652
3653 CHECK_STRING (attribute);
3654 CHECK_STRING (class);
3655
3656 if (!NILP (component))
3657 CHECK_STRING (component);
3658 if (!NILP (subclass))
3659 CHECK_STRING (subclass);
3660 if (NILP (component) != NILP (subclass))
3661 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3662
3663 validate_x_resource_name ();
3664
3665 /* Allocate space for the components, the dots which separate them,
3666 and the final '\0'. Make them big enough for the worst case. */
3667 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3668 + (STRINGP (component)
3669 ? SBYTES (component) : 0)
3670 + SBYTES (attribute)
3671 + 3);
3672
3673 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3674 + SBYTES (class)
3675 + (STRINGP (subclass)
3676 ? SBYTES (subclass) : 0)
3677 + 3);
3678
3679 /* Start with emacs.FRAMENAME for the name (the specific one)
3680 and with `Emacs' for the class key (the general one). */
3681 strcpy (name_key, SSDATA (Vx_resource_name));
3682 strcpy (class_key, SSDATA (Vx_resource_class));
3683
3684 strcat (class_key, ".");
3685 strcat (class_key, SSDATA (class));
3686
3687 if (!NILP (component))
3688 {
3689 strcat (class_key, ".");
3690 strcat (class_key, SSDATA (subclass));
3691
3692 strcat (name_key, ".");
3693 strcat (name_key, SSDATA (component));
3694 }
3695
3696 strcat (name_key, ".");
3697 strcat (name_key, SSDATA (attribute));
3698
3699 value = x_get_string_resource (rdb, name_key, class_key);
3700
3701 if (value != (char *) 0 && *value)
3702 return build_string (value);
3703 else
3704 return Qnil;
3705 }
3706
3707
3708 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3709 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3710 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3711 class, where INSTANCE is the name under which Emacs was invoked, or
3712 the name specified by the `-name' or `-rn' command-line arguments.
3713
3714 The optional arguments COMPONENT and SUBCLASS add to the key and the
3715 class, respectively. You must specify both of them or neither.
3716 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3717 and the class is `Emacs.CLASS.SUBCLASS'. */)
3718 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3719 {
3720 #ifdef HAVE_X_WINDOWS
3721 check_x ();
3722 #endif
3723
3724 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3725 attribute, class, component, subclass);
3726 }
3727
3728 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3729
3730 Lisp_Object
3731 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3732 {
3733 return xrdb_get_resource (dpyinfo->xrdb,
3734 attribute, class, component, subclass);
3735 }
3736
3737 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3738 /* Used when C code wants a resource value. */
3739 /* Called from oldXMenu/Create.c. */
3740 char *
3741 x_get_resource_string (const char *attribute, const char *class)
3742 {
3743 char *name_key;
3744 char *class_key;
3745 char *result;
3746 struct frame *sf = SELECTED_FRAME ();
3747 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3748 USE_SAFE_ALLOCA;
3749
3750 /* Allocate space for the components, the dots which separate them,
3751 and the final '\0'. */
3752 SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
3753 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3754 + strlen (class) + 2);
3755
3756 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3757 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3758
3759 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3760 name_key, class_key);
3761 SAFE_FREE ();
3762 return result;
3763 }
3764 #endif
3765
3766 /* Return the value of parameter PARAM.
3767
3768 First search ALIST, then Vdefault_frame_alist, then the X defaults
3769 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3770
3771 Convert the resource to the type specified by desired_type.
3772
3773 If no default is specified, return Qunbound. If you call
3774 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3775 and don't let it get stored in any Lisp-visible variables! */
3776
3777 Lisp_Object
3778 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3779 const char *attribute, const char *class, enum resource_types type)
3780 {
3781 register Lisp_Object tem;
3782
3783 tem = Fassq (param, alist);
3784
3785 if (!NILP (tem))
3786 {
3787 /* If we find this parm in ALIST, clear it out
3788 so that it won't be "left over" at the end. */
3789 Lisp_Object tail;
3790 XSETCAR (tem, Qnil);
3791 /* In case the parameter appears more than once in the alist,
3792 clear it out. */
3793 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3794 if (CONSP (XCAR (tail))
3795 && EQ (XCAR (XCAR (tail)), param))
3796 XSETCAR (XCAR (tail), Qnil);
3797 }
3798 else
3799 tem = Fassq (param, Vdefault_frame_alist);
3800
3801 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3802 look in the X resources. */
3803 if (EQ (tem, Qnil))
3804 {
3805 if (attribute && dpyinfo)
3806 {
3807 tem = display_x_get_resource (dpyinfo,
3808 build_string (attribute),
3809 build_string (class),
3810 Qnil, Qnil);
3811
3812 if (NILP (tem))
3813 return Qunbound;
3814
3815 switch (type)
3816 {
3817 case RES_TYPE_NUMBER:
3818 return make_number (atoi (SSDATA (tem)));
3819
3820 case RES_TYPE_BOOLEAN_NUMBER:
3821 if (!strcmp (SSDATA (tem), "on")
3822 || !strcmp (SSDATA (tem), "true"))
3823 return make_number (1);
3824 return make_number (atoi (SSDATA (tem)));
3825 break;
3826
3827 case RES_TYPE_FLOAT:
3828 return make_float (atof (SSDATA (tem)));
3829
3830 case RES_TYPE_BOOLEAN:
3831 tem = Fdowncase (tem);
3832 if (!strcmp (SSDATA (tem), "on")
3833 #ifdef HAVE_NS
3834 || !strcmp (SSDATA (tem), "yes")
3835 #endif
3836 || !strcmp (SSDATA (tem), "true"))
3837 return Qt;
3838 else
3839 return Qnil;
3840
3841 case RES_TYPE_STRING:
3842 return tem;
3843
3844 case RES_TYPE_SYMBOL:
3845 /* As a special case, we map the values `true' and `on'
3846 to Qt, and `false' and `off' to Qnil. */
3847 {
3848 Lisp_Object lower;
3849 lower = Fdowncase (tem);
3850 if (!strcmp (SSDATA (lower), "on")
3851 #ifdef HAVE_NS
3852 || !strcmp (SSDATA (lower), "yes")
3853 #endif
3854 || !strcmp (SSDATA (lower), "true"))
3855 return Qt;
3856 else if (!strcmp (SSDATA (lower), "off")
3857 #ifdef HAVE_NS
3858 || !strcmp (SSDATA (lower), "no")
3859 #endif
3860 || !strcmp (SSDATA (lower), "false"))
3861 return Qnil;
3862 else
3863 return Fintern (tem, Qnil);
3864 }
3865
3866 default:
3867 abort ();
3868 }
3869 }
3870 else
3871 return Qunbound;
3872 }
3873 return Fcdr (tem);
3874 }
3875
3876 static Lisp_Object
3877 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3878 const char *attribute, const char *class,
3879 enum resource_types type)
3880 {
3881 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3882 alist, param, attribute, class, type);
3883 }
3884
3885 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3886
3887 Lisp_Object
3888 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3889 Lisp_Object param,
3890 const char *attribute, const char *class,
3891 enum resource_types type)
3892 {
3893 Lisp_Object value;
3894
3895 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3896 attribute, class, type);
3897 if (! NILP (value) && ! EQ (value, Qunbound))
3898 store_frame_param (f, param, value);
3899
3900 return value;
3901 }
3902
3903
3904 /* Record in frame F the specified or default value according to ALIST
3905 of the parameter named PROP (a Lisp symbol).
3906 If no value is specified for PROP, look for an X default for XPROP
3907 on the frame named NAME.
3908 If that is not found either, use the value DEFLT. */
3909
3910 Lisp_Object
3911 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3912 Lisp_Object deflt, const char *xprop, const char *xclass,
3913 enum resource_types type)
3914 {
3915 Lisp_Object tem;
3916
3917 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3918 if (EQ (tem, Qunbound))
3919 tem = deflt;
3920 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3921 return tem;
3922 }
3923
3924
3925
3926 \f
3927 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3928 make-docfile: the documentation string in ns-win.el was used for
3929 x-parse-geometry even in non-NS builds.
3930
3931 With two definitions of x-parse-geometry in this file, various
3932 things still get confused (eg M-x apropos documentation), so that
3933 it is best if the two definitions just share the same doc-string.
3934 */
3935 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3936 doc: /* Parse a display geometry string STRING.
3937 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3938 The properties returned may include `top', `left', `height', and `width'.
3939 For X, the value of `left' or `top' may be an integer,
3940 or a list (+ N) meaning N pixels relative to top/left corner,
3941 or a list (- N) meaning -N pixels relative to bottom/right corner.
3942 On Nextstep, this just calls `ns-parse-geometry'. */)
3943 (Lisp_Object string)
3944 {
3945 #ifdef HAVE_NS
3946 call1 (Qns_parse_geometry, string);
3947 #else
3948 int geometry, x, y;
3949 unsigned int width, height;
3950 Lisp_Object result;
3951
3952 CHECK_STRING (string);
3953
3954 geometry = XParseGeometry (SSDATA (string),
3955 &x, &y, &width, &height);
3956 result = Qnil;
3957 if (geometry & XValue)
3958 {
3959 Lisp_Object element;
3960
3961 if (x >= 0 && (geometry & XNegative))
3962 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3963 else if (x < 0 && ! (geometry & XNegative))
3964 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3965 else
3966 element = Fcons (Qleft, make_number (x));
3967 result = Fcons (element, result);
3968 }
3969
3970 if (geometry & YValue)
3971 {
3972 Lisp_Object element;
3973
3974 if (y >= 0 && (geometry & YNegative))
3975 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3976 else if (y < 0 && ! (geometry & YNegative))
3977 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3978 else
3979 element = Fcons (Qtop, make_number (y));
3980 result = Fcons (element, result);
3981 }
3982
3983 if (geometry & WidthValue)
3984 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3985 if (geometry & HeightValue)
3986 result = Fcons (Fcons (Qheight, make_number (height)), result);
3987
3988 return result;
3989 #endif /* HAVE_NS */
3990 }
3991
3992
3993 /* Calculate the desired size and position of frame F.
3994 Return the flags saying which aspects were specified.
3995
3996 Also set the win_gravity and size_hint_flags of F.
3997
3998 Adjust height for toolbar if TOOLBAR_P is 1.
3999
4000 This function does not make the coordinates positive. */
4001
4002 #define DEFAULT_ROWS 35
4003 #define DEFAULT_COLS 80
4004
4005 int
4006 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
4007 {
4008 register Lisp_Object tem0, tem1, tem2;
4009 long window_prompting = 0;
4010 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4011
4012 /* Default values if we fall through.
4013 Actually, if that happens we should get
4014 window manager prompting. */
4015 SET_FRAME_COLS (f, DEFAULT_COLS);
4016 FRAME_LINES (f) = DEFAULT_ROWS;
4017 /* Window managers expect that if program-specified
4018 positions are not (0,0), they're intentional, not defaults. */
4019 f->top_pos = 0;
4020 f->left_pos = 0;
4021
4022 /* Ensure that old new_text_cols and new_text_lines will not override the
4023 values set here. */
4024 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4025 f->new_text_cols = f->new_text_lines = 0;
4026
4027 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4028 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4029 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4030 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4031 {
4032 if (!EQ (tem0, Qunbound))
4033 {
4034 CHECK_NUMBER (tem0);
4035 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4036 xsignal1 (Qargs_out_of_range, tem0);
4037 FRAME_LINES (f) = XINT (tem0);
4038 }
4039 if (!EQ (tem1, Qunbound))
4040 {
4041 CHECK_NUMBER (tem1);
4042 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4043 xsignal1 (Qargs_out_of_range, tem1);
4044 SET_FRAME_COLS (f, XINT (tem1));
4045 }
4046 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4047 window_prompting |= USSize;
4048 else
4049 window_prompting |= PSize;
4050 }
4051
4052 f->scroll_bar_actual_width
4053 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4054
4055 /* This used to be done _before_ calling x_figure_window_size, but
4056 since the height is reset here, this was really a no-op. I
4057 assume that moving it here does what Gerd intended (although he
4058 no longer can remember what that was... ++KFS, 2003-03-25. */
4059
4060 /* Add the tool-bar height to the initial frame height so that the
4061 user gets a text display area of the size he specified with -g or
4062 via .Xdefaults. Later changes of the tool-bar height don't
4063 change the frame size. This is done so that users can create
4064 tall Emacs frames without having to guess how tall the tool-bar
4065 will get. */
4066 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4067 {
4068 int margin, relief, bar_height;
4069
4070 relief = (tool_bar_button_relief >= 0
4071 ? tool_bar_button_relief
4072 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4073
4074 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4075 margin = XFASTINT (Vtool_bar_button_margin);
4076 else if (CONSP (Vtool_bar_button_margin)
4077 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4078 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4079 else
4080 margin = 0;
4081
4082 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4083 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4084 }
4085
4086 compute_fringe_widths (f, 0);
4087
4088 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4089 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4090
4091 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4092 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4093 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4094 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4095 {
4096 if (EQ (tem0, Qminus))
4097 {
4098 f->top_pos = 0;
4099 window_prompting |= YNegative;
4100 }
4101 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4102 && CONSP (XCDR (tem0))
4103 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4104 {
4105 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4106 window_prompting |= YNegative;
4107 }
4108 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4109 && CONSP (XCDR (tem0))
4110 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4111 {
4112 f->top_pos = XINT (XCAR (XCDR (tem0)));
4113 }
4114 else if (EQ (tem0, Qunbound))
4115 f->top_pos = 0;
4116 else
4117 {
4118 CHECK_NUMBER (tem0);
4119 f->top_pos = XINT (tem0);
4120 if (f->top_pos < 0)
4121 window_prompting |= YNegative;
4122 }
4123
4124 if (EQ (tem1, Qminus))
4125 {
4126 f->left_pos = 0;
4127 window_prompting |= XNegative;
4128 }
4129 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4130 && CONSP (XCDR (tem1))
4131 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4132 {
4133 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4134 window_prompting |= XNegative;
4135 }
4136 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4137 && CONSP (XCDR (tem1))
4138 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4139 {
4140 f->left_pos = XINT (XCAR (XCDR (tem1)));
4141 }
4142 else if (EQ (tem1, Qunbound))
4143 f->left_pos = 0;
4144 else
4145 {
4146 CHECK_NUMBER (tem1);
4147 f->left_pos = XINT (tem1);
4148 if (f->left_pos < 0)
4149 window_prompting |= XNegative;
4150 }
4151
4152 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4153 window_prompting |= USPosition;
4154 else
4155 window_prompting |= PPosition;
4156 }
4157
4158 if (window_prompting & XNegative)
4159 {
4160 if (window_prompting & YNegative)
4161 f->win_gravity = SouthEastGravity;
4162 else
4163 f->win_gravity = NorthEastGravity;
4164 }
4165 else
4166 {
4167 if (window_prompting & YNegative)
4168 f->win_gravity = SouthWestGravity;
4169 else
4170 f->win_gravity = NorthWestGravity;
4171 }
4172
4173 f->size_hint_flags = window_prompting;
4174
4175 return window_prompting;
4176 }
4177
4178
4179
4180 #endif /* HAVE_WINDOW_SYSTEM */
4181
4182 void
4183 frame_make_pointer_invisible (void)
4184 {
4185 if (! NILP (Vmake_pointer_invisible))
4186 {
4187 struct frame *f;
4188 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4189 return;
4190
4191 f = SELECTED_FRAME ();
4192 if (f && !f->pointer_invisible
4193 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4194 {
4195 f->mouse_moved = 0;
4196 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4197 f->pointer_invisible = 1;
4198 }
4199 }
4200 }
4201
4202 void
4203 frame_make_pointer_visible (void)
4204 {
4205 /* We don't check Vmake_pointer_invisible here in case the
4206 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4207 struct frame *f;
4208
4209 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4210 return;
4211
4212 f = SELECTED_FRAME ();
4213 if (f && f->pointer_invisible && f->mouse_moved
4214 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4215 {
4216 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4217 f->pointer_invisible = 0;
4218 }
4219 }
4220
4221 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4222 Sframe_pointer_visible_p, 0, 1, 0,
4223 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4224 Otherwise it returns nil. FRAME omitted or nil means the
4225 selected frame. This is useful when `make-pointer-invisible' is set. */)
4226 (Lisp_Object frame)
4227 {
4228 if (NILP (frame))
4229 frame = selected_frame;
4230
4231 CHECK_FRAME (frame);
4232
4233 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4234 }
4235
4236 \f
4237 /***********************************************************************
4238 Initialization
4239 ***********************************************************************/
4240
4241 void
4242 syms_of_frame (void)
4243 {
4244 DEFSYM (Qframep, "framep");
4245 DEFSYM (Qframe_live_p, "frame-live-p");
4246 DEFSYM (Qexplicit_name, "explicit-name");
4247 DEFSYM (Qheight, "height");
4248 DEFSYM (Qicon, "icon");
4249 DEFSYM (Qminibuffer, "minibuffer");
4250 DEFSYM (Qmodeline, "modeline");
4251 DEFSYM (Qonly, "only");
4252 DEFSYM (Qwidth, "width");
4253 DEFSYM (Qgeometry, "geometry");
4254 DEFSYM (Qicon_left, "icon-left");
4255 DEFSYM (Qicon_top, "icon-top");
4256 DEFSYM (Qtooltip, "tooltip");
4257 DEFSYM (Qleft, "left");
4258 DEFSYM (Qright, "right");
4259 DEFSYM (Quser_position, "user-position");
4260 DEFSYM (Quser_size, "user-size");
4261 DEFSYM (Qwindow_id, "window-id");
4262 #ifdef HAVE_X_WINDOWS
4263 DEFSYM (Qouter_window_id, "outer-window-id");
4264 #endif
4265 DEFSYM (Qparent_id, "parent-id");
4266 DEFSYM (Qx, "x");
4267 DEFSYM (Qw32, "w32");
4268 DEFSYM (Qpc, "pc");
4269 DEFSYM (Qmac, "mac");
4270 DEFSYM (Qns, "ns");
4271 DEFSYM (Qvisible, "visible");
4272 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4273 DEFSYM (Qbuffer_list, "buffer-list");
4274 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4275 DEFSYM (Qdisplay_type, "display-type");
4276 DEFSYM (Qbackground_mode, "background-mode");
4277 DEFSYM (Qnoelisp, "noelisp");
4278 DEFSYM (Qtty_color_mode, "tty-color-mode");
4279 DEFSYM (Qtty, "tty");
4280 DEFSYM (Qtty_type, "tty-type");
4281
4282 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4283
4284 DEFSYM (Qfullwidth, "fullwidth");
4285 DEFSYM (Qfullheight, "fullheight");
4286 DEFSYM (Qfullboth, "fullboth");
4287 DEFSYM (Qmaximized, "maximized");
4288 DEFSYM (Qx_resource_name, "x-resource-name");
4289 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4290
4291 DEFSYM (Qterminal, "terminal");
4292 DEFSYM (Qterminal_live_p, "terminal-live-p");
4293
4294 #ifdef HAVE_NS
4295 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4296 #endif
4297
4298 {
4299 int i;
4300
4301 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4302 {
4303 Lisp_Object v = intern_c_string (frame_parms[i].name);
4304 if (frame_parms[i].variable)
4305 {
4306 *frame_parms[i].variable = v;
4307 staticpro (frame_parms[i].variable);
4308 }
4309 Fput (v, Qx_frame_parameter, make_number (i));
4310 }
4311 }
4312
4313 #ifdef HAVE_WINDOW_SYSTEM
4314 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4315 doc: /* The name Emacs uses to look up X resources.
4316 `x-get-resource' uses this as the first component of the instance name
4317 when requesting resource values.
4318 Emacs initially sets `x-resource-name' to the name under which Emacs
4319 was invoked, or to the value specified with the `-name' or `-rn'
4320 switches, if present.
4321
4322 It may be useful to bind this variable locally around a call
4323 to `x-get-resource'. See also the variable `x-resource-class'. */);
4324 Vx_resource_name = Qnil;
4325
4326 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4327 doc: /* The class Emacs uses to look up X resources.
4328 `x-get-resource' uses this as the first component of the instance class
4329 when requesting resource values.
4330
4331 Emacs initially sets `x-resource-class' to "Emacs".
4332
4333 Setting this variable permanently is not a reasonable thing to do,
4334 but binding this variable locally around a call to `x-get-resource'
4335 is a reasonable practice. See also the variable `x-resource-name'. */);
4336 Vx_resource_class = build_string (EMACS_CLASS);
4337
4338 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4339 doc: /* The lower limit of the frame opacity (alpha transparency).
4340 The value should range from 0 (invisible) to 100 (completely opaque).
4341 You can also use a floating number between 0.0 and 1.0.
4342 The default is 20. */);
4343 Vframe_alpha_lower_limit = make_number (20);
4344 #endif
4345
4346 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4347 doc: /* Alist of default values for frame creation.
4348 These may be set in your init file, like this:
4349 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4350 These override values given in window system configuration data,
4351 including X Windows' defaults database.
4352 For values specific to the first Emacs frame, see `initial-frame-alist'.
4353 For window-system specific values, see `window-system-default-frame-alist'.
4354 For values specific to the separate minibuffer frame, see
4355 `minibuffer-frame-alist'.
4356 The `menu-bar-lines' element of the list controls whether new frames
4357 have menu bars; `menu-bar-mode' works by altering this element.
4358 Setting this variable does not affect existing frames, only new ones. */);
4359 Vdefault_frame_alist = Qnil;
4360
4361 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4362 doc: /* Default position of scroll bars on this window-system. */);
4363 #ifdef HAVE_WINDOW_SYSTEM
4364 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4365 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4366 default. */
4367 Vdefault_frame_scroll_bars = Qright;
4368 #else
4369 Vdefault_frame_scroll_bars = Qleft;
4370 #endif
4371 #else
4372 Vdefault_frame_scroll_bars = Qnil;
4373 #endif
4374
4375 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4376 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4377
4378 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4379 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4380 `mouse-position' calls this function, passing its usual return value as
4381 argument, and returns whatever this function returns.
4382 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4383 which need to do mouse handling at the Lisp level. */);
4384 Vmouse_position_function = Qnil;
4385
4386 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4387 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4388 If the value is an integer, highlighting is only shown after moving the
4389 mouse, while keyboard input turns off the highlight even when the mouse
4390 is over the clickable text. However, the mouse shape still indicates
4391 when the mouse is over clickable text. */);
4392 Vmouse_highlight = Qt;
4393
4394 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4395 doc: /* If non-nil, make pointer invisible while typing.
4396 The pointer becomes visible again when the mouse is moved. */);
4397 Vmake_pointer_invisible = Qt;
4398
4399 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4400 doc: /* Functions to be run before deleting a frame.
4401 The functions are run with one arg, the frame to be deleted.
4402 See `delete-frame'.
4403
4404 Note that functions in this list may be called just before the frame is
4405 actually deleted, or some time later (or even both when an earlier function
4406 in `delete-frame-functions' (indirectly) calls `delete-frame'
4407 recursively). */);
4408 Vdelete_frame_functions = Qnil;
4409 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4410
4411 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4412 doc: /* Non-nil if Menu-Bar mode is enabled.
4413 See the command `menu-bar-mode' for a description of this minor mode.
4414 Setting this variable directly does not take effect;
4415 either customize it (see the info node `Easy Customization')
4416 or call the function `menu-bar-mode'. */);
4417 Vmenu_bar_mode = Qt;
4418
4419 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4420 doc: /* Non-nil if Tool-Bar mode is enabled.
4421 See the command `tool-bar-mode' for a description of this minor mode.
4422 Setting this variable directly does not take effect;
4423 either customize it (see the info node `Easy Customization')
4424 or call the function `tool-bar-mode'. */);
4425 #ifdef HAVE_WINDOW_SYSTEM
4426 Vtool_bar_mode = Qt;
4427 #else
4428 Vtool_bar_mode = Qnil;
4429 #endif
4430
4431 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4432 doc: /* Minibufferless frames use this frame's minibuffer.
4433
4434 Emacs cannot create minibufferless frames unless this is set to an
4435 appropriate surrogate.
4436
4437 Emacs consults this variable only when creating minibufferless
4438 frames; once the frame is created, it sticks with its assigned
4439 minibuffer, no matter what this variable is set to. This means that
4440 this variable doesn't necessarily say anything meaningful about the
4441 current set of frames, or where the minibuffer is currently being
4442 displayed.
4443
4444 This variable is local to the current terminal and cannot be buffer-local. */);
4445
4446 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4447 doc: /* Non-nil if window system changes focus when you move the mouse.
4448 You should set this variable to tell Emacs how your window manager
4449 handles focus, since there is no way in general for Emacs to find out
4450 automatically. See also `mouse-autoselect-window'. */);
4451 focus_follows_mouse = 0;
4452
4453 staticpro (&Vframe_list);
4454
4455 defsubr (&Sframep);
4456 defsubr (&Sframe_live_p);
4457 defsubr (&Swindow_system);
4458 defsubr (&Smake_terminal_frame);
4459 defsubr (&Shandle_switch_frame);
4460 defsubr (&Sselect_frame);
4461 defsubr (&Sselected_frame);
4462 defsubr (&Sframe_list);
4463 defsubr (&Snext_frame);
4464 defsubr (&Sprevious_frame);
4465 defsubr (&Sdelete_frame);
4466 defsubr (&Smouse_position);
4467 defsubr (&Smouse_pixel_position);
4468 defsubr (&Sset_mouse_position);
4469 defsubr (&Sset_mouse_pixel_position);
4470 #if 0
4471 defsubr (&Sframe_configuration);
4472 defsubr (&Srestore_frame_configuration);
4473 #endif
4474 defsubr (&Smake_frame_visible);
4475 defsubr (&Smake_frame_invisible);
4476 defsubr (&Siconify_frame);
4477 defsubr (&Sframe_visible_p);
4478 defsubr (&Svisible_frame_list);
4479 defsubr (&Sraise_frame);
4480 defsubr (&Slower_frame);
4481 defsubr (&Sredirect_frame_focus);
4482 defsubr (&Sframe_focus);
4483 defsubr (&Sframe_parameters);
4484 defsubr (&Sframe_parameter);
4485 defsubr (&Smodify_frame_parameters);
4486 defsubr (&Sframe_char_height);
4487 defsubr (&Sframe_char_width);
4488 defsubr (&Sframe_pixel_height);
4489 defsubr (&Sframe_pixel_width);
4490 defsubr (&Stool_bar_pixel_width);
4491 defsubr (&Sset_frame_height);
4492 defsubr (&Sset_frame_width);
4493 defsubr (&Sset_frame_size);
4494 defsubr (&Sset_frame_position);
4495 defsubr (&Sframe_pointer_visible_p);
4496
4497 #ifdef HAVE_WINDOW_SYSTEM
4498 defsubr (&Sx_get_resource);
4499 defsubr (&Sx_parse_geometry);
4500 #endif
4501
4502 }