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