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