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