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