Commit | Line | Data |
---|---|---|
01f1ba30 | 1 | /* Functions for the X window system. |
e9bffc61 | 2 | |
ab422c4d | 3 | Copyright (C) 1989, 1992-2013 Free Software Foundation, Inc. |
01f1ba30 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
9ec0b715 | 7 | GNU Emacs is free software: you can redistribute it and/or modify |
01f1ba30 | 8 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. | |
01f1ba30 JB |
11 | |
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
01f1ba30 | 19 | |
c389a86d | 20 | #include <config.h> |
333b20bb | 21 | #include <stdio.h> |
d62c8769 | 22 | #include <math.h> |
3ecaf7e5 | 23 | #include <unistd.h> |
3ecaf7e5 | 24 | |
40e6f148 | 25 | /* This makes the fields of a Display accessible, in Xlib header files. */ |
333b20bb | 26 | |
40e6f148 RS |
27 | #define XLIB_ILLEGAL_ACCESS |
28 | ||
01f1ba30 JB |
29 | #include "lisp.h" |
30 | #include "xterm.h" | |
f676886a | 31 | #include "frame.h" |
01f1ba30 | 32 | #include "window.h" |
e5560ff7 | 33 | #include "character.h" |
01f1ba30 | 34 | #include "buffer.h" |
58cad5ed | 35 | #include "intervals.h" |
01f1ba30 | 36 | #include "dispextern.h" |
1f98fa48 | 37 | #include "keyboard.h" |
9ac0d9e0 | 38 | #include "blockinput.h" |
57bda87a | 39 | #include <epaths.h> |
942ea06d | 40 | #include "charset.h" |
96db09e4 | 41 | #include "coding.h" |
942ea06d | 42 | #include "fontset.h" |
333b20bb GM |
43 | #include "systime.h" |
44 | #include "termhooks.h" | |
4ae9a85e | 45 | #include "atimer.h" |
28d440ab | 46 | #include "termchar.h" |
02ed2ea8 | 47 | #include "font.h" |
02ed2ea8 | 48 | |
01f1ba30 | 49 | #ifdef HAVE_X_WINDOWS |
67ba84d1 | 50 | |
63cec32f GM |
51 | #include <sys/types.h> |
52 | #include <sys/stat.h> | |
01f1ba30 | 53 | |
0505a740 | 54 | #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */ |
ef493a27 RS |
55 | #include "bitmaps/gray.xbm" |
56 | #else | |
dbc4e1c1 | 57 | #include <X11/bitmaps/gray> |
ef493a27 | 58 | #endif |
dbc4e1c1 | 59 | |
1b9ac145 AS |
60 | #include "xsettings.h" |
61 | ||
4e3f9230 YM |
62 | #ifdef HAVE_XRANDR |
63 | #include <X11/extensions/Xrandr.h> | |
64 | #endif | |
65 | #ifdef HAVE_XINERAMA | |
66 | #include <X11/extensions/Xinerama.h> | |
67 | #endif | |
68 | ||
488dd4c4 JD |
69 | #ifdef USE_GTK |
70 | #include "gtkutil.h" | |
71 | #endif | |
72 | ||
9ef48a9d RS |
73 | #ifdef USE_X_TOOLKIT |
74 | #include <X11/Shell.h> | |
75 | ||
398ffa92 | 76 | #ifndef USE_MOTIF |
8ab9202e CY |
77 | #ifdef HAVE_XAW3D |
78 | #include <X11/Xaw3d/Paned.h> | |
a6ec6cfb | 79 | #include <X11/Xaw3d/Label.h> |
8ab9202e | 80 | #else /* !HAVE_XAW3D */ |
9ef48a9d RS |
81 | #include <X11/Xaw/Paned.h> |
82 | #include <X11/Xaw/Label.h> | |
8ab9202e | 83 | #endif /* HAVE_XAW3D */ |
398ffa92 | 84 | #endif /* USE_MOTIF */ |
9ef48a9d RS |
85 | |
86 | #ifdef USG | |
87 | #undef USG /* ####KLUDGE for Solaris 2.2 and up */ | |
88 | #include <X11/Xos.h> | |
89 | #define USG | |
dc5ddd85 PE |
90 | #ifdef USG /* Pacify gcc -Wunused-macros. */ |
91 | #endif | |
9ef48a9d RS |
92 | #else |
93 | #include <X11/Xos.h> | |
94 | #endif | |
95 | ||
96 | #include "widget.h" | |
97 | ||
98 | #include "../lwlib/lwlib.h" | |
99 | ||
333b20bb GM |
100 | #ifdef USE_MOTIF |
101 | #include <Xm/Xm.h> | |
102 | #include <Xm/DialogS.h> | |
103 | #include <Xm/FileSB.h> | |
dee186b6 J |
104 | #include <Xm/List.h> |
105 | #include <Xm/TextF.h> | |
333b20bb GM |
106 | #endif |
107 | ||
eec47d6b DN |
108 | #ifdef USE_LUCID |
109 | #include "../lwlib/xlwmenu.h" | |
110 | #endif | |
111 | ||
5e617bc2 | 112 | #if !defined (NO_EDITRES) |
6c32dd68 | 113 | #define HACK_EDITRES |
764430a3 | 114 | extern void _XEditResCheckMessages (Widget, XtPointer, XEvent *, Boolean *); |
ee6bacd4 | 115 | #endif /* not defined NO_EDITRES */ |
6c32dd68 | 116 | |
333b20bb GM |
117 | /* Unique id counter for widgets created by the Lucid Widget Library. */ |
118 | ||
6c32dd68 PR |
119 | extern LWLIB_ID widget_id_tick; |
120 | ||
fc2cdd9a GM |
121 | #ifdef USE_MOTIF |
122 | ||
fc2cdd9a GM |
123 | #endif /* USE_MOTIF */ |
124 | ||
9ef48a9d RS |
125 | #endif /* USE_X_TOOLKIT */ |
126 | ||
6b61353c KH |
127 | #ifdef USE_GTK |
128 | ||
6b61353c KH |
129 | #endif /* USE_GTK */ |
130 | ||
9d317b2c | 131 | #define MAXREQUEST(dpy) (XMaxRequestSize (dpy)) |
9d317b2c | 132 | |
955cbe7b PE |
133 | static Lisp_Object Qsuppress_icon; |
134 | static Lisp_Object Qundefined_color; | |
135 | static Lisp_Object Qcompound_text, Qcancel_timer; | |
4e3f9230 | 136 | static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource; |
581e51e8 | 137 | Lisp_Object Qfont_param; |
01f1ba30 | 138 | |
e509cfa6 | 139 | #ifdef GLYPH_DEBUG |
13464394 PE |
140 | static ptrdiff_t image_cache_refcount; |
141 | static int dpyinfo_refcount; | |
eaf1eea9 GM |
142 | #endif |
143 | ||
e4cebfca PE |
144 | static struct x_display_info *x_display_info_for_name (Lisp_Object); |
145 | ||
7e59217d | 146 | /* Let the user specify an X display with a Lisp object. |
708e05dc | 147 | OBJECT may be nil, a frame or a terminal object. |
b9dc4443 RS |
148 | nil stands for the selected frame--or, if that is not an X frame, |
149 | the first X display on the list. */ | |
150 | ||
7c0d3ed8 | 151 | struct x_display_info * |
971de7fb | 152 | check_x_display_info (Lisp_Object object) |
b9dc4443 | 153 | { |
8ec8a5ec | 154 | struct x_display_info *dpyinfo = NULL; |
177c0ea7 | 155 | |
7e59217d | 156 | if (NILP (object)) |
b9dc4443 | 157 | { |
0fe92f72 | 158 | struct frame *sf = XFRAME (selected_frame); |
177c0ea7 | 159 | |
0fe92f72 | 160 | if (FRAME_X_P (sf) && FRAME_LIVE_P (sf)) |
8ec8a5ec | 161 | dpyinfo = FRAME_X_DISPLAY_INFO (sf); |
b9dc4443 | 162 | else if (x_display_list != 0) |
8ec8a5ec | 163 | dpyinfo = x_display_list; |
b9dc4443 RS |
164 | else |
165 | error ("X windows are not in use or not initialized"); | |
166 | } | |
708e05dc | 167 | else if (TERMINALP (object)) |
b6660415 | 168 | { |
fd0f53a9 | 169 | struct terminal *t = get_terminal (object, 1); |
b6660415 | 170 | |
6ed8eeff | 171 | if (t->type != output_x_window) |
c2982e87 | 172 | error ("Terminal %"pI"d is not an X display", XINT (object)); |
b6660415 | 173 | |
6ed8eeff | 174 | dpyinfo = t->display_info.x; |
b6660415 | 175 | } |
7e59217d KL |
176 | else if (STRINGP (object)) |
177 | dpyinfo = x_display_info_for_name (object); | |
b9dc4443 RS |
178 | else |
179 | { | |
7452b7bd | 180 | FRAME_PTR f = decode_window_system_frame (object); |
8ec8a5ec | 181 | dpyinfo = FRAME_X_DISPLAY_INFO (f); |
b9dc4443 | 182 | } |
8ec8a5ec GM |
183 | |
184 | return dpyinfo; | |
b9dc4443 | 185 | } |
333b20bb | 186 | |
b9dc4443 | 187 | \f |
f676886a JB |
188 | /* Return the Emacs frame-object corresponding to an X window. |
189 | It could be the frame's main window or an icon window. */ | |
01f1ba30 | 190 | |
34ca5317 | 191 | /* This function can be called during GC, so use GC_xxx type test macros. */ |
bcb2db92 | 192 | |
f676886a | 193 | struct frame * |
971de7fb | 194 | x_window_to_frame (struct x_display_info *dpyinfo, int wdesc) |
01f1ba30 | 195 | { |
f676886a JB |
196 | Lisp_Object tail, frame; |
197 | struct frame *f; | |
01f1ba30 | 198 | |
5b04e9f9 DA |
199 | if (wdesc == None) |
200 | return NULL; | |
10b43ac3 | 201 | |
5b04e9f9 | 202 | FOR_EACH_FRAME (tail, frame) |
01f1ba30 | 203 | { |
f676886a | 204 | f = XFRAME (frame); |
2d764c78 | 205 | if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) |
2d271e2e | 206 | continue; |
0af913d7 | 207 | if (f->output_data.x->hourglass_window == wdesc) |
17cbbf95 | 208 | return f; |
9ef48a9d | 209 | #ifdef USE_X_TOOLKIT |
177c0ea7 | 210 | if ((f->output_data.x->edit_widget |
7556890b | 211 | && XtWindow (f->output_data.x->edit_widget) == wdesc) |
333b20bb GM |
212 | /* A tooltip frame? */ |
213 | || (!f->output_data.x->edit_widget | |
214 | && FRAME_X_WINDOW (f) == wdesc) | |
7556890b | 215 | || f->output_data.x->icon_desc == wdesc) |
9ef48a9d RS |
216 | return f; |
217 | #else /* not USE_X_TOOLKIT */ | |
488dd4c4 JD |
218 | #ifdef USE_GTK |
219 | if (f->output_data.x->edit_widget) | |
220 | { | |
6b61353c | 221 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 JD |
222 | struct x_output *x = f->output_data.x; |
223 | if (gwdesc != 0 && gwdesc == x->edit_widget) | |
224 | return f; | |
225 | } | |
226 | #endif /* USE_GTK */ | |
fe24a618 | 227 | if (FRAME_X_WINDOW (f) == wdesc |
7556890b | 228 | || f->output_data.x->icon_desc == wdesc) |
f676886a | 229 | return f; |
9ef48a9d RS |
230 | #endif /* not USE_X_TOOLKIT */ |
231 | } | |
232 | return 0; | |
233 | } | |
234 | ||
488dd4c4 | 235 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
9ef48a9d RS |
236 | /* Like x_window_to_frame but also compares the window with the widget's |
237 | windows. */ | |
238 | ||
239 | struct frame * | |
971de7fb | 240 | x_any_window_to_frame (struct x_display_info *dpyinfo, int wdesc) |
9ef48a9d RS |
241 | { |
242 | Lisp_Object tail, frame; | |
5b04e9f9 | 243 | struct frame *f, *found = NULL; |
7556890b | 244 | struct x_output *x; |
9ef48a9d | 245 | |
5b04e9f9 DA |
246 | if (wdesc == None) |
247 | return NULL; | |
10b43ac3 | 248 | |
5b04e9f9 | 249 | FOR_EACH_FRAME (tail, frame) |
9ef48a9d | 250 | { |
5b04e9f9 DA |
251 | if (found) |
252 | break; | |
9ef48a9d | 253 | f = XFRAME (frame); |
17cbbf95 | 254 | if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo) |
333b20bb | 255 | { |
17cbbf95 GM |
256 | /* This frame matches if the window is any of its widgets. */ |
257 | x = f->output_data.x; | |
0af913d7 | 258 | if (x->hourglass_window == wdesc) |
17cbbf95 GM |
259 | found = f; |
260 | else if (x->widget) | |
261 | { | |
488dd4c4 | 262 | #ifdef USE_GTK |
6b61353c | 263 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 | 264 | if (gwdesc != 0 |
a54fa5b7 | 265 | && gtk_widget_get_toplevel (gwdesc) == x->widget) |
488dd4c4 JD |
266 | found = f; |
267 | #else | |
177c0ea7 JB |
268 | if (wdesc == XtWindow (x->widget) |
269 | || wdesc == XtWindow (x->column_widget) | |
17cbbf95 GM |
270 | || wdesc == XtWindow (x->edit_widget)) |
271 | found = f; | |
272 | /* Match if the window is this frame's menubar. */ | |
273 | else if (lw_window_is_in_menubar (wdesc, x->menubar_widget)) | |
274 | found = f; | |
488dd4c4 | 275 | #endif |
17cbbf95 GM |
276 | } |
277 | else if (FRAME_X_WINDOW (f) == wdesc) | |
278 | /* A tooltip frame. */ | |
279 | found = f; | |
333b20bb | 280 | } |
01f1ba30 | 281 | } |
177c0ea7 | 282 | |
17cbbf95 | 283 | return found; |
01f1ba30 | 284 | } |
5e65b9ab | 285 | |
fd3a3022 RS |
286 | /* Likewise, but consider only the menu bar widget. */ |
287 | ||
288 | struct frame * | |
fea9cabd | 289 | x_menubar_window_to_frame (struct x_display_info *dpyinfo, XEvent *event) |
fd3a3022 | 290 | { |
b78f9767 | 291 | Window wdesc = event->xany.window; |
fd3a3022 RS |
292 | Lisp_Object tail, frame; |
293 | struct frame *f; | |
7556890b | 294 | struct x_output *x; |
fd3a3022 | 295 | |
5b04e9f9 DA |
296 | if (wdesc == None) |
297 | return NULL; | |
10b43ac3 | 298 | |
5b04e9f9 | 299 | FOR_EACH_FRAME (tail, frame) |
fd3a3022 | 300 | { |
fd3a3022 | 301 | f = XFRAME (frame); |
2d764c78 | 302 | if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) |
fd3a3022 | 303 | continue; |
7556890b | 304 | x = f->output_data.x; |
488dd4c4 | 305 | #ifdef USE_GTK |
b78f9767 J |
306 | if (x->menubar_widget && xg_event_is_for_menubar (f, event)) |
307 | return f; | |
488dd4c4 | 308 | #else |
b78f9767 | 309 | /* Match if the window is this frame's menubar. */ |
333b20bb GM |
310 | if (x->menubar_widget |
311 | && lw_window_is_in_menubar (wdesc, x->menubar_widget)) | |
fd3a3022 | 312 | return f; |
488dd4c4 | 313 | #endif |
fd3a3022 RS |
314 | } |
315 | return 0; | |
316 | } | |
317 | ||
5e65b9ab RS |
318 | /* Return the frame whose principal (outermost) window is WDESC. |
319 | If WDESC is some other (smaller) window, we return 0. */ | |
320 | ||
321 | struct frame * | |
971de7fb | 322 | x_top_window_to_frame (struct x_display_info *dpyinfo, int wdesc) |
5e65b9ab RS |
323 | { |
324 | Lisp_Object tail, frame; | |
325 | struct frame *f; | |
7556890b | 326 | struct x_output *x; |
5e65b9ab | 327 | |
5b04e9f9 DA |
328 | if (wdesc == None) |
329 | return NULL; | |
10b43ac3 | 330 | |
5b04e9f9 | 331 | FOR_EACH_FRAME (tail, frame) |
5e65b9ab | 332 | { |
5e65b9ab | 333 | f = XFRAME (frame); |
2d764c78 | 334 | if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) |
2d271e2e | 335 | continue; |
7556890b | 336 | x = f->output_data.x; |
333b20bb GM |
337 | |
338 | if (x->widget) | |
339 | { | |
340 | /* This frame matches if the window is its topmost widget. */ | |
488dd4c4 | 341 | #ifdef USE_GTK |
6b61353c | 342 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 JD |
343 | if (gwdesc == x->widget) |
344 | return f; | |
345 | #else | |
333b20bb GM |
346 | if (wdesc == XtWindow (x->widget)) |
347 | return f; | |
7a994728 KH |
348 | #if 0 /* I don't know why it did this, |
349 | but it seems logically wrong, | |
350 | and it causes trouble for MapNotify events. */ | |
333b20bb | 351 | /* Match if the window is this frame's menubar. */ |
177c0ea7 | 352 | if (x->menubar_widget |
333b20bb GM |
353 | && wdesc == XtWindow (x->menubar_widget)) |
354 | return f; | |
488dd4c4 | 355 | #endif |
7a994728 | 356 | #endif |
333b20bb GM |
357 | } |
358 | else if (FRAME_X_WINDOW (f) == wdesc) | |
359 | /* Tooltip frame. */ | |
360 | return f; | |
5e65b9ab RS |
361 | } |
362 | return 0; | |
363 | } | |
488dd4c4 | 364 | #endif /* USE_X_TOOLKIT || USE_GTK */ |
01f1ba30 | 365 | |
01f1ba30 | 366 | \f |
203c1d73 | 367 | |
08a90d6a | 368 | /* Store the screen positions of frame F into XPTR and YPTR. |
e9445337 RS |
369 | These are the positions of the containing window manager window, |
370 | not Emacs's own window. */ | |
371 | ||
372 | void | |
971de7fb | 373 | x_real_positions (FRAME_PTR f, int *xptr, int *yptr) |
e9445337 | 374 | { |
8ffc96f5 | 375 | int win_x, win_y, outer_x IF_LINT (= 0), outer_y IF_LINT (= 0); |
49d41073 EZ |
376 | int real_x = 0, real_y = 0; |
377 | int had_errors = 0; | |
378 | Window win = f->output_data.x->parent_desc; | |
d75c9992 JD |
379 | Atom actual_type; |
380 | unsigned long actual_size, bytes_remaining; | |
06b0c8a0 | 381 | int rc, actual_format; |
d75c9992 JD |
382 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
383 | long max_len = 400; | |
384 | Display *dpy = FRAME_X_DISPLAY (f); | |
385 | unsigned char *tmp_data = NULL; | |
386 | Atom target_type = XA_CARDINAL; | |
e9445337 | 387 | |
4d7e6e51 | 388 | block_input (); |
49d41073 | 389 | |
d75c9992 | 390 | x_catch_errors (dpy); |
043835a3 | 391 | |
31887d45 | 392 | if (win == dpyinfo->root_window) |
49d41073 EZ |
393 | win = FRAME_OUTER_WINDOW (f); |
394 | ||
395 | /* This loop traverses up the containment tree until we hit the root | |
396 | window. Window managers may intersect many windows between our window | |
397 | and the root window. The window we find just before the root window | |
398 | should be the outer WM window. */ | |
399 | for (;;) | |
e9445337 | 400 | { |
49d41073 EZ |
401 | Window wm_window, rootw; |
402 | Window *tmp_children; | |
403 | unsigned int tmp_nchildren; | |
e7161ad9 | 404 | int success; |
ca7bac79 | 405 | |
e7161ad9 RS |
406 | success = XQueryTree (FRAME_X_DISPLAY (f), win, &rootw, |
407 | &wm_window, &tmp_children, &tmp_nchildren); | |
08a90d6a | 408 | |
49d41073 | 409 | had_errors = x_had_errors_p (FRAME_X_DISPLAY (f)); |
08a90d6a | 410 | |
e7161ad9 RS |
411 | /* Don't free tmp_children if XQueryTree failed. */ |
412 | if (! success) | |
413 | break; | |
414 | ||
98c6f1e3 | 415 | XFree (tmp_children); |
e7161ad9 | 416 | |
49d41073 EZ |
417 | if (wm_window == rootw || had_errors) |
418 | break; | |
08a90d6a | 419 | |
49d41073 EZ |
420 | win = wm_window; |
421 | } | |
177c0ea7 | 422 | |
49d41073 EZ |
423 | if (! had_errors) |
424 | { | |
47c53789 | 425 | unsigned int ign; |
49d41073 | 426 | Window child, rootw; |
177c0ea7 | 427 | |
49d41073 EZ |
428 | /* Get the real coordinates for the WM window upper left corner */ |
429 | XGetGeometry (FRAME_X_DISPLAY (f), win, | |
430 | &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign); | |
431 | ||
432 | /* Translate real coordinates to coordinates relative to our | |
433 | window. For our window, the upper left corner is 0, 0. | |
434 | Since the upper left corner of the WM window is outside | |
435 | our window, win_x and win_y will be negative: | |
436 | ||
437 | ------------------ ---> x | |
438 | | title | | |
439 | | ----------------- v y | |
440 | | | our window | |
441 | */ | |
8a07bba0 | 442 | XTranslateCoordinates (FRAME_X_DISPLAY (f), |
e9445337 | 443 | |
8a07bba0 | 444 | /* From-window, to-window. */ |
8a07bba0 | 445 | FRAME_X_DISPLAY_INFO (f)->root_window, |
49d41073 | 446 | FRAME_X_WINDOW (f), |
e9445337 | 447 | |
8a07bba0 | 448 | /* From-position, to-position. */ |
49d41073 | 449 | real_x, real_y, &win_x, &win_y, |
08a90d6a | 450 | |
8a07bba0 RS |
451 | /* Child of win. */ |
452 | &child); | |
e9445337 | 453 | |
49d41073 | 454 | if (FRAME_X_WINDOW (f) == FRAME_OUTER_WINDOW (f)) |
845e9d85 | 455 | { |
49d41073 EZ |
456 | outer_x = win_x; |
457 | outer_y = win_y; | |
845e9d85 | 458 | } |
49d41073 EZ |
459 | else |
460 | { | |
461 | XTranslateCoordinates (FRAME_X_DISPLAY (f), | |
ca7bac79 | 462 | |
49d41073 EZ |
463 | /* From-window, to-window. */ |
464 | FRAME_X_DISPLAY_INFO (f)->root_window, | |
465 | FRAME_OUTER_WINDOW (f), | |
177c0ea7 | 466 | |
49d41073 EZ |
467 | /* From-position, to-position. */ |
468 | real_x, real_y, &outer_x, &outer_y, | |
177c0ea7 | 469 | |
49d41073 EZ |
470 | /* Child of win. */ |
471 | &child); | |
be786000 | 472 | } |
08a90d6a | 473 | |
49d41073 EZ |
474 | had_errors = x_had_errors_p (FRAME_X_DISPLAY (f)); |
475 | } | |
177c0ea7 | 476 | |
31887d45 JD |
477 | |
478 | if (dpyinfo->root_window == f->output_data.x->parent_desc) | |
479 | { | |
480 | /* Try _NET_FRAME_EXTENTS if our parent is the root window. */ | |
481 | rc = XGetWindowProperty (dpy, win, dpyinfo->Xatom_net_frame_extents, | |
482 | 0, max_len, False, target_type, | |
483 | &actual_type, &actual_format, &actual_size, | |
484 | &bytes_remaining, &tmp_data); | |
485 | ||
486 | if (rc == Success && actual_type == target_type && !x_had_errors_p (dpy) | |
487 | && actual_size == 4 && actual_format == 32) | |
488 | { | |
717c30e0 | 489 | unsigned int ign; |
31887d45 | 490 | Window rootw; |
c0098065 | 491 | long *fe = (long *)tmp_data; |
31887d45 JD |
492 | |
493 | XGetGeometry (FRAME_X_DISPLAY (f), win, | |
494 | &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign); | |
31887d45 JD |
495 | outer_x = -fe[0]; |
496 | outer_y = -fe[2]; | |
497 | real_x -= fe[0]; | |
498 | real_y -= fe[2]; | |
499 | } | |
500 | } | |
501 | ||
502 | if (tmp_data) XFree (tmp_data); | |
503 | ||
4545fa20 | 504 | x_uncatch_errors (); |
177c0ea7 | 505 | |
4d7e6e51 | 506 | unblock_input (); |
49d41073 EZ |
507 | |
508 | if (had_errors) return; | |
177c0ea7 | 509 | |
be786000 KS |
510 | f->x_pixels_diff = -win_x; |
511 | f->y_pixels_diff = -win_y; | |
512 | ||
513 | FRAME_X_OUTPUT (f)->x_pixels_outer_diff = -outer_x; | |
514 | FRAME_X_OUTPUT (f)->y_pixels_outer_diff = -outer_y; | |
49d41073 EZ |
515 | |
516 | *xptr = real_x; | |
517 | *yptr = real_y; | |
e9445337 RS |
518 | } |
519 | ||
01f1ba30 | 520 | \f |
82978295 | 521 | |
d62c8769 GM |
522 | |
523 | /* Gamma-correct COLOR on frame F. */ | |
524 | ||
525 | void | |
971de7fb | 526 | gamma_correct (struct frame *f, XColor *color) |
d62c8769 GM |
527 | { |
528 | if (f->gamma) | |
529 | { | |
530 | color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5; | |
531 | color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5; | |
532 | color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5; | |
533 | } | |
534 | } | |
535 | ||
536 | ||
7b746c38 | 537 | /* Decide if color named COLOR_NAME is valid for use on frame F. If |
578098f3 PE |
538 | so, return the RGB values in COLOR. If ALLOC_P, |
539 | allocate the color. Value is false if COLOR_NAME is invalid, or | |
7b746c38 | 540 | no color could be allocated. */ |
e12d55b2 | 541 | |
578098f3 | 542 | bool |
eec47d6b | 543 | x_defined_color (struct frame *f, const char *color_name, |
578098f3 | 544 | XColor *color, bool alloc_p) |
01f1ba30 | 545 | { |
578098f3 | 546 | bool success_p = 0; |
7b746c38 GM |
547 | Display *dpy = FRAME_X_DISPLAY (f); |
548 | Colormap cmap = FRAME_X_COLORMAP (f); | |
01f1ba30 | 549 | |
4d7e6e51 | 550 | block_input (); |
3a46642b J |
551 | #ifdef USE_GTK |
552 | success_p = xg_check_special_colors (f, color_name, color); | |
553 | #endif | |
554 | if (!success_p) | |
578098f3 | 555 | success_p = XParseColor (dpy, cmap, color_name, color) != 0; |
7b746c38 GM |
556 | if (success_p && alloc_p) |
557 | success_p = x_alloc_nearest_color (f, cmap, color); | |
4d7e6e51 | 558 | unblock_input (); |
01f1ba30 | 559 | |
7b746c38 | 560 | return success_p; |
01f1ba30 JB |
561 | } |
562 | ||
9b2956e2 GM |
563 | |
564 | /* Return the pixel color value for color COLOR_NAME on frame F. If F | |
565 | is a monochrome frame, return MONO_COLOR regardless of what ARG says. | |
566 | Signal an error if color can't be allocated. */ | |
01f1ba30 | 567 | |
f78faa98 | 568 | static int |
971de7fb | 569 | x_decode_color (FRAME_PTR f, Lisp_Object color_name, int mono_color) |
01f1ba30 | 570 | { |
b9dc4443 | 571 | XColor cdef; |
01f1ba30 | 572 | |
b7826503 | 573 | CHECK_STRING (color_name); |
01f1ba30 | 574 | |
9b2956e2 GM |
575 | #if 0 /* Don't do this. It's wrong when we're not using the default |
576 | colormap, it makes freeing difficult, and it's probably not | |
577 | an important optimization. */ | |
d5db4077 | 578 | if (strcmp (SDATA (color_name), "black") == 0) |
b9dc4443 | 579 | return BLACK_PIX_DEFAULT (f); |
d5db4077 | 580 | else if (strcmp (SDATA (color_name), "white") == 0) |
b9dc4443 | 581 | return WHITE_PIX_DEFAULT (f); |
9b2956e2 | 582 | #endif |
01f1ba30 | 583 | |
9b2956e2 | 584 | /* Return MONO_COLOR for monochrome frames. */ |
b9dc4443 | 585 | if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1) |
9b2956e2 | 586 | return mono_color; |
01f1ba30 | 587 | |
2d764c78 | 588 | /* x_defined_color is responsible for coping with failures |
95626e11 | 589 | by looking for a near-miss. */ |
42a5b22f | 590 | if (x_defined_color (f, SSDATA (color_name), &cdef, 1)) |
95626e11 RS |
591 | return cdef.pixel; |
592 | ||
93217cef | 593 | signal_error ("Undefined color", color_name); |
01f1ba30 | 594 | } |
9b2956e2 GM |
595 | |
596 | ||
01f1ba30 | 597 | \f |
ea0a1f53 GM |
598 | /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is |
599 | the previous value of that parameter, NEW_VALUE is the new value. | |
600 | See also the comment of wait_for_wm in struct x_output. */ | |
601 | ||
602 | static void | |
971de7fb | 603 | x_set_wait_for_wm (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) |
ea0a1f53 GM |
604 | { |
605 | f->output_data.x->wait_for_wm = !NILP (new_value); | |
606 | } | |
607 | ||
bfeabdc3 JD |
608 | static void |
609 | x_set_tool_bar_position (struct frame *f, | |
610 | Lisp_Object new_value, | |
611 | Lisp_Object old_value) | |
612 | { | |
613 | if (! EQ (new_value, Qleft) && ! EQ (new_value, Qright) | |
614 | && ! EQ (new_value, Qbottom) && ! EQ (new_value, Qtop)) | |
615 | return; | |
616 | if (EQ (new_value, old_value)) return; | |
617 | ||
618 | #ifdef USE_GTK | |
18e27ea8 PE |
619 | xg_change_toolbar_position (f, new_value); |
620 | fset_tool_bar_position (f, new_value); | |
bfeabdc3 JD |
621 | #endif |
622 | } | |
623 | ||
993d0721 JB |
624 | #ifdef USE_GTK |
625 | ||
465aa50a JD |
626 | /* Set icon from FILE for frame F. By using GTK functions the icon |
627 | may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */ | |
993d0721 JB |
628 | |
629 | int | |
971de7fb | 630 | xg_set_icon (FRAME_PTR f, Lisp_Object file) |
993d0721 | 631 | { |
465aa50a JD |
632 | int result = 0; |
633 | Lisp_Object found; | |
993d0721 | 634 | |
465aa50a JD |
635 | found = x_find_image_file (file); |
636 | ||
637 | if (! NILP (found)) | |
638 | { | |
639 | GdkPixbuf *pixbuf; | |
640 | GError *err = NULL; | |
51b59d79 | 641 | char *filename = SSDATA (found); |
4d7e6e51 | 642 | block_input (); |
465aa50a JD |
643 | |
644 | pixbuf = gdk_pixbuf_new_from_file (filename, &err); | |
645 | ||
646 | if (pixbuf) | |
647 | { | |
648 | gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
649 | pixbuf); | |
650 | g_object_unref (pixbuf); | |
651 | ||
652 | result = 1; | |
653 | } | |
654 | else | |
655 | g_error_free (err); | |
656 | ||
4d7e6e51 | 657 | unblock_input (); |
465aa50a JD |
658 | } |
659 | ||
465aa50a | 660 | return result; |
993d0721 | 661 | } |
9f7b984b CY |
662 | |
663 | int | |
648801d1 | 664 | xg_set_icon_from_xpm_data (FRAME_PTR f, const char **data) |
9f7b984b | 665 | { |
648801d1 | 666 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (data); |
9f7b984b CY |
667 | |
668 | if (!pixbuf) | |
47c53789 | 669 | return 0; |
9f7b984b | 670 | |
47c53789 | 671 | gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), pixbuf); |
9f7b984b CY |
672 | g_object_unref (pixbuf); |
673 | return 1; | |
674 | } | |
993d0721 JB |
675 | #endif /* USE_GTK */ |
676 | ||
ea0a1f53 | 677 | |
f676886a | 678 | /* Functions called only from `x_set_frame_param' |
01f1ba30 JB |
679 | to set individual parameters. |
680 | ||
fe24a618 | 681 | If FRAME_X_WINDOW (f) is 0, |
f676886a | 682 | the frame is being created and its X-window does not exist yet. |
01f1ba30 JB |
683 | In that case, just record the parameter's new value |
684 | in the standard place; do not attempt to change the window. */ | |
685 | ||
e4cebfca | 686 | static void |
971de7fb | 687 | x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 688 | { |
09393d07 GM |
689 | struct x_output *x = f->output_data.x; |
690 | unsigned long fg, old_fg; | |
a76206dc | 691 | |
09393d07 | 692 | fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
ce593f6e KL |
693 | old_fg = FRAME_FOREGROUND_PIXEL (f); |
694 | FRAME_FOREGROUND_PIXEL (f) = fg; | |
a76206dc | 695 | |
fe24a618 | 696 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 697 | { |
09393d07 | 698 | Display *dpy = FRAME_X_DISPLAY (f); |
177c0ea7 | 699 | |
4d7e6e51 | 700 | block_input (); |
09393d07 GM |
701 | XSetForeground (dpy, x->normal_gc, fg); |
702 | XSetBackground (dpy, x->reverse_gc, fg); | |
36d42089 | 703 | |
09393d07 GM |
704 | if (x->cursor_pixel == old_fg) |
705 | { | |
706 | unload_color (f, x->cursor_pixel); | |
707 | x->cursor_pixel = x_copy_color (f, fg); | |
708 | XSetBackground (dpy, x->cursor_gc, x->cursor_pixel); | |
709 | } | |
177c0ea7 | 710 | |
4d7e6e51 | 711 | unblock_input (); |
177c0ea7 | 712 | |
05c8abbe | 713 | update_face_from_frame_parameter (f, Qforeground_color, arg); |
177c0ea7 | 714 | |
179956b9 | 715 | if (FRAME_VISIBLE_P (f)) |
f676886a | 716 | redraw_frame (f); |
01f1ba30 | 717 | } |
177c0ea7 | 718 | |
09393d07 | 719 | unload_color (f, old_fg); |
01f1ba30 JB |
720 | } |
721 | ||
e4cebfca | 722 | static void |
971de7fb | 723 | x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 724 | { |
09393d07 GM |
725 | struct x_output *x = f->output_data.x; |
726 | unsigned long bg; | |
01f1ba30 | 727 | |
09393d07 | 728 | bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); |
ce593f6e KL |
729 | unload_color (f, FRAME_BACKGROUND_PIXEL (f)); |
730 | FRAME_BACKGROUND_PIXEL (f) = bg; | |
a76206dc | 731 | |
fe24a618 | 732 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 733 | { |
09393d07 | 734 | Display *dpy = FRAME_X_DISPLAY (f); |
177c0ea7 | 735 | |
4d7e6e51 | 736 | block_input (); |
09393d07 GM |
737 | XSetBackground (dpy, x->normal_gc, bg); |
738 | XSetForeground (dpy, x->reverse_gc, bg); | |
739 | XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg); | |
740 | XSetForeground (dpy, x->cursor_gc, bg); | |
741 | ||
488dd4c4 JD |
742 | #ifdef USE_GTK |
743 | xg_set_background_color (f, bg); | |
744 | #endif | |
745 | ||
f76e0368 GM |
746 | #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with |
747 | toolkit scroll bars. */ | |
748 | { | |
749 | Lisp_Object bar; | |
750 | for (bar = FRAME_SCROLL_BARS (f); | |
751 | !NILP (bar); | |
752 | bar = XSCROLL_BAR (bar)->next) | |
753 | { | |
056ce195 | 754 | Window window = XSCROLL_BAR (bar)->x_window; |
f76e0368 GM |
755 | XSetWindowBackground (dpy, window, bg); |
756 | } | |
757 | } | |
758 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
01f1ba30 | 759 | |
4d7e6e51 | 760 | unblock_input (); |
05c8abbe | 761 | update_face_from_frame_parameter (f, Qbackground_color, arg); |
ea96210c | 762 | |
179956b9 | 763 | if (FRAME_VISIBLE_P (f)) |
f676886a | 764 | redraw_frame (f); |
01f1ba30 JB |
765 | } |
766 | } | |
767 | ||
e044e4fc | 768 | static Cursor |
971de7fb | 769 | make_invisible_cursor (struct frame *f) |
e044e4fc JD |
770 | { |
771 | Display *dpy = FRAME_X_DISPLAY (f); | |
772 | static char const no_data[] = { 0 }; | |
773 | Pixmap pix; | |
774 | XColor col; | |
8664db06 | 775 | Cursor c = 0; |
e044e4fc JD |
776 | |
777 | x_catch_errors (dpy); | |
778 | pix = XCreateBitmapFromData (dpy, FRAME_X_DISPLAY_INFO (f)->root_window, | |
779 | no_data, 1, 1); | |
780 | if (! x_had_errors_p (dpy) && pix != None) | |
781 | { | |
8664db06 | 782 | Cursor pixc; |
e044e4fc JD |
783 | col.pixel = 0; |
784 | col.red = col.green = col.blue = 0; | |
785 | col.flags = DoRed | DoGreen | DoBlue; | |
8664db06 PE |
786 | pixc = XCreatePixmapCursor (dpy, pix, pix, &col, &col, 0, 0); |
787 | if (! x_had_errors_p (dpy) && pixc != None) | |
788 | c = pixc; | |
e044e4fc JD |
789 | XFreePixmap (dpy, pix); |
790 | } | |
791 | ||
792 | x_uncatch_errors (); | |
793 | ||
794 | return c; | |
795 | } | |
796 | ||
e4cebfca | 797 | static void |
971de7fb | 798 | x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 799 | { |
09393d07 GM |
800 | struct x_output *x = f->output_data.x; |
801 | Display *dpy = FRAME_X_DISPLAY (f); | |
3d970f28 | 802 | Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; |
0af913d7 | 803 | Cursor hourglass_cursor, horizontal_drag_cursor; |
51a1d2d8 | 804 | unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
ce593f6e | 805 | unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f); |
a76206dc | 806 | |
51a1d2d8 | 807 | /* Don't let pointers be invisible. */ |
09393d07 | 808 | if (mask_color == pixel) |
bcf26b38 GM |
809 | { |
810 | x_free_colors (f, &pixel, 1); | |
ce593f6e | 811 | pixel = x_copy_color (f, FRAME_FOREGROUND_PIXEL (f)); |
bcf26b38 | 812 | } |
a76206dc | 813 | |
09393d07 GM |
814 | unload_color (f, x->mouse_pixel); |
815 | x->mouse_pixel = pixel; | |
01f1ba30 | 816 | |
4d7e6e51 | 817 | block_input (); |
fe24a618 | 818 | |
eb8c3be9 | 819 | /* It's not okay to crash if the user selects a screwy cursor. */ |
9ba8e10d | 820 | x_catch_errors (dpy); |
fe24a618 | 821 | |
09393d07 | 822 | if (!NILP (Vx_pointer_shape)) |
01f1ba30 | 823 | { |
b7826503 | 824 | CHECK_NUMBER (Vx_pointer_shape); |
09393d07 | 825 | cursor = XCreateFontCursor (dpy, XINT (Vx_pointer_shape)); |
01f1ba30 JB |
826 | } |
827 | else | |
09393d07 GM |
828 | cursor = XCreateFontCursor (dpy, XC_xterm); |
829 | x_check_errors (dpy, "bad text pointer cursor: %s"); | |
01f1ba30 | 830 | |
09393d07 | 831 | if (!NILP (Vx_nontext_pointer_shape)) |
01f1ba30 | 832 | { |
b7826503 | 833 | CHECK_NUMBER (Vx_nontext_pointer_shape); |
09393d07 GM |
834 | nontext_cursor |
835 | = XCreateFontCursor (dpy, XINT (Vx_nontext_pointer_shape)); | |
01f1ba30 JB |
836 | } |
837 | else | |
09393d07 GM |
838 | nontext_cursor = XCreateFontCursor (dpy, XC_left_ptr); |
839 | x_check_errors (dpy, "bad nontext pointer cursor: %s"); | |
01f1ba30 | 840 | |
09393d07 | 841 | if (!NILP (Vx_hourglass_pointer_shape)) |
333b20bb | 842 | { |
b7826503 | 843 | CHECK_NUMBER (Vx_hourglass_pointer_shape); |
09393d07 GM |
844 | hourglass_cursor |
845 | = XCreateFontCursor (dpy, XINT (Vx_hourglass_pointer_shape)); | |
333b20bb GM |
846 | } |
847 | else | |
09393d07 GM |
848 | hourglass_cursor = XCreateFontCursor (dpy, XC_watch); |
849 | x_check_errors (dpy, "bad hourglass pointer cursor: %s"); | |
177c0ea7 | 850 | |
09393d07 | 851 | if (!NILP (Vx_mode_pointer_shape)) |
01f1ba30 | 852 | { |
b7826503 | 853 | CHECK_NUMBER (Vx_mode_pointer_shape); |
09393d07 | 854 | mode_cursor = XCreateFontCursor (dpy, XINT (Vx_mode_pointer_shape)); |
01f1ba30 JB |
855 | } |
856 | else | |
09393d07 GM |
857 | mode_cursor = XCreateFontCursor (dpy, XC_xterm); |
858 | x_check_errors (dpy, "bad modeline pointer cursor: %s"); | |
95f80c78 | 859 | |
09393d07 | 860 | if (!NILP (Vx_sensitive_text_pointer_shape)) |
95f80c78 | 861 | { |
b7826503 | 862 | CHECK_NUMBER (Vx_sensitive_text_pointer_shape); |
3d970f28 | 863 | hand_cursor |
09393d07 | 864 | = XCreateFontCursor (dpy, XINT (Vx_sensitive_text_pointer_shape)); |
95f80c78 FP |
865 | } |
866 | else | |
3d970f28 | 867 | hand_cursor = XCreateFontCursor (dpy, XC_hand2); |
01f1ba30 | 868 | |
8fb4ec9c GM |
869 | if (!NILP (Vx_window_horizontal_drag_shape)) |
870 | { | |
b7826503 | 871 | CHECK_NUMBER (Vx_window_horizontal_drag_shape); |
8fb4ec9c | 872 | horizontal_drag_cursor |
09393d07 | 873 | = XCreateFontCursor (dpy, XINT (Vx_window_horizontal_drag_shape)); |
8fb4ec9c GM |
874 | } |
875 | else | |
876 | horizontal_drag_cursor | |
09393d07 | 877 | = XCreateFontCursor (dpy, XC_sb_h_double_arrow); |
8fb4ec9c | 878 | |
fe24a618 | 879 | /* Check and report errors with the above calls. */ |
09393d07 | 880 | x_check_errors (dpy, "can't set cursor shape: %s"); |
4545fa20 | 881 | x_uncatch_errors (); |
fe24a618 | 882 | |
01f1ba30 JB |
883 | { |
884 | XColor fore_color, back_color; | |
885 | ||
09393d07 | 886 | fore_color.pixel = x->mouse_pixel; |
a31fedb7 | 887 | x_query_color (f, &fore_color); |
01f1ba30 | 888 | back_color.pixel = mask_color; |
a31fedb7 | 889 | x_query_color (f, &back_color); |
177c0ea7 | 890 | |
09393d07 GM |
891 | XRecolorCursor (dpy, cursor, &fore_color, &back_color); |
892 | XRecolorCursor (dpy, nontext_cursor, &fore_color, &back_color); | |
893 | XRecolorCursor (dpy, mode_cursor, &fore_color, &back_color); | |
3d970f28 | 894 | XRecolorCursor (dpy, hand_cursor, &fore_color, &back_color); |
09393d07 GM |
895 | XRecolorCursor (dpy, hourglass_cursor, &fore_color, &back_color); |
896 | XRecolorCursor (dpy, horizontal_drag_cursor, &fore_color, &back_color); | |
01f1ba30 | 897 | } |
01f1ba30 | 898 | |
fe24a618 | 899 | if (FRAME_X_WINDOW (f) != 0) |
e044e4fc JD |
900 | XDefineCursor (dpy, FRAME_X_WINDOW (f), |
901 | f->output_data.x->current_cursor = cursor); | |
09393d07 | 902 | |
e044e4fc JD |
903 | if (FRAME_X_DISPLAY_INFO (f)->invisible_cursor == 0) |
904 | FRAME_X_DISPLAY_INFO (f)->invisible_cursor = make_invisible_cursor (f); | |
f5f6c0e0 | 905 | |
09393d07 GM |
906 | if (cursor != x->text_cursor |
907 | && x->text_cursor != 0) | |
908 | XFreeCursor (dpy, x->text_cursor); | |
909 | x->text_cursor = cursor; | |
910 | ||
911 | if (nontext_cursor != x->nontext_cursor | |
912 | && x->nontext_cursor != 0) | |
913 | XFreeCursor (dpy, x->nontext_cursor); | |
914 | x->nontext_cursor = nontext_cursor; | |
915 | ||
916 | if (hourglass_cursor != x->hourglass_cursor | |
917 | && x->hourglass_cursor != 0) | |
918 | XFreeCursor (dpy, x->hourglass_cursor); | |
919 | x->hourglass_cursor = hourglass_cursor; | |
920 | ||
921 | if (mode_cursor != x->modeline_cursor | |
922 | && x->modeline_cursor != 0) | |
923 | XFreeCursor (dpy, f->output_data.x->modeline_cursor); | |
924 | x->modeline_cursor = mode_cursor; | |
177c0ea7 | 925 | |
3d970f28 KS |
926 | if (hand_cursor != x->hand_cursor |
927 | && x->hand_cursor != 0) | |
928 | XFreeCursor (dpy, x->hand_cursor); | |
929 | x->hand_cursor = hand_cursor; | |
01f1ba30 | 930 | |
09393d07 GM |
931 | if (horizontal_drag_cursor != x->horizontal_drag_cursor |
932 | && x->horizontal_drag_cursor != 0) | |
933 | XFreeCursor (dpy, x->horizontal_drag_cursor); | |
934 | x->horizontal_drag_cursor = horizontal_drag_cursor; | |
8fb4ec9c | 935 | |
09393d07 | 936 | XFlush (dpy); |
4d7e6e51 | 937 | unblock_input (); |
05c8abbe GM |
938 | |
939 | update_face_from_frame_parameter (f, Qmouse_color, arg); | |
01f1ba30 JB |
940 | } |
941 | ||
e4cebfca | 942 | static void |
971de7fb | 943 | x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 944 | { |
a76206dc | 945 | unsigned long fore_pixel, pixel; |
10168ebb | 946 | int fore_pixel_allocated_p = 0, pixel_allocated_p = 0; |
09393d07 | 947 | struct x_output *x = f->output_data.x; |
01f1ba30 | 948 | |
10168ebb GM |
949 | if (!NILP (Vx_cursor_fore_pixel)) |
950 | { | |
951 | fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel, | |
952 | WHITE_PIX_DEFAULT (f)); | |
953 | fore_pixel_allocated_p = 1; | |
954 | } | |
01f1ba30 | 955 | else |
ce593f6e | 956 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
177c0ea7 | 957 | |
a76206dc | 958 | pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
10168ebb | 959 | pixel_allocated_p = 1; |
a76206dc | 960 | |
f9942c9e | 961 | /* Make sure that the cursor color differs from the background color. */ |
ce593f6e | 962 | if (pixel == FRAME_BACKGROUND_PIXEL (f)) |
01f1ba30 | 963 | { |
10168ebb GM |
964 | if (pixel_allocated_p) |
965 | { | |
966 | x_free_colors (f, &pixel, 1); | |
967 | pixel_allocated_p = 0; | |
968 | } | |
177c0ea7 | 969 | |
09393d07 | 970 | pixel = x->mouse_pixel; |
a76206dc | 971 | if (pixel == fore_pixel) |
10168ebb GM |
972 | { |
973 | if (fore_pixel_allocated_p) | |
974 | { | |
975 | x_free_colors (f, &fore_pixel, 1); | |
976 | fore_pixel_allocated_p = 0; | |
977 | } | |
ce593f6e | 978 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
10168ebb | 979 | } |
01f1ba30 | 980 | } |
a76206dc | 981 | |
09393d07 | 982 | unload_color (f, x->cursor_foreground_pixel); |
10168ebb GM |
983 | if (!fore_pixel_allocated_p) |
984 | fore_pixel = x_copy_color (f, fore_pixel); | |
09393d07 | 985 | x->cursor_foreground_pixel = fore_pixel; |
01f1ba30 | 986 | |
09393d07 | 987 | unload_color (f, x->cursor_pixel); |
10168ebb GM |
988 | if (!pixel_allocated_p) |
989 | pixel = x_copy_color (f, pixel); | |
09393d07 | 990 | x->cursor_pixel = pixel; |
a76206dc | 991 | |
fe24a618 | 992 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 993 | { |
4d7e6e51 | 994 | block_input (); |
09393d07 GM |
995 | XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel); |
996 | XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel); | |
4d7e6e51 | 997 | unblock_input (); |
01f1ba30 | 998 | |
179956b9 | 999 | if (FRAME_VISIBLE_P (f)) |
01f1ba30 | 1000 | { |
cedadcfa RS |
1001 | x_update_cursor (f, 0); |
1002 | x_update_cursor (f, 1); | |
01f1ba30 JB |
1003 | } |
1004 | } | |
05c8abbe GM |
1005 | |
1006 | update_face_from_frame_parameter (f, Qcursor_color, arg); | |
01f1ba30 | 1007 | } |
943b580d | 1008 | \f |
f676886a | 1009 | /* Set the border-color of frame F to pixel value PIX. |
01f1ba30 | 1010 | Note that this does not fully take effect if done before |
f676886a | 1011 | F has an x-window. */ |
01f1ba30 | 1012 | |
e4cebfca | 1013 | static void |
971de7fb | 1014 | x_set_border_pixel (struct frame *f, int pix) |
01f1ba30 | 1015 | { |
a76206dc | 1016 | unload_color (f, f->output_data.x->border_pixel); |
7556890b | 1017 | f->output_data.x->border_pixel = pix; |
01f1ba30 | 1018 | |
be786000 | 1019 | if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0) |
01f1ba30 | 1020 | { |
4d7e6e51 | 1021 | block_input (); |
578c21e6 | 1022 | XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), pix); |
4d7e6e51 | 1023 | unblock_input (); |
01f1ba30 | 1024 | |
179956b9 | 1025 | if (FRAME_VISIBLE_P (f)) |
f676886a | 1026 | redraw_frame (f); |
01f1ba30 JB |
1027 | } |
1028 | } | |
1029 | ||
7c0d3ed8 KS |
1030 | /* Set the border-color of frame F to value described by ARG. |
1031 | ARG can be a string naming a color. | |
1032 | The border-color is used for the border that is drawn by the X server. | |
1033 | Note that this does not fully take effect if done before | |
1034 | F has an x-window; it must be redone when the window is created. | |
1035 | ||
1036 | Note: this is done in two routines because of the way X10 works. | |
1037 | ||
1038 | Note: under X11, this is normally the province of the window manager, | |
1039 | and so emacs' border colors may be overridden. */ | |
1040 | ||
e4cebfca | 1041 | static void |
971de7fb | 1042 | x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
7c0d3ed8 KS |
1043 | { |
1044 | int pix; | |
1045 | ||
1046 | CHECK_STRING (arg); | |
1047 | pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); | |
1048 | x_set_border_pixel (f, pix); | |
1049 | update_face_from_frame_parameter (f, Qborder_color, arg); | |
1050 | } | |
0d1469d6 | 1051 | |
0d1469d6 | 1052 | |
e4cebfca | 1053 | static void |
971de7fb | 1054 | x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
0d1469d6 | 1055 | { |
33b2311e | 1056 | set_frame_cursor_types (f, arg); |
dbc4e1c1 | 1057 | |
75691005 RS |
1058 | /* Make sure the cursor gets redrawn. */ |
1059 | cursor_type_changed = 1; | |
dbc4e1c1 | 1060 | } |
943b580d | 1061 | \f |
e4cebfca | 1062 | static void |
971de7fb | 1063 | x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 1064 | { |
01f1ba30 JB |
1065 | int result; |
1066 | ||
203c1d73 RS |
1067 | if (STRINGP (arg)) |
1068 | { | |
1069 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
1070 | return; | |
1071 | } | |
1072 | else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) | |
01f1ba30 JB |
1073 | return; |
1074 | ||
4d7e6e51 | 1075 | block_input (); |
265a9e55 | 1076 | if (NILP (arg)) |
80534dd6 | 1077 | result = x_text_icon (f, |
e69b0960 DA |
1078 | SSDATA ((!NILP (f->icon_name) |
1079 | ? f->icon_name | |
1080 | : f->name))); | |
f1c7b5a6 RS |
1081 | else |
1082 | result = x_bitmap_icon (f, arg); | |
01f1ba30 JB |
1083 | |
1084 | if (result) | |
1085 | { | |
4d7e6e51 | 1086 | unblock_input (); |
0fb53770 | 1087 | error ("No icon window available"); |
01f1ba30 JB |
1088 | } |
1089 | ||
b9dc4443 | 1090 | XFlush (FRAME_X_DISPLAY (f)); |
4d7e6e51 | 1091 | unblock_input (); |
01f1ba30 JB |
1092 | } |
1093 | ||
e4cebfca | 1094 | static void |
971de7fb | 1095 | x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
80534dd6 | 1096 | { |
80534dd6 KH |
1097 | int result; |
1098 | ||
1099 | if (STRINGP (arg)) | |
1100 | { | |
1101 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
1102 | return; | |
1103 | } | |
56f41f98 | 1104 | else if (!NILP (arg) || NILP (oldval)) |
80534dd6 KH |
1105 | return; |
1106 | ||
f00af5b1 | 1107 | fset_icon_name (f, arg); |
80534dd6 | 1108 | |
7556890b | 1109 | if (f->output_data.x->icon_bitmap != 0) |
80534dd6 KH |
1110 | return; |
1111 | ||
4d7e6e51 | 1112 | block_input (); |
80534dd6 KH |
1113 | |
1114 | result = x_text_icon (f, | |
e69b0960 DA |
1115 | SSDATA ((!NILP (f->icon_name) |
1116 | ? f->icon_name | |
1117 | : !NILP (f->title) | |
1118 | ? f->title | |
1119 | : f->name))); | |
80534dd6 KH |
1120 | |
1121 | if (result) | |
1122 | { | |
4d7e6e51 | 1123 | unblock_input (); |
80534dd6 KH |
1124 | error ("No icon window available"); |
1125 | } | |
1126 | ||
80534dd6 | 1127 | XFlush (FRAME_X_DISPLAY (f)); |
4d7e6e51 | 1128 | unblock_input (); |
80534dd6 | 1129 | } |
7c0d3ed8 | 1130 | |
943b580d | 1131 | \f |
01f1ba30 | 1132 | void |
971de7fb | 1133 | x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
01f1ba30 | 1134 | { |
7c0d3ed8 | 1135 | int nlines; |
6b61353c | 1136 | #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) |
7c0d3ed8 KS |
1137 | int olines = FRAME_MENU_BAR_LINES (f); |
1138 | #endif | |
177c0ea7 | 1139 | |
7c0d3ed8 KS |
1140 | /* Right now, menu bars don't work properly in minibuf-only frames; |
1141 | most of the commands try to apply themselves to the minibuffer | |
1142 | frame itself, and get an error because you can't switch buffers | |
1143 | in or split the minibuffer window. */ | |
1144 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1145 | return; | |
177c0ea7 | 1146 | |
d311d28c | 1147 | if (TYPE_RANGED_INTEGERP (int, value)) |
7c0d3ed8 | 1148 | nlines = XINT (value); |
ea96210c | 1149 | else |
7c0d3ed8 | 1150 | nlines = 0; |
a367641f | 1151 | |
7c0d3ed8 KS |
1152 | /* Make sure we redisplay all windows in this frame. */ |
1153 | windows_or_buffers_changed++; | |
3d09b6be | 1154 | |
488dd4c4 | 1155 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
9ef48a9d RS |
1156 | FRAME_MENU_BAR_LINES (f) = 0; |
1157 | if (nlines) | |
0d8ef3f4 RS |
1158 | { |
1159 | FRAME_EXTERNAL_MENU_BAR (f) = 1; | |
97a1ff91 | 1160 | if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0) |
0d8ef3f4 | 1161 | /* Make sure next redisplay shows the menu bar. */ |
c98ff5dd | 1162 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = 1; |
0d8ef3f4 | 1163 | } |
9ef48a9d RS |
1164 | else |
1165 | { | |
6bc20398 FP |
1166 | if (FRAME_EXTERNAL_MENU_BAR (f) == 1) |
1167 | free_frame_menubar (f); | |
9ef48a9d | 1168 | FRAME_EXTERNAL_MENU_BAR (f) = 0; |
97a1ff91 RS |
1169 | if (FRAME_X_P (f)) |
1170 | f->output_data.x->menubar_widget = 0; | |
9ef48a9d | 1171 | } |
488dd4c4 | 1172 | #else /* not USE_X_TOOLKIT && not USE_GTK */ |
d043f1a4 | 1173 | FRAME_MENU_BAR_LINES (f) = nlines; |
562dd5e9 | 1174 | resize_frame_windows (f, FRAME_LINES (f), 0); |
1df47e38 YM |
1175 | |
1176 | /* If the menu bar height gets changed, the internal border below | |
1177 | the top margin has to be cleared. Also, if the menu bar gets | |
1178 | larger, the area for the added lines has to be cleared except for | |
1179 | the first menu bar line that is to be drawn later. */ | |
1180 | if (nlines != olines) | |
1181 | { | |
1182 | int height = FRAME_INTERNAL_BORDER_WIDTH (f); | |
1183 | int width = FRAME_PIXEL_WIDTH (f); | |
1184 | int y; | |
1185 | ||
1186 | /* height can be zero here. */ | |
1187 | if (height > 0 && width > 0) | |
1188 | { | |
1189 | y = FRAME_TOP_MARGIN_HEIGHT (f); | |
1190 | ||
4d7e6e51 | 1191 | block_input (); |
1df47e38 YM |
1192 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1193 | 0, y, width, height, False); | |
4d7e6e51 | 1194 | unblock_input (); |
1df47e38 YM |
1195 | } |
1196 | ||
1197 | if (nlines > 1 && nlines > olines) | |
1198 | { | |
1199 | y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f); | |
1200 | height = nlines * FRAME_LINE_HEIGHT (f) - y; | |
1201 | ||
4d7e6e51 | 1202 | block_input (); |
1df47e38 YM |
1203 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1204 | 0, y, width, height, False); | |
4d7e6e51 | 1205 | unblock_input (); |
1df47e38 YM |
1206 | } |
1207 | ||
e69b0960 DA |
1208 | if (nlines == 0 && WINDOWP (f->menu_bar_window)) |
1209 | clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix); | |
1df47e38 YM |
1210 | } |
1211 | #endif /* not USE_X_TOOLKIT && not USE_GTK */ | |
333b20bb | 1212 | adjust_glyphs (f); |
562dd5e9 | 1213 | run_window_configuration_change_hook (f); |
333b20bb GM |
1214 | } |
1215 | ||
1216 | ||
1217 | /* Set the number of lines used for the tool bar of frame F to VALUE. | |
1218 | VALUE not an integer, or < 0 means set the lines to zero. OLDVAL | |
1219 | is the old number of tool bar lines. This function changes the | |
1220 | height of all windows on frame F to match the new tool bar height. | |
1221 | The frame's height doesn't change. */ | |
1222 | ||
1223 | void | |
971de7fb | 1224 | x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
333b20bb | 1225 | { |
52de7ce9 GM |
1226 | int delta, nlines, root_height; |
1227 | Lisp_Object root_window; | |
333b20bb | 1228 | |
e870b7ba GM |
1229 | /* Treat tool bars like menu bars. */ |
1230 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1231 | return; | |
1232 | ||
d311d28c PE |
1233 | /* Use VALUE only if an int >= 0. */ |
1234 | if (RANGED_INTEGERP (0, value, INT_MAX)) | |
333b20bb GM |
1235 | nlines = XFASTINT (value); |
1236 | else | |
1237 | nlines = 0; | |
1238 | ||
488dd4c4 JD |
1239 | #ifdef USE_GTK |
1240 | FRAME_TOOL_BAR_LINES (f) = 0; | |
1241 | if (nlines) | |
1242 | { | |
1243 | FRAME_EXTERNAL_TOOL_BAR (f) = 1; | |
1244 | if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0) | |
1245 | /* Make sure next redisplay shows the tool bar. */ | |
5fceba1d | 1246 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = 1; |
488dd4c4 JD |
1247 | update_frame_tool_bar (f); |
1248 | } | |
1249 | else | |
1250 | { | |
1251 | if (FRAME_EXTERNAL_TOOL_BAR (f)) | |
1252 | free_frame_tool_bar (f); | |
1253 | FRAME_EXTERNAL_TOOL_BAR (f) = 0; | |
1254 | } | |
1255 | ||
1256 | return; | |
1257 | #endif | |
177c0ea7 | 1258 | |
488dd4c4 | 1259 | /* Make sure we redisplay all windows in this frame. */ |
333b20bb GM |
1260 | ++windows_or_buffers_changed; |
1261 | ||
9ea173e8 | 1262 | delta = nlines - FRAME_TOOL_BAR_LINES (f); |
52de7ce9 GM |
1263 | |
1264 | /* Don't resize the tool-bar to more than we have room for. */ | |
1265 | root_window = FRAME_ROOT_WINDOW (f); | |
be786000 | 1266 | root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window)); |
52de7ce9 GM |
1267 | if (root_height - delta < 1) |
1268 | { | |
1269 | delta = root_height - 1; | |
1270 | nlines = FRAME_TOOL_BAR_LINES (f) + delta; | |
1271 | } | |
1272 | ||
9ea173e8 | 1273 | FRAME_TOOL_BAR_LINES (f) = nlines; |
562dd5e9 | 1274 | resize_frame_windows (f, FRAME_LINES (f), 0); |
333b20bb | 1275 | adjust_glyphs (f); |
177c0ea7 | 1276 | |
ccba751c GM |
1277 | /* We also have to make sure that the internal border at the top of |
1278 | the frame, below the menu bar or tool bar, is redrawn when the | |
1279 | tool bar disappears. This is so because the internal border is | |
1280 | below the tool bar if one is displayed, but is below the menu bar | |
1281 | if there isn't a tool bar. The tool bar draws into the area | |
1282 | below the menu bar. */ | |
1283 | if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) | |
1284 | { | |
385ed61f | 1285 | clear_frame (f); |
fb3cd89b | 1286 | clear_current_matrices (f); |
ccba751c | 1287 | } |
b6f91066 GM |
1288 | |
1289 | /* If the tool bar gets smaller, the internal border below it | |
1290 | has to be cleared. It was formerly part of the display | |
1291 | of the larger tool bar, and updating windows won't clear it. */ | |
1292 | if (delta < 0) | |
1293 | { | |
1294 | int height = FRAME_INTERNAL_BORDER_WIDTH (f); | |
be786000 | 1295 | int width = FRAME_PIXEL_WIDTH (f); |
4b00d3b1 | 1296 | int y = (FRAME_MENU_BAR_LINES (f) + nlines) * FRAME_LINE_HEIGHT (f); |
b6f91066 | 1297 | |
caacfeb8 JD |
1298 | /* height can be zero here. */ |
1299 | if (height > 0 && width > 0) | |
1300 | { | |
4d7e6e51 | 1301 | block_input (); |
caacfeb8 JD |
1302 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1303 | 0, y, width, height, False); | |
4d7e6e51 | 1304 | unblock_input (); |
caacfeb8 | 1305 | } |
ddc24747 | 1306 | |
e69b0960 DA |
1307 | if (WINDOWP (f->tool_bar_window)) |
1308 | clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); | |
b6f91066 | 1309 | } |
562dd5e9 MR |
1310 | |
1311 | run_window_configuration_change_hook (f); | |
1312 | ||
333b20bb GM |
1313 | } |
1314 | ||
1315 | ||
1316 | /* Set the foreground color for scroll bars on frame F to VALUE. | |
1317 | VALUE should be a string, a color name. If it isn't a string or | |
1318 | isn't a valid color name, do nothing. OLDVAL is the old value of | |
1319 | the frame parameter. */ | |
1320 | ||
e4cebfca | 1321 | static void |
971de7fb | 1322 | x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
333b20bb GM |
1323 | { |
1324 | unsigned long pixel; | |
177c0ea7 | 1325 | |
333b20bb GM |
1326 | if (STRINGP (value)) |
1327 | pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f)); | |
1328 | else | |
1329 | pixel = -1; | |
1330 | ||
1331 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
1332 | unload_color (f, f->output_data.x->scroll_bar_foreground_pixel); | |
177c0ea7 | 1333 | |
333b20bb GM |
1334 | f->output_data.x->scroll_bar_foreground_pixel = pixel; |
1335 | if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) | |
1336 | { | |
1337 | /* Remove all scroll bars because they have wrong colors. */ | |
6ed8eeff KL |
1338 | if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook) |
1339 | (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f); | |
1340 | if (FRAME_TERMINAL (f)->judge_scroll_bars_hook) | |
1341 | (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f); | |
05c8abbe GM |
1342 | |
1343 | update_face_from_frame_parameter (f, Qscroll_bar_foreground, value); | |
333b20bb GM |
1344 | redraw_frame (f); |
1345 | } | |
1346 | } | |
1347 | ||
1348 | ||
1349 | /* Set the background color for scroll bars on frame F to VALUE VALUE | |
1350 | should be a string, a color name. If it isn't a string or isn't a | |
1351 | valid color name, do nothing. OLDVAL is the old value of the frame | |
1352 | parameter. */ | |
1353 | ||
e4cebfca | 1354 | static void |
971de7fb | 1355 | x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
333b20bb GM |
1356 | { |
1357 | unsigned long pixel; | |
1358 | ||
1359 | if (STRINGP (value)) | |
1360 | pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f)); | |
1361 | else | |
1362 | pixel = -1; | |
177c0ea7 | 1363 | |
333b20bb GM |
1364 | if (f->output_data.x->scroll_bar_background_pixel != -1) |
1365 | unload_color (f, f->output_data.x->scroll_bar_background_pixel); | |
177c0ea7 | 1366 | |
f15340b7 MB |
1367 | #ifdef USE_TOOLKIT_SCROLL_BARS |
1368 | /* Scrollbar shadow colors. */ | |
1369 | if (f->output_data.x->scroll_bar_top_shadow_pixel != -1) | |
1370 | { | |
1371 | unload_color (f, f->output_data.x->scroll_bar_top_shadow_pixel); | |
1372 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
1373 | } | |
1374 | if (f->output_data.x->scroll_bar_bottom_shadow_pixel != -1) | |
1375 | { | |
1376 | unload_color (f, f->output_data.x->scroll_bar_bottom_shadow_pixel); | |
1377 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
1378 | } | |
1379 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
1380 | ||
333b20bb GM |
1381 | f->output_data.x->scroll_bar_background_pixel = pixel; |
1382 | if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) | |
1383 | { | |
1384 | /* Remove all scroll bars because they have wrong colors. */ | |
6ed8eeff KL |
1385 | if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook) |
1386 | (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f); | |
1387 | if (FRAME_TERMINAL (f)->judge_scroll_bars_hook) | |
1388 | (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f); | |
177c0ea7 | 1389 | |
05c8abbe | 1390 | update_face_from_frame_parameter (f, Qscroll_bar_background, value); |
333b20bb GM |
1391 | redraw_frame (f); |
1392 | } | |
d043f1a4 | 1393 | } |
333b20bb | 1394 | |
943b580d | 1395 | \f |
3a258507 | 1396 | /* Encode Lisp string STRING as a text in a format appropriate for |
96db09e4 KH |
1397 | XICCC (X Inter Client Communication Conventions). |
1398 | ||
6f103132 RS |
1399 | This can call Lisp code, so callers must GCPRO. |
1400 | ||
96db09e4 KH |
1401 | If STRING contains only ASCII characters, do no conversion and |
1402 | return the string data of STRING. Otherwise, encode the text by | |
1403 | CODING_SYSTEM, and return a newly allocated memory area which | |
1404 | should be freed by `xfree' by a caller. | |
1405 | ||
37323f34 EZ |
1406 | SELECTIONP non-zero means the string is being encoded for an X |
1407 | selection, so it is safe to run pre-write conversions (which | |
1408 | may run Lisp code). | |
1409 | ||
96db09e4 KH |
1410 | Store the byte length of resulting text in *TEXT_BYTES. |
1411 | ||
d60660d6 | 1412 | If the text contains only ASCII and Latin-1, store 1 in *STRING_P, |
96db09e4 | 1413 | which means that the `encoding' of the result can be `STRING'. |
d60660d6 | 1414 | Otherwise store 0 in *STRINGP, which means that the `encoding' of |
96db09e4 KH |
1415 | the result should be `COMPOUND_TEXT'. */ |
1416 | ||
df630496 | 1417 | static unsigned char * |
c678c835 PE |
1418 | x_encode_text (Lisp_Object string, Lisp_Object coding_system, int selectionp, |
1419 | ptrdiff_t *text_bytes, int *stringp, int *freep) | |
96db09e4 | 1420 | { |
0f8c4c4f | 1421 | int result = string_xstring_p (string); |
96db09e4 KH |
1422 | struct coding_system coding; |
1423 | ||
0f8c4c4f | 1424 | if (result == 0) |
96db09e4 KH |
1425 | { |
1426 | /* No multibyte character in OBJ. We need not encode it. */ | |
8f924df7 | 1427 | *text_bytes = SBYTES (string); |
d60660d6 | 1428 | *stringp = 1; |
df630496 | 1429 | *freep = 0; |
8f924df7 | 1430 | return SDATA (string); |
96db09e4 KH |
1431 | } |
1432 | ||
1433 | setup_coding_system (coding_system, &coding); | |
0f8c4c4f | 1434 | coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK); |
35bc5887 | 1435 | /* We suppress producing escape sequences for composition. */ |
0f8c4c4f | 1436 | coding.common_flags &= ~CODING_ANNOTATION_MASK; |
0065d054 | 1437 | coding.destination = xnmalloc (SCHARS (string), 2); |
8f924df7 | 1438 | coding.dst_bytes = SCHARS (string) * 2; |
0f8c4c4f | 1439 | encode_coding_object (&coding, string, 0, 0, |
8f924df7 | 1440 | SCHARS (string), SBYTES (string), Qnil); |
96db09e4 | 1441 | *text_bytes = coding.produced; |
0f8c4c4f | 1442 | *stringp = (result == 1 || !EQ (coding_system, Qcompound_text)); |
df630496 | 1443 | *freep = 1; |
b954d586 | 1444 | return coding.destination; |
96db09e4 KH |
1445 | } |
1446 | ||
1447 | \f | |
b10daec7 JD |
1448 | /* Set the WM name to NAME for frame F. Also set the icon name. |
1449 | If the frame already has an icon name, use that, otherwise set the | |
1450 | icon name to NAME. */ | |
f945b920 | 1451 | |
b10daec7 | 1452 | static void |
971de7fb | 1453 | x_set_name_internal (FRAME_PTR f, Lisp_Object name) |
f945b920 | 1454 | { |
fe24a618 | 1455 | if (FRAME_X_WINDOW (f)) |
01f1ba30 | 1456 | { |
4d7e6e51 | 1457 | block_input (); |
fe24a618 | 1458 | { |
80534dd6 | 1459 | XTextProperty text, icon; |
c678c835 PE |
1460 | ptrdiff_t bytes; |
1461 | int stringp; | |
b10daec7 | 1462 | int do_free_icon_value = 0, do_free_text_value = 0; |
11270583 | 1463 | Lisp_Object coding_system; |
c2915ced | 1464 | Lisp_Object encoded_name; |
00be444c | 1465 | Lisp_Object encoded_icon_name; |
c2915ced CY |
1466 | struct gcpro gcpro1; |
1467 | ||
1468 | /* As ENCODE_UTF_8 may cause GC and relocation of string data, | |
1469 | we use it before x_encode_text that may return string data. */ | |
1470 | GCPRO1 (name); | |
1471 | encoded_name = ENCODE_UTF_8 (name); | |
1472 | UNGCPRO; | |
80534dd6 | 1473 | |
b10daec7 | 1474 | coding_system = Qcompound_text; |
3201ea57 KH |
1475 | /* Note: Encoding strategy |
1476 | ||
1477 | We encode NAME by compound-text and use "COMPOUND-TEXT" in | |
1478 | text.encoding. But, there are non-internationalized window | |
1479 | managers which don't support that encoding. So, if NAME | |
1480 | contains only ASCII and 8859-1 characters, encode it by | |
1481 | iso-latin-1, and use "STRING" in text.encoding hoping that | |
34e8c597 | 1482 | such window managers at least analyze this format correctly, |
3201ea57 KH |
1483 | i.e. treat 8-bit bytes as 8859-1 characters. |
1484 | ||
1485 | We may also be able to use "UTF8_STRING" in text.encoding | |
34e8c597 | 1486 | in the future which can encode all Unicode characters. |
3201ea57 | 1487 | But, for the moment, there's no way to know that the |
00be444c J |
1488 | current window manager supports it or not. |
1489 | ||
1490 | Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME | |
1491 | properties. Per the EWMH specification, those two properties | |
1492 | are always UTF8_STRING. This matches what gtk_window_set_title() | |
1493 | does in the USE_GTK case. */ | |
df630496 KS |
1494 | text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp, |
1495 | &do_free_text_value); | |
d60660d6 | 1496 | text.encoding = (stringp ? XA_STRING |
96db09e4 | 1497 | : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); |
fe24a618 | 1498 | text.format = 8; |
96db09e4 | 1499 | text.nitems = bytes; |
c678c835 PE |
1500 | if (text.nitems != bytes) |
1501 | error ("Window name too large"); | |
80534dd6 | 1502 | |
e69b0960 | 1503 | if (!STRINGP (f->icon_name)) |
96db09e4 KH |
1504 | { |
1505 | icon = text; | |
00be444c | 1506 | encoded_icon_name = encoded_name; |
96db09e4 KH |
1507 | } |
1508 | else | |
1509 | { | |
3201ea57 | 1510 | /* See the above comment "Note: Encoding strategy". */ |
e69b0960 | 1511 | icon.value = x_encode_text (f->icon_name, coding_system, 0, |
df630496 | 1512 | &bytes, &stringp, &do_free_icon_value); |
d60660d6 | 1513 | icon.encoding = (stringp ? XA_STRING |
96db09e4 KH |
1514 | : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); |
1515 | icon.format = 8; | |
1516 | icon.nitems = bytes; | |
c678c835 PE |
1517 | if (icon.nitems != bytes) |
1518 | error ("Icon name too large"); | |
00be444c | 1519 | |
e69b0960 | 1520 | encoded_icon_name = ENCODE_UTF_8 (f->icon_name); |
96db09e4 | 1521 | } |
b10daec7 | 1522 | |
488dd4c4 JD |
1523 | #ifdef USE_GTK |
1524 | gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
51b59d79 | 1525 | SSDATA (encoded_name)); |
488dd4c4 | 1526 | #else /* not USE_GTK */ |
2436a4e4 | 1527 | XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); |
00be444c J |
1528 | XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), |
1529 | FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_name, | |
1530 | FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING, | |
1531 | 8, PropModeReplace, | |
42a5b22f | 1532 | SDATA (encoded_name), |
00be444c | 1533 | SBYTES (encoded_name)); |
7c0d3ed8 | 1534 | #endif /* not USE_GTK */ |
abb4b7ec | 1535 | |
7c0d3ed8 | 1536 | XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon); |
00be444c J |
1537 | XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), |
1538 | FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_icon_name, | |
1539 | FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING, | |
1540 | 8, PropModeReplace, | |
42a5b22f | 1541 | SDATA (encoded_icon_name), |
00be444c | 1542 | SBYTES (encoded_icon_name)); |
abb4b7ec | 1543 | |
b10daec7 | 1544 | if (do_free_icon_value) |
7c0d3ed8 | 1545 | xfree (icon.value); |
b10daec7 | 1546 | if (do_free_text_value) |
7c0d3ed8 KS |
1547 | xfree (text.value); |
1548 | } | |
4d7e6e51 | 1549 | unblock_input (); |
7c0d3ed8 | 1550 | } |
abb4b7ec RS |
1551 | } |
1552 | ||
b10daec7 JD |
1553 | /* Change the name of frame F to NAME. If NAME is nil, set F's name to |
1554 | x_id_name. | |
1555 | ||
1556 | If EXPLICIT is non-zero, that indicates that lisp code is setting the | |
1557 | name; if NAME is a string, set F's name to NAME and set | |
1558 | F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
1559 | ||
1560 | If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
1561 | suggesting a new name, which lisp code should override; if | |
1562 | F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
1563 | ||
f78faa98 | 1564 | static void |
971de7fb | 1565 | x_set_name (struct frame *f, Lisp_Object name, int explicit) |
b10daec7 JD |
1566 | { |
1567 | /* Make sure that requests from lisp code override requests from | |
1568 | Emacs redisplay code. */ | |
1569 | if (explicit) | |
1570 | { | |
1571 | /* If we're switching from explicit to implicit, we had better | |
1572 | update the mode lines and thereby update the title. */ | |
1573 | if (f->explicit_name && NILP (name)) | |
1574 | update_mode_lines = 1; | |
1575 | ||
1576 | f->explicit_name = ! NILP (name); | |
1577 | } | |
1578 | else if (f->explicit_name) | |
1579 | return; | |
1580 | ||
1581 | /* If NAME is nil, set the name to the x_id_name. */ | |
1582 | if (NILP (name)) | |
1583 | { | |
1584 | /* Check for no change needed in this very common case | |
1585 | before we do any consing. */ | |
1586 | if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name, | |
e69b0960 | 1587 | SSDATA (f->name))) |
b10daec7 JD |
1588 | return; |
1589 | name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name); | |
1590 | } | |
1591 | else | |
1592 | CHECK_STRING (name); | |
1593 | ||
1594 | /* Don't change the name if it's already NAME. */ | |
e69b0960 | 1595 | if (! NILP (Fstring_equal (name, f->name))) |
b10daec7 JD |
1596 | return; |
1597 | ||
f00af5b1 | 1598 | fset_name (f, name); |
b10daec7 JD |
1599 | |
1600 | /* For setting the frame title, the title parameter should override | |
1601 | the name parameter. */ | |
e69b0960 DA |
1602 | if (! NILP (f->title)) |
1603 | name = f->title; | |
b10daec7 JD |
1604 | |
1605 | x_set_name_internal (f, name); | |
1606 | } | |
1607 | ||
7c0d3ed8 KS |
1608 | /* This function should be called when the user's lisp code has |
1609 | specified a name for the frame; the name will override any set by the | |
1610 | redisplay code. */ | |
e4cebfca | 1611 | static void |
971de7fb | 1612 | x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
3402e1a4 | 1613 | { |
7c0d3ed8 | 1614 | x_set_name (f, arg, 1); |
3402e1a4 RS |
1615 | } |
1616 | ||
7c0d3ed8 KS |
1617 | /* This function should be called by Emacs redisplay code to set the |
1618 | name; names set this way will never override names set by the user's | |
1619 | lisp code. */ | |
1620 | void | |
971de7fb | 1621 | x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
333b20bb | 1622 | { |
7c0d3ed8 KS |
1623 | x_set_name (f, arg, 0); |
1624 | } | |
1625 | \f | |
1626 | /* Change the title of frame F to NAME. | |
40aa4c27 | 1627 | If NAME is nil, use the frame name as the title. */ |
01f1ba30 | 1628 | |
e4cebfca | 1629 | static void |
971de7fb | 1630 | x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name) |
01f1ba30 | 1631 | { |
7c0d3ed8 | 1632 | /* Don't change the title if it's already NAME. */ |
e69b0960 | 1633 | if (EQ (name, f->title)) |
7c0d3ed8 | 1634 | return; |
01f1ba30 | 1635 | |
7c0d3ed8 | 1636 | update_mode_lines = 1; |
60fb3ee1 | 1637 | |
f00af5b1 | 1638 | fset_title (f, name); |
f9942c9e | 1639 | |
7c0d3ed8 | 1640 | if (NILP (name)) |
e69b0960 | 1641 | name = f->name; |
7c0d3ed8 KS |
1642 | else |
1643 | CHECK_STRING (name); | |
f9942c9e | 1644 | |
b10daec7 | 1645 | x_set_name_internal (f, name); |
01f1ba30 JB |
1646 | } |
1647 | ||
7c0d3ed8 | 1648 | void |
971de7fb | 1649 | x_set_scroll_bar_default_width (struct frame *f) |
e4f79258 | 1650 | { |
be786000 | 1651 | int wid = FRAME_COLUMN_WIDTH (f); |
7c0d3ed8 | 1652 | #ifdef USE_TOOLKIT_SCROLL_BARS |
a059fe24 | 1653 | #ifdef USE_GTK |
c195f2de | 1654 | int minw = xg_get_default_scrollbar_width (); |
4a1b9832 PE |
1655 | #else |
1656 | int minw = 16; | |
a059fe24 | 1657 | #endif |
7c0d3ed8 | 1658 | /* A minimum width of 14 doesn't look good for toolkit scroll bars. */ |
4a1b9832 | 1659 | int width = minw + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM; |
be786000 KS |
1660 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (width + wid - 1) / wid; |
1661 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = width; | |
7c0d3ed8 KS |
1662 | #else |
1663 | /* Make the actual width at least 14 pixels and a multiple of a | |
1664 | character width. */ | |
be786000 | 1665 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid; |
01f1ba30 | 1666 | |
7c0d3ed8 KS |
1667 | /* Use all of that space (aside from required margins) for the |
1668 | scroll bar. */ | |
be786000 | 1669 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 0; |
7c0d3ed8 | 1670 | #endif |
01f1ba30 | 1671 | } |
333b20bb | 1672 | |
7c0d3ed8 | 1673 | \f |
333b20bb GM |
1674 | /* Record in frame F the specified or default value according to ALIST |
1675 | of the parameter named PROP (a Lisp symbol). If no value is | |
1676 | specified for PROP, look for an X default for XPROP on the frame | |
1677 | named NAME. If that is not found either, use the value DEFLT. */ | |
1678 | ||
1679 | static Lisp_Object | |
d5a3eaaf AS |
1680 | x_default_scroll_bar_color_parameter (struct frame *f, |
1681 | Lisp_Object alist, Lisp_Object prop, | |
675e2c69 | 1682 | const char *xprop, const char *xclass, |
d5a3eaaf | 1683 | int foreground_p) |
333b20bb GM |
1684 | { |
1685 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
1686 | Lisp_Object tem; | |
1687 | ||
1688 | tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING); | |
1689 | if (EQ (tem, Qunbound)) | |
1690 | { | |
1691 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
1692 | ||
1693 | /* See if an X resource for the scroll bar color has been | |
1694 | specified. */ | |
1695 | tem = display_x_get_resource (dpyinfo, | |
1696 | build_string (foreground_p | |
1697 | ? "foreground" | |
1698 | : "background"), | |
6ecd75be | 1699 | empty_unibyte_string, |
333b20bb | 1700 | build_string ("verticalScrollBar"), |
6ecd75be | 1701 | empty_unibyte_string); |
333b20bb GM |
1702 | if (!STRINGP (tem)) |
1703 | { | |
1704 | /* If nothing has been specified, scroll bars will use a | |
1705 | toolkit-dependent default. Because these defaults are | |
1706 | difficult to get at without actually creating a scroll | |
1707 | bar, use nil to indicate that no color has been | |
1708 | specified. */ | |
1709 | tem = Qnil; | |
1710 | } | |
177c0ea7 | 1711 | |
333b20bb | 1712 | #else /* not USE_TOOLKIT_SCROLL_BARS */ |
177c0ea7 | 1713 | |
333b20bb | 1714 | tem = Qnil; |
177c0ea7 | 1715 | |
333b20bb GM |
1716 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
1717 | } | |
1718 | ||
1719 | x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil)); | |
1720 | return tem; | |
1721 | } | |
1722 | ||
1723 | ||
01f1ba30 | 1724 | |
9ef48a9d RS |
1725 | \f |
1726 | #ifdef USE_X_TOOLKIT | |
1727 | ||
8e3d10a9 RS |
1728 | /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS, |
1729 | WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may | |
59aa6c90 RS |
1730 | already be present because of the toolkit (Motif adds some of them, |
1731 | for example, but Xt doesn't). */ | |
9ef48a9d RS |
1732 | |
1733 | static void | |
ebd15611 | 1734 | hack_wm_protocols (FRAME_PTR f, Widget widget) |
9ef48a9d RS |
1735 | { |
1736 | Display *dpy = XtDisplay (widget); | |
1737 | Window w = XtWindow (widget); | |
1738 | int need_delete = 1; | |
1739 | int need_focus = 1; | |
59aa6c90 | 1740 | int need_save = 1; |
9ef48a9d | 1741 | |
4d7e6e51 | 1742 | block_input (); |
9ef48a9d | 1743 | { |
a3db4b26 AS |
1744 | Atom type; |
1745 | unsigned char *catoms; | |
9ef48a9d RS |
1746 | int format = 0; |
1747 | unsigned long nitems = 0; | |
1748 | unsigned long bytes_after; | |
1749 | ||
270958e8 KH |
1750 | if ((XGetWindowProperty (dpy, w, |
1751 | FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, | |
34d5ae1e | 1752 | (long)0, (long)100, False, XA_ATOM, |
270958e8 | 1753 | &type, &format, &nitems, &bytes_after, |
a3db4b26 | 1754 | &catoms) |
270958e8 | 1755 | == Success) |
9ef48a9d | 1756 | && format == 32 && type == XA_ATOM) |
a3db4b26 AS |
1757 | { |
1758 | Atom *atoms = (Atom *) catoms; | |
1759 | while (nitems > 0) | |
1760 | { | |
1761 | nitems--; | |
1762 | if (atoms[nitems] | |
1763 | == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window) | |
1764 | need_delete = 0; | |
1765 | else if (atoms[nitems] | |
1766 | == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus) | |
1767 | need_focus = 0; | |
1768 | else if (atoms[nitems] | |
1769 | == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself) | |
1770 | need_save = 0; | |
1771 | } | |
1772 | } | |
1773 | if (catoms) | |
1774 | XFree (catoms); | |
9ef48a9d RS |
1775 | } |
1776 | { | |
1777 | Atom props [10]; | |
1778 | int count = 0; | |
b9dc4443 RS |
1779 | if (need_delete) |
1780 | props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window; | |
1781 | if (need_focus) | |
1782 | props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus; | |
1783 | if (need_save) | |
1784 | props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself; | |
9ef48a9d | 1785 | if (count) |
b9dc4443 RS |
1786 | XChangeProperty (dpy, w, FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, |
1787 | XA_ATOM, 32, PropModeAppend, | |
9ef48a9d RS |
1788 | (unsigned char *) props, count); |
1789 | } | |
4d7e6e51 | 1790 | unblock_input (); |
9ef48a9d RS |
1791 | } |
1792 | #endif | |
86779fac GM |
1793 | |
1794 | ||
5a7df7d7 GM |
1795 | \f |
1796 | /* Support routines for XIC (X Input Context). */ | |
86779fac | 1797 | |
5a7df7d7 GM |
1798 | #ifdef HAVE_X_I18N |
1799 | ||
f57e2426 J |
1800 | static XFontSet xic_create_xfontset (struct frame *); |
1801 | static XIMStyle best_xim_style (XIMStyles *, XIMStyles *); | |
5a7df7d7 GM |
1802 | |
1803 | ||
1576f1ad | 1804 | /* Supported XIM styles, ordered by preference. */ |
5a7df7d7 GM |
1805 | |
1806 | static XIMStyle supported_xim_styles[] = | |
1807 | { | |
1808 | XIMPreeditPosition | XIMStatusArea, | |
1809 | XIMPreeditPosition | XIMStatusNothing, | |
1810 | XIMPreeditPosition | XIMStatusNone, | |
1811 | XIMPreeditNothing | XIMStatusArea, | |
1812 | XIMPreeditNothing | XIMStatusNothing, | |
1813 | XIMPreeditNothing | XIMStatusNone, | |
1814 | XIMPreeditNone | XIMStatusArea, | |
1815 | XIMPreeditNone | XIMStatusNothing, | |
1816 | XIMPreeditNone | XIMStatusNone, | |
1817 | 0, | |
1818 | }; | |
1819 | ||
1820 | ||
e4cebfca | 1821 | #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT |
c27ed90a | 1822 | /* Create an X fontset on frame F with base font name BASE_FONTNAME. */ |
5a7df7d7 | 1823 | |
333f9019 | 1824 | static const char xic_default_fontset[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*"; |
bb07fa29 | 1825 | |
c28e7ae8 SM |
1826 | /* Create an Xt fontset spec from the name of a base font. |
1827 | If `motif' is True use the Motif syntax. */ | |
bb07fa29 | 1828 | char * |
e6cba650 | 1829 | xic_create_fontsetname (const char *base_fontname, int motif) |
bb07fa29 | 1830 | { |
c28e7ae8 SM |
1831 | const char *sep = motif ? ";" : ","; |
1832 | char *fontsetname; | |
1833 | ||
bb07fa29 | 1834 | /* Make a fontset name from the base font name. */ |
333f9019 | 1835 | if (xic_default_fontset == base_fontname) |
38182d90 | 1836 | { |
afa2ffd8 DA |
1837 | /* There is no base font name, use the default. */ |
1838 | fontsetname = xmalloc (strlen (base_fontname) + 2); | |
c28e7ae8 SM |
1839 | strcpy (fontsetname, base_fontname); |
1840 | } | |
bb07fa29 SM |
1841 | else |
1842 | { | |
1843 | /* Make a fontset name from the base font name. | |
1844 | The font set will be made of the following elements: | |
1845 | - the base font. | |
1846 | - the base font where the charset spec is replaced by -*-*. | |
1847 | - the same but with the family also replaced with -*-*-. */ | |
e6cba650 | 1848 | const char *p = base_fontname; |
25ed6cc3 | 1849 | ptrdiff_t i; |
df630496 | 1850 | |
bb07fa29 SM |
1851 | for (i = 0; *p; p++) |
1852 | if (*p == '-') i++; | |
1853 | if (i != 14) | |
afa2ffd8 DA |
1854 | { |
1855 | /* As the font name doesn't conform to XLFD, we can't | |
bb07fa29 SM |
1856 | modify it to generalize it to allcs and allfamilies. |
1857 | Use the specified font plus the default. */ | |
afa2ffd8 DA |
1858 | fontsetname = xmalloc (strlen (base_fontname) |
1859 | + strlen (xic_default_fontset) + 3); | |
bb07fa29 | 1860 | strcpy (fontsetname, base_fontname); |
c28e7ae8 | 1861 | strcat (fontsetname, sep); |
333f9019 | 1862 | strcat (fontsetname, xic_default_fontset); |
bb07fa29 SM |
1863 | } |
1864 | else | |
1865 | { | |
25ed6cc3 | 1866 | ptrdiff_t len; |
e6cba650 | 1867 | const char *p1 = NULL, *p2 = NULL, *p3 = NULL; |
bb07fa29 SM |
1868 | char *font_allcs = NULL; |
1869 | char *font_allfamilies = NULL; | |
968a6679 | 1870 | char *font_all = NULL; |
e6cba650 DN |
1871 | const char *allcs = "*-*-*-*-*-*-*"; |
1872 | const char *allfamilies = "-*-*-"; | |
1873 | const char *all = "*-*-*-*-"; | |
cd987aaa | 1874 | char *base; |
df630496 | 1875 | |
bb07fa29 SM |
1876 | for (i = 0, p = base_fontname; i < 8; p++) |
1877 | { | |
1878 | if (*p == '-') | |
1879 | { | |
1880 | i++; | |
1881 | if (i == 3) | |
1882 | p1 = p + 1; | |
968a6679 SM |
1883 | else if (i == 7) |
1884 | p2 = p + 1; | |
cd987aaa KH |
1885 | else if (i == 6) |
1886 | p3 = p + 1; | |
bb07fa29 SM |
1887 | } |
1888 | } | |
cd987aaa KH |
1889 | /* If base_fontname specifies ADSTYLE, make it a |
1890 | wildcard. */ | |
1891 | if (*p3 != '*') | |
1892 | { | |
25ed6cc3 | 1893 | ptrdiff_t diff = (p2 - p3) - 2; |
cd987aaa KH |
1894 | |
1895 | base = alloca (strlen (base_fontname) + 1); | |
72af86bd | 1896 | memcpy (base, base_fontname, p3 - base_fontname); |
cd987aaa KH |
1897 | base[p3 - base_fontname] = '*'; |
1898 | base[(p3 - base_fontname) + 1] = '-'; | |
1899 | strcpy (base + (p3 - base_fontname) + 2, p2); | |
1900 | p = base + (p - base_fontname) - diff; | |
1901 | p1 = base + (p1 - base_fontname); | |
1902 | p2 = base + (p2 - base_fontname) - diff; | |
1903 | base_fontname = base; | |
1904 | } | |
1905 | ||
bb07fa29 SM |
1906 | /* Build the font spec that matches all charsets. */ |
1907 | len = p - base_fontname + strlen (allcs) + 1; | |
38182d90 | 1908 | font_allcs = alloca (len); |
72af86bd | 1909 | memcpy (font_allcs, base_fontname, p - base_fontname); |
bb07fa29 SM |
1910 | strcat (font_allcs, allcs); |
1911 | ||
cd987aaa KH |
1912 | /* Build the font spec that matches all families and |
1913 | add-styles. */ | |
bb07fa29 | 1914 | len = p - p1 + strlen (allcs) + strlen (allfamilies) + 1; |
38182d90 | 1915 | font_allfamilies = alloca (len); |
bb07fa29 | 1916 | strcpy (font_allfamilies, allfamilies); |
72af86bd | 1917 | memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1); |
bb07fa29 SM |
1918 | strcat (font_allfamilies, allcs); |
1919 | ||
968a6679 SM |
1920 | /* Build the font spec that matches all. */ |
1921 | len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1; | |
38182d90 | 1922 | font_all = alloca (len); |
968a6679 SM |
1923 | strcpy (font_all, allfamilies); |
1924 | strcat (font_all, all); | |
72af86bd | 1925 | memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2); |
968a6679 SM |
1926 | strcat (font_all, allcs); |
1927 | ||
bb07fa29 SM |
1928 | /* Build the actual font set name. */ |
1929 | len = strlen (base_fontname) + strlen (font_allcs) | |
968a6679 | 1930 | + strlen (font_allfamilies) + strlen (font_all) + 5; |
bb07fa29 | 1931 | fontsetname = xmalloc (len); |
bb07fa29 | 1932 | strcpy (fontsetname, base_fontname); |
c28e7ae8 | 1933 | strcat (fontsetname, sep); |
bb07fa29 | 1934 | strcat (fontsetname, font_allcs); |
c28e7ae8 | 1935 | strcat (fontsetname, sep); |
bb07fa29 | 1936 | strcat (fontsetname, font_allfamilies); |
968a6679 SM |
1937 | strcat (fontsetname, sep); |
1938 | strcat (fontsetname, font_all); | |
bb07fa29 | 1939 | } |
bb07fa29 | 1940 | } |
c28e7ae8 SM |
1941 | if (motif) |
1942 | strcat (fontsetname, ":"); | |
1943 | return fontsetname; | |
bb07fa29 | 1944 | } |
e4cebfca | 1945 | #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */ |
bb07fa29 | 1946 | |
2da34f50 KH |
1947 | #ifdef DEBUG_XIC_FONTSET |
1948 | static void | |
1dae0f0a AS |
1949 | print_fontset_result (XFontSet xfs, char *name, char **missing_list, |
1950 | int missing_count) | |
2da34f50 KH |
1951 | { |
1952 | if (xfs) | |
1953 | fprintf (stderr, "XIC Fontset created: %s\n", name); | |
1954 | else | |
1955 | { | |
1956 | fprintf (stderr, "XIC Fontset failed: %s\n", name); | |
1957 | while (missing_count-- > 0) | |
1958 | { | |
1959 | fprintf (stderr, " missing: %s\n", *missing_list); | |
1960 | missing_list++; | |
1961 | } | |
1962 | } | |
1963 | ||
1964 | } | |
1965 | #endif | |
1966 | ||
5a7df7d7 | 1967 | static XFontSet |
971de7fb | 1968 | xic_create_xfontset (struct frame *f) |
86779fac | 1969 | { |
c27ed90a | 1970 | XFontSet xfs = NULL; |
b51238f5 | 1971 | struct font *font = FRAME_FONT (f); |
a32f056c KH |
1972 | int pixel_size = font->pixel_size; |
1973 | Lisp_Object rest, frame; | |
1974 | ||
1975 | /* See if there is another frame already using same fontset. */ | |
1976 | FOR_EACH_FRAME (rest, frame) | |
1977 | { | |
1978 | struct frame *cf = XFRAME (frame); | |
1979 | ||
1980 | if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) | |
1981 | && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f) | |
b51238f5 KH |
1982 | && FRAME_FONT (f) |
1983 | && FRAME_FONT (f)->pixel_size == pixel_size) | |
a32f056c KH |
1984 | { |
1985 | xfs = FRAME_XIC_FONTSET (cf); | |
1986 | break; | |
1987 | } | |
1988 | } | |
1989 | ||
1990 | if (! xfs) | |
1991 | { | |
1992 | char buf[256]; | |
1993 | char **missing_list; | |
1994 | int missing_count; | |
1995 | char *def_string; | |
e6cba650 | 1996 | const char *xlfd_format = "-*-*-medium-r-normal--%d-*-*-*-*-*"; |
a32f056c KH |
1997 | |
1998 | sprintf (buf, xlfd_format, pixel_size); | |
1999 | missing_list = NULL; | |
2000 | xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf, | |
2001 | &missing_list, &missing_count, &def_string); | |
d3483d71 | 2002 | #ifdef DEBUG_XIC_FONTSET |
22a8f595 | 2003 | print_fontset_result (xfs, buf, missing_list, missing_count); |
d3483d71 | 2004 | #endif |
a32f056c KH |
2005 | if (missing_list) |
2006 | XFreeStringList (missing_list); | |
2007 | if (! xfs) | |
2008 | { | |
2009 | /* List of pixel sizes most likely available. Find one that | |
2010 | is closest to pixel_size. */ | |
2011 | int sizes[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0}; | |
2012 | int *smaller, *larger; | |
2013 | ||
2014 | for (smaller = sizes; smaller[1]; smaller++) | |
2015 | if (smaller[1] >= pixel_size) | |
2016 | break; | |
2017 | larger = smaller + 1; | |
2018 | if (*larger == pixel_size) | |
2019 | larger++; | |
2020 | while (*smaller || *larger) | |
2021 | { | |
2022 | int this_size; | |
2023 | ||
2024 | if (! *larger) | |
2025 | this_size = *smaller--; | |
2026 | else if (! *smaller) | |
2027 | this_size = *larger++; | |
2028 | else if (pixel_size - *smaller < *larger - pixel_size) | |
2029 | this_size = *smaller--; | |
2030 | else | |
2031 | this_size = *larger++; | |
2032 | sprintf (buf, xlfd_format, this_size); | |
2033 | missing_list = NULL; | |
2034 | xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf, | |
2035 | &missing_list, &missing_count, &def_string); | |
d3483d71 | 2036 | #ifdef DEBUG_XIC_FONTSET |
22a8f595 | 2037 | print_fontset_result (xfs, buf, missing_list, missing_count); |
d3483d71 | 2038 | #endif |
a32f056c KH |
2039 | if (missing_list) |
2040 | XFreeStringList (missing_list); | |
2041 | if (xfs) | |
2042 | break; | |
2043 | } | |
2044 | } | |
2da34f50 KH |
2045 | if (! xfs) |
2046 | { | |
675e2c69 | 2047 | const char *last_resort = "-*-*-*-r-normal--*-*-*-*-*-*"; |
2da34f50 KH |
2048 | |
2049 | missing_list = NULL; | |
2050 | xfs = XCreateFontSet (FRAME_X_DISPLAY (f), last_resort, | |
2051 | &missing_list, &missing_count, &def_string); | |
2052 | #ifdef DEBUG_XIC_FONTSET | |
2053 | print_fontset_result (xfs, last_resort, missing_list, missing_count); | |
2054 | #endif | |
2055 | if (missing_list) | |
2056 | XFreeStringList (missing_list); | |
2057 | } | |
2058 | ||
a32f056c KH |
2059 | } |
2060 | ||
2061 | return xfs; | |
2062 | } | |
a32f056c | 2063 | |
c27ed90a JD |
2064 | /* Free the X fontset of frame F if it is the last frame using it. */ |
2065 | ||
2066 | void | |
971de7fb | 2067 | xic_free_xfontset (struct frame *f) |
c27ed90a JD |
2068 | { |
2069 | Lisp_Object rest, frame; | |
2070 | int shared_p = 0; | |
2071 | ||
2072 | if (!FRAME_XIC_FONTSET (f)) | |
2073 | return; | |
2074 | ||
2075 | /* See if there is another frame sharing the same fontset. */ | |
2076 | FOR_EACH_FRAME (rest, frame) | |
2077 | { | |
2078 | struct frame *cf = XFRAME (frame); | |
2079 | if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) | |
2080 | && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f) | |
2081 | && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f)) | |
2082 | { | |
2083 | shared_p = 1; | |
2084 | break; | |
2085 | } | |
2086 | } | |
2087 | ||
2088 | if (!shared_p) | |
2089 | /* The fontset is not used anymore. It is safe to free it. */ | |
2090 | XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); | |
2091 | ||
2092 | if (FRAME_XIC_BASE_FONTNAME (f)) | |
2093 | xfree (FRAME_XIC_BASE_FONTNAME (f)); | |
2094 | FRAME_XIC_BASE_FONTNAME (f) = NULL; | |
2095 | FRAME_XIC_FONTSET (f) = NULL; | |
2096 | } | |
2097 | ||
5a7df7d7 GM |
2098 | |
2099 | /* Value is the best input style, given user preferences USER (already | |
2100 | checked to be supported by Emacs), and styles supported by the | |
2101 | input method XIM. */ | |
2102 | ||
2103 | static XIMStyle | |
971de7fb | 2104 | best_xim_style (XIMStyles *user, XIMStyles *xim) |
5a7df7d7 GM |
2105 | { |
2106 | int i, j; | |
2107 | ||
2108 | for (i = 0; i < user->count_styles; ++i) | |
2109 | for (j = 0; j < xim->count_styles; ++j) | |
2110 | if (user->supported_styles[i] == xim->supported_styles[j]) | |
2111 | return user->supported_styles[i]; | |
2112 | ||
2113 | /* Return the default style. */ | |
2114 | return XIMPreeditNothing | XIMStatusNothing; | |
2115 | } | |
2116 | ||
2117 | /* Create XIC for frame F. */ | |
2118 | ||
5df79d3d GM |
2119 | static XIMStyle xic_style; |
2120 | ||
5a7df7d7 | 2121 | void |
971de7fb | 2122 | create_frame_xic (struct frame *f) |
5a7df7d7 | 2123 | { |
5a7df7d7 GM |
2124 | XIM xim; |
2125 | XIC xic = NULL; | |
2126 | XFontSet xfs = NULL; | |
86779fac | 2127 | |
5a7df7d7 GM |
2128 | if (FRAME_XIC (f)) |
2129 | return; | |
177c0ea7 | 2130 | |
bb07fa29 | 2131 | /* Create X fontset. */ |
b51238f5 | 2132 | xfs = xic_create_xfontset (f); |
5a7df7d7 GM |
2133 | xim = FRAME_X_XIM (f); |
2134 | if (xim) | |
2135 | { | |
d9d57cb2 DL |
2136 | XRectangle s_area; |
2137 | XPoint spot; | |
5a7df7d7 GM |
2138 | XVaNestedList preedit_attr; |
2139 | XVaNestedList status_attr; | |
5a7df7d7 | 2140 | |
d9d57cb2 DL |
2141 | s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1; |
2142 | spot.x = 0; spot.y = 1; | |
86779fac | 2143 | |
5a7df7d7 GM |
2144 | /* Determine XIC style. */ |
2145 | if (xic_style == 0) | |
2146 | { | |
2147 | XIMStyles supported_list; | |
2148 | supported_list.count_styles = (sizeof supported_xim_styles | |
2149 | / sizeof supported_xim_styles[0]); | |
2150 | supported_list.supported_styles = supported_xim_styles; | |
2151 | xic_style = best_xim_style (&supported_list, | |
2152 | FRAME_X_XIM_STYLES (f)); | |
2153 | } | |
86779fac | 2154 | |
5a7df7d7 GM |
2155 | preedit_attr = XVaCreateNestedList (0, |
2156 | XNFontSet, xfs, | |
2157 | XNForeground, | |
2158 | FRAME_FOREGROUND_PIXEL (f), | |
2159 | XNBackground, | |
2160 | FRAME_BACKGROUND_PIXEL (f), | |
2161 | (xic_style & XIMPreeditPosition | |
2162 | ? XNSpotLocation | |
2163 | : NULL), | |
2164 | &spot, | |
2165 | NULL); | |
2166 | status_attr = XVaCreateNestedList (0, | |
2167 | XNArea, | |
2168 | &s_area, | |
2169 | XNFontSet, | |
2170 | xfs, | |
2171 | XNForeground, | |
2172 | FRAME_FOREGROUND_PIXEL (f), | |
2173 | XNBackground, | |
2174 | FRAME_BACKGROUND_PIXEL (f), | |
2175 | NULL); | |
2176 | ||
2177 | xic = XCreateIC (xim, | |
2178 | XNInputStyle, xic_style, | |
6b61353c KH |
2179 | XNClientWindow, FRAME_X_WINDOW (f), |
2180 | XNFocusWindow, FRAME_X_WINDOW (f), | |
5a7df7d7 GM |
2181 | XNStatusAttributes, status_attr, |
2182 | XNPreeditAttributes, preedit_attr, | |
2183 | NULL); | |
2184 | XFree (preedit_attr); | |
2185 | XFree (status_attr); | |
2186 | } | |
177c0ea7 | 2187 | |
5a7df7d7 GM |
2188 | FRAME_XIC (f) = xic; |
2189 | FRAME_XIC_STYLE (f) = xic_style; | |
2190 | FRAME_XIC_FONTSET (f) = xfs; | |
86779fac GM |
2191 | } |
2192 | ||
5a7df7d7 GM |
2193 | |
2194 | /* Destroy XIC and free XIC fontset of frame F, if any. */ | |
2195 | ||
2196 | void | |
971de7fb | 2197 | free_frame_xic (struct frame *f) |
5a7df7d7 GM |
2198 | { |
2199 | if (FRAME_XIC (f) == NULL) | |
2200 | return; | |
177c0ea7 | 2201 | |
5a7df7d7 | 2202 | XDestroyIC (FRAME_XIC (f)); |
c27ed90a | 2203 | xic_free_xfontset (f); |
5a7df7d7 GM |
2204 | |
2205 | FRAME_XIC (f) = NULL; | |
5a7df7d7 GM |
2206 | } |
2207 | ||
2208 | ||
2209 | /* Place preedit area for XIC of window W's frame to specified | |
2210 | pixel position X/Y. X and Y are relative to window W. */ | |
2211 | ||
2212 | void | |
971de7fb | 2213 | xic_set_preeditarea (struct window *w, int x, int y) |
5a7df7d7 | 2214 | { |
d3d50620 | 2215 | struct frame *f = XFRAME (w->frame); |
5a7df7d7 GM |
2216 | XVaNestedList attr; |
2217 | XPoint spot; | |
177c0ea7 | 2218 | |
17e6d491 | 2219 | spot.x = WINDOW_TO_FRAME_PIXEL_X (w, x) + WINDOW_LEFT_FRINGE_WIDTH (w); |
5a7df7d7 GM |
2220 | spot.y = WINDOW_TO_FRAME_PIXEL_Y (w, y) + FONT_BASE (FRAME_FONT (f)); |
2221 | attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); | |
2222 | XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL); | |
2223 | XFree (attr); | |
2224 | } | |
2225 | ||
2226 | ||
2227 | /* Place status area for XIC in bottom right corner of frame F.. */ | |
2228 | ||
2229 | void | |
971de7fb | 2230 | xic_set_statusarea (struct frame *f) |
5a7df7d7 GM |
2231 | { |
2232 | XIC xic = FRAME_XIC (f); | |
2233 | XVaNestedList attr; | |
2234 | XRectangle area; | |
2235 | XRectangle *needed; | |
2236 | ||
2237 | /* Negotiate geometry of status area. If input method has existing | |
2238 | status area, use its current size. */ | |
2239 | area.x = area.y = area.width = area.height = 0; | |
2240 | attr = XVaCreateNestedList (0, XNAreaNeeded, &area, NULL); | |
2241 | XSetICValues (xic, XNStatusAttributes, attr, NULL); | |
2242 | XFree (attr); | |
177c0ea7 | 2243 | |
5a7df7d7 GM |
2244 | attr = XVaCreateNestedList (0, XNAreaNeeded, &needed, NULL); |
2245 | XGetICValues (xic, XNStatusAttributes, attr, NULL); | |
2246 | XFree (attr); | |
2247 | ||
2248 | if (needed->width == 0) /* Use XNArea instead of XNAreaNeeded */ | |
2249 | { | |
2250 | attr = XVaCreateNestedList (0, XNArea, &needed, NULL); | |
2251 | XGetICValues (xic, XNStatusAttributes, attr, NULL); | |
2252 | XFree (attr); | |
2253 | } | |
2254 | ||
2255 | area.width = needed->width; | |
2256 | area.height = needed->height; | |
be786000 KS |
2257 | area.x = FRAME_PIXEL_WIDTH (f) - area.width - FRAME_INTERNAL_BORDER_WIDTH (f); |
2258 | area.y = (FRAME_PIXEL_HEIGHT (f) - area.height | |
488dd4c4 | 2259 | - FRAME_MENUBAR_HEIGHT (f) |
bfeabdc3 | 2260 | - FRAME_TOOLBAR_TOP_HEIGHT (f) |
488dd4c4 | 2261 | - FRAME_INTERNAL_BORDER_WIDTH (f)); |
5a7df7d7 GM |
2262 | XFree (needed); |
2263 | ||
2264 | attr = XVaCreateNestedList (0, XNArea, &area, NULL); | |
6b61353c | 2265 | XSetICValues (xic, XNStatusAttributes, attr, NULL); |
5a7df7d7 GM |
2266 | XFree (attr); |
2267 | } | |
2268 | ||
2269 | ||
2270 | /* Set X fontset for XIC of frame F, using base font name | |
2271 | BASE_FONTNAME. Called when a new Emacs fontset is chosen. */ | |
2272 | ||
2273 | void | |
eec47d6b | 2274 | xic_set_xfontset (struct frame *f, const char *base_fontname) |
5a7df7d7 GM |
2275 | { |
2276 | XVaNestedList attr; | |
2277 | XFontSet xfs; | |
2278 | ||
c27ed90a JD |
2279 | xic_free_xfontset (f); |
2280 | ||
b51238f5 | 2281 | xfs = xic_create_xfontset (f); |
5a7df7d7 GM |
2282 | |
2283 | attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL); | |
2284 | if (FRAME_XIC_STYLE (f) & XIMPreeditPosition) | |
2285 | XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL); | |
2286 | if (FRAME_XIC_STYLE (f) & XIMStatusArea) | |
2287 | XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL); | |
2288 | XFree (attr); | |
177c0ea7 | 2289 | |
5a7df7d7 GM |
2290 | FRAME_XIC_FONTSET (f) = xfs; |
2291 | } | |
2292 | ||
2293 | #endif /* HAVE_X_I18N */ | |
2294 | ||
2295 | ||
9ef48a9d | 2296 | \f |
8fc2766b RS |
2297 | #ifdef USE_X_TOOLKIT |
2298 | ||
2299 | /* Create and set up the X widget for frame F. */ | |
f58534a3 | 2300 | |
01f1ba30 | 2301 | static void |
ebd15611 | 2302 | x_window (struct frame *f, long window_prompting, int minibuffer_only) |
01f1ba30 | 2303 | { |
9ef48a9d | 2304 | XClassHint class_hints; |
31ac8d8c FP |
2305 | XSetWindowAttributes attributes; |
2306 | unsigned long attribute_mask; | |
9ef48a9d RS |
2307 | Widget shell_widget; |
2308 | Widget pane_widget; | |
6c32dd68 | 2309 | Widget frame_widget; |
9ef48a9d RS |
2310 | Arg al [25]; |
2311 | int ac; | |
2312 | ||
4d7e6e51 | 2313 | block_input (); |
9ef48a9d | 2314 | |
b7975ee4 KH |
2315 | /* Use the resource name as the top-level widget name |
2316 | for looking up resources. Make a non-Lisp copy | |
2317 | for the window manager, so GC relocation won't bother it. | |
2318 | ||
2319 | Elsewhere we specify the window name for the window manager. */ | |
177c0ea7 | 2320 | |
cca176a0 | 2321 | { |
51b59d79 | 2322 | char *str = SSDATA (Vx_resource_name); |
23f86fce | 2323 | f->namebuf = xmalloc (strlen (str) + 1); |
cca176a0 KH |
2324 | strcpy (f->namebuf, str); |
2325 | } | |
9ef48a9d RS |
2326 | |
2327 | ac = 0; | |
2328 | XtSetArg (al[ac], XtNallowShellResize, 1); ac++; | |
2329 | XtSetArg (al[ac], XtNinput, 1); ac++; | |
97787173 | 2330 | XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++; |
be786000 | 2331 | XtSetArg (al[ac], XtNborderWidth, f->border_width); ac++; |
9b2956e2 GM |
2332 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; |
2333 | XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++; | |
2334 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; | |
cca176a0 | 2335 | shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS, |
7a994728 | 2336 | applicationShellWidgetClass, |
82c90203 | 2337 | FRAME_X_DISPLAY (f), al, ac); |
9ef48a9d | 2338 | |
7556890b | 2339 | f->output_data.x->widget = shell_widget; |
9ef48a9d RS |
2340 | /* maybe_set_screen_title_format (shell_widget); */ |
2341 | ||
6c32dd68 PR |
2342 | pane_widget = lw_create_widget ("main", "pane", widget_id_tick++, |
2343 | (widget_value *) NULL, | |
2344 | shell_widget, False, | |
2345 | (lw_callback) NULL, | |
2346 | (lw_callback) NULL, | |
b6e11efd | 2347 | (lw_callback) NULL, |
6c32dd68 | 2348 | (lw_callback) NULL); |
9ef48a9d | 2349 | |
9b2956e2 GM |
2350 | ac = 0; |
2351 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; | |
2352 | XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++; | |
2353 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; | |
723f5a07 | 2354 | XtSetArg (al[ac], XtNborderWidth, 0); ac++; |
9b2956e2 | 2355 | XtSetValues (pane_widget, al, ac); |
7556890b | 2356 | f->output_data.x->column_widget = pane_widget; |
a7f7d550 | 2357 | |
177c0ea7 | 2358 | /* mappedWhenManaged to false tells to the paned window to not map/unmap |
5e65b9ab | 2359 | the emacs screen when changing menubar. This reduces flickering. */ |
9ef48a9d RS |
2360 | |
2361 | ac = 0; | |
2362 | XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++; | |
2363 | XtSetArg (al[ac], XtNshowGrip, 0); ac++; | |
2364 | XtSetArg (al[ac], XtNallowResize, 1); ac++; | |
2365 | XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++; | |
2366 | XtSetArg (al[ac], XtNemacsFrame, f); ac++; | |
9b2956e2 GM |
2367 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; |
2368 | XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++; | |
2369 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; | |
723f5a07 | 2370 | XtSetArg (al[ac], XtNborderWidth, 0); ac++; |
9b2956e2 GM |
2371 | frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget, |
2372 | al, ac); | |
177c0ea7 | 2373 | |
7556890b | 2374 | f->output_data.x->edit_widget = frame_widget; |
177c0ea7 JB |
2375 | |
2376 | XtManageChild (frame_widget); | |
a7f7d550 FP |
2377 | |
2378 | /* Do some needed geometry management. */ | |
2379 | { | |
b7163a50 | 2380 | char *tem, shell_position[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)]; |
8a94ea33 PE |
2381 | Arg gal[10]; |
2382 | int gac = 0; | |
5031cc10 | 2383 | int extra_borders = 0; |
177c0ea7 | 2384 | int menubar_size |
7556890b RS |
2385 | = (f->output_data.x->menubar_widget |
2386 | ? (f->output_data.x->menubar_widget->core.height | |
2387 | + f->output_data.x->menubar_widget->core.border_width) | |
8fc2766b | 2388 | : 0); |
a7f7d550 | 2389 | |
f7008aff RS |
2390 | #if 0 /* Experimentally, we now get the right results |
2391 | for -geometry -0-0 without this. 24 Aug 96, rms. */ | |
01cbdba5 RS |
2392 | if (FRAME_EXTERNAL_MENU_BAR (f)) |
2393 | { | |
dd254b21 | 2394 | Dimension ibw = 0; |
01cbdba5 RS |
2395 | XtVaGetValues (pane_widget, XtNinternalBorderWidth, &ibw, NULL); |
2396 | menubar_size += ibw; | |
2397 | } | |
f7008aff | 2398 | #endif |
01cbdba5 | 2399 | |
7556890b | 2400 | f->output_data.x->menubar_height = menubar_size; |
00983aba | 2401 | |
440b0bfd | 2402 | #ifndef USE_LUCID |
5031cc10 KH |
2403 | /* Motif seems to need this amount added to the sizes |
2404 | specified for the shell widget. The Athena/Lucid widgets don't. | |
2405 | Both conclusions reached experimentally. -- rms. */ | |
440b0bfd RS |
2406 | XtVaGetValues (f->output_data.x->edit_widget, XtNinternalBorderWidth, |
2407 | &extra_borders, NULL); | |
2408 | extra_borders *= 2; | |
2409 | #endif | |
5031cc10 | 2410 | |
97787173 RS |
2411 | /* Convert our geometry parameters into a geometry string |
2412 | and specify it. | |
2413 | Note that we do not specify here whether the position | |
2414 | is a user-specified or program-specified one. | |
2415 | We pass that information later, in x_wm_set_size_hints. */ | |
2416 | { | |
be786000 | 2417 | int left = f->left_pos; |
97787173 | 2418 | int xneg = window_prompting & XNegative; |
be786000 | 2419 | int top = f->top_pos; |
97787173 RS |
2420 | int yneg = window_prompting & YNegative; |
2421 | if (xneg) | |
2422 | left = -left; | |
2423 | if (yneg) | |
2424 | top = -top; | |
c760f47e KH |
2425 | |
2426 | if (window_prompting & USPosition) | |
5031cc10 | 2427 | sprintf (shell_position, "=%dx%d%c%d%c%d", |
be786000 KS |
2428 | FRAME_PIXEL_WIDTH (f) + extra_borders, |
2429 | FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders, | |
c760f47e KH |
2430 | (xneg ? '-' : '+'), left, |
2431 | (yneg ? '-' : '+'), top); | |
2432 | else | |
6b61353c KH |
2433 | { |
2434 | sprintf (shell_position, "=%dx%d", | |
2435 | FRAME_PIXEL_WIDTH (f) + extra_borders, | |
2436 | FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders); | |
2437 | ||
2438 | /* Setting x and y when the position is not specified in | |
2439 | the geometry string will set program position in the WM hints. | |
2440 | If Emacs had just one program position, we could set it in | |
2441 | fallback resources, but since each make-frame call can specify | |
2442 | different program positions, this is easier. */ | |
8a94ea33 PE |
2443 | XtSetArg (gal[gac], XtNx, left); gac++; |
2444 | XtSetArg (gal[gac], XtNy, top); gac++; | |
6b61353c | 2445 | } |
97787173 RS |
2446 | } |
2447 | ||
77110caa RS |
2448 | /* We don't free this because we don't know whether |
2449 | it is safe to free it while the frame exists. | |
2450 | It isn't worth the trouble of arranging to free it | |
2451 | when the frame is deleted. */ | |
b3b4476b | 2452 | tem = xstrdup (shell_position); |
8a94ea33 PE |
2453 | XtSetArg (gal[gac], XtNgeometry, tem); gac++; |
2454 | XtSetValues (shell_widget, gal, gac); | |
a7f7d550 FP |
2455 | } |
2456 | ||
9ef48a9d RS |
2457 | XtManageChild (pane_widget); |
2458 | XtRealizeWidget (shell_widget); | |
2459 | ||
2532f20c JD |
2460 | if (FRAME_X_EMBEDDED_P (f)) |
2461 | XReparentWindow (FRAME_X_DISPLAY (f), XtWindow (shell_widget), | |
2462 | f->output_data.x->parent_desc, 0, 0); | |
2463 | ||
177c0ea7 | 2464 | FRAME_X_WINDOW (f) = XtWindow (frame_widget); |
9ef48a9d RS |
2465 | |
2466 | validate_x_resource_name (); | |
b7975ee4 | 2467 | |
51b59d79 PE |
2468 | class_hints.res_name = SSDATA (Vx_resource_name); |
2469 | class_hints.res_class = SSDATA (Vx_resource_class); | |
b9dc4443 | 2470 | XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints); |
5a7df7d7 GM |
2471 | |
2472 | #ifdef HAVE_X_I18N | |
2473 | FRAME_XIC (f) = NULL; | |
1576f1ad DL |
2474 | if (use_xim) |
2475 | create_frame_xic (f); | |
5a7df7d7 | 2476 | #endif |
64d16748 | 2477 | |
7556890b RS |
2478 | f->output_data.x->wm_hints.input = True; |
2479 | f->output_data.x->wm_hints.flags |= InputHint; | |
b9dc4443 | 2480 | XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2481 | &f->output_data.x->wm_hints); |
b8228beb | 2482 | |
c4ec904f | 2483 | hack_wm_protocols (f, shell_widget); |
9ef48a9d | 2484 | |
6c32dd68 PR |
2485 | #ifdef HACK_EDITRES |
2486 | XtAddEventHandler (shell_widget, 0, True, _XEditResCheckMessages, 0); | |
2487 | #endif | |
2488 | ||
9ef48a9d | 2489 | /* Do a stupid property change to force the server to generate a |
333b20bb | 2490 | PropertyNotify event so that the event_stream server timestamp will |
9ef48a9d RS |
2491 | be initialized to something relevant to the time we created the window. |
2492 | */ | |
6c32dd68 | 2493 | XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget), |
b9dc4443 RS |
2494 | FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, |
2495 | XA_ATOM, 32, PropModeAppend, | |
9ef48a9d RS |
2496 | (unsigned char*) NULL, 0); |
2497 | ||
5a7df7d7 | 2498 | /* Make all the standard events reach the Emacs frame. */ |
31ac8d8c | 2499 | attributes.event_mask = STANDARD_EVENT_SET; |
5a7df7d7 GM |
2500 | |
2501 | #ifdef HAVE_X_I18N | |
2502 | if (FRAME_XIC (f)) | |
2503 | { | |
2504 | /* XIM server might require some X events. */ | |
2505 | unsigned long fevent = NoEventMask; | |
6b61353c | 2506 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
5a7df7d7 GM |
2507 | attributes.event_mask |= fevent; |
2508 | } | |
2509 | #endif /* HAVE_X_I18N */ | |
177c0ea7 | 2510 | |
31ac8d8c FP |
2511 | attribute_mask = CWEventMask; |
2512 | XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget), | |
2513 | attribute_mask, &attributes); | |
2514 | ||
6c32dd68 | 2515 | XtMapWidget (frame_widget); |
9ef48a9d | 2516 | |
8fc2766b RS |
2517 | /* x_set_name normally ignores requests to set the name if the |
2518 | requested name is the same as the current name. This is the one | |
2519 | place where that assumption isn't correct; f->name is set, but | |
2520 | the X server hasn't been told. */ | |
2521 | { | |
2522 | Lisp_Object name; | |
2523 | int explicit = f->explicit_name; | |
2524 | ||
2525 | f->explicit_name = 0; | |
e69b0960 | 2526 | name = f->name; |
f00af5b1 | 2527 | fset_name (f, Qnil); |
8fc2766b RS |
2528 | x_set_name (f, name, explicit); |
2529 | } | |
2530 | ||
b9dc4443 | 2531 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
db3b2dc8 JD |
2532 | f->output_data.x->current_cursor |
2533 | = f->output_data.x->text_cursor); | |
8fc2766b | 2534 | |
4d7e6e51 | 2535 | unblock_input (); |
8fc2766b | 2536 | |
495fa05e GM |
2537 | /* This is a no-op, except under Motif. Make sure main areas are |
2538 | set to something reasonable, in case we get an error later. */ | |
2539 | lw_set_main_areas (pane_widget, 0, frame_widget); | |
8fc2766b RS |
2540 | } |
2541 | ||
9ef48a9d | 2542 | #else /* not USE_X_TOOLKIT */ |
488dd4c4 | 2543 | #ifdef USE_GTK |
f78faa98 | 2544 | static void |
971de7fb | 2545 | x_window (FRAME_PTR f) |
488dd4c4 JD |
2546 | { |
2547 | if (! xg_create_frame_widgets (f)) | |
2548 | error ("Unable to create window"); | |
1fcfb866 JD |
2549 | |
2550 | #ifdef HAVE_X_I18N | |
2551 | FRAME_XIC (f) = NULL; | |
6b61353c | 2552 | if (use_xim) |
1576f1ad | 2553 | { |
4d7e6e51 | 2554 | block_input (); |
1576f1ad DL |
2555 | create_frame_xic (f); |
2556 | if (FRAME_XIC (f)) | |
2557 | { | |
2558 | /* XIM server might require some X events. */ | |
2559 | unsigned long fevent = NoEventMask; | |
6b61353c | 2560 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
1fcfb866 | 2561 | |
1576f1ad DL |
2562 | if (fevent != NoEventMask) |
2563 | { | |
2564 | XSetWindowAttributes attributes; | |
2565 | XWindowAttributes wattr; | |
2566 | unsigned long attribute_mask; | |
2567 | ||
2568 | XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2569 | &wattr); | |
2570 | attributes.event_mask = wattr.your_event_mask | fevent; | |
2571 | attribute_mask = CWEventMask; | |
2572 | XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2573 | attribute_mask, &attributes); | |
2574 | } | |
2575 | } | |
4d7e6e51 | 2576 | unblock_input (); |
1576f1ad | 2577 | } |
1fcfb866 | 2578 | #endif |
488dd4c4 | 2579 | } |
9ef48a9d | 2580 | |
488dd4c4 | 2581 | #else /*! USE_GTK */ |
8fc2766b RS |
2582 | /* Create and set up the X window for frame F. */ |
2583 | ||
f78faa98 | 2584 | static void |
0521f580 | 2585 | x_window (struct frame *f) |
8fc2766b RS |
2586 | { |
2587 | XClassHint class_hints; | |
2588 | XSetWindowAttributes attributes; | |
2589 | unsigned long attribute_mask; | |
2590 | ||
5bcee7ef | 2591 | attributes.background_pixel = FRAME_BACKGROUND_PIXEL (f); |
7556890b | 2592 | attributes.border_pixel = f->output_data.x->border_pixel; |
01f1ba30 JB |
2593 | attributes.bit_gravity = StaticGravity; |
2594 | attributes.backing_store = NotUseful; | |
2595 | attributes.save_under = True; | |
2596 | attributes.event_mask = STANDARD_EVENT_SET; | |
9b2956e2 GM |
2597 | attributes.colormap = FRAME_X_COLORMAP (f); |
2598 | attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask | |
2599 | | CWColormap); | |
01f1ba30 | 2600 | |
4d7e6e51 | 2601 | block_input (); |
fe24a618 | 2602 | FRAME_X_WINDOW (f) |
b9dc4443 | 2603 | = XCreateWindow (FRAME_X_DISPLAY (f), |
7556890b | 2604 | f->output_data.x->parent_desc, |
be786000 KS |
2605 | f->left_pos, |
2606 | f->top_pos, | |
2607 | FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), | |
2608 | f->border_width, | |
01f1ba30 JB |
2609 | CopyFromParent, /* depth */ |
2610 | InputOutput, /* class */ | |
383d6ffc | 2611 | FRAME_X_VISUAL (f), |
01f1ba30 | 2612 | attribute_mask, &attributes); |
5a7df7d7 GM |
2613 | |
2614 | #ifdef HAVE_X_I18N | |
4dacadcc | 2615 | if (use_xim) |
5a7df7d7 | 2616 | { |
1576f1ad DL |
2617 | create_frame_xic (f); |
2618 | if (FRAME_XIC (f)) | |
2619 | { | |
2620 | /* XIM server might require some X events. */ | |
2621 | unsigned long fevent = NoEventMask; | |
6b61353c | 2622 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
1576f1ad DL |
2623 | attributes.event_mask |= fevent; |
2624 | attribute_mask = CWEventMask; | |
2625 | XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2626 | attribute_mask, &attributes); | |
2627 | } | |
5a7df7d7 GM |
2628 | } |
2629 | #endif /* HAVE_X_I18N */ | |
177c0ea7 | 2630 | |
d387c960 | 2631 | validate_x_resource_name (); |
b7975ee4 | 2632 | |
51b59d79 PE |
2633 | class_hints.res_name = SSDATA (Vx_resource_name); |
2634 | class_hints.res_class = SSDATA (Vx_resource_class); | |
b9dc4443 | 2635 | XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints); |
01f1ba30 | 2636 | |
00983aba KH |
2637 | /* The menubar is part of the ordinary display; |
2638 | it does not count in addition to the height of the window. */ | |
7556890b | 2639 | f->output_data.x->menubar_height = 0; |
00983aba | 2640 | |
179956b9 JB |
2641 | /* This indicates that we use the "Passive Input" input model. |
2642 | Unless we do this, we don't get the Focus{In,Out} events that we | |
2643 | need to draw the cursor correctly. Accursed bureaucrats. | |
b9dc4443 | 2644 | XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */ |
179956b9 | 2645 | |
7556890b RS |
2646 | f->output_data.x->wm_hints.input = True; |
2647 | f->output_data.x->wm_hints.flags |= InputHint; | |
b9dc4443 | 2648 | XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2649 | &f->output_data.x->wm_hints); |
6d078211 | 2650 | f->output_data.x->wm_hints.icon_pixmap = None; |
179956b9 | 2651 | |
032e4ebe RS |
2652 | /* Request "save yourself" and "delete window" commands from wm. */ |
2653 | { | |
2654 | Atom protocols[2]; | |
b9dc4443 RS |
2655 | protocols[0] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window; |
2656 | protocols[1] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself; | |
2657 | XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2); | |
032e4ebe | 2658 | } |
9ef48a9d | 2659 | |
e373f201 JB |
2660 | /* x_set_name normally ignores requests to set the name if the |
2661 | requested name is the same as the current name. This is the one | |
2662 | place where that assumption isn't correct; f->name is set, but | |
2663 | the X server hasn't been told. */ | |
2664 | { | |
98381190 | 2665 | Lisp_Object name; |
cf177271 | 2666 | int explicit = f->explicit_name; |
e373f201 | 2667 | |
cf177271 | 2668 | f->explicit_name = 0; |
e69b0960 | 2669 | name = f->name; |
f00af5b1 | 2670 | fset_name (f, Qnil); |
cf177271 | 2671 | x_set_name (f, name, explicit); |
e373f201 JB |
2672 | } |
2673 | ||
b9dc4443 | 2674 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
72ec0c8d JD |
2675 | f->output_data.x->current_cursor |
2676 | = f->output_data.x->text_cursor); | |
9ef48a9d | 2677 | |
4d7e6e51 | 2678 | unblock_input (); |
01f1ba30 | 2679 | |
fe24a618 | 2680 | if (FRAME_X_WINDOW (f) == 0) |
9ef48a9d | 2681 | error ("Unable to create window"); |
01f1ba30 JB |
2682 | } |
2683 | ||
488dd4c4 | 2684 | #endif /* not USE_GTK */ |
8fc2766b RS |
2685 | #endif /* not USE_X_TOOLKIT */ |
2686 | ||
289978b5 LT |
2687 | /* Verify that the icon position args for this window are valid. */ |
2688 | ||
2689 | static void | |
971de7fb | 2690 | x_icon_verify (struct frame *f, Lisp_Object parms) |
289978b5 LT |
2691 | { |
2692 | Lisp_Object icon_x, icon_y; | |
2693 | ||
2694 | /* Set the position of the icon. Note that twm groups all | |
2695 | icons in an icon window. */ | |
2696 | icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); | |
2697 | icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
2698 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) | |
2699 | { | |
2700 | CHECK_NUMBER (icon_x); | |
2701 | CHECK_NUMBER (icon_y); | |
2702 | } | |
2703 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) | |
2704 | error ("Both left and top icon corners of icon must be specified"); | |
2705 | } | |
2706 | ||
01f1ba30 JB |
2707 | /* Handle the icon stuff for this window. Perhaps later we might |
2708 | want an x_set_icon_position which can be called interactively as | |
b9dc4443 | 2709 | well. */ |
01f1ba30 JB |
2710 | |
2711 | static void | |
971de7fb | 2712 | x_icon (struct frame *f, Lisp_Object parms) |
01f1ba30 | 2713 | { |
f9942c9e | 2714 | Lisp_Object icon_x, icon_y; |
fd0f53a9 | 2715 | #if 0 |
abb4b7ec | 2716 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
fd0f53a9 | 2717 | #endif |
01f1ba30 JB |
2718 | |
2719 | /* Set the position of the icon. Note that twm groups all | |
b9dc4443 | 2720 | icons in an icon window. */ |
7c0d3ed8 KS |
2721 | icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); |
2722 | icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
f9942c9e | 2723 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) |
01f1ba30 | 2724 | { |
d311d28c PE |
2725 | CHECK_TYPE_RANGED_INTEGER (int, icon_x); |
2726 | CHECK_TYPE_RANGED_INTEGER (int, icon_y); | |
01f1ba30 | 2727 | } |
f9942c9e | 2728 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) |
01f1ba30 | 2729 | error ("Both left and top icon corners of icon must be specified"); |
01f1ba30 | 2730 | |
4d7e6e51 | 2731 | block_input (); |
f9942c9e | 2732 | |
fe24a618 JB |
2733 | if (! EQ (icon_x, Qunbound)) |
2734 | x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y)); | |
f9942c9e | 2735 | |
a9d54793 KL |
2736 | #if 0 /* x_get_arg removes the visibility parameter as a side effect, |
2737 | but x_create_frame still needs it. */ | |
01f1ba30 | 2738 | /* Start up iconic or window? */ |
49795535 | 2739 | x_wm_set_window_state |
333b20bb GM |
2740 | (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL), |
2741 | Qicon) | |
49795535 JB |
2742 | ? IconicState |
2743 | : NormalState)); | |
a9d54793 | 2744 | #endif |
01f1ba30 | 2745 | |
e69b0960 DA |
2746 | x_text_icon (f, SSDATA ((!NILP (f->icon_name) |
2747 | ? f->icon_name | |
2748 | : f->name))); | |
80534dd6 | 2749 | |
4d7e6e51 | 2750 | unblock_input (); |
01f1ba30 JB |
2751 | } |
2752 | ||
b243755a | 2753 | /* Make the GCs needed for this window, setting the |
01f1ba30 JB |
2754 | background, border and mouse colors; also create the |
2755 | mouse cursor and the gray border tile. */ | |
2756 | ||
2757 | static void | |
971de7fb | 2758 | x_make_gc (struct frame *f) |
01f1ba30 JB |
2759 | { |
2760 | XGCValues gc_values; | |
01f1ba30 | 2761 | |
4d7e6e51 | 2762 | block_input (); |
6afb1d07 | 2763 | |
b243755a | 2764 | /* Create the GCs of this frame. |
9ef48a9d | 2765 | Note that many default values are used. */ |
01f1ba30 | 2766 | |
ce593f6e KL |
2767 | gc_values.foreground = FRAME_FOREGROUND_PIXEL (f); |
2768 | gc_values.background = FRAME_BACKGROUND_PIXEL (f); | |
9ef48a9d | 2769 | gc_values.line_width = 0; /* Means 1 using fast algorithm. */ |
959e647d GM |
2770 | f->output_data.x->normal_gc |
2771 | = XCreateGC (FRAME_X_DISPLAY (f), | |
2772 | FRAME_X_WINDOW (f), | |
b51238f5 | 2773 | GCLineWidth | GCForeground | GCBackground, |
959e647d | 2774 | &gc_values); |
01f1ba30 | 2775 | |
b9dc4443 | 2776 | /* Reverse video style. */ |
ce593f6e KL |
2777 | gc_values.foreground = FRAME_BACKGROUND_PIXEL (f); |
2778 | gc_values.background = FRAME_FOREGROUND_PIXEL (f); | |
959e647d GM |
2779 | f->output_data.x->reverse_gc |
2780 | = XCreateGC (FRAME_X_DISPLAY (f), | |
2781 | FRAME_X_WINDOW (f), | |
b51238f5 | 2782 | GCForeground | GCBackground | GCLineWidth, |
959e647d | 2783 | &gc_values); |
01f1ba30 | 2784 | |
9ef48a9d | 2785 | /* Cursor has cursor-color background, background-color foreground. */ |
ce593f6e | 2786 | gc_values.foreground = FRAME_BACKGROUND_PIXEL (f); |
7556890b | 2787 | gc_values.background = f->output_data.x->cursor_pixel; |
01f1ba30 | 2788 | gc_values.fill_style = FillOpaqueStippled; |
7556890b | 2789 | f->output_data.x->cursor_gc |
b9dc4443 | 2790 | = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
b51238f5 | 2791 | (GCForeground | GCBackground |
c8bcd18a | 2792 | | GCFillStyle | GCLineWidth), |
01f1ba30 JB |
2793 | &gc_values); |
2794 | ||
333b20bb GM |
2795 | /* Reliefs. */ |
2796 | f->output_data.x->white_relief.gc = 0; | |
2797 | f->output_data.x->black_relief.gc = 0; | |
2798 | ||
01f1ba30 | 2799 | /* Create the gray border tile used when the pointer is not in |
f676886a | 2800 | the frame. Since this depends on the frame's pixel values, |
9ef48a9d | 2801 | this must be done on a per-frame basis. */ |
7556890b | 2802 | f->output_data.x->border_tile |
d043f1a4 | 2803 | = (XCreatePixmapFromBitmapData |
177c0ea7 | 2804 | (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, |
d043f1a4 | 2805 | gray_bits, gray_width, gray_height, |
ce593f6e KL |
2806 | FRAME_FOREGROUND_PIXEL (f), |
2807 | FRAME_BACKGROUND_PIXEL (f), | |
ab452f99 | 2808 | DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); |
6afb1d07 | 2809 | |
4d7e6e51 | 2810 | unblock_input (); |
01f1ba30 | 2811 | } |
01f1ba30 | 2812 | |
959e647d | 2813 | |
2b34df4e | 2814 | /* Free what was allocated in x_make_gc. */ |
959e647d GM |
2815 | |
2816 | void | |
971de7fb | 2817 | x_free_gcs (struct frame *f) |
959e647d GM |
2818 | { |
2819 | Display *dpy = FRAME_X_DISPLAY (f); | |
2820 | ||
4d7e6e51 | 2821 | block_input (); |
177c0ea7 | 2822 | |
959e647d GM |
2823 | if (f->output_data.x->normal_gc) |
2824 | { | |
2825 | XFreeGC (dpy, f->output_data.x->normal_gc); | |
2826 | f->output_data.x->normal_gc = 0; | |
2827 | } | |
2828 | ||
2829 | if (f->output_data.x->reverse_gc) | |
2830 | { | |
2831 | XFreeGC (dpy, f->output_data.x->reverse_gc); | |
2832 | f->output_data.x->reverse_gc = 0; | |
2833 | } | |
177c0ea7 | 2834 | |
959e647d GM |
2835 | if (f->output_data.x->cursor_gc) |
2836 | { | |
2837 | XFreeGC (dpy, f->output_data.x->cursor_gc); | |
2838 | f->output_data.x->cursor_gc = 0; | |
2839 | } | |
2840 | ||
2841 | if (f->output_data.x->border_tile) | |
2842 | { | |
2843 | XFreePixmap (dpy, f->output_data.x->border_tile); | |
2844 | f->output_data.x->border_tile = 0; | |
2845 | } | |
2846 | ||
4d7e6e51 | 2847 | unblock_input (); |
959e647d GM |
2848 | } |
2849 | ||
2850 | ||
eaf1eea9 | 2851 | /* Handler for signals raised during x_create_frame and |
c9e7db78 | 2852 | x_create_tip_frame. FRAME is the frame which is partially |
eaf1eea9 GM |
2853 | constructed. */ |
2854 | ||
2855 | static Lisp_Object | |
971de7fb | 2856 | unwind_create_frame (Lisp_Object frame) |
eaf1eea9 GM |
2857 | { |
2858 | struct frame *f = XFRAME (frame); | |
2859 | ||
8346e08b KL |
2860 | /* If frame is already dead, nothing to do. This can happen if the |
2861 | display is disconnected after the frame has become official, but | |
2862 | before x_create_frame removes the unwind protect. */ | |
2863 | if (!FRAME_LIVE_P (f)) | |
2864 | return Qnil; | |
2865 | ||
eaf1eea9 | 2866 | /* If frame is ``official'', nothing to do. */ |
97f18cc8 | 2867 | if (NILP (Fmemq (frame, Vframe_list))) |
eaf1eea9 | 2868 | { |
e509cfa6 | 2869 | #if defined GLYPH_DEBUG && defined ENABLE_CHECKING |
eaf1eea9 GM |
2870 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
2871 | #endif | |
177c0ea7 | 2872 | |
eaf1eea9 | 2873 | x_free_frame_resources (f); |
2a58bbc1 | 2874 | free_glyphs (f); |
eaf1eea9 | 2875 | |
e509cfa6 | 2876 | #if defined GLYPH_DEBUG && defined ENABLE_CHECKING |
eaf1eea9 | 2877 | /* Check that reference counts are indeed correct. */ |
a54e2c05 DA |
2878 | eassert (dpyinfo->reference_count == dpyinfo_refcount); |
2879 | eassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount); | |
5b3f8550 | 2880 | #endif |
c844a81a | 2881 | return Qt; |
eaf1eea9 | 2882 | } |
177c0ea7 | 2883 | |
eaf1eea9 GM |
2884 | return Qnil; |
2885 | } | |
2886 | ||
f01d3321 CY |
2887 | static Lisp_Object |
2888 | unwind_create_frame_1 (Lisp_Object val) | |
2889 | { | |
d1f55f16 | 2890 | inhibit_lisp_code = val; |
f01d3321 CY |
2891 | return Qnil; |
2892 | } | |
b51238f5 | 2893 | |
02ed2ea8 | 2894 | static void |
971de7fb | 2895 | x_default_font_parameter (struct frame *f, Lisp_Object parms) |
02ed2ea8 KH |
2896 | { |
2897 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
770e2e6e | 2898 | Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL, |
637fa988 | 2899 | RES_TYPE_STRING); |
e9b7ab96 | 2900 | Lisp_Object font = Qnil; |
770e2e6e | 2901 | if (EQ (font_param, Qunbound)) |
0d1d0d26 JD |
2902 | font_param = Qnil; |
2903 | ||
2904 | if (NILP (font_param)) | |
637fa988 | 2905 | { |
e1dbe924 | 2906 | /* System font should take precedence over X resources. We suggest this |
0d1d0d26 JD |
2907 | regardless of font-use-system-font because .emacs may not have been |
2908 | read yet. */ | |
2909 | const char *system_font = xsettings_get_system_font (); | |
e9b7ab96 | 2910 | if (system_font) |
d7ea76b4 | 2911 | font = font_open_by_name (f, build_unibyte_string (system_font)); |
637fa988 | 2912 | } |
0d1d0d26 | 2913 | |
e9b7ab96 JD |
2914 | if (NILP (font)) |
2915 | font = !NILP (font_param) ? font_param | |
2916 | : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING); | |
2917 | ||
2918 | if (! FONTP (font) && ! STRINGP (font)) | |
02ed2ea8 | 2919 | { |
675e2c69 | 2920 | const char *names[] |
be9d013a CY |
2921 | = { |
2922 | #ifdef HAVE_XFT | |
d7afccca | 2923 | /* This will find the normal Xft font. */ |
c024ac08 | 2924 | "monospace-10", |
be9d013a CY |
2925 | #endif |
2926 | "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1", | |
2927 | "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", | |
02ed2ea8 KH |
2928 | "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", |
2929 | /* This was formerly the first thing tried, but it finds | |
2930 | too many fonts and takes too long. */ | |
2931 | "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1", | |
2932 | /* If those didn't work, look for something which will | |
2933 | at least work. */ | |
2934 | "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1", | |
25c25256 | 2935 | "fixed", |
02ed2ea8 KH |
2936 | NULL }; |
2937 | int i; | |
2938 | ||
2939 | for (i = 0; names[i]; i++) | |
2940 | { | |
d7ea76b4 | 2941 | font = font_open_by_name (f, build_unibyte_string (names[i])); |
02ed2ea8 KH |
2942 | if (! NILP (font)) |
2943 | break; | |
2944 | } | |
2945 | if (NILP (font)) | |
25c25256 | 2946 | error ("No suitable font was found"); |
02ed2ea8 | 2947 | } |
770e2e6e | 2948 | else if (!NILP (font_param)) |
27129af9 SM |
2949 | { |
2950 | /* Remember the explicit font parameter, so we can re-apply it after | |
2951 | we've applied the `default' face settings. */ | |
770e2e6e SM |
2952 | x_set_frame_parameters (f, Fcons (Fcons (Qfont_param, font_param), Qnil)); |
2953 | } | |
637fa988 | 2954 | |
5fc8e5bc J |
2955 | /* This call will make X resources override any system font setting. */ |
2956 | x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING); | |
02ed2ea8 | 2957 | } |
b51238f5 | 2958 | |
eaf1eea9 | 2959 | |
1c44e124 CY |
2960 | DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint, Sx_wm_set_size_hint, |
2961 | 0, 1, 0, | |
2962 | doc: /* Send the size hints for frame FRAME to the window manager. | |
5890e400 DA |
2963 | If FRAME is omitted or nil, use the selected frame. |
2964 | Signal error if FRAME is not an X frame. */) | |
5842a27b | 2965 | (Lisp_Object frame) |
1c44e124 | 2966 | { |
7452b7bd | 2967 | struct frame *f = decode_window_system_frame (frame); |
5890e400 | 2968 | |
4d7e6e51 | 2969 | block_input (); |
5890e400 | 2970 | x_wm_set_size_hint (f, 0, 0); |
4d7e6e51 | 2971 | unblock_input (); |
653a3150 | 2972 | return Qnil; |
1c44e124 CY |
2973 | } |
2974 | ||
3e6bec3b JD |
2975 | static void |
2976 | set_machine_and_pid_properties (struct frame *f) | |
2977 | { | |
ac61e7e1 | 2978 | long pid = (long) getpid (); |
3e6bec3b | 2979 | |
66b16767 J |
2980 | /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */ |
2981 | XSetWMProperties (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), NULL, NULL, | |
2982 | NULL, 0, NULL, NULL, NULL); | |
3e6bec3b JD |
2983 | XChangeProperty (FRAME_X_DISPLAY (f), |
2984 | FRAME_OUTER_WINDOW (f), | |
2985 | XInternAtom (FRAME_X_DISPLAY (f), | |
2986 | "_NET_WM_PID", | |
2987 | False), | |
2988 | XA_CARDINAL, 32, PropModeReplace, | |
2989 | (unsigned char *) &pid, 1); | |
2990 | } | |
2991 | ||
f676886a | 2992 | DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, |
01f1ba30 | 2993 | 1, 1, 0, |
7ee72033 | 2994 | doc: /* Make a new X window, which is called a "frame" in Emacs terms. |
d29a9848 | 2995 | Return an Emacs frame object. |
e0079d39 | 2996 | PARMS is an alist of frame parameters. |
c061c855 GM |
2997 | If the parameters specify that the frame should not have a minibuffer, |
2998 | and do not specify a specific minibuffer window to use, | |
2999 | then `default-minibuffer-frame' must be a frame whose minibuffer can | |
3000 | be shared by the new frame. | |
3001 | ||
7ee72033 | 3002 | This function is an internal primitive--use `make-frame' instead. */) |
5842a27b | 3003 | (Lisp_Object parms) |
01f1ba30 | 3004 | { |
f676886a | 3005 | struct frame *f; |
2365c027 | 3006 | Lisp_Object frame, tem; |
01f1ba30 JB |
3007 | Lisp_Object name; |
3008 | int minibuffer_only = 0; | |
3009 | long window_prompting = 0; | |
45d45af5 | 3010 | int width, height; |
d311d28c | 3011 | ptrdiff_t count = SPECPDL_INDEX (); |
ecaca587 | 3012 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
b9dc4443 | 3013 | Lisp_Object display; |
333b20bb | 3014 | struct x_display_info *dpyinfo = NULL; |
a59e4f3d | 3015 | Lisp_Object parent; |
e557f19d | 3016 | struct kboard *kb; |
01f1ba30 | 3017 | |
5fa98fcf RS |
3018 | parms = Fcopy_alist (parms); |
3019 | ||
b7975ee4 KH |
3020 | /* Use this general default value to start with |
3021 | until we know if this frame has a specified name. */ | |
3022 | Vx_resource_name = Vinvocation_name; | |
3023 | ||
6ed8eeff | 3024 | display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER); |
1705c933 | 3025 | if (EQ (display, Qunbound)) |
b6660415 | 3026 | display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING); |
b9dc4443 RS |
3027 | if (EQ (display, Qunbound)) |
3028 | display = Qnil; | |
3029 | dpyinfo = check_x_display_info (display); | |
6ed8eeff | 3030 | kb = dpyinfo->terminal->kboard; |
b9dc4443 | 3031 | |
89acb56d SM |
3032 | if (!dpyinfo->terminal->name) |
3033 | error ("Terminal is not live, can't create new frames on it"); | |
ab797f65 | 3034 | |
333b20bb | 3035 | name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); |
6a5e54e2 | 3036 | if (!STRINGP (name) |
cf177271 JB |
3037 | && ! EQ (name, Qunbound) |
3038 | && ! NILP (name)) | |
08a90d6a | 3039 | error ("Invalid frame name--not a string or nil"); |
01f1ba30 | 3040 | |
b7975ee4 KH |
3041 | if (STRINGP (name)) |
3042 | Vx_resource_name = name; | |
3043 | ||
a59e4f3d | 3044 | /* See if parent window is specified. */ |
333b20bb | 3045 | parent = x_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER); |
a59e4f3d RS |
3046 | if (EQ (parent, Qunbound)) |
3047 | parent = Qnil; | |
3048 | if (! NILP (parent)) | |
b7826503 | 3049 | CHECK_NUMBER (parent); |
a59e4f3d | 3050 | |
ecaca587 RS |
3051 | /* make_frame_without_minibuffer can run Lisp code and garbage collect. */ |
3052 | /* No need to protect DISPLAY because that's not used after passing | |
3053 | it to make_frame_without_minibuffer. */ | |
3054 | frame = Qnil; | |
3055 | GCPRO4 (parms, parent, name, frame); | |
333b20bb GM |
3056 | tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer", |
3057 | RES_TYPE_SYMBOL); | |
f9942c9e | 3058 | if (EQ (tem, Qnone) || NILP (tem)) |
2526c290 | 3059 | f = make_frame_without_minibuffer (Qnil, kb, display); |
f9942c9e | 3060 | else if (EQ (tem, Qonly)) |
01f1ba30 | 3061 | { |
f676886a | 3062 | f = make_minibuffer_frame (); |
01f1ba30 JB |
3063 | minibuffer_only = 1; |
3064 | } | |
6a5e54e2 | 3065 | else if (WINDOWP (tem)) |
2526c290 | 3066 | f = make_frame_without_minibuffer (tem, kb, display); |
f9942c9e JB |
3067 | else |
3068 | f = make_frame (1); | |
01f1ba30 | 3069 | |
ecaca587 RS |
3070 | XSETFRAME (frame, f); |
3071 | ||
6ed8eeff | 3072 | f->terminal = dpyinfo->terminal; |
428a555e | 3073 | |
08a90d6a | 3074 | f->output_method = output_x_window; |
38182d90 | 3075 | f->output_data.x = xzalloc (sizeof *f->output_data.x); |
7556890b | 3076 | f->output_data.x->icon_bitmap = -1; |
be786000 | 3077 | FRAME_FONTSET (f) = -1; |
333b20bb GM |
3078 | f->output_data.x->scroll_bar_foreground_pixel = -1; |
3079 | f->output_data.x->scroll_bar_background_pixel = -1; | |
f15340b7 MB |
3080 | #ifdef USE_TOOLKIT_SCROLL_BARS |
3081 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
3082 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
3083 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
08a90d6a | 3084 | |
f00af5b1 PE |
3085 | fset_icon_name (f, |
3086 | x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title", | |
3087 | RES_TYPE_STRING)); | |
e69b0960 | 3088 | if (! STRINGP (f->icon_name)) |
f00af5b1 | 3089 | fset_icon_name (f, Qnil); |
80534dd6 | 3090 | |
08a90d6a | 3091 | FRAME_X_DISPLAY_INFO (f) = dpyinfo; |
e3d56613 RS |
3092 | |
3093 | /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */ | |
3094 | record_unwind_protect (unwind_create_frame, frame); | |
08a90d6a | 3095 | |
9b2956e2 GM |
3096 | /* These colors will be set anyway later, but it's important |
3097 | to get the color reference counts right, so initialize them! */ | |
3098 | { | |
3099 | Lisp_Object black; | |
dbf31225 | 3100 | struct gcpro gcpro1; |
cefecbcf GM |
3101 | |
3102 | /* Function x_decode_color can signal an error. Make | |
3103 | sure to initialize color slots so that we won't try | |
3104 | to free colors we haven't allocated. */ | |
ce593f6e KL |
3105 | FRAME_FOREGROUND_PIXEL (f) = -1; |
3106 | FRAME_BACKGROUND_PIXEL (f) = -1; | |
cefecbcf GM |
3107 | f->output_data.x->cursor_pixel = -1; |
3108 | f->output_data.x->cursor_foreground_pixel = -1; | |
3109 | f->output_data.x->border_pixel = -1; | |
3110 | f->output_data.x->mouse_pixel = -1; | |
177c0ea7 | 3111 | |
9b2956e2 | 3112 | black = build_string ("black"); |
dbf31225 | 3113 | GCPRO1 (black); |
ce593f6e | 3114 | FRAME_FOREGROUND_PIXEL (f) |
9b2956e2 | 3115 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
ce593f6e | 3116 | FRAME_BACKGROUND_PIXEL (f) |
9b2956e2 GM |
3117 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
3118 | f->output_data.x->cursor_pixel | |
3119 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3120 | f->output_data.x->cursor_foreground_pixel | |
3121 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3122 | f->output_data.x->border_pixel | |
3123 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3124 | f->output_data.x->mouse_pixel | |
3125 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
dbf31225 | 3126 | UNGCPRO; |
9b2956e2 GM |
3127 | } |
3128 | ||
a59e4f3d RS |
3129 | /* Specify the parent under which to make this X window. */ |
3130 | ||
3131 | if (!NILP (parent)) | |
3132 | { | |
8c239ac3 | 3133 | f->output_data.x->parent_desc = (Window) XFASTINT (parent); |
7556890b | 3134 | f->output_data.x->explicit_parent = 1; |
a59e4f3d RS |
3135 | } |
3136 | else | |
3137 | { | |
7556890b RS |
3138 | f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; |
3139 | f->output_data.x->explicit_parent = 0; | |
a59e4f3d RS |
3140 | } |
3141 | ||
cf177271 JB |
3142 | /* Set the name; the functions to which we pass f expect the name to |
3143 | be set. */ | |
3144 | if (EQ (name, Qunbound) || NILP (name)) | |
3145 | { | |
f00af5b1 | 3146 | fset_name (f, build_string (dpyinfo->x_id_name)); |
cf177271 JB |
3147 | f->explicit_name = 0; |
3148 | } | |
3149 | else | |
3150 | { | |
f00af5b1 | 3151 | fset_name (f, name); |
cf177271 | 3152 | f->explicit_name = 1; |
9ef48a9d RS |
3153 | /* use the frame's title when getting resources for this frame. */ |
3154 | specbind (Qx_resource_name, name); | |
cf177271 | 3155 | } |
01f1ba30 | 3156 | |
02ed2ea8 KH |
3157 | #ifdef HAVE_FREETYPE |
3158 | #ifdef HAVE_XFT | |
b51238f5 | 3159 | register_font_driver (&xftfont_driver, f); |
02ed2ea8 | 3160 | #else /* not HAVE_XFT */ |
b51238f5 | 3161 | register_font_driver (&ftxfont_driver, f); |
02ed2ea8 KH |
3162 | #endif /* not HAVE_XFT */ |
3163 | #endif /* HAVE_FREETYPE */ | |
6332668d | 3164 | register_font_driver (&xfont_driver, f); |
297cc20a | 3165 | |
b51238f5 KH |
3166 | x_default_parameter (f, parms, Qfont_backend, Qnil, |
3167 | "fontBackend", "FontBackend", RES_TYPE_STRING); | |
02ed2ea8 | 3168 | |
01f1ba30 JB |
3169 | /* Extract the window parameters from the supplied values |
3170 | that are needed to determine window geometry. */ | |
b51238f5 | 3171 | x_default_font_parameter (f, parms); |
62d168d8 CY |
3172 | if (!FRAME_FONT (f)) |
3173 | { | |
3174 | delete_frame (frame, Qnoelisp); | |
3175 | error ("Invalid frame font"); | |
3176 | } | |
9ef48a9d | 3177 | |
2532f20c JD |
3178 | /* Frame contents get displaced if an embedded X window has a border. */ |
3179 | if (! FRAME_X_EMBEDDED_P (f)) | |
4bef8d26 | 3180 | x_default_parameter (f, parms, Qborder_width, make_number (0), |
2532f20c | 3181 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); |
177c0ea7 | 3182 | |
4e397688 | 3183 | /* This defaults to 1 in order to match xterm. We recognize either |
ddf768c3 JB |
3184 | internalBorderWidth or internalBorder (which is what xterm calls |
3185 | it). */ | |
3186 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
3187 | { | |
3188 | Lisp_Object value; | |
3189 | ||
abb4b7ec | 3190 | value = x_get_arg (dpyinfo, parms, Qinternal_border_width, |
333b20bb | 3191 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); |
ddf768c3 JB |
3192 | if (! EQ (value, Qunbound)) |
3193 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
3194 | parms); | |
3195 | } | |
a099c27a SM |
3196 | x_default_parameter (f, parms, Qinternal_border_width, |
3197 | #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */ | |
3198 | make_number (0), | |
3199 | #else | |
3200 | make_number (1), | |
3201 | #endif | |
333b20bb GM |
3202 | "internalBorderWidth", "internalBorderWidth", |
3203 | RES_TYPE_NUMBER); | |
303500aa | 3204 | x_default_parameter (f, parms, Qvertical_scroll_bars, |
5e617bc2 | 3205 | #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS) |
303500aa CY |
3206 | Qright, |
3207 | #else | |
3208 | Qleft, | |
3209 | #endif | |
333b20bb GM |
3210 | "verticalScrollBars", "ScrollBars", |
3211 | RES_TYPE_SYMBOL); | |
01f1ba30 | 3212 | |
b9dc4443 | 3213 | /* Also do the stuff which must be set before the window exists. */ |
cf177271 | 3214 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), |
333b20bb | 3215 | "foreground", "Foreground", RES_TYPE_STRING); |
cf177271 | 3216 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), |
0b60fc91 | 3217 | "background", "Background", RES_TYPE_STRING); |
cf177271 | 3218 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), |
333b20bb | 3219 | "pointerColor", "Foreground", RES_TYPE_STRING); |
cf177271 | 3220 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), |
333b20bb | 3221 | "borderColor", "BorderColor", RES_TYPE_STRING); |
d62c8769 GM |
3222 | x_default_parameter (f, parms, Qscreen_gamma, Qnil, |
3223 | "screenGamma", "ScreenGamma", RES_TYPE_FLOAT); | |
563b67aa GM |
3224 | x_default_parameter (f, parms, Qline_spacing, Qnil, |
3225 | "lineSpacing", "LineSpacing", RES_TYPE_NUMBER); | |
b3ba0aa8 KS |
3226 | x_default_parameter (f, parms, Qleft_fringe, Qnil, |
3227 | "leftFringe", "LeftFringe", RES_TYPE_NUMBER); | |
3228 | x_default_parameter (f, parms, Qright_fringe, Qnil, | |
3229 | "rightFringe", "RightFringe", RES_TYPE_NUMBER); | |
333b20bb GM |
3230 | |
3231 | x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground, | |
3232 | "scrollBarForeground", | |
3233 | "ScrollBarForeground", 1); | |
3234 | x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background, | |
3235 | "scrollBarBackground", | |
3236 | "ScrollBarBackground", 0); | |
3237 | ||
e509cfa6 | 3238 | #ifdef GLYPH_DEBUG |
c9e7db78 JD |
3239 | image_cache_refcount = |
3240 | FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0; | |
3241 | dpyinfo_refcount = dpyinfo->reference_count; | |
3242 | #endif /* GLYPH_DEBUG */ | |
3243 | ||
333b20bb GM |
3244 | /* Init faces before x_default_parameter is called for scroll-bar |
3245 | parameters because that function calls x_set_scroll_bar_width, | |
3246 | which calls change_frame_size, which calls Fset_window_buffer, | |
3247 | which runs hooks, which call Fvertical_motion. At the end, we | |
3248 | end up in init_iterator with a null face cache, which should not | |
3249 | happen. */ | |
3250 | init_frame_faces (f); | |
177c0ea7 | 3251 | |
f01d3321 CY |
3252 | /* Set the menu-bar-lines and tool-bar-lines parameters. We don't |
3253 | look up the X resources controlling the menu-bar and tool-bar | |
3254 | here; they are processed specially at startup, and reflected in | |
3255 | the values of the mode variables. | |
3256 | ||
3257 | Avoid calling window-configuration-change-hook; otherwise we | |
3258 | could get an infloop in next_frame since the frame is not yet in | |
3259 | Vframe_list. */ | |
3260 | { | |
a89654f8 | 3261 | ptrdiff_t count2 = SPECPDL_INDEX (); |
d1f55f16 CY |
3262 | record_unwind_protect (unwind_create_frame_1, inhibit_lisp_code); |
3263 | inhibit_lisp_code = Qt; | |
f01d3321 CY |
3264 | |
3265 | x_default_parameter (f, parms, Qmenu_bar_lines, | |
3266 | NILP (Vmenu_bar_mode) | |
3267 | ? make_number (0) : make_number (1), | |
3268 | NULL, NULL, RES_TYPE_NUMBER); | |
3269 | x_default_parameter (f, parms, Qtool_bar_lines, | |
3270 | NILP (Vtool_bar_mode) | |
3271 | ? make_number (0) : make_number (1), | |
3272 | NULL, NULL, RES_TYPE_NUMBER); | |
3273 | ||
3274 | unbind_to (count2, Qnil); | |
3275 | } | |
6431f2e6 | 3276 | |
79873d50 | 3277 | x_default_parameter (f, parms, Qbuffer_predicate, Qnil, |
333b20bb GM |
3278 | "bufferPredicate", "BufferPredicate", |
3279 | RES_TYPE_SYMBOL); | |
c2304e02 | 3280 | x_default_parameter (f, parms, Qtitle, Qnil, |
333b20bb | 3281 | "title", "Title", RES_TYPE_STRING); |
ea0a1f53 GM |
3282 | x_default_parameter (f, parms, Qwait_for_wm, Qt, |
3283 | "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN); | |
49d41073 EZ |
3284 | x_default_parameter (f, parms, Qfullscreen, Qnil, |
3285 | "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); | |
2b4e6277 | 3286 | x_default_parameter (f, parms, Qtool_bar_position, |
e69b0960 | 3287 | f->tool_bar_position, 0, 0, RES_TYPE_SYMBOL); |
90eb1019 | 3288 | |
35f59f6b | 3289 | /* Compute the size of the X window. */ |
7c0d3ed8 | 3290 | window_prompting = x_figure_window_size (f, parms, 1); |
38d22040 | 3291 | |
495fa05e GM |
3292 | tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); |
3293 | f->no_split = minibuffer_only || EQ (tem, Qt); | |
3294 | ||
289978b5 LT |
3295 | x_icon_verify (f, parms); |
3296 | ||
6a1bcd01 | 3297 | /* Create the X widget or window. */ |
a7f7d550 FP |
3298 | #ifdef USE_X_TOOLKIT |
3299 | x_window (f, window_prompting, minibuffer_only); | |
3300 | #else | |
f676886a | 3301 | x_window (f); |
a7f7d550 | 3302 | #endif |
177c0ea7 | 3303 | |
f676886a JB |
3304 | x_icon (f, parms); |
3305 | x_make_gc (f); | |
01f1ba30 | 3306 | |
495fa05e | 3307 | /* Now consider the frame official. */ |
c9e7db78 | 3308 | f->terminal->reference_count++; |
495fa05e GM |
3309 | FRAME_X_DISPLAY_INFO (f)->reference_count++; |
3310 | Vframe_list = Fcons (frame, Vframe_list); | |
3311 | ||
f9942c9e JB |
3312 | /* We need to do this after creating the X window, so that the |
3313 | icon-creation functions can say whose icon they're describing. */ | |
84f25880 | 3314 | x_default_parameter (f, parms, Qicon_type, Qt, |
33ed493b | 3315 | "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN); |
f9942c9e | 3316 | |
cf177271 | 3317 | x_default_parameter (f, parms, Qauto_raise, Qnil, |
333b20bb | 3318 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
cf177271 | 3319 | x_default_parameter (f, parms, Qauto_lower, Qnil, |
333b20bb | 3320 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
dbc4e1c1 | 3321 | x_default_parameter (f, parms, Qcursor_type, Qbox, |
333b20bb | 3322 | "cursorType", "CursorType", RES_TYPE_SYMBOL); |
28d7281d GM |
3323 | x_default_parameter (f, parms, Qscroll_bar_width, Qnil, |
3324 | "scrollBarWidth", "ScrollBarWidth", | |
3325 | RES_TYPE_NUMBER); | |
271a71c7 GM |
3326 | x_default_parameter (f, parms, Qalpha, Qnil, |
3327 | "alpha", "Alpha", RES_TYPE_NUMBER); | |
f9942c9e | 3328 | |
be786000 | 3329 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
01f1ba30 | 3330 | Change will not be effected unless different from the current |
be786000 KS |
3331 | FRAME_LINES (f). */ |
3332 | width = FRAME_COLS (f); | |
3333 | height = FRAME_LINES (f); | |
177c0ea7 | 3334 | |
be786000 KS |
3335 | SET_FRAME_COLS (f, 0); |
3336 | FRAME_LINES (f) = 0; | |
8938a4fb | 3337 | change_frame_size (f, height, width, 1, 0, 0); |
d043f1a4 | 3338 | |
488dd4c4 | 3339 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
495fa05e GM |
3340 | /* Create the menu bar. */ |
3341 | if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f)) | |
3342 | { | |
3343 | /* If this signals an error, we haven't set size hints for the | |
3344 | frame and we didn't make it visible. */ | |
3345 | initialize_frame_menubar (f); | |
3346 | ||
488dd4c4 | 3347 | #ifndef USE_GTK |
495fa05e GM |
3348 | /* This is a no-op, except under Motif where it arranges the |
3349 | main window for the widgets on it. */ | |
3350 | lw_set_main_areas (f->output_data.x->column_widget, | |
3351 | f->output_data.x->menubar_widget, | |
3352 | f->output_data.x->edit_widget); | |
488dd4c4 | 3353 | #endif /* not USE_GTK */ |
495fa05e | 3354 | } |
488dd4c4 | 3355 | #endif /* USE_X_TOOLKIT || USE_GTK */ |
495fa05e GM |
3356 | |
3357 | /* Tell the server what size and position, etc, we want, and how | |
3358 | badly we want them. This should be done after we have the menu | |
3359 | bar so that its size can be taken into account. */ | |
4d7e6e51 | 3360 | block_input (); |
7989f084 | 3361 | x_wm_set_size_hint (f, window_prompting, 0); |
4d7e6e51 | 3362 | unblock_input (); |
01f1ba30 | 3363 | |
495fa05e GM |
3364 | /* Make the window appear on the frame and enable display, unless |
3365 | the caller says not to. However, with explicit parent, Emacs | |
3366 | cannot control visibility, so don't try. */ | |
7556890b | 3367 | if (! f->output_data.x->explicit_parent) |
a59e4f3d RS |
3368 | { |
3369 | Lisp_Object visibility; | |
49795535 | 3370 | |
333b20bb GM |
3371 | visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, |
3372 | RES_TYPE_SYMBOL); | |
a59e4f3d RS |
3373 | if (EQ (visibility, Qunbound)) |
3374 | visibility = Qt; | |
49795535 | 3375 | |
a59e4f3d RS |
3376 | if (EQ (visibility, Qicon)) |
3377 | x_iconify_frame (f); | |
3378 | else if (! NILP (visibility)) | |
3379 | x_make_frame_visible (f); | |
3380 | else | |
6b437900 PE |
3381 | { |
3382 | /* Must have been Qnil. */ | |
3383 | } | |
a59e4f3d | 3384 | } |
01f1ba30 | 3385 | |
4d7e6e51 | 3386 | block_input (); |
717c30e0 | 3387 | |
3e6bec3b | 3388 | /* Set machine name and pid for the purpose of window managers. */ |
5e617bc2 | 3389 | set_machine_and_pid_properties (f); |
3e6bec3b | 3390 | |
6b61353c KH |
3391 | /* Set the WM leader property. GTK does this itself, so this is not |
3392 | needed when using GTK. */ | |
3393 | if (dpyinfo->client_leader_window != 0) | |
3394 | { | |
6b61353c KH |
3395 | XChangeProperty (FRAME_X_DISPLAY (f), |
3396 | FRAME_OUTER_WINDOW (f), | |
3397 | dpyinfo->Xatom_wm_client_leader, | |
3398 | XA_WINDOW, 32, PropModeReplace, | |
47c53789 | 3399 | (unsigned char *) &dpyinfo->client_leader_window, 1); |
6b61353c KH |
3400 | } |
3401 | ||
4d7e6e51 | 3402 | unblock_input (); |
3e6bec3b | 3403 | |
225c13a5 | 3404 | /* Initialize `default-minibuffer-frame' in case this is the first |
6ed8eeff | 3405 | frame on this terminal. */ |
225c13a5 | 3406 | if (FRAME_HAS_MINIBUF_P (f) |
1344aad4 TT |
3407 | && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame)) |
3408 | || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))) | |
15dbb4d6 | 3409 | kset_default_minibuffer_frame (kb, frame); |
225c13a5 | 3410 | |
5fa98fcf RS |
3411 | /* All remaining specified parameters, which have not been "used" |
3412 | by x_get_arg and friends, now go in the misc. alist of the frame. */ | |
9beb8baa | 3413 | for (tem = parms; CONSP (tem); tem = XCDR (tem)) |
5fa98fcf | 3414 | if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem)))) |
f00af5b1 | 3415 | fset_param_alist (f, Fcons (XCAR (tem), f->param_alist)); |
5fa98fcf | 3416 | |
495fa05e | 3417 | UNGCPRO; |
9e57df62 GM |
3418 | |
3419 | /* Make sure windows on this frame appear in calls to next-window | |
3420 | and similar functions. */ | |
3421 | Vwindow_list = Qnil; | |
177c0ea7 | 3422 | |
9ef48a9d | 3423 | return unbind_to (count, frame); |
01f1ba30 JB |
3424 | } |
3425 | ||
eaf1eea9 | 3426 | |
0d17d282 KH |
3427 | /* FRAME is used only to get a handle on the X display. We don't pass the |
3428 | display info directly because we're called from frame.c, which doesn't | |
3429 | know about that structure. */ | |
e4f79258 | 3430 | |
87498171 | 3431 | Lisp_Object |
971de7fb | 3432 | x_get_focus_frame (struct frame *frame) |
87498171 | 3433 | { |
0d17d282 | 3434 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame); |
87498171 | 3435 | Lisp_Object xfocus; |
0d17d282 | 3436 | if (! dpyinfo->x_focus_frame) |
87498171 KH |
3437 | return Qnil; |
3438 | ||
0d17d282 | 3439 | XSETFRAME (xfocus, dpyinfo->x_focus_frame); |
87498171 KH |
3440 | return xfocus; |
3441 | } | |
f0614854 | 3442 | |
3decc1e7 GM |
3443 | |
3444 | /* In certain situations, when the window manager follows a | |
3445 | click-to-focus policy, there seems to be no way around calling | |
3446 | XSetInputFocus to give another frame the input focus . | |
3447 | ||
3448 | In an ideal world, XSetInputFocus should generally be avoided so | |
3449 | that applications don't interfere with the window manager's focus | |
3450 | policy. But I think it's okay to use when it's clearly done | |
3451 | following a user-command. */ | |
3452 | ||
a7ca3326 | 3453 | DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0, |
7ee72033 MB |
3454 | doc: /* Set the input focus to FRAME. |
3455 | FRAME nil means use the selected frame. */) | |
5842a27b | 3456 | (Lisp_Object frame) |
3decc1e7 | 3457 | { |
7452b7bd | 3458 | struct frame *f = decode_window_system_frame (frame); |
3decc1e7 | 3459 | Display *dpy = FRAME_X_DISPLAY (f); |
3decc1e7 | 3460 | |
4d7e6e51 | 3461 | block_input (); |
9ba8e10d | 3462 | x_catch_errors (dpy); |
75bf0d33 DB |
3463 | |
3464 | if (FRAME_X_EMBEDDED_P (f)) | |
3465 | { | |
3466 | /* For Xembedded frames, normally the embedder forwards key | |
3467 | events. See XEmbed Protocol Specification at | |
3468 | http://freedesktop.org/wiki/Specifications/xembed-spec */ | |
3469 | xembed_request_focus (f); | |
3470 | } | |
3471 | else | |
3472 | { | |
3473 | XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
3474 | RevertToParent, CurrentTime); | |
3475 | x_ewmh_activate_frame (f); | |
3476 | } | |
3477 | ||
4545fa20 | 3478 | x_uncatch_errors (); |
4d7e6e51 | 3479 | unblock_input (); |
177c0ea7 | 3480 | |
3decc1e7 GM |
3481 | return Qnil; |
3482 | } | |
3483 | ||
f0614854 | 3484 | \f |
2d764c78 | 3485 | DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, |
4f4f2973 GM |
3486 | doc: /* Internal function called by `color-defined-p', which see |
3487 | .\(Note that the Nextstep version of this function ignores FRAME.) */) | |
5842a27b | 3488 | (Lisp_Object color, Lisp_Object frame) |
e12d55b2 | 3489 | { |
b9dc4443 | 3490 | XColor foo; |
7452b7bd | 3491 | FRAME_PTR f = decode_window_system_frame (frame); |
e12d55b2 | 3492 | |
b7826503 | 3493 | CHECK_STRING (color); |
b9dc4443 | 3494 | |
42a5b22f | 3495 | if (x_defined_color (f, SSDATA (color), &foo, 0)) |
e12d55b2 RS |
3496 | return Qt; |
3497 | else | |
3498 | return Qnil; | |
3499 | } | |
3500 | ||
2d764c78 | 3501 | DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, |
7ee72033 | 3502 | doc: /* Internal function called by `color-values', which see. */) |
5842a27b | 3503 | (Lisp_Object color, Lisp_Object frame) |
01f1ba30 | 3504 | { |
b9dc4443 | 3505 | XColor foo; |
7452b7bd | 3506 | FRAME_PTR f = decode_window_system_frame (frame); |
b9dc4443 | 3507 | |
b7826503 | 3508 | CHECK_STRING (color); |
01f1ba30 | 3509 | |
42a5b22f | 3510 | if (x_defined_color (f, SSDATA (color), &foo, 0)) |
3de717bd | 3511 | return list3i (foo.red, foo.green, foo.blue); |
01f1ba30 JB |
3512 | else |
3513 | return Qnil; | |
3514 | } | |
3515 | ||
a7ca3326 | 3516 | DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, |
7ee72033 | 3517 | doc: /* Internal function called by `display-color-p', which see. */) |
5842a27b | 3518 | (Lisp_Object terminal) |
01f1ba30 | 3519 | { |
6ed8eeff | 3520 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
11ae94fe | 3521 | |
b9dc4443 | 3522 | if (dpyinfo->n_planes <= 2) |
01f1ba30 JB |
3523 | return Qnil; |
3524 | ||
b9dc4443 | 3525 | switch (dpyinfo->visual->class) |
01f1ba30 JB |
3526 | { |
3527 | case StaticColor: | |
3528 | case PseudoColor: | |
3529 | case TrueColor: | |
3530 | case DirectColor: | |
3531 | return Qt; | |
3532 | ||
3533 | default: | |
3534 | return Qnil; | |
3535 | } | |
3536 | } | |
3537 | ||
a7ca3326 | 3538 | DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p, |
c061c855 | 3539 | 0, 1, 0, |
7ee72033 | 3540 | doc: /* Return t if the X display supports shades of gray. |
c061c855 | 3541 | Note that color displays do support shades of gray. |
6ed8eeff | 3542 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3543 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3544 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3545 | (Lisp_Object terminal) |
d0c9d219 | 3546 | { |
6ed8eeff | 3547 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
d0c9d219 | 3548 | |
ae6b58f9 | 3549 | if (dpyinfo->n_planes <= 1) |
b9dc4443 RS |
3550 | return Qnil; |
3551 | ||
ae6b58f9 RS |
3552 | switch (dpyinfo->visual->class) |
3553 | { | |
3554 | case StaticColor: | |
3555 | case PseudoColor: | |
3556 | case TrueColor: | |
3557 | case DirectColor: | |
3558 | case StaticGray: | |
3559 | case GrayScale: | |
3560 | return Qt; | |
3561 | ||
3562 | default: | |
3563 | return Qnil; | |
3564 | } | |
d0c9d219 RS |
3565 | } |
3566 | ||
41beb8fc | 3567 | DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, |
c061c855 | 3568 | 0, 1, 0, |
d29a9848 | 3569 | doc: /* Return the width in pixels of the X display TERMINAL. |
6ed8eeff | 3570 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3571 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3572 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3573 | (Lisp_Object terminal) |
41beb8fc | 3574 | { |
6ed8eeff | 3575 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3576 | |
abe9d29c | 3577 | return make_number (x_display_pixel_width (dpyinfo)); |
41beb8fc RS |
3578 | } |
3579 | ||
3580 | DEFUN ("x-display-pixel-height", Fx_display_pixel_height, | |
c061c855 | 3581 | Sx_display_pixel_height, 0, 1, 0, |
d29a9848 | 3582 | doc: /* Return the height in pixels of the X display TERMINAL. |
6ed8eeff | 3583 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3584 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3585 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3586 | (Lisp_Object terminal) |
41beb8fc | 3587 | { |
6ed8eeff | 3588 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3589 | |
abe9d29c | 3590 | return make_number (x_display_pixel_height (dpyinfo)); |
41beb8fc RS |
3591 | } |
3592 | ||
3593 | DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, | |
c061c855 | 3594 | 0, 1, 0, |
d29a9848 | 3595 | doc: /* Return the number of bitplanes of the X display TERMINAL. |
6ed8eeff | 3596 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3597 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3598 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3599 | (Lisp_Object terminal) |
41beb8fc | 3600 | { |
6ed8eeff | 3601 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3602 | |
3603 | return make_number (dpyinfo->n_planes); | |
41beb8fc RS |
3604 | } |
3605 | ||
3606 | DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells, | |
c061c855 | 3607 | 0, 1, 0, |
d29a9848 | 3608 | doc: /* Return the number of color cells of the X display TERMINAL. |
6ed8eeff | 3609 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3610 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3611 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3612 | (Lisp_Object terminal) |
41beb8fc | 3613 | { |
6ed8eeff | 3614 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3615 | |
6b61353c KH |
3616 | int nr_planes = DisplayPlanes (dpyinfo->display, |
3617 | XScreenNumberOfScreen (dpyinfo->screen)); | |
3618 | ||
3619 | /* Truncate nr_planes to 24 to avoid integer overflow. | |
3620 | Some displays says 32, but only 24 bits are actually significant. | |
3621 | There are only very few and rare video cards that have more than | |
3622 | 24 significant bits. Also 24 bits is more than 16 million colors, | |
3623 | it "should be enough for everyone". */ | |
3624 | if (nr_planes > 24) nr_planes = 24; | |
3625 | ||
3626 | return make_number (1 << nr_planes); | |
41beb8fc RS |
3627 | } |
3628 | ||
9d317b2c RS |
3629 | DEFUN ("x-server-max-request-size", Fx_server_max_request_size, |
3630 | Sx_server_max_request_size, | |
c061c855 | 3631 | 0, 1, 0, |
d29a9848 | 3632 | doc: /* Return the maximum request size of the X server of display TERMINAL. |
6ed8eeff | 3633 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3634 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3635 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3636 | (Lisp_Object terminal) |
9d317b2c | 3637 | { |
6ed8eeff | 3638 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3639 | |
3640 | return make_number (MAXREQUEST (dpyinfo->display)); | |
9d317b2c RS |
3641 | } |
3642 | ||
41beb8fc | 3643 | DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0, |
d29a9848 | 3644 | doc: /* Return the "vendor ID" string of the X server of display TERMINAL. |
09e80d9f | 3645 | \(Labeling every distributor as a "vendor" embodies the false assumption |
95d62d8a | 3646 | that operating systems cannot be developed and distributed noncommercially.) |
6ed8eeff | 3647 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3648 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3649 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3650 | (Lisp_Object terminal) |
41beb8fc | 3651 | { |
6ed8eeff | 3652 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
675e2c69 | 3653 | const char *vendor = ServerVendor (dpyinfo->display); |
b9dc4443 | 3654 | |
41beb8fc RS |
3655 | if (! vendor) vendor = ""; |
3656 | return build_string (vendor); | |
3657 | } | |
3658 | ||
3659 | DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0, | |
d29a9848 | 3660 | doc: /* Return the version numbers of the X server of display TERMINAL. |
c061c855 | 3661 | The value is a list of three integers: the major and minor |
95d62d8a | 3662 | version numbers of the X Protocol in use, and the distributor-specific release |
c061c855 GM |
3663 | number. See also the function `x-server-vendor'. |
3664 | ||
6ed8eeff | 3665 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3666 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3667 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3668 | (Lisp_Object terminal) |
41beb8fc | 3669 | { |
6ed8eeff | 3670 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3671 | Display *dpy = dpyinfo->display; |
11ae94fe | 3672 | |
3de717bd DA |
3673 | return list3i (ProtocolVersion (dpy), ProtocolRevision (dpy), |
3674 | VendorRelease (dpy)); | |
41beb8fc RS |
3675 | } |
3676 | ||
3677 | DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0, | |
6ed8eeff KL |
3678 | doc: /* Return the number of screens on the X server of display TERMINAL. |
3679 | The optional argument TERMINAL specifies which display to ask about. | |
708e05dc | 3680 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3681 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3682 | (Lisp_Object terminal) |
41beb8fc | 3683 | { |
6ed8eeff | 3684 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3685 | |
3686 | return make_number (ScreenCount (dpyinfo->display)); | |
41beb8fc RS |
3687 | } |
3688 | ||
3689 | DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0, | |
6ed8eeff KL |
3690 | doc: /* Return the height in millimeters of the X display TERMINAL. |
3691 | The optional argument TERMINAL specifies which display to ask about. | |
708e05dc | 3692 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3693 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3694 | (Lisp_Object terminal) |
41beb8fc | 3695 | { |
6ed8eeff | 3696 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3697 | |
3698 | return make_number (HeightMMOfScreen (dpyinfo->screen)); | |
41beb8fc RS |
3699 | } |
3700 | ||
3701 | DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, | |
6ed8eeff KL |
3702 | doc: /* Return the width in millimeters of the X display TERMINAL. |
3703 | The optional argument TERMINAL specifies which display to ask about. | |
708e05dc | 3704 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3705 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3706 | (Lisp_Object terminal) |
41beb8fc | 3707 | { |
6ed8eeff | 3708 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3709 | |
3710 | return make_number (WidthMMOfScreen (dpyinfo->screen)); | |
41beb8fc RS |
3711 | } |
3712 | ||
3713 | DEFUN ("x-display-backing-store", Fx_display_backing_store, | |
c061c855 | 3714 | Sx_display_backing_store, 0, 1, 0, |
d29a9848 | 3715 | doc: /* Return an indication of whether X display TERMINAL does backing store. |
c061c855 | 3716 | The value may be `always', `when-mapped', or `not-useful'. |
6ed8eeff | 3717 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3718 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3719 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3720 | (Lisp_Object terminal) |
41beb8fc | 3721 | { |
6ed8eeff | 3722 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
8ec8a5ec | 3723 | Lisp_Object result; |
11ae94fe | 3724 | |
b9dc4443 | 3725 | switch (DoesBackingStore (dpyinfo->screen)) |
41beb8fc RS |
3726 | { |
3727 | case Always: | |
8ec8a5ec GM |
3728 | result = intern ("always"); |
3729 | break; | |
41beb8fc RS |
3730 | |
3731 | case WhenMapped: | |
8ec8a5ec GM |
3732 | result = intern ("when-mapped"); |
3733 | break; | |
41beb8fc RS |
3734 | |
3735 | case NotUseful: | |
8ec8a5ec GM |
3736 | result = intern ("not-useful"); |
3737 | break; | |
41beb8fc RS |
3738 | |
3739 | default: | |
3740 | error ("Strange value for BackingStore parameter of screen"); | |
3741 | } | |
8ec8a5ec GM |
3742 | |
3743 | return result; | |
41beb8fc RS |
3744 | } |
3745 | ||
3746 | DEFUN ("x-display-visual-class", Fx_display_visual_class, | |
c061c855 | 3747 | Sx_display_visual_class, 0, 1, 0, |
6ed8eeff | 3748 | doc: /* Return the visual class of the X display TERMINAL. |
c061c855 GM |
3749 | The value is one of the symbols `static-gray', `gray-scale', |
3750 | `static-color', `pseudo-color', `true-color', or `direct-color'. | |
3751 | ||
6ed8eeff | 3752 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3753 | TERMINAL should a terminal object, a frame or a display name (a string). |
7ee72033 | 3754 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3755 | (Lisp_Object terminal) |
41beb8fc | 3756 | { |
6ed8eeff | 3757 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
8ec8a5ec | 3758 | Lisp_Object result; |
11ae94fe | 3759 | |
b9dc4443 | 3760 | switch (dpyinfo->visual->class) |
41beb8fc | 3761 | { |
8ec8a5ec GM |
3762 | case StaticGray: |
3763 | result = intern ("static-gray"); | |
3764 | break; | |
3765 | case GrayScale: | |
3766 | result = intern ("gray-scale"); | |
3767 | break; | |
3768 | case StaticColor: | |
3769 | result = intern ("static-color"); | |
3770 | break; | |
3771 | case PseudoColor: | |
3772 | result = intern ("pseudo-color"); | |
3773 | break; | |
3774 | case TrueColor: | |
3775 | result = intern ("true-color"); | |
3776 | break; | |
3777 | case DirectColor: | |
3778 | result = intern ("direct-color"); | |
3779 | break; | |
41beb8fc RS |
3780 | default: |
3781 | error ("Display has an unknown visual class"); | |
3782 | } | |
177c0ea7 | 3783 | |
8ec8a5ec | 3784 | return result; |
41beb8fc RS |
3785 | } |
3786 | ||
3787 | DEFUN ("x-display-save-under", Fx_display_save_under, | |
c061c855 | 3788 | Sx_display_save_under, 0, 1, 0, |
d29a9848 | 3789 | doc: /* Return t if the X display TERMINAL supports the save-under feature. |
6ed8eeff | 3790 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3791 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3792 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3793 | (Lisp_Object terminal) |
41beb8fc | 3794 | { |
6ed8eeff | 3795 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
11ae94fe | 3796 | |
b9dc4443 | 3797 | if (DoesSaveUnders (dpyinfo->screen) == True) |
41beb8fc RS |
3798 | return Qt; |
3799 | else | |
3800 | return Qnil; | |
3801 | } | |
4e3f9230 YM |
3802 | |
3803 | /* Store the geometry of the workarea on display DPYINFO into *RECT. | |
3804 | Return false if and only if the workarea information cannot be | |
3805 | obtained via the _NET_WORKAREA root window property. */ | |
3806 | ||
e0c9d565 PE |
3807 | #ifndef USE_GTK |
3808 | ||
4e3f9230 YM |
3809 | static bool |
3810 | x_get_net_workarea (struct x_display_info *dpyinfo, XRectangle *rect) | |
3811 | { | |
3812 | Display *dpy = dpyinfo->display; | |
3813 | long offset, max_len; | |
3814 | Atom target_type, actual_type; | |
3815 | unsigned long actual_size, bytes_remaining; | |
3816 | int rc, actual_format; | |
3817 | unsigned char *tmp_data = NULL; | |
3818 | bool result = false; | |
3819 | ||
3820 | x_catch_errors (dpy); | |
3821 | offset = 0; | |
3822 | max_len = 1; | |
3823 | target_type = XA_CARDINAL; | |
3824 | rc = XGetWindowProperty (dpy, dpyinfo->root_window, | |
3825 | dpyinfo->Xatom_net_current_desktop, | |
3826 | offset, max_len, False, target_type, | |
3827 | &actual_type, &actual_format, &actual_size, | |
3828 | &bytes_remaining, &tmp_data); | |
3829 | if (rc == Success && actual_type == target_type && !x_had_errors_p (dpy) | |
3830 | && actual_format == 32 && actual_size == max_len) | |
3831 | { | |
3832 | long current_desktop = ((long *) tmp_data)[0]; | |
3833 | ||
3834 | XFree (tmp_data); | |
3835 | tmp_data = NULL; | |
3836 | ||
3837 | offset = 4 * current_desktop; | |
3838 | max_len = 4; | |
3839 | rc = XGetWindowProperty (dpy, dpyinfo->root_window, | |
3840 | dpyinfo->Xatom_net_workarea, | |
3841 | offset, max_len, False, target_type, | |
3842 | &actual_type, &actual_format, &actual_size, | |
3843 | &bytes_remaining, &tmp_data); | |
3844 | if (rc == Success && actual_type == target_type && !x_had_errors_p (dpy) | |
3845 | && actual_format == 32 && actual_size == max_len) | |
3846 | { | |
3847 | long *values = (long *) tmp_data; | |
3848 | ||
3849 | rect->x = values[0]; | |
3850 | rect->y = values[1]; | |
3851 | rect->width = values[2]; | |
3852 | rect->height = values[3]; | |
3853 | ||
3854 | XFree (tmp_data); | |
3855 | tmp_data = NULL; | |
3856 | ||
3857 | result = true; | |
3858 | } | |
3859 | } | |
3860 | if (tmp_data) | |
3861 | XFree (tmp_data); | |
3862 | x_uncatch_errors (); | |
3863 | ||
3864 | return result; | |
3865 | } | |
3866 | ||
3867 | struct MonitorInfo { | |
3868 | XRectangle geom, work; | |
3869 | int mm_width, mm_height; | |
3870 | char *name; | |
3871 | }; | |
3872 | ||
e0c9d565 | 3873 | #if defined HAVE_XINERAMA || defined HAVE_XRANDR |
4e3f9230 YM |
3874 | static void |
3875 | free_monitors (struct MonitorInfo *monitors, int n_monitors) | |
3876 | { | |
3877 | int i; | |
3878 | for (i = 0; i < n_monitors; ++i) | |
3879 | xfree (monitors[i].name); | |
3880 | xfree (monitors); | |
3881 | } | |
e0c9d565 | 3882 | #endif /* HAVE_XINERAMA || HAVE_XRANDR */ |
4e3f9230 YM |
3883 | |
3884 | ||
3885 | /* Return monitor number where F is "most" or closest to. */ | |
3886 | static int | |
3887 | x_get_monitor_for_frame (struct frame *f, | |
3888 | struct MonitorInfo *monitors, | |
3889 | int n_monitors) | |
3890 | { | |
3891 | XRectangle frect; | |
3892 | int area = 0, dist = -1; | |
3893 | int best_area = -1, best_dist = -1; | |
3894 | int i; | |
3895 | ||
3896 | if (n_monitors == 1) return 0; | |
3897 | frect.x = f->left_pos; | |
3898 | frect.y = f->top_pos; | |
3899 | frect.width = FRAME_PIXEL_WIDTH (f); | |
3900 | frect.height = FRAME_PIXEL_HEIGHT (f); | |
3901 | ||
3902 | for (i = 0; i < n_monitors; ++i) | |
3903 | { | |
3904 | struct MonitorInfo *mi = &monitors[i]; | |
3905 | XRectangle res; | |
3906 | int a = 0; | |
3907 | ||
3908 | if (mi->geom.width == 0) continue; | |
3909 | ||
3910 | if (x_intersect_rectangles (&mi->geom, &frect, &res)) | |
3911 | { | |
3912 | a = res.width * res.height; | |
e0c9d565 PE |
3913 | if (a > area) |
3914 | { | |
3915 | area = a; | |
3916 | best_area = i; | |
3917 | } | |
4e3f9230 YM |
3918 | } |
3919 | ||
3920 | if (a == 0 && area == 0) | |
3921 | { | |
3922 | int dx, dy, d; | |
3923 | if (frect.x + frect.width < mi->geom.x) | |
3924 | dx = mi->geom.x - frect.x + frect.width; | |
3925 | else if (frect.x > mi->geom.x + mi->geom.width) | |
3926 | dx = frect.x - mi->geom.x + mi->geom.width; | |
3927 | else | |
3928 | dx = 0; | |
3929 | if (frect.y + frect.height < mi->geom.y) | |
3930 | dy = mi->geom.y - frect.y + frect.height; | |
3931 | else if (frect.y > mi->geom.y + mi->geom.height) | |
3932 | dy = frect.y - mi->geom.y + mi->geom.height; | |
3933 | else | |
3934 | dy = 0; | |
3935 | ||
3936 | d = dx*dx + dy*dy; | |
3937 | if (dist == -1 || dist > d) | |
3938 | { | |
3939 | dist = d; | |
3940 | best_dist = i; | |
3941 | } | |
3942 | } | |
3943 | } | |
3944 | ||
3945 | return best_area != -1 ? best_area : (best_dist != -1 ? best_dist : 0); | |
3946 | } | |
3947 | ||
3948 | static Lisp_Object | |
3949 | x_make_monitor_attribute_list (struct MonitorInfo *monitors, | |
3950 | int n_monitors, | |
3951 | int primary_monitor, | |
3952 | struct x_display_info *dpyinfo, | |
3953 | const char *source) | |
3954 | { | |
3955 | Lisp_Object monitor_frames = Fmake_vector (make_number (n_monitors), Qnil); | |
3956 | Lisp_Object frame, rest, attributes_list = Qnil; | |
3957 | Lisp_Object primary_monitor_attributes = Qnil; | |
3958 | int i; | |
3959 | ||
3960 | FOR_EACH_FRAME (rest, frame) | |
3961 | { | |
3962 | struct frame *f = XFRAME (frame); | |
3963 | ||
3964 | if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo | |
3965 | && !EQ (frame, tip_frame)) | |
3966 | { | |
3967 | i = x_get_monitor_for_frame (f, monitors, n_monitors); | |
3968 | ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i))); | |
3969 | } | |
3970 | } | |
3971 | ||
3972 | for (i = 0; i < n_monitors; ++i) | |
3973 | { | |
3974 | Lisp_Object geometry, workarea, attributes = Qnil; | |
3975 | struct MonitorInfo *mi = &monitors[i]; | |
3976 | ||
3977 | if (mi->geom.width == 0) continue; | |
3978 | ||
3979 | workarea = list4i (mi->work.x, mi->work.y, | |
3980 | mi->work.width, mi->work.height); | |
3981 | geometry = list4i (mi->geom.x, mi->geom.y, | |
3982 | mi->geom.width, mi->geom.height); | |
3983 | attributes = Fcons (Fcons (Qsource, | |
3984 | make_string (source, strlen (source))), | |
3985 | attributes); | |
3986 | attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)), | |
3987 | attributes); | |
3988 | attributes = Fcons (Fcons (Qmm_size, | |
3989 | list2i (mi->mm_width, mi->mm_height)), | |
3990 | attributes); | |
3991 | attributes = Fcons (Fcons (Qworkarea, workarea), attributes); | |
3992 | attributes = Fcons (Fcons (Qgeometry, geometry), attributes); | |
3993 | if (mi->name) | |
3994 | attributes = Fcons (Fcons (Qname, make_string (mi->name, | |
3995 | strlen (mi->name))), | |
3996 | attributes); | |
3997 | ||
3998 | if (i == primary_monitor) | |
3999 | primary_monitor_attributes = attributes; | |
4000 | else | |
4001 | attributes_list = Fcons (attributes, attributes_list); | |
4002 | } | |
4003 | ||
4004 | if (!NILP (primary_monitor_attributes)) | |
4005 | attributes_list = Fcons (primary_monitor_attributes, attributes_list); | |
4006 | return attributes_list; | |
4007 | } | |
4008 | ||
4009 | static Lisp_Object | |
4010 | x_get_monitor_attributes_fallback (struct x_display_info *dpyinfo) | |
4011 | { | |
4012 | struct MonitorInfo monitor; | |
4e3f9230 YM |
4013 | XRectangle workarea_r; |
4014 | ||
4015 | /* Fallback: treat (possibly) multiple physical monitors as if they | |
4016 | formed a single monitor as a whole. This should provide a | |
4017 | consistent result at least on single monitor environments. */ | |
4018 | monitor.geom.x = monitor.geom.y = 0; | |
4019 | monitor.geom.width = x_display_pixel_width (dpyinfo); | |
4020 | monitor.geom.height = x_display_pixel_height (dpyinfo); | |
4021 | monitor.mm_width = WidthMMOfScreen (dpyinfo->screen); | |
4022 | monitor.mm_height = HeightMMOfScreen (dpyinfo->screen); | |
4023 | monitor.name = xstrdup ("combined screen"); | |
4024 | ||
4025 | if (x_get_net_workarea (dpyinfo, &workarea_r)) | |
4026 | monitor.work = workarea_r; | |
4027 | else | |
4028 | monitor.work = monitor.geom; | |
4029 | return x_make_monitor_attribute_list (&monitor, 1, 0, dpyinfo, "fallback"); | |
4030 | } | |
4031 | ||
4032 | ||
4033 | #ifdef HAVE_XINERAMA | |
4034 | static Lisp_Object | |
4035 | x_get_monitor_attributes_xinerama (struct x_display_info *dpyinfo) | |
4036 | { | |
4037 | int n_monitors, i; | |
4038 | Lisp_Object attributes_list = Qnil; | |
4039 | Display *dpy = dpyinfo->display; | |
4040 | XineramaScreenInfo *info = XineramaQueryScreens (dpy, &n_monitors); | |
4041 | struct MonitorInfo *monitors; | |
e0c9d565 | 4042 | double mm_width_per_pixel, mm_height_per_pixel; |
4e3f9230 YM |
4043 | |
4044 | if (! info || n_monitors == 0) | |
4045 | { | |
4046 | if (info) | |
4047 | XFree (info); | |
4048 | return attributes_list; | |
4049 | } | |
4050 | ||
e0c9d565 | 4051 | mm_width_per_pixel = ((double) WidthMMOfScreen (dpyinfo->screen) |
4e3f9230 | 4052 | / x_display_pixel_width (dpyinfo)); |
e0c9d565 | 4053 | mm_height_per_pixel = ((double) HeightMMOfScreen (dpyinfo->screen) |
4e3f9230 YM |
4054 | / x_display_pixel_height (dpyinfo)); |
4055 | monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors)); | |
4056 | for (i = 0; i < n_monitors; ++i) | |
4057 | { | |
4058 | struct MonitorInfo *mi = &monitors[i]; | |
4059 | XRectangle workarea_r; | |
4060 | ||
4061 | mi->geom.x = info[i].x_org; | |
4062 | mi->geom.y = info[i].y_org; | |
4063 | mi->geom.width = info[i].width; | |
4064 | mi->geom.height = info[i].height; | |
4065 | mi->mm_width = mi->geom.width * mm_width_per_pixel + 0.5; | |
4066 | mi->mm_height = mi->geom.height * mm_height_per_pixel + 0.5; | |
4067 | mi->name = 0; | |
4068 | ||
4069 | /* Xinerama usually have primary monitor first, just use that. */ | |
4070 | if (i == 0 && x_get_net_workarea (dpyinfo, &workarea_r)) | |
4071 | { | |
4072 | mi->work = workarea_r; | |
4073 | if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work)) | |
4074 | mi->work = mi->geom; | |
4075 | } | |
4076 | else | |
4077 | mi->work = mi->geom; | |
4078 | } | |
4079 | XFree (info); | |
4080 | ||
4081 | attributes_list = x_make_monitor_attribute_list (monitors, | |
4082 | n_monitors, | |
4083 | 0, | |
4084 | dpyinfo, | |
4085 | "Xinerama"); | |
4086 | free_monitors (monitors, n_monitors); | |
4087 | return attributes_list; | |
4088 | } | |
4089 | #endif /* HAVE_XINERAMA */ | |
4090 | ||
4091 | ||
4092 | #ifdef HAVE_XRANDR | |
4093 | static Lisp_Object | |
4094 | x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo) | |
4095 | { | |
4096 | Lisp_Object attributes_list = Qnil; | |
4097 | XRRScreenResources *resources; | |
4098 | Display *dpy = dpyinfo->display; | |
4099 | int i, n_monitors, primary = -1; | |
4100 | RROutput pxid = None; | |
4101 | struct MonitorInfo *monitors; | |
4102 | ||
4103 | #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT | |
4104 | resources = XRRGetScreenResourcesCurrent (dpy, dpyinfo->root_window); | |
4105 | #else | |
4106 | resources = XRRGetScreenResources (dpy, dpyinfo->root_window); | |
4107 | #endif | |
4108 | if (! resources || resources->noutput == 0) | |
4109 | { | |
4110 | if (resources) | |
4111 | XRRFreeScreenResources (resources); | |
4112 | return Qnil; | |
4113 | } | |
4114 | n_monitors = resources->noutput; | |
4115 | monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors)); | |
4116 | ||
4117 | #ifdef HAVE_XRRGETOUTPUTPRIMARY | |
4118 | pxid = XRRGetOutputPrimary (dpy, dpyinfo->root_window); | |
4119 | #endif | |
4120 | ||
4121 | for (i = 0; i < n_monitors; ++i) | |
4122 | { | |
4123 | XRROutputInfo *info = XRRGetOutputInfo (dpy, resources, | |
4124 | resources->outputs[i]); | |
4125 | Connection conn = info ? info->connection : RR_Disconnected; | |
4126 | RRCrtc id = info ? info->crtc : None; | |
4127 | ||
4128 | if (strcmp (info->name, "default") == 0) | |
4129 | { | |
4130 | /* Non XRandr 1.2 driver, does not give useful data. */ | |
4131 | XRRFreeOutputInfo (info); | |
4132 | XRRFreeScreenResources (resources); | |
4133 | free_monitors (monitors, n_monitors); | |
4134 | return Qnil; | |
4135 | } | |
4136 | ||
4137 | if (conn != RR_Disconnected && id != None) | |
4138 | { | |
4139 | XRRCrtcInfo *crtc = XRRGetCrtcInfo (dpy, resources, id); | |
4140 | struct MonitorInfo *mi = &monitors[i]; | |
4141 | XRectangle workarea_r; | |
4142 | ||
4143 | if (! crtc) | |
4144 | { | |
4145 | XRRFreeOutputInfo (info); | |
4146 | continue; | |
4147 | } | |
4148 | ||
4149 | mi->geom.x = crtc->x; | |
4150 | mi->geom.y = crtc->y; | |
4151 | mi->geom.width = crtc->width; | |
4152 | mi->geom.height = crtc->height; | |
4153 | mi->mm_width = info->mm_width; | |
4154 | mi->mm_height = info->mm_height; | |
4155 | mi->name = xstrdup (info->name); | |
4156 | ||
4157 | if (pxid != None && pxid == resources->outputs[i]) | |
4158 | primary = i; | |
4159 | else if (primary == -1 && strcmp (info->name, "LVDS") == 0) | |
4160 | primary = i; | |
4161 | ||
4162 | if (i == primary && x_get_net_workarea (dpyinfo, &workarea_r)) | |
4163 | { | |
4164 | mi->work= workarea_r; | |
4165 | if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work)) | |
4166 | mi->work = mi->geom; | |
4167 | } | |
4168 | else | |
4169 | mi->work = mi->geom; | |
4170 | ||
4171 | XRRFreeCrtcInfo (crtc); | |
4172 | } | |
4173 | XRRFreeOutputInfo (info); | |
4174 | } | |
4175 | XRRFreeScreenResources (resources); | |
4176 | ||
4177 | attributes_list = x_make_monitor_attribute_list (monitors, | |
4178 | n_monitors, | |
4179 | primary, | |
4180 | dpyinfo, | |
4181 | "XRandr"); | |
4182 | free_monitors (monitors, n_monitors); | |
4183 | return attributes_list; | |
4184 | } | |
4185 | #endif /* HAVE_XRANDR */ | |
4186 | ||
4187 | static Lisp_Object | |
4188 | x_get_monitor_attributes (struct x_display_info *dpyinfo) | |
4189 | { | |
4190 | Lisp_Object attributes_list = Qnil; | |
4191 | Display *dpy = dpyinfo->display; | |
4192 | ||
4193 | #ifdef HAVE_XRANDR | |
4194 | int xrr_event_base, xrr_error_base; | |
4195 | bool xrr_ok = false; | |
4196 | xrr_ok = XRRQueryExtension (dpy, &xrr_event_base, &xrr_error_base); | |
4197 | if (xrr_ok) | |
4198 | { | |
4199 | int xrr_major, xrr_minor; | |
4200 | XRRQueryVersion (dpy, &xrr_major, &xrr_minor); | |
4201 | xrr_ok = (xrr_major == 1 && xrr_minor >= 2) || xrr_major > 1; | |
4202 | } | |
4203 | ||
4204 | if (xrr_ok) | |
4205 | attributes_list = x_get_monitor_attributes_xrandr (dpyinfo); | |
4206 | #endif /* HAVE_XRANDR */ | |
4207 | ||
4208 | #ifdef HAVE_XINERAMA | |
4209 | if (NILP (attributes_list)) | |
4210 | { | |
4211 | int xin_event_base, xin_error_base; | |
4212 | bool xin_ok = false; | |
4213 | xin_ok = XineramaQueryExtension (dpy, &xin_event_base, &xin_error_base); | |
4214 | if (xin_ok && XineramaIsActive (dpy)) | |
4215 | attributes_list = x_get_monitor_attributes_xinerama (dpyinfo); | |
4216 | } | |
4217 | #endif /* HAVE_XINERAMA */ | |
4218 | ||
4219 | if (NILP (attributes_list)) | |
4220 | attributes_list = x_get_monitor_attributes_fallback (dpyinfo); | |
4221 | ||
4222 | return attributes_list; | |
4223 | } | |
4224 | ||
e0c9d565 PE |
4225 | #endif /* !USE_GTK */ |
4226 | ||
4e3f9230 YM |
4227 | DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list, |
4228 | Sx_display_monitor_attributes_list, | |
4229 | 0, 1, 0, | |
4230 | doc: /* Return a list of physical monitor attributes on the X display TERMINAL. | |
4231 | ||
4232 | The optional argument TERMINAL specifies which display to ask about. | |
4233 | TERMINAL should be a terminal object, a frame or a display name (a string). | |
4234 | If omitted or nil, that stands for the selected frame's display. | |
4235 | ||
4236 | In addition to the standard attribute keys listed in | |
4237 | `display-monitor-attributes-list', the following keys are contained in | |
4238 | the attributes: | |
4239 | ||
4240 | source -- String describing the source from which multi-monitor | |
4241 | information is obtained, one of \"Gdk\", \"XRandr\", | |
4242 | \"Xinerama\", or \"fallback\" | |
4243 | ||
4244 | Internal use only, use `display-monitor-attributes-list' instead. */) | |
4245 | (Lisp_Object terminal) | |
4246 | { | |
4247 | struct x_display_info *dpyinfo = check_x_display_info (terminal); | |
4248 | Lisp_Object attributes_list = Qnil; | |
4249 | ||
4250 | #ifdef USE_GTK | |
e0c9d565 | 4251 | double mm_width_per_pixel, mm_height_per_pixel; |
4e3f9230 YM |
4252 | GdkDisplay *gdpy; |
4253 | GdkScreen *gscreen; | |
4254 | gint primary_monitor = 0, n_monitors, i; | |
4255 | Lisp_Object primary_monitor_attributes = Qnil; | |
4256 | Lisp_Object monitor_frames, rest, frame; | |
4257 | static const char *source = "Gdk"; | |
4258 | ||
4259 | block_input (); | |
e0c9d565 | 4260 | mm_width_per_pixel = ((double) WidthMMOfScreen (dpyinfo->screen) |
4e3f9230 | 4261 | / x_display_pixel_width (dpyinfo)); |
e0c9d565 | 4262 | mm_height_per_pixel = ((double) HeightMMOfScreen (dpyinfo->screen) |
4e3f9230 YM |
4263 | / x_display_pixel_height (dpyinfo)); |
4264 | gdpy = gdk_x11_lookup_xdisplay (dpyinfo->display); | |
4265 | gscreen = gdk_display_get_default_screen (gdpy); | |
4266 | #if GTK_MAJOR_VERSION > 2 || GTK_MINOR_VERSION >= 20 | |
4267 | primary_monitor = gdk_screen_get_primary_monitor (gscreen); | |
4268 | #endif | |
4269 | n_monitors = gdk_screen_get_n_monitors (gscreen); | |
4270 | monitor_frames = Fmake_vector (make_number (n_monitors), Qnil); | |
4271 | FOR_EACH_FRAME (rest, frame) | |
4272 | { | |
4273 | struct frame *f = XFRAME (frame); | |
4274 | ||
4275 | if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo | |
4276 | && !EQ (frame, tip_frame)) | |
4277 | { | |
4278 | GdkWindow *gwin = gtk_widget_get_window (FRAME_GTK_WIDGET (f)); | |
4279 | ||
4280 | i = gdk_screen_get_monitor_at_window (gscreen, gwin); | |
4281 | ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i))); | |
4282 | } | |
4283 | } | |
4284 | ||
4285 | i = n_monitors; | |
4286 | while (i-- > 0) | |
4287 | { | |
4288 | Lisp_Object geometry, workarea, attributes = Qnil; | |
4289 | gint width_mm = -1, height_mm = -1; | |
4290 | GdkRectangle rec; | |
4291 | ||
4292 | attributes = Fcons (Fcons (Qsource, | |
4293 | make_string (source, strlen (source))), | |
4294 | attributes); | |
4295 | attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)), | |
4296 | attributes); | |
4297 | ||
4298 | gdk_screen_get_monitor_geometry (gscreen, i, &rec); | |
4299 | geometry = list4i (rec.x, rec.y, rec.width, rec.height); | |
4300 | ||
4301 | #if GTK_MAJOR_VERSION > 2 || GTK_MINOR_VERSION >= 14 | |
4302 | width_mm = gdk_screen_get_monitor_width_mm (gscreen, i); | |
4303 | height_mm = gdk_screen_get_monitor_height_mm (gscreen, i); | |
4304 | #endif | |
4305 | if (width_mm < 0) | |
4306 | width_mm = rec.width * mm_width_per_pixel + 0.5; | |
4307 | if (height_mm < 0) | |
4308 | height_mm = rec.height * mm_height_per_pixel + 0.5; | |
4309 | attributes = Fcons (Fcons (Qmm_size, | |
4310 | list2i (width_mm, height_mm)), | |
4311 | attributes); | |
4312 | ||
4313 | #if GTK_MAJOR_VERSION > 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 4) | |
4314 | gdk_screen_get_monitor_workarea (gscreen, i, &rec); | |
4315 | workarea = list4i (rec.x, rec.y, rec.width, rec.height); | |
4316 | #else | |
4317 | /* Emulate the behavior of GTK+ 3.4. */ | |
4318 | { | |
4319 | XRectangle workarea_r; | |
4320 | ||
4321 | workarea = Qnil; | |
4322 | if (i == primary_monitor && x_get_net_workarea (dpyinfo, &workarea_r)) | |
4323 | { | |
4324 | GdkRectangle work; | |
4325 | ||
4326 | work.x = workarea_r.x; | |
4327 | work.y = workarea_r.y; | |
4328 | work.width = workarea_r.width; | |
4329 | work.height = workarea_r.height; | |
4330 | if (gdk_rectangle_intersect (&rec, &work, &work)) | |
4331 | workarea = list4i (work.x, work.y, work.width, work.height); | |
4332 | } | |
4333 | if (NILP (workarea)) | |
4334 | workarea = geometry; | |
4335 | } | |
4336 | #endif | |
4337 | attributes = Fcons (Fcons (Qworkarea, workarea), attributes); | |
4338 | ||
4339 | attributes = Fcons (Fcons (Qgeometry, geometry), attributes); | |
4340 | #if GTK_MAJOR_VERSION > 2 || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 14) | |
4341 | { | |
4342 | char *name = gdk_screen_get_monitor_plug_name (gscreen, i); | |
4343 | if (name) | |
4344 | attributes = Fcons (Fcons (Qname, make_string (name, strlen (name))), | |
4345 | attributes); | |
4346 | } | |
4347 | #endif | |
4348 | ||
4349 | if (i == primary_monitor) | |
4350 | primary_monitor_attributes = attributes; | |
4351 | else | |
4352 | attributes_list = Fcons (attributes, attributes_list); | |
4353 | } | |
4354 | ||
4355 | if (!NILP (primary_monitor_attributes)) | |
4356 | attributes_list = Fcons (primary_monitor_attributes, attributes_list); | |
4357 | unblock_input (); | |
4358 | #else /* not USE_GTK */ | |
4359 | ||
4360 | block_input (); | |
4361 | attributes_list = x_get_monitor_attributes (dpyinfo); | |
4362 | unblock_input (); | |
4363 | ||
4364 | #endif /* not USE_GTK */ | |
4365 | ||
4366 | return attributes_list; | |
4367 | } | |
4368 | ||
41beb8fc | 4369 | \f |
b9dc4443 | 4370 | int |
971de7fb | 4371 | x_pixel_width (register struct frame *f) |
01f1ba30 | 4372 | { |
be786000 | 4373 | return FRAME_PIXEL_WIDTH (f); |
01f1ba30 JB |
4374 | } |
4375 | ||
b9dc4443 | 4376 | int |
971de7fb | 4377 | x_pixel_height (register struct frame *f) |
01f1ba30 | 4378 | { |
be786000 | 4379 | return FRAME_PIXEL_HEIGHT (f); |
55caf99c RS |
4380 | } |
4381 | ||
a6ad00c0 GM |
4382 | /************************************************************************ |
4383 | X Displays | |
4384 | ************************************************************************/ | |
4385 | ||
01f1ba30 | 4386 | \f |
a6ad00c0 GM |
4387 | /* Mapping visual names to visuals. */ |
4388 | ||
4389 | static struct visual_class | |
4390 | { | |
675e2c69 | 4391 | const char *name; |
a6ad00c0 GM |
4392 | int class; |
4393 | } | |
4394 | visual_classes[] = | |
4395 | { | |
4396 | {"StaticGray", StaticGray}, | |
4397 | {"GrayScale", GrayScale}, | |
4398 | {"StaticColor", StaticColor}, | |
4399 | {"PseudoColor", PseudoColor}, | |
4400 | {"TrueColor", TrueColor}, | |
4401 | {"DirectColor", DirectColor}, | |
9908a324 | 4402 | {NULL, 0} |
a6ad00c0 GM |
4403 | }; |
4404 | ||
4405 | ||
404daac1 | 4406 | #ifndef HAVE_XSCREENNUMBEROFSCREEN |
a6ad00c0 GM |
4407 | |
4408 | /* Value is the screen number of screen SCR. This is a substitute for | |
4409 | the X function with the same name when that doesn't exist. */ | |
4410 | ||
404daac1 RS |
4411 | int |
4412 | XScreenNumberOfScreen (scr) | |
4413 | register Screen *scr; | |
4414 | { | |
a6ad00c0 GM |
4415 | Display *dpy = scr->display; |
4416 | int i; | |
3df34fdb | 4417 | |
a6ad00c0 | 4418 | for (i = 0; i < dpy->nscreens; ++i) |
fbd5ceb2 | 4419 | if (scr == dpy->screens + i) |
a6ad00c0 | 4420 | break; |
404daac1 | 4421 | |
a6ad00c0 | 4422 | return i; |
404daac1 | 4423 | } |
a6ad00c0 | 4424 | |
404daac1 RS |
4425 | #endif /* not HAVE_XSCREENNUMBEROFSCREEN */ |
4426 | ||
01f1ba30 | 4427 | |
a6ad00c0 GM |
4428 | /* Select the visual that should be used on display DPYINFO. Set |
4429 | members of DPYINFO appropriately. Called from x_term_init. */ | |
fe24a618 | 4430 | |
a6ad00c0 | 4431 | void |
971de7fb | 4432 | select_visual (struct x_display_info *dpyinfo) |
a6ad00c0 GM |
4433 | { |
4434 | Display *dpy = dpyinfo->display; | |
4435 | Screen *screen = dpyinfo->screen; | |
4436 | Lisp_Object value; | |
fe24a618 | 4437 | |
a6ad00c0 GM |
4438 | /* See if a visual is specified. */ |
4439 | value = display_x_get_resource (dpyinfo, | |
4440 | build_string ("visualClass"), | |
4441 | build_string ("VisualClass"), | |
4442 | Qnil, Qnil); | |
4443 | if (STRINGP (value)) | |
4444 | { | |
4445 | /* VALUE should be of the form CLASS-DEPTH, where CLASS is one | |
4446 | of `PseudoColor', `TrueColor' etc. and DEPTH is the color | |
4447 | depth, a decimal number. NAME is compared with case ignored. */ | |
38182d90 | 4448 | char *s = alloca (SBYTES (value) + 1); |
a6ad00c0 GM |
4449 | char *dash; |
4450 | int i, class = -1; | |
4451 | XVisualInfo vinfo; | |
4452 | ||
42a5b22f | 4453 | strcpy (s, SSDATA (value)); |
8966b757 | 4454 | dash = strchr (s, '-'); |
a6ad00c0 GM |
4455 | if (dash) |
4456 | { | |
4457 | dpyinfo->n_planes = atoi (dash + 1); | |
4458 | *dash = '\0'; | |
4459 | } | |
4460 | else | |
4461 | /* We won't find a matching visual with depth 0, so that | |
4462 | an error will be printed below. */ | |
4463 | dpyinfo->n_planes = 0; | |
f0614854 | 4464 | |
a6ad00c0 GM |
4465 | /* Determine the visual class. */ |
4466 | for (i = 0; visual_classes[i].name; ++i) | |
05131107 | 4467 | if (xstrcasecmp (s, visual_classes[i].name) == 0) |
a6ad00c0 GM |
4468 | { |
4469 | class = visual_classes[i].class; | |
4470 | break; | |
4471 | } | |
01f1ba30 | 4472 | |
a6ad00c0 GM |
4473 | /* Look up a matching visual for the specified class. */ |
4474 | if (class == -1 | |
4475 | || !XMatchVisualInfo (dpy, XScreenNumberOfScreen (screen), | |
4476 | dpyinfo->n_planes, class, &vinfo)) | |
d5db4077 | 4477 | fatal ("Invalid visual specification `%s'", SDATA (value)); |
177c0ea7 | 4478 | |
a6ad00c0 GM |
4479 | dpyinfo->visual = vinfo.visual; |
4480 | } | |
01f1ba30 JB |
4481 | else |
4482 | { | |
a6ad00c0 GM |
4483 | int n_visuals; |
4484 | XVisualInfo *vinfo, vinfo_template; | |
177c0ea7 | 4485 | |
a6ad00c0 GM |
4486 | dpyinfo->visual = DefaultVisualOfScreen (screen); |
4487 | ||
a6ad00c0 | 4488 | vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual); |
a6ad00c0 GM |
4489 | vinfo_template.screen = XScreenNumberOfScreen (screen); |
4490 | vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask, | |
4491 | &vinfo_template, &n_visuals); | |
83725342 | 4492 | if (n_visuals <= 0) |
a6ad00c0 GM |
4493 | fatal ("Can't get proper X visual info"); |
4494 | ||
94ac875b | 4495 | dpyinfo->n_planes = vinfo->depth; |
98c6f1e3 | 4496 | XFree (vinfo); |
a6ad00c0 | 4497 | } |
01f1ba30 | 4498 | } |
01f1ba30 | 4499 | |
a6ad00c0 | 4500 | |
b9dc4443 RS |
4501 | /* Return the X display structure for the display named NAME. |
4502 | Open a new connection if necessary. */ | |
4503 | ||
e4cebfca | 4504 | static struct x_display_info * |
971de7fb | 4505 | x_display_info_for_name (Lisp_Object name) |
b9dc4443 | 4506 | { |
08a90d6a | 4507 | Lisp_Object names; |
b9dc4443 RS |
4508 | struct x_display_info *dpyinfo; |
4509 | ||
b7826503 | 4510 | CHECK_STRING (name); |
b9dc4443 | 4511 | |
2246281f KL |
4512 | #if 0 |
4513 | if (! EQ (Vinitial_window_system, intern ("x"))) | |
4514 | error ("Not using X Windows"); /* That doesn't stop us anymore. */ | |
4515 | #endif | |
806048df | 4516 | |
08a90d6a RS |
4517 | for (dpyinfo = x_display_list, names = x_display_name_list; |
4518 | dpyinfo; | |
8e713be6 | 4519 | dpyinfo = dpyinfo->next, names = XCDR (names)) |
b9dc4443 RS |
4520 | { |
4521 | Lisp_Object tem; | |
8e713be6 | 4522 | tem = Fstring_equal (XCAR (XCAR (names)), name); |
08a90d6a | 4523 | if (!NILP (tem)) |
b9dc4443 RS |
4524 | return dpyinfo; |
4525 | } | |
4526 | ||
b7975ee4 KH |
4527 | /* Use this general default value to start with. */ |
4528 | Vx_resource_name = Vinvocation_name; | |
4529 | ||
b9dc4443 RS |
4530 | validate_x_resource_name (); |
4531 | ||
9b207e8e | 4532 | dpyinfo = x_term_init (name, (char *)0, |
51b59d79 | 4533 | SSDATA (Vx_resource_name)); |
b9dc4443 | 4534 | |
08a90d6a | 4535 | if (dpyinfo == 0) |
d5db4077 | 4536 | error ("Cannot connect to X server %s", SDATA (name)); |
08a90d6a | 4537 | |
b9dc4443 RS |
4538 | XSETFASTINT (Vwindow_system_version, 11); |
4539 | ||
4540 | return dpyinfo; | |
4541 | } | |
4542 | ||
a6ad00c0 | 4543 | |
01f1ba30 | 4544 | DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, |
c061c855 | 4545 | 1, 3, 0, |
4f4f2973 | 4546 | doc: /* Open a connection to a display server. |
c061c855 GM |
4547 | DISPLAY is the name of the display to connect to. |
4548 | Optional second arg XRM-STRING is a string of resources in xrdb format. | |
4549 | If the optional third arg MUST-SUCCEED is non-nil, | |
4f4f2973 GM |
4550 | terminate Emacs if we can't open the connection. |
4551 | \(In the Nextstep version, the last two arguments are currently ignored.) */) | |
5842a27b | 4552 | (Lisp_Object display, Lisp_Object xrm_string, Lisp_Object must_succeed) |
01f1ba30 | 4553 | { |
5f742c1b | 4554 | char *xrm_option; |
b9dc4443 | 4555 | struct x_display_info *dpyinfo; |
01f1ba30 | 4556 | |
b7826503 | 4557 | CHECK_STRING (display); |
d387c960 | 4558 | if (! NILP (xrm_string)) |
b7826503 | 4559 | CHECK_STRING (xrm_string); |
01f1ba30 | 4560 | |
2246281f KL |
4561 | #if 0 |
4562 | if (! EQ (Vinitial_window_system, intern ("x"))) | |
4563 | error ("Not using X Windows"); /* That doesn't stop us anymore. */ | |
4564 | #endif | |
806048df | 4565 | |
d387c960 | 4566 | if (! NILP (xrm_string)) |
5f742c1b | 4567 | xrm_option = SSDATA (xrm_string); |
01f1ba30 | 4568 | else |
5f742c1b | 4569 | xrm_option = (char *) 0; |
d387c960 JB |
4570 | |
4571 | validate_x_resource_name (); | |
4572 | ||
e1b1bee8 | 4573 | /* This is what opens the connection and sets x_current_display. |
b9dc4443 RS |
4574 | This also initializes many symbols, such as those used for input. */ |
4575 | dpyinfo = x_term_init (display, xrm_option, | |
51b59d79 | 4576 | SSDATA (Vx_resource_name)); |
f1c16f36 | 4577 | |
08a90d6a RS |
4578 | if (dpyinfo == 0) |
4579 | { | |
4580 | if (!NILP (must_succeed)) | |
10ffbc14 GM |
4581 | fatal ("Cannot connect to X server %s.\n\ |
4582 | Check the DISPLAY environment variable or use `-d'.\n\ | |
842a9389 JB |
4583 | Also use the `xauth' program to verify that you have the proper\n\ |
4584 | authorization information needed to connect the X server.\n\ | |
bf770132 | 4585 | An insecure way to solve the problem may be to use `xhost'.\n", |
d5db4077 | 4586 | SDATA (display)); |
08a90d6a | 4587 | else |
d5db4077 | 4588 | error ("Cannot connect to X server %s", SDATA (display)); |
08a90d6a RS |
4589 | } |
4590 | ||
b9dc4443 | 4591 | XSETFASTINT (Vwindow_system_version, 11); |
01f1ba30 JB |
4592 | return Qnil; |
4593 | } | |
4594 | ||
08a90d6a RS |
4595 | DEFUN ("x-close-connection", Fx_close_connection, |
4596 | Sx_close_connection, 1, 1, 0, | |
00d385b0 | 4597 | doc: /* Close the connection to TERMINAL's X server. |
708e05dc | 4598 | For TERMINAL, specify a terminal object, a frame or a display name (a |
00d385b0 KL |
4599 | string). If TERMINAL is nil, that stands for the selected frame's |
4600 | terminal. */) | |
5842a27b | 4601 | (Lisp_Object terminal) |
01f1ba30 | 4602 | { |
00d385b0 | 4603 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
3457bc6e | 4604 | |
08a90d6a RS |
4605 | if (dpyinfo->reference_count > 0) |
4606 | error ("Display still has frames on it"); | |
01f1ba30 | 4607 | |
6ed8eeff | 4608 | x_delete_terminal (dpyinfo->terminal); |
3457bc6e | 4609 | |
01f1ba30 JB |
4610 | return Qnil; |
4611 | } | |
4612 | ||
08a90d6a | 4613 | DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, |
7ee72033 | 4614 | doc: /* Return the list of display names that Emacs has connections to. */) |
5842a27b | 4615 | (void) |
08a90d6a RS |
4616 | { |
4617 | Lisp_Object tail, result; | |
4618 | ||
4619 | result = Qnil; | |
9beb8baa | 4620 | for (tail = x_display_name_list; CONSP (tail); tail = XCDR (tail)) |
8e713be6 | 4621 | result = Fcons (XCAR (XCAR (tail)), result); |
08a90d6a RS |
4622 | |
4623 | return result; | |
4624 | } | |
4625 | ||
4626 | DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0, | |
7ee72033 | 4627 | doc: /* If ON is non-nil, report X errors as soon as the erring request is made. |
7c051dd8 GM |
4628 | This function only has an effect on X Windows. With MS Windows, it is |
4629 | defined but does nothing. | |
4630 | ||
c061c855 GM |
4631 | If ON is nil, allow buffering of requests. |
4632 | Turning on synchronization prohibits the Xlib routines from buffering | |
4633 | requests and seriously degrades performance, but makes debugging much | |
4634 | easier. | |
00d385b0 | 4635 | The optional second argument TERMINAL specifies which display to act on. |
708e05dc | 4636 | TERMINAL should be a terminal object, a frame or a display name (a string). |
00d385b0 | 4637 | If TERMINAL is omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 4638 | (Lisp_Object on, Lisp_Object terminal) |
01f1ba30 | 4639 | { |
00d385b0 | 4640 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
11ae94fe | 4641 | |
b9dc4443 | 4642 | XSynchronize (dpyinfo->display, !EQ (on, Qnil)); |
01f1ba30 JB |
4643 | |
4644 | return Qnil; | |
4645 | } | |
4646 | ||
b9dc4443 | 4647 | /* Wait for responses to all X commands issued so far for frame F. */ |
6b7b1820 RS |
4648 | |
4649 | void | |
971de7fb | 4650 | x_sync (FRAME_PTR f) |
6b7b1820 | 4651 | { |
4d7e6e51 | 4652 | block_input (); |
b9dc4443 | 4653 | XSync (FRAME_X_DISPLAY (f), False); |
4d7e6e51 | 4654 | unblock_input (); |
6b7b1820 | 4655 | } |
333b20bb | 4656 | |
01f1ba30 | 4657 | \f |
333b20bb | 4658 | /*********************************************************************** |
6b61353c | 4659 | Window properties |
333b20bb | 4660 | ***********************************************************************/ |
f1c16f36 | 4661 | |
6b61353c KH |
4662 | DEFUN ("x-change-window-property", Fx_change_window_property, |
4663 | Sx_change_window_property, 2, 6, 0, | |
4664 | doc: /* Change window property PROP to VALUE on the X window of FRAME. | |
7c051dd8 GM |
4665 | PROP must be a string. VALUE may be a string or a list of conses, |
4666 | numbers and/or strings. If an element in the list is a string, it is | |
4667 | converted to an atom and the value of the atom is used. If an element | |
4668 | is a cons, it is converted to a 32 bit number where the car is the 16 | |
4669 | top bits and the cdr is the lower 16 bits. | |
4670 | ||
6b61353c KH |
4671 | FRAME nil or omitted means use the selected frame. |
4672 | If TYPE is given and non-nil, it is the name of the type of VALUE. | |
4673 | If TYPE is not given or nil, the type is STRING. | |
4674 | FORMAT gives the size in bits of each element if VALUE is a list. | |
4675 | It must be one of 8, 16 or 32. | |
4676 | If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8. | |
fca8d6b6 | 4677 | If OUTER-P is non-nil, the property is changed for the outer X window of |
7c051dd8 | 4678 | FRAME. Default is to change on the edit X window. */) |
fca8d6b6 AS |
4679 | (Lisp_Object prop, Lisp_Object value, Lisp_Object frame, |
4680 | Lisp_Object type, Lisp_Object format, Lisp_Object outer_p) | |
6b61353c | 4681 | { |
7452b7bd | 4682 | struct frame *f = decode_window_system_frame (frame); |
6b61353c KH |
4683 | Atom prop_atom; |
4684 | Atom target_type = XA_STRING; | |
4685 | int element_format = 8; | |
4686 | unsigned char *data; | |
4687 | int nelements; | |
4688 | Window w; | |
333b20bb | 4689 | |
6b61353c | 4690 | CHECK_STRING (prop); |
333b20bb | 4691 | |
6b61353c KH |
4692 | if (! NILP (format)) |
4693 | { | |
4694 | CHECK_NUMBER (format); | |
333b20bb | 4695 | |
d311d28c PE |
4696 | if (XINT (format) != 8 && XINT (format) != 16 |
4697 | && XINT (format) != 32) | |
6b61353c | 4698 | error ("FORMAT must be one of 8, 16 or 32"); |
d311d28c | 4699 | element_format = XINT (format); |
6b61353c | 4700 | } |
333b20bb | 4701 | |
6b61353c KH |
4702 | if (CONSP (value)) |
4703 | { | |
c678c835 PE |
4704 | ptrdiff_t elsize; |
4705 | ||
6b61353c KH |
4706 | nelements = x_check_property_data (value); |
4707 | if (nelements == -1) | |
4708 | error ("Bad data in VALUE, must be number, string or cons"); | |
333b20bb | 4709 | |
c678c835 PE |
4710 | /* The man page for XChangeProperty: |
4711 | "If the specified format is 32, the property data must be a | |
4712 | long array." | |
4713 | This applies even if long is more than 32 bits. The X library | |
4714 | converts to 32 bits before sending to the X server. */ | |
4715 | elsize = element_format == 32 ? sizeof (long) : element_format >> 3; | |
0065d054 | 4716 | data = xnmalloc (nelements, elsize); |
333b20bb | 4717 | |
6b61353c KH |
4718 | x_fill_property_data (FRAME_X_DISPLAY (f), value, data, element_format); |
4719 | } | |
4720 | else | |
4721 | { | |
4722 | CHECK_STRING (value); | |
4723 | data = SDATA (value); | |
c678c835 PE |
4724 | if (INT_MAX < SBYTES (value)) |
4725 | error ("VALUE too long"); | |
4726 | nelements = SBYTES (value); | |
6b61353c | 4727 | } |
333b20bb | 4728 | |
4d7e6e51 | 4729 | block_input (); |
42a5b22f | 4730 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); |
6b61353c KH |
4731 | if (! NILP (type)) |
4732 | { | |
4733 | CHECK_STRING (type); | |
42a5b22f | 4734 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (type), False); |
6b61353c | 4735 | } |
333b20bb | 4736 | |
6b61353c KH |
4737 | if (! NILP (outer_p)) w = FRAME_OUTER_WINDOW (f); |
4738 | else w = FRAME_X_WINDOW (f); | |
5b3f8550 | 4739 | |
6b61353c KH |
4740 | XChangeProperty (FRAME_X_DISPLAY (f), w, |
4741 | prop_atom, target_type, element_format, PropModeReplace, | |
4742 | data, nelements); | |
333b20bb | 4743 | |
6b61353c | 4744 | if (CONSP (value)) xfree (data); |
333b20bb | 4745 | |
6b61353c KH |
4746 | /* Make sure the property is set when we return. */ |
4747 | XFlush (FRAME_X_DISPLAY (f)); | |
4d7e6e51 | 4748 | unblock_input (); |
333b20bb | 4749 | |
6b61353c | 4750 | return value; |
333b20bb GM |
4751 | } |
4752 | ||
4753 | ||
6b61353c KH |
4754 | DEFUN ("x-delete-window-property", Fx_delete_window_property, |
4755 | Sx_delete_window_property, 1, 2, 0, | |
4756 | doc: /* Remove window property PROP from X window of FRAME. | |
4757 | FRAME nil or omitted means use the selected frame. Value is PROP. */) | |
5842a27b | 4758 | (Lisp_Object prop, Lisp_Object frame) |
333b20bb | 4759 | { |
7452b7bd | 4760 | struct frame *f = decode_window_system_frame (frame); |
6b61353c | 4761 | Atom prop_atom; |
333b20bb | 4762 | |
6b61353c | 4763 | CHECK_STRING (prop); |
4d7e6e51 | 4764 | block_input (); |
42a5b22f | 4765 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); |
6b61353c | 4766 | XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom); |
333b20bb | 4767 | |
6b61353c KH |
4768 | /* Make sure the property is removed when we return. */ |
4769 | XFlush (FRAME_X_DISPLAY (f)); | |
4d7e6e51 | 4770 | unblock_input (); |
333b20bb | 4771 | |
6b61353c KH |
4772 | return prop; |
4773 | } | |
333b20bb | 4774 | |
333b20bb | 4775 | |
6b61353c KH |
4776 | DEFUN ("x-window-property", Fx_window_property, Sx_window_property, |
4777 | 1, 6, 0, | |
4778 | doc: /* Value is the value of window property PROP on FRAME. | |
4779 | If FRAME is nil or omitted, use the selected frame. | |
7c051dd8 | 4780 | |
7c051dd8 GM |
4781 | On X Windows, the following optional arguments are also accepted: |
4782 | If TYPE is nil or omitted, get the property as a string. | |
4783 | Otherwise TYPE is the name of the atom that denotes the type expected. | |
6b61353c KH |
4784 | If SOURCE is non-nil, get the property on that window instead of from |
4785 | FRAME. The number 0 denotes the root window. | |
ddadbc0e AS |
4786 | If DELETE-P is non-nil, delete the property after retrieving it. |
4787 | If VECTOR-RET-P is non-nil, don't return a string but a vector of values. | |
4788 | ||
4789 | On MS Windows, this function accepts but ignores those optional arguments. | |
6b61353c KH |
4790 | |
4791 | Value is nil if FRAME hasn't a property with name PROP or if PROP has | |
7c051dd8 | 4792 | no value of TYPE (always string in the MS Windows case). */) |
ddadbc0e AS |
4793 | (Lisp_Object prop, Lisp_Object frame, Lisp_Object type, |
4794 | Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p) | |
333b20bb | 4795 | { |
7452b7bd | 4796 | struct frame *f = decode_window_system_frame (frame); |
6b61353c KH |
4797 | Atom prop_atom; |
4798 | int rc; | |
4799 | Lisp_Object prop_value = Qnil; | |
a3db4b26 | 4800 | unsigned char *tmp_data = NULL; |
6b61353c KH |
4801 | Atom actual_type; |
4802 | Atom target_type = XA_STRING; | |
4803 | int actual_format; | |
4804 | unsigned long actual_size, bytes_remaining; | |
4805 | Window target_window = FRAME_X_WINDOW (f); | |
4806 | struct gcpro gcpro1; | |
177c0ea7 | 4807 | |
6b61353c KH |
4808 | GCPRO1 (prop_value); |
4809 | CHECK_STRING (prop); | |
1783ffa2 | 4810 | |
6b61353c KH |
4811 | if (! NILP (source)) |
4812 | { | |
be44ca6c PE |
4813 | CONS_TO_INTEGER (source, Window, target_window); |
4814 | if (! target_window) | |
4815 | target_window = FRAME_X_DISPLAY_INFO (f)->root_window; | |
333b20bb GM |
4816 | } |
4817 | ||
4d7e6e51 | 4818 | block_input (); |
6b61353c KH |
4819 | if (STRINGP (type)) |
4820 | { | |
42a5b22f | 4821 | if (strcmp ("AnyPropertyType", SSDATA (type)) == 0) |
6b61353c KH |
4822 | target_type = AnyPropertyType; |
4823 | else | |
42a5b22f | 4824 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (type), False); |
6b61353c | 4825 | } |
333b20bb | 4826 | |
42a5b22f | 4827 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); |
6b61353c KH |
4828 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
4829 | prop_atom, 0, 0, False, target_type, | |
4830 | &actual_type, &actual_format, &actual_size, | |
a3db4b26 | 4831 | &bytes_remaining, &tmp_data); |
6b61353c KH |
4832 | if (rc == Success) |
4833 | { | |
4834 | int size = bytes_remaining; | |
333b20bb | 4835 | |
6b61353c KH |
4836 | XFree (tmp_data); |
4837 | tmp_data = NULL; | |
333b20bb | 4838 | |
6b61353c | 4839 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
333b20bb | 4840 | prop_atom, 0, bytes_remaining, |
6b61353c | 4841 | ! NILP (delete_p), target_type, |
177c0ea7 JB |
4842 | &actual_type, &actual_format, |
4843 | &actual_size, &bytes_remaining, | |
a3db4b26 | 4844 | &tmp_data); |
4c8c7926 | 4845 | if (rc == Success && tmp_data) |
6b61353c | 4846 | { |
fede04ef JD |
4847 | /* The man page for XGetWindowProperty says: |
4848 | "If the returned format is 32, the returned data is represented | |
4849 | as a long array and should be cast to that type to obtain the | |
4850 | elements." | |
4851 | This applies even if long is more than 32 bits, the X library | |
4852 | converts from 32 bit elements received from the X server to long | |
72af86bd | 4853 | and passes the long array to us. Thus, for that case memcpy can not |
fede04ef JD |
4854 | be used. We convert to a 32 bit type here, because so much code |
4855 | assume on that. | |
4856 | ||
4857 | The bytes and offsets passed to XGetWindowProperty refers to the | |
4858 | property and those are indeed in 32 bit quantities if format is | |
4859 | 32. */ | |
4860 | ||
908589fd | 4861 | if (BITS_PER_LONG > 32 && actual_format == 32) |
fede04ef JD |
4862 | { |
4863 | unsigned long i; | |
4864 | int *idata = (int *) tmp_data; | |
4865 | long *ldata = (long *) tmp_data; | |
4866 | ||
4867 | for (i = 0; i < actual_size; ++i) | |
a3db4b26 | 4868 | idata[i] = (int) ldata[i]; |
fede04ef JD |
4869 | } |
4870 | ||
6b61353c | 4871 | if (NILP (vector_ret_p)) |
5f742c1b | 4872 | prop_value = make_string ((char *) tmp_data, size); |
6b61353c KH |
4873 | else |
4874 | prop_value = x_property_data_to_lisp (f, | |
a3db4b26 | 4875 | tmp_data, |
6b61353c KH |
4876 | actual_type, |
4877 | actual_format, | |
4878 | actual_size); | |
4879 | } | |
333b20bb | 4880 | |
6b61353c | 4881 | if (tmp_data) XFree (tmp_data); |
333b20bb GM |
4882 | } |
4883 | ||
4d7e6e51 | 4884 | unblock_input (); |
6b61353c | 4885 | UNGCPRO; |
333b20bb GM |
4886 | return prop_value; |
4887 | } | |
4888 | ||
4889 | ||
4890 | \f | |
4891 | /*********************************************************************** | |
4892 | Busy cursor | |
4893 | ***********************************************************************/ | |
4894 | ||
0af913d7 GM |
4895 | /* Timer function of hourglass_atimer. TIMER is equal to |
4896 | hourglass_atimer. | |
4ae9a85e | 4897 | |
0af913d7 GM |
4898 | Display an hourglass pointer on all frames by mapping the frames' |
4899 | hourglass_window. Set the hourglass_p flag in the frames' | |
4900 | output_data.x structure to indicate that an hourglass cursor is | |
4901 | shown on the frames. */ | |
4ae9a85e | 4902 | |
1885ab29 | 4903 | void |
971de7fb | 4904 | show_hourglass (struct atimer *timer) |
4ae9a85e GM |
4905 | { |
4906 | /* The timer implementation will cancel this timer automatically | |
0af913d7 | 4907 | after this function has run. Set hourglass_atimer to null |
4ae9a85e | 4908 | so that we know the timer doesn't have to be canceled. */ |
0af913d7 | 4909 | hourglass_atimer = NULL; |
4ae9a85e | 4910 | |
0af913d7 | 4911 | if (!hourglass_shown_p) |
333b20bb GM |
4912 | { |
4913 | Lisp_Object rest, frame; | |
177c0ea7 | 4914 | |
4d7e6e51 | 4915 | block_input (); |
177c0ea7 | 4916 | |
333b20bb | 4917 | FOR_EACH_FRAME (rest, frame) |
5f7a1890 GM |
4918 | { |
4919 | struct frame *f = XFRAME (frame); | |
177c0ea7 | 4920 | |
5f7a1890 GM |
4921 | if (FRAME_LIVE_P (f) && FRAME_X_P (f) && FRAME_X_DISPLAY (f)) |
4922 | { | |
4923 | Display *dpy = FRAME_X_DISPLAY (f); | |
177c0ea7 | 4924 | |
5f7a1890 GM |
4925 | #ifdef USE_X_TOOLKIT |
4926 | if (f->output_data.x->widget) | |
4927 | #else | |
4928 | if (FRAME_OUTER_WINDOW (f)) | |
4929 | #endif | |
4930 | { | |
0af913d7 | 4931 | f->output_data.x->hourglass_p = 1; |
177c0ea7 | 4932 | |
0af913d7 | 4933 | if (!f->output_data.x->hourglass_window) |
5f7a1890 GM |
4934 | { |
4935 | unsigned long mask = CWCursor; | |
4936 | XSetWindowAttributes attrs; | |
49b8b5dc JD |
4937 | #ifdef USE_GTK |
4938 | Window parent = FRAME_X_WINDOW (f); | |
4939 | #else | |
4940 | Window parent = FRAME_OUTER_WINDOW (f); | |
4941 | #endif | |
0af913d7 | 4942 | attrs.cursor = f->output_data.x->hourglass_cursor; |
177c0ea7 | 4943 | |
0af913d7 | 4944 | f->output_data.x->hourglass_window |
49b8b5dc | 4945 | = XCreateWindow (dpy, parent, |
5f7a1890 GM |
4946 | 0, 0, 32000, 32000, 0, 0, |
4947 | InputOnly, | |
4948 | CopyFromParent, | |
4949 | mask, &attrs); | |
4950 | } | |
177c0ea7 | 4951 | |
0af913d7 | 4952 | XMapRaised (dpy, f->output_data.x->hourglass_window); |
5f7a1890 GM |
4953 | XFlush (dpy); |
4954 | } | |
4955 | } | |
4956 | } | |
333b20bb | 4957 | |
0af913d7 | 4958 | hourglass_shown_p = 1; |
4d7e6e51 | 4959 | unblock_input (); |
4ae9a85e | 4960 | } |
333b20bb GM |
4961 | } |
4962 | ||
4963 | ||
0af913d7 GM |
4964 | /* Hide the hourglass pointer on all frames, if it is currently |
4965 | shown. */ | |
333b20bb | 4966 | |
1885ab29 | 4967 | void |
971de7fb | 4968 | hide_hourglass (void) |
4ae9a85e | 4969 | { |
0af913d7 | 4970 | if (hourglass_shown_p) |
333b20bb | 4971 | { |
4ae9a85e GM |
4972 | Lisp_Object rest, frame; |
4973 | ||
4d7e6e51 | 4974 | block_input (); |
4ae9a85e | 4975 | FOR_EACH_FRAME (rest, frame) |
333b20bb | 4976 | { |
4ae9a85e | 4977 | struct frame *f = XFRAME (frame); |
177c0ea7 | 4978 | |
4ae9a85e GM |
4979 | if (FRAME_X_P (f) |
4980 | /* Watch out for newly created frames. */ | |
0af913d7 | 4981 | && f->output_data.x->hourglass_window) |
4ae9a85e | 4982 | { |
0af913d7 GM |
4983 | XUnmapWindow (FRAME_X_DISPLAY (f), |
4984 | f->output_data.x->hourglass_window); | |
4985 | /* Sync here because XTread_socket looks at the | |
4986 | hourglass_p flag that is reset to zero below. */ | |
4ae9a85e | 4987 | XSync (FRAME_X_DISPLAY (f), False); |
0af913d7 | 4988 | f->output_data.x->hourglass_p = 0; |
4ae9a85e | 4989 | } |
333b20bb | 4990 | } |
333b20bb | 4991 | |
0af913d7 | 4992 | hourglass_shown_p = 0; |
4d7e6e51 | 4993 | unblock_input (); |
4ae9a85e | 4994 | } |
333b20bb GM |
4995 | } |
4996 | ||
4997 | ||
4998 | \f | |
4999 | /*********************************************************************** | |
5000 | Tool tips | |
5001 | ***********************************************************************/ | |
5002 | ||
f57e2426 J |
5003 | static Lisp_Object x_create_tip_frame (struct x_display_info *, |
5004 | Lisp_Object, Lisp_Object); | |
5005 | static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object, | |
5006 | Lisp_Object, int, int, int *, int *); | |
177c0ea7 | 5007 | |
44b5a125 | 5008 | /* The frame of a currently visible tooltip. */ |
333b20bb | 5009 | |
44b5a125 | 5010 | Lisp_Object tip_frame; |
333b20bb GM |
5011 | |
5012 | /* If non-nil, a timer started that hides the last tooltip when it | |
5013 | fires. */ | |
5014 | ||
e4cebfca | 5015 | static Lisp_Object tip_timer; |
333b20bb GM |
5016 | Window tip_window; |
5017 | ||
06d62053 GM |
5018 | /* If non-nil, a vector of 3 elements containing the last args |
5019 | with which x-show-tip was called. See there. */ | |
5020 | ||
e4cebfca | 5021 | static Lisp_Object last_show_tip_args; |
06d62053 | 5022 | |
eaf1eea9 GM |
5023 | |
5024 | static Lisp_Object | |
971de7fb | 5025 | unwind_create_tip_frame (Lisp_Object frame) |
eaf1eea9 | 5026 | { |
c844a81a GM |
5027 | Lisp_Object deleted; |
5028 | ||
5029 | deleted = unwind_create_frame (frame); | |
5030 | if (EQ (deleted, Qt)) | |
5031 | { | |
5032 | tip_window = None; | |
5033 | tip_frame = Qnil; | |
5034 | } | |
177c0ea7 | 5035 | |
c844a81a | 5036 | return deleted; |
eaf1eea9 GM |
5037 | } |
5038 | ||
5039 | ||
333b20bb | 5040 | /* Create a frame for a tooltip on the display described by DPYINFO. |
275841bf GM |
5041 | PARMS is a list of frame parameters. TEXT is the string to |
5042 | display in the tip frame. Value is the frame. | |
eaf1eea9 GM |
5043 | |
5044 | Note that functions called here, esp. x_default_parameter can | |
5045 | signal errors, for instance when a specified color name is | |
5046 | undefined. We have to make sure that we're in a consistent state | |
5047 | when this happens. */ | |
333b20bb GM |
5048 | |
5049 | static Lisp_Object | |
aa1859f5 J |
5050 | x_create_tip_frame (struct x_display_info *dpyinfo, |
5051 | Lisp_Object parms, | |
5052 | Lisp_Object text) | |
333b20bb GM |
5053 | { |
5054 | struct frame *f; | |
06b0c8a0 | 5055 | Lisp_Object frame; |
333b20bb | 5056 | Lisp_Object name; |
333b20bb | 5057 | int width, height; |
d311d28c | 5058 | ptrdiff_t count = SPECPDL_INDEX (); |
b6d7acec | 5059 | struct gcpro gcpro1, gcpro2, gcpro3; |
06d62053 | 5060 | int face_change_count_before = face_change_count; |
275841bf GM |
5061 | Lisp_Object buffer; |
5062 | struct buffer *old_buffer; | |
333b20bb | 5063 | |
89acb56d SM |
5064 | if (!dpyinfo->terminal->name) |
5065 | error ("Terminal is not live, can't create new frames on it"); | |
333b20bb | 5066 | |
47f3c6b4 | 5067 | parms = Fcopy_alist (parms); |
333b20bb GM |
5068 | |
5069 | /* Get the name of the frame to use for resource lookup. */ | |
5070 | name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); | |
5071 | if (!STRINGP (name) | |
5072 | && !EQ (name, Qunbound) | |
5073 | && !NILP (name)) | |
5074 | error ("Invalid frame name--not a string or nil"); | |
333b20bb GM |
5075 | |
5076 | frame = Qnil; | |
5077 | GCPRO3 (parms, name, frame); | |
44b5a125 | 5078 | f = make_frame (1); |
333b20bb | 5079 | XSETFRAME (frame, f); |
275841bf GM |
5080 | |
5081 | buffer = Fget_buffer_create (build_string (" *tip*")); | |
08908aca MR |
5082 | /* Use set_window_buffer instead of Fset_window_buffer (see |
5083 | discussion of bug#11984, bug#12025, bug#12026). */ | |
5084 | set_window_buffer (FRAME_ROOT_WINDOW (f), buffer, 0, 0); | |
275841bf GM |
5085 | old_buffer = current_buffer; |
5086 | set_buffer_internal_1 (XBUFFER (buffer)); | |
39eb03f1 | 5087 | bset_truncate_lines (current_buffer, Qnil); |
5c2a995d KH |
5088 | specbind (Qinhibit_read_only, Qt); |
5089 | specbind (Qinhibit_modification_hooks, Qt); | |
275841bf GM |
5090 | Ferase_buffer (); |
5091 | Finsert (1, &text); | |
5092 | set_buffer_internal_1 (old_buffer); | |
177c0ea7 | 5093 | |
8a1a7743 | 5094 | record_unwind_protect (unwind_create_tip_frame, frame); |
333b20bb | 5095 | |
6ed8eeff | 5096 | f->terminal = dpyinfo->terminal; |
daf01701 | 5097 | |
eaf1eea9 GM |
5098 | /* By setting the output method, we're essentially saying that |
5099 | the frame is live, as per FRAME_LIVE_P. If we get a signal | |
5100 | from this point on, x_destroy_window might screw up reference | |
5101 | counts etc. */ | |
333b20bb | 5102 | f->output_method = output_x_window; |
38182d90 | 5103 | f->output_data.x = xzalloc (sizeof *f->output_data.x); |
333b20bb | 5104 | f->output_data.x->icon_bitmap = -1; |
be786000 | 5105 | FRAME_FONTSET (f) = -1; |
61d461a8 GM |
5106 | f->output_data.x->scroll_bar_foreground_pixel = -1; |
5107 | f->output_data.x->scroll_bar_background_pixel = -1; | |
f15340b7 MB |
5108 | #ifdef USE_TOOLKIT_SCROLL_BARS |
5109 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
5110 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
5111 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
f00af5b1 | 5112 | fset_icon_name (f, Qnil); |
333b20bb | 5113 | FRAME_X_DISPLAY_INFO (f) = dpyinfo; |
333b20bb GM |
5114 | f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; |
5115 | f->output_data.x->explicit_parent = 0; | |
5116 | ||
61d461a8 GM |
5117 | /* These colors will be set anyway later, but it's important |
5118 | to get the color reference counts right, so initialize them! */ | |
5119 | { | |
5120 | Lisp_Object black; | |
dbf31225 | 5121 | struct gcpro gcpro1; |
177c0ea7 | 5122 | |
9d3d44ba KL |
5123 | /* Function x_decode_color can signal an error. Make |
5124 | sure to initialize color slots so that we won't try | |
5125 | to free colors we haven't allocated. */ | |
ce593f6e KL |
5126 | FRAME_FOREGROUND_PIXEL (f) = -1; |
5127 | FRAME_BACKGROUND_PIXEL (f) = -1; | |
9d3d44ba KL |
5128 | f->output_data.x->cursor_pixel = -1; |
5129 | f->output_data.x->cursor_foreground_pixel = -1; | |
5130 | f->output_data.x->border_pixel = -1; | |
5131 | f->output_data.x->mouse_pixel = -1; | |
5132 | ||
61d461a8 | 5133 | black = build_string ("black"); |
dbf31225 | 5134 | GCPRO1 (black); |
ce593f6e | 5135 | FRAME_FOREGROUND_PIXEL (f) |
61d461a8 | 5136 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
ce593f6e | 5137 | FRAME_BACKGROUND_PIXEL (f) |
61d461a8 GM |
5138 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
5139 | f->output_data.x->cursor_pixel | |
5140 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
5141 | f->output_data.x->cursor_foreground_pixel | |
5142 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
5143 | f->output_data.x->border_pixel | |
5144 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
5145 | f->output_data.x->mouse_pixel | |
5146 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
dbf31225 | 5147 | UNGCPRO; |
61d461a8 GM |
5148 | } |
5149 | ||
333b20bb GM |
5150 | /* Set the name; the functions to which we pass f expect the name to |
5151 | be set. */ | |
5152 | if (EQ (name, Qunbound) || NILP (name)) | |
5153 | { | |
f00af5b1 | 5154 | fset_name (f, build_string (dpyinfo->x_id_name)); |
333b20bb GM |
5155 | f->explicit_name = 0; |
5156 | } | |
5157 | else | |
5158 | { | |
f00af5b1 | 5159 | fset_name (f, name); |
333b20bb GM |
5160 | f->explicit_name = 1; |
5161 | /* use the frame's title when getting resources for this frame. */ | |
5162 | specbind (Qx_resource_name, name); | |
5163 | } | |
5164 | ||
bf970f2b | 5165 | register_font_driver (&xfont_driver, f); |
02ed2ea8 KH |
5166 | #ifdef HAVE_FREETYPE |
5167 | #ifdef HAVE_XFT | |
b51238f5 | 5168 | register_font_driver (&xftfont_driver, f); |
02ed2ea8 | 5169 | #else /* not HAVE_XFT */ |
b51238f5 | 5170 | register_font_driver (&ftxfont_driver, f); |
02ed2ea8 KH |
5171 | #endif /* not HAVE_XFT */ |
5172 | #endif /* HAVE_FREETYPE */ | |
d43f6b74 | 5173 | |
b51238f5 KH |
5174 | x_default_parameter (f, parms, Qfont_backend, Qnil, |
5175 | "fontBackend", "FontBackend", RES_TYPE_STRING); | |
02ed2ea8 | 5176 | |
eaf1eea9 GM |
5177 | /* Extract the window parameters from the supplied values that are |
5178 | needed to determine window geometry. */ | |
b51238f5 | 5179 | x_default_font_parameter (f, parms); |
333b20bb | 5180 | |
4bef8d26 | 5181 | x_default_parameter (f, parms, Qborder_width, make_number (0), |
333b20bb | 5182 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); |
177c0ea7 | 5183 | |
333b20bb GM |
5184 | /* This defaults to 2 in order to match xterm. We recognize either |
5185 | internalBorderWidth or internalBorder (which is what xterm calls | |
5186 | it). */ | |
5187 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
5188 | { | |
5189 | Lisp_Object value; | |
5190 | ||
5191 | value = x_get_arg (dpyinfo, parms, Qinternal_border_width, | |
5192 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); | |
5193 | if (! EQ (value, Qunbound)) | |
5194 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
5195 | parms); | |
5196 | } | |
5197 | ||
5198 | x_default_parameter (f, parms, Qinternal_border_width, make_number (1), | |
5199 | "internalBorderWidth", "internalBorderWidth", | |
5200 | RES_TYPE_NUMBER); | |
5201 | ||
5202 | /* Also do the stuff which must be set before the window exists. */ | |
5203 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), | |
5204 | "foreground", "Foreground", RES_TYPE_STRING); | |
5205 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), | |
5206 | "background", "Background", RES_TYPE_STRING); | |
5207 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), | |
5208 | "pointerColor", "Foreground", RES_TYPE_STRING); | |
5209 | x_default_parameter (f, parms, Qcursor_color, build_string ("black"), | |
5210 | "cursorColor", "Foreground", RES_TYPE_STRING); | |
5211 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), | |
5212 | "borderColor", "BorderColor", RES_TYPE_STRING); | |
5213 | ||
e509cfa6 | 5214 | #ifdef GLYPH_DEBUG |
c9e7db78 JD |
5215 | image_cache_refcount = |
5216 | FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0; | |
5217 | dpyinfo_refcount = dpyinfo->reference_count; | |
5218 | #endif /* GLYPH_DEBUG */ | |
5219 | ||
333b20bb GM |
5220 | /* Init faces before x_default_parameter is called for scroll-bar |
5221 | parameters because that function calls x_set_scroll_bar_width, | |
5222 | which calls change_frame_size, which calls Fset_window_buffer, | |
5223 | which runs hooks, which call Fvertical_motion. At the end, we | |
5224 | end up in init_iterator with a null face cache, which should not | |
5225 | happen. */ | |
5226 | init_frame_faces (f); | |
177c0ea7 | 5227 | |
333b20bb | 5228 | f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; |
333b20bb | 5229 | |
0ce7538d | 5230 | x_figure_window_size (f, parms, 0); |
333b20bb | 5231 | |
333b20bb GM |
5232 | { |
5233 | XSetWindowAttributes attrs; | |
5234 | unsigned long mask; | |
36acb2a7 | 5235 | Atom type = FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip; |
177c0ea7 | 5236 | |
4d7e6e51 | 5237 | block_input (); |
c51d2b5e GM |
5238 | mask = CWBackPixel | CWOverrideRedirect | CWEventMask; |
5239 | if (DoesSaveUnders (dpyinfo->screen)) | |
5240 | mask |= CWSaveUnder; | |
177c0ea7 | 5241 | |
9b2956e2 GM |
5242 | /* Window managers look at the override-redirect flag to determine |
5243 | whether or net to give windows a decoration (Xlib spec, chapter | |
333b20bb GM |
5244 | 3.2.8). */ |
5245 | attrs.override_redirect = True; | |
5246 | attrs.save_under = True; | |
5247 | attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f); | |
5248 | /* Arrange for getting MapNotify and UnmapNotify events. */ | |
5249 | attrs.event_mask = StructureNotifyMask; | |
5250 | tip_window | |
5251 | = FRAME_X_WINDOW (f) | |
5252 | = XCreateWindow (FRAME_X_DISPLAY (f), | |
5253 | FRAME_X_DISPLAY_INFO (f)->root_window, | |
5254 | /* x, y, width, height */ | |
5255 | 0, 0, 1, 1, | |
5256 | /* Border. */ | |
a979dde1 | 5257 | f->border_width, |
333b20bb GM |
5258 | CopyFromParent, InputOutput, CopyFromParent, |
5259 | mask, &attrs); | |
36acb2a7 JD |
5260 | XChangeProperty (FRAME_X_DISPLAY (f), tip_window, |
5261 | FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type, | |
5262 | XA_ATOM, 32, PropModeReplace, | |
5263 | (unsigned char *)&type, 1); | |
4d7e6e51 | 5264 | unblock_input (); |
333b20bb GM |
5265 | } |
5266 | ||
5267 | x_make_gc (f); | |
5268 | ||
333b20bb GM |
5269 | x_default_parameter (f, parms, Qauto_raise, Qnil, |
5270 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
5271 | x_default_parameter (f, parms, Qauto_lower, Qnil, | |
5272 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
5273 | x_default_parameter (f, parms, Qcursor_type, Qbox, | |
5274 | "cursorType", "CursorType", RES_TYPE_SYMBOL); | |
5275 | ||
be786000 | 5276 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
333b20bb | 5277 | Change will not be effected unless different from the current |
be786000 KS |
5278 | FRAME_LINES (f). */ |
5279 | width = FRAME_COLS (f); | |
5280 | height = FRAME_LINES (f); | |
5281 | SET_FRAME_COLS (f, 0); | |
5282 | FRAME_LINES (f) = 0; | |
8938a4fb | 5283 | change_frame_size (f, height, width, 1, 0, 0); |
177c0ea7 | 5284 | |
cd1d850f | 5285 | /* Add `tooltip' frame parameter's default value. */ |
54ee7410 CY |
5286 | if (NILP (Fframe_parameter (frame, Qtooltip))) |
5287 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qtooltip, Qt), Qnil)); | |
177c0ea7 | 5288 | |
cedb4d8b GM |
5289 | /* FIXME - can this be done in a similar way to normal frames? |
5290 | http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */ | |
5291 | ||
35fdaa62 GM |
5292 | /* Set the `display-type' frame parameter before setting up faces. */ |
5293 | { | |
5294 | Lisp_Object disptype; | |
5295 | ||
5296 | if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1) | |
5297 | disptype = intern ("mono"); | |
219ccf1b RS |
5298 | else if (FRAME_X_DISPLAY_INFO (f)->visual->class == GrayScale |
5299 | || FRAME_X_DISPLAY_INFO (f)->visual->class == StaticGray) | |
35fdaa62 GM |
5300 | disptype = intern ("grayscale"); |
5301 | else | |
5302 | disptype = intern ("color"); | |
5303 | ||
5304 | if (NILP (Fframe_parameter (frame, Qdisplay_type))) | |
5305 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qdisplay_type, disptype), | |
5306 | Qnil)); | |
5307 | } | |
5308 | ||
035d5114 | 5309 | /* Set up faces after all frame parameters are known. This call |
6801a572 GM |
5310 | also merges in face attributes specified for new frames. |
5311 | ||
5312 | Frame parameters may be changed if .Xdefaults contains | |
5313 | specifications for the default font. For example, if there is an | |
5314 | `Emacs.default.attributeBackground: pink', the `background-color' | |
5315 | attribute of the frame get's set, which let's the internal border | |
5316 | of the tooltip frame appear in pink. Prevent this. */ | |
5317 | { | |
5318 | Lisp_Object bg = Fframe_parameter (frame, Qbackground_color); | |
5319 | ||
5320 | /* Set tip_frame here, so that */ | |
5321 | tip_frame = frame; | |
45cebfd9 | 5322 | call2 (Qface_set_after_frame_default, frame, Qnil); |
177c0ea7 | 5323 | |
6801a572 GM |
5324 | if (!EQ (bg, Fframe_parameter (frame, Qbackground_color))) |
5325 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg), | |
5326 | Qnil)); | |
5327 | } | |
177c0ea7 | 5328 | |
333b20bb GM |
5329 | f->no_split = 1; |
5330 | ||
5331 | UNGCPRO; | |
5332 | ||
c9e7db78 JD |
5333 | /* Now that the frame will be official, it counts as a reference to |
5334 | its display and terminal. */ | |
5335 | FRAME_X_DISPLAY_INFO (f)->reference_count++; | |
5336 | f->terminal->reference_count++; | |
5337 | ||
333b20bb GM |
5338 | /* It is now ok to make the frame official even if we get an error |
5339 | below. And the frame needs to be on Vframe_list or making it | |
5340 | visible won't work. */ | |
5341 | Vframe_list = Fcons (frame, Vframe_list); | |
5342 | ||
333b20bb | 5343 | |
06d62053 GM |
5344 | /* Setting attributes of faces of the tooltip frame from resources |
5345 | and similar will increment face_change_count, which leads to the | |
5346 | clearing of all current matrices. Since this isn't necessary | |
5347 | here, avoid it by resetting face_change_count to the value it | |
5348 | had before we created the tip frame. */ | |
5349 | face_change_count = face_change_count_before; | |
5350 | ||
eaf1eea9 | 5351 | /* Discard the unwind_protect. */ |
333b20bb GM |
5352 | return unbind_to (count, frame); |
5353 | } | |
5354 | ||
5355 | ||
06d62053 GM |
5356 | /* Compute where to display tip frame F. PARMS is the list of frame |
5357 | parameters for F. DX and DY are specified offsets from the current | |
ab452f99 GM |
5358 | location of the mouse. WIDTH and HEIGHT are the width and height |
5359 | of the tooltip. Return coordinates relative to the root window of | |
5360 | the display in *ROOT_X, and *ROOT_Y. */ | |
06d62053 GM |
5361 | |
5362 | static void | |
971de7fb | 5363 | compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object dy, int width, int height, int *root_x, int *root_y) |
06d62053 GM |
5364 | { |
5365 | Lisp_Object left, top; | |
5366 | int win_x, win_y; | |
5367 | Window root, child; | |
5368 | unsigned pmask; | |
177c0ea7 | 5369 | |
06d62053 GM |
5370 | /* User-specified position? */ |
5371 | left = Fcdr (Fassq (Qleft, parms)); | |
5372 | top = Fcdr (Fassq (Qtop, parms)); | |
177c0ea7 | 5373 | |
06d62053 GM |
5374 | /* Move the tooltip window where the mouse pointer is. Resize and |
5375 | show it. */ | |
570d22b0 | 5376 | if (!INTEGERP (left) || !INTEGERP (top)) |
ab452f99 | 5377 | { |
4d7e6e51 | 5378 | block_input (); |
ab452f99 GM |
5379 | XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, |
5380 | &root, &child, root_x, root_y, &win_x, &win_y, &pmask); | |
4d7e6e51 | 5381 | unblock_input (); |
ab452f99 | 5382 | } |
06d62053 | 5383 | |
06d62053 GM |
5384 | if (INTEGERP (top)) |
5385 | *root_y = XINT (top); | |
bf63eb69 JD |
5386 | else if (*root_y + XINT (dy) <= 0) |
5387 | *root_y = 0; /* Can happen for negative dy */ | |
abe9d29c CY |
5388 | else if (*root_y + XINT (dy) + height |
5389 | <= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f))) | |
7e8410d1 | 5390 | /* It fits below the pointer */ |
abe9d29c | 5391 | *root_y += XINT (dy); |
7e8410d1 JD |
5392 | else if (height + XINT (dy) <= *root_y) |
5393 | /* It fits above the pointer. */ | |
5394 | *root_y -= height + XINT (dy); | |
5395 | else | |
5396 | /* Put it on the top. */ | |
5397 | *root_y = 0; | |
ab452f99 GM |
5398 | |
5399 | if (INTEGERP (left)) | |
5400 | *root_x = XINT (left); | |
bf63eb69 JD |
5401 | else if (*root_x + XINT (dx) <= 0) |
5402 | *root_x = 0; /* Can happen for negative dx */ | |
abe9d29c CY |
5403 | else if (*root_x + XINT (dx) + width |
5404 | <= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f))) | |
d682d3df RS |
5405 | /* It fits to the right of the pointer. */ |
5406 | *root_x += XINT (dx); | |
5407 | else if (width + XINT (dx) <= *root_x) | |
5408 | /* It fits to the left of the pointer. */ | |
ab452f99 GM |
5409 | *root_x -= width + XINT (dx); |
5410 | else | |
d682d3df RS |
5411 | /* Put it left-justified on the screen--it ought to fit that way. */ |
5412 | *root_x = 0; | |
06d62053 GM |
5413 | } |
5414 | ||
5415 | ||
0634ce98 | 5416 | DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, |
7ee72033 | 5417 | doc: /* Show STRING in a "tooltip" window on frame FRAME. |
c061c855 GM |
5418 | A tooltip window is a small X window displaying a string. |
5419 | ||
87c891c7 EZ |
5420 | This is an internal function; Lisp code should call `tooltip-show'. |
5421 | ||
c061c855 GM |
5422 | FRAME nil or omitted means use the selected frame. |
5423 | ||
5424 | PARMS is an optional list of frame parameters which can be used to | |
5425 | change the tooltip's appearance. | |
5426 | ||
5427 | Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil | |
5428 | means use the default timeout of 5 seconds. | |
5429 | ||
c869cc37 | 5430 | If the list of frame parameters PARMS contains a `left' parameters, |
c061c855 GM |
5431 | the tooltip is displayed at that x-position. Otherwise it is |
5432 | displayed at the mouse position, with offset DX added (default is 5 if | |
5433 | DX isn't specified). Likewise for the y-position; if a `top' frame | |
5434 | parameter is specified, it determines the y-position of the tooltip | |
5435 | window, otherwise it is displayed at the mouse position, with offset | |
5436 | DY added (default is -10). | |
5437 | ||
5438 | A tooltip's maximum size is specified by `x-max-tooltip-size'. | |
7ee72033 | 5439 | Text larger than the specified size is clipped. */) |
5842a27b | 5440 | (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy) |
333b20bb GM |
5441 | { |
5442 | struct frame *f; | |
5443 | struct window *w; | |
06d62053 | 5444 | int root_x, root_y; |
333b20bb GM |
5445 | struct buffer *old_buffer; |
5446 | struct text_pos pos; | |
a971c0a7 | 5447 | int i, width, height, seen_reversed_p; |
393f2d14 | 5448 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
333b20bb | 5449 | int old_windows_or_buffers_changed = windows_or_buffers_changed; |
d311d28c | 5450 | ptrdiff_t count = SPECPDL_INDEX (); |
177c0ea7 | 5451 | |
333b20bb GM |
5452 | specbind (Qinhibit_redisplay, Qt); |
5453 | ||
393f2d14 | 5454 | GCPRO4 (string, parms, frame, timeout); |
333b20bb | 5455 | |
b7826503 | 5456 | CHECK_STRING (string); |
2d7117fe JD |
5457 | if (SCHARS (string) == 0) |
5458 | string = make_unibyte_string (" ", 1); | |
5459 | ||
7452b7bd | 5460 | f = decode_window_system_frame (frame); |
333b20bb GM |
5461 | if (NILP (timeout)) |
5462 | timeout = make_number (5); | |
5463 | else | |
b7826503 | 5464 | CHECK_NATNUM (timeout); |
177c0ea7 | 5465 | |
0634ce98 GM |
5466 | if (NILP (dx)) |
5467 | dx = make_number (5); | |
5468 | else | |
b7826503 | 5469 | CHECK_NUMBER (dx); |
177c0ea7 | 5470 | |
0634ce98 | 5471 | if (NILP (dy)) |
12c67a7f | 5472 | dy = make_number (-10); |
0634ce98 | 5473 | else |
b7826503 | 5474 | CHECK_NUMBER (dy); |
333b20bb | 5475 | |
aa1859f5 J |
5476 | #ifdef USE_GTK |
5477 | if (x_gtk_use_system_tooltips) | |
5478 | { | |
18e27ea8 | 5479 | bool ok; |
aa1859f5 J |
5480 | |
5481 | /* Hide a previous tip, if any. */ | |
5482 | Fx_hide_tip (); | |
5483 | ||
4d7e6e51 | 5484 | block_input (); |
18e27ea8 PE |
5485 | ok = xg_prepare_tooltip (f, string, &width, &height); |
5486 | if (ok) | |
aa1859f5 J |
5487 | { |
5488 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); | |
5489 | xg_show_tooltip (f, root_x, root_y); | |
5490 | /* This is used in Fx_hide_tip. */ | |
5491 | XSETFRAME (tip_frame, f); | |
5492 | } | |
4d7e6e51 | 5493 | unblock_input (); |
aa1859f5 J |
5494 | if (ok) goto start_timer; |
5495 | } | |
5496 | #endif /* USE_GTK */ | |
5497 | ||
06d62053 GM |
5498 | if (NILP (last_show_tip_args)) |
5499 | last_show_tip_args = Fmake_vector (make_number (3), Qnil); | |
5500 | ||
5501 | if (!NILP (tip_frame)) | |
5502 | { | |
5503 | Lisp_Object last_string = AREF (last_show_tip_args, 0); | |
5504 | Lisp_Object last_frame = AREF (last_show_tip_args, 1); | |
5505 | Lisp_Object last_parms = AREF (last_show_tip_args, 2); | |
5506 | ||
5507 | if (EQ (frame, last_frame) | |
5508 | && !NILP (Fequal (last_string, string)) | |
5509 | && !NILP (Fequal (last_parms, parms))) | |
5510 | { | |
58d2d479 | 5511 | struct frame *tip_f = XFRAME (tip_frame); |
177c0ea7 | 5512 | |
06d62053 GM |
5513 | /* Only DX and DY have changed. */ |
5514 | if (!NILP (tip_timer)) | |
ae782866 GM |
5515 | { |
5516 | Lisp_Object timer = tip_timer; | |
5517 | tip_timer = Qnil; | |
5518 | call1 (Qcancel_timer, timer); | |
5519 | } | |
06d62053 | 5520 | |
4d7e6e51 | 5521 | block_input (); |
58d2d479 PE |
5522 | compute_tip_xy (tip_f, parms, dx, dy, FRAME_PIXEL_WIDTH (tip_f), |
5523 | FRAME_PIXEL_HEIGHT (tip_f), &root_x, &root_y); | |
5524 | XMoveWindow (FRAME_X_DISPLAY (tip_f), FRAME_X_WINDOW (tip_f), | |
ab452f99 | 5525 | root_x, root_y); |
4d7e6e51 | 5526 | unblock_input (); |
06d62053 GM |
5527 | goto start_timer; |
5528 | } | |
5529 | } | |
5530 | ||
333b20bb GM |
5531 | /* Hide a previous tip, if any. */ |
5532 | Fx_hide_tip (); | |
5533 | ||
06d62053 GM |
5534 | ASET (last_show_tip_args, 0, string); |
5535 | ASET (last_show_tip_args, 1, frame); | |
5536 | ASET (last_show_tip_args, 2, parms); | |
5537 | ||
333b20bb GM |
5538 | /* Add default values to frame parameters. */ |
5539 | if (NILP (Fassq (Qname, parms))) | |
5540 | parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms); | |
5541 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
5542 | parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms); | |
5543 | if (NILP (Fassq (Qborder_width, parms))) | |
5544 | parms = Fcons (Fcons (Qborder_width, make_number (1)), parms); | |
5545 | if (NILP (Fassq (Qborder_color, parms))) | |
5546 | parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms); | |
5547 | if (NILP (Fassq (Qbackground_color, parms))) | |
5548 | parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")), | |
5549 | parms); | |
5550 | ||
5551 | /* Create a frame for the tooltip, and record it in the global | |
5552 | variable tip_frame. */ | |
275841bf | 5553 | frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms, string); |
44b5a125 | 5554 | f = XFRAME (frame); |
333b20bb | 5555 | |
d63931a2 | 5556 | /* Set up the frame's root window. */ |
333b20bb | 5557 | w = XWINDOW (FRAME_ROOT_WINDOW (f)); |
5f24fa51 DA |
5558 | w->left_col = 0; |
5559 | w->top_line = 0; | |
177c0ea7 | 5560 | |
d63931a2 | 5561 | if (CONSP (Vx_max_tooltip_size) |
d311d28c PE |
5562 | && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size), INT_MAX) |
5563 | && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size), INT_MAX)) | |
d63931a2 | 5564 | { |
5f24fa51 DA |
5565 | w->total_cols = XFASTINT (XCAR (Vx_max_tooltip_size)); |
5566 | w->total_lines = XFASTINT (XCDR (Vx_max_tooltip_size)); | |
d63931a2 GM |
5567 | } |
5568 | else | |
5569 | { | |
5f24fa51 DA |
5570 | w->total_cols = 80; |
5571 | w->total_lines = 40; | |
d63931a2 | 5572 | } |
177c0ea7 | 5573 | |
5f24fa51 | 5574 | FRAME_TOTAL_COLS (f) = w->total_cols; |
333b20bb GM |
5575 | adjust_glyphs (f); |
5576 | w->pseudo_window_p = 1; | |
5577 | ||
5578 | /* Display the tooltip text in a temporary buffer. */ | |
333b20bb | 5579 | old_buffer = current_buffer; |
e74aeda8 | 5580 | set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->contents)); |
39eb03f1 | 5581 | bset_truncate_lines (current_buffer, Qnil); |
5634ff85 YM |
5582 | clear_glyph_matrix (w->desired_matrix); |
5583 | clear_glyph_matrix (w->current_matrix); | |
5584 | SET_TEXT_POS (pos, BEGV, BEGV_BYTE); | |
6eff5c3d | 5585 | try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); |
333b20bb GM |
5586 | |
5587 | /* Compute width and height of the tooltip. */ | |
a971c0a7 | 5588 | width = height = seen_reversed_p = 0; |
333b20bb GM |
5589 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
5590 | { | |
5591 | struct glyph_row *row = &w->desired_matrix->rows[i]; | |
5592 | struct glyph *last; | |
5593 | int row_width; | |
5594 | ||
5595 | /* Stop at the first empty row at the end. */ | |
138c0ae8 | 5596 | if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row)) |
333b20bb GM |
5597 | break; |
5598 | ||
d7bf0342 GM |
5599 | /* Let the row go over the full width of the frame. */ |
5600 | row->full_width_p = 1; | |
333b20bb | 5601 | |
5b253e9c | 5602 | row_width = row->pixel_width; |
333b20bb GM |
5603 | if (row->used[TEXT_AREA]) |
5604 | { | |
a971c0a7 EZ |
5605 | /* There's a glyph at the end of rows that is used to place |
5606 | the cursor there. Don't include the width of this glyph. */ | |
5607 | if (!row->reversed_p) | |
5608 | { | |
5609 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
5610 | if (INTEGERP (last->object)) | |
5611 | row_width -= last->pixel_width; | |
5612 | } | |
5613 | else | |
5614 | { | |
5615 | /* There could be a stretch glyph at the beginning of R2L | |
5616 | rows that is produced by extend_face_to_end_of_line. | |
5617 | Don't count that glyph. */ | |
5618 | struct glyph *g = row->glyphs[TEXT_AREA]; | |
5619 | ||
5620 | if (g->type == STRETCH_GLYPH && INTEGERP (g->object)) | |
5621 | { | |
5622 | row_width -= g->pixel_width; | |
5623 | seen_reversed_p = 1; | |
5624 | } | |
5625 | } | |
333b20bb | 5626 | } |
177c0ea7 | 5627 | |
333b20bb GM |
5628 | height += row->height; |
5629 | width = max (width, row_width); | |
5630 | } | |
5631 | ||
a971c0a7 EZ |
5632 | /* If we've seen partial-length R2L rows, we need to re-adjust the |
5633 | tool-tip frame width and redisplay it again, to avoid over-wide | |
5634 | tips due to the stretch glyph that extends R2L lines to full | |
5635 | width of the frame. */ | |
5636 | if (seen_reversed_p) | |
5637 | { | |
5638 | /* w->total_cols and FRAME_TOTAL_COLS want the width in columns, | |
5639 | not in pixels. */ | |
5640 | width /= WINDOW_FRAME_COLUMN_WIDTH (w); | |
5f24fa51 | 5641 | w->total_cols = width; |
a971c0a7 EZ |
5642 | FRAME_TOTAL_COLS (f) = width; |
5643 | adjust_glyphs (f); | |
5644 | clear_glyph_matrix (w->desired_matrix); | |
5645 | clear_glyph_matrix (w->current_matrix); | |
5646 | try_window (FRAME_ROOT_WINDOW (f), pos, 0); | |
5647 | width = height = 0; | |
5648 | /* Recompute width and height of the tooltip. */ | |
5649 | for (i = 0; i < w->desired_matrix->nrows; ++i) | |
5650 | { | |
5651 | struct glyph_row *row = &w->desired_matrix->rows[i]; | |
5652 | struct glyph *last; | |
5653 | int row_width; | |
5654 | ||
138c0ae8 | 5655 | if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row)) |
a971c0a7 EZ |
5656 | break; |
5657 | row->full_width_p = 1; | |
5658 | row_width = row->pixel_width; | |
5659 | if (row->used[TEXT_AREA] && !row->reversed_p) | |
5660 | { | |
5661 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
5662 | if (INTEGERP (last->object)) | |
5663 | row_width -= last->pixel_width; | |
5664 | } | |
5665 | ||
5666 | height += row->height; | |
5667 | width = max (width, row_width); | |
5668 | } | |
5669 | } | |
5670 | ||
333b20bb GM |
5671 | /* Add the frame's internal border to the width and height the X |
5672 | window should have. */ | |
5673 | height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
5674 | width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
5675 | ||
5676 | /* Move the tooltip window where the mouse pointer is. Resize and | |
5677 | show it. */ | |
ab452f99 | 5678 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); |
0634ce98 | 5679 | |
4d7e6e51 | 5680 | block_input (); |
333b20bb | 5681 | XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
ab452f99 | 5682 | root_x, root_y, width, height); |
333b20bb | 5683 | XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
4d7e6e51 | 5684 | unblock_input (); |
177c0ea7 | 5685 | |
333b20bb GM |
5686 | /* Draw into the window. */ |
5687 | w->must_be_updated_p = 1; | |
5688 | update_single_window (w, 1); | |
5689 | ||
5690 | /* Restore original current buffer. */ | |
5691 | set_buffer_internal_1 (old_buffer); | |
5692 | windows_or_buffers_changed = old_windows_or_buffers_changed; | |
5693 | ||
06d62053 | 5694 | start_timer: |
333b20bb GM |
5695 | /* Let the tip disappear after timeout seconds. */ |
5696 | tip_timer = call3 (intern ("run-at-time"), timeout, Qnil, | |
5697 | intern ("x-hide-tip")); | |
a744a2ec DL |
5698 | |
5699 | UNGCPRO; | |
333b20bb GM |
5700 | return unbind_to (count, Qnil); |
5701 | } | |
5702 | ||
5703 | ||
a7ca3326 | 5704 | DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0, |
7ee72033 MB |
5705 | doc: /* Hide the current tooltip window, if there is any. |
5706 | Value is t if tooltip was open, nil otherwise. */) | |
5842a27b | 5707 | (void) |
333b20bb | 5708 | { |
d311d28c | 5709 | ptrdiff_t count; |
c0006262 GM |
5710 | Lisp_Object deleted, frame, timer; |
5711 | struct gcpro gcpro1, gcpro2; | |
44b5a125 GM |
5712 | |
5713 | /* Return quickly if nothing to do. */ | |
c0006262 | 5714 | if (NILP (tip_timer) && NILP (tip_frame)) |
44b5a125 | 5715 | return Qnil; |
177c0ea7 | 5716 | |
c0006262 GM |
5717 | frame = tip_frame; |
5718 | timer = tip_timer; | |
5719 | GCPRO2 (frame, timer); | |
5720 | tip_frame = tip_timer = deleted = Qnil; | |
177c0ea7 | 5721 | |
331379bf | 5722 | count = SPECPDL_INDEX (); |
333b20bb | 5723 | specbind (Qinhibit_redisplay, Qt); |
44b5a125 | 5724 | specbind (Qinhibit_quit, Qt); |
177c0ea7 | 5725 | |
c0006262 | 5726 | if (!NILP (timer)) |
ae782866 | 5727 | call1 (Qcancel_timer, timer); |
333b20bb | 5728 | |
aa1859f5 | 5729 | #ifdef USE_GTK |
1fe72bf8 PE |
5730 | { |
5731 | /* When using system tooltip, tip_frame is the Emacs frame on which | |
5732 | the tip is shown. */ | |
5733 | struct frame *f = XFRAME (frame); | |
5734 | if (FRAME_LIVE_P (f) && xg_hide_tooltip (f)) | |
5735 | frame = Qnil; | |
5736 | } | |
aa1859f5 J |
5737 | #endif |
5738 | ||
c0006262 | 5739 | if (FRAMEP (frame)) |
333b20bb | 5740 | { |
56f2de10 | 5741 | delete_frame (frame, Qnil); |
44b5a125 | 5742 | deleted = Qt; |
f6c44811 GM |
5743 | |
5744 | #ifdef USE_LUCID | |
5745 | /* Bloodcurdling hack alert: The Lucid menu bar widget's | |
5746 | redisplay procedure is not called when a tip frame over menu | |
5747 | items is unmapped. Redisplay the menu manually... */ | |
5748 | { | |
aa1859f5 | 5749 | Widget w; |
1fe72bf8 | 5750 | struct frame *f = SELECTED_FRAME (); |
aa1859f5 | 5751 | w = f->output_data.x->menubar_widget; |
9180dc8c | 5752 | |
f6c44811 | 5753 | if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen) |
dbc64aa7 | 5754 | && w != NULL) |
f6c44811 | 5755 | { |
4d7e6e51 | 5756 | block_input (); |
f6c44811 | 5757 | xlwmenu_redisplay (w); |
4d7e6e51 | 5758 | unblock_input (); |
f6c44811 GM |
5759 | } |
5760 | } | |
5761 | #endif /* USE_LUCID */ | |
333b20bb GM |
5762 | } |
5763 | ||
c0006262 | 5764 | UNGCPRO; |
44b5a125 | 5765 | return unbind_to (count, deleted); |
333b20bb GM |
5766 | } |
5767 | ||
5768 | ||
5769 | \f | |
5770 | /*********************************************************************** | |
5771 | File selection dialog | |
5772 | ***********************************************************************/ | |
5773 | ||
90f2e16b JD |
5774 | DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog, |
5775 | Sx_uses_old_gtk_dialog, | |
5776 | 0, 0, 0, | |
5777 | doc: /* Return t if the old Gtk+ file selection dialog is used. */) | |
5842a27b | 5778 | (void) |
90f2e16b JD |
5779 | { |
5780 | #ifdef USE_GTK | |
90f2e16b JD |
5781 | if (use_dialog_box |
5782 | && use_file_dialog | |
7452b7bd | 5783 | && window_system_available (SELECTED_FRAME ()) |
90f2e16b JD |
5784 | && xg_uses_old_file_dialog ()) |
5785 | return Qt; | |
5786 | #endif | |
5787 | return Qnil; | |
5788 | } | |
5789 | ||
333b20bb | 5790 | |
90f2e16b | 5791 | #ifdef USE_MOTIF |
333b20bb GM |
5792 | /* Callback for "OK" and "Cancel" on file selection dialog. */ |
5793 | ||
5794 | static void | |
dee186b6 | 5795 | file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data) |
333b20bb GM |
5796 | { |
5797 | int *result = (int *) client_data; | |
5798 | XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data; | |
5799 | *result = cb->reason; | |
5800 | } | |
5801 | ||
5802 | ||
a779d213 GM |
5803 | /* Callback for unmapping a file selection dialog. This is used to |
5804 | capture the case where a dialog is closed via a window manager's | |
5805 | closer button, for example. Using a XmNdestroyCallback didn't work | |
5806 | in this case. */ | |
5807 | ||
5808 | static void | |
dee186b6 | 5809 | file_dialog_unmap_cb (Widget widget, XtPointer client_data, XtPointer call_data) |
a779d213 GM |
5810 | { |
5811 | int *result = (int *) client_data; | |
5812 | *result = XmCR_CANCEL; | |
5813 | } | |
5814 | ||
24ca7c5a | 5815 | static Lisp_Object |
dee186b6 | 5816 | clean_up_file_dialog (Lisp_Object arg) |
24ca7c5a | 5817 | { |
2b30549c | 5818 | Widget dialog = XSAVE_POINTER (arg, 0); |
24ca7c5a JD |
5819 | |
5820 | /* Clean up. */ | |
4d7e6e51 | 5821 | block_input (); |
24ca7c5a JD |
5822 | XtUnmanageChild (dialog); |
5823 | XtDestroyWidget (dialog); | |
5824 | x_menu_set_in_use (0); | |
4d7e6e51 | 5825 | unblock_input (); |
24ca7c5a JD |
5826 | |
5827 | return Qnil; | |
5828 | } | |
5829 | ||
a779d213 | 5830 | |
f9d64bb3 | 5831 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
7ee72033 | 5832 | doc: /* Read file name, prompting with PROMPT in directory DIR. |
f9d64bb3 JD |
5833 | Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file |
5834 | selection box, if specified. If MUSTMATCH is non-nil, the returned file | |
7c051dd8 GM |
5835 | or directory must exist. |
5836 | ||
d7e642cc | 5837 | This function is only defined on NS, MS Windows, and X Windows with the |
7c051dd8 GM |
5838 | Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. |
5839 | Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) | |
5842a27b | 5840 | (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) |
333b20bb GM |
5841 | { |
5842 | int result; | |
0fe92f72 | 5843 | struct frame *f = SELECTED_FRAME (); |
333b20bb | 5844 | Lisp_Object file = Qnil; |
a8f4bdc6 | 5845 | Lisp_Object decoded_file; |
f9d64bb3 | 5846 | Widget dialog, text, help; |
333b20bb GM |
5847 | Arg al[10]; |
5848 | int ac = 0; | |
333b20bb | 5849 | XmString dir_xmstring, pattern_xmstring; |
d311d28c | 5850 | ptrdiff_t count = SPECPDL_INDEX (); |
f9d64bb3 | 5851 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
333b20bb | 5852 | |
7452b7bd | 5853 | check_window_system (f); |
6eeee4d6 | 5854 | |
f9d64bb3 | 5855 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
24ca7c5a | 5856 | |
5ae53dcf | 5857 | if (popup_activated ()) |
24ca7c5a JD |
5858 | error ("Trying to use a menu from within a menu-entry"); |
5859 | ||
b7826503 PJ |
5860 | CHECK_STRING (prompt); |
5861 | CHECK_STRING (dir); | |
333b20bb GM |
5862 | |
5863 | /* Prevent redisplay. */ | |
5864 | specbind (Qinhibit_redisplay, Qt); | |
5865 | ||
4d7e6e51 | 5866 | block_input (); |
333b20bb GM |
5867 | |
5868 | /* Create the dialog with PROMPT as title, using DIR as initial | |
5869 | directory and using "*" as pattern. */ | |
5870 | dir = Fexpand_file_name (dir, Qnil); | |
c09bfb2f | 5871 | dir_xmstring = XmStringCreateLocalized (SSDATA (dir)); |
333b20bb | 5872 | pattern_xmstring = XmStringCreateLocalized ("*"); |
177c0ea7 | 5873 | |
d5db4077 | 5874 | XtSetArg (al[ac], XmNtitle, SDATA (prompt)); ++ac; |
333b20bb GM |
5875 | XtSetArg (al[ac], XmNdirectory, dir_xmstring); ++ac; |
5876 | XtSetArg (al[ac], XmNpattern, pattern_xmstring); ++ac; | |
5877 | XtSetArg (al[ac], XmNresizePolicy, XmRESIZE_GROW); ++ac; | |
5878 | XtSetArg (al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ++ac; | |
5879 | dialog = XmCreateFileSelectionDialog (f->output_data.x->widget, | |
5880 | "fsb", al, ac); | |
5881 | XmStringFree (dir_xmstring); | |
5882 | XmStringFree (pattern_xmstring); | |
5883 | ||
5884 | /* Add callbacks for OK and Cancel. */ | |
5885 | XtAddCallback (dialog, XmNokCallback, file_dialog_cb, | |
5886 | (XtPointer) &result); | |
5887 | XtAddCallback (dialog, XmNcancelCallback, file_dialog_cb, | |
5888 | (XtPointer) &result); | |
a779d213 GM |
5889 | XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb, |
5890 | (XtPointer) &result); | |
333b20bb | 5891 | |
f9d64bb3 | 5892 | /* Remove the help button since we can't display help. */ |
333b20bb | 5893 | help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON); |
f9d64bb3 | 5894 | XtUnmanageChild (help); |
333b20bb | 5895 | |
177c0ea7 | 5896 | /* Mark OK button as default. */ |
333b20bb GM |
5897 | XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON), |
5898 | XmNshowAsDefault, True, NULL); | |
5899 | ||
5900 | /* If MUSTMATCH is non-nil, disable the file entry field of the | |
5901 | dialog, so that the user must select a file from the files list | |
5902 | box. We can't remove it because we wouldn't have a way to get at | |
5903 | the result file name, then. */ | |
5904 | text = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT); | |
5905 | if (!NILP (mustmatch)) | |
5906 | { | |
5907 | Widget label; | |
5908 | label = XmFileSelectionBoxGetChild (dialog, XmDIALOG_SELECTION_LABEL); | |
5909 | XtSetSensitive (text, False); | |
5910 | XtSetSensitive (label, False); | |
5911 | } | |
5912 | ||
5913 | /* Manage the dialog, so that list boxes get filled. */ | |
5914 | XtManageChild (dialog); | |
5915 | ||
333b20bb GM |
5916 | if (STRINGP (default_filename)) |
5917 | { | |
5918 | XmString default_xmstring; | |
f9d64bb3 JD |
5919 | Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT); |
5920 | Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST); | |
333b20bb | 5921 | |
f9d64bb3 JD |
5922 | XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext); |
5923 | XmTextFieldReplace (wtext, 0, last_pos, | |
c09bfb2f | 5924 | (SSDATA (Ffile_name_nondirectory (default_filename)))); |
333b20bb | 5925 | |
f9d64bb3 JD |
5926 | /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME |
5927 | must include the path for this to work. */ | |
5928 | ||
c09bfb2f | 5929 | default_xmstring = XmStringCreateLocalized (SSDATA (default_filename)); |
333b20bb | 5930 | |
f9d64bb3 JD |
5931 | if (XmListItemExists (list, default_xmstring)) |
5932 | { | |
5933 | int item_pos = XmListItemPos (list, default_xmstring); | |
5934 | /* Select the item and scroll it into view. */ | |
5935 | XmListSelectPos (list, item_pos, True); | |
5936 | XmListSetPos (list, item_pos); | |
5937 | } | |
5938 | ||
5939 | XmStringFree (default_xmstring); | |
333b20bb GM |
5940 | } |
5941 | ||
468afbac | 5942 | record_unwind_protect (clean_up_file_dialog, make_save_pointer (dialog)); |
24ca7c5a | 5943 | |
bf338245 | 5944 | /* Process events until the user presses Cancel or OK. */ |
5ae53dcf | 5945 | x_menu_set_in_use (1); |
03100098 | 5946 | result = 0; |
a779d213 | 5947 | while (result == 0) |
563b384d | 5948 | { |
bf338245 | 5949 | XEvent event; |
24ca7c5a | 5950 | x_menu_wait_for_event (0); |
bf338245 | 5951 | XtAppNextEvent (Xt_app_con, &event); |
9f6fcdc5 JD |
5952 | if (event.type == KeyPress |
5953 | && FRAME_X_DISPLAY (f) == event.xkey.display) | |
5954 | { | |
5955 | KeySym keysym = XLookupKeysym (&event.xkey, 0); | |
5956 | ||
5957 | /* Pop down on C-g. */ | |
5958 | if (keysym == XK_g && (event.xkey.state & ControlMask) != 0) | |
5959 | XtUnmanageChild (dialog); | |
5960 | } | |
5b3f8550 | 5961 | |
24ca7c5a | 5962 | (void) x_dispatch_event (&event, FRAME_X_DISPLAY (f)); |
563b384d | 5963 | } |
03100098 | 5964 | |
333b20bb GM |
5965 | /* Get the result. */ |
5966 | if (result == XmCR_OK) | |
5967 | { | |
91a3e27b | 5968 | XmString text_string; |
333b20bb | 5969 | String data; |
177c0ea7 | 5970 | |
91a3e27b PE |
5971 | XtVaGetValues (dialog, XmNtextString, &text_string, NULL); |
5972 | XmStringGetLtoR (text_string, XmFONTLIST_DEFAULT_TAG, &data); | |
5973 | XmStringFree (text_string); | |
333b20bb GM |
5974 | file = build_string (data); |
5975 | XtFree (data); | |
5976 | } | |
5977 | else | |
5978 | file = Qnil; | |
5979 | ||
4d7e6e51 | 5980 | unblock_input (); |
333b20bb GM |
5981 | UNGCPRO; |
5982 | ||
5983 | /* Make "Cancel" equivalent to C-g. */ | |
5984 | if (NILP (file)) | |
5985 | Fsignal (Qquit, Qnil); | |
177c0ea7 | 5986 | |
a8f4bdc6 JD |
5987 | decoded_file = DECODE_FILE (file); |
5988 | ||
5989 | return unbind_to (count, decoded_file); | |
333b20bb GM |
5990 | } |
5991 | ||
5992 | #endif /* USE_MOTIF */ | |
5993 | ||
488dd4c4 JD |
5994 | #ifdef USE_GTK |
5995 | ||
24ca7c5a | 5996 | static Lisp_Object |
971de7fb | 5997 | clean_up_dialog (Lisp_Object arg) |
24ca7c5a JD |
5998 | { |
5999 | x_menu_set_in_use (0); | |
6000 | ||
6001 | return Qnil; | |
6002 | } | |
6003 | ||
f9d64bb3 JD |
6004 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
6005 | doc: /* Read file name, prompting with PROMPT in directory DIR. | |
6006 | Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file | |
6007 | selection box, if specified. If MUSTMATCH is non-nil, the returned file | |
7c051dd8 GM |
6008 | or directory must exist. |
6009 | ||
d7e642cc | 6010 | This function is only defined on NS, MS Windows, and X Windows with the |
7c051dd8 GM |
6011 | Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. |
6012 | Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) | |
5842a27b | 6013 | (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) |
488dd4c4 JD |
6014 | { |
6015 | FRAME_PTR f = SELECTED_FRAME (); | |
6016 | char *fn; | |
6017 | Lisp_Object file = Qnil; | |
a8f4bdc6 | 6018 | Lisp_Object decoded_file; |
d311d28c | 6019 | ptrdiff_t count = SPECPDL_INDEX (); |
f9d64bb3 | 6020 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
488dd4c4 | 6021 | char *cdef_file; |
177c0ea7 | 6022 | |
7452b7bd | 6023 | check_window_system (f); |
6eeee4d6 | 6024 | |
f9d64bb3 | 6025 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
24ca7c5a | 6026 | |
5ae53dcf | 6027 | if (popup_activated ()) |
24ca7c5a JD |
6028 | error ("Trying to use a menu from within a menu-entry"); |
6029 | ||
488dd4c4 JD |
6030 | CHECK_STRING (prompt); |
6031 | CHECK_STRING (dir); | |
6032 | ||
6033 | /* Prevent redisplay. */ | |
6034 | specbind (Qinhibit_redisplay, Qt); | |
24ca7c5a | 6035 | record_unwind_protect (clean_up_dialog, Qnil); |
488dd4c4 | 6036 | |
4d7e6e51 | 6037 | block_input (); |
488dd4c4 JD |
6038 | |
6039 | if (STRINGP (default_filename)) | |
c0951e53 | 6040 | cdef_file = SSDATA (default_filename); |
488dd4c4 | 6041 | else |
c0951e53 | 6042 | cdef_file = SSDATA (dir); |
488dd4c4 | 6043 | |
c0951e53 | 6044 | fn = xg_get_file_name (f, SSDATA (prompt), cdef_file, |
f9d64bb3 JD |
6045 | ! NILP (mustmatch), |
6046 | ! NILP (only_dir_p)); | |
177c0ea7 | 6047 | |
488dd4c4 JD |
6048 | if (fn) |
6049 | { | |
6050 | file = build_string (fn); | |
6051 | xfree (fn); | |
6052 | } | |
6053 | ||
4d7e6e51 | 6054 | unblock_input (); |
488dd4c4 JD |
6055 | UNGCPRO; |
6056 | ||
6057 | /* Make "Cancel" equivalent to C-g. */ | |
6058 | if (NILP (file)) | |
6059 | Fsignal (Qquit, Qnil); | |
177c0ea7 | 6060 | |
a8f4bdc6 JD |
6061 | decoded_file = DECODE_FILE (file); |
6062 | ||
6063 | return unbind_to (count, decoded_file); | |
488dd4c4 JD |
6064 | } |
6065 | ||
9bf80974 CY |
6066 | |
6067 | #ifdef HAVE_FREETYPE | |
6068 | ||
f82605c6 | 6069 | DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0, |
f2045622 CY |
6070 | doc: /* Read a font using a GTK dialog. |
6071 | Return either a font spec (for GTK versions >= 3.2) or a string | |
6072 | containing a GTK-style font name. | |
f82605c6 | 6073 | |
f2045622 CY |
6074 | FRAME is the frame on which to pop up the font chooser. If omitted or |
6075 | nil, it defaults to the selected frame. */) | |
5842a27b | 6076 | (Lisp_Object frame, Lisp_Object ignored) |
9bf80974 | 6077 | { |
7452b7bd | 6078 | FRAME_PTR f = decode_window_system_frame (frame); |
637fa988 | 6079 | Lisp_Object font; |
e0ab5fcf JD |
6080 | Lisp_Object font_param; |
6081 | char *default_name = NULL; | |
637fa988 | 6082 | struct gcpro gcpro1, gcpro2; |
d311d28c | 6083 | ptrdiff_t count = SPECPDL_INDEX (); |
9bf80974 | 6084 | |
9bf80974 CY |
6085 | if (popup_activated ()) |
6086 | error ("Trying to use a menu from within a menu-entry"); | |
6087 | ||
6088 | /* Prevent redisplay. */ | |
6089 | specbind (Qinhibit_redisplay, Qt); | |
6090 | record_unwind_protect (clean_up_dialog, Qnil); | |
6091 | ||
4d7e6e51 | 6092 | block_input (); |
9bf80974 | 6093 | |
5e617bc2 | 6094 | GCPRO2 (font_param, font); |
e0ab5fcf | 6095 | |
637fa988 | 6096 | XSETFONT (font, FRAME_FONT (f)); |
581e51e8 | 6097 | font_param = Ffont_get (font, intern (":name")); |
637fa988 | 6098 | if (STRINGP (font_param)) |
c0951e53 | 6099 | default_name = xstrdup (SSDATA (font_param)); |
f5f6c0e0 | 6100 | else |
53c7540d | 6101 | { |
637fa988 JD |
6102 | font_param = Fframe_parameter (frame, Qfont_param); |
6103 | if (STRINGP (font_param)) | |
c0951e53 | 6104 | default_name = xstrdup (SSDATA (font_param)); |
53c7540d | 6105 | } |
e0ab5fcf | 6106 | |
f2045622 | 6107 | font = xg_get_font (f, default_name); |
581e51e8 | 6108 | xfree (default_name); |
9bf80974 | 6109 | |
4d7e6e51 | 6110 | unblock_input (); |
9bf80974 CY |
6111 | |
6112 | if (NILP (font)) | |
6113 | Fsignal (Qquit, Qnil); | |
6114 | ||
6115 | return unbind_to (count, font); | |
6116 | } | |
6117 | #endif /* HAVE_FREETYPE */ | |
6118 | ||
488dd4c4 | 6119 | #endif /* USE_GTK */ |
333b20bb GM |
6120 | |
6121 | \f | |
82bab41c GM |
6122 | /*********************************************************************** |
6123 | Keyboard | |
6124 | ***********************************************************************/ | |
6125 | ||
afeee3e5 | 6126 | #ifdef HAVE_XKB |
82bab41c GM |
6127 | #include <X11/XKBlib.h> |
6128 | #include <X11/keysym.h> | |
6129 | #endif | |
6130 | ||
6131 | DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p, | |
6132 | Sx_backspace_delete_keys_p, 0, 1, 0, | |
7ee72033 | 6133 | doc: /* Check if both Backspace and Delete keys are on the keyboard of FRAME. |
c061c855 GM |
6134 | FRAME nil means use the selected frame. |
6135 | Value is t if we know that both keys are present, and are mapped to the | |
20d1c5c5 DN |
6136 | usual X keysyms. Value is `lambda' if we cannot determine if both keys are |
6137 | present and mapped to the usual X keysyms. */) | |
5842a27b | 6138 | (Lisp_Object frame) |
82bab41c | 6139 | { |
afeee3e5 PE |
6140 | #ifndef HAVE_XKB |
6141 | return Qlambda; | |
6142 | #else | |
82bab41c | 6143 | XkbDescPtr kb; |
7452b7bd | 6144 | struct frame *f = decode_window_system_frame (frame); |
82bab41c GM |
6145 | Display *dpy = FRAME_X_DISPLAY (f); |
6146 | Lisp_Object have_keys; | |
58d2d479 | 6147 | int major, minor, op, event, error_code; |
82bab41c | 6148 | |
4d7e6e51 | 6149 | block_input (); |
46f6a258 GM |
6150 | |
6151 | /* Check library version in case we're dynamically linked. */ | |
6152 | major = XkbMajorVersion; | |
6153 | minor = XkbMinorVersion; | |
6154 | if (!XkbLibraryVersion (&major, &minor)) | |
c1efd260 | 6155 | { |
4d7e6e51 | 6156 | unblock_input (); |
20d1c5c5 | 6157 | return Qlambda; |
c1efd260 | 6158 | } |
46f6a258 GM |
6159 | |
6160 | /* Check that the server supports XKB. */ | |
6161 | major = XkbMajorVersion; | |
6162 | minor = XkbMinorVersion; | |
58d2d479 | 6163 | if (!XkbQueryExtension (dpy, &op, &event, &error_code, &major, &minor)) |
c1efd260 | 6164 | { |
4d7e6e51 | 6165 | unblock_input (); |
20d1c5c5 | 6166 | return Qlambda; |
c1efd260 | 6167 | } |
177c0ea7 | 6168 | |
3a441526 JD |
6169 | /* In this code we check that the keyboard has physical keys with names |
6170 | that start with BKSP (Backspace) and DELE (Delete), and that they | |
6171 | generate keysym XK_BackSpace and XK_Delete respectively. | |
6172 | This function is used to test if normal-erase-is-backspace should be | |
6173 | turned on. | |
6174 | An alternative approach would be to just check if XK_BackSpace and | |
6175 | XK_Delete are mapped to any key. But if any of those are mapped to | |
6176 | some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the | |
6177 | user doesn't know about it, it is better to return false here. | |
6178 | It is more obvious to the user what to do if she/he has two keys | |
6179 | clearly marked with names/symbols and one key does something not | |
6180 | expected (i.e. she/he then tries the other). | |
6181 | The cases where Backspace/Delete is mapped to some other key combination | |
6182 | are rare, and in those cases, normal-erase-is-backspace can be turned on | |
6183 | manually. */ | |
6184 | ||
46f6a258 | 6185 | have_keys = Qnil; |
c1efd260 | 6186 | kb = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd); |
82bab41c GM |
6187 | if (kb) |
6188 | { | |
6189 | int delete_keycode = 0, backspace_keycode = 0, i; | |
c1efd260 GM |
6190 | |
6191 | if (XkbGetNames (dpy, XkbAllNamesMask, kb) == Success) | |
82bab41c | 6192 | { |
c1efd260 GM |
6193 | for (i = kb->min_key_code; |
6194 | (i < kb->max_key_code | |
6195 | && (delete_keycode == 0 || backspace_keycode == 0)); | |
6196 | ++i) | |
6197 | { | |
d63931a2 GM |
6198 | /* The XKB symbolic key names can be seen most easily in |
6199 | the PS file generated by `xkbprint -label name | |
6200 | $DISPLAY'. */ | |
72af86bd | 6201 | if (memcmp ("DELE", kb->names->keys[i].name, 4) == 0) |
c1efd260 | 6202 | delete_keycode = i; |
72af86bd | 6203 | else if (memcmp ("BKSP", kb->names->keys[i].name, 4) == 0) |
c1efd260 GM |
6204 | backspace_keycode = i; |
6205 | } | |
6206 | ||
6207 | XkbFreeNames (kb, 0, True); | |
82bab41c GM |
6208 | } |
6209 | ||
c1efd260 | 6210 | XkbFreeClientMap (kb, 0, True); |
177c0ea7 | 6211 | |
82bab41c GM |
6212 | if (delete_keycode |
6213 | && backspace_keycode | |
6214 | && XKeysymToKeycode (dpy, XK_Delete) == delete_keycode | |
6215 | && XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode) | |
6216 | have_keys = Qt; | |
6217 | } | |
4d7e6e51 | 6218 | unblock_input (); |
82bab41c | 6219 | return have_keys; |
afeee3e5 | 6220 | #endif |
82bab41c GM |
6221 | } |
6222 | ||
6223 | ||
6224 | \f | |
333b20bb GM |
6225 | /*********************************************************************** |
6226 | Initialization | |
6227 | ***********************************************************************/ | |
6228 | ||
4dacadcc | 6229 | /* Keep this list in the same order as frame_parms in frame.c. |
7c0d3ed8 KS |
6230 | Use 0 for unsupported frame parameters. */ |
6231 | ||
6232 | frame_parm_handler x_frame_parm_handlers[] = | |
6233 | { | |
6234 | x_set_autoraise, | |
6235 | x_set_autolower, | |
6236 | x_set_background_color, | |
6237 | x_set_border_color, | |
6238 | x_set_border_width, | |
6239 | x_set_cursor_color, | |
6240 | x_set_cursor_type, | |
6241 | x_set_font, | |
6242 | x_set_foreground_color, | |
6243 | x_set_icon_name, | |
6244 | x_set_icon_type, | |
6245 | x_set_internal_border_width, | |
6246 | x_set_menu_bar_lines, | |
6247 | x_set_mouse_color, | |
6248 | x_explicitly_set_name, | |
6249 | x_set_scroll_bar_width, | |
6250 | x_set_title, | |
6251 | x_set_unsplittable, | |
6252 | x_set_vertical_scroll_bars, | |
6253 | x_set_visibility, | |
6254 | x_set_tool_bar_lines, | |
6255 | x_set_scroll_bar_foreground, | |
6256 | x_set_scroll_bar_background, | |
6257 | x_set_screen_gamma, | |
6258 | x_set_line_spacing, | |
6259 | x_set_fringe_width, | |
6260 | x_set_fringe_width, | |
6261 | x_set_wait_for_wm, | |
6262 | x_set_fullscreen, | |
271a71c7 | 6263 | x_set_font_backend, |
cad9ef74 JD |
6264 | x_set_alpha, |
6265 | x_set_sticky, | |
bfeabdc3 | 6266 | x_set_tool_bar_position, |
7c0d3ed8 KS |
6267 | }; |
6268 | ||
333b20bb | 6269 | void |
971de7fb | 6270 | syms_of_xfns (void) |
333b20bb | 6271 | { |
333b20bb GM |
6272 | /* The section below is built by the lisp expression at the top of the file, |
6273 | just above where these variables are declared. */ | |
6274 | /*&&& init symbols here &&&*/ | |
cd3520a4 JB |
6275 | DEFSYM (Qsuppress_icon, "suppress-icon"); |
6276 | DEFSYM (Qundefined_color, "undefined-color"); | |
6277 | DEFSYM (Qcompound_text, "compound-text"); | |
6278 | DEFSYM (Qcancel_timer, "cancel-timer"); | |
4e3f9230 YM |
6279 | DEFSYM (Qgeometry, "geometry"); |
6280 | DEFSYM (Qworkarea, "workarea"); | |
6281 | DEFSYM (Qmm_size, "mm-size"); | |
6282 | DEFSYM (Qframes, "frames"); | |
6283 | DEFSYM (Qsource, "source"); | |
cd3520a4 | 6284 | DEFSYM (Qfont_param, "font-parameter"); |
f9942c9e JB |
6285 | /* This is the end of symbol initialization. */ |
6286 | ||
01f1ba30 | 6287 | Fput (Qundefined_color, Qerror_conditions, |
3438fe21 | 6288 | listn (CONSTYPE_PURE, 2, Qundefined_color, Qerror)); |
01f1ba30 | 6289 | Fput (Qundefined_color, Qerror_message, |
2a0213a6 | 6290 | build_pure_c_string ("Undefined color")); |
01f1ba30 | 6291 | |
29208e82 | 6292 | DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape, |
7ee72033 | 6293 | doc: /* The shape of the pointer when over text. |
c061c855 GM |
6294 | Changing the value does not affect existing frames |
6295 | unless you set the mouse color. */); | |
01f1ba30 JB |
6296 | Vx_pointer_shape = Qnil; |
6297 | ||
ca0ecbf5 | 6298 | #if 0 /* This doesn't really do anything. */ |
29208e82 | 6299 | DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape, |
7ee72033 | 6300 | doc: /* The shape of the pointer when not over text. |
c061c855 GM |
6301 | This variable takes effect when you create a new frame |
6302 | or when you set the mouse color. */); | |
af01ef26 | 6303 | #endif |
01f1ba30 JB |
6304 | Vx_nontext_pointer_shape = Qnil; |
6305 | ||
29208e82 | 6306 | DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape, |
7ee72033 | 6307 | doc: /* The shape of the pointer when Emacs is busy. |
c061c855 GM |
6308 | This variable takes effect when you create a new frame |
6309 | or when you set the mouse color. */); | |
0af913d7 | 6310 | Vx_hourglass_pointer_shape = Qnil; |
333b20bb | 6311 | |
ca0ecbf5 | 6312 | #if 0 /* This doesn't really do anything. */ |
29208e82 | 6313 | DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape, |
7ee72033 | 6314 | doc: /* The shape of the pointer when over the mode line. |
c061c855 GM |
6315 | This variable takes effect when you create a new frame |
6316 | or when you set the mouse color. */); | |
af01ef26 | 6317 | #endif |
01f1ba30 JB |
6318 | Vx_mode_pointer_shape = Qnil; |
6319 | ||
d3b06468 | 6320 | DEFVAR_LISP ("x-sensitive-text-pointer-shape", |
29208e82 | 6321 | Vx_sensitive_text_pointer_shape, |
7ee72033 | 6322 | doc: /* The shape of the pointer when over mouse-sensitive text. |
c061c855 GM |
6323 | This variable takes effect when you create a new frame |
6324 | or when you set the mouse color. */); | |
ca0ecbf5 | 6325 | Vx_sensitive_text_pointer_shape = Qnil; |
95f80c78 | 6326 | |
8fb4ec9c | 6327 | DEFVAR_LISP ("x-window-horizontal-drag-cursor", |
29208e82 | 6328 | Vx_window_horizontal_drag_shape, |
7ee72033 | 6329 | doc: /* Pointer shape to use for indicating a window can be dragged horizontally. |
c061c855 GM |
6330 | This variable takes effect when you create a new frame |
6331 | or when you set the mouse color. */); | |
8fb4ec9c GM |
6332 | Vx_window_horizontal_drag_shape = Qnil; |
6333 | ||
29208e82 | 6334 | DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel, |
7ee72033 | 6335 | doc: /* A string indicating the foreground color of the cursor box. */); |
01f1ba30 JB |
6336 | Vx_cursor_fore_pixel = Qnil; |
6337 | ||
29208e82 | 6338 | DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size, |
f5f6c0e0 JB |
6339 | doc: /* Maximum size for tooltips. |
6340 | Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */); | |
d63931a2 | 6341 | Vx_max_tooltip_size = Fcons (make_number (80), make_number (40)); |
177c0ea7 | 6342 | |
29208e82 | 6343 | DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager, |
7ee72033 | 6344 | doc: /* Non-nil if no X window manager is in use. |
c061c855 GM |
6345 | Emacs doesn't try to figure this out; this is always nil |
6346 | unless you set it to something else. */); | |
2d38195d RS |
6347 | /* We don't have any way to find this out, so set it to nil |
6348 | and maybe the user would like to set it to t. */ | |
6349 | Vx_no_window_manager = Qnil; | |
1d3dac41 | 6350 | |
942ea06d | 6351 | DEFVAR_LISP ("x-pixel-size-width-font-regexp", |
29208e82 | 6352 | Vx_pixel_size_width_font_regexp, |
7ee72033 | 6353 | doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. |
c061c855 GM |
6354 | |
6355 | Since Emacs gets width of a font matching with this regexp from | |
6356 | PIXEL_SIZE field of the name, font finding mechanism gets faster for | |
6357 | such a font. This is especially effective for such large fonts as | |
6358 | Chinese, Japanese, and Korean. */); | |
942ea06d KH |
6359 | Vx_pixel_size_width_font_regexp = Qnil; |
6360 | ||
255e4140 | 6361 | /* This is not ifdef:ed, so other builds than GTK can customize it. */ |
29208e82 | 6362 | DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog, |
fb7ada5f | 6363 | doc: /* Non-nil means prompt with the old GTK file selection dialog. |
255e4140 JD |
6364 | If nil or if the file selection dialog is not available, the new GTK file |
6365 | chooser is used instead. To turn off all file dialogs set the | |
6366 | variable `use-file-dialog'. */); | |
fe2b14b7 | 6367 | x_gtk_use_old_file_dialog = 0; |
255e4140 | 6368 | |
29208e82 | 6369 | DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files, |
fb7ada5f | 6370 | doc: /* If non-nil, the GTK file chooser will by default show hidden files. |
a8a35720 JD |
6371 | Note that this is just the default, there is a toggle button on the file |
6372 | chooser to show or not show hidden files on a case by case basis. */); | |
6373 | x_gtk_show_hidden_files = 0; | |
6374 | ||
29208e82 | 6375 | DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text, |
fb7ada5f | 6376 | doc: /* If non-nil, the GTK file chooser will show additional help text. |
641c0105 JD |
6377 | If more space for files in the file chooser dialog is wanted, set this to nil |
6378 | to turn the additional text off. */); | |
159f8da7 | 6379 | x_gtk_file_dialog_help_text = 1; |
641c0105 | 6380 | |
29208e82 | 6381 | DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", x_gtk_whole_detached_tool_bar, |
fb7ada5f | 6382 | doc: /* If non-nil, a detached tool bar is shown in full. |
e0f467cb JD |
6383 | The default is to just show an arrow and pressing on that arrow shows |
6384 | the tool bar buttons. */); | |
6385 | x_gtk_whole_detached_tool_bar = 0; | |
6386 | ||
29208e82 | 6387 | DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips, |
fb7ada5f | 6388 | doc: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used. |
aa1859f5 J |
6389 | Otherwise use Emacs own tooltip implementation. |
6390 | When using Gtk+ tooltips, the tooltip face is not used. */); | |
6391 | x_gtk_use_system_tooltips = 1; | |
6392 | ||
d67b4f80 | 6393 | Fprovide (intern_c_string ("x"), Qnil); |
49be9d28 | 6394 | |
1d3dac41 | 6395 | #ifdef USE_X_TOOLKIT |
d67b4f80 | 6396 | Fprovide (intern_c_string ("x-toolkit"), Qnil); |
5b827abb | 6397 | #ifdef USE_MOTIF |
d67b4f80 | 6398 | Fprovide (intern_c_string ("motif"), Qnil); |
fc2cdd9a | 6399 | |
29208e82 | 6400 | DEFVAR_LISP ("motif-version-string", Vmotif_version_string, |
7ee72033 | 6401 | doc: /* Version info for LessTif/Motif. */); |
fc2cdd9a GM |
6402 | Vmotif_version_string = build_string (XmVERSION_STRING); |
6403 | #endif /* USE_MOTIF */ | |
6404 | #endif /* USE_X_TOOLKIT */ | |
01f1ba30 | 6405 | |
6b61353c | 6406 | #ifdef USE_GTK |
1ec2a572 JD |
6407 | /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it |
6408 | is not an X toolkit in that sense (USE_X_TOOLKIT is not defined). | |
6409 | But for a user it is a toolkit for X, and indeed, configure | |
6410 | accepts --with-x-toolkit=gtk. */ | |
d67b4f80 DN |
6411 | Fprovide (intern_c_string ("x-toolkit"), Qnil); |
6412 | Fprovide (intern_c_string ("gtk"), Qnil); | |
bfeabdc3 | 6413 | Fprovide (intern_c_string ("move-toolbar"), Qnil); |
6b61353c | 6414 | |
29208e82 | 6415 | DEFVAR_LISP ("gtk-version-string", Vgtk_version_string, |
6b61353c KH |
6416 | doc: /* Version info for GTK+. */); |
6417 | { | |
99027bdd PE |
6418 | char gtk_version[sizeof ".." + 3 * INT_STRLEN_BOUND (int)]; |
6419 | int len = sprintf (gtk_version, "%d.%d.%d", | |
6420 | GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); | |
6421 | Vgtk_version_string = make_pure_string (gtk_version, len, len, 0); | |
6b61353c KH |
6422 | } |
6423 | #endif /* USE_GTK */ | |
6424 | ||
333b20bb GM |
6425 | /* X window properties. */ |
6426 | defsubr (&Sx_change_window_property); | |
6427 | defsubr (&Sx_delete_window_property); | |
6428 | defsubr (&Sx_window_property); | |
6429 | ||
2d764c78 | 6430 | defsubr (&Sxw_display_color_p); |
d0c9d219 | 6431 | defsubr (&Sx_display_grayscale_p); |
2d764c78 EZ |
6432 | defsubr (&Sxw_color_defined_p); |
6433 | defsubr (&Sxw_color_values); | |
9d317b2c | 6434 | defsubr (&Sx_server_max_request_size); |
41beb8fc RS |
6435 | defsubr (&Sx_server_vendor); |
6436 | defsubr (&Sx_server_version); | |
6437 | defsubr (&Sx_display_pixel_width); | |
6438 | defsubr (&Sx_display_pixel_height); | |
6439 | defsubr (&Sx_display_mm_width); | |
6440 | defsubr (&Sx_display_mm_height); | |
6441 | defsubr (&Sx_display_screens); | |
6442 | defsubr (&Sx_display_planes); | |
6443 | defsubr (&Sx_display_color_cells); | |
6444 | defsubr (&Sx_display_visual_class); | |
6445 | defsubr (&Sx_display_backing_store); | |
6446 | defsubr (&Sx_display_save_under); | |
4e3f9230 | 6447 | defsubr (&Sx_display_monitor_attributes_list); |
1c44e124 | 6448 | defsubr (&Sx_wm_set_size_hint); |
f676886a | 6449 | defsubr (&Sx_create_frame); |
01f1ba30 | 6450 | defsubr (&Sx_open_connection); |
08a90d6a RS |
6451 | defsubr (&Sx_close_connection); |
6452 | defsubr (&Sx_display_list); | |
01f1ba30 | 6453 | defsubr (&Sx_synchronize); |
3decc1e7 | 6454 | defsubr (&Sx_focus_frame); |
82bab41c | 6455 | defsubr (&Sx_backspace_delete_keys_p); |
177c0ea7 | 6456 | |
333b20bb GM |
6457 | defsubr (&Sx_show_tip); |
6458 | defsubr (&Sx_hide_tip); | |
333b20bb | 6459 | tip_timer = Qnil; |
44b5a125 GM |
6460 | staticpro (&tip_timer); |
6461 | tip_frame = Qnil; | |
6462 | staticpro (&tip_frame); | |
333b20bb | 6463 | |
06d62053 GM |
6464 | last_show_tip_args = Qnil; |
6465 | staticpro (&last_show_tip_args); | |
6466 | ||
90f2e16b | 6467 | defsubr (&Sx_uses_old_gtk_dialog); |
29fabd8c | 6468 | #if defined (USE_MOTIF) || defined (USE_GTK) |
333b20bb GM |
6469 | defsubr (&Sx_file_dialog); |
6470 | #endif | |
9bf80974 | 6471 | |
946598bf | 6472 | #if defined (USE_GTK) && defined (HAVE_FREETYPE) |
f82605c6 | 6473 | defsubr (&Sx_select_font); |
9bf80974 | 6474 | #endif |
333b20bb GM |
6475 | } |
6476 | ||
01f1ba30 | 6477 | #endif /* HAVE_X_WINDOWS */ |