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