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