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