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