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