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