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