]> code.delx.au - gnu-emacs/blob - src/frame.c
Merge from emacs-24; up to 117669
[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: /* Set height of frame FRAME to HEIGHT 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.
2835
2836 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2837 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2838 window managers may refuse to honor a HEIGHT that is not an integer
2839 multiple of the default frame font height. */)
2840 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2841 {
2842 struct frame *f = decode_live_frame (frame);
2843 int pixel_height;
2844
2845 CHECK_TYPE_RANGED_INTEGER (int, height);
2846
2847 pixel_height = (!NILP (pixelwise)
2848 ? XINT (height)
2849 : XINT (height) * FRAME_LINE_HEIGHT (f));
2850 if (pixel_height != FRAME_TEXT_HEIGHT (f))
2851 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend));
2852
2853 return Qnil;
2854 }
2855
2856 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2857 doc: /* Set width of frame FRAME to WIDTH columns.
2858 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2859 columns but that the idea of the actual width of the frame should not
2860 be changed.
2861
2862 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2863 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2864 window managers may refuse to honor a WIDTH that is not an integer
2865 multiple of the default frame font width. */)
2866 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2867 {
2868 struct frame *f = decode_live_frame (frame);
2869 int pixel_width;
2870
2871 CHECK_TYPE_RANGED_INTEGER (int, width);
2872
2873 pixel_width = (!NILP (pixelwise)
2874 ? XINT (width)
2875 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2876 if (pixel_width != FRAME_TEXT_WIDTH (f))
2877 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend));
2878
2879 return Qnil;
2880 }
2881
2882 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2883 doc: /* Set size of FRAME to WIDTH by HEIGHT, measured in characters.
2884 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2885 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2886 honor a WIDTH that is not an integer multiple of the default frame font
2887 width or a HEIGHT that is not an integer multiple of the default frame
2888 font height. */)
2889 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2890 {
2891 struct frame *f = decode_live_frame (frame);
2892 int pixel_width, pixel_height;
2893
2894 CHECK_TYPE_RANGED_INTEGER (int, width);
2895 CHECK_TYPE_RANGED_INTEGER (int, height);
2896
2897 pixel_width = (!NILP (pixelwise)
2898 ? XINT (width)
2899 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2900 pixel_height = (!NILP (pixelwise)
2901 ? XINT (height)
2902 : XINT (height) * FRAME_LINE_HEIGHT (f));
2903
2904 if (pixel_width != FRAME_TEXT_WIDTH (f)
2905 || pixel_height != FRAME_TEXT_HEIGHT (f))
2906 adjust_frame_size (f, pixel_width, pixel_height, 1, 0);
2907
2908 return Qnil;
2909 }
2910
2911 DEFUN ("set-frame-position", Fset_frame_position,
2912 Sset_frame_position, 3, 3, 0,
2913 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2914 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2915 actually the position of the upper left corner of the frame. Negative
2916 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2917 or bottommost possible position (that stays within the screen). */)
2918 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2919 {
2920 register struct frame *f = decode_live_frame (frame);
2921
2922 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2923 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2924
2925 /* I think this should be done with a hook. */
2926 #ifdef HAVE_WINDOW_SYSTEM
2927 if (FRAME_WINDOW_P (f))
2928 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2929 #endif
2930
2931 return Qt;
2932 }
2933
2934 \f
2935 /***********************************************************************
2936 Frame Parameters
2937 ***********************************************************************/
2938
2939 /* Connect the frame-parameter names for X frames
2940 to the ways of passing the parameter values to the window system.
2941
2942 The name of a parameter, as a Lisp symbol,
2943 has an `x-frame-parameter' property which is an integer in Lisp
2944 that is an index in this table. */
2945
2946 struct frame_parm_table {
2947 const char *name;
2948 Lisp_Object *variable;
2949 };
2950
2951 static const struct frame_parm_table frame_parms[] =
2952 {
2953 {"auto-raise", &Qauto_raise},
2954 {"auto-lower", &Qauto_lower},
2955 {"background-color", 0},
2956 {"border-color", &Qborder_color},
2957 {"border-width", &Qborder_width},
2958 {"cursor-color", &Qcursor_color},
2959 {"cursor-type", &Qcursor_type},
2960 {"font", 0},
2961 {"foreground-color", 0},
2962 {"icon-name", &Qicon_name},
2963 {"icon-type", &Qicon_type},
2964 {"internal-border-width", &Qinternal_border_width},
2965 {"right-divider-width", &Qright_divider_width},
2966 {"bottom-divider-width", &Qbottom_divider_width},
2967 {"menu-bar-lines", &Qmenu_bar_lines},
2968 {"mouse-color", &Qmouse_color},
2969 {"name", &Qname},
2970 {"scroll-bar-width", &Qscroll_bar_width},
2971 {"scroll-bar-height", &Qscroll_bar_height},
2972 {"title", &Qtitle},
2973 {"unsplittable", &Qunsplittable},
2974 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2975 {"horizontal-scroll-bars", &Qhorizontal_scroll_bars},
2976 {"visibility", &Qvisibility},
2977 {"tool-bar-lines", &Qtool_bar_lines},
2978 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2979 {"scroll-bar-background", &Qscroll_bar_background},
2980 {"screen-gamma", &Qscreen_gamma},
2981 {"line-spacing", &Qline_spacing},
2982 {"left-fringe", &Qleft_fringe},
2983 {"right-fringe", &Qright_fringe},
2984 {"wait-for-wm", &Qwait_for_wm},
2985 {"fullscreen", &Qfullscreen},
2986 {"font-backend", &Qfont_backend},
2987 {"alpha", &Qalpha},
2988 {"sticky", &Qsticky},
2989 {"tool-bar-position", &Qtool_bar_position},
2990 };
2991
2992 #ifdef HAVE_WINDOW_SYSTEM
2993
2994 /* Change the parameters of frame F as specified by ALIST.
2995 If a parameter is not specially recognized, do nothing special;
2996 otherwise call the `x_set_...' function for that parameter.
2997 Except for certain geometry properties, always call store_frame_param
2998 to store the new value in the parameter alist. */
2999
3000 void
3001 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3002 {
3003 Lisp_Object tail;
3004
3005 /* If both of these parameters are present, it's more efficient to
3006 set them both at once. So we wait until we've looked at the
3007 entire list before we set them. */
3008 int width IF_LINT (= 0), height IF_LINT (= 0);
3009 bool width_change = 0, height_change = 0;
3010
3011 /* Same here. */
3012 Lisp_Object left, top;
3013
3014 /* Same with these. */
3015 Lisp_Object icon_left, icon_top;
3016
3017 /* Record in these vectors all the parms specified. */
3018 Lisp_Object *parms;
3019 Lisp_Object *values;
3020 ptrdiff_t i, p;
3021 bool left_no_change = 0, top_no_change = 0;
3022 #ifdef HAVE_X_WINDOWS
3023 bool icon_left_no_change = 0, icon_top_no_change = 0;
3024 #endif
3025
3026 i = 0;
3027 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3028 i++;
3029
3030 USE_SAFE_ALLOCA;
3031 SAFE_ALLOCA_LISP (parms, 2 * i);
3032 values = parms + i;
3033
3034 /* Extract parm names and values into those vectors. */
3035
3036 i = 0;
3037 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3038 {
3039 Lisp_Object elt;
3040
3041 elt = XCAR (tail);
3042 parms[i] = Fcar (elt);
3043 values[i] = Fcdr (elt);
3044 i++;
3045 }
3046 /* TAIL and ALIST are not used again below here. */
3047 alist = tail = Qnil;
3048
3049 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3050 because their values appear in VALUES and strings are not valid. */
3051 top = left = Qunbound;
3052 icon_left = icon_top = Qunbound;
3053
3054 /* Process foreground_color and background_color before anything else.
3055 They are independent of other properties, but other properties (e.g.,
3056 cursor_color) are dependent upon them. */
3057 /* Process default font as well, since fringe widths depends on it. */
3058 for (p = 0; p < i; p++)
3059 {
3060 Lisp_Object prop, val;
3061
3062 prop = parms[p];
3063 val = values[p];
3064 if (EQ (prop, Qforeground_color)
3065 || EQ (prop, Qbackground_color)
3066 || EQ (prop, Qfont))
3067 {
3068 register Lisp_Object param_index, old_value;
3069
3070 old_value = get_frame_param (f, prop);
3071 if (NILP (Fequal (val, old_value)))
3072 {
3073 store_frame_param (f, prop, val);
3074
3075 param_index = Fget (prop, Qx_frame_parameter);
3076 if (NATNUMP (param_index)
3077 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3078 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3079 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3080 }
3081 }
3082 }
3083
3084 /* Now process them in reverse of specified order. */
3085 while (i-- != 0)
3086 {
3087 Lisp_Object prop, val;
3088
3089 prop = parms[i];
3090 val = values[i];
3091
3092 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3093 {
3094 width_change = 1;
3095 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3096 }
3097 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3098 {
3099 height_change = 1;
3100 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3101 }
3102 else if (EQ (prop, Qtop))
3103 top = val;
3104 else if (EQ (prop, Qleft))
3105 left = val;
3106 else if (EQ (prop, Qicon_top))
3107 icon_top = val;
3108 else if (EQ (prop, Qicon_left))
3109 icon_left = val;
3110 else if (EQ (prop, Qforeground_color)
3111 || EQ (prop, Qbackground_color)
3112 || EQ (prop, Qfont))
3113 /* Processed above. */
3114 continue;
3115 else
3116 {
3117 register Lisp_Object param_index, old_value;
3118
3119 old_value = get_frame_param (f, prop);
3120
3121 store_frame_param (f, prop, val);
3122
3123 param_index = Fget (prop, Qx_frame_parameter);
3124 if (NATNUMP (param_index)
3125 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3126 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3127 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3128 }
3129 }
3130
3131 /* Don't die if just one of these was set. */
3132 if (EQ (left, Qunbound))
3133 {
3134 left_no_change = 1;
3135 if (f->left_pos < 0)
3136 left = list2 (Qplus, make_number (f->left_pos));
3137 else
3138 XSETINT (left, f->left_pos);
3139 }
3140 if (EQ (top, Qunbound))
3141 {
3142 top_no_change = 1;
3143 if (f->top_pos < 0)
3144 top = list2 (Qplus, make_number (f->top_pos));
3145 else
3146 XSETINT (top, f->top_pos);
3147 }
3148
3149 /* If one of the icon positions was not set, preserve or default it. */
3150 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3151 {
3152 #ifdef HAVE_X_WINDOWS
3153 icon_left_no_change = 1;
3154 #endif
3155 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3156 if (NILP (icon_left))
3157 XSETINT (icon_left, 0);
3158 }
3159 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3160 {
3161 #ifdef HAVE_X_WINDOWS
3162 icon_top_no_change = 1;
3163 #endif
3164 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3165 if (NILP (icon_top))
3166 XSETINT (icon_top, 0);
3167 }
3168
3169 /* Don't set these parameters unless they've been explicitly
3170 specified. The window might be mapped or resized while we're in
3171 this function, and we don't want to override that unless the lisp
3172 code has asked for it.
3173
3174 Don't set these parameters unless they actually differ from the
3175 window's current parameters; the window may not actually exist
3176 yet. */
3177 {
3178 Lisp_Object frame;
3179
3180 XSETFRAME (frame, f);
3181
3182 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3183 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3184 || f->new_height || f->new_width)
3185 {
3186 /* If necessary provide default values for HEIGHT and WIDTH. Do
3187 that here since otherwise a size change implied by an
3188 intermittent font change may get lost as in Bug#17142. */
3189 if (!width_change)
3190 width = (f->new_width
3191 ? (f->new_pixelwise
3192 ? f->new_width
3193 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3194 : FRAME_TEXT_WIDTH (f));
3195
3196 if (!height_change)
3197 height = (f->new_height
3198 ? (f->new_pixelwise
3199 ? f->new_height
3200 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3201 : FRAME_TEXT_HEIGHT (f));
3202
3203 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3204 }
3205
3206 if ((!NILP (left) || !NILP (top))
3207 && ! (left_no_change && top_no_change)
3208 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3209 && NUMBERP (top) && XINT (top) == f->top_pos))
3210 {
3211 int leftpos = 0;
3212 int toppos = 0;
3213
3214 /* Record the signs. */
3215 f->size_hint_flags &= ~ (XNegative | YNegative);
3216 if (EQ (left, Qminus))
3217 f->size_hint_flags |= XNegative;
3218 else if (TYPE_RANGED_INTEGERP (int, left))
3219 {
3220 leftpos = XINT (left);
3221 if (leftpos < 0)
3222 f->size_hint_flags |= XNegative;
3223 }
3224 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3225 && CONSP (XCDR (left))
3226 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3227 {
3228 leftpos = - XINT (XCAR (XCDR (left)));
3229 f->size_hint_flags |= XNegative;
3230 }
3231 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3232 && CONSP (XCDR (left))
3233 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3234 {
3235 leftpos = XINT (XCAR (XCDR (left)));
3236 }
3237
3238 if (EQ (top, Qminus))
3239 f->size_hint_flags |= YNegative;
3240 else if (TYPE_RANGED_INTEGERP (int, top))
3241 {
3242 toppos = XINT (top);
3243 if (toppos < 0)
3244 f->size_hint_flags |= YNegative;
3245 }
3246 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3247 && CONSP (XCDR (top))
3248 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3249 {
3250 toppos = - XINT (XCAR (XCDR (top)));
3251 f->size_hint_flags |= YNegative;
3252 }
3253 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3254 && CONSP (XCDR (top))
3255 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3256 {
3257 toppos = XINT (XCAR (XCDR (top)));
3258 }
3259
3260
3261 /* Store the numeric value of the position. */
3262 f->top_pos = toppos;
3263 f->left_pos = leftpos;
3264
3265 f->win_gravity = NorthWestGravity;
3266
3267 /* Actually set that position, and convert to absolute. */
3268 x_set_offset (f, leftpos, toppos, -1);
3269 }
3270 #ifdef HAVE_X_WINDOWS
3271 if ((!NILP (icon_left) || !NILP (icon_top))
3272 && ! (icon_left_no_change && icon_top_no_change))
3273 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3274 #endif /* HAVE_X_WINDOWS */
3275 }
3276
3277 SAFE_FREE ();
3278 }
3279
3280
3281 /* Insert a description of internally-recorded parameters of frame X
3282 into the parameter alist *ALISTPTR that is to be given to the user.
3283 Only parameters that are specific to the X window system
3284 and whose values are not correctly recorded in the frame's
3285 param_alist need to be considered here. */
3286
3287 void
3288 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3289 {
3290 Lisp_Object tem;
3291 uprintmax_t w;
3292 char buf[INT_BUFSIZE_BOUND (w)];
3293
3294 /* Represent negative positions (off the top or left screen edge)
3295 in a way that Fmodify_frame_parameters will understand correctly. */
3296 XSETINT (tem, f->left_pos);
3297 if (f->left_pos >= 0)
3298 store_in_alist (alistptr, Qleft, tem);
3299 else
3300 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3301
3302 XSETINT (tem, f->top_pos);
3303 if (f->top_pos >= 0)
3304 store_in_alist (alistptr, Qtop, tem);
3305 else
3306 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3307
3308 store_in_alist (alistptr, Qborder_width,
3309 make_number (f->border_width));
3310 store_in_alist (alistptr, Qinternal_border_width,
3311 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3312 store_in_alist (alistptr, Qright_divider_width,
3313 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3314 store_in_alist (alistptr, Qbottom_divider_width,
3315 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3316 store_in_alist (alistptr, Qleft_fringe,
3317 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3318 store_in_alist (alistptr, Qright_fringe,
3319 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3320 store_in_alist (alistptr, Qscroll_bar_width,
3321 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3322 ? make_number (0)
3323 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3324 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3325 /* nil means "use default width"
3326 for non-toolkit scroll bar.
3327 ruler-mode.el depends on this. */
3328 : Qnil));
3329 store_in_alist (alistptr, Qscroll_bar_height,
3330 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3331 ? make_number (0)
3332 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3333 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3334 /* nil means "use default height"
3335 for non-toolkit scroll bar. */
3336 : Qnil));
3337 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3338 MS-Windows it returns a value whose type is HANDLE, which is
3339 actually a pointer. Explicit casting avoids compiler
3340 warnings. */
3341 w = (uintptr_t) FRAME_X_WINDOW (f);
3342 store_in_alist (alistptr, Qwindow_id,
3343 make_formatted_string (buf, "%"pMu, w));
3344 #ifdef HAVE_X_WINDOWS
3345 #ifdef USE_X_TOOLKIT
3346 /* Tooltip frame may not have this widget. */
3347 if (FRAME_X_OUTPUT (f)->widget)
3348 #endif
3349 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3350 store_in_alist (alistptr, Qouter_window_id,
3351 make_formatted_string (buf, "%"pMu, w));
3352 #endif
3353 store_in_alist (alistptr, Qicon_name, f->icon_name);
3354 store_in_alist (alistptr, Qvisibility,
3355 (FRAME_VISIBLE_P (f) ? Qt
3356 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3357 store_in_alist (alistptr, Qdisplay,
3358 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3359
3360 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3361 tem = Qnil;
3362 else
3363 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3364 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3365 store_in_alist (alistptr, Qparent_id, tem);
3366 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3367 }
3368
3369
3370 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3371 the previous value of that parameter, NEW_VALUE is the new value. */
3372
3373 void
3374 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3375 {
3376 if (NILP (new_value))
3377 f->want_fullscreen = FULLSCREEN_NONE;
3378 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3379 f->want_fullscreen = FULLSCREEN_BOTH;
3380 else if (EQ (new_value, Qfullwidth))
3381 f->want_fullscreen = FULLSCREEN_WIDTH;
3382 else if (EQ (new_value, Qfullheight))
3383 f->want_fullscreen = FULLSCREEN_HEIGHT;
3384 else if (EQ (new_value, Qmaximized))
3385 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3386
3387 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3388 FRAME_TERMINAL (f)->fullscreen_hook (f);
3389 }
3390
3391
3392 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3393 the previous value of that parameter, NEW_VALUE is the new value. */
3394
3395 void
3396 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3397 {
3398 if (NILP (new_value))
3399 f->extra_line_spacing = 0;
3400 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3401 f->extra_line_spacing = XFASTINT (new_value);
3402 else if (FLOATP (new_value))
3403 {
3404 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3405
3406 if (new_spacing >= 0)
3407 f->extra_line_spacing = new_spacing;
3408 else
3409 signal_error ("Invalid line-spacing", new_value);
3410 }
3411 else
3412 signal_error ("Invalid line-spacing", new_value);
3413 if (FRAME_VISIBLE_P (f))
3414 redraw_frame (f);
3415 }
3416
3417
3418 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3419 the previous value of that parameter, NEW_VALUE is the new value. */
3420
3421 void
3422 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3423 {
3424 Lisp_Object bgcolor;
3425
3426 if (NILP (new_value))
3427 f->gamma = 0;
3428 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3429 /* The value 0.4545 is the normal viewing gamma. */
3430 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3431 else
3432 signal_error ("Invalid screen-gamma", new_value);
3433
3434 /* Apply the new gamma value to the frame background. */
3435 bgcolor = Fassq (Qbackground_color, f->param_alist);
3436 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3437 {
3438 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3439 if (NATNUMP (parm_index)
3440 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3441 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3442 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3443 (f, bgcolor, Qnil);
3444 }
3445
3446 Fclear_face_cache (Qnil);
3447 }
3448
3449
3450 void
3451 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3452 {
3453 Lisp_Object font_object;
3454 int fontset = -1;
3455 #ifdef HAVE_X_WINDOWS
3456 Lisp_Object font_param = arg;
3457 #endif
3458
3459 /* Set the frame parameter back to the old value because we may
3460 fail to use ARG as the new parameter value. */
3461 store_frame_param (f, Qfont, oldval);
3462
3463 /* ARG is a fontset name, a font name, a cons of fontset name and a
3464 font object, or a font object. In the last case, this function
3465 never fail. */
3466 if (STRINGP (arg))
3467 {
3468 fontset = fs_query_fontset (arg, 0);
3469 if (fontset < 0)
3470 {
3471 font_object = font_open_by_name (f, arg);
3472 if (NILP (font_object))
3473 error ("Font `%s' is not defined", SSDATA (arg));
3474 arg = AREF (font_object, FONT_NAME_INDEX);
3475 }
3476 else if (fontset > 0)
3477 {
3478 font_object = font_open_by_name (f, fontset_ascii (fontset));
3479 if (NILP (font_object))
3480 error ("Font `%s' is not defined", SDATA (arg));
3481 arg = AREF (font_object, FONT_NAME_INDEX);
3482 }
3483 else
3484 error ("The default fontset can't be used for a frame font");
3485 }
3486 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3487 {
3488 /* This is the case that the ASCII font of F's fontset XCAR
3489 (arg) is changed to the font XCDR (arg) by
3490 `set-fontset-font'. */
3491 fontset = fs_query_fontset (XCAR (arg), 0);
3492 if (fontset < 0)
3493 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3494 font_object = XCDR (arg);
3495 arg = AREF (font_object, FONT_NAME_INDEX);
3496 #ifdef HAVE_X_WINDOWS
3497 font_param = Ffont_get (font_object, QCname);
3498 #endif
3499 }
3500 else if (FONT_OBJECT_P (arg))
3501 {
3502 font_object = arg;
3503 #ifdef HAVE_X_WINDOWS
3504 font_param = Ffont_get (font_object, QCname);
3505 #endif
3506 /* This is to store the XLFD font name in the frame parameter for
3507 backward compatibility. We should store the font-object
3508 itself in the future. */
3509 arg = AREF (font_object, FONT_NAME_INDEX);
3510 fontset = FRAME_FONTSET (f);
3511 /* Check if we can use the current fontset. If not, set FONTSET
3512 to -1 to generate a new fontset from FONT-OBJECT. */
3513 if (fontset >= 0)
3514 {
3515 Lisp_Object ascii_font = fontset_ascii (fontset);
3516 Lisp_Object spec = font_spec_from_name (ascii_font);
3517
3518 if (NILP (spec))
3519 signal_error ("Invalid font name", ascii_font);
3520
3521 if (! font_match_p (spec, font_object))
3522 fontset = -1;
3523 }
3524 }
3525 else
3526 signal_error ("Invalid font", arg);
3527
3528 if (! NILP (Fequal (font_object, oldval)))
3529 return;
3530
3531 x_new_font (f, font_object, fontset);
3532 store_frame_param (f, Qfont, arg);
3533 #ifdef HAVE_X_WINDOWS
3534 store_frame_param (f, Qfont_param, font_param);
3535 #endif
3536 /* Recalculate toolbar height. */
3537 f->n_tool_bar_rows = 0;
3538
3539 /* Ensure we redraw it. */
3540 clear_current_matrices (f);
3541
3542 /* Attempt to hunt down bug#16028. */
3543 SET_FRAME_GARBAGED (f);
3544
3545 recompute_basic_faces (f);
3546
3547 do_pending_window_change (0);
3548
3549 /* We used to call face-set-after-frame-default here, but it leads to
3550 recursive calls (since that function can set the `default' face's
3551 font which in turns changes the frame's `font' parameter).
3552 Also I don't know what this call is meant to do, but it seems the
3553 wrong way to do it anyway (it does a lot more work than what seems
3554 reasonable in response to a change to `font'). */
3555 }
3556
3557
3558 void
3559 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3560 {
3561 if (! NILP (new_value)
3562 && !CONSP (new_value))
3563 {
3564 char *p0, *p1;
3565
3566 CHECK_STRING (new_value);
3567 p0 = p1 = SSDATA (new_value);
3568 new_value = Qnil;
3569 while (*p0)
3570 {
3571 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3572 if (p0 < p1)
3573 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3574 new_value);
3575 if (*p1)
3576 {
3577 int c;
3578
3579 while ((c = *++p1) && c_isspace (c));
3580 }
3581 p0 = p1;
3582 }
3583 new_value = Fnreverse (new_value);
3584 }
3585
3586 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3587 return;
3588
3589 if (FRAME_FONT (f))
3590 free_all_realized_faces (Qnil);
3591
3592 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3593 if (NILP (new_value))
3594 {
3595 if (NILP (old_value))
3596 error ("No font backend available");
3597 font_update_drivers (f, old_value);
3598 error ("None of specified font backends are available");
3599 }
3600 store_frame_param (f, Qfont_backend, new_value);
3601
3602 if (FRAME_FONT (f))
3603 {
3604 Lisp_Object frame;
3605
3606 XSETFRAME (frame, f);
3607 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3608 ++face_change_count;
3609 windows_or_buffers_changed = 18;
3610 }
3611 }
3612
3613 void
3614 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3615 {
3616 int unit = FRAME_COLUMN_WIDTH (f);
3617 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3618 int new_width;
3619
3620 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3621 ? eabs (XINT (new_value)) : 8);
3622
3623 if (new_width != old_width)
3624 {
3625 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3626 FRAME_FRINGE_COLS (f) /* Round up. */
3627 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3628
3629 if (FRAME_X_WINDOW (f) != 0)
3630 adjust_frame_size (f, -1, -1, 3, 0);
3631
3632 SET_FRAME_GARBAGED (f);
3633 }
3634 }
3635
3636
3637 void
3638 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3639 {
3640 int unit = FRAME_COLUMN_WIDTH (f);
3641 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3642 int new_width;
3643
3644 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3645 ? eabs (XINT (new_value)) : 8);
3646
3647 if (new_width != old_width)
3648 {
3649 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3650 FRAME_FRINGE_COLS (f) /* Round up. */
3651 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3652
3653 if (FRAME_X_WINDOW (f) != 0)
3654 adjust_frame_size (f, -1, -1, 3, 0);
3655
3656 SET_FRAME_GARBAGED (f);
3657 }
3658 }
3659
3660
3661 void
3662 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3663 {
3664 CHECK_TYPE_RANGED_INTEGER (int, arg);
3665
3666 if (XINT (arg) == f->border_width)
3667 return;
3668
3669 if (FRAME_X_WINDOW (f) != 0)
3670 error ("Cannot change the border width of a frame");
3671
3672 f->border_width = XINT (arg);
3673 }
3674
3675 void
3676 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3677 {
3678 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3679
3680 CHECK_TYPE_RANGED_INTEGER (int, arg);
3681 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3682 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3683 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3684 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3685 {
3686 adjust_frame_size (f, -1, -1, 4, 0);
3687 adjust_frame_glyphs (f);
3688 SET_FRAME_GARBAGED (f);
3689 }
3690
3691 }
3692
3693 void
3694 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3695 {
3696 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3697
3698 CHECK_TYPE_RANGED_INTEGER (int, arg);
3699 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3700 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3701 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3702 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3703 {
3704 adjust_frame_size (f, -1, -1, 4, 0);
3705 adjust_frame_glyphs (f);
3706 SET_FRAME_GARBAGED (f);
3707 }
3708 }
3709
3710 void
3711 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3712 {
3713 Lisp_Object frame;
3714 XSETFRAME (frame, f);
3715
3716 if (NILP (value))
3717 Fmake_frame_invisible (frame, Qt);
3718 else if (EQ (value, Qicon))
3719 Ficonify_frame (frame);
3720 else
3721 Fmake_frame_visible (frame);
3722 }
3723
3724 void
3725 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3726 {
3727 f->auto_raise = !EQ (Qnil, arg);
3728 }
3729
3730 void
3731 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3732 {
3733 f->auto_lower = !EQ (Qnil, arg);
3734 }
3735
3736 void
3737 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3738 {
3739 f->no_split = !NILP (arg);
3740 }
3741
3742 void
3743 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3744 {
3745 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3746 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3747 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3748 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3749 {
3750 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3751 = (NILP (arg)
3752 ? vertical_scroll_bar_none
3753 : EQ (Qleft, arg)
3754 ? vertical_scroll_bar_left
3755 : EQ (Qright, arg)
3756 ? vertical_scroll_bar_right
3757 : EQ (Qleft, Vdefault_frame_scroll_bars)
3758 ? vertical_scroll_bar_left
3759 : EQ (Qright, Vdefault_frame_scroll_bars)
3760 ? vertical_scroll_bar_right
3761 : vertical_scroll_bar_none);
3762
3763 /* We set this parameter before creating the X window for the
3764 frame, so we can get the geometry right from the start.
3765 However, if the window hasn't been created yet, we shouldn't
3766 call x_set_window_size. */
3767 if (FRAME_X_WINDOW (f))
3768 adjust_frame_size (f, -1, -1, 3, 0);
3769
3770 SET_FRAME_GARBAGED (f);
3771 }
3772 }
3773
3774 void
3775 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3776 {
3777 #if USE_HORIZONTAL_SCROLL_BARS
3778 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3779 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3780 {
3781 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3782
3783 /* We set this parameter before creating the X window for the
3784 frame, so we can get the geometry right from the start.
3785 However, if the window hasn't been created yet, we shouldn't
3786 call x_set_window_size. */
3787 if (FRAME_X_WINDOW (f))
3788 adjust_frame_size (f, -1, -1, 3, 0);
3789
3790 SET_FRAME_GARBAGED (f);
3791 }
3792 #endif
3793 }
3794
3795 void
3796 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3797 {
3798 int unit = FRAME_COLUMN_WIDTH (f);
3799
3800 if (NILP (arg))
3801 {
3802 x_set_scroll_bar_default_width (f);
3803
3804 if (FRAME_X_WINDOW (f))
3805 adjust_frame_size (f, -1, -1, 3, 0);
3806
3807 SET_FRAME_GARBAGED (f);
3808 }
3809 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3810 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3811 {
3812 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3813 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3814 if (FRAME_X_WINDOW (f))
3815 adjust_frame_size (f, -1, -1, 3, 0);
3816
3817 SET_FRAME_GARBAGED (f);
3818 }
3819
3820 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3821 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3822 }
3823
3824 void
3825 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3826 {
3827 #if USE_HORIZONTAL_SCROLL_BARS
3828 int unit = FRAME_LINE_HEIGHT (f);
3829
3830 if (NILP (arg))
3831 {
3832 x_set_scroll_bar_default_height (f);
3833
3834 if (FRAME_X_WINDOW (f))
3835 adjust_frame_size (f, -1, -1, 3, 0);
3836
3837 SET_FRAME_GARBAGED (f);
3838 }
3839 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3840 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3841 {
3842 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3843 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3844 if (FRAME_X_WINDOW (f))
3845 adjust_frame_size (f, -1, -1, 3, 0);
3846
3847 SET_FRAME_GARBAGED (f);
3848 }
3849
3850 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3851 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3852 #endif
3853 }
3854
3855 void
3856 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3857 {
3858 double alpha = 1.0;
3859 double newval[2];
3860 int i;
3861 Lisp_Object item;
3862
3863 for (i = 0; i < 2; i++)
3864 {
3865 newval[i] = 1.0;
3866 if (CONSP (arg))
3867 {
3868 item = CAR (arg);
3869 arg = CDR (arg);
3870 }
3871 else
3872 item = arg;
3873
3874 if (NILP (item))
3875 alpha = - 1.0;
3876 else if (FLOATP (item))
3877 {
3878 alpha = XFLOAT_DATA (item);
3879 if (! (0 <= alpha && alpha <= 1.0))
3880 args_out_of_range (make_float (0.0), make_float (1.0));
3881 }
3882 else if (INTEGERP (item))
3883 {
3884 EMACS_INT ialpha = XINT (item);
3885 if (! (0 <= ialpha && alpha <= 100))
3886 args_out_of_range (make_number (0), make_number (100));
3887 alpha = ialpha / 100.0;
3888 }
3889 else
3890 wrong_type_argument (Qnumberp, item);
3891 newval[i] = alpha;
3892 }
3893
3894 for (i = 0; i < 2; i++)
3895 f->alpha[i] = newval[i];
3896
3897 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3898 block_input ();
3899 x_set_frame_alpha (f);
3900 unblock_input ();
3901 #endif
3902
3903 return;
3904 }
3905
3906 #ifndef HAVE_NS
3907
3908 /* Non-zero if mouse is grabbed on DPYINFO
3909 and we know the frame where it is. */
3910
3911 bool x_mouse_grabbed (Display_Info *dpyinfo)
3912 {
3913 return (dpyinfo->grabbed
3914 && dpyinfo->last_mouse_frame
3915 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3916 }
3917
3918 /* Re-highlight something with mouse-face properties
3919 on DPYINFO using saved frame and mouse position. */
3920
3921 void
3922 x_redo_mouse_highlight (Display_Info *dpyinfo)
3923 {
3924 if (dpyinfo->last_mouse_motion_frame
3925 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3926 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3927 dpyinfo->last_mouse_motion_x,
3928 dpyinfo->last_mouse_motion_y);
3929 }
3930
3931 #endif /* HAVE_NS */
3932
3933 /* Subroutines of creating an X frame. */
3934
3935 /* Make sure that Vx_resource_name is set to a reasonable value.
3936 Fix it up, or set it to `emacs' if it is too hopeless. */
3937
3938 void
3939 validate_x_resource_name (void)
3940 {
3941 ptrdiff_t len = 0;
3942 /* Number of valid characters in the resource name. */
3943 ptrdiff_t good_count = 0;
3944 /* Number of invalid characters in the resource name. */
3945 ptrdiff_t bad_count = 0;
3946 Lisp_Object new;
3947 ptrdiff_t i;
3948
3949 if (!STRINGP (Vx_resource_class))
3950 Vx_resource_class = build_string (EMACS_CLASS);
3951
3952 if (STRINGP (Vx_resource_name))
3953 {
3954 unsigned char *p = SDATA (Vx_resource_name);
3955
3956 len = SBYTES (Vx_resource_name);
3957
3958 /* Only letters, digits, - and _ are valid in resource names.
3959 Count the valid characters and count the invalid ones. */
3960 for (i = 0; i < len; i++)
3961 {
3962 int c = p[i];
3963 if (! ((c >= 'a' && c <= 'z')
3964 || (c >= 'A' && c <= 'Z')
3965 || (c >= '0' && c <= '9')
3966 || c == '-' || c == '_'))
3967 bad_count++;
3968 else
3969 good_count++;
3970 }
3971 }
3972 else
3973 /* Not a string => completely invalid. */
3974 bad_count = 5, good_count = 0;
3975
3976 /* If name is valid already, return. */
3977 if (bad_count == 0)
3978 return;
3979
3980 /* If name is entirely invalid, or nearly so, or is so implausibly
3981 large that alloca might not work, use `emacs'. */
3982 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3983 {
3984 Vx_resource_name = build_string ("emacs");
3985 return;
3986 }
3987
3988 /* Name is partly valid. Copy it and replace the invalid characters
3989 with underscores. */
3990
3991 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3992
3993 for (i = 0; i < len; i++)
3994 {
3995 int c = SREF (new, i);
3996 if (! ((c >= 'a' && c <= 'z')
3997 || (c >= 'A' && c <= 'Z')
3998 || (c >= '0' && c <= '9')
3999 || c == '-' || c == '_'))
4000 SSET (new, i, '_');
4001 }
4002 }
4003
4004 /* Get specified attribute from resource database RDB.
4005 See Fx_get_resource below for other parameters. */
4006
4007 static Lisp_Object
4008 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4009 {
4010 CHECK_STRING (attribute);
4011 CHECK_STRING (class);
4012
4013 if (!NILP (component))
4014 CHECK_STRING (component);
4015 if (!NILP (subclass))
4016 CHECK_STRING (subclass);
4017 if (NILP (component) != NILP (subclass))
4018 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4019
4020 validate_x_resource_name ();
4021
4022 /* Allocate space for the components, the dots which separate them,
4023 and the final '\0'. Make them big enough for the worst case. */
4024 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4025 + (STRINGP (component)
4026 ? SBYTES (component) : 0)
4027 + SBYTES (attribute)
4028 + 3);
4029
4030 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4031 + SBYTES (class)
4032 + (STRINGP (subclass)
4033 ? SBYTES (subclass) : 0)
4034 + 3);
4035 USE_SAFE_ALLOCA;
4036 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4037 char *class_key = name_key + name_keysize;
4038
4039 /* Start with emacs.FRAMENAME for the name (the specific one)
4040 and with `Emacs' for the class key (the general one). */
4041 lispstpcpy (name_key, Vx_resource_name);
4042 lispstpcpy (class_key, Vx_resource_class);
4043
4044 strcat (class_key, ".");
4045 strcat (class_key, SSDATA (class));
4046
4047 if (!NILP (component))
4048 {
4049 strcat (class_key, ".");
4050 strcat (class_key, SSDATA (subclass));
4051
4052 strcat (name_key, ".");
4053 strcat (name_key, SSDATA (component));
4054 }
4055
4056 strcat (name_key, ".");
4057 strcat (name_key, SSDATA (attribute));
4058
4059 char *value = x_get_string_resource (rdb, name_key, class_key);
4060 SAFE_FREE();
4061
4062 if (value && *value)
4063 return build_string (value);
4064 else
4065 return Qnil;
4066 }
4067
4068
4069 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4070 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4071 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4072 class, where INSTANCE is the name under which Emacs was invoked, or
4073 the name specified by the `-name' or `-rn' command-line arguments.
4074
4075 The optional arguments COMPONENT and SUBCLASS add to the key and the
4076 class, respectively. You must specify both of them or neither.
4077 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4078 and the class is `Emacs.CLASS.SUBCLASS'. */)
4079 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4080 Lisp_Object subclass)
4081 {
4082 check_window_system (NULL);
4083
4084 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4085 attribute, class, component, subclass);
4086 }
4087
4088 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4089
4090 Lisp_Object
4091 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4092 Lisp_Object class, Lisp_Object component,
4093 Lisp_Object subclass)
4094 {
4095 return xrdb_get_resource (dpyinfo->xrdb,
4096 attribute, class, component, subclass);
4097 }
4098
4099 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
4100 /* Used when C code wants a resource value. */
4101 /* Called from oldXMenu/Create.c. */
4102 char *
4103 x_get_resource_string (const char *attribute, const char *class)
4104 {
4105 char *result;
4106 struct frame *sf = SELECTED_FRAME ();
4107 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4108 USE_SAFE_ALLOCA;
4109
4110 /* Allocate space for the components, the dots which separate them,
4111 and the final '\0'. */
4112 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4113 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4114 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4115 char *class_key = name_key + name_keysize;
4116
4117 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4118 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4119
4120 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4121 name_key, class_key);
4122 SAFE_FREE ();
4123 return result;
4124 }
4125 #endif
4126
4127 /* Return the value of parameter PARAM.
4128
4129 First search ALIST, then Vdefault_frame_alist, then the X defaults
4130 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4131
4132 Convert the resource to the type specified by desired_type.
4133
4134 If no default is specified, return Qunbound. If you call
4135 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4136 and don't let it get stored in any Lisp-visible variables! */
4137
4138 Lisp_Object
4139 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4140 const char *attribute, const char *class, enum resource_types type)
4141 {
4142 Lisp_Object tem;
4143
4144 tem = Fassq (param, alist);
4145
4146 if (!NILP (tem))
4147 {
4148 /* If we find this parm in ALIST, clear it out
4149 so that it won't be "left over" at the end. */
4150 Lisp_Object tail;
4151 XSETCAR (tem, Qnil);
4152 /* In case the parameter appears more than once in the alist,
4153 clear it out. */
4154 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4155 if (CONSP (XCAR (tail))
4156 && EQ (XCAR (XCAR (tail)), param))
4157 XSETCAR (XCAR (tail), Qnil);
4158 }
4159 else
4160 tem = Fassq (param, Vdefault_frame_alist);
4161
4162 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4163 look in the X resources. */
4164 if (EQ (tem, Qnil))
4165 {
4166 if (attribute && dpyinfo)
4167 {
4168 AUTO_STRING (at, attribute);
4169 AUTO_STRING (cl, class);
4170 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4171
4172 if (NILP (tem))
4173 return Qunbound;
4174
4175 switch (type)
4176 {
4177 case RES_TYPE_NUMBER:
4178 return make_number (atoi (SSDATA (tem)));
4179
4180 case RES_TYPE_BOOLEAN_NUMBER:
4181 if (!strcmp (SSDATA (tem), "on")
4182 || !strcmp (SSDATA (tem), "true"))
4183 return make_number (1);
4184 return make_number (atoi (SSDATA (tem)));
4185 break;
4186
4187 case RES_TYPE_FLOAT:
4188 return make_float (atof (SSDATA (tem)));
4189
4190 case RES_TYPE_BOOLEAN:
4191 tem = Fdowncase (tem);
4192 if (!strcmp (SSDATA (tem), "on")
4193 #ifdef HAVE_NS
4194 || !strcmp (SSDATA (tem), "yes")
4195 #endif
4196 || !strcmp (SSDATA (tem), "true"))
4197 return Qt;
4198 else
4199 return Qnil;
4200
4201 case RES_TYPE_STRING:
4202 return tem;
4203
4204 case RES_TYPE_SYMBOL:
4205 /* As a special case, we map the values `true' and `on'
4206 to Qt, and `false' and `off' to Qnil. */
4207 {
4208 Lisp_Object lower;
4209 lower = Fdowncase (tem);
4210 if (!strcmp (SSDATA (lower), "on")
4211 #ifdef HAVE_NS
4212 || !strcmp (SSDATA (lower), "yes")
4213 #endif
4214 || !strcmp (SSDATA (lower), "true"))
4215 return Qt;
4216 else if (!strcmp (SSDATA (lower), "off")
4217 #ifdef HAVE_NS
4218 || !strcmp (SSDATA (lower), "no")
4219 #endif
4220 || !strcmp (SSDATA (lower), "false"))
4221 return Qnil;
4222 else
4223 return Fintern (tem, Qnil);
4224 }
4225
4226 default:
4227 emacs_abort ();
4228 }
4229 }
4230 else
4231 return Qunbound;
4232 }
4233 return Fcdr (tem);
4234 }
4235
4236 static Lisp_Object
4237 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4238 const char *attribute, const char *class,
4239 enum resource_types type)
4240 {
4241 return x_get_arg (FRAME_DISPLAY_INFO (f),
4242 alist, param, attribute, class, type);
4243 }
4244
4245 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4246
4247 Lisp_Object
4248 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4249 Lisp_Object param,
4250 const char *attribute, const char *class,
4251 enum resource_types type)
4252 {
4253 Lisp_Object value;
4254
4255 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4256 attribute, class, type);
4257 if (! NILP (value) && ! EQ (value, Qunbound))
4258 store_frame_param (f, param, value);
4259
4260 return value;
4261 }
4262
4263
4264 /* Record in frame F the specified or default value according to ALIST
4265 of the parameter named PROP (a Lisp symbol).
4266 If no value is specified for PROP, look for an X default for XPROP
4267 on the frame named NAME.
4268 If that is not found either, use the value DEFLT. */
4269
4270 Lisp_Object
4271 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4272 Lisp_Object deflt, const char *xprop, const char *xclass,
4273 enum resource_types type)
4274 {
4275 Lisp_Object tem;
4276
4277 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4278 if (EQ (tem, Qunbound))
4279 tem = deflt;
4280 AUTO_FRAME_ARG (arg, prop, tem);
4281 x_set_frame_parameters (f, arg);
4282 return tem;
4283 }
4284
4285
4286 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4287
4288 /*
4289 * XParseGeometry parses strings of the form
4290 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4291 * width, height, xoffset, and yoffset are unsigned integers.
4292 * Example: "=80x24+300-49"
4293 * The equal sign is optional.
4294 * It returns a bitmask that indicates which of the four values
4295 * were actually found in the string. For each value found,
4296 * the corresponding argument is updated; for each value
4297 * not found, the corresponding argument is left unchanged.
4298 */
4299
4300 static int
4301 XParseGeometry (char *string,
4302 int *x, int *y,
4303 unsigned int *width, unsigned int *height)
4304 {
4305 int mask = NoValue;
4306 char *strind;
4307 unsigned long tempWidth, tempHeight;
4308 long int tempX, tempY;
4309 char *nextCharacter;
4310
4311 if (string == NULL || *string == '\0')
4312 return mask;
4313 if (*string == '=')
4314 string++; /* ignore possible '=' at beg of geometry spec */
4315
4316 strind = string;
4317 if (*strind != '+' && *strind != '-' && *strind != 'x')
4318 {
4319 tempWidth = strtoul (strind, &nextCharacter, 10);
4320 if (strind == nextCharacter)
4321 return 0;
4322 strind = nextCharacter;
4323 mask |= WidthValue;
4324 }
4325
4326 if (*strind == 'x' || *strind == 'X')
4327 {
4328 strind++;
4329 tempHeight = strtoul (strind, &nextCharacter, 10);
4330 if (strind == nextCharacter)
4331 return 0;
4332 strind = nextCharacter;
4333 mask |= HeightValue;
4334 }
4335
4336 if (*strind == '+' || *strind == '-')
4337 {
4338 if (*strind == '-')
4339 mask |= XNegative;
4340 tempX = strtol (strind, &nextCharacter, 10);
4341 if (strind == nextCharacter)
4342 return 0;
4343 strind = nextCharacter;
4344 mask |= XValue;
4345 if (*strind == '+' || *strind == '-')
4346 {
4347 if (*strind == '-')
4348 mask |= YNegative;
4349 tempY = strtol (strind, &nextCharacter, 10);
4350 if (strind == nextCharacter)
4351 return 0;
4352 strind = nextCharacter;
4353 mask |= YValue;
4354 }
4355 }
4356
4357 /* If strind isn't at the end of the string then it's an invalid
4358 geometry specification. */
4359
4360 if (*strind != '\0')
4361 return 0;
4362
4363 if (mask & XValue)
4364 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4365 if (mask & YValue)
4366 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4367 if (mask & WidthValue)
4368 *width = min (tempWidth, UINT_MAX);
4369 if (mask & HeightValue)
4370 *height = min (tempHeight, UINT_MAX);
4371 return mask;
4372 }
4373
4374 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4375
4376 \f
4377 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4378 make-docfile: the documentation string in ns-win.el was used for
4379 x-parse-geometry even in non-NS builds.
4380
4381 With two definitions of x-parse-geometry in this file, various
4382 things still get confused (eg M-x apropos documentation), so that
4383 it is best if the two definitions just share the same doc-string.
4384 */
4385 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4386 doc: /* Parse a display geometry string STRING.
4387 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4388 The properties returned may include `top', `left', `height', and `width'.
4389 For X, the value of `left' or `top' may be an integer,
4390 or a list (+ N) meaning N pixels relative to top/left corner,
4391 or a list (- N) meaning -N pixels relative to bottom/right corner.
4392 On Nextstep, this just calls `ns-parse-geometry'. */)
4393 (Lisp_Object string)
4394 {
4395 int geometry, x, y;
4396 unsigned int width, height;
4397 Lisp_Object result;
4398
4399 CHECK_STRING (string);
4400
4401 #ifdef HAVE_NS
4402 if (strchr (SSDATA (string), ' ') != NULL)
4403 return call1 (Qns_parse_geometry, string);
4404 #endif
4405 geometry = XParseGeometry (SSDATA (string),
4406 &x, &y, &width, &height);
4407 result = Qnil;
4408 if (geometry & XValue)
4409 {
4410 Lisp_Object element;
4411
4412 if (x >= 0 && (geometry & XNegative))
4413 element = list3 (Qleft, Qminus, make_number (-x));
4414 else if (x < 0 && ! (geometry & XNegative))
4415 element = list3 (Qleft, Qplus, make_number (x));
4416 else
4417 element = Fcons (Qleft, make_number (x));
4418 result = Fcons (element, result);
4419 }
4420
4421 if (geometry & YValue)
4422 {
4423 Lisp_Object element;
4424
4425 if (y >= 0 && (geometry & YNegative))
4426 element = list3 (Qtop, Qminus, make_number (-y));
4427 else if (y < 0 && ! (geometry & YNegative))
4428 element = list3 (Qtop, Qplus, make_number (y));
4429 else
4430 element = Fcons (Qtop, make_number (y));
4431 result = Fcons (element, result);
4432 }
4433
4434 if (geometry & WidthValue)
4435 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4436 if (geometry & HeightValue)
4437 result = Fcons (Fcons (Qheight, make_number (height)), result);
4438
4439 return result;
4440 }
4441
4442
4443 /* Calculate the desired size and position of frame F.
4444 Return the flags saying which aspects were specified.
4445
4446 Also set the win_gravity and size_hint_flags of F.
4447
4448 Adjust height for toolbar if TOOLBAR_P is 1.
4449
4450 This function does not make the coordinates positive. */
4451
4452 #define DEFAULT_ROWS 35
4453 #define DEFAULT_COLS 80
4454
4455 long
4456 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4457 {
4458 Lisp_Object height, width, user_size, top, left, user_position;
4459 long window_prompting = 0;
4460 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4461
4462 /* Default values if we fall through.
4463 Actually, if that happens we should get
4464 window manager prompting. */
4465 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4466 SET_FRAME_COLS (f, DEFAULT_COLS);
4467 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4468 SET_FRAME_LINES (f, DEFAULT_ROWS);
4469
4470 /* Window managers expect that if program-specified
4471 positions are not (0,0), they're intentional, not defaults. */
4472 f->top_pos = 0;
4473 f->left_pos = 0;
4474
4475 /* Ensure that earlier new_width and new_height settings won't
4476 override what we specify below. */
4477 f->new_width = f->new_height = 0;
4478
4479 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4480 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4481 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4482 {
4483 if (!EQ (width, Qunbound))
4484 {
4485 CHECK_NUMBER (width);
4486 if (! (0 <= XINT (width) && XINT (width) <= INT_MAX))
4487 xsignal1 (Qargs_out_of_range, width);
4488
4489 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4490 }
4491
4492 if (!EQ (height, Qunbound))
4493 {
4494 CHECK_NUMBER (height);
4495 if (! (0 <= XINT (height) && XINT (height) <= INT_MAX))
4496 xsignal1 (Qargs_out_of_range, height);
4497
4498 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4499 }
4500
4501 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4502 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4503 window_prompting |= USSize;
4504 else
4505 window_prompting |= PSize;
4506 }
4507
4508 /* Add a tool bar height to the initial frame height so that the user
4509 gets a text display area of the size he specified with -g or via
4510 .Xdefaults. Later changes of the tool bar height don't change the
4511 frame size. This is done so that users can create tall Emacs
4512 frames without having to guess how tall the tool bar will get. */
4513 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4514 {
4515 int margin, relief;
4516
4517 relief = (tool_bar_button_relief >= 0
4518 ? tool_bar_button_relief
4519 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4520
4521 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4522 margin = XFASTINT (Vtool_bar_button_margin);
4523 else if (CONSP (Vtool_bar_button_margin)
4524 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4525 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4526 else
4527 margin = 0;
4528
4529 FRAME_TOOL_BAR_HEIGHT (f)
4530 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4531 Vframe_initial_frame_tool_bar_height = make_number (FRAME_TOOL_BAR_HEIGHT (f));
4532 }
4533
4534 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4535 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4536 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4537 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4538 {
4539 if (EQ (top, Qminus))
4540 {
4541 f->top_pos = 0;
4542 window_prompting |= YNegative;
4543 }
4544 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4545 && CONSP (XCDR (top))
4546 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4547 {
4548 f->top_pos = - XINT (XCAR (XCDR (top)));
4549 window_prompting |= YNegative;
4550 }
4551 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4552 && CONSP (XCDR (top))
4553 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4554 {
4555 f->top_pos = XINT (XCAR (XCDR (top)));
4556 }
4557 else if (EQ (top, Qunbound))
4558 f->top_pos = 0;
4559 else
4560 {
4561 CHECK_TYPE_RANGED_INTEGER (int, top);
4562 f->top_pos = XINT (top);
4563 if (f->top_pos < 0)
4564 window_prompting |= YNegative;
4565 }
4566
4567 if (EQ (left, Qminus))
4568 {
4569 f->left_pos = 0;
4570 window_prompting |= XNegative;
4571 }
4572 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4573 && CONSP (XCDR (left))
4574 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4575 {
4576 f->left_pos = - XINT (XCAR (XCDR (left)));
4577 window_prompting |= XNegative;
4578 }
4579 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4580 && CONSP (XCDR (left))
4581 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4582 {
4583 f->left_pos = XINT (XCAR (XCDR (left)));
4584 }
4585 else if (EQ (left, Qunbound))
4586 f->left_pos = 0;
4587 else
4588 {
4589 CHECK_TYPE_RANGED_INTEGER (int, left);
4590 f->left_pos = XINT (left);
4591 if (f->left_pos < 0)
4592 window_prompting |= XNegative;
4593 }
4594
4595 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4596 window_prompting |= USPosition;
4597 else
4598 window_prompting |= PPosition;
4599 }
4600
4601 if (window_prompting & XNegative)
4602 {
4603 if (window_prompting & YNegative)
4604 f->win_gravity = SouthEastGravity;
4605 else
4606 f->win_gravity = NorthEastGravity;
4607 }
4608 else
4609 {
4610 if (window_prompting & YNegative)
4611 f->win_gravity = SouthWestGravity;
4612 else
4613 f->win_gravity = NorthWestGravity;
4614 }
4615
4616 f->size_hint_flags = window_prompting;
4617
4618 return window_prompting;
4619 }
4620
4621
4622
4623 #endif /* HAVE_WINDOW_SYSTEM */
4624
4625 void
4626 frame_make_pointer_invisible (struct frame *f)
4627 {
4628 if (! NILP (Vmake_pointer_invisible))
4629 {
4630 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4631 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4632 {
4633 f->mouse_moved = 0;
4634 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4635 f->pointer_invisible = 1;
4636 }
4637 }
4638 }
4639
4640 void
4641 frame_make_pointer_visible (struct frame *f)
4642 {
4643 /* We don't check Vmake_pointer_invisible here in case the
4644 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4645 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4646 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4647 {
4648 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4649 f->pointer_invisible = 0;
4650 }
4651 }
4652
4653 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4654 Sframe_pointer_visible_p, 0, 1, 0,
4655 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4656 Otherwise it returns nil. FRAME omitted or nil means the
4657 selected frame. This is useful when `make-pointer-invisible' is set. */)
4658 (Lisp_Object frame)
4659 {
4660 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4661 }
4662
4663
4664 \f
4665 /***********************************************************************
4666 Multimonitor data
4667 ***********************************************************************/
4668
4669 #ifdef HAVE_WINDOW_SYSTEM
4670
4671 # if (defined HAVE_NS \
4672 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4673 void
4674 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4675 {
4676 int i;
4677 for (i = 0; i < n_monitors; ++i)
4678 xfree (monitors[i].name);
4679 xfree (monitors);
4680 }
4681 # endif
4682
4683 Lisp_Object
4684 make_monitor_attribute_list (struct MonitorInfo *monitors,
4685 int n_monitors,
4686 int primary_monitor,
4687 Lisp_Object monitor_frames,
4688 const char *source)
4689 {
4690 Lisp_Object attributes_list = Qnil;
4691 Lisp_Object primary_monitor_attributes = Qnil;
4692 int i;
4693
4694 for (i = 0; i < n_monitors; ++i)
4695 {
4696 Lisp_Object geometry, workarea, attributes = Qnil;
4697 struct MonitorInfo *mi = &monitors[i];
4698
4699 if (mi->geom.width == 0) continue;
4700
4701 workarea = list4i (mi->work.x, mi->work.y,
4702 mi->work.width, mi->work.height);
4703 geometry = list4i (mi->geom.x, mi->geom.y,
4704 mi->geom.width, mi->geom.height);
4705 attributes = Fcons (Fcons (Qsource, build_string (source)),
4706 attributes);
4707 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4708 attributes);
4709 attributes = Fcons (Fcons (Qmm_size,
4710 list2i (mi->mm_width, mi->mm_height)),
4711 attributes);
4712 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4713 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4714 if (mi->name)
4715 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4716 strlen (mi->name))),
4717 attributes);
4718
4719 if (i == primary_monitor)
4720 primary_monitor_attributes = attributes;
4721 else
4722 attributes_list = Fcons (attributes, attributes_list);
4723 }
4724
4725 if (!NILP (primary_monitor_attributes))
4726 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4727 return attributes_list;
4728 }
4729
4730 #endif /* HAVE_WINDOW_SYSTEM */
4731
4732 \f
4733 /***********************************************************************
4734 Initialization
4735 ***********************************************************************/
4736
4737 void
4738 syms_of_frame (void)
4739 {
4740 DEFSYM (Qframep, "framep");
4741 DEFSYM (Qframe_live_p, "frame-live-p");
4742 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4743 DEFSYM (Qexplicit_name, "explicit-name");
4744 DEFSYM (Qheight, "height");
4745 DEFSYM (Qicon, "icon");
4746 DEFSYM (Qminibuffer, "minibuffer");
4747 DEFSYM (Qmodeline, "modeline");
4748 DEFSYM (Qonly, "only");
4749 DEFSYM (Qnone, "none");
4750 DEFSYM (Qwidth, "width");
4751 DEFSYM (Qgeometry, "geometry");
4752 DEFSYM (Qicon_left, "icon-left");
4753 DEFSYM (Qicon_top, "icon-top");
4754 DEFSYM (Qtooltip, "tooltip");
4755 DEFSYM (Quser_position, "user-position");
4756 DEFSYM (Quser_size, "user-size");
4757 DEFSYM (Qwindow_id, "window-id");
4758 #ifdef HAVE_X_WINDOWS
4759 DEFSYM (Qouter_window_id, "outer-window-id");
4760 #endif
4761 DEFSYM (Qparent_id, "parent-id");
4762 DEFSYM (Qx, "x");
4763 DEFSYM (Qw32, "w32");
4764 DEFSYM (Qpc, "pc");
4765 DEFSYM (Qns, "ns");
4766 DEFSYM (Qvisible, "visible");
4767 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4768 DEFSYM (Qbuffer_list, "buffer-list");
4769 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4770 DEFSYM (Qdisplay_type, "display-type");
4771 DEFSYM (Qbackground_mode, "background-mode");
4772 DEFSYM (Qnoelisp, "noelisp");
4773 DEFSYM (Qtty_color_mode, "tty-color-mode");
4774 DEFSYM (Qtty, "tty");
4775 DEFSYM (Qtty_type, "tty-type");
4776
4777 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4778
4779 DEFSYM (Qfullwidth, "fullwidth");
4780 DEFSYM (Qfullheight, "fullheight");
4781 DEFSYM (Qfullboth, "fullboth");
4782 DEFSYM (Qmaximized, "maximized");
4783 DEFSYM (Qx_resource_name, "x-resource-name");
4784 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4785
4786 DEFSYM (Qterminal, "terminal");
4787
4788 DEFSYM (Qgeometry, "geometry");
4789 DEFSYM (Qworkarea, "workarea");
4790 DEFSYM (Qmm_size, "mm-size");
4791 DEFSYM (Qframes, "frames");
4792 DEFSYM (Qsource, "source");
4793
4794 #ifdef HAVE_NS
4795 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4796 #endif
4797
4798 {
4799 int i;
4800
4801 for (i = 0; i < ARRAYELTS (frame_parms); i++)
4802 {
4803 Lisp_Object v = intern_c_string (frame_parms[i].name);
4804 if (frame_parms[i].variable)
4805 {
4806 *frame_parms[i].variable = v;
4807 staticpro (frame_parms[i].variable);
4808 }
4809 Fput (v, Qx_frame_parameter, make_number (i));
4810 }
4811 }
4812
4813 #ifdef HAVE_WINDOW_SYSTEM
4814 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4815 doc: /* The name Emacs uses to look up X resources.
4816 `x-get-resource' uses this as the first component of the instance name
4817 when requesting resource values.
4818 Emacs initially sets `x-resource-name' to the name under which Emacs
4819 was invoked, or to the value specified with the `-name' or `-rn'
4820 switches, if present.
4821
4822 It may be useful to bind this variable locally around a call
4823 to `x-get-resource'. See also the variable `x-resource-class'. */);
4824 Vx_resource_name = Qnil;
4825
4826 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4827 doc: /* The class Emacs uses to look up X resources.
4828 `x-get-resource' uses this as the first component of the instance class
4829 when requesting resource values.
4830
4831 Emacs initially sets `x-resource-class' to "Emacs".
4832
4833 Setting this variable permanently is not a reasonable thing to do,
4834 but binding this variable locally around a call to `x-get-resource'
4835 is a reasonable practice. See also the variable `x-resource-name'. */);
4836 Vx_resource_class = build_string (EMACS_CLASS);
4837
4838 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4839 doc: /* The lower limit of the frame opacity (alpha transparency).
4840 The value should range from 0 (invisible) to 100 (completely opaque).
4841 You can also use a floating number between 0.0 and 1.0. */);
4842 Vframe_alpha_lower_limit = make_number (20);
4843 #endif
4844
4845 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4846 doc: /* Alist of default values for frame creation.
4847 These may be set in your init file, like this:
4848 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4849 These override values given in window system configuration data,
4850 including X Windows' defaults database.
4851 For values specific to the first Emacs frame, see `initial-frame-alist'.
4852 For window-system specific values, see `window-system-default-frame-alist'.
4853 For values specific to the separate minibuffer frame, see
4854 `minibuffer-frame-alist'.
4855 The `menu-bar-lines' element of the list controls whether new frames
4856 have menu bars; `menu-bar-mode' works by altering this element.
4857 Setting this variable does not affect existing frames, only new ones. */);
4858 Vdefault_frame_alist = Qnil;
4859
4860 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4861 doc: /* Default position of vertical scroll bars on this window-system. */);
4862 #ifdef HAVE_WINDOW_SYSTEM
4863 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4864 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4865 default. */
4866 Vdefault_frame_scroll_bars = Qright;
4867 #else
4868 Vdefault_frame_scroll_bars = Qleft;
4869 #endif
4870 #else
4871 Vdefault_frame_scroll_bars = Qnil;
4872 #endif
4873
4874 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4875 scroll_bar_adjust_thumb_portion_p,
4876 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4877 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4878 even if the end of the buffer is shown (i.e. overscrolling).
4879 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4880 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4881 is visible. In this case you can not overscroll. */);
4882 scroll_bar_adjust_thumb_portion_p = 1;
4883
4884 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4885 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4886
4887 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4888 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4889 `mouse-position' and `mouse-pixel-position' call this function, passing their
4890 usual return value as argument, and return whatever this function returns.
4891 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4892 which need to do mouse handling at the Lisp level. */);
4893 Vmouse_position_function = Qnil;
4894
4895 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4896 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4897 If the value is an integer, highlighting is only shown after moving the
4898 mouse, while keyboard input turns off the highlight even when the mouse
4899 is over the clickable text. However, the mouse shape still indicates
4900 when the mouse is over clickable text. */);
4901 Vmouse_highlight = Qt;
4902
4903 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4904 doc: /* If non-nil, make pointer invisible while typing.
4905 The pointer becomes visible again when the mouse is moved. */);
4906 Vmake_pointer_invisible = Qt;
4907
4908 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4909 doc: /* Normal hook run when a frame gains input focus. */);
4910 Vfocus_in_hook = Qnil;
4911 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4912
4913 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4914 doc: /* Normal hook run when a frame loses input focus. */);
4915 Vfocus_out_hook = Qnil;
4916 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4917
4918 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4919 doc: /* Functions run before deleting a frame.
4920 The functions are run with one arg, the frame to be deleted.
4921 See `delete-frame'.
4922
4923 Note that functions in this list may be called just before the frame is
4924 actually deleted, or some time later (or even both when an earlier function
4925 in `delete-frame-functions' (indirectly) calls `delete-frame'
4926 recursively). */);
4927 Vdelete_frame_functions = Qnil;
4928 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4929
4930 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4931 doc: /* Non-nil if Menu-Bar mode is enabled.
4932 See the command `menu-bar-mode' for a description of this minor mode.
4933 Setting this variable directly does not take effect;
4934 either customize it (see the info node `Easy Customization')
4935 or call the function `menu-bar-mode'. */);
4936 Vmenu_bar_mode = Qt;
4937
4938 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4939 doc: /* Non-nil if Tool-Bar mode is enabled.
4940 See the command `tool-bar-mode' for a description of this minor mode.
4941 Setting this variable directly does not take effect;
4942 either customize it (see the info node `Easy Customization')
4943 or call the function `tool-bar-mode'. */);
4944 #ifdef HAVE_WINDOW_SYSTEM
4945 Vtool_bar_mode = Qt;
4946 #else
4947 Vtool_bar_mode = Qnil;
4948 #endif
4949
4950 DEFVAR_LISP ("frame-initial-frame-tool-bar-height", Vframe_initial_frame_tool_bar_height,
4951 doc: /* Height of tool bar of initial frame. */);
4952 Vframe_initial_frame_tool_bar_height = make_number (0);
4953
4954 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4955 doc: /* Minibufferless frames use this frame's minibuffer.
4956 Emacs cannot create minibufferless frames unless this is set to an
4957 appropriate surrogate.
4958
4959 Emacs consults this variable only when creating minibufferless
4960 frames; once the frame is created, it sticks with its assigned
4961 minibuffer, no matter what this variable is set to. This means that
4962 this variable doesn't necessarily say anything meaningful about the
4963 current set of frames, or where the minibuffer is currently being
4964 displayed.
4965
4966 This variable is local to the current terminal and cannot be buffer-local. */);
4967
4968 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4969 doc: /* Non-nil if window system changes focus when you move the mouse.
4970 You should set this variable to tell Emacs how your window manager
4971 handles focus, since there is no way in general for Emacs to find out
4972 automatically. See also `mouse-autoselect-window'. */);
4973 focus_follows_mouse = 0;
4974
4975 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
4976 doc: /* Non-nil means resize frames pixelwise.
4977 If this option is nil, resizing a frame rounds its sizes to the frame's
4978 current values of `frame-char-height' and `frame-char-width'. If this
4979 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4980 by one pixel.
4981
4982 With some window managers you may have to set this to non-nil in order
4983 to set the size of a frame in pixels, to maximize frames or to make them
4984 fullscreen. To resize your initial frame pixelwise, set this option to
4985 a non-nil value in your init file. */);
4986 frame_resize_pixelwise = 0;
4987
4988 DEFVAR_BOOL ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
4989 doc: /* Non-nil means do not resize frames implicitly.
4990 If this option is nil, setting default font, menubar mode, fringe width,
4991 or scroll bar mode of a specific frame may resize the frame in order to
4992 preserve the number of columns or lines it displays. If this option is
4993 non-nil, no such resizing is done. */);
4994 frame_inhibit_implied_resize = 0;
4995
4996 staticpro (&Vframe_list);
4997
4998 defsubr (&Sframep);
4999 defsubr (&Sframe_live_p);
5000 defsubr (&Swindow_system);
5001 defsubr (&Smake_terminal_frame);
5002 defsubr (&Shandle_switch_frame);
5003 defsubr (&Sselect_frame);
5004 defsubr (&Sselected_frame);
5005 defsubr (&Sframe_list);
5006 defsubr (&Snext_frame);
5007 defsubr (&Sprevious_frame);
5008 defsubr (&Slast_nonminibuf_frame);
5009 defsubr (&Sdelete_frame);
5010 defsubr (&Smouse_position);
5011 defsubr (&Smouse_pixel_position);
5012 defsubr (&Sset_mouse_position);
5013 defsubr (&Sset_mouse_pixel_position);
5014 #if 0
5015 defsubr (&Sframe_configuration);
5016 defsubr (&Srestore_frame_configuration);
5017 #endif
5018 defsubr (&Smake_frame_visible);
5019 defsubr (&Smake_frame_invisible);
5020 defsubr (&Siconify_frame);
5021 defsubr (&Sframe_visible_p);
5022 defsubr (&Svisible_frame_list);
5023 defsubr (&Sraise_frame);
5024 defsubr (&Slower_frame);
5025 defsubr (&Sx_focus_frame);
5026 defsubr (&Sredirect_frame_focus);
5027 defsubr (&Sframe_focus);
5028 defsubr (&Sframe_parameters);
5029 defsubr (&Sframe_parameter);
5030 defsubr (&Smodify_frame_parameters);
5031 defsubr (&Sframe_char_height);
5032 defsubr (&Sframe_char_width);
5033 defsubr (&Sframe_pixel_height);
5034 defsubr (&Sframe_pixel_width);
5035 defsubr (&Sframe_text_cols);
5036 defsubr (&Sframe_text_lines);
5037 defsubr (&Sframe_total_cols);
5038 defsubr (&Sframe_total_lines);
5039 defsubr (&Sframe_text_width);
5040 defsubr (&Sframe_text_height);
5041 defsubr (&Sscroll_bar_width);
5042 defsubr (&Sscroll_bar_height);
5043 defsubr (&Sfringe_width);
5044 defsubr (&Sborder_width);
5045 defsubr (&Sright_divider_width);
5046 defsubr (&Sbottom_divider_width);
5047 defsubr (&Stool_bar_pixel_width);
5048 defsubr (&Sset_frame_height);
5049 defsubr (&Sset_frame_width);
5050 defsubr (&Sset_frame_size);
5051 defsubr (&Sset_frame_position);
5052 defsubr (&Sframe_pointer_visible_p);
5053
5054 #ifdef HAVE_WINDOW_SYSTEM
5055 defsubr (&Sx_get_resource);
5056 defsubr (&Sx_parse_geometry);
5057 #endif
5058
5059 }