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