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