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