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