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