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