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