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