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