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