1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2003, 2004, 2005
3 Free Software Foundation.
5 This file is part of GNU Emacs.
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 2, or (at your option)
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.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
37 /* These help us bind and responding to switch-frame events. */
41 #ifdef HAVE_WINDOW_SYSTEM
44 #include "blockinput.h"
46 #include "termhooks.h"
47 #include "dispextern.h"
55 #ifdef HAVE_WINDOW_SYSTEM
57 /* The name we're using in resource queries. Most often "emacs". */
59 Lisp_Object Vx_resource_name
;
61 /* The application class we're using in resource queries.
64 Lisp_Object Vx_resource_class
;
68 Lisp_Object Qframep
, Qframe_live_p
;
69 Lisp_Object Qicon
, Qmodeline
;
71 Lisp_Object Qx
, Qw32
, Qmac
, Qpc
;
73 Lisp_Object Qdisplay_type
;
74 Lisp_Object Qbackground_mode
;
75 Lisp_Object Qinhibit_default_face_x_resources
;
77 Lisp_Object Qx_frame_parameter
;
78 Lisp_Object Qx_resource_name
;
79 Lisp_Object Qdisplay_id
;
80 Lisp_Object Qdisplay_live_p
;
82 /* Frame parameters (set or reported). */
84 Lisp_Object Qauto_raise
, Qauto_lower
;
85 Lisp_Object Qborder_color
, Qborder_width
;
86 Lisp_Object Qcursor_color
, Qcursor_type
;
87 Lisp_Object Qgeometry
; /* Not used */
88 Lisp_Object Qheight
, Qwidth
;
89 Lisp_Object Qleft
, Qright
;
90 Lisp_Object Qicon_left
, Qicon_top
, Qicon_type
, Qicon_name
;
91 Lisp_Object Qinternal_border_width
;
92 Lisp_Object Qmouse_color
;
93 Lisp_Object Qminibuffer
;
94 Lisp_Object Qscroll_bar_width
, Qvertical_scroll_bars
;
95 Lisp_Object Qvisibility
;
96 Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
97 Lisp_Object Qscreen_gamma
;
98 Lisp_Object Qline_spacing
;
99 Lisp_Object Quser_position
, Quser_size
;
100 Lisp_Object Qwait_for_wm
;
101 Lisp_Object Qwindow_id
;
102 #ifdef HAVE_X_WINDOWS
103 Lisp_Object Qouter_window_id
;
105 Lisp_Object Qparent_id
;
106 Lisp_Object Qtitle
, Qname
;
107 Lisp_Object Qunsplittable
;
108 Lisp_Object Qmenu_bar_lines
, Qtool_bar_lines
;
109 Lisp_Object Qleft_fringe
, Qright_fringe
;
110 Lisp_Object Qbuffer_predicate
, Qbuffer_list
;
111 Lisp_Object Qtty_color_mode
;
112 Lisp_Object Qtty
, Qtty_type
;
113 Lisp_Object Qwindow_system
;
115 Lisp_Object Qfullscreen
, Qfullwidth
, Qfullheight
, Qfullboth
;
117 Lisp_Object Qface_set_after_frame_default
;
119 Lisp_Object Vterminal_frame
;
120 Lisp_Object Vdefault_frame_alist
;
121 Lisp_Object Vdefault_frame_scroll_bars
;
122 Lisp_Object Vmouse_position_function
;
123 Lisp_Object Vmouse_highlight
;
124 Lisp_Object Vdelete_frame_functions
;
127 set_menu_bar_lines_1 (window
, n
)
131 struct window
*w
= XWINDOW (window
);
133 XSETFASTINT (w
->last_modified
, 0);
134 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
135 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
137 if (INTEGERP (w
->orig_top_line
))
138 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
139 if (INTEGERP (w
->orig_total_lines
))
140 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
142 /* Handle just the top child in a vertical split. */
143 if (!NILP (w
->vchild
))
144 set_menu_bar_lines_1 (w
->vchild
, n
);
146 /* Adjust all children in a horizontal split. */
147 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
149 w
= XWINDOW (window
);
150 set_menu_bar_lines_1 (window
, n
);
155 set_menu_bar_lines (f
, value
, oldval
)
157 Lisp_Object value
, oldval
;
160 int olines
= FRAME_MENU_BAR_LINES (f
);
162 /* Right now, menu bars don't work properly in minibuf-only frames;
163 most of the commands try to apply themselves to the minibuffer
164 frame itself, and get an error because you can't switch buffers
165 in or split the minibuffer window. */
166 if (FRAME_MINIBUF_ONLY_P (f
))
169 if (INTEGERP (value
))
170 nlines
= XINT (value
);
174 if (nlines
!= olines
)
176 windows_or_buffers_changed
++;
177 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
178 FRAME_MENU_BAR_LINES (f
) = nlines
;
179 set_menu_bar_lines_1 (f
->root_window
, nlines
- olines
);
184 Lisp_Object Vemacs_iconified
;
185 Lisp_Object Vframe_list
;
187 extern Lisp_Object Vminibuffer_list
;
188 extern Lisp_Object
get_minibuffer ();
189 extern Lisp_Object
Fhandle_switch_frame ();
190 extern Lisp_Object
Fredirect_frame_focus ();
191 extern Lisp_Object
x_get_focus_frame ();
193 DEFUN ("framep", Fframep
, Sframep
, 1, 1, 0,
194 doc
: /* Return non-nil if OBJECT is a frame.
195 Value is t for a termcap frame (a character-only terminal),
196 `x' for an Emacs frame that is really an X window,
197 `w32' for an Emacs frame that is a window on MS-Windows display,
198 `mac' for an Emacs frame on a Macintosh display,
199 `pc' for a direct-write MS-DOS frame.
200 See also `frame-live-p'. */)
204 if (!FRAMEP (object
))
206 switch (XFRAME (object
)->output_method
)
208 case output_initial
: /* The initial frame is like a termcap frame. */
211 case output_x_window
:
215 case output_msdos_raw
:
224 DEFUN ("frame-live-p", Fframe_live_p
, Sframe_live_p
, 1, 1, 0,
225 doc
: /* Return non-nil if OBJECT is a frame which has not been deleted.
226 Value is nil if OBJECT is not a live frame. If object is a live
227 frame, the return value indicates what sort of output device it is
228 displayed on. See the documentation of `framep' for possible
233 return ((FRAMEP (object
)
234 && FRAME_LIVE_P (XFRAME (object
)))
239 DEFUN ("window-system", Fwindow_system
, Swindow_system
, 0, 1, 0,
240 doc
: /* The name of the window system that FRAME is displaying through.
241 The value is a symbol---for instance, 'x' for X windows.
242 The value is nil if Emacs is using a text-only terminal.
244 FRAME defaults to the currently selected frame. */)
250 frame
= selected_frame
;
252 type
= Fframep (frame
);
255 wrong_type_argument (Qframep
, frame
);
268 register struct frame
*f
;
269 register Lisp_Object root_window
;
270 register Lisp_Object mini_window
;
272 f
= allocate_frame ();
273 XSETFRAME (frame
, f
);
275 f
->desired_matrix
= 0;
276 f
->current_matrix
= 0;
279 f
->glyphs_initialized_p
= 0;
280 f
->decode_mode_spec_buffer
= 0;
282 f
->async_visible
= 0;
283 f
->output_data
.nothing
= 0;
285 f
->async_iconified
= 0;
286 f
->wants_modeline
= 1;
291 f
->has_minibuffer
= mini_p
;
292 f
->focus_frame
= Qnil
;
293 f
->explicit_name
= 0;
294 f
->can_have_scroll_bars
= 0;
295 f
->vertical_scroll_bar_type
= vertical_scroll_bar_none
;
296 f
->param_alist
= Qnil
;
297 f
->scroll_bars
= Qnil
;
298 f
->condemned_scroll_bars
= Qnil
;
299 f
->face_alist
= Qnil
;
300 f
->face_cache
= NULL
;
301 f
->menu_bar_items
= Qnil
;
302 f
->menu_bar_vector
= Qnil
;
303 f
->menu_bar_items_used
= 0;
304 f
->buffer_predicate
= Qnil
;
305 f
->buffer_list
= Qnil
;
307 f
->kboard
= initial_kboard
;
311 f
->menu_bar_window
= Qnil
;
312 f
->tool_bar_window
= Qnil
;
313 f
->tool_bar_items
= Qnil
;
314 f
->desired_tool_bar_string
= f
->current_tool_bar_string
= Qnil
;
315 f
->n_tool_bar_items
= 0;
316 f
->left_fringe_width
= f
->right_fringe_width
= 0;
318 f
->scroll_bar_actual_width
= 0;
320 f
->internal_border_width
= 0;
321 f
->column_width
= 1; /* !FRAME_WINDOW_P value */
322 f
->line_height
= 1; /* !FRAME_WINDOW_P value */
323 f
->x_pixels_diff
= f
->y_pixels_diff
= 0;
324 #ifdef HAVE_WINDOW_SYSTEM
325 f
->want_fullscreen
= FULLSCREEN_NONE
;
327 f
->size_hint_flags
= 0;
330 root_window
= make_window ();
333 mini_window
= make_window ();
334 XWINDOW (root_window
)->next
= mini_window
;
335 XWINDOW (mini_window
)->prev
= root_window
;
336 XWINDOW (mini_window
)->mini_p
= Qt
;
337 XWINDOW (mini_window
)->frame
= frame
;
338 f
->minibuffer_window
= mini_window
;
343 XWINDOW (root_window
)->next
= Qnil
;
344 f
->minibuffer_window
= Qnil
;
347 XWINDOW (root_window
)->frame
= frame
;
350 just so that there is "something there."
351 Correct size will be set up later with change_frame_size. */
353 SET_FRAME_COLS (f
, 10);
354 FRAME_LINES (f
) = 10;
356 XSETFASTINT (XWINDOW (root_window
)->total_cols
, 10);
357 XSETFASTINT (XWINDOW (root_window
)->total_lines
, (mini_p
? 9 : 10));
361 XSETFASTINT (XWINDOW (mini_window
)->total_cols
, 10);
362 XSETFASTINT (XWINDOW (mini_window
)->top_line
, 9);
363 XSETFASTINT (XWINDOW (mini_window
)->total_lines
, 1);
366 /* Choose a buffer for the frame's root window. */
370 XWINDOW (root_window
)->buffer
= Qt
;
371 buf
= Fcurrent_buffer ();
372 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
373 a space), try to find another one. */
374 if (SREF (Fbuffer_name (buf
), 0) == ' ')
375 buf
= Fother_buffer (buf
, Qnil
, Qnil
);
377 /* Use set_window_buffer, not Fset_window_buffer, and don't let
378 hooks be run by it. The reason is that the whole frame/window
379 arrangement is not yet fully intialized at this point. Windows
380 don't have the right size, glyph matrices aren't initialized
381 etc. Running Lisp functions at this point surely ends in a
383 set_window_buffer (root_window
, buf
, 0, 0);
384 f
->buffer_list
= Fcons (buf
, Qnil
);
389 XWINDOW (mini_window
)->buffer
= Qt
;
390 set_window_buffer (mini_window
,
391 (NILP (Vminibuffer_list
)
393 : Fcar (Vminibuffer_list
)),
397 f
->root_window
= root_window
;
398 f
->selected_window
= root_window
;
399 /* Make sure this window seems more recently used than
400 a newly-created, never-selected window. */
401 ++window_select_count
;
402 XSETFASTINT (XWINDOW (f
->selected_window
)->use_time
, window_select_count
);
404 f
->default_face_done_p
= 0;
409 #ifdef HAVE_WINDOW_SYSTEM
410 /* Make a frame using a separate minibuffer window on another frame.
411 MINI_WINDOW is the minibuffer window to use. nil means use the
412 default (the global minibuffer). */
415 make_frame_without_minibuffer (mini_window
, kb
, display
)
416 register Lisp_Object mini_window
;
420 register struct frame
*f
;
423 if (!NILP (mini_window
))
424 CHECK_LIVE_WINDOW (mini_window
);
427 if (!NILP (mini_window
)
428 && XFRAME (XWINDOW (mini_window
)->frame
)->kboard
!= kb
)
429 error ("frame and minibuffer must be on the same display");
432 /* Make a frame containing just a root window. */
435 if (NILP (mini_window
))
437 /* Use default-minibuffer-frame if possible. */
438 if (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
439 || ! FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
)))
441 Lisp_Object frame_dummy
;
443 XSETFRAME (frame_dummy
, f
);
444 GCPRO1 (frame_dummy
);
445 /* If there's no minibuffer frame to use, create one. */
446 kb
->Vdefault_minibuffer_frame
=
447 call1 (intern ("make-initial-minibuffer-frame"), display
);
451 mini_window
= XFRAME (kb
->Vdefault_minibuffer_frame
)->minibuffer_window
;
454 f
->minibuffer_window
= mini_window
;
456 /* Make the chosen minibuffer window display the proper minibuffer,
457 unless it is already showing a minibuffer. */
458 if (NILP (Fmemq (XWINDOW (mini_window
)->buffer
, Vminibuffer_list
)))
459 Fset_window_buffer (mini_window
,
460 (NILP (Vminibuffer_list
)
462 : Fcar (Vminibuffer_list
)), Qnil
);
466 /* Make a frame containing only a minibuffer window. */
469 make_minibuffer_frame ()
471 /* First make a frame containing just a root window, no minibuffer. */
473 register struct frame
*f
= make_frame (0);
474 register Lisp_Object mini_window
;
475 register Lisp_Object frame
;
477 XSETFRAME (frame
, f
);
482 f
->wants_modeline
= 0;
483 f
->has_minibuffer
= 1;
485 /* Now label the root window as also being the minibuffer.
486 Avoid infinite looping on the window chain by marking next pointer
489 mini_window
= f
->minibuffer_window
= f
->root_window
;
490 XWINDOW (mini_window
)->mini_p
= Qt
;
491 XWINDOW (mini_window
)->next
= Qnil
;
492 XWINDOW (mini_window
)->prev
= Qnil
;
493 XWINDOW (mini_window
)->frame
= frame
;
495 /* Put the proper buffer in that window. */
497 Fset_window_buffer (mini_window
,
498 (NILP (Vminibuffer_list
)
500 : Fcar (Vminibuffer_list
)), Qnil
);
503 #endif /* HAVE_WINDOW_SYSTEM */
505 /* Construct a frame that refers to a terminal. */
507 static int terminal_frame_count
;
510 make_initial_frame (void)
513 struct display
*display
;
517 /* Create the initial keyboard. */
520 initial_kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
521 init_kboard (initial_kboard
);
522 initial_kboard
->next_kboard
= all_kboards
;
523 all_kboards
= initial_kboard
;
527 /* The first call must initialize Vframe_list. */
528 if (! (NILP (Vframe_list
) || CONSP (Vframe_list
)))
531 display
= init_initial_display ();
534 XSETFRAME (frame
, f
);
536 Vframe_list
= Fcons (frame
, Vframe_list
);
538 terminal_frame_count
= 1;
539 f
->name
= build_string ("F1");
542 f
->async_visible
= 1;
544 f
->output_method
= display
->type
;
545 f
->display
= display
;
546 f
->display
->reference_count
++;
547 f
->output_data
.nothing
= 0;
549 FRAME_FOREGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_FG_COLOR
;
550 FRAME_BACKGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_BG_COLOR
;
552 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
553 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
;
556 f
->kboard
= initial_kboard
;
564 make_terminal_frame (struct display
*display
)
566 register struct frame
*f
;
572 XSETFRAME (frame
, f
);
573 Vframe_list
= Fcons (frame
, Vframe_list
);
575 terminal_frame_count
++;
576 sprintf (name
, "F%d", terminal_frame_count
);
577 f
->name
= build_string (name
);
579 f
->visible
= 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
580 f
->async_visible
= 1; /* Don't let visible be cleared later. */
582 f
->output_data
.x
= &the_only_x_display
;
583 if (!inhibit_window_system
584 && (!FRAMEP (selected_frame
) || !FRAME_LIVE_P (XFRAME (selected_frame
))
585 || XFRAME (selected_frame
)->output_method
== output_msdos_raw
))
587 f
->output_method
= output_msdos_raw
;
588 /* This initialization of foreground and background pixels is
589 only important for the initial frame created in temacs. If
590 we don't do that, we get black background and foreground in
591 the dumped Emacs because the_only_x_display is a static
592 variable, hence it is born all-zeroes, and zero is the code
593 for the black color. Other frames all inherit their pixels
594 from what's already in the_only_x_display. */
595 if ((!FRAMEP (selected_frame
) || !FRAME_LIVE_P (XFRAME (selected_frame
)))
596 && f
->output_data
.x
->background_pixel
== 0
597 && f
->output_data
.x
->foreground_pixel
== 0)
599 f
->output_data
.x
->background_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
600 f
->output_data
.x
->foreground_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
604 f
->output_method
= output_termcap
;
607 f
->output_method
= output_termcap
;
608 f
->output_data
.x
= &tty_display
; /* XXX ??? */
611 make_mac_terminal_frame (f
);
614 f
->output_method
= output_termcap
;
615 f
->display
= display
;
616 f
->display
->reference_count
++;
617 create_tty_output (f
);
619 FRAME_FOREGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_FG_COLOR
;
620 FRAME_BACKGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_BG_COLOR
;
622 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
623 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
;
626 f
->kboard
= FRAME_TTY (f
)->kboard
;
629 /* Set the top frame to the newly created frame. */
630 if (FRAME_TTY (f
)->top_frame
631 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f
)->top_frame
)))
632 XFRAME (FRAME_TTY (f
)->top_frame
)->async_visible
= 2; /* obscured */
634 FRAME_TTY (f
)->top_frame
= frame
;
638 FRAME_FOREGROUND_PIXEL(f
) = FACE_TTY_DEFAULT_FG_COLOR
;
639 FRAME_BACKGROUND_PIXEL(f
) = FACE_TTY_DEFAULT_BG_COLOR
;
642 #endif /* WINDOWSNT */
646 init_frame_faces (f
);
651 DEFUN ("make-terminal-frame", Fmake_terminal_frame
, Smake_terminal_frame
,
653 doc
: /* Create an additional terminal frame, possibly on another terminal.
654 This function takes one argument, an alist specifying frame parameters.
656 You can create multiple frames on a single text-only terminal, but
657 only one of them (the selected terminal frame) is actually displayed.
659 In practice, generally you don't need to specify any parameters,
660 except when you want to create a new frame on another terminal.
661 In that case, the `tty' parameter specifies the device file to open,
662 and the `tty-type' parameter specifies the terminal type. Example:
664 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
666 Note that changing the size of one terminal frame automatically
667 affects all frames on the same terminal device. */)
672 struct display
*d
= NULL
;
673 Lisp_Object frame
, tem
;
674 struct frame
*sf
= SELECTED_FRAME ();
677 if (sf
->output_method
!= output_msdos_raw
678 && sf
->output_method
!= output_termcap
)
680 #else /* not MSDOS */
683 if (sf
->output_method
!= output_mac
)
684 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
686 #if 0 /* This should work now! */
687 if (sf
->output_method
!= output_termcap
)
688 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
691 #endif /* not MSDOS */
694 Lisp_Object display_device
;
696 display_device
= Fassq (Qdisplay_id
, parms
);
697 if (!NILP (display_device
))
699 display_device
= XCDR (display_device
);
700 CHECK_NUMBER (display_device
);
701 d
= get_display (XINT (display_device
));
703 wrong_type_argument (Qdisplay_live_p
, display_device
);
709 Lisp_Object tty
, tty_type
;
710 char *name
= 0, *type
= 0;
712 tty
= Fassq (Qtty
, parms
);
714 tty
= Fassq (Qtty
, XFRAME (selected_frame
)->param_alist
);
715 if (EQ (tty
, Qnil
) && FRAME_TERMCAP_P (XFRAME (selected_frame
))
716 && FRAME_TTY (XFRAME (selected_frame
))->name
)
717 tty
= build_string (FRAME_TTY (XFRAME (selected_frame
))->name
);
719 tty
= Fassq (Qtty
, Vdefault_frame_alist
);
720 if (! EQ (tty
, Qnil
) && ! STRINGP (tty
))
722 if (EQ (tty
, Qnil
) || !STRINGP (tty
))
725 tty_type
= Fassq (Qtty_type
, parms
);
726 if (EQ (tty_type
, Qnil
))
727 tty_type
= Fassq (Qtty
, XFRAME (selected_frame
)->param_alist
);
728 if (EQ (tty_type
, Qnil
) && FRAME_TERMCAP_P (XFRAME (selected_frame
))
729 && FRAME_TTY (XFRAME (selected_frame
))->type
)
730 tty_type
= build_string (FRAME_TTY (XFRAME (selected_frame
))->type
);
731 if (EQ (tty_type
, Qnil
))
732 tty_type
= Fassq (Qtty_type
, Vdefault_frame_alist
);
733 if (! EQ (tty_type
, Qnil
) && ! STRINGP (tty_type
))
734 tty_type
= XCDR (tty_type
);
735 if (EQ (tty_type
, Qnil
) || !STRINGP (tty_type
))
738 if (! EQ (tty
, Qnil
))
740 name
= (char *) alloca (SBYTES (tty
) + 1);
741 strncpy (name
, SDATA (tty
), SBYTES (tty
));
742 name
[SBYTES (tty
)] = 0;
745 if (! EQ (tty_type
, Qnil
))
747 type
= (char *) alloca (SBYTES (tty_type
) + 1);
748 strncpy (type
, SDATA (tty_type
), SBYTES (tty_type
));
749 type
[SBYTES (tty_type
)] = 0;
752 d
= term_init (name
, type
, 0); /* Errors are not fatal. */
755 f
= make_terminal_frame (d
);
759 get_tty_size (fileno (FRAME_TTY (f
)->input
), &width
, &height
);
760 change_frame_size (f
, height
, width
, 0, 0, 0);
765 XSETFRAME (frame
, f
);
766 Fmodify_frame_parameters (frame
, Vdefault_frame_alist
);
767 Fmodify_frame_parameters (frame
, parms
);
768 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qwindow_system
, Qnil
), Qnil
));
770 /* Make the frame face alist be frame-specific, so that each
771 frame could change its face definitions independently. */
772 f
->face_alist
= Fcopy_alist (sf
->face_alist
);
773 /* Simple Fcopy_alist isn't enough, because we need the contents of
774 the vectors which are the CDRs of associations in face_alist to
775 be copied as well. */
776 for (tem
= f
->face_alist
; CONSP (tem
); tem
= XCDR (tem
))
777 XSETCDR (XCAR (tem
), Fcopy_sequence (XCDR (XCAR (tem
))));
782 /* Perform the switch to frame FRAME.
784 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
787 If TRACK is non-zero and the frame that currently has the focus
788 redirects its focus to the selected frame, redirect that focused
789 frame's focus to FRAME instead.
791 FOR_DELETION non-zero means that the selected frame is being
792 deleted, which includes the possibility that the frame's display
796 do_switch_frame (frame
, track
, for_deletion
)
798 int track
, for_deletion
;
800 struct frame
*sf
= SELECTED_FRAME ();
802 /* If FRAME is a switch-frame event, extract the frame we should
805 && EQ (XCAR (frame
), Qswitch_frame
)
806 && CONSP (XCDR (frame
)))
807 frame
= XCAR (XCDR (frame
));
809 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
810 a switch-frame event to arrive after a frame is no longer live,
811 especially when deleting the initial frame during startup. */
813 if (! FRAME_LIVE_P (XFRAME (frame
)))
816 if (sf
== XFRAME (frame
))
819 /* This is too greedy; it causes inappropriate focus redirection
820 that's hard to get rid of. */
822 /* If a frame's focus has been redirected toward the currently
823 selected frame, we should change the redirection to point to the
824 newly selected frame. This means that if the focus is redirected
825 from a minibufferless frame to a surrogate minibuffer frame, we
826 can use `other-window' to switch between all the frames using
827 that minibuffer frame, and the focus redirection will follow us
833 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
837 if (!FRAMEP (XCAR (tail
)))
840 focus
= FRAME_FOCUS_FRAME (XFRAME (XCAR (tail
)));
842 if (FRAMEP (focus
) && XFRAME (focus
) == SELECTED_FRAME ())
843 Fredirect_frame_focus (XCAR (tail
), frame
);
847 /* Instead, apply it only to the frame we're pointing to. */
848 #ifdef HAVE_WINDOW_SYSTEM
849 if (track
&& FRAME_WINDOW_P (XFRAME (frame
)))
851 Lisp_Object focus
, xfocus
;
853 xfocus
= x_get_focus_frame (XFRAME (frame
));
856 focus
= FRAME_FOCUS_FRAME (XFRAME (xfocus
));
857 if (FRAMEP (focus
) && XFRAME (focus
) == SELECTED_FRAME ())
858 Fredirect_frame_focus (xfocus
, frame
);
861 #endif /* HAVE_X_WINDOWS */
864 if (!for_deletion
&& FRAME_HAS_MINIBUF_P (sf
))
865 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf
)), 1);
867 if (FRAME_TERMCAP_P (XFRAME (selected_frame
))
868 && FRAME_TERMCAP_P (XFRAME (frame
))
869 && FRAME_TTY (XFRAME (selected_frame
)) == FRAME_TTY (XFRAME (frame
)))
871 XFRAME (selected_frame
)->async_visible
= 2; /* obscured */
872 XFRAME (frame
)->async_visible
= 1;
873 FRAME_TTY (XFRAME (frame
))->top_frame
= frame
;
876 selected_frame
= frame
;
877 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame
)))
878 last_nonminibuf_frame
= XFRAME (selected_frame
);
880 Fselect_window (XFRAME (frame
)->selected_window
, Qnil
);
883 /* Make sure to switch the tty color mode to that of the newly
885 sf
= SELECTED_FRAME ();
886 if (FRAME_TERMCAP_P (sf
))
888 Lisp_Object color_mode_spec
, color_mode
;
890 color_mode_spec
= assq_no_quit (Qtty_color_mode
, sf
->param_alist
);
891 if (CONSP (color_mode_spec
))
892 color_mode
= XCDR (color_mode_spec
);
894 color_mode
= make_number (0);
895 set_tty_color_mode (sf
, color_mode
);
897 #endif /* !WINDOWSNT */
899 /* We want to make sure that the next event generates a frame-switch
900 event to the appropriate frame. This seems kludgy to me, but
901 before you take it out, make sure that evaluating something like
902 (select-window (frame-root-window (new-frame))) doesn't end up
903 with your typing being interpreted in the new frame instead of
904 the one you're actually typing in. */
905 internal_last_event_frame
= Qnil
;
910 DEFUN ("select-frame", Fselect_frame
, Sselect_frame
, 1, 2, "e",
911 doc
: /* Select the frame FRAME.
912 Subsequent editing commands apply to its selected window.
913 The selection of FRAME lasts until the next time the user does
914 something to select a different frame, or until the next time this
915 function is called. If you are using a window system, the previously
916 selected frame may be restored as the selected frame after return to
917 the command loop, because it still may have the window system's input
918 focus. On a text-only terminal, the next redisplay will display FRAME.
920 This function returns FRAME, or nil if FRAME has been deleted. */)
922 Lisp_Object frame
, no_enter
;
924 return do_switch_frame (frame
, 1, 0);
928 DEFUN ("handle-switch-frame", Fhandle_switch_frame
, Shandle_switch_frame
, 1, 2, "e",
929 doc
: /* Handle a switch-frame event EVENT.
930 Switch-frame events are usually bound to this function.
931 A switch-frame event tells Emacs that the window manager has requested
932 that the user's events be directed to the frame mentioned in the event.
933 This function selects the selected window of the frame of EVENT.
935 If EVENT is frame object, handle it as if it were a switch-frame event
938 Lisp_Object event
, no_enter
;
940 /* Preserve prefix arg that the command loop just cleared. */
941 current_kboard
->Vprefix_arg
= Vcurrent_prefix_arg
;
942 call1 (Vrun_hooks
, Qmouse_leave_buffer_hook
);
943 return do_switch_frame (event
, 0, 0);
946 DEFUN ("selected-frame", Fselected_frame
, Sselected_frame
, 0, 0, 0,
947 doc
: /* Return the frame that is now selected. */)
950 return selected_frame
;
953 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
954 doc
: /* Return the frame object that window WINDOW is on. */)
958 CHECK_LIVE_WINDOW (window
);
959 return XWINDOW (window
)->frame
;
962 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
963 doc
: /* Returns the topmost, leftmost window of FRAME.
964 If omitted, FRAME defaults to the currently selected frame. */)
971 w
= SELECTED_FRAME ()->root_window
;
974 CHECK_LIVE_FRAME (frame
);
975 w
= XFRAME (frame
)->root_window
;
977 while (NILP (XWINDOW (w
)->buffer
))
979 if (! NILP (XWINDOW (w
)->hchild
))
980 w
= XWINDOW (w
)->hchild
;
981 else if (! NILP (XWINDOW (w
)->vchild
))
982 w
= XWINDOW (w
)->vchild
;
989 DEFUN ("active-minibuffer-window", Factive_minibuffer_window
,
990 Sactive_minibuffer_window
, 0, 0, 0,
991 doc
: /* Return the currently active minibuffer window, or nil if none. */)
994 return minibuf_level
? minibuf_window
: Qnil
;
997 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
998 doc
: /* Returns the root-window of FRAME.
999 If omitted, FRAME defaults to the currently selected frame. */)
1006 window
= SELECTED_FRAME ()->root_window
;
1009 CHECK_LIVE_FRAME (frame
);
1010 window
= XFRAME (frame
)->root_window
;
1016 DEFUN ("frame-selected-window", Fframe_selected_window
,
1017 Sframe_selected_window
, 0, 1, 0,
1018 doc
: /* Return the selected window of frame object FRAME.
1019 If omitted, FRAME defaults to the currently selected frame. */)
1026 window
= SELECTED_FRAME ()->selected_window
;
1029 CHECK_LIVE_FRAME (frame
);
1030 window
= XFRAME (frame
)->selected_window
;
1036 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
1037 Sset_frame_selected_window
, 2, 2, 0,
1038 doc
: /* Set the selected window of frame object FRAME to WINDOW.
1040 If FRAME is nil, the selected frame is used.
1041 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1043 Lisp_Object frame
, window
;
1046 frame
= selected_frame
;
1048 CHECK_LIVE_FRAME (frame
);
1049 CHECK_LIVE_WINDOW (window
);
1051 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
1052 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1054 if (EQ (frame
, selected_frame
))
1055 return Fselect_window (window
, Qnil
);
1057 return XFRAME (frame
)->selected_window
= window
;
1061 DEFUN ("frame-display", Fframe_display
, Sframe_display
, 0, 1, 0,
1062 doc
: /* Return the display device that FRAME is displayed on.
1063 If FRAME is nil, the selected frame is used.
1065 The display device is represented by its integer identifier. */)
1072 frame
= selected_frame
;
1074 CHECK_LIVE_FRAME (frame
);
1076 d
= get_display (frame
);
1081 return make_number (d
->id
);
1085 DEFUN ("frame-list", Fframe_list
, Sframe_list
,
1087 doc
: /* Return a list of all frames. */)
1091 frames
= Fcopy_sequence (Vframe_list
);
1092 #ifdef HAVE_WINDOW_SYSTEM
1093 if (FRAMEP (tip_frame
))
1094 frames
= Fdelq (tip_frame
, frames
);
1099 /* Return the next frame in the frame list after FRAME.
1100 If MINIBUF is nil, exclude minibuffer-only frames.
1101 If MINIBUF is a window, include only its own frame
1102 and any frame now using that window as the minibuffer.
1103 If MINIBUF is `visible', include all visible frames.
1104 If MINIBUF is 0, include all visible and iconified frames.
1105 Otherwise, include all frames. */
1108 next_frame (frame
, minibuf
)
1110 Lisp_Object minibuf
;
1115 /* There must always be at least one frame in Vframe_list. */
1116 if (! CONSP (Vframe_list
))
1119 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1120 forever. Forestall that. */
1121 CHECK_LIVE_FRAME (frame
);
1124 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1131 && ((!FRAME_TERMCAP_P (XFRAME (f
)) && !FRAME_TERMCAP_P (XFRAME (frame
))
1132 && FRAME_KBOARD (XFRAME (f
)) == FRAME_KBOARD (XFRAME (frame
)))
1133 || (FRAME_TERMCAP_P (XFRAME (f
)) && FRAME_TERMCAP_P (XFRAME (frame
))
1134 && FRAME_TTY (XFRAME (f
)) == FRAME_TTY (XFRAME (frame
)))))
1136 /* Decide whether this frame is eligible to be returned. */
1138 /* If we've looped all the way around without finding any
1139 eligible frames, return the original frame. */
1143 /* Let minibuf decide if this frame is acceptable. */
1146 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f
)))
1149 else if (EQ (minibuf
, Qvisible
))
1151 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
1152 if (FRAME_VISIBLE_P (XFRAME (f
)))
1155 else if (INTEGERP (minibuf
) && XINT (minibuf
) == 0)
1157 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
1158 if (FRAME_VISIBLE_P (XFRAME (f
))
1159 || FRAME_ICONIFIED_P (XFRAME (f
)))
1162 else if (WINDOWP (minibuf
))
1164 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f
)), minibuf
)
1165 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)), f
)
1166 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)),
1167 FRAME_FOCUS_FRAME (XFRAME (f
))))
1179 /* Return the previous frame in the frame list before FRAME.
1180 If MINIBUF is nil, exclude minibuffer-only frames.
1181 If MINIBUF is a window, include only its own frame
1182 and any frame now using that window as the minibuffer.
1183 If MINIBUF is `visible', include all visible frames.
1184 If MINIBUF is 0, include all visible and iconified frames.
1185 Otherwise, include all frames. */
1188 prev_frame (frame
, minibuf
)
1190 Lisp_Object minibuf
;
1195 /* There must always be at least one frame in Vframe_list. */
1196 if (! CONSP (Vframe_list
))
1200 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1208 if (EQ (frame
, f
) && !NILP (prev
))
1211 if ((!FRAME_TERMCAP_P (XFRAME (f
)) && !FRAME_TERMCAP_P (XFRAME (frame
))
1212 && FRAME_KBOARD (XFRAME (f
)) == FRAME_KBOARD (XFRAME (frame
)))
1213 || (FRAME_TERMCAP_P (XFRAME (f
)) && FRAME_TERMCAP_P (XFRAME (frame
))
1214 && FRAME_TTY (XFRAME (f
)) == FRAME_TTY (XFRAME (frame
))))
1216 /* Decide whether this frame is eligible to be returned,
1217 according to minibuf. */
1220 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f
)))
1223 else if (WINDOWP (minibuf
))
1225 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f
)), minibuf
)
1226 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)), f
)
1227 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)),
1228 FRAME_FOCUS_FRAME (XFRAME (f
))))
1231 else if (EQ (minibuf
, Qvisible
))
1233 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
1234 if (FRAME_VISIBLE_P (XFRAME (f
)))
1237 else if (XFASTINT (minibuf
) == 0)
1239 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
1240 if (FRAME_VISIBLE_P (XFRAME (f
))
1241 || FRAME_ICONIFIED_P (XFRAME (f
)))
1249 /* We've scanned the entire list. */
1251 /* We went through the whole frame list without finding a single
1252 acceptable frame. Return the original frame. */
1255 /* There were no acceptable frames in the list before FRAME; otherwise,
1256 we would have returned directly from the loop. Since PREV is the last
1257 acceptable frame in the list, return it. */
1262 DEFUN ("next-frame", Fnext_frame
, Snext_frame
, 0, 2, 0,
1263 doc
: /* Return the next frame in the frame list after FRAME.
1264 It considers only frames on the same terminal as FRAME.
1265 By default, skip minibuffer-only frames.
1266 If omitted, FRAME defaults to the selected frame.
1267 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1268 If MINIFRAME is a window, include only its own frame
1269 and any frame now using that window as the minibuffer.
1270 If MINIFRAME is `visible', include all visible frames.
1271 If MINIFRAME is 0, include all visible and iconified frames.
1272 Otherwise, include all frames. */)
1274 Lisp_Object frame
, miniframe
;
1277 frame
= selected_frame
;
1279 CHECK_LIVE_FRAME (frame
);
1280 return next_frame (frame
, miniframe
);
1283 DEFUN ("previous-frame", Fprevious_frame
, Sprevious_frame
, 0, 2, 0,
1284 doc
: /* Return the previous frame in the frame list before FRAME.
1285 It considers only frames on the same terminal as FRAME.
1286 By default, skip minibuffer-only frames.
1287 If omitted, FRAME defaults to the selected frame.
1288 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1289 If MINIFRAME is a window, include only its own frame
1290 and any frame now using that window as the minibuffer.
1291 If MINIFRAME is `visible', include all visible frames.
1292 If MINIFRAME is 0, include all visible and iconified frames.
1293 Otherwise, include all frames. */)
1295 Lisp_Object frame
, miniframe
;
1298 frame
= selected_frame
;
1299 CHECK_LIVE_FRAME (frame
);
1300 return prev_frame (frame
, miniframe
);
1303 /* Return 1 if it is ok to delete frame F;
1304 0 if all frames aside from F are invisible.
1305 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1308 other_visible_frames (f
)
1311 /* We know the selected frame is visible,
1312 so if F is some other frame, it can't be the sole visible one. */
1313 if (f
== SELECTED_FRAME ())
1318 for (frames
= Vframe_list
;
1320 frames
= XCDR (frames
))
1324 this = XCAR (frames
);
1325 /* Verify that the frame's window still exists
1326 and we can still talk to it. And note any recent change
1328 #ifdef HAVE_WINDOW_SYSTEM
1329 if (FRAME_WINDOW_P (XFRAME (this)))
1331 x_sync (XFRAME (this));
1332 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1336 if (FRAME_VISIBLE_P (XFRAME (this))
1337 || FRAME_ICONIFIED_P (XFRAME (this))
1338 /* Allow deleting the terminal frame when at least
1339 one X frame exists! */
1340 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f
)))
1348 DEFUN ("delete-frame", Fdelete_frame
, Sdelete_frame
, 0, 2, "",
1349 doc
: /* Delete FRAME, permanently eliminating it from use.
1350 If omitted, FRAME defaults to the selected frame.
1351 A frame may not be deleted if its minibuffer is used by other frames.
1352 Normally, you may not delete a frame if all other frames are invisible,
1353 but if the second optional argument FORCE is non-nil, you may do so.
1355 This function runs `delete-frame-functions' before actually deleting the
1356 frame, unless the frame is a tooltip.
1357 The functions are run with one arg, the frame to be deleted. */)
1359 Lisp_Object frame
, force
;
1362 struct frame
*sf
= SELECTED_FRAME ();
1363 int minibuffer_selected
;
1365 if (EQ (frame
, Qnil
))
1368 XSETFRAME (frame
, f
);
1372 CHECK_FRAME (frame
);
1376 if (! FRAME_LIVE_P (f
))
1379 if (NILP (force
) && !other_visible_frames (f
)
1381 /* Terminal frame deleted before any other visible frames are
1383 && strcmp (SDATA (f
->name
), "F1") != 0
1386 error ("Attempt to delete the sole visible or iconified frame");
1389 /* This is a nice idea, but x_connection_closed needs to be able
1390 to delete the last frame, if it is gone. */
1391 if (NILP (XCDR (Vframe_list
)))
1392 error ("Attempt to delete the only frame");
1395 /* Does this frame have a minibuffer, and is it the surrogate
1396 minibuffer for any other frame? */
1397 if (FRAME_HAS_MINIBUF_P (XFRAME (frame
)))
1401 for (frames
= Vframe_list
;
1403 frames
= XCDR (frames
))
1406 this = XCAR (frames
);
1408 if (! EQ (this, frame
)
1410 WINDOW_FRAME (XWINDOW
1411 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1412 error ("Attempt to delete a surrogate minibuffer frame");
1416 /* Run `delete-frame-functions' unless frame is a tooltip. */
1417 if (!NILP (Vrun_hooks
)
1418 && NILP (Fframe_parameter (frame
, intern ("tooltip"))))
1420 Lisp_Object args
[2];
1421 args
[0] = intern ("delete-frame-functions");
1423 Frun_hook_with_args (2, args
);
1426 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1427 if (! FRAME_LIVE_P (f
))
1430 minibuffer_selected
= EQ (minibuf_window
, selected_window
);
1432 /* Don't let the frame remain selected. */
1435 Lisp_Object tail
, frame1
;
1437 /* Look for another visible frame on the same terminal. */
1438 frame1
= next_frame (frame
, Qvisible
);
1440 /* If there is none, find *some* other frame. */
1441 if (NILP (frame1
) || EQ (frame1
, frame
))
1443 FOR_EACH_FRAME (tail
, frame1
)
1445 if (! EQ (frame
, frame1
) && FRAME_LIVE_P (XFRAME (frame1
)))
1450 do_switch_frame (frame1
, 0, 1);
1451 sf
= SELECTED_FRAME ();
1454 /* Don't allow minibuf_window to remain on a deleted frame. */
1455 if (EQ (f
->minibuffer_window
, minibuf_window
))
1457 Fset_window_buffer (sf
->minibuffer_window
,
1458 XWINDOW (minibuf_window
)->buffer
, Qnil
);
1459 minibuf_window
= sf
->minibuffer_window
;
1461 /* If the dying minibuffer window was selected,
1462 select the new one. */
1463 if (minibuffer_selected
)
1464 Fselect_window (minibuf_window
, Qnil
);
1467 /* Don't let echo_area_window to remain on a deleted frame. */
1468 if (EQ (f
->minibuffer_window
, echo_area_window
))
1469 echo_area_window
= sf
->minibuffer_window
;
1471 /* Clear any X selections for this frame. */
1472 #ifdef HAVE_X_WINDOWS
1474 x_clear_frame_selections (f
);
1478 This function must be called before the window tree of the
1479 frame is deleted because windows contain dynamically allocated
1483 /* Mark all the windows that used to be on FRAME as deleted, and then
1484 remove the reference to them. */
1485 delete_all_subwindows (XWINDOW (f
->root_window
));
1486 f
->root_window
= Qnil
;
1488 Vframe_list
= Fdelq (frame
, Vframe_list
);
1489 FRAME_SET_VISIBLE (f
, 0);
1493 if (f
->decode_mode_spec_buffer
)
1494 xfree (f
->decode_mode_spec_buffer
);
1495 if (FRAME_INSERT_COST (f
))
1496 xfree (FRAME_INSERT_COST (f
));
1497 if (FRAME_DELETEN_COST (f
))
1498 xfree (FRAME_DELETEN_COST (f
));
1499 if (FRAME_INSERTN_COST (f
))
1500 xfree (FRAME_INSERTN_COST (f
));
1501 if (FRAME_DELETE_COST (f
))
1502 xfree (FRAME_DELETE_COST (f
));
1503 if (FRAME_MESSAGE_BUF (f
))
1504 xfree (FRAME_MESSAGE_BUF (f
));
1506 /* Since some events are handled at the interrupt level, we may get
1507 an event for f at any time; if we zero out the frame's display
1508 now, then we may trip up the event-handling code. Instead, we'll
1509 promise that the display of the frame must be valid until we have
1510 called the window-system-dependent frame destruction routine. */
1512 if (FRAME_DISPLAY (f
)->delete_frame_hook
)
1513 (*FRAME_DISPLAY (f
)->delete_frame_hook
) (f
);
1516 struct display
*display
= FRAME_DISPLAY (f
);
1518 f
->output_data
.nothing
= 0;
1519 f
->display
= 0; /* Now the frame is dead. */
1521 /* If needed, delete the device that this frame was on.
1522 (This must be done after the frame is killed.) */
1523 display
->reference_count
--;
1524 if (display
->reference_count
== 0)
1526 if (display
->delete_display_hook
)
1527 (*display
->delete_display_hook
) (display
);
1529 delete_display (display
);
1533 /* If we've deleted the last_nonminibuf_frame, then try to find
1535 if (f
== last_nonminibuf_frame
)
1539 last_nonminibuf_frame
= 0;
1541 for (frames
= Vframe_list
;
1543 frames
= XCDR (frames
))
1545 f
= XFRAME (XCAR (frames
));
1546 if (!FRAME_MINIBUF_ONLY_P (f
))
1548 last_nonminibuf_frame
= f
;
1554 /* If there's no other frame on the same kboard, get out of
1555 single-kboard state if we're in it for this kboard. */
1558 /* Some frame we found on the same kboard, or nil if there are none. */
1559 Lisp_Object frame_on_same_kboard
;
1561 frame_on_same_kboard
= Qnil
;
1563 for (frames
= Vframe_list
;
1565 frames
= XCDR (frames
))
1570 this = XCAR (frames
);
1575 if (FRAME_KBOARD (f
) == FRAME_KBOARD (f1
))
1576 frame_on_same_kboard
= this;
1579 if (NILP (frame_on_same_kboard
))
1580 not_single_kboard_state (FRAME_KBOARD (f
));
1584 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1585 find another one. Prefer minibuffer-only frames, but also notice
1586 frames with other windows. */
1587 if (EQ (frame
, FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
))
1591 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1592 Lisp_Object frame_with_minibuf
;
1593 /* Some frame we found on the same kboard, or nil if there are none. */
1594 Lisp_Object frame_on_same_kboard
;
1596 frame_on_same_kboard
= Qnil
;
1597 frame_with_minibuf
= Qnil
;
1599 for (frames
= Vframe_list
;
1601 frames
= XCDR (frames
))
1606 this = XCAR (frames
);
1611 /* Consider only frames on the same kboard
1612 and only those with minibuffers. */
1613 if (FRAME_KBOARD (f
) == FRAME_KBOARD (f1
)
1614 && FRAME_HAS_MINIBUF_P (f1
))
1616 frame_with_minibuf
= this;
1617 if (FRAME_MINIBUF_ONLY_P (f1
))
1621 if (FRAME_KBOARD (f
) == FRAME_KBOARD (f1
))
1622 frame_on_same_kboard
= this;
1625 if (!NILP (frame_on_same_kboard
))
1627 /* We know that there must be some frame with a minibuffer out
1628 there. If this were not true, all of the frames present
1629 would have to be minibufferless, which implies that at some
1630 point their minibuffer frames must have been deleted, but
1631 that is prohibited at the top; you can't delete surrogate
1632 minibuffer frames. */
1633 if (NILP (frame_with_minibuf
))
1636 FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
= frame_with_minibuf
;
1639 /* No frames left on this kboard--say no minibuffer either. */
1640 FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
= Qnil
;
1643 /* Cause frame titles to update--necessary if we now have just one frame. */
1644 update_mode_lines
= 1;
1649 /* Return mouse position in character cell units. */
1651 DEFUN ("mouse-position", Fmouse_position
, Smouse_position
, 0, 0, 0,
1652 doc
: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1653 The position is given in character cells, where (0, 0) is the
1655 If Emacs is running on a mouseless terminal or hasn't been programmed
1656 to read the mouse position, it returns the selected frame for FRAME
1657 and nil for X and Y.
1658 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1659 passing the normal return value to that function as an argument,
1660 and returns whatever that function returns. */)
1664 Lisp_Object lispy_dummy
;
1665 enum scroll_bar_part party_dummy
;
1666 Lisp_Object x
, y
, retval
;
1668 unsigned long long_dummy
;
1669 struct gcpro gcpro1
;
1671 f
= SELECTED_FRAME ();
1675 /* It's okay for the hook to refrain from storing anything. */
1676 if (FRAME_DISPLAY (f
)->mouse_position_hook
)
1677 (*FRAME_DISPLAY (f
)->mouse_position_hook
) (&f
, -1,
1678 &lispy_dummy
, &party_dummy
,
1685 pixel_to_glyph_coords (f
, col
, row
, &col
, &row
, NULL
, 1);
1690 XSETFRAME (lispy_dummy
, f
);
1691 retval
= Fcons (lispy_dummy
, Fcons (x
, y
));
1693 if (!NILP (Vmouse_position_function
))
1694 retval
= call1 (Vmouse_position_function
, retval
);
1695 RETURN_UNGCPRO (retval
);
1698 DEFUN ("mouse-pixel-position", Fmouse_pixel_position
,
1699 Smouse_pixel_position
, 0, 0, 0,
1700 doc
: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1701 The position is given in pixel units, where (0, 0) is the
1703 If Emacs is running on a mouseless terminal or hasn't been programmed
1704 to read the mouse position, it returns the selected frame for FRAME
1705 and nil for X and Y. */)
1709 Lisp_Object lispy_dummy
;
1710 enum scroll_bar_part party_dummy
;
1712 unsigned long long_dummy
;
1714 f
= SELECTED_FRAME ();
1718 /* It's okay for the hook to refrain from storing anything. */
1719 if (FRAME_DISPLAY (f
)->mouse_position_hook
)
1720 (*FRAME_DISPLAY (f
)->mouse_position_hook
) (&f
, -1,
1721 &lispy_dummy
, &party_dummy
,
1725 XSETFRAME (lispy_dummy
, f
);
1726 return Fcons (lispy_dummy
, Fcons (x
, y
));
1729 DEFUN ("set-mouse-position", Fset_mouse_position
, Sset_mouse_position
, 3, 3, 0,
1730 doc
: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1731 Coordinates are relative to the frame, not a window,
1732 so the coordinates of the top left character in the frame
1733 may be nonzero due to left-hand scroll bars or the menu bar.
1735 This function is a no-op for an X frame that is not visible.
1736 If you have just created a frame, you must wait for it to become visible
1737 before calling this function on it, like this.
1738 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1740 Lisp_Object frame
, x
, y
;
1742 CHECK_LIVE_FRAME (frame
);
1746 /* I think this should be done with a hook. */
1747 #ifdef HAVE_WINDOW_SYSTEM
1748 if (FRAME_WINDOW_P (XFRAME (frame
)))
1749 /* Warping the mouse will cause enternotify and focus events. */
1750 x_set_mouse_position (XFRAME (frame
), XINT (x
), XINT (y
));
1752 #if defined (MSDOS) && defined (HAVE_MOUSE)
1753 if (FRAME_MSDOS_P (XFRAME (frame
)))
1755 Fselect_frame (frame
, Qnil
);
1756 mouse_moveto (XINT (x
), XINT (y
));
1764 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position
,
1765 Sset_mouse_pixel_position
, 3, 3, 0,
1766 doc
: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1767 Note, this is a no-op for an X frame that is not visible.
1768 If you have just created a frame, you must wait for it to become visible
1769 before calling this function on it, like this.
1770 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1772 Lisp_Object frame
, x
, y
;
1774 CHECK_LIVE_FRAME (frame
);
1778 /* I think this should be done with a hook. */
1779 #ifdef HAVE_WINDOW_SYSTEM
1780 if (FRAME_WINDOW_P (XFRAME (frame
)))
1781 /* Warping the mouse will cause enternotify and focus events. */
1782 x_set_mouse_pixel_position (XFRAME (frame
), XINT (x
), XINT (y
));
1784 #if defined (MSDOS) && defined (HAVE_MOUSE)
1785 if (FRAME_MSDOS_P (XFRAME (frame
)))
1787 Fselect_frame (frame
, Qnil
);
1788 mouse_moveto (XINT (x
), XINT (y
));
1796 static void make_frame_visible_1
P_ ((Lisp_Object
));
1798 DEFUN ("make-frame-visible", Fmake_frame_visible
, Smake_frame_visible
,
1800 doc
: /* Make the frame FRAME visible (assuming it is an X window).
1801 If omitted, FRAME defaults to the currently selected frame. */)
1806 frame
= selected_frame
;
1808 CHECK_LIVE_FRAME (frame
);
1810 /* I think this should be done with a hook. */
1811 #ifdef HAVE_WINDOW_SYSTEM
1812 if (FRAME_WINDOW_P (XFRAME (frame
)))
1814 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1815 x_make_frame_visible (XFRAME (frame
));
1819 make_frame_visible_1 (XFRAME (frame
)->root_window
);
1821 /* Make menu bar update for the Buffers and Frames menus. */
1822 windows_or_buffers_changed
++;
1827 /* Update the display_time slot of the buffers shown in WINDOW
1828 and all its descendents. */
1831 make_frame_visible_1 (window
)
1836 for (;!NILP (window
); window
= w
->next
)
1838 w
= XWINDOW (window
);
1840 if (!NILP (w
->buffer
))
1841 XBUFFER (w
->buffer
)->display_time
= Fcurrent_time ();
1843 if (!NILP (w
->vchild
))
1844 make_frame_visible_1 (w
->vchild
);
1845 if (!NILP (w
->hchild
))
1846 make_frame_visible_1 (w
->hchild
);
1850 DEFUN ("make-frame-invisible", Fmake_frame_invisible
, Smake_frame_invisible
,
1852 doc
: /* Make the frame FRAME invisible (assuming it is an X window).
1853 If omitted, FRAME defaults to the currently selected frame.
1854 Normally you may not make FRAME invisible if all other frames are invisible,
1855 but if the second optional argument FORCE is non-nil, you may do so. */)
1857 Lisp_Object frame
, force
;
1860 frame
= selected_frame
;
1862 CHECK_LIVE_FRAME (frame
);
1864 if (NILP (force
) && !other_visible_frames (XFRAME (frame
)))
1865 error ("Attempt to make invisible the sole visible or iconified frame");
1867 #if 0 /* This isn't logically necessary, and it can do GC. */
1868 /* Don't let the frame remain selected. */
1869 if (EQ (frame
, selected_frame
))
1870 do_switch_frame (next_frame (frame
, Qt
), 0, 0)
1873 /* Don't allow minibuf_window to remain on a deleted frame. */
1874 if (EQ (XFRAME (frame
)->minibuffer_window
, minibuf_window
))
1876 struct frame
*sf
= XFRAME (selected_frame
);
1877 Fset_window_buffer (sf
->minibuffer_window
,
1878 XWINDOW (minibuf_window
)->buffer
, Qnil
);
1879 minibuf_window
= sf
->minibuffer_window
;
1882 /* I think this should be done with a hook. */
1883 #ifdef HAVE_WINDOW_SYSTEM
1884 if (FRAME_WINDOW_P (XFRAME (frame
)))
1885 x_make_frame_invisible (XFRAME (frame
));
1888 /* Make menu bar update for the Buffers and Frames menus. */
1889 windows_or_buffers_changed
++;
1894 DEFUN ("iconify-frame", Ficonify_frame
, Siconify_frame
,
1896 doc
: /* Make the frame FRAME into an icon.
1897 If omitted, FRAME defaults to the currently selected frame. */)
1902 frame
= selected_frame
;
1904 CHECK_LIVE_FRAME (frame
);
1906 #if 0 /* This isn't logically necessary, and it can do GC. */
1907 /* Don't let the frame remain selected. */
1908 if (EQ (frame
, selected_frame
))
1909 Fhandle_switch_frame (next_frame (frame
, Qt
), Qnil
);
1912 /* Don't allow minibuf_window to remain on a deleted frame. */
1913 if (EQ (XFRAME (frame
)->minibuffer_window
, minibuf_window
))
1915 struct frame
*sf
= XFRAME (selected_frame
);
1916 Fset_window_buffer (sf
->minibuffer_window
,
1917 XWINDOW (minibuf_window
)->buffer
, Qnil
);
1918 minibuf_window
= sf
->minibuffer_window
;
1921 /* I think this should be done with a hook. */
1922 #ifdef HAVE_WINDOW_SYSTEM
1923 if (FRAME_WINDOW_P (XFRAME (frame
)))
1924 x_iconify_frame (XFRAME (frame
));
1927 /* Make menu bar update for the Buffers and Frames menus. */
1928 windows_or_buffers_changed
++;
1933 DEFUN ("frame-visible-p", Fframe_visible_p
, Sframe_visible_p
,
1935 doc
: /* Return t if FRAME is now \"visible\" (actually in use for display).
1936 A frame that is not \"visible\" is not updated and, if it works through
1937 a window system, it may not show at all.
1938 Return the symbol `icon' if frame is visible only as an icon.
1940 On a text-only terminal, all frames are considered visible, whether
1941 they are currently being displayed or not, and this function returns t
1946 CHECK_LIVE_FRAME (frame
);
1948 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1950 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1952 if (FRAME_ICONIFIED_P (XFRAME (frame
)))
1957 DEFUN ("visible-frame-list", Fvisible_frame_list
, Svisible_frame_list
,
1959 doc
: /* Return a list of all frames now \"visible\" (being updated). */)
1962 Lisp_Object tail
, frame
;
1967 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1969 frame
= XCAR (tail
);
1970 if (!FRAMEP (frame
))
1973 if (FRAME_VISIBLE_P (f
))
1974 value
= Fcons (frame
, value
);
1980 DEFUN ("raise-frame", Fraise_frame
, Sraise_frame
, 0, 1, "",
1981 doc
: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1982 If FRAME is invisible or iconified, make it visible.
1983 If you don't specify a frame, the selected frame is used.
1984 If Emacs is displaying on an ordinary terminal or some other device which
1985 doesn't support multiple overlapping frames, this function does nothing. */)
1991 frame
= selected_frame
;
1993 CHECK_LIVE_FRAME (frame
);
1997 /* Do like the documentation says. */
1998 Fmake_frame_visible (frame
);
2000 if (FRAME_DISPLAY (f
)->frame_raise_lower_hook
)
2001 (*FRAME_DISPLAY (f
)->frame_raise_lower_hook
) (f
, 1);
2006 /* Should we have a corresponding function called Flower_Power? */
2007 DEFUN ("lower-frame", Flower_frame
, Slower_frame
, 0, 1, "",
2008 doc
: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2009 If you don't specify a frame, the selected frame is used.
2010 If Emacs is displaying on an ordinary terminal or some other device which
2011 doesn't support multiple overlapping frames, this function does nothing. */)
2018 frame
= selected_frame
;
2020 CHECK_LIVE_FRAME (frame
);
2024 if (FRAME_DISPLAY (f
)->frame_raise_lower_hook
)
2025 (*FRAME_DISPLAY (f
)->frame_raise_lower_hook
) (f
, 0);
2031 DEFUN ("redirect-frame-focus", Fredirect_frame_focus
, Sredirect_frame_focus
,
2033 doc
: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2034 In other words, switch-frame events caused by events in FRAME will
2035 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2036 FOCUS-FRAME after reading an event typed at FRAME.
2038 If FOCUS-FRAME is omitted or nil, any existing redirection is
2039 cancelled, and the frame again receives its own keystrokes.
2041 Focus redirection is useful for temporarily redirecting keystrokes to
2042 a surrogate minibuffer frame when a frame doesn't have its own
2045 A frame's focus redirection can be changed by select-frame. If frame
2046 FOO is selected, and then a different frame BAR is selected, any
2047 frames redirecting their focus to FOO are shifted to redirect their
2048 focus to BAR. This allows focus redirection to work properly when the
2049 user switches from one frame to another using `select-window'.
2051 This means that a frame whose focus is redirected to itself is treated
2052 differently from a frame whose focus is redirected to nil; the former
2053 is affected by select-frame, while the latter is not.
2055 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2056 (frame
, focus_frame
)
2057 Lisp_Object frame
, focus_frame
;
2061 /* Note that we don't check for a live frame here. It's reasonable
2062 to redirect the focus of a frame you're about to delete, if you
2063 know what other frame should receive those keystrokes. */
2064 CHECK_FRAME (frame
);
2066 if (! NILP (focus_frame
))
2067 CHECK_LIVE_FRAME (focus_frame
);
2071 f
->focus_frame
= focus_frame
;
2073 if (FRAME_DISPLAY (f
)->frame_rehighlight_hook
)
2074 (*FRAME_DISPLAY (f
)->frame_rehighlight_hook
) (f
);
2080 DEFUN ("frame-focus", Fframe_focus
, Sframe_focus
, 1, 1, 0,
2081 doc
: /* Return the frame to which FRAME's keystrokes are currently being sent.
2082 This returns nil if FRAME's focus is not redirected.
2083 See `redirect-frame-focus'. */)
2087 CHECK_LIVE_FRAME (frame
);
2089 return FRAME_FOCUS_FRAME (XFRAME (frame
));
2094 /* Return the value of frame parameter PROP in frame FRAME. */
2097 get_frame_param (frame
, prop
)
2098 register struct frame
*frame
;
2101 register Lisp_Object tem
;
2103 tem
= Fassq (prop
, frame
->param_alist
);
2109 /* Return the buffer-predicate of the selected frame. */
2112 frame_buffer_predicate (frame
)
2115 return XFRAME (frame
)->buffer_predicate
;
2118 /* Return the buffer-list of the selected frame. */
2121 frame_buffer_list (frame
)
2124 return XFRAME (frame
)->buffer_list
;
2127 /* Set the buffer-list of the selected frame. */
2130 set_frame_buffer_list (frame
, list
)
2131 Lisp_Object frame
, list
;
2133 XFRAME (frame
)->buffer_list
= list
;
2136 /* Discard BUFFER from the buffer-list of each frame. */
2139 frames_discard_buffer (buffer
)
2142 Lisp_Object frame
, tail
;
2144 FOR_EACH_FRAME (tail
, frame
)
2146 XFRAME (frame
)->buffer_list
2147 = Fdelq (buffer
, XFRAME (frame
)->buffer_list
);
2151 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2152 If the alist already has an element for PROP, we change it. */
2155 store_in_alist (alistptr
, prop
, val
)
2156 Lisp_Object
*alistptr
, val
;
2159 register Lisp_Object tem
;
2161 tem
= Fassq (prop
, *alistptr
);
2163 *alistptr
= Fcons (Fcons (prop
, val
), *alistptr
);
2169 frame_name_fnn_p (str
, len
)
2173 if (len
> 1 && str
[0] == 'F')
2177 strtol (str
+ 1, &end_ptr
, 10);
2179 if (end_ptr
== str
+ len
)
2185 /* Set the name of the terminal frame. Also used by MSDOS frames.
2186 Modeled after x_set_name which is used for WINDOW frames. */
2189 set_term_frame_name (f
, name
)
2193 f
->explicit_name
= ! NILP (name
);
2195 /* If NAME is nil, set the name to F<num>. */
2200 /* Check for no change needed in this very common case
2201 before we do any consing. */
2202 if (frame_name_fnn_p (SDATA (f
->name
),
2206 terminal_frame_count
++;
2207 sprintf (namebuf
, "F%d", terminal_frame_count
);
2208 name
= build_string (namebuf
);
2212 CHECK_STRING (name
);
2214 /* Don't change the name if it's already NAME. */
2215 if (! NILP (Fstring_equal (name
, f
->name
)))
2218 /* Don't allow the user to set the frame name to F<num>, so it
2219 doesn't clash with the names we generate for terminal frames. */
2220 if (frame_name_fnn_p (SDATA (name
), SBYTES (name
)))
2221 error ("Frame names of the form F<num> are usurped by Emacs");
2225 update_mode_lines
= 1;
2229 store_frame_param (f
, prop
, val
)
2231 Lisp_Object prop
, val
;
2233 register Lisp_Object old_alist_elt
;
2235 /* The buffer-alist parameter is stored in a special place and is
2236 not in the alist. */
2237 if (EQ (prop
, Qbuffer_list
))
2239 f
->buffer_list
= val
;
2243 /* If PROP is a symbol which is supposed to have frame-local values,
2244 and it is set up based on this frame, switch to the global
2245 binding. That way, we can create or alter the frame-local binding
2246 without messing up the symbol's status. */
2249 Lisp_Object valcontents
;
2250 valcontents
= SYMBOL_VALUE (prop
);
2251 if ((BUFFER_LOCAL_VALUEP (valcontents
)
2252 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
2253 && XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
2254 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents
)->frame
) == f
)
2255 swap_in_global_binding (prop
);
2259 /* The tty color mode needs to be set before the frame's parameter
2260 alist is updated with the new value, because set_tty_color_mode
2261 wants to look at the old mode. */
2262 if (FRAME_TERMCAP_P (f
) && EQ (prop
, Qtty_color_mode
))
2263 set_tty_color_mode (f
, val
);
2266 /* Update the frame parameter alist. */
2267 old_alist_elt
= Fassq (prop
, f
->param_alist
);
2268 if (EQ (old_alist_elt
, Qnil
))
2269 f
->param_alist
= Fcons (Fcons (prop
, val
), f
->param_alist
);
2271 Fsetcdr (old_alist_elt
, val
);
2273 /* Update some other special parameters in their special places
2274 in addition to the alist. */
2276 if (EQ (prop
, Qbuffer_predicate
))
2277 f
->buffer_predicate
= val
;
2279 if (! FRAME_WINDOW_P (f
))
2281 if (EQ (prop
, Qmenu_bar_lines
))
2282 set_menu_bar_lines (f
, val
, make_number (FRAME_MENU_BAR_LINES (f
)));
2283 else if (EQ (prop
, Qname
))
2284 set_term_frame_name (f
, val
);
2287 if (EQ (prop
, Qminibuffer
) && WINDOWP (val
))
2289 if (! MINI_WINDOW_P (XWINDOW (val
)))
2290 error ("Surrogate minibuffer windows must be minibuffer windows");
2292 if ((FRAME_HAS_MINIBUF_P (f
) || FRAME_MINIBUF_ONLY_P (f
))
2293 && !EQ (val
, f
->minibuffer_window
))
2294 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2296 /* Install the chosen minibuffer window, with proper buffer. */
2297 f
->minibuffer_window
= val
;
2301 DEFUN ("frame-parameters", Fframe_parameters
, Sframe_parameters
, 0, 1, 0,
2302 doc
: /* Return the parameters-alist of frame FRAME.
2303 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2304 The meaningful PARMs depend on the kind of frame.
2305 If FRAME is omitted, return information on the currently selected frame. */)
2312 struct gcpro gcpro1
;
2315 frame
= selected_frame
;
2317 CHECK_FRAME (frame
);
2320 if (!FRAME_LIVE_P (f
))
2323 alist
= Fcopy_alist (f
->param_alist
);
2326 if (!FRAME_WINDOW_P (f
))
2328 int fg
= FRAME_FOREGROUND_PIXEL (f
);
2329 int bg
= FRAME_BACKGROUND_PIXEL (f
);
2332 /* If the frame's parameter alist says the colors are
2333 unspecified and reversed, take the frame's background pixel
2334 for foreground and vice versa. */
2335 elt
= Fassq (Qforeground_color
, alist
);
2336 if (!NILP (elt
) && CONSP (elt
) && STRINGP (XCDR (elt
)))
2338 if (strncmp (SDATA (XCDR (elt
)),
2340 SCHARS (XCDR (elt
))) == 0)
2341 store_in_alist (&alist
, Qforeground_color
, tty_color_name (f
, bg
));
2342 else if (strncmp (SDATA (XCDR (elt
)),
2344 SCHARS (XCDR (elt
))) == 0)
2345 store_in_alist (&alist
, Qforeground_color
, tty_color_name (f
, fg
));
2348 store_in_alist (&alist
, Qforeground_color
, tty_color_name (f
, fg
));
2349 elt
= Fassq (Qbackground_color
, alist
);
2350 if (!NILP (elt
) && CONSP (elt
) && STRINGP (XCDR (elt
)))
2352 if (strncmp (SDATA (XCDR (elt
)),
2354 SCHARS (XCDR (elt
))) == 0)
2355 store_in_alist (&alist
, Qbackground_color
, tty_color_name (f
, fg
));
2356 else if (strncmp (SDATA (XCDR (elt
)),
2358 SCHARS (XCDR (elt
))) == 0)
2359 store_in_alist (&alist
, Qbackground_color
, tty_color_name (f
, bg
));
2362 store_in_alist (&alist
, Qbackground_color
, tty_color_name (f
, bg
));
2363 store_in_alist (&alist
, intern ("font"),
2364 build_string (FRAME_MSDOS_P (f
)
2366 : FRAME_W32_P (f
) ? "w32term"
2369 store_in_alist (&alist
, Qname
, f
->name
);
2370 height
= (f
->new_text_lines
? f
->new_text_lines
: FRAME_LINES (f
));
2371 store_in_alist (&alist
, Qheight
, make_number (height
));
2372 width
= (f
->new_text_cols
? f
->new_text_cols
: FRAME_COLS (f
));
2373 store_in_alist (&alist
, Qwidth
, make_number (width
));
2374 store_in_alist (&alist
, Qmodeline
, (FRAME_WANTS_MODELINE_P (f
) ? Qt
: Qnil
));
2375 store_in_alist (&alist
, Qminibuffer
,
2376 (! FRAME_HAS_MINIBUF_P (f
) ? Qnil
2377 : FRAME_MINIBUF_ONLY_P (f
) ? Qonly
2378 : FRAME_MINIBUF_WINDOW (f
)));
2379 store_in_alist (&alist
, Qunsplittable
, (FRAME_NO_SPLIT_P (f
) ? Qt
: Qnil
));
2380 store_in_alist (&alist
, Qbuffer_list
, frame_buffer_list (frame
));
2382 /* I think this should be done with a hook. */
2383 #ifdef HAVE_WINDOW_SYSTEM
2384 if (FRAME_WINDOW_P (f
))
2385 x_report_frame_params (f
, &alist
);
2389 /* This ought to be correct in f->param_alist for an X frame. */
2391 XSETFASTINT (lines
, FRAME_MENU_BAR_LINES (f
));
2392 store_in_alist (&alist
, Qmenu_bar_lines
, lines
);
2400 DEFUN ("frame-parameter", Fframe_parameter
, Sframe_parameter
, 2, 2, 0,
2401 doc
: /* Return FRAME's value for parameter PARAMETER.
2402 If FRAME is nil, describe the currently selected frame. */)
2404 Lisp_Object frame
, parameter
;
2410 frame
= selected_frame
;
2412 CHECK_FRAME (frame
);
2413 CHECK_SYMBOL (parameter
);
2418 if (FRAME_LIVE_P (f
))
2420 /* Avoid consing in frequent cases. */
2421 if (EQ (parameter
, Qname
))
2423 #ifdef HAVE_X_WINDOWS
2424 else if (EQ (parameter
, Qdisplay
) && FRAME_X_P (f
))
2425 value
= XCAR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
);
2426 #endif /* HAVE_X_WINDOWS */
2427 else if (EQ (parameter
, Qbackground_color
)
2428 || EQ (parameter
, Qforeground_color
))
2430 value
= Fassq (parameter
, f
->param_alist
);
2433 value
= XCDR (value
);
2434 /* Fframe_parameters puts the actual fg/bg color names,
2435 even if f->param_alist says otherwise. This is
2436 important when param_alist's notion of colors is
2437 "unspecified". We need to do the same here. */
2438 if (STRINGP (value
) && !FRAME_WINDOW_P (f
))
2440 const char *color_name
;
2443 if (EQ (parameter
, Qbackground_color
))
2445 color_name
= SDATA (value
);
2446 csz
= SCHARS (value
);
2447 if (strncmp (color_name
, unspecified_bg
, csz
) == 0)
2448 value
= tty_color_name (f
, FRAME_BACKGROUND_PIXEL (f
));
2449 else if (strncmp (color_name
, unspecified_fg
, csz
) == 0)
2450 value
= tty_color_name (f
, FRAME_FOREGROUND_PIXEL (f
));
2452 else if (EQ (parameter
, Qforeground_color
))
2454 color_name
= SDATA (value
);
2455 csz
= SCHARS (value
);
2456 if (strncmp (color_name
, unspecified_fg
, csz
) == 0)
2457 value
= tty_color_name (f
, FRAME_FOREGROUND_PIXEL (f
));
2458 else if (strncmp (color_name
, unspecified_bg
, csz
) == 0)
2459 value
= tty_color_name (f
, FRAME_BACKGROUND_PIXEL (f
));
2464 value
= Fcdr (Fassq (parameter
, Fframe_parameters (frame
)));
2466 else if (EQ (parameter
, Qdisplay_type
)
2467 || EQ (parameter
, Qbackground_mode
))
2468 value
= Fcdr (Fassq (parameter
, f
->param_alist
));
2470 value
= Fcdr (Fassq (parameter
, Fframe_parameters (frame
)));
2477 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters
,
2478 Smodify_frame_parameters
, 2, 2, 0,
2479 doc
: /* Modify the parameters of frame FRAME according to ALIST.
2480 If FRAME is nil, it defaults to the selected frame.
2481 ALIST is an alist of parameters to change and their new values.
2482 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2483 The meaningful PARMs depend on the kind of frame.
2484 Undefined PARMs are ignored, but stored in the frame's parameter list
2485 so that `frame-parameters' will return them.
2487 The value of frame parameter FOO can also be accessed
2488 as a frame-local binding for the variable FOO, if you have
2489 enabled such bindings for that variable with `make-variable-frame-local'. */)
2491 Lisp_Object frame
, alist
;
2494 register Lisp_Object tail
, prop
, val
;
2495 int count
= SPECPDL_INDEX ();
2497 /* Bind this to t to inhibit initialization of the default face from
2498 X resources in face-set-after-frame-default. If we don't inhibit
2499 this, modifying the `font' frame parameter, for example, while
2500 there is a `default.attributeFont' X resource, won't work,
2501 because `default's font is reset to the value of the X resource
2502 and that resets the `font' frame parameter. */
2503 specbind (Qinhibit_default_face_x_resources
, Qt
);
2505 if (EQ (frame
, Qnil
))
2506 frame
= selected_frame
;
2507 CHECK_LIVE_FRAME (frame
);
2510 /* I think this should be done with a hook. */
2511 #ifdef HAVE_WINDOW_SYSTEM
2512 if (FRAME_WINDOW_P (f
))
2513 x_set_frame_parameters (f
, alist
);
2517 if (FRAME_MSDOS_P (f
))
2518 IT_set_frame_parameters (f
, alist
);
2523 int length
= XINT (Flength (alist
));
2526 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
2528 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
2530 /* Extract parm names and values into those vectors. */
2533 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
2538 parms
[i
] = Fcar (elt
);
2539 values
[i
] = Fcdr (elt
);
2543 /* Now process them in reverse of specified order. */
2544 for (i
--; i
>= 0; i
--)
2548 store_frame_param (f
, prop
, val
);
2552 return unbind_to (count
, Qnil
);
2555 DEFUN ("frame-char-height", Fframe_char_height
, Sframe_char_height
,
2557 doc
: /* Height in pixels of a line in the font in frame FRAME.
2558 If FRAME is omitted, the selected frame is used.
2559 For a terminal frame, the value is always 1. */)
2566 frame
= selected_frame
;
2567 CHECK_FRAME (frame
);
2570 #ifdef HAVE_WINDOW_SYSTEM
2571 if (FRAME_WINDOW_P (f
))
2572 return make_number (x_char_height (f
));
2575 return make_number (1);
2579 DEFUN ("frame-char-width", Fframe_char_width
, Sframe_char_width
,
2581 doc
: /* Width in pixels of characters in the font in frame FRAME.
2582 If FRAME is omitted, the selected frame is used.
2583 The width is the same for all characters, because
2584 currently Emacs supports only fixed-width fonts.
2585 For a terminal screen, the value is always 1. */)
2592 frame
= selected_frame
;
2593 CHECK_FRAME (frame
);
2596 #ifdef HAVE_WINDOW_SYSTEM
2597 if (FRAME_WINDOW_P (f
))
2598 return make_number (x_char_width (f
));
2601 return make_number (1);
2604 DEFUN ("frame-pixel-height", Fframe_pixel_height
,
2605 Sframe_pixel_height
, 0, 1, 0,
2606 doc
: /* Return a FRAME's height in pixels.
2607 This counts only the height available for text lines,
2608 not menu bars on window-system Emacs frames.
2609 For a terminal frame, the result really gives the height in characters.
2610 If FRAME is omitted, the selected frame is used. */)
2617 frame
= selected_frame
;
2618 CHECK_FRAME (frame
);
2621 #ifdef HAVE_WINDOW_SYSTEM
2622 if (FRAME_WINDOW_P (f
))
2623 return make_number (x_pixel_height (f
));
2626 return make_number (FRAME_LINES (f
));
2629 DEFUN ("frame-pixel-width", Fframe_pixel_width
,
2630 Sframe_pixel_width
, 0, 1, 0,
2631 doc
: /* Return FRAME's width in pixels.
2632 For a terminal frame, the result really gives the width in characters.
2633 If FRAME is omitted, the selected frame is used. */)
2640 frame
= selected_frame
;
2641 CHECK_FRAME (frame
);
2644 #ifdef HAVE_WINDOW_SYSTEM
2645 if (FRAME_WINDOW_P (f
))
2646 return make_number (x_pixel_width (f
));
2649 return make_number (FRAME_COLS (f
));
2652 DEFUN ("set-frame-height", Fset_frame_height
, Sset_frame_height
, 2, 3, 0,
2653 doc
: /* Specify that the frame FRAME has LINES lines.
2654 Optional third arg non-nil means that redisplay should use LINES lines
2655 but that the idea of the actual height of the frame should not be changed. */)
2656 (frame
, lines
, pretend
)
2657 Lisp_Object frame
, lines
, pretend
;
2659 register struct frame
*f
;
2661 CHECK_NUMBER (lines
);
2663 frame
= selected_frame
;
2664 CHECK_LIVE_FRAME (frame
);
2667 /* I think this should be done with a hook. */
2668 #ifdef HAVE_WINDOW_SYSTEM
2669 if (FRAME_WINDOW_P (f
))
2671 if (XINT (lines
) != FRAME_LINES (f
))
2672 x_set_window_size (f
, 1, FRAME_COLS (f
), XINT (lines
));
2673 do_pending_window_change (0);
2677 change_frame_size (f
, XINT (lines
), 0, !NILP (pretend
), 0, 0);
2681 DEFUN ("set-frame-width", Fset_frame_width
, Sset_frame_width
, 2, 3, 0,
2682 doc
: /* Specify that the frame FRAME has COLS columns.
2683 Optional third arg non-nil means that redisplay should use COLS columns
2684 but that the idea of the actual width of the frame should not be changed. */)
2685 (frame
, cols
, pretend
)
2686 Lisp_Object frame
, cols
, pretend
;
2688 register struct frame
*f
;
2689 CHECK_NUMBER (cols
);
2691 frame
= selected_frame
;
2692 CHECK_LIVE_FRAME (frame
);
2695 /* I think this should be done with a hook. */
2696 #ifdef HAVE_WINDOW_SYSTEM
2697 if (FRAME_WINDOW_P (f
))
2699 if (XINT (cols
) != FRAME_COLS (f
))
2700 x_set_window_size (f
, 1, XINT (cols
), FRAME_LINES (f
));
2701 do_pending_window_change (0);
2705 change_frame_size (f
, 0, XINT (cols
), !NILP (pretend
), 0, 0);
2709 DEFUN ("set-frame-size", Fset_frame_size
, Sset_frame_size
, 3, 3, 0,
2710 doc
: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2712 Lisp_Object frame
, cols
, rows
;
2714 register struct frame
*f
;
2716 CHECK_LIVE_FRAME (frame
);
2717 CHECK_NUMBER (cols
);
2718 CHECK_NUMBER (rows
);
2721 /* I think this should be done with a hook. */
2722 #ifdef HAVE_WINDOW_SYSTEM
2723 if (FRAME_WINDOW_P (f
))
2725 if (XINT (rows
) != FRAME_LINES (f
)
2726 || XINT (cols
) != FRAME_COLS (f
)
2727 || f
->new_text_lines
|| f
->new_text_cols
)
2728 x_set_window_size (f
, 1, XINT (cols
), XINT (rows
));
2729 do_pending_window_change (0);
2733 change_frame_size (f
, XINT (rows
), XINT (cols
), 0, 0, 0);
2738 DEFUN ("set-frame-position", Fset_frame_position
,
2739 Sset_frame_position
, 3, 3, 0,
2740 doc
: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2741 This is actually the position of the upper left corner of the frame.
2742 Negative values for XOFFSET or YOFFSET are interpreted relative to
2743 the rightmost or bottommost possible position (that stays within the screen). */)
2744 (frame
, xoffset
, yoffset
)
2745 Lisp_Object frame
, xoffset
, yoffset
;
2747 register struct frame
*f
;
2749 CHECK_LIVE_FRAME (frame
);
2750 CHECK_NUMBER (xoffset
);
2751 CHECK_NUMBER (yoffset
);
2754 /* I think this should be done with a hook. */
2755 #ifdef HAVE_WINDOW_SYSTEM
2756 if (FRAME_WINDOW_P (f
))
2757 x_set_offset (f
, XINT (xoffset
), XINT (yoffset
), 1);
2764 /***********************************************************************
2766 ***********************************************************************/
2768 /* Connect the frame-parameter names for X frames
2769 to the ways of passing the parameter values to the window system.
2771 The name of a parameter, as a Lisp symbol,
2772 has an `x-frame-parameter' property which is an integer in Lisp
2773 that is an index in this table. */
2775 struct frame_parm_table
{
2777 Lisp_Object
*variable
;
2780 static struct frame_parm_table frame_parms
[] =
2782 {"auto-raise", &Qauto_raise
},
2783 {"auto-lower", &Qauto_lower
},
2784 {"background-color", 0},
2785 {"border-color", &Qborder_color
},
2786 {"border-width", &Qborder_width
},
2787 {"cursor-color", &Qcursor_color
},
2788 {"cursor-type", &Qcursor_type
},
2790 {"foreground-color", 0},
2791 {"icon-name", &Qicon_name
},
2792 {"icon-type", &Qicon_type
},
2793 {"internal-border-width", &Qinternal_border_width
},
2794 {"menu-bar-lines", &Qmenu_bar_lines
},
2795 {"mouse-color", &Qmouse_color
},
2797 {"scroll-bar-width", &Qscroll_bar_width
},
2799 {"unsplittable", &Qunsplittable
},
2800 {"vertical-scroll-bars", &Qvertical_scroll_bars
},
2801 {"visibility", &Qvisibility
},
2802 {"tool-bar-lines", &Qtool_bar_lines
},
2803 {"scroll-bar-foreground", &Qscroll_bar_foreground
},
2804 {"scroll-bar-background", &Qscroll_bar_background
},
2805 {"screen-gamma", &Qscreen_gamma
},
2806 {"line-spacing", &Qline_spacing
},
2807 {"left-fringe", &Qleft_fringe
},
2808 {"right-fringe", &Qright_fringe
},
2809 {"wait-for-wm", &Qwait_for_wm
},
2810 {"fullscreen", &Qfullscreen
},
2813 #ifdef HAVE_WINDOW_SYSTEM
2815 extern Lisp_Object Qbox
;
2816 extern Lisp_Object Qtop
;
2818 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2819 wanted positions of the WM window (not emacs window).
2820 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2821 window (FRAME_X_WINDOW).
2825 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
2832 int newwidth
= FRAME_COLS (f
);
2833 int newheight
= FRAME_LINES (f
);
2835 *top_pos
= f
->top_pos
;
2836 *left_pos
= f
->left_pos
;
2838 if (f
->want_fullscreen
& FULLSCREEN_HEIGHT
)
2842 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
2843 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
2844 ph
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, newheight
) - f
->y_pixels_diff
;
2845 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
2849 if (f
->want_fullscreen
& FULLSCREEN_WIDTH
)
2853 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
2854 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
2855 pw
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, newwidth
) - f
->x_pixels_diff
;
2856 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
2861 *height
= newheight
;
2865 /* Change the parameters of frame F as specified by ALIST.
2866 If a parameter is not specially recognized, do nothing special;
2867 otherwise call the `x_set_...' function for that parameter.
2868 Except for certain geometry properties, always call store_frame_param
2869 to store the new value in the parameter alist. */
2872 x_set_frame_parameters (f
, alist
)
2878 /* If both of these parameters are present, it's more efficient to
2879 set them both at once. So we wait until we've looked at the
2880 entire list before we set them. */
2884 Lisp_Object left
, top
;
2886 /* Same with these. */
2887 Lisp_Object icon_left
, icon_top
;
2889 /* Record in these vectors all the parms specified. */
2891 Lisp_Object
*values
;
2893 int left_no_change
= 0, top_no_change
= 0;
2894 int icon_left_no_change
= 0, icon_top_no_change
= 0;
2895 int fullscreen_is_being_set
= 0;
2897 struct gcpro gcpro1
, gcpro2
;
2900 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
2903 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
2904 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
2906 /* Extract parm names and values into those vectors. */
2909 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
2914 parms
[i
] = Fcar (elt
);
2915 values
[i
] = Fcdr (elt
);
2918 /* TAIL and ALIST are not used again below here. */
2919 alist
= tail
= Qnil
;
2921 GCPRO2 (*parms
, *values
);
2925 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2926 because their values appear in VALUES and strings are not valid. */
2927 top
= left
= Qunbound
;
2928 icon_left
= icon_top
= Qunbound
;
2930 /* Provide default values for HEIGHT and WIDTH. */
2931 width
= (f
->new_text_cols
? f
->new_text_cols
: FRAME_COLS (f
));
2932 height
= (f
->new_text_lines
? f
->new_text_lines
: FRAME_LINES (f
));
2934 /* Process foreground_color and background_color before anything else.
2935 They are independent of other properties, but other properties (e.g.,
2936 cursor_color) are dependent upon them. */
2937 /* Process default font as well, since fringe widths depends on it. */
2938 /* Also, process fullscreen, width and height depend upon that */
2939 for (p
= 0; p
< i
; p
++)
2941 Lisp_Object prop
, val
;
2945 if (EQ (prop
, Qforeground_color
)
2946 || EQ (prop
, Qbackground_color
)
2948 || EQ (prop
, Qfullscreen
))
2950 register Lisp_Object param_index
, old_value
;
2952 old_value
= get_frame_param (f
, prop
);
2953 fullscreen_is_being_set
|= EQ (prop
, Qfullscreen
);
2955 if (NILP (Fequal (val
, old_value
)))
2957 store_frame_param (f
, prop
, val
);
2959 param_index
= Fget (prop
, Qx_frame_parameter
);
2960 if (NATNUMP (param_index
)
2961 && (XFASTINT (param_index
)
2962 < sizeof (frame_parms
)/sizeof (frame_parms
[0]))
2963 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
2964 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
2969 /* Now process them in reverse of specified order. */
2970 for (i
--; i
>= 0; i
--)
2972 Lisp_Object prop
, val
;
2977 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
2978 width
= XFASTINT (val
);
2979 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
2980 height
= XFASTINT (val
);
2981 else if (EQ (prop
, Qtop
))
2983 else if (EQ (prop
, Qleft
))
2985 else if (EQ (prop
, Qicon_top
))
2987 else if (EQ (prop
, Qicon_left
))
2989 else if (EQ (prop
, Qforeground_color
)
2990 || EQ (prop
, Qbackground_color
)
2992 || EQ (prop
, Qfullscreen
))
2993 /* Processed above. */
2997 register Lisp_Object param_index
, old_value
;
2999 old_value
= get_frame_param (f
, prop
);
3001 store_frame_param (f
, prop
, val
);
3003 param_index
= Fget (prop
, Qx_frame_parameter
);
3004 if (NATNUMP (param_index
)
3005 && (XFASTINT (param_index
)
3006 < sizeof (frame_parms
)/sizeof (frame_parms
[0]))
3007 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
3008 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
3012 /* Don't die if just one of these was set. */
3013 if (EQ (left
, Qunbound
))
3016 if (f
->left_pos
< 0)
3017 left
= Fcons (Qplus
, Fcons (make_number (f
->left_pos
), Qnil
));
3019 XSETINT (left
, f
->left_pos
);
3021 if (EQ (top
, Qunbound
))
3025 top
= Fcons (Qplus
, Fcons (make_number (f
->top_pos
), Qnil
));
3027 XSETINT (top
, f
->top_pos
);
3030 /* If one of the icon positions was not set, preserve or default it. */
3031 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
3033 icon_left_no_change
= 1;
3034 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
3035 if (NILP (icon_left
))
3036 XSETINT (icon_left
, 0);
3038 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
3040 icon_top_no_change
= 1;
3041 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
3042 if (NILP (icon_top
))
3043 XSETINT (icon_top
, 0);
3046 if (FRAME_VISIBLE_P (f
) && fullscreen_is_being_set
)
3048 /* If the frame is visible already and the fullscreen parameter is
3049 being set, it is too late to set WM manager hints to specify
3051 Here we first get the width, height and position that applies to
3052 fullscreen. We then move the frame to the appropriate
3053 position. Resize of the frame is taken care of in the code after
3054 this if-statement. */
3055 int new_left
, new_top
;
3057 x_fullscreen_adjust (f
, &width
, &height
, &new_top
, &new_left
);
3058 if (new_top
!= f
->top_pos
|| new_left
!= f
->left_pos
)
3059 x_set_offset (f
, new_left
, new_top
, 1);
3062 /* Don't set these parameters unless they've been explicitly
3063 specified. The window might be mapped or resized while we're in
3064 this function, and we don't want to override that unless the lisp
3065 code has asked for it.
3067 Don't set these parameters unless they actually differ from the
3068 window's current parameters; the window may not actually exist
3073 check_frame_size (f
, &height
, &width
);
3075 XSETFRAME (frame
, f
);
3077 if (width
!= FRAME_COLS (f
)
3078 || height
!= FRAME_LINES (f
)
3079 || f
->new_text_lines
|| f
->new_text_cols
)
3080 Fset_frame_size (frame
, make_number (width
), make_number (height
));
3082 if ((!NILP (left
) || !NILP (top
))
3083 && ! (left_no_change
&& top_no_change
)
3084 && ! (NUMBERP (left
) && XINT (left
) == f
->left_pos
3085 && NUMBERP (top
) && XINT (top
) == f
->top_pos
))
3090 /* Record the signs. */
3091 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
3092 if (EQ (left
, Qminus
))
3093 f
->size_hint_flags
|= XNegative
;
3094 else if (INTEGERP (left
))
3096 leftpos
= XINT (left
);
3098 f
->size_hint_flags
|= XNegative
;
3100 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
3101 && CONSP (XCDR (left
))
3102 && INTEGERP (XCAR (XCDR (left
))))
3104 leftpos
= - XINT (XCAR (XCDR (left
)));
3105 f
->size_hint_flags
|= XNegative
;
3107 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
3108 && CONSP (XCDR (left
))
3109 && INTEGERP (XCAR (XCDR (left
))))
3111 leftpos
= XINT (XCAR (XCDR (left
)));
3114 if (EQ (top
, Qminus
))
3115 f
->size_hint_flags
|= YNegative
;
3116 else if (INTEGERP (top
))
3118 toppos
= XINT (top
);
3120 f
->size_hint_flags
|= YNegative
;
3122 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
3123 && CONSP (XCDR (top
))
3124 && INTEGERP (XCAR (XCDR (top
))))
3126 toppos
= - XINT (XCAR (XCDR (top
)));
3127 f
->size_hint_flags
|= YNegative
;
3129 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
3130 && CONSP (XCDR (top
))
3131 && INTEGERP (XCAR (XCDR (top
))))
3133 toppos
= XINT (XCAR (XCDR (top
)));
3137 /* Store the numeric value of the position. */
3138 f
->top_pos
= toppos
;
3139 f
->left_pos
= leftpos
;
3141 f
->win_gravity
= NorthWestGravity
;
3143 /* Actually set that position, and convert to absolute. */
3144 x_set_offset (f
, leftpos
, toppos
, -1);
3147 if ((!NILP (icon_left
) || !NILP (icon_top
))
3148 && ! (icon_left_no_change
&& icon_top_no_change
))
3149 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
3156 /* Insert a description of internally-recorded parameters of frame X
3157 into the parameter alist *ALISTPTR that is to be given to the user.
3158 Only parameters that are specific to the X window system
3159 and whose values are not correctly recorded in the frame's
3160 param_alist need to be considered here. */
3163 x_report_frame_params (f
, alistptr
)
3165 Lisp_Object
*alistptr
;
3170 /* Represent negative positions (off the top or left screen edge)
3171 in a way that Fmodify_frame_parameters will understand correctly. */
3172 XSETINT (tem
, f
->left_pos
);
3173 if (f
->left_pos
>= 0)
3174 store_in_alist (alistptr
, Qleft
, tem
);
3176 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
3178 XSETINT (tem
, f
->top_pos
);
3179 if (f
->top_pos
>= 0)
3180 store_in_alist (alistptr
, Qtop
, tem
);
3182 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
3184 store_in_alist (alistptr
, Qborder_width
,
3185 make_number (f
->border_width
));
3186 store_in_alist (alistptr
, Qinternal_border_width
,
3187 make_number (FRAME_INTERNAL_BORDER_WIDTH (f
)));
3188 store_in_alist (alistptr
, Qleft_fringe
,
3189 make_number (FRAME_LEFT_FRINGE_WIDTH (f
)));
3190 store_in_alist (alistptr
, Qright_fringe
,
3191 make_number (FRAME_RIGHT_FRINGE_WIDTH (f
)));
3192 store_in_alist (alistptr
, Qscroll_bar_width
,
3193 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3195 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
3196 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3197 /* nil means "use default width"
3198 for non-toolkit scroll bar.
3199 ruler-mode.el depends on this. */
3201 sprintf (buf
, "%ld", (long) FRAME_X_WINDOW (f
));
3202 store_in_alist (alistptr
, Qwindow_id
,
3203 build_string (buf
));
3204 #ifdef HAVE_X_WINDOWS
3205 #ifdef USE_X_TOOLKIT
3206 /* Tooltip frame may not have this widget. */
3207 if (FRAME_X_OUTPUT (f
)->widget
)
3209 sprintf (buf
, "%ld", (long) FRAME_OUTER_WINDOW (f
));
3210 store_in_alist (alistptr
, Qouter_window_id
,
3211 build_string (buf
));
3213 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
3214 FRAME_SAMPLE_VISIBILITY (f
);
3215 store_in_alist (alistptr
, Qvisibility
,
3216 (FRAME_VISIBLE_P (f
) ? Qt
3217 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
3218 store_in_alist (alistptr
, Qdisplay
,
3219 XCAR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
3221 if (FRAME_X_OUTPUT (f
)->parent_desc
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
3224 XSETFASTINT (tem
, FRAME_X_OUTPUT (f
)->parent_desc
);
3225 store_in_alist (alistptr
, Qparent_id
, tem
);
3229 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3230 the previous value of that parameter, NEW_VALUE is the new value. */
3233 x_set_fullscreen (f
, new_value
, old_value
)
3235 Lisp_Object new_value
, old_value
;
3237 if (NILP (new_value
))
3238 f
->want_fullscreen
= FULLSCREEN_NONE
;
3239 else if (EQ (new_value
, Qfullboth
))
3240 f
->want_fullscreen
= FULLSCREEN_BOTH
;
3241 else if (EQ (new_value
, Qfullwidth
))
3242 f
->want_fullscreen
= FULLSCREEN_WIDTH
;
3243 else if (EQ (new_value
, Qfullheight
))
3244 f
->want_fullscreen
= FULLSCREEN_HEIGHT
;
3248 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3249 the previous value of that parameter, NEW_VALUE is the new value. */
3252 x_set_line_spacing (f
, new_value
, old_value
)
3254 Lisp_Object new_value
, old_value
;
3256 if (NILP (new_value
))
3257 f
->extra_line_spacing
= 0;
3258 else if (NATNUMP (new_value
))
3259 f
->extra_line_spacing
= XFASTINT (new_value
);
3261 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
3262 Fcons (new_value
, Qnil
)));
3263 if (FRAME_VISIBLE_P (f
))
3268 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3269 the previous value of that parameter, NEW_VALUE is the new value. */
3272 x_set_screen_gamma (f
, new_value
, old_value
)
3274 Lisp_Object new_value
, old_value
;
3276 if (NILP (new_value
))
3278 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
3279 /* The value 0.4545 is the normal viewing gamma. */
3280 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
3282 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
3283 Fcons (new_value
, Qnil
)));
3285 clear_face_cache (0);
3290 x_set_font (f
, arg
, oldval
)
3292 Lisp_Object arg
, oldval
;
3295 Lisp_Object fontset_name
;
3297 int old_fontset
= FRAME_FONTSET(f
);
3301 fontset_name
= Fquery_fontset (arg
, Qnil
);
3304 result
= (STRINGP (fontset_name
)
3305 ? x_new_fontset (f
, SDATA (fontset_name
))
3306 : x_new_font (f
, SDATA (arg
)));
3309 if (EQ (result
, Qnil
))
3310 error ("Font `%s' is not defined", SDATA (arg
));
3311 else if (EQ (result
, Qt
))
3312 error ("The characters of the given font have varying widths");
3313 else if (STRINGP (result
))
3315 set_default_ascii_font (result
);
3316 if (STRINGP (fontset_name
))
3318 /* Fontset names are built from ASCII font names, so the
3319 names may be equal despite there was a change. */
3320 if (old_fontset
== FRAME_FONTSET (f
))
3323 else if (!NILP (Fequal (result
, oldval
)))
3326 store_frame_param (f
, Qfont
, result
);
3327 recompute_basic_faces (f
);
3332 do_pending_window_change (0);
3334 /* Don't call `face-set-after-frame-default' when faces haven't been
3335 initialized yet. This is the case when called from
3336 Fx_create_frame. In that case, the X widget or window doesn't
3337 exist either, and we can end up in x_report_frame_params with a
3338 null widget which gives a segfault. */
3339 if (FRAME_FACE_CACHE (f
))
3341 XSETFRAME (frame
, f
);
3342 call1 (Qface_set_after_frame_default
, frame
);
3348 x_set_fringe_width (f
, new_value
, old_value
)
3350 Lisp_Object new_value
, old_value
;
3352 compute_fringe_widths (f
, 1);
3356 x_set_border_width (f
, arg
, oldval
)
3358 Lisp_Object arg
, oldval
;
3362 if (XINT (arg
) == f
->border_width
)
3366 if (FRAME_X_WINDOW (f
) != 0)
3367 error ("Cannot change the border width of a window");
3368 #endif /* MAC_TODO */
3370 f
->border_width
= XINT (arg
);
3374 x_set_internal_border_width (f
, arg
, oldval
)
3376 Lisp_Object arg
, oldval
;
3378 int old
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3381 FRAME_INTERNAL_BORDER_WIDTH (f
) = XINT (arg
);
3382 if (FRAME_INTERNAL_BORDER_WIDTH (f
) < 0)
3383 FRAME_INTERNAL_BORDER_WIDTH (f
) = 0;
3385 #ifdef USE_X_TOOLKIT
3386 if (FRAME_X_OUTPUT (f
)->edit_widget
)
3387 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
3390 if (FRAME_INTERNAL_BORDER_WIDTH (f
) == old
)
3393 if (FRAME_X_WINDOW (f
) != 0)
3395 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
3396 SET_FRAME_GARBAGED (f
);
3397 do_pending_window_change (0);
3400 SET_FRAME_GARBAGED (f
);
3404 x_set_visibility (f
, value
, oldval
)
3406 Lisp_Object value
, oldval
;
3409 XSETFRAME (frame
, f
);
3412 Fmake_frame_invisible (frame
, Qt
);
3413 else if (EQ (value
, Qicon
))
3414 Ficonify_frame (frame
);
3416 Fmake_frame_visible (frame
);
3420 x_set_autoraise (f
, arg
, oldval
)
3422 Lisp_Object arg
, oldval
;
3424 f
->auto_raise
= !EQ (Qnil
, arg
);
3428 x_set_autolower (f
, arg
, oldval
)
3430 Lisp_Object arg
, oldval
;
3432 f
->auto_lower
= !EQ (Qnil
, arg
);
3436 x_set_unsplittable (f
, arg
, oldval
)
3438 Lisp_Object arg
, oldval
;
3440 f
->no_split
= !NILP (arg
);
3444 x_set_vertical_scroll_bars (f
, arg
, oldval
)
3446 Lisp_Object arg
, oldval
;
3448 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3449 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
3450 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3451 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
3453 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
)
3455 ? vertical_scroll_bar_none
3457 ? vertical_scroll_bar_left
3459 ? vertical_scroll_bar_right
3460 : EQ (Qleft
, Vdefault_frame_scroll_bars
)
3461 ? vertical_scroll_bar_left
3462 : EQ (Qright
, Vdefault_frame_scroll_bars
)
3463 ? vertical_scroll_bar_right
3464 : vertical_scroll_bar_none
);
3466 /* We set this parameter before creating the X window for the
3467 frame, so we can get the geometry right from the start.
3468 However, if the window hasn't been created yet, we shouldn't
3469 call x_set_window_size. */
3470 if (FRAME_X_WINDOW (f
))
3471 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
3472 do_pending_window_change (0);
3477 x_set_scroll_bar_width (f
, arg
, oldval
)
3479 Lisp_Object arg
, oldval
;
3481 int wid
= FRAME_COLUMN_WIDTH (f
);
3485 x_set_scroll_bar_default_width (f
);
3487 if (FRAME_X_WINDOW (f
))
3488 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
3489 do_pending_window_change (0);
3491 else if (INTEGERP (arg
) && XINT (arg
) > 0
3492 && XFASTINT (arg
) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3494 if (XFASTINT (arg
) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
3495 XSETINT (arg
, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
+ 1);
3497 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = XFASTINT (arg
);
3498 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (XFASTINT (arg
) + wid
-1) / wid
;
3499 if (FRAME_X_WINDOW (f
))
3500 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
3501 do_pending_window_change (0);
3504 change_frame_size (f
, 0, FRAME_COLS (f
), 0, 0, 0);
3505 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
3506 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
3511 /* Return non-nil if frame F wants a bitmap icon. */
3519 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
3527 /* Subroutines of creating an X frame. */
3529 /* Make sure that Vx_resource_name is set to a reasonable value.
3530 Fix it up, or set it to `emacs' if it is too hopeless. */
3533 validate_x_resource_name ()
3536 /* Number of valid characters in the resource name. */
3538 /* Number of invalid characters in the resource name. */
3543 if (!STRINGP (Vx_resource_class
))
3544 Vx_resource_class
= build_string (EMACS_CLASS
);
3546 if (STRINGP (Vx_resource_name
))
3548 unsigned char *p
= SDATA (Vx_resource_name
);
3551 len
= SBYTES (Vx_resource_name
);
3553 /* Only letters, digits, - and _ are valid in resource names.
3554 Count the valid characters and count the invalid ones. */
3555 for (i
= 0; i
< len
; i
++)
3558 if (! ((c
>= 'a' && c
<= 'z')
3559 || (c
>= 'A' && c
<= 'Z')
3560 || (c
>= '0' && c
<= '9')
3561 || c
== '-' || c
== '_'))
3568 /* Not a string => completely invalid. */
3569 bad_count
= 5, good_count
= 0;
3571 /* If name is valid already, return. */
3575 /* If name is entirely invalid, or nearly so, use `emacs'. */
3577 || (good_count
== 1 && bad_count
> 0))
3579 Vx_resource_name
= build_string ("emacs");
3583 /* Name is partly valid. Copy it and replace the invalid characters
3584 with underscores. */
3586 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
3588 for (i
= 0; i
< len
; i
++)
3590 int c
= SREF (new, i
);
3591 if (! ((c
>= 'a' && c
<= 'z')
3592 || (c
>= 'A' && c
<= 'Z')
3593 || (c
>= '0' && c
<= '9')
3594 || c
== '-' || c
== '_'))
3600 extern char *x_get_string_resource
P_ ((XrmDatabase
, char *, char *));
3601 extern Display_Info
*check_x_display_info
P_ ((Lisp_Object
));
3604 /* Get specified attribute from resource database RDB.
3605 See Fx_get_resource below for other parameters. */
3608 xrdb_get_resource (rdb
, attribute
, class, component
, subclass
)
3610 Lisp_Object attribute
, class, component
, subclass
;
3612 register char *value
;
3616 CHECK_STRING (attribute
);
3617 CHECK_STRING (class);
3619 if (!NILP (component
))
3620 CHECK_STRING (component
);
3621 if (!NILP (subclass
))
3622 CHECK_STRING (subclass
);
3623 if (NILP (component
) != NILP (subclass
))
3624 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3626 validate_x_resource_name ();
3628 /* Allocate space for the components, the dots which separate them,
3629 and the final '\0'. Make them big enough for the worst case. */
3630 name_key
= (char *) alloca (SBYTES (Vx_resource_name
)
3631 + (STRINGP (component
)
3632 ? SBYTES (component
) : 0)
3633 + SBYTES (attribute
)
3636 class_key
= (char *) alloca (SBYTES (Vx_resource_class
)
3638 + (STRINGP (subclass
)
3639 ? SBYTES (subclass
) : 0)
3642 /* Start with emacs.FRAMENAME for the name (the specific one)
3643 and with `Emacs' for the class key (the general one). */
3644 strcpy (name_key
, SDATA (Vx_resource_name
));
3645 strcpy (class_key
, SDATA (Vx_resource_class
));
3647 strcat (class_key
, ".");
3648 strcat (class_key
, SDATA (class));
3650 if (!NILP (component
))
3652 strcat (class_key
, ".");
3653 strcat (class_key
, SDATA (subclass
));
3655 strcat (name_key
, ".");
3656 strcat (name_key
, SDATA (component
));
3659 strcat (name_key
, ".");
3660 strcat (name_key
, SDATA (attribute
));
3662 value
= x_get_string_resource (rdb
, name_key
, class_key
);
3664 if (value
!= (char *) 0)
3665 return build_string (value
);
3671 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
3672 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3673 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3674 class, where INSTANCE is the name under which Emacs was invoked, or
3675 the name specified by the `-name' or `-rn' command-line arguments.
3677 The optional arguments COMPONENT and SUBCLASS add to the key and the
3678 class, respectively. You must specify both of them or neither.
3679 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3680 and the class is `Emacs.CLASS.SUBCLASS'. */)
3681 (attribute
, class, component
, subclass
)
3682 Lisp_Object attribute
, class, component
, subclass
;
3684 #ifdef HAVE_X_WINDOWS
3688 return xrdb_get_resource (check_x_display_info (Qnil
)->xrdb
,
3689 attribute
, class, component
, subclass
);
3692 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3695 display_x_get_resource (dpyinfo
, attribute
, class, component
, subclass
)
3696 Display_Info
*dpyinfo
;
3697 Lisp_Object attribute
, class, component
, subclass
;
3699 return xrdb_get_resource (dpyinfo
->xrdb
,
3700 attribute
, class, component
, subclass
);
3703 /* Used when C code wants a resource value. */
3706 x_get_resource_string (attribute
, class)
3707 char *attribute
, *class;
3711 struct frame
*sf
= SELECTED_FRAME ();
3713 /* Allocate space for the components, the dots which separate them,
3714 and the final '\0'. */
3715 name_key
= (char *) alloca (SBYTES (Vinvocation_name
)
3716 + strlen (attribute
) + 2);
3717 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
3718 + strlen (class) + 2);
3720 sprintf (name_key
, "%s.%s", SDATA (Vinvocation_name
), attribute
);
3721 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3723 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf
)->xrdb
,
3724 name_key
, class_key
);
3728 /* Return the value of parameter PARAM.
3730 First search ALIST, then Vdefault_frame_alist, then the X defaults
3731 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3733 Convert the resource to the type specified by desired_type.
3735 If no default is specified, return Qunbound. If you call
3736 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3737 and don't let it get stored in any Lisp-visible variables! */
3740 x_get_arg (dpyinfo
, alist
, param
, attribute
, class, type
)
3741 Display_Info
*dpyinfo
;
3742 Lisp_Object alist
, param
;
3745 enum resource_types type
;
3747 register Lisp_Object tem
;
3749 tem
= Fassq (param
, alist
);
3751 tem
= Fassq (param
, Vdefault_frame_alist
);
3756 tem
= display_x_get_resource (dpyinfo
,
3757 build_string (attribute
),
3758 build_string (class),
3766 case RES_TYPE_NUMBER
:
3767 return make_number (atoi (SDATA (tem
)));
3769 case RES_TYPE_FLOAT
:
3770 return make_float (atof (SDATA (tem
)));
3772 case RES_TYPE_BOOLEAN
:
3773 tem
= Fdowncase (tem
);
3774 if (!strcmp (SDATA (tem
), "on")
3775 || !strcmp (SDATA (tem
), "true"))
3780 case RES_TYPE_STRING
:
3783 case RES_TYPE_SYMBOL
:
3784 /* As a special case, we map the values `true' and `on'
3785 to Qt, and `false' and `off' to Qnil. */
3788 lower
= Fdowncase (tem
);
3789 if (!strcmp (SDATA (lower
), "on")
3790 || !strcmp (SDATA (lower
), "true"))
3792 else if (!strcmp (SDATA (lower
), "off")
3793 || !strcmp (SDATA (lower
), "false"))
3796 return Fintern (tem
, Qnil
);
3810 x_frame_get_arg (f
, alist
, param
, attribute
, class, type
)
3812 Lisp_Object alist
, param
;
3815 enum resource_types type
;
3817 return x_get_arg (FRAME_X_DISPLAY_INFO (f
),
3818 alist
, param
, attribute
, class, type
);
3821 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3824 x_frame_get_and_record_arg (f
, alist
, param
, attribute
, class, type
)
3826 Lisp_Object alist
, param
;
3829 enum resource_types type
;
3833 value
= x_get_arg (FRAME_X_DISPLAY_INFO (f
), alist
, param
,
3834 attribute
, class, type
);
3836 store_frame_param (f
, param
, value
);
3842 /* Record in frame F the specified or default value according to ALIST
3843 of the parameter named PROP (a Lisp symbol).
3844 If no value is specified for PROP, look for an X default for XPROP
3845 on the frame named NAME.
3846 If that is not found either, use the value DEFLT. */
3849 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3856 enum resource_types type
;
3860 tem
= x_frame_get_arg (f
, alist
, prop
, xprop
, xclass
, type
);
3861 if (EQ (tem
, Qunbound
))
3863 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3870 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3871 doc
: /* Parse an X-style geometry string STRING.
3872 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3873 The properties returned may include `top', `left', `height', and `width'.
3874 The value of `left' or `top' may be an integer,
3875 or a list (+ N) meaning N pixels relative to top/left corner,
3876 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3881 unsigned int width
, height
;
3884 CHECK_STRING (string
);
3886 geometry
= XParseGeometry ((char *) SDATA (string
),
3887 &x
, &y
, &width
, &height
);
3890 if (!!(geometry
& XValue
) != !!(geometry
& YValue
))
3891 error ("Must specify both x and y position, or neither");
3895 if (geometry
& XValue
)
3897 Lisp_Object element
;
3899 if (x
>= 0 && (geometry
& XNegative
))
3900 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3901 else if (x
< 0 && ! (geometry
& XNegative
))
3902 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3904 element
= Fcons (Qleft
, make_number (x
));
3905 result
= Fcons (element
, result
);
3908 if (geometry
& YValue
)
3910 Lisp_Object element
;
3912 if (y
>= 0 && (geometry
& YNegative
))
3913 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3914 else if (y
< 0 && ! (geometry
& YNegative
))
3915 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3917 element
= Fcons (Qtop
, make_number (y
));
3918 result
= Fcons (element
, result
);
3921 if (geometry
& WidthValue
)
3922 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3923 if (geometry
& HeightValue
)
3924 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3929 /* Calculate the desired size and position of frame F.
3930 Return the flags saying which aspects were specified.
3932 Also set the win_gravity and size_hint_flags of F.
3934 Adjust height for toolbar if TOOLBAR_P is 1.
3936 This function does not make the coordinates positive. */
3938 #define DEFAULT_ROWS 40
3939 #define DEFAULT_COLS 80
3942 x_figure_window_size (f
, parms
, toolbar_p
)
3947 register Lisp_Object tem0
, tem1
, tem2
;
3948 long window_prompting
= 0;
3949 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3951 /* Default values if we fall through.
3952 Actually, if that happens we should get
3953 window manager prompting. */
3954 SET_FRAME_COLS (f
, DEFAULT_COLS
);
3955 FRAME_LINES (f
) = DEFAULT_ROWS
;
3956 /* Window managers expect that if program-specified
3957 positions are not (0,0), they're intentional, not defaults. */
3961 /* Ensure that old new_text_cols and new_text_lines will not override the
3963 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3964 f
->new_text_cols
= f
->new_text_lines
= 0;
3966 tem0
= x_get_arg (dpyinfo
, parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3967 tem1
= x_get_arg (dpyinfo
, parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3968 tem2
= x_get_arg (dpyinfo
, parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3969 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3971 if (!EQ (tem0
, Qunbound
))
3973 CHECK_NUMBER (tem0
);
3974 FRAME_LINES (f
) = XINT (tem0
);
3976 if (!EQ (tem1
, Qunbound
))
3978 CHECK_NUMBER (tem1
);
3979 SET_FRAME_COLS (f
, XINT (tem1
));
3981 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3982 window_prompting
|= USSize
;
3984 window_prompting
|= PSize
;
3987 f
->scroll_bar_actual_width
3988 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
3990 /* This used to be done _before_ calling x_figure_window_size, but
3991 since the height is reset here, this was really a no-op. I
3992 assume that moving it here does what Gerd intended (although he
3993 no longer can remember what that was... ++KFS, 2003-03-25. */
3995 /* Add the tool-bar height to the initial frame height so that the
3996 user gets a text display area of the size he specified with -g or
3997 via .Xdefaults. Later changes of the tool-bar height don't
3998 change the frame size. This is done so that users can create
3999 tall Emacs frames without having to guess how tall the tool-bar
4001 if (toolbar_p
&& FRAME_TOOL_BAR_LINES (f
))
4003 int margin
, relief
, bar_height
;
4005 relief
= (tool_bar_button_relief
>= 0
4006 ? tool_bar_button_relief
4007 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
4009 if (INTEGERP (Vtool_bar_button_margin
)
4010 && XINT (Vtool_bar_button_margin
) > 0)
4011 margin
= XFASTINT (Vtool_bar_button_margin
);
4012 else if (CONSP (Vtool_bar_button_margin
)
4013 && INTEGERP (XCDR (Vtool_bar_button_margin
))
4014 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
4015 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
4019 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
4020 FRAME_LINES (f
) += (bar_height
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
4023 compute_fringe_widths (f
, 0);
4025 FRAME_PIXEL_WIDTH (f
) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, FRAME_COLS (f
));
4026 FRAME_PIXEL_HEIGHT (f
) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
4028 tem0
= x_get_arg (dpyinfo
, parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
4029 tem1
= x_get_arg (dpyinfo
, parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
4030 tem2
= x_get_arg (dpyinfo
, parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
4031 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
4033 if (EQ (tem0
, Qminus
))
4036 window_prompting
|= YNegative
;
4038 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
4039 && CONSP (XCDR (tem0
))
4040 && INTEGERP (XCAR (XCDR (tem0
))))
4042 f
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
4043 window_prompting
|= YNegative
;
4045 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
4046 && CONSP (XCDR (tem0
))
4047 && INTEGERP (XCAR (XCDR (tem0
))))
4049 f
->top_pos
= XINT (XCAR (XCDR (tem0
)));
4051 else if (EQ (tem0
, Qunbound
))
4055 CHECK_NUMBER (tem0
);
4056 f
->top_pos
= XINT (tem0
);
4058 window_prompting
|= YNegative
;
4061 if (EQ (tem1
, Qminus
))
4064 window_prompting
|= XNegative
;
4066 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
4067 && CONSP (XCDR (tem1
))
4068 && INTEGERP (XCAR (XCDR (tem1
))))
4070 f
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
4071 window_prompting
|= XNegative
;
4073 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
4074 && CONSP (XCDR (tem1
))
4075 && INTEGERP (XCAR (XCDR (tem1
))))
4077 f
->left_pos
= XINT (XCAR (XCDR (tem1
)));
4079 else if (EQ (tem1
, Qunbound
))
4083 CHECK_NUMBER (tem1
);
4084 f
->left_pos
= XINT (tem1
);
4085 if (f
->left_pos
< 0)
4086 window_prompting
|= XNegative
;
4089 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
4090 window_prompting
|= USPosition
;
4092 window_prompting
|= PPosition
;
4095 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
4100 /* It takes both for some WM:s to place it where we want */
4101 window_prompting
= USPosition
| PPosition
;
4102 x_fullscreen_adjust (f
, &width
, &height
, &top
, &left
);
4103 FRAME_COLS (f
) = width
;
4104 FRAME_LINES (f
) = height
;
4105 FRAME_PIXEL_WIDTH (f
) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, width
);
4106 FRAME_PIXEL_HEIGHT (f
) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, height
);
4111 if (window_prompting
& XNegative
)
4113 if (window_prompting
& YNegative
)
4114 f
->win_gravity
= SouthEastGravity
;
4116 f
->win_gravity
= NorthEastGravity
;
4120 if (window_prompting
& YNegative
)
4121 f
->win_gravity
= SouthWestGravity
;
4123 f
->win_gravity
= NorthWestGravity
;
4126 f
->size_hint_flags
= window_prompting
;
4128 return window_prompting
;
4133 #endif /* HAVE_WINDOW_SYSTEM */
4137 /***********************************************************************
4139 ***********************************************************************/
4144 Qframep
= intern ("framep");
4145 staticpro (&Qframep
);
4146 Qframe_live_p
= intern ("frame-live-p");
4147 staticpro (&Qframe_live_p
);
4148 Qheight
= intern ("height");
4149 staticpro (&Qheight
);
4150 Qicon
= intern ("icon");
4152 Qminibuffer
= intern ("minibuffer");
4153 staticpro (&Qminibuffer
);
4154 Qmodeline
= intern ("modeline");
4155 staticpro (&Qmodeline
);
4156 Qonly
= intern ("only");
4158 Qwidth
= intern ("width");
4159 staticpro (&Qwidth
);
4160 Qgeometry
= intern ("geometry");
4161 staticpro (&Qgeometry
);
4162 Qicon_left
= intern ("icon-left");
4163 staticpro (&Qicon_left
);
4164 Qicon_top
= intern ("icon-top");
4165 staticpro (&Qicon_top
);
4166 Qleft
= intern ("left");
4168 Qright
= intern ("right");
4169 staticpro (&Qright
);
4170 Quser_position
= intern ("user-position");
4171 staticpro (&Quser_position
);
4172 Quser_size
= intern ("user-size");
4173 staticpro (&Quser_size
);
4174 Qwindow_id
= intern ("window-id");
4175 staticpro (&Qwindow_id
);
4176 #ifdef HAVE_X_WINDOWS
4177 Qouter_window_id
= intern ("outer-window-id");
4178 staticpro (&Qouter_window_id
);
4180 Qparent_id
= intern ("parent-id");
4181 staticpro (&Qparent_id
);
4184 Qw32
= intern ("w32");
4186 Qpc
= intern ("pc");
4188 Qmac
= intern ("mac");
4190 Qvisible
= intern ("visible");
4191 staticpro (&Qvisible
);
4192 Qbuffer_predicate
= intern ("buffer-predicate");
4193 staticpro (&Qbuffer_predicate
);
4194 Qbuffer_list
= intern ("buffer-list");
4195 staticpro (&Qbuffer_list
);
4196 Qdisplay_type
= intern ("display-type");
4197 staticpro (&Qdisplay_type
);
4198 Qbackground_mode
= intern ("background-mode");
4199 staticpro (&Qbackground_mode
);
4200 Qtty_color_mode
= intern ("tty-color-mode");
4201 staticpro (&Qtty_color_mode
);
4202 Qtty
= intern ("tty");
4204 Qtty_type
= intern ("tty-type");
4205 staticpro (&Qtty_type
);
4206 Qwindow_system
= intern ("window-system");
4207 staticpro (&Qwindow_system
);
4209 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
4210 staticpro (&Qface_set_after_frame_default
);
4212 Qfullwidth
= intern ("fullwidth");
4213 staticpro (&Qfullwidth
);
4214 Qfullheight
= intern ("fullheight");
4215 staticpro (&Qfullheight
);
4216 Qfullboth
= intern ("fullboth");
4217 staticpro (&Qfullboth
);
4218 Qx_resource_name
= intern ("x-resource-name");
4219 staticpro (&Qx_resource_name
);
4221 Qx_frame_parameter
= intern ("x-frame-parameter");
4222 staticpro (&Qx_frame_parameter
);
4224 Qdisplay_id
= intern ("display-id");
4225 staticpro (&Qdisplay_id
);
4226 Qdisplay_live_p
= intern ("display-live-p");
4227 staticpro (&Qdisplay_live_p
);
4232 for (i
= 0; i
< sizeof (frame_parms
) / sizeof (frame_parms
[0]); i
++)
4234 Lisp_Object v
= intern (frame_parms
[i
].name
);
4235 if (frame_parms
[i
].variable
)
4237 *frame_parms
[i
].variable
= v
;
4238 staticpro (frame_parms
[i
].variable
);
4240 Fput (v
, Qx_frame_parameter
, make_number (i
));
4244 #ifdef HAVE_WINDOW_SYSTEM
4245 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
4246 doc
: /* The name Emacs uses to look up X resources.
4247 `x-get-resource' uses this as the first component of the instance name
4248 when requesting resource values.
4249 Emacs initially sets `x-resource-name' to the name under which Emacs
4250 was invoked, or to the value specified with the `-name' or `-rn'
4251 switches, if present.
4253 It may be useful to bind this variable locally around a call
4254 to `x-get-resource'. See also the variable `x-resource-class'. */);
4255 Vx_resource_name
= Qnil
;
4257 DEFVAR_LISP ("x-resource-class", &Vx_resource_class
,
4258 doc
: /* The class Emacs uses to look up X resources.
4259 `x-get-resource' uses this as the first component of the instance class
4260 when requesting resource values.
4262 Emacs initially sets `x-resource-class' to "Emacs".
4264 Setting this variable permanently is not a reasonable thing to do,
4265 but binding this variable locally around a call to `x-get-resource'
4266 is a reasonable practice. See also the variable `x-resource-name'. */);
4267 Vx_resource_class
= build_string (EMACS_CLASS
);
4270 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist
,
4271 doc
: /* Alist of default values for frame creation.
4272 These may be set in your init file, like this:
4273 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4274 These override values given in window system configuration data,
4275 including X Windows' defaults database.
4276 For values specific to the first Emacs frame, see `initial-frame-alist'.
4277 For values specific to the separate minibuffer frame, see
4278 `minibuffer-frame-alist'.
4279 The `menu-bar-lines' element of the list controls whether new frames
4280 have menu bars; `menu-bar-mode' works by altering this element.
4281 Setting this variable does not affect existing frames, only new ones. */);
4282 Vdefault_frame_alist
= Qnil
;
4284 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars
,
4285 doc
: /* Default position of scroll bars on this window-system. */);
4286 #ifdef HAVE_WINDOW_SYSTEM
4287 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4288 /* MS-Windows has scroll bars on the right by default. */
4289 Vdefault_frame_scroll_bars
= Qright
;
4291 Vdefault_frame_scroll_bars
= Qleft
;
4294 Vdefault_frame_scroll_bars
= Qnil
;
4297 Qinhibit_default_face_x_resources
4298 = intern ("inhibit-default-face-x-resources");
4299 staticpro (&Qinhibit_default_face_x_resources
);
4301 DEFVAR_LISP ("terminal-frame", &Vterminal_frame
,
4302 doc
: /* The initial frame-object, which represents Emacs's stdout. */);
4304 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified
,
4305 doc
: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4306 Vemacs_iconified
= Qnil
;
4308 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function
,
4309 doc
: /* If non-nil, function to transform normal value of `mouse-position'.
4310 `mouse-position' calls this function, passing its usual return value as
4311 argument, and returns whatever this function returns.
4312 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4313 which need to do mouse handling at the Lisp level. */);
4314 Vmouse_position_function
= Qnil
;
4316 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight
,
4317 doc
: /* If non-nil, clickable text is highlighted when mouse is over it.
4318 If the value is an integer, highlighting is only shown after moving the
4319 mouse, while keyboard input turns off the highlight even when the mouse
4320 is over the clickable text. However, the mouse shape still indicates
4321 when the mouse is over clickable text. */);
4322 Vmouse_highlight
= Qt
;
4324 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions
,
4325 doc
: /* Functions to be run before deleting a frame.
4326 The functions are run with one arg, the frame to be deleted.
4327 See `delete-frame'. */);
4328 Vdelete_frame_functions
= Qnil
;
4330 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame
,
4331 doc
: /* Minibufferless frames use this frame's minibuffer.
4333 Emacs cannot create minibufferless frames unless this is set to an
4334 appropriate surrogate.
4336 Emacs consults this variable only when creating minibufferless
4337 frames; once the frame is created, it sticks with its assigned
4338 minibuffer, no matter what this variable is set to. This means that
4339 this variable doesn't necessarily say anything meaningful about the
4340 current set of frames, or where the minibuffer is currently being
4343 This variable is local to the current terminal and cannot be buffer-local. */);
4345 staticpro (&Vframe_list
);
4347 defsubr (&Sactive_minibuffer_window
);
4349 defsubr (&Sframe_live_p
);
4350 defsubr (&Swindow_system
);
4351 defsubr (&Smake_terminal_frame
);
4352 defsubr (&Shandle_switch_frame
);
4353 defsubr (&Sselect_frame
);
4354 defsubr (&Sselected_frame
);
4355 defsubr (&Swindow_frame
);
4356 defsubr (&Sframe_root_window
);
4357 defsubr (&Sframe_first_window
);
4358 defsubr (&Sframe_selected_window
);
4359 defsubr (&Sset_frame_selected_window
);
4360 defsubr (&Sframe_display
);
4361 defsubr (&Sframe_list
);
4362 defsubr (&Snext_frame
);
4363 defsubr (&Sprevious_frame
);
4364 defsubr (&Sdelete_frame
);
4365 defsubr (&Smouse_position
);
4366 defsubr (&Smouse_pixel_position
);
4367 defsubr (&Sset_mouse_position
);
4368 defsubr (&Sset_mouse_pixel_position
);
4370 defsubr (&Sframe_configuration
);
4371 defsubr (&Srestore_frame_configuration
);
4373 defsubr (&Smake_frame_visible
);
4374 defsubr (&Smake_frame_invisible
);
4375 defsubr (&Siconify_frame
);
4376 defsubr (&Sframe_visible_p
);
4377 defsubr (&Svisible_frame_list
);
4378 defsubr (&Sraise_frame
);
4379 defsubr (&Slower_frame
);
4380 defsubr (&Sredirect_frame_focus
);
4381 defsubr (&Sframe_focus
);
4382 defsubr (&Sframe_parameters
);
4383 defsubr (&Sframe_parameter
);
4384 defsubr (&Smodify_frame_parameters
);
4385 defsubr (&Sframe_char_height
);
4386 defsubr (&Sframe_char_width
);
4387 defsubr (&Sframe_pixel_height
);
4388 defsubr (&Sframe_pixel_width
);
4389 defsubr (&Sset_frame_height
);
4390 defsubr (&Sset_frame_width
);
4391 defsubr (&Sset_frame_size
);
4392 defsubr (&Sset_frame_position
);
4394 #ifdef HAVE_WINDOW_SYSTEM
4395 defsubr (&Sx_get_resource
);
4396 defsubr (&Sx_parse_geometry
);
4401 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4402 (do not change this comment) */