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