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