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