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