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