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