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
55 Lisp_Object Qns_parse_geometry
;
58 Lisp_Object Qframep
, Qframe_live_p
;
59 Lisp_Object Qicon
, Qmodeline
;
60 Lisp_Object Qonly
, Qnone
;
61 Lisp_Object Qx
, Qw32
, Qpc
, Qns
;
63 Lisp_Object Qdisplay_type
;
64 static Lisp_Object Qbackground_mode
;
67 static Lisp_Object Qx_frame_parameter
;
68 Lisp_Object Qx_resource_name
;
69 Lisp_Object Qterminal
;
71 /* Frame parameters (set or reported). */
73 Lisp_Object Qauto_raise
, Qauto_lower
;
74 Lisp_Object Qborder_color
, Qborder_width
;
75 Lisp_Object Qcursor_color
, Qcursor_type
;
76 Lisp_Object Qheight
, Qwidth
;
77 Lisp_Object Qleft
, Qright
;
78 Lisp_Object Qicon_left
, Qicon_top
, Qicon_type
, Qicon_name
;
80 Lisp_Object Qinternal_border_width
;
81 Lisp_Object Qright_divider_width
, Qbottom_divider_width
;
82 Lisp_Object Qmouse_color
;
83 Lisp_Object Qminibuffer
;
84 Lisp_Object Qscroll_bar_width
, Qvertical_scroll_bars
;
85 Lisp_Object Qvisibility
;
86 Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
87 Lisp_Object Qscreen_gamma
;
88 Lisp_Object Qline_spacing
;
89 static Lisp_Object Quser_position
, Quser_size
;
90 Lisp_Object Qwait_for_wm
;
91 static Lisp_Object Qwindow_id
;
93 static Lisp_Object Qouter_window_id
;
95 Lisp_Object Qparent_id
;
96 Lisp_Object Qtitle
, Qname
;
97 static Lisp_Object Qexplicit_name
;
98 Lisp_Object Qunsplittable
;
99 Lisp_Object Qmenu_bar_lines
, Qtool_bar_lines
, Qtool_bar_position
;
100 Lisp_Object Qleft_fringe
, Qright_fringe
;
101 Lisp_Object Qbuffer_predicate
;
102 static Lisp_Object Qbuffer_list
, Qburied_buffer_list
;
103 Lisp_Object Qtty_color_mode
;
104 Lisp_Object Qtty
, Qtty_type
;
106 Lisp_Object Qfullscreen
, Qfullwidth
, Qfullheight
, Qfullboth
, Qmaximized
;
108 Lisp_Object Qfont_backend
;
111 Lisp_Object Qface_set_after_frame_default
;
113 static Lisp_Object Qfocus_in_hook
;
114 static Lisp_Object Qfocus_out_hook
;
115 static Lisp_Object Qdelete_frame_functions
;
117 static Lisp_Object Qgeometry
, Qworkarea
, Qmm_size
, Qframes
, Qsource
;
119 /* The currently selected frame. */
121 Lisp_Object selected_frame
;
123 /* A frame which is not just a mini-buffer, or NULL if there are no such
124 frames. This is usually the most recent such frame that was selected. */
126 static struct frame
*last_nonminibuf_frame
;
128 /* False means there are no visible garbaged frames. */
131 #ifdef HAVE_WINDOW_SYSTEM
132 static void x_report_frame_params (struct frame
*, Lisp_Object
*);
135 /* These setters are used only in this file, so they can be private. */
137 fset_buffer_predicate (struct frame
*f
, Lisp_Object val
)
139 f
->buffer_predicate
= val
;
142 fset_minibuffer_window (struct frame
*f
, Lisp_Object val
)
144 f
->minibuffer_window
= val
;
148 decode_live_frame (register Lisp_Object frame
)
151 frame
= selected_frame
;
152 CHECK_LIVE_FRAME (frame
);
153 return XFRAME (frame
);
157 decode_any_frame (register Lisp_Object frame
)
160 frame
= selected_frame
;
162 return XFRAME (frame
);
165 #ifdef HAVE_WINDOW_SYSTEM
168 window_system_available (struct frame
*f
)
170 return f
? FRAME_WINDOW_P (f
) || FRAME_MSDOS_P (f
) : x_display_list
!= NULL
;
173 #endif /* HAVE_WINDOW_SYSTEM */
176 decode_window_system_frame (Lisp_Object frame
)
178 struct frame
*f
= decode_live_frame (frame
);
180 if (!window_system_available (f
))
181 error ("Window system frame should be used");
186 check_window_system (struct frame
*f
)
188 if (!window_system_available (f
))
189 error (f
? "Window system frame should be used"
190 : "Window system is not in use or not initialized");
194 set_menu_bar_lines_1 (Lisp_Object window
, int n
)
196 struct window
*w
= XWINDOW (window
);
197 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
200 w
->pixel_top
+= n
* FRAME_LINE_HEIGHT (f
);
202 w
->pixel_height
-= n
* FRAME_LINE_HEIGHT (f
);
204 /* Handle just the top child in a vertical split. */
205 if (WINDOW_VERTICAL_COMBINATION_P (w
))
206 set_menu_bar_lines_1 (w
->contents
, n
);
207 else if (WINDOW_HORIZONTAL_COMBINATION_P (w
))
208 /* Adjust all children in a horizontal split. */
209 for (window
= w
->contents
; !NILP (window
); window
= w
->next
)
211 w
= XWINDOW (window
);
212 set_menu_bar_lines_1 (window
, n
);
217 set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
220 int olines
= FRAME_MENU_BAR_LINES (f
);
222 /* Right now, menu bars don't work properly in minibuf-only frames;
223 most of the commands try to apply themselves to the minibuffer
224 frame itself, and get an error because you can't switch buffers
225 in or split the minibuffer window. */
226 if (FRAME_MINIBUF_ONLY_P (f
))
229 if (TYPE_RANGED_INTEGERP (int, value
))
230 nlines
= XINT (value
);
234 if (nlines
!= olines
)
236 windows_or_buffers_changed
= 14;
237 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
238 FRAME_MENU_BAR_LINES (f
) = nlines
;
239 FRAME_MENU_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
240 set_menu_bar_lines_1 (f
->root_window
, nlines
- olines
);
241 adjust_frame_glyphs (f
);
245 Lisp_Object Vframe_list
;
248 DEFUN ("framep", Fframep
, Sframep
, 1, 1, 0,
249 doc
: /* Return non-nil if OBJECT is a frame.
251 t for a termcap frame (a character-only terminal),
252 'x' for an Emacs frame that is really an X window,
253 'w32' for an Emacs frame that is a window on MS-Windows display,
254 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
255 'pc' for a direct-write MS-DOS frame.
256 See also `frame-live-p'. */)
259 if (!FRAMEP (object
))
261 switch (XFRAME (object
)->output_method
)
263 case output_initial
: /* The initial frame is like a termcap frame. */
266 case output_x_window
:
270 case output_msdos_raw
:
279 DEFUN ("frame-live-p", Fframe_live_p
, Sframe_live_p
, 1, 1, 0,
280 doc
: /* Return non-nil if OBJECT is a frame which has not been deleted.
281 Value is nil if OBJECT is not a live frame. If object is a live
282 frame, the return value indicates what sort of terminal device it is
283 displayed on. See the documentation of `framep' for possible
287 return ((FRAMEP (object
)
288 && FRAME_LIVE_P (XFRAME (object
)))
293 DEFUN ("window-system", Fwindow_system
, Swindow_system
, 0, 1, 0,
294 doc
: /* The name of the window system that FRAME is displaying through.
295 The value is a symbol:
296 nil for a termcap frame (a character-only terminal),
297 'x' for an Emacs frame that is really an X window,
298 'w32' for an Emacs frame that is a window on MS-Windows display,
299 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
300 'pc' for a direct-write MS-DOS frame.
302 FRAME defaults to the currently selected frame.
304 Use of this function as a predicate is deprecated. Instead,
305 use `display-graphic-p' or any of the other `display-*-p'
306 predicates which report frame's specific UI-related capabilities. */)
311 frame
= selected_frame
;
313 type
= Fframep (frame
);
316 wrong_type_argument (Qframep
, frame
);
325 make_frame (bool mini_p
)
328 register struct frame
*f
;
329 register struct window
*rw
, *mw
;
330 register Lisp_Object root_window
;
331 register Lisp_Object mini_window
;
333 f
= allocate_frame ();
334 XSETFRAME (frame
, f
);
336 /* Initialize Lisp data. Note that allocate_frame initializes all
337 Lisp data to nil, so do it only for slots which should not be nil. */
338 fset_tool_bar_position (f
, Qtop
);
340 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
341 non-Lisp data, so do it only for slots which should not be zero.
342 To avoid subtle bugs and for the sake of readability, it's better to
343 initialize enum members explicitly even if their values are zero. */
344 f
->wants_modeline
= true;
347 f
->vertical_scroll_bar_type
= vertical_scroll_bar_none
;
348 f
->column_width
= 1; /* !FRAME_WINDOW_P value. */
349 f
->line_height
= 1; /* !FRAME_WINDOW_P value. */
350 #ifdef HAVE_WINDOW_SYSTEM
351 f
->want_fullscreen
= FULLSCREEN_NONE
;
352 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
353 f
->last_tool_bar_item
= -1;
357 root_window
= make_window ();
358 rw
= XWINDOW (root_window
);
361 mini_window
= make_window ();
362 mw
= XWINDOW (mini_window
);
363 wset_next (rw
, mini_window
);
364 wset_prev (mw
, root_window
);
366 wset_frame (mw
, frame
);
367 fset_minibuffer_window (f
, mini_window
);
372 wset_next (rw
, Qnil
);
373 fset_minibuffer_window (f
, Qnil
);
376 wset_frame (rw
, frame
);
379 just so that there is "something there."
380 Correct size will be set up later with change_frame_size. */
382 SET_FRAME_COLS (f
, 10);
383 FRAME_LINES (f
) = 10;
384 SET_FRAME_WIDTH (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
385 SET_FRAME_HEIGHT (f
, FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
));
388 rw
->pixel_width
= rw
->total_cols
* FRAME_COLUMN_WIDTH (f
);
389 rw
->total_lines
= mini_p
? 9 : 10;
390 rw
->pixel_height
= rw
->total_lines
* FRAME_LINE_HEIGHT (f
);
394 mw
->top_line
= rw
->total_lines
;
395 mw
->pixel_top
= rw
->pixel_height
;
396 mw
->total_cols
= rw
->total_cols
;
397 mw
->pixel_width
= rw
->pixel_width
;
399 mw
->pixel_height
= FRAME_LINE_HEIGHT (f
);
402 /* Choose a buffer for the frame's root window. */
404 Lisp_Object buf
= Fcurrent_buffer ();
406 /* If current buffer is hidden, try to find another one. */
407 if (BUFFER_HIDDEN_P (XBUFFER (buf
)))
408 buf
= other_buffer_safely (buf
);
410 /* Use set_window_buffer, not Fset_window_buffer, and don't let
411 hooks be run by it. The reason is that the whole frame/window
412 arrangement is not yet fully initialized at this point. Windows
413 don't have the right size, glyph matrices aren't initialized
414 etc. Running Lisp functions at this point surely ends in a
416 set_window_buffer (root_window
, buf
, 0, 0);
417 fset_buffer_list (f
, list1 (buf
));
421 set_window_buffer (mini_window
,
422 (NILP (Vminibuffer_list
)
424 : Fcar (Vminibuffer_list
)),
427 fset_root_window (f
, root_window
);
428 fset_selected_window (f
, root_window
);
429 /* Make sure this window seems more recently used than
430 a newly-created, never-selected window. */
431 XWINDOW (f
->selected_window
)->use_time
= ++window_select_count
;
436 #ifdef HAVE_WINDOW_SYSTEM
437 /* Make a frame using a separate minibuffer window on another frame.
438 MINI_WINDOW is the minibuffer window to use. nil means use the
439 default (the global minibuffer). */
442 make_frame_without_minibuffer (register Lisp_Object mini_window
, KBOARD
*kb
, Lisp_Object display
)
444 register struct frame
*f
;
447 if (!NILP (mini_window
))
448 CHECK_LIVE_WINDOW (mini_window
);
450 if (!NILP (mini_window
)
451 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window
)->frame
)) != kb
)
452 error ("Frame and minibuffer must be on the same terminal");
454 /* Make a frame containing just a root window. */
457 if (NILP (mini_window
))
459 /* Use default-minibuffer-frame if possible. */
460 if (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
461 || ! FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
))))
463 Lisp_Object frame_dummy
;
465 XSETFRAME (frame_dummy
, f
);
466 GCPRO1 (frame_dummy
);
467 /* If there's no minibuffer frame to use, create one. */
468 kset_default_minibuffer_frame
469 (kb
, call1 (intern ("make-initial-minibuffer-frame"), display
));
474 = XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
))->minibuffer_window
;
477 fset_minibuffer_window (f
, mini_window
);
479 /* Make the chosen minibuffer window display the proper minibuffer,
480 unless it is already showing a minibuffer. */
481 if (NILP (Fmemq (XWINDOW (mini_window
)->contents
, Vminibuffer_list
)))
482 /* Use set_window_buffer instead of Fset_window_buffer (see
483 discussion of bug#11984, bug#12025, bug#12026). */
484 set_window_buffer (mini_window
,
485 (NILP (Vminibuffer_list
)
487 : Fcar (Vminibuffer_list
)), 0, 0);
491 /* Make a frame containing only a minibuffer window. */
494 make_minibuffer_frame (void)
496 /* First make a frame containing just a root window, no minibuffer. */
498 register struct frame
*f
= make_frame (0);
499 register Lisp_Object mini_window
;
500 register Lisp_Object frame
;
502 XSETFRAME (frame
, f
);
507 f
->wants_modeline
= 0;
509 /* Now label the root window as also being the minibuffer.
510 Avoid infinite looping on the window chain by marking next pointer
513 mini_window
= f
->root_window
;
514 fset_minibuffer_window (f
, mini_window
);
515 XWINDOW (mini_window
)->mini
= 1;
516 wset_next (XWINDOW (mini_window
), Qnil
);
517 wset_prev (XWINDOW (mini_window
), Qnil
);
518 wset_frame (XWINDOW (mini_window
), frame
);
520 /* Put the proper buffer in that window. */
522 /* Use set_window_buffer instead of Fset_window_buffer (see
523 discussion of bug#11984, bug#12025, bug#12026). */
524 set_window_buffer (mini_window
,
525 (NILP (Vminibuffer_list
)
527 : Fcar (Vminibuffer_list
)), 0, 0);
530 #endif /* HAVE_WINDOW_SYSTEM */
532 /* Construct a frame that refers to a terminal. */
534 static printmax_t tty_frame_count
;
537 make_initial_frame (void)
540 struct terminal
*terminal
;
543 eassert (initial_kboard
);
545 /* The first call must initialize Vframe_list. */
546 if (! (NILP (Vframe_list
) || CONSP (Vframe_list
)))
549 terminal
= init_initial_terminal ();
552 XSETFRAME (frame
, f
);
554 Vframe_list
= Fcons (frame
, Vframe_list
);
557 fset_name (f
, build_pure_c_string ("F1"));
559 SET_FRAME_VISIBLE (f
, 1);
561 f
->output_method
= terminal
->type
;
562 f
->terminal
= terminal
;
563 f
->terminal
->reference_count
++;
564 f
->output_data
.nothing
= 0;
566 FRAME_FOREGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_FG_COLOR
;
567 FRAME_BACKGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_BG_COLOR
;
569 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
;
571 /* The default value of menu-bar-mode is t. */
572 set_menu_bar_lines (f
, make_number (1), Qnil
);
575 init_frame_faces (f
);
577 last_nonminibuf_frame
= f
;
583 static struct frame
*
584 make_terminal_frame (struct terminal
*terminal
)
586 register struct frame
*f
;
588 char name
[sizeof "F" + INT_STRLEN_BOUND (printmax_t
)];
591 error ("Terminal is not live, can't create new frames on it");
595 XSETFRAME (frame
, f
);
596 Vframe_list
= Fcons (frame
, Vframe_list
);
598 fset_name (f
, make_formatted_string (name
, "F%"pMd
, ++tty_frame_count
));
600 SET_FRAME_VISIBLE (f
, 1);
602 f
->terminal
= terminal
;
603 f
->terminal
->reference_count
++;
605 f
->output_data
.tty
->display_info
= &the_only_display_info
;
606 if (!inhibit_window_system
607 && (!FRAMEP (selected_frame
) || !FRAME_LIVE_P (XFRAME (selected_frame
))
608 || XFRAME (selected_frame
)->output_method
== output_msdos_raw
))
609 f
->output_method
= output_msdos_raw
;
611 f
->output_method
= output_termcap
;
612 #else /* not MSDOS */
613 f
->output_method
= output_termcap
;
614 create_tty_output (f
);
615 FRAME_FOREGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_FG_COLOR
;
616 FRAME_BACKGROUND_PIXEL (f
) = FACE_TTY_DEFAULT_BG_COLOR
;
617 #endif /* not MSDOS */
619 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
;
620 FRAME_MENU_BAR_LINES (f
) = NILP (Vmenu_bar_mode
) ? 0 : 1;
621 FRAME_MENU_BAR_HEIGHT (f
) = FRAME_MENU_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
);
623 /* Set the top frame to the newly created frame. */
624 if (FRAMEP (FRAME_TTY (f
)->top_frame
)
625 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f
)->top_frame
)))
626 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f
)->top_frame
), 2); /* obscured */
628 FRAME_TTY (f
)->top_frame
= frame
;
631 init_frame_faces (f
);
636 /* Get a suitable value for frame parameter PARAMETER for a newly
637 created frame, based on (1) the user-supplied frame parameter
638 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
641 get_future_frame_param (Lisp_Object parameter
,
642 Lisp_Object supplied_parms
,
647 result
= Fassq (parameter
, supplied_parms
);
649 result
= Fassq (parameter
, XFRAME (selected_frame
)->param_alist
);
650 if (NILP (result
) && current_value
!= NULL
)
651 result
= build_string (current_value
);
652 if (!NILP (result
) && !STRINGP (result
))
653 result
= XCDR (result
);
654 if (NILP (result
) || !STRINGP (result
))
660 DEFUN ("make-terminal-frame", Fmake_terminal_frame
, Smake_terminal_frame
,
662 doc
: /* Create an additional terminal frame, possibly on another terminal.
663 This function takes one argument, an alist specifying frame parameters.
665 You can create multiple frames on a single text terminal, but only one
666 of them (the selected terminal frame) is actually displayed.
668 In practice, generally you don't need to specify any parameters,
669 except when you want to create a new frame on another terminal.
670 In that case, the `tty' parameter specifies the device file to open,
671 and the `tty-type' parameter specifies the terminal type. Example:
673 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
675 Note that changing the size of one terminal frame automatically
676 affects all frames on the same terminal device. */)
680 struct terminal
*t
= NULL
;
681 Lisp_Object frame
, tem
;
682 struct frame
*sf
= SELECTED_FRAME ();
685 if (sf
->output_method
!= output_msdos_raw
686 && sf
->output_method
!= output_termcap
)
688 #else /* not MSDOS */
690 #ifdef WINDOWSNT /* This should work now! */
691 if (sf
->output_method
!= output_termcap
)
692 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
694 #endif /* not MSDOS */
697 Lisp_Object terminal
;
699 terminal
= Fassq (Qterminal
, parms
);
700 if (CONSP (terminal
))
702 terminal
= XCDR (terminal
);
703 t
= get_terminal (terminal
, 1);
706 if (t
&& t
!= the_only_display_info
.terminal
)
707 /* msdos.c assumes a single tty_display_info object. */
708 error ("Multiple terminals are not supported on this platform");
710 t
= the_only_display_info
.terminal
;
716 char *name
= 0, *type
= 0;
717 Lisp_Object tty
, tty_type
;
719 tty
= get_future_frame_param
720 (Qtty
, parms
, (FRAME_TERMCAP_P (XFRAME (selected_frame
))
721 ? FRAME_TTY (XFRAME (selected_frame
))->name
724 name
= xlispstrdupa (tty
);
726 tty_type
= get_future_frame_param
727 (Qtty_type
, parms
, (FRAME_TERMCAP_P (XFRAME (selected_frame
))
728 ? FRAME_TTY (XFRAME (selected_frame
))->type
730 if (!NILP (tty_type
))
731 type
= xlispstrdupa (tty_type
);
733 t
= init_tty (name
, type
, 0); /* Errors are not fatal. */
736 f
= make_terminal_frame (t
);
740 get_tty_size (fileno (FRAME_TTY (f
)->input
), &width
, &height
);
741 change_frame_size (f
, width
, height
, 0, 0, 0, 0);
744 adjust_frame_glyphs (f
);
746 XSETFRAME (frame
, f
);
748 store_in_alist (&parms
, Qtty_type
, build_string (t
->display_info
.tty
->type
));
749 store_in_alist (&parms
, Qtty
,
750 (t
->display_info
.tty
->name
751 ? build_string (t
->display_info
.tty
->name
)
753 Fmodify_frame_parameters (frame
, parms
);
755 /* Make the frame face alist be frame-specific, so that each
756 frame could change its face definitions independently. */
757 fset_face_alist (f
, Fcopy_alist (sf
->face_alist
));
758 /* Simple Fcopy_alist isn't enough, because we need the contents of
759 the vectors which are the CDRs of associations in face_alist to
760 be copied as well. */
761 for (tem
= f
->face_alist
; CONSP (tem
); tem
= XCDR (tem
))
762 XSETCDR (XCAR (tem
), Fcopy_sequence (XCDR (XCAR (tem
))));
767 /* Perform the switch to frame FRAME.
769 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
772 If TRACK is non-zero and the frame that currently has the focus
773 redirects its focus to the selected frame, redirect that focused
774 frame's focus to FRAME instead.
776 FOR_DELETION non-zero means that the selected frame is being
777 deleted, which includes the possibility that the frame's terminal
780 The value of NORECORD is passed as argument to Fselect_window. */
783 do_switch_frame (Lisp_Object frame
, int track
, int for_deletion
, Lisp_Object norecord
)
785 struct frame
*sf
= SELECTED_FRAME ();
787 /* If FRAME is a switch-frame event, extract the frame we should
790 && EQ (XCAR (frame
), Qswitch_frame
)
791 && CONSP (XCDR (frame
)))
792 frame
= XCAR (XCDR (frame
));
794 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
795 a switch-frame event to arrive after a frame is no longer live,
796 especially when deleting the initial frame during startup. */
798 if (! FRAME_LIVE_P (XFRAME (frame
)))
801 if (sf
== XFRAME (frame
))
804 /* If a frame's focus has been redirected toward the currently
805 selected frame, we should change the redirection to point to the
806 newly selected frame. This means that if the focus is redirected
807 from a minibufferless frame to a surrogate minibuffer frame, we
808 can use `other-window' to switch between all the frames using
809 that minibuffer frame, and the focus redirection will follow us
812 /* This is too greedy; it causes inappropriate focus redirection
813 that's hard to get rid of. */
818 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
822 if (!FRAMEP (XCAR (tail
)))
825 focus
= FRAME_FOCUS_FRAME (XFRAME (XCAR (tail
)));
827 if (FRAMEP (focus
) && XFRAME (focus
) == SELECTED_FRAME ())
828 Fredirect_frame_focus (XCAR (tail
), frame
);
832 /* Instead, apply it only to the frame we're pointing to. */
833 #ifdef HAVE_WINDOW_SYSTEM
834 if (track
&& FRAME_WINDOW_P (XFRAME (frame
)))
836 Lisp_Object focus
, xfocus
;
838 xfocus
= x_get_focus_frame (XFRAME (frame
));
841 focus
= FRAME_FOCUS_FRAME (XFRAME (xfocus
));
842 if (FRAMEP (focus
) && XFRAME (focus
) == SELECTED_FRAME ())
843 Fredirect_frame_focus (xfocus
, frame
);
846 #endif /* HAVE_X_WINDOWS */
849 if (!for_deletion
&& FRAME_HAS_MINIBUF_P (sf
))
850 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf
)), 1);
852 if (FRAME_TERMCAP_P (XFRAME (frame
)) || FRAME_MSDOS_P (XFRAME (frame
)))
854 Lisp_Object top_frame
= FRAME_TTY (XFRAME (frame
))->top_frame
;
856 /* Don't mark the frame garbaged and/or obscured if we are
857 switching to the frame that is already the top frame of that
859 if (!EQ (frame
, top_frame
))
861 if (FRAMEP (top_frame
))
862 /* Mark previously displayed frame as now obscured. */
863 SET_FRAME_VISIBLE (XFRAME (top_frame
), 2);
864 SET_FRAME_VISIBLE (XFRAME (frame
), 1);
866 FRAME_TTY (XFRAME (frame
))->top_frame
= frame
;
869 selected_frame
= frame
;
870 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame
)))
871 last_nonminibuf_frame
= XFRAME (selected_frame
);
873 Fselect_window (XFRAME (frame
)->selected_window
, norecord
);
875 /* We want to make sure that the next event generates a frame-switch
876 event to the appropriate frame. This seems kludgy to me, but
877 before you take it out, make sure that evaluating something like
878 (select-window (frame-root-window (new-frame))) doesn't end up
879 with your typing being interpreted in the new frame instead of
880 the one you're actually typing in. */
881 internal_last_event_frame
= Qnil
;
886 DEFUN ("select-frame", Fselect_frame
, Sselect_frame
, 1, 2, "e",
887 doc
: /* Select FRAME.
888 Subsequent editing commands apply to its selected window.
889 Optional argument NORECORD means to neither change the order of
890 recently selected windows nor the buffer list.
892 The selection of FRAME lasts until the next time the user does
893 something to select a different frame, or until the next time
894 this function is called. If you are using a window system, the
895 previously selected frame may be restored as the selected frame
896 when returning to the command loop, because it still may have
897 the window system's input focus. On a text terminal, the next
898 redisplay will display FRAME.
900 This function returns FRAME, or nil if FRAME has been deleted. */)
901 (Lisp_Object frame
, Lisp_Object norecord
)
903 return do_switch_frame (frame
, 1, 0, norecord
);
906 DEFUN ("handle-switch-frame", Fhandle_switch_frame
, Shandle_switch_frame
, 1, 1, "e",
907 doc
: /* Handle a switch-frame event EVENT.
908 Switch-frame events are usually bound to this function.
909 A switch-frame event tells Emacs that the window manager has requested
910 that the user's events be directed to the frame mentioned in the event.
911 This function selects the selected window of the frame of EVENT.
913 If EVENT is frame object, handle it as if it were a switch-frame event
917 /* Preserve prefix arg that the command loop just cleared. */
918 kset_prefix_arg (current_kboard
, Vcurrent_prefix_arg
);
919 Frun_hooks (1, &Qmouse_leave_buffer_hook
);
920 /* `switch-frame' implies a focus in. */
921 call1 (intern ("handle-focus-in"), event
);
922 return do_switch_frame (event
, 0, 0, Qnil
);
925 DEFUN ("selected-frame", Fselected_frame
, Sselected_frame
, 0, 0, 0,
926 doc
: /* Return the frame that is now selected. */)
929 return selected_frame
;
932 DEFUN ("frame-list", Fframe_list
, Sframe_list
,
934 doc
: /* Return a list of all live frames. */)
938 frames
= Fcopy_sequence (Vframe_list
);
939 #ifdef HAVE_WINDOW_SYSTEM
940 if (FRAMEP (tip_frame
))
941 frames
= Fdelq (tip_frame
, frames
);
946 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
947 same tty (for tty frames) or among frames which uses FRAME's keyboard.
948 If MINIBUF is nil, do not consider minibuffer-only candidate.
949 If MINIBUF is `visible', do not consider an invisible candidate.
950 If MINIBUF is a window, consider only its own frame and candidate now
951 using that window as the minibuffer.
952 If MINIBUF is 0, consider candidate if it is visible or iconified.
953 Otherwise consider any candidate and return nil if CANDIDATE is not
957 candidate_frame (Lisp_Object candidate
, Lisp_Object frame
, Lisp_Object minibuf
)
959 struct frame
*c
= XFRAME (candidate
), *f
= XFRAME (frame
);
961 if ((!FRAME_TERMCAP_P (c
) && !FRAME_TERMCAP_P (f
)
962 && FRAME_KBOARD (c
) == FRAME_KBOARD (f
))
963 || (FRAME_TERMCAP_P (c
) && FRAME_TERMCAP_P (f
)
964 && FRAME_TTY (c
) == FRAME_TTY (f
)))
968 if (!FRAME_MINIBUF_ONLY_P (c
))
971 else if (EQ (minibuf
, Qvisible
))
973 if (FRAME_VISIBLE_P (c
))
976 else if (WINDOWP (minibuf
))
978 if (EQ (FRAME_MINIBUF_WINDOW (c
), minibuf
)
979 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)), candidate
)
980 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)),
981 FRAME_FOCUS_FRAME (c
)))
984 else if (XFASTINT (minibuf
) == 0)
986 if (FRAME_VISIBLE_P (c
) || FRAME_ICONIFIED_P (c
))
995 /* Return the next frame in the frame list after FRAME. */
998 next_frame (Lisp_Object frame
, Lisp_Object minibuf
)
1000 Lisp_Object f
, tail
;
1003 /* There must always be at least one frame in Vframe_list. */
1004 eassert (CONSP (Vframe_list
));
1007 FOR_EACH_FRAME (tail
, f
)
1011 f
= candidate_frame (f
, frame
, minibuf
);
1021 /* Return the previous frame in the frame list before FRAME. */
1024 prev_frame (Lisp_Object frame
, Lisp_Object minibuf
)
1026 Lisp_Object f
, tail
, prev
= Qnil
;
1028 /* There must always be at least one frame in Vframe_list. */
1029 eassert (CONSP (Vframe_list
));
1031 FOR_EACH_FRAME (tail
, f
)
1033 if (EQ (frame
, f
) && !NILP (prev
))
1035 f
= candidate_frame (f
, frame
, minibuf
);
1040 /* We've scanned the entire list. */
1042 /* We went through the whole frame list without finding a single
1043 acceptable frame. Return the original frame. */
1046 /* There were no acceptable frames in the list before FRAME; otherwise,
1047 we would have returned directly from the loop. Since PREV is the last
1048 acceptable frame in the list, return it. */
1053 DEFUN ("next-frame", Fnext_frame
, Snext_frame
, 0, 2, 0,
1054 doc
: /* Return the next frame in the frame list after FRAME.
1055 It considers only frames on the same terminal as FRAME.
1056 By default, skip minibuffer-only frames.
1057 If omitted, FRAME defaults to the selected frame.
1058 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1059 If MINIFRAME is a window, include only its own frame
1060 and any frame now using that window as the minibuffer.
1061 If MINIFRAME is `visible', include all visible frames.
1062 If MINIFRAME is 0, include all visible and iconified frames.
1063 Otherwise, include all frames. */)
1064 (Lisp_Object frame
, Lisp_Object miniframe
)
1067 frame
= selected_frame
;
1068 CHECK_LIVE_FRAME (frame
);
1069 return next_frame (frame
, miniframe
);
1072 DEFUN ("previous-frame", Fprevious_frame
, Sprevious_frame
, 0, 2, 0,
1073 doc
: /* Return the previous frame in the frame list before 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 prev_frame (frame
, miniframe
);
1091 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame
,
1092 Slast_nonminibuf_frame
, 0, 0, 0,
1093 doc
: /* Return last non-minibuffer frame selected. */)
1096 Lisp_Object frame
= Qnil
;
1098 if (last_nonminibuf_frame
)
1099 XSETFRAME (frame
, last_nonminibuf_frame
);
1104 /* Return 1 if it is ok to delete frame F;
1105 0 if all frames aside from F are invisible.
1106 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1109 other_visible_frames (struct frame
*f
)
1111 Lisp_Object frames
, this;
1113 FOR_EACH_FRAME (frames
, this)
1115 if (f
== XFRAME (this))
1118 /* Verify that we can still talk to the frame's X window,
1119 and note any recent change in visibility. */
1120 #ifdef HAVE_X_WINDOWS
1121 if (FRAME_WINDOW_P (XFRAME (this)))
1122 x_sync (XFRAME (this));
1125 if (FRAME_VISIBLE_P (XFRAME (this))
1126 || FRAME_ICONIFIED_P (XFRAME (this))
1127 /* Allow deleting the terminal frame when at least one X
1129 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f
)))
1135 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1136 window. Preferably use the selected frame's minibuffer window
1137 instead. If the selected frame doesn't have one, get some other
1138 frame's minibuffer window. SELECT non-zero means select the new
1139 minibuffer window. */
1141 check_minibuf_window (Lisp_Object frame
, int select
)
1143 struct frame
*f
= decode_live_frame (frame
);
1145 XSETFRAME (frame
, f
);
1147 if (WINDOWP (minibuf_window
) && EQ (f
->minibuffer_window
, minibuf_window
))
1149 Lisp_Object frames
, this, window
= make_number (0);
1151 if (!EQ (frame
, selected_frame
)
1152 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame
)))
1153 window
= FRAME_MINIBUF_WINDOW (XFRAME (selected_frame
));
1155 FOR_EACH_FRAME (frames
, this)
1157 if (!EQ (this, frame
) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1159 window
= FRAME_MINIBUF_WINDOW (XFRAME (this));
1164 /* Don't abort if no window was found (Bug#15247). */
1165 if (WINDOWP (window
))
1167 /* Use set_window_buffer instead of Fset_window_buffer (see
1168 discussion of bug#11984, bug#12025, bug#12026). */
1169 set_window_buffer (window
, XWINDOW (minibuf_window
)->contents
, 0, 0);
1170 minibuf_window
= window
;
1172 /* SELECT non-zero usually means that FRAME's minibuffer
1173 window was selected; select the new one. */
1175 Fselect_window (minibuf_window
, Qnil
);
1181 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1182 unconditionally. x_connection_closed and delete_terminal use
1183 this. Any other value of FORCE implements the semantics
1184 described for Fdelete_frame. */
1186 delete_frame (Lisp_Object frame
, Lisp_Object force
)
1188 struct frame
*f
= decode_any_frame (frame
);
1192 int minibuffer_selected
, is_tooltip_frame
;
1194 if (! FRAME_LIVE_P (f
))
1197 if (NILP (force
) && !other_visible_frames (f
))
1198 error ("Attempt to delete the sole visible or iconified frame");
1200 /* x_connection_closed must have set FORCE to `noelisp' in order
1201 to delete the last frame, if it is gone. */
1202 if (NILP (XCDR (Vframe_list
)) && !EQ (force
, Qnoelisp
))
1203 error ("Attempt to delete the only frame");
1205 XSETFRAME (frame
, f
);
1207 /* Does this frame have a minibuffer, and is it the surrogate
1208 minibuffer for any other frame? */
1209 if (FRAME_HAS_MINIBUF_P (f
))
1211 Lisp_Object frames
, this;
1213 FOR_EACH_FRAME (frames
, this)
1217 if (EQ (this, frame
))
1220 fminiw
= FRAME_MINIBUF_WINDOW (XFRAME (this));
1222 if (WINDOWP (fminiw
) && EQ (frame
, WINDOW_FRAME (XWINDOW (fminiw
))))
1224 /* If we MUST delete this frame, delete the other first.
1225 But do this only if FORCE equals `noelisp'. */
1226 if (EQ (force
, Qnoelisp
))
1227 delete_frame (this, Qnoelisp
);
1229 error ("Attempt to delete a surrogate minibuffer frame");
1234 is_tooltip_frame
= !NILP (Fframe_parameter (frame
, intern ("tooltip")));
1236 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1237 frame is a tooltip. FORCE is set to `noelisp' when handling
1238 a disconnect from the terminal, so we don't dare call Lisp
1240 if (NILP (Vrun_hooks
) || is_tooltip_frame
)
1242 else if (EQ (force
, Qnoelisp
))
1244 = Fcons (list3 (Qrun_hook_with_args
, Qdelete_frame_functions
, frame
),
1248 #ifdef HAVE_X_WINDOWS
1249 /* Also, save clipboard to the clipboard manager. */
1250 x_clipboard_manager_save_frame (frame
);
1253 safe_call2 (Qrun_hook_with_args
, Qdelete_frame_functions
, frame
);
1256 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1257 if (! FRAME_LIVE_P (f
))
1260 /* At this point, we are committed to deleting the frame.
1261 There is no more chance for errors to prevent it. */
1263 minibuffer_selected
= EQ (minibuf_window
, selected_window
);
1264 sf
= SELECTED_FRAME ();
1265 /* Don't let the frame remain selected. */
1269 Lisp_Object frame1
= Qnil
;
1271 /* Look for another visible frame on the same terminal.
1272 Do not call next_frame here because it may loop forever.
1273 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1274 FOR_EACH_FRAME (tail
, frame1
)
1275 if (!EQ (frame
, frame1
)
1276 && (FRAME_TERMINAL (XFRAME (frame
))
1277 == FRAME_TERMINAL (XFRAME (frame1
)))
1278 && FRAME_VISIBLE_P (XFRAME (frame1
)))
1281 /* If there is none, find *some* other frame. */
1282 if (NILP (frame1
) || EQ (frame1
, frame
))
1284 FOR_EACH_FRAME (tail
, frame1
)
1286 if (! EQ (frame
, frame1
) && FRAME_LIVE_P (XFRAME (frame1
)))
1288 /* Do not change a text terminal's top-frame. */
1289 struct frame
*f1
= XFRAME (frame1
);
1290 if (FRAME_TERMCAP_P (f1
) || FRAME_MSDOS_P (f1
))
1292 Lisp_Object top_frame
= FRAME_TTY (f1
)->top_frame
;
1293 if (!EQ (top_frame
, frame
))
1300 #ifdef NS_IMPL_COCOA
1302 /* Under NS, there is no system mechanism for choosing a new
1303 window to get focus -- it is left to application code.
1304 So the portion of THIS application interfacing with NS
1305 needs to know about it. We call Fraise_frame, but the
1306 purpose is really to transfer focus. */
1307 Fraise_frame (frame1
);
1310 do_switch_frame (frame1
, 0, 1, Qnil
);
1311 sf
= SELECTED_FRAME ();
1314 /* Don't allow minibuf_window to remain on a deleted frame. */
1315 check_minibuf_window (frame
, minibuffer_selected
);
1317 /* Don't let echo_area_window to remain on a deleted frame. */
1318 if (EQ (f
->minibuffer_window
, echo_area_window
))
1319 echo_area_window
= sf
->minibuffer_window
;
1321 /* Clear any X selections for this frame. */
1322 #ifdef HAVE_X_WINDOWS
1324 x_clear_frame_selections (f
);
1328 This function must be called before the window tree of the
1329 frame is deleted because windows contain dynamically allocated
1333 #ifdef HAVE_WINDOW_SYSTEM
1334 /* Give chance to each font driver to free a frame specific data. */
1335 font_update_drivers (f
, Qnil
);
1338 /* Mark all the windows that used to be on FRAME as deleted, and then
1339 remove the reference to them. */
1340 delete_all_child_windows (f
->root_window
);
1341 fset_root_window (f
, Qnil
);
1343 Vframe_list
= Fdelq (frame
, Vframe_list
);
1344 SET_FRAME_VISIBLE (f
, 0);
1346 /* Allow the vector of menu bar contents to be freed in the next
1347 garbage collection. The frame object itself may not be garbage
1348 collected until much later, because recent_keys and other data
1349 structures can still refer to it. */
1350 fset_menu_bar_vector (f
, Qnil
);
1352 /* If FRAME's buffer lists contains killed
1353 buffers, this helps GC to reclaim them. */
1354 fset_buffer_list (f
, Qnil
);
1355 fset_buried_buffer_list (f
, Qnil
);
1357 free_font_driver_list (f
);
1359 xfree (f
->decode_mode_spec_buffer
);
1360 xfree (FRAME_INSERT_COST (f
));
1361 xfree (FRAME_DELETEN_COST (f
));
1362 xfree (FRAME_INSERTN_COST (f
));
1363 xfree (FRAME_DELETE_COST (f
));
1365 /* Since some events are handled at the interrupt level, we may get
1366 an event for f at any time; if we zero out the frame's terminal
1367 now, then we may trip up the event-handling code. Instead, we'll
1368 promise that the terminal of the frame must be valid until we
1369 have called the window-system-dependent frame destruction
1374 struct terminal
*terminal
;
1376 if (FRAME_TERMINAL (f
)->delete_frame_hook
)
1377 (*FRAME_TERMINAL (f
)->delete_frame_hook
) (f
);
1378 terminal
= FRAME_TERMINAL (f
);
1379 f
->output_data
.nothing
= 0;
1380 f
->terminal
= 0; /* Now the frame is dead. */
1383 /* If needed, delete the terminal that this frame was on.
1384 (This must be done after the frame is killed.) */
1385 terminal
->reference_count
--;
1387 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1389 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1390 if (terminal
->reference_count
== 0 && terminal
->type
== output_x_window
)
1391 terminal
->reference_count
= 1;
1392 #endif /* USE_GTK */
1393 if (terminal
->reference_count
== 0)
1396 XSETTERMINAL (tmp
, terminal
);
1399 Fdelete_terminal (tmp
, NILP (force
) ? Qt
: force
);
1402 kb
= terminal
->kboard
;
1405 /* If we've deleted the last_nonminibuf_frame, then try to find
1407 if (f
== last_nonminibuf_frame
)
1409 Lisp_Object frames
, this;
1411 last_nonminibuf_frame
= 0;
1413 FOR_EACH_FRAME (frames
, this)
1416 if (!FRAME_MINIBUF_ONLY_P (f
))
1418 last_nonminibuf_frame
= f
;
1424 /* If there's no other frame on the same kboard, get out of
1425 single-kboard state if we're in it for this kboard. */
1428 Lisp_Object frames
, this;
1429 /* Some frame we found on the same kboard, or nil if there are none. */
1430 Lisp_Object frame_on_same_kboard
= Qnil
;
1432 FOR_EACH_FRAME (frames
, this)
1433 if (kb
== FRAME_KBOARD (XFRAME (this)))
1434 frame_on_same_kboard
= this;
1436 if (NILP (frame_on_same_kboard
))
1437 not_single_kboard_state (kb
);
1441 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1442 find another one. Prefer minibuffer-only frames, but also notice
1443 frames with other windows. */
1444 if (kb
!= NULL
&& EQ (frame
, KVAR (kb
, Vdefault_minibuffer_frame
)))
1446 Lisp_Object frames
, this;
1448 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1449 Lisp_Object frame_with_minibuf
= Qnil
;
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)
1455 struct frame
*f1
= XFRAME (this);
1457 /* Consider only frames on the same kboard
1458 and only those with minibuffers. */
1459 if (kb
== FRAME_KBOARD (f1
)
1460 && FRAME_HAS_MINIBUF_P (f1
))
1462 frame_with_minibuf
= this;
1463 if (FRAME_MINIBUF_ONLY_P (f1
))
1467 if (kb
== FRAME_KBOARD (f1
))
1468 frame_on_same_kboard
= this;
1471 if (!NILP (frame_on_same_kboard
))
1473 /* We know that there must be some frame with a minibuffer out
1474 there. If this were not true, all of the frames present
1475 would have to be minibufferless, which implies that at some
1476 point their minibuffer frames must have been deleted, but
1477 that is prohibited at the top; you can't delete surrogate
1478 minibuffer frames. */
1479 if (NILP (frame_with_minibuf
))
1482 kset_default_minibuffer_frame (kb
, frame_with_minibuf
);
1485 /* No frames left on this kboard--say no minibuffer either. */
1486 kset_default_minibuffer_frame (kb
, Qnil
);
1489 /* Cause frame titles to update--necessary if we now have just one frame. */
1490 if (!is_tooltip_frame
)
1491 update_mode_lines
= 15;
1496 DEFUN ("delete-frame", Fdelete_frame
, Sdelete_frame
, 0, 2, "",
1497 doc
: /* Delete FRAME, permanently eliminating it from use.
1498 FRAME defaults to the selected frame.
1500 A frame may not be deleted if its minibuffer is used by other frames.
1501 Normally, you may not delete a frame if all other frames are invisible,
1502 but if the second optional argument FORCE is non-nil, you may do so.
1504 This function runs `delete-frame-functions' before actually
1505 deleting the frame, unless the frame is a tooltip.
1506 The functions are run with one argument, the frame to be deleted. */)
1507 (Lisp_Object frame
, Lisp_Object force
)
1509 return delete_frame (frame
, !NILP (force
) ? Qt
: Qnil
);
1513 /* Return mouse position in character cell units. */
1515 DEFUN ("mouse-position", Fmouse_position
, Smouse_position
, 0, 0, 0,
1516 doc
: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1517 The position is given in character cells, where (0, 0) is the
1518 upper-left corner of the frame, X is the horizontal offset, and Y is
1519 the vertical offset.
1520 If Emacs is running on a mouseless terminal or hasn't been programmed
1521 to read the mouse position, it returns the selected frame for FRAME
1522 and nil for X and Y.
1523 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1524 passing the normal return value to that function as an argument,
1525 and returns whatever that function returns. */)
1529 Lisp_Object lispy_dummy
;
1530 Lisp_Object x
, y
, retval
;
1531 struct gcpro gcpro1
;
1533 f
= SELECTED_FRAME ();
1536 /* It's okay for the hook to refrain from storing anything. */
1537 if (FRAME_TERMINAL (f
)->mouse_position_hook
)
1539 enum scroll_bar_part party_dummy
;
1541 (*FRAME_TERMINAL (f
)->mouse_position_hook
) (&f
, -1,
1542 &lispy_dummy
, &party_dummy
,
1551 pixel_to_glyph_coords (f
, col
, row
, &col
, &row
, NULL
, 1);
1555 XSETFRAME (lispy_dummy
, f
);
1556 retval
= Fcons (lispy_dummy
, Fcons (x
, y
));
1558 if (!NILP (Vmouse_position_function
))
1559 retval
= call1 (Vmouse_position_function
, retval
);
1560 RETURN_UNGCPRO (retval
);
1563 DEFUN ("mouse-pixel-position", Fmouse_pixel_position
,
1564 Smouse_pixel_position
, 0, 0, 0,
1565 doc
: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1566 The position is given in pixel units, where (0, 0) is the
1567 upper-left corner of the frame, X is the horizontal offset, and Y is
1568 the vertical offset.
1569 If Emacs is running on a mouseless terminal or hasn't been programmed
1570 to read the mouse position, it returns the selected frame for FRAME
1571 and nil for X and Y. */)
1575 Lisp_Object lispy_dummy
;
1578 f
= SELECTED_FRAME ();
1581 /* It's okay for the hook to refrain from storing anything. */
1582 if (FRAME_TERMINAL (f
)->mouse_position_hook
)
1584 enum scroll_bar_part party_dummy
;
1586 (*FRAME_TERMINAL (f
)->mouse_position_hook
) (&f
, -1,
1587 &lispy_dummy
, &party_dummy
,
1592 XSETFRAME (lispy_dummy
, f
);
1593 return Fcons (lispy_dummy
, Fcons (x
, y
));
1596 #ifdef HAVE_WINDOW_SYSTEM
1598 /* On frame F, convert character coordinates X and Y to pixel
1599 coordinates *PIX_X and *PIX_Y. */
1602 frame_char_to_pixel_position (struct frame
*f
, int x
, int y
,
1603 int *pix_x
, int *pix_y
)
1605 *pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
1606 *pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
1610 if (*pix_x
> FRAME_PIXEL_WIDTH (f
))
1611 *pix_x
= FRAME_PIXEL_WIDTH (f
);
1615 if (*pix_y
> FRAME_PIXEL_HEIGHT (f
))
1616 *pix_y
= FRAME_PIXEL_HEIGHT (f
);
1619 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1622 frame_set_mouse_position (struct frame
*f
, int x
, int y
)
1626 frame_char_to_pixel_position (f
, x
, y
, &pix_x
, &pix_y
);
1627 frame_set_mouse_pixel_position (f
, pix_x
, pix_y
);
1630 #endif /* HAVE_WINDOW_SYSTEM */
1632 DEFUN ("set-mouse-position", Fset_mouse_position
, Sset_mouse_position
, 3, 3, 0,
1633 doc
: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1634 Coordinates are relative to the frame, not a window,
1635 so the coordinates of the top left character in the frame
1636 may be nonzero due to left-hand scroll bars or the menu bar.
1638 The position is given in character cells, where (0, 0) is the
1639 upper-left corner of the frame, X is the horizontal offset, and Y is
1640 the vertical offset.
1642 This function is a no-op for an X frame that is not visible.
1643 If you have just created a frame, you must wait for it to become visible
1644 before calling this function on it, like this.
1645 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1646 (Lisp_Object frame
, Lisp_Object x
, Lisp_Object y
)
1648 CHECK_LIVE_FRAME (frame
);
1649 CHECK_TYPE_RANGED_INTEGER (int, x
);
1650 CHECK_TYPE_RANGED_INTEGER (int, y
);
1652 /* I think this should be done with a hook. */
1653 #ifdef HAVE_WINDOW_SYSTEM
1654 if (FRAME_WINDOW_P (XFRAME (frame
)))
1655 /* Warping the mouse will cause enternotify and focus events. */
1656 frame_set_mouse_position (XFRAME (frame
), XINT (x
), XINT (y
));
1659 if (FRAME_MSDOS_P (XFRAME (frame
)))
1661 Fselect_frame (frame
, Qnil
);
1662 mouse_moveto (XINT (x
), XINT (y
));
1667 Fselect_frame (frame
, Qnil
);
1668 term_mouse_moveto (XINT (x
), XINT (y
));
1677 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position
,
1678 Sset_mouse_pixel_position
, 3, 3, 0,
1679 doc
: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1680 The position is given in pixels, where (0, 0) is the upper-left corner
1681 of the frame, X is the horizontal offset, and Y is the vertical offset.
1683 Note, this is a no-op for an X frame that is not visible.
1684 If you have just created a frame, you must wait for it to become visible
1685 before calling this function on it, like this.
1686 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1687 (Lisp_Object frame
, Lisp_Object x
, Lisp_Object y
)
1689 CHECK_LIVE_FRAME (frame
);
1690 CHECK_TYPE_RANGED_INTEGER (int, x
);
1691 CHECK_TYPE_RANGED_INTEGER (int, y
);
1693 /* I think this should be done with a hook. */
1694 #ifdef HAVE_WINDOW_SYSTEM
1695 if (FRAME_WINDOW_P (XFRAME (frame
)))
1696 /* Warping the mouse will cause enternotify and focus events. */
1697 frame_set_mouse_pixel_position (XFRAME (frame
), XINT (x
), XINT (y
));
1700 if (FRAME_MSDOS_P (XFRAME (frame
)))
1702 Fselect_frame (frame
, Qnil
);
1703 mouse_moveto (XINT (x
), XINT (y
));
1708 Fselect_frame (frame
, Qnil
);
1709 term_mouse_moveto (XINT (x
), XINT (y
));
1718 static void make_frame_visible_1 (Lisp_Object
);
1720 DEFUN ("make-frame-visible", Fmake_frame_visible
, Smake_frame_visible
,
1722 doc
: /* Make the frame FRAME visible (assuming it is an X window).
1723 If omitted, FRAME defaults to the currently selected frame. */)
1726 struct frame
*f
= decode_live_frame (frame
);
1728 /* I think this should be done with a hook. */
1729 #ifdef HAVE_WINDOW_SYSTEM
1730 if (FRAME_WINDOW_P (f
))
1731 x_make_frame_visible (f
);
1734 make_frame_visible_1 (f
->root_window
);
1736 /* Make menu bar update for the Buffers and Frames menus. */
1737 /* windows_or_buffers_changed = 15; FIXME: Why? */
1739 XSETFRAME (frame
, f
);
1743 /* Update the display_time slot of the buffers shown in WINDOW
1744 and all its descendants. */
1747 make_frame_visible_1 (Lisp_Object window
)
1751 for (; !NILP (window
); window
= w
->next
)
1753 w
= XWINDOW (window
);
1754 if (WINDOWP (w
->contents
))
1755 make_frame_visible_1 (w
->contents
);
1757 bset_display_time (XBUFFER (w
->contents
), Fcurrent_time ());
1761 DEFUN ("make-frame-invisible", Fmake_frame_invisible
, Smake_frame_invisible
,
1763 doc
: /* Make the frame FRAME invisible.
1764 If omitted, FRAME defaults to the currently selected frame.
1765 On graphical displays, invisible frames are not updated and are
1766 usually not displayed at all, even in a window system's \"taskbar\".
1768 Normally you may not make FRAME invisible if all other frames are invisible,
1769 but if the second optional argument FORCE is non-nil, you may do so.
1771 This function has no effect on text terminal frames. Such frames are
1772 always considered visible, whether or not they are currently being
1773 displayed in the terminal. */)
1774 (Lisp_Object frame
, Lisp_Object force
)
1776 struct frame
*f
= decode_live_frame (frame
);
1778 if (NILP (force
) && !other_visible_frames (f
))
1779 error ("Attempt to make invisible the sole visible or iconified frame");
1781 /* Don't allow minibuf_window to remain on an invisible frame. */
1782 check_minibuf_window (frame
, EQ (minibuf_window
, selected_window
));
1784 /* I think this should be done with a hook. */
1785 #ifdef HAVE_WINDOW_SYSTEM
1786 if (FRAME_WINDOW_P (f
))
1787 x_make_frame_invisible (f
);
1790 /* Make menu bar update for the Buffers and Frames menus. */
1791 windows_or_buffers_changed
= 16;
1796 DEFUN ("iconify-frame", Ficonify_frame
, Siconify_frame
,
1798 doc
: /* Make the frame FRAME into an icon.
1799 If omitted, FRAME defaults to the currently selected frame. */)
1802 struct frame
*f
= decode_live_frame (frame
);
1804 /* Don't allow minibuf_window to remain on an iconified frame. */
1805 check_minibuf_window (frame
, EQ (minibuf_window
, selected_window
));
1807 /* I think this should be done with a hook. */
1808 #ifdef HAVE_WINDOW_SYSTEM
1809 if (FRAME_WINDOW_P (f
))
1810 x_iconify_frame (f
);
1813 /* Make menu bar update for the Buffers and Frames menus. */
1814 windows_or_buffers_changed
= 17;
1819 DEFUN ("frame-visible-p", Fframe_visible_p
, Sframe_visible_p
,
1821 doc
: /* Return t if FRAME is \"visible\" (actually in use for display).
1822 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1823 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1824 On graphical displays, invisible frames are not updated and are
1825 usually not displayed at all, even in a window system's \"taskbar\".
1827 If FRAME is a text terminal frame, this always returns t.
1828 Such frames are always considered visible, whether or not they are
1829 currently being displayed on the terminal. */)
1832 CHECK_LIVE_FRAME (frame
);
1834 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1836 if (FRAME_ICONIFIED_P (XFRAME (frame
)))
1841 DEFUN ("visible-frame-list", Fvisible_frame_list
, Svisible_frame_list
,
1843 doc
: /* Return a list of all frames now \"visible\" (being updated). */)
1846 Lisp_Object tail
, frame
, value
= Qnil
;
1848 FOR_EACH_FRAME (tail
, frame
)
1849 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1850 value
= Fcons (frame
, value
);
1856 DEFUN ("raise-frame", Fraise_frame
, Sraise_frame
, 0, 1, "",
1857 doc
: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1858 If FRAME is invisible or iconified, make it visible.
1859 If you don't specify a frame, the selected frame is used.
1860 If Emacs is displaying on an ordinary terminal or some other device which
1861 doesn't support multiple overlapping frames, this function selects FRAME. */)
1864 struct frame
*f
= decode_live_frame (frame
);
1866 XSETFRAME (frame
, f
);
1868 if (FRAME_TERMCAP_P (f
))
1869 /* On a text terminal select FRAME. */
1870 Fselect_frame (frame
, Qnil
);
1872 /* Do like the documentation says. */
1873 Fmake_frame_visible (frame
);
1875 if (FRAME_TERMINAL (f
)->frame_raise_lower_hook
)
1876 (*FRAME_TERMINAL (f
)->frame_raise_lower_hook
) (f
, 1);
1881 /* Should we have a corresponding function called Flower_Power? */
1882 DEFUN ("lower-frame", Flower_frame
, Slower_frame
, 0, 1, "",
1883 doc
: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1884 If you don't specify a frame, the selected frame is used.
1885 If Emacs is displaying on an ordinary terminal or some other device which
1886 doesn't support multiple overlapping frames, this function does nothing. */)
1889 struct frame
*f
= decode_live_frame (frame
);
1891 if (FRAME_TERMINAL (f
)->frame_raise_lower_hook
)
1892 (*FRAME_TERMINAL (f
)->frame_raise_lower_hook
) (f
, 0);
1898 DEFUN ("redirect-frame-focus", Fredirect_frame_focus
, Sredirect_frame_focus
,
1900 doc
: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1901 In other words, switch-frame events caused by events in FRAME will
1902 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1903 FOCUS-FRAME after reading an event typed at FRAME.
1905 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1906 frame again receives its own keystrokes.
1908 Focus redirection is useful for temporarily redirecting keystrokes to
1909 a surrogate minibuffer frame when a frame doesn't have its own
1912 A frame's focus redirection can be changed by `select-frame'. If frame
1913 FOO is selected, and then a different frame BAR is selected, any
1914 frames redirecting their focus to FOO are shifted to redirect their
1915 focus to BAR. This allows focus redirection to work properly when the
1916 user switches from one frame to another using `select-window'.
1918 This means that a frame whose focus is redirected to itself is treated
1919 differently from a frame whose focus is redirected to nil; the former
1920 is affected by `select-frame', while the latter is not.
1922 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1923 (Lisp_Object frame
, Lisp_Object focus_frame
)
1925 /* Note that we don't check for a live frame here. It's reasonable
1926 to redirect the focus of a frame you're about to delete, if you
1927 know what other frame should receive those keystrokes. */
1928 struct frame
*f
= decode_any_frame (frame
);
1930 if (! NILP (focus_frame
))
1931 CHECK_LIVE_FRAME (focus_frame
);
1933 fset_focus_frame (f
, focus_frame
);
1935 if (FRAME_TERMINAL (f
)->frame_rehighlight_hook
)
1936 (*FRAME_TERMINAL (f
)->frame_rehighlight_hook
) (f
);
1942 DEFUN ("frame-focus", Fframe_focus
, Sframe_focus
, 0, 1, 0,
1943 doc
: /* Return the frame to which FRAME's keystrokes are currently being sent.
1944 If FRAME is omitted or nil, the selected frame is used.
1945 Return nil if FRAME's focus is not redirected.
1946 See `redirect-frame-focus'. */)
1949 return FRAME_FOCUS_FRAME (decode_live_frame (frame
));
1952 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
1953 doc
: /* Set the input focus to FRAME.
1954 FRAME nil means use the selected frame.
1955 If there is no window system support, this function does nothing. */)
1958 #ifdef HAVE_WINDOW_SYSTEM
1959 x_focus_frame (decode_window_system_frame (frame
));
1965 /* Return the value of frame parameter PROP in frame FRAME. */
1967 #ifdef HAVE_WINDOW_SYSTEM
1969 get_frame_param (register struct frame
*frame
, Lisp_Object prop
)
1971 register Lisp_Object tem
;
1973 tem
= Fassq (prop
, frame
->param_alist
);
1980 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1983 frames_discard_buffer (Lisp_Object buffer
)
1985 Lisp_Object frame
, tail
;
1987 FOR_EACH_FRAME (tail
, frame
)
1990 (XFRAME (frame
), Fdelq (buffer
, XFRAME (frame
)->buffer_list
));
1991 fset_buried_buffer_list
1992 (XFRAME (frame
), Fdelq (buffer
, XFRAME (frame
)->buried_buffer_list
));
1996 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1997 If the alist already has an element for PROP, we change it. */
2000 store_in_alist (Lisp_Object
*alistptr
, Lisp_Object prop
, Lisp_Object val
)
2002 register Lisp_Object tem
;
2004 tem
= Fassq (prop
, *alistptr
);
2006 *alistptr
= Fcons (Fcons (prop
, val
), *alistptr
);
2012 frame_name_fnn_p (char *str
, ptrdiff_t len
)
2014 if (len
> 1 && str
[0] == 'F' && '0' <= str
[1] && str
[1] <= '9')
2017 while ('0' <= *p
&& *p
<= '9')
2025 /* Set the name of the terminal frame. Also used by MSDOS frames.
2026 Modeled after x_set_name which is used for WINDOW frames. */
2029 set_term_frame_name (struct frame
*f
, Lisp_Object name
)
2031 f
->explicit_name
= ! NILP (name
);
2033 /* If NAME is nil, set the name to F<num>. */
2036 char namebuf
[sizeof "F" + INT_STRLEN_BOUND (printmax_t
)];
2038 /* Check for no change needed in this very common case
2039 before we do any consing. */
2040 if (frame_name_fnn_p (SSDATA (f
->name
), SBYTES (f
->name
)))
2043 name
= make_formatted_string (namebuf
, "F%"pMd
, ++tty_frame_count
);
2047 CHECK_STRING (name
);
2049 /* Don't change the name if it's already NAME. */
2050 if (! NILP (Fstring_equal (name
, f
->name
)))
2053 /* Don't allow the user to set the frame name to F<num>, so it
2054 doesn't clash with the names we generate for terminal frames. */
2055 if (frame_name_fnn_p (SSDATA (name
), SBYTES (name
)))
2056 error ("Frame names of the form F<num> are usurped by Emacs");
2059 fset_name (f
, name
);
2060 update_mode_lines
= 16;
2065 set_frame_param (struct frame
*f
, Lisp_Object prop
, Lisp_Object val
)
2067 register Lisp_Object old_alist_elt
;
2069 old_alist_elt
= Fassq (prop
, f
->param_alist
);
2070 if (EQ (old_alist_elt
, Qnil
))
2071 fset_param_alist (f
, Fcons (Fcons (prop
, val
), f
->param_alist
));
2073 Fsetcdr (old_alist_elt
, val
);
2078 store_frame_param (struct frame
*f
, Lisp_Object prop
, Lisp_Object val
)
2080 register Lisp_Object old_alist_elt
;
2082 /* The buffer-list parameters are stored in a special place and not
2083 in the alist. All buffers must be live. */
2084 if (EQ (prop
, Qbuffer_list
))
2086 Lisp_Object list
= Qnil
;
2087 for (; CONSP (val
); val
= XCDR (val
))
2088 if (!NILP (Fbuffer_live_p (XCAR (val
))))
2089 list
= Fcons (XCAR (val
), list
);
2090 fset_buffer_list (f
, Fnreverse (list
));
2093 if (EQ (prop
, Qburied_buffer_list
))
2095 Lisp_Object list
= Qnil
;
2096 for (; CONSP (val
); val
= XCDR (val
))
2097 if (!NILP (Fbuffer_live_p (XCAR (val
))))
2098 list
= Fcons (XCAR (val
), list
);
2099 fset_buried_buffer_list (f
, Fnreverse (list
));
2103 /* If PROP is a symbol which is supposed to have frame-local values,
2104 and it is set up based on this frame, switch to the global
2105 binding. That way, we can create or alter the frame-local binding
2106 without messing up the symbol's status. */
2109 struct Lisp_Symbol
*sym
= XSYMBOL (prop
);
2111 switch (sym
->redirect
)
2113 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
2114 case SYMBOL_PLAINVAL
: case SYMBOL_FORWARDED
: break;
2115 case SYMBOL_LOCALIZED
:
2116 { struct Lisp_Buffer_Local_Value
*blv
= sym
->val
.blv
;
2117 if (blv
->frame_local
&& blv_found (blv
) && XFRAME (blv
->where
) == f
)
2118 swap_in_global_binding (sym
);
2121 default: emacs_abort ();
2125 /* The tty color needed to be set before the frame's parameter
2126 alist was updated with the new value. This is not true any more,
2127 but we still do this test early on. */
2128 if (FRAME_TERMCAP_P (f
) && EQ (prop
, Qtty_color_mode
)
2129 && f
== FRAME_TTY (f
)->previous_frame
)
2130 /* Force redisplay of this tty. */
2131 FRAME_TTY (f
)->previous_frame
= NULL
;
2133 /* Update the frame parameter alist. */
2134 old_alist_elt
= Fassq (prop
, f
->param_alist
);
2135 if (EQ (old_alist_elt
, Qnil
))
2136 fset_param_alist (f
, Fcons (Fcons (prop
, val
), f
->param_alist
));
2138 Fsetcdr (old_alist_elt
, val
);
2140 /* Update some other special parameters in their special places
2141 in addition to the alist. */
2143 if (EQ (prop
, Qbuffer_predicate
))
2144 fset_buffer_predicate (f
, val
);
2146 if (! FRAME_WINDOW_P (f
))
2148 if (EQ (prop
, Qmenu_bar_lines
))
2149 set_menu_bar_lines (f
, val
, make_number (FRAME_MENU_BAR_LINES (f
)));
2150 else if (EQ (prop
, Qname
))
2151 set_term_frame_name (f
, val
);
2154 if (EQ (prop
, Qminibuffer
) && WINDOWP (val
))
2156 if (! MINI_WINDOW_P (XWINDOW (val
)))
2157 error ("Surrogate minibuffer windows must be minibuffer windows");
2159 if ((FRAME_HAS_MINIBUF_P (f
) || FRAME_MINIBUF_ONLY_P (f
))
2160 && !EQ (val
, f
->minibuffer_window
))
2161 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2163 /* Install the chosen minibuffer window, with proper buffer. */
2164 fset_minibuffer_window (f
, val
);
2168 DEFUN ("frame-parameters", Fframe_parameters
, Sframe_parameters
, 0, 1, 0,
2169 doc
: /* Return the parameters-alist of frame FRAME.
2170 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2171 The meaningful PARMs depend on the kind of frame.
2172 If FRAME is omitted or nil, return information on the currently selected frame. */)
2176 struct frame
*f
= decode_any_frame (frame
);
2178 struct gcpro gcpro1
;
2180 if (!FRAME_LIVE_P (f
))
2183 alist
= Fcopy_alist (f
->param_alist
);
2186 if (!FRAME_WINDOW_P (f
))
2188 int fg
= FRAME_FOREGROUND_PIXEL (f
);
2189 int bg
= FRAME_BACKGROUND_PIXEL (f
);
2192 /* If the frame's parameter alist says the colors are
2193 unspecified and reversed, take the frame's background pixel
2194 for foreground and vice versa. */
2195 elt
= Fassq (Qforeground_color
, alist
);
2196 if (CONSP (elt
) && STRINGP (XCDR (elt
)))
2198 if (strncmp (SSDATA (XCDR (elt
)),
2200 SCHARS (XCDR (elt
))) == 0)
2201 store_in_alist (&alist
, Qforeground_color
, tty_color_name (f
, bg
));
2202 else if (strncmp (SSDATA (XCDR (elt
)),
2204 SCHARS (XCDR (elt
))) == 0)
2205 store_in_alist (&alist
, Qforeground_color
, tty_color_name (f
, fg
));
2208 store_in_alist (&alist
, Qforeground_color
, tty_color_name (f
, fg
));
2209 elt
= Fassq (Qbackground_color
, alist
);
2210 if (CONSP (elt
) && STRINGP (XCDR (elt
)))
2212 if (strncmp (SSDATA (XCDR (elt
)),
2214 SCHARS (XCDR (elt
))) == 0)
2215 store_in_alist (&alist
, Qbackground_color
, tty_color_name (f
, fg
));
2216 else if (strncmp (SSDATA (XCDR (elt
)),
2218 SCHARS (XCDR (elt
))) == 0)
2219 store_in_alist (&alist
, Qbackground_color
, tty_color_name (f
, bg
));
2222 store_in_alist (&alist
, Qbackground_color
, tty_color_name (f
, bg
));
2223 store_in_alist (&alist
, intern ("font"),
2224 build_string (FRAME_MSDOS_P (f
)
2226 : FRAME_W32_P (f
) ? "w32term"
2229 store_in_alist (&alist
, Qname
, f
->name
);
2230 height
= (f
->new_height
2232 ? (f
->new_height
/ FRAME_LINE_HEIGHT (f
))
2235 store_in_alist (&alist
, Qheight
, make_number (height
));
2236 width
= (f
->new_width
2238 ? (f
->new_width
/ FRAME_COLUMN_WIDTH (f
))
2241 store_in_alist (&alist
, Qwidth
, make_number (width
));
2242 store_in_alist (&alist
, Qmodeline
, (FRAME_WANTS_MODELINE_P (f
) ? Qt
: Qnil
));
2243 store_in_alist (&alist
, Qminibuffer
,
2244 (! FRAME_HAS_MINIBUF_P (f
) ? Qnil
2245 : FRAME_MINIBUF_ONLY_P (f
) ? Qonly
2246 : FRAME_MINIBUF_WINDOW (f
)));
2247 store_in_alist (&alist
, Qunsplittable
, (FRAME_NO_SPLIT_P (f
) ? Qt
: Qnil
));
2248 store_in_alist (&alist
, Qbuffer_list
, f
->buffer_list
);
2249 store_in_alist (&alist
, Qburied_buffer_list
, f
->buried_buffer_list
);
2251 /* I think this should be done with a hook. */
2252 #ifdef HAVE_WINDOW_SYSTEM
2253 if (FRAME_WINDOW_P (f
))
2254 x_report_frame_params (f
, &alist
);
2258 /* This ought to be correct in f->param_alist for an X frame. */
2260 XSETFASTINT (lines
, FRAME_MENU_BAR_LINES (f
));
2261 store_in_alist (&alist
, Qmenu_bar_lines
, lines
);
2269 DEFUN ("frame-parameter", Fframe_parameter
, Sframe_parameter
, 2, 2, 0,
2270 doc
: /* Return FRAME's value for parameter PARAMETER.
2271 If FRAME is nil, describe the currently selected frame. */)
2272 (Lisp_Object frame
, Lisp_Object parameter
)
2274 struct frame
*f
= decode_any_frame (frame
);
2275 Lisp_Object value
= Qnil
;
2277 CHECK_SYMBOL (parameter
);
2279 XSETFRAME (frame
, f
);
2281 if (FRAME_LIVE_P (f
))
2283 /* Avoid consing in frequent cases. */
2284 if (EQ (parameter
, Qname
))
2286 #ifdef HAVE_X_WINDOWS
2287 else if (EQ (parameter
, Qdisplay
) && FRAME_X_P (f
))
2288 value
= XCAR (FRAME_DISPLAY_INFO (f
)->name_list_element
);
2289 #endif /* HAVE_X_WINDOWS */
2290 else if (EQ (parameter
, Qbackground_color
)
2291 || EQ (parameter
, Qforeground_color
))
2293 value
= Fassq (parameter
, f
->param_alist
);
2296 value
= XCDR (value
);
2297 /* Fframe_parameters puts the actual fg/bg color names,
2298 even if f->param_alist says otherwise. This is
2299 important when param_alist's notion of colors is
2300 "unspecified". We need to do the same here. */
2301 if (STRINGP (value
) && !FRAME_WINDOW_P (f
))
2303 const char *color_name
;
2306 if (EQ (parameter
, Qbackground_color
))
2308 color_name
= SSDATA (value
);
2309 csz
= SCHARS (value
);
2310 if (strncmp (color_name
, unspecified_bg
, csz
) == 0)
2311 value
= tty_color_name (f
, FRAME_BACKGROUND_PIXEL (f
));
2312 else if (strncmp (color_name
, unspecified_fg
, csz
) == 0)
2313 value
= tty_color_name (f
, FRAME_FOREGROUND_PIXEL (f
));
2315 else if (EQ (parameter
, Qforeground_color
))
2317 color_name
= SSDATA (value
);
2318 csz
= SCHARS (value
);
2319 if (strncmp (color_name
, unspecified_fg
, csz
) == 0)
2320 value
= tty_color_name (f
, FRAME_FOREGROUND_PIXEL (f
));
2321 else if (strncmp (color_name
, unspecified_bg
, csz
) == 0)
2322 value
= tty_color_name (f
, FRAME_BACKGROUND_PIXEL (f
));
2327 value
= Fcdr (Fassq (parameter
, Fframe_parameters (frame
)));
2329 else if (EQ (parameter
, Qdisplay_type
)
2330 || EQ (parameter
, Qbackground_mode
))
2331 value
= Fcdr (Fassq (parameter
, f
->param_alist
));
2333 /* FIXME: Avoid this code path at all (as well as code duplication)
2334 by sharing more code with Fframe_parameters. */
2335 value
= Fcdr (Fassq (parameter
, Fframe_parameters (frame
)));
2342 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters
,
2343 Smodify_frame_parameters
, 2, 2, 0,
2344 doc
: /* Modify the parameters of frame FRAME according to ALIST.
2345 If FRAME is nil, it defaults to the selected frame.
2346 ALIST is an alist of parameters to change and their new values.
2347 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2348 The meaningful PARMs depend on the kind of frame.
2349 Undefined PARMs are ignored, but stored in the frame's parameter list
2350 so that `frame-parameters' will return them.
2352 The value of frame parameter FOO can also be accessed
2353 as a frame-local binding for the variable FOO, if you have
2354 enabled such bindings for that variable with `make-variable-frame-local'.
2355 Note that this functionality is obsolete as of Emacs 22.2, and its
2356 use is not recommended. Explicitly check for a frame-parameter instead. */)
2357 (Lisp_Object frame
, Lisp_Object alist
)
2359 struct frame
*f
= decode_live_frame (frame
);
2360 register Lisp_Object prop
, val
;
2364 /* I think this should be done with a hook. */
2365 #ifdef HAVE_WINDOW_SYSTEM
2366 if (FRAME_WINDOW_P (f
))
2367 x_set_frame_parameters (f
, alist
);
2371 if (FRAME_MSDOS_P (f
))
2372 IT_set_frame_parameters (f
, alist
);
2377 EMACS_INT length
= XFASTINT (Flength (alist
));
2380 Lisp_Object
*values
;
2382 SAFE_ALLOCA_LISP (parms
, 2 * length
);
2383 values
= parms
+ length
;
2385 /* Extract parm names and values into those vectors. */
2387 for (i
= 0; CONSP (alist
); alist
= XCDR (alist
))
2392 parms
[i
] = Fcar (elt
);
2393 values
[i
] = Fcdr (elt
);
2397 /* Now process them in reverse of specified order. */
2402 store_frame_param (f
, prop
, val
);
2404 if (EQ (prop
, Qforeground_color
)
2405 || EQ (prop
, Qbackground_color
))
2406 update_face_from_frame_parameter (f
, prop
, val
);
2414 DEFUN ("frame-char-height", Fframe_char_height
, Sframe_char_height
,
2416 doc
: /* Height in pixels of a line in the font in frame FRAME.
2417 If FRAME is omitted or nil, the selected frame is used.
2418 For a terminal frame, the value is always 1. */)
2421 #ifdef HAVE_WINDOW_SYSTEM
2422 struct frame
*f
= decode_any_frame (frame
);
2424 if (FRAME_WINDOW_P (f
))
2425 return make_number (FRAME_LINE_HEIGHT (f
));
2428 return make_number (1);
2432 DEFUN ("frame-char-width", Fframe_char_width
, Sframe_char_width
,
2434 doc
: /* Width in pixels of characters in the font in frame FRAME.
2435 If FRAME is omitted or nil, the selected frame is used.
2436 On a graphical screen, the width is the standard width of the default font.
2437 For a terminal screen, the value is always 1. */)
2440 #ifdef HAVE_WINDOW_SYSTEM
2441 struct frame
*f
= decode_any_frame (frame
);
2443 if (FRAME_WINDOW_P (f
))
2444 return make_number (FRAME_COLUMN_WIDTH (f
));
2447 return make_number (1);
2450 DEFUN ("frame-pixel-height", Fframe_pixel_height
,
2451 Sframe_pixel_height
, 0, 1, 0,
2452 doc
: /* Return a FRAME's height in pixels.
2453 If FRAME is omitted or nil, the selected frame is used. The exact value
2454 of the result depends on the window-system and toolkit in use:
2456 In the Gtk+ version of Emacs, it includes only any window (including
2457 the minibuffer or echo area), mode line, and header line. It does not
2458 include the tool bar or menu bar.
2460 With other graphical versions, it also includes the tool bar and the
2463 For a text terminal, it includes the menu bar. In this case, the
2464 result is really in characters rather than pixels (i.e., is identical
2465 to `frame-height'). */)
2468 struct frame
*f
= decode_any_frame (frame
);
2470 #ifdef HAVE_WINDOW_SYSTEM
2471 if (FRAME_WINDOW_P (f
))
2472 return make_number (FRAME_PIXEL_HEIGHT (f
));
2475 return make_number (FRAME_LINES (f
));
2478 DEFUN ("frame-pixel-width", Fframe_pixel_width
,
2479 Sframe_pixel_width
, 0, 1, 0,
2480 doc
: /* Return FRAME's width in pixels.
2481 For a terminal frame, the result really gives the width in characters.
2482 If FRAME is omitted or nil, the selected frame is used. */)
2485 struct frame
*f
= decode_any_frame (frame
);
2487 #ifdef HAVE_WINDOW_SYSTEM
2488 if (FRAME_WINDOW_P (f
))
2489 return make_number (FRAME_PIXEL_WIDTH (f
));
2492 return make_number (FRAME_COLS (f
));
2495 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width
,
2496 Stool_bar_pixel_width
, 0, 1, 0,
2497 doc
: /* Return width in pixels of FRAME's tool bar.
2498 The result is greater than zero only when the tool bar is on the left
2499 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2503 #ifdef FRAME_TOOLBAR_WIDTH
2504 struct frame
*f
= decode_any_frame (frame
);
2506 if (FRAME_WINDOW_P (f
))
2507 return make_number (FRAME_TOOLBAR_WIDTH (f
));
2509 return make_number (0);
2512 DEFUN ("frame-text-cols", Fframe_text_cols
, Sframe_text_cols
, 0, 1, 0,
2513 doc
: /* Return width in columns of FRAME's text area. */)
2516 return make_number (FRAME_COLS (decode_any_frame (frame
)));
2519 DEFUN ("frame-text-lines", Fframe_text_lines
, Sframe_text_lines
, 0, 1, 0,
2520 doc
: /* Return height in lines of FRAME's text area. */)
2523 return make_number (FRAME_LINES (decode_any_frame (frame
)));
2526 DEFUN ("frame-total-cols", Fframe_total_cols
, Sframe_total_cols
, 0, 1, 0,
2527 doc
: /* Return total columns of FRAME. */)
2530 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame
)));
2533 DEFUN ("frame-text-width", Fframe_text_width
, Sframe_text_width
, 0, 1, 0,
2534 doc
: /* Return text area width of FRAME in pixels. */)
2537 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame
)));
2540 DEFUN ("frame-text-height", Fframe_text_height
, Sframe_text_height
, 0, 1, 0,
2541 doc
: /* Return text area height of FRAME in pixels. */)
2544 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame
)));
2547 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width
, Sscroll_bar_width
, 0, 1, 0,
2548 doc
: /* Return scroll bar width of FRAME in pixels. */)
2551 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame
)));
2554 DEFUN ("frame-fringe-width", Ffringe_width
, Sfringe_width
, 0, 1, 0,
2555 doc
: /* Return fringe width of FRAME in pixels. */)
2558 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame
)));
2561 DEFUN ("frame-border-width", Fborder_width
, Sborder_width
, 0, 1, 0,
2562 doc
: /* Return border width of FRAME in pixels. */)
2565 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame
)));
2568 DEFUN ("frame-right-divider-width", Fright_divider_width
, Sright_divider_width
, 0, 1, 0,
2569 doc
: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2572 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame
)));
2575 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width
, Sbottom_divider_width
, 0, 1, 0,
2576 doc
: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2579 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame
)));
2582 DEFUN ("set-frame-height", Fset_frame_height
, Sset_frame_height
, 2, 4, 0,
2583 doc
: /* Specify that the frame FRAME has HEIGHT text lines.
2584 Optional third arg PRETEND non-nil means that redisplay should use
2585 HEIGHT lines but that the idea of the actual height of the frame should
2586 not be changed. Optional fourth argument PIXELWISE non-nil means that
2587 FRAME should be HEIGHT pixels high. */)
2588 (Lisp_Object frame
, Lisp_Object height
, Lisp_Object pretend
, Lisp_Object pixelwise
)
2590 register struct frame
*f
= decode_live_frame (frame
);
2592 CHECK_TYPE_RANGED_INTEGER (int, height
);
2594 /* I think this should be done with a hook. */
2595 #ifdef HAVE_WINDOW_SYSTEM
2596 if (FRAME_WINDOW_P (f
))
2598 if (NILP (pixelwise
))
2600 if (XINT (height
) != FRAME_LINES (f
))
2601 x_set_window_size (f
, 1, FRAME_COLS (f
), XINT (height
), 0);
2603 do_pending_window_change (0);
2605 else if (XINT (height
) != FRAME_TEXT_HEIGHT (f
))
2607 x_set_window_size (f
, 1, FRAME_TEXT_WIDTH (f
), XINT (height
), 1);
2608 do_pending_window_change (0);
2613 change_frame_size (f
, 0, XINT (height
), !NILP (pretend
), 0, 0,
2614 NILP (pixelwise
) ? 0 : 1);
2618 DEFUN ("set-frame-width", Fset_frame_width
, Sset_frame_width
, 2, 4, 0,
2619 doc
: /* Specify that the frame FRAME has WIDTH columns.
2620 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2621 columns but that the idea of the actual width of the frame should not
2622 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2623 should be WIDTH pixels wide. */)
2624 (Lisp_Object frame
, Lisp_Object width
, Lisp_Object pretend
, Lisp_Object pixelwise
)
2626 register struct frame
*f
= decode_live_frame (frame
);
2628 CHECK_TYPE_RANGED_INTEGER (int, width
);
2630 /* I think this should be done with a hook. */
2631 #ifdef HAVE_WINDOW_SYSTEM
2632 if (FRAME_WINDOW_P (f
))
2634 if (NILP (pixelwise
))
2636 if (XINT (width
) != FRAME_COLS (f
))
2637 x_set_window_size (f
, 1, XINT (width
), FRAME_LINES (f
), 0);
2639 do_pending_window_change (0);
2641 else if (XINT (width
) != FRAME_TEXT_WIDTH (f
))
2643 x_set_window_size (f
, 1, XINT (width
), FRAME_TEXT_HEIGHT (f
), 1);
2644 do_pending_window_change (0);
2649 change_frame_size (f
, XINT (width
), 0, !NILP (pretend
), 0, 0,
2650 NILP (pixelwise
) ? 0 : 1);
2654 DEFUN ("set-frame-size", Fset_frame_size
, Sset_frame_size
, 3, 4, 0,
2655 doc
: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2656 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2657 (Lisp_Object frame
, Lisp_Object width
, Lisp_Object height
, Lisp_Object pixelwise
)
2659 register struct frame
*f
= decode_live_frame (frame
);
2661 CHECK_TYPE_RANGED_INTEGER (int, width
);
2662 CHECK_TYPE_RANGED_INTEGER (int, height
);
2664 /* I think this should be done with a hook. */
2665 #ifdef HAVE_WINDOW_SYSTEM
2666 if (FRAME_WINDOW_P (f
))
2668 if (!NILP (pixelwise
)
2669 ? (XINT (width
) != FRAME_TEXT_WIDTH (f
)
2670 || XINT (height
) != FRAME_TEXT_HEIGHT (f
)
2671 || f
->new_height
|| f
->new_width
)
2672 : (XINT (width
) != FRAME_COLS (f
)
2673 || XINT (height
) != FRAME_LINES (f
)
2674 || f
->new_height
|| f
->new_width
))
2676 x_set_window_size (f
, 1, XINT (width
), XINT (height
),
2677 NILP (pixelwise
) ? 0 : 1);
2678 do_pending_window_change (0);
2683 change_frame_size (f
, XINT (width
), XINT (height
), 0, 0, 0,
2684 NILP (pixelwise
) ? 0 : 1);
2689 DEFUN ("set-frame-position", Fset_frame_position
,
2690 Sset_frame_position
, 3, 3, 0,
2691 doc
: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2692 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2693 actually the position of the upper left corner of the frame. Negative
2694 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2695 or bottommost possible position (that stays within the screen). */)
2696 (Lisp_Object frame
, Lisp_Object xoffset
, Lisp_Object yoffset
)
2698 register struct frame
*f
= decode_live_frame (frame
);
2700 CHECK_TYPE_RANGED_INTEGER (int, xoffset
);
2701 CHECK_TYPE_RANGED_INTEGER (int, yoffset
);
2703 /* I think this should be done with a hook. */
2704 #ifdef HAVE_WINDOW_SYSTEM
2705 if (FRAME_WINDOW_P (f
))
2706 x_set_offset (f
, XINT (xoffset
), XINT (yoffset
), 1);
2713 /***********************************************************************
2715 ***********************************************************************/
2717 /* Connect the frame-parameter names for X frames
2718 to the ways of passing the parameter values to the window system.
2720 The name of a parameter, as a Lisp symbol,
2721 has an `x-frame-parameter' property which is an integer in Lisp
2722 that is an index in this table. */
2724 struct frame_parm_table
{
2726 Lisp_Object
*variable
;
2729 static const struct frame_parm_table frame_parms
[] =
2731 {"auto-raise", &Qauto_raise
},
2732 {"auto-lower", &Qauto_lower
},
2733 {"background-color", 0},
2734 {"border-color", &Qborder_color
},
2735 {"border-width", &Qborder_width
},
2736 {"cursor-color", &Qcursor_color
},
2737 {"cursor-type", &Qcursor_type
},
2739 {"foreground-color", 0},
2740 {"icon-name", &Qicon_name
},
2741 {"icon-type", &Qicon_type
},
2742 {"internal-border-width", &Qinternal_border_width
},
2743 {"right-divider-width", &Qright_divider_width
},
2744 {"bottom-divider-width", &Qbottom_divider_width
},
2745 {"menu-bar-lines", &Qmenu_bar_lines
},
2746 {"mouse-color", &Qmouse_color
},
2748 {"scroll-bar-width", &Qscroll_bar_width
},
2750 {"unsplittable", &Qunsplittable
},
2751 {"vertical-scroll-bars", &Qvertical_scroll_bars
},
2752 {"visibility", &Qvisibility
},
2753 {"tool-bar-lines", &Qtool_bar_lines
},
2754 {"scroll-bar-foreground", &Qscroll_bar_foreground
},
2755 {"scroll-bar-background", &Qscroll_bar_background
},
2756 {"screen-gamma", &Qscreen_gamma
},
2757 {"line-spacing", &Qline_spacing
},
2758 {"left-fringe", &Qleft_fringe
},
2759 {"right-fringe", &Qright_fringe
},
2760 {"wait-for-wm", &Qwait_for_wm
},
2761 {"fullscreen", &Qfullscreen
},
2762 {"font-backend", &Qfont_backend
},
2764 {"sticky", &Qsticky
},
2765 {"tool-bar-position", &Qtool_bar_position
},
2770 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2771 wanted positions of the WM window (not Emacs window).
2772 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2773 window (FRAME_X_WINDOW).
2777 x_fullscreen_adjust (struct frame
*f
, int *width
, int *height
, int *top_pos
, int *left_pos
)
2779 int newwidth
= FRAME_COLS (f
);
2780 int newheight
= FRAME_LINES (f
);
2781 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2783 *top_pos
= f
->top_pos
;
2784 *left_pos
= f
->left_pos
;
2786 if (f
->want_fullscreen
& FULLSCREEN_HEIGHT
)
2790 ph
= x_display_pixel_height (dpyinfo
);
2791 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
2792 ph
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, newheight
) - f
->y_pixels_diff
;
2793 newheight
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, ph
);
2797 if (f
->want_fullscreen
& FULLSCREEN_WIDTH
)
2801 pw
= x_display_pixel_width (dpyinfo
);
2802 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
2803 pw
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, newwidth
) - f
->x_pixels_diff
;
2804 newwidth
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, pw
);
2809 *height
= newheight
;
2812 #endif /* HAVE_NTGUI */
2814 #ifdef HAVE_WINDOW_SYSTEM
2816 /* Change the parameters of frame F as specified by ALIST.
2817 If a parameter is not specially recognized, do nothing special;
2818 otherwise call the `x_set_...' function for that parameter.
2819 Except for certain geometry properties, always call store_frame_param
2820 to store the new value in the parameter alist. */
2823 x_set_frame_parameters (struct frame
*f
, Lisp_Object alist
)
2827 /* If both of these parameters are present, it's more efficient to
2828 set them both at once. So we wait until we've looked at the
2829 entire list before we set them. */
2830 int width
= 0, height
= 0;
2831 bool width_change
= 0, height_change
= 0;
2834 Lisp_Object left
, top
;
2836 /* Same with these. */
2837 Lisp_Object icon_left
, icon_top
;
2839 /* Record in these vectors all the parms specified. */
2841 Lisp_Object
*values
;
2843 bool left_no_change
= 0, top_no_change
= 0;
2844 #ifdef HAVE_X_WINDOWS
2845 bool icon_left_no_change
= 0, icon_top_no_change
= 0;
2847 struct gcpro gcpro1
, gcpro2
;
2850 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
2853 parms
= alloca (i
* sizeof *parms
);
2854 values
= alloca (i
* sizeof *values
);
2856 /* Extract parm names and values into those vectors. */
2859 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
2864 parms
[i
] = Fcar (elt
);
2865 values
[i
] = Fcdr (elt
);
2868 /* TAIL and ALIST are not used again below here. */
2869 alist
= tail
= Qnil
;
2871 GCPRO2 (*parms
, *values
);
2875 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2876 because their values appear in VALUES and strings are not valid. */
2877 top
= left
= Qunbound
;
2878 icon_left
= icon_top
= Qunbound
;
2880 /* Process foreground_color and background_color before anything else.
2881 They are independent of other properties, but other properties (e.g.,
2882 cursor_color) are dependent upon them. */
2883 /* Process default font as well, since fringe widths depends on it. */
2884 for (p
= 0; p
< i
; p
++)
2886 Lisp_Object prop
, val
;
2890 if (EQ (prop
, Qforeground_color
)
2891 || EQ (prop
, Qbackground_color
)
2892 || EQ (prop
, Qfont
))
2894 register Lisp_Object param_index
, old_value
;
2896 old_value
= get_frame_param (f
, prop
);
2897 if (NILP (Fequal (val
, old_value
)))
2899 store_frame_param (f
, prop
, val
);
2901 param_index
= Fget (prop
, Qx_frame_parameter
);
2902 if (NATNUMP (param_index
)
2903 && XFASTINT (param_index
) < ARRAYELTS (frame_parms
)
2904 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
2905 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
2910 /* Now process them in reverse of specified order. */
2913 Lisp_Object prop
, val
;
2918 if (EQ (prop
, Qwidth
) && RANGED_INTEGERP (0, val
, INT_MAX
))
2921 width
= XFASTINT (val
) * FRAME_COLUMN_WIDTH (f
) ;
2923 else if (EQ (prop
, Qheight
) && RANGED_INTEGERP (0, val
, INT_MAX
))
2926 height
= XFASTINT (val
) * FRAME_LINE_HEIGHT (f
);
2928 else if (EQ (prop
, Qtop
))
2930 else if (EQ (prop
, Qleft
))
2932 else if (EQ (prop
, Qicon_top
))
2934 else if (EQ (prop
, Qicon_left
))
2936 else if (EQ (prop
, Qforeground_color
)
2937 || EQ (prop
, Qbackground_color
)
2938 || EQ (prop
, Qfont
))
2939 /* Processed above. */
2943 register Lisp_Object param_index
, old_value
;
2945 old_value
= get_frame_param (f
, prop
);
2947 store_frame_param (f
, prop
, val
);
2949 param_index
= Fget (prop
, Qx_frame_parameter
);
2950 if (NATNUMP (param_index
)
2951 && XFASTINT (param_index
) < ARRAYELTS (frame_parms
)
2952 && FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])
2953 (*(FRAME_RIF (f
)->frame_parm_handlers
[XINT (param_index
)])) (f
, val
, old_value
);
2957 /* Don't die if just one of these was set. */
2958 if (EQ (left
, Qunbound
))
2961 if (f
->left_pos
< 0)
2962 left
= list2 (Qplus
, make_number (f
->left_pos
));
2964 XSETINT (left
, f
->left_pos
);
2966 if (EQ (top
, Qunbound
))
2970 top
= list2 (Qplus
, make_number (f
->top_pos
));
2972 XSETINT (top
, f
->top_pos
);
2975 /* If one of the icon positions was not set, preserve or default it. */
2976 if (! TYPE_RANGED_INTEGERP (int, icon_left
))
2978 #ifdef HAVE_X_WINDOWS
2979 icon_left_no_change
= 1;
2981 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
2982 if (NILP (icon_left
))
2983 XSETINT (icon_left
, 0);
2985 if (! TYPE_RANGED_INTEGERP (int, icon_top
))
2987 #ifdef HAVE_X_WINDOWS
2988 icon_top_no_change
= 1;
2990 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
2991 if (NILP (icon_top
))
2992 XSETINT (icon_top
, 0);
2995 /* Don't set these parameters unless they've been explicitly
2996 specified. The window might be mapped or resized while we're in
2997 this function, and we don't want to override that unless the lisp
2998 code has asked for it.
3000 Don't set these parameters unless they actually differ from the
3001 window's current parameters; the window may not actually exist
3006 /* Make this 1, eventually. */
3007 check_frame_size (f
, &width
, &height
, 1);
3009 XSETFRAME (frame
, f
);
3011 if ((width_change
|| height_change
)
3012 && (width
!= FRAME_TEXT_WIDTH (f
)
3013 || height
!= FRAME_TEXT_HEIGHT (f
)
3014 || f
->new_height
|| f
->new_width
))
3016 /* If necessary provide default values for HEIGHT and WIDTH. Do
3017 that here since otherwise a size change implied by an
3018 intermittent font change may get lost as in Bug#17142. */
3020 width
= (f
->new_width
3023 : (f
->new_width
* FRAME_COLUMN_WIDTH (f
)))
3024 : FRAME_TEXT_WIDTH (f
));
3027 height
= (f
->new_height
3030 : (f
->new_height
* FRAME_LINE_HEIGHT (f
)))
3031 : FRAME_TEXT_HEIGHT (f
));
3033 Fset_frame_size (frame
, make_number (width
), make_number (height
), Qt
);
3036 if ((!NILP (left
) || !NILP (top
))
3037 && ! (left_no_change
&& top_no_change
)
3038 && ! (NUMBERP (left
) && XINT (left
) == f
->left_pos
3039 && NUMBERP (top
) && XINT (top
) == f
->top_pos
))
3044 /* Record the signs. */
3045 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
3046 if (EQ (left
, Qminus
))
3047 f
->size_hint_flags
|= XNegative
;
3048 else if (TYPE_RANGED_INTEGERP (int, left
))
3050 leftpos
= XINT (left
);
3052 f
->size_hint_flags
|= XNegative
;
3054 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
3055 && CONSP (XCDR (left
))
3056 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (left
)), INT_MAX
))
3058 leftpos
= - XINT (XCAR (XCDR (left
)));
3059 f
->size_hint_flags
|= XNegative
;
3061 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
3062 && CONSP (XCDR (left
))
3063 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left
))))
3065 leftpos
= XINT (XCAR (XCDR (left
)));
3068 if (EQ (top
, Qminus
))
3069 f
->size_hint_flags
|= YNegative
;
3070 else if (TYPE_RANGED_INTEGERP (int, top
))
3072 toppos
= XINT (top
);
3074 f
->size_hint_flags
|= YNegative
;
3076 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
3077 && CONSP (XCDR (top
))
3078 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (top
)), INT_MAX
))
3080 toppos
= - XINT (XCAR (XCDR (top
)));
3081 f
->size_hint_flags
|= YNegative
;
3083 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
3084 && CONSP (XCDR (top
))
3085 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top
))))
3087 toppos
= XINT (XCAR (XCDR (top
)));
3091 /* Store the numeric value of the position. */
3092 f
->top_pos
= toppos
;
3093 f
->left_pos
= leftpos
;
3095 f
->win_gravity
= NorthWestGravity
;
3097 /* Actually set that position, and convert to absolute. */
3098 x_set_offset (f
, leftpos
, toppos
, -1);
3100 #ifdef HAVE_X_WINDOWS
3101 if ((!NILP (icon_left
) || !NILP (icon_top
))
3102 && ! (icon_left_no_change
&& icon_top_no_change
))
3103 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
3104 #endif /* HAVE_X_WINDOWS */
3111 /* Insert a description of internally-recorded parameters of frame X
3112 into the parameter alist *ALISTPTR that is to be given to the user.
3113 Only parameters that are specific to the X window system
3114 and whose values are not correctly recorded in the frame's
3115 param_alist need to be considered here. */
3118 x_report_frame_params (struct frame
*f
, Lisp_Object
*alistptr
)
3122 char buf
[INT_BUFSIZE_BOUND (w
)];
3124 /* Represent negative positions (off the top or left screen edge)
3125 in a way that Fmodify_frame_parameters will understand correctly. */
3126 XSETINT (tem
, f
->left_pos
);
3127 if (f
->left_pos
>= 0)
3128 store_in_alist (alistptr
, Qleft
, tem
);
3130 store_in_alist (alistptr
, Qleft
, list2 (Qplus
, tem
));
3132 XSETINT (tem
, f
->top_pos
);
3133 if (f
->top_pos
>= 0)
3134 store_in_alist (alistptr
, Qtop
, tem
);
3136 store_in_alist (alistptr
, Qtop
, list2 (Qplus
, tem
));
3138 store_in_alist (alistptr
, Qborder_width
,
3139 make_number (f
->border_width
));
3140 store_in_alist (alistptr
, Qinternal_border_width
,
3141 make_number (FRAME_INTERNAL_BORDER_WIDTH (f
)));
3142 store_in_alist (alistptr
, Qright_divider_width
,
3143 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f
)));
3144 store_in_alist (alistptr
, Qbottom_divider_width
,
3145 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f
)));
3146 store_in_alist (alistptr
, Qleft_fringe
,
3147 make_number (FRAME_LEFT_FRINGE_WIDTH (f
)));
3148 store_in_alist (alistptr
, Qright_fringe
,
3149 make_number (FRAME_RIGHT_FRINGE_WIDTH (f
)));
3150 store_in_alist (alistptr
, Qscroll_bar_width
,
3151 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3153 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
3154 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3155 /* nil means "use default width"
3156 for non-toolkit scroll bar.
3157 ruler-mode.el depends on this. */
3159 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3160 MS-Windows it returns a value whose type is HANDLE, which is
3161 actually a pointer. Explicit casting avoids compiler
3163 w
= (uintptr_t) FRAME_X_WINDOW (f
);
3164 store_in_alist (alistptr
, Qwindow_id
,
3165 make_formatted_string (buf
, "%"pMu
, w
));
3166 #ifdef HAVE_X_WINDOWS
3167 #ifdef USE_X_TOOLKIT
3168 /* Tooltip frame may not have this widget. */
3169 if (FRAME_X_OUTPUT (f
)->widget
)
3171 w
= (uintptr_t) FRAME_OUTER_WINDOW (f
);
3172 store_in_alist (alistptr
, Qouter_window_id
,
3173 make_formatted_string (buf
, "%"pMu
, w
));
3175 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
3176 store_in_alist (alistptr
, Qvisibility
,
3177 (FRAME_VISIBLE_P (f
) ? Qt
3178 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
3179 store_in_alist (alistptr
, Qdisplay
,
3180 XCAR (FRAME_DISPLAY_INFO (f
)->name_list_element
));
3182 if (FRAME_X_OUTPUT (f
)->parent_desc
== FRAME_DISPLAY_INFO (f
)->root_window
)
3185 tem
= make_natnum ((uintptr_t) FRAME_X_OUTPUT (f
)->parent_desc
);
3186 store_in_alist (alistptr
, Qexplicit_name
, (f
->explicit_name
? Qt
: Qnil
));
3187 store_in_alist (alistptr
, Qparent_id
, tem
);
3188 store_in_alist (alistptr
, Qtool_bar_position
, f
->tool_bar_position
);
3192 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3193 the previous value of that parameter, NEW_VALUE is the new value. */
3196 x_set_fullscreen (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3198 if (NILP (new_value
))
3199 f
->want_fullscreen
= FULLSCREEN_NONE
;
3200 else if (EQ (new_value
, Qfullboth
) || EQ (new_value
, Qfullscreen
))
3201 f
->want_fullscreen
= FULLSCREEN_BOTH
;
3202 else if (EQ (new_value
, Qfullwidth
))
3203 f
->want_fullscreen
= FULLSCREEN_WIDTH
;
3204 else if (EQ (new_value
, Qfullheight
))
3205 f
->want_fullscreen
= FULLSCREEN_HEIGHT
;
3206 else if (EQ (new_value
, Qmaximized
))
3207 f
->want_fullscreen
= FULLSCREEN_MAXIMIZED
;
3209 if (FRAME_TERMINAL (f
)->fullscreen_hook
!= NULL
)
3210 FRAME_TERMINAL (f
)->fullscreen_hook (f
);
3214 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3215 the previous value of that parameter, NEW_VALUE is the new value. */
3218 x_set_line_spacing (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3220 if (NILP (new_value
))
3221 f
->extra_line_spacing
= 0;
3222 else if (RANGED_INTEGERP (0, new_value
, INT_MAX
))
3223 f
->extra_line_spacing
= XFASTINT (new_value
);
3224 else if (FLOATP (new_value
))
3226 int new_spacing
= XFLOAT_DATA (new_value
) * FRAME_LINE_HEIGHT (f
) + 0.5;
3228 if (new_spacing
>= 0)
3229 f
->extra_line_spacing
= new_spacing
;
3231 signal_error ("Invalid line-spacing", new_value
);
3234 signal_error ("Invalid line-spacing", new_value
);
3235 if (FRAME_VISIBLE_P (f
))
3240 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3241 the previous value of that parameter, NEW_VALUE is the new value. */
3244 x_set_screen_gamma (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3246 Lisp_Object bgcolor
;
3248 if (NILP (new_value
))
3250 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
3251 /* The value 0.4545 is the normal viewing gamma. */
3252 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
3254 signal_error ("Invalid screen-gamma", new_value
);
3256 /* Apply the new gamma value to the frame background. */
3257 bgcolor
= Fassq (Qbackground_color
, f
->param_alist
);
3258 if (CONSP (bgcolor
) && (bgcolor
= XCDR (bgcolor
), STRINGP (bgcolor
)))
3260 Lisp_Object parm_index
= Fget (Qbackground_color
, Qx_frame_parameter
);
3261 if (NATNUMP (parm_index
)
3262 && XFASTINT (parm_index
) < ARRAYELTS (frame_parms
)
3263 && FRAME_RIF (f
)->frame_parm_handlers
[XFASTINT (parm_index
)])
3264 (*FRAME_RIF (f
)->frame_parm_handlers
[XFASTINT (parm_index
)])
3268 Fclear_face_cache (Qnil
);
3273 x_set_font (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3275 Lisp_Object font_object
;
3277 #ifdef HAVE_X_WINDOWS
3278 Lisp_Object font_param
= arg
;
3281 /* Set the frame parameter back to the old value because we may
3282 fail to use ARG as the new parameter value. */
3283 store_frame_param (f
, Qfont
, oldval
);
3285 /* ARG is a fontset name, a font name, a cons of fontset name and a
3286 font object, or a font object. In the last case, this function
3290 fontset
= fs_query_fontset (arg
, 0);
3293 font_object
= font_open_by_name (f
, arg
);
3294 if (NILP (font_object
))
3295 error ("Font `%s' is not defined", SSDATA (arg
));
3296 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3298 else if (fontset
> 0)
3300 font_object
= font_open_by_name (f
, fontset_ascii (fontset
));
3301 if (NILP (font_object
))
3302 error ("Font `%s' is not defined", SDATA (arg
));
3303 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3306 error ("The default fontset can't be used for a frame font");
3308 else if (CONSP (arg
) && STRINGP (XCAR (arg
)) && FONT_OBJECT_P (XCDR (arg
)))
3310 /* This is the case that the ASCII font of F's fontset XCAR
3311 (arg) is changed to the font XCDR (arg) by
3312 `set-fontset-font'. */
3313 fontset
= fs_query_fontset (XCAR (arg
), 0);
3315 error ("Unknown fontset: %s", SDATA (XCAR (arg
)));
3316 font_object
= XCDR (arg
);
3317 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3318 #ifdef HAVE_X_WINDOWS
3319 font_param
= Ffont_get (font_object
, QCname
);
3322 else if (FONT_OBJECT_P (arg
))
3325 #ifdef HAVE_X_WINDOWS
3326 font_param
= Ffont_get (font_object
, QCname
);
3328 /* This is to store the XLFD font name in the frame parameter for
3329 backward compatibility. We should store the font-object
3330 itself in the future. */
3331 arg
= AREF (font_object
, FONT_NAME_INDEX
);
3332 fontset
= FRAME_FONTSET (f
);
3333 /* Check if we can use the current fontset. If not, set FONTSET
3334 to -1 to generate a new fontset from FONT-OBJECT. */
3337 Lisp_Object ascii_font
= fontset_ascii (fontset
);
3338 Lisp_Object spec
= font_spec_from_name (ascii_font
);
3341 signal_error ("Invalid font name", ascii_font
);
3343 if (! font_match_p (spec
, font_object
))
3348 signal_error ("Invalid font", arg
);
3350 if (! NILP (Fequal (font_object
, oldval
)))
3353 x_new_font (f
, font_object
, fontset
);
3354 store_frame_param (f
, Qfont
, arg
);
3355 #ifdef HAVE_X_WINDOWS
3356 store_frame_param (f
, Qfont_param
, font_param
);
3358 /* Recalculate toolbar height. */
3359 f
->n_tool_bar_rows
= 0;
3361 /* Ensure we redraw it. */
3362 clear_current_matrices (f
);
3364 /* Attempt to hunt down bug#16028. */
3365 SET_FRAME_GARBAGED (f
);
3367 recompute_basic_faces (f
);
3369 do_pending_window_change (0);
3371 /* We used to call face-set-after-frame-default here, but it leads to
3372 recursive calls (since that function can set the `default' face's
3373 font which in turns changes the frame's `font' parameter).
3374 Also I don't know what this call is meant to do, but it seems the
3375 wrong way to do it anyway (it does a lot more work than what seems
3376 reasonable in response to a change to `font'). */
3381 x_set_font_backend (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3383 if (! NILP (new_value
)
3384 && !CONSP (new_value
))
3388 CHECK_STRING (new_value
);
3389 p0
= p1
= SSDATA (new_value
);
3393 while (*p1
&& ! c_isspace (*p1
) && *p1
!= ',') p1
++;
3395 new_value
= Fcons (Fintern (make_string (p0
, p1
- p0
), Qnil
),
3401 while ((c
= *++p1
) && c_isspace (c
));
3405 new_value
= Fnreverse (new_value
);
3408 if (! NILP (old_value
) && ! NILP (Fequal (old_value
, new_value
)))
3412 free_all_realized_faces (Qnil
);
3414 new_value
= font_update_drivers (f
, NILP (new_value
) ? Qt
: new_value
);
3415 if (NILP (new_value
))
3417 if (NILP (old_value
))
3418 error ("No font backend available");
3419 font_update_drivers (f
, old_value
);
3420 error ("None of specified font backends are available");
3422 store_frame_param (f
, Qfont_backend
, new_value
);
3428 XSETFRAME (frame
, f
);
3429 x_set_font (f
, Fframe_parameter (frame
, Qfont
), Qnil
);
3430 ++face_change_count
;
3431 windows_or_buffers_changed
= 18;
3437 x_set_fringe_width (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
3439 compute_fringe_widths (f
, 1);
3440 #ifdef HAVE_X_WINDOWS
3441 /* Must adjust this so window managers report correct number of columns. */
3442 if (FRAME_X_WINDOW (f
) != 0)
3443 x_wm_set_size_hint (f
, 0, 0);
3448 x_set_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3450 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3452 if (XINT (arg
) == f
->border_width
)
3455 if (FRAME_X_WINDOW (f
) != 0)
3456 error ("Cannot change the border width of a frame");
3458 f
->border_width
= XINT (arg
);
3462 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3464 int old
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3466 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3467 FRAME_INTERNAL_BORDER_WIDTH (f
) = XINT (arg
);
3468 if (FRAME_INTERNAL_BORDER_WIDTH (f
) < 0)
3469 FRAME_INTERNAL_BORDER_WIDTH (f
) = 0;
3471 #ifdef USE_X_TOOLKIT
3472 if (FRAME_X_OUTPUT (f
)->edit_widget
)
3473 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
3476 if (FRAME_INTERNAL_BORDER_WIDTH (f
) == old
)
3479 if (FRAME_X_WINDOW (f
) != 0)
3481 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3482 SET_FRAME_GARBAGED (f
);
3483 do_pending_window_change (0);
3486 SET_FRAME_GARBAGED (f
);
3490 x_set_right_divider_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3492 int old
= FRAME_RIGHT_DIVIDER_WIDTH (f
);
3494 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3495 FRAME_RIGHT_DIVIDER_WIDTH (f
) = XINT (arg
);
3496 if (FRAME_RIGHT_DIVIDER_WIDTH (f
) < 0)
3497 FRAME_RIGHT_DIVIDER_WIDTH (f
) = 0;
3499 if (FRAME_RIGHT_DIVIDER_WIDTH (f
) == old
)
3502 if (FRAME_X_WINDOW (f
) != 0)
3504 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3505 SET_FRAME_GARBAGED (f
);
3506 do_pending_window_change (0);
3509 SET_FRAME_GARBAGED (f
);
3513 x_set_bottom_divider_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3515 int old
= FRAME_BOTTOM_DIVIDER_WIDTH (f
);
3517 CHECK_TYPE_RANGED_INTEGER (int, arg
);
3518 FRAME_BOTTOM_DIVIDER_WIDTH (f
) = XINT (arg
);
3519 if (FRAME_BOTTOM_DIVIDER_WIDTH (f
) < 0)
3520 FRAME_BOTTOM_DIVIDER_WIDTH (f
) = 0;
3522 if (FRAME_BOTTOM_DIVIDER_WIDTH (f
) == old
)
3525 if (FRAME_X_WINDOW (f
) != 0)
3527 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 1);
3528 SET_FRAME_GARBAGED (f
);
3529 do_pending_window_change (0);
3532 SET_FRAME_GARBAGED (f
);
3536 x_set_visibility (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
3539 XSETFRAME (frame
, f
);
3542 Fmake_frame_invisible (frame
, Qt
);
3543 else if (EQ (value
, Qicon
))
3544 Ficonify_frame (frame
);
3546 Fmake_frame_visible (frame
);
3550 x_set_autoraise (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3552 f
->auto_raise
= !EQ (Qnil
, arg
);
3556 x_set_autolower (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3558 f
->auto_lower
= !EQ (Qnil
, arg
);
3562 x_set_unsplittable (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3564 f
->no_split
= !NILP (arg
);
3568 x_set_vertical_scroll_bars (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3570 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
3571 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
3572 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3573 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
3575 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
)
3577 ? vertical_scroll_bar_none
3579 ? vertical_scroll_bar_left
3581 ? vertical_scroll_bar_right
3582 : EQ (Qleft
, Vdefault_frame_scroll_bars
)
3583 ? vertical_scroll_bar_left
3584 : EQ (Qright
, Vdefault_frame_scroll_bars
)
3585 ? vertical_scroll_bar_right
3586 : vertical_scroll_bar_none
);
3588 /* We set this parameter before creating the X window for the
3589 frame, so we can get the geometry right from the start.
3590 However, if the window hasn't been created yet, we shouldn't
3591 call x_set_window_size. */
3592 if (FRAME_X_WINDOW (f
))
3593 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3594 FRAME_TEXT_HEIGHT (f
), 1);
3595 do_pending_window_change (0);
3600 x_set_scroll_bar_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3602 int unit
= FRAME_COLUMN_WIDTH (f
);
3606 x_set_scroll_bar_default_width (f
);
3608 if (FRAME_X_WINDOW (f
))
3609 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3610 FRAME_TEXT_HEIGHT (f
), 1);
3611 do_pending_window_change (0);
3613 else if (RANGED_INTEGERP (1, arg
, INT_MAX
)
3614 && XFASTINT (arg
) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f
))
3616 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = XFASTINT (arg
);
3617 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (XFASTINT (arg
) + unit
- 1) / unit
;
3618 if (FRAME_X_WINDOW (f
))
3619 x_set_window_size (f
, 0, FRAME_TEXT_WIDTH (f
),
3620 FRAME_TEXT_HEIGHT (f
), 1);
3621 do_pending_window_change (0);
3624 /* Eventually remove the following call. It should have been done by
3625 x_set_window_size already. */
3626 change_frame_size (f
, 0, 0, 0, 0, 0, 1);
3627 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
3628 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
3632 x_set_alpha (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
3639 for (i
= 0; i
< 2; i
++)
3652 else if (FLOATP (item
))
3654 alpha
= XFLOAT_DATA (item
);
3655 if (! (0 <= alpha
&& alpha
<= 1.0))
3656 args_out_of_range (make_float (0.0), make_float (1.0));
3658 else if (INTEGERP (item
))
3660 EMACS_INT ialpha
= XINT (item
);
3661 if (! (0 <= ialpha
&& alpha
<= 100))
3662 args_out_of_range (make_number (0), make_number (100));
3663 alpha
= ialpha
/ 100.0;
3666 wrong_type_argument (Qnumberp
, item
);
3670 for (i
= 0; i
< 2; i
++)
3671 f
->alpha
[i
] = newval
[i
];
3673 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3675 x_set_frame_alpha (f
);
3684 /* Non-zero if mouse is grabbed on DPYINFO
3685 and we know the frame where it is. */
3687 bool x_mouse_grabbed (Display_Info
*dpyinfo
)
3689 return (dpyinfo
->grabbed
3690 && dpyinfo
->last_mouse_frame
3691 && FRAME_LIVE_P (dpyinfo
->last_mouse_frame
));
3694 /* Re-highlight something with mouse-face properties
3695 on DPYINFO using saved frame and mouse position. */
3698 x_redo_mouse_highlight (Display_Info
*dpyinfo
)
3700 if (dpyinfo
->last_mouse_motion_frame
3701 && FRAME_LIVE_P (dpyinfo
->last_mouse_motion_frame
))
3702 note_mouse_highlight (dpyinfo
->last_mouse_motion_frame
,
3703 dpyinfo
->last_mouse_motion_x
,
3704 dpyinfo
->last_mouse_motion_y
);
3707 #endif /* HAVE_NS */
3709 /* Subroutines of creating an X frame. */
3711 /* Make sure that Vx_resource_name is set to a reasonable value.
3712 Fix it up, or set it to `emacs' if it is too hopeless. */
3715 validate_x_resource_name (void)
3718 /* Number of valid characters in the resource name. */
3719 ptrdiff_t good_count
= 0;
3720 /* Number of invalid characters in the resource name. */
3721 ptrdiff_t bad_count
= 0;
3725 if (!STRINGP (Vx_resource_class
))
3726 Vx_resource_class
= build_string (EMACS_CLASS
);
3728 if (STRINGP (Vx_resource_name
))
3730 unsigned char *p
= SDATA (Vx_resource_name
);
3732 len
= SBYTES (Vx_resource_name
);
3734 /* Only letters, digits, - and _ are valid in resource names.
3735 Count the valid characters and count the invalid ones. */
3736 for (i
= 0; i
< len
; i
++)
3739 if (! ((c
>= 'a' && c
<= 'z')
3740 || (c
>= 'A' && c
<= 'Z')
3741 || (c
>= '0' && c
<= '9')
3742 || c
== '-' || c
== '_'))
3749 /* Not a string => completely invalid. */
3750 bad_count
= 5, good_count
= 0;
3752 /* If name is valid already, return. */
3756 /* If name is entirely invalid, or nearly so, or is so implausibly
3757 large that alloca might not work, use `emacs'. */
3758 if (good_count
< 2 || MAX_ALLOCA
- sizeof ".customization" < len
)
3760 Vx_resource_name
= build_string ("emacs");
3764 /* Name is partly valid. Copy it and replace the invalid characters
3765 with underscores. */
3767 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
3769 for (i
= 0; i
< len
; i
++)
3771 int c
= SREF (new, i
);
3772 if (! ((c
>= 'a' && c
<= 'z')
3773 || (c
>= 'A' && c
<= 'Z')
3774 || (c
>= '0' && c
<= '9')
3775 || c
== '-' || c
== '_'))
3780 /* Get specified attribute from resource database RDB.
3781 See Fx_get_resource below for other parameters. */
3784 xrdb_get_resource (XrmDatabase rdb
, Lisp_Object attribute
, Lisp_Object
class, Lisp_Object component
, Lisp_Object subclass
)
3786 register char *value
;
3790 CHECK_STRING (attribute
);
3791 CHECK_STRING (class);
3793 if (!NILP (component
))
3794 CHECK_STRING (component
);
3795 if (!NILP (subclass
))
3796 CHECK_STRING (subclass
);
3797 if (NILP (component
) != NILP (subclass
))
3798 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3800 validate_x_resource_name ();
3802 /* Allocate space for the components, the dots which separate them,
3803 and the final '\0'. Make them big enough for the worst case. */
3804 name_key
= alloca (SBYTES (Vx_resource_name
)
3805 + (STRINGP (component
)
3806 ? SBYTES (component
) : 0)
3807 + SBYTES (attribute
)
3810 class_key
= alloca (SBYTES (Vx_resource_class
)
3812 + (STRINGP (subclass
)
3813 ? SBYTES (subclass
) : 0)
3816 /* Start with emacs.FRAMENAME for the name (the specific one)
3817 and with `Emacs' for the class key (the general one). */
3818 strcpy (name_key
, SSDATA (Vx_resource_name
));
3819 strcpy (class_key
, SSDATA (Vx_resource_class
));
3821 strcat (class_key
, ".");
3822 strcat (class_key
, SSDATA (class));
3824 if (!NILP (component
))
3826 strcat (class_key
, ".");
3827 strcat (class_key
, SSDATA (subclass
));
3829 strcat (name_key
, ".");
3830 strcat (name_key
, SSDATA (component
));
3833 strcat (name_key
, ".");
3834 strcat (name_key
, SSDATA (attribute
));
3836 value
= x_get_string_resource (rdb
, name_key
, class_key
);
3838 if (value
&& *value
)
3839 return build_string (value
);
3845 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
3846 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3847 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3848 class, where INSTANCE is the name under which Emacs was invoked, or
3849 the name specified by the `-name' or `-rn' command-line arguments.
3851 The optional arguments COMPONENT and SUBCLASS add to the key and the
3852 class, respectively. You must specify both of them or neither.
3853 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3854 and the class is `Emacs.CLASS.SUBCLASS'. */)
3855 (Lisp_Object attribute
, Lisp_Object
class, Lisp_Object component
,
3856 Lisp_Object subclass
)
3858 check_window_system (NULL
);
3860 return xrdb_get_resource (check_x_display_info (Qnil
)->xrdb
,
3861 attribute
, class, component
, subclass
);
3864 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3867 display_x_get_resource (Display_Info
*dpyinfo
, Lisp_Object attribute
,
3868 Lisp_Object
class, Lisp_Object component
,
3869 Lisp_Object subclass
)
3871 return xrdb_get_resource (dpyinfo
->xrdb
,
3872 attribute
, class, component
, subclass
);
3875 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3876 /* Used when C code wants a resource value. */
3877 /* Called from oldXMenu/Create.c. */
3879 x_get_resource_string (const char *attribute
, const char *class)
3882 struct frame
*sf
= SELECTED_FRAME ();
3883 ptrdiff_t invocation_namelen
= SBYTES (Vinvocation_name
);
3886 /* Allocate space for the components, the dots which separate them,
3887 and the final '\0'. */
3888 char *name_key
= SAFE_ALLOCA (invocation_namelen
+ strlen (attribute
) + 2);
3889 char *class_key
= alloca ((sizeof (EMACS_CLASS
) - 1) + strlen (class) + 2);
3891 esprintf (name_key
, "%s.%s", SSDATA (Vinvocation_name
), attribute
);
3892 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3894 result
= x_get_string_resource (FRAME_DISPLAY_INFO (sf
)->xrdb
,
3895 name_key
, class_key
);
3901 /* Return the value of parameter PARAM.
3903 First search ALIST, then Vdefault_frame_alist, then the X defaults
3904 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3906 Convert the resource to the type specified by desired_type.
3908 If no default is specified, return Qunbound. If you call
3909 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3910 and don't let it get stored in any Lisp-visible variables! */
3913 x_get_arg (Display_Info
*dpyinfo
, Lisp_Object alist
, Lisp_Object param
,
3914 const char *attribute
, const char *class, enum resource_types type
)
3916 register Lisp_Object tem
;
3918 tem
= Fassq (param
, alist
);
3922 /* If we find this parm in ALIST, clear it out
3923 so that it won't be "left over" at the end. */
3925 XSETCAR (tem
, Qnil
);
3926 /* In case the parameter appears more than once in the alist,
3928 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
3929 if (CONSP (XCAR (tail
))
3930 && EQ (XCAR (XCAR (tail
)), param
))
3931 XSETCAR (XCAR (tail
), Qnil
);
3934 tem
= Fassq (param
, Vdefault_frame_alist
);
3936 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3937 look in the X resources. */
3940 if (attribute
&& dpyinfo
)
3942 tem
= display_x_get_resource (dpyinfo
,
3943 build_string (attribute
),
3944 build_string (class),
3952 case RES_TYPE_NUMBER
:
3953 return make_number (atoi (SSDATA (tem
)));
3955 case RES_TYPE_BOOLEAN_NUMBER
:
3956 if (!strcmp (SSDATA (tem
), "on")
3957 || !strcmp (SSDATA (tem
), "true"))
3958 return make_number (1);
3959 return make_number (atoi (SSDATA (tem
)));
3962 case RES_TYPE_FLOAT
:
3963 return make_float (atof (SSDATA (tem
)));
3965 case RES_TYPE_BOOLEAN
:
3966 tem
= Fdowncase (tem
);
3967 if (!strcmp (SSDATA (tem
), "on")
3969 || !strcmp (SSDATA (tem
), "yes")
3971 || !strcmp (SSDATA (tem
), "true"))
3976 case RES_TYPE_STRING
:
3979 case RES_TYPE_SYMBOL
:
3980 /* As a special case, we map the values `true' and `on'
3981 to Qt, and `false' and `off' to Qnil. */
3984 lower
= Fdowncase (tem
);
3985 if (!strcmp (SSDATA (lower
), "on")
3987 || !strcmp (SSDATA (lower
), "yes")
3989 || !strcmp (SSDATA (lower
), "true"))
3991 else if (!strcmp (SSDATA (lower
), "off")
3993 || !strcmp (SSDATA (lower
), "no")
3995 || !strcmp (SSDATA (lower
), "false"))
3998 return Fintern (tem
, Qnil
);
4012 x_frame_get_arg (struct frame
*f
, Lisp_Object alist
, Lisp_Object param
,
4013 const char *attribute
, const char *class,
4014 enum resource_types type
)
4016 return x_get_arg (FRAME_DISPLAY_INFO (f
),
4017 alist
, param
, attribute
, class, type
);
4020 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4023 x_frame_get_and_record_arg (struct frame
*f
, Lisp_Object alist
,
4025 const char *attribute
, const char *class,
4026 enum resource_types type
)
4030 value
= x_get_arg (FRAME_DISPLAY_INFO (f
), alist
, param
,
4031 attribute
, class, type
);
4032 if (! NILP (value
) && ! EQ (value
, Qunbound
))
4033 store_frame_param (f
, param
, value
);
4039 /* Record in frame F the specified or default value according to ALIST
4040 of the parameter named PROP (a Lisp symbol).
4041 If no value is specified for PROP, look for an X default for XPROP
4042 on the frame named NAME.
4043 If that is not found either, use the value DEFLT. */
4046 x_default_parameter (struct frame
*f
, Lisp_Object alist
, Lisp_Object prop
,
4047 Lisp_Object deflt
, const char *xprop
, const char *xclass
,
4048 enum resource_types type
)
4052 tem
= x_frame_get_arg (f
, alist
, prop
, xprop
, xclass
, type
);
4053 if (EQ (tem
, Qunbound
))
4055 x_set_frame_parameters (f
, list1 (Fcons (prop
, tem
)));
4060 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4063 * XParseGeometry parses strings of the form
4064 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4065 * width, height, xoffset, and yoffset are unsigned integers.
4066 * Example: "=80x24+300-49"
4067 * The equal sign is optional.
4068 * It returns a bitmask that indicates which of the four values
4069 * were actually found in the string. For each value found,
4070 * the corresponding argument is updated; for each value
4071 * not found, the corresponding argument is left unchanged.
4075 XParseGeometry (char *string
,
4077 unsigned int *width
, unsigned int *height
)
4081 unsigned long tempWidth
, tempHeight
;
4082 long int tempX
, tempY
;
4083 char *nextCharacter
;
4085 if (string
== NULL
|| *string
== '\0')
4088 string
++; /* ignore possible '=' at beg of geometry spec */
4091 if (*strind
!= '+' && *strind
!= '-' && *strind
!= 'x')
4093 tempWidth
= strtoul (strind
, &nextCharacter
, 10);
4094 if (strind
== nextCharacter
)
4096 strind
= nextCharacter
;
4100 if (*strind
== 'x' || *strind
== 'X')
4103 tempHeight
= strtoul (strind
, &nextCharacter
, 10);
4104 if (strind
== nextCharacter
)
4106 strind
= nextCharacter
;
4107 mask
|= HeightValue
;
4110 if (*strind
== '+' || *strind
== '-')
4114 tempX
= strtol (strind
, &nextCharacter
, 10);
4115 if (strind
== nextCharacter
)
4117 strind
= nextCharacter
;
4119 if (*strind
== '+' || *strind
== '-')
4123 tempY
= strtol (strind
, &nextCharacter
, 10);
4124 if (strind
== nextCharacter
)
4126 strind
= nextCharacter
;
4131 /* If strind isn't at the end of the string then it's an invalid
4132 geometry specification. */
4134 if (*strind
!= '\0')
4138 *x
= clip_to_bounds (INT_MIN
, tempX
, INT_MAX
);
4140 *y
= clip_to_bounds (INT_MIN
, tempY
, INT_MAX
);
4141 if (mask
& WidthValue
)
4142 *width
= min (tempWidth
, UINT_MAX
);
4143 if (mask
& HeightValue
)
4144 *height
= min (tempHeight
, UINT_MAX
);
4148 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4151 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4152 make-docfile: the documentation string in ns-win.el was used for
4153 x-parse-geometry even in non-NS builds.
4155 With two definitions of x-parse-geometry in this file, various
4156 things still get confused (eg M-x apropos documentation), so that
4157 it is best if the two definitions just share the same doc-string.
4159 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
4160 doc
: /* Parse a display geometry string STRING.
4161 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4162 The properties returned may include `top', `left', `height', and `width'.
4163 For X, the value of `left' or `top' may be an integer,
4164 or a list (+ N) meaning N pixels relative to top/left corner,
4165 or a list (- N) meaning -N pixels relative to bottom/right corner.
4166 On Nextstep, this just calls `ns-parse-geometry'. */)
4167 (Lisp_Object string
)
4170 unsigned int width
, height
;
4173 CHECK_STRING (string
);
4176 if (strchr (SSDATA (string
), ' ') != NULL
)
4177 return call1 (Qns_parse_geometry
, string
);
4179 geometry
= XParseGeometry (SSDATA (string
),
4180 &x
, &y
, &width
, &height
);
4182 if (geometry
& XValue
)
4184 Lisp_Object element
;
4186 if (x
>= 0 && (geometry
& XNegative
))
4187 element
= list3 (Qleft
, Qminus
, make_number (-x
));
4188 else if (x
< 0 && ! (geometry
& XNegative
))
4189 element
= list3 (Qleft
, Qplus
, make_number (x
));
4191 element
= Fcons (Qleft
, make_number (x
));
4192 result
= Fcons (element
, result
);
4195 if (geometry
& YValue
)
4197 Lisp_Object element
;
4199 if (y
>= 0 && (geometry
& YNegative
))
4200 element
= list3 (Qtop
, Qminus
, make_number (-y
));
4201 else if (y
< 0 && ! (geometry
& YNegative
))
4202 element
= list3 (Qtop
, Qplus
, make_number (y
));
4204 element
= Fcons (Qtop
, make_number (y
));
4205 result
= Fcons (element
, result
);
4208 if (geometry
& WidthValue
)
4209 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
4210 if (geometry
& HeightValue
)
4211 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
4217 /* Calculate the desired size and position of frame F.
4218 Return the flags saying which aspects were specified.
4220 Also set the win_gravity and size_hint_flags of F.
4222 Adjust height for toolbar if TOOLBAR_P is 1.
4224 This function does not make the coordinates positive. */
4226 #define DEFAULT_ROWS 35
4227 #define DEFAULT_COLS 80
4230 x_figure_window_size (struct frame
*f
, Lisp_Object parms
, bool toolbar_p
)
4232 register Lisp_Object tem0
, tem1
, tem2
;
4233 long window_prompting
= 0;
4234 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
4236 /* Default values if we fall through.
4237 Actually, if that happens we should get
4238 window manager prompting. */
4239 SET_FRAME_WIDTH (f
, DEFAULT_COLS
* FRAME_COLUMN_WIDTH (f
));
4240 SET_FRAME_COLS (f
, DEFAULT_COLS
);
4241 SET_FRAME_HEIGHT (f
, DEFAULT_ROWS
* FRAME_LINE_HEIGHT (f
));
4242 FRAME_LINES (f
) = DEFAULT_ROWS
;
4244 /* Window managers expect that if program-specified
4245 positions are not (0,0), they're intentional, not defaults. */
4249 /* Ensure that old new_width and new_height will not override the
4251 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4252 f
->new_width
= f
->new_height
= f
->new_pixelwise
= 0;
4254 tem0
= x_get_arg (dpyinfo
, parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
4255 tem1
= x_get_arg (dpyinfo
, parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
4256 tem2
= x_get_arg (dpyinfo
, parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
4257 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
4259 if (!EQ (tem0
, Qunbound
))
4261 CHECK_NUMBER (tem0
);
4262 if (! (0 <= XINT (tem0
) && XINT (tem0
) <= INT_MAX
))
4263 xsignal1 (Qargs_out_of_range
, tem0
);
4264 FRAME_LINES (f
) = XINT (tem0
);
4266 if (!EQ (tem1
, Qunbound
))
4268 CHECK_NUMBER (tem1
);
4269 if (! (0 <= XINT (tem1
) && XINT (tem1
) <= INT_MAX
))
4270 xsignal1 (Qargs_out_of_range
, tem1
);
4271 SET_FRAME_COLS (f
, XINT (tem1
));
4273 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
4274 window_prompting
|= USSize
;
4276 window_prompting
|= PSize
;
4280 /* This used to be done _before_ calling x_figure_window_size, but
4281 since the height is reset here, this was really a no-op. I
4282 assume that moving it here does what Gerd intended (although he
4283 no longer can remember what that was... ++KFS, 2003-03-25. */
4285 /* Add the tool-bar height to the initial frame height so that the
4286 user gets a text display area of the size he specified with -g or
4287 via .Xdefaults. Later changes of the tool-bar height don't
4288 change the frame size. This is done so that users can create
4289 tall Emacs frames without having to guess how tall the tool-bar
4291 if (toolbar_p
&& FRAME_TOOL_BAR_HEIGHT (f
))
4293 int margin
, relief
, bar_height
;
4295 relief
= (tool_bar_button_relief
>= 0
4296 ? tool_bar_button_relief
4297 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
4299 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
, INT_MAX
))
4300 margin
= XFASTINT (Vtool_bar_button_margin
);
4301 else if (CONSP (Vtool_bar_button_margin
)
4302 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
), INT_MAX
))
4303 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
4307 /* PXW: We should be able to not round here. */
4308 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
4309 FRAME_LINES (f
) += (bar_height
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
4312 compute_fringe_widths (f
, 0);
4314 SET_FRAME_WIDTH (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
4315 SET_FRAME_HEIGHT(f
, FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
));
4317 tem0
= x_get_arg (dpyinfo
, parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
4318 tem1
= x_get_arg (dpyinfo
, parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
4319 tem2
= x_get_arg (dpyinfo
, parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
4320 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
4322 if (EQ (tem0
, Qminus
))
4325 window_prompting
|= YNegative
;
4327 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
4328 && CONSP (XCDR (tem0
))
4329 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (tem0
)), INT_MAX
))
4331 f
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
4332 window_prompting
|= YNegative
;
4334 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
4335 && CONSP (XCDR (tem0
))
4336 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0
))))
4338 f
->top_pos
= XINT (XCAR (XCDR (tem0
)));
4340 else if (EQ (tem0
, Qunbound
))
4344 CHECK_TYPE_RANGED_INTEGER (int, tem0
);
4345 f
->top_pos
= XINT (tem0
);
4347 window_prompting
|= YNegative
;
4350 if (EQ (tem1
, Qminus
))
4353 window_prompting
|= XNegative
;
4355 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
4356 && CONSP (XCDR (tem1
))
4357 && RANGED_INTEGERP (-INT_MAX
, XCAR (XCDR (tem1
)), INT_MAX
))
4359 f
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
4360 window_prompting
|= XNegative
;
4362 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
4363 && CONSP (XCDR (tem1
))
4364 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1
))))
4366 f
->left_pos
= XINT (XCAR (XCDR (tem1
)));
4368 else if (EQ (tem1
, Qunbound
))
4372 CHECK_TYPE_RANGED_INTEGER (int, tem1
);
4373 f
->left_pos
= XINT (tem1
);
4374 if (f
->left_pos
< 0)
4375 window_prompting
|= XNegative
;
4378 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
4379 window_prompting
|= USPosition
;
4381 window_prompting
|= PPosition
;
4384 if (window_prompting
& XNegative
)
4386 if (window_prompting
& YNegative
)
4387 f
->win_gravity
= SouthEastGravity
;
4389 f
->win_gravity
= NorthEastGravity
;
4393 if (window_prompting
& YNegative
)
4394 f
->win_gravity
= SouthWestGravity
;
4396 f
->win_gravity
= NorthWestGravity
;
4399 f
->size_hint_flags
= window_prompting
;
4401 return window_prompting
;
4406 #endif /* HAVE_WINDOW_SYSTEM */
4409 frame_make_pointer_invisible (struct frame
*f
)
4411 if (! NILP (Vmake_pointer_invisible
))
4413 if (f
&& FRAME_LIVE_P (f
) && !f
->pointer_invisible
4414 && FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook
)
4417 FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook (f
, 1);
4418 f
->pointer_invisible
= 1;
4424 frame_make_pointer_visible (struct frame
*f
)
4426 /* We don't check Vmake_pointer_invisible here in case the
4427 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4428 if (f
&& FRAME_LIVE_P (f
) && f
->pointer_invisible
&& f
->mouse_moved
4429 && FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook
)
4431 FRAME_TERMINAL (f
)->toggle_invisible_pointer_hook (f
, 0);
4432 f
->pointer_invisible
= 0;
4436 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p
,
4437 Sframe_pointer_visible_p
, 0, 1, 0,
4438 doc
: /* Return t if the mouse pointer displayed on FRAME is visible.
4439 Otherwise it returns nil. FRAME omitted or nil means the
4440 selected frame. This is useful when `make-pointer-invisible' is set. */)
4443 return decode_any_frame (frame
)->pointer_invisible
? Qnil
: Qt
;
4448 /***********************************************************************
4450 ***********************************************************************/
4452 #ifdef HAVE_WINDOW_SYSTEM
4454 # if (defined HAVE_NS \
4455 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4457 free_monitors (struct MonitorInfo
*monitors
, int n_monitors
)
4460 for (i
= 0; i
< n_monitors
; ++i
)
4461 xfree (monitors
[i
].name
);
4467 make_monitor_attribute_list (struct MonitorInfo
*monitors
,
4469 int primary_monitor
,
4470 Lisp_Object monitor_frames
,
4473 Lisp_Object attributes_list
= Qnil
;
4474 Lisp_Object primary_monitor_attributes
= Qnil
;
4477 for (i
= 0; i
< n_monitors
; ++i
)
4479 Lisp_Object geometry
, workarea
, attributes
= Qnil
;
4480 struct MonitorInfo
*mi
= &monitors
[i
];
4482 if (mi
->geom
.width
== 0) continue;
4484 workarea
= list4i (mi
->work
.x
, mi
->work
.y
,
4485 mi
->work
.width
, mi
->work
.height
);
4486 geometry
= list4i (mi
->geom
.x
, mi
->geom
.y
,
4487 mi
->geom
.width
, mi
->geom
.height
);
4488 attributes
= Fcons (Fcons (Qsource
, build_string (source
)),
4490 attributes
= Fcons (Fcons (Qframes
, AREF (monitor_frames
, i
)),
4492 attributes
= Fcons (Fcons (Qmm_size
,
4493 list2i (mi
->mm_width
, mi
->mm_height
)),
4495 attributes
= Fcons (Fcons (Qworkarea
, workarea
), attributes
);
4496 attributes
= Fcons (Fcons (Qgeometry
, geometry
), attributes
);
4498 attributes
= Fcons (Fcons (Qname
, make_string (mi
->name
,
4499 strlen (mi
->name
))),
4502 if (i
== primary_monitor
)
4503 primary_monitor_attributes
= attributes
;
4505 attributes_list
= Fcons (attributes
, attributes_list
);
4508 if (!NILP (primary_monitor_attributes
))
4509 attributes_list
= Fcons (primary_monitor_attributes
, attributes_list
);
4510 return attributes_list
;
4513 #endif /* HAVE_WINDOW_SYSTEM */
4516 /***********************************************************************
4518 ***********************************************************************/
4521 syms_of_frame (void)
4523 DEFSYM (Qframep
, "framep");
4524 DEFSYM (Qframe_live_p
, "frame-live-p");
4525 DEFSYM (Qexplicit_name
, "explicit-name");
4526 DEFSYM (Qheight
, "height");
4527 DEFSYM (Qicon
, "icon");
4528 DEFSYM (Qminibuffer
, "minibuffer");
4529 DEFSYM (Qmodeline
, "modeline");
4530 DEFSYM (Qonly
, "only");
4531 DEFSYM (Qnone
, "none");
4532 DEFSYM (Qwidth
, "width");
4533 DEFSYM (Qgeometry
, "geometry");
4534 DEFSYM (Qicon_left
, "icon-left");
4535 DEFSYM (Qicon_top
, "icon-top");
4536 DEFSYM (Qtooltip
, "tooltip");
4537 DEFSYM (Qleft
, "left");
4538 DEFSYM (Qright
, "right");
4539 DEFSYM (Quser_position
, "user-position");
4540 DEFSYM (Quser_size
, "user-size");
4541 DEFSYM (Qwindow_id
, "window-id");
4542 #ifdef HAVE_X_WINDOWS
4543 DEFSYM (Qouter_window_id
, "outer-window-id");
4545 DEFSYM (Qparent_id
, "parent-id");
4547 DEFSYM (Qw32
, "w32");
4550 DEFSYM (Qvisible
, "visible");
4551 DEFSYM (Qbuffer_predicate
, "buffer-predicate");
4552 DEFSYM (Qbuffer_list
, "buffer-list");
4553 DEFSYM (Qburied_buffer_list
, "buried-buffer-list");
4554 DEFSYM (Qdisplay_type
, "display-type");
4555 DEFSYM (Qbackground_mode
, "background-mode");
4556 DEFSYM (Qnoelisp
, "noelisp");
4557 DEFSYM (Qtty_color_mode
, "tty-color-mode");
4558 DEFSYM (Qtty
, "tty");
4559 DEFSYM (Qtty_type
, "tty-type");
4561 DEFSYM (Qface_set_after_frame_default
, "face-set-after-frame-default");
4563 DEFSYM (Qfullwidth
, "fullwidth");
4564 DEFSYM (Qfullheight
, "fullheight");
4565 DEFSYM (Qfullboth
, "fullboth");
4566 DEFSYM (Qmaximized
, "maximized");
4567 DEFSYM (Qx_resource_name
, "x-resource-name");
4568 DEFSYM (Qx_frame_parameter
, "x-frame-parameter");
4570 DEFSYM (Qterminal
, "terminal");
4572 DEFSYM (Qgeometry
, "geometry");
4573 DEFSYM (Qworkarea
, "workarea");
4574 DEFSYM (Qmm_size
, "mm-size");
4575 DEFSYM (Qframes
, "frames");
4576 DEFSYM (Qsource
, "source");
4579 DEFSYM (Qns_parse_geometry
, "ns-parse-geometry");
4585 for (i
= 0; i
< ARRAYELTS (frame_parms
); i
++)
4587 Lisp_Object v
= intern_c_string (frame_parms
[i
].name
);
4588 if (frame_parms
[i
].variable
)
4590 *frame_parms
[i
].variable
= v
;
4591 staticpro (frame_parms
[i
].variable
);
4593 Fput (v
, Qx_frame_parameter
, make_number (i
));
4597 #ifdef HAVE_WINDOW_SYSTEM
4598 DEFVAR_LISP ("x-resource-name", Vx_resource_name
,
4599 doc
: /* The name Emacs uses to look up X resources.
4600 `x-get-resource' uses this as the first component of the instance name
4601 when requesting resource values.
4602 Emacs initially sets `x-resource-name' to the name under which Emacs
4603 was invoked, or to the value specified with the `-name' or `-rn'
4604 switches, if present.
4606 It may be useful to bind this variable locally around a call
4607 to `x-get-resource'. See also the variable `x-resource-class'. */);
4608 Vx_resource_name
= Qnil
;
4610 DEFVAR_LISP ("x-resource-class", Vx_resource_class
,
4611 doc
: /* The class Emacs uses to look up X resources.
4612 `x-get-resource' uses this as the first component of the instance class
4613 when requesting resource values.
4615 Emacs initially sets `x-resource-class' to "Emacs".
4617 Setting this variable permanently is not a reasonable thing to do,
4618 but binding this variable locally around a call to `x-get-resource'
4619 is a reasonable practice. See also the variable `x-resource-name'. */);
4620 Vx_resource_class
= build_string (EMACS_CLASS
);
4622 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit
,
4623 doc
: /* The lower limit of the frame opacity (alpha transparency).
4624 The value should range from 0 (invisible) to 100 (completely opaque).
4625 You can also use a floating number between 0.0 and 1.0. */);
4626 Vframe_alpha_lower_limit
= make_number (20);
4629 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist
,
4630 doc
: /* Alist of default values for frame creation.
4631 These may be set in your init file, like this:
4632 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4633 These override values given in window system configuration data,
4634 including X Windows' defaults database.
4635 For values specific to the first Emacs frame, see `initial-frame-alist'.
4636 For window-system specific values, see `window-system-default-frame-alist'.
4637 For values specific to the separate minibuffer frame, see
4638 `minibuffer-frame-alist'.
4639 The `menu-bar-lines' element of the list controls whether new frames
4640 have menu bars; `menu-bar-mode' works by altering this element.
4641 Setting this variable does not affect existing frames, only new ones. */);
4642 Vdefault_frame_alist
= Qnil
;
4644 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars
,
4645 doc
: /* Default position of scroll bars on this window-system. */);
4646 #ifdef HAVE_WINDOW_SYSTEM
4647 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4648 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4650 Vdefault_frame_scroll_bars
= Qright
;
4652 Vdefault_frame_scroll_bars
= Qleft
;
4655 Vdefault_frame_scroll_bars
= Qnil
;
4658 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4659 scroll_bar_adjust_thumb_portion_p
,
4660 doc
: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4661 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4662 even if the end of the buffer is shown (i.e. overscrolling).
4663 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4664 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4665 is visible. In this case you can not overscroll. */);
4666 scroll_bar_adjust_thumb_portion_p
= 1;
4668 DEFVAR_LISP ("terminal-frame", Vterminal_frame
,
4669 doc
: /* The initial frame-object, which represents Emacs's stdout. */);
4671 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function
,
4672 doc
: /* If non-nil, function to transform normal value of `mouse-position'.
4673 `mouse-position' calls this function, passing its usual return value as
4674 argument, and returns whatever this function returns.
4675 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4676 which need to do mouse handling at the Lisp level. */);
4677 Vmouse_position_function
= Qnil
;
4679 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight
,
4680 doc
: /* If non-nil, clickable text is highlighted when mouse is over it.
4681 If the value is an integer, highlighting is only shown after moving the
4682 mouse, while keyboard input turns off the highlight even when the mouse
4683 is over the clickable text. However, the mouse shape still indicates
4684 when the mouse is over clickable text. */);
4685 Vmouse_highlight
= Qt
;
4687 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible
,
4688 doc
: /* If non-nil, make pointer invisible while typing.
4689 The pointer becomes visible again when the mouse is moved. */);
4690 Vmake_pointer_invisible
= Qt
;
4692 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook
,
4693 doc
: /* Normal hook run when a frame gains input focus. */);
4694 Vfocus_in_hook
= Qnil
;
4695 DEFSYM (Qfocus_in_hook
, "focus-in-hook");
4697 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook
,
4698 doc
: /* Normal hook run when a frame loses input focus. */);
4699 Vfocus_out_hook
= Qnil
;
4700 DEFSYM (Qfocus_out_hook
, "focus-out-hook");
4702 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions
,
4703 doc
: /* Functions run before deleting a frame.
4704 The functions are run with one arg, the frame to be deleted.
4707 Note that functions in this list may be called just before the frame is
4708 actually deleted, or some time later (or even both when an earlier function
4709 in `delete-frame-functions' (indirectly) calls `delete-frame'
4711 Vdelete_frame_functions
= Qnil
;
4712 DEFSYM (Qdelete_frame_functions
, "delete-frame-functions");
4714 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode
,
4715 doc
: /* Non-nil if Menu-Bar mode is enabled.
4716 See the command `menu-bar-mode' for a description of this minor mode.
4717 Setting this variable directly does not take effect;
4718 either customize it (see the info node `Easy Customization')
4719 or call the function `menu-bar-mode'. */);
4720 Vmenu_bar_mode
= Qt
;
4722 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode
,
4723 doc
: /* Non-nil if Tool-Bar mode is enabled.
4724 See the command `tool-bar-mode' for a description of this minor mode.
4725 Setting this variable directly does not take effect;
4726 either customize it (see the info node `Easy Customization')
4727 or call the function `tool-bar-mode'. */);
4728 #ifdef HAVE_WINDOW_SYSTEM
4729 Vtool_bar_mode
= Qt
;
4731 Vtool_bar_mode
= Qnil
;
4734 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame
,
4735 doc
: /* Minibufferless frames use this frame's minibuffer.
4736 Emacs cannot create minibufferless frames unless this is set to an
4737 appropriate surrogate.
4739 Emacs consults this variable only when creating minibufferless
4740 frames; once the frame is created, it sticks with its assigned
4741 minibuffer, no matter what this variable is set to. This means that
4742 this variable doesn't necessarily say anything meaningful about the
4743 current set of frames, or where the minibuffer is currently being
4746 This variable is local to the current terminal and cannot be buffer-local. */);
4748 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse
,
4749 doc
: /* Non-nil if window system changes focus when you move the mouse.
4750 You should set this variable to tell Emacs how your window manager
4751 handles focus, since there is no way in general for Emacs to find out
4752 automatically. See also `mouse-autoselect-window'. */);
4753 focus_follows_mouse
= 0;
4755 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise
,
4756 doc
: /* Non-nil means resize frames pixelwise.
4757 If this option is nil, resizing a frame rounds its sizes to the frame's
4758 current values of `frame-char-height' and `frame-char-width'. If this
4759 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4762 With some window managers you have to set this to non-nil in order to
4763 fully maximize frames. To resize your initial frame pixelwise,
4764 set this option to a non-nil value in your init file. */);
4765 frame_resize_pixelwise
= 0;
4767 staticpro (&Vframe_list
);
4770 defsubr (&Sframe_live_p
);
4771 defsubr (&Swindow_system
);
4772 defsubr (&Smake_terminal_frame
);
4773 defsubr (&Shandle_switch_frame
);
4774 defsubr (&Sselect_frame
);
4775 defsubr (&Sselected_frame
);
4776 defsubr (&Sframe_list
);
4777 defsubr (&Snext_frame
);
4778 defsubr (&Sprevious_frame
);
4779 defsubr (&Slast_nonminibuf_frame
);
4780 defsubr (&Sdelete_frame
);
4781 defsubr (&Smouse_position
);
4782 defsubr (&Smouse_pixel_position
);
4783 defsubr (&Sset_mouse_position
);
4784 defsubr (&Sset_mouse_pixel_position
);
4786 defsubr (&Sframe_configuration
);
4787 defsubr (&Srestore_frame_configuration
);
4789 defsubr (&Smake_frame_visible
);
4790 defsubr (&Smake_frame_invisible
);
4791 defsubr (&Siconify_frame
);
4792 defsubr (&Sframe_visible_p
);
4793 defsubr (&Svisible_frame_list
);
4794 defsubr (&Sraise_frame
);
4795 defsubr (&Slower_frame
);
4796 defsubr (&Sx_focus_frame
);
4797 defsubr (&Sredirect_frame_focus
);
4798 defsubr (&Sframe_focus
);
4799 defsubr (&Sframe_parameters
);
4800 defsubr (&Sframe_parameter
);
4801 defsubr (&Smodify_frame_parameters
);
4802 defsubr (&Sframe_char_height
);
4803 defsubr (&Sframe_char_width
);
4804 defsubr (&Sframe_pixel_height
);
4805 defsubr (&Sframe_pixel_width
);
4806 defsubr (&Sframe_text_cols
);
4807 defsubr (&Sframe_text_lines
);
4808 defsubr (&Sframe_total_cols
);
4809 defsubr (&Sframe_text_width
);
4810 defsubr (&Sframe_text_height
);
4811 defsubr (&Sscroll_bar_width
);
4812 defsubr (&Sfringe_width
);
4813 defsubr (&Sborder_width
);
4814 defsubr (&Sright_divider_width
);
4815 defsubr (&Sbottom_divider_width
);
4816 defsubr (&Stool_bar_pixel_width
);
4817 defsubr (&Sset_frame_height
);
4818 defsubr (&Sset_frame_width
);
4819 defsubr (&Sset_frame_size
);
4820 defsubr (&Sset_frame_position
);
4821 defsubr (&Sframe_pointer_visible_p
);
4823 #ifdef HAVE_WINDOW_SYSTEM
4824 defsubr (&Sx_get_resource
);
4825 defsubr (&Sx_parse_geometry
);