use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / frame.c
CommitLineData
ff11dfa1 1/* Generic frame functions.
e9bffc61 2
ba318903 3Copyright (C) 1993-1995, 1997, 1999-2014 Free Software Foundation, Inc.
dc6f92b8
JB
4
5This file is part of GNU Emacs.
6
9ec0b715 7GNU Emacs is free software: you can redistribute it and/or modify
dc6f92b8 8it under the terms of the GNU General Public License as published by
9ec0b715
GM
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
dc6f92b8
JB
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
9ec0b715 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
dc6f92b8 19
18160b98 20#include <config.h>
565620a5
RS
21
22#include <stdio.h>
9055082e
PE
23#include <errno.h>
24#include <limits.h>
620f13b0
PE
25
26#include <c-ctype.h>
27
cc38027b 28#include "lisp.h"
83be827a 29#include "character.h"
17a2cbbd
DC
30
31#ifdef HAVE_WINDOW_SYSTEM
32#include TERM_HEADER
33#endif /* HAVE_WINDOW_SYSTEM */
34
2538fae4
AI
35#include "buffer.h"
36/* These help us bind and responding to switch-frame events. */
37#include "commands.h"
38#include "keyboard.h"
cc38027b 39#include "frame.h"
972f4259 40#include "blockinput.h"
28d440ab 41#include "termchar.h"
bc1ed486 42#include "termhooks.h"
dfcf069d 43#include "dispextern.h"
f769f1b2 44#include "window.h"
e0c8ad78 45#include "font.h"
2cc7b62f 46#ifdef HAVE_WINDOW_SYSTEM
e0c8ad78
KH
47#include "fontset.h"
48#endif
87485d6f
MW
49#ifdef MSDOS
50#include "msdos.h"
4aec4b29 51#include "dosfns.h"
87485d6f 52#endif
73bfe891
PE
53#ifdef USE_X_TOOLKIT
54#include "widget.h"
55#endif
e5d77022 56
dc4db71c
CY
57#ifdef HAVE_NS
58Lisp_Object Qns_parse_geometry;
59#endif
60
972f4259
KS
61Lisp_Object Qframep, Qframe_live_p;
62Lisp_Object Qicon, Qmodeline;
9fb0c957 63Lisp_Object Qonly, Qnone;
4b298d5a 64Lisp_Object Qx, Qw32, Qpc, Qns;
f7af3f7b 65Lisp_Object Qvisible;
8b60f7bc 66Lisp_Object Qdisplay_type;
955cbe7b 67static Lisp_Object Qbackground_mode;
c53956fe 68Lisp_Object Qnoelisp;
972f4259 69
955cbe7b 70static Lisp_Object Qx_frame_parameter;
972f4259 71Lisp_Object Qx_resource_name;
6ed8eeff 72Lisp_Object Qterminal;
972f4259
KS
73
74/* Frame parameters (set or reported). */
75
76Lisp_Object Qauto_raise, Qauto_lower;
77Lisp_Object Qborder_color, Qborder_width;
78Lisp_Object Qcursor_color, Qcursor_type;
972f4259
KS
79Lisp_Object Qheight, Qwidth;
80Lisp_Object Qleft, Qright;
81Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
54ee7410 82Lisp_Object Qtooltip;
972f4259 83Lisp_Object Qinternal_border_width;
880e6158 84Lisp_Object Qright_divider_width, Qbottom_divider_width;
972f4259
KS
85Lisp_Object Qmouse_color;
86Lisp_Object Qminibuffer;
87Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
88Lisp_Object Qvisibility;
89Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
90Lisp_Object Qscreen_gamma;
91Lisp_Object Qline_spacing;
955cbe7b 92static Lisp_Object Quser_position, Quser_size;
972f4259 93Lisp_Object Qwait_for_wm;
955cbe7b 94static Lisp_Object Qwindow_id;
972f4259 95#ifdef HAVE_X_WINDOWS
955cbe7b 96static Lisp_Object Qouter_window_id;
972f4259
KS
97#endif
98Lisp_Object Qparent_id;
99Lisp_Object Qtitle, Qname;
955cbe7b 100static Lisp_Object Qexplicit_name;
972f4259 101Lisp_Object Qunsplittable;
bfeabdc3 102Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
972f4259 103Lisp_Object Qleft_fringe, Qright_fringe;
955cbe7b
PE
104Lisp_Object Qbuffer_predicate;
105static Lisp_Object Qbuffer_list, Qburied_buffer_list;
94674d18 106Lisp_Object Qtty_color_mode;
28d440ab 107Lisp_Object Qtty, Qtty_type;
dc6f92b8 108
3f1c6666 109Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
cad9ef74 110Lisp_Object Qsticky;
1a356571 111Lisp_Object Qfont_backend;
0a708637 112Lisp_Object Qalpha;
972f4259
KS
113
114Lisp_Object Qface_set_after_frame_default;
115
8e015705
BJ
116static Lisp_Object Qfocus_in_hook;
117static Lisp_Object Qfocus_out_hook;
29208e82 118static Lisp_Object Qdelete_frame_functions;
da1da002 119
3d5ee10a 120static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
6799bb26 121
5492865b
DA
122/* The currently selected frame. */
123
124Lisp_Object selected_frame;
125
126/* A frame which is not just a mini-buffer, or NULL if there are no such
127 frames. This is usually the most recent such frame that was selected. */
128
129static struct frame *last_nonminibuf_frame;
130
caecb91c 131/* False means there are no visible garbaged frames. */
5492865b
DA
132bool frame_garbaged;
133
81626931
PE
134#ifdef HAVE_WINDOW_SYSTEM
135static void x_report_frame_params (struct frame *, Lisp_Object *);
136#endif
137
f00af5b1 138/* These setters are used only in this file, so they can be private. */
b0ab8123 139static void
f00af5b1
PE
140fset_buffer_predicate (struct frame *f, Lisp_Object val)
141{
142 f->buffer_predicate = val;
143}
b0ab8123 144static void
f00af5b1
PE
145fset_minibuffer_window (struct frame *f, Lisp_Object val)
146{
147 f->minibuffer_window = val;
148}
149
d9f07150
DA
150struct frame *
151decode_live_frame (register Lisp_Object frame)
152{
153 if (NILP (frame))
154 frame = selected_frame;
155 CHECK_LIVE_FRAME (frame);
156 return XFRAME (frame);
157}
158
159struct frame *
160decode_any_frame (register Lisp_Object frame)
161{
162 if (NILP (frame))
163 frame = selected_frame;
164 CHECK_FRAME (frame);
165 return XFRAME (frame);
166}
167
bd009aef
DA
168#ifdef HAVE_WINDOW_SYSTEM
169
7452b7bd
DA
170bool
171window_system_available (struct frame *f)
172{
bd009aef 173 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
7452b7bd
DA
174}
175
bd009aef
DA
176#endif /* HAVE_WINDOW_SYSTEM */
177
7452b7bd
DA
178struct frame *
179decode_window_system_frame (Lisp_Object frame)
180{
181 struct frame *f = decode_live_frame (frame);
3d5ee10a 182
7452b7bd
DA
183 if (!window_system_available (f))
184 error ("Window system frame should be used");
185 return f;
186}
187
188void
189check_window_system (struct frame *f)
190{
191 if (!window_system_available (f))
192 error (f ? "Window system frame should be used"
193 : "Window system is not in use or not initialized");
194}
195
a249de79 196static void
971de7fb 197set_menu_bar_lines_1 (Lisp_Object window, int n)
a249de79
RS
198{
199 struct window *w = XWINDOW (window);
880e6158 200 struct frame *f = XFRAME (WINDOW_FRAME (w));
a249de79 201
5f24fa51 202 w->top_line += n;
880e6158 203 w->pixel_top += n * FRAME_LINE_HEIGHT (f);
5f24fa51 204 w->total_lines -= n;
880e6158 205 w->pixel_height -= n * FRAME_LINE_HEIGHT (f);
177c0ea7 206
a249de79 207 /* Handle just the top child in a vertical split. */
e74aeda8
DA
208 if (WINDOW_VERTICAL_COMBINATION_P (w))
209 set_menu_bar_lines_1 (w->contents, n);
210 else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
211 /* Adjust all children in a horizontal split. */
212 for (window = w->contents; !NILP (window); window = w->next)
213 {
214 w = XWINDOW (window);
215 set_menu_bar_lines_1 (window, n);
216 }
a249de79
RS
217}
218
e48f782c 219void
971de7fb 220set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
a249de79
RS
221{
222 int nlines;
223 int olines = FRAME_MENU_BAR_LINES (f);
224
225 /* Right now, menu bars don't work properly in minibuf-only frames;
226 most of the commands try to apply themselves to the minibuffer
e3678b64 227 frame itself, and get an error because you can't switch buffers
a249de79
RS
228 in or split the minibuffer window. */
229 if (FRAME_MINIBUF_ONLY_P (f))
230 return;
231
b8898fda 232 if (TYPE_RANGED_INTEGERP (int, value))
a249de79
RS
233 nlines = XINT (value);
234 else
235 nlines = 0;
236
57aeea1e
RS
237 if (nlines != olines)
238 {
94ae2ad4 239 windows_or_buffers_changed = 14;
57aeea1e
RS
240 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
241 FRAME_MENU_BAR_LINES (f) = nlines;
880e6158 242 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
e69b0960 243 set_menu_bar_lines_1 (f->root_window, nlines - olines);
bd0443bb 244 adjust_frame_glyphs (f);
57aeea1e 245 }
a249de79
RS
246}
247\f
a249de79 248Lisp_Object Vframe_list;
a249de79 249
dc6f92b8 250\f
ff11dfa1 251DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
14ff1ee0 252 doc: /* Return non-nil if OBJECT is a frame.
89baa1df
EZ
253Value is:
254 t for a termcap frame (a character-only terminal),
255 'x' for an Emacs frame that is really an X window,
256 'w32' for an Emacs frame that is a window on MS-Windows display,
257 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
258 'pc' for a direct-write MS-DOS frame.
14ff1ee0 259See also `frame-live-p'. */)
5842a27b 260 (Lisp_Object object)
dc6f92b8 261{
e35d291d 262 if (!FRAMEP (object))
dc6f92b8 263 return Qnil;
ff11dfa1 264 switch (XFRAME (object)->output_method)
dc6f92b8 265 {
3224dac1 266 case output_initial: /* The initial frame is like a termcap frame. */
dc6f92b8
JB
267 case output_termcap:
268 return Qt;
269 case output_x_window:
fd0c2bd1 270 return Qx;
fbd6baed
GV
271 case output_w32:
272 return Qw32;
bb221971
RS
273 case output_msdos_raw:
274 return Qpc;
edfda783
AR
275 case output_ns:
276 return Qns;
dc6f92b8 277 default:
1088b922 278 emacs_abort ();
dc6f92b8
JB
279 }
280}
281
dbc4e1c1 282DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
14ff1ee0
PJ
283 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
284Value is nil if OBJECT is not a live frame. If object is a live
6ed8eeff 285frame, the return value indicates what sort of terminal device it is
f6fa0866 286displayed on. See the documentation of `framep' for possible
4e10df59 287return values. */)
5842a27b 288 (Lisp_Object object)
f9898cc6 289{
ff11dfa1
JB
290 return ((FRAMEP (object)
291 && FRAME_LIVE_P (XFRAME (object)))
292 ? Fframep (object)
f9898cc6
JB
293 : Qnil);
294}
295
a7ca3326 296DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
428a555e 297 doc: /* The name of the window system that FRAME is displaying through.
89baa1df
EZ
298The value is a symbol:
299 nil for a termcap frame (a character-only terminal),
300 'x' for an Emacs frame that is really an X window,
301 'w32' for an Emacs frame that is a window on MS-Windows display,
302 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
303 'pc' for a direct-write MS-DOS frame.
304
305FRAME defaults to the currently selected frame.
306
307Use of this function as a predicate is deprecated. Instead,
308use `display-graphic-p' or any of the other `display-*-p'
309predicates which report frame's specific UI-related capabilities. */)
5842a27b 310 (Lisp_Object frame)
428a555e
KL
311{
312 Lisp_Object type;
313 if (NILP (frame))
314 frame = selected_frame;
315
316 type = Fframep (frame);
317
318 if (NILP (type))
319 wrong_type_argument (Qframep, frame);
320
321 if (EQ (type, Qt))
322 return Qnil;
323 else
324 return type;
a3547743 325}
428a555e 326
ff11dfa1 327struct frame *
959067a1 328make_frame (bool mini_p)
dc6f92b8 329{
ff11dfa1
JB
330 Lisp_Object frame;
331 register struct frame *f;
880e6158 332 register struct window *rw, *mw;
dc6f92b8
JB
333 register Lisp_Object root_window;
334 register Lisp_Object mini_window;
e9c96c62
GM
335
336 f = allocate_frame ();
36af7d69 337 XSETFRAME (frame, f);
ff11dfa1 338
62efea5e
DA
339 /* Initialize Lisp data. Note that allocate_frame initializes all
340 Lisp data to nil, so do it only for slots which should not be nil. */
f00af5b1 341 fset_tool_bar_position (f, Qtop);
62efea5e
DA
342
343 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
344 non-Lisp data, so do it only for slots which should not be zero.
345 To avoid subtle bugs and for the sake of readability, it's better to
346 initialize enum members explicitly even if their values are zero. */
655ab9a3
SM
347 f->wants_modeline = true;
348 f->redisplay = true;
349 f->garbaged = true;
3a43d2dd 350 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
655ab9a3
SM
351 f->column_width = 1; /* !FRAME_WINDOW_P value. */
352 f->line_height = 1; /* !FRAME_WINDOW_P value. */
93421a1f 353#ifdef HAVE_WINDOW_SYSTEM
5af5757b 354 f->want_fullscreen = FULLSCREEN_NONE;
bfd55935
DA
355#if ! defined (USE_GTK) && ! defined (HAVE_NS)
356 f->last_tool_bar_item = -1;
357#endif
93421a1f 358#endif
dc6f92b8 359
cc38027b 360 root_window = make_window ();
880e6158 361 rw = XWINDOW (root_window);
dc6f92b8
JB
362 if (mini_p)
363 {
cc38027b 364 mini_window = make_window ();
880e6158
MR
365 mw = XWINDOW (mini_window);
366 wset_next (rw, mini_window);
367 wset_prev (mw, root_window);
368 mw->mini = 1;
369 wset_frame (mw, frame);
f00af5b1 370 fset_minibuffer_window (f, mini_window);
dc6f92b8
JB
371 }
372 else
373 {
374 mini_window = Qnil;
880e6158 375 wset_next (rw, Qnil);
f00af5b1 376 fset_minibuffer_window (f, Qnil);
dc6f92b8
JB
377 }
378
880e6158 379 wset_frame (rw, frame);
dc6f92b8
JB
380
381 /* 10 is arbitrary,
382 just so that there is "something there."
ff11dfa1 383 Correct size will be set up later with change_frame_size. */
dc6f92b8 384
5af5757b
KS
385 SET_FRAME_COLS (f, 10);
386 FRAME_LINES (f) = 10;
880e6158
MR
387 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
388 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
dc6f92b8 389
880e6158
MR
390 rw->total_cols = 10;
391 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
392 rw->total_lines = mini_p ? 9 : 10;
393 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
dc6f92b8
JB
394
395 if (mini_p)
396 {
880e6158
MR
397 mw->top_line = rw->total_lines;
398 mw->pixel_top = rw->pixel_height;
399 mw->total_cols = rw->total_cols;
400 mw->pixel_width = rw->pixel_width;
401 mw->total_lines = 1;
402 mw->pixel_height = FRAME_LINE_HEIGHT (f);
dc6f92b8
JB
403 }
404
ff11dfa1 405 /* Choose a buffer for the frame's root window. */
5bce042c 406 {
ed08365b 407 Lisp_Object buf = Fcurrent_buffer ();
5bce042c 408
ed08365b
DA
409 /* If current buffer is hidden, try to find another one. */
410 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
e10ac9f1 411 buf = other_buffer_safely (buf);
fa54c6ae 412
18082e2d
GM
413 /* Use set_window_buffer, not Fset_window_buffer, and don't let
414 hooks be run by it. The reason is that the whole frame/window
cd1181db 415 arrangement is not yet fully initialized at this point. Windows
18082e2d
GM
416 don't have the right size, glyph matrices aren't initialized
417 etc. Running Lisp functions at this point surely ends in a
418 SEGV. */
5af5757b 419 set_window_buffer (root_window, buf, 0, 0);
6c6f1994 420 fset_buffer_list (f, list1 (buf));
5bce042c
JB
421 }
422
dc6f92b8 423 if (mini_p)
822995f8
DA
424 set_window_buffer (mini_window,
425 (NILP (Vminibuffer_list)
426 ? get_minibuffer (0)
427 : Fcar (Vminibuffer_list)),
428 0, 0);
dc6f92b8 429
f00af5b1
PE
430 fset_root_window (f, root_window);
431 fset_selected_window (f, root_window);
d5e7c279
JB
432 /* Make sure this window seems more recently used than
433 a newly-created, never-selected window. */
e69b0960 434 XWINDOW (f->selected_window)->use_time = ++window_select_count;
dc6f92b8 435
ff11dfa1 436 return f;
dc6f92b8
JB
437}
438\f
bba88bb1 439#ifdef HAVE_WINDOW_SYSTEM
ff11dfa1 440/* Make a frame using a separate minibuffer window on another frame.
dc6f92b8
JB
441 MINI_WINDOW is the minibuffer window to use. nil means use the
442 default (the global minibuffer). */
443
ff11dfa1 444struct frame *
971de7fb 445make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
dc6f92b8 446{
ff11dfa1 447 register struct frame *f;
363b873b 448 struct gcpro gcpro1;
dc6f92b8 449
b0660239 450 if (!NILP (mini_window))
b7826503 451 CHECK_LIVE_WINDOW (mini_window);
dc6f92b8 452
b0660239 453 if (!NILP (mini_window)
d3d50620 454 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
6ed8eeff 455 error ("Frame and minibuffer must be on the same terminal");
662ac59a 456
ff11dfa1
JB
457 /* Make a frame containing just a root window. */
458 f = make_frame (0);
dc6f92b8 459
b0660239
KH
460 if (NILP (mini_window))
461 {
462 /* Use default-minibuffer-frame if possible. */
1344aad4
TT
463 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
464 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
b0660239 465 {
363b873b
RS
466 Lisp_Object frame_dummy;
467
468 XSETFRAME (frame_dummy, f);
469 GCPRO1 (frame_dummy);
b0660239 470 /* If there's no minibuffer frame to use, create one. */
15dbb4d6
PE
471 kset_default_minibuffer_frame
472 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
363b873b 473 UNGCPRO;
b0660239 474 }
177c0ea7 475
e69b0960
DA
476 mini_window
477 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
b0660239 478 }
a2812a26 479
f00af5b1 480 fset_minibuffer_window (f, mini_window);
a2812a26
RS
481
482 /* Make the chosen minibuffer window display the proper minibuffer,
483 unless it is already showing a minibuffer. */
e74aeda8 484 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
08908aca
MR
485 /* Use set_window_buffer instead of Fset_window_buffer (see
486 discussion of bug#11984, bug#12025, bug#12026). */
487 set_window_buffer (mini_window,
488 (NILP (Vminibuffer_list)
489 ? get_minibuffer (0)
490 : Fcar (Vminibuffer_list)), 0, 0);
ff11dfa1 491 return f;
dc6f92b8
JB
492}
493
ff11dfa1 494/* Make a frame containing only a minibuffer window. */
dc6f92b8 495
ff11dfa1 496struct frame *
971de7fb 497make_minibuffer_frame (void)
dc6f92b8 498{
ff11dfa1 499 /* First make a frame containing just a root window, no minibuffer. */
dc6f92b8 500
ff11dfa1 501 register struct frame *f = make_frame (0);
dc6f92b8 502 register Lisp_Object mini_window;
ff11dfa1 503 register Lisp_Object frame;
dc6f92b8 504
2d80a27a 505 XSETFRAME (frame, f);
dc6f92b8 506
804518aa 507 f->auto_raise = 0;
ff11dfa1
JB
508 f->auto_lower = 0;
509 f->no_split = 1;
510 f->wants_modeline = 0;
dc6f92b8
JB
511
512 /* Now label the root window as also being the minibuffer.
513 Avoid infinite looping on the window chain by marking next pointer
514 as nil. */
515
f00af5b1
PE
516 mini_window = f->root_window;
517 fset_minibuffer_window (f, mini_window);
c98ff5dd 518 XWINDOW (mini_window)->mini = 1;
e8c17b81
PE
519 wset_next (XWINDOW (mini_window), Qnil);
520 wset_prev (XWINDOW (mini_window), Qnil);
521 wset_frame (XWINDOW (mini_window), frame);
dc6f92b8
JB
522
523 /* Put the proper buffer in that window. */
524
08908aca
MR
525 /* Use set_window_buffer instead of Fset_window_buffer (see
526 discussion of bug#11984, bug#12025, bug#12026). */
527 set_window_buffer (mini_window,
528 (NILP (Vminibuffer_list)
529 ? get_minibuffer (0)
530 : Fcar (Vminibuffer_list)), 0, 0);
ff11dfa1 531 return f;
dc6f92b8 532}
bba88bb1 533#endif /* HAVE_WINDOW_SYSTEM */
dc6f92b8 534\f
28d440ab 535/* Construct a frame that refers to a terminal. */
dc6f92b8 536
8a401434 537static printmax_t tty_frame_count;
bb1513c9 538
ff11dfa1 539struct frame *
3224dac1 540make_initial_frame (void)
dc6f92b8 541{
3224dac1 542 struct frame *f;
6ed8eeff 543 struct terminal *terminal;
d063751a 544 Lisp_Object frame;
bb1513c9 545
1bc973c2 546 eassert (initial_kboard);
b4f0ee5d 547
bb1513c9
RS
548 /* The first call must initialize Vframe_list. */
549 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
550 Vframe_list = Qnil;
ff11dfa1 551
6ed8eeff 552 terminal = init_initial_terminal ();
3224dac1
KL
553
554 f = make_frame (1);
555 XSETFRAME (frame, f);
556
557 Vframe_list = Fcons (frame, Vframe_list);
558
6ed8eeff 559 tty_frame_count = 1;
f00af5b1 560 fset_name (f, build_pure_c_string ("F1"));
3224dac1 561
edfa7fa0 562 SET_FRAME_VISIBLE (f, 1);
3224dac1 563
6ed8eeff
KL
564 f->output_method = terminal->type;
565 f->terminal = terminal;
566 f->terminal->reference_count++;
3224dac1 567 f->output_data.nothing = 0;
a3547743 568
3224dac1
KL
569 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
570 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
a3547743 571
3224dac1 572 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
3b8eff32
CY
573
574 /* The default value of menu-bar-mode is t. */
575 set_menu_bar_lines (f, make_number (1), Qnil);
3224dac1 576
edfda783
AR
577 if (!noninteractive)
578 init_frame_faces (f);
edfda783 579
5492865b
DA
580 last_nonminibuf_frame = f;
581
3224dac1
KL
582 return f;
583}
584
585
81626931 586static struct frame *
6ed8eeff 587make_terminal_frame (struct terminal *terminal)
3224dac1
KL
588{
589 register struct frame *f;
3224dac1 590 Lisp_Object frame;
8a401434 591 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
ab797f65 592
4e213843
SM
593 if (!terminal->name)
594 error ("Terminal is not live, can't create new frames on it");
ab797f65 595
ff11dfa1 596 f = make_frame (1);
d063751a 597
2d80a27a 598 XSETFRAME (frame, f);
d063751a
RS
599 Vframe_list = Fcons (frame, Vframe_list);
600
f00af5b1 601 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
bb1513c9 602
edfa7fa0
DA
603 SET_FRAME_VISIBLE (f, 1);
604
1266f9ef
EZ
605 f->terminal = terminal;
606 f->terminal->reference_count++;
bb221971 607#ifdef MSDOS
99dda2cd 608 f->output_data.tty->display_info = &the_only_display_info;
2d764c78
EZ
609 if (!inhibit_window_system
610 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
611 || XFRAME (selected_frame)->output_method == output_msdos_raw))
02ab7130 612 f->output_method = output_msdos_raw;
2d764c78
EZ
613 else
614 f->output_method = output_termcap;
5bbdf7aa
DN
615#else /* not MSDOS */
616 f->output_method = output_termcap;
617 create_tty_output (f);
618 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
619 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
620#endif /* not MSDOS */
574a1a90 621
1266f9ef 622 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
880e6158
MR
623 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
624 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
1266f9ef 625
caecb91c 626 /* Set the top frame to the newly created frame. */
1266f9ef
EZ
627 if (FRAMEP (FRAME_TTY (f)->top_frame)
628 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
edfa7fa0 629 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
1266f9ef
EZ
630
631 FRAME_TTY (f)->top_frame = frame;
632
1a6d3623
EZ
633 if (!noninteractive)
634 init_frame_faces (f);
1a578e9b 635
ff11dfa1 636 return f;
dc6f92b8 637}
bb1513c9 638
ed8dad6b
KL
639/* Get a suitable value for frame parameter PARAMETER for a newly
640 created frame, based on (1) the user-supplied frame parameter
c1ef4455 641 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
ed8dad6b
KL
642
643static Lisp_Object
644get_future_frame_param (Lisp_Object parameter,
645 Lisp_Object supplied_parms,
646 char *current_value)
647{
648 Lisp_Object result;
649
650 result = Fassq (parameter, supplied_parms);
651 if (NILP (result))
e69b0960 652 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
ed8dad6b
KL
653 if (NILP (result) && current_value != NULL)
654 result = build_string (current_value);
ed8dad6b
KL
655 if (!NILP (result) && !STRINGP (result))
656 result = XCDR (result);
657 if (NILP (result) || !STRINGP (result))
658 result = Qnil;
659
660 return result;
661}
662
bb1513c9 663DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
14ff1ee0 664 1, 1, 0,
28d440ab 665 doc: /* Create an additional terminal frame, possibly on another terminal.
14ff1ee0 666This function takes one argument, an alist specifying frame parameters.
28d440ab 667
c6bf3022
CY
668You can create multiple frames on a single text terminal, but only one
669of them (the selected terminal frame) is actually displayed.
28d440ab
KL
670
671In practice, generally you don't need to specify any parameters,
672except when you want to create a new frame on another terminal.
673In that case, the `tty' parameter specifies the device file to open,
674and the `tty-type' parameter specifies the terminal type. Example:
675
676 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
677
0b0d3e0b
KL
678Note that changing the size of one terminal frame automatically
679affects all frames on the same terminal device. */)
5842a27b 680 (Lisp_Object parms)
bb1513c9
RS
681{
682 struct frame *f;
6ed8eeff 683 struct terminal *t = NULL;
574a1a90 684 Lisp_Object frame, tem;
8d2666fe 685 struct frame *sf = SELECTED_FRAME ();
bb1513c9 686
541580aa 687#ifdef MSDOS
2d764c78
EZ
688 if (sf->output_method != output_msdos_raw
689 && sf->output_method != output_termcap)
1088b922 690 emacs_abort ();
574a1a90
RS
691#else /* not MSDOS */
692
99b72cc4 693#ifdef WINDOWSNT /* This should work now! */
8d2666fe 694 if (sf->output_method != output_termcap)
bb1513c9 695 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
bb221971 696#endif
574a1a90 697#endif /* not MSDOS */
a3547743 698
b6660415 699 {
6ed8eeff 700 Lisp_Object terminal;
bb1513c9 701
6ed8eeff 702 terminal = Fassq (Qterminal, parms);
090cf9db 703 if (CONSP (terminal))
28d440ab 704 {
6ed8eeff
KL
705 terminal = XCDR (terminal);
706 t = get_terminal (terminal, 1);
28d440ab 707 }
1266f9ef
EZ
708#ifdef MSDOS
709 if (t && t != the_only_display_info.terminal)
710 /* msdos.c assumes a single tty_display_info object. */
711 error ("Multiple terminals are not supported on this platform");
712 if (!t)
713 t = the_only_display_info.terminal;
714#endif
28d440ab 715 }
a3547743 716
6ed8eeff 717 if (!t)
a3547743 718 {
b6660415 719 char *name = 0, *type = 0;
ed8dad6b 720 Lisp_Object tty, tty_type;
b6660415 721
ed8dad6b
KL
722 tty = get_future_frame_param
723 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
724 ? FRAME_TTY (XFRAME (selected_frame))->name
725 : NULL));
726 if (!NILP (tty))
5b71542d 727 name = xlispstrdupa (tty);
a3547743 728
ed8dad6b
KL
729 tty_type = get_future_frame_param
730 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
731 ? FRAME_TTY (XFRAME (selected_frame))->type
732 : NULL));
733 if (!NILP (tty_type))
5b71542d 734 type = xlispstrdupa (tty_type);
b6660415 735
dc6c0eda 736 t = init_tty (name, type, 0); /* Errors are not fatal. */
b6660415 737 }
bb1513c9 738
6ed8eeff 739 f = make_terminal_frame (t);
574a1a90 740
9628b887
KL
741 {
742 int width, height;
0b0d3e0b 743 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
880e6158 744 change_frame_size (f, width, height, 0, 0, 0, 0);
9628b887 745 }
a3547743 746
bd0443bb 747 adjust_frame_glyphs (f);
bb1513c9
RS
748 calculate_costs (f);
749 XSETFRAME (frame, f);
84231434
DA
750
751 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
9acc1074 752 store_in_alist (&parms, Qtty,
84231434
DA
753 (t->display_info.tty->name
754 ? build_string (t->display_info.tty->name)
755 : Qnil));
bb1513c9 756 Fmodify_frame_parameters (frame, parms);
a3547743 757
87f1940e
EZ
758 /* Make the frame face alist be frame-specific, so that each
759 frame could change its face definitions independently. */
f00af5b1 760 fset_face_alist (f, Fcopy_alist (sf->face_alist));
87f1940e
EZ
761 /* Simple Fcopy_alist isn't enough, because we need the contents of
762 the vectors which are the CDRs of associations in face_alist to
763 be copied as well. */
e69b0960 764 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
f3fbd155 765 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
bb1513c9
RS
766 return frame;
767}
1e8324d9 768
dc6f92b8 769\f
1e8324d9
GM
770/* Perform the switch to frame FRAME.
771
772 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
773 FRAME1 as frame.
774
775 If TRACK is non-zero and the frame that currently has the focus
776 redirects its focus to the selected frame, redirect that focused
777 frame's focus to FRAME instead.
778
779 FOR_DELETION non-zero means that the selected frame is being
6ed8eeff 780 deleted, which includes the possibility that the frame's terminal
216e6a14
MR
781 is dead.
782
783 The value of NORECORD is passed as argument to Fselect_window. */
1e8324d9 784
61f94483 785Lisp_Object
971de7fb 786do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
dc6f92b8 787{
8d2666fe 788 struct frame *sf = SELECTED_FRAME ();
177c0ea7 789
2f0b07e0
JB
790 /* If FRAME is a switch-frame event, extract the frame we should
791 switch to. */
792 if (CONSP (frame)
7539e11f
KR
793 && EQ (XCAR (frame), Qswitch_frame)
794 && CONSP (XCDR (frame)))
795 frame = XCAR (XCDR (frame));
2f0b07e0 796
09907c3a
KH
797 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
798 a switch-frame event to arrive after a frame is no longer live,
799 especially when deleting the initial frame during startup. */
b7826503 800 CHECK_FRAME (frame);
09907c3a
KH
801 if (! FRAME_LIVE_P (XFRAME (frame)))
802 return Qnil;
dc6f92b8 803
8d2666fe 804 if (sf == XFRAME (frame))
ff11dfa1 805 return frame;
dc6f92b8 806
a42e9724
JB
807 /* If a frame's focus has been redirected toward the currently
808 selected frame, we should change the redirection to point to the
809 newly selected frame. This means that if the focus is redirected
810 from a minibufferless frame to a surrogate minibuffer frame, we
811 can use `other-window' to switch between all the frames using
812 that minibuffer frame, and the focus redirection will follow us
813 around. */
655ab9a3
SM
814#if 0
815 /* This is too greedy; it causes inappropriate focus redirection
816 that's hard to get rid of. */
0aed85f4
KH
817 if (track)
818 {
819 Lisp_Object tail;
a42e9724 820
7539e11f 821 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
0aed85f4
KH
822 {
823 Lisp_Object focus;
a42e9724 824
7539e11f 825 if (!FRAMEP (XCAR (tail)))
1088b922 826 emacs_abort ();
a42e9724 827
7539e11f 828 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
a42e9724 829
8d2666fe 830 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
7539e11f 831 Fredirect_frame_focus (XCAR (tail), frame);
0aed85f4
KH
832 }
833 }
834#else /* ! 0 */
835 /* Instead, apply it only to the frame we're pointing to. */
032d78fe 836#ifdef HAVE_WINDOW_SYSTEM
1e8324d9 837 if (track && FRAME_WINDOW_P (XFRAME (frame)))
0aed85f4
KH
838 {
839 Lisp_Object focus, xfocus;
840
d7266360 841 xfocus = x_get_focus_frame (XFRAME (frame));
0aed85f4
KH
842 if (FRAMEP (xfocus))
843 {
844 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
8d2666fe 845 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
0aed85f4
KH
846 Fredirect_frame_focus (xfocus, frame);
847 }
848 }
849#endif /* HAVE_X_WINDOWS */
850#endif /* ! 0 */
a42e9724 851
1e8324d9 852 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
550f0e6a
GM
853 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
854
a4e628d4 855 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
9628b887 856 {
f009190a
EZ
857 Lisp_Object top_frame = FRAME_TTY (XFRAME (frame))->top_frame;
858
859 /* Don't mark the frame garbaged and/or obscured if we are
860 switching to the frame that is already the top frame of that
861 TTY. */
862 if (!EQ (frame, top_frame))
863 {
864 if (FRAMEP (top_frame))
865 /* Mark previously displayed frame as now obscured. */
866 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
867 SET_FRAME_VISIBLE (XFRAME (frame), 1);
868 }
9628b887
KL
869 FRAME_TTY (XFRAME (frame))->top_frame = frame;
870 }
871
8d2666fe
GM
872 selected_frame = frame;
873 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
874 last_nonminibuf_frame = XFRAME (selected_frame);
d5e7c279 875
e69b0960 876 Fselect_window (XFRAME (frame)->selected_window, norecord);
dc6f92b8 877
074577b8 878 /* We want to make sure that the next event generates a frame-switch
eb8c3be9 879 event to the appropriate frame. This seems kludgy to me, but
074577b8
JB
880 before you take it out, make sure that evaluating something like
881 (select-window (frame-root-window (new-frame))) doesn't end up
882 with your typing being interpreted in the new frame instead of
883 the one you're actually typing in. */
ef352596 884 internal_last_event_frame = Qnil;
074577b8 885
ff11dfa1 886 return frame;
dc6f92b8
JB
887}
888
a7ca3326 889DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
216e6a14 890 doc: /* Select FRAME.
14ff1ee0 891Subsequent editing commands apply to its selected window.
216e6a14
MR
892Optional argument NORECORD means to neither change the order of
893recently selected windows nor the buffer list.
894
14ff1ee0 895The selection of FRAME lasts until the next time the user does
216e6a14
MR
896something to select a different frame, or until the next time
897this function is called. If you are using a window system, the
898previously selected frame may be restored as the selected frame
057bce6f 899when returning to the command loop, because it still may have
c6bf3022
CY
900the window system's input focus. On a text terminal, the next
901redisplay will display FRAME.
e4ed805e
LT
902
903This function returns FRAME, or nil if FRAME has been deleted. */)
5842a27b 904 (Lisp_Object frame, Lisp_Object norecord)
0aed85f4 905{
216e6a14 906 return do_switch_frame (frame, 1, 0, norecord);
0aed85f4
KH
907}
908
20dc6fbb 909DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
14ff1ee0
PJ
910 doc: /* Handle a switch-frame event EVENT.
911Switch-frame events are usually bound to this function.
912A switch-frame event tells Emacs that the window manager has requested
913that the user's events be directed to the frame mentioned in the event.
914This function selects the selected window of the frame of EVENT.
915
916If EVENT is frame object, handle it as if it were a switch-frame event
917to that frame. */)
5842a27b 918 (Lisp_Object event)
0aed85f4 919{
6951cd71 920 /* Preserve prefix arg that the command loop just cleared. */
15dbb4d6 921 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
dee091a3 922 Frun_hooks (1, &Qmouse_leave_buffer_hook);
511fa0d3
SM
923 /* `switch-frame' implies a focus in. */
924 call1 (intern ("handle-focus-in"), event);
216e6a14 925 return do_switch_frame (event, 0, 0, Qnil);
0aed85f4
KH
926}
927
a7ca3326 928DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
14ff1ee0 929 doc: /* Return the frame that is now selected. */)
5842a27b 930 (void)
dc6f92b8 931{
8d2666fe 932 return selected_frame;
dc6f92b8 933}
4a7cfafc 934\f
ff11dfa1 935DEFUN ("frame-list", Fframe_list, Sframe_list,
dc6f92b8 936 0, 0, 0,
c15dfb29 937 doc: /* Return a list of all live frames. */)
5842a27b 938 (void)
dc6f92b8 939{
d74c1900
GM
940 Lisp_Object frames;
941 frames = Fcopy_sequence (Vframe_list);
6a65b1b5 942#ifdef HAVE_WINDOW_SYSTEM
d74c1900
GM
943 if (FRAMEP (tip_frame))
944 frames = Fdelq (tip_frame, frames);
6a65b1b5 945#endif
d74c1900 946 return frames;
dc6f92b8
JB
947}
948
565212e5
DA
949/* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
950 same tty (for tty frames) or among frames which uses FRAME's keyboard.
951 If MINIBUF is nil, do not consider minibuffer-only candidate.
7216e43b 952 If MINIBUF is `visible', do not consider an invisible candidate.
565212e5
DA
953 If MINIBUF is a window, consider only its own frame and candidate now
954 using that window as the minibuffer.
955 If MINIBUF is 0, consider candidate if it is visible or iconified.
956 Otherwise consider any candidate and return nil if CANDIDATE is not
957 acceptable. */
958
959static Lisp_Object
960candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
961{
962 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
963
964 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
965 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
966 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
967 && FRAME_TTY (c) == FRAME_TTY (f)))
968 {
969 if (NILP (minibuf))
970 {
971 if (!FRAME_MINIBUF_ONLY_P (c))
972 return candidate;
973 }
974 else if (EQ (minibuf, Qvisible))
975 {
565212e5
DA
976 if (FRAME_VISIBLE_P (c))
977 return candidate;
978 }
979 else if (WINDOWP (minibuf))
980 {
981 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
982 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
983 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
984 FRAME_FOCUS_FRAME (c)))
985 return candidate;
986 }
987 else if (XFASTINT (minibuf) == 0)
988 {
565212e5
DA
989 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
990 return candidate;
991 }
992 else
993 return candidate;
994 }
995 return Qnil;
996}
997
998/* Return the next frame in the frame list after FRAME. */
f7af3f7b 999
66a9dbbe 1000static Lisp_Object
971de7fb 1001next_frame (Lisp_Object frame, Lisp_Object minibuf)
dc6f92b8 1002{
5b04e9f9 1003 Lisp_Object f, tail;
dc6f92b8
JB
1004 int passed = 0;
1005
ff11dfa1 1006 /* There must always be at least one frame in Vframe_list. */
565212e5 1007 eassert (CONSP (Vframe_list));
dbc4e1c1 1008
565212e5 1009 while (passed < 2)
5b04e9f9 1010 FOR_EACH_FRAME (tail, f)
dc6f92b8 1011 {
565212e5 1012 if (passed)
d5e7c279 1013 {
565212e5
DA
1014 f = candidate_frame (f, frame, minibuf);
1015 if (!NILP (f))
ff11dfa1 1016 return f;
d5e7c279 1017 }
d06a8a56 1018 if (EQ (frame, f))
dc6f92b8
JB
1019 passed++;
1020 }
565212e5 1021 return frame;
dc6f92b8
JB
1022}
1023
565212e5 1024/* Return the previous frame in the frame list before FRAME. */
f7af3f7b 1025
66a9dbbe 1026static Lisp_Object
971de7fb 1027prev_frame (Lisp_Object frame, Lisp_Object minibuf)
dc6f92b8 1028{
5b04e9f9 1029 Lisp_Object f, tail, prev = Qnil;
dc6f92b8 1030
ff11dfa1 1031 /* There must always be at least one frame in Vframe_list. */
5b04e9f9 1032 eassert (CONSP (Vframe_list));
f9898cc6 1033
5b04e9f9 1034 FOR_EACH_FRAME (tail, f)
f9898cc6 1035 {
d06a8a56
JB
1036 if (EQ (frame, f) && !NILP (prev))
1037 return prev;
565212e5
DA
1038 f = candidate_frame (f, frame, minibuf);
1039 if (!NILP (f))
1040 prev = f;
f9898cc6 1041 }
d06a8a56
JB
1042
1043 /* We've scanned the entire list. */
1044 if (NILP (prev))
1045 /* We went through the whole frame list without finding a single
1046 acceptable frame. Return the original frame. */
1047 return frame;
1048 else
1049 /* There were no acceptable frames in the list before FRAME; otherwise,
1050 we would have returned directly from the loop. Since PREV is the last
1051 acceptable frame in the list, return it. */
1052 return prev;
dc6f92b8
JB
1053}
1054
ef2c57ac 1055
ff11dfa1 1056DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
14ff1ee0
PJ
1057 doc: /* Return the next frame in the frame list after FRAME.
1058It considers only frames on the same terminal as FRAME.
1059By default, skip minibuffer-only frames.
1060If omitted, FRAME defaults to the selected frame.
1061If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1062If MINIFRAME is a window, include only its own frame
1063and any frame now using that window as the minibuffer.
1064If MINIFRAME is `visible', include all visible frames.
1065If MINIFRAME is 0, include all visible and iconified frames.
1066Otherwise, include all frames. */)
5842a27b 1067 (Lisp_Object frame, Lisp_Object miniframe)
dc6f92b8 1068{
ff11dfa1 1069 if (NILP (frame))
8d2666fe 1070 frame = selected_frame;
b7826503 1071 CHECK_LIVE_FRAME (frame);
ff11dfa1 1072 return next_frame (frame, miniframe);
dc6f92b8 1073}
dbc4e1c1 1074
ef2c57ac 1075DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
14ff1ee0
PJ
1076 doc: /* Return the previous frame in the frame list before FRAME.
1077It considers only frames on the same terminal as FRAME.
1078By default, skip minibuffer-only frames.
1079If omitted, FRAME defaults to the selected frame.
1080If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1081If MINIFRAME is a window, include only its own frame
1082and any frame now using that window as the minibuffer.
1083If MINIFRAME is `visible', include all visible frames.
1084If MINIFRAME is 0, include all visible and iconified frames.
1085Otherwise, include all frames. */)
5842a27b 1086 (Lisp_Object frame, Lisp_Object miniframe)
ef2c57ac 1087{
ef2c57ac 1088 if (NILP (frame))
8d2666fe 1089 frame = selected_frame;
b7826503 1090 CHECK_LIVE_FRAME (frame);
ef2c57ac
RM
1091 return prev_frame (frame, miniframe);
1092}
9718b207
MR
1093
1094DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1095 Slast_nonminibuf_frame, 0, 0, 0,
1096 doc: /* Return last non-minibuffer frame selected. */)
1097 (void)
1098{
1099 Lisp_Object frame = Qnil;
1100
1101 if (last_nonminibuf_frame)
1102 XSETFRAME (frame, last_nonminibuf_frame);
1103
1104 return frame;
1105}
dc6f92b8 1106\f
808c0f20
RS
1107/* Return 1 if it is ok to delete frame F;
1108 0 if all frames aside from F are invisible.
1109 (Exception: if F is the terminal frame, and we are using X, return 1.) */
dc6f92b8 1110
4475bec4 1111static int
a10c8269 1112other_visible_frames (struct frame *f)
808c0f20 1113{
5b04e9f9 1114 Lisp_Object frames, this;
c08c95c7 1115
5b04e9f9 1116 FOR_EACH_FRAME (frames, this)
1de11f56 1117 {
1de11f56
CY
1118 if (f == XFRAME (this))
1119 continue;
c08c95c7 1120
1de11f56
CY
1121 /* Verify that we can still talk to the frame's X window,
1122 and note any recent change in visibility. */
83fc0554 1123#ifdef HAVE_X_WINDOWS
1de11f56 1124 if (FRAME_WINDOW_P (XFRAME (this)))
edfa7fa0 1125 x_sync (XFRAME (this));
5e7b7c5b
RS
1126#endif
1127
1de11f56
CY
1128 if (FRAME_VISIBLE_P (XFRAME (this))
1129 || FRAME_ICONIFIED_P (XFRAME (this))
1130 /* Allow deleting the terminal frame when at least one X
1131 frame exists. */
1132 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1133 return 1;
c08c95c7 1134 }
1de11f56 1135 return 0;
808c0f20
RS
1136}
1137
bfff6445
MR
1138/* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1139 window. Preferably use the selected frame's minibuffer window
1140 instead. If the selected frame doesn't have one, get some other
1141 frame's minibuffer window. SELECT non-zero means select the new
1142 minibuffer window. */
1143static void
1144check_minibuf_window (Lisp_Object frame, int select)
1145{
1146 struct frame *f = decode_live_frame (frame);
1147
98b7f4bd
DA
1148 XSETFRAME (frame, f);
1149
bfff6445
MR
1150 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1151 {
f5adc984 1152 Lisp_Object frames, this, window = make_number (0);
bfff6445
MR
1153
1154 if (!EQ (frame, selected_frame)
1155 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1156 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1157 else
1158 FOR_EACH_FRAME (frames, this)
1159 {
1160 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1161 {
1162 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1163 break;
1164 }
1165 }
1166
8b098236
MR
1167 /* Don't abort if no window was found (Bug#15247). */
1168 if (WINDOWP (window))
bfff6445
MR
1169 {
1170 /* Use set_window_buffer instead of Fset_window_buffer (see
1171 discussion of bug#11984, bug#12025, bug#12026). */
1172 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1173 minibuf_window = window;
1174
1175 /* SELECT non-zero usually means that FRAME's minibuffer
1176 window was selected; select the new one. */
1177 if (select)
1178 Fselect_window (minibuf_window, Qnil);
1179 }
1180 }
1181}
1182
1183
56f2de10
MR
1184/* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1185 unconditionally. x_connection_closed and delete_terminal use
1186 this. Any other value of FORCE implements the semantics
1187 described for Fdelete_frame. */
1188Lisp_Object
971de7fb 1189delete_frame (Lisp_Object frame, Lisp_Object force)
808c0f20 1190{
d9f07150 1191 struct frame *f = decode_any_frame (frame);
d3e2acb6 1192 struct frame *sf;
bedb9c0e
KL
1193 struct kboard *kb;
1194
cf5fc6db 1195 int minibuffer_selected, is_tooltip_frame;
808c0f20 1196
808c0f20
RS
1197 if (! FRAME_LIVE_P (f))
1198 return Qnil;
1199
e39a993c 1200 if (NILP (force) && !other_visible_frames (f))
808c0f20 1201 error ("Attempt to delete the sole visible or iconified frame");
d5e7c279 1202
56f2de10 1203 /* x_connection_closed must have set FORCE to `noelisp' in order
00c5fd51 1204 to delete the last frame, if it is gone. */
56f2de10 1205 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
e9687ee8
RS
1206 error ("Attempt to delete the only frame");
1207
d9f07150
DA
1208 XSETFRAME (frame, f);
1209
ff11dfa1
JB
1210 /* Does this frame have a minibuffer, and is it the surrogate
1211 minibuffer for any other frame? */
d9f07150 1212 if (FRAME_HAS_MINIBUF_P (f))
dc6f92b8 1213 {
5b04e9f9 1214 Lisp_Object frames, this;
1113d9db 1215
5b04e9f9 1216 FOR_EACH_FRAME (frames, this)
1113d9db 1217 {
2e5ce5de 1218 Lisp_Object fminiw;
2e5ce5de 1219
e560aba9
PE
1220 if (EQ (this, frame))
1221 continue;
1222
1223 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1224
1225 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
a31787b1 1226 {
56f2de10
MR
1227 /* If we MUST delete this frame, delete the other first.
1228 But do this only if FORCE equals `noelisp'. */
1229 if (EQ (force, Qnoelisp))
1230 delete_frame (this, Qnoelisp);
a31787b1
RS
1231 else
1232 error ("Attempt to delete a surrogate minibuffer frame");
1233 }
1113d9db 1234 }
dc6f92b8
JB
1235 }
1236
cf5fc6db 1237 is_tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
54ee7410 1238
56f2de10
MR
1239 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1240 frame is a tooltip. FORCE is set to `noelisp' when handling
1241 a disconnect from the terminal, so we don't dare call Lisp
1242 code. */
cf5fc6db 1243 if (NILP (Vrun_hooks) || is_tooltip_frame)
58555d81 1244 ;
54ee7410 1245 else if (EQ (force, Qnoelisp))
58555d81
SM
1246 pending_funcalls
1247 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1248 pending_funcalls);
1249 else
1dd3c2d9
CY
1250 {
1251#ifdef HAVE_X_WINDOWS
58179cce 1252 /* Also, save clipboard to the clipboard manager. */
1dd3c2d9
CY
1253 x_clipboard_manager_save_frame (frame);
1254#endif
1255
1256 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1257 }
0e662342 1258
b6660415
KL
1259 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1260 if (! FRAME_LIVE_P (f))
1261 return Qnil;
1262
a31787b1
RS
1263 /* At this point, we are committed to deleting the frame.
1264 There is no more chance for errors to prevent it. */
1265
99b92e64 1266 minibuffer_selected = EQ (minibuf_window, selected_window);
d3e2acb6 1267 sf = SELECTED_FRAME ();
ff11dfa1 1268 /* Don't let the frame remain selected. */
8d2666fe 1269 if (f == sf)
06537cc8 1270 {
691a357f
PE
1271 Lisp_Object tail;
1272 Lisp_Object frame1 = Qnil;
06537cc8 1273
42fe2e88
DA
1274 /* Look for another visible frame on the same terminal.
1275 Do not call next_frame here because it may loop forever.
1276 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1277 FOR_EACH_FRAME (tail, frame1)
1278 if (!EQ (frame, frame1)
1279 && (FRAME_TERMINAL (XFRAME (frame))
1280 == FRAME_TERMINAL (XFRAME (frame1)))
1281 && FRAME_VISIBLE_P (XFRAME (frame1)))
1282 break;
06537cc8
RS
1283
1284 /* If there is none, find *some* other frame. */
1285 if (NILP (frame1) || EQ (frame1, frame))
1286 {
1287 FOR_EACH_FRAME (tail, frame1)
1288 {
fca177d4 1289 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
c6bf3022
CY
1290 {
1291 /* Do not change a text terminal's top-frame. */
1292 struct frame *f1 = XFRAME (frame1);
1293 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1294 {
1295 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1296 if (!EQ (top_frame, frame))
1297 frame1 = top_frame;
1298 }
1299 break;
1300 }
06537cc8
RS
1301 }
1302 }
ac71ced7
SM
1303#ifdef NS_IMPL_COCOA
1304 else
1305 /* Under NS, there is no system mechanism for choosing a new
1306 window to get focus -- it is left to application code.
1307 So the portion of THIS application interfacing with NS
1308 needs to know about it. We call Fraise_frame, but the
1309 purpose is really to transfer focus. */
1310 Fraise_frame (frame1);
1311#endif
06537cc8 1312
216e6a14 1313 do_switch_frame (frame1, 0, 1, Qnil);
79a65b7f 1314 sf = SELECTED_FRAME ();
06537cc8 1315 }
dc6f92b8 1316
ff11dfa1 1317 /* Don't allow minibuf_window to remain on a deleted frame. */
bfff6445 1318 check_minibuf_window (frame, minibuffer_selected);
dc6f92b8 1319
130adcb7 1320 /* Don't let echo_area_window to remain on a deleted frame. */
e69b0960
DA
1321 if (EQ (f->minibuffer_window, echo_area_window))
1322 echo_area_window = sf->minibuffer_window;
130adcb7 1323
bb2a0a65
RS
1324 /* Clear any X selections for this frame. */
1325#ifdef HAVE_X_WINDOWS
1326 if (FRAME_X_P (f))
1327 x_clear_frame_selections (f);
1328#endif
1329
177c0ea7
JB
1330 /* Free glyphs.
1331 This function must be called before the window tree of the
18082e2d
GM
1332 frame is deleted because windows contain dynamically allocated
1333 memory. */
1334 free_glyphs (f);
1335
1ccdfd33 1336#ifdef HAVE_WINDOW_SYSTEM
50e3873c
KH
1337 /* Give chance to each font driver to free a frame specific data. */
1338 font_update_drivers (f, Qnil);
1ccdfd33 1339#endif
50e3873c 1340
4a88b3b0
JB
1341 /* Mark all the windows that used to be on FRAME as deleted, and then
1342 remove the reference to them. */
e69b0960 1343 delete_all_child_windows (f->root_window);
f00af5b1 1344 fset_root_window (f, Qnil);
4a88b3b0 1345
ff11dfa1 1346 Vframe_list = Fdelq (frame, Vframe_list);
edfa7fa0 1347 SET_FRAME_VISIBLE (f, 0);
dc6f92b8 1348
a90af46f
CY
1349 /* Allow the vector of menu bar contents to be freed in the next
1350 garbage collection. The frame object itself may not be garbage
1351 collected until much later, because recent_keys and other data
1352 structures can still refer to it. */
f00af5b1 1353 fset_menu_bar_vector (f, Qnil);
acc49a52 1354
d59a1afb
DA
1355 /* If FRAME's buffer lists contains killed
1356 buffers, this helps GC to reclaim them. */
1357 fset_buffer_list (f, Qnil);
1358 fset_buried_buffer_list (f, Qnil);
1359
ebbbc028 1360 free_font_driver_list (f);
70fdbb46
JM
1361 xfree (f->namebuf);
1362 xfree (f->decode_mode_spec_buffer);
1363 xfree (FRAME_INSERT_COST (f));
1364 xfree (FRAME_DELETEN_COST (f));
1365 xfree (FRAME_INSERTN_COST (f));
1366 xfree (FRAME_DELETE_COST (f));
d2bee99e 1367
8678b9cc 1368 /* Since some events are handled at the interrupt level, we may get
6ed8eeff 1369 an event for f at any time; if we zero out the frame's terminal
8678b9cc 1370 now, then we may trip up the event-handling code. Instead, we'll
6ed8eeff
KL
1371 promise that the terminal of the frame must be valid until we
1372 have called the window-system-dependent frame destruction
1373 routine. */
dbc4e1c1 1374
d5e7c279 1375
428a555e 1376 {
56a0e352 1377 struct terminal *terminal;
caa50be2
JD
1378 block_input ();
1379 if (FRAME_TERMINAL (f)->delete_frame_hook)
1380 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
56a0e352 1381 terminal = FRAME_TERMINAL (f);
a3547743 1382 f->output_data.nothing = 0;
b09cca6a 1383 f->terminal = 0; /* Now the frame is dead. */
caa50be2 1384 unblock_input ();
428a555e 1385
6ed8eeff 1386 /* If needed, delete the terminal that this frame was on.
b09cca6a 1387 (This must be done after the frame is killed.) */
6ed8eeff 1388 terminal->reference_count--;
a2addb04
TH
1389#ifdef USE_GTK
1390 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1391 bug.
1392 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1393 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1394 terminal->reference_count = 1;
1395#endif /* USE_GTK */
6ed8eeff 1396 if (terminal->reference_count == 0)
bedb9c0e 1397 {
174105f7
SM
1398 Lisp_Object tmp;
1399 XSETTERMINAL (tmp, terminal);
1400
bedb9c0e 1401 kb = NULL;
174105f7 1402 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
bedb9c0e
KL
1403 }
1404 else
6ed8eeff 1405 kb = terminal->kboard;
428a555e 1406 }
8678b9cc 1407
ff11dfa1 1408 /* If we've deleted the last_nonminibuf_frame, then try to find
d5e7c279 1409 another one. */
ff11dfa1 1410 if (f == last_nonminibuf_frame)
d5e7c279 1411 {
5b04e9f9 1412 Lisp_Object frames, this;
1113d9db 1413
ff11dfa1 1414 last_nonminibuf_frame = 0;
d5e7c279 1415
5b04e9f9 1416 FOR_EACH_FRAME (frames, this)
d5e7c279 1417 {
5b04e9f9 1418 f = XFRAME (this);
ff11dfa1 1419 if (!FRAME_MINIBUF_ONLY_P (f))
d5e7c279 1420 {
ff11dfa1 1421 last_nonminibuf_frame = f;
d5e7c279
JB
1422 break;
1423 }
1424 }
1425 }
dc6f92b8 1426
8ceb7434
RS
1427 /* If there's no other frame on the same kboard, get out of
1428 single-kboard state if we're in it for this kboard. */
bedb9c0e
KL
1429 if (kb != NULL)
1430 {
5b04e9f9 1431 Lisp_Object frames, this;
bedb9c0e 1432 /* Some frame we found on the same kboard, or nil if there are none. */
5b04e9f9 1433 Lisp_Object frame_on_same_kboard = Qnil;
8ceb7434 1434
5b04e9f9
DA
1435 FOR_EACH_FRAME (frames, this)
1436 if (kb == FRAME_KBOARD (XFRAME (this)))
1437 frame_on_same_kboard = this;
8ceb7434 1438
bedb9c0e
KL
1439 if (NILP (frame_on_same_kboard))
1440 not_single_kboard_state (kb);
1441 }
8ceb7434
RS
1442
1443
c4c6d073
KH
1444 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1445 find another one. Prefer minibuffer-only frames, but also notice
1446 frames with other windows. */
1344aad4 1447 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1113d9db 1448 {
5b04e9f9 1449 Lisp_Object frames, this;
1113d9db 1450
ff11dfa1 1451 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
5b04e9f9 1452 Lisp_Object frame_with_minibuf = Qnil;
32fda9ba 1453 /* Some frame we found on the same kboard, or nil if there are none. */
5b04e9f9 1454 Lisp_Object frame_on_same_kboard = Qnil;
32fda9ba 1455
5b04e9f9 1456 FOR_EACH_FRAME (frames, this)
1113d9db 1457 {
5b04e9f9 1458 struct frame *f1 = XFRAME (this);
1113d9db 1459
c4c6d073
KH
1460 /* Consider only frames on the same kboard
1461 and only those with minibuffers. */
bedb9c0e 1462 if (kb == FRAME_KBOARD (f1)
c4c6d073 1463 && FRAME_HAS_MINIBUF_P (f1))
1113d9db 1464 {
ff11dfa1 1465 frame_with_minibuf = this;
c4c6d073 1466 if (FRAME_MINIBUF_ONLY_P (f1))
1113d9db
JB
1467 break;
1468 }
32fda9ba 1469
bedb9c0e 1470 if (kb == FRAME_KBOARD (f1))
32fda9ba 1471 frame_on_same_kboard = this;
1113d9db
JB
1472 }
1473
32fda9ba
RS
1474 if (!NILP (frame_on_same_kboard))
1475 {
1476 /* We know that there must be some frame with a minibuffer out
1477 there. If this were not true, all of the frames present
1478 would have to be minibufferless, which implies that at some
1479 point their minibuffer frames must have been deleted, but
1480 that is prohibited at the top; you can't delete surrogate
1481 minibuffer frames. */
1482 if (NILP (frame_with_minibuf))
1088b922 1483 emacs_abort ();
1113d9db 1484
15dbb4d6 1485 kset_default_minibuffer_frame (kb, frame_with_minibuf);
32fda9ba
RS
1486 }
1487 else
1488 /* No frames left on this kboard--say no minibuffer either. */
15dbb4d6 1489 kset_default_minibuffer_frame (kb, Qnil);
1113d9db
JB
1490 }
1491
e681c92a 1492 /* Cause frame titles to update--necessary if we now have just one frame. */
cf5fc6db 1493 if (!is_tooltip_frame)
2ec9db5d 1494 update_mode_lines = 15;
e681c92a 1495
dc6f92b8
JB
1496 return Qnil;
1497}
56f2de10
MR
1498
1499DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1500 doc: /* Delete FRAME, permanently eliminating it from use.
1501FRAME defaults to the selected frame.
1502
1503A frame may not be deleted if its minibuffer is used by other frames.
1504Normally, you may not delete a frame if all other frames are invisible,
1505but if the second optional argument FORCE is non-nil, you may do so.
1506
1507This function runs `delete-frame-functions' before actually
1508deleting the frame, unless the frame is a tooltip.
1509The functions are run with one argument, the frame to be deleted. */)
5842a27b 1510 (Lisp_Object frame, Lisp_Object force)
56f2de10
MR
1511{
1512 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1513}
1514
dc6f92b8
JB
1515\f
1516/* Return mouse position in character cell units. */
1517
f9898cc6 1518DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
14ff1ee0
PJ
1519 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1520The position is given in character cells, where (0, 0) is the
d0cd961e
EZ
1521upper-left corner of the frame, X is the horizontal offset, and Y is
1522the vertical offset.
14ff1ee0
PJ
1523If Emacs is running on a mouseless terminal or hasn't been programmed
1524to read the mouse position, it returns the selected frame for FRAME
1525and nil for X and Y.
1526If `mouse-position-function' is non-nil, `mouse-position' calls it,
1527passing the normal return value to that function as an argument,
1528and returns whatever that function returns. */)
5842a27b 1529 (void)
dc6f92b8 1530{
a10c8269 1531 struct frame *f;
dbc4e1c1 1532 Lisp_Object lispy_dummy;
beb0bc36 1533 Lisp_Object x, y, retval;
cb2255b3 1534 struct gcpro gcpro1;
dc6f92b8 1535
8d2666fe 1536 f = SELECTED_FRAME ();
c5074d8c
RS
1537 x = y = Qnil;
1538
1539 /* It's okay for the hook to refrain from storing anything. */
6ed8eeff 1540 if (FRAME_TERMINAL (f)->mouse_position_hook)
4973679b
PE
1541 {
1542 enum scroll_bar_part party_dummy;
1543 Time time_dummy;
1544 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1545 &lispy_dummy, &party_dummy,
1546 &x, &y,
1547 &time_dummy);
1548 }
1549
76db7eb4
KH
1550 if (! NILP (x))
1551 {
4973679b
PE
1552 int col = XINT (x);
1553 int row = XINT (y);
8126c3b4 1554 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
76db7eb4
KH
1555 XSETINT (x, col);
1556 XSETINT (y, row);
1557 }
2d80a27a 1558 XSETFRAME (lispy_dummy, f);
beb0bc36 1559 retval = Fcons (lispy_dummy, Fcons (x, y));
cb2255b3 1560 GCPRO1 (retval);
beb0bc36 1561 if (!NILP (Vmouse_position_function))
cb2255b3 1562 retval = call1 (Vmouse_position_function, retval);
2bfa3d3e 1563 return retval;
dc6f92b8
JB
1564}
1565
152e6c70
RS
1566DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1567 Smouse_pixel_position, 0, 0, 0,
14ff1ee0
PJ
1568 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1569The position is given in pixel units, where (0, 0) is the
d0cd961e
EZ
1570upper-left corner of the frame, X is the horizontal offset, and Y is
1571the vertical offset.
14ff1ee0
PJ
1572If Emacs is running on a mouseless terminal or hasn't been programmed
1573to read the mouse position, it returns the selected frame for FRAME
1574and nil for X and Y. */)
5842a27b 1575 (void)
152e6c70 1576{
a10c8269 1577 struct frame *f;
152e6c70 1578 Lisp_Object lispy_dummy;
152e6c70 1579 Lisp_Object x, y;
152e6c70 1580
8d2666fe 1581 f = SELECTED_FRAME ();
152e6c70
RS
1582 x = y = Qnil;
1583
1584 /* It's okay for the hook to refrain from storing anything. */
6ed8eeff 1585 if (FRAME_TERMINAL (f)->mouse_position_hook)
4973679b
PE
1586 {
1587 enum scroll_bar_part party_dummy;
1588 Time time_dummy;
1589 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1590 &lispy_dummy, &party_dummy,
1591 &x, &y,
1592 &time_dummy);
1593 }
1594
2d80a27a 1595 XSETFRAME (lispy_dummy, f);
152e6c70
RS
1596 return Fcons (lispy_dummy, Fcons (x, y));
1597}
1598
6b5d3a51
PE
1599#ifdef HAVE_WINDOW_SYSTEM
1600
1601/* On frame F, convert character coordinates X and Y to pixel
1602 coordinates *PIX_X and *PIX_Y. */
1603
1604static void
1605frame_char_to_pixel_position (struct frame *f, int x, int y,
1606 int *pix_x, int *pix_y)
1607{
1608 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1609 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1610
1611 if (*pix_x < 0)
1612 *pix_x = 0;
1613 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1614 *pix_x = FRAME_PIXEL_WIDTH (f);
1615
1616 if (*pix_y < 0)
1617 *pix_y = 0;
1618 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1619 *pix_y = FRAME_PIXEL_HEIGHT (f);
1620}
1621
1622/* On frame F, reposition mouse pointer to character coordinates X and Y. */
1623
1624static void
1625frame_set_mouse_position (struct frame *f, int x, int y)
1626{
1627 int pix_x, pix_y;
1628
1629 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1630 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1631}
1632
1633#endif /* HAVE_WINDOW_SYSTEM */
1634
dc6f92b8 1635DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
14ff1ee0
PJ
1636 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1637Coordinates are relative to the frame, not a window,
1638so the coordinates of the top left character in the frame
1639may be nonzero due to left-hand scroll bars or the menu bar.
1640
d0cd961e
EZ
1641The position is given in character cells, where (0, 0) is the
1642upper-left corner of the frame, X is the horizontal offset, and Y is
1643the vertical offset.
1644
14ff1ee0
PJ
1645This function is a no-op for an X frame that is not visible.
1646If you have just created a frame, you must wait for it to become visible
1647before calling this function on it, like this.
1648 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
5842a27b 1649 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
dc6f92b8 1650{
b7826503 1651 CHECK_LIVE_FRAME (frame);
d311d28c
PE
1652 CHECK_TYPE_RANGED_INTEGER (int, x);
1653 CHECK_TYPE_RANGED_INTEGER (int, y);
dc6f92b8 1654
dbc4e1c1 1655 /* I think this should be done with a hook. */
032d78fe
GV
1656#ifdef HAVE_WINDOW_SYSTEM
1657 if (FRAME_WINDOW_P (XFRAME (frame)))
d19be8a9 1658 /* Warping the mouse will cause enternotify and focus events. */
2b511374 1659 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1660#else
bcd77a2b 1661#if defined (MSDOS)
bb221971
RS
1662 if (FRAME_MSDOS_P (XFRAME (frame)))
1663 {
216e6a14 1664 Fselect_frame (frame, Qnil);
bb221971
RS
1665 mouse_moveto (XINT (x), XINT (y));
1666 }
4d1d51d2
NR
1667#else
1668#ifdef HAVE_GPM
1669 {
216e6a14 1670 Fselect_frame (frame, Qnil);
4d1d51d2
NR
1671 term_mouse_moveto (XINT (x), XINT (y));
1672 }
1673#endif
bb221971 1674#endif
dc6f92b8
JB
1675#endif
1676
1677 return Qnil;
1678}
152e6c70
RS
1679
1680DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1681 Sset_mouse_pixel_position, 3, 3, 0,
14ff1ee0 1682 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
d0cd961e
EZ
1683The position is given in pixels, where (0, 0) is the upper-left corner
1684of the frame, X is the horizontal offset, and Y is the vertical offset.
1685
14ff1ee0
PJ
1686Note, this is a no-op for an X frame that is not visible.
1687If you have just created a frame, you must wait for it to become visible
1688before calling this function on it, like this.
1689 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
5842a27b 1690 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
152e6c70 1691{
b7826503 1692 CHECK_LIVE_FRAME (frame);
d311d28c
PE
1693 CHECK_TYPE_RANGED_INTEGER (int, x);
1694 CHECK_TYPE_RANGED_INTEGER (int, y);
152e6c70
RS
1695
1696 /* I think this should be done with a hook. */
032d78fe
GV
1697#ifdef HAVE_WINDOW_SYSTEM
1698 if (FRAME_WINDOW_P (XFRAME (frame)))
d19be8a9 1699 /* Warping the mouse will cause enternotify and focus events. */
2b511374 1700 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1701#else
bcd77a2b 1702#if defined (MSDOS)
bb221971
RS
1703 if (FRAME_MSDOS_P (XFRAME (frame)))
1704 {
216e6a14 1705 Fselect_frame (frame, Qnil);
bb221971
RS
1706 mouse_moveto (XINT (x), XINT (y));
1707 }
67f6e31c
NR
1708#else
1709#ifdef HAVE_GPM
1710 {
216e6a14 1711 Fselect_frame (frame, Qnil);
67f6e31c
NR
1712 term_mouse_moveto (XINT (x), XINT (y));
1713 }
1714#endif
bb221971 1715#endif
152e6c70
RS
1716#endif
1717
1718 return Qnil;
1719}
dc6f92b8 1720\f
f57e2426 1721static void make_frame_visible_1 (Lisp_Object);
98ce1622 1722
a7ca3326 1723DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
fc25d15d 1724 0, 1, "",
14ff1ee0
PJ
1725 doc: /* Make the frame FRAME visible (assuming it is an X window).
1726If omitted, FRAME defaults to the currently selected frame. */)
5842a27b 1727 (Lisp_Object frame)
dc6f92b8 1728{
d9f07150 1729 struct frame *f = decode_live_frame (frame);
dc6f92b8 1730
dbc4e1c1 1731 /* I think this should be done with a hook. */
032d78fe 1732#ifdef HAVE_WINDOW_SYSTEM
d9f07150 1733 if (FRAME_WINDOW_P (f))
edfa7fa0 1734 x_make_frame_visible (f);
fd0c2bd1 1735#endif
dc6f92b8 1736
d9f07150 1737 make_frame_visible_1 (f->root_window);
98ce1622 1738
d19be8a9 1739 /* Make menu bar update for the Buffers and Frames menus. */
655ab9a3 1740 /* windows_or_buffers_changed = 15; FIXME: Why? */
565620a5 1741
d9f07150 1742 XSETFRAME (frame, f);
ff11dfa1 1743 return frame;
dc6f92b8
JB
1744}
1745
98ce1622 1746/* Update the display_time slot of the buffers shown in WINDOW
cd1181db 1747 and all its descendants. */
98ce1622
RS
1748
1749static void
971de7fb 1750make_frame_visible_1 (Lisp_Object window)
98ce1622
RS
1751{
1752 struct window *w;
1753
e74aeda8 1754 for (; !NILP (window); window = w->next)
98ce1622
RS
1755 {
1756 w = XWINDOW (window);
e74aeda8
DA
1757 if (WINDOWP (w->contents))
1758 make_frame_visible_1 (w->contents);
1759 else
1760 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
98ce1622
RS
1761 }
1762}
1763
ff11dfa1 1764DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
808c0f20 1765 0, 2, "",
c38eb027 1766 doc: /* Make the frame FRAME invisible.
14ff1ee0 1767If omitted, FRAME defaults to the currently selected frame.
c38eb027
CY
1768On graphical displays, invisible frames are not updated and are
1769usually not displayed at all, even in a window system's \"taskbar\".
1770
14ff1ee0 1771Normally you may not make FRAME invisible if all other frames are invisible,
c38eb027
CY
1772but if the second optional argument FORCE is non-nil, you may do so.
1773
c6bf3022
CY
1774This function has no effect on text terminal frames. Such frames are
1775always considered visible, whether or not they are currently being
c38eb027 1776displayed in the terminal. */)
5842a27b 1777 (Lisp_Object frame, Lisp_Object force)
dc6f92b8 1778{
d9f07150 1779 struct frame *f = decode_live_frame (frame);
1aa66088 1780
d9f07150 1781 if (NILP (force) && !other_visible_frames (f))
808c0f20
RS
1782 error ("Attempt to make invisible the sole visible or iconified frame");
1783
bfff6445
MR
1784 /* Don't allow minibuf_window to remain on an invisible frame. */
1785 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
9c394f17 1786
dbc4e1c1 1787 /* I think this should be done with a hook. */
032d78fe 1788#ifdef HAVE_WINDOW_SYSTEM
d9f07150
DA
1789 if (FRAME_WINDOW_P (f))
1790 x_make_frame_invisible (f);
fd0c2bd1 1791#endif
dc6f92b8 1792
d19be8a9 1793 /* Make menu bar update for the Buffers and Frames menus. */
94ae2ad4 1794 windows_or_buffers_changed = 16;
565620a5 1795
dc6f92b8
JB
1796 return Qnil;
1797}
1798
a7ca3326 1799DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1aa66088 1800 0, 1, "",
14ff1ee0
PJ
1801 doc: /* Make the frame FRAME into an icon.
1802If omitted, FRAME defaults to the currently selected frame. */)
5842a27b 1803 (Lisp_Object frame)
dc6f92b8 1804{
d9f07150 1805 struct frame *f = decode_live_frame (frame);
9c394f17 1806
08908aca 1807 /* Don't allow minibuf_window to remain on an iconified frame. */
bfff6445 1808 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
9c394f17 1809
dbc4e1c1 1810 /* I think this should be done with a hook. */
032d78fe 1811#ifdef HAVE_WINDOW_SYSTEM
d9f07150
DA
1812 if (FRAME_WINDOW_P (f))
1813 x_iconify_frame (f);
fd0c2bd1 1814#endif
dc6f92b8 1815
d19be8a9 1816 /* Make menu bar update for the Buffers and Frames menus. */
94ae2ad4 1817 windows_or_buffers_changed = 17;
565620a5 1818
dc6f92b8
JB
1819 return Qnil;
1820}
1821
ff11dfa1 1822DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
dc6f92b8 1823 1, 1, 0,
c38eb027
CY
1824 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1825Return the symbol `icon' if FRAME is iconified or \"minimized\".
1826Return nil if FRAME was made invisible, via `make-frame-invisible'.
1827On graphical displays, invisible frames are not updated and are
1828usually not displayed at all, even in a window system's \"taskbar\".
1829
c6bf3022 1830If FRAME is a text terminal frame, this always returns t.
c38eb027
CY
1831Such frames are always considered visible, whether or not they are
1832currently being displayed on the terminal. */)
5842a27b 1833 (Lisp_Object frame)
dc6f92b8 1834{
b7826503 1835 CHECK_LIVE_FRAME (frame);
dc6f92b8 1836
a42e9724 1837 if (FRAME_VISIBLE_P (XFRAME (frame)))
dc6f92b8 1838 return Qt;
a42e9724 1839 if (FRAME_ICONIFIED_P (XFRAME (frame)))
fd0c2bd1 1840 return Qicon;
dc6f92b8
JB
1841 return Qnil;
1842}
1843
ff11dfa1 1844DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
dc6f92b8 1845 0, 0, 0,
14ff1ee0 1846 doc: /* Return a list of all frames now \"visible\" (being updated). */)
5842a27b 1847 (void)
dc6f92b8 1848{
5b04e9f9
DA
1849 Lisp_Object tail, frame, value = Qnil;
1850
1851 FOR_EACH_FRAME (tail, frame)
1852 if (FRAME_VISIBLE_P (XFRAME (frame)))
1853 value = Fcons (frame, value);
dc6f92b8 1854
dc6f92b8
JB
1855 return value;
1856}
d5e7c279
JB
1857
1858
a7ca3326 1859DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
14ff1ee0 1860 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
e4ed805e 1861If FRAME is invisible or iconified, make it visible.
14ff1ee0
PJ
1862If you don't specify a frame, the selected frame is used.
1863If Emacs is displaying on an ordinary terminal or some other device which
1bf72735 1864doesn't support multiple overlapping frames, this function selects FRAME. */)
5842a27b 1865 (Lisp_Object frame)
dbc4e1c1 1866{
d9f07150 1867 struct frame *f = decode_live_frame (frame);
828ac693 1868
d9f07150 1869 XSETFRAME (frame, f);
a3547743 1870
1bf72735 1871 if (FRAME_TERMCAP_P (f))
c6bf3022 1872 /* On a text terminal select FRAME. */
216e6a14 1873 Fselect_frame (frame, Qnil);
1bf72735
MR
1874 else
1875 /* Do like the documentation says. */
1876 Fmake_frame_visible (frame);
8a981af5 1877
6ed8eeff
KL
1878 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1879 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
dbc4e1c1
JB
1880
1881 return Qnil;
1882}
1883
b49f5578 1884/* Should we have a corresponding function called Flower_Power? */
e518d5e1 1885DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
14ff1ee0
PJ
1886 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1887If you don't specify a frame, the selected frame is used.
1888If Emacs is displaying on an ordinary terminal or some other device which
1889doesn't support multiple overlapping frames, this function does nothing. */)
5842a27b 1890 (Lisp_Object frame)
dbc4e1c1 1891{
d9f07150 1892 struct frame *f = decode_live_frame (frame);
a3547743 1893
6ed8eeff
KL
1894 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1895 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
dbc4e1c1
JB
1896
1897 return Qnil;
1898}
1899
d5e7c279 1900\f
a7ca3326 1901DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
d5e7c279 1902 1, 2, 0,
14ff1ee0
PJ
1903 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1904In other words, switch-frame events caused by events in FRAME will
1905request a switch to FOCUS-FRAME, and `last-event-frame' will be
1906FOCUS-FRAME after reading an event typed at FRAME.
1907
8137e7b3
MR
1908If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1909frame again receives its own keystrokes.
14ff1ee0
PJ
1910
1911Focus redirection is useful for temporarily redirecting keystrokes to
1912a surrogate minibuffer frame when a frame doesn't have its own
1913minibuffer window.
1914
66a9dbbe 1915A frame's focus redirection can be changed by `select-frame'. If frame
14ff1ee0
PJ
1916FOO is selected, and then a different frame BAR is selected, any
1917frames redirecting their focus to FOO are shifted to redirect their
1918focus to BAR. This allows focus redirection to work properly when the
1919user switches from one frame to another using `select-window'.
1920
1921This means that a frame whose focus is redirected to itself is treated
1922differently from a frame whose focus is redirected to nil; the former
66a9dbbe 1923is affected by `select-frame', while the latter is not.
14ff1ee0
PJ
1924
1925The redirection lasts until `redirect-frame-focus' is called to change it. */)
5842a27b 1926 (Lisp_Object frame, Lisp_Object focus_frame)
d5e7c279 1927{
13144095
JB
1928 /* Note that we don't check for a live frame here. It's reasonable
1929 to redirect the focus of a frame you're about to delete, if you
1930 know what other frame should receive those keystrokes. */
d9f07150 1931 struct frame *f = decode_any_frame (frame);
f9898cc6 1932
a42e9724 1933 if (! NILP (focus_frame))
b7826503 1934 CHECK_LIVE_FRAME (focus_frame);
d5e7c279 1935
f00af5b1 1936 fset_focus_frame (f, focus_frame);
d5e7c279 1937
6ed8eeff
KL
1938 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1939 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
177c0ea7 1940
d5e7c279
JB
1941 return Qnil;
1942}
1943
1944
d9f07150 1945DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
14ff1ee0 1946 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
d9f07150
DA
1947If FRAME is omitted or nil, the selected frame is used.
1948Return nil if FRAME's focus is not redirected.
14ff1ee0 1949See `redirect-frame-focus'. */)
5842a27b 1950 (Lisp_Object frame)
d5e7c279 1951{
d9f07150 1952 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
d5e7c279
JB
1953}
1954
fcd42c11
DA
1955DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
1956 doc: /* Set the input focus to FRAME.
97fc2468
DA
1957FRAME nil means use the selected frame.
1958If there is no window system support, this function does nothing. */)
fcd42c11
DA
1959 (Lisp_Object frame)
1960{
97fc2468 1961#ifdef HAVE_WINDOW_SYSTEM
fcd42c11 1962 x_focus_frame (decode_window_system_frame (frame));
97fc2468 1963#endif
fcd42c11
DA
1964 return Qnil;
1965}
d5e7c279 1966
dc6f92b8 1967\f
329ca574
RS
1968/* Return the value of frame parameter PROP in frame FRAME. */
1969
298819b9 1970#ifdef HAVE_WINDOW_SYSTEM
dc6f92b8 1971Lisp_Object
971de7fb 1972get_frame_param (register struct frame *frame, Lisp_Object prop)
dc6f92b8
JB
1973{
1974 register Lisp_Object tem;
1975
e69b0960 1976 tem = Fassq (prop, frame->param_alist);
dc6f92b8
JB
1977 if (EQ (tem, Qnil))
1978 return tem;
1979 return Fcdr (tem);
1980}
298819b9 1981#endif
dc6f92b8 1982
a18b8cb5 1983/* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
fa54c6ae
RS
1984
1985void
971de7fb 1986frames_discard_buffer (Lisp_Object buffer)
fa54c6ae
RS
1987{
1988 Lisp_Object frame, tail;
1989
1990 FOR_EACH_FRAME (tail, frame)
1991 {
f00af5b1
PE
1992 fset_buffer_list
1993 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
1994 fset_buried_buffer_list
1995 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
fa54c6ae
RS
1996 }
1997}
1998
329ca574
RS
1999/* Modify the alist in *ALISTPTR to associate PROP with VAL.
2000 If the alist already has an element for PROP, we change it. */
2001
dc6f92b8 2002void
971de7fb 2003store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
dc6f92b8
JB
2004{
2005 register Lisp_Object tem;
dc6f92b8 2006
dc6f92b8
JB
2007 tem = Fassq (prop, *alistptr);
2008 if (EQ (tem, Qnil))
2009 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2010 else
2011 Fsetcdr (tem, val);
2012}
2013
e5317d61 2014static int
d311d28c 2015frame_name_fnn_p (char *str, ptrdiff_t len)
e5317d61 2016{
5e073ec7 2017 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
e5317d61 2018 {
5e073ec7
PE
2019 char *p = str + 2;
2020 while ('0' <= *p && *p <= '9')
2021 p++;
2022 if (p == str + len)
e5317d61
EZ
2023 return 1;
2024 }
2025 return 0;
2026}
2027
2028/* Set the name of the terminal frame. Also used by MSDOS frames.
2029 Modeled after x_set_name which is used for WINDOW frames. */
2030
66a9dbbe 2031static void
971de7fb 2032set_term_frame_name (struct frame *f, Lisp_Object name)
e5317d61
EZ
2033{
2034 f->explicit_name = ! NILP (name);
2035
2036 /* If NAME is nil, set the name to F<num>. */
2037 if (NILP (name))
2038 {
8a401434 2039 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
e5317d61
EZ
2040
2041 /* Check for no change needed in this very common case
2042 before we do any consing. */
e69b0960 2043 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
e5317d61
EZ
2044 return;
2045
a8290ec3 2046 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
e5317d61
EZ
2047 }
2048 else
2049 {
b7826503 2050 CHECK_STRING (name);
e5317d61
EZ
2051
2052 /* Don't change the name if it's already NAME. */
e69b0960 2053 if (! NILP (Fstring_equal (name, f->name)))
e5317d61
EZ
2054 return;
2055
2056 /* Don't allow the user to set the frame name to F<num>, so it
2057 doesn't clash with the names we generate for terminal frames. */
42a5b22f 2058 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
e5317d61
EZ
2059 error ("Frame names of the form F<num> are usurped by Emacs");
2060 }
2061
f00af5b1 2062 fset_name (f, name);
2ec9db5d 2063 update_mode_lines = 16;
e5317d61
EZ
2064}
2065
75b09539 2066#ifdef HAVE_NTGUI
880e6158
MR
2067void
2068set_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2069{
2070 register Lisp_Object old_alist_elt;
2071
2072 old_alist_elt = Fassq (prop, f->param_alist);
2073 if (EQ (old_alist_elt, Qnil))
2074 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2075 else
2076 Fsetcdr (old_alist_elt, val);
2077}
75b09539 2078#endif
880e6158 2079
dc6f92b8 2080void
971de7fb 2081store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
dc6f92b8 2082{
7eb63b72 2083 register Lisp_Object old_alist_elt;
dc6f92b8 2084
a18b8cb5 2085 /* The buffer-list parameters are stored in a special place and not
52eb77a6 2086 in the alist. All buffers must be live. */
fa54c6ae
RS
2087 if (EQ (prop, Qbuffer_list))
2088 {
52eb77a6
CY
2089 Lisp_Object list = Qnil;
2090 for (; CONSP (val); val = XCDR (val))
2091 if (!NILP (Fbuffer_live_p (XCAR (val))))
2092 list = Fcons (XCAR (val), list);
f00af5b1 2093 fset_buffer_list (f, Fnreverse (list));
fa54c6ae
RS
2094 return;
2095 }
a18b8cb5
KL
2096 if (EQ (prop, Qburied_buffer_list))
2097 {
52eb77a6
CY
2098 Lisp_Object list = Qnil;
2099 for (; CONSP (val); val = XCDR (val))
2100 if (!NILP (Fbuffer_live_p (XCAR (val))))
2101 list = Fcons (XCAR (val), list);
f00af5b1 2102 fset_buried_buffer_list (f, Fnreverse (list));
a18b8cb5
KL
2103 return;
2104 }
fa54c6ae 2105
7eb63b72
GM
2106 /* If PROP is a symbol which is supposed to have frame-local values,
2107 and it is set up based on this frame, switch to the global
2108 binding. That way, we can create or alter the frame-local binding
2109 without messing up the symbol's status. */
2110 if (SYMBOLP (prop))
2111 {
ce5b453a
SM
2112 struct Lisp_Symbol *sym = XSYMBOL (prop);
2113 start:
2114 switch (sym->redirect)
2115 {
2116 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2117 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2118 case SYMBOL_LOCALIZED:
2119 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
a04e2c62 2120 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
ce5b453a
SM
2121 swap_in_global_binding (sym);
2122 break;
2123 }
1088b922 2124 default: emacs_abort ();
ce5b453a 2125 }
7eb63b72
GM
2126 }
2127
9b2cd403
SM
2128 /* The tty color needed to be set before the frame's parameter
2129 alist was updated with the new value. This is not true any more,
2130 but we still do this test early on. */
2131 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2132 && f == FRAME_TTY (f)->previous_frame)
2133 /* Force redisplay of this tty. */
2134 FRAME_TTY (f)->previous_frame = NULL;
94674d18 2135
7eb63b72 2136 /* Update the frame parameter alist. */
e69b0960 2137 old_alist_elt = Fassq (prop, f->param_alist);
7eb63b72 2138 if (EQ (old_alist_elt, Qnil))
f00af5b1 2139 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
dc6f92b8 2140 else
7eb63b72 2141 Fsetcdr (old_alist_elt, val);
bc93c097 2142
7eb63b72
GM
2143 /* Update some other special parameters in their special places
2144 in addition to the alist. */
177c0ea7 2145
329ca574 2146 if (EQ (prop, Qbuffer_predicate))
f00af5b1 2147 fset_buffer_predicate (f, val);
329ca574 2148
032d78fe 2149 if (! FRAME_WINDOW_P (f))
e5317d61
EZ
2150 {
2151 if (EQ (prop, Qmenu_bar_lines))
2152 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2153 else if (EQ (prop, Qname))
2154 set_term_frame_name (f, val);
2155 }
a249de79 2156
e35d291d 2157 if (EQ (prop, Qminibuffer) && WINDOWP (val))
bc93c097
JB
2158 {
2159 if (! MINI_WINDOW_P (XWINDOW (val)))
6b61353c 2160 error ("Surrogate minibuffer windows must be minibuffer windows");
bc93c097 2161
213bac8a 2162 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
e69b0960 2163 && !EQ (val, f->minibuffer_window))
7af7ef38 2164 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
bc93c097
JB
2165
2166 /* Install the chosen minibuffer window, with proper buffer. */
f00af5b1 2167 fset_minibuffer_window (f, val);
bc93c097 2168 }
dc6f92b8
JB
2169}
2170
ff11dfa1 2171DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
14ff1ee0
PJ
2172 doc: /* Return the parameters-alist of frame FRAME.
2173It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2174The meaningful PARMs depend on the kind of frame.
d9f07150 2175If FRAME is omitted or nil, return information on the currently selected frame. */)
5842a27b 2176 (Lisp_Object frame)
dc6f92b8
JB
2177{
2178 Lisp_Object alist;
d9f07150 2179 struct frame *f = decode_any_frame (frame);
dd10ec4f 2180 int height, width;
57629833 2181 struct gcpro gcpro1;
dc6f92b8 2182
f769f1b2 2183 if (!FRAME_LIVE_P (f))
dc6f92b8
JB
2184 return Qnil;
2185
e69b0960 2186 alist = Fcopy_alist (f->param_alist);
57629833 2187 GCPRO1 (alist);
177c0ea7 2188
2d764c78 2189 if (!FRAME_WINDOW_P (f))
bb221971 2190 {
4aec4b29
EZ
2191 int fg = FRAME_FOREGROUND_PIXEL (f);
2192 int bg = FRAME_BACKGROUND_PIXEL (f);
e1d0bbc9
EZ
2193 Lisp_Object elt;
2194
2195 /* If the frame's parameter alist says the colors are
2196 unspecified and reversed, take the frame's background pixel
2197 for foreground and vice versa. */
2198 elt = Fassq (Qforeground_color, alist);
19b5e79b 2199 if (CONSP (elt) && STRINGP (XCDR (elt)))
70de9f06 2200 {
42a5b22f 2201 if (strncmp (SSDATA (XCDR (elt)),
70de9f06 2202 unspecified_bg,
d5db4077 2203 SCHARS (XCDR (elt))) == 0)
70de9f06 2204 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
42a5b22f 2205 else if (strncmp (SSDATA (XCDR (elt)),
70de9f06 2206 unspecified_fg,
d5db4077 2207 SCHARS (XCDR (elt))) == 0)
70de9f06
EZ
2208 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2209 }
e1d0bbc9
EZ
2210 else
2211 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2212 elt = Fassq (Qbackground_color, alist);
19b5e79b 2213 if (CONSP (elt) && STRINGP (XCDR (elt)))
70de9f06 2214 {
42a5b22f 2215 if (strncmp (SSDATA (XCDR (elt)),
70de9f06 2216 unspecified_fg,
d5db4077 2217 SCHARS (XCDR (elt))) == 0)
70de9f06 2218 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
42a5b22f 2219 else if (strncmp (SSDATA (XCDR (elt)),
70de9f06 2220 unspecified_bg,
d5db4077 2221 SCHARS (XCDR (elt))) == 0)
70de9f06
EZ
2222 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2223 }
e1d0bbc9
EZ
2224 else
2225 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2d764c78
EZ
2226 store_in_alist (&alist, intern ("font"),
2227 build_string (FRAME_MSDOS_P (f)
2228 ? "ms-dos"
4ec0d3c1 2229 : FRAME_W32_P (f) ? "w32term"
4ec0d3c1 2230 :"tty"));
bb221971 2231 }
e69b0960 2232 store_in_alist (&alist, Qname, f->name);
880e6158
MR
2233 height = (f->new_height
2234 ? (f->new_pixelwise
2235 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2236 : f->new_height)
2237 : FRAME_LINES (f));
dd10ec4f 2238 store_in_alist (&alist, Qheight, make_number (height));
880e6158
MR
2239 width = (f->new_width
2240 ? (f->new_pixelwise
2241 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2242 : f->new_width)
2243 : FRAME_COLS (f));
dd10ec4f 2244 store_in_alist (&alist, Qwidth, make_number (width));
f769f1b2 2245 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
fd0c2bd1 2246 store_in_alist (&alist, Qminibuffer,
39acc701 2247 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
f769f1b2
KH
2248 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2249 : FRAME_MINIBUF_WINDOW (f)));
2250 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
d9f07150
DA
2251 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2252 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
fd0c2bd1 2253
dbc4e1c1 2254 /* I think this should be done with a hook. */
032d78fe
GV
2255#ifdef HAVE_WINDOW_SYSTEM
2256 if (FRAME_WINDOW_P (f))
ff11dfa1 2257 x_report_frame_params (f, &alist);
b6dd20ed 2258 else
fd0c2bd1 2259#endif
16a3738c
KH
2260 {
2261 /* This ought to be correct in f->param_alist for an X frame. */
2262 Lisp_Object lines;
f4e93c40 2263 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
16a3738c
KH
2264 store_in_alist (&alist, Qmenu_bar_lines, lines);
2265 }
57629833
GM
2266
2267 UNGCPRO;
dc6f92b8
JB
2268 return alist;
2269}
2270
8b60f7bc 2271
a7ca3326 2272DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
14ff1ee0
PJ
2273 doc: /* Return FRAME's value for parameter PARAMETER.
2274If FRAME is nil, describe the currently selected frame. */)
5842a27b 2275 (Lisp_Object frame, Lisp_Object parameter)
8b60f7bc 2276{
d9f07150
DA
2277 struct frame *f = decode_any_frame (frame);
2278 Lisp_Object value = Qnil;
8b60f7bc 2279
b7826503 2280 CHECK_SYMBOL (parameter);
177c0ea7 2281
d9f07150 2282 XSETFRAME (frame, f);
177c0ea7 2283
8b60f7bc
GM
2284 if (FRAME_LIVE_P (f))
2285 {
5cd62b8c 2286 /* Avoid consing in frequent cases. */
67d853e6 2287 if (EQ (parameter, Qname))
e69b0960 2288 value = f->name;
6345f6aa
GM
2289#ifdef HAVE_X_WINDOWS
2290 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
aad3612f 2291 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
6345f6aa 2292#endif /* HAVE_X_WINDOWS */
75700ff2
GM
2293 else if (EQ (parameter, Qbackground_color)
2294 || EQ (parameter, Qforeground_color))
67d853e6 2295 {
e69b0960 2296 value = Fassq (parameter, f->param_alist);
67d853e6 2297 if (CONSP (value))
5f65b39d 2298 {
5f65b39d
EZ
2299 value = XCDR (value);
2300 /* Fframe_parameters puts the actual fg/bg color names,
2301 even if f->param_alist says otherwise. This is
2302 important when param_alist's notion of colors is
2303 "unspecified". We need to do the same here. */
2304 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2305 {
c9b08ba8 2306 const char *color_name;
d311d28c 2307 ptrdiff_t csz;
e1d0bbc9
EZ
2308
2309 if (EQ (parameter, Qbackground_color))
2310 {
42a5b22f 2311 color_name = SSDATA (value);
d5db4077 2312 csz = SCHARS (value);
e1d0bbc9
EZ
2313 if (strncmp (color_name, unspecified_bg, csz) == 0)
2314 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2315 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2316 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2317 }
2318 else if (EQ (parameter, Qforeground_color))
2319 {
42a5b22f 2320 color_name = SSDATA (value);
d5db4077 2321 csz = SCHARS (value);
e1d0bbc9
EZ
2322 if (strncmp (color_name, unspecified_fg, csz) == 0)
2323 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2324 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2325 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2326 }
5f65b39d
EZ
2327 }
2328 }
b23236fb
EZ
2329 else
2330 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
67d853e6 2331 }
75700ff2
GM
2332 else if (EQ (parameter, Qdisplay_type)
2333 || EQ (parameter, Qbackground_mode))
e69b0960 2334 value = Fcdr (Fassq (parameter, f->param_alist));
75700ff2 2335 else
ce5b453a
SM
2336 /* FIXME: Avoid this code path at all (as well as code duplication)
2337 by sharing more code with Fframe_parameters. */
75700ff2 2338 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
8b60f7bc 2339 }
177c0ea7 2340
8b60f7bc
GM
2341 return value;
2342}
2343
2344
a7ca3326 2345DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
ff11dfa1 2346 Smodify_frame_parameters, 2, 2, 0,
14ff1ee0
PJ
2347 doc: /* Modify the parameters of frame FRAME according to ALIST.
2348If FRAME is nil, it defaults to the selected frame.
2349ALIST is an alist of parameters to change and their new values.
2350Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2351The meaningful PARMs depend on the kind of frame.
2352Undefined PARMs are ignored, but stored in the frame's parameter list
2353so that `frame-parameters' will return them.
2354
2355The value of frame parameter FOO can also be accessed
2356as a frame-local binding for the variable FOO, if you have
cf36572d
GM
2357enabled such bindings for that variable with `make-variable-frame-local'.
2358Note that this functionality is obsolete as of Emacs 22.2, and its
2359use is not recommended. Explicitly check for a frame-parameter instead. */)
5842a27b 2360 (Lisp_Object frame, Lisp_Object alist)
dc6f92b8 2361{
d9f07150 2362 struct frame *f = decode_live_frame (frame);
ec3058af
DA
2363 register Lisp_Object prop, val;
2364
2365 CHECK_LIST (alist);
dc6f92b8 2366
dbc4e1c1 2367 /* I think this should be done with a hook. */
032d78fe
GV
2368#ifdef HAVE_WINDOW_SYSTEM
2369 if (FRAME_WINDOW_P (f))
fd0c2bd1 2370 x_set_frame_parameters (f, alist);
329ca574 2371 else
bb221971
RS
2372#endif
2373#ifdef MSDOS
2374 if (FRAME_MSDOS_P (f))
2375 IT_set_frame_parameters (f, alist);
2376 else
329ca574 2377#endif
574a1a90 2378
41d44f1f 2379 {
d311d28c
PE
2380 EMACS_INT length = XFASTINT (Flength (alist));
2381 ptrdiff_t i;
2382 Lisp_Object *parms;
2383 Lisp_Object *values;
2384 USE_SAFE_ALLOCA;
2385 SAFE_ALLOCA_LISP (parms, 2 * length);
2386 values = parms + length;
41d44f1f
RS
2387
2388 /* Extract parm names and values into those vectors. */
2389
ec3058af 2390 for (i = 0; CONSP (alist); alist = XCDR (alist))
41d44f1f 2391 {
213bac8a 2392 Lisp_Object elt;
41d44f1f 2393
ec3058af 2394 elt = XCAR (alist);
41d44f1f
RS
2395 parms[i] = Fcar (elt);
2396 values[i] = Fcdr (elt);
2397 i++;
2398 }
2399
2400 /* Now process them in reverse of specified order. */
5ffe6683 2401 while (--i >= 0)
41d44f1f
RS
2402 {
2403 prop = parms[i];
2404 val = values[i];
2405 store_frame_param (f, prop, val);
33d537f0 2406
043604ee
CY
2407 if (EQ (prop, Qforeground_color)
2408 || EQ (prop, Qbackground_color))
2409 update_face_from_frame_parameter (f, prop, val);
41d44f1f 2410 }
d311d28c
PE
2411
2412 SAFE_FREE ();
41d44f1f 2413 }
3b58be21 2414 return Qnil;
dc6f92b8
JB
2415}
2416\f
a26a1f95 2417DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
14ff1ee0
PJ
2418 0, 1, 0,
2419 doc: /* Height in pixels of a line in the font in frame FRAME.
d9f07150 2420If FRAME is omitted or nil, the selected frame is used.
14ff1ee0 2421For a terminal frame, the value is always 1. */)
5842a27b 2422 (Lisp_Object frame)
dc6f92b8 2423{
032d78fe 2424#ifdef HAVE_WINDOW_SYSTEM
d9f07150
DA
2425 struct frame *f = decode_any_frame (frame);
2426
032d78fe 2427 if (FRAME_WINDOW_P (f))
1700db3c 2428 return make_number (FRAME_LINE_HEIGHT (f));
a26a1f95 2429 else
dc6d9681 2430#endif
a26a1f95
RS
2431 return make_number (1);
2432}
dc6d9681 2433
dc6f92b8 2434
a26a1f95 2435DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
14ff1ee0
PJ
2436 0, 1, 0,
2437 doc: /* Width in pixels of characters in the font in frame FRAME.
d9f07150 2438If FRAME is omitted or nil, the selected frame is used.
31b7cc74 2439On a graphical screen, the width is the standard width of the default font.
14ff1ee0 2440For a terminal screen, the value is always 1. */)
5842a27b 2441 (Lisp_Object frame)
dc6f92b8 2442{
032d78fe 2443#ifdef HAVE_WINDOW_SYSTEM
d9f07150
DA
2444 struct frame *f = decode_any_frame (frame);
2445
032d78fe 2446 if (FRAME_WINDOW_P (f))
1700db3c 2447 return make_number (FRAME_COLUMN_WIDTH (f));
a26a1f95
RS
2448 else
2449#endif
2450 return make_number (1);
dc6f92b8
JB
2451}
2452
177c0ea7 2453DEFUN ("frame-pixel-height", Fframe_pixel_height,
a26a1f95 2454 Sframe_pixel_height, 0, 1, 0,
14ff1ee0 2455 doc: /* Return a FRAME's height in pixels.
d9f07150 2456If FRAME is omitted or nil, the selected frame is used. The exact value
9ec6f100
GM
2457of the result depends on the window-system and toolkit in use:
2458
2459In the Gtk+ version of Emacs, it includes only any window (including
4c36be58 2460the minibuffer or echo area), mode line, and header line. It does not
9ec6f100
GM
2461include the tool bar or menu bar.
2462
02615da0
JD
2463With other graphical versions, it also includes the tool bar and the
2464menu bar.
9ec6f100 2465
c6bf3022 2466For a text terminal, it includes the menu bar. In this case, the
9ec6f100
GM
2467result is really in characters rather than pixels (i.e., is identical
2468to `frame-height'). */)
5842a27b 2469 (Lisp_Object frame)
dc6f92b8 2470{
d9f07150 2471 struct frame *f = decode_any_frame (frame);
a26a1f95 2472
032d78fe
GV
2473#ifdef HAVE_WINDOW_SYSTEM
2474 if (FRAME_WINDOW_P (f))
f435830e 2475 return make_number (FRAME_PIXEL_HEIGHT (f));
a26a1f95 2476 else
dc6d9681 2477#endif
5af5757b 2478 return make_number (FRAME_LINES (f));
a26a1f95
RS
2479}
2480
177c0ea7 2481DEFUN ("frame-pixel-width", Fframe_pixel_width,
a26a1f95 2482 Sframe_pixel_width, 0, 1, 0,
14ff1ee0
PJ
2483 doc: /* Return FRAME's width in pixels.
2484For a terminal frame, the result really gives the width in characters.
d9f07150 2485If FRAME is omitted or nil, the selected frame is used. */)
5842a27b 2486 (Lisp_Object frame)
a26a1f95 2487{
d9f07150 2488 struct frame *f = decode_any_frame (frame);
dc6f92b8 2489
032d78fe
GV
2490#ifdef HAVE_WINDOW_SYSTEM
2491 if (FRAME_WINDOW_P (f))
f435830e 2492 return make_number (FRAME_PIXEL_WIDTH (f));
a26a1f95
RS
2493 else
2494#endif
5af5757b 2495 return make_number (FRAME_COLS (f));
a26a1f95 2496}
fb0cf781
J
2497
2498DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2499 Stool_bar_pixel_width, 0, 1, 0,
2500 doc: /* Return width in pixels of FRAME's tool bar.
2501The result is greater than zero only when the tool bar is on the left
d9f07150
DA
2502or right side of FRAME. If FRAME is omitted or nil, the selected frame
2503is used. */)
fb0cf781
J
2504 (Lisp_Object frame)
2505{
fb0cf781 2506#ifdef FRAME_TOOLBAR_WIDTH
d9f07150
DA
2507 struct frame *f = decode_any_frame (frame);
2508
2509 if (FRAME_WINDOW_P (f))
2510 return make_number (FRAME_TOOLBAR_WIDTH (f));
fb0cf781 2511#endif
4ddb20d6 2512 return make_number (0);
fb0cf781 2513}
880e6158
MR
2514
2515DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2516 doc: /* Return width in columns of FRAME's text area. */)
2517 (Lisp_Object frame)
2518{
2519 return make_number (FRAME_COLS (decode_any_frame (frame)));
2520}
2521
2522DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2523 doc: /* Return height in lines of FRAME's text area. */)
2524 (Lisp_Object frame)
2525{
2526 return make_number (FRAME_LINES (decode_any_frame (frame)));
2527}
2528
2529DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2530 doc: /* Return total columns of FRAME. */)
2531 (Lisp_Object frame)
2532{
2533 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2534}
2535
2536DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2537 doc: /* Return text area width of FRAME in pixels. */)
2538 (Lisp_Object frame)
2539{
2540 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2541}
2542
2543DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2544 doc: /* Return text area height of FRAME in pixels. */)
2545 (Lisp_Object frame)
2546{
2547 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2548}
2549
2550DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2551 doc: /* Return scroll bar width of FRAME in pixels. */)
2552 (Lisp_Object frame)
2553{
c44de18d 2554 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
880e6158
MR
2555}
2556
2557DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2558 doc: /* Return fringe width of FRAME in pixels. */)
2559 (Lisp_Object frame)
2560{
2561 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2562}
2563
2564DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2565 doc: /* Return border width of FRAME in pixels. */)
2566 (Lisp_Object frame)
2567{
2568 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2569}
2570
2571DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2572 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2573 (Lisp_Object frame)
2574{
2575 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2576}
2577
2578DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2579 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2580 (Lisp_Object frame)
2581{
2582 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2583}
a26a1f95 2584\f
880e6158
MR
2585DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2586 doc: /* Specify that the frame FRAME has HEIGHT text lines.
2587Optional third arg PRETEND non-nil means that redisplay should use
2588HEIGHT lines but that the idea of the actual height of the frame should
2589not be changed. Optional fourth argument PIXELWISE non-nil means that
2590FRAME should be HEIGHT pixels high. */)
2591 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
dc6f92b8 2592{
d9f07150 2593 register struct frame *f = decode_live_frame (frame);
dc6f92b8 2594
880e6158 2595 CHECK_TYPE_RANGED_INTEGER (int, height);
dc6f92b8 2596
dbc4e1c1 2597 /* I think this should be done with a hook. */
032d78fe
GV
2598#ifdef HAVE_WINDOW_SYSTEM
2599 if (FRAME_WINDOW_P (f))
dc6f92b8 2600 {
880e6158
MR
2601 if (NILP (pixelwise))
2602 {
2603 if (XINT (height) != FRAME_LINES (f))
2604 x_set_window_size (f, 1, FRAME_COLS (f), XINT (height), 0);
2605
2606 do_pending_window_change (0);
2607 }
2608 else if (XINT (height) != FRAME_TEXT_HEIGHT (f))
2609 {
2610 x_set_window_size (f, 1, FRAME_TEXT_WIDTH (f), XINT (height), 1);
2611 do_pending_window_change (0);
2612 }
dc6f92b8
JB
2613 }
2614 else
fd0c2bd1 2615#endif
880e6158
MR
2616 change_frame_size (f, 0, XINT (height), !NILP (pretend), 0, 0,
2617 NILP (pixelwise) ? 0 : 1);
dc6f92b8
JB
2618 return Qnil;
2619}
2620
880e6158
MR
2621DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2622 doc: /* Specify that the frame FRAME has WIDTH columns.
2623Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2624columns but that the idea of the actual width of the frame should not
2625be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2626should be WIDTH pixels wide. */)
2627 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
dc6f92b8 2628{
d9f07150
DA
2629 register struct frame *f = decode_live_frame (frame);
2630
880e6158 2631 CHECK_TYPE_RANGED_INTEGER (int, width);
dc6f92b8 2632
dbc4e1c1 2633 /* I think this should be done with a hook. */
032d78fe
GV
2634#ifdef HAVE_WINDOW_SYSTEM
2635 if (FRAME_WINDOW_P (f))
dc6f92b8 2636 {
880e6158
MR
2637 if (NILP (pixelwise))
2638 {
2639 if (XINT (width) != FRAME_COLS (f))
2640 x_set_window_size (f, 1, XINT (width), FRAME_LINES (f), 0);
2641
2642 do_pending_window_change (0);
2643 }
2644 else if (XINT (width) != FRAME_TEXT_WIDTH (f))
2645 {
2646 x_set_window_size (f, 1, XINT (width), FRAME_TEXT_HEIGHT (f), 1);
2647 do_pending_window_change (0);
2648 }
dc6f92b8
JB
2649 }
2650 else
fd0c2bd1 2651#endif
880e6158
MR
2652 change_frame_size (f, XINT (width), 0, !NILP (pretend), 0, 0,
2653 NILP (pixelwise) ? 0 : 1);
dc6f92b8
JB
2654 return Qnil;
2655}
2656
880e6158
MR
2657DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2658 doc: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2659Optional argument PIXELWISE non-nil means to measure in pixels. */)
2660 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
dc6f92b8 2661{
4c131798 2662 register struct frame *f = decode_live_frame (frame);
dc6f92b8 2663
880e6158
MR
2664 CHECK_TYPE_RANGED_INTEGER (int, width);
2665 CHECK_TYPE_RANGED_INTEGER (int, height);
dc6f92b8 2666
dbc4e1c1 2667 /* I think this should be done with a hook. */
032d78fe
GV
2668#ifdef HAVE_WINDOW_SYSTEM
2669 if (FRAME_WINDOW_P (f))
dc6f92b8 2670 {
880e6158
MR
2671 if (!NILP (pixelwise)
2672 ? (XINT (width) != FRAME_TEXT_WIDTH (f)
2673 || XINT (height) != FRAME_TEXT_HEIGHT (f)
2674 || f->new_height || f->new_width)
2675 : (XINT (width) != FRAME_COLS (f)
2676 || XINT (height) != FRAME_LINES (f)
2677 || f->new_height || f->new_width))
2678 {
2679 x_set_window_size (f, 1, XINT (width), XINT (height),
2680 NILP (pixelwise) ? 0 : 1);
2681 do_pending_window_change (0);
2682 }
dc6f92b8
JB
2683 }
2684 else
fd0c2bd1 2685#endif
880e6158
MR
2686 change_frame_size (f, XINT (width), XINT (height), 0, 0, 0,
2687 NILP (pixelwise) ? 0 : 1);
dc6f92b8
JB
2688
2689 return Qnil;
2690}
2691
177c0ea7 2692DEFUN ("set-frame-position", Fset_frame_position,
ff11dfa1 2693 Sset_frame_position, 3, 3, 0,
14ff1ee0 2694 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
4c131798
DA
2695If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2696actually the position of the upper left corner of the frame. Negative
2697values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2698or bottommost possible position (that stays within the screen). */)
5842a27b 2699 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
dc6f92b8 2700{
4c131798 2701 register struct frame *f = decode_live_frame (frame);
dc6f92b8 2702
d311d28c
PE
2703 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2704 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
dc6f92b8 2705
dbc4e1c1 2706 /* I think this should be done with a hook. */
032d78fe
GV
2707#ifdef HAVE_WINDOW_SYSTEM
2708 if (FRAME_WINDOW_P (f))
c7c70761 2709 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
fd0c2bd1 2710#endif
dc6f92b8
JB
2711
2712 return Qt;
2713}
dc6d9681 2714
dc6f92b8 2715\f
972f4259
KS
2716/***********************************************************************
2717 Frame Parameters
2718 ***********************************************************************/
2719
2720/* Connect the frame-parameter names for X frames
2721 to the ways of passing the parameter values to the window system.
2722
2723 The name of a parameter, as a Lisp symbol,
2724 has an `x-frame-parameter' property which is an integer in Lisp
2725 that is an index in this table. */
2726
2727struct frame_parm_table {
675e2c69 2728 const char *name;
972f4259
KS
2729 Lisp_Object *variable;
2730};
2731
94eed851 2732static const struct frame_parm_table frame_parms[] =
972f4259
KS
2733{
2734 {"auto-raise", &Qauto_raise},
2735 {"auto-lower", &Qauto_lower},
2736 {"background-color", 0},
2737 {"border-color", &Qborder_color},
2738 {"border-width", &Qborder_width},
2739 {"cursor-color", &Qcursor_color},
2740 {"cursor-type", &Qcursor_type},
2741 {"font", 0},
2742 {"foreground-color", 0},
2743 {"icon-name", &Qicon_name},
2744 {"icon-type", &Qicon_type},
2745 {"internal-border-width", &Qinternal_border_width},
880e6158
MR
2746 {"right-divider-width", &Qright_divider_width},
2747 {"bottom-divider-width", &Qbottom_divider_width},
972f4259
KS
2748 {"menu-bar-lines", &Qmenu_bar_lines},
2749 {"mouse-color", &Qmouse_color},
2750 {"name", &Qname},
2751 {"scroll-bar-width", &Qscroll_bar_width},
2752 {"title", &Qtitle},
2753 {"unsplittable", &Qunsplittable},
2754 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2755 {"visibility", &Qvisibility},
2756 {"tool-bar-lines", &Qtool_bar_lines},
2757 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2758 {"scroll-bar-background", &Qscroll_bar_background},
2759 {"screen-gamma", &Qscreen_gamma},
2760 {"line-spacing", &Qline_spacing},
2761 {"left-fringe", &Qleft_fringe},
2762 {"right-fringe", &Qright_fringe},
2763 {"wait-for-wm", &Qwait_for_wm},
2764 {"fullscreen", &Qfullscreen},
0a708637 2765 {"font-backend", &Qfont_backend},
cad9ef74
JD
2766 {"alpha", &Qalpha},
2767 {"sticky", &Qsticky},
bfeabdc3 2768 {"tool-bar-position", &Qtool_bar_position},
972f4259
KS
2769};
2770
0fda9b75 2771#ifdef HAVE_NTGUI
972f4259 2772
972f4259 2773/* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
bd45aef7 2774 wanted positions of the WM window (not Emacs window).
972f4259
KS
2775 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2776 window (FRAME_X_WINDOW).
2777 */
2778
dfcf069d 2779void
971de7fb 2780x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
dc6f92b8 2781{
5af5757b
KS
2782 int newwidth = FRAME_COLS (f);
2783 int newheight = FRAME_LINES (f);
aad3612f 2784 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
dc6f92b8 2785
5af5757b
KS
2786 *top_pos = f->top_pos;
2787 *left_pos = f->left_pos;
3df1fda2 2788
5af5757b 2789 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
972f4259
KS
2790 {
2791 int ph;
2792
a0fe6cca 2793 ph = x_display_pixel_height (dpyinfo);
5af5757b
KS
2794 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2795 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2796 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
972f4259
KS
2797 *top_pos = 0;
2798 }
dc6f92b8 2799
5af5757b 2800 if (f->want_fullscreen & FULLSCREEN_WIDTH)
972f4259
KS
2801 {
2802 int pw;
2803
a0fe6cca 2804 pw = x_display_pixel_width (dpyinfo);
5af5757b
KS
2805 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2806 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2807 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
972f4259
KS
2808 *left_pos = 0;
2809 }
dc6f92b8 2810
972f4259
KS
2811 *width = newwidth;
2812 *height = newheight;
2813}
dc6f92b8 2814
0fda9b75 2815#endif /* HAVE_NTGUI */
81626931
PE
2816
2817#ifdef HAVE_WINDOW_SYSTEM
beb0bc36 2818
972f4259
KS
2819/* Change the parameters of frame F as specified by ALIST.
2820 If a parameter is not specially recognized, do nothing special;
2821 otherwise call the `x_set_...' function for that parameter.
2822 Except for certain geometry properties, always call store_frame_param
2823 to store the new value in the parameter alist. */
14ff1ee0 2824
972f4259 2825void
a10c8269 2826x_set_frame_parameters (struct frame *f, Lisp_Object alist)
972f4259
KS
2827{
2828 Lisp_Object tail;
dc6f92b8 2829
972f4259
KS
2830 /* If both of these parameters are present, it's more efficient to
2831 set them both at once. So we wait until we've looked at the
2832 entire list before we set them. */
afca0e75 2833 int width = 0, height = 0;
632e91a6 2834 bool width_change = 0, height_change = 0;
3df1fda2 2835
972f4259
KS
2836 /* Same here. */
2837 Lisp_Object left, top;
2838
2839 /* Same with these. */
2840 Lisp_Object icon_left, icon_top;
2841
2842 /* Record in these vectors all the parms specified. */
2843 Lisp_Object *parms;
2844 Lisp_Object *values;
f66c7cf8 2845 ptrdiff_t i, p;
959067a1 2846 bool left_no_change = 0, top_no_change = 0;
af025ae8 2847#ifdef HAVE_X_WINDOWS
959067a1 2848 bool icon_left_no_change = 0, icon_top_no_change = 0;
af025ae8 2849#endif
972f4259
KS
2850 struct gcpro gcpro1, gcpro2;
2851
2852 i = 0;
7d7bbefd 2853 for (tail = alist; CONSP (tail); tail = XCDR (tail))
972f4259
KS
2854 i++;
2855
38182d90
PE
2856 parms = alloca (i * sizeof *parms);
2857 values = alloca (i * sizeof *values);
972f4259
KS
2858
2859 /* Extract parm names and values into those vectors. */
2860
2861 i = 0;
d7b10f4c 2862 for (tail = alist; CONSP (tail); tail = XCDR (tail))
972f4259
KS
2863 {
2864 Lisp_Object elt;
2865
d7b10f4c 2866 elt = XCAR (tail);
972f4259
KS
2867 parms[i] = Fcar (elt);
2868 values[i] = Fcdr (elt);
2869 i++;
2870 }
2871 /* TAIL and ALIST are not used again below here. */
2872 alist = tail = Qnil;
2873
2874 GCPRO2 (*parms, *values);
2875 gcpro1.nvars = i;
2876 gcpro2.nvars = i;
2877
2878 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2879 because their values appear in VALUES and strings are not valid. */
2880 top = left = Qunbound;
2881 icon_left = icon_top = Qunbound;
2882
972f4259
KS
2883 /* Process foreground_color and background_color before anything else.
2884 They are independent of other properties, but other properties (e.g.,
2885 cursor_color) are dependent upon them. */
2886 /* Process default font as well, since fringe widths depends on it. */
972f4259
KS
2887 for (p = 0; p < i; p++)
2888 {
2889 Lisp_Object prop, val;
2890
2891 prop = parms[p];
2892 val = values[p];
2893 if (EQ (prop, Qforeground_color)
2894 || EQ (prop, Qbackground_color)
3f1c6666 2895 || EQ (prop, Qfont))
972f4259
KS
2896 {
2897 register Lisp_Object param_index, old_value;
2898
2899 old_value = get_frame_param (f, prop);
972f4259
KS
2900 if (NILP (Fequal (val, old_value)))
2901 {
2902 store_frame_param (f, prop, val);
2903
2904 param_index = Fget (prop, Qx_frame_parameter);
2905 if (NATNUMP (param_index)
c72d972c 2906 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
fa971ac3
KL
2907 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2908 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
972f4259
KS
2909 }
2910 }
2911 }
2912
2913 /* Now process them in reverse of specified order. */
c5101a77 2914 while (i-- != 0)
972f4259
KS
2915 {
2916 Lisp_Object prop, val;
2917
2918 prop = parms[i];
2919 val = values[i];
2920
d311d28c 2921 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3f1c6666 2922 {
632e91a6 2923 width_change = 1;
8960529e 2924 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3f1c6666 2925 }
d311d28c 2926 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3f1c6666 2927 {
632e91a6 2928 height_change = 1;
8960529e 2929 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3f1c6666 2930 }
972f4259
KS
2931 else if (EQ (prop, Qtop))
2932 top = val;
2933 else if (EQ (prop, Qleft))
2934 left = val;
2935 else if (EQ (prop, Qicon_top))
2936 icon_top = val;
2937 else if (EQ (prop, Qicon_left))
2938 icon_left = val;
2939 else if (EQ (prop, Qforeground_color)
2940 || EQ (prop, Qbackground_color)
3f1c6666 2941 || EQ (prop, Qfont))
972f4259
KS
2942 /* Processed above. */
2943 continue;
2944 else
2945 {
2946 register Lisp_Object param_index, old_value;
2947
2948 old_value = get_frame_param (f, prop);
2949
2950 store_frame_param (f, prop, val);
2951
2952 param_index = Fget (prop, Qx_frame_parameter);
2953 if (NATNUMP (param_index)
c72d972c 2954 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
fa971ac3
KL
2955 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2956 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
972f4259
KS
2957 }
2958 }
2959
2960 /* Don't die if just one of these was set. */
5fbfb018 2961 if (EQ (left, Qunbound))
972f4259
KS
2962 {
2963 left_no_change = 1;
5af5757b 2964 if (f->left_pos < 0)
6c6f1994 2965 left = list2 (Qplus, make_number (f->left_pos));
972f4259 2966 else
5af5757b 2967 XSETINT (left, f->left_pos);
972f4259 2968 }
5fbfb018 2969 if (EQ (top, Qunbound))
972f4259
KS
2970 {
2971 top_no_change = 1;
5af5757b 2972 if (f->top_pos < 0)
6c6f1994 2973 top = list2 (Qplus, make_number (f->top_pos));
972f4259 2974 else
5af5757b 2975 XSETINT (top, f->top_pos);
972f4259
KS
2976 }
2977
2978 /* If one of the icon positions was not set, preserve or default it. */
d311d28c 2979 if (! TYPE_RANGED_INTEGERP (int, icon_left))
972f4259 2980 {
af025ae8 2981#ifdef HAVE_X_WINDOWS
972f4259 2982 icon_left_no_change = 1;
af025ae8 2983#endif
e69b0960 2984 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
972f4259
KS
2985 if (NILP (icon_left))
2986 XSETINT (icon_left, 0);
2987 }
d311d28c 2988 if (! TYPE_RANGED_INTEGERP (int, icon_top))
972f4259 2989 {
af025ae8 2990#ifdef HAVE_X_WINDOWS
972f4259 2991 icon_top_no_change = 1;
af025ae8 2992#endif
e69b0960 2993 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
972f4259
KS
2994 if (NILP (icon_top))
2995 XSETINT (icon_top, 0);
2996 }
2997
972f4259
KS
2998 /* Don't set these parameters unless they've been explicitly
2999 specified. The window might be mapped or resized while we're in
3000 this function, and we don't want to override that unless the lisp
3001 code has asked for it.
3002
3003 Don't set these parameters unless they actually differ from the
3004 window's current parameters; the window may not actually exist
3005 yet. */
3006 {
3007 Lisp_Object frame;
3008
880e6158 3009 /* Make this 1, eventually. */
8960529e 3010 check_frame_size (f, &width, &height, 1);
972f4259
KS
3011
3012 XSETFRAME (frame, f);
3013
632e91a6 3014 if ((width_change || height_change)
8960529e
MR
3015 && (width != FRAME_TEXT_WIDTH (f)
3016 || height != FRAME_TEXT_HEIGHT (f)
880e6158 3017 || f->new_height || f->new_width))
632e91a6
MR
3018 {
3019 /* If necessary provide default values for HEIGHT and WIDTH. Do
3020 that here since otherwise a size change implied by an
3021 intermittent font change may get lost as in Bug#17142. */
3022 if (!width_change)
3023 width = (f->new_width
3024 ? (f->new_pixelwise
3025 ? f->new_width
3026 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3027 : FRAME_TEXT_WIDTH (f));
3028
3029 if (!height_change)
3030 height = (f->new_height
3031 ? (f->new_pixelwise
3032 ? f->new_height
3033 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3034 : FRAME_TEXT_HEIGHT (f));
3035
3036 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3037 }
972f4259
KS
3038
3039 if ((!NILP (left) || !NILP (top))
3040 && ! (left_no_change && top_no_change)
5af5757b
KS
3041 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3042 && NUMBERP (top) && XINT (top) == f->top_pos))
972f4259
KS
3043 {
3044 int leftpos = 0;
3045 int toppos = 0;
3046
3047 /* Record the signs. */
5af5757b 3048 f->size_hint_flags &= ~ (XNegative | YNegative);
972f4259 3049 if (EQ (left, Qminus))
5af5757b 3050 f->size_hint_flags |= XNegative;
b8898fda 3051 else if (TYPE_RANGED_INTEGERP (int, left))
972f4259
KS
3052 {
3053 leftpos = XINT (left);
3054 if (leftpos < 0)
5af5757b 3055 f->size_hint_flags |= XNegative;
972f4259
KS
3056 }
3057 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3058 && CONSP (XCDR (left))
b8898fda 3059 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
972f4259
KS
3060 {
3061 leftpos = - XINT (XCAR (XCDR (left)));
5af5757b 3062 f->size_hint_flags |= XNegative;
972f4259
KS
3063 }
3064 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3065 && CONSP (XCDR (left))
b8898fda 3066 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
972f4259
KS
3067 {
3068 leftpos = XINT (XCAR (XCDR (left)));
3069 }
3070
3071 if (EQ (top, Qminus))
5af5757b 3072 f->size_hint_flags |= YNegative;
b8898fda 3073 else if (TYPE_RANGED_INTEGERP (int, top))
972f4259
KS
3074 {
3075 toppos = XINT (top);
3076 if (toppos < 0)
5af5757b 3077 f->size_hint_flags |= YNegative;
972f4259
KS
3078 }
3079 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3080 && CONSP (XCDR (top))
b8898fda 3081 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
972f4259
KS
3082 {
3083 toppos = - XINT (XCAR (XCDR (top)));
5af5757b 3084 f->size_hint_flags |= YNegative;
972f4259
KS
3085 }
3086 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3087 && CONSP (XCDR (top))
b8898fda 3088 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
972f4259
KS
3089 {
3090 toppos = XINT (XCAR (XCDR (top)));
3091 }
3092
3093
3094 /* Store the numeric value of the position. */
5af5757b
KS
3095 f->top_pos = toppos;
3096 f->left_pos = leftpos;
972f4259 3097
5af5757b 3098 f->win_gravity = NorthWestGravity;
972f4259
KS
3099
3100 /* Actually set that position, and convert to absolute. */
3101 x_set_offset (f, leftpos, toppos, -1);
3102 }
52b8a085 3103#ifdef HAVE_X_WINDOWS
972f4259
KS
3104 if ((!NILP (icon_left) || !NILP (icon_top))
3105 && ! (icon_left_no_change && icon_top_no_change))
3106 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
52b8a085 3107#endif /* HAVE_X_WINDOWS */
972f4259
KS
3108 }
3109
3110 UNGCPRO;
3111}
3112
3113
3114/* Insert a description of internally-recorded parameters of frame X
3115 into the parameter alist *ALISTPTR that is to be given to the user.
3116 Only parameters that are specific to the X window system
3117 and whose values are not correctly recorded in the frame's
3118 param_alist need to be considered here. */
3119
3120void
971de7fb 3121x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
972f4259 3122{
972f4259 3123 Lisp_Object tem;
82ef37c1
PE
3124 uprintmax_t w;
3125 char buf[INT_BUFSIZE_BOUND (w)];
972f4259
KS
3126
3127 /* Represent negative positions (off the top or left screen edge)
3128 in a way that Fmodify_frame_parameters will understand correctly. */
5af5757b
KS
3129 XSETINT (tem, f->left_pos);
3130 if (f->left_pos >= 0)
972f4259
KS
3131 store_in_alist (alistptr, Qleft, tem);
3132 else
6c6f1994 3133 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
972f4259 3134
5af5757b
KS
3135 XSETINT (tem, f->top_pos);
3136 if (f->top_pos >= 0)
972f4259
KS
3137 store_in_alist (alistptr, Qtop, tem);
3138 else
6c6f1994 3139 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
972f4259
KS
3140
3141 store_in_alist (alistptr, Qborder_width,
5af5757b 3142 make_number (f->border_width));
972f4259 3143 store_in_alist (alistptr, Qinternal_border_width,
5af5757b 3144 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
880e6158
MR
3145 store_in_alist (alistptr, Qright_divider_width,
3146 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3147 store_in_alist (alistptr, Qbottom_divider_width,
3148 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
972f4259 3149 store_in_alist (alistptr, Qleft_fringe,
5af5757b 3150 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
972f4259 3151 store_in_alist (alistptr, Qright_fringe,
5af5757b 3152 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
972f4259
KS
3153 store_in_alist (alistptr, Qscroll_bar_width,
3154 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3155 ? make_number (0)
5af5757b
KS
3156 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3157 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
972f4259
KS
3158 /* nil means "use default width"
3159 for non-toolkit scroll bar.
3160 ruler-mode.el depends on this. */
3161 : Qnil));
208a048d
EZ
3162 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3163 MS-Windows it returns a value whose type is HANDLE, which is
3164 actually a pointer. Explicit casting avoids compiler
3165 warnings. */
82ef37c1 3166 w = (uintptr_t) FRAME_X_WINDOW (f);
972f4259 3167 store_in_alist (alistptr, Qwindow_id,
62aba0d4 3168 make_formatted_string (buf, "%"pMu, w));
972f4259
KS
3169#ifdef HAVE_X_WINDOWS
3170#ifdef USE_X_TOOLKIT
3171 /* Tooltip frame may not have this widget. */
3172 if (FRAME_X_OUTPUT (f)->widget)
3173#endif
82ef37c1 3174 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
972f4259 3175 store_in_alist (alistptr, Qouter_window_id,
62aba0d4 3176 make_formatted_string (buf, "%"pMu, w));
972f4259 3177#endif
e69b0960 3178 store_in_alist (alistptr, Qicon_name, f->icon_name);
972f4259
KS
3179 store_in_alist (alistptr, Qvisibility,
3180 (FRAME_VISIBLE_P (f) ? Qt
3181 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3182 store_in_alist (alistptr, Qdisplay,
aad3612f 3183 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
972f4259 3184
aad3612f 3185 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
972f4259
KS
3186 tem = Qnil;
3187 else
ec6ecaad 3188 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
5839d7e8 3189 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
972f4259 3190 store_in_alist (alistptr, Qparent_id, tem);
e69b0960 3191 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
972f4259
KS
3192}
3193
3194
3195/* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3196 the previous value of that parameter, NEW_VALUE is the new value. */
3197
3198void
971de7fb 3199x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
972f4259 3200{
972f4259 3201 if (NILP (new_value))
5af5757b 3202 f->want_fullscreen = FULLSCREEN_NONE;
3f1c6666 3203 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
5af5757b 3204 f->want_fullscreen = FULLSCREEN_BOTH;
972f4259 3205 else if (EQ (new_value, Qfullwidth))
5af5757b 3206 f->want_fullscreen = FULLSCREEN_WIDTH;
972f4259 3207 else if (EQ (new_value, Qfullheight))
5af5757b 3208 f->want_fullscreen = FULLSCREEN_HEIGHT;
3f1c6666
JD
3209 else if (EQ (new_value, Qmaximized))
3210 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
d761dd42 3211
a3547743 3212 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
974b73e8 3213 FRAME_TERMINAL (f)->fullscreen_hook (f);
972f4259
KS
3214}
3215
3216
3217/* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3218 the previous value of that parameter, NEW_VALUE is the new value. */
3219
3220void
971de7fb 3221x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
972f4259
KS
3222{
3223 if (NILP (new_value))
3224 f->extra_line_spacing = 0;
d311d28c 3225 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
972f4259 3226 f->extra_line_spacing = XFASTINT (new_value);
fdda0220
EZ
3227 else if (FLOATP (new_value))
3228 {
3229 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3230
3231 if (new_spacing >= 0)
3232 f->extra_line_spacing = new_spacing;
3233 else
3234 signal_error ("Invalid line-spacing", new_value);
3235 }
972f4259 3236 else
9dc95187 3237 signal_error ("Invalid line-spacing", new_value);
972f4259
KS
3238 if (FRAME_VISIBLE_P (f))
3239 redraw_frame (f);
3240}
3241
3242
3243/* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3244 the previous value of that parameter, NEW_VALUE is the new value. */
3245
3246void
971de7fb 3247x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
972f4259 3248{
05fc2ef7
CY
3249 Lisp_Object bgcolor;
3250
972f4259
KS
3251 if (NILP (new_value))
3252 f->gamma = 0;
3253 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
05fc2ef7
CY
3254 /* The value 0.4545 is the normal viewing gamma. */
3255 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
972f4259 3256 else
9dc95187 3257 signal_error ("Invalid screen-gamma", new_value);
972f4259 3258
05fc2ef7 3259 /* Apply the new gamma value to the frame background. */
e69b0960 3260 bgcolor = Fassq (Qbackground_color, f->param_alist);
05fc2ef7
CY
3261 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3262 {
76c1cebc
PE
3263 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3264 if (NATNUMP (parm_index)
c72d972c 3265 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
76c1cebc
PE
3266 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3267 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
6baa22c1 3268 (f, bgcolor, Qnil);
05fc2ef7
CY
3269 }
3270
3271 Fclear_face_cache (Qnil);
972f4259
KS
3272}
3273
3274
3275void
971de7fb 3276x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259 3277{
6045c4fd 3278 Lisp_Object font_object;
e0c8ad78 3279 int fontset = -1;
6045c4fd
PE
3280#ifdef HAVE_X_WINDOWS
3281 Lisp_Object font_param = arg;
3282#endif
972f4259 3283
178377e1 3284 /* Set the frame parameter back to the old value because we may
e0c8ad78
KH
3285 fail to use ARG as the new parameter value. */
3286 store_frame_param (f, Qfont, oldval);
0169d360 3287
d507f8d7
KH
3288 /* ARG is a fontset name, a font name, a cons of fontset name and a
3289 font object, or a font object. In the last case, this function
3290 never fail. */
e0c8ad78
KH
3291 if (STRINGP (arg))
3292 {
3293 fontset = fs_query_fontset (arg, 0);
3294 if (fontset < 0)
0169d360 3295 {
d7ea76b4 3296 font_object = font_open_by_name (f, arg);
e0c8ad78 3297 if (NILP (font_object))
42a5b22f 3298 error ("Font `%s' is not defined", SSDATA (arg));
e0c8ad78 3299 arg = AREF (font_object, FONT_NAME_INDEX);
0169d360 3300 }
e0c8ad78
KH
3301 else if (fontset > 0)
3302 {
d7ea76b4 3303 font_object = font_open_by_name (f, fontset_ascii (fontset));
e0c8ad78
KH
3304 if (NILP (font_object))
3305 error ("Font `%s' is not defined", SDATA (arg));
97d42150 3306 arg = AREF (font_object, FONT_NAME_INDEX);
e0c8ad78 3307 }
0169d360 3308 else
e0c8ad78 3309 error ("The default fontset can't be used for a frame font");
0169d360 3310 }
d507f8d7
KH
3311 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3312 {
3313 /* This is the case that the ASCII font of F's fontset XCAR
3314 (arg) is changed to the font XCDR (arg) by
3315 `set-fontset-font'. */
3316 fontset = fs_query_fontset (XCAR (arg), 0);
3317 if (fontset < 0)
3318 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3319 font_object = XCDR (arg);
3320 arg = AREF (font_object, FONT_NAME_INDEX);
6045c4fd 3321#ifdef HAVE_X_WINDOWS
581e51e8 3322 font_param = Ffont_get (font_object, QCname);
6045c4fd 3323#endif
d507f8d7 3324 }
e0c8ad78 3325 else if (FONT_OBJECT_P (arg))
698ca23e 3326 {
e0c8ad78 3327 font_object = arg;
6045c4fd 3328#ifdef HAVE_X_WINDOWS
581e51e8 3329 font_param = Ffont_get (font_object, QCname);
6045c4fd 3330#endif
b17ae93a 3331 /* This is to store the XLFD font name in the frame parameter for
057bce6f 3332 backward compatibility. We should store the font-object
e0c8ad78
KH
3333 itself in the future. */
3334 arg = AREF (font_object, FONT_NAME_INDEX);
b17ae93a 3335 fontset = FRAME_FONTSET (f);
518c4881
KH
3336 /* Check if we can use the current fontset. If not, set FONTSET
3337 to -1 to generate a new fontset from FONT-OBJECT. */
3338 if (fontset >= 0)
3339 {
3340 Lisp_Object ascii_font = fontset_ascii (fontset);
3341 Lisp_Object spec = font_spec_from_name (ascii_font);
3342
e483264c
SM
3343 if (NILP (spec))
3344 signal_error ("Invalid font name", ascii_font);
3345
518c4881
KH
3346 if (! font_match_p (spec, font_object))
3347 fontset = -1;
3348 }
698ca23e 3349 }
e0c8ad78
KH
3350 else
3351 signal_error ("Invalid font", arg);
972f4259 3352
e0c8ad78
KH
3353 if (! NILP (Fequal (font_object, oldval)))
3354 return;
5a9aae2e 3355
e0c8ad78
KH
3356 x_new_font (f, font_object, fontset);
3357 store_frame_param (f, Qfont, arg);
581e51e8
JD
3358#ifdef HAVE_X_WINDOWS
3359 store_frame_param (f, Qfont_param, font_param);
3360#endif
e0c8ad78
KH
3361 /* Recalculate toolbar height. */
3362 f->n_tool_bar_rows = 0;
acfe4602 3363
e0c8ad78
KH
3364 /* Ensure we redraw it. */
3365 clear_current_matrices (f);
ca03f883 3366
acfe4602
MR
3367 /* Attempt to hunt down bug#16028. */
3368 SET_FRAME_GARBAGED (f);
3369
e0c8ad78 3370 recompute_basic_faces (f);
972f4259
KS
3371
3372 do_pending_window_change (0);
3373
a6f75881
CY
3374 /* We used to call face-set-after-frame-default here, but it leads to
3375 recursive calls (since that function can set the `default' face's
3376 font which in turns changes the frame's `font' parameter).
3377 Also I don't know what this call is meant to do, but it seems the
3378 wrong way to do it anyway (it does a lot more work than what seems
3379 reasonable in response to a change to `font'). */
972f4259
KS
3380}
3381
3382
1a356571 3383void
971de7fb 3384x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
1a356571 3385{
1a356571
KH
3386 if (! NILP (new_value)
3387 && !CONSP (new_value))
3388 {
3389 char *p0, *p1;
1bf72735 3390
1a356571 3391 CHECK_STRING (new_value);
42a5b22f 3392 p0 = p1 = SSDATA (new_value);
1a356571
KH
3393 new_value = Qnil;
3394 while (*p0)
3395 {
620f13b0 3396 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
1a356571
KH
3397 if (p0 < p1)
3398 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3399 new_value);
3400 if (*p1)
22e64f7c
KH
3401 {
3402 int c;
3403
620f13b0 3404 while ((c = *++p1) && c_isspace (c));
22e64f7c 3405 }
1a356571
KH
3406 p0 = p1;
3407 }
8fb9e675
KH
3408 new_value = Fnreverse (new_value);
3409 }
3410
3411 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3412 return;
3413
e0c8ad78 3414 if (FRAME_FONT (f))
dfdf55c0 3415 free_all_realized_faces (Qnil);
1a356571 3416
dfdf55c0 3417 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
8fb9e675 3418 if (NILP (new_value))
dfdf55c0
KH
3419 {
3420 if (NILP (old_value))
3421 error ("No font backend available");
3422 font_update_drivers (f, old_value);
3423 error ("None of specified font backends are available");
3424 }
8fb9e675
KH
3425 store_frame_param (f, Qfont_backend, new_value);
3426
e0c8ad78 3427 if (FRAME_FONT (f))
8fb9e675
KH
3428 {
3429 Lisp_Object frame;
3430
3431 XSETFRAME (frame, f);
3432 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3433 ++face_change_count;
94ae2ad4 3434 windows_or_buffers_changed = 18;
8fb9e675 3435 }
1a356571 3436}
1a356571
KH
3437
3438
972f4259 3439void
971de7fb 3440x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
972f4259
KS
3441{
3442 compute_fringe_widths (f, 1);
bfeabdc3
JD
3443#ifdef HAVE_X_WINDOWS
3444 /* Must adjust this so window managers report correct number of columns. */
3445 if (FRAME_X_WINDOW (f) != 0)
3446 x_wm_set_size_hint (f, 0, 0);
3447#endif
972f4259
KS
3448}
3449
3450void
971de7fb 3451x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259 3452{
d311d28c 3453 CHECK_TYPE_RANGED_INTEGER (int, arg);
972f4259 3454
5af5757b 3455 if (XINT (arg) == f->border_width)
972f4259
KS
3456 return;
3457
972f4259 3458 if (FRAME_X_WINDOW (f) != 0)
dac85f4b 3459 error ("Cannot change the border width of a frame");
972f4259 3460
5af5757b 3461 f->border_width = XINT (arg);
972f4259
KS
3462}
3463
3464void
971de7fb 3465x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259 3466{
5af5757b 3467 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
972f4259 3468
d311d28c 3469 CHECK_TYPE_RANGED_INTEGER (int, arg);
5af5757b
KS
3470 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3471 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3472 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
972f4259
KS
3473
3474#ifdef USE_X_TOOLKIT
3475 if (FRAME_X_OUTPUT (f)->edit_widget)
3476 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3477#endif
3478
5af5757b 3479 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
972f4259
KS
3480 return;
3481
3482 if (FRAME_X_WINDOW (f) != 0)
3483 {
880e6158
MR
3484 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3485 SET_FRAME_GARBAGED (f);
3486 do_pending_window_change (0);
3487 }
3488 else
3489 SET_FRAME_GARBAGED (f);
3490}
3491
3492void
3493x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3494{
3495 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3496
3497 CHECK_TYPE_RANGED_INTEGER (int, arg);
3498 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3499 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3500 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3501
3502 if (FRAME_RIGHT_DIVIDER_WIDTH (f) == old)
3503 return;
3504
3505 if (FRAME_X_WINDOW (f) != 0)
3506 {
3507 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3508 SET_FRAME_GARBAGED (f);
3509 do_pending_window_change (0);
3510 }
3511 else
3512 SET_FRAME_GARBAGED (f);
3513}
3514
3515void
3516x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3517{
3518 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3519
3520 CHECK_TYPE_RANGED_INTEGER (int, arg);
3521 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3522 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3523 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3524
3525 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) == old)
3526 return;
3527
3528 if (FRAME_X_WINDOW (f) != 0)
3529 {
3530 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
972f4259
KS
3531 SET_FRAME_GARBAGED (f);
3532 do_pending_window_change (0);
3533 }
3534 else
3535 SET_FRAME_GARBAGED (f);
3536}
3537
3538void
971de7fb 3539x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
972f4259
KS
3540{
3541 Lisp_Object frame;
3542 XSETFRAME (frame, f);
3543
3544 if (NILP (value))
3545 Fmake_frame_invisible (frame, Qt);
3546 else if (EQ (value, Qicon))
3547 Ficonify_frame (frame);
3548 else
3549 Fmake_frame_visible (frame);
3550}
3551
3552void
971de7fb 3553x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259
KS
3554{
3555 f->auto_raise = !EQ (Qnil, arg);
3556}
3557
3558void
971de7fb 3559x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259
KS
3560{
3561 f->auto_lower = !EQ (Qnil, arg);
3562}
3563
3564void
971de7fb 3565x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259
KS
3566{
3567 f->no_split = !NILP (arg);
3568}
3569
3570void
971de7fb 3571x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259
KS
3572{
3573 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3574 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3575 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3576 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3577 {
3578 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3579 = (NILP (arg)
3580 ? vertical_scroll_bar_none
3581 : EQ (Qleft, arg)
3582 ? vertical_scroll_bar_left
3583 : EQ (Qright, arg)
3584 ? vertical_scroll_bar_right
6b61353c
KH
3585 : EQ (Qleft, Vdefault_frame_scroll_bars)
3586 ? vertical_scroll_bar_left
3587 : EQ (Qright, Vdefault_frame_scroll_bars)
3588 ? vertical_scroll_bar_right
3589 : vertical_scroll_bar_none);
972f4259
KS
3590
3591 /* We set this parameter before creating the X window for the
3592 frame, so we can get the geometry right from the start.
3593 However, if the window hasn't been created yet, we shouldn't
3594 call x_set_window_size. */
3595 if (FRAME_X_WINDOW (f))
880e6158
MR
3596 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3597 FRAME_TEXT_HEIGHT (f), 1);
972f4259
KS
3598 do_pending_window_change (0);
3599 }
3600}
3601
3602void
971de7fb 3603x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
972f4259 3604{
880e6158 3605 int unit = FRAME_COLUMN_WIDTH (f);
972f4259
KS
3606
3607 if (NILP (arg))
3608 {
3609 x_set_scroll_bar_default_width (f);
3610
3611 if (FRAME_X_WINDOW (f))
880e6158
MR
3612 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3613 FRAME_TEXT_HEIGHT (f), 1);
972f4259
KS
3614 do_pending_window_change (0);
3615 }
b8898fda 3616 else if (RANGED_INTEGERP (1, arg, INT_MAX)
5af5757b 3617 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
972f4259 3618 {
5af5757b 3619 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
880e6158 3620 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
972f4259 3621 if (FRAME_X_WINDOW (f))
880e6158
MR
3622 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3623 FRAME_TEXT_HEIGHT (f), 1);
972f4259
KS
3624 do_pending_window_change (0);
3625 }
3626
44c5e192
MR
3627 /* Eventually remove the following call. It should have been done by
3628 x_set_window_size already. */
880e6158 3629 change_frame_size (f, 0, 0, 0, 0, 0, 1);
972f4259
KS
3630 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3631 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3632}
3633
0a708637 3634void
971de7fb 3635x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
0a708637
GM
3636{
3637 double alpha = 1.0;
3638 double newval[2];
b8898fda 3639 int i;
0a708637
GM
3640 Lisp_Object item;
3641
3642 for (i = 0; i < 2; i++)
3643 {
3644 newval[i] = 1.0;
3645 if (CONSP (arg))
3646 {
3647 item = CAR (arg);
3648 arg = CDR (arg);
3649 }
3650 else
1fd877d6 3651 item = arg;
0a708637 3652
62e62ea8
CY
3653 if (NILP (item))
3654 alpha = - 1.0;
3655 else if (FLOATP (item))
3656 {
3657 alpha = XFLOAT_DATA (item);
7216e43b 3658 if (! (0 <= alpha && alpha <= 1.0))
62e62ea8
CY
3659 args_out_of_range (make_float (0.0), make_float (1.0));
3660 }
3661 else if (INTEGERP (item))
3662 {
b8898fda 3663 EMACS_INT ialpha = XINT (item);
7216e43b 3664 if (! (0 <= ialpha && alpha <= 100))
62e62ea8 3665 args_out_of_range (make_number (0), make_number (100));
7216e43b 3666 alpha = ialpha / 100.0;
62e62ea8
CY
3667 }
3668 else
3669 wrong_type_argument (Qnumberp, item);
0a708637
GM
3670 newval[i] = alpha;
3671 }
3672
3673 for (i = 0; i < 2; i++)
3674 f->alpha[i] = newval[i];
3675
59bc82c0 3676#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4d7e6e51 3677 block_input ();
0a708637 3678 x_set_frame_alpha (f);
4d7e6e51 3679 unblock_input ();
0a708637
GM
3680#endif
3681
3682 return;
3683}
3684
582ed56c
DA
3685#ifndef HAVE_NS
3686
7a0c745a
DA
3687/* Non-zero if mouse is grabbed on DPYINFO
3688 and we know the frame where it is. */
3689
3690bool x_mouse_grabbed (Display_Info *dpyinfo)
3691{
3692 return (dpyinfo->grabbed
3693 && dpyinfo->last_mouse_frame
3694 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3695}
3696
18da0d8a
DA
3697/* Re-highlight something with mouse-face properties
3698 on DPYINFO using saved frame and mouse position. */
3699
3700void
3701x_redo_mouse_highlight (Display_Info *dpyinfo)
3702{
3703 if (dpyinfo->last_mouse_motion_frame
3704 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3705 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3706 dpyinfo->last_mouse_motion_x,
3707 dpyinfo->last_mouse_motion_y);
3708}
3709
582ed56c
DA
3710#endif /* HAVE_NS */
3711
972f4259
KS
3712/* Subroutines of creating an X frame. */
3713
3714/* Make sure that Vx_resource_name is set to a reasonable value.
3715 Fix it up, or set it to `emacs' if it is too hopeless. */
3716
3717void
971de7fb 3718validate_x_resource_name (void)
972f4259 3719{
8a401434 3720 ptrdiff_t len = 0;
972f4259 3721 /* Number of valid characters in the resource name. */
8a401434 3722 ptrdiff_t good_count = 0;
972f4259 3723 /* Number of invalid characters in the resource name. */
8a401434 3724 ptrdiff_t bad_count = 0;
972f4259 3725 Lisp_Object new;
8a401434 3726 ptrdiff_t i;
972f4259
KS
3727
3728 if (!STRINGP (Vx_resource_class))
3729 Vx_resource_class = build_string (EMACS_CLASS);
3730
3731 if (STRINGP (Vx_resource_name))
3732 {
3733 unsigned char *p = SDATA (Vx_resource_name);
972f4259
KS
3734
3735 len = SBYTES (Vx_resource_name);
3736
3737 /* Only letters, digits, - and _ are valid in resource names.
3738 Count the valid characters and count the invalid ones. */
3739 for (i = 0; i < len; i++)
3740 {
3741 int c = p[i];
3742 if (! ((c >= 'a' && c <= 'z')
3743 || (c >= 'A' && c <= 'Z')
3744 || (c >= '0' && c <= '9')
3745 || c == '-' || c == '_'))
3746 bad_count++;
3747 else
3748 good_count++;
3749 }
3750 }
3751 else
3752 /* Not a string => completely invalid. */
3753 bad_count = 5, good_count = 0;
3754
3755 /* If name is valid already, return. */
3756 if (bad_count == 0)
3757 return;
3758
8a401434
PE
3759 /* If name is entirely invalid, or nearly so, or is so implausibly
3760 large that alloca might not work, use `emacs'. */
3761 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
972f4259
KS
3762 {
3763 Vx_resource_name = build_string ("emacs");
3764 return;
3765 }
3766
3767 /* Name is partly valid. Copy it and replace the invalid characters
3768 with underscores. */
3769
3770 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3771
3772 for (i = 0; i < len; i++)
3773 {
3774 int c = SREF (new, i);
3775 if (! ((c >= 'a' && c <= 'z')
3776 || (c >= 'A' && c <= 'Z')
3777 || (c >= '0' && c <= '9')
3778 || c == '-' || c == '_'))
3779 SSET (new, i, '_');
3780 }
3781}
3782
b5251fe7 3783/* Get specified attribute from resource database RDB.
972f4259
KS
3784 See Fx_get_resource below for other parameters. */
3785
3786static Lisp_Object
971de7fb 3787xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
972f4259
KS
3788{
3789 register char *value;
3790 char *name_key;
3791 char *class_key;
3792
3793 CHECK_STRING (attribute);
3794 CHECK_STRING (class);
3795
3796 if (!NILP (component))
3797 CHECK_STRING (component);
3798 if (!NILP (subclass))
3799 CHECK_STRING (subclass);
3800 if (NILP (component) != NILP (subclass))
3801 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3802
3803 validate_x_resource_name ();
3804
3805 /* Allocate space for the components, the dots which separate them,
3806 and the final '\0'. Make them big enough for the worst case. */
38182d90
PE
3807 name_key = alloca (SBYTES (Vx_resource_name)
3808 + (STRINGP (component)
3809 ? SBYTES (component) : 0)
3810 + SBYTES (attribute)
3811 + 3);
3812
3813 class_key = alloca (SBYTES (Vx_resource_class)
3814 + SBYTES (class)
3815 + (STRINGP (subclass)
3816 ? SBYTES (subclass) : 0)
3817 + 3);
972f4259
KS
3818
3819 /* Start with emacs.FRAMENAME for the name (the specific one)
3820 and with `Emacs' for the class key (the general one). */
42a5b22f
PE
3821 strcpy (name_key, SSDATA (Vx_resource_name));
3822 strcpy (class_key, SSDATA (Vx_resource_class));
972f4259
KS
3823
3824 strcat (class_key, ".");
42a5b22f 3825 strcat (class_key, SSDATA (class));
972f4259
KS
3826
3827 if (!NILP (component))
3828 {
3829 strcat (class_key, ".");
42a5b22f 3830 strcat (class_key, SSDATA (subclass));
972f4259
KS
3831
3832 strcat (name_key, ".");
42a5b22f 3833 strcat (name_key, SSDATA (component));
972f4259
KS
3834 }
3835
3836 strcat (name_key, ".");
42a5b22f 3837 strcat (name_key, SSDATA (attribute));
972f4259
KS
3838
3839 value = x_get_string_resource (rdb, name_key, class_key);
3840
7d652d97 3841 if (value && *value)
972f4259
KS
3842 return build_string (value);
3843 else
3844 return Qnil;
3845}
3846
3847
3848DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3849 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3850This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3851class, where INSTANCE is the name under which Emacs was invoked, or
3852the name specified by the `-name' or `-rn' command-line arguments.
3853
3854The optional arguments COMPONENT and SUBCLASS add to the key and the
3855class, respectively. You must specify both of them or neither.
3856If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3857and the class is `Emacs.CLASS.SUBCLASS'. */)
2bf7d27a
DA
3858 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
3859 Lisp_Object subclass)
972f4259 3860{
7452b7bd 3861 check_window_system (NULL);
972f4259
KS
3862
3863 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3864 attribute, class, component, subclass);
3865}
3866
3867/* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3868
3869Lisp_Object
2bf7d27a
DA
3870display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
3871 Lisp_Object class, Lisp_Object component,
3872 Lisp_Object subclass)
972f4259
KS
3873{
3874 return xrdb_get_resource (dpyinfo->xrdb,
3875 attribute, class, component, subclass);
3876}
3877
018c5e19
PE
3878#if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3879/* Used when C code wants a resource value. */
3880/* Called from oldXMenu/Create.c. */
3881char *
3882x_get_resource_string (const char *attribute, const char *class)
3883{
8a401434 3884 char *result;
018c5e19 3885 struct frame *sf = SELECTED_FRAME ();
8a401434
PE
3886 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3887 USE_SAFE_ALLOCA;
018c5e19
PE
3888
3889 /* Allocate space for the components, the dots which separate them,
3890 and the final '\0'. */
98c6f1e3
PE
3891 char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
3892 char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
018c5e19 3893
8a401434 3894 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
018c5e19
PE
3895 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3896
aad3612f 3897 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
8a401434
PE
3898 name_key, class_key);
3899 SAFE_FREE ();
3900 return result;
018c5e19
PE
3901}
3902#endif
3903
972f4259
KS
3904/* Return the value of parameter PARAM.
3905
3906 First search ALIST, then Vdefault_frame_alist, then the X defaults
3907 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3908
3909 Convert the resource to the type specified by desired_type.
3910
3911 If no default is specified, return Qunbound. If you call
3912 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3913 and don't let it get stored in any Lisp-visible variables! */
3914
3915Lisp_Object
eec47d6b
DN
3916x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3917 const char *attribute, const char *class, enum resource_types type)
972f4259
KS
3918{
3919 register Lisp_Object tem;
3920
3921 tem = Fassq (param, alist);
d00368cf
RS
3922
3923 if (!NILP (tem))
3924 {
3925 /* If we find this parm in ALIST, clear it out
3926 so that it won't be "left over" at the end. */
5f694926 3927 Lisp_Object tail;
d00368cf 3928 XSETCAR (tem, Qnil);
5f694926
RS
3929 /* In case the parameter appears more than once in the alist,
3930 clear it out. */
3931 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3932 if (CONSP (XCAR (tail))
3933 && EQ (XCAR (XCAR (tail)), param))
3934 XSETCAR (XCAR (tail), Qnil);
d00368cf
RS
3935 }
3936 else
972f4259 3937 tem = Fassq (param, Vdefault_frame_alist);
d00368cf
RS
3938
3939 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3940 look in the X resources. */
972f4259
KS
3941 if (EQ (tem, Qnil))
3942 {
4e23bedb 3943 if (attribute && dpyinfo)
972f4259
KS
3944 {
3945 tem = display_x_get_resource (dpyinfo,
3946 build_string (attribute),
3947 build_string (class),
3948 Qnil, Qnil);
3949
3950 if (NILP (tem))
3951 return Qunbound;
3952
3953 switch (type)
3954 {
3955 case RES_TYPE_NUMBER:
42a5b22f 3956 return make_number (atoi (SSDATA (tem)));
972f4259 3957
93318cbd 3958 case RES_TYPE_BOOLEAN_NUMBER:
42a5b22f
PE
3959 if (!strcmp (SSDATA (tem), "on")
3960 || !strcmp (SSDATA (tem), "true"))
93318cbd 3961 return make_number (1);
42a5b22f 3962 return make_number (atoi (SSDATA (tem)));
93318cbd
JD
3963 break;
3964
972f4259 3965 case RES_TYPE_FLOAT:
42a5b22f 3966 return make_float (atof (SSDATA (tem)));
972f4259
KS
3967
3968 case RES_TYPE_BOOLEAN:
3969 tem = Fdowncase (tem);
42a5b22f 3970 if (!strcmp (SSDATA (tem), "on")
edfda783 3971#ifdef HAVE_NS
42a5b22f 3972 || !strcmp (SSDATA (tem), "yes")
edfda783 3973#endif
42a5b22f 3974 || !strcmp (SSDATA (tem), "true"))
972f4259
KS
3975 return Qt;
3976 else
3977 return Qnil;
3978
3979 case RES_TYPE_STRING:
3980 return tem;
3981
3982 case RES_TYPE_SYMBOL:
3983 /* As a special case, we map the values `true' and `on'
3984 to Qt, and `false' and `off' to Qnil. */
3985 {
3986 Lisp_Object lower;
3987 lower = Fdowncase (tem);
42a5b22f 3988 if (!strcmp (SSDATA (lower), "on")
edfda783 3989#ifdef HAVE_NS
42a5b22f 3990 || !strcmp (SSDATA (lower), "yes")
edfda783 3991#endif
42a5b22f 3992 || !strcmp (SSDATA (lower), "true"))
972f4259 3993 return Qt;
42a5b22f 3994 else if (!strcmp (SSDATA (lower), "off")
edfda783 3995#ifdef HAVE_NS
42a5b22f 3996 || !strcmp (SSDATA (lower), "no")
edfda783 3997#endif
42a5b22f 3998 || !strcmp (SSDATA (lower), "false"))
972f4259
KS
3999 return Qnil;
4000 else
4001 return Fintern (tem, Qnil);
4002 }
4003
4004 default:
1088b922 4005 emacs_abort ();
972f4259
KS
4006 }
4007 }
4008 else
4009 return Qunbound;
4010 }
4011 return Fcdr (tem);
4012}
4013
2f7c71a1 4014static Lisp_Object
eec47d6b
DN
4015x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4016 const char *attribute, const char *class,
4017 enum resource_types type)
972f4259 4018{
aad3612f 4019 return x_get_arg (FRAME_DISPLAY_INFO (f),
972f4259
KS
4020 alist, param, attribute, class, type);
4021}
4022
4023/* Like x_frame_get_arg, but also record the value in f->param_alist. */
4024
4025Lisp_Object
eec47d6b
DN
4026x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4027 Lisp_Object param,
4028 const char *attribute, const char *class,
4029 enum resource_types type)
972f4259
KS
4030{
4031 Lisp_Object value;
4032
aad3612f 4033 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
972f4259 4034 attribute, class, type);
edd1c685 4035 if (! NILP (value) && ! EQ (value, Qunbound))
972f4259
KS
4036 store_frame_param (f, param, value);
4037
4038 return value;
4039}
4040
4041
4042/* Record in frame F the specified or default value according to ALIST
4043 of the parameter named PROP (a Lisp symbol).
4044 If no value is specified for PROP, look for an X default for XPROP
4045 on the frame named NAME.
4046 If that is not found either, use the value DEFLT. */
4047
4048Lisp_Object
eec47d6b
DN
4049x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4050 Lisp_Object deflt, const char *xprop, const char *xclass,
4051 enum resource_types type)
972f4259
KS
4052{
4053 Lisp_Object tem;
4054
4055 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4056 if (EQ (tem, Qunbound))
4057 tem = deflt;
6c6f1994 4058 x_set_frame_parameters (f, list1 (Fcons (prop, tem)));
972f4259
KS
4059 return tem;
4060}
4061
4062
e543ae91
JD
4063#if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4064
4065/*
4066 * XParseGeometry parses strings of the form
4067 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4068 * width, height, xoffset, and yoffset are unsigned integers.
4069 * Example: "=80x24+300-49"
4070 * The equal sign is optional.
4071 * It returns a bitmask that indicates which of the four values
4072 * were actually found in the string. For each value found,
4073 * the corresponding argument is updated; for each value
4074 * not found, the corresponding argument is left unchanged.
4075 */
4076
4077static int
e543ae91
JD
4078XParseGeometry (char *string,
4079 int *x, int *y,
4080 unsigned int *width, unsigned int *height)
4081{
4082 int mask = NoValue;
05642592 4083 char *strind;
2d9783e0 4084 unsigned long tempWidth, tempHeight;
05642592 4085 long int tempX, tempY;
e543ae91
JD
4086 char *nextCharacter;
4087
05642592
PE
4088 if (string == NULL || *string == '\0')
4089 return mask;
e543ae91
JD
4090 if (*string == '=')
4091 string++; /* ignore possible '=' at beg of geometry spec */
4092
05642592 4093 strind = string;
e543ae91
JD
4094 if (*strind != '+' && *strind != '-' && *strind != 'x')
4095 {
05642592 4096 tempWidth = strtoul (strind, &nextCharacter, 10);
e543ae91 4097 if (strind == nextCharacter)
05642592 4098 return 0;
e543ae91
JD
4099 strind = nextCharacter;
4100 mask |= WidthValue;
4101 }
4102
4103 if (*strind == 'x' || *strind == 'X')
4104 {
4105 strind++;
05642592 4106 tempHeight = strtoul (strind, &nextCharacter, 10);
e543ae91 4107 if (strind == nextCharacter)
05642592 4108 return 0;
e543ae91
JD
4109 strind = nextCharacter;
4110 mask |= HeightValue;
4111 }
4112
05642592 4113 if (*strind == '+' || *strind == '-')
e543ae91
JD
4114 {
4115 if (*strind == '-')
05642592
PE
4116 mask |= XNegative;
4117 tempX = strtol (strind, &nextCharacter, 10);
4118 if (strind == nextCharacter)
4119 return 0;
4120 strind = nextCharacter;
e543ae91 4121 mask |= XValue;
05642592 4122 if (*strind == '+' || *strind == '-')
e543ae91
JD
4123 {
4124 if (*strind == '-')
05642592
PE
4125 mask |= YNegative;
4126 tempY = strtol (strind, &nextCharacter, 10);
4127 if (strind == nextCharacter)
4128 return 0;
4129 strind = nextCharacter;
e543ae91
JD
4130 mask |= YValue;
4131 }
4132 }
4133
4134 /* If strind isn't at the end of the string then it's an invalid
4135 geometry specification. */
4136
05642592
PE
4137 if (*strind != '\0')
4138 return 0;
e543ae91
JD
4139
4140 if (mask & XValue)
05642592 4141 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
e543ae91 4142 if (mask & YValue)
05642592 4143 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
e543ae91 4144 if (mask & WidthValue)
05642592 4145 *width = min (tempWidth, UINT_MAX);
e543ae91 4146 if (mask & HeightValue)
05642592
PE
4147 *height = min (tempHeight, UINT_MAX);
4148 return mask;
e543ae91
JD
4149}
4150
4151#endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
972f4259
KS
4152
4153\f
7ab5d780
GM
4154/* NS used to define x-parse-geometry in ns-win.el, but that confused
4155 make-docfile: the documentation string in ns-win.el was used for
4156 x-parse-geometry even in non-NS builds.
4157
4158 With two definitions of x-parse-geometry in this file, various
4159 things still get confused (eg M-x apropos documentation), so that
4160 it is best if the two definitions just share the same doc-string.
4161*/
972f4259 4162DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
7ab5d780 4163 doc: /* Parse a display geometry string STRING.
972f4259
KS
4164Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4165The properties returned may include `top', `left', `height', and `width'.
7ab5d780 4166For X, the value of `left' or `top' may be an integer,
972f4259 4167or a list (+ N) meaning N pixels relative to top/left corner,
7ab5d780
GM
4168or a list (- N) meaning -N pixels relative to bottom/right corner.
4169On Nextstep, this just calls `ns-parse-geometry'. */)
5842a27b 4170 (Lisp_Object string)
972f4259
KS
4171{
4172 int geometry, x, y;
4173 unsigned int width, height;
4174 Lisp_Object result;
4175
4176 CHECK_STRING (string);
4177
e543ae91
JD
4178#ifdef HAVE_NS
4179 if (strchr (SSDATA (string), ' ') != NULL)
4180 return call1 (Qns_parse_geometry, string);
4181#endif
51b59d79 4182 geometry = XParseGeometry (SSDATA (string),
972f4259 4183 &x, &y, &width, &height);
972f4259
KS
4184 result = Qnil;
4185 if (geometry & XValue)
4186 {
4187 Lisp_Object element;
4188
4189 if (x >= 0 && (geometry & XNegative))
6c6f1994 4190 element = list3 (Qleft, Qminus, make_number (-x));
972f4259 4191 else if (x < 0 && ! (geometry & XNegative))
6c6f1994 4192 element = list3 (Qleft, Qplus, make_number (x));
972f4259
KS
4193 else
4194 element = Fcons (Qleft, make_number (x));
4195 result = Fcons (element, result);
4196 }
4197
4198 if (geometry & YValue)
4199 {
4200 Lisp_Object element;
4201
4202 if (y >= 0 && (geometry & YNegative))
6c6f1994 4203 element = list3 (Qtop, Qminus, make_number (-y));
972f4259 4204 else if (y < 0 && ! (geometry & YNegative))
6c6f1994 4205 element = list3 (Qtop, Qplus, make_number (y));
972f4259
KS
4206 else
4207 element = Fcons (Qtop, make_number (y));
4208 result = Fcons (element, result);
4209 }
4210
4211 if (geometry & WidthValue)
4212 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4213 if (geometry & HeightValue)
4214 result = Fcons (Fcons (Qheight, make_number (height)), result);
4215
4216 return result;
7ab5d780 4217}
dc4db71c 4218
972f4259
KS
4219
4220/* Calculate the desired size and position of frame F.
4221 Return the flags saying which aspects were specified.
4222
4223 Also set the win_gravity and size_hint_flags of F.
4224
4225 Adjust height for toolbar if TOOLBAR_P is 1.
4226
4227 This function does not make the coordinates positive. */
4228
c024ac08 4229#define DEFAULT_ROWS 35
972f4259
KS
4230#define DEFAULT_COLS 80
4231
959067a1
DA
4232long
4233x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
972f4259
KS
4234{
4235 register Lisp_Object tem0, tem1, tem2;
4236 long window_prompting = 0;
aad3612f 4237 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
972f4259
KS
4238
4239 /* Default values if we fall through.
4240 Actually, if that happens we should get
4241 window manager prompting. */
880e6158 4242 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
5af5757b 4243 SET_FRAME_COLS (f, DEFAULT_COLS);
880e6158 4244 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
5af5757b 4245 FRAME_LINES (f) = DEFAULT_ROWS;
880e6158 4246
972f4259
KS
4247 /* Window managers expect that if program-specified
4248 positions are not (0,0), they're intentional, not defaults. */
5af5757b
KS
4249 f->top_pos = 0;
4250 f->left_pos = 0;
972f4259 4251
880e6158 4252 /* Ensure that old new_width and new_height will not override the
972f4259
KS
4253 values set here. */
4254 /* ++KFS: This was specific to W32, but seems ok for all platforms */
880e6158 4255 f->new_width = f->new_height = f->new_pixelwise = 0;
972f4259
KS
4256
4257 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4258 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4259 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4260 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4261 {
4262 if (!EQ (tem0, Qunbound))
4263 {
4264 CHECK_NUMBER (tem0);
b8898fda
PE
4265 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4266 xsignal1 (Qargs_out_of_range, tem0);
5af5757b 4267 FRAME_LINES (f) = XINT (tem0);
972f4259
KS
4268 }
4269 if (!EQ (tem1, Qunbound))
4270 {
4271 CHECK_NUMBER (tem1);
b8898fda
PE
4272 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4273 xsignal1 (Qargs_out_of_range, tem1);
5af5757b 4274 SET_FRAME_COLS (f, XINT (tem1));
972f4259
KS
4275 }
4276 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4277 window_prompting |= USSize;
4278 else
4279 window_prompting |= PSize;
4280 }
4281
972f4259
KS
4282
4283 /* This used to be done _before_ calling x_figure_window_size, but
4284 since the height is reset here, this was really a no-op. I
4285 assume that moving it here does what Gerd intended (although he
4286 no longer can remember what that was... ++KFS, 2003-03-25. */
4287
4288 /* Add the tool-bar height to the initial frame height so that the
4289 user gets a text display area of the size he specified with -g or
4290 via .Xdefaults. Later changes of the tool-bar height don't
4291 change the frame size. This is done so that users can create
4292 tall Emacs frames without having to guess how tall the tool-bar
4293 will get. */
880e6158 4294 if (toolbar_p && FRAME_TOOL_BAR_HEIGHT (f))
972f4259
KS
4295 {
4296 int margin, relief, bar_height;
4297
4298 relief = (tool_bar_button_relief >= 0
4299 ? tool_bar_button_relief
4300 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4301
b8898fda 4302 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
972f4259
KS
4303 margin = XFASTINT (Vtool_bar_button_margin);
4304 else if (CONSP (Vtool_bar_button_margin)
b8898fda 4305 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
972f4259
KS
4306 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4307 else
4308 margin = 0;
4309
880e6158 4310 /* PXW: We should be able to not round here. */
972f4259 4311 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
5af5757b 4312 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
972f4259
KS
4313 }
4314
4315 compute_fringe_widths (f, 0);
4316
880e6158
MR
4317 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
4318 SET_FRAME_HEIGHT(f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
972f4259
KS
4319
4320 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4321 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4322 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4323 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4324 {
4325 if (EQ (tem0, Qminus))
4326 {
5af5757b 4327 f->top_pos = 0;
972f4259
KS
4328 window_prompting |= YNegative;
4329 }
4330 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4331 && CONSP (XCDR (tem0))
b8898fda 4332 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
972f4259 4333 {
5af5757b 4334 f->top_pos = - XINT (XCAR (XCDR (tem0)));
972f4259
KS
4335 window_prompting |= YNegative;
4336 }
4337 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4338 && CONSP (XCDR (tem0))
b8898fda 4339 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
972f4259 4340 {
5af5757b 4341 f->top_pos = XINT (XCAR (XCDR (tem0)));
972f4259
KS
4342 }
4343 else if (EQ (tem0, Qunbound))
5af5757b 4344 f->top_pos = 0;
972f4259
KS
4345 else
4346 {
d311d28c 4347 CHECK_TYPE_RANGED_INTEGER (int, tem0);
5af5757b
KS
4348 f->top_pos = XINT (tem0);
4349 if (f->top_pos < 0)
972f4259
KS
4350 window_prompting |= YNegative;
4351 }
4352
4353 if (EQ (tem1, Qminus))
4354 {
5af5757b 4355 f->left_pos = 0;
972f4259
KS
4356 window_prompting |= XNegative;
4357 }
4358 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4359 && CONSP (XCDR (tem1))
b8898fda 4360 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
972f4259 4361 {
5af5757b 4362 f->left_pos = - XINT (XCAR (XCDR (tem1)));
972f4259
KS
4363 window_prompting |= XNegative;
4364 }
4365 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4366 && CONSP (XCDR (tem1))
b8898fda 4367 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
972f4259 4368 {
5af5757b 4369 f->left_pos = XINT (XCAR (XCDR (tem1)));
972f4259
KS
4370 }
4371 else if (EQ (tem1, Qunbound))
5af5757b 4372 f->left_pos = 0;
972f4259
KS
4373 else
4374 {
d311d28c 4375 CHECK_TYPE_RANGED_INTEGER (int, tem1);
5af5757b
KS
4376 f->left_pos = XINT (tem1);
4377 if (f->left_pos < 0)
972f4259
KS
4378 window_prompting |= XNegative;
4379 }
4380
4381 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4382 window_prompting |= USPosition;
4383 else
4384 window_prompting |= PPosition;
4385 }
4386
972f4259
KS
4387 if (window_prompting & XNegative)
4388 {
4389 if (window_prompting & YNegative)
5af5757b 4390 f->win_gravity = SouthEastGravity;
972f4259 4391 else
5af5757b 4392 f->win_gravity = NorthEastGravity;
972f4259
KS
4393 }
4394 else
4395 {
4396 if (window_prompting & YNegative)
5af5757b 4397 f->win_gravity = SouthWestGravity;
972f4259 4398 else
5af5757b 4399 f->win_gravity = NorthWestGravity;
972f4259
KS
4400 }
4401
5af5757b 4402 f->size_hint_flags = window_prompting;
972f4259
KS
4403
4404 return window_prompting;
4405}
4406
4407
4408
4409#endif /* HAVE_WINDOW_SYSTEM */
4410
e044e4fc 4411void
632fd57c 4412frame_make_pointer_invisible (struct frame *f)
e044e4fc
JD
4413{
4414 if (! NILP (Vmake_pointer_invisible))
4415 {
632fd57c 4416 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
e044e4fc
JD
4417 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4418 {
4419 f->mouse_moved = 0;
4420 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4421 f->pointer_invisible = 1;
4422 }
4423 }
4424}
4425
4426void
632fd57c 4427frame_make_pointer_visible (struct frame *f)
e044e4fc
JD
4428{
4429 /* We don't check Vmake_pointer_invisible here in case the
4430 pointer was invisible when Vmake_pointer_invisible was set to nil. */
632fd57c 4431 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
e044e4fc
JD
4432 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4433 {
4434 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4435 f->pointer_invisible = 0;
4436 }
4437}
4438
c978536f
JD
4439DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4440 Sframe_pointer_visible_p, 0, 1, 0,
4441 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4442Otherwise it returns nil. FRAME omitted or nil means the
4443selected frame. This is useful when `make-pointer-invisible' is set. */)
4444 (Lisp_Object frame)
4445{
d9f07150 4446 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
c978536f 4447}
972f4259 4448
6799bb26
JD
4449
4450\f
4451/***********************************************************************
4452 Multimonitor data
4453 ***********************************************************************/
4454
4455#ifdef HAVE_WINDOW_SYSTEM
4456
3d5ee10a
PE
4457# if (defined HAVE_NS \
4458 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
6799bb26
JD
4459void
4460free_monitors (struct MonitorInfo *monitors, int n_monitors)
4461{
4462 int i;
4463 for (i = 0; i < n_monitors; ++i)
4464 xfree (monitors[i].name);
4465 xfree (monitors);
4466}
3d5ee10a 4467# endif
6799bb26
JD
4468
4469Lisp_Object
4470make_monitor_attribute_list (struct MonitorInfo *monitors,
4471 int n_monitors,
4472 int primary_monitor,
4473 Lisp_Object monitor_frames,
4474 const char *source)
4475{
4476 Lisp_Object attributes_list = Qnil;
4477 Lisp_Object primary_monitor_attributes = Qnil;
4478 int i;
4479
4480 for (i = 0; i < n_monitors; ++i)
4481 {
4482 Lisp_Object geometry, workarea, attributes = Qnil;
4483 struct MonitorInfo *mi = &monitors[i];
4484
4485 if (mi->geom.width == 0) continue;
4486
4487 workarea = list4i (mi->work.x, mi->work.y,
4488 mi->work.width, mi->work.height);
4489 geometry = list4i (mi->geom.x, mi->geom.y,
4490 mi->geom.width, mi->geom.height);
9acc1074 4491 attributes = Fcons (Fcons (Qsource, build_string (source)),
6799bb26
JD
4492 attributes);
4493 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4494 attributes);
4495 attributes = Fcons (Fcons (Qmm_size,
4496 list2i (mi->mm_width, mi->mm_height)),
4497 attributes);
4498 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4499 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4500 if (mi->name)
4501 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4502 strlen (mi->name))),
4503 attributes);
4504
4505 if (i == primary_monitor)
4506 primary_monitor_attributes = attributes;
4507 else
4508 attributes_list = Fcons (attributes, attributes_list);
4509 }
4510
4511 if (!NILP (primary_monitor_attributes))
4512 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4513 return attributes_list;
4514}
4515
4516#endif /* HAVE_WINDOW_SYSTEM */
4517
972f4259
KS
4518\f
4519/***********************************************************************
4520 Initialization
4521 ***********************************************************************/
4522
4523void
971de7fb 4524syms_of_frame (void)
972f4259 4525{
fe6aa7a1
BT
4526#include "frame.x"
4527
cd3520a4
JB
4528 DEFSYM (Qframep, "framep");
4529 DEFSYM (Qframe_live_p, "frame-live-p");
4530 DEFSYM (Qexplicit_name, "explicit-name");
4531 DEFSYM (Qheight, "height");
4532 DEFSYM (Qicon, "icon");
4533 DEFSYM (Qminibuffer, "minibuffer");
4534 DEFSYM (Qmodeline, "modeline");
4535 DEFSYM (Qonly, "only");
9fb0c957 4536 DEFSYM (Qnone, "none");
cd3520a4
JB
4537 DEFSYM (Qwidth, "width");
4538 DEFSYM (Qgeometry, "geometry");
4539 DEFSYM (Qicon_left, "icon-left");
4540 DEFSYM (Qicon_top, "icon-top");
4541 DEFSYM (Qtooltip, "tooltip");
4542 DEFSYM (Qleft, "left");
4543 DEFSYM (Qright, "right");
4544 DEFSYM (Quser_position, "user-position");
4545 DEFSYM (Quser_size, "user-size");
4546 DEFSYM (Qwindow_id, "window-id");
972f4259 4547#ifdef HAVE_X_WINDOWS
cd3520a4 4548 DEFSYM (Qouter_window_id, "outer-window-id");
972f4259 4549#endif
cd3520a4
JB
4550 DEFSYM (Qparent_id, "parent-id");
4551 DEFSYM (Qx, "x");
4552 DEFSYM (Qw32, "w32");
4553 DEFSYM (Qpc, "pc");
cd3520a4
JB
4554 DEFSYM (Qns, "ns");
4555 DEFSYM (Qvisible, "visible");
4556 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4557 DEFSYM (Qbuffer_list, "buffer-list");
4558 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4559 DEFSYM (Qdisplay_type, "display-type");
4560 DEFSYM (Qbackground_mode, "background-mode");
4561 DEFSYM (Qnoelisp, "noelisp");
4562 DEFSYM (Qtty_color_mode, "tty-color-mode");
4563 DEFSYM (Qtty, "tty");
4564 DEFSYM (Qtty_type, "tty-type");
4565
4566 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4567
4568 DEFSYM (Qfullwidth, "fullwidth");
4569 DEFSYM (Qfullheight, "fullheight");
4570 DEFSYM (Qfullboth, "fullboth");
4571 DEFSYM (Qmaximized, "maximized");
4572 DEFSYM (Qx_resource_name, "x-resource-name");
4573 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4574
4575 DEFSYM (Qterminal, "terminal");
a3547743 4576
6799bb26
JD
4577 DEFSYM (Qgeometry, "geometry");
4578 DEFSYM (Qworkarea, "workarea");
4579 DEFSYM (Qmm_size, "mm-size");
4580 DEFSYM (Qframes, "frames");
4581 DEFSYM (Qsource, "source");
4582
dc4db71c 4583#ifdef HAVE_NS
cd3520a4 4584 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
dc4db71c
CY
4585#endif
4586
972f4259
KS
4587 {
4588 int i;
4589
c72d972c 4590 for (i = 0; i < ARRAYELTS (frame_parms); i++)
972f4259 4591 {
d67b4f80 4592 Lisp_Object v = intern_c_string (frame_parms[i].name);
972f4259
KS
4593 if (frame_parms[i].variable)
4594 {
4595 *frame_parms[i].variable = v;
4596 staticpro (frame_parms[i].variable);
4597 }
4598 Fput (v, Qx_frame_parameter, make_number (i));
4599 }
4600 }
4601
2731a0ad 4602#ifdef HAVE_WINDOW_SYSTEM
29208e82 4603 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
972f4259
KS
4604 doc: /* The name Emacs uses to look up X resources.
4605`x-get-resource' uses this as the first component of the instance name
4606when requesting resource values.
4607Emacs initially sets `x-resource-name' to the name under which Emacs
4608was invoked, or to the value specified with the `-name' or `-rn'
4609switches, if present.
4610
4611It may be useful to bind this variable locally around a call
4612to `x-get-resource'. See also the variable `x-resource-class'. */);
4613 Vx_resource_name = Qnil;
4614
29208e82 4615 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
972f4259
KS
4616 doc: /* The class Emacs uses to look up X resources.
4617`x-get-resource' uses this as the first component of the instance class
4618when requesting resource values.
4619
4620Emacs initially sets `x-resource-class' to "Emacs".
4621
4622Setting this variable permanently is not a reasonable thing to do,
4623but binding this variable locally around a call to `x-get-resource'
4624is a reasonable practice. See also the variable `x-resource-name'. */);
4625 Vx_resource_class = build_string (EMACS_CLASS);
0a708637 4626
29208e82 4627 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
0a708637
GM
4628 doc: /* The lower limit of the frame opacity (alpha transparency).
4629The value should range from 0 (invisible) to 100 (completely opaque).
ca58fa73 4630You can also use a floating number between 0.0 and 1.0. */);
0a708637 4631 Vframe_alpha_lower_limit = make_number (20);
2731a0ad 4632#endif
972f4259 4633
29208e82 4634 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
972f4259
KS
4635 doc: /* Alist of default values for frame creation.
4636These may be set in your init file, like this:
5ff00c42 4637 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
972f4259
KS
4638These override values given in window system configuration data,
4639 including X Windows' defaults database.
4640For values specific to the first Emacs frame, see `initial-frame-alist'.
095fe281 4641For window-system specific values, see `window-system-default-frame-alist'.
972f4259
KS
4642For values specific to the separate minibuffer frame, see
4643 `minibuffer-frame-alist'.
4644The `menu-bar-lines' element of the list controls whether new frames
4645 have menu bars; `menu-bar-mode' works by altering this element.
4646Setting this variable does not affect existing frames, only new ones. */);
fac580eb 4647 Vdefault_frame_alist = Qnil;
972f4259 4648
29208e82 4649 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
6b61353c
KH
4650 doc: /* Default position of scroll bars on this window-system. */);
4651#ifdef HAVE_WINDOW_SYSTEM
5e617bc2 4652#if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
303500aa
CY
4653 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4654 default. */
6b61353c 4655 Vdefault_frame_scroll_bars = Qright;
303500aa
CY
4656#else
4657 Vdefault_frame_scroll_bars = Qleft;
4658#endif
6b61353c
KH
4659#else
4660 Vdefault_frame_scroll_bars = Qnil;
4661#endif
4662
fd9547e8
JD
4663 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4664 scroll_bar_adjust_thumb_portion_p,
4665 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4666Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4667even if the end of the buffer is shown (i.e. overscrolling).
4668Set to nil if you want the thumb to be at the bottom when the end of the buffer
4669is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4670is visible. In this case you can not overscroll. */);
4671 scroll_bar_adjust_thumb_portion_p = 1;
4672
29208e82 4673 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
daf01701 4674 doc: /* The initial frame-object, which represents Emacs's stdout. */);
972f4259 4675
29208e82 4676 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
972f4259
KS
4677 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4678`mouse-position' calls this function, passing its usual return value as
4679argument, and returns whatever this function returns.
4680This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4681which need to do mouse handling at the Lisp level. */);
4682 Vmouse_position_function = Qnil;
4683
29208e82 4684 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
972f4259
KS
4685 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4686If the value is an integer, highlighting is only shown after moving the
4687mouse, while keyboard input turns off the highlight even when the mouse
4688is over the clickable text. However, the mouse shape still indicates
4689when the mouse is over clickable text. */);
4690 Vmouse_highlight = Qt;
4691
29208e82 4692 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
e044e4fc
JD
4693 doc: /* If non-nil, make pointer invisible while typing.
4694The pointer becomes visible again when the mouse is moved. */);
4695 Vmake_pointer_invisible = Qt;
4696
8e015705
BJ
4697 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4698 doc: /* Normal hook run when a frame gains input focus. */);
4699 Vfocus_in_hook = Qnil;
4700 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4701
4702 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4703 doc: /* Normal hook run when a frame loses input focus. */);
4704 Vfocus_out_hook = Qnil;
4705 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4706
29208e82 4707 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
e5d9c0d1 4708 doc: /* Functions run before deleting a frame.
972f4259 4709The functions are run with one arg, the frame to be deleted.
e519a50b
KL
4710See `delete-frame'.
4711
58555d81
SM
4712Note that functions in this list may be called just before the frame is
4713actually deleted, or some time later (or even both when an earlier function
4714in `delete-frame-functions' (indirectly) calls `delete-frame'
4715recursively). */);
972f4259 4716 Vdelete_frame_functions = Qnil;
cd3520a4 4717 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
972f4259 4718
29208e82 4719 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
e1fd756b
GM
4720 doc: /* Non-nil if Menu-Bar mode is enabled.
4721See the command `menu-bar-mode' for a description of this minor mode.
4722Setting this variable directly does not take effect;
4723either customize it (see the info node `Easy Customization')
4724or call the function `menu-bar-mode'. */);
6431f2e6
CY
4725 Vmenu_bar_mode = Qt;
4726
29208e82 4727 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
9d794026
GM
4728 doc: /* Non-nil if Tool-Bar mode is enabled.
4729See the command `tool-bar-mode' for a description of this minor mode.
4730Setting this variable directly does not take effect;
4731either customize it (see the info node `Easy Customization')
4732or call the function `tool-bar-mode'. */);
c8c59954 4733#ifdef HAVE_WINDOW_SYSTEM
6431f2e6 4734 Vtool_bar_mode = Qt;
c8c59954
GM
4735#else
4736 Vtool_bar_mode = Qnil;
4737#endif
6431f2e6 4738
972f4259
KS
4739 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4740 doc: /* Minibufferless frames use this frame's minibuffer.
972f4259
KS
4741Emacs cannot create minibufferless frames unless this is set to an
4742appropriate surrogate.
4743
4744Emacs consults this variable only when creating minibufferless
4745frames; once the frame is created, it sticks with its assigned
4746minibuffer, no matter what this variable is set to. This means that
4747this variable doesn't necessarily say anything meaningful about the
4748current set of frames, or where the minibuffer is currently being
4749displayed.
4750
4751This variable is local to the current terminal and cannot be buffer-local. */);
4752
29208e82 4753 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
da1da002
MR
4754 doc: /* Non-nil if window system changes focus when you move the mouse.
4755You should set this variable to tell Emacs how your window manager
4756handles focus, since there is no way in general for Emacs to find out
86677b58 4757automatically. See also `mouse-autoselect-window'. */);
da1da002 4758 focus_follows_mouse = 0;
a3547743 4759
880e6158 4760 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
f96d0a6b
MR
4761 doc: /* Non-nil means resize frames pixelwise.
4762If this option is nil, resizing a frame rounds its sizes to the frame's
4763current values of `frame-char-height' and `frame-char-width'. If this
4764is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4765by one pixel.
4766
4767With some window managers you have to set this to non-nil in order to
ca58fa73
GM
4768fully maximize frames. To resize your initial frame pixelwise,
4769set this option to a non-nil value in your init file. */);
880e6158
MR
4770 frame_resize_pixelwise = 0;
4771
972f4259 4772 staticpro (&Vframe_list);
dc6f92b8 4773}