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