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