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