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