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