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