]> code.delx.au - gnu-emacs/blob - src/frame.c
Merge from emacs--devo--0
[gnu-emacs] / src / frame.c
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007 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
79 Lisp_Object Qx_frame_parameter;
80 Lisp_Object Qx_resource_name;
81
82 /* Frame parameters (set or reported). */
83
84 Lisp_Object Qauto_raise, Qauto_lower;
85 Lisp_Object Qborder_color, Qborder_width;
86 Lisp_Object Qcursor_color, Qcursor_type;
87 Lisp_Object Qgeometry; /* Not used */
88 Lisp_Object Qheight, Qwidth;
89 Lisp_Object Qleft, Qright;
90 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
91 Lisp_Object Qinternal_border_width;
92 Lisp_Object Qmouse_color;
93 Lisp_Object Qminibuffer;
94 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
95 Lisp_Object Qvisibility;
96 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
97 Lisp_Object Qscreen_gamma;
98 Lisp_Object Qline_spacing;
99 Lisp_Object Quser_position, Quser_size;
100 Lisp_Object Qwait_for_wm;
101 Lisp_Object Qwindow_id;
102 #ifdef HAVE_X_WINDOWS
103 Lisp_Object Qouter_window_id;
104 #endif
105 Lisp_Object Qparent_id;
106 Lisp_Object Qtitle, Qname;
107 Lisp_Object Qunsplittable;
108 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
109 Lisp_Object Qleft_fringe, Qright_fringe;
110 Lisp_Object Qbuffer_predicate, Qbuffer_list;
111 Lisp_Object Qtty_color_mode;
112
113 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
114 #ifdef USE_FONT_BACKEND
115 Lisp_Object Qfont_backend;
116 #endif /* USE_FONT_BACKEND */
117
118 Lisp_Object Qinhibit_face_set_after_frame_default;
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 of the frame, X is the horizontal offset, and Y is
1443 the vertical offset.
1444 If Emacs is running on a mouseless terminal or hasn't been programmed
1445 to read the mouse position, it returns the selected frame for FRAME
1446 and nil for X and Y.
1447 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1448 passing the normal return value to that function as an argument,
1449 and returns whatever that function returns. */)
1450 ()
1451 {
1452 FRAME_PTR f;
1453 Lisp_Object lispy_dummy;
1454 enum scroll_bar_part party_dummy;
1455 Lisp_Object x, y, retval;
1456 int col, row;
1457 unsigned long long_dummy;
1458 struct gcpro gcpro1;
1459
1460 f = SELECTED_FRAME ();
1461 x = y = Qnil;
1462
1463 #ifdef HAVE_MOUSE
1464 /* It's okay for the hook to refrain from storing anything. */
1465 if (mouse_position_hook)
1466 (*mouse_position_hook) (&f, -1,
1467 &lispy_dummy, &party_dummy,
1468 &x, &y,
1469 &long_dummy);
1470 if (! NILP (x))
1471 {
1472 col = XINT (x);
1473 row = XINT (y);
1474 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1475 XSETINT (x, col);
1476 XSETINT (y, row);
1477 }
1478 #endif
1479 XSETFRAME (lispy_dummy, f);
1480 retval = Fcons (lispy_dummy, Fcons (x, y));
1481 GCPRO1 (retval);
1482 if (!NILP (Vmouse_position_function))
1483 retval = call1 (Vmouse_position_function, retval);
1484 RETURN_UNGCPRO (retval);
1485 }
1486
1487 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1488 Smouse_pixel_position, 0, 0, 0,
1489 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1490 The position is given in pixel units, where (0, 0) is the
1491 upper-left corner of the frame, X is the horizontal offset, and Y is
1492 the vertical offset.
1493 If Emacs is running on a mouseless terminal or hasn't been programmed
1494 to read the mouse position, it returns the selected frame for FRAME
1495 and nil for X and Y. */)
1496 ()
1497 {
1498 FRAME_PTR f;
1499 Lisp_Object lispy_dummy;
1500 enum scroll_bar_part party_dummy;
1501 Lisp_Object x, y;
1502 unsigned long long_dummy;
1503
1504 f = SELECTED_FRAME ();
1505 x = y = Qnil;
1506
1507 #ifdef HAVE_MOUSE
1508 /* It's okay for the hook to refrain from storing anything. */
1509 if (mouse_position_hook)
1510 (*mouse_position_hook) (&f, -1,
1511 &lispy_dummy, &party_dummy,
1512 &x, &y,
1513 &long_dummy);
1514 #endif
1515 XSETFRAME (lispy_dummy, f);
1516 return Fcons (lispy_dummy, Fcons (x, y));
1517 }
1518
1519 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1520 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1521 Coordinates are relative to the frame, not a window,
1522 so the coordinates of the top left character in the frame
1523 may be nonzero due to left-hand scroll bars or the menu bar.
1524
1525 The position is given in character cells, where (0, 0) is the
1526 upper-left corner of the frame, X is the horizontal offset, and Y is
1527 the vertical offset.
1528
1529 This function is a no-op for an X frame that is not visible.
1530 If you have just created a frame, you must wait for it to become visible
1531 before calling this function on it, like this.
1532 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1533 (frame, x, y)
1534 Lisp_Object frame, x, y;
1535 {
1536 CHECK_LIVE_FRAME (frame);
1537 CHECK_NUMBER (x);
1538 CHECK_NUMBER (y);
1539
1540 /* I think this should be done with a hook. */
1541 #ifdef HAVE_WINDOW_SYSTEM
1542 if (FRAME_WINDOW_P (XFRAME (frame)))
1543 /* Warping the mouse will cause enternotify and focus events. */
1544 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1545 #else
1546 #if defined (MSDOS) && defined (HAVE_MOUSE)
1547 if (FRAME_MSDOS_P (XFRAME (frame)))
1548 {
1549 Fselect_frame (frame);
1550 mouse_moveto (XINT (x), XINT (y));
1551 }
1552 #endif
1553 #endif
1554
1555 return Qnil;
1556 }
1557
1558 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1559 Sset_mouse_pixel_position, 3, 3, 0,
1560 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1561 The position is given in pixels, where (0, 0) is the upper-left corner
1562 of the frame, X is the horizontal offset, and Y is the vertical offset.
1563
1564 Note, this is a no-op for an X frame that is not visible.
1565 If you have just created a frame, you must wait for it to become visible
1566 before calling this function on it, like this.
1567 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1568 (frame, x, y)
1569 Lisp_Object frame, x, y;
1570 {
1571 CHECK_LIVE_FRAME (frame);
1572 CHECK_NUMBER (x);
1573 CHECK_NUMBER (y);
1574
1575 /* I think this should be done with a hook. */
1576 #ifdef HAVE_WINDOW_SYSTEM
1577 if (FRAME_WINDOW_P (XFRAME (frame)))
1578 /* Warping the mouse will cause enternotify and focus events. */
1579 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1580 #else
1581 #if defined (MSDOS) && defined (HAVE_MOUSE)
1582 if (FRAME_MSDOS_P (XFRAME (frame)))
1583 {
1584 Fselect_frame (frame);
1585 mouse_moveto (XINT (x), XINT (y));
1586 }
1587 #endif
1588 #endif
1589
1590 return Qnil;
1591 }
1592 \f
1593 static void make_frame_visible_1 P_ ((Lisp_Object));
1594
1595 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1596 0, 1, "",
1597 doc: /* Make the frame FRAME visible (assuming it is an X window).
1598 If omitted, FRAME defaults to the currently selected frame. */)
1599 (frame)
1600 Lisp_Object frame;
1601 {
1602 if (NILP (frame))
1603 frame = selected_frame;
1604
1605 CHECK_LIVE_FRAME (frame);
1606
1607 /* I think this should be done with a hook. */
1608 #ifdef HAVE_WINDOW_SYSTEM
1609 if (FRAME_WINDOW_P (XFRAME (frame)))
1610 {
1611 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1612 x_make_frame_visible (XFRAME (frame));
1613 }
1614 #endif
1615
1616 make_frame_visible_1 (XFRAME (frame)->root_window);
1617
1618 /* Make menu bar update for the Buffers and Frames menus. */
1619 windows_or_buffers_changed++;
1620
1621 return frame;
1622 }
1623
1624 /* Update the display_time slot of the buffers shown in WINDOW
1625 and all its descendents. */
1626
1627 static void
1628 make_frame_visible_1 (window)
1629 Lisp_Object window;
1630 {
1631 struct window *w;
1632
1633 for (;!NILP (window); window = w->next)
1634 {
1635 w = XWINDOW (window);
1636
1637 if (!NILP (w->buffer))
1638 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1639
1640 if (!NILP (w->vchild))
1641 make_frame_visible_1 (w->vchild);
1642 if (!NILP (w->hchild))
1643 make_frame_visible_1 (w->hchild);
1644 }
1645 }
1646
1647 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1648 0, 2, "",
1649 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1650 If omitted, FRAME defaults to the currently selected frame.
1651 Normally you may not make FRAME invisible if all other frames are invisible,
1652 but if the second optional argument FORCE is non-nil, you may do so. */)
1653 (frame, force)
1654 Lisp_Object frame, force;
1655 {
1656 if (NILP (frame))
1657 frame = selected_frame;
1658
1659 CHECK_LIVE_FRAME (frame);
1660
1661 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1662 error ("Attempt to make invisible the sole visible or iconified frame");
1663
1664 #if 0 /* This isn't logically necessary, and it can do GC. */
1665 /* Don't let the frame remain selected. */
1666 if (EQ (frame, selected_frame))
1667 do_switch_frame (next_frame (frame, Qt), 0, 0)
1668 #endif
1669
1670 /* Don't allow minibuf_window to remain on a deleted frame. */
1671 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1672 {
1673 struct frame *sf = XFRAME (selected_frame);
1674 Fset_window_buffer (sf->minibuffer_window,
1675 XWINDOW (minibuf_window)->buffer, Qnil);
1676 minibuf_window = sf->minibuffer_window;
1677 }
1678
1679 /* I think this should be done with a hook. */
1680 #ifdef HAVE_WINDOW_SYSTEM
1681 if (FRAME_WINDOW_P (XFRAME (frame)))
1682 x_make_frame_invisible (XFRAME (frame));
1683 #endif
1684
1685 /* Make menu bar update for the Buffers and Frames menus. */
1686 windows_or_buffers_changed++;
1687
1688 return Qnil;
1689 }
1690
1691 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1692 0, 1, "",
1693 doc: /* Make the frame FRAME into an icon.
1694 If omitted, FRAME defaults to the currently selected frame. */)
1695 (frame)
1696 Lisp_Object frame;
1697 {
1698 if (NILP (frame))
1699 frame = selected_frame;
1700
1701 CHECK_LIVE_FRAME (frame);
1702
1703 #if 0 /* This isn't logically necessary, and it can do GC. */
1704 /* Don't let the frame remain selected. */
1705 if (EQ (frame, selected_frame))
1706 Fhandle_switch_frame (next_frame (frame, Qt));
1707 #endif
1708
1709 /* Don't allow minibuf_window to remain on a deleted frame. */
1710 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1711 {
1712 struct frame *sf = XFRAME (selected_frame);
1713 Fset_window_buffer (sf->minibuffer_window,
1714 XWINDOW (minibuf_window)->buffer, Qnil);
1715 minibuf_window = sf->minibuffer_window;
1716 }
1717
1718 /* I think this should be done with a hook. */
1719 #ifdef HAVE_WINDOW_SYSTEM
1720 if (FRAME_WINDOW_P (XFRAME (frame)))
1721 x_iconify_frame (XFRAME (frame));
1722 #endif
1723
1724 /* Make menu bar update for the Buffers and Frames menus. */
1725 windows_or_buffers_changed++;
1726
1727 return Qnil;
1728 }
1729
1730 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1731 1, 1, 0,
1732 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1733 A frame that is not \"visible\" is not updated and, if it works through
1734 a window system, it may not show at all.
1735 Return the symbol `icon' if frame is visible only as an icon.
1736
1737 On a text-only terminal, all frames are considered visible, whether
1738 they are currently being displayed or not, and this function returns t
1739 for all frames. */)
1740 (frame)
1741 Lisp_Object frame;
1742 {
1743 CHECK_LIVE_FRAME (frame);
1744
1745 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1746
1747 if (FRAME_VISIBLE_P (XFRAME (frame)))
1748 return Qt;
1749 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1750 return Qicon;
1751 return Qnil;
1752 }
1753
1754 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1755 0, 0, 0,
1756 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1757 ()
1758 {
1759 Lisp_Object tail, frame;
1760 struct frame *f;
1761 Lisp_Object value;
1762
1763 value = Qnil;
1764 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1765 {
1766 frame = XCAR (tail);
1767 if (!FRAMEP (frame))
1768 continue;
1769 f = XFRAME (frame);
1770 if (FRAME_VISIBLE_P (f))
1771 value = Fcons (frame, value);
1772 }
1773 return value;
1774 }
1775
1776
1777 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1778 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1779 If FRAME is invisible or iconified, make it visible.
1780 If you don't specify a frame, the selected frame is used.
1781 If Emacs is displaying on an ordinary terminal or some other device which
1782 doesn't support multiple overlapping frames, this function does nothing. */)
1783 (frame)
1784 Lisp_Object frame;
1785 {
1786 if (NILP (frame))
1787 frame = selected_frame;
1788
1789 CHECK_LIVE_FRAME (frame);
1790
1791 /* Do like the documentation says. */
1792 Fmake_frame_visible (frame);
1793
1794 if (frame_raise_lower_hook)
1795 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1796
1797 return Qnil;
1798 }
1799
1800 /* Should we have a corresponding function called Flower_Power? */
1801 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1802 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1803 If you don't specify a frame, the selected frame is used.
1804 If Emacs is displaying on an ordinary terminal or some other device which
1805 doesn't support multiple overlapping frames, this function does nothing. */)
1806 (frame)
1807 Lisp_Object frame;
1808 {
1809 if (NILP (frame))
1810 frame = selected_frame;
1811
1812 CHECK_LIVE_FRAME (frame);
1813
1814 if (frame_raise_lower_hook)
1815 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1816
1817 return Qnil;
1818 }
1819
1820 \f
1821 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1822 1, 2, 0,
1823 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1824 In other words, switch-frame events caused by events in FRAME will
1825 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1826 FOCUS-FRAME after reading an event typed at FRAME.
1827
1828 If FOCUS-FRAME is omitted or nil, any existing redirection is
1829 cancelled, and the frame again receives its own keystrokes.
1830
1831 Focus redirection is useful for temporarily redirecting keystrokes to
1832 a surrogate minibuffer frame when a frame doesn't have its own
1833 minibuffer window.
1834
1835 A frame's focus redirection can be changed by `select-frame'. If frame
1836 FOO is selected, and then a different frame BAR is selected, any
1837 frames redirecting their focus to FOO are shifted to redirect their
1838 focus to BAR. This allows focus redirection to work properly when the
1839 user switches from one frame to another using `select-window'.
1840
1841 This means that a frame whose focus is redirected to itself is treated
1842 differently from a frame whose focus is redirected to nil; the former
1843 is affected by `select-frame', while the latter is not.
1844
1845 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1846 (frame, focus_frame)
1847 Lisp_Object frame, focus_frame;
1848 {
1849 /* Note that we don't check for a live frame here. It's reasonable
1850 to redirect the focus of a frame you're about to delete, if you
1851 know what other frame should receive those keystrokes. */
1852 CHECK_FRAME (frame);
1853
1854 if (! NILP (focus_frame))
1855 CHECK_LIVE_FRAME (focus_frame);
1856
1857 XFRAME (frame)->focus_frame = focus_frame;
1858
1859 if (frame_rehighlight_hook)
1860 (*frame_rehighlight_hook) (XFRAME (frame));
1861
1862 return Qnil;
1863 }
1864
1865
1866 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1867 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1868 This returns nil if FRAME's focus is not redirected.
1869 See `redirect-frame-focus'. */)
1870 (frame)
1871 Lisp_Object frame;
1872 {
1873 CHECK_LIVE_FRAME (frame);
1874
1875 return FRAME_FOCUS_FRAME (XFRAME (frame));
1876 }
1877
1878
1879 \f
1880 /* Return the value of frame parameter PROP in frame FRAME. */
1881
1882 Lisp_Object
1883 get_frame_param (frame, prop)
1884 register struct frame *frame;
1885 Lisp_Object prop;
1886 {
1887 register Lisp_Object tem;
1888
1889 tem = Fassq (prop, frame->param_alist);
1890 if (EQ (tem, Qnil))
1891 return tem;
1892 return Fcdr (tem);
1893 }
1894
1895 /* Return the buffer-predicate of the selected frame. */
1896
1897 Lisp_Object
1898 frame_buffer_predicate (frame)
1899 Lisp_Object frame;
1900 {
1901 return XFRAME (frame)->buffer_predicate;
1902 }
1903
1904 /* Return the buffer-list of the selected frame. */
1905
1906 Lisp_Object
1907 frame_buffer_list (frame)
1908 Lisp_Object frame;
1909 {
1910 return XFRAME (frame)->buffer_list;
1911 }
1912
1913 /* Set the buffer-list of the selected frame. */
1914
1915 void
1916 set_frame_buffer_list (frame, list)
1917 Lisp_Object frame, list;
1918 {
1919 XFRAME (frame)->buffer_list = list;
1920 }
1921
1922 /* Discard BUFFER from the buffer-list of each frame. */
1923
1924 void
1925 frames_discard_buffer (buffer)
1926 Lisp_Object buffer;
1927 {
1928 Lisp_Object frame, tail;
1929
1930 FOR_EACH_FRAME (tail, frame)
1931 {
1932 XFRAME (frame)->buffer_list
1933 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1934 }
1935 }
1936
1937 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1938 If the alist already has an element for PROP, we change it. */
1939
1940 void
1941 store_in_alist (alistptr, prop, val)
1942 Lisp_Object *alistptr, val;
1943 Lisp_Object prop;
1944 {
1945 register Lisp_Object tem;
1946
1947 tem = Fassq (prop, *alistptr);
1948 if (EQ (tem, Qnil))
1949 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1950 else
1951 Fsetcdr (tem, val);
1952 }
1953
1954 static int
1955 frame_name_fnn_p (str, len)
1956 char *str;
1957 EMACS_INT len;
1958 {
1959 if (len > 1 && str[0] == 'F')
1960 {
1961 char *end_ptr;
1962
1963 strtol (str + 1, &end_ptr, 10);
1964
1965 if (end_ptr == str + len)
1966 return 1;
1967 }
1968 return 0;
1969 }
1970
1971 /* Set the name of the terminal frame. Also used by MSDOS frames.
1972 Modeled after x_set_name which is used for WINDOW frames. */
1973
1974 static void
1975 set_term_frame_name (f, name)
1976 struct frame *f;
1977 Lisp_Object name;
1978 {
1979 f->explicit_name = ! NILP (name);
1980
1981 /* If NAME is nil, set the name to F<num>. */
1982 if (NILP (name))
1983 {
1984 char namebuf[20];
1985
1986 /* Check for no change needed in this very common case
1987 before we do any consing. */
1988 if (frame_name_fnn_p (SDATA (f->name),
1989 SBYTES (f->name)))
1990 return;
1991
1992 terminal_frame_count++;
1993 sprintf (namebuf, "F%d", terminal_frame_count);
1994 name = build_string (namebuf);
1995 }
1996 else
1997 {
1998 CHECK_STRING (name);
1999
2000 /* Don't change the name if it's already NAME. */
2001 if (! NILP (Fstring_equal (name, f->name)))
2002 return;
2003
2004 /* Don't allow the user to set the frame name to F<num>, so it
2005 doesn't clash with the names we generate for terminal frames. */
2006 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2007 error ("Frame names of the form F<num> are usurped by Emacs");
2008 }
2009
2010 f->name = name;
2011 update_mode_lines = 1;
2012 }
2013
2014 void
2015 store_frame_param (f, prop, val)
2016 struct frame *f;
2017 Lisp_Object prop, val;
2018 {
2019 register Lisp_Object old_alist_elt;
2020
2021 /* The buffer-alist parameter is stored in a special place and is
2022 not in the alist. */
2023 if (EQ (prop, Qbuffer_list))
2024 {
2025 f->buffer_list = val;
2026 return;
2027 }
2028
2029 /* If PROP is a symbol which is supposed to have frame-local values,
2030 and it is set up based on this frame, switch to the global
2031 binding. That way, we can create or alter the frame-local binding
2032 without messing up the symbol's status. */
2033 if (SYMBOLP (prop))
2034 {
2035 Lisp_Object valcontents;
2036 valcontents = SYMBOL_VALUE (prop);
2037 if ((BUFFER_LOCAL_VALUEP (valcontents)
2038 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2039 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2040 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2041 swap_in_global_binding (prop);
2042 }
2043
2044 #ifndef WINDOWSNT
2045 /* The tty color mode needs to be set before the frame's parameter
2046 alist is updated with the new value, because set_tty_color_mode
2047 wants to look at the old mode. */
2048 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2049 set_tty_color_mode (f, val);
2050 #endif
2051
2052 /* Update the frame parameter alist. */
2053 old_alist_elt = Fassq (prop, f->param_alist);
2054 if (EQ (old_alist_elt, Qnil))
2055 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2056 else
2057 Fsetcdr (old_alist_elt, val);
2058
2059 /* Update some other special parameters in their special places
2060 in addition to the alist. */
2061
2062 if (EQ (prop, Qbuffer_predicate))
2063 f->buffer_predicate = val;
2064
2065 if (! FRAME_WINDOW_P (f))
2066 {
2067 if (EQ (prop, Qmenu_bar_lines))
2068 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2069 else if (EQ (prop, Qname))
2070 set_term_frame_name (f, val);
2071 }
2072
2073 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2074 {
2075 if (! MINI_WINDOW_P (XWINDOW (val)))
2076 error ("Surrogate minibuffer windows must be minibuffer windows");
2077
2078 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2079 && !EQ (val, f->minibuffer_window))
2080 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2081
2082 /* Install the chosen minibuffer window, with proper buffer. */
2083 f->minibuffer_window = val;
2084 }
2085 }
2086
2087 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2088 doc: /* Return the parameters-alist of frame FRAME.
2089 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2090 The meaningful PARMs depend on the kind of frame.
2091 If FRAME is omitted, return information on the currently selected frame. */)
2092 (frame)
2093 Lisp_Object frame;
2094 {
2095 Lisp_Object alist;
2096 FRAME_PTR f;
2097 int height, width;
2098 struct gcpro gcpro1;
2099
2100 if (NILP (frame))
2101 frame = selected_frame;
2102
2103 CHECK_FRAME (frame);
2104 f = XFRAME (frame);
2105
2106 if (!FRAME_LIVE_P (f))
2107 return Qnil;
2108
2109 alist = Fcopy_alist (f->param_alist);
2110 GCPRO1 (alist);
2111
2112 if (!FRAME_WINDOW_P (f))
2113 {
2114 int fg = FRAME_FOREGROUND_PIXEL (f);
2115 int bg = FRAME_BACKGROUND_PIXEL (f);
2116 Lisp_Object elt;
2117
2118 /* If the frame's parameter alist says the colors are
2119 unspecified and reversed, take the frame's background pixel
2120 for foreground and vice versa. */
2121 elt = Fassq (Qforeground_color, alist);
2122 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2123 {
2124 if (strncmp (SDATA (XCDR (elt)),
2125 unspecified_bg,
2126 SCHARS (XCDR (elt))) == 0)
2127 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2128 else if (strncmp (SDATA (XCDR (elt)),
2129 unspecified_fg,
2130 SCHARS (XCDR (elt))) == 0)
2131 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2132 }
2133 else
2134 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2135 elt = Fassq (Qbackground_color, alist);
2136 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2137 {
2138 if (strncmp (SDATA (XCDR (elt)),
2139 unspecified_fg,
2140 SCHARS (XCDR (elt))) == 0)
2141 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2142 else if (strncmp (SDATA (XCDR (elt)),
2143 unspecified_bg,
2144 SCHARS (XCDR (elt))) == 0)
2145 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2146 }
2147 else
2148 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2149 store_in_alist (&alist, intern ("font"),
2150 build_string (FRAME_MSDOS_P (f)
2151 ? "ms-dos"
2152 : FRAME_W32_P (f) ? "w32term"
2153 :"tty"));
2154 }
2155 store_in_alist (&alist, Qname, f->name);
2156 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2157 store_in_alist (&alist, Qheight, make_number (height));
2158 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2159 store_in_alist (&alist, Qwidth, make_number (width));
2160 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2161 store_in_alist (&alist, Qminibuffer,
2162 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2163 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2164 : FRAME_MINIBUF_WINDOW (f)));
2165 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2166 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2167
2168 /* I think this should be done with a hook. */
2169 #ifdef HAVE_WINDOW_SYSTEM
2170 if (FRAME_WINDOW_P (f))
2171 x_report_frame_params (f, &alist);
2172 else
2173 #endif
2174 {
2175 /* This ought to be correct in f->param_alist for an X frame. */
2176 Lisp_Object lines;
2177 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2178 store_in_alist (&alist, Qmenu_bar_lines, lines);
2179 }
2180
2181 UNGCPRO;
2182 return alist;
2183 }
2184
2185
2186 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2187 doc: /* Return FRAME's value for parameter PARAMETER.
2188 If FRAME is nil, describe the currently selected frame. */)
2189 (frame, parameter)
2190 Lisp_Object frame, parameter;
2191 {
2192 struct frame *f;
2193 Lisp_Object value;
2194
2195 if (NILP (frame))
2196 frame = selected_frame;
2197 else
2198 CHECK_FRAME (frame);
2199 CHECK_SYMBOL (parameter);
2200
2201 f = XFRAME (frame);
2202 value = Qnil;
2203
2204 if (FRAME_LIVE_P (f))
2205 {
2206 /* Avoid consing in frequent cases. */
2207 if (EQ (parameter, Qname))
2208 value = f->name;
2209 #ifdef HAVE_X_WINDOWS
2210 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2211 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2212 #endif /* HAVE_X_WINDOWS */
2213 else if (EQ (parameter, Qbackground_color)
2214 || EQ (parameter, Qforeground_color))
2215 {
2216 value = Fassq (parameter, f->param_alist);
2217 if (CONSP (value))
2218 {
2219 value = XCDR (value);
2220 /* Fframe_parameters puts the actual fg/bg color names,
2221 even if f->param_alist says otherwise. This is
2222 important when param_alist's notion of colors is
2223 "unspecified". We need to do the same here. */
2224 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2225 {
2226 const char *color_name;
2227 EMACS_INT csz;
2228
2229 if (EQ (parameter, Qbackground_color))
2230 {
2231 color_name = SDATA (value);
2232 csz = SCHARS (value);
2233 if (strncmp (color_name, unspecified_bg, csz) == 0)
2234 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2235 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2236 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2237 }
2238 else if (EQ (parameter, Qforeground_color))
2239 {
2240 color_name = SDATA (value);
2241 csz = SCHARS (value);
2242 if (strncmp (color_name, unspecified_fg, csz) == 0)
2243 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2244 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2245 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2246 }
2247 }
2248 }
2249 else
2250 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2251 }
2252 else if (EQ (parameter, Qdisplay_type)
2253 || EQ (parameter, Qbackground_mode))
2254 value = Fcdr (Fassq (parameter, f->param_alist));
2255 else
2256 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2257 }
2258
2259 return value;
2260 }
2261
2262
2263 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2264 Smodify_frame_parameters, 2, 2, 0,
2265 doc: /* Modify the parameters of frame FRAME according to ALIST.
2266 If FRAME is nil, it defaults to the selected frame.
2267 ALIST is an alist of parameters to change and their new values.
2268 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2269 The meaningful PARMs depend on the kind of frame.
2270 Undefined PARMs are ignored, but stored in the frame's parameter list
2271 so that `frame-parameters' will return them.
2272
2273 The value of frame parameter FOO can also be accessed
2274 as a frame-local binding for the variable FOO, if you have
2275 enabled such bindings for that variable with `make-variable-frame-local'. */)
2276 (frame, alist)
2277 Lisp_Object frame, alist;
2278 {
2279 FRAME_PTR f;
2280 register Lisp_Object tail, prop, val;
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 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 int count = SPECPDL_INDEX ();
2737
2738 old_value = get_frame_param (f, prop);
2739 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2740
2741 if (NILP (Fequal (val, old_value)))
2742 {
2743 /* For :font attributes, the frame_parm_handler
2744 x_set_font calls `face-set-after-frame-default'.
2745 Unless we bind inhibit-face-set-after-frame-default
2746 here, this would reset the :font attribute that we
2747 just applied to the default value for new faces. */
2748 specbind (Qinhibit_face_set_after_frame_default, Qt);
2749
2750 store_frame_param (f, prop, val);
2751
2752 param_index = Fget (prop, Qx_frame_parameter);
2753 if (NATNUMP (param_index)
2754 && (XFASTINT (param_index)
2755 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2756 && rif->frame_parm_handlers[XINT (param_index)])
2757 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2758
2759 unbind_to (count, Qnil);
2760 }
2761 }
2762 }
2763
2764 /* Now process them in reverse of specified order. */
2765 for (i--; i >= 0; i--)
2766 {
2767 Lisp_Object prop, val;
2768
2769 prop = parms[i];
2770 val = values[i];
2771
2772 if (EQ (prop, Qwidth) && NUMBERP (val))
2773 width = XFASTINT (val);
2774 else if (EQ (prop, Qheight) && NUMBERP (val))
2775 height = XFASTINT (val);
2776 else if (EQ (prop, Qtop))
2777 top = val;
2778 else if (EQ (prop, Qleft))
2779 left = val;
2780 else if (EQ (prop, Qicon_top))
2781 icon_top = val;
2782 else if (EQ (prop, Qicon_left))
2783 icon_left = val;
2784 else if (EQ (prop, Qforeground_color)
2785 || EQ (prop, Qbackground_color)
2786 || EQ (prop, Qfont)
2787 || EQ (prop, Qfullscreen))
2788 /* Processed above. */
2789 continue;
2790 else
2791 {
2792 register Lisp_Object param_index, old_value;
2793
2794 old_value = get_frame_param (f, prop);
2795
2796 store_frame_param (f, prop, val);
2797
2798 param_index = Fget (prop, Qx_frame_parameter);
2799 if (NATNUMP (param_index)
2800 && (XFASTINT (param_index)
2801 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2802 && rif->frame_parm_handlers[XINT (param_index)])
2803 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2804 }
2805 }
2806
2807 /* Don't die if just one of these was set. */
2808 if (EQ (left, Qunbound))
2809 {
2810 left_no_change = 1;
2811 if (f->left_pos < 0)
2812 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2813 else
2814 XSETINT (left, f->left_pos);
2815 }
2816 if (EQ (top, Qunbound))
2817 {
2818 top_no_change = 1;
2819 if (f->top_pos < 0)
2820 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2821 else
2822 XSETINT (top, f->top_pos);
2823 }
2824
2825 /* If one of the icon positions was not set, preserve or default it. */
2826 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
2827 {
2828 icon_left_no_change = 1;
2829 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2830 if (NILP (icon_left))
2831 XSETINT (icon_left, 0);
2832 }
2833 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
2834 {
2835 icon_top_no_change = 1;
2836 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2837 if (NILP (icon_top))
2838 XSETINT (icon_top, 0);
2839 }
2840
2841 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
2842 {
2843 /* If the frame is visible already and the fullscreen parameter is
2844 being set, it is too late to set WM manager hints to specify
2845 size and position.
2846 Here we first get the width, height and position that applies to
2847 fullscreen. We then move the frame to the appropriate
2848 position. Resize of the frame is taken care of in the code after
2849 this if-statement. */
2850 int new_left, new_top;
2851
2852 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
2853 if (new_top != f->top_pos || new_left != f->left_pos)
2854 x_set_offset (f, new_left, new_top, 1);
2855 }
2856
2857 /* Don't set these parameters unless they've been explicitly
2858 specified. The window might be mapped or resized while we're in
2859 this function, and we don't want to override that unless the lisp
2860 code has asked for it.
2861
2862 Don't set these parameters unless they actually differ from the
2863 window's current parameters; the window may not actually exist
2864 yet. */
2865 {
2866 Lisp_Object frame;
2867
2868 check_frame_size (f, &height, &width);
2869
2870 XSETFRAME (frame, f);
2871
2872 if (width != FRAME_COLS (f)
2873 || height != FRAME_LINES (f)
2874 || f->new_text_lines || f->new_text_cols)
2875 Fset_frame_size (frame, make_number (width), make_number (height));
2876
2877 if ((!NILP (left) || !NILP (top))
2878 && ! (left_no_change && top_no_change)
2879 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2880 && NUMBERP (top) && XINT (top) == f->top_pos))
2881 {
2882 int leftpos = 0;
2883 int toppos = 0;
2884
2885 /* Record the signs. */
2886 f->size_hint_flags &= ~ (XNegative | YNegative);
2887 if (EQ (left, Qminus))
2888 f->size_hint_flags |= XNegative;
2889 else if (INTEGERP (left))
2890 {
2891 leftpos = XINT (left);
2892 if (leftpos < 0)
2893 f->size_hint_flags |= XNegative;
2894 }
2895 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2896 && CONSP (XCDR (left))
2897 && INTEGERP (XCAR (XCDR (left))))
2898 {
2899 leftpos = - XINT (XCAR (XCDR (left)));
2900 f->size_hint_flags |= XNegative;
2901 }
2902 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2903 && CONSP (XCDR (left))
2904 && INTEGERP (XCAR (XCDR (left))))
2905 {
2906 leftpos = XINT (XCAR (XCDR (left)));
2907 }
2908
2909 if (EQ (top, Qminus))
2910 f->size_hint_flags |= YNegative;
2911 else if (INTEGERP (top))
2912 {
2913 toppos = XINT (top);
2914 if (toppos < 0)
2915 f->size_hint_flags |= YNegative;
2916 }
2917 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2918 && CONSP (XCDR (top))
2919 && INTEGERP (XCAR (XCDR (top))))
2920 {
2921 toppos = - XINT (XCAR (XCDR (top)));
2922 f->size_hint_flags |= YNegative;
2923 }
2924 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2925 && CONSP (XCDR (top))
2926 && INTEGERP (XCAR (XCDR (top))))
2927 {
2928 toppos = XINT (XCAR (XCDR (top)));
2929 }
2930
2931
2932 /* Store the numeric value of the position. */
2933 f->top_pos = toppos;
2934 f->left_pos = leftpos;
2935
2936 f->win_gravity = NorthWestGravity;
2937
2938 /* Actually set that position, and convert to absolute. */
2939 x_set_offset (f, leftpos, toppos, -1);
2940 }
2941
2942 if ((!NILP (icon_left) || !NILP (icon_top))
2943 && ! (icon_left_no_change && icon_top_no_change))
2944 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2945 }
2946
2947 UNGCPRO;
2948 }
2949
2950
2951 /* Insert a description of internally-recorded parameters of frame X
2952 into the parameter alist *ALISTPTR that is to be given to the user.
2953 Only parameters that are specific to the X window system
2954 and whose values are not correctly recorded in the frame's
2955 param_alist need to be considered here. */
2956
2957 void
2958 x_report_frame_params (f, alistptr)
2959 struct frame *f;
2960 Lisp_Object *alistptr;
2961 {
2962 char buf[16];
2963 Lisp_Object tem;
2964
2965 /* Represent negative positions (off the top or left screen edge)
2966 in a way that Fmodify_frame_parameters will understand correctly. */
2967 XSETINT (tem, f->left_pos);
2968 if (f->left_pos >= 0)
2969 store_in_alist (alistptr, Qleft, tem);
2970 else
2971 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
2972
2973 XSETINT (tem, f->top_pos);
2974 if (f->top_pos >= 0)
2975 store_in_alist (alistptr, Qtop, tem);
2976 else
2977 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
2978
2979 store_in_alist (alistptr, Qborder_width,
2980 make_number (f->border_width));
2981 store_in_alist (alistptr, Qinternal_border_width,
2982 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
2983 store_in_alist (alistptr, Qleft_fringe,
2984 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
2985 store_in_alist (alistptr, Qright_fringe,
2986 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
2987 store_in_alist (alistptr, Qscroll_bar_width,
2988 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2989 ? make_number (0)
2990 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
2991 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
2992 /* nil means "use default width"
2993 for non-toolkit scroll bar.
2994 ruler-mode.el depends on this. */
2995 : Qnil));
2996 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
2997 store_in_alist (alistptr, Qwindow_id,
2998 build_string (buf));
2999 #ifdef HAVE_X_WINDOWS
3000 #ifdef USE_X_TOOLKIT
3001 /* Tooltip frame may not have this widget. */
3002 if (FRAME_X_OUTPUT (f)->widget)
3003 #endif
3004 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3005 store_in_alist (alistptr, Qouter_window_id,
3006 build_string (buf));
3007 #endif
3008 store_in_alist (alistptr, Qicon_name, f->icon_name);
3009 FRAME_SAMPLE_VISIBILITY (f);
3010 store_in_alist (alistptr, Qvisibility,
3011 (FRAME_VISIBLE_P (f) ? Qt
3012 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3013 store_in_alist (alistptr, Qdisplay,
3014 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3015
3016 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3017 tem = Qnil;
3018 else
3019 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3020 store_in_alist (alistptr, Qparent_id, tem);
3021 }
3022
3023
3024 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3025 the previous value of that parameter, NEW_VALUE is the new value. */
3026
3027 void
3028 x_set_fullscreen (f, new_value, old_value)
3029 struct frame *f;
3030 Lisp_Object new_value, old_value;
3031 {
3032 if (NILP (new_value))
3033 f->want_fullscreen = FULLSCREEN_NONE;
3034 else if (EQ (new_value, Qfullboth))
3035 f->want_fullscreen = FULLSCREEN_BOTH;
3036 else if (EQ (new_value, Qfullwidth))
3037 f->want_fullscreen = FULLSCREEN_WIDTH;
3038 else if (EQ (new_value, Qfullheight))
3039 f->want_fullscreen = FULLSCREEN_HEIGHT;
3040
3041 if (fullscreen_hook != NULL)
3042 fullscreen_hook (f);
3043 }
3044
3045
3046 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3047 the previous value of that parameter, NEW_VALUE is the new value. */
3048
3049 void
3050 x_set_line_spacing (f, new_value, old_value)
3051 struct frame *f;
3052 Lisp_Object new_value, old_value;
3053 {
3054 if (NILP (new_value))
3055 f->extra_line_spacing = 0;
3056 else if (NATNUMP (new_value))
3057 f->extra_line_spacing = XFASTINT (new_value);
3058 else
3059 signal_error ("Invalid line-spacing", new_value);
3060 if (FRAME_VISIBLE_P (f))
3061 redraw_frame (f);
3062 }
3063
3064
3065 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3066 the previous value of that parameter, NEW_VALUE is the new value. */
3067
3068 void
3069 x_set_screen_gamma (f, new_value, old_value)
3070 struct frame *f;
3071 Lisp_Object new_value, old_value;
3072 {
3073 Lisp_Object bgcolor;
3074
3075 if (NILP (new_value))
3076 f->gamma = 0;
3077 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3078 /* The value 0.4545 is the normal viewing gamma. */
3079 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3080 else
3081 signal_error ("Invalid screen-gamma", new_value);
3082
3083 /* Apply the new gamma value to the frame background. */
3084 bgcolor = Fassq (Qbackground_color, f->param_alist);
3085 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3086 {
3087 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3088 if (NATNUMP (index)
3089 && (XFASTINT (index)
3090 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3091 && rif->frame_parm_handlers[XFASTINT (index)])
3092 (*(rif->frame_parm_handlers[XFASTINT (index)]))
3093 (f, bgcolor, Qnil);
3094 }
3095
3096 Fclear_face_cache (Qnil);
3097 }
3098
3099
3100 void
3101 x_set_font (f, arg, oldval)
3102 struct frame *f;
3103 Lisp_Object arg, oldval;
3104 {
3105 Lisp_Object result;
3106 Lisp_Object fontset_name;
3107 Lisp_Object frame;
3108 int old_fontset = FRAME_FONTSET(f);
3109
3110 #ifdef USE_FONT_BACKEND
3111 if (enable_font_backend)
3112 {
3113 int fontset = -1;
3114 Lisp_Object font_object;
3115
3116 /* ARG is a fontset name, a font name, or a font object.
3117 In the last case, this function never fail. */
3118 if (STRINGP (arg))
3119 {
3120 fontset = fs_query_fontset (arg, 0);
3121 if (fontset < 0)
3122 font_object = font_open_by_name (f, SDATA (arg));
3123 else if (fontset > 0)
3124 {
3125 Lisp_Object ascii_font = fontset_ascii (fontset);
3126
3127 font_object = font_open_by_name (f, SDATA (ascii_font));
3128 }
3129 }
3130 else
3131 font_object = arg;
3132
3133 if (fontset < 0 && ! NILP (font_object))
3134 fontset = new_fontset_from_font (font_object);
3135
3136 if (fontset == 0)
3137 /* Refuse the default fontset. */
3138 result = Qt;
3139 else if (NILP (font_object))
3140 result = Qnil;
3141 else
3142 result = x_new_fontset2 (f, fontset, font_object);
3143 }
3144 else
3145 {
3146 #endif /* USE_FONT_BACKEND */
3147 CHECK_STRING (arg);
3148
3149 fontset_name = Fquery_fontset (arg, Qnil);
3150
3151 BLOCK_INPUT;
3152 result = (STRINGP (fontset_name)
3153 ? x_new_fontset (f, fontset_name)
3154 : x_new_fontset (f, arg));
3155 UNBLOCK_INPUT;
3156 #ifdef USE_FONT_BACKEND
3157 }
3158 #endif
3159
3160 if (EQ (result, Qnil))
3161 error ("Font `%s' is not defined", SDATA (arg));
3162 else if (EQ (result, Qt))
3163 error ("The default fontset can't be used for a frame font");
3164 else if (STRINGP (result))
3165 {
3166 set_default_ascii_font (result);
3167 if (STRINGP (fontset_name))
3168 {
3169 /* Fontset names are built from ASCII font names, so the
3170 names may be equal despite there was a change. */
3171 if (old_fontset == FRAME_FONTSET (f))
3172 return;
3173 }
3174 store_frame_param (f, Qfont, result);
3175
3176 if (!NILP (Fequal (result, oldval)))
3177 return;
3178
3179 /* Recalculate toolbar height. */
3180 f->n_tool_bar_rows = 0;
3181 /* Ensure we redraw it. */
3182 clear_current_matrices (f);
3183
3184 recompute_basic_faces (f);
3185 }
3186 else
3187 abort ();
3188
3189 do_pending_window_change (0);
3190
3191 /* Don't call `face-set-after-frame-default' when faces haven't been
3192 initialized yet. This is the case when called from
3193 Fx_create_frame. In that case, the X widget or window doesn't
3194 exist either, and we can end up in x_report_frame_params with a
3195 null widget which gives a segfault. */
3196 if (FRAME_FACE_CACHE (f))
3197 {
3198 XSETFRAME (frame, f);
3199 call1 (Qface_set_after_frame_default, frame);
3200 }
3201 }
3202
3203
3204 #ifdef USE_FONT_BACKEND
3205 void
3206 x_set_font_backend (f, new_value, old_value)
3207 struct frame *f;
3208 Lisp_Object new_value, old_value;
3209 {
3210 if (! NILP (new_value)
3211 && !CONSP (new_value))
3212 {
3213 char *p0, *p1;
3214
3215 CHECK_STRING (new_value);
3216 p0 = p1 = SDATA (new_value);
3217 new_value = Qnil;
3218 while (*p0)
3219 {
3220 while (*p1 && *p1 != ',') p1++;
3221 if (p0 < p1)
3222 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3223 new_value);
3224 if (*p1)
3225 p1++;
3226 p0 = p1;
3227 }
3228 new_value = Fnreverse (new_value);
3229 }
3230
3231 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3232 return;
3233
3234 if (FRAME_FONT_OBJECT (f))
3235 {
3236 free_all_realized_faces (Qnil);
3237 Fclear_font_cache ();
3238 }
3239
3240 new_value = font_update_drivers (f, new_value);
3241 if (NILP (new_value))
3242 error ("No font backend available");
3243 store_frame_param (f, Qfont_backend, new_value);
3244
3245 if (FRAME_FONT_OBJECT (f))
3246 {
3247 Lisp_Object frame;
3248
3249 XSETFRAME (frame, f);
3250 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3251 ++face_change_count;
3252 ++windows_or_buffers_changed;
3253 }
3254 }
3255 #endif /* USE_FONT_BACKEND */
3256
3257
3258 void
3259 x_set_fringe_width (f, new_value, old_value)
3260 struct frame *f;
3261 Lisp_Object new_value, old_value;
3262 {
3263 compute_fringe_widths (f, 1);
3264 }
3265
3266 void
3267 x_set_border_width (f, arg, oldval)
3268 struct frame *f;
3269 Lisp_Object arg, oldval;
3270 {
3271 CHECK_NUMBER (arg);
3272
3273 if (XINT (arg) == f->border_width)
3274 return;
3275
3276 if (FRAME_X_WINDOW (f) != 0)
3277 error ("Cannot change the border width of a frame");
3278
3279 f->border_width = XINT (arg);
3280 }
3281
3282 void
3283 x_set_internal_border_width (f, arg, oldval)
3284 struct frame *f;
3285 Lisp_Object arg, oldval;
3286 {
3287 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3288
3289 CHECK_NUMBER (arg);
3290 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3291 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3292 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3293
3294 #ifdef USE_X_TOOLKIT
3295 if (FRAME_X_OUTPUT (f)->edit_widget)
3296 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3297 #endif
3298
3299 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3300 return;
3301
3302 if (FRAME_X_WINDOW (f) != 0)
3303 {
3304 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3305 SET_FRAME_GARBAGED (f);
3306 do_pending_window_change (0);
3307 }
3308 else
3309 SET_FRAME_GARBAGED (f);
3310 }
3311
3312 void
3313 x_set_visibility (f, value, oldval)
3314 struct frame *f;
3315 Lisp_Object value, oldval;
3316 {
3317 Lisp_Object frame;
3318 XSETFRAME (frame, f);
3319
3320 if (NILP (value))
3321 Fmake_frame_invisible (frame, Qt);
3322 else if (EQ (value, Qicon))
3323 Ficonify_frame (frame);
3324 else
3325 Fmake_frame_visible (frame);
3326 }
3327
3328 void
3329 x_set_autoraise (f, arg, oldval)
3330 struct frame *f;
3331 Lisp_Object arg, oldval;
3332 {
3333 f->auto_raise = !EQ (Qnil, arg);
3334 }
3335
3336 void
3337 x_set_autolower (f, arg, oldval)
3338 struct frame *f;
3339 Lisp_Object arg, oldval;
3340 {
3341 f->auto_lower = !EQ (Qnil, arg);
3342 }
3343
3344 void
3345 x_set_unsplittable (f, arg, oldval)
3346 struct frame *f;
3347 Lisp_Object arg, oldval;
3348 {
3349 f->no_split = !NILP (arg);
3350 }
3351
3352 void
3353 x_set_vertical_scroll_bars (f, arg, oldval)
3354 struct frame *f;
3355 Lisp_Object arg, oldval;
3356 {
3357 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3358 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3359 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3360 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3361 {
3362 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3363 = (NILP (arg)
3364 ? vertical_scroll_bar_none
3365 : EQ (Qleft, arg)
3366 ? vertical_scroll_bar_left
3367 : EQ (Qright, arg)
3368 ? vertical_scroll_bar_right
3369 : EQ (Qleft, Vdefault_frame_scroll_bars)
3370 ? vertical_scroll_bar_left
3371 : EQ (Qright, Vdefault_frame_scroll_bars)
3372 ? vertical_scroll_bar_right
3373 : vertical_scroll_bar_none);
3374
3375 /* We set this parameter before creating the X window for the
3376 frame, so we can get the geometry right from the start.
3377 However, if the window hasn't been created yet, we shouldn't
3378 call x_set_window_size. */
3379 if (FRAME_X_WINDOW (f))
3380 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3381 do_pending_window_change (0);
3382 }
3383 }
3384
3385 void
3386 x_set_scroll_bar_width (f, arg, oldval)
3387 struct frame *f;
3388 Lisp_Object arg, oldval;
3389 {
3390 int wid = FRAME_COLUMN_WIDTH (f);
3391
3392 if (NILP (arg))
3393 {
3394 x_set_scroll_bar_default_width (f);
3395
3396 if (FRAME_X_WINDOW (f))
3397 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3398 do_pending_window_change (0);
3399 }
3400 else if (INTEGERP (arg) && XINT (arg) > 0
3401 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3402 {
3403 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3404 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3405
3406 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3407 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3408 if (FRAME_X_WINDOW (f))
3409 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3410 do_pending_window_change (0);
3411 }
3412
3413 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3414 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3415 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3416 }
3417
3418
3419
3420 /* Return non-nil if frame F wants a bitmap icon. */
3421
3422 Lisp_Object
3423 x_icon_type (f)
3424 FRAME_PTR f;
3425 {
3426 Lisp_Object tem;
3427
3428 tem = assq_no_quit (Qicon_type, f->param_alist);
3429 if (CONSP (tem))
3430 return XCDR (tem);
3431 else
3432 return Qnil;
3433 }
3434
3435 \f
3436 /* Subroutines of creating an X frame. */
3437
3438 /* Make sure that Vx_resource_name is set to a reasonable value.
3439 Fix it up, or set it to `emacs' if it is too hopeless. */
3440
3441 void
3442 validate_x_resource_name ()
3443 {
3444 int len = 0;
3445 /* Number of valid characters in the resource name. */
3446 int good_count = 0;
3447 /* Number of invalid characters in the resource name. */
3448 int bad_count = 0;
3449 Lisp_Object new;
3450 int i;
3451
3452 if (!STRINGP (Vx_resource_class))
3453 Vx_resource_class = build_string (EMACS_CLASS);
3454
3455 if (STRINGP (Vx_resource_name))
3456 {
3457 unsigned char *p = SDATA (Vx_resource_name);
3458 int i;
3459
3460 len = SBYTES (Vx_resource_name);
3461
3462 /* Only letters, digits, - and _ are valid in resource names.
3463 Count the valid characters and count the invalid ones. */
3464 for (i = 0; i < len; i++)
3465 {
3466 int c = p[i];
3467 if (! ((c >= 'a' && c <= 'z')
3468 || (c >= 'A' && c <= 'Z')
3469 || (c >= '0' && c <= '9')
3470 || c == '-' || c == '_'))
3471 bad_count++;
3472 else
3473 good_count++;
3474 }
3475 }
3476 else
3477 /* Not a string => completely invalid. */
3478 bad_count = 5, good_count = 0;
3479
3480 /* If name is valid already, return. */
3481 if (bad_count == 0)
3482 return;
3483
3484 /* If name is entirely invalid, or nearly so, use `emacs'. */
3485 if (good_count == 0
3486 || (good_count == 1 && bad_count > 0))
3487 {
3488 Vx_resource_name = build_string ("emacs");
3489 return;
3490 }
3491
3492 /* Name is partly valid. Copy it and replace the invalid characters
3493 with underscores. */
3494
3495 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3496
3497 for (i = 0; i < len; i++)
3498 {
3499 int c = SREF (new, i);
3500 if (! ((c >= 'a' && c <= 'z')
3501 || (c >= 'A' && c <= 'Z')
3502 || (c >= '0' && c <= '9')
3503 || c == '-' || c == '_'))
3504 SSET (new, i, '_');
3505 }
3506 }
3507
3508
3509 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3510 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3511
3512
3513 /* Get specified attribute from resource database RDB.
3514 See Fx_get_resource below for other parameters. */
3515
3516 static Lisp_Object
3517 xrdb_get_resource (rdb, attribute, class, component, subclass)
3518 XrmDatabase rdb;
3519 Lisp_Object attribute, class, component, subclass;
3520 {
3521 register char *value;
3522 char *name_key;
3523 char *class_key;
3524
3525 CHECK_STRING (attribute);
3526 CHECK_STRING (class);
3527
3528 if (!NILP (component))
3529 CHECK_STRING (component);
3530 if (!NILP (subclass))
3531 CHECK_STRING (subclass);
3532 if (NILP (component) != NILP (subclass))
3533 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3534
3535 validate_x_resource_name ();
3536
3537 /* Allocate space for the components, the dots which separate them,
3538 and the final '\0'. Make them big enough for the worst case. */
3539 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3540 + (STRINGP (component)
3541 ? SBYTES (component) : 0)
3542 + SBYTES (attribute)
3543 + 3);
3544
3545 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3546 + SBYTES (class)
3547 + (STRINGP (subclass)
3548 ? SBYTES (subclass) : 0)
3549 + 3);
3550
3551 /* Start with emacs.FRAMENAME for the name (the specific one)
3552 and with `Emacs' for the class key (the general one). */
3553 strcpy (name_key, SDATA (Vx_resource_name));
3554 strcpy (class_key, SDATA (Vx_resource_class));
3555
3556 strcat (class_key, ".");
3557 strcat (class_key, SDATA (class));
3558
3559 if (!NILP (component))
3560 {
3561 strcat (class_key, ".");
3562 strcat (class_key, SDATA (subclass));
3563
3564 strcat (name_key, ".");
3565 strcat (name_key, SDATA (component));
3566 }
3567
3568 strcat (name_key, ".");
3569 strcat (name_key, SDATA (attribute));
3570
3571 value = x_get_string_resource (rdb, name_key, class_key);
3572
3573 if (value != (char *) 0)
3574 return build_string (value);
3575 else
3576 return Qnil;
3577 }
3578
3579
3580 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3581 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3582 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3583 class, where INSTANCE is the name under which Emacs was invoked, or
3584 the name specified by the `-name' or `-rn' command-line arguments.
3585
3586 The optional arguments COMPONENT and SUBCLASS add to the key and the
3587 class, respectively. You must specify both of them or neither.
3588 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3589 and the class is `Emacs.CLASS.SUBCLASS'. */)
3590 (attribute, class, component, subclass)
3591 Lisp_Object attribute, class, component, subclass;
3592 {
3593 #ifdef HAVE_X_WINDOWS
3594 check_x ();
3595 #endif
3596
3597 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3598 attribute, class, component, subclass);
3599 }
3600
3601 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3602
3603 Lisp_Object
3604 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3605 Display_Info *dpyinfo;
3606 Lisp_Object attribute, class, component, subclass;
3607 {
3608 return xrdb_get_resource (dpyinfo->xrdb,
3609 attribute, class, component, subclass);
3610 }
3611
3612 /* Used when C code wants a resource value. */
3613
3614 char *
3615 x_get_resource_string (attribute, class)
3616 char *attribute, *class;
3617 {
3618 char *name_key;
3619 char *class_key;
3620 struct frame *sf = SELECTED_FRAME ();
3621
3622 /* Allocate space for the components, the dots which separate them,
3623 and the final '\0'. */
3624 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3625 + strlen (attribute) + 2);
3626 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3627 + strlen (class) + 2);
3628
3629 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3630 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3631
3632 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3633 name_key, class_key);
3634 }
3635
3636
3637 /* Return the value of parameter PARAM.
3638
3639 First search ALIST, then Vdefault_frame_alist, then the X defaults
3640 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3641
3642 Convert the resource to the type specified by desired_type.
3643
3644 If no default is specified, return Qunbound. If you call
3645 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3646 and don't let it get stored in any Lisp-visible variables! */
3647
3648 Lisp_Object
3649 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3650 Display_Info *dpyinfo;
3651 Lisp_Object alist, param;
3652 char *attribute;
3653 char *class;
3654 enum resource_types type;
3655 {
3656 register Lisp_Object tem;
3657
3658 tem = Fassq (param, alist);
3659
3660 if (!NILP (tem))
3661 {
3662 /* If we find this parm in ALIST, clear it out
3663 so that it won't be "left over" at the end. */
3664 #ifndef WINDOWSNT /* w32fns.c has not yet been changed to cope with this. */
3665 Lisp_Object tail;
3666 XSETCAR (tem, Qnil);
3667 /* In case the parameter appears more than once in the alist,
3668 clear it out. */
3669 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3670 if (CONSP (XCAR (tail))
3671 && EQ (XCAR (XCAR (tail)), param))
3672 XSETCAR (XCAR (tail), Qnil);
3673 #endif
3674 }
3675 else
3676 tem = Fassq (param, Vdefault_frame_alist);
3677
3678 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3679 look in the X resources. */
3680 if (EQ (tem, Qnil))
3681 {
3682 if (attribute)
3683 {
3684 tem = display_x_get_resource (dpyinfo,
3685 build_string (attribute),
3686 build_string (class),
3687 Qnil, Qnil);
3688
3689 if (NILP (tem))
3690 return Qunbound;
3691
3692 switch (type)
3693 {
3694 case RES_TYPE_NUMBER:
3695 return make_number (atoi (SDATA (tem)));
3696
3697 case RES_TYPE_FLOAT:
3698 return make_float (atof (SDATA (tem)));
3699
3700 case RES_TYPE_BOOLEAN:
3701 tem = Fdowncase (tem);
3702 if (!strcmp (SDATA (tem), "on")
3703 || !strcmp (SDATA (tem), "true"))
3704 return Qt;
3705 else
3706 return Qnil;
3707
3708 case RES_TYPE_STRING:
3709 return tem;
3710
3711 case RES_TYPE_SYMBOL:
3712 /* As a special case, we map the values `true' and `on'
3713 to Qt, and `false' and `off' to Qnil. */
3714 {
3715 Lisp_Object lower;
3716 lower = Fdowncase (tem);
3717 if (!strcmp (SDATA (lower), "on")
3718 || !strcmp (SDATA (lower), "true"))
3719 return Qt;
3720 else if (!strcmp (SDATA (lower), "off")
3721 || !strcmp (SDATA (lower), "false"))
3722 return Qnil;
3723 else
3724 return Fintern (tem, Qnil);
3725 }
3726
3727 default:
3728 abort ();
3729 }
3730 }
3731 else
3732 return Qunbound;
3733 }
3734 return Fcdr (tem);
3735 }
3736
3737 Lisp_Object
3738 x_frame_get_arg (f, alist, param, attribute, class, type)
3739 struct frame *f;
3740 Lisp_Object alist, param;
3741 char *attribute;
3742 char *class;
3743 enum resource_types type;
3744 {
3745 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3746 alist, param, attribute, class, type);
3747 }
3748
3749 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3750
3751 Lisp_Object
3752 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3753 struct frame *f;
3754 Lisp_Object alist, param;
3755 char *attribute;
3756 char *class;
3757 enum resource_types type;
3758 {
3759 Lisp_Object value;
3760
3761 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3762 attribute, class, type);
3763 if (! NILP (value) && ! EQ (value, Qunbound))
3764 store_frame_param (f, param, value);
3765
3766 return value;
3767 }
3768
3769
3770 /* Record in frame F the specified or default value according to ALIST
3771 of the parameter named PROP (a Lisp symbol).
3772 If no value is specified for PROP, look for an X default for XPROP
3773 on the frame named NAME.
3774 If that is not found either, use the value DEFLT. */
3775
3776 Lisp_Object
3777 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3778 struct frame *f;
3779 Lisp_Object alist;
3780 Lisp_Object prop;
3781 Lisp_Object deflt;
3782 char *xprop;
3783 char *xclass;
3784 enum resource_types type;
3785 {
3786 Lisp_Object tem;
3787
3788 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3789 if (EQ (tem, Qunbound))
3790 tem = deflt;
3791 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3792 return tem;
3793 }
3794
3795
3796
3797 \f
3798 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3799 doc: /* Parse an X-style geometry string STRING.
3800 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3801 The properties returned may include `top', `left', `height', and `width'.
3802 The value of `left' or `top' may be an integer,
3803 or a list (+ N) meaning N pixels relative to top/left corner,
3804 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3805 (string)
3806 Lisp_Object string;
3807 {
3808 int geometry, x, y;
3809 unsigned int width, height;
3810 Lisp_Object result;
3811
3812 CHECK_STRING (string);
3813
3814 geometry = XParseGeometry ((char *) SDATA (string),
3815 &x, &y, &width, &height);
3816
3817 #if 0
3818 if (!!(geometry & XValue) != !!(geometry & YValue))
3819 error ("Must specify both x and y position, or neither");
3820 #endif
3821
3822 result = Qnil;
3823 if (geometry & XValue)
3824 {
3825 Lisp_Object element;
3826
3827 if (x >= 0 && (geometry & XNegative))
3828 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3829 else if (x < 0 && ! (geometry & XNegative))
3830 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3831 else
3832 element = Fcons (Qleft, make_number (x));
3833 result = Fcons (element, result);
3834 }
3835
3836 if (geometry & YValue)
3837 {
3838 Lisp_Object element;
3839
3840 if (y >= 0 && (geometry & YNegative))
3841 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3842 else if (y < 0 && ! (geometry & YNegative))
3843 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3844 else
3845 element = Fcons (Qtop, make_number (y));
3846 result = Fcons (element, result);
3847 }
3848
3849 if (geometry & WidthValue)
3850 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3851 if (geometry & HeightValue)
3852 result = Fcons (Fcons (Qheight, make_number (height)), result);
3853
3854 return result;
3855 }
3856
3857 /* Calculate the desired size and position of frame F.
3858 Return the flags saying which aspects were specified.
3859
3860 Also set the win_gravity and size_hint_flags of F.
3861
3862 Adjust height for toolbar if TOOLBAR_P is 1.
3863
3864 This function does not make the coordinates positive. */
3865
3866 #define DEFAULT_ROWS 40
3867 #define DEFAULT_COLS 80
3868
3869 int
3870 x_figure_window_size (f, parms, toolbar_p)
3871 struct frame *f;
3872 Lisp_Object parms;
3873 int toolbar_p;
3874 {
3875 register Lisp_Object tem0, tem1, tem2;
3876 long window_prompting = 0;
3877 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3878
3879 /* Default values if we fall through.
3880 Actually, if that happens we should get
3881 window manager prompting. */
3882 SET_FRAME_COLS (f, DEFAULT_COLS);
3883 FRAME_LINES (f) = DEFAULT_ROWS;
3884 /* Window managers expect that if program-specified
3885 positions are not (0,0), they're intentional, not defaults. */
3886 f->top_pos = 0;
3887 f->left_pos = 0;
3888
3889 /* Ensure that old new_text_cols and new_text_lines will not override the
3890 values set here. */
3891 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3892 f->new_text_cols = f->new_text_lines = 0;
3893
3894 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3895 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3896 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3897 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3898 {
3899 if (!EQ (tem0, Qunbound))
3900 {
3901 CHECK_NUMBER (tem0);
3902 FRAME_LINES (f) = XINT (tem0);
3903 }
3904 if (!EQ (tem1, Qunbound))
3905 {
3906 CHECK_NUMBER (tem1);
3907 SET_FRAME_COLS (f, XINT (tem1));
3908 }
3909 if (!NILP (tem2) && !EQ (tem2, Qunbound))
3910 window_prompting |= USSize;
3911 else
3912 window_prompting |= PSize;
3913 }
3914
3915 f->scroll_bar_actual_width
3916 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
3917
3918 /* This used to be done _before_ calling x_figure_window_size, but
3919 since the height is reset here, this was really a no-op. I
3920 assume that moving it here does what Gerd intended (although he
3921 no longer can remember what that was... ++KFS, 2003-03-25. */
3922
3923 /* Add the tool-bar height to the initial frame height so that the
3924 user gets a text display area of the size he specified with -g or
3925 via .Xdefaults. Later changes of the tool-bar height don't
3926 change the frame size. This is done so that users can create
3927 tall Emacs frames without having to guess how tall the tool-bar
3928 will get. */
3929 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
3930 {
3931 int margin, relief, bar_height;
3932
3933 relief = (tool_bar_button_relief >= 0
3934 ? tool_bar_button_relief
3935 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
3936
3937 if (INTEGERP (Vtool_bar_button_margin)
3938 && XINT (Vtool_bar_button_margin) > 0)
3939 margin = XFASTINT (Vtool_bar_button_margin);
3940 else if (CONSP (Vtool_bar_button_margin)
3941 && INTEGERP (XCDR (Vtool_bar_button_margin))
3942 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
3943 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
3944 else
3945 margin = 0;
3946
3947 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
3948 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
3949 }
3950
3951 compute_fringe_widths (f, 0);
3952
3953 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
3954 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
3955
3956 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
3957 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
3958 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
3959 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3960 {
3961 if (EQ (tem0, Qminus))
3962 {
3963 f->top_pos = 0;
3964 window_prompting |= YNegative;
3965 }
3966 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
3967 && CONSP (XCDR (tem0))
3968 && INTEGERP (XCAR (XCDR (tem0))))
3969 {
3970 f->top_pos = - XINT (XCAR (XCDR (tem0)));
3971 window_prompting |= YNegative;
3972 }
3973 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
3974 && CONSP (XCDR (tem0))
3975 && INTEGERP (XCAR (XCDR (tem0))))
3976 {
3977 f->top_pos = XINT (XCAR (XCDR (tem0)));
3978 }
3979 else if (EQ (tem0, Qunbound))
3980 f->top_pos = 0;
3981 else
3982 {
3983 CHECK_NUMBER (tem0);
3984 f->top_pos = XINT (tem0);
3985 if (f->top_pos < 0)
3986 window_prompting |= YNegative;
3987 }
3988
3989 if (EQ (tem1, Qminus))
3990 {
3991 f->left_pos = 0;
3992 window_prompting |= XNegative;
3993 }
3994 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
3995 && CONSP (XCDR (tem1))
3996 && INTEGERP (XCAR (XCDR (tem1))))
3997 {
3998 f->left_pos = - XINT (XCAR (XCDR (tem1)));
3999 window_prompting |= XNegative;
4000 }
4001 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4002 && CONSP (XCDR (tem1))
4003 && INTEGERP (XCAR (XCDR (tem1))))
4004 {
4005 f->left_pos = XINT (XCAR (XCDR (tem1)));
4006 }
4007 else if (EQ (tem1, Qunbound))
4008 f->left_pos = 0;
4009 else
4010 {
4011 CHECK_NUMBER (tem1);
4012 f->left_pos = XINT (tem1);
4013 if (f->left_pos < 0)
4014 window_prompting |= XNegative;
4015 }
4016
4017 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4018 window_prompting |= USPosition;
4019 else
4020 window_prompting |= PPosition;
4021 }
4022
4023 if (f->want_fullscreen != FULLSCREEN_NONE)
4024 {
4025 int left, top;
4026 int width, height;
4027
4028 /* It takes both for some WM:s to place it where we want */
4029 window_prompting = USPosition | PPosition;
4030 x_fullscreen_adjust (f, &width, &height, &top, &left);
4031 FRAME_COLS (f) = width;
4032 FRAME_LINES (f) = height;
4033 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4034 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4035 f->left_pos = left;
4036 f->top_pos = top;
4037 }
4038
4039 if (window_prompting & XNegative)
4040 {
4041 if (window_prompting & YNegative)
4042 f->win_gravity = SouthEastGravity;
4043 else
4044 f->win_gravity = NorthEastGravity;
4045 }
4046 else
4047 {
4048 if (window_prompting & YNegative)
4049 f->win_gravity = SouthWestGravity;
4050 else
4051 f->win_gravity = NorthWestGravity;
4052 }
4053
4054 f->size_hint_flags = window_prompting;
4055
4056 return window_prompting;
4057 }
4058
4059
4060
4061 #endif /* HAVE_WINDOW_SYSTEM */
4062
4063
4064 \f
4065 /***********************************************************************
4066 Initialization
4067 ***********************************************************************/
4068
4069 void
4070 syms_of_frame ()
4071 {
4072 Qframep = intern ("framep");
4073 staticpro (&Qframep);
4074 Qframe_live_p = intern ("frame-live-p");
4075 staticpro (&Qframe_live_p);
4076 Qheight = intern ("height");
4077 staticpro (&Qheight);
4078 Qicon = intern ("icon");
4079 staticpro (&Qicon);
4080 Qminibuffer = intern ("minibuffer");
4081 staticpro (&Qminibuffer);
4082 Qmodeline = intern ("modeline");
4083 staticpro (&Qmodeline);
4084 Qonly = intern ("only");
4085 staticpro (&Qonly);
4086 Qwidth = intern ("width");
4087 staticpro (&Qwidth);
4088 Qgeometry = intern ("geometry");
4089 staticpro (&Qgeometry);
4090 Qicon_left = intern ("icon-left");
4091 staticpro (&Qicon_left);
4092 Qicon_top = intern ("icon-top");
4093 staticpro (&Qicon_top);
4094 Qleft = intern ("left");
4095 staticpro (&Qleft);
4096 Qright = intern ("right");
4097 staticpro (&Qright);
4098 Quser_position = intern ("user-position");
4099 staticpro (&Quser_position);
4100 Quser_size = intern ("user-size");
4101 staticpro (&Quser_size);
4102 Qwindow_id = intern ("window-id");
4103 staticpro (&Qwindow_id);
4104 #ifdef HAVE_X_WINDOWS
4105 Qouter_window_id = intern ("outer-window-id");
4106 staticpro (&Qouter_window_id);
4107 #endif
4108 Qparent_id = intern ("parent-id");
4109 staticpro (&Qparent_id);
4110 Qx = intern ("x");
4111 staticpro (&Qx);
4112 Qw32 = intern ("w32");
4113 staticpro (&Qw32);
4114 Qpc = intern ("pc");
4115 staticpro (&Qpc);
4116 Qmac = intern ("mac");
4117 staticpro (&Qmac);
4118 Qvisible = intern ("visible");
4119 staticpro (&Qvisible);
4120 Qbuffer_predicate = intern ("buffer-predicate");
4121 staticpro (&Qbuffer_predicate);
4122 Qbuffer_list = intern ("buffer-list");
4123 staticpro (&Qbuffer_list);
4124 Qdisplay_type = intern ("display-type");
4125 staticpro (&Qdisplay_type);
4126 Qbackground_mode = intern ("background-mode");
4127 staticpro (&Qbackground_mode);
4128 Qtty_color_mode = intern ("tty-color-mode");
4129 staticpro (&Qtty_color_mode);
4130
4131 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4132 staticpro (&Qface_set_after_frame_default);
4133
4134 Qinhibit_face_set_after_frame_default
4135 = intern ("inhibit-face-set-after-frame-default");
4136 staticpro (&Qinhibit_face_set_after_frame_default);
4137
4138 Qfullwidth = intern ("fullwidth");
4139 staticpro (&Qfullwidth);
4140 Qfullheight = intern ("fullheight");
4141 staticpro (&Qfullheight);
4142 Qfullboth = intern ("fullboth");
4143 staticpro (&Qfullboth);
4144 Qx_resource_name = intern ("x-resource-name");
4145 staticpro (&Qx_resource_name);
4146
4147 Qx_frame_parameter = intern ("x-frame-parameter");
4148 staticpro (&Qx_frame_parameter);
4149
4150 {
4151 int i;
4152
4153 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4154 {
4155 Lisp_Object v = intern (frame_parms[i].name);
4156 if (frame_parms[i].variable)
4157 {
4158 *frame_parms[i].variable = v;
4159 staticpro (frame_parms[i].variable);
4160 }
4161 Fput (v, Qx_frame_parameter, make_number (i));
4162 }
4163 }
4164
4165 #ifdef HAVE_WINDOW_SYSTEM
4166 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4167 doc: /* The name Emacs uses to look up X resources.
4168 `x-get-resource' uses this as the first component of the instance name
4169 when requesting resource values.
4170 Emacs initially sets `x-resource-name' to the name under which Emacs
4171 was invoked, or to the value specified with the `-name' or `-rn'
4172 switches, if present.
4173
4174 It may be useful to bind this variable locally around a call
4175 to `x-get-resource'. See also the variable `x-resource-class'. */);
4176 Vx_resource_name = Qnil;
4177
4178 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4179 doc: /* The class Emacs uses to look up X resources.
4180 `x-get-resource' uses this as the first component of the instance class
4181 when requesting resource values.
4182
4183 Emacs initially sets `x-resource-class' to "Emacs".
4184
4185 Setting this variable permanently is not a reasonable thing to do,
4186 but binding this variable locally around a call to `x-get-resource'
4187 is a reasonable practice. See also the variable `x-resource-name'. */);
4188 Vx_resource_class = build_string (EMACS_CLASS);
4189 #endif
4190
4191 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4192 doc: /* Alist of default values for frame creation.
4193 These may be set in your init file, like this:
4194 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4195 These override values given in window system configuration data,
4196 including X Windows' defaults database.
4197 For values specific to the first Emacs frame, see `initial-frame-alist'.
4198 For values specific to the separate minibuffer frame, see
4199 `minibuffer-frame-alist'.
4200 The `menu-bar-lines' element of the list controls whether new frames
4201 have menu bars; `menu-bar-mode' works by altering this element.
4202 Setting this variable does not affect existing frames, only new ones. */);
4203 Vdefault_frame_alist = Qnil;
4204
4205 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4206 doc: /* Default position of scroll bars on this window-system. */);
4207 #ifdef HAVE_WINDOW_SYSTEM
4208 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4209 /* MS-Windows has scroll bars on the right by default. */
4210 Vdefault_frame_scroll_bars = Qright;
4211 #else
4212 Vdefault_frame_scroll_bars = Qleft;
4213 #endif
4214 #else
4215 Vdefault_frame_scroll_bars = Qnil;
4216 #endif
4217
4218 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4219 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4220
4221 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4222 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
4223 Vemacs_iconified = Qnil;
4224
4225 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4226 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4227 `mouse-position' calls this function, passing its usual return value as
4228 argument, and returns whatever this function returns.
4229 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4230 which need to do mouse handling at the Lisp level. */);
4231 Vmouse_position_function = Qnil;
4232
4233 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4234 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4235 If the value is an integer, highlighting is only shown after moving the
4236 mouse, while keyboard input turns off the highlight even when the mouse
4237 is over the clickable text. However, the mouse shape still indicates
4238 when the mouse is over clickable text. */);
4239 Vmouse_highlight = Qt;
4240
4241 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4242 doc: /* Functions to be run before deleting a frame.
4243 The functions are run with one arg, the frame to be deleted.
4244 See `delete-frame'. */);
4245 Vdelete_frame_functions = Qnil;
4246
4247 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4248 doc: /* Minibufferless frames use this frame's minibuffer.
4249
4250 Emacs cannot create minibufferless frames unless this is set to an
4251 appropriate surrogate.
4252
4253 Emacs consults this variable only when creating minibufferless
4254 frames; once the frame is created, it sticks with its assigned
4255 minibuffer, no matter what this variable is set to. This means that
4256 this variable doesn't necessarily say anything meaningful about the
4257 current set of frames, or where the minibuffer is currently being
4258 displayed.
4259
4260 This variable is local to the current terminal and cannot be buffer-local. */);
4261
4262 staticpro (&Vframe_list);
4263
4264 defsubr (&Sactive_minibuffer_window);
4265 defsubr (&Sframep);
4266 defsubr (&Sframe_live_p);
4267 defsubr (&Smake_terminal_frame);
4268 defsubr (&Shandle_switch_frame);
4269 defsubr (&Sselect_frame);
4270 defsubr (&Sselected_frame);
4271 defsubr (&Swindow_frame);
4272 defsubr (&Sframe_root_window);
4273 defsubr (&Sframe_first_window);
4274 defsubr (&Sframe_selected_window);
4275 defsubr (&Sset_frame_selected_window);
4276 defsubr (&Sframe_list);
4277 defsubr (&Snext_frame);
4278 defsubr (&Sprevious_frame);
4279 defsubr (&Sdelete_frame);
4280 defsubr (&Smouse_position);
4281 defsubr (&Smouse_pixel_position);
4282 defsubr (&Sset_mouse_position);
4283 defsubr (&Sset_mouse_pixel_position);
4284 #if 0
4285 defsubr (&Sframe_configuration);
4286 defsubr (&Srestore_frame_configuration);
4287 #endif
4288 defsubr (&Smake_frame_visible);
4289 defsubr (&Smake_frame_invisible);
4290 defsubr (&Siconify_frame);
4291 defsubr (&Sframe_visible_p);
4292 defsubr (&Svisible_frame_list);
4293 defsubr (&Sraise_frame);
4294 defsubr (&Slower_frame);
4295 defsubr (&Sredirect_frame_focus);
4296 defsubr (&Sframe_focus);
4297 defsubr (&Sframe_parameters);
4298 defsubr (&Sframe_parameter);
4299 defsubr (&Smodify_frame_parameters);
4300 defsubr (&Sframe_char_height);
4301 defsubr (&Sframe_char_width);
4302 defsubr (&Sframe_pixel_height);
4303 defsubr (&Sframe_pixel_width);
4304 defsubr (&Sset_frame_height);
4305 defsubr (&Sset_frame_width);
4306 defsubr (&Sset_frame_size);
4307 defsubr (&Sset_frame_position);
4308
4309 #ifdef HAVE_WINDOW_SYSTEM
4310 defsubr (&Sx_get_resource);
4311 defsubr (&Sx_parse_geometry);
4312 #endif
4313
4314 }
4315
4316 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4317 (do not change this comment) */