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