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