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