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