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