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