1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2014 Free Software Foundation, Inc.
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 3 of the License, or
10 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
29 #include "character.h"
31 #ifdef HAVE_WINDOW_SYSTEM
33 #endif /* HAVE_WINDOW_SYSTEM */
36 /* These help us bind and responding to switch-frame events. */
40 #include "blockinput.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
46 #ifdef HAVE_WINDOW_SYSTEM
59 Lisp_Object Qns_parse_geometry
;
62 Lisp_Object Qframep
, Qframe_live_p
;
63 Lisp_Object Qicon
, Qmodeline
;
64 Lisp_Object Qonly
, Qnone
;
65 Lisp_Object Qx
, Qw32
, Qpc
, Qns
;
67 Lisp_Object Qdisplay_type
;
68 static Lisp_Object Qbackground_mode
;
71 static Lisp_Object Qx_frame_parameter
;
72 Lisp_Object Qx_resource_name
;
73 Lisp_Object Qterminal
;
75 /* Frame parameters (set or reported). */
77 Lisp_Object Qauto_raise
, Qauto_lower
;
78 Lisp_Object Qborder_color
, Qborder_width
;
79 Lisp_Object Qcursor_color
, Qcursor_type
;
80 Lisp_Object Qheight
, Qwidth
;
81 Lisp_Object Qicon_left
, Qicon_top
, Qicon_type
, Qicon_name
;
83 Lisp_Object Qinternal_border_width
;
84 Lisp_Object Qright_divider_width
, Qbottom_divider_width
;
85 Lisp_Object Qmouse_color
;
86 Lisp_Object Qminibuffer
;
87 Lisp_Object Qscroll_bar_width
, Qvertical_scroll_bars
;
88 Lisp_Object Qvisibility
;
89 Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
90 Lisp_Object Qscreen_gamma
;
91 Lisp_Object Qline_spacing
;
92 static Lisp_Object Quser_position
, Quser_size
;
93 Lisp_Object Qwait_for_wm
;
94 static Lisp_Object Qwindow_id
;
96 static Lisp_Object Qouter_window_id
;
98 Lisp_Object Qparent_id
;
99 Lisp_Object Qtitle
, Qname
;
100 static Lisp_Object Qexplicit_name
;
101 Lisp_Object Qunsplittable
;
102 Lisp_Object Qmenu_bar_lines
, Qtool_bar_lines
, Qtool_bar_position
;
103 Lisp_Object Qleft_fringe
, Qright_fringe
;
104 Lisp_Object Qbuffer_predicate
;
105 static Lisp_Object Qbuffer_list
, Qburied_buffer_list
;
106 Lisp_Object Qtty_color_mode
;
107 Lisp_Object Qtty
, Qtty_type
;
109 Lisp_Object Qfullscreen
, Qfullwidth
, Qfullheight
, Qfullboth
, Qmaximized
;
111 Lisp_Object Qfont_backend
;
114 Lisp_Object Qface_set_after_frame_default
;
116 static Lisp_Object Qfocus_in_hook
;
117 static Lisp_Object Qfocus_out_hook
;
118 static Lisp_Object Qdelete_frame_functions
;
120 static Lisp_Object Qgeometry
, Qworkarea
, Qmm_size
, Qframes
, Qsource
;
122 /* The currently selected frame. */
124 Lisp_Object selected_frame
;
126 /* A frame which is not just a mini-buffer, or NULL if there are no such
127 frames. This is usually the most recent such frame that was selected. */
129 static struct frame
*last_nonminibuf_frame
;
131 /* False means there are no visible garbaged frames. */
134 #ifdef HAVE_WINDOW_SYSTEM
135 static void x_report_frame_params (struct frame
*, Lisp_Object
*);
138 /* These setters are used only in this file, so they can be private. */
140 fset_buffer_predicate (struct frame
*f
, Lisp_Object val
)
142 f
->buffer_predicate
= val
;
145 fset_minibuffer_window (struct frame
*f
, Lisp_Object val
)
147 f
->minibuffer_window
= val
;
151 decode_live_frame (register Lisp_Object frame
)
154 frame
= selected_frame
;
155 CHECK_LIVE_FRAME (frame
);
156 return XFRAME (frame
);
160 decode_any_frame (register Lisp_Object frame
)
163 frame
= selected_frame
;
165 return XFRAME (frame
);
168 #ifdef HAVE_WINDOW_SYSTEM
171 window_system_available (struct frame
*f
)
173 return f
? FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
) : x_display_list
!= NULL
;
176 #endif /* HAVE_WINDOW_SYSTEM */
179 decode_window_system_frame (Lisp_Object frame
)
181 struct frame
*f
= decode_live_frame (frame
);
183 if (!window_system_available (f
))
184 error ("Window system frame should be used");
189 check_window_system (struct frame
*f
)
191 if (!window_system_available (f
))
192 error (f
? "Window system frame should be used"
193 : "Window system is not in use or not initialized");
197 set_menu_bar_lines_1 (Lisp_Object window
, int n
)
199 struct window
*w
= XWINDOW (window
);
200 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
203 w
->pixel_top
+= n
* FRAME_LINE_HEIGHT (f
);
205 w
->pixel_height
-= n
* FRAME_LINE_HEIGHT (f
);
207 /* Handle just the top child in a vertical split. */
208 if (WINDOW_VERTICAL_COMBINATION_P (w
))
209 set_menu_bar_lines_1 (w
->contents
, n
);
210 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
211 /* Adjust all children in a horizontal split. */
212 for (window
= w
->contents
; !NILP (window
); window
= w
->next
)
214 w
= XWINDOW (window
);
215 set_menu_bar_lines_1 (window
, n
);
220 set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
223 int olines
= FRAME_MENU_BAR_LINES (f
);
225 /* Right now, menu bars don't work properly in minibuf-only frames;
226 most of the commands try to apply themselves to the minibuffer
227 frame itself, and get an error because you can't switch buffers
228 in or split the minibuffer window. */
229 if (FRAME_MINIBUF_ONLY_P (f
))
232 if (TYPE_RANGED_INTEGERP (int, value
))
233 nlines
= XINT (value
);
237 if (nlines
!= olines
)
239 windows_or_buffers_changed
= 14;
240 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
241 FRAME_MENU_BAR_LINES (f
) = nlines
;
242 FRAME_MENU_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
243 set_menu_bar_lines_1 (f
->root_window
, nlines
- olines
);
244 adjust_frame_glyphs (f
);
248 Lisp_Object Vframe_list
;
251 DEFUN ("framep", Fframep
, Sframep
, 1, 1, 0,
252 doc
: /* Return non-nil if OBJECT is a frame.
254 t for a termcap frame (a character-only terminal),
255 'x' for an Emacs frame that is really an X window,
256 'w32' for an Emacs frame that is a window on MS-Windows display,
257 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
258 'pc' for a direct-write MS-DOS frame.
259 See also `frame-live-p'. */)
262 if (!FRAMEP (object
))
264 switch (XFRAME (object
)->output_method
)
266 case output_initial
: /* The initial frame is like a termcap frame. */
269 case output_x_window
:
273 case output_msdos_raw
:
282 DEFUN ("frame-live-p", Fframe_live_p
, Sframe_live_p
, 1, 1, 0,
283 doc
: /* Return non-nil if OBJECT is a frame which has not been deleted.
284 Value is nil if OBJECT is not a live frame. If object is a live
285 frame, the return value indicates what sort of terminal device it is
286 displayed on. See the documentation of `framep' for possible
290 return ((FRAMEP (object
)
291 && FRAME_LIVE_P (XFRAME (object
)))
296 DEFUN ("window-system", Fwindow_system
, Swindow_system
, 0, 1, 0,
297 doc
: /* The name of the window system that FRAME is displaying through.
298 The value is a symbol:
299 nil for a termcap frame (a character-only terminal),
300 'x' for an Emacs frame that is really an X window,
301 'w32' for an Emacs frame that is a window on MS-Windows display,
302 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
303 'pc' for a direct-write MS-DOS frame.
305 FRAME defaults to the currently selected frame.
307 Use of this function as a predicate is deprecated. Instead,
308 use `display-graphic-p' or any of the other `display-*-p'
309 predicates which report frame's specific UI-related capabilities. */)
314 frame
= selected_frame
;
316 type
= Fframep (frame
);
319 wrong_type_argument (Qframep
, frame
);
328 make_frame (bool mini_p
)
331 register struct frame
*f
;
332 register struct window
*rw
, *mw
;
333 register Lisp_Object root_window
;
334 register Lisp_Object mini_window
;
336 f
= allocate_frame ();
337 XSETFRAME (frame
, f
);
340 /* Initialize Lisp data. Note that allocate_frame initializes all
341 Lisp data to nil, so do it only for slots which should not be nil. */
342 fset_tool_bar_position (f
, Qtop
);
345 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
346 non-Lisp data, so do it only for slots which should not be zero.
347 To avoid subtle bugs and for the sake of readability, it's better to
348 initialize enum members explicitly even if their values are zero. */
349 f
->wants_modeline
= true;
352 f
->column_width
= 1; /* !FRAME_WINDOW_P value. */
353 f
->line_height
= 1; /* !FRAME_WINDOW_P value. */
354 #ifdef HAVE_WINDOW_SYSTEM
355 f
->vertical_scroll_bar_type
= vertical_scroll_bar_none
;
356 f
->want_fullscreen
= FULLSCREEN_NONE
;
357 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
358 f
->last_tool_bar_item
= -1;
362 root_window
= make_window ();
363 rw
= XWINDOW (root_window
);
366 mini_window
= make_window ();
367 mw
= XWINDOW (mini_window
);
368 wset_next (rw
, mini_window
);
369 wset_prev (mw
, root_window
);
371 wset_frame (mw
, frame
);
372 fset_minibuffer_window (f
, mini_window
);
377 wset_next (rw
, Qnil
);
378 fset_minibuffer_window (f
, Qnil
);
381 wset_frame (rw
, frame
);
384 just so that there is "something there."
385 Correct size will be set up later with change_frame_size. */
387 SET_FRAME_COLS (f
, 10);
388 FRAME_LINES (f
) = 10;
389 SET_FRAME_WIDTH (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
390 SET_FRAME_HEIGHT (f
, FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
));
393 rw
->pixel_width
= rw
->total_cols
* FRAME_COLUMN_WIDTH (f
);
394 rw
->total_lines
= mini_p
? 9 : 10;
395 rw
->pixel_height
= rw
->total_lines
* FRAME_LINE_HEIGHT (f
);
399 mw
->top_line
= rw
->total_lines
;
400 mw
->pixel_top
= rw
->pixel_height
;
401 mw
->total_cols
= rw
->total_cols
;
402 mw
->pixel_width
= rw
->pixel_width
;
404 mw
->pixel_height
= FRAME_LINE_HEIGHT (f
);
407 /* Choose a buffer for the frame's root window. */
409 Lisp_Object buf
= Fcurrent_buffer ();
411 /* If current buffer is hidden, try to find another one. */
412 if (BUFFER_HIDDEN_P (XBUFFER (buf
)))
413 buf
= other_buffer_safely (buf
);
415 /* Use set_window_buffer, not Fset_window_buffer, and don't let
416 hooks be run by it. The reason is that the whole frame/window
417 arrangement is not yet fully initialized at this point. Windows
418 don't have the right size, glyph matrices aren't initialized
419 etc. Running Lisp functions at this point surely ends in a
421 set_window_buffer (root_window
, buf
, 0, 0);
422 fset_buffer_list (f
, list1 (buf
));
426 set_window_buffer (mini_window
,
427 (NILP (Vminibuffer_list
)
429 : Fcar (Vminibuffer_list
)),
432 fset_root_window (f
, root_window
);
433 fset_selected_window (f
, root_window
);
434 /* Make sure this window seems more recently used than
435 a newly-created, never-selected window. */
436 XWINDOW (f
->selected_window
)->use_time
= ++window_select_count
;
441 #ifdef HAVE_WINDOW_SYSTEM
442 /* Make a frame using a separate minibuffer window on another frame.
443 MINI_WINDOW is the minibuffer window to use. nil means use the
444 default (the global minibuffer). */
447 make_frame_without_minibuffer (register Lisp_Object mini_window
, KBOARD
*kb
, Lisp_Object display
)
449 register struct frame
*f
;
452 if (!NILP (mini_window
))
453 CHECK_LIVE_WINDOW (mini_window
);
455 if (!NILP (mini_window
)
456 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window
)->frame
)) != kb
)
457 error ("Frame and minibuffer must be on the same terminal");
459 /* Make a frame containing just a root window. */
462 if (NILP (mini_window
))
464 /* Use default-minibuffer-frame if possible. */
465 if (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
466 || ! FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
))))
468 Lisp_Object frame_dummy
;
470 XSETFRAME (frame_dummy
, f
);
471 GCPRO1 (frame_dummy
);
472 /* If there's no minibuffer frame to use, create one. */
473 kset_default_minibuffer_frame
474 (kb
, call1 (intern ("make-initial-minibuffer-frame"), display
));
479 = XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
))->minibuffer_window
;
482 fset_minibuffer_window (f
, mini_window
);
484 /* Make the chosen minibuffer window display the proper minibuffer,
485 unless it is already showing a minibuffer. */
486 if (NILP (Fmemq (XWINDOW (mini_window
)->contents
, Vminibuffer_list
)))
487 /* Use set_window_buffer instead of Fset_window_buffer (see
488 discussion of bug#11984, bug#12025, bug#12026). */
489 set_window_buffer (mini_window
,
490 (NILP (Vminibuffer_list
)
492 : Fcar (Vminibuffer_list
)), 0, 0);
496 /* Make a frame containing only a minibuffer window. */
499 make_minibuffer_frame (void)
501 /* First make a frame containing just a root window, no minibuffer. */
503 register struct frame
*f
= make_frame (0);
504 register Lisp_Object mini_window
;
505 register Lisp_Object frame
;
507 XSETFRAME (frame
, f
);
512 f
->wants_modeline
= 0;
514 /* Now label the root window as also being the minibuffer.
515 Avoid infinite looping on the window chain by marking next pointer
518 mini_window
= f
->root_window
;
519 fset_minibuffer_window (f
, mini_window
);
520 XWINDOW (mini_window
)->mini
= 1;
521 wset_next (XWINDOW (mini_window
), Qnil
);
522 wset_prev (XWINDOW (mini_window
), Qnil
);
523 wset_frame (XWINDOW (mini_window
), frame
);
525 /* Put the proper buffer in that window. */
527 /* Use set_window_buffer instead of Fset_window_buffer (see
528 discussion of bug#11984, bug#12025, bug#12026). */
529 set_window_buffer (mini_window
,
530 (NILP (Vminibuffer_list
)
532 : Fcar (Vminibuffer_list
)), 0, 0);
535 #endif /* HAVE_WINDOW_SYSTEM */
537 /* Construct a frame that refers to a terminal. */
539 static printmax_t tty_frame_count
;
542 make_initial_frame (void)
545 struct terminal
*terminal
;
548 eassert (initial_kboard
);
550 /* The first call must initialize Vframe_list. */
551 if (! (NILP (Vframe_list
) || CONSP (Vframe_list
)))
554 terminal
= init_initial_terminal ();
557 XSETFRAME (frame
, f
);
559 Vframe_list
= Fcons (frame
, Vframe_list
);
562 fset_name (f
, build_pure_c_string ("F1"));
564 SET_FRAME_VISIBLE (f
, 1);
566 f
->output_method
= terminal
->type
;
567 f
->terminal
= terminal
;
568 f
->terminal
->reference_count
++;
569 f
->output_data
.nothing
= 0;
571 FRAME_FOREGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_FG_COLOR
;
572 FRAME_BACKGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_BG_COLOR
;
574 #ifdef HAVE_WINDOW_SYSTEM
575 f
->vertical_scroll_bar_type
= vertical_scroll_bar_none
;
578 /* The default value of menu-bar-mode is t. */
579 set_menu_bar_lines (f
, make_number (1), Qnil
);
582 init_frame_faces (f
);
584 last_nonminibuf_frame
= f
;
590 static struct frame
*
591 make_terminal_frame (struct terminal
*terminal
)
593 register struct frame
*f
;
595 char name
[sizeof "F" + INT_STRLEN_BOUND (printmax_t
)];
598 error ("Terminal is not live, can't create new frames on it");
602 XSETFRAME (frame
, f
);
603 Vframe_list
= Fcons (frame
, Vframe_list
);
605 fset_name (f
, make_formatted_string (name
, "F%"pMd
, ++tty_frame_count
));
607 SET_FRAME_VISIBLE (f
, 1);
609 f
->terminal
= terminal
;
610 f
->terminal
->reference_count
++;
612 f
->output_data
.tty
->display_info
= &the_only_display_info
;
613 if (!inhibit_window_system
614 && (!FRAMEP (selected_frame
) || !FRAME_LIVE_P (XFRAME (selected_frame
))
615 || XFRAME (selected_frame
)->output_method
== output_msdos_raw
))
616 f
->output_method
= output_msdos_raw
;
618 f
->output_method
= output_termcap
;
619 #else /* not MSDOS */
620 f
->output_method
= output_termcap
;
621 create_tty_output (f
);
622 FRAME_FOREGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_FG_COLOR
;
623 FRAME_BACKGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_BG_COLOR
;
624 #endif /* not MSDOS */
626 #ifdef HAVE_WINDOW_SYSTEM
627 f
->vertical_scroll_bar_type
= vertical_scroll_bar_none
;
630 FRAME_MENU_BAR_LINES (f
) = NILP (Vmenu_bar_mode
) ? 0 : 1;
631 FRAME_MENU_BAR_HEIGHT (f
) = FRAME_MENU_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
);
633 /* Set the top frame to the newly created frame. */
634 if (FRAMEP (FRAME_TTY (f
)->top_frame
)
635 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f
)->top_frame
)))
636 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f
)->top_frame
), 2); /* obscured */
638 FRAME_TTY (f
)->top_frame
= frame
;
641 init_frame_faces (f
);
646 /* Get a suitable value for frame parameter PARAMETER for a newly
647 created frame, based on (1) the user-supplied frame parameter
648 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
651 get_future_frame_param (Lisp_Object parameter
,
652 Lisp_Object supplied_parms
,
657 result
= Fassq (parameter
, supplied_parms
);
659 result
= Fassq (parameter
, XFRAME (selected_frame
)->param_alist
);
660 if (NILP (result
) && current_value
!= NULL
)
661 result
= build_string (current_value
);
662 if (!NILP (result
) && !STRINGP (result
))
663 result
= XCDR (result
);
664 if (NILP (result
) || !STRINGP (result
))
670 DEFUN ("make-terminal-frame", Fmake_terminal_frame
, Smake_terminal_frame
,
672 doc
: /* Create an additional terminal frame, possibly on another terminal.
673 This function takes one argument, an alist specifying frame parameters.
675 You can create multiple frames on a single text terminal, but only one
676 of them (the selected terminal frame) is actually displayed.
678 In practice, generally you don't need to specify any parameters,
679 except when you want to create a new frame on another terminal.
680 In that case, the `tty' parameter specifies the device file to open,
681 and the `tty-type' parameter specifies the terminal type. Example:
683 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
685 Note that changing the size of one terminal frame automatically
686 affects all frames on the same terminal device. */)
690 struct terminal
*t
= NULL
;
691 Lisp_Object frame
, tem
;
692 struct frame
*sf
= SELECTED_FRAME ();
695 if (sf
->output_method
!= output_msdos_raw
696 && sf
->output_method
!= output_termcap
)
698 #else /* not MSDOS */
700 #ifdef WINDOWSNT /* This should work now! */
701 if (sf
->output_method
!= output_termcap
)
702 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
704 #endif /* not MSDOS */
707 Lisp_Object terminal
;
709 terminal
= Fassq (Qterminal
, parms
);
710 if (CONSP (terminal
))
712 terminal
= XCDR (terminal
);
713 t
= get_terminal (terminal
, 1);
716 if (t
&& t
!= the_only_display_info
.terminal
)
717 /* msdos.c assumes a single tty_display_info object. */
718 error ("Multiple terminals are not supported on this platform");
720 t
= the_only_display_info
.terminal
;
726 char *name
= 0, *type
= 0;
727 Lisp_Object tty
, tty_type
;
729 tty
= get_future_frame_param
730 (Qtty
, parms
, (FRAME_TERMCAP_P (XFRAME (selected_frame
))
731 ? FRAME_TTY (XFRAME (selected_frame
))->name
734 name
= xlispstrdupa (tty
);
736 tty_type
= get_future_frame_param
737 (Qtty_type
, parms
, (FRAME_TERMCAP_P (XFRAME (selected_frame
))
738 ? FRAME_TTY (XFRAME (selected_frame
))->type
740 if (!NILP (tty_type
))
741 type
= xlispstrdupa (tty_type
);
743 t
= init_tty (name
, type
, 0); /* Errors are not fatal. */
746 f
= make_terminal_frame (t
);
750 get_tty_size (fileno (FRAME_TTY (f
)->input
), &width
, &height
);
751 change_frame_size (f
, width
, height
, 0, 0, 0, 0);
754 adjust_frame_glyphs (f
);
756 XSETFRAME (frame
, f
);
758 store_in_alist (&parms
, Qtty_type
, build_string (t
->display_info
.tty
->type
));
759 store_in_alist (&parms
, Qtty
,
760 (t
->display_info
.tty
->name
761 ? build_string (t
->display_info
.tty
->name
)
763 Fmodify_frame_parameters (frame
, parms
);
765 /* Make the frame face alist be frame-specific, so that each
766 frame could change its face definitions independently. */
767 fset_face_alist (f
, Fcopy_alist (sf
->face_alist
));
768 /* Simple Fcopy_alist isn't enough, because we need the contents of
769 the vectors which are the CDRs of associations in face_alist to
770 be copied as well. */
771 for (tem
= f
->face_alist
; CONSP (tem
); tem
= XCDR (tem
))
772 XSETCDR (XCAR (tem
), Fcopy_sequence (XCDR (XCAR (tem
))));
777 /* Perform the switch to frame FRAME.
779 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
782 If TRACK is non-zero and the frame that currently has the focus
783 redirects its focus to the selected frame, redirect that focused
784 frame's focus to FRAME instead.
786 FOR_DELETION non-zero means that the selected frame is being
787 deleted, which includes the possibility that the frame's terminal
790 The value of NORECORD is passed as argument to Fselect_window. */
793 do_switch_frame (Lisp_Object frame
, int track
, int for_deletion
, Lisp_Object norecord
)
795 struct frame
*sf
= SELECTED_FRAME ();
797 /* If FRAME is a switch-frame event, extract the frame we should
800 && EQ (XCAR (frame
), Qswitch_frame
)
801 && CONSP (XCDR (frame
)))
802 frame
= XCAR (XCDR (frame
));
804 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
805 a switch-frame event to arrive after a frame is no longer live,
806 especially when deleting the initial frame during startup. */
808 if (! FRAME_LIVE_P (XFRAME (frame
)))
811 if (sf
== XFRAME (frame
))
814 /* If a frame's focus has been redirected toward the currently
815 selected frame, we should change the redirection to point to the
816 newly selected frame. This means that if the focus is redirected
817 from a minibufferless frame to a surrogate minibuffer frame, we
818 can use `other-window' to switch between all the frames using
819 that minibuffer frame, and the focus redirection will follow us
822 /* This is too greedy; it causes inappropriate focus redirection
823 that's hard to get rid of. */
828 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
832 if (!FRAMEP (XCAR (tail
)))
835 focus
= FRAME_FOCUS_FRAME (XFRAME (XCAR (tail
)));
837 if (FRAMEP (focus
) && XFRAME (focus
) == SELECTED_FRAME ())
838 Fredirect_frame_focus (XCAR (tail
), frame
);
842 /* Instead, apply it only to the frame we're pointing to. */
843 #ifdef HAVE_WINDOW_SYSTEM
844 if (track
&& FRAME_WINDOW_P (XFRAME (frame
)))
846 Lisp_Object focus
, xfocus
;
848 xfocus
= x_get_focus_frame (XFRAME (frame
));
851 focus
= FRAME_FOCUS_FRAME (XFRAME (xfocus
));
852 if (FRAMEP (focus
) && XFRAME (focus
) == SELECTED_FRAME ())
853 Fredirect_frame_focus (xfocus
, frame
);
856 #endif /* HAVE_X_WINDOWS */
859 if (!for_deletion
&& FRAME_HAS_MINIBUF_P (sf
))
860 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf
)), 1);
862 if (FRAME_TERMCAP_P (XFRAME (frame
)) || FRAME_MSDOS_P (XFRAME (frame
)))
864 struct frame
*f
= XFRAME (frame
);
865 struct tty_display_info
*tty
= FRAME_TTY (f
);
866 Lisp_Object top_frame
= tty
->top_frame
;
868 /* Don't mark the frame garbaged and/or obscured if we are
869 switching to the frame that is already the top frame of that
871 if (!EQ (frame
, top_frame
))
873 if (FRAMEP (top_frame
))
874 /* Mark previously displayed frame as now obscured. */
875 SET_FRAME_VISIBLE (XFRAME (top_frame
), 2);
876 SET_FRAME_VISIBLE (f
, 1);
877 /* If the new TTY frame changed dimensions, we need to
878 resync term.c's idea of the frame size with the new
880 if (FRAME_COLS (f
) != FrameCols (tty
))
881 FrameCols (tty
) = FRAME_COLS (f
);
882 if (FRAME_LINES (f
) != FrameRows (tty
))
883 FrameRows (tty
) = FRAME_LINES (f
);
885 tty
->top_frame
= frame
;
888 selected_frame
= frame
;
889 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame
)))
890 last_nonminibuf_frame
= XFRAME (selected_frame
);
892 Fselect_window (XFRAME (frame
)->selected_window
, norecord
);
894 /* We want to make sure that the next event generates a frame-switch
895 event to the appropriate frame. This seems kludgy to me, but
896 before you take it out, make sure that evaluating something like
897 (select-window (frame-root-window (new-frame))) doesn't end up
898 with your typing being interpreted in the new frame instead of
899 the one you're actually typing in. */
900 internal_last_event_frame
= Qnil
;
905 DEFUN ("select-frame", Fselect_frame
, Sselect_frame
, 1, 2, "e",
906 doc
: /* Select FRAME.
907 Subsequent editing commands apply to its selected window.
908 Optional argument NORECORD means to neither change the order of
909 recently selected windows nor the buffer list.
911 The selection of FRAME lasts until the next time the user does
912 something to select a different frame, or until the next time
913 this function is called. If you are using a window system, the
914 previously selected frame may be restored as the selected frame
915 when returning to the command loop, because it still may have
916 the window system's input focus. On a text terminal, the next
917 redisplay will display FRAME.
919 This function returns FRAME, or nil if FRAME has been deleted. */)
920 (Lisp_Object frame
, Lisp_Object norecord
)
922 return do_switch_frame (frame
, 1, 0, norecord
);
925 DEFUN ("handle-switch-frame", Fhandle_switch_frame
, Shandle_switch_frame
, 1, 1, "e",
926 doc
: /* Handle a switch-frame event EVENT.
927 Switch-frame events are usually bound to this function.
928 A switch-frame event tells Emacs that the window manager has requested
929 that the user's events be directed to the frame mentioned in the event.
930 This function selects the selected window of the frame of EVENT.
932 If EVENT is frame object, handle it as if it were a switch-frame event
936 /* Preserve prefix arg that the command loop just cleared. */
937 kset_prefix_arg (current_kboard
, Vcurrent_prefix_arg
);
938 Frun_hooks (1, &Qmouse_leave_buffer_hook
);
939 /* `switch-frame' implies a focus in. */
940 call1 (intern ("handle-focus-in"), event
);
941 return do_switch_frame (event
, 0, 0, Qnil
);
944 DEFUN ("selected-frame", Fselected_frame
, Sselected_frame
, 0, 0, 0,
945 doc
: /* Return the frame that is now selected. */)
948 return selected_frame
;
951 DEFUN ("frame-list", Fframe_list
, Sframe_list
,
953 doc
: /* Return a list of all live frames. */)
957 frames
= Fcopy_sequence (Vframe_list
);
958 #ifdef HAVE_WINDOW_SYSTEM
959 if (FRAMEP (tip_frame
))
960 frames
= Fdelq (tip_frame
, frames
);
965 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
966 same tty (for tty frames) or among frames which uses FRAME's keyboard.
967 If MINIBUF is nil, do not consider minibuffer-only candidate.
968 If MINIBUF is `visible', do not consider an invisible candidate.
969 If MINIBUF is a window, consider only its own frame and candidate now
970 using that window as the minibuffer.
971 If MINIBUF is 0, consider candidate if it is visible or iconified.
972 Otherwise consider any candidate and return nil if CANDIDATE is not
976 candidate_frame (Lisp_Object candidate
, Lisp_Object frame
, Lisp_Object minibuf
)
978 struct frame
*c
= XFRAME (candidate
), *f
= XFRAME (frame
);
980 if ((!FRAME_TERMCAP_P (c
) && !FRAME_TERMCAP_P (f
)
981 && FRAME_KBOARD (c
) == FRAME_KBOARD (f
))
982 || (FRAME_TERMCAP_P (c
) && FRAME_TERMCAP_P (f
)
983 && FRAME_TTY (c
) == FRAME_TTY (f
)))
987 if (!FRAME_MINIBUF_ONLY_P (c
))
990 else if (EQ (minibuf
, Qvisible
))
992 if (FRAME_VISIBLE_P (c
))
995 else if (WINDOWP (minibuf
))
997 if (EQ (FRAME_MINIBUF_WINDOW (c
), minibuf
)
998 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)), candidate
)
999 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)),
1000 FRAME_FOCUS_FRAME (c
)))
1003 else if (XFASTINT (minibuf
) == 0)
1005 if (FRAME_VISIBLE_P (c
) || FRAME_ICONIFIED_P (c
))
1014 /* Return the next frame in the frame list after FRAME. */
1017 next_frame (Lisp_Object frame
, Lisp_Object minibuf
)
1019 Lisp_Object f
, tail
;
1022 /* There must always be at least one frame in Vframe_list. */
1023 eassert (CONSP (Vframe_list
));
1026 FOR_EACH_FRAME (tail
, f
)
1030 f
= candidate_frame (f
, frame
, minibuf
);
1040 /* Return the previous frame in the frame list before FRAME. */
1043 prev_frame (Lisp_Object frame
, Lisp_Object minibuf
)
1045 Lisp_Object f
, tail
, prev
= Qnil
;
1047 /* There must always be at least one frame in Vframe_list. */
1048 eassert (CONSP (Vframe_list
));
1050 FOR_EACH_FRAME (tail
, f
)
1052 if (EQ (frame
, f
) && !NILP (prev
))
1054 f
= candidate_frame (f
, frame
, minibuf
);
1059 /* We've scanned the entire list. */
1061 /* We went through the whole frame list without finding a single
1062 acceptable frame. Return the original frame. */
1065 /* There were no acceptable frames in the list before FRAME; otherwise,
1066 we would have returned directly from the loop. Since PREV is the last
1067 acceptable frame in the list, return it. */
1072 DEFUN ("next-frame", Fnext_frame
, Snext_frame
, 0, 2, 0,
1073 doc
: /* Return the next frame in the frame list after FRAME.
1074 It considers only frames on the same terminal as FRAME.
1075 By default, skip minibuffer-only frames.
1076 If omitted, FRAME defaults to the selected frame.
1077 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1078 If MINIFRAME is a window, include only its own frame
1079 and any frame now using that window as the minibuffer.
1080 If MINIFRAME is `visible', include all visible frames.
1081 If MINIFRAME is 0, include all visible and iconified frames.
1082 Otherwise, include all frames. */)
1083 (Lisp_Object frame
, Lisp_Object miniframe
)
1086 frame
= selected_frame
;
1087 CHECK_LIVE_FRAME (frame
);
1088 return next_frame (frame
, miniframe
);
1091 DEFUN ("previous-frame", Fprevious_frame
, Sprevious_frame
, 0, 2, 0,
1092 doc
: /* Return the previous frame in the frame list before FRAME.
1093 It considers only frames on the same terminal as FRAME.
1094 By default, skip minibuffer-only frames.
1095 If omitted, FRAME defaults to the selected frame.
1096 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1097 If MINIFRAME is a window, include only its own frame
1098 and any frame now using that window as the minibuffer.
1099 If MINIFRAME is `visible', include all visible frames.
1100 If MINIFRAME is 0, include all visible and iconified frames.
1101 Otherwise, include all frames. */)
1102 (Lisp_Object frame
, Lisp_Object miniframe
)
1105 frame
= selected_frame
;
1106 CHECK_LIVE_FRAME (frame
);
1107 return prev_frame (frame
, miniframe
);
1110 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame
,
1111 Slast_nonminibuf_frame
, 0, 0, 0,
1112 doc
: /* Return last non-minibuffer frame selected. */)
1115 Lisp_Object frame
= Qnil
;
1117 if (last_nonminibuf_frame
)
1118 XSETFRAME (frame
, last_nonminibuf_frame
);
1123 /* Return 1 if it is ok to delete frame F;
1124 0 if all frames aside from F are invisible.
1125 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1128 other_visible_frames (struct frame
*f
)
1130 Lisp_Object frames
, this;
1132 FOR_EACH_FRAME (frames
, this)
1134 if (f
== XFRAME (this))
1137 /* Verify that we can still talk to the frame's X window,
1138 and note any recent change in visibility. */
1139 #ifdef HAVE_X_WINDOWS
1140 if (FRAME_WINDOW_P (XFRAME (this)))
1141 x_sync (XFRAME (this));
1144 if (FRAME_VISIBLE_P (XFRAME (this))
1145 || FRAME_ICONIFIED_P (XFRAME (this))
1146 /* Allow deleting the terminal frame when at least one X
1148 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f
)))
1154 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1155 window. Preferably use the selected frame's minibuffer window
1156 instead. If the selected frame doesn't have one, get some other
1157 frame's minibuffer window. SELECT non-zero means select the new
1158 minibuffer window. */
1160 check_minibuf_window (Lisp_Object frame
, int select
)
1162 struct frame
*f
= decode_live_frame (frame
);
1164 XSETFRAME (frame
, f
);
1166 if (WINDOWP (minibuf_window
) && EQ (f
->minibuffer_window
, minibuf_window
))
1168 Lisp_Object frames
, this, window
= make_number (0);
1170 if (!EQ (frame
, selected_frame
)
1171 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame
)))
1172 window
= FRAME_MINIBUF_WINDOW (XFRAME (selected_frame
));
1174 FOR_EACH_FRAME (frames
, this)
1176 if (!EQ (this, frame
) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1178 window
= FRAME_MINIBUF_WINDOW (XFRAME (this));
1183 /* Don't abort if no window was found (Bug#15247). */
1184 if (WINDOWP (window
))
1186 /* Use set_window_buffer instead of Fset_window_buffer (see
1187 discussion of bug#11984, bug#12025, bug#12026). */
1188 set_window_buffer (window
, XWINDOW (minibuf_window
)->contents
, 0, 0);
1189 minibuf_window
= window
;
1191 /* SELECT non-zero usually means that FRAME's minibuffer
1192 window was selected; select the new one. */
1194 Fselect_window (minibuf_window
, Qnil
);
1200 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1201 unconditionally. x_connection_closed and delete_terminal use
1202 this. Any other value of FORCE implements the semantics
1203 described for Fdelete_frame. */
1205 delete_frame (Lisp_Object frame
, Lisp_Object force
)
1207 struct frame
*f
= decode_any_frame (frame
);
1211 int minibuffer_selected
, is_tooltip_frame
;
1213 if (! FRAME_LIVE_P (f
))
1216 if (NILP (force
) && !other_visible_frames (f
))
1217 error ("Attempt to delete the sole visible or iconified frame");
1219 /* x_connection_closed must have set FORCE to `noelisp' in order
1220 to delete the last frame, if it is gone. */
1221 if (NILP (XCDR (Vframe_list
)) && !EQ (force
, Qnoelisp
))
1222 error ("Attempt to delete the only frame");
1224 XSETFRAME (frame
, f
);
1226 /* Does this frame have a minibuffer, and is it the surrogate
1227 minibuffer for any other frame? */
1228 if (FRAME_HAS_MINIBUF_P (f
))
1230 Lisp_Object frames
, this;
1232 FOR_EACH_FRAME (frames
, this)
1236 if (EQ (this, frame
))
1239 fminiw
= FRAME_MINIBUF_WINDOW (XFRAME (this));
1241 if (WINDOWP (fminiw
) && EQ (frame
, WINDOW_FRAME (XWINDOW (fminiw
))))
1243 /* If we MUST delete this frame, delete the other first.
1244 But do this only if FORCE equals `noelisp'. */
1245 if (EQ (force
, Qnoelisp
))
1246 delete_frame (this, Qnoelisp
);
1248 error ("Attempt to delete a surrogate minibuffer frame");
1253 is_tooltip_frame
= !NILP (Fframe_parameter (frame
, intern ("tooltip")));
1255 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1256 frame is a tooltip. FORCE is set to `noelisp' when handling
1257 a disconnect from the terminal, so we don't dare call Lisp
1259 if (NILP (Vrun_hooks
) || is_tooltip_frame
)
1261 else if (EQ (force
, Qnoelisp
))
1263 = Fcons (list3 (Qrun_hook_with_args
, Qdelete_frame_functions
, frame
),
1267 #ifdef HAVE_X_WINDOWS
1268 /* Also, save clipboard to the clipboard manager. */
1269 x_clipboard_manager_save_frame (frame
);
1272 safe_call2 (Qrun_hook_with_args
, Qdelete_frame_functions
, frame
);
1275 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1276 if (! FRAME_LIVE_P (f
))
1279 /* At this point, we are committed to deleting the frame.
1280 There is no more chance for errors to prevent it. */
1282 minibuffer_selected
= EQ (minibuf_window
, selected_window
);
1283 sf
= SELECTED_FRAME ();
1284 /* Don't let the frame remain selected. */
1288 Lisp_Object frame1
= Qnil
;
1290 /* Look for another visible frame on the same terminal.
1291 Do not call next_frame here because it may loop forever.
1292 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1293 FOR_EACH_FRAME (tail
, frame1
)
1294 if (!EQ (frame
, frame1
)
1295 && (FRAME_TERMINAL (XFRAME (frame
))
1296 == FRAME_TERMINAL (XFRAME (frame1
)))
1297 && FRAME_VISIBLE_P (XFRAME (frame1
)))
1300 /* If there is none, find *some* other frame. */
1301 if (NILP (frame1
) || EQ (frame1
, frame
))
1303 FOR_EACH_FRAME (tail
, frame1
)
1305 if (! EQ (frame
, frame1
) && FRAME_LIVE_P (XFRAME (frame1
)))
1307 /* Do not change a text terminal's top-frame. */
1308 struct frame
*f1
= XFRAME (frame1
);
1309 if (FRAME_TERMCAP_P (f1
) || FRAME_MSDOS_P (f1
))
1311 Lisp_Object top_frame
= FRAME_TTY (f1
)->top_frame
;
1312 if (!EQ (top_frame
, frame
))
1319 #ifdef NS_IMPL_COCOA
1321 /* Under NS, there is no system mechanism for choosing a new
1322 window to get focus -- it is left to application code.
1323 So the portion of THIS application interfacing with NS
1324 needs to know about it. We call Fraise_frame, but the
1325 purpose is really to transfer focus. */
1326 Fraise_frame (frame1
);
1329 do_switch_frame (frame1
, 0, 1, Qnil
);
1330 sf
= SELECTED_FRAME ();
1333 /* Don't allow minibuf_window to remain on a deleted frame. */
1334 check_minibuf_window (frame
, minibuffer_selected
);
1336 /* Don't let echo_area_window to remain on a deleted frame. */
1337 if (EQ (f
->minibuffer_window
, echo_area_window
))
1338 echo_area_window
= sf
->minibuffer_window
;
1340 /* Clear any X selections for this frame. */
1341 #ifdef HAVE_X_WINDOWS
1343 x_clear_frame_selections (f
);
1347 This function must be called before the window tree of the
1348 frame is deleted because windows contain dynamically allocated
1352 #ifdef HAVE_WINDOW_SYSTEM
1353 /* Give chance to each font driver to free a frame specific data. */
1354 font_update_drivers (f
, Qnil
);
1357 /* Mark all the windows that used to be on FRAME as deleted, and then
1358 remove the reference to them. */
1359 delete_all_child_windows (f
->root_window
);
1360 fset_root_window (f
, Qnil
);
1362 Vframe_list
= Fdelq (frame
, Vframe_list
);
1363 SET_FRAME_VISIBLE (f
, 0);
1365 /* Allow the vector of menu bar contents to be freed in the next
1366 garbage collection. The frame object itself may not be garbage
1367 collected until much later, because recent_keys and other data
1368 structures can still refer to it. */
1369 fset_menu_bar_vector (f
, Qnil
);
1371 /* If FRAME's buffer lists contains killed
1372 buffers, this helps GC to reclaim them. */
1373 fset_buffer_list (f
, Qnil
);
1374 fset_buried_buffer_list (f
, Qnil
);
1376 free_font_driver_list (f
);
1377 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1380 xfree (f
->decode_mode_spec_buffer
);
1381 xfree (FRAME_INSERT_COST (f
));
1382 xfree (FRAME_DELETEN_COST (f
));
1383 xfree (FRAME_INSERTN_COST (f
));
1384 xfree (FRAME_DELETE_COST (f
));
1386 /* Since some events are handled at the interrupt level, we may get
1387 an event for f at any time; if we zero out the frame's terminal
1388 now, then we may trip up the event-handling code. Instead, we'll
1389 promise that the terminal of the frame must be valid until we
1390 have called the window-system-dependent frame destruction
1395 struct terminal
*terminal
;
1397 if (FRAME_TERMINAL (f
)->delete_frame_hook
)
1398 (*FRAME_TERMINAL (f
)->delete_frame_hook
) (f
);
1399 terminal
= FRAME_TERMINAL (f
);
1400 f
->output_data
.nothing
= 0;
1401 f
->terminal
= 0; /* Now the frame is dead. */
1404 /* If needed, delete the terminal that this frame was on.
1405 (This must be done after the frame is killed.) */
1406 terminal
->reference_count
--;
1408 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1410 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1411 if (terminal
->reference_count
== 0 && terminal
->type
== output_x_window
)
1412 terminal
->reference_count
= 1;
1413 #endif /* USE_GTK */
1414 if (terminal
->reference_count
== 0)
1417 XSETTERMINAL (tmp
, terminal
);
1420 Fdelete_terminal (tmp
, NILP (force
) ? Qt
: force
);
1423 kb
= terminal
->kboard
;
1426 /* If we've deleted the last_nonminibuf_frame, then try to find
1428 if (f
== last_nonminibuf_frame
)
1430 Lisp_Object frames
, this;
1432 last_nonminibuf_frame
= 0;
1434 FOR_EACH_FRAME (frames
, this)
1437 if (!FRAME_MINIBUF_ONLY_P (f
))
1439 last_nonminibuf_frame
= f
;
1445 /* If there's no other frame on the same kboard, get out of
1446 single-kboard state if we're in it for this kboard. */
1449 Lisp_Object frames
, this;
1450 /* Some frame we found on the same kboard, or nil if there are none. */
1451 Lisp_Object frame_on_same_kboard
= Qnil
;
1453 FOR_EACH_FRAME (frames
, this)
1454 if (kb
== FRAME_KBOARD (XFRAME (this)))
1455 frame_on_same_kboard
= this;
1457 if (NILP (frame_on_same_kboard
))
1458 not_single_kboard_state (kb
);
1462 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1463 find another one. Prefer minibuffer-only frames, but also notice
1464 frames with other windows. */
1465 if (kb
!= NULL
&& EQ (frame
, KVAR (kb
, Vdefault_minibuffer_frame
)))
1467 Lisp_Object frames
, this;
1469 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1470 Lisp_Object frame_with_minibuf
= Qnil
;
1471 /* Some frame we found on the same kboard, or nil if there are none. */
1472 Lisp_Object frame_on_same_kboard
= Qnil
;
1474 FOR_EACH_FRAME (frames
, this)
1476 struct frame
*f1
= XFRAME (this);
1478 /* Consider only frames on the same kboard
1479 and only those with minibuffers. */
1480 if (kb
== FRAME_KBOARD (f1
)
1481 && FRAME_HAS_MINIBUF_P (f1
))
1483 frame_with_minibuf
= this;
1484 if (FRAME_MINIBUF_ONLY_P (f1
))
1488 if (kb
== FRAME_KBOARD (f1
))
1489 frame_on_same_kboard
= this;
1492 if (!NILP (frame_on_same_kboard
))
1494 /* We know that there must be some frame with a minibuffer out
1495 there. If this were not true, all of the frames present
1496 would have to be minibufferless, which implies that at some
1497 point their minibuffer frames must have been deleted, but
1498 that is prohibited at the top; you can't delete surrogate
1499 minibuffer frames. */
1500 if (NILP (frame_with_minibuf
))
1503 kset_default_minibuffer_frame (kb
, frame_with_minibuf
);
1506 /* No frames left on this kboard--say no minibuffer either. */
1507 kset_default_minibuffer_frame (kb
, Qnil
);
1510 /* Cause frame titles to update--necessary if we now have just one frame. */
1511 if (!is_tooltip_frame
)
1512 update_mode_lines
= 15;
1517 DEFUN ("delete-frame", Fdelete_frame
, Sdelete_frame
, 0, 2, "",
1518 doc
: /* Delete FRAME, permanently eliminating it from use.
1519 FRAME defaults to the selected frame.
1521 A frame may not be deleted if its minibuffer is used by other frames.
1522 Normally, you may not delete a frame if all other frames are invisible,
1523 but if the second optional argument FORCE is non-nil, you may do so.
1525 This function runs `delete-frame-functions' before actually
1526 deleting the frame, unless the frame is a tooltip.
1527 The functions are run with one argument, the frame to be deleted. */)
1528 (Lisp_Object frame
, Lisp_Object force
)
1530 return delete_frame (frame
, !NILP (force
) ? Qt
: Qnil
);
1534 /* Return mouse position in character cell units. */
1536 DEFUN ("mouse-position", Fmouse_position
, Smouse_position
, 0, 0, 0,
1537 doc
: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1538 The position is given in character cells, where (0, 0) is the
1539 upper-left corner of the frame, X is the horizontal offset, and Y is
1540 the vertical offset.
1541 If Emacs is running on a mouseless terminal or hasn't been programmed
1542 to read the mouse position, it returns the selected frame for FRAME
1543 and nil for X and Y.
1544 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1545 passing the normal return value to that function as an argument,
1546 and returns whatever that function returns. */)
1550 Lisp_Object lispy_dummy
;
1551 Lisp_Object x
, y
, retval
;
1552 struct gcpro gcpro1
;
1554 f
= SELECTED_FRAME ();
1557 /* It's okay for the hook to refrain from storing anything. */
1558 if (FRAME_TERMINAL (f
)->mouse_position_hook
)
1560 enum scroll_bar_part party_dummy
;
1562 (*FRAME_TERMINAL (f
)->mouse_position_hook
) (&f
, -1,
1563 &lispy_dummy
, &party_dummy
,
1572 pixel_to_glyph_coords (f
, col
, row
, &col
, &row
, NULL
, 1);
1576 XSETFRAME (lispy_dummy
, f
);
1577 retval
= Fcons (lispy_dummy
, Fcons (x
, y
));
1579 if (!NILP (Vmouse_position_function
))
1580 retval
= call1 (Vmouse_position_function
, retval
);
1581 RETURN_UNGCPRO (retval
);
1584 DEFUN ("mouse-pixel-position", Fmouse_pixel_position
,
1585 Smouse_pixel_position
, 0, 0, 0,
1586 doc
: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1587 The position is given in pixel units, where (0, 0) is the
1588 upper-left corner of the frame, X is the horizontal offset, and Y is
1589 the vertical offset.
1590 If Emacs is running on a mouseless terminal or hasn't been programmed
1591 to read the mouse position, it returns the selected frame for FRAME
1592 and nil for X and Y. */)
1596 Lisp_Object lispy_dummy
;
1599 f
= SELECTED_FRAME ();
1602 /* It's okay for the hook to refrain from storing anything. */
1603 if (FRAME_TERMINAL (f
)->mouse_position_hook
)
1605 enum scroll_bar_part party_dummy
;
1607 (*FRAME_TERMINAL (f
)->mouse_position_hook
) (&f
, -1,
1608 &lispy_dummy
, &party_dummy
,
1613 XSETFRAME (lispy_dummy
, f
);
1614 return Fcons (lispy_dummy
, Fcons (x
, y
));
1617 #ifdef HAVE_WINDOW_SYSTEM
1619 /* On frame F, convert character coordinates X and Y to pixel
1620 coordinates *PIX_X and *PIX_Y. */
1623 frame_char_to_pixel_position (struct frame
*f
, int x
, int y
,
1624 int *pix_x
, int *pix_y
)
1626 *pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
1627 *pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
1631 if (*pix_x
> FRAME_PIXEL_WIDTH (f
))
1632 *pix_x
= FRAME_PIXEL_WIDTH (f
);
1636 if (*pix_y
> FRAME_PIXEL_HEIGHT (f
))
1637 *pix_y
= FRAME_PIXEL_HEIGHT (f
);
1640 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1643 frame_set_mouse_position (struct frame
*f
, int x
, int y
)
1647 frame_char_to_pixel_position (f
, x
, y
, &pix_x
, &pix_y
);
1648 frame_set_mouse_pixel_position (f
, pix_x
, pix_y
);
1651 #endif /* HAVE_WINDOW_SYSTEM */
1653 DEFUN ("set-mouse-position", Fset_mouse_position
, Sset_mouse_position
, 3, 3, 0,
1654 doc
: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1655 Coordinates are relative to the frame, not a window,
1656 so the coordinates of the top left character in the frame
1657 may be nonzero due to left-hand scroll bars or the menu bar.
1659 The position is given in character cells, where (0, 0) is the
1660 upper-left corner of the frame, X is the horizontal offset, and Y is
1661 the vertical offset.
1663 This function is a no-op for an X frame that is not visible.
1664 If you have just created a frame, you must wait for it to become visible
1665 before calling this function on it, like this.
1666 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1667 (Lisp_Object frame
, Lisp_Object x
, Lisp_Object y
)
1669 CHECK_LIVE_FRAME (frame
);
1670 CHECK_TYPE_RANGED_INTEGER (int, x
);
1671 CHECK_TYPE_RANGED_INTEGER (int, y
);
1673 /* I think this should be done with a hook. */
1674 #ifdef HAVE_WINDOW_SYSTEM
1675 if (FRAME_WINDOW_P (XFRAME (frame
)))
1676 /* Warping the mouse will cause enternotify and focus events. */
1677 frame_set_mouse_position (XFRAME (frame
), XINT (x
), XINT (y
));
1680 if (FRAME_MSDOS_P (XFRAME (frame
)))
1682 Fselect_frame (frame
, Qnil
);
1683 mouse_moveto (XINT (x
), XINT (y
));
1688 Fselect_frame (frame
, Qnil
);
1689 term_mouse_moveto (XINT (x
), XINT (y
));
1698 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position
,
1699 Sset_mouse_pixel_position
, 3, 3, 0,
1700 doc
: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1701 The position is given in pixels, where (0, 0) is the upper-left corner
1702 of the frame, X is the horizontal offset, and Y is the vertical offset.
1704 Note, this is a no-op for an X frame that is not visible.
1705 If you have just created a frame, you must wait for it to become visible
1706 before calling this function on it, like this.
1707 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1708 (Lisp_Object frame
, Lisp_Object x
, Lisp_Object y
)
1710 CHECK_LIVE_FRAME (frame
);
1711 CHECK_TYPE_RANGED_INTEGER (int, x
);
1712 CHECK_TYPE_RANGED_INTEGER (int, y
);
1714 /* I think this should be done with a hook. */
1715 #ifdef HAVE_WINDOW_SYSTEM
1716 if (FRAME_WINDOW_P (XFRAME (frame
)))
1717 /* Warping the mouse will cause enternotify and focus events. */
1718 frame_set_mouse_pixel_position (XFRAME (frame
), XINT (x
), XINT (y
));
1721 if (FRAME_MSDOS_P (XFRAME (frame
)))
1723 Fselect_frame (frame
, Qnil
);
1724 mouse_moveto (XINT (x
), XINT (y
));
1729 Fselect_frame (frame
, Qnil
);
1730 term_mouse_moveto (XINT (x
), XINT (y
));
1739 static void make_frame_visible_1 (Lisp_Object
);
1741 DEFUN ("make-frame-visible", Fmake_frame_visible
, Smake_frame_visible
,
1743 doc
: /* Make the frame FRAME visible (assuming it is an X window).
1744 If omitted, FRAME defaults to the currently selected frame. */)
1747 struct frame
*f
= decode_live_frame (frame
);
1749 /* I think this should be done with a hook. */
1750 #ifdef HAVE_WINDOW_SYSTEM
1751 if (FRAME_WINDOW_P (f
))
1752 x_make_frame_visible (f
);
1755 make_frame_visible_1 (f
->root_window
);
1757 /* Make menu bar update for the Buffers and Frames menus. */
1758 /* windows_or_buffers_changed = 15; FIXME: Why? */
1760 XSETFRAME (frame
, f
);
1764 /* Update the display_time slot of the buffers shown in WINDOW
1765 and all its descendants. */
1768 make_frame_visible_1 (Lisp_Object window
)
1772 for (; !NILP (window
); window
= w
->next
)
1774 w
= XWINDOW (window
);
1775 if (WINDOWP (w
->contents
))
1776 make_frame_visible_1 (w
->contents
);
1778 bset_display_time (XBUFFER (w
->contents
), Fcurrent_time ());
1782 DEFUN ("make-frame-invisible", Fmake_frame_invisible
, Smake_frame_invisible
,
1784 doc
: /* Make the frame FRAME invisible.
1785 If omitted, FRAME defaults to the currently selected frame.
1786 On graphical displays, invisible frames are not updated and are
1787 usually not displayed at all, even in a window system's \"taskbar\".
1789 Normally you may not make FRAME invisible if all other frames are invisible,
1790 but if the second optional argument FORCE is non-nil, you may do so.
1792 This function has no effect on text terminal frames. Such frames are
1793 always considered visible, whether or not they are currently being
1794 displayed in the terminal. */)
1795 (Lisp_Object frame
, Lisp_Object force
)
1797 struct frame
*f
= decode_live_frame (frame
);
1799 if (NILP (force
) && !other_visible_frames (f
))
1800 error ("Attempt to make invisible the sole visible or iconified frame");
1802 /* Don't allow minibuf_window to remain on an invisible frame. */
1803 check_minibuf_window (frame
, EQ (minibuf_window
, selected_window
));
1805 /* I think this should be done with a hook. */
1806 #ifdef HAVE_WINDOW_SYSTEM
1807 if (FRAME_WINDOW_P (f
))
1808 x_make_frame_invisible (f
);
1811 /* Make menu bar update for the Buffers and Frames menus. */
1812 windows_or_buffers_changed
= 16;
1817 DEFUN ("iconify-frame", Ficonify_frame
, Siconify_frame
,
1819 doc
: /* Make the frame FRAME into an icon.
1820 If omitted, FRAME defaults to the currently selected frame. */)
1823 struct frame
*f
= decode_live_frame (frame
);
1825 /* Don't allow minibuf_window to remain on an iconified frame. */
1826 check_minibuf_window (frame
, EQ (minibuf_window
, selected_window
));
1828 /* I think this should be done with a hook. */
1829 #ifdef HAVE_WINDOW_SYSTEM
1830 if (FRAME_WINDOW_P (f
))
1831 x_iconify_frame (f
);
1834 /* Make menu bar update for the Buffers and Frames menus. */
1835 windows_or_buffers_changed
= 17;
1840 DEFUN ("frame-visible-p", Fframe_visible_p
, Sframe_visible_p
,
1842 doc
: /* Return t if FRAME is \"visible\" (actually in use for display).
1843 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1844 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1845 On graphical displays, invisible frames are not updated and are
1846 usually not displayed at all, even in a window system's \"taskbar\".
1848 If FRAME is a text terminal frame, this always returns t.
1849 Such frames are always considered visible, whether or not they are
1850 currently being displayed on the terminal. */)
1853 CHECK_LIVE_FRAME (frame
);
1855 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1857 if (FRAME_ICONIFIED_P (XFRAME (frame
)))
1862 DEFUN ("visible-frame-list", Fvisible_frame_list
, Svisible_frame_list
,
1864 doc
: /* Return a list of all frames now \"visible\" (being updated). */)
1867 Lisp_Object tail
, frame
, value
= Qnil
;
1869 FOR_EACH_FRAME (tail
, frame
)
1870 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1871 value
= Fcons (frame
, value
);
1877 DEFUN ("raise-frame", Fraise_frame
, Sraise_frame
, 0, 1, "",
1878 doc
: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1879 If FRAME is invisible or iconified, make it visible.
1880 If you don't specify a frame, the selected frame is used.
1881 If Emacs is displaying on an ordinary terminal or some other device which
1882 doesn't support multiple overlapping frames, this function selects FRAME. */)
1885 struct frame
*f
= decode_live_frame (frame
);
1887 XSETFRAME (frame
, f
);
1889 if (FRAME_TERMCAP_P (f
))
1890 /* On a text terminal select FRAME. */
1891 Fselect_frame (frame
, Qnil
);
1893 /* Do like the documentation says. */
1894 Fmake_frame_visible (frame
);
1896 if (FRAME_TERMINAL (f
)->frame_raise_lower_hook
)
1897 (*FRAME_TERMINAL (f
)->frame_raise_lower_hook
) (f
, 1);
1902 /* Should we have a corresponding function called Flower_Power? */
1903 DEFUN ("lower-frame", Flower_frame
, Slower_frame
, 0, 1, "",
1904 doc
: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1905 If you don't specify a frame, the selected frame is used.
1906 If Emacs is displaying on an ordinary terminal or some other device which
1907 doesn't support multiple overlapping frames, this function does nothing. */)
1910 struct frame
*f
= decode_live_frame (frame
);
1912 if (FRAME_TERMINAL (f
)->frame_raise_lower_hook
)
1913 (*FRAME_TERMINAL (f
)->frame_raise_lower_hook
) (f
, 0);
1919 DEFUN ("redirect-frame-focus", Fredirect_frame_focus
, Sredirect_frame_focus
,
1921 doc
: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1922 In other words, switch-frame events caused by events in FRAME will
1923 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1924 FOCUS-FRAME after reading an event typed at FRAME.
1926 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1927 frame again receives its own keystrokes.
1929 Focus redirection is useful for temporarily redirecting keystrokes to
1930 a surrogate minibuffer frame when a frame doesn't have its own
1933 A frame's focus redirection can be changed by `select-frame'. If frame
1934 FOO is selected, and then a different frame BAR is selected, any
1935 frames redirecting their focus to FOO are shifted to redirect their
1936 focus to BAR. This allows focus redirection to work properly when the
1937 user switches from one frame to another using `select-window'.
1939 This means that a frame whose focus is redirected to itself is treated
1940 differently from a frame whose focus is redirected to nil; the former
1941 is affected by `select-frame', while the latter is not.
1943 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1944 (Lisp_Object frame
, Lisp_Object focus_frame
)
1946 /* Note that we don't check for a live frame here. It's reasonable
1947 to redirect the focus of a frame you're about to delete, if you
1948 know what other frame should receive those keystrokes. */
1949 struct frame
*f
= decode_any_frame (frame
);
1951 if (! NILP (focus_frame
))
1952 CHECK_LIVE_FRAME (focus_frame
);
1954 fset_focus_frame (f
, focus_frame
);
1956 if (FRAME_TERMINAL (f
)->frame_rehighlight_hook
)
1957 (*FRAME_TERMINAL (f
)->frame_rehighlight_hook
) (f
);
1963 DEFUN ("frame-focus", Fframe_focus
, Sframe_focus
, 0, 1, 0,
1964 doc
: /* Return the frame to which FRAME's keystrokes are currently being sent.
1965 If FRAME is omitted or nil, the selected frame is used.
1966 Return nil if FRAME's focus is not redirected.
1967 See `redirect-frame-focus'. */)
1970 return FRAME_FOCUS_FRAME (decode_live_frame (frame
));
1973 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
1974 doc
: /* Set the input focus to FRAME.
1975 FRAME nil means use the selected frame.
1976 If there is no window system support, this function does nothing. */)
1979 #ifdef HAVE_WINDOW_SYSTEM
1980 x_focus_frame (decode_window_system_frame (frame
));
1986 /* Return the value of frame parameter PROP in frame FRAME. */
1988 #ifdef HAVE_WINDOW_SYSTEM
1990 get_frame_param (register struct frame
*frame
, Lisp_Object prop
)
1992 register Lisp_Object tem
;
1994 tem
= Fassq (prop
, frame
->param_alist
);
2001 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2004 frames_discard_buffer (Lisp_Object buffer
)
2006 Lisp_Object frame
, tail
;
2008 FOR_EACH_FRAME (tail
, frame
)
2011 (XFRAME (frame
), Fdelq (buffer
, XFRAME (frame
)->buffer_list
));
2012 fset_buried_buffer_list
2013 (XFRAME (frame
), Fdelq (buffer
, XFRAME (frame
)->buried_buffer_list
));
2017 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2018 If the alist already has an element for PROP, we change it. */
2021 store_in_alist (Lisp_Object
*alistptr
, Lisp_Object prop
, Lisp_Object val
)
2023 register Lisp_Object tem
;
2025 tem
= Fassq (prop
, *alistptr
);
2027 *alistptr
= Fcons (Fcons (prop
, val
), *alistptr
);
2033 frame_name_fnn_p (char *str
, ptrdiff_t len
)
2035 if (len
> 1 && str
[0] == 'F' && '0' <= str
[1] && str
[1] <= '9')
2038 while ('0' <= *p
&& *p
<= '9')
2046 /* Set the name of the terminal frame. Also used by MSDOS frames.
2047 Modeled after x_set_name which is used for WINDOW frames. */
2050 set_term_frame_name (struct frame
*f
, Lisp_Object name
)
2052 f
->explicit_name
= ! NILP (name
);
2054 /* If NAME is nil, set the name to F<num>. */
2057 char namebuf
[sizeof "F" + INT_STRLEN_BOUND (printmax_t
)];
2059 /* Check for no change needed in this very common case
2060 before we do any consing. */
2061 if (frame_name_fnn_p (SSDATA (f
->name
), SBYTES (f
->name
)))
2064 name
= make_formatted_string (namebuf
, "F%"pMd
, ++tty_frame_count
);
2068 CHECK_STRING (name
);
2070 /* Don't change the name if it's already NAME. */
2071 if (! NILP (Fstring_equal (name
, f
->name
)))
2074 /* Don't allow the user to set the frame name to F<num>, so it
2075 doesn't clash with the names we generate for terminal frames. */
2076 if (frame_name_fnn_p (SSDATA (name
), SBYTES (name
)))
2077 error ("Frame names of the form F<num> are usurped by Emacs");
2080 fset_name (f
, name
);
2081 update_mode_lines
= 16;
2085 store_frame_param (struct frame
*f
, Lisp_Object prop
, Lisp_Object val
)
2087 register Lisp_Object old_alist_elt
;
2089 /* The buffer-list parameters are stored in a special place and not
2090 in the alist. All buffers must be live. */
2091 if (EQ (prop
, Qbuffer_list
))
2093 Lisp_Object list
= Qnil
;
2094 for (; CONSP (val
); val
= XCDR (val
))
2095 if (!NILP (Fbuffer_live_p (XCAR (val
))))
2096 list
= Fcons (XCAR (val
), list
);
2097 fset_buffer_list (f
, Fnreverse (list
));
2100 if (EQ (prop
, Qburied_buffer_list
))
2102 Lisp_Object list
= Qnil
;
2103 for (; CONSP (val
); val
= XCDR (val
))
2104 if (!NILP (Fbuffer_live_p (XCAR (val
))))
2105 list
= Fcons (XCAR (val
), list
);
2106 fset_buried_buffer_list (f
, Fnreverse (list
));
2110 /* If PROP is a symbol which is supposed to have frame-local values,
2111 and it is set up based on this frame, switch to the global
2112 binding. That way, we can create or alter the frame-local binding
2113 without messing up the symbol's status. */
2116 struct Lisp_Symbol
*sym
= XSYMBOL (prop
);
2118 switch (sym
->redirect
)
2120 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
2121 case SYMBOL_PLAINVAL
: case SYMBOL_FORWARDED
: break;
2122 case SYMBOL_LOCALIZED
:
2123 { struct Lisp_Buffer_Local_Value
*blv
= sym
->val
.blv
;
2124 if (blv
->frame_local
&& blv_found (blv
) && XFRAME (blv
->where
) == f
)
2125 swap_in_global_binding (sym
);
2128 default: emacs_abort ();
2132 /* The tty color needed to be set before the frame's parameter
2133 alist was updated with the new value. This is not true any more,
2134 but we still do this test early on. */
2135 if (FRAME_TERMCAP_P (f
) && EQ (prop
, Qtty_color_mode
)
2136 && f
== FRAME_TTY (f
)->previous_frame
)
2137 /* Force redisplay of this tty. */
2138 FRAME_TTY (f
)->previous_frame
= NULL
;
2140 /* Update the frame parameter alist. */
2141 old_alist_elt
= Fassq (prop
, f
->param_alist
);
2142 if (EQ (old_alist_elt
, Qnil
))
2143 fset_param_alist (f
, Fcons (Fcons (prop
, val
), f
->param_alist
));
2145 Fsetcdr (old_alist_elt
, val
);
2147 /* Update some other special parameters in their special places
2148 in addition to the alist. */
2150 if (EQ (prop
, Qbuffer_predicate
))
2151 fset_buffer_predicate (f
, val
);
2153 if (! FRAME_WINDOW_P (f
))
2155 if (EQ (prop
, Qmenu_bar_lines
))
2156 set_menu_bar_lines (f
, val
, make_number (FRAME_MENU_BAR_LINES (f
)));
2157 else if (EQ (prop
, Qname
))
2158 set_term_frame_name (f
, val
);
2161 if (EQ (prop
, Qminibuffer
) && WINDOWP (val
))
2163 if (! MINI_WINDOW_P (XWINDOW (val
)))
2164 error ("Surrogate minibuffer windows must be minibuffer windows");
2166 if ((FRAME_HAS_MINIBUF_P (f
) || FRAME_MINIBUF_ONLY_P (f
))
2167 && !EQ (val
, f
->minibuffer_window
))
2168 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2170 /* Install the chosen minibuffer window, with proper buffer. */
2171 fset_minibuffer_window (f
, val
);
2175 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2176 is not an unspecified foreground or background color. */
2179 frame_unspecified_color (struct frame
*f
, Lisp_Object unspec
)
2181 return (!strncmp (SSDATA (unspec
), unspecified_bg
, SBYTES (unspec
))
2182 ? tty_color_name (f
, FRAME_BACKGROUND_PIXEL (f
))
2183 : (!strncmp (SSDATA (unspec
), unspecified_fg
, SBYTES (unspec
))
2184 ? tty_color_name (f
, FRAME_FOREGROUND_PIXEL (f
)) : Qnil
));
2187 DEFUN ("frame-parameters", Fframe_parameters
, Sframe_parameters
, 0, 1, 0,
2188 doc
: /* Return the parameters-alist of frame FRAME.
2189 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2190 The meaningful PARMs depend on the kind of frame.
2191 If FRAME is omitted or nil, return information on the currently selected frame. */)
2195 struct frame
*f
= decode_any_frame (frame
);
2197 struct gcpro gcpro1
;
2199 if (!FRAME_LIVE_P (f
))
2202 alist
= Fcopy_alist (f
->param_alist
);
2205 if (!FRAME_WINDOW_P (f
))
2209 /* If the frame's parameter alist says the colors are
2210 unspecified and reversed, take the frame's background pixel
2211 for foreground and vice versa. */
2212 elt
= Fassq (Qforeground_color
, alist
);
2213 if (CONSP (elt
) && STRINGP (XCDR (elt
)))
2215 elt
= frame_unspecified_color (f
, XCDR (elt
));
2217 store_in_alist (&alist
, Qforeground_color
, elt
);
2220 store_in_alist (&alist
, Qforeground_color
,
2221 tty_color_name (f
, FRAME_FOREGROUND_PIXEL (f
)));
2222 elt
= Fassq (Qbackground_color
, alist
);
2223 if (CONSP (elt
) && STRINGP (XCDR (elt
)))
2225 elt
= frame_unspecified_color (f
, XCDR (elt
));
2227 store_in_alist (&alist
, Qbackground_color
, elt
);
2230 store_in_alist (&alist
, Qbackground_color
,
2231 tty_color_name (f
, FRAME_BACKGROUND_PIXEL (f
)));
2232 store_in_alist (&alist
, intern ("font"),
2233 build_string (FRAME_MSDOS_P (f
)
2235 : FRAME_W32_P (f
) ? "w32term"
2238 store_in_alist (&alist
, Qname
, f
->name
);
2239 height
= (f
->new_height
2241 ? (f
->new_height
/ FRAME_LINE_HEIGHT (f
))
2243 : FRAME_LINES (f
)) - FRAME_TOP_MARGIN (f
);
2244 store_in_alist (&alist
, Qheight
, make_number (height
));
2245 width
= (f
->new_width
2247 ? (f
->new_width
/ FRAME_COLUMN_WIDTH (f
))
2250 store_in_alist (&alist
, Qwidth
, make_number (width
));
2251 store_in_alist (&alist
, Qmodeline
, (FRAME_WANTS_MODELINE_P (f
) ? Qt
: Qnil
));
2252 store_in_alist (&alist
, Qminibuffer
,
2253 (! FRAME_HAS_MINIBUF_P (f
) ? Qnil
2254 : FRAME_MINIBUF_ONLY_P (f
) ? Qonly
2255 : FRAME_MINIBUF_WINDOW (f
)));
2256 store_in_alist (&alist
, Qunsplittable
, (FRAME_NO_SPLIT_P (f
) ? Qt
: Qnil
));
2257 store_in_alist (&alist
, Qbuffer_list
, f
->buffer_list
);
2258 store_in_alist (&alist
, Qburied_buffer_list
, f
->buried_buffer_list
);
2260 /* I think this should be done with a hook. */
2261 #ifdef HAVE_WINDOW_SYSTEM
2262 if (FRAME_WINDOW_P (f
))
2263 x_report_frame_params (f
, &alist
);
2267 /* This ought to be correct in f->param_alist for an X frame. */
2269 XSETFASTINT (lines
, FRAME_MENU_BAR_LINES (f
));
2270 store_in_alist (&alist
, Qmenu_bar_lines
, lines
);
2278 DEFUN ("frame-parameter", Fframe_parameter
, Sframe_parameter
, 2, 2, 0,
2279 doc
: /* Return FRAME's value for parameter PARAMETER.
2280 If FRAME is nil, describe the currently selected frame. */)
2281 (Lisp_Object frame
, Lisp_Object parameter
)
2283 struct frame
*f
= decode_any_frame (frame
);
2284 Lisp_Object value
= Qnil
;
2286 CHECK_SYMBOL (parameter
);
2288 XSETFRAME (frame
, f
);
2290 if (FRAME_LIVE_P (f
))
2292 /* Avoid consing in frequent cases. */
2293 if (EQ (parameter
, Qname
))
2295 #ifdef HAVE_X_WINDOWS
2296 else if (EQ (parameter
, Qdisplay
) && FRAME_X_P (f
))
2297 value
= XCAR (FRAME_DISPLAY_INFO (f
)->name_list_element
);
2298 #endif /* HAVE_X_WINDOWS */
2299 else if (EQ (parameter
, Qbackground_color
)
2300 || EQ (parameter
, Qforeground_color
))
2302 value
= Fassq (parameter
, f
->param_alist
);
2305 value
= XCDR (value
);
2306 /* Fframe_parameters puts the actual fg/bg color names,
2307 even if f->param_alist says otherwise. This is
2308 important when param_alist's notion of colors is
2309 "unspecified". We need to do the same here. */
2310 if (STRINGP (value
) && !FRAME_WINDOW_P (f
))
2311 value
= frame_unspecified_color (f
, value
);
2314 value
= Fcdr (Fassq (parameter
, Fframe_parameters (frame
)));
2316 else if (EQ (parameter
, Qdisplay_type
)
2317 || EQ (parameter
, Qbackground_mode
))
2318 value
= Fcdr (Fassq (parameter
, f
->param_alist
));
2320 /* FIXME: Avoid this code path at all (as well as code duplication)
2321 by sharing more code with Fframe_parameters. */
2322 value
= Fcdr (Fassq (parameter
, Fframe_parameters (frame
)));
2329 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters
,
2330 Smodify_frame_parameters
, 2, 2, 0,
2331 doc
: /* Modify the parameters of frame FRAME according to ALIST.
2332 If FRAME is nil, it defaults to the selected frame.
2333 ALIST is an alist of parameters to change and their new values.
2334 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2335 The meaningful PARMs depend on the kind of frame.
2336 Undefined PARMs are ignored, but stored in the frame's parameter list
2337 so that `frame-parameters' will return them.
2339 The value of frame parameter FOO can also be accessed
2340 as a frame-local binding for the variable FOO, if you have
2341 enabled such bindings for that variable with `make-variable-frame-local'.
2342 Note that this functionality is obsolete as of Emacs 22.2, and its
2343 use is not recommended. Explicitly check for a frame-parameter instead. */)
2344 (Lisp_Object frame
, Lisp_Object alist
)
2346 struct frame
*f
= decode_live_frame (frame
);
2347 register Lisp_Object prop
, val
;
2351 /* I think this should be done with a hook. */
2352 #ifdef HAVE_WINDOW_SYSTEM
2353 if (FRAME_WINDOW_P (f
))
2354 x_set_frame_parameters (f
, alist
);
2358 if (FRAME_MSDOS_P (f
))
2359 IT_set_frame_parameters (f
, alist
);
2364 EMACS_INT length
= XFASTINT (Flength (alist
));
2367 Lisp_Object
*values
;
2369 SAFE_ALLOCA_LISP (parms
, 2 * length
);
2370 values
= parms
+ length
;
2372 /* Extract parm names and values into those vectors. */
2374 for (i
= 0; CONSP (alist
); alist
= XCDR (alist
))
2379 parms
[i
] = Fcar (elt
);
2380 values
[i
] = Fcdr (elt
);
2384 /* Now process them in reverse of specified order. */
2389 store_frame_param (f
, prop
, val
);
2391 if (EQ (prop
, Qforeground_color
)
2392 || EQ (prop
, Qbackground_color
))
2393 update_face_from_frame_parameter (f
, prop
, val
);
2401 DEFUN ("frame-char-height", Fframe_char_height
, Sframe_char_height
,
2403 doc
: /* Height in pixels of a line in the font in frame FRAME.
2404 If FRAME is omitted or nil, the selected frame is used.
2405 For a terminal frame, the value is always 1. */)
2408 #ifdef HAVE_WINDOW_SYSTEM
2409 struct frame
*f
= decode_any_frame (frame
);
2411 if (FRAME_WINDOW_P (f
))
2412 return make_number (FRAME_LINE_HEIGHT (f
));
2415 return make_number (1);
2419 DEFUN ("frame-char-width", Fframe_char_width
, Sframe_char_width
,
2421 doc
: /* Width in pixels of characters in the font in frame FRAME.
2422 If FRAME is omitted or nil, the selected frame is used.
2423 On a graphical screen, the width is the standard width of the default font.
2424 For a terminal screen, the value is always 1. */)
2427 #ifdef HAVE_WINDOW_SYSTEM
2428 struct frame
*f
= decode_any_frame (frame
);
2430 if (FRAME_WINDOW_P (f
))
2431 return make_number (FRAME_COLUMN_WIDTH (f
));
2434 return make_number (1);
2437 DEFUN ("frame-pixel-height", Fframe_pixel_height
,
2438 Sframe_pixel_height
, 0, 1, 0,
2439 doc
: /* Return a FRAME's height in pixels.
2440 If FRAME is omitted or nil, the selected frame is used. The exact value
2441 of the result depends on the window-system and toolkit in use:
2443 In the Gtk+ version of Emacs, it includes only any window (including
2444 the minibuffer or echo area), mode line, and header line. It does not
2445 include the tool bar or menu bar.
2447 With other graphical versions, it also includes the tool bar and the
2450 For a text terminal, it includes the menu bar. In this case, the
2451 result is really in characters rather than pixels (i.e., is identical
2452 to `frame-height'). */)
2455 struct frame
*f
= decode_any_frame (frame
);
2457 #ifdef HAVE_WINDOW_SYSTEM
2458 if (FRAME_WINDOW_P (f
))
2459 return make_number (FRAME_PIXEL_HEIGHT (f
));
2462 return make_number (FRAME_LINES (f
));
2465 DEFUN ("frame-pixel-width", Fframe_pixel_width
,
2466 Sframe_pixel_width
, 0, 1, 0,
2467 doc
: /* Return FRAME's width in pixels.
2468 For a terminal frame, the result really gives the width in characters.
2469 If FRAME is omitted or nil, the selected frame is used. */)
2472 struct frame
*f
= decode_any_frame (frame
);
2474 #ifdef HAVE_WINDOW_SYSTEM
2475 if (FRAME_WINDOW_P (f
))
2476 return make_number (FRAME_PIXEL_WIDTH (f
));
2479 return make_number (FRAME_COLS (f
));
2482 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width
,
2483 Stool_bar_pixel_width
, 0, 1, 0,
2484 doc
: /* Return width in pixels of FRAME's tool bar.
2485 The result is greater than zero only when the tool bar is on the left
2486 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2490 #ifdef FRAME_TOOLBAR_WIDTH
2491 struct frame
*f
= decode_any_frame (frame
);
2493 if (FRAME_WINDOW_P (f
))
2494 return make_number (FRAME_TOOLBAR_WIDTH (f
));
2496 return make_number (0);
2499 DEFUN ("frame-text-cols", Fframe_text_cols
, Sframe_text_cols
, 0, 1, 0,
2500 doc
: /* Return width in columns of FRAME's text area. */)
2503 return make_number (FRAME_COLS (decode_any_frame (frame
)));
2506 DEFUN ("frame-text-lines", Fframe_text_lines
, Sframe_text_lines
, 0, 1, 0,
2507 doc
: /* Return height in lines of FRAME's text area. */)
2510 return make_number (FRAME_LINES (decode_any_frame (frame
)));
2513 DEFUN ("frame-total-cols", Fframe_total_cols
, Sframe_total_cols
, 0, 1, 0,
2514 doc
: /* Return total columns of FRAME. */)
2517 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame
)));
2520 DEFUN ("frame-text-width", Fframe_text_width
, Sframe_text_width
, 0, 1, 0,
2521 doc
: /* Return text area width of FRAME in pixels. */)
2524 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame
)));
2527 DEFUN ("frame-text-height", Fframe_text_height
, Sframe_text_height
, 0, 1, 0,
2528 doc
: /* Return text area height of FRAME in pixels. */)
2531 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame
)));
2534 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width
, Sscroll_bar_width
, 0, 1, 0,
2535 doc
: /* Return scroll bar width of FRAME in pixels. */)
2538 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame
)));
2541 DEFUN ("frame-fringe-width", Ffringe_width
, Sfringe_width
, 0, 1, 0,
2542 doc
: /* Return fringe width of FRAME in pixels. */)
2545 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame
)));
2548 DEFUN ("frame-border-width", Fborder_width
, Sborder_width
, 0, 1, 0,
2549 doc
: /* Return border width of FRAME in pixels. */)
2552 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame
)));
2555 DEFUN ("frame-right-divider-width", Fright_divider_width
, Sright_divider_width
, 0, 1, 0,
2556 doc
: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2559 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame
)));
2562 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width
, Sbottom_divider_width
, 0, 1, 0,
2563 doc
: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2566 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame
)));
2569 /* For requested height in *HEIGHTP, calculate new height of frame F in
2570 character units and return true if actual height should be changed. */
2573 adjust_frame_height (struct frame
*f
, int *heightp
)
2575 if (FRAME_LINES (f
) - FRAME_TOP_MARGIN (f
) != *heightp
)
2577 *heightp
+= FRAME_TOP_MARGIN (f
);
2583 DEFUN ("set-frame-height", Fset_frame_height
, Sset_frame_height
, 2, 4, 0,
2584 doc
: /* Specify that the frame FRAME has HEIGHT text lines.
2585 Optional third arg PRETEND non-nil means that redisplay should use
2586 HEIGHT lines but that the idea of the actual height of the frame should
2587 not be changed. Optional fourth argument PIXELWISE non-nil means that
2588 FRAME should be HEIGHT pixels high. */)
2589 (Lisp_Object frame
, Lisp_Object height
, Lisp_Object pretend
, Lisp_Object pixelwise
)
2591 register struct frame
*f
= decode_live_frame (frame
);
2593 CHECK_TYPE_RANGED_INTEGER (int, height
);
2595 /* I think this should be done with a hook. */
2596 #ifdef HAVE_WINDOW_SYSTEM
2597 if (FRAME_WINDOW_P (f
))
2599 if (NILP (pixelwise
))
2601 int h
= XINT (height
);
2603 if (adjust_frame_height (f
, &h
))
2604 x_set_window_size (f
, 1, FRAME_COLS (f
), h
, 0);
2606 do_pending_window_change (0);
2608 else if (XINT (height
) != FRAME_TEXT_HEIGHT (f
))
2610 x_set_window_size (f
, 1, FRAME_TEXT_WIDTH (f
), XINT (height
), 1);
2611 do_pending_window_change (0);
2616 change_frame_size (f
, 0, XINT (height
), !NILP (pretend
), 0, 0,
2617 NILP (pixelwise
) ? 0 : 1);
2621 DEFUN ("set-frame-width", Fset_frame_width
, Sset_frame_width
, 2, 4, 0,
2622 doc
: /* Specify that the frame FRAME has WIDTH columns.
2623 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2624 columns but that the idea of the actual width of the frame should not
2625 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2626 should be WIDTH pixels wide. */)
2627 (Lisp_Object frame
, Lisp_Object width
, Lisp_Object pretend
, Lisp_Object pixelwise
)
2629 register struct frame
*f
= decode_live_frame (frame
);
2631 CHECK_TYPE_RANGED_INTEGER (int, width
);
2633 /* I think this should be done with a hook. */
2634 #ifdef HAVE_WINDOW_SYSTEM
2635 if (FRAME_WINDOW_P (f
))
2637 if (NILP (pixelwise
))
2639 if (XINT (width
) != FRAME_COLS (f
))
2640 x_set_window_size (f
, 1, XINT (width
), FRAME_LINES (f
), 0);
2642 do_pending_window_change (0);
2644 else if (XINT (width
) != FRAME_TEXT_WIDTH (f
))
2646 x_set_window_size (f
, 1, XINT (width
), FRAME_TEXT_HEIGHT (f
), 1);
2647 do_pending_window_change (0);
2652 change_frame_size (f
, XINT (width
), 0, !NILP (pretend
), 0, 0,
2653 NILP (pixelwise
) ? 0 : 1);
2657 DEFUN ("set-frame-size", Fset_frame_size
, Sset_frame_size
, 3, 4, 0,
2658 doc
: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2659 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2660 (Lisp_Object frame
, Lisp_Object width
, Lisp_Object height
, Lisp_Object pixelwise
)
2662 register struct frame
*f
= decode_live_frame (frame
);
2664 CHECK_TYPE_RANGED_INTEGER (int, width
);
2665 CHECK_TYPE_RANGED_INTEGER (int, height
);
2667 /* I think this should be done with a hook. */
2668 #ifdef HAVE_WINDOW_SYSTEM
2669 if (FRAME_WINDOW_P (f
))
2671 int h
= XINT (height
);
2673 if (!NILP (pixelwise
)
2674 ? (XINT (width
) != FRAME_TEXT_WIDTH (f
)
2675 || h
!= FRAME_TEXT_HEIGHT (f
)
2676 || f
->new_height
|| f
->new_width
)
2677 : (adjust_frame_height (f
, &h
)
2678 || XINT (width
) != FRAME_COLS (f
)
2679 || f
->new_height
|| f
->new_width
))
2681 x_set_window_size (f
, 1, XINT (width
), h
,
2682 NILP (pixelwise
) ? 0 : 1);
2683 do_pending_window_change (0);
2688 change_frame_size (f
, XINT (width
), XINT (height
), 0, 0, 0,
2689 NILP (pixelwise
) ? 0 : 1);
2694 DEFUN ("set-frame-position", Fset_frame_position
,
2695 Sset_frame_position
, 3, 3, 0,
2696 doc
: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2697 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2698 actually the position of the upper left corner of the frame. Negative
2699 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2700 or bottommost possible position (that stays within the screen). */)
2701 (Lisp_Object frame
, Lisp_Object xoffset
, Lisp_Object yoffset
)
2703 register struct frame
*f
= decode_live_frame (frame
);
2705 CHECK_TYPE_RANGED_INTEGER (int, xoffset
);
2706 CHECK_TYPE_RANGED_INTEGER (int, yoffset
);
2708 /* I think this should be done with a hook. */
2709 #ifdef HAVE_WINDOW_SYSTEM
2710 if (FRAME_WINDOW_P (f
))
2711 x_set_offset (f
, XINT (xoffset
), XINT (yoffset
), 1);
2718 /***********************************************************************
2720 ***********************************************************************/
2722 /* Connect the frame-parameter names for X frames
2723 to the ways of passing the parameter values to the window system.
2725 The name of a parameter, as a Lisp symbol,
2726 has an `x-frame-parameter' property which is an integer in Lisp
2727 that is an index in this table. */
2729 struct frame_parm_table
{
2731 Lisp_Object
*variable
;
2734 static const struct frame_parm_table frame_parms
[] =
2736 {"auto-raise", &Qauto_raise
},
2737 {"auto-lower", &Qauto_lower
},
2738 {"background-color", 0},
2739 {"border-color", &Qborder_color
},
2740 {"border-width", &Qborder_width
},
2741 {"cursor-color", &Qcursor_color
},
2742 {"cursor-type", &Qcursor_type
},
2744 {"foreground-color", 0},
2745 {"icon-name", &Qicon_name
},
2746 {"icon-type", &Qicon_type
},
2747 {"internal-border-width", &Qinternal_border_width
},
2748 {"right-divider-width", &Qright_divider_width
},
2749 {"bottom-divider-width", &Qbottom_divider_width
},
2750 {"menu-bar-lines", &Qmenu_bar_lines
},
2751 {"mouse-color", &Qmouse_color
},
2753 {"scroll-bar-width", &Qscroll_bar_width
},
2755 {"unsplittable", &Qunsplittable
},
2756 {"vertical-scroll-bars", &Qvertical_scroll_bars
},
2757 {"visibility", &Qvisibility
},
2758 {"tool-bar-lines", &Qtool_bar_lines
},
2759 {"scroll-bar-foreground", &Qscroll_bar_foreground
},
2760 {"scroll-bar-background", &Qscroll_bar_background
},
2761 {"screen-gamma", &Qscreen_gamma
},
2762 {"line-spacing", &Qline_spacing
},
2763 {"left-fringe", &Qleft_fringe
},
2764 {"right-fringe", &Qright_fringe
},
2765 {"wait-for-wm", &Qwait_for_wm
},
2766 {"fullscreen", &Qfullscreen
},
2767 {"font-backend", &Qfont_backend
},
2769 {"sticky", &Qsticky
},
2770 {"tool-bar-position", &Qtool_bar_position
},
2773 #ifdef HAVE_WINDOW_SYSTEM
2775 /* Change the parameters of frame F as specified by ALIST.
2776 If a parameter is not specially recognized, do nothing special;
2777 otherwise call the `x_set_...' function for that parameter.
2778 Except for certain geometry properties, always call store_frame_param
2779 to store the new value in the parameter alist. */
2782 x_set_frame_parameters (struct frame
*f
, Lisp_Object alist
)
2786 /* If both of these parameters are present, it's more efficient to
2787 set them both at once. So we wait until we've looked at the
2788 entire list before we set them. */
2789 int width
= 0, height
= 0;
2790 bool width_change
= 0, height_change
= 0;
2793 Lisp_Object left
, top
;
2795 /* Same with these. */
2796 Lisp_Object icon_left
, icon_top
;
2798 /* Record in these vectors all the parms specified. */
2800 Lisp_Object
*values
;
2802 bool left_no_change
= 0, top_no_change
= 0;
2803 #ifdef HAVE_X_WINDOWS
2804 bool icon_left_no_change
= 0, icon_top_no_change
= 0;
2806 struct gcpro gcpro1
, gcpro2
;
2809 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
2812 parms
= alloca (i
* sizeof *parms
);
2813 values
= alloca (i
* sizeof *values
);
2815 /* Extract parm names and values into those vectors. */
2818 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
2823 parms
[i
] = Fcar (elt
);
2824 values
[i
] = Fcdr (elt
);
2827 /* TAIL and ALIST are not used again below here. */
2828 alist
= tail
= Qnil
;
2830 GCPRO2 (*parms
, *values
);
2834 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2835 because their values appear in VALUES and strings are not valid. */
2836 top
= left
= Qunbound
;
2837 icon_left
= icon_top
= Qunbound
;
2839 /* Process foreground_color and background_color before anything else.
2840 They are independent of other properties, but other properties (e.g.,
2841 cursor_color) are dependent upon them. */
2842 /* Process default font as well, since fringe widths depends on it. */
2843 for (p
= 0; p
< i
; p
++)
2845 Lisp_Object prop
, val
;
2849 if (EQ (prop
, Qforeground_color
)
2850 || EQ (prop
, Qbackground_color
)
2851 || EQ (prop
, Qfont
))
2853 register Lisp_Object param_index
, old_value
;
2855 old_value
= get_frame_param (f
, prop
);
2856 if (NILP (Fequal (val
, old_value
)))
2858 store_frame_param (f
, prop
, val
);
2860 param_index
= Fget (prop
, Qx_frame_parameter
);
2861 if (NATNUMP (param_index
)
2862 && XFASTINT (param_index
) < ARRAYELTS (frame_parms
)
2863 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
2864 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
2869 /* Now process them in reverse of specified order. */
2872 Lisp_Object prop
, val
;
2877 if (EQ (prop
, Qwidth
) && RANGED_INTEGERP (0, val
, INT_MAX
))
2880 width
= XFASTINT (val
) * FRAME_COLUMN_WIDTH (f
) ;
2882 else if (EQ (prop
, Qheight
) && RANGED_INTEGERP (0, val
, INT_MAX
))
2885 /* Add menu and tool bar lines to correctly resize F pixelwise. */
2887 = (XFASTINT (val
) + FRAME_TOP_MARGIN (f
)) * FRAME_LINE_HEIGHT (f
);
2889 else if (EQ (prop
, Qtop
))
2891 else if (EQ (prop
, Qleft
))
2893 else if (EQ (prop
, Qicon_top
))
2895 else if (EQ (prop
, Qicon_left
))
2897 else if (EQ (prop
, Qforeground_color
)
2898 || EQ (prop
, Qbackground_color
)
2899 || EQ (prop
, Qfont
))
2900 /* Processed above. */
2904 register Lisp_Object param_index
, old_value
;
2906 old_value
= get_frame_param (f
, prop
);
2908 store_frame_param (f
, prop
, val
);
2910 param_index
= Fget (prop
, Qx_frame_parameter
);
2911 if (NATNUMP (param_index
)
2912 && XFASTINT (param_index
) < ARRAYELTS (frame_parms
)
2913 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
2914 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
2918 /* Don't die if just one of these was set. */
2919 if (EQ (left
, Qunbound
))
2922 if (f
->left_pos
< 0)
2923 left
= list2 (Qplus
, make_number (f
->left_pos
));
2925 XSETINT (left
, f
->left_pos
);
2927 if (EQ (top
, Qunbound
))
2931 top
= list2 (Qplus
, make_number (f
->top_pos
));
2933 XSETINT (top
, f
->top_pos
);
2936 /* If one of the icon positions was not set, preserve or default it. */
2937 if (! TYPE_RANGED_INTEGERP (int, icon_left
))
2939 #ifdef HAVE_X_WINDOWS
2940 icon_left_no_change
= 1;
2942 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
2943 if (NILP (icon_left
))
2944 XSETINT (icon_left
, 0);
2946 if (! TYPE_RANGED_INTEGERP (int, icon_top
))
2948 #ifdef HAVE_X_WINDOWS
2949 icon_top_no_change
= 1;
2951 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
2952 if (NILP (icon_top
))
2953 XSETINT (icon_top
, 0);
2956 /* Don't set these parameters unless they've been explicitly
2957 specified. The window might be mapped or resized while we're in
2958 this function, and we don't want to override that unless the lisp
2959 code has asked for it.
2961 Don't set these parameters unless they actually differ from the
2962 window's current parameters; the window may not actually exist
2967 /* Make this 1, eventually. */
2968 check_frame_size (f
, &width
, &height
, 1);
2970 XSETFRAME (frame
, f
);
2972 if ((width_change
|| height_change
)
2973 && (width
!= FRAME_TEXT_WIDTH (f
)
2974 || height
!= FRAME_TEXT_HEIGHT (f
)
2975 || f
->new_height
|| f
->new_width
))
2977 /* If necessary provide default values for HEIGHT and WIDTH. Do
2978 that here since otherwise a size change implied by an
2979 intermittent font change may get lost as in Bug#17142. */
2981 width
= (f
->new_width
2984 : (f
->new_width
* FRAME_COLUMN_WIDTH (f
)))
2985 : FRAME_TEXT_WIDTH (f
));
2988 height
= (f
->new_height
2991 : (f
->new_height
* FRAME_LINE_HEIGHT (f
)))
2992 : FRAME_TEXT_HEIGHT (f
));
2994 Fset_frame_size (frame
, make_number (width
), make_number (height
), Qt
);
2997 if ((!NILP (left
) || !NILP (top
))
2998 && ! (left_no_change
&& top_no_change
)
2999 && ! (NUMBERP (left
) && XINT (left
) == f
->left_pos
3000 && NUMBERP (top
) && XINT (top
) == f
->top_pos
))
3005 /* Record the signs. */
3006 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
3007 if (EQ (left
, Qminus
))
3008 f
->size_hint_flags
|= XNegative
;
3009 else if (TYPE_RANGED_INTEGERP (int, left
))
3011 leftpos
= XINT (left
);
3013 f
->size_hint_flags
|= XNegative
;
3015 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
3016 && CONSP (XCDR (left
))
3017 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (left
)), INT_MAX
))
3019 leftpos
= - XINT (XCAR (XCDR (left
)));
3020 f
->size_hint_flags
|= XNegative
;
3022 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
3023 && CONSP (XCDR (left
))
3024 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left
))))
3026 leftpos
= XINT (XCAR (XCDR (left
)));
3029 if (EQ (top
, Qminus
))
3030 f
->size_hint_flags
|= YNegative
;
3031 else if (TYPE_RANGED_INTEGERP (int, top
))
3033 toppos
= XINT (top
);
3035 f
->size_hint_flags
|= YNegative
;
3037 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
3038 && CONSP (XCDR (top
))
3039 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (top
)), INT_MAX
))
3041 toppos
= - XINT (XCAR (XCDR (top
)));
3042 f
->size_hint_flags
|= YNegative
;
3044 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
3045 && CONSP (XCDR (top
))
3046 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top
))))
3048 toppos
= XINT (XCAR (XCDR (top
)));
3052 /* Store the numeric value of the position. */
3053 f
->top_pos
= toppos
;
3054 f
->left_pos
= leftpos
;
3056 f
->win_gravity
= NorthWestGravity
;
3058 /* Actually set that position, and convert to absolute. */
3059 x_set_offset (f
, leftpos
, toppos
, -1);
3061 #ifdef HAVE_X_WINDOWS
3062 if ((!NILP (icon_left
) || !NILP (icon_top
))
3063 && ! (icon_left_no_change
&& icon_top_no_change
))
3064 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
3065 #endif /* HAVE_X_WINDOWS */
3072 /* Insert a description of internally-recorded parameters of frame X
3073 into the parameter alist *ALISTPTR that is to be given to the user.
3074 Only parameters that are specific to the X window system
3075 and whose values are not correctly recorded in the frame's
3076 param_alist need to be considered here. */
3079 x_report_frame_params (struct frame
*f
, Lisp_Object
*alistptr
)
3083 char buf
[INT_BUFSIZE_BOUND (w
)];
3085 /* Represent negative positions (off the top or left screen edge)
3086 in a way that Fmodify_frame_parameters will understand correctly. */
3087 XSETINT (tem
, f
->left_pos
);
3088 if (f
->left_pos
>= 0)
3089 store_in_alist (alistptr
, Qleft
, tem
);
3091 store_in_alist (alistptr
, Qleft
, list2 (Qplus
, tem
));
3093 XSETINT (tem
, f
->top_pos
);
3094 if (f
->top_pos
>= 0)
3095 store_in_alist (alistptr
, Qtop
, tem
);
3097 store_in_alist (alistptr
, Qtop
, list2 (Qplus
, tem
));
3099 store_in_alist (alistptr
, Qborder_width
,
3100 make_number (f
->border_width
));
3101 store_in_alist (alistptr
, Qinternal_border_width
,
3102 make_number (FRAME_INTERNAL_BORDER_WIDTH (f
)));
3103 store_in_alist (alistptr
, Qright_divider_width
,
3104 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f
)));
3105 store_in_alist (alistptr
, Qbottom_divider_width
,
3106 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f
)));
3107 store_in_alist (alistptr
, Qleft_fringe
,
3108 make_number (FRAME_LEFT_FRINGE_WIDTH (f
)));
3109 store_in_alist (alistptr
, Qright_fringe
,
3110 make_number (FRAME_RIGHT_FRINGE_WIDTH (f
)));
3111 store_in_alist (alistptr
, Qscroll_bar_width
,
3112 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3114 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
3115 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3116 /* nil means "use default width"
3117 for non-toolkit scroll bar.
3118 ruler-mode.el depends on this. */
3120 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3121 MS-Windows it returns a value whose type is HANDLE, which is
3122 actually a pointer. Explicit casting avoids compiler
3124 w
= (uintptr_t) FRAME_X_WINDOW (f
);
3125 store_in_alist (alistptr
, Qwindow_id
,
3126 make_formatted_string (buf
, "%"pMu
, w
));
3127 #ifdef HAVE_X_WINDOWS
3128 #ifdef USE_X_TOOLKIT
3129 /* Tooltip frame may not have this widget. */
3130 if (FRAME_X_OUTPUT (f
)->widget
)
3132 w
= (uintptr_t) FRAME_OUTER_WINDOW (f
);
3133 store_in_alist (alistptr
, Qouter_window_id
,
3134 make_formatted_string (buf
, "%"pMu
, w
));
3136 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
3137 store_in_alist (alistptr
, Qvisibility
,
3138 (FRAME_VISIBLE_P (f
) ? Qt
3139 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
3140 store_in_alist (alistptr
, Qdisplay
,
3141 XCAR (FRAME_DISPLAY_INFO (f
)->name_list_element
));
3143 if (FRAME_X_OUTPUT (f
)->parent_desc
== FRAME_DISPLAY_INFO (f
)->root_window
)
3146 tem
= make_natnum ((uintptr_t) FRAME_X_OUTPUT (f
)->parent_desc
);
3147 store_in_alist (alistptr
, Qexplicit_name
, (f
->explicit_name
? Qt
: Qnil
));
3148 store_in_alist (alistptr
, Qparent_id
, tem
);
3149 store_in_alist (alistptr
, Qtool_bar_position
, FRAME_TOOL_BAR_POSITION (f
));
3153 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3154 the previous value of that parameter, NEW_VALUE is the new value. */
3157 x_set_fullscreen (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3159 if (NILP (new_value
))
3160 f
->want_fullscreen
= FULLSCREEN_NONE
;
3161 else if (EQ (new_value
, Qfullboth
) || EQ (new_value
, Qfullscreen
))
3162 f
->want_fullscreen
= FULLSCREEN_BOTH
;
3163 else if (EQ (new_value
, Qfullwidth
))
3164 f
->want_fullscreen
= FULLSCREEN_WIDTH
;
3165 else if (EQ (new_value
, Qfullheight
))
3166 f
->want_fullscreen
= FULLSCREEN_HEIGHT
;
3167 else if (EQ (new_value
, Qmaximized
))
3168 f
->want_fullscreen
= FULLSCREEN_MAXIMIZED
;
3170 if (FRAME_TERMINAL (f
)->fullscreen_hook
!= NULL
)
3171 FRAME_TERMINAL (f
)->fullscreen_hook (f
);
3175 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3176 the previous value of that parameter, NEW_VALUE is the new value. */
3179 x_set_line_spacing (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3181 if (NILP (new_value
))
3182 f
->extra_line_spacing
= 0;
3183 else if (RANGED_INTEGERP (0, new_value
, INT_MAX
))
3184 f
->extra_line_spacing
= XFASTINT (new_value
);
3185 else if (FLOATP (new_value
))
3187 int new_spacing
= XFLOAT_DATA (new_value
) * FRAME_LINE_HEIGHT (f
) + 0.5;
3189 if (new_spacing
>= 0)
3190 f
->extra_line_spacing
= new_spacing
;
3192 signal_error ("Invalid line-spacing", new_value
);
3195 signal_error ("Invalid line-spacing", new_value
);
3196 if (FRAME_VISIBLE_P (f
))
3201 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3202 the previous value of that parameter, NEW_VALUE is the new value. */
3205 x_set_screen_gamma (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3207 Lisp_Object bgcolor
;
3209 if (NILP (new_value
))
3211 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
3212 /* The value 0.4545 is the normal viewing gamma. */
3213 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
3215 signal_error ("Invalid screen-gamma", new_value
);
3217 /* Apply the new gamma value to the frame background. */
3218 bgcolor
= Fassq (Qbackground_color
, f
->param_alist
);
3219 if (CONSP (bgcolor
) && (bgcolor
= XCDR (bgcolor
), STRINGP (bgcolor
)))
3221 Lisp_Object parm_index
= Fget (Qbackground_color
, Qx_frame_parameter
);
3222 if (NATNUMP (parm_index
)
3223 && XFASTINT (parm_index
) < ARRAYELTS (frame_parms
)
3224 && FRAME_RIF (f
)->frame_parm_handlers
[XFASTINT (parm_index
)])
3225 (*FRAME_RIF (f
)->frame_parm_handlers
[XFASTINT (parm_index
)])
3229 Fclear_face_cache (Qnil
);
3234 x_set_font (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3236 Lisp_Object font_object
;
3238 #ifdef HAVE_X_WINDOWS
3239 Lisp_Object font_param
= arg
;
3242 /* Set the frame parameter back to the old value because we may
3243 fail to use ARG as the new parameter value. */
3244 store_frame_param (f
, Qfont
, oldval
);
3246 /* ARG is a fontset name, a font name, a cons of fontset name and a
3247 font object, or a font object. In the last case, this function
3251 fontset
= fs_query_fontset (arg
, 0);
3254 font_object
= font_open_by_name (f
, arg
);
3255 if (NILP (font_object
))
3256 error ("Font `%s' is not defined", SSDATA (arg
));
3257 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3259 else if (fontset
> 0)
3261 font_object
= font_open_by_name (f
, fontset_ascii (fontset
));
3262 if (NILP (font_object
))
3263 error ("Font `%s' is not defined", SDATA (arg
));
3264 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3267 error ("The default fontset can't be used for a frame font");
3269 else if (CONSP (arg
) && STRINGP (XCAR (arg
)) && FONT_OBJECT_P (XCDR (arg
)))
3271 /* This is the case that the ASCII font of F's fontset XCAR
3272 (arg) is changed to the font XCDR (arg) by
3273 `set-fontset-font'. */
3274 fontset
= fs_query_fontset (XCAR (arg
), 0);
3276 error ("Unknown fontset: %s", SDATA (XCAR (arg
)));
3277 font_object
= XCDR (arg
);
3278 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3279 #ifdef HAVE_X_WINDOWS
3280 font_param
= Ffont_get (font_object
, QCname
);
3283 else if (FONT_OBJECT_P (arg
))
3286 #ifdef HAVE_X_WINDOWS
3287 font_param
= Ffont_get (font_object
, QCname
);
3289 /* This is to store the XLFD font name in the frame parameter for
3290 backward compatibility. We should store the font-object
3291 itself in the future. */
3292 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3293 fontset
= FRAME_FONTSET (f
);
3294 /* Check if we can use the current fontset. If not, set FONTSET
3295 to -1 to generate a new fontset from FONT-OBJECT. */
3298 Lisp_Object ascii_font
= fontset_ascii (fontset
);
3299 Lisp_Object spec
= font_spec_from_name (ascii_font
);
3302 signal_error ("Invalid font name", ascii_font
);
3304 if (! font_match_p (spec
, font_object
))
3309 signal_error ("Invalid font", arg
);
3311 if (! NILP (Fequal (font_object
, oldval
)))
3314 x_new_font (f
, font_object
, fontset
);
3315 store_frame_param (f
, Qfont
, arg
);
3316 #ifdef HAVE_X_WINDOWS
3317 store_frame_param (f
, Qfont_param
, font_param
);
3319 /* Recalculate toolbar height. */
3320 f
->n_tool_bar_rows
= 0;
3322 /* Ensure we redraw it. */
3323 clear_current_matrices (f
);
3325 /* Attempt to hunt down bug#16028. */
3326 SET_FRAME_GARBAGED (f
);
3328 recompute_basic_faces (f
);
3330 do_pending_window_change (0);
3332 /* We used to call face-set-after-frame-default here, but it leads to
3333 recursive calls (since that function can set the `default' face's
3334 font which in turns changes the frame's `font' parameter).
3335 Also I don't know what this call is meant to do, but it seems the
3336 wrong way to do it anyway (it does a lot more work than what seems
3337 reasonable in response to a change to `font'). */
3342 x_set_font_backend (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3344 if (! NILP (new_value
)
3345 && !CONSP (new_value
))
3349 CHECK_STRING (new_value
);
3350 p0
= p1
= SSDATA (new_value
);
3354 while (*p1
&& ! c_isspace (*p1
) && *p1
!= ',') p1
++;
3356 new_value
= Fcons (Fintern (make_string (p0
, p1
- p0
), Qnil
),
3362 while ((c
= *++p1
) && c_isspace (c
));
3366 new_value
= Fnreverse (new_value
);
3369 if (! NILP (old_value
) && ! NILP (Fequal (old_value
, new_value
)))
3373 free_all_realized_faces (Qnil
);
3375 new_value
= font_update_drivers (f
, NILP (new_value
) ? Qt
: new_value
);
3376 if (NILP (new_value
))
3378 if (NILP (old_value
))
3379 error ("No font backend available");
3380 font_update_drivers (f
, old_value
);
3381 error ("None of specified font backends are available");
3383 store_frame_param (f
, Qfont_backend
, new_value
);
3389 XSETFRAME (frame
, f
);
3390 x_set_font (f
, Fframe_parameter (frame
, Qfont
), Qnil
);
3391 ++face_change_count
;
3392 windows_or_buffers_changed
= 18;
3398 x_set_fringe_width (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3400 compute_fringe_widths (f
, 1);
3401 #ifdef HAVE_X_WINDOWS
3402 /* Must adjust this so window managers report correct number of columns. */
3403 if (FRAME_X_WINDOW (f
) != 0)
3404 x_wm_set_size_hint (f
, 0, 0);
3409 x_set_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3411 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3413 if (XINT (arg
) == f
->border_width
)
3416 if (FRAME_X_WINDOW (f
) != 0)
3417 error ("Cannot change the border width of a frame");
3419 f
->border_width
= XINT (arg
);
3423 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3425 int old
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3427 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3428 FRAME_INTERNAL_BORDER_WIDTH (f
) = XINT (arg
);
3429 if (FRAME_INTERNAL_BORDER_WIDTH (f
) < 0)
3430 FRAME_INTERNAL_BORDER_WIDTH (f
) = 0;
3432 #ifdef USE_X_TOOLKIT
3433 if (FRAME_X_OUTPUT (f
)->edit_widget
)
3434 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
3437 if (FRAME_INTERNAL_BORDER_WIDTH (f
) == old
)
3440 if (FRAME_X_WINDOW (f
) != 0)
3442 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3443 SET_FRAME_GARBAGED (f
);
3444 do_pending_window_change (0);
3447 SET_FRAME_GARBAGED (f
);
3451 x_set_right_divider_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3453 int old
= FRAME_RIGHT_DIVIDER_WIDTH (f
);
3455 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3456 FRAME_RIGHT_DIVIDER_WIDTH (f
) = XINT (arg
);
3457 if (FRAME_RIGHT_DIVIDER_WIDTH (f
) < 0)
3458 FRAME_RIGHT_DIVIDER_WIDTH (f
) = 0;
3460 if (FRAME_RIGHT_DIVIDER_WIDTH (f
) == old
)
3463 if (FRAME_X_WINDOW (f
) != 0)
3465 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3466 SET_FRAME_GARBAGED (f
);
3467 do_pending_window_change (0);
3470 SET_FRAME_GARBAGED (f
);
3474 x_set_bottom_divider_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3476 int old
= FRAME_BOTTOM_DIVIDER_WIDTH (f
);
3478 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3479 FRAME_BOTTOM_DIVIDER_WIDTH (f
) = XINT (arg
);
3480 if (FRAME_BOTTOM_DIVIDER_WIDTH (f
) < 0)
3481 FRAME_BOTTOM_DIVIDER_WIDTH (f
) = 0;
3483 if (FRAME_BOTTOM_DIVIDER_WIDTH (f
) == old
)
3486 if (FRAME_X_WINDOW (f
) != 0)
3488 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3489 SET_FRAME_GARBAGED (f
);
3490 do_pending_window_change (0);
3493 SET_FRAME_GARBAGED (f
);
3497 x_set_visibility (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
3500 XSETFRAME (frame
, f
);
3503 Fmake_frame_invisible (frame
, Qt
);
3504 else if (EQ (value
, Qicon
))
3505 Ficonify_frame (frame
);
3507 Fmake_frame_visible (frame
);
3511 x_set_autoraise (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3513 f
->auto_raise
= !EQ (Qnil
, arg
);
3517 x_set_autolower (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3519 f
->auto_lower
= !EQ (Qnil
, arg
);
3523 x_set_unsplittable (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3525 f
->no_split
= !NILP (arg
);
3529 x_set_vertical_scroll_bars (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3531 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3532 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
3533 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3534 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
3536 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
)
3538 ? vertical_scroll_bar_none
3540 ? vertical_scroll_bar_left
3542 ? vertical_scroll_bar_right
3543 : EQ (Qleft
, Vdefault_frame_scroll_bars
)
3544 ? vertical_scroll_bar_left
3545 : EQ (Qright
, Vdefault_frame_scroll_bars
)
3546 ? vertical_scroll_bar_right
3547 : vertical_scroll_bar_none
);
3549 /* We set this parameter before creating the X window for the
3550 frame, so we can get the geometry right from the start.
3551 However, if the window hasn't been created yet, we shouldn't
3552 call x_set_window_size. */
3553 if (FRAME_X_WINDOW (f
))
3554 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3555 FRAME_TEXT_HEIGHT (f
), 1);
3556 do_pending_window_change (0);
3561 x_set_scroll_bar_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3563 int unit
= FRAME_COLUMN_WIDTH (f
);
3567 x_set_scroll_bar_default_width (f
);
3569 if (FRAME_X_WINDOW (f
))
3570 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3571 FRAME_TEXT_HEIGHT (f
), 1);
3572 do_pending_window_change (0);
3574 else if (RANGED_INTEGERP (1, arg
, INT_MAX
)
3575 && XFASTINT (arg
) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3577 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = XFASTINT (arg
);
3578 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (XFASTINT (arg
) + unit
- 1) / unit
;
3579 if (FRAME_X_WINDOW (f
))
3580 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3581 FRAME_TEXT_HEIGHT (f
), 1);
3582 do_pending_window_change (0);
3585 /* Eventually remove the following call. It should have been done by
3586 x_set_window_size already. */
3587 change_frame_size (f
, 0, 0, 0, 0, 0, 1);
3588 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
3589 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
3593 x_set_alpha (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3600 for (i
= 0; i
< 2; i
++)
3613 else if (FLOATP (item
))
3615 alpha
= XFLOAT_DATA (item
);
3616 if (! (0 <= alpha
&& alpha
<= 1.0))
3617 args_out_of_range (make_float (0.0), make_float (1.0));
3619 else if (INTEGERP (item
))
3621 EMACS_INT ialpha
= XINT (item
);
3622 if (! (0 <= ialpha
&& alpha
<= 100))
3623 args_out_of_range (make_number (0), make_number (100));
3624 alpha
= ialpha
/ 100.0;
3627 wrong_type_argument (Qnumberp
, item
);
3631 for (i
= 0; i
< 2; i
++)
3632 f
->alpha
[i
] = newval
[i
];
3634 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3636 x_set_frame_alpha (f
);
3645 /* Non-zero if mouse is grabbed on DPYINFO
3646 and we know the frame where it is. */
3648 bool x_mouse_grabbed (Display_Info
*dpyinfo
)
3650 return (dpyinfo
->grabbed
3651 && dpyinfo
->last_mouse_frame
3652 && FRAME_LIVE_P (dpyinfo
->last_mouse_frame
));
3655 /* Re-highlight something with mouse-face properties
3656 on DPYINFO using saved frame and mouse position. */
3659 x_redo_mouse_highlight (Display_Info
*dpyinfo
)
3661 if (dpyinfo
->last_mouse_motion_frame
3662 && FRAME_LIVE_P (dpyinfo
->last_mouse_motion_frame
))
3663 note_mouse_highlight (dpyinfo
->last_mouse_motion_frame
,
3664 dpyinfo
->last_mouse_motion_x
,
3665 dpyinfo
->last_mouse_motion_y
);
3668 #endif /* HAVE_NS */
3670 /* Subroutines of creating an X frame. */
3672 /* Make sure that Vx_resource_name is set to a reasonable value.
3673 Fix it up, or set it to `emacs' if it is too hopeless. */
3676 validate_x_resource_name (void)
3679 /* Number of valid characters in the resource name. */
3680 ptrdiff_t good_count
= 0;
3681 /* Number of invalid characters in the resource name. */
3682 ptrdiff_t bad_count
= 0;
3686 if (!STRINGP (Vx_resource_class
))
3687 Vx_resource_class
= build_string (EMACS_CLASS
);
3689 if (STRINGP (Vx_resource_name
))
3691 unsigned char *p
= SDATA (Vx_resource_name
);
3693 len
= SBYTES (Vx_resource_name
);
3695 /* Only letters, digits, - and _ are valid in resource names.
3696 Count the valid characters and count the invalid ones. */
3697 for (i
= 0; i
< len
; i
++)
3700 if (! ((c
>= 'a' && c
<= 'z')
3701 || (c
>= 'A' && c
<= 'Z')
3702 || (c
>= '0' && c
<= '9')
3703 || c
== '-' || c
== '_'))
3710 /* Not a string => completely invalid. */
3711 bad_count
= 5, good_count
= 0;
3713 /* If name is valid already, return. */
3717 /* If name is entirely invalid, or nearly so, or is so implausibly
3718 large that alloca might not work, use `emacs'. */
3719 if (good_count
< 2 || MAX_ALLOCA
- sizeof ".customization" < len
)
3721 Vx_resource_name
= build_string ("emacs");
3725 /* Name is partly valid. Copy it and replace the invalid characters
3726 with underscores. */
3728 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
3730 for (i
= 0; i
< len
; i
++)
3732 int c
= SREF (new, i
);
3733 if (! ((c
>= 'a' && c
<= 'z')
3734 || (c
>= 'A' && c
<= 'Z')
3735 || (c
>= '0' && c
<= '9')
3736 || c
== '-' || c
== '_'))
3741 /* Get specified attribute from resource database RDB.
3742 See Fx_get_resource below for other parameters. */
3745 xrdb_get_resource (XrmDatabase rdb
, Lisp_Object attribute
, Lisp_Object
class, Lisp_Object component
, Lisp_Object subclass
)
3747 register char *value
;
3751 CHECK_STRING (attribute
);
3752 CHECK_STRING (class);
3754 if (!NILP (component
))
3755 CHECK_STRING (component
);
3756 if (!NILP (subclass
))
3757 CHECK_STRING (subclass
);
3758 if (NILP (component
) != NILP (subclass
))
3759 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3761 validate_x_resource_name ();
3763 /* Allocate space for the components, the dots which separate them,
3764 and the final '\0'. Make them big enough for the worst case. */
3765 name_key
= alloca (SBYTES (Vx_resource_name
)
3766 + (STRINGP (component
)
3767 ? SBYTES (component
) : 0)
3768 + SBYTES (attribute
)
3771 class_key
= alloca (SBYTES (Vx_resource_class
)
3773 + (STRINGP (subclass
)
3774 ? SBYTES (subclass
) : 0)
3777 /* Start with emacs.FRAMENAME for the name (the specific one)
3778 and with `Emacs' for the class key (the general one). */
3779 strcpy (name_key
, SSDATA (Vx_resource_name
));
3780 strcpy (class_key
, SSDATA (Vx_resource_class
));
3782 strcat (class_key
, ".");
3783 strcat (class_key
, SSDATA (class));
3785 if (!NILP (component
))
3787 strcat (class_key
, ".");
3788 strcat (class_key
, SSDATA (subclass
));
3790 strcat (name_key
, ".");
3791 strcat (name_key
, SSDATA (component
));
3794 strcat (name_key
, ".");
3795 strcat (name_key
, SSDATA (attribute
));
3797 value
= x_get_string_resource (rdb
, name_key
, class_key
);
3799 if (value
&& *value
)
3800 return build_string (value
);
3806 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
3807 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3808 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3809 class, where INSTANCE is the name under which Emacs was invoked, or
3810 the name specified by the `-name' or `-rn' command-line arguments.
3812 The optional arguments COMPONENT and SUBCLASS add to the key and the
3813 class, respectively. You must specify both of them or neither.
3814 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3815 and the class is `Emacs.CLASS.SUBCLASS'. */)
3816 (Lisp_Object attribute
, Lisp_Object
class, Lisp_Object component
,
3817 Lisp_Object subclass
)
3819 check_window_system (NULL
);
3821 return xrdb_get_resource (check_x_display_info (Qnil
)->xrdb
,
3822 attribute
, class, component
, subclass
);
3825 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3828 display_x_get_resource (Display_Info
*dpyinfo
, Lisp_Object attribute
,
3829 Lisp_Object
class, Lisp_Object component
,
3830 Lisp_Object subclass
)
3832 return xrdb_get_resource (dpyinfo
->xrdb
,
3833 attribute
, class, component
, subclass
);
3836 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3837 /* Used when C code wants a resource value. */
3838 /* Called from oldXMenu/Create.c. */
3840 x_get_resource_string (const char *attribute
, const char *class)
3843 struct frame
*sf
= SELECTED_FRAME ();
3844 ptrdiff_t invocation_namelen
= SBYTES (Vinvocation_name
);
3847 /* Allocate space for the components, the dots which separate them,
3848 and the final '\0'. */
3849 char *name_key
= SAFE_ALLOCA (invocation_namelen
+ strlen (attribute
) + 2);
3850 char *class_key
= alloca ((sizeof (EMACS_CLASS
) - 1) + strlen (class) + 2);
3852 esprintf (name_key
, "%s.%s", SSDATA (Vinvocation_name
), attribute
);
3853 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3855 result
= x_get_string_resource (FRAME_DISPLAY_INFO (sf
)->xrdb
,
3856 name_key
, class_key
);
3862 /* Return the value of parameter PARAM.
3864 First search ALIST, then Vdefault_frame_alist, then the X defaults
3865 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3867 Convert the resource to the type specified by desired_type.
3869 If no default is specified, return Qunbound. If you call
3870 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3871 and don't let it get stored in any Lisp-visible variables! */
3874 x_get_arg (Display_Info
*dpyinfo
, Lisp_Object alist
, Lisp_Object param
,
3875 const char *attribute
, const char *class, enum resource_types type
)
3877 register Lisp_Object tem
;
3879 tem
= Fassq (param
, alist
);
3883 /* If we find this parm in ALIST, clear it out
3884 so that it won't be "left over" at the end. */
3886 XSETCAR (tem
, Qnil
);
3887 /* In case the parameter appears more than once in the alist,
3889 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
3890 if (CONSP (XCAR (tail
))
3891 && EQ (XCAR (XCAR (tail
)), param
))
3892 XSETCAR (XCAR (tail
), Qnil
);
3895 tem
= Fassq (param
, Vdefault_frame_alist
);
3897 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3898 look in the X resources. */
3901 if (attribute
&& dpyinfo
)
3903 tem
= display_x_get_resource (dpyinfo
,
3904 build_string (attribute
),
3905 build_string (class),
3913 case RES_TYPE_NUMBER
:
3914 return make_number (atoi (SSDATA (tem
)));
3916 case RES_TYPE_BOOLEAN_NUMBER
:
3917 if (!strcmp (SSDATA (tem
), "on")
3918 || !strcmp (SSDATA (tem
), "true"))
3919 return make_number (1);
3920 return make_number (atoi (SSDATA (tem
)));
3923 case RES_TYPE_FLOAT
:
3924 return make_float (atof (SSDATA (tem
)));
3926 case RES_TYPE_BOOLEAN
:
3927 tem
= Fdowncase (tem
);
3928 if (!strcmp (SSDATA (tem
), "on")
3930 || !strcmp (SSDATA (tem
), "yes")
3932 || !strcmp (SSDATA (tem
), "true"))
3937 case RES_TYPE_STRING
:
3940 case RES_TYPE_SYMBOL
:
3941 /* As a special case, we map the values `true' and `on'
3942 to Qt, and `false' and `off' to Qnil. */
3945 lower
= Fdowncase (tem
);
3946 if (!strcmp (SSDATA (lower
), "on")
3948 || !strcmp (SSDATA (lower
), "yes")
3950 || !strcmp (SSDATA (lower
), "true"))
3952 else if (!strcmp (SSDATA (lower
), "off")
3954 || !strcmp (SSDATA (lower
), "no")
3956 || !strcmp (SSDATA (lower
), "false"))
3959 return Fintern (tem
, Qnil
);
3973 x_frame_get_arg (struct frame
*f
, Lisp_Object alist
, Lisp_Object param
,
3974 const char *attribute
, const char *class,
3975 enum resource_types type
)
3977 return x_get_arg (FRAME_DISPLAY_INFO (f
),
3978 alist
, param
, attribute
, class, type
);
3981 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3984 x_frame_get_and_record_arg (struct frame
*f
, Lisp_Object alist
,
3986 const char *attribute
, const char *class,
3987 enum resource_types type
)
3991 value
= x_get_arg (FRAME_DISPLAY_INFO (f
), alist
, param
,
3992 attribute
, class, type
);
3993 if (! NILP (value
) && ! EQ (value
, Qunbound
))
3994 store_frame_param (f
, param
, value
);
4000 /* Record in frame F the specified or default value according to ALIST
4001 of the parameter named PROP (a Lisp symbol).
4002 If no value is specified for PROP, look for an X default for XPROP
4003 on the frame named NAME.
4004 If that is not found either, use the value DEFLT. */
4007 x_default_parameter (struct frame
*f
, Lisp_Object alist
, Lisp_Object prop
,
4008 Lisp_Object deflt
, const char *xprop
, const char *xclass
,
4009 enum resource_types type
)
4013 tem
= x_frame_get_arg (f
, alist
, prop
, xprop
, xclass
, type
);
4014 if (EQ (tem
, Qunbound
))
4016 x_set_frame_parameters (f
, list1 (Fcons (prop
, tem
)));
4021 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4024 * XParseGeometry parses strings of the form
4025 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4026 * width, height, xoffset, and yoffset are unsigned integers.
4027 * Example: "=80x24+300-49"
4028 * The equal sign is optional.
4029 * It returns a bitmask that indicates which of the four values
4030 * were actually found in the string. For each value found,
4031 * the corresponding argument is updated; for each value
4032 * not found, the corresponding argument is left unchanged.
4036 XParseGeometry (char *string
,
4038 unsigned int *width
, unsigned int *height
)
4042 unsigned long tempWidth
, tempHeight
;
4043 long int tempX
, tempY
;
4044 char *nextCharacter
;
4046 if (string
== NULL
|| *string
== '\0')
4049 string
++; /* ignore possible '=' at beg of geometry spec */
4052 if (*strind
!= '+' && *strind
!= '-' && *strind
!= 'x')
4054 tempWidth
= strtoul (strind
, &nextCharacter
, 10);
4055 if (strind
== nextCharacter
)
4057 strind
= nextCharacter
;
4061 if (*strind
== 'x' || *strind
== 'X')
4064 tempHeight
= strtoul (strind
, &nextCharacter
, 10);
4065 if (strind
== nextCharacter
)
4067 strind
= nextCharacter
;
4068 mask
|= HeightValue
;
4071 if (*strind
== '+' || *strind
== '-')
4075 tempX
= strtol (strind
, &nextCharacter
, 10);
4076 if (strind
== nextCharacter
)
4078 strind
= nextCharacter
;
4080 if (*strind
== '+' || *strind
== '-')
4084 tempY
= strtol (strind
, &nextCharacter
, 10);
4085 if (strind
== nextCharacter
)
4087 strind
= nextCharacter
;
4092 /* If strind isn't at the end of the string then it's an invalid
4093 geometry specification. */
4095 if (*strind
!= '\0')
4099 *x
= clip_to_bounds (INT_MIN
, tempX
, INT_MAX
);
4101 *y
= clip_to_bounds (INT_MIN
, tempY
, INT_MAX
);
4102 if (mask
& WidthValue
)
4103 *width
= min (tempWidth
, UINT_MAX
);
4104 if (mask
& HeightValue
)
4105 *height
= min (tempHeight
, UINT_MAX
);
4109 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4112 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4113 make-docfile: the documentation string in ns-win.el was used for
4114 x-parse-geometry even in non-NS builds.
4116 With two definitions of x-parse-geometry in this file, various
4117 things still get confused (eg M-x apropos documentation), so that
4118 it is best if the two definitions just share the same doc-string.
4120 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
4121 doc
: /* Parse a display geometry string STRING.
4122 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4123 The properties returned may include `top', `left', `height', and `width'.
4124 For X, the value of `left' or `top' may be an integer,
4125 or a list (+ N) meaning N pixels relative to top/left corner,
4126 or a list (- N) meaning -N pixels relative to bottom/right corner.
4127 On Nextstep, this just calls `ns-parse-geometry'. */)
4128 (Lisp_Object string
)
4131 unsigned int width
, height
;
4134 CHECK_STRING (string
);
4137 if (strchr (SSDATA (string
), ' ') != NULL
)
4138 return call1 (Qns_parse_geometry
, string
);
4140 geometry
= XParseGeometry (SSDATA (string
),
4141 &x
, &y
, &width
, &height
);
4143 if (geometry
& XValue
)
4145 Lisp_Object element
;
4147 if (x
>= 0 && (geometry
& XNegative
))
4148 element
= list3 (Qleft
, Qminus
, make_number (-x
));
4149 else if (x
< 0 && ! (geometry
& XNegative
))
4150 element
= list3 (Qleft
, Qplus
, make_number (x
));
4152 element
= Fcons (Qleft
, make_number (x
));
4153 result
= Fcons (element
, result
);
4156 if (geometry
& YValue
)
4158 Lisp_Object element
;
4160 if (y
>= 0 && (geometry
& YNegative
))
4161 element
= list3 (Qtop
, Qminus
, make_number (-y
));
4162 else if (y
< 0 && ! (geometry
& YNegative
))
4163 element
= list3 (Qtop
, Qplus
, make_number (y
));
4165 element
= Fcons (Qtop
, make_number (y
));
4166 result
= Fcons (element
, result
);
4169 if (geometry
& WidthValue
)
4170 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
4171 if (geometry
& HeightValue
)
4172 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
4178 /* Calculate the desired size and position of frame F.
4179 Return the flags saying which aspects were specified.
4181 Also set the win_gravity and size_hint_flags of F.
4183 Adjust height for toolbar if TOOLBAR_P is 1.
4185 This function does not make the coordinates positive. */
4187 #define DEFAULT_ROWS 35
4188 #define DEFAULT_COLS 80
4191 x_figure_window_size (struct frame
*f
, Lisp_Object parms
, bool toolbar_p
)
4193 register Lisp_Object tem0
, tem1
, tem2
;
4194 long window_prompting
= 0;
4195 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4197 /* Default values if we fall through.
4198 Actually, if that happens we should get
4199 window manager prompting. */
4200 SET_FRAME_WIDTH (f
, DEFAULT_COLS
* FRAME_COLUMN_WIDTH (f
));
4201 SET_FRAME_COLS (f
, DEFAULT_COLS
);
4202 SET_FRAME_HEIGHT (f
, DEFAULT_ROWS
* FRAME_LINE_HEIGHT (f
));
4203 FRAME_LINES (f
) = DEFAULT_ROWS
;
4205 /* Window managers expect that if program-specified
4206 positions are not (0,0), they're intentional, not defaults. */
4210 /* Ensure that old new_width and new_height will not override the
4212 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4213 f
->new_width
= f
->new_height
= f
->new_pixelwise
= 0;
4215 tem0
= x_get_arg (dpyinfo
, parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
4216 tem1
= x_get_arg (dpyinfo
, parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
4217 tem2
= x_get_arg (dpyinfo
, parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
4218 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
4220 if (!EQ (tem0
, Qunbound
))
4222 CHECK_NUMBER (tem0
);
4223 if (! (0 <= XINT (tem0
) && XINT (tem0
) <= INT_MAX
))
4224 xsignal1 (Qargs_out_of_range
, tem0
);
4225 FRAME_LINES (f
) = XINT (tem0
);
4227 if (!EQ (tem1
, Qunbound
))
4229 CHECK_NUMBER (tem1
);
4230 if (! (0 <= XINT (tem1
) && XINT (tem1
) <= INT_MAX
))
4231 xsignal1 (Qargs_out_of_range
, tem1
);
4232 SET_FRAME_COLS (f
, XINT (tem1
));
4234 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
4235 window_prompting
|= USSize
;
4237 window_prompting
|= PSize
;
4241 /* This used to be done _before_ calling x_figure_window_size, but
4242 since the height is reset here, this was really a no-op. I
4243 assume that moving it here does what Gerd intended (although he
4244 no longer can remember what that was... ++KFS, 2003-03-25. */
4246 /* Add the tool-bar height to the initial frame height so that the
4247 user gets a text display area of the size he specified with -g or
4248 via .Xdefaults. Later changes of the tool-bar height don't
4249 change the frame size. This is done so that users can create
4250 tall Emacs frames without having to guess how tall the tool-bar
4252 if (toolbar_p
&& FRAME_TOOL_BAR_HEIGHT (f
))
4254 int margin
, relief
, bar_height
;
4256 relief
= (tool_bar_button_relief
>= 0
4257 ? tool_bar_button_relief
4258 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
4260 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
, INT_MAX
))
4261 margin
= XFASTINT (Vtool_bar_button_margin
);
4262 else if (CONSP (Vtool_bar_button_margin
)
4263 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
), INT_MAX
))
4264 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
4268 /* PXW: We should be able to not round here. */
4269 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
4270 FRAME_LINES (f
) += (bar_height
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
4273 compute_fringe_widths (f
, 0);
4275 SET_FRAME_WIDTH (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
4276 SET_FRAME_HEIGHT(f
, FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
));
4278 tem0
= x_get_arg (dpyinfo
, parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
4279 tem1
= x_get_arg (dpyinfo
, parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
4280 tem2
= x_get_arg (dpyinfo
, parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
4281 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
4283 if (EQ (tem0
, Qminus
))
4286 window_prompting
|= YNegative
;
4288 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
4289 && CONSP (XCDR (tem0
))
4290 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (tem0
)), INT_MAX
))
4292 f
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
4293 window_prompting
|= YNegative
;
4295 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
4296 && CONSP (XCDR (tem0
))
4297 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0
))))
4299 f
->top_pos
= XINT (XCAR (XCDR (tem0
)));
4301 else if (EQ (tem0
, Qunbound
))
4305 CHECK_TYPE_RANGED_INTEGER (int, tem0
);
4306 f
->top_pos
= XINT (tem0
);
4308 window_prompting
|= YNegative
;
4311 if (EQ (tem1
, Qminus
))
4314 window_prompting
|= XNegative
;
4316 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
4317 && CONSP (XCDR (tem1
))
4318 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (tem1
)), INT_MAX
))
4320 f
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
4321 window_prompting
|= XNegative
;
4323 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
4324 && CONSP (XCDR (tem1
))
4325 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1
))))
4327 f
->left_pos
= XINT (XCAR (XCDR (tem1
)));
4329 else if (EQ (tem1
, Qunbound
))
4333 CHECK_TYPE_RANGED_INTEGER (int, tem1
);
4334 f
->left_pos
= XINT (tem1
);
4335 if (f
->left_pos
< 0)
4336 window_prompting
|= XNegative
;
4339 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
4340 window_prompting
|= USPosition
;
4342 window_prompting
|= PPosition
;
4345 if (window_prompting
& XNegative
)
4347 if (window_prompting
& YNegative
)
4348 f
->win_gravity
= SouthEastGravity
;
4350 f
->win_gravity
= NorthEastGravity
;
4354 if (window_prompting
& YNegative
)
4355 f
->win_gravity
= SouthWestGravity
;
4357 f
->win_gravity
= NorthWestGravity
;
4360 f
->size_hint_flags
= window_prompting
;
4362 return window_prompting
;
4367 #endif /* HAVE_WINDOW_SYSTEM */
4370 frame_make_pointer_invisible (struct frame
*f
)
4372 if (! NILP (Vmake_pointer_invisible
))
4374 if (f
&& FRAME_LIVE_P (f
) && !f
->pointer_invisible
4375 && FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook
)
4378 FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook (f
, 1);
4379 f
->pointer_invisible
= 1;
4385 frame_make_pointer_visible (struct frame
*f
)
4387 /* We don't check Vmake_pointer_invisible here in case the
4388 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4389 if (f
&& FRAME_LIVE_P (f
) && f
->pointer_invisible
&& f
->mouse_moved
4390 && FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook
)
4392 FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook (f
, 0);
4393 f
->pointer_invisible
= 0;
4397 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p
,
4398 Sframe_pointer_visible_p
, 0, 1, 0,
4399 doc
: /* Return t if the mouse pointer displayed on FRAME is visible.
4400 Otherwise it returns nil. FRAME omitted or nil means the
4401 selected frame. This is useful when `make-pointer-invisible' is set. */)
4404 return decode_any_frame (frame
)->pointer_invisible
? Qnil
: Qt
;
4409 /***********************************************************************
4411 ***********************************************************************/
4413 #ifdef HAVE_WINDOW_SYSTEM
4415 # if (defined HAVE_NS \
4416 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4418 free_monitors (struct MonitorInfo
*monitors
, int n_monitors
)
4421 for (i
= 0; i
< n_monitors
; ++i
)
4422 xfree (monitors
[i
].name
);
4428 make_monitor_attribute_list (struct MonitorInfo
*monitors
,
4430 int primary_monitor
,
4431 Lisp_Object monitor_frames
,
4434 Lisp_Object attributes_list
= Qnil
;
4435 Lisp_Object primary_monitor_attributes
= Qnil
;
4438 for (i
= 0; i
< n_monitors
; ++i
)
4440 Lisp_Object geometry
, workarea
, attributes
= Qnil
;
4441 struct MonitorInfo
*mi
= &monitors
[i
];
4443 if (mi
->geom
.width
== 0) continue;
4445 workarea
= list4i (mi
->work
.x
, mi
->work
.y
,
4446 mi
->work
.width
, mi
->work
.height
);
4447 geometry
= list4i (mi
->geom
.x
, mi
->geom
.y
,
4448 mi
->geom
.width
, mi
->geom
.height
);
4449 attributes
= Fcons (Fcons (Qsource
, build_string (source
)),
4451 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
4453 attributes
= Fcons (Fcons (Qmm_size
,
4454 list2i (mi
->mm_width
, mi
->mm_height
)),
4456 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
4457 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
4459 attributes
= Fcons (Fcons (Qname
, make_string (mi
->name
,
4460 strlen (mi
->name
))),
4463 if (i
== primary_monitor
)
4464 primary_monitor_attributes
= attributes
;
4466 attributes_list
= Fcons (attributes
, attributes_list
);
4469 if (!NILP (primary_monitor_attributes
))
4470 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
4471 return attributes_list
;
4474 #endif /* HAVE_WINDOW_SYSTEM */
4477 /***********************************************************************
4479 ***********************************************************************/
4482 syms_of_frame (void)
4484 DEFSYM (Qframep
, "framep");
4485 DEFSYM (Qframe_live_p
, "frame-live-p");
4486 DEFSYM (Qexplicit_name
, "explicit-name");
4487 DEFSYM (Qheight
, "height");
4488 DEFSYM (Qicon
, "icon");
4489 DEFSYM (Qminibuffer
, "minibuffer");
4490 DEFSYM (Qmodeline
, "modeline");
4491 DEFSYM (Qonly
, "only");
4492 DEFSYM (Qnone
, "none");
4493 DEFSYM (Qwidth
, "width");
4494 DEFSYM (Qgeometry
, "geometry");
4495 DEFSYM (Qicon_left
, "icon-left");
4496 DEFSYM (Qicon_top
, "icon-top");
4497 DEFSYM (Qtooltip
, "tooltip");
4498 DEFSYM (Quser_position
, "user-position");
4499 DEFSYM (Quser_size
, "user-size");
4500 DEFSYM (Qwindow_id
, "window-id");
4501 #ifdef HAVE_X_WINDOWS
4502 DEFSYM (Qouter_window_id
, "outer-window-id");
4504 DEFSYM (Qparent_id
, "parent-id");
4506 DEFSYM (Qw32
, "w32");
4509 DEFSYM (Qvisible
, "visible");
4510 DEFSYM (Qbuffer_predicate
, "buffer-predicate");
4511 DEFSYM (Qbuffer_list
, "buffer-list");
4512 DEFSYM (Qburied_buffer_list
, "buried-buffer-list");
4513 DEFSYM (Qdisplay_type
, "display-type");
4514 DEFSYM (Qbackground_mode
, "background-mode");
4515 DEFSYM (Qnoelisp
, "noelisp");
4516 DEFSYM (Qtty_color_mode
, "tty-color-mode");
4517 DEFSYM (Qtty
, "tty");
4518 DEFSYM (Qtty_type
, "tty-type");
4520 DEFSYM (Qface_set_after_frame_default
, "face-set-after-frame-default");
4522 DEFSYM (Qfullwidth
, "fullwidth");
4523 DEFSYM (Qfullheight
, "fullheight");
4524 DEFSYM (Qfullboth
, "fullboth");
4525 DEFSYM (Qmaximized
, "maximized");
4526 DEFSYM (Qx_resource_name
, "x-resource-name");
4527 DEFSYM (Qx_frame_parameter
, "x-frame-parameter");
4529 DEFSYM (Qterminal
, "terminal");
4531 DEFSYM (Qgeometry
, "geometry");
4532 DEFSYM (Qworkarea
, "workarea");
4533 DEFSYM (Qmm_size
, "mm-size");
4534 DEFSYM (Qframes
, "frames");
4535 DEFSYM (Qsource
, "source");
4538 DEFSYM (Qns_parse_geometry
, "ns-parse-geometry");
4544 for (i
= 0; i
< ARRAYELTS (frame_parms
); i
++)
4546 Lisp_Object v
= intern_c_string (frame_parms
[i
].name
);
4547 if (frame_parms
[i
].variable
)
4549 *frame_parms
[i
].variable
= v
;
4550 staticpro (frame_parms
[i
].variable
);
4552 Fput (v
, Qx_frame_parameter
, make_number (i
));
4556 #ifdef HAVE_WINDOW_SYSTEM
4557 DEFVAR_LISP ("x-resource-name", Vx_resource_name
,
4558 doc
: /* The name Emacs uses to look up X resources.
4559 `x-get-resource' uses this as the first component of the instance name
4560 when requesting resource values.
4561 Emacs initially sets `x-resource-name' to the name under which Emacs
4562 was invoked, or to the value specified with the `-name' or `-rn'
4563 switches, if present.
4565 It may be useful to bind this variable locally around a call
4566 to `x-get-resource'. See also the variable `x-resource-class'. */);
4567 Vx_resource_name
= Qnil
;
4569 DEFVAR_LISP ("x-resource-class", Vx_resource_class
,
4570 doc
: /* The class Emacs uses to look up X resources.
4571 `x-get-resource' uses this as the first component of the instance class
4572 when requesting resource values.
4574 Emacs initially sets `x-resource-class' to "Emacs".
4576 Setting this variable permanently is not a reasonable thing to do,
4577 but binding this variable locally around a call to `x-get-resource'
4578 is a reasonable practice. See also the variable `x-resource-name'. */);
4579 Vx_resource_class
= build_string (EMACS_CLASS
);
4581 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit
,
4582 doc
: /* The lower limit of the frame opacity (alpha transparency).
4583 The value should range from 0 (invisible) to 100 (completely opaque).
4584 You can also use a floating number between 0.0 and 1.0. */);
4585 Vframe_alpha_lower_limit
= make_number (20);
4588 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist
,
4589 doc
: /* Alist of default values for frame creation.
4590 These may be set in your init file, like this:
4591 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4592 These override values given in window system configuration data,
4593 including X Windows' defaults database.
4594 For values specific to the first Emacs frame, see `initial-frame-alist'.
4595 For window-system specific values, see `window-system-default-frame-alist'.
4596 For values specific to the separate minibuffer frame, see
4597 `minibuffer-frame-alist'.
4598 The `menu-bar-lines' element of the list controls whether new frames
4599 have menu bars; `menu-bar-mode' works by altering this element.
4600 Setting this variable does not affect existing frames, only new ones. */);
4601 Vdefault_frame_alist
= Qnil
;
4603 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars
,
4604 doc
: /* Default position of scroll bars on this window-system. */);
4605 #ifdef HAVE_WINDOW_SYSTEM
4606 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4607 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4609 Vdefault_frame_scroll_bars
= Qright
;
4611 Vdefault_frame_scroll_bars
= Qleft
;
4614 Vdefault_frame_scroll_bars
= Qnil
;
4617 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4618 scroll_bar_adjust_thumb_portion_p
,
4619 doc
: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4620 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4621 even if the end of the buffer is shown (i.e. overscrolling).
4622 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4623 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4624 is visible. In this case you can not overscroll. */);
4625 scroll_bar_adjust_thumb_portion_p
= 1;
4627 DEFVAR_LISP ("terminal-frame", Vterminal_frame
,
4628 doc
: /* The initial frame-object, which represents Emacs's stdout. */);
4630 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function
,
4631 doc
: /* If non-nil, function to transform normal value of `mouse-position'.
4632 `mouse-position' calls this function, passing its usual return value as
4633 argument, and returns whatever this function returns.
4634 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4635 which need to do mouse handling at the Lisp level. */);
4636 Vmouse_position_function
= Qnil
;
4638 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight
,
4639 doc
: /* If non-nil, clickable text is highlighted when mouse is over it.
4640 If the value is an integer, highlighting is only shown after moving the
4641 mouse, while keyboard input turns off the highlight even when the mouse
4642 is over the clickable text. However, the mouse shape still indicates
4643 when the mouse is over clickable text. */);
4644 Vmouse_highlight
= Qt
;
4646 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible
,
4647 doc
: /* If non-nil, make pointer invisible while typing.
4648 The pointer becomes visible again when the mouse is moved. */);
4649 Vmake_pointer_invisible
= Qt
;
4651 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook
,
4652 doc
: /* Normal hook run when a frame gains input focus. */);
4653 Vfocus_in_hook
= Qnil
;
4654 DEFSYM (Qfocus_in_hook
, "focus-in-hook");
4656 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook
,
4657 doc
: /* Normal hook run when a frame loses input focus. */);
4658 Vfocus_out_hook
= Qnil
;
4659 DEFSYM (Qfocus_out_hook
, "focus-out-hook");
4661 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions
,
4662 doc
: /* Functions run before deleting a frame.
4663 The functions are run with one arg, the frame to be deleted.
4666 Note that functions in this list may be called just before the frame is
4667 actually deleted, or some time later (or even both when an earlier function
4668 in `delete-frame-functions' (indirectly) calls `delete-frame'
4670 Vdelete_frame_functions
= Qnil
;
4671 DEFSYM (Qdelete_frame_functions
, "delete-frame-functions");
4673 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode
,
4674 doc
: /* Non-nil if Menu-Bar mode is enabled.
4675 See the command `menu-bar-mode' for a description of this minor mode.
4676 Setting this variable directly does not take effect;
4677 either customize it (see the info node `Easy Customization')
4678 or call the function `menu-bar-mode'. */);
4679 Vmenu_bar_mode
= Qt
;
4681 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode
,
4682 doc
: /* Non-nil if Tool-Bar mode is enabled.
4683 See the command `tool-bar-mode' for a description of this minor mode.
4684 Setting this variable directly does not take effect;
4685 either customize it (see the info node `Easy Customization')
4686 or call the function `tool-bar-mode'. */);
4687 #ifdef HAVE_WINDOW_SYSTEM
4688 Vtool_bar_mode
= Qt
;
4690 Vtool_bar_mode
= Qnil
;
4693 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame
,
4694 doc
: /* Minibufferless frames use this frame's minibuffer.
4695 Emacs cannot create minibufferless frames unless this is set to an
4696 appropriate surrogate.
4698 Emacs consults this variable only when creating minibufferless
4699 frames; once the frame is created, it sticks with its assigned
4700 minibuffer, no matter what this variable is set to. This means that
4701 this variable doesn't necessarily say anything meaningful about the
4702 current set of frames, or where the minibuffer is currently being
4705 This variable is local to the current terminal and cannot be buffer-local. */);
4707 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse
,
4708 doc
: /* Non-nil if window system changes focus when you move the mouse.
4709 You should set this variable to tell Emacs how your window manager
4710 handles focus, since there is no way in general for Emacs to find out
4711 automatically. See also `mouse-autoselect-window'. */);
4712 focus_follows_mouse
= 0;
4714 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise
,
4715 doc
: /* Non-nil means resize frames pixelwise.
4716 If this option is nil, resizing a frame rounds its sizes to the frame's
4717 current values of `frame-char-height' and `frame-char-width'. If this
4718 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4721 With some window managers you have to set this to non-nil in order to
4722 fully maximize frames. To resize your initial frame pixelwise,
4723 set this option to a non-nil value in your init file. */);
4724 frame_resize_pixelwise
= 0;
4726 staticpro (&Vframe_list
);
4729 defsubr (&Sframe_live_p
);
4730 defsubr (&Swindow_system
);
4731 defsubr (&Smake_terminal_frame
);
4732 defsubr (&Shandle_switch_frame
);
4733 defsubr (&Sselect_frame
);
4734 defsubr (&Sselected_frame
);
4735 defsubr (&Sframe_list
);
4736 defsubr (&Snext_frame
);
4737 defsubr (&Sprevious_frame
);
4738 defsubr (&Slast_nonminibuf_frame
);
4739 defsubr (&Sdelete_frame
);
4740 defsubr (&Smouse_position
);
4741 defsubr (&Smouse_pixel_position
);
4742 defsubr (&Sset_mouse_position
);
4743 defsubr (&Sset_mouse_pixel_position
);
4745 defsubr (&Sframe_configuration
);
4746 defsubr (&Srestore_frame_configuration
);
4748 defsubr (&Smake_frame_visible
);
4749 defsubr (&Smake_frame_invisible
);
4750 defsubr (&Siconify_frame
);
4751 defsubr (&Sframe_visible_p
);
4752 defsubr (&Svisible_frame_list
);
4753 defsubr (&Sraise_frame
);
4754 defsubr (&Slower_frame
);
4755 defsubr (&Sx_focus_frame
);
4756 defsubr (&Sredirect_frame_focus
);
4757 defsubr (&Sframe_focus
);
4758 defsubr (&Sframe_parameters
);
4759 defsubr (&Sframe_parameter
);
4760 defsubr (&Smodify_frame_parameters
);
4761 defsubr (&Sframe_char_height
);
4762 defsubr (&Sframe_char_width
);
4763 defsubr (&Sframe_pixel_height
);
4764 defsubr (&Sframe_pixel_width
);
4765 defsubr (&Sframe_text_cols
);
4766 defsubr (&Sframe_text_lines
);
4767 defsubr (&Sframe_total_cols
);
4768 defsubr (&Sframe_text_width
);
4769 defsubr (&Sframe_text_height
);
4770 defsubr (&Sscroll_bar_width
);
4771 defsubr (&Sfringe_width
);
4772 defsubr (&Sborder_width
);
4773 defsubr (&Sright_divider_width
);
4774 defsubr (&Sbottom_divider_width
);
4775 defsubr (&Stool_bar_pixel_width
);
4776 defsubr (&Sset_frame_height
);
4777 defsubr (&Sset_frame_width
);
4778 defsubr (&Sset_frame_size
);
4779 defsubr (&Sset_frame_position
);
4780 defsubr (&Sframe_pointer_visible_p
);
4782 #ifdef HAVE_WINDOW_SYSTEM
4783 defsubr (&Sx_get_resource
);
4784 defsubr (&Sx_parse_geometry
);