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