* frame.c (make_initial_frame): Use set_menu_bar_lines (Bug#6660).
[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 /* Error handler for `delete-frame-functions'. */
1284 static Lisp_Object
1285 delete_frame_handler (Lisp_Object arg)
1286 {
1287 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1288 return Qnil;
1289 }
1290
1291 extern Lisp_Object Qrun_hook_with_args;
1292
1293 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1294 unconditionally. x_connection_closed and delete_terminal use
1295 this. Any other value of FORCE implements the semantics
1296 described for Fdelete_frame. */
1297 Lisp_Object
1298 delete_frame (Lisp_Object frame, Lisp_Object force)
1299 /* If we use `register' here, gcc-4.0.2 on amd64 using
1300 -DUSE_LISP_UNION_TYPE complains further down that we're getting the
1301 address of `force'. Go figure. */
1302
1303 {
1304 struct frame *f;
1305 struct frame *sf = SELECTED_FRAME ();
1306 struct kboard *kb;
1307
1308 int minibuffer_selected, tooltip_frame;
1309
1310 if (EQ (frame, Qnil))
1311 {
1312 f = sf;
1313 XSETFRAME (frame, f);
1314 }
1315 else
1316 {
1317 CHECK_FRAME (frame);
1318 f = XFRAME (frame);
1319 }
1320
1321 if (! FRAME_LIVE_P (f))
1322 return Qnil;
1323
1324 if (NILP (force) && !other_visible_frames (f))
1325 error ("Attempt to delete the sole visible or iconified frame");
1326
1327 /* x_connection_closed must have set FORCE to `noelisp' in order
1328 to delete the last frame, if it is gone. */
1329 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1330 error ("Attempt to delete the only frame");
1331
1332 /* Does this frame have a minibuffer, and is it the surrogate
1333 minibuffer for any other frame? */
1334 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1335 {
1336 Lisp_Object frames;
1337
1338 for (frames = Vframe_list;
1339 CONSP (frames);
1340 frames = XCDR (frames))
1341 {
1342 Lisp_Object this;
1343 this = XCAR (frames);
1344
1345 if (! EQ (this, frame)
1346 && EQ (frame,
1347 WINDOW_FRAME (XWINDOW
1348 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1349 {
1350 /* If we MUST delete this frame, delete the other first.
1351 But do this only if FORCE equals `noelisp'. */
1352 if (EQ (force, Qnoelisp))
1353 delete_frame (this, Qnoelisp);
1354 else
1355 error ("Attempt to delete a surrogate minibuffer frame");
1356 }
1357 }
1358 }
1359
1360 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1361
1362 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1363 frame is a tooltip. FORCE is set to `noelisp' when handling
1364 a disconnect from the terminal, so we don't dare call Lisp
1365 code. */
1366 if (NILP (Vrun_hooks) || tooltip_frame)
1367 ;
1368 else if (EQ (force, Qnoelisp))
1369 pending_funcalls
1370 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1371 pending_funcalls);
1372 else
1373 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1374
1375 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1376 if (! FRAME_LIVE_P (f))
1377 return Qnil;
1378
1379 /* At this point, we are committed to deleting the frame.
1380 There is no more chance for errors to prevent it. */
1381
1382 minibuffer_selected = EQ (minibuf_window, selected_window);
1383
1384 /* Don't let the frame remain selected. */
1385 if (f == sf)
1386 {
1387 Lisp_Object tail, frame1;
1388
1389 /* Look for another visible frame on the same terminal. */
1390 frame1 = next_frame (frame, Qvisible);
1391
1392 /* If there is none, find *some* other frame. */
1393 if (NILP (frame1) || EQ (frame1, frame))
1394 {
1395 FOR_EACH_FRAME (tail, frame1)
1396 {
1397 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1398 break;
1399 }
1400 }
1401 #ifdef NS_IMPL_COCOA
1402 else
1403 /* Under NS, there is no system mechanism for choosing a new
1404 window to get focus -- it is left to application code.
1405 So the portion of THIS application interfacing with NS
1406 needs to know about it. We call Fraise_frame, but the
1407 purpose is really to transfer focus. */
1408 Fraise_frame (frame1);
1409 #endif
1410
1411 do_switch_frame (frame1, 0, 1, Qnil);
1412 sf = SELECTED_FRAME ();
1413 }
1414
1415 /* Don't allow minibuf_window to remain on a deleted frame. */
1416 if (EQ (f->minibuffer_window, minibuf_window))
1417 {
1418 Fset_window_buffer (sf->minibuffer_window,
1419 XWINDOW (minibuf_window)->buffer, Qnil);
1420 minibuf_window = sf->minibuffer_window;
1421
1422 /* If the dying minibuffer window was selected,
1423 select the new one. */
1424 if (minibuffer_selected)
1425 Fselect_window (minibuf_window, Qnil);
1426 }
1427
1428 /* Don't let echo_area_window to remain on a deleted frame. */
1429 if (EQ (f->minibuffer_window, echo_area_window))
1430 echo_area_window = sf->minibuffer_window;
1431
1432 /* Clear any X selections for this frame. */
1433 #ifdef HAVE_X_WINDOWS
1434 if (FRAME_X_P (f))
1435 x_clear_frame_selections (f);
1436 #endif
1437
1438 /* Free glyphs.
1439 This function must be called before the window tree of the
1440 frame is deleted because windows contain dynamically allocated
1441 memory. */
1442 free_glyphs (f);
1443
1444 #ifdef HAVE_WINDOW_SYSTEM
1445 /* Give chance to each font driver to free a frame specific data. */
1446 font_update_drivers (f, Qnil);
1447 #endif
1448
1449 /* Mark all the windows that used to be on FRAME as deleted, and then
1450 remove the reference to them. */
1451 delete_all_subwindows (XWINDOW (f->root_window));
1452 f->root_window = Qnil;
1453
1454 Vframe_list = Fdelq (frame, Vframe_list);
1455 FRAME_SET_VISIBLE (f, 0);
1456
1457 /* Allow the vector of menu bar contents to be freed in the next
1458 garbage collection. The frame object itself may not be garbage
1459 collected until much later, because recent_keys and other data
1460 structures can still refer to it. */
1461 f->menu_bar_vector = Qnil;
1462
1463 free_font_driver_list (f);
1464 xfree (f->namebuf);
1465 xfree (f->decode_mode_spec_buffer);
1466 xfree (FRAME_INSERT_COST (f));
1467 xfree (FRAME_DELETEN_COST (f));
1468 xfree (FRAME_INSERTN_COST (f));
1469 xfree (FRAME_DELETE_COST (f));
1470 xfree (FRAME_MESSAGE_BUF (f));
1471
1472 /* Since some events are handled at the interrupt level, we may get
1473 an event for f at any time; if we zero out the frame's terminal
1474 now, then we may trip up the event-handling code. Instead, we'll
1475 promise that the terminal of the frame must be valid until we
1476 have called the window-system-dependent frame destruction
1477 routine. */
1478
1479 if (FRAME_TERMINAL (f)->delete_frame_hook)
1480 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1481
1482 {
1483 struct terminal *terminal = FRAME_TERMINAL (f);
1484 f->output_data.nothing = 0;
1485 f->terminal = 0; /* Now the frame is dead. */
1486
1487 /* If needed, delete the terminal that this frame was on.
1488 (This must be done after the frame is killed.) */
1489 terminal->reference_count--;
1490 if (terminal->reference_count == 0)
1491 {
1492 Lisp_Object tmp;
1493 XSETTERMINAL (tmp, terminal);
1494
1495 kb = NULL;
1496 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1497 }
1498 else
1499 kb = terminal->kboard;
1500 }
1501
1502 /* If we've deleted the last_nonminibuf_frame, then try to find
1503 another one. */
1504 if (f == last_nonminibuf_frame)
1505 {
1506 Lisp_Object frames;
1507
1508 last_nonminibuf_frame = 0;
1509
1510 for (frames = Vframe_list;
1511 CONSP (frames);
1512 frames = XCDR (frames))
1513 {
1514 f = XFRAME (XCAR (frames));
1515 if (!FRAME_MINIBUF_ONLY_P (f))
1516 {
1517 last_nonminibuf_frame = f;
1518 break;
1519 }
1520 }
1521 }
1522
1523 /* If there's no other frame on the same kboard, get out of
1524 single-kboard state if we're in it for this kboard. */
1525 if (kb != NULL)
1526 {
1527 Lisp_Object frames;
1528 /* Some frame we found on the same kboard, or nil if there are none. */
1529 Lisp_Object frame_on_same_kboard;
1530
1531 frame_on_same_kboard = Qnil;
1532
1533 for (frames = Vframe_list;
1534 CONSP (frames);
1535 frames = XCDR (frames))
1536 {
1537 Lisp_Object this;
1538 struct frame *f1;
1539
1540 this = XCAR (frames);
1541 if (!FRAMEP (this))
1542 abort ();
1543 f1 = XFRAME (this);
1544
1545 if (kb == FRAME_KBOARD (f1))
1546 frame_on_same_kboard = this;
1547 }
1548
1549 if (NILP (frame_on_same_kboard))
1550 not_single_kboard_state (kb);
1551 }
1552
1553
1554 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1555 find another one. Prefer minibuffer-only frames, but also notice
1556 frames with other windows. */
1557 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1558 {
1559 Lisp_Object frames;
1560
1561 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1562 Lisp_Object frame_with_minibuf;
1563 /* Some frame we found on the same kboard, or nil if there are none. */
1564 Lisp_Object frame_on_same_kboard;
1565
1566 frame_on_same_kboard = Qnil;
1567 frame_with_minibuf = Qnil;
1568
1569 for (frames = Vframe_list;
1570 CONSP (frames);
1571 frames = XCDR (frames))
1572 {
1573 Lisp_Object this;
1574 struct frame *f1;
1575
1576 this = XCAR (frames);
1577 if (!FRAMEP (this))
1578 abort ();
1579 f1 = XFRAME (this);
1580
1581 /* Consider only frames on the same kboard
1582 and only those with minibuffers. */
1583 if (kb == FRAME_KBOARD (f1)
1584 && FRAME_HAS_MINIBUF_P (f1))
1585 {
1586 frame_with_minibuf = this;
1587 if (FRAME_MINIBUF_ONLY_P (f1))
1588 break;
1589 }
1590
1591 if (kb == FRAME_KBOARD (f1))
1592 frame_on_same_kboard = this;
1593 }
1594
1595 if (!NILP (frame_on_same_kboard))
1596 {
1597 /* We know that there must be some frame with a minibuffer out
1598 there. If this were not true, all of the frames present
1599 would have to be minibufferless, which implies that at some
1600 point their minibuffer frames must have been deleted, but
1601 that is prohibited at the top; you can't delete surrogate
1602 minibuffer frames. */
1603 if (NILP (frame_with_minibuf))
1604 abort ();
1605
1606 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1607 }
1608 else
1609 /* No frames left on this kboard--say no minibuffer either. */
1610 kb->Vdefault_minibuffer_frame = Qnil;
1611 }
1612
1613 /* Cause frame titles to update--necessary if we now have just one frame. */
1614 if (!tooltip_frame)
1615 update_mode_lines = 1;
1616
1617 return Qnil;
1618 }
1619
1620 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1621 doc: /* Delete FRAME, permanently eliminating it from use.
1622 FRAME defaults to the selected frame.
1623
1624 A frame may not be deleted if its minibuffer is used by other frames.
1625 Normally, you may not delete a frame if all other frames are invisible,
1626 but if the second optional argument FORCE is non-nil, you may do so.
1627
1628 This function runs `delete-frame-functions' before actually
1629 deleting the frame, unless the frame is a tooltip.
1630 The functions are run with one argument, the frame to be deleted. */)
1631 (Lisp_Object frame, Lisp_Object force)
1632 {
1633 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1634 }
1635
1636 \f
1637 /* Return mouse position in character cell units. */
1638
1639 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1640 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1641 The position is given in character cells, where (0, 0) is the
1642 upper-left corner of the frame, X is the horizontal offset, and Y is
1643 the vertical offset.
1644 If Emacs is running on a mouseless terminal or hasn't been programmed
1645 to read the mouse position, it returns the selected frame for FRAME
1646 and nil for X and Y.
1647 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1648 passing the normal return value to that function as an argument,
1649 and returns whatever that function returns. */)
1650 (void)
1651 {
1652 FRAME_PTR f;
1653 Lisp_Object lispy_dummy;
1654 enum scroll_bar_part party_dummy;
1655 Lisp_Object x, y, retval;
1656 int col, row;
1657 unsigned long long_dummy;
1658 struct gcpro gcpro1;
1659
1660 f = SELECTED_FRAME ();
1661 x = y = Qnil;
1662
1663 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1664 /* It's okay for the hook to refrain from storing anything. */
1665 if (FRAME_TERMINAL (f)->mouse_position_hook)
1666 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1667 &lispy_dummy, &party_dummy,
1668 &x, &y,
1669 &long_dummy);
1670 if (! NILP (x))
1671 {
1672 col = XINT (x);
1673 row = XINT (y);
1674 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1675 XSETINT (x, col);
1676 XSETINT (y, row);
1677 }
1678 #endif
1679 XSETFRAME (lispy_dummy, f);
1680 retval = Fcons (lispy_dummy, Fcons (x, y));
1681 GCPRO1 (retval);
1682 if (!NILP (Vmouse_position_function))
1683 retval = call1 (Vmouse_position_function, retval);
1684 RETURN_UNGCPRO (retval);
1685 }
1686
1687 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1688 Smouse_pixel_position, 0, 0, 0,
1689 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1690 The position is given in pixel units, where (0, 0) is the
1691 upper-left corner of the frame, X is the horizontal offset, and Y is
1692 the vertical offset.
1693 If Emacs is running on a mouseless terminal or hasn't been programmed
1694 to read the mouse position, it returns the selected frame for FRAME
1695 and nil for X and Y. */)
1696 (void)
1697 {
1698 FRAME_PTR f;
1699 Lisp_Object lispy_dummy;
1700 enum scroll_bar_part party_dummy;
1701 Lisp_Object x, y;
1702 unsigned long long_dummy;
1703
1704 f = SELECTED_FRAME ();
1705 x = y = Qnil;
1706
1707 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1708 /* It's okay for the hook to refrain from storing anything. */
1709 if (FRAME_TERMINAL (f)->mouse_position_hook)
1710 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1711 &lispy_dummy, &party_dummy,
1712 &x, &y,
1713 &long_dummy);
1714 #endif
1715 XSETFRAME (lispy_dummy, f);
1716 return Fcons (lispy_dummy, Fcons (x, y));
1717 }
1718
1719 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1720 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1721 Coordinates are relative to the frame, not a window,
1722 so the coordinates of the top left character in the frame
1723 may be nonzero due to left-hand scroll bars or the menu bar.
1724
1725 The position is given in character cells, where (0, 0) is the
1726 upper-left corner of the frame, X is the horizontal offset, and Y is
1727 the vertical offset.
1728
1729 This function is a no-op for an X frame that is not visible.
1730 If you have just created a frame, you must wait for it to become visible
1731 before calling this function on it, like this.
1732 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1733 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1734 {
1735 CHECK_LIVE_FRAME (frame);
1736 CHECK_NUMBER (x);
1737 CHECK_NUMBER (y);
1738
1739 /* I think this should be done with a hook. */
1740 #ifdef HAVE_WINDOW_SYSTEM
1741 if (FRAME_WINDOW_P (XFRAME (frame)))
1742 /* Warping the mouse will cause enternotify and focus events. */
1743 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1744 #else
1745 #if defined (MSDOS) && defined (HAVE_MOUSE)
1746 if (FRAME_MSDOS_P (XFRAME (frame)))
1747 {
1748 Fselect_frame (frame, Qnil);
1749 mouse_moveto (XINT (x), XINT (y));
1750 }
1751 #else
1752 #ifdef HAVE_GPM
1753 {
1754 Fselect_frame (frame, Qnil);
1755 term_mouse_moveto (XINT (x), XINT (y));
1756 }
1757 #endif
1758 #endif
1759 #endif
1760
1761 return Qnil;
1762 }
1763
1764 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1765 Sset_mouse_pixel_position, 3, 3, 0,
1766 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1767 The position is given in pixels, where (0, 0) is the upper-left corner
1768 of the frame, X is the horizontal offset, and Y is the vertical offset.
1769
1770 Note, this is a no-op for an X frame that is not visible.
1771 If you have just created a frame, you must wait for it to become visible
1772 before calling this function on it, like this.
1773 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1774 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1775 {
1776 CHECK_LIVE_FRAME (frame);
1777 CHECK_NUMBER (x);
1778 CHECK_NUMBER (y);
1779
1780 /* I think this should be done with a hook. */
1781 #ifdef HAVE_WINDOW_SYSTEM
1782 if (FRAME_WINDOW_P (XFRAME (frame)))
1783 /* Warping the mouse will cause enternotify and focus events. */
1784 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1785 #else
1786 #if defined (MSDOS) && defined (HAVE_MOUSE)
1787 if (FRAME_MSDOS_P (XFRAME (frame)))
1788 {
1789 Fselect_frame (frame, Qnil);
1790 mouse_moveto (XINT (x), XINT (y));
1791 }
1792 #else
1793 #ifdef HAVE_GPM
1794 {
1795 Fselect_frame (frame, Qnil);
1796 term_mouse_moveto (XINT (x), XINT (y));
1797 }
1798 #endif
1799 #endif
1800 #endif
1801
1802 return Qnil;
1803 }
1804 \f
1805 static void make_frame_visible_1 (Lisp_Object);
1806
1807 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1808 0, 1, "",
1809 doc: /* Make the frame FRAME visible (assuming it is an X window).
1810 If omitted, FRAME defaults to the currently selected frame. */)
1811 (Lisp_Object frame)
1812 {
1813 if (NILP (frame))
1814 frame = selected_frame;
1815
1816 CHECK_LIVE_FRAME (frame);
1817
1818 /* I think this should be done with a hook. */
1819 #ifdef HAVE_WINDOW_SYSTEM
1820 if (FRAME_WINDOW_P (XFRAME (frame)))
1821 {
1822 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1823 x_make_frame_visible (XFRAME (frame));
1824 }
1825 #endif
1826
1827 make_frame_visible_1 (XFRAME (frame)->root_window);
1828
1829 /* Make menu bar update for the Buffers and Frames menus. */
1830 windows_or_buffers_changed++;
1831
1832 return frame;
1833 }
1834
1835 /* Update the display_time slot of the buffers shown in WINDOW
1836 and all its descendents. */
1837
1838 static void
1839 make_frame_visible_1 (Lisp_Object window)
1840 {
1841 struct window *w;
1842
1843 for (;!NILP (window); window = w->next)
1844 {
1845 w = XWINDOW (window);
1846
1847 if (!NILP (w->buffer))
1848 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1849
1850 if (!NILP (w->vchild))
1851 make_frame_visible_1 (w->vchild);
1852 if (!NILP (w->hchild))
1853 make_frame_visible_1 (w->hchild);
1854 }
1855 }
1856
1857 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1858 0, 2, "",
1859 doc: /* Make the frame FRAME invisible.
1860 If omitted, FRAME defaults to the currently selected frame.
1861 On graphical displays, invisible frames are not updated and are
1862 usually not displayed at all, even in a window system's \"taskbar\".
1863
1864 Normally you may not make FRAME invisible if all other frames are invisible,
1865 but if the second optional argument FORCE is non-nil, you may do so.
1866
1867 This function has no effect on text-only terminal frames. Such frames
1868 are always considered visible, whether or not they are currently being
1869 displayed in the terminal. */)
1870 (Lisp_Object frame, Lisp_Object force)
1871 {
1872 if (NILP (frame))
1873 frame = selected_frame;
1874
1875 CHECK_LIVE_FRAME (frame);
1876
1877 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1878 error ("Attempt to make invisible the sole visible or iconified frame");
1879
1880 #if 0 /* This isn't logically necessary, and it can do GC. */
1881 /* Don't let the frame remain selected. */
1882 if (EQ (frame, selected_frame))
1883 do_switch_frame (next_frame (frame, Qt), 0, 0, Qnil)
1884 #endif
1885
1886 /* Don't allow minibuf_window to remain on a deleted frame. */
1887 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1888 {
1889 struct frame *sf = XFRAME (selected_frame);
1890 Fset_window_buffer (sf->minibuffer_window,
1891 XWINDOW (minibuf_window)->buffer, Qnil);
1892 minibuf_window = sf->minibuffer_window;
1893 }
1894
1895 /* I think this should be done with a hook. */
1896 #ifdef HAVE_WINDOW_SYSTEM
1897 if (FRAME_WINDOW_P (XFRAME (frame)))
1898 x_make_frame_invisible (XFRAME (frame));
1899 #endif
1900
1901 /* Make menu bar update for the Buffers and Frames menus. */
1902 windows_or_buffers_changed++;
1903
1904 return Qnil;
1905 }
1906
1907 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1908 0, 1, "",
1909 doc: /* Make the frame FRAME into an icon.
1910 If omitted, FRAME defaults to the currently selected frame. */)
1911 (Lisp_Object frame)
1912 {
1913 if (NILP (frame))
1914 frame = selected_frame;
1915
1916 CHECK_LIVE_FRAME (frame);
1917
1918 #if 0 /* This isn't logically necessary, and it can do GC. */
1919 /* Don't let the frame remain selected. */
1920 if (EQ (frame, selected_frame))
1921 Fhandle_switch_frame (next_frame (frame, Qt));
1922 #endif
1923
1924 /* Don't allow minibuf_window to remain on a deleted frame. */
1925 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1926 {
1927 struct frame *sf = XFRAME (selected_frame);
1928 Fset_window_buffer (sf->minibuffer_window,
1929 XWINDOW (minibuf_window)->buffer, Qnil);
1930 minibuf_window = sf->minibuffer_window;
1931 }
1932
1933 /* I think this should be done with a hook. */
1934 #ifdef HAVE_WINDOW_SYSTEM
1935 if (FRAME_WINDOW_P (XFRAME (frame)))
1936 x_iconify_frame (XFRAME (frame));
1937 #endif
1938
1939 /* Make menu bar update for the Buffers and Frames menus. */
1940 windows_or_buffers_changed++;
1941
1942 return Qnil;
1943 }
1944
1945 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1946 1, 1, 0,
1947 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1948 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1949 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1950 On graphical displays, invisible frames are not updated and are
1951 usually not displayed at all, even in a window system's \"taskbar\".
1952
1953 If FRAME is a text-only terminal frame, this always returns t.
1954 Such frames are always considered visible, whether or not they are
1955 currently being displayed on the terminal. */)
1956 (Lisp_Object frame)
1957 {
1958 CHECK_LIVE_FRAME (frame);
1959
1960 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1961
1962 if (FRAME_VISIBLE_P (XFRAME (frame)))
1963 return Qt;
1964 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1965 return Qicon;
1966 return Qnil;
1967 }
1968
1969 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1970 0, 0, 0,
1971 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1972 (void)
1973 {
1974 Lisp_Object tail, frame;
1975 struct frame *f;
1976 Lisp_Object value;
1977
1978 value = Qnil;
1979 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1980 {
1981 frame = XCAR (tail);
1982 if (!FRAMEP (frame))
1983 continue;
1984 f = XFRAME (frame);
1985 if (FRAME_VISIBLE_P (f))
1986 value = Fcons (frame, value);
1987 }
1988 return value;
1989 }
1990
1991
1992 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1993 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1994 If FRAME is invisible or iconified, make it visible.
1995 If you don't specify a frame, the selected frame is used.
1996 If Emacs is displaying on an ordinary terminal or some other device which
1997 doesn't support multiple overlapping frames, this function selects FRAME. */)
1998 (Lisp_Object frame)
1999 {
2000 struct frame *f;
2001 if (NILP (frame))
2002 frame = selected_frame;
2003
2004 CHECK_LIVE_FRAME (frame);
2005
2006 f = XFRAME (frame);
2007
2008 if (FRAME_TERMCAP_P (f))
2009 /* On a text-only terminal select FRAME. */
2010 Fselect_frame (frame, Qnil);
2011 else
2012 /* Do like the documentation says. */
2013 Fmake_frame_visible (frame);
2014
2015 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2016 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2017
2018 return Qnil;
2019 }
2020
2021 /* Should we have a corresponding function called Flower_Power? */
2022 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2023 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2024 If you don't specify a frame, the selected frame is used.
2025 If Emacs is displaying on an ordinary terminal or some other device which
2026 doesn't support multiple overlapping frames, this function does nothing. */)
2027 (Lisp_Object frame)
2028 {
2029 struct frame *f;
2030
2031 if (NILP (frame))
2032 frame = selected_frame;
2033
2034 CHECK_LIVE_FRAME (frame);
2035
2036 f = XFRAME (frame);
2037
2038 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2039 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2040
2041 return Qnil;
2042 }
2043
2044 \f
2045 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2046 1, 2, 0,
2047 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2048 In other words, switch-frame events caused by events in FRAME will
2049 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2050 FOCUS-FRAME after reading an event typed at FRAME.
2051
2052 If FOCUS-FRAME is omitted or nil, any existing redirection is
2053 cancelled, and the frame again receives its own keystrokes.
2054
2055 Focus redirection is useful for temporarily redirecting keystrokes to
2056 a surrogate minibuffer frame when a frame doesn't have its own
2057 minibuffer window.
2058
2059 A frame's focus redirection can be changed by `select-frame'. If frame
2060 FOO is selected, and then a different frame BAR is selected, any
2061 frames redirecting their focus to FOO are shifted to redirect their
2062 focus to BAR. This allows focus redirection to work properly when the
2063 user switches from one frame to another using `select-window'.
2064
2065 This means that a frame whose focus is redirected to itself is treated
2066 differently from a frame whose focus is redirected to nil; the former
2067 is affected by `select-frame', while the latter is not.
2068
2069 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2070 (Lisp_Object frame, Lisp_Object focus_frame)
2071 {
2072 struct frame *f;
2073
2074 /* Note that we don't check for a live frame here. It's reasonable
2075 to redirect the focus of a frame you're about to delete, if you
2076 know what other frame should receive those keystrokes. */
2077 CHECK_FRAME (frame);
2078
2079 if (! NILP (focus_frame))
2080 CHECK_LIVE_FRAME (focus_frame);
2081
2082 f = XFRAME (frame);
2083
2084 f->focus_frame = focus_frame;
2085
2086 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2087 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2088
2089 return Qnil;
2090 }
2091
2092
2093 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2094 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2095 This returns nil if FRAME's focus is not redirected.
2096 See `redirect-frame-focus'. */)
2097 (Lisp_Object frame)
2098 {
2099 CHECK_LIVE_FRAME (frame);
2100
2101 return FRAME_FOCUS_FRAME (XFRAME (frame));
2102 }
2103
2104
2105 \f
2106 /* Return the value of frame parameter PROP in frame FRAME. */
2107
2108 Lisp_Object
2109 get_frame_param (register struct frame *frame, Lisp_Object prop)
2110 {
2111 register Lisp_Object tem;
2112
2113 tem = Fassq (prop, frame->param_alist);
2114 if (EQ (tem, Qnil))
2115 return tem;
2116 return Fcdr (tem);
2117 }
2118
2119 /* Return the buffer-predicate of the selected frame. */
2120
2121 Lisp_Object
2122 frame_buffer_predicate (Lisp_Object frame)
2123 {
2124 return XFRAME (frame)->buffer_predicate;
2125 }
2126
2127 /* Return the buffer-list of the selected frame. */
2128
2129 Lisp_Object
2130 frame_buffer_list (Lisp_Object frame)
2131 {
2132 return XFRAME (frame)->buffer_list;
2133 }
2134
2135 /* Set the buffer-list of the selected frame. */
2136
2137 void
2138 set_frame_buffer_list (Lisp_Object frame, Lisp_Object list)
2139 {
2140 XFRAME (frame)->buffer_list = list;
2141 }
2142
2143 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2144
2145 void
2146 frames_discard_buffer (Lisp_Object buffer)
2147 {
2148 Lisp_Object frame, tail;
2149
2150 FOR_EACH_FRAME (tail, frame)
2151 {
2152 XFRAME (frame)->buffer_list
2153 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2154 XFRAME (frame)->buried_buffer_list
2155 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2156 }
2157 }
2158
2159 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2160 If the alist already has an element for PROP, we change it. */
2161
2162 void
2163 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2164 {
2165 register Lisp_Object tem;
2166
2167 tem = Fassq (prop, *alistptr);
2168 if (EQ (tem, Qnil))
2169 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2170 else
2171 Fsetcdr (tem, val);
2172 }
2173
2174 static int
2175 frame_name_fnn_p (char *str, EMACS_INT len)
2176 {
2177 if (len > 1 && str[0] == 'F')
2178 {
2179 char *end_ptr;
2180
2181 strtol (str + 1, &end_ptr, 10);
2182
2183 if (end_ptr == str + len)
2184 return 1;
2185 }
2186 return 0;
2187 }
2188
2189 /* Set the name of the terminal frame. Also used by MSDOS frames.
2190 Modeled after x_set_name which is used for WINDOW frames. */
2191
2192 static void
2193 set_term_frame_name (struct frame *f, Lisp_Object name)
2194 {
2195 f->explicit_name = ! NILP (name);
2196
2197 /* If NAME is nil, set the name to F<num>. */
2198 if (NILP (name))
2199 {
2200 char namebuf[20];
2201
2202 /* Check for no change needed in this very common case
2203 before we do any consing. */
2204 if (frame_name_fnn_p (SDATA (f->name),
2205 SBYTES (f->name)))
2206 return;
2207
2208 tty_frame_count++;
2209 sprintf (namebuf, "F%d", tty_frame_count);
2210 name = build_string (namebuf);
2211 }
2212 else
2213 {
2214 CHECK_STRING (name);
2215
2216 /* Don't change the name if it's already NAME. */
2217 if (! NILP (Fstring_equal (name, f->name)))
2218 return;
2219
2220 /* Don't allow the user to set the frame name to F<num>, so it
2221 doesn't clash with the names we generate for terminal frames. */
2222 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2223 error ("Frame names of the form F<num> are usurped by Emacs");
2224 }
2225
2226 f->name = name;
2227 update_mode_lines = 1;
2228 }
2229
2230 void
2231 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2232 {
2233 register Lisp_Object old_alist_elt;
2234
2235 /* The buffer-list parameters are stored in a special place and not
2236 in the alist. */
2237 if (EQ (prop, Qbuffer_list))
2238 {
2239 f->buffer_list = val;
2240 return;
2241 }
2242 if (EQ (prop, Qburied_buffer_list))
2243 {
2244 f->buried_buffer_list = val;
2245 return;
2246 }
2247
2248 /* If PROP is a symbol which is supposed to have frame-local values,
2249 and it is set up based on this frame, switch to the global
2250 binding. That way, we can create or alter the frame-local binding
2251 without messing up the symbol's status. */
2252 if (SYMBOLP (prop))
2253 {
2254 struct Lisp_Symbol *sym = XSYMBOL (prop);
2255 start:
2256 switch (sym->redirect)
2257 {
2258 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2259 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2260 case SYMBOL_LOCALIZED:
2261 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2262 if (blv->frame_local && BLV_FOUND (blv) && XFRAME (blv->where) == f)
2263 swap_in_global_binding (sym);
2264 break;
2265 }
2266 default: abort ();
2267 }
2268 }
2269
2270 /* The tty color needed to be set before the frame's parameter
2271 alist was updated with the new value. This is not true any more,
2272 but we still do this test early on. */
2273 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2274 && f == FRAME_TTY (f)->previous_frame)
2275 /* Force redisplay of this tty. */
2276 FRAME_TTY (f)->previous_frame = NULL;
2277
2278 /* Update the frame parameter alist. */
2279 old_alist_elt = Fassq (prop, f->param_alist);
2280 if (EQ (old_alist_elt, Qnil))
2281 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2282 else
2283 Fsetcdr (old_alist_elt, val);
2284
2285 /* Update some other special parameters in their special places
2286 in addition to the alist. */
2287
2288 if (EQ (prop, Qbuffer_predicate))
2289 f->buffer_predicate = val;
2290
2291 if (! FRAME_WINDOW_P (f))
2292 {
2293 if (EQ (prop, Qmenu_bar_lines))
2294 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2295 else if (EQ (prop, Qname))
2296 set_term_frame_name (f, val);
2297 }
2298
2299 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2300 {
2301 if (! MINI_WINDOW_P (XWINDOW (val)))
2302 error ("Surrogate minibuffer windows must be minibuffer windows");
2303
2304 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2305 && !EQ (val, f->minibuffer_window))
2306 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2307
2308 /* Install the chosen minibuffer window, with proper buffer. */
2309 f->minibuffer_window = val;
2310 }
2311 }
2312
2313 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2314 doc: /* Return the parameters-alist of frame FRAME.
2315 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2316 The meaningful PARMs depend on the kind of frame.
2317 If FRAME is omitted, return information on the currently selected frame. */)
2318 (Lisp_Object frame)
2319 {
2320 Lisp_Object alist;
2321 FRAME_PTR f;
2322 int height, width;
2323 struct gcpro gcpro1;
2324
2325 if (NILP (frame))
2326 frame = selected_frame;
2327
2328 CHECK_FRAME (frame);
2329 f = XFRAME (frame);
2330
2331 if (!FRAME_LIVE_P (f))
2332 return Qnil;
2333
2334 alist = Fcopy_alist (f->param_alist);
2335 GCPRO1 (alist);
2336
2337 if (!FRAME_WINDOW_P (f))
2338 {
2339 int fg = FRAME_FOREGROUND_PIXEL (f);
2340 int bg = FRAME_BACKGROUND_PIXEL (f);
2341 Lisp_Object elt;
2342
2343 /* If the frame's parameter alist says the colors are
2344 unspecified and reversed, take the frame's background pixel
2345 for foreground and vice versa. */
2346 elt = Fassq (Qforeground_color, alist);
2347 if (CONSP (elt) && STRINGP (XCDR (elt)))
2348 {
2349 if (strncmp (SDATA (XCDR (elt)),
2350 unspecified_bg,
2351 SCHARS (XCDR (elt))) == 0)
2352 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2353 else if (strncmp (SDATA (XCDR (elt)),
2354 unspecified_fg,
2355 SCHARS (XCDR (elt))) == 0)
2356 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2357 }
2358 else
2359 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2360 elt = Fassq (Qbackground_color, alist);
2361 if (CONSP (elt) && STRINGP (XCDR (elt)))
2362 {
2363 if (strncmp (SDATA (XCDR (elt)),
2364 unspecified_fg,
2365 SCHARS (XCDR (elt))) == 0)
2366 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2367 else if (strncmp (SDATA (XCDR (elt)),
2368 unspecified_bg,
2369 SCHARS (XCDR (elt))) == 0)
2370 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2371 }
2372 else
2373 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2374 store_in_alist (&alist, intern ("font"),
2375 build_string (FRAME_MSDOS_P (f)
2376 ? "ms-dos"
2377 : FRAME_W32_P (f) ? "w32term"
2378 :"tty"));
2379 }
2380 store_in_alist (&alist, Qname, f->name);
2381 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2382 store_in_alist (&alist, Qheight, make_number (height));
2383 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2384 store_in_alist (&alist, Qwidth, make_number (width));
2385 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2386 store_in_alist (&alist, Qminibuffer,
2387 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2388 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2389 : FRAME_MINIBUF_WINDOW (f)));
2390 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2391 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2392 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2393
2394 /* I think this should be done with a hook. */
2395 #ifdef HAVE_WINDOW_SYSTEM
2396 if (FRAME_WINDOW_P (f))
2397 x_report_frame_params (f, &alist);
2398 else
2399 #endif
2400 {
2401 /* This ought to be correct in f->param_alist for an X frame. */
2402 Lisp_Object lines;
2403 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2404 store_in_alist (&alist, Qmenu_bar_lines, lines);
2405 }
2406
2407 UNGCPRO;
2408 return alist;
2409 }
2410
2411
2412 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2413 doc: /* Return FRAME's value for parameter PARAMETER.
2414 If FRAME is nil, describe the currently selected frame. */)
2415 (Lisp_Object frame, Lisp_Object parameter)
2416 {
2417 struct frame *f;
2418 Lisp_Object value;
2419
2420 if (NILP (frame))
2421 frame = selected_frame;
2422 else
2423 CHECK_FRAME (frame);
2424 CHECK_SYMBOL (parameter);
2425
2426 f = XFRAME (frame);
2427 value = Qnil;
2428
2429 if (FRAME_LIVE_P (f))
2430 {
2431 /* Avoid consing in frequent cases. */
2432 if (EQ (parameter, Qname))
2433 value = f->name;
2434 #ifdef HAVE_X_WINDOWS
2435 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2436 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2437 #endif /* HAVE_X_WINDOWS */
2438 else if (EQ (parameter, Qbackground_color)
2439 || EQ (parameter, Qforeground_color))
2440 {
2441 value = Fassq (parameter, f->param_alist);
2442 if (CONSP (value))
2443 {
2444 value = XCDR (value);
2445 /* Fframe_parameters puts the actual fg/bg color names,
2446 even if f->param_alist says otherwise. This is
2447 important when param_alist's notion of colors is
2448 "unspecified". We need to do the same here. */
2449 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2450 {
2451 const char *color_name;
2452 EMACS_INT csz;
2453
2454 if (EQ (parameter, Qbackground_color))
2455 {
2456 color_name = SDATA (value);
2457 csz = SCHARS (value);
2458 if (strncmp (color_name, unspecified_bg, csz) == 0)
2459 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2460 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2461 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2462 }
2463 else if (EQ (parameter, Qforeground_color))
2464 {
2465 color_name = SDATA (value);
2466 csz = SCHARS (value);
2467 if (strncmp (color_name, unspecified_fg, csz) == 0)
2468 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2469 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2470 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2471 }
2472 }
2473 }
2474 else
2475 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2476 }
2477 else if (EQ (parameter, Qdisplay_type)
2478 || EQ (parameter, Qbackground_mode))
2479 value = Fcdr (Fassq (parameter, f->param_alist));
2480 else
2481 /* FIXME: Avoid this code path at all (as well as code duplication)
2482 by sharing more code with Fframe_parameters. */
2483 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2484 }
2485
2486 return value;
2487 }
2488
2489
2490 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2491 Smodify_frame_parameters, 2, 2, 0,
2492 doc: /* Modify the parameters of frame FRAME according to ALIST.
2493 If FRAME is nil, it defaults to the selected frame.
2494 ALIST is an alist of parameters to change and their new values.
2495 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2496 The meaningful PARMs depend on the kind of frame.
2497 Undefined PARMs are ignored, but stored in the frame's parameter list
2498 so that `frame-parameters' will return them.
2499
2500 The value of frame parameter FOO can also be accessed
2501 as a frame-local binding for the variable FOO, if you have
2502 enabled such bindings for that variable with `make-variable-frame-local'.
2503 Note that this functionality is obsolete as of Emacs 22.2, and its
2504 use is not recommended. Explicitly check for a frame-parameter instead. */)
2505 (Lisp_Object frame, Lisp_Object alist)
2506 {
2507 FRAME_PTR f;
2508 register Lisp_Object tail, prop, val;
2509
2510 if (EQ (frame, Qnil))
2511 frame = selected_frame;
2512 CHECK_LIVE_FRAME (frame);
2513 f = XFRAME (frame);
2514
2515 /* I think this should be done with a hook. */
2516 #ifdef HAVE_WINDOW_SYSTEM
2517 if (FRAME_WINDOW_P (f))
2518 x_set_frame_parameters (f, alist);
2519 else
2520 #endif
2521 #ifdef MSDOS
2522 if (FRAME_MSDOS_P (f))
2523 IT_set_frame_parameters (f, alist);
2524 else
2525 #endif
2526
2527 {
2528 int length = XINT (Flength (alist));
2529 int i;
2530 Lisp_Object *parms
2531 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2532 Lisp_Object *values
2533 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2534
2535 /* Extract parm names and values into those vectors. */
2536
2537 i = 0;
2538 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2539 {
2540 Lisp_Object elt;
2541
2542 elt = XCAR (tail);
2543 parms[i] = Fcar (elt);
2544 values[i] = Fcdr (elt);
2545 i++;
2546 }
2547
2548 /* Now process them in reverse of specified order. */
2549 for (i--; i >= 0; i--)
2550 {
2551 prop = parms[i];
2552 val = values[i];
2553 store_frame_param (f, prop, val);
2554
2555 /* Changing the background color might change the background
2556 mode, so that we have to load new defface specs.
2557 Call frame-set-background-mode to do that. */
2558 if (EQ (prop, Qbackground_color))
2559 call1 (Qframe_set_background_mode, frame);
2560 }
2561 }
2562 return Qnil;
2563 }
2564 \f
2565 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2566 0, 1, 0,
2567 doc: /* Height in pixels of a line in the font in frame FRAME.
2568 If FRAME is omitted, the selected frame is used.
2569 For a terminal frame, the value is always 1. */)
2570 (Lisp_Object frame)
2571 {
2572 struct frame *f;
2573
2574 if (NILP (frame))
2575 frame = selected_frame;
2576 CHECK_FRAME (frame);
2577 f = XFRAME (frame);
2578
2579 #ifdef HAVE_WINDOW_SYSTEM
2580 if (FRAME_WINDOW_P (f))
2581 return make_number (x_char_height (f));
2582 else
2583 #endif
2584 return make_number (1);
2585 }
2586
2587
2588 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2589 0, 1, 0,
2590 doc: /* Width in pixels of characters in the font in frame FRAME.
2591 If FRAME is omitted, the selected frame is used.
2592 On a graphical screen, the width is the standard width of the default font.
2593 For a terminal screen, the value is always 1. */)
2594 (Lisp_Object frame)
2595 {
2596 struct frame *f;
2597
2598 if (NILP (frame))
2599 frame = selected_frame;
2600 CHECK_FRAME (frame);
2601 f = XFRAME (frame);
2602
2603 #ifdef HAVE_WINDOW_SYSTEM
2604 if (FRAME_WINDOW_P (f))
2605 return make_number (x_char_width (f));
2606 else
2607 #endif
2608 return make_number (1);
2609 }
2610
2611 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2612 Sframe_pixel_height, 0, 1, 0,
2613 doc: /* Return a FRAME's height in pixels.
2614 If FRAME is omitted, the selected frame is used. The exact value
2615 of the result depends on the window-system and toolkit in use:
2616
2617 In the Gtk+ version of Emacs, it includes only any window (including
2618 the minibuffer or eacho area), mode line, and header line. It does not
2619 include the tool bar or menu bar.
2620
2621 With the Motif or Lucid toolkits, it also includes the tool bar (but
2622 not the menu bar).
2623
2624 In a graphical version with no toolkit, it includes both the tool bar
2625 and menu bar.
2626
2627 For a text-only terminal, it includes the menu bar. In this case, the
2628 result is really in characters rather than pixels (i.e., is identical
2629 to `frame-height'). */)
2630 (Lisp_Object frame)
2631 {
2632 struct frame *f;
2633
2634 if (NILP (frame))
2635 frame = selected_frame;
2636 CHECK_FRAME (frame);
2637 f = XFRAME (frame);
2638
2639 #ifdef HAVE_WINDOW_SYSTEM
2640 if (FRAME_WINDOW_P (f))
2641 return make_number (x_pixel_height (f));
2642 else
2643 #endif
2644 return make_number (FRAME_LINES (f));
2645 }
2646
2647 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2648 Sframe_pixel_width, 0, 1, 0,
2649 doc: /* Return FRAME's width in pixels.
2650 For a terminal frame, the result really gives the width in characters.
2651 If FRAME is omitted, the selected frame is used. */)
2652 (Lisp_Object frame)
2653 {
2654 struct frame *f;
2655
2656 if (NILP (frame))
2657 frame = selected_frame;
2658 CHECK_FRAME (frame);
2659 f = XFRAME (frame);
2660
2661 #ifdef HAVE_WINDOW_SYSTEM
2662 if (FRAME_WINDOW_P (f))
2663 return make_number (x_pixel_width (f));
2664 else
2665 #endif
2666 return make_number (FRAME_COLS (f));
2667 }
2668 \f
2669 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2670 doc: /* Specify that the frame FRAME has LINES lines.
2671 Optional third arg non-nil means that redisplay should use LINES lines
2672 but that the idea of the actual height of the frame should not be changed. */)
2673 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2674 {
2675 register struct frame *f;
2676
2677 CHECK_NUMBER (lines);
2678 if (NILP (frame))
2679 frame = selected_frame;
2680 CHECK_LIVE_FRAME (frame);
2681 f = XFRAME (frame);
2682
2683 /* I think this should be done with a hook. */
2684 #ifdef HAVE_WINDOW_SYSTEM
2685 if (FRAME_WINDOW_P (f))
2686 {
2687 if (XINT (lines) != FRAME_LINES (f))
2688 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2689 do_pending_window_change (0);
2690 }
2691 else
2692 #endif
2693 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2694 return Qnil;
2695 }
2696
2697 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2698 doc: /* Specify that the frame FRAME has COLS columns.
2699 Optional third arg non-nil means that redisplay should use COLS columns
2700 but that the idea of the actual width of the frame should not be changed. */)
2701 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2702 {
2703 register struct frame *f;
2704 CHECK_NUMBER (cols);
2705 if (NILP (frame))
2706 frame = selected_frame;
2707 CHECK_LIVE_FRAME (frame);
2708 f = XFRAME (frame);
2709
2710 /* I think this should be done with a hook. */
2711 #ifdef HAVE_WINDOW_SYSTEM
2712 if (FRAME_WINDOW_P (f))
2713 {
2714 if (XINT (cols) != FRAME_COLS (f))
2715 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2716 do_pending_window_change (0);
2717 }
2718 else
2719 #endif
2720 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2721 return Qnil;
2722 }
2723
2724 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2725 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2726 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2727 {
2728 register struct frame *f;
2729
2730 CHECK_LIVE_FRAME (frame);
2731 CHECK_NUMBER (cols);
2732 CHECK_NUMBER (rows);
2733 f = XFRAME (frame);
2734
2735 /* I think this should be done with a hook. */
2736 #ifdef HAVE_WINDOW_SYSTEM
2737 if (FRAME_WINDOW_P (f))
2738 {
2739 if (XINT (rows) != FRAME_LINES (f)
2740 || XINT (cols) != FRAME_COLS (f)
2741 || f->new_text_lines || f->new_text_cols)
2742 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2743 do_pending_window_change (0);
2744 }
2745 else
2746 #endif
2747 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2748
2749 return Qnil;
2750 }
2751
2752 DEFUN ("set-frame-position", Fset_frame_position,
2753 Sset_frame_position, 3, 3, 0,
2754 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2755 This is actually the position of the upper left corner of the frame.
2756 Negative values for XOFFSET or YOFFSET are interpreted relative to
2757 the rightmost or bottommost possible position (that stays within the screen). */)
2758 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2759 {
2760 register struct frame *f;
2761
2762 CHECK_LIVE_FRAME (frame);
2763 CHECK_NUMBER (xoffset);
2764 CHECK_NUMBER (yoffset);
2765 f = XFRAME (frame);
2766
2767 /* I think this should be done with a hook. */
2768 #ifdef HAVE_WINDOW_SYSTEM
2769 if (FRAME_WINDOW_P (f))
2770 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2771 #endif
2772
2773 return Qt;
2774 }
2775
2776 \f
2777 /***********************************************************************
2778 Frame Parameters
2779 ***********************************************************************/
2780
2781 /* Connect the frame-parameter names for X frames
2782 to the ways of passing the parameter values to the window system.
2783
2784 The name of a parameter, as a Lisp symbol,
2785 has an `x-frame-parameter' property which is an integer in Lisp
2786 that is an index in this table. */
2787
2788 struct frame_parm_table {
2789 char *name;
2790 Lisp_Object *variable;
2791 };
2792
2793 static struct frame_parm_table frame_parms[] =
2794 {
2795 {"auto-raise", &Qauto_raise},
2796 {"auto-lower", &Qauto_lower},
2797 {"background-color", 0},
2798 {"border-color", &Qborder_color},
2799 {"border-width", &Qborder_width},
2800 {"cursor-color", &Qcursor_color},
2801 {"cursor-type", &Qcursor_type},
2802 {"font", 0},
2803 {"foreground-color", 0},
2804 {"icon-name", &Qicon_name},
2805 {"icon-type", &Qicon_type},
2806 {"internal-border-width", &Qinternal_border_width},
2807 {"menu-bar-lines", &Qmenu_bar_lines},
2808 {"mouse-color", &Qmouse_color},
2809 {"name", &Qname},
2810 {"scroll-bar-width", &Qscroll_bar_width},
2811 {"title", &Qtitle},
2812 {"unsplittable", &Qunsplittable},
2813 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2814 {"visibility", &Qvisibility},
2815 {"tool-bar-lines", &Qtool_bar_lines},
2816 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2817 {"scroll-bar-background", &Qscroll_bar_background},
2818 {"screen-gamma", &Qscreen_gamma},
2819 {"line-spacing", &Qline_spacing},
2820 {"left-fringe", &Qleft_fringe},
2821 {"right-fringe", &Qright_fringe},
2822 {"wait-for-wm", &Qwait_for_wm},
2823 {"fullscreen", &Qfullscreen},
2824 {"font-backend", &Qfont_backend},
2825 {"alpha", &Qalpha},
2826 {"sticky", &Qsticky},
2827 };
2828
2829 #ifdef HAVE_WINDOW_SYSTEM
2830
2831 extern Lisp_Object Qbox;
2832 extern Lisp_Object Qtop;
2833
2834 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2835 wanted positions of the WM window (not Emacs window).
2836 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2837 window (FRAME_X_WINDOW).
2838 */
2839
2840 void
2841 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2842 {
2843 int newwidth = FRAME_COLS (f);
2844 int newheight = FRAME_LINES (f);
2845 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2846
2847 *top_pos = f->top_pos;
2848 *left_pos = f->left_pos;
2849
2850 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2851 {
2852 int ph;
2853
2854 ph = x_display_pixel_height (dpyinfo);
2855 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2856 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2857 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2858 *top_pos = 0;
2859 }
2860
2861 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2862 {
2863 int pw;
2864
2865 pw = x_display_pixel_width (dpyinfo);
2866 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2867 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2868 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2869 *left_pos = 0;
2870 }
2871
2872 *width = newwidth;
2873 *height = newheight;
2874 }
2875
2876
2877 /* Change the parameters of frame F as specified by ALIST.
2878 If a parameter is not specially recognized, do nothing special;
2879 otherwise call the `x_set_...' function for that parameter.
2880 Except for certain geometry properties, always call store_frame_param
2881 to store the new value in the parameter alist. */
2882
2883 void
2884 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2885 {
2886 Lisp_Object tail;
2887
2888 /* If both of these parameters are present, it's more efficient to
2889 set them both at once. So we wait until we've looked at the
2890 entire list before we set them. */
2891 int width, height;
2892
2893 /* Same here. */
2894 Lisp_Object left, top;
2895
2896 /* Same with these. */
2897 Lisp_Object icon_left, icon_top;
2898
2899 /* Record in these vectors all the parms specified. */
2900 Lisp_Object *parms;
2901 Lisp_Object *values;
2902 int i, p;
2903 int left_no_change = 0, top_no_change = 0;
2904 int icon_left_no_change = 0, icon_top_no_change = 0;
2905 int size_changed = 0;
2906 struct gcpro gcpro1, gcpro2;
2907
2908 i = 0;
2909 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2910 i++;
2911
2912 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2913 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2914
2915 /* Extract parm names and values into those vectors. */
2916
2917 i = 0;
2918 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2919 {
2920 Lisp_Object elt;
2921
2922 elt = XCAR (tail);
2923 parms[i] = Fcar (elt);
2924 values[i] = Fcdr (elt);
2925 i++;
2926 }
2927 /* TAIL and ALIST are not used again below here. */
2928 alist = tail = Qnil;
2929
2930 GCPRO2 (*parms, *values);
2931 gcpro1.nvars = i;
2932 gcpro2.nvars = i;
2933
2934 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2935 because their values appear in VALUES and strings are not valid. */
2936 top = left = Qunbound;
2937 icon_left = icon_top = Qunbound;
2938
2939 /* Provide default values for HEIGHT and WIDTH. */
2940 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2941 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2942
2943 /* Process foreground_color and background_color before anything else.
2944 They are independent of other properties, but other properties (e.g.,
2945 cursor_color) are dependent upon them. */
2946 /* Process default font as well, since fringe widths depends on it. */
2947 for (p = 0; p < i; p++)
2948 {
2949 Lisp_Object prop, val;
2950
2951 prop = parms[p];
2952 val = values[p];
2953 if (EQ (prop, Qforeground_color)
2954 || EQ (prop, Qbackground_color)
2955 || EQ (prop, Qfont))
2956 {
2957 register Lisp_Object param_index, old_value;
2958
2959 old_value = get_frame_param (f, prop);
2960 if (NILP (Fequal (val, old_value)))
2961 {
2962 store_frame_param (f, prop, val);
2963
2964 param_index = Fget (prop, Qx_frame_parameter);
2965 if (NATNUMP (param_index)
2966 && (XFASTINT (param_index)
2967 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2968 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2969 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2970 }
2971 }
2972 }
2973
2974 /* Now process them in reverse of specified order. */
2975 for (i--; i >= 0; i--)
2976 {
2977 Lisp_Object prop, val;
2978
2979 prop = parms[i];
2980 val = values[i];
2981
2982 if (EQ (prop, Qwidth) && NATNUMP (val))
2983 {
2984 size_changed = 1;
2985 width = XFASTINT (val);
2986 }
2987 else if (EQ (prop, Qheight) && NATNUMP (val))
2988 {
2989 size_changed = 1;
2990 height = XFASTINT (val);
2991 }
2992 else if (EQ (prop, Qtop))
2993 top = val;
2994 else if (EQ (prop, Qleft))
2995 left = val;
2996 else if (EQ (prop, Qicon_top))
2997 icon_top = val;
2998 else if (EQ (prop, Qicon_left))
2999 icon_left = val;
3000 else if (EQ (prop, Qforeground_color)
3001 || EQ (prop, Qbackground_color)
3002 || EQ (prop, Qfont))
3003 /* Processed above. */
3004 continue;
3005 else
3006 {
3007 register Lisp_Object param_index, old_value;
3008
3009 old_value = get_frame_param (f, prop);
3010
3011 store_frame_param (f, prop, val);
3012
3013 param_index = Fget (prop, Qx_frame_parameter);
3014 if (NATNUMP (param_index)
3015 && (XFASTINT (param_index)
3016 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3017 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3018 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3019 }
3020 }
3021
3022 /* Don't die if just one of these was set. */
3023 if (EQ (left, Qunbound))
3024 {
3025 left_no_change = 1;
3026 if (f->left_pos < 0)
3027 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3028 else
3029 XSETINT (left, f->left_pos);
3030 }
3031 if (EQ (top, Qunbound))
3032 {
3033 top_no_change = 1;
3034 if (f->top_pos < 0)
3035 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3036 else
3037 XSETINT (top, f->top_pos);
3038 }
3039
3040 /* If one of the icon positions was not set, preserve or default it. */
3041 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3042 {
3043 icon_left_no_change = 1;
3044 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3045 if (NILP (icon_left))
3046 XSETINT (icon_left, 0);
3047 }
3048 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3049 {
3050 icon_top_no_change = 1;
3051 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3052 if (NILP (icon_top))
3053 XSETINT (icon_top, 0);
3054 }
3055
3056 /* Don't set these parameters unless they've been explicitly
3057 specified. The window might be mapped or resized while we're in
3058 this function, and we don't want to override that unless the lisp
3059 code has asked for it.
3060
3061 Don't set these parameters unless they actually differ from the
3062 window's current parameters; the window may not actually exist
3063 yet. */
3064 {
3065 Lisp_Object frame;
3066
3067 check_frame_size (f, &height, &width);
3068
3069 XSETFRAME (frame, f);
3070
3071 if (size_changed
3072 && (width != FRAME_COLS (f)
3073 || height != FRAME_LINES (f)
3074 || f->new_text_lines || f->new_text_cols))
3075 Fset_frame_size (frame, make_number (width), make_number (height));
3076
3077 if ((!NILP (left) || !NILP (top))
3078 && ! (left_no_change && top_no_change)
3079 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3080 && NUMBERP (top) && XINT (top) == f->top_pos))
3081 {
3082 int leftpos = 0;
3083 int toppos = 0;
3084
3085 /* Record the signs. */
3086 f->size_hint_flags &= ~ (XNegative | YNegative);
3087 if (EQ (left, Qminus))
3088 f->size_hint_flags |= XNegative;
3089 else if (INTEGERP (left))
3090 {
3091 leftpos = XINT (left);
3092 if (leftpos < 0)
3093 f->size_hint_flags |= XNegative;
3094 }
3095 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3096 && CONSP (XCDR (left))
3097 && INTEGERP (XCAR (XCDR (left))))
3098 {
3099 leftpos = - XINT (XCAR (XCDR (left)));
3100 f->size_hint_flags |= XNegative;
3101 }
3102 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3103 && CONSP (XCDR (left))
3104 && INTEGERP (XCAR (XCDR (left))))
3105 {
3106 leftpos = XINT (XCAR (XCDR (left)));
3107 }
3108
3109 if (EQ (top, Qminus))
3110 f->size_hint_flags |= YNegative;
3111 else if (INTEGERP (top))
3112 {
3113 toppos = XINT (top);
3114 if (toppos < 0)
3115 f->size_hint_flags |= YNegative;
3116 }
3117 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3118 && CONSP (XCDR (top))
3119 && INTEGERP (XCAR (XCDR (top))))
3120 {
3121 toppos = - XINT (XCAR (XCDR (top)));
3122 f->size_hint_flags |= YNegative;
3123 }
3124 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3125 && CONSP (XCDR (top))
3126 && INTEGERP (XCAR (XCDR (top))))
3127 {
3128 toppos = XINT (XCAR (XCDR (top)));
3129 }
3130
3131
3132 /* Store the numeric value of the position. */
3133 f->top_pos = toppos;
3134 f->left_pos = leftpos;
3135
3136 f->win_gravity = NorthWestGravity;
3137
3138 /* Actually set that position, and convert to absolute. */
3139 x_set_offset (f, leftpos, toppos, -1);
3140 }
3141
3142 if ((!NILP (icon_left) || !NILP (icon_top))
3143 && ! (icon_left_no_change && icon_top_no_change))
3144 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3145 }
3146
3147 UNGCPRO;
3148 }
3149
3150
3151 /* Insert a description of internally-recorded parameters of frame X
3152 into the parameter alist *ALISTPTR that is to be given to the user.
3153 Only parameters that are specific to the X window system
3154 and whose values are not correctly recorded in the frame's
3155 param_alist need to be considered here. */
3156
3157 void
3158 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3159 {
3160 char buf[16];
3161 Lisp_Object tem;
3162
3163 /* Represent negative positions (off the top or left screen edge)
3164 in a way that Fmodify_frame_parameters will understand correctly. */
3165 XSETINT (tem, f->left_pos);
3166 if (f->left_pos >= 0)
3167 store_in_alist (alistptr, Qleft, tem);
3168 else
3169 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3170
3171 XSETINT (tem, f->top_pos);
3172 if (f->top_pos >= 0)
3173 store_in_alist (alistptr, Qtop, tem);
3174 else
3175 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3176
3177 store_in_alist (alistptr, Qborder_width,
3178 make_number (f->border_width));
3179 store_in_alist (alistptr, Qinternal_border_width,
3180 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3181 store_in_alist (alistptr, Qleft_fringe,
3182 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3183 store_in_alist (alistptr, Qright_fringe,
3184 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3185 store_in_alist (alistptr, Qscroll_bar_width,
3186 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3187 ? make_number (0)
3188 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3189 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3190 /* nil means "use default width"
3191 for non-toolkit scroll bar.
3192 ruler-mode.el depends on this. */
3193 : Qnil));
3194 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3195 store_in_alist (alistptr, Qwindow_id,
3196 build_string (buf));
3197 #ifdef HAVE_X_WINDOWS
3198 #ifdef USE_X_TOOLKIT
3199 /* Tooltip frame may not have this widget. */
3200 if (FRAME_X_OUTPUT (f)->widget)
3201 #endif
3202 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3203 store_in_alist (alistptr, Qouter_window_id,
3204 build_string (buf));
3205 #endif
3206 store_in_alist (alistptr, Qicon_name, f->icon_name);
3207 FRAME_SAMPLE_VISIBILITY (f);
3208 store_in_alist (alistptr, Qvisibility,
3209 (FRAME_VISIBLE_P (f) ? Qt
3210 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3211 store_in_alist (alistptr, Qdisplay,
3212 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3213
3214 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3215 tem = Qnil;
3216 else
3217 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3218 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3219 store_in_alist (alistptr, Qparent_id, tem);
3220 }
3221
3222
3223 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3224 the previous value of that parameter, NEW_VALUE is the new value. */
3225
3226 void
3227 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3228 {
3229 if (NILP (new_value))
3230 f->want_fullscreen = FULLSCREEN_NONE;
3231 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3232 f->want_fullscreen = FULLSCREEN_BOTH;
3233 else if (EQ (new_value, Qfullwidth))
3234 f->want_fullscreen = FULLSCREEN_WIDTH;
3235 else if (EQ (new_value, Qfullheight))
3236 f->want_fullscreen = FULLSCREEN_HEIGHT;
3237 else if (EQ (new_value, Qmaximized))
3238 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3239
3240 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3241 FRAME_TERMINAL (f)->fullscreen_hook (f);
3242 }
3243
3244
3245 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3246 the previous value of that parameter, NEW_VALUE is the new value. */
3247
3248 void
3249 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3250 {
3251 if (NILP (new_value))
3252 f->extra_line_spacing = 0;
3253 else if (NATNUMP (new_value))
3254 f->extra_line_spacing = XFASTINT (new_value);
3255 else
3256 signal_error ("Invalid line-spacing", new_value);
3257 if (FRAME_VISIBLE_P (f))
3258 redraw_frame (f);
3259 }
3260
3261
3262 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3263 the previous value of that parameter, NEW_VALUE is the new value. */
3264
3265 void
3266 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3267 {
3268 Lisp_Object bgcolor;
3269
3270 if (NILP (new_value))
3271 f->gamma = 0;
3272 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3273 /* The value 0.4545 is the normal viewing gamma. */
3274 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3275 else
3276 signal_error ("Invalid screen-gamma", new_value);
3277
3278 /* Apply the new gamma value to the frame background. */
3279 bgcolor = Fassq (Qbackground_color, f->param_alist);
3280 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3281 {
3282 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3283 if (NATNUMP (index)
3284 && (XFASTINT (index)
3285 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3286 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3287 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3288 (f, bgcolor, Qnil);
3289 }
3290
3291 Fclear_face_cache (Qnil);
3292 }
3293
3294
3295 void
3296 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3297 {
3298 Lisp_Object frame, font_object, font_param = Qnil;
3299 int fontset = -1;
3300
3301 /* Set the frame parameter back to the old value because we may
3302 fail to use ARG as the new parameter value. */
3303 store_frame_param (f, Qfont, oldval);
3304
3305 /* ARG is a fontset name, a font name, a cons of fontset name and a
3306 font object, or a font object. In the last case, this function
3307 never fail. */
3308 if (STRINGP (arg))
3309 {
3310 font_param = arg;
3311 fontset = fs_query_fontset (arg, 0);
3312 if (fontset < 0)
3313 {
3314 font_object = font_open_by_name (f, SDATA (arg));
3315 if (NILP (font_object))
3316 error ("Font `%s' is not defined", SDATA (arg));
3317 arg = AREF (font_object, FONT_NAME_INDEX);
3318 }
3319 else if (fontset > 0)
3320 {
3321 Lisp_Object ascii_font = fontset_ascii (fontset);
3322
3323 font_object = font_open_by_name (f, SDATA (ascii_font));
3324 if (NILP (font_object))
3325 error ("Font `%s' is not defined", SDATA (arg));
3326 arg = AREF (font_object, FONT_NAME_INDEX);
3327 }
3328 else
3329 error ("The default fontset can't be used for a frame font");
3330 }
3331 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3332 {
3333 /* This is the case that the ASCII font of F's fontset XCAR
3334 (arg) is changed to the font XCDR (arg) by
3335 `set-fontset-font'. */
3336 fontset = fs_query_fontset (XCAR (arg), 0);
3337 if (fontset < 0)
3338 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3339 font_object = XCDR (arg);
3340 arg = AREF (font_object, FONT_NAME_INDEX);
3341 font_param = Ffont_get (font_object, QCname);
3342 }
3343 else if (FONT_OBJECT_P (arg))
3344 {
3345 font_object = arg;
3346 font_param = Ffont_get (font_object, QCname);
3347 /* This is to store the XLFD font name in the frame parameter for
3348 backward compatibility. We should store the font-object
3349 itself in the future. */
3350 arg = AREF (font_object, FONT_NAME_INDEX);
3351 fontset = FRAME_FONTSET (f);
3352 /* Check if we can use the current fontset. If not, set FONTSET
3353 to -1 to generate a new fontset from FONT-OBJECT. */
3354 if (fontset >= 0)
3355 {
3356 Lisp_Object ascii_font = fontset_ascii (fontset);
3357 Lisp_Object spec = font_spec_from_name (ascii_font);
3358
3359 if (! font_match_p (spec, font_object))
3360 fontset = -1;
3361 }
3362 }
3363 else
3364 signal_error ("Invalid font", arg);
3365
3366 if (! NILP (Fequal (font_object, oldval)))
3367 return;
3368
3369 x_new_font (f, font_object, fontset);
3370 store_frame_param (f, Qfont, arg);
3371 #ifdef HAVE_X_WINDOWS
3372 store_frame_param (f, Qfont_param, font_param);
3373 #endif
3374 /* Recalculate toolbar height. */
3375 f->n_tool_bar_rows = 0;
3376 /* Ensure we redraw it. */
3377 clear_current_matrices (f);
3378
3379 recompute_basic_faces (f);
3380
3381 do_pending_window_change (0);
3382
3383 /* We used to call face-set-after-frame-default here, but it leads to
3384 recursive calls (since that function can set the `default' face's
3385 font which in turns changes the frame's `font' parameter).
3386 Also I don't know what this call is meant to do, but it seems the
3387 wrong way to do it anyway (it does a lot more work than what seems
3388 reasonable in response to a change to `font'). */
3389 }
3390
3391
3392 void
3393 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3394 {
3395 if (! NILP (new_value)
3396 && !CONSP (new_value))
3397 {
3398 char *p0, *p1;
3399
3400 CHECK_STRING (new_value);
3401 p0 = p1 = SDATA (new_value);
3402 new_value = Qnil;
3403 while (*p0)
3404 {
3405 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3406 if (p0 < p1)
3407 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3408 new_value);
3409 if (*p1)
3410 {
3411 int c;
3412
3413 while ((c = *++p1) && isspace (c));
3414 }
3415 p0 = p1;
3416 }
3417 new_value = Fnreverse (new_value);
3418 }
3419
3420 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3421 return;
3422
3423 if (FRAME_FONT (f))
3424 free_all_realized_faces (Qnil);
3425
3426 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3427 if (NILP (new_value))
3428 {
3429 if (NILP (old_value))
3430 error ("No font backend available");
3431 font_update_drivers (f, old_value);
3432 error ("None of specified font backends are available");
3433 }
3434 store_frame_param (f, Qfont_backend, new_value);
3435
3436 if (FRAME_FONT (f))
3437 {
3438 Lisp_Object frame;
3439
3440 XSETFRAME (frame, f);
3441 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3442 ++face_change_count;
3443 ++windows_or_buffers_changed;
3444 }
3445 }
3446
3447
3448 void
3449 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3450 {
3451 compute_fringe_widths (f, 1);
3452 }
3453
3454 void
3455 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3456 {
3457 CHECK_NUMBER (arg);
3458
3459 if (XINT (arg) == f->border_width)
3460 return;
3461
3462 if (FRAME_X_WINDOW (f) != 0)
3463 error ("Cannot change the border width of a frame");
3464
3465 f->border_width = XINT (arg);
3466 }
3467
3468 void
3469 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3470 {
3471 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3472
3473 CHECK_NUMBER (arg);
3474 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3475 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3476 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3477
3478 #ifdef USE_X_TOOLKIT
3479 if (FRAME_X_OUTPUT (f)->edit_widget)
3480 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3481 #endif
3482
3483 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3484 return;
3485
3486 if (FRAME_X_WINDOW (f) != 0)
3487 {
3488 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3489 SET_FRAME_GARBAGED (f);
3490 do_pending_window_change (0);
3491 }
3492 else
3493 SET_FRAME_GARBAGED (f);
3494 }
3495
3496 void
3497 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3498 {
3499 Lisp_Object frame;
3500 XSETFRAME (frame, f);
3501
3502 if (NILP (value))
3503 Fmake_frame_invisible (frame, Qt);
3504 else if (EQ (value, Qicon))
3505 Ficonify_frame (frame);
3506 else
3507 Fmake_frame_visible (frame);
3508 }
3509
3510 void
3511 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3512 {
3513 f->auto_raise = !EQ (Qnil, arg);
3514 }
3515
3516 void
3517 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3518 {
3519 f->auto_lower = !EQ (Qnil, arg);
3520 }
3521
3522 void
3523 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3524 {
3525 f->no_split = !NILP (arg);
3526 }
3527
3528 void
3529 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3530 {
3531 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3532 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3533 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3534 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3535 {
3536 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3537 = (NILP (arg)
3538 ? vertical_scroll_bar_none
3539 : EQ (Qleft, arg)
3540 ? vertical_scroll_bar_left
3541 : EQ (Qright, arg)
3542 ? vertical_scroll_bar_right
3543 : EQ (Qleft, Vdefault_frame_scroll_bars)
3544 ? vertical_scroll_bar_left
3545 : EQ (Qright, Vdefault_frame_scroll_bars)
3546 ? vertical_scroll_bar_right
3547 : vertical_scroll_bar_none);
3548
3549 /* We set this parameter before creating the X window for the
3550 frame, so we can get the geometry right from the start.
3551 However, if the window hasn't been created yet, we shouldn't
3552 call x_set_window_size. */
3553 if (FRAME_X_WINDOW (f))
3554 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3555 do_pending_window_change (0);
3556 }
3557 }
3558
3559 void
3560 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3561 {
3562 int wid = FRAME_COLUMN_WIDTH (f);
3563
3564 if (NILP (arg))
3565 {
3566 x_set_scroll_bar_default_width (f);
3567
3568 if (FRAME_X_WINDOW (f))
3569 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3570 do_pending_window_change (0);
3571 }
3572 else if (INTEGERP (arg) && XINT (arg) > 0
3573 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3574 {
3575 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3576 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3577
3578 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3579 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3580 if (FRAME_X_WINDOW (f))
3581 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3582 do_pending_window_change (0);
3583 }
3584
3585 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3586 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3587 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3588 }
3589
3590
3591
3592 /* Return non-nil if frame F wants a bitmap icon. */
3593
3594 Lisp_Object
3595 x_icon_type (FRAME_PTR f)
3596 {
3597 Lisp_Object tem;
3598
3599 tem = assq_no_quit (Qicon_type, f->param_alist);
3600 if (CONSP (tem))
3601 return XCDR (tem);
3602 else
3603 return Qnil;
3604 }
3605
3606 void
3607 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3608 {
3609 double alpha = 1.0;
3610 double newval[2];
3611 int i, ialpha;
3612 Lisp_Object item;
3613
3614 for (i = 0; i < 2; i++)
3615 {
3616 newval[i] = 1.0;
3617 if (CONSP (arg))
3618 {
3619 item = CAR (arg);
3620 arg = CDR (arg);
3621 }
3622 else
3623 item = arg;
3624
3625 if (NILP (item))
3626 alpha = - 1.0;
3627 else if (FLOATP (item))
3628 {
3629 alpha = XFLOAT_DATA (item);
3630 if (alpha < 0.0 || 1.0 < alpha)
3631 args_out_of_range (make_float (0.0), make_float (1.0));
3632 }
3633 else if (INTEGERP (item))
3634 {
3635 ialpha = XINT (item);
3636 if (ialpha < 0 || 100 < ialpha)
3637 args_out_of_range (make_number (0), make_number (100));
3638 else
3639 alpha = ialpha / 100.0;
3640 }
3641 else
3642 wrong_type_argument (Qnumberp, item);
3643 newval[i] = alpha;
3644 }
3645
3646 for (i = 0; i < 2; i++)
3647 f->alpha[i] = newval[i];
3648
3649 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3650 BLOCK_INPUT;
3651 x_set_frame_alpha (f);
3652 UNBLOCK_INPUT;
3653 #endif
3654
3655 return;
3656 }
3657
3658 \f
3659 /* Subroutines of creating an X frame. */
3660
3661 /* Make sure that Vx_resource_name is set to a reasonable value.
3662 Fix it up, or set it to `emacs' if it is too hopeless. */
3663
3664 void
3665 validate_x_resource_name (void)
3666 {
3667 int len = 0;
3668 /* Number of valid characters in the resource name. */
3669 int good_count = 0;
3670 /* Number of invalid characters in the resource name. */
3671 int bad_count = 0;
3672 Lisp_Object new;
3673 int i;
3674
3675 if (!STRINGP (Vx_resource_class))
3676 Vx_resource_class = build_string (EMACS_CLASS);
3677
3678 if (STRINGP (Vx_resource_name))
3679 {
3680 unsigned char *p = SDATA (Vx_resource_name);
3681 int i;
3682
3683 len = SBYTES (Vx_resource_name);
3684
3685 /* Only letters, digits, - and _ are valid in resource names.
3686 Count the valid characters and count the invalid ones. */
3687 for (i = 0; i < len; i++)
3688 {
3689 int c = p[i];
3690 if (! ((c >= 'a' && c <= 'z')
3691 || (c >= 'A' && c <= 'Z')
3692 || (c >= '0' && c <= '9')
3693 || c == '-' || c == '_'))
3694 bad_count++;
3695 else
3696 good_count++;
3697 }
3698 }
3699 else
3700 /* Not a string => completely invalid. */
3701 bad_count = 5, good_count = 0;
3702
3703 /* If name is valid already, return. */
3704 if (bad_count == 0)
3705 return;
3706
3707 /* If name is entirely invalid, or nearly so, use `emacs'. */
3708 if (good_count == 0
3709 || (good_count == 1 && bad_count > 0))
3710 {
3711 Vx_resource_name = build_string ("emacs");
3712 return;
3713 }
3714
3715 /* Name is partly valid. Copy it and replace the invalid characters
3716 with underscores. */
3717
3718 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3719
3720 for (i = 0; i < len; i++)
3721 {
3722 int c = SREF (new, i);
3723 if (! ((c >= 'a' && c <= 'z')
3724 || (c >= 'A' && c <= 'Z')
3725 || (c >= '0' && c <= '9')
3726 || c == '-' || c == '_'))
3727 SSET (new, i, '_');
3728 }
3729 }
3730
3731
3732 extern char *x_get_string_resource (XrmDatabase, char *, char *);
3733 extern Display_Info *check_x_display_info (Lisp_Object);
3734
3735
3736 /* Get specified attribute from resource database RDB.
3737 See Fx_get_resource below for other parameters. */
3738
3739 static Lisp_Object
3740 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3741 {
3742 register char *value;
3743 char *name_key;
3744 char *class_key;
3745
3746 CHECK_STRING (attribute);
3747 CHECK_STRING (class);
3748
3749 if (!NILP (component))
3750 CHECK_STRING (component);
3751 if (!NILP (subclass))
3752 CHECK_STRING (subclass);
3753 if (NILP (component) != NILP (subclass))
3754 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3755
3756 validate_x_resource_name ();
3757
3758 /* Allocate space for the components, the dots which separate them,
3759 and the final '\0'. Make them big enough for the worst case. */
3760 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3761 + (STRINGP (component)
3762 ? SBYTES (component) : 0)
3763 + SBYTES (attribute)
3764 + 3);
3765
3766 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3767 + SBYTES (class)
3768 + (STRINGP (subclass)
3769 ? SBYTES (subclass) : 0)
3770 + 3);
3771
3772 /* Start with emacs.FRAMENAME for the name (the specific one)
3773 and with `Emacs' for the class key (the general one). */
3774 strcpy (name_key, SDATA (Vx_resource_name));
3775 strcpy (class_key, SDATA (Vx_resource_class));
3776
3777 strcat (class_key, ".");
3778 strcat (class_key, SDATA (class));
3779
3780 if (!NILP (component))
3781 {
3782 strcat (class_key, ".");
3783 strcat (class_key, SDATA (subclass));
3784
3785 strcat (name_key, ".");
3786 strcat (name_key, SDATA (component));
3787 }
3788
3789 strcat (name_key, ".");
3790 strcat (name_key, SDATA (attribute));
3791
3792 value = x_get_string_resource (rdb, name_key, class_key);
3793
3794 if (value != (char *) 0 && *value)
3795 return build_string (value);
3796 else
3797 return Qnil;
3798 }
3799
3800
3801 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3802 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3803 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3804 class, where INSTANCE is the name under which Emacs was invoked, or
3805 the name specified by the `-name' or `-rn' command-line arguments.
3806
3807 The optional arguments COMPONENT and SUBCLASS add to the key and the
3808 class, respectively. You must specify both of them or neither.
3809 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3810 and the class is `Emacs.CLASS.SUBCLASS'. */)
3811 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3812 {
3813 #ifdef HAVE_X_WINDOWS
3814 check_x ();
3815 #endif
3816
3817 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3818 attribute, class, component, subclass);
3819 }
3820
3821 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3822
3823 Lisp_Object
3824 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3825 {
3826 return xrdb_get_resource (dpyinfo->xrdb,
3827 attribute, class, component, subclass);
3828 }
3829
3830 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3831 /* Used when C code wants a resource value. */
3832 /* Called from oldXMenu/Create.c. */
3833 char *
3834 x_get_resource_string (char *attribute, char *class)
3835 {
3836 char *name_key;
3837 char *class_key;
3838 struct frame *sf = SELECTED_FRAME ();
3839
3840 /* Allocate space for the components, the dots which separate them,
3841 and the final '\0'. */
3842 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3843 + strlen (attribute) + 2);
3844 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3845 + strlen (class) + 2);
3846
3847 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3848 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3849
3850 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3851 name_key, class_key);
3852 }
3853 #endif
3854
3855 /* Return the value of parameter PARAM.
3856
3857 First search ALIST, then Vdefault_frame_alist, then the X defaults
3858 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3859
3860 Convert the resource to the type specified by desired_type.
3861
3862 If no default is specified, return Qunbound. If you call
3863 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3864 and don't let it get stored in any Lisp-visible variables! */
3865
3866 Lisp_Object
3867 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param, char *attribute, char *class, enum resource_types type)
3868 {
3869 register Lisp_Object tem;
3870
3871 tem = Fassq (param, alist);
3872
3873 if (!NILP (tem))
3874 {
3875 /* If we find this parm in ALIST, clear it out
3876 so that it won't be "left over" at the end. */
3877 Lisp_Object tail;
3878 XSETCAR (tem, Qnil);
3879 /* In case the parameter appears more than once in the alist,
3880 clear it out. */
3881 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3882 if (CONSP (XCAR (tail))
3883 && EQ (XCAR (XCAR (tail)), param))
3884 XSETCAR (XCAR (tail), Qnil);
3885 }
3886 else
3887 tem = Fassq (param, Vdefault_frame_alist);
3888
3889 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3890 look in the X resources. */
3891 if (EQ (tem, Qnil))
3892 {
3893 if (attribute && dpyinfo)
3894 {
3895 tem = display_x_get_resource (dpyinfo,
3896 build_string (attribute),
3897 build_string (class),
3898 Qnil, Qnil);
3899
3900 if (NILP (tem))
3901 return Qunbound;
3902
3903 switch (type)
3904 {
3905 case RES_TYPE_NUMBER:
3906 return make_number (atoi (SDATA (tem)));
3907
3908 case RES_TYPE_BOOLEAN_NUMBER:
3909 if (!strcmp (SDATA (tem), "on")
3910 || !strcmp (SDATA (tem), "true"))
3911 return make_number (1);
3912 return make_number (atoi (SDATA (tem)));
3913 break;
3914
3915 case RES_TYPE_FLOAT:
3916 return make_float (atof (SDATA (tem)));
3917
3918 case RES_TYPE_BOOLEAN:
3919 tem = Fdowncase (tem);
3920 if (!strcmp (SDATA (tem), "on")
3921 #ifdef HAVE_NS
3922 || !strcmp(SDATA(tem), "yes")
3923 #endif
3924 || !strcmp (SDATA (tem), "true"))
3925 return Qt;
3926 else
3927 return Qnil;
3928
3929 case RES_TYPE_STRING:
3930 return tem;
3931
3932 case RES_TYPE_SYMBOL:
3933 /* As a special case, we map the values `true' and `on'
3934 to Qt, and `false' and `off' to Qnil. */
3935 {
3936 Lisp_Object lower;
3937 lower = Fdowncase (tem);
3938 if (!strcmp (SDATA (lower), "on")
3939 #ifdef HAVE_NS
3940 || !strcmp(SDATA(lower), "yes")
3941 #endif
3942 || !strcmp (SDATA (lower), "true"))
3943 return Qt;
3944 else if (!strcmp (SDATA (lower), "off")
3945 #ifdef HAVE_NS
3946 || !strcmp(SDATA(lower), "no")
3947 #endif
3948 || !strcmp (SDATA (lower), "false"))
3949 return Qnil;
3950 else
3951 return Fintern (tem, Qnil);
3952 }
3953
3954 default:
3955 abort ();
3956 }
3957 }
3958 else
3959 return Qunbound;
3960 }
3961 return Fcdr (tem);
3962 }
3963
3964 Lisp_Object
3965 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param, char *attribute, char *class, enum resource_types type)
3966 {
3967 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3968 alist, param, attribute, class, type);
3969 }
3970
3971 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3972
3973 Lisp_Object
3974 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist, Lisp_Object param, char *attribute, char *class, enum resource_types type)
3975 {
3976 Lisp_Object value;
3977
3978 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3979 attribute, class, type);
3980 if (! NILP (value) && ! EQ (value, Qunbound))
3981 store_frame_param (f, param, value);
3982
3983 return value;
3984 }
3985
3986
3987 /* Record in frame F the specified or default value according to ALIST
3988 of the parameter named PROP (a Lisp symbol).
3989 If no value is specified for PROP, look for an X default for XPROP
3990 on the frame named NAME.
3991 If that is not found either, use the value DEFLT. */
3992
3993 Lisp_Object
3994 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop, Lisp_Object deflt, char *xprop, char *xclass, 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) */