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
))
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 DEFUN ("set-frame-height", Fset_frame_height
, Sset_frame_height
, 2, 4, 0,
2570 doc
: /* Specify that the frame FRAME has HEIGHT text lines.
2571 Optional third arg PRETEND non-nil means that redisplay should use
2572 HEIGHT lines but that the idea of the actual height of the frame should
2573 not be changed. Optional fourth argument PIXELWISE non-nil means that
2574 FRAME should be HEIGHT pixels high. */)
2575 (Lisp_Object frame
, Lisp_Object height
, Lisp_Object pretend
, Lisp_Object pixelwise
)
2577 register struct frame
*f
= decode_live_frame (frame
);
2579 CHECK_TYPE_RANGED_INTEGER (int, height
);
2581 /* I think this should be done with a hook. */
2582 #ifdef HAVE_WINDOW_SYSTEM
2583 if (FRAME_WINDOW_P (f
))
2585 if (NILP (pixelwise
))
2587 if (XINT (height
) != FRAME_LINES (f
))
2588 x_set_window_size (f
, 1, FRAME_COLS (f
), XINT (height
), 0);
2590 do_pending_window_change (0);
2592 else if (XINT (height
) != FRAME_TEXT_HEIGHT (f
))
2594 x_set_window_size (f
, 1, FRAME_TEXT_WIDTH (f
), XINT (height
), 1);
2595 do_pending_window_change (0);
2600 change_frame_size (f
, 0, XINT (height
), !NILP (pretend
), 0, 0,
2601 NILP (pixelwise
) ? 0 : 1);
2605 DEFUN ("set-frame-width", Fset_frame_width
, Sset_frame_width
, 2, 4, 0,
2606 doc
: /* Specify that the frame FRAME has WIDTH columns.
2607 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2608 columns but that the idea of the actual width of the frame should not
2609 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2610 should be WIDTH pixels wide. */)
2611 (Lisp_Object frame
, Lisp_Object width
, Lisp_Object pretend
, Lisp_Object pixelwise
)
2613 register struct frame
*f
= decode_live_frame (frame
);
2615 CHECK_TYPE_RANGED_INTEGER (int, width
);
2617 /* I think this should be done with a hook. */
2618 #ifdef HAVE_WINDOW_SYSTEM
2619 if (FRAME_WINDOW_P (f
))
2621 if (NILP (pixelwise
))
2623 if (XINT (width
) != FRAME_COLS (f
))
2624 x_set_window_size (f
, 1, XINT (width
), FRAME_LINES (f
), 0);
2626 do_pending_window_change (0);
2628 else if (XINT (width
) != FRAME_TEXT_WIDTH (f
))
2630 x_set_window_size (f
, 1, XINT (width
), FRAME_TEXT_HEIGHT (f
), 1);
2631 do_pending_window_change (0);
2636 change_frame_size (f
, XINT (width
), 0, !NILP (pretend
), 0, 0,
2637 NILP (pixelwise
) ? 0 : 1);
2641 DEFUN ("set-frame-size", Fset_frame_size
, Sset_frame_size
, 3, 4, 0,
2642 doc
: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2643 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2644 (Lisp_Object frame
, Lisp_Object width
, Lisp_Object height
, Lisp_Object pixelwise
)
2646 register struct frame
*f
= decode_live_frame (frame
);
2648 CHECK_TYPE_RANGED_INTEGER (int, width
);
2649 CHECK_TYPE_RANGED_INTEGER (int, height
);
2651 /* I think this should be done with a hook. */
2652 #ifdef HAVE_WINDOW_SYSTEM
2653 if (FRAME_WINDOW_P (f
))
2655 if (!NILP (pixelwise
)
2656 ? (XINT (width
) != FRAME_TEXT_WIDTH (f
)
2657 || XINT (height
) != FRAME_TEXT_HEIGHT (f
)
2658 || f
->new_height
|| f
->new_width
)
2659 : (XINT (width
) != FRAME_COLS (f
)
2660 || XINT (height
) != FRAME_LINES (f
)
2661 || f
->new_height
|| f
->new_width
))
2663 x_set_window_size (f
, 1, XINT (width
), XINT (height
),
2664 NILP (pixelwise
) ? 0 : 1);
2665 do_pending_window_change (0);
2670 change_frame_size (f
, XINT (width
), XINT (height
), 0, 0, 0,
2671 NILP (pixelwise
) ? 0 : 1);
2676 DEFUN ("set-frame-position", Fset_frame_position
,
2677 Sset_frame_position
, 3, 3, 0,
2678 doc
: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2679 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2680 actually the position of the upper left corner of the frame. Negative
2681 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2682 or bottommost possible position (that stays within the screen). */)
2683 (Lisp_Object frame
, Lisp_Object xoffset
, Lisp_Object yoffset
)
2685 register struct frame
*f
= decode_live_frame (frame
);
2687 CHECK_TYPE_RANGED_INTEGER (int, xoffset
);
2688 CHECK_TYPE_RANGED_INTEGER (int, yoffset
);
2690 /* I think this should be done with a hook. */
2691 #ifdef HAVE_WINDOW_SYSTEM
2692 if (FRAME_WINDOW_P (f
))
2693 x_set_offset (f
, XINT (xoffset
), XINT (yoffset
), 1);
2700 /***********************************************************************
2702 ***********************************************************************/
2704 /* Connect the frame-parameter names for X frames
2705 to the ways of passing the parameter values to the window system.
2707 The name of a parameter, as a Lisp symbol,
2708 has an `x-frame-parameter' property which is an integer in Lisp
2709 that is an index in this table. */
2711 struct frame_parm_table
{
2713 Lisp_Object
*variable
;
2716 static const struct frame_parm_table frame_parms
[] =
2718 {"auto-raise", &Qauto_raise
},
2719 {"auto-lower", &Qauto_lower
},
2720 {"background-color", 0},
2721 {"border-color", &Qborder_color
},
2722 {"border-width", &Qborder_width
},
2723 {"cursor-color", &Qcursor_color
},
2724 {"cursor-type", &Qcursor_type
},
2726 {"foreground-color", 0},
2727 {"icon-name", &Qicon_name
},
2728 {"icon-type", &Qicon_type
},
2729 {"internal-border-width", &Qinternal_border_width
},
2730 {"right-divider-width", &Qright_divider_width
},
2731 {"bottom-divider-width", &Qbottom_divider_width
},
2732 {"menu-bar-lines", &Qmenu_bar_lines
},
2733 {"mouse-color", &Qmouse_color
},
2735 {"scroll-bar-width", &Qscroll_bar_width
},
2737 {"unsplittable", &Qunsplittable
},
2738 {"vertical-scroll-bars", &Qvertical_scroll_bars
},
2739 {"visibility", &Qvisibility
},
2740 {"tool-bar-lines", &Qtool_bar_lines
},
2741 {"scroll-bar-foreground", &Qscroll_bar_foreground
},
2742 {"scroll-bar-background", &Qscroll_bar_background
},
2743 {"screen-gamma", &Qscreen_gamma
},
2744 {"line-spacing", &Qline_spacing
},
2745 {"left-fringe", &Qleft_fringe
},
2746 {"right-fringe", &Qright_fringe
},
2747 {"wait-for-wm", &Qwait_for_wm
},
2748 {"fullscreen", &Qfullscreen
},
2749 {"font-backend", &Qfont_backend
},
2751 {"sticky", &Qsticky
},
2752 {"tool-bar-position", &Qtool_bar_position
},
2755 #ifdef HAVE_WINDOW_SYSTEM
2757 /* Change the parameters of frame F as specified by ALIST.
2758 If a parameter is not specially recognized, do nothing special;
2759 otherwise call the `x_set_...' function for that parameter.
2760 Except for certain geometry properties, always call store_frame_param
2761 to store the new value in the parameter alist. */
2764 x_set_frame_parameters (struct frame
*f
, Lisp_Object alist
)
2768 /* If both of these parameters are present, it's more efficient to
2769 set them both at once. So we wait until we've looked at the
2770 entire list before we set them. */
2771 int width
= 0, height
= 0;
2772 bool width_change
= 0, height_change
= 0;
2775 Lisp_Object left
, top
;
2777 /* Same with these. */
2778 Lisp_Object icon_left
, icon_top
;
2780 /* Record in these vectors all the parms specified. */
2782 Lisp_Object
*values
;
2784 bool left_no_change
= 0, top_no_change
= 0;
2785 #ifdef HAVE_X_WINDOWS
2786 bool icon_left_no_change
= 0, icon_top_no_change
= 0;
2788 struct gcpro gcpro1
, gcpro2
;
2791 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
2794 parms
= alloca (i
* sizeof *parms
);
2795 values
= alloca (i
* sizeof *values
);
2797 /* Extract parm names and values into those vectors. */
2800 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
2805 parms
[i
] = Fcar (elt
);
2806 values
[i
] = Fcdr (elt
);
2809 /* TAIL and ALIST are not used again below here. */
2810 alist
= tail
= Qnil
;
2812 GCPRO2 (*parms
, *values
);
2816 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2817 because their values appear in VALUES and strings are not valid. */
2818 top
= left
= Qunbound
;
2819 icon_left
= icon_top
= Qunbound
;
2821 /* Process foreground_color and background_color before anything else.
2822 They are independent of other properties, but other properties (e.g.,
2823 cursor_color) are dependent upon them. */
2824 /* Process default font as well, since fringe widths depends on it. */
2825 for (p
= 0; p
< i
; p
++)
2827 Lisp_Object prop
, val
;
2831 if (EQ (prop
, Qforeground_color
)
2832 || EQ (prop
, Qbackground_color
)
2833 || EQ (prop
, Qfont
))
2835 register Lisp_Object param_index
, old_value
;
2837 old_value
= get_frame_param (f
, prop
);
2838 if (NILP (Fequal (val
, old_value
)))
2840 store_frame_param (f
, prop
, val
);
2842 param_index
= Fget (prop
, Qx_frame_parameter
);
2843 if (NATNUMP (param_index
)
2844 && XFASTINT (param_index
) < ARRAYELTS (frame_parms
)
2845 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
2846 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
2851 /* Now process them in reverse of specified order. */
2854 Lisp_Object prop
, val
;
2859 if (EQ (prop
, Qwidth
) && RANGED_INTEGERP (0, val
, INT_MAX
))
2862 width
= XFASTINT (val
) * FRAME_COLUMN_WIDTH (f
) ;
2864 else if (EQ (prop
, Qheight
) && RANGED_INTEGERP (0, val
, INT_MAX
))
2867 height
= XFASTINT (val
) * FRAME_LINE_HEIGHT (f
);
2869 else if (EQ (prop
, Qtop
))
2871 else if (EQ (prop
, Qleft
))
2873 else if (EQ (prop
, Qicon_top
))
2875 else if (EQ (prop
, Qicon_left
))
2877 else if (EQ (prop
, Qforeground_color
)
2878 || EQ (prop
, Qbackground_color
)
2879 || EQ (prop
, Qfont
))
2880 /* Processed above. */
2884 register Lisp_Object param_index
, old_value
;
2886 old_value
= get_frame_param (f
, prop
);
2888 store_frame_param (f
, prop
, val
);
2890 param_index
= Fget (prop
, Qx_frame_parameter
);
2891 if (NATNUMP (param_index
)
2892 && XFASTINT (param_index
) < ARRAYELTS (frame_parms
)
2893 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
2894 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
2898 /* Don't die if just one of these was set. */
2899 if (EQ (left
, Qunbound
))
2902 if (f
->left_pos
< 0)
2903 left
= list2 (Qplus
, make_number (f
->left_pos
));
2905 XSETINT (left
, f
->left_pos
);
2907 if (EQ (top
, Qunbound
))
2911 top
= list2 (Qplus
, make_number (f
->top_pos
));
2913 XSETINT (top
, f
->top_pos
);
2916 /* If one of the icon positions was not set, preserve or default it. */
2917 if (! TYPE_RANGED_INTEGERP (int, icon_left
))
2919 #ifdef HAVE_X_WINDOWS
2920 icon_left_no_change
= 1;
2922 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
2923 if (NILP (icon_left
))
2924 XSETINT (icon_left
, 0);
2926 if (! TYPE_RANGED_INTEGERP (int, icon_top
))
2928 #ifdef HAVE_X_WINDOWS
2929 icon_top_no_change
= 1;
2931 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
2932 if (NILP (icon_top
))
2933 XSETINT (icon_top
, 0);
2936 /* Don't set these parameters unless they've been explicitly
2937 specified. The window might be mapped or resized while we're in
2938 this function, and we don't want to override that unless the lisp
2939 code has asked for it.
2941 Don't set these parameters unless they actually differ from the
2942 window's current parameters; the window may not actually exist
2947 /* Make this 1, eventually. */
2948 check_frame_size (f
, &width
, &height
, 1);
2950 XSETFRAME (frame
, f
);
2952 if ((width_change
|| height_change
)
2953 && (width
!= FRAME_TEXT_WIDTH (f
)
2954 || height
!= FRAME_TEXT_HEIGHT (f
)
2955 || f
->new_height
|| f
->new_width
))
2957 /* If necessary provide default values for HEIGHT and WIDTH. Do
2958 that here since otherwise a size change implied by an
2959 intermittent font change may get lost as in Bug#17142. */
2961 width
= (f
->new_width
2964 : (f
->new_width
* FRAME_COLUMN_WIDTH (f
)))
2965 : FRAME_TEXT_WIDTH (f
));
2968 height
= (f
->new_height
2971 : (f
->new_height
* FRAME_LINE_HEIGHT (f
)))
2972 : FRAME_TEXT_HEIGHT (f
));
2974 Fset_frame_size (frame
, make_number (width
), make_number (height
), Qt
);
2977 if ((!NILP (left
) || !NILP (top
))
2978 && ! (left_no_change
&& top_no_change
)
2979 && ! (NUMBERP (left
) && XINT (left
) == f
->left_pos
2980 && NUMBERP (top
) && XINT (top
) == f
->top_pos
))
2985 /* Record the signs. */
2986 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
2987 if (EQ (left
, Qminus
))
2988 f
->size_hint_flags
|= XNegative
;
2989 else if (TYPE_RANGED_INTEGERP (int, left
))
2991 leftpos
= XINT (left
);
2993 f
->size_hint_flags
|= XNegative
;
2995 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
2996 && CONSP (XCDR (left
))
2997 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (left
)), INT_MAX
))
2999 leftpos
= - XINT (XCAR (XCDR (left
)));
3000 f
->size_hint_flags
|= XNegative
;
3002 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
3003 && CONSP (XCDR (left
))
3004 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left
))))
3006 leftpos
= XINT (XCAR (XCDR (left
)));
3009 if (EQ (top
, Qminus
))
3010 f
->size_hint_flags
|= YNegative
;
3011 else if (TYPE_RANGED_INTEGERP (int, top
))
3013 toppos
= XINT (top
);
3015 f
->size_hint_flags
|= YNegative
;
3017 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
3018 && CONSP (XCDR (top
))
3019 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (top
)), INT_MAX
))
3021 toppos
= - XINT (XCAR (XCDR (top
)));
3022 f
->size_hint_flags
|= YNegative
;
3024 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
3025 && CONSP (XCDR (top
))
3026 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top
))))
3028 toppos
= XINT (XCAR (XCDR (top
)));
3032 /* Store the numeric value of the position. */
3033 f
->top_pos
= toppos
;
3034 f
->left_pos
= leftpos
;
3036 f
->win_gravity
= NorthWestGravity
;
3038 /* Actually set that position, and convert to absolute. */
3039 x_set_offset (f
, leftpos
, toppos
, -1);
3041 #ifdef HAVE_X_WINDOWS
3042 if ((!NILP (icon_left
) || !NILP (icon_top
))
3043 && ! (icon_left_no_change
&& icon_top_no_change
))
3044 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
3045 #endif /* HAVE_X_WINDOWS */
3052 /* Insert a description of internally-recorded parameters of frame X
3053 into the parameter alist *ALISTPTR that is to be given to the user.
3054 Only parameters that are specific to the X window system
3055 and whose values are not correctly recorded in the frame's
3056 param_alist need to be considered here. */
3059 x_report_frame_params (struct frame
*f
, Lisp_Object
*alistptr
)
3063 char buf
[INT_BUFSIZE_BOUND (w
)];
3065 /* Represent negative positions (off the top or left screen edge)
3066 in a way that Fmodify_frame_parameters will understand correctly. */
3067 XSETINT (tem
, f
->left_pos
);
3068 if (f
->left_pos
>= 0)
3069 store_in_alist (alistptr
, Qleft
, tem
);
3071 store_in_alist (alistptr
, Qleft
, list2 (Qplus
, tem
));
3073 XSETINT (tem
, f
->top_pos
);
3074 if (f
->top_pos
>= 0)
3075 store_in_alist (alistptr
, Qtop
, tem
);
3077 store_in_alist (alistptr
, Qtop
, list2 (Qplus
, tem
));
3079 store_in_alist (alistptr
, Qborder_width
,
3080 make_number (f
->border_width
));
3081 store_in_alist (alistptr
, Qinternal_border_width
,
3082 make_number (FRAME_INTERNAL_BORDER_WIDTH (f
)));
3083 store_in_alist (alistptr
, Qright_divider_width
,
3084 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f
)));
3085 store_in_alist (alistptr
, Qbottom_divider_width
,
3086 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f
)));
3087 store_in_alist (alistptr
, Qleft_fringe
,
3088 make_number (FRAME_LEFT_FRINGE_WIDTH (f
)));
3089 store_in_alist (alistptr
, Qright_fringe
,
3090 make_number (FRAME_RIGHT_FRINGE_WIDTH (f
)));
3091 store_in_alist (alistptr
, Qscroll_bar_width
,
3092 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3094 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
3095 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3096 /* nil means "use default width"
3097 for non-toolkit scroll bar.
3098 ruler-mode.el depends on this. */
3100 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3101 MS-Windows it returns a value whose type is HANDLE, which is
3102 actually a pointer. Explicit casting avoids compiler
3104 w
= (uintptr_t) FRAME_X_WINDOW (f
);
3105 store_in_alist (alistptr
, Qwindow_id
,
3106 make_formatted_string (buf
, "%"pMu
, w
));
3107 #ifdef HAVE_X_WINDOWS
3108 #ifdef USE_X_TOOLKIT
3109 /* Tooltip frame may not have this widget. */
3110 if (FRAME_X_OUTPUT (f
)->widget
)
3112 w
= (uintptr_t) FRAME_OUTER_WINDOW (f
);
3113 store_in_alist (alistptr
, Qouter_window_id
,
3114 make_formatted_string (buf
, "%"pMu
, w
));
3116 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
3117 store_in_alist (alistptr
, Qvisibility
,
3118 (FRAME_VISIBLE_P (f
) ? Qt
3119 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
3120 store_in_alist (alistptr
, Qdisplay
,
3121 XCAR (FRAME_DISPLAY_INFO (f
)->name_list_element
));
3123 if (FRAME_X_OUTPUT (f
)->parent_desc
== FRAME_DISPLAY_INFO (f
)->root_window
)
3126 tem
= make_natnum ((uintptr_t) FRAME_X_OUTPUT (f
)->parent_desc
);
3127 store_in_alist (alistptr
, Qexplicit_name
, (f
->explicit_name
? Qt
: Qnil
));
3128 store_in_alist (alistptr
, Qparent_id
, tem
);
3129 store_in_alist (alistptr
, Qtool_bar_position
, FRAME_TOOL_BAR_POSITION (f
));
3133 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3134 the previous value of that parameter, NEW_VALUE is the new value. */
3137 x_set_fullscreen (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3139 if (NILP (new_value
))
3140 f
->want_fullscreen
= FULLSCREEN_NONE
;
3141 else if (EQ (new_value
, Qfullboth
) || EQ (new_value
, Qfullscreen
))
3142 f
->want_fullscreen
= FULLSCREEN_BOTH
;
3143 else if (EQ (new_value
, Qfullwidth
))
3144 f
->want_fullscreen
= FULLSCREEN_WIDTH
;
3145 else if (EQ (new_value
, Qfullheight
))
3146 f
->want_fullscreen
= FULLSCREEN_HEIGHT
;
3147 else if (EQ (new_value
, Qmaximized
))
3148 f
->want_fullscreen
= FULLSCREEN_MAXIMIZED
;
3150 if (FRAME_TERMINAL (f
)->fullscreen_hook
!= NULL
)
3151 FRAME_TERMINAL (f
)->fullscreen_hook (f
);
3155 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3156 the previous value of that parameter, NEW_VALUE is the new value. */
3159 x_set_line_spacing (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3161 if (NILP (new_value
))
3162 f
->extra_line_spacing
= 0;
3163 else if (RANGED_INTEGERP (0, new_value
, INT_MAX
))
3164 f
->extra_line_spacing
= XFASTINT (new_value
);
3165 else if (FLOATP (new_value
))
3167 int new_spacing
= XFLOAT_DATA (new_value
) * FRAME_LINE_HEIGHT (f
) + 0.5;
3169 if (new_spacing
>= 0)
3170 f
->extra_line_spacing
= new_spacing
;
3172 signal_error ("Invalid line-spacing", new_value
);
3175 signal_error ("Invalid line-spacing", new_value
);
3176 if (FRAME_VISIBLE_P (f
))
3181 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3182 the previous value of that parameter, NEW_VALUE is the new value. */
3185 x_set_screen_gamma (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3187 Lisp_Object bgcolor
;
3189 if (NILP (new_value
))
3191 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
3192 /* The value 0.4545 is the normal viewing gamma. */
3193 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
3195 signal_error ("Invalid screen-gamma", new_value
);
3197 /* Apply the new gamma value to the frame background. */
3198 bgcolor
= Fassq (Qbackground_color
, f
->param_alist
);
3199 if (CONSP (bgcolor
) && (bgcolor
= XCDR (bgcolor
), STRINGP (bgcolor
)))
3201 Lisp_Object parm_index
= Fget (Qbackground_color
, Qx_frame_parameter
);
3202 if (NATNUMP (parm_index
)
3203 && XFASTINT (parm_index
) < ARRAYELTS (frame_parms
)
3204 && FRAME_RIF (f
)->frame_parm_handlers
[XFASTINT (parm_index
)])
3205 (*FRAME_RIF (f
)->frame_parm_handlers
[XFASTINT (parm_index
)])
3209 Fclear_face_cache (Qnil
);
3214 x_set_font (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3216 Lisp_Object font_object
;
3218 #ifdef HAVE_X_WINDOWS
3219 Lisp_Object font_param
= arg
;
3222 /* Set the frame parameter back to the old value because we may
3223 fail to use ARG as the new parameter value. */
3224 store_frame_param (f
, Qfont
, oldval
);
3226 /* ARG is a fontset name, a font name, a cons of fontset name and a
3227 font object, or a font object. In the last case, this function
3231 fontset
= fs_query_fontset (arg
, 0);
3234 font_object
= font_open_by_name (f
, arg
);
3235 if (NILP (font_object
))
3236 error ("Font `%s' is not defined", SSDATA (arg
));
3237 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3239 else if (fontset
> 0)
3241 font_object
= font_open_by_name (f
, fontset_ascii (fontset
));
3242 if (NILP (font_object
))
3243 error ("Font `%s' is not defined", SDATA (arg
));
3244 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3247 error ("The default fontset can't be used for a frame font");
3249 else if (CONSP (arg
) && STRINGP (XCAR (arg
)) && FONT_OBJECT_P (XCDR (arg
)))
3251 /* This is the case that the ASCII font of F's fontset XCAR
3252 (arg) is changed to the font XCDR (arg) by
3253 `set-fontset-font'. */
3254 fontset
= fs_query_fontset (XCAR (arg
), 0);
3256 error ("Unknown fontset: %s", SDATA (XCAR (arg
)));
3257 font_object
= XCDR (arg
);
3258 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3259 #ifdef HAVE_X_WINDOWS
3260 font_param
= Ffont_get (font_object
, QCname
);
3263 else if (FONT_OBJECT_P (arg
))
3266 #ifdef HAVE_X_WINDOWS
3267 font_param
= Ffont_get (font_object
, QCname
);
3269 /* This is to store the XLFD font name in the frame parameter for
3270 backward compatibility. We should store the font-object
3271 itself in the future. */
3272 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3273 fontset
= FRAME_FONTSET (f
);
3274 /* Check if we can use the current fontset. If not, set FONTSET
3275 to -1 to generate a new fontset from FONT-OBJECT. */
3278 Lisp_Object ascii_font
= fontset_ascii (fontset
);
3279 Lisp_Object spec
= font_spec_from_name (ascii_font
);
3282 signal_error ("Invalid font name", ascii_font
);
3284 if (! font_match_p (spec
, font_object
))
3289 signal_error ("Invalid font", arg
);
3291 if (! NILP (Fequal (font_object
, oldval
)))
3294 x_new_font (f
, font_object
, fontset
);
3295 store_frame_param (f
, Qfont
, arg
);
3296 #ifdef HAVE_X_WINDOWS
3297 store_frame_param (f
, Qfont_param
, font_param
);
3299 /* Recalculate toolbar height. */
3300 f
->n_tool_bar_rows
= 0;
3302 /* Ensure we redraw it. */
3303 clear_current_matrices (f
);
3305 /* Attempt to hunt down bug#16028. */
3306 SET_FRAME_GARBAGED (f
);
3308 recompute_basic_faces (f
);
3310 do_pending_window_change (0);
3312 /* We used to call face-set-after-frame-default here, but it leads to
3313 recursive calls (since that function can set the `default' face's
3314 font which in turns changes the frame's `font' parameter).
3315 Also I don't know what this call is meant to do, but it seems the
3316 wrong way to do it anyway (it does a lot more work than what seems
3317 reasonable in response to a change to `font'). */
3322 x_set_font_backend (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3324 if (! NILP (new_value
)
3325 && !CONSP (new_value
))
3329 CHECK_STRING (new_value
);
3330 p0
= p1
= SSDATA (new_value
);
3334 while (*p1
&& ! c_isspace (*p1
) && *p1
!= ',') p1
++;
3336 new_value
= Fcons (Fintern (make_string (p0
, p1
- p0
), Qnil
),
3342 while ((c
= *++p1
) && c_isspace (c
));
3346 new_value
= Fnreverse (new_value
);
3349 if (! NILP (old_value
) && ! NILP (Fequal (old_value
, new_value
)))
3353 free_all_realized_faces (Qnil
);
3355 new_value
= font_update_drivers (f
, NILP (new_value
) ? Qt
: new_value
);
3356 if (NILP (new_value
))
3358 if (NILP (old_value
))
3359 error ("No font backend available");
3360 font_update_drivers (f
, old_value
);
3361 error ("None of specified font backends are available");
3363 store_frame_param (f
, Qfont_backend
, new_value
);
3369 XSETFRAME (frame
, f
);
3370 x_set_font (f
, Fframe_parameter (frame
, Qfont
), Qnil
);
3371 ++face_change_count
;
3372 windows_or_buffers_changed
= 18;
3378 x_set_fringe_width (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3380 compute_fringe_widths (f
, 1);
3381 #ifdef HAVE_X_WINDOWS
3382 /* Must adjust this so window managers report correct number of columns. */
3383 if (FRAME_X_WINDOW (f
) != 0)
3384 x_wm_set_size_hint (f
, 0, 0);
3389 x_set_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3391 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3393 if (XINT (arg
) == f
->border_width
)
3396 if (FRAME_X_WINDOW (f
) != 0)
3397 error ("Cannot change the border width of a frame");
3399 f
->border_width
= XINT (arg
);
3403 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3405 int old
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3407 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3408 FRAME_INTERNAL_BORDER_WIDTH (f
) = XINT (arg
);
3409 if (FRAME_INTERNAL_BORDER_WIDTH (f
) < 0)
3410 FRAME_INTERNAL_BORDER_WIDTH (f
) = 0;
3412 #ifdef USE_X_TOOLKIT
3413 if (FRAME_X_OUTPUT (f
)->edit_widget
)
3414 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
3417 if (FRAME_INTERNAL_BORDER_WIDTH (f
) == old
)
3420 if (FRAME_X_WINDOW (f
) != 0)
3422 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3423 SET_FRAME_GARBAGED (f
);
3424 do_pending_window_change (0);
3427 SET_FRAME_GARBAGED (f
);
3431 x_set_right_divider_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3433 int old
= FRAME_RIGHT_DIVIDER_WIDTH (f
);
3435 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3436 FRAME_RIGHT_DIVIDER_WIDTH (f
) = XINT (arg
);
3437 if (FRAME_RIGHT_DIVIDER_WIDTH (f
) < 0)
3438 FRAME_RIGHT_DIVIDER_WIDTH (f
) = 0;
3440 if (FRAME_RIGHT_DIVIDER_WIDTH (f
) == old
)
3443 if (FRAME_X_WINDOW (f
) != 0)
3445 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3446 SET_FRAME_GARBAGED (f
);
3447 do_pending_window_change (0);
3450 SET_FRAME_GARBAGED (f
);
3454 x_set_bottom_divider_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3456 int old
= FRAME_BOTTOM_DIVIDER_WIDTH (f
);
3458 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3459 FRAME_BOTTOM_DIVIDER_WIDTH (f
) = XINT (arg
);
3460 if (FRAME_BOTTOM_DIVIDER_WIDTH (f
) < 0)
3461 FRAME_BOTTOM_DIVIDER_WIDTH (f
) = 0;
3463 if (FRAME_BOTTOM_DIVIDER_WIDTH (f
) == old
)
3466 if (FRAME_X_WINDOW (f
) != 0)
3468 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3469 SET_FRAME_GARBAGED (f
);
3470 do_pending_window_change (0);
3473 SET_FRAME_GARBAGED (f
);
3477 x_set_visibility (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
3480 XSETFRAME (frame
, f
);
3483 Fmake_frame_invisible (frame
, Qt
);
3484 else if (EQ (value
, Qicon
))
3485 Ficonify_frame (frame
);
3487 Fmake_frame_visible (frame
);
3491 x_set_autoraise (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3493 f
->auto_raise
= !EQ (Qnil
, arg
);
3497 x_set_autolower (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3499 f
->auto_lower
= !EQ (Qnil
, arg
);
3503 x_set_unsplittable (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3505 f
->no_split
= !NILP (arg
);
3509 x_set_vertical_scroll_bars (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3511 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3512 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
3513 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3514 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
3516 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
)
3518 ? vertical_scroll_bar_none
3520 ? vertical_scroll_bar_left
3522 ? vertical_scroll_bar_right
3523 : EQ (Qleft
, Vdefault_frame_scroll_bars
)
3524 ? vertical_scroll_bar_left
3525 : EQ (Qright
, Vdefault_frame_scroll_bars
)
3526 ? vertical_scroll_bar_right
3527 : vertical_scroll_bar_none
);
3529 /* We set this parameter before creating the X window for the
3530 frame, so we can get the geometry right from the start.
3531 However, if the window hasn't been created yet, we shouldn't
3532 call x_set_window_size. */
3533 if (FRAME_X_WINDOW (f
))
3534 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3535 FRAME_TEXT_HEIGHT (f
), 1);
3536 do_pending_window_change (0);
3541 x_set_scroll_bar_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3543 int unit
= FRAME_COLUMN_WIDTH (f
);
3547 x_set_scroll_bar_default_width (f
);
3549 if (FRAME_X_WINDOW (f
))
3550 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3551 FRAME_TEXT_HEIGHT (f
), 1);
3552 do_pending_window_change (0);
3554 else if (RANGED_INTEGERP (1, arg
, INT_MAX
)
3555 && XFASTINT (arg
) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3557 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = XFASTINT (arg
);
3558 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (XFASTINT (arg
) + unit
- 1) / unit
;
3559 if (FRAME_X_WINDOW (f
))
3560 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3561 FRAME_TEXT_HEIGHT (f
), 1);
3562 do_pending_window_change (0);
3565 /* Eventually remove the following call. It should have been done by
3566 x_set_window_size already. */
3567 change_frame_size (f
, 0, 0, 0, 0, 0, 1);
3568 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
3569 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
3573 x_set_alpha (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3580 for (i
= 0; i
< 2; i
++)
3593 else if (FLOATP (item
))
3595 alpha
= XFLOAT_DATA (item
);
3596 if (! (0 <= alpha
&& alpha
<= 1.0))
3597 args_out_of_range (make_float (0.0), make_float (1.0));
3599 else if (INTEGERP (item
))
3601 EMACS_INT ialpha
= XINT (item
);
3602 if (! (0 <= ialpha
&& alpha
<= 100))
3603 args_out_of_range (make_number (0), make_number (100));
3604 alpha
= ialpha
/ 100.0;
3607 wrong_type_argument (Qnumberp
, item
);
3611 for (i
= 0; i
< 2; i
++)
3612 f
->alpha
[i
] = newval
[i
];
3614 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3616 x_set_frame_alpha (f
);
3625 /* Non-zero if mouse is grabbed on DPYINFO
3626 and we know the frame where it is. */
3628 bool x_mouse_grabbed (Display_Info
*dpyinfo
)
3630 return (dpyinfo
->grabbed
3631 && dpyinfo
->last_mouse_frame
3632 && FRAME_LIVE_P (dpyinfo
->last_mouse_frame
));
3635 /* Re-highlight something with mouse-face properties
3636 on DPYINFO using saved frame and mouse position. */
3639 x_redo_mouse_highlight (Display_Info
*dpyinfo
)
3641 if (dpyinfo
->last_mouse_motion_frame
3642 && FRAME_LIVE_P (dpyinfo
->last_mouse_motion_frame
))
3643 note_mouse_highlight (dpyinfo
->last_mouse_motion_frame
,
3644 dpyinfo
->last_mouse_motion_x
,
3645 dpyinfo
->last_mouse_motion_y
);
3648 #endif /* HAVE_NS */
3650 /* Subroutines of creating an X frame. */
3652 /* Make sure that Vx_resource_name is set to a reasonable value.
3653 Fix it up, or set it to `emacs' if it is too hopeless. */
3656 validate_x_resource_name (void)
3659 /* Number of valid characters in the resource name. */
3660 ptrdiff_t good_count
= 0;
3661 /* Number of invalid characters in the resource name. */
3662 ptrdiff_t bad_count
= 0;
3666 if (!STRINGP (Vx_resource_class
))
3667 Vx_resource_class
= build_string (EMACS_CLASS
);
3669 if (STRINGP (Vx_resource_name
))
3671 unsigned char *p
= SDATA (Vx_resource_name
);
3673 len
= SBYTES (Vx_resource_name
);
3675 /* Only letters, digits, - and _ are valid in resource names.
3676 Count the valid characters and count the invalid ones. */
3677 for (i
= 0; i
< len
; i
++)
3680 if (! ((c
>= 'a' && c
<= 'z')
3681 || (c
>= 'A' && c
<= 'Z')
3682 || (c
>= '0' && c
<= '9')
3683 || c
== '-' || c
== '_'))
3690 /* Not a string => completely invalid. */
3691 bad_count
= 5, good_count
= 0;
3693 /* If name is valid already, return. */
3697 /* If name is entirely invalid, or nearly so, or is so implausibly
3698 large that alloca might not work, use `emacs'. */
3699 if (good_count
< 2 || MAX_ALLOCA
- sizeof ".customization" < len
)
3701 Vx_resource_name
= build_string ("emacs");
3705 /* Name is partly valid. Copy it and replace the invalid characters
3706 with underscores. */
3708 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
3710 for (i
= 0; i
< len
; i
++)
3712 int c
= SREF (new, i
);
3713 if (! ((c
>= 'a' && c
<= 'z')
3714 || (c
>= 'A' && c
<= 'Z')
3715 || (c
>= '0' && c
<= '9')
3716 || c
== '-' || c
== '_'))
3721 /* Get specified attribute from resource database RDB.
3722 See Fx_get_resource below for other parameters. */
3725 xrdb_get_resource (XrmDatabase rdb
, Lisp_Object attribute
, Lisp_Object
class, Lisp_Object component
, Lisp_Object subclass
)
3727 register char *value
;
3731 CHECK_STRING (attribute
);
3732 CHECK_STRING (class);
3734 if (!NILP (component
))
3735 CHECK_STRING (component
);
3736 if (!NILP (subclass
))
3737 CHECK_STRING (subclass
);
3738 if (NILP (component
) != NILP (subclass
))
3739 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3741 validate_x_resource_name ();
3743 /* Allocate space for the components, the dots which separate them,
3744 and the final '\0'. Make them big enough for the worst case. */
3745 name_key
= alloca (SBYTES (Vx_resource_name
)
3746 + (STRINGP (component
)
3747 ? SBYTES (component
) : 0)
3748 + SBYTES (attribute
)
3751 class_key
= alloca (SBYTES (Vx_resource_class
)
3753 + (STRINGP (subclass
)
3754 ? SBYTES (subclass
) : 0)
3757 /* Start with emacs.FRAMENAME for the name (the specific one)
3758 and with `Emacs' for the class key (the general one). */
3759 strcpy (name_key
, SSDATA (Vx_resource_name
));
3760 strcpy (class_key
, SSDATA (Vx_resource_class
));
3762 strcat (class_key
, ".");
3763 strcat (class_key
, SSDATA (class));
3765 if (!NILP (component
))
3767 strcat (class_key
, ".");
3768 strcat (class_key
, SSDATA (subclass
));
3770 strcat (name_key
, ".");
3771 strcat (name_key
, SSDATA (component
));
3774 strcat (name_key
, ".");
3775 strcat (name_key
, SSDATA (attribute
));
3777 value
= x_get_string_resource (rdb
, name_key
, class_key
);
3779 if (value
&& *value
)
3780 return build_string (value
);
3786 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
3787 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3788 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3789 class, where INSTANCE is the name under which Emacs was invoked, or
3790 the name specified by the `-name' or `-rn' command-line arguments.
3792 The optional arguments COMPONENT and SUBCLASS add to the key and the
3793 class, respectively. You must specify both of them or neither.
3794 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3795 and the class is `Emacs.CLASS.SUBCLASS'. */)
3796 (Lisp_Object attribute
, Lisp_Object
class, Lisp_Object component
,
3797 Lisp_Object subclass
)
3799 check_window_system (NULL
);
3801 return xrdb_get_resource (check_x_display_info (Qnil
)->xrdb
,
3802 attribute
, class, component
, subclass
);
3805 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3808 display_x_get_resource (Display_Info
*dpyinfo
, Lisp_Object attribute
,
3809 Lisp_Object
class, Lisp_Object component
,
3810 Lisp_Object subclass
)
3812 return xrdb_get_resource (dpyinfo
->xrdb
,
3813 attribute
, class, component
, subclass
);
3816 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3817 /* Used when C code wants a resource value. */
3818 /* Called from oldXMenu/Create.c. */
3820 x_get_resource_string (const char *attribute
, const char *class)
3823 struct frame
*sf
= SELECTED_FRAME ();
3824 ptrdiff_t invocation_namelen
= SBYTES (Vinvocation_name
);
3827 /* Allocate space for the components, the dots which separate them,
3828 and the final '\0'. */
3829 char *name_key
= SAFE_ALLOCA (invocation_namelen
+ strlen (attribute
) + 2);
3830 char *class_key
= alloca ((sizeof (EMACS_CLASS
) - 1) + strlen (class) + 2);
3832 esprintf (name_key
, "%s.%s", SSDATA (Vinvocation_name
), attribute
);
3833 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3835 result
= x_get_string_resource (FRAME_DISPLAY_INFO (sf
)->xrdb
,
3836 name_key
, class_key
);
3842 /* Return the value of parameter PARAM.
3844 First search ALIST, then Vdefault_frame_alist, then the X defaults
3845 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3847 Convert the resource to the type specified by desired_type.
3849 If no default is specified, return Qunbound. If you call
3850 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3851 and don't let it get stored in any Lisp-visible variables! */
3854 x_get_arg (Display_Info
*dpyinfo
, Lisp_Object alist
, Lisp_Object param
,
3855 const char *attribute
, const char *class, enum resource_types type
)
3857 register Lisp_Object tem
;
3859 tem
= Fassq (param
, alist
);
3863 /* If we find this parm in ALIST, clear it out
3864 so that it won't be "left over" at the end. */
3866 XSETCAR (tem
, Qnil
);
3867 /* In case the parameter appears more than once in the alist,
3869 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
3870 if (CONSP (XCAR (tail
))
3871 && EQ (XCAR (XCAR (tail
)), param
))
3872 XSETCAR (XCAR (tail
), Qnil
);
3875 tem
= Fassq (param
, Vdefault_frame_alist
);
3877 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3878 look in the X resources. */
3881 if (attribute
&& dpyinfo
)
3883 tem
= display_x_get_resource (dpyinfo
,
3884 build_string (attribute
),
3885 build_string (class),
3893 case RES_TYPE_NUMBER
:
3894 return make_number (atoi (SSDATA (tem
)));
3896 case RES_TYPE_BOOLEAN_NUMBER
:
3897 if (!strcmp (SSDATA (tem
), "on")
3898 || !strcmp (SSDATA (tem
), "true"))
3899 return make_number (1);
3900 return make_number (atoi (SSDATA (tem
)));
3903 case RES_TYPE_FLOAT
:
3904 return make_float (atof (SSDATA (tem
)));
3906 case RES_TYPE_BOOLEAN
:
3907 tem
= Fdowncase (tem
);
3908 if (!strcmp (SSDATA (tem
), "on")
3910 || !strcmp (SSDATA (tem
), "yes")
3912 || !strcmp (SSDATA (tem
), "true"))
3917 case RES_TYPE_STRING
:
3920 case RES_TYPE_SYMBOL
:
3921 /* As a special case, we map the values `true' and `on'
3922 to Qt, and `false' and `off' to Qnil. */
3925 lower
= Fdowncase (tem
);
3926 if (!strcmp (SSDATA (lower
), "on")
3928 || !strcmp (SSDATA (lower
), "yes")
3930 || !strcmp (SSDATA (lower
), "true"))
3932 else if (!strcmp (SSDATA (lower
), "off")
3934 || !strcmp (SSDATA (lower
), "no")
3936 || !strcmp (SSDATA (lower
), "false"))
3939 return Fintern (tem
, Qnil
);
3953 x_frame_get_arg (struct frame
*f
, Lisp_Object alist
, Lisp_Object param
,
3954 const char *attribute
, const char *class,
3955 enum resource_types type
)
3957 return x_get_arg (FRAME_DISPLAY_INFO (f
),
3958 alist
, param
, attribute
, class, type
);
3961 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3964 x_frame_get_and_record_arg (struct frame
*f
, Lisp_Object alist
,
3966 const char *attribute
, const char *class,
3967 enum resource_types type
)
3971 value
= x_get_arg (FRAME_DISPLAY_INFO (f
), alist
, param
,
3972 attribute
, class, type
);
3973 if (! NILP (value
) && ! EQ (value
, Qunbound
))
3974 store_frame_param (f
, param
, value
);
3980 /* Record in frame F the specified or default value according to ALIST
3981 of the parameter named PROP (a Lisp symbol).
3982 If no value is specified for PROP, look for an X default for XPROP
3983 on the frame named NAME.
3984 If that is not found either, use the value DEFLT. */
3987 x_default_parameter (struct frame
*f
, Lisp_Object alist
, Lisp_Object prop
,
3988 Lisp_Object deflt
, const char *xprop
, const char *xclass
,
3989 enum resource_types type
)
3993 tem
= x_frame_get_arg (f
, alist
, prop
, xprop
, xclass
, type
);
3994 if (EQ (tem
, Qunbound
))
3996 x_set_frame_parameters (f
, list1 (Fcons (prop
, tem
)));
4001 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4004 * XParseGeometry parses strings of the form
4005 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4006 * width, height, xoffset, and yoffset are unsigned integers.
4007 * Example: "=80x24+300-49"
4008 * The equal sign is optional.
4009 * It returns a bitmask that indicates which of the four values
4010 * were actually found in the string. For each value found,
4011 * the corresponding argument is updated; for each value
4012 * not found, the corresponding argument is left unchanged.
4016 XParseGeometry (char *string
,
4018 unsigned int *width
, unsigned int *height
)
4022 unsigned long tempWidth
, tempHeight
;
4023 long int tempX
, tempY
;
4024 char *nextCharacter
;
4026 if (string
== NULL
|| *string
== '\0')
4029 string
++; /* ignore possible '=' at beg of geometry spec */
4032 if (*strind
!= '+' && *strind
!= '-' && *strind
!= 'x')
4034 tempWidth
= strtoul (strind
, &nextCharacter
, 10);
4035 if (strind
== nextCharacter
)
4037 strind
= nextCharacter
;
4041 if (*strind
== 'x' || *strind
== 'X')
4044 tempHeight
= strtoul (strind
, &nextCharacter
, 10);
4045 if (strind
== nextCharacter
)
4047 strind
= nextCharacter
;
4048 mask
|= HeightValue
;
4051 if (*strind
== '+' || *strind
== '-')
4055 tempX
= strtol (strind
, &nextCharacter
, 10);
4056 if (strind
== nextCharacter
)
4058 strind
= nextCharacter
;
4060 if (*strind
== '+' || *strind
== '-')
4064 tempY
= strtol (strind
, &nextCharacter
, 10);
4065 if (strind
== nextCharacter
)
4067 strind
= nextCharacter
;
4072 /* If strind isn't at the end of the string then it's an invalid
4073 geometry specification. */
4075 if (*strind
!= '\0')
4079 *x
= clip_to_bounds (INT_MIN
, tempX
, INT_MAX
);
4081 *y
= clip_to_bounds (INT_MIN
, tempY
, INT_MAX
);
4082 if (mask
& WidthValue
)
4083 *width
= min (tempWidth
, UINT_MAX
);
4084 if (mask
& HeightValue
)
4085 *height
= min (tempHeight
, UINT_MAX
);
4089 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4092 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4093 make-docfile: the documentation string in ns-win.el was used for
4094 x-parse-geometry even in non-NS builds.
4096 With two definitions of x-parse-geometry in this file, various
4097 things still get confused (eg M-x apropos documentation), so that
4098 it is best if the two definitions just share the same doc-string.
4100 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
4101 doc
: /* Parse a display geometry string STRING.
4102 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4103 The properties returned may include `top', `left', `height', and `width'.
4104 For X, the value of `left' or `top' may be an integer,
4105 or a list (+ N) meaning N pixels relative to top/left corner,
4106 or a list (- N) meaning -N pixels relative to bottom/right corner.
4107 On Nextstep, this just calls `ns-parse-geometry'. */)
4108 (Lisp_Object string
)
4111 unsigned int width
, height
;
4114 CHECK_STRING (string
);
4117 if (strchr (SSDATA (string
), ' ') != NULL
)
4118 return call1 (Qns_parse_geometry
, string
);
4120 geometry
= XParseGeometry (SSDATA (string
),
4121 &x
, &y
, &width
, &height
);
4123 if (geometry
& XValue
)
4125 Lisp_Object element
;
4127 if (x
>= 0 && (geometry
& XNegative
))
4128 element
= list3 (Qleft
, Qminus
, make_number (-x
));
4129 else if (x
< 0 && ! (geometry
& XNegative
))
4130 element
= list3 (Qleft
, Qplus
, make_number (x
));
4132 element
= Fcons (Qleft
, make_number (x
));
4133 result
= Fcons (element
, result
);
4136 if (geometry
& YValue
)
4138 Lisp_Object element
;
4140 if (y
>= 0 && (geometry
& YNegative
))
4141 element
= list3 (Qtop
, Qminus
, make_number (-y
));
4142 else if (y
< 0 && ! (geometry
& YNegative
))
4143 element
= list3 (Qtop
, Qplus
, make_number (y
));
4145 element
= Fcons (Qtop
, make_number (y
));
4146 result
= Fcons (element
, result
);
4149 if (geometry
& WidthValue
)
4150 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
4151 if (geometry
& HeightValue
)
4152 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
4158 /* Calculate the desired size and position of frame F.
4159 Return the flags saying which aspects were specified.
4161 Also set the win_gravity and size_hint_flags of F.
4163 Adjust height for toolbar if TOOLBAR_P is 1.
4165 This function does not make the coordinates positive. */
4167 #define DEFAULT_ROWS 35
4168 #define DEFAULT_COLS 80
4171 x_figure_window_size (struct frame
*f
, Lisp_Object parms
, bool toolbar_p
)
4173 register Lisp_Object tem0
, tem1
, tem2
;
4174 long window_prompting
= 0;
4175 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4177 /* Default values if we fall through.
4178 Actually, if that happens we should get
4179 window manager prompting. */
4180 SET_FRAME_WIDTH (f
, DEFAULT_COLS
* FRAME_COLUMN_WIDTH (f
));
4181 SET_FRAME_COLS (f
, DEFAULT_COLS
);
4182 SET_FRAME_HEIGHT (f
, DEFAULT_ROWS
* FRAME_LINE_HEIGHT (f
));
4183 FRAME_LINES (f
) = DEFAULT_ROWS
;
4185 /* Window managers expect that if program-specified
4186 positions are not (0,0), they're intentional, not defaults. */
4190 /* Ensure that old new_width and new_height will not override the
4192 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4193 f
->new_width
= f
->new_height
= f
->new_pixelwise
= 0;
4195 tem0
= x_get_arg (dpyinfo
, parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
4196 tem1
= x_get_arg (dpyinfo
, parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
4197 tem2
= x_get_arg (dpyinfo
, parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
4198 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
4200 if (!EQ (tem0
, Qunbound
))
4202 CHECK_NUMBER (tem0
);
4203 if (! (0 <= XINT (tem0
) && XINT (tem0
) <= INT_MAX
))
4204 xsignal1 (Qargs_out_of_range
, tem0
);
4205 FRAME_LINES (f
) = XINT (tem0
);
4207 if (!EQ (tem1
, Qunbound
))
4209 CHECK_NUMBER (tem1
);
4210 if (! (0 <= XINT (tem1
) && XINT (tem1
) <= INT_MAX
))
4211 xsignal1 (Qargs_out_of_range
, tem1
);
4212 SET_FRAME_COLS (f
, XINT (tem1
));
4214 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
4215 window_prompting
|= USSize
;
4217 window_prompting
|= PSize
;
4221 /* This used to be done _before_ calling x_figure_window_size, but
4222 since the height is reset here, this was really a no-op. I
4223 assume that moving it here does what Gerd intended (although he
4224 no longer can remember what that was... ++KFS, 2003-03-25. */
4226 /* Add the tool-bar height to the initial frame height so that the
4227 user gets a text display area of the size he specified with -g or
4228 via .Xdefaults. Later changes of the tool-bar height don't
4229 change the frame size. This is done so that users can create
4230 tall Emacs frames without having to guess how tall the tool-bar
4232 if (toolbar_p
&& FRAME_TOOL_BAR_HEIGHT (f
))
4234 int margin
, relief
, bar_height
;
4236 relief
= (tool_bar_button_relief
>= 0
4237 ? tool_bar_button_relief
4238 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
4240 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
, INT_MAX
))
4241 margin
= XFASTINT (Vtool_bar_button_margin
);
4242 else if (CONSP (Vtool_bar_button_margin
)
4243 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
), INT_MAX
))
4244 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
4248 /* PXW: We should be able to not round here. */
4249 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
4250 FRAME_LINES (f
) += (bar_height
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
4253 compute_fringe_widths (f
, 0);
4255 SET_FRAME_WIDTH (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
4256 SET_FRAME_HEIGHT(f
, FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
));
4258 tem0
= x_get_arg (dpyinfo
, parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
4259 tem1
= x_get_arg (dpyinfo
, parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
4260 tem2
= x_get_arg (dpyinfo
, parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
4261 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
4263 if (EQ (tem0
, Qminus
))
4266 window_prompting
|= YNegative
;
4268 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
4269 && CONSP (XCDR (tem0
))
4270 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (tem0
)), INT_MAX
))
4272 f
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
4273 window_prompting
|= YNegative
;
4275 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
4276 && CONSP (XCDR (tem0
))
4277 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0
))))
4279 f
->top_pos
= XINT (XCAR (XCDR (tem0
)));
4281 else if (EQ (tem0
, Qunbound
))
4285 CHECK_TYPE_RANGED_INTEGER (int, tem0
);
4286 f
->top_pos
= XINT (tem0
);
4288 window_prompting
|= YNegative
;
4291 if (EQ (tem1
, Qminus
))
4294 window_prompting
|= XNegative
;
4296 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
4297 && CONSP (XCDR (tem1
))
4298 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (tem1
)), INT_MAX
))
4300 f
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
4301 window_prompting
|= XNegative
;
4303 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
4304 && CONSP (XCDR (tem1
))
4305 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1
))))
4307 f
->left_pos
= XINT (XCAR (XCDR (tem1
)));
4309 else if (EQ (tem1
, Qunbound
))
4313 CHECK_TYPE_RANGED_INTEGER (int, tem1
);
4314 f
->left_pos
= XINT (tem1
);
4315 if (f
->left_pos
< 0)
4316 window_prompting
|= XNegative
;
4319 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
4320 window_prompting
|= USPosition
;
4322 window_prompting
|= PPosition
;
4325 if (window_prompting
& XNegative
)
4327 if (window_prompting
& YNegative
)
4328 f
->win_gravity
= SouthEastGravity
;
4330 f
->win_gravity
= NorthEastGravity
;
4334 if (window_prompting
& YNegative
)
4335 f
->win_gravity
= SouthWestGravity
;
4337 f
->win_gravity
= NorthWestGravity
;
4340 f
->size_hint_flags
= window_prompting
;
4342 return window_prompting
;
4347 #endif /* HAVE_WINDOW_SYSTEM */
4350 frame_make_pointer_invisible (struct frame
*f
)
4352 if (! NILP (Vmake_pointer_invisible
))
4354 if (f
&& FRAME_LIVE_P (f
) && !f
->pointer_invisible
4355 && FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook
)
4358 FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook (f
, 1);
4359 f
->pointer_invisible
= 1;
4365 frame_make_pointer_visible (struct frame
*f
)
4367 /* We don't check Vmake_pointer_invisible here in case the
4368 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4369 if (f
&& FRAME_LIVE_P (f
) && f
->pointer_invisible
&& f
->mouse_moved
4370 && FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook
)
4372 FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook (f
, 0);
4373 f
->pointer_invisible
= 0;
4377 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p
,
4378 Sframe_pointer_visible_p
, 0, 1, 0,
4379 doc
: /* Return t if the mouse pointer displayed on FRAME is visible.
4380 Otherwise it returns nil. FRAME omitted or nil means the
4381 selected frame. This is useful when `make-pointer-invisible' is set. */)
4384 return decode_any_frame (frame
)->pointer_invisible
? Qnil
: Qt
;
4389 /***********************************************************************
4391 ***********************************************************************/
4393 #ifdef HAVE_WINDOW_SYSTEM
4395 # if (defined HAVE_NS \
4396 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4398 free_monitors (struct MonitorInfo
*monitors
, int n_monitors
)
4401 for (i
= 0; i
< n_monitors
; ++i
)
4402 xfree (monitors
[i
].name
);
4408 make_monitor_attribute_list (struct MonitorInfo
*monitors
,
4410 int primary_monitor
,
4411 Lisp_Object monitor_frames
,
4414 Lisp_Object attributes_list
= Qnil
;
4415 Lisp_Object primary_monitor_attributes
= Qnil
;
4418 for (i
= 0; i
< n_monitors
; ++i
)
4420 Lisp_Object geometry
, workarea
, attributes
= Qnil
;
4421 struct MonitorInfo
*mi
= &monitors
[i
];
4423 if (mi
->geom
.width
== 0) continue;
4425 workarea
= list4i (mi
->work
.x
, mi
->work
.y
,
4426 mi
->work
.width
, mi
->work
.height
);
4427 geometry
= list4i (mi
->geom
.x
, mi
->geom
.y
,
4428 mi
->geom
.width
, mi
->geom
.height
);
4429 attributes
= Fcons (Fcons (Qsource
, build_string (source
)),
4431 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
4433 attributes
= Fcons (Fcons (Qmm_size
,
4434 list2i (mi
->mm_width
, mi
->mm_height
)),
4436 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
4437 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
4439 attributes
= Fcons (Fcons (Qname
, make_string (mi
->name
,
4440 strlen (mi
->name
))),
4443 if (i
== primary_monitor
)
4444 primary_monitor_attributes
= attributes
;
4446 attributes_list
= Fcons (attributes
, attributes_list
);
4449 if (!NILP (primary_monitor_attributes
))
4450 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
4451 return attributes_list
;
4454 #endif /* HAVE_WINDOW_SYSTEM */
4457 /***********************************************************************
4459 ***********************************************************************/
4462 syms_of_frame (void)
4464 DEFSYM (Qframep
, "framep");
4465 DEFSYM (Qframe_live_p
, "frame-live-p");
4466 DEFSYM (Qexplicit_name
, "explicit-name");
4467 DEFSYM (Qheight
, "height");
4468 DEFSYM (Qicon
, "icon");
4469 DEFSYM (Qminibuffer
, "minibuffer");
4470 DEFSYM (Qmodeline
, "modeline");
4471 DEFSYM (Qonly
, "only");
4472 DEFSYM (Qnone
, "none");
4473 DEFSYM (Qwidth
, "width");
4474 DEFSYM (Qgeometry
, "geometry");
4475 DEFSYM (Qicon_left
, "icon-left");
4476 DEFSYM (Qicon_top
, "icon-top");
4477 DEFSYM (Qtooltip
, "tooltip");
4478 DEFSYM (Quser_position
, "user-position");
4479 DEFSYM (Quser_size
, "user-size");
4480 DEFSYM (Qwindow_id
, "window-id");
4481 #ifdef HAVE_X_WINDOWS
4482 DEFSYM (Qouter_window_id
, "outer-window-id");
4484 DEFSYM (Qparent_id
, "parent-id");
4486 DEFSYM (Qw32
, "w32");
4489 DEFSYM (Qvisible
, "visible");
4490 DEFSYM (Qbuffer_predicate
, "buffer-predicate");
4491 DEFSYM (Qbuffer_list
, "buffer-list");
4492 DEFSYM (Qburied_buffer_list
, "buried-buffer-list");
4493 DEFSYM (Qdisplay_type
, "display-type");
4494 DEFSYM (Qbackground_mode
, "background-mode");
4495 DEFSYM (Qnoelisp
, "noelisp");
4496 DEFSYM (Qtty_color_mode
, "tty-color-mode");
4497 DEFSYM (Qtty
, "tty");
4498 DEFSYM (Qtty_type
, "tty-type");
4500 DEFSYM (Qface_set_after_frame_default
, "face-set-after-frame-default");
4502 DEFSYM (Qfullwidth
, "fullwidth");
4503 DEFSYM (Qfullheight
, "fullheight");
4504 DEFSYM (Qfullboth
, "fullboth");
4505 DEFSYM (Qmaximized
, "maximized");
4506 DEFSYM (Qx_resource_name
, "x-resource-name");
4507 DEFSYM (Qx_frame_parameter
, "x-frame-parameter");
4509 DEFSYM (Qterminal
, "terminal");
4511 DEFSYM (Qgeometry
, "geometry");
4512 DEFSYM (Qworkarea
, "workarea");
4513 DEFSYM (Qmm_size
, "mm-size");
4514 DEFSYM (Qframes
, "frames");
4515 DEFSYM (Qsource
, "source");
4518 DEFSYM (Qns_parse_geometry
, "ns-parse-geometry");
4524 for (i
= 0; i
< ARRAYELTS (frame_parms
); i
++)
4526 Lisp_Object v
= intern_c_string (frame_parms
[i
].name
);
4527 if (frame_parms
[i
].variable
)
4529 *frame_parms
[i
].variable
= v
;
4530 staticpro (frame_parms
[i
].variable
);
4532 Fput (v
, Qx_frame_parameter
, make_number (i
));
4536 #ifdef HAVE_WINDOW_SYSTEM
4537 DEFVAR_LISP ("x-resource-name", Vx_resource_name
,
4538 doc
: /* The name Emacs uses to look up X resources.
4539 `x-get-resource' uses this as the first component of the instance name
4540 when requesting resource values.
4541 Emacs initially sets `x-resource-name' to the name under which Emacs
4542 was invoked, or to the value specified with the `-name' or `-rn'
4543 switches, if present.
4545 It may be useful to bind this variable locally around a call
4546 to `x-get-resource'. See also the variable `x-resource-class'. */);
4547 Vx_resource_name
= Qnil
;
4549 DEFVAR_LISP ("x-resource-class", Vx_resource_class
,
4550 doc
: /* The class Emacs uses to look up X resources.
4551 `x-get-resource' uses this as the first component of the instance class
4552 when requesting resource values.
4554 Emacs initially sets `x-resource-class' to "Emacs".
4556 Setting this variable permanently is not a reasonable thing to do,
4557 but binding this variable locally around a call to `x-get-resource'
4558 is a reasonable practice. See also the variable `x-resource-name'. */);
4559 Vx_resource_class
= build_string (EMACS_CLASS
);
4561 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit
,
4562 doc
: /* The lower limit of the frame opacity (alpha transparency).
4563 The value should range from 0 (invisible) to 100 (completely opaque).
4564 You can also use a floating number between 0.0 and 1.0. */);
4565 Vframe_alpha_lower_limit
= make_number (20);
4568 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist
,
4569 doc
: /* Alist of default values for frame creation.
4570 These may be set in your init file, like this:
4571 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4572 These override values given in window system configuration data,
4573 including X Windows' defaults database.
4574 For values specific to the first Emacs frame, see `initial-frame-alist'.
4575 For window-system specific values, see `window-system-default-frame-alist'.
4576 For values specific to the separate minibuffer frame, see
4577 `minibuffer-frame-alist'.
4578 The `menu-bar-lines' element of the list controls whether new frames
4579 have menu bars; `menu-bar-mode' works by altering this element.
4580 Setting this variable does not affect existing frames, only new ones. */);
4581 Vdefault_frame_alist
= Qnil
;
4583 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars
,
4584 doc
: /* Default position of scroll bars on this window-system. */);
4585 #ifdef HAVE_WINDOW_SYSTEM
4586 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4587 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4589 Vdefault_frame_scroll_bars
= Qright
;
4591 Vdefault_frame_scroll_bars
= Qleft
;
4594 Vdefault_frame_scroll_bars
= Qnil
;
4597 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4598 scroll_bar_adjust_thumb_portion_p
,
4599 doc
: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4600 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4601 even if the end of the buffer is shown (i.e. overscrolling).
4602 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4603 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4604 is visible. In this case you can not overscroll. */);
4605 scroll_bar_adjust_thumb_portion_p
= 1;
4607 DEFVAR_LISP ("terminal-frame", Vterminal_frame
,
4608 doc
: /* The initial frame-object, which represents Emacs's stdout. */);
4610 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function
,
4611 doc
: /* If non-nil, function to transform normal value of `mouse-position'.
4612 `mouse-position' calls this function, passing its usual return value as
4613 argument, and returns whatever this function returns.
4614 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4615 which need to do mouse handling at the Lisp level. */);
4616 Vmouse_position_function
= Qnil
;
4618 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight
,
4619 doc
: /* If non-nil, clickable text is highlighted when mouse is over it.
4620 If the value is an integer, highlighting is only shown after moving the
4621 mouse, while keyboard input turns off the highlight even when the mouse
4622 is over the clickable text. However, the mouse shape still indicates
4623 when the mouse is over clickable text. */);
4624 Vmouse_highlight
= Qt
;
4626 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible
,
4627 doc
: /* If non-nil, make pointer invisible while typing.
4628 The pointer becomes visible again when the mouse is moved. */);
4629 Vmake_pointer_invisible
= Qt
;
4631 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook
,
4632 doc
: /* Normal hook run when a frame gains input focus. */);
4633 Vfocus_in_hook
= Qnil
;
4634 DEFSYM (Qfocus_in_hook
, "focus-in-hook");
4636 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook
,
4637 doc
: /* Normal hook run when a frame loses input focus. */);
4638 Vfocus_out_hook
= Qnil
;
4639 DEFSYM (Qfocus_out_hook
, "focus-out-hook");
4641 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions
,
4642 doc
: /* Functions run before deleting a frame.
4643 The functions are run with one arg, the frame to be deleted.
4646 Note that functions in this list may be called just before the frame is
4647 actually deleted, or some time later (or even both when an earlier function
4648 in `delete-frame-functions' (indirectly) calls `delete-frame'
4650 Vdelete_frame_functions
= Qnil
;
4651 DEFSYM (Qdelete_frame_functions
, "delete-frame-functions");
4653 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode
,
4654 doc
: /* Non-nil if Menu-Bar mode is enabled.
4655 See the command `menu-bar-mode' for a description of this minor mode.
4656 Setting this variable directly does not take effect;
4657 either customize it (see the info node `Easy Customization')
4658 or call the function `menu-bar-mode'. */);
4659 Vmenu_bar_mode
= Qt
;
4661 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode
,
4662 doc
: /* Non-nil if Tool-Bar mode is enabled.
4663 See the command `tool-bar-mode' for a description of this minor mode.
4664 Setting this variable directly does not take effect;
4665 either customize it (see the info node `Easy Customization')
4666 or call the function `tool-bar-mode'. */);
4667 #ifdef HAVE_WINDOW_SYSTEM
4668 Vtool_bar_mode
= Qt
;
4670 Vtool_bar_mode
= Qnil
;
4673 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame
,
4674 doc
: /* Minibufferless frames use this frame's minibuffer.
4675 Emacs cannot create minibufferless frames unless this is set to an
4676 appropriate surrogate.
4678 Emacs consults this variable only when creating minibufferless
4679 frames; once the frame is created, it sticks with its assigned
4680 minibuffer, no matter what this variable is set to. This means that
4681 this variable doesn't necessarily say anything meaningful about the
4682 current set of frames, or where the minibuffer is currently being
4685 This variable is local to the current terminal and cannot be buffer-local. */);
4687 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse
,
4688 doc
: /* Non-nil if window system changes focus when you move the mouse.
4689 You should set this variable to tell Emacs how your window manager
4690 handles focus, since there is no way in general for Emacs to find out
4691 automatically. See also `mouse-autoselect-window'. */);
4692 focus_follows_mouse
= 0;
4694 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise
,
4695 doc
: /* Non-nil means resize frames pixelwise.
4696 If this option is nil, resizing a frame rounds its sizes to the frame's
4697 current values of `frame-char-height' and `frame-char-width'. If this
4698 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4701 With some window managers you have to set this to non-nil in order to
4702 fully maximize frames. To resize your initial frame pixelwise,
4703 set this option to a non-nil value in your init file. */);
4704 frame_resize_pixelwise
= 0;
4706 staticpro (&Vframe_list
);
4709 defsubr (&Sframe_live_p
);
4710 defsubr (&Swindow_system
);
4711 defsubr (&Smake_terminal_frame
);
4712 defsubr (&Shandle_switch_frame
);
4713 defsubr (&Sselect_frame
);
4714 defsubr (&Sselected_frame
);
4715 defsubr (&Sframe_list
);
4716 defsubr (&Snext_frame
);
4717 defsubr (&Sprevious_frame
);
4718 defsubr (&Slast_nonminibuf_frame
);
4719 defsubr (&Sdelete_frame
);
4720 defsubr (&Smouse_position
);
4721 defsubr (&Smouse_pixel_position
);
4722 defsubr (&Sset_mouse_position
);
4723 defsubr (&Sset_mouse_pixel_position
);
4725 defsubr (&Sframe_configuration
);
4726 defsubr (&Srestore_frame_configuration
);
4728 defsubr (&Smake_frame_visible
);
4729 defsubr (&Smake_frame_invisible
);
4730 defsubr (&Siconify_frame
);
4731 defsubr (&Sframe_visible_p
);
4732 defsubr (&Svisible_frame_list
);
4733 defsubr (&Sraise_frame
);
4734 defsubr (&Slower_frame
);
4735 defsubr (&Sx_focus_frame
);
4736 defsubr (&Sredirect_frame_focus
);
4737 defsubr (&Sframe_focus
);
4738 defsubr (&Sframe_parameters
);
4739 defsubr (&Sframe_parameter
);
4740 defsubr (&Smodify_frame_parameters
);
4741 defsubr (&Sframe_char_height
);
4742 defsubr (&Sframe_char_width
);
4743 defsubr (&Sframe_pixel_height
);
4744 defsubr (&Sframe_pixel_width
);
4745 defsubr (&Sframe_text_cols
);
4746 defsubr (&Sframe_text_lines
);
4747 defsubr (&Sframe_total_cols
);
4748 defsubr (&Sframe_text_width
);
4749 defsubr (&Sframe_text_height
);
4750 defsubr (&Sscroll_bar_width
);
4751 defsubr (&Sfringe_width
);
4752 defsubr (&Sborder_width
);
4753 defsubr (&Sright_divider_width
);
4754 defsubr (&Sbottom_divider_width
);
4755 defsubr (&Stool_bar_pixel_width
);
4756 defsubr (&Sset_frame_height
);
4757 defsubr (&Sset_frame_width
);
4758 defsubr (&Sset_frame_size
);
4759 defsubr (&Sset_frame_position
);
4760 defsubr (&Sframe_pointer_visible_p
);
4762 #ifdef HAVE_WINDOW_SYSTEM
4763 defsubr (&Sx_get_resource
);
4764 defsubr (&Sx_parse_geometry
);