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