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