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