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