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