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