Mercurial > emacs
annotate src/xfns.c @ 464:4ddaee1a9029
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Fri, 20 Dec 1991 07:15:37 +0000 |
parents | 6e0a136fca4f |
children | 8c615e453683 |
rev | line source |
---|---|
389 | 1 /* Functions for the X window system. |
2 Copyright (C) 1989 Free Software Foundation. | |
3 | |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 /* Completely rewritten by Richard Stallman. */ | |
21 | |
22 /* Rewritten for X11 by Joseph Arceneaux */ | |
23 | |
24 #if 0 | |
25 #include <stdio.h> | |
26 #endif | |
27 #include <signal.h> | |
28 #include "config.h" | |
29 #include "lisp.h" | |
30 #include "xterm.h" | |
31 #include "screen.h" | |
32 #include "window.h" | |
33 #include "buffer.h" | |
34 #include "dispextern.h" | |
35 #include "xscrollbar.h" | |
36 | |
37 #ifdef HAVE_X_WINDOWS | |
38 extern void abort (); | |
39 | |
40 void x_set_screen_param (); | |
41 | |
42 #define min(a,b) ((a) < (b) ? (a) : (b)) | |
43 #define max(a,b) ((a) > (b) ? (a) : (b)) | |
44 | |
45 #ifdef HAVE_X11 | |
46 /* X Resource data base */ | |
47 static XrmDatabase xrdb; | |
48 | |
49 /* The class of this X application. */ | |
50 #define EMACS_CLASS "Emacs" | |
51 | |
52 /* The class of Emacs screens. */ | |
53 #define SCREEN_CLASS "Screen" | |
398 | 54 Lisp_Object screen_class; |
389 | 55 |
56 /* Title name and application name for X stuff. */ | |
398 | 57 extern char *x_id_name; |
389 | 58 extern Lisp_Object invocation_name; |
59 | |
60 /* The background and shape of the mouse pointer, and shape when not | |
61 over text or in the modeline. */ | |
62 Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape; | |
63 | |
64 /* Color of chars displayed in cursor box. */ | |
65 Lisp_Object Vx_cursor_fore_pixel; | |
66 | |
67 /* If non-nil, use vertical bar cursor. */ | |
68 Lisp_Object Vbar_cursor; | |
69 | |
70 /* The X Visual we are using for X windows (the default) */ | |
71 Visual *screen_visual; | |
72 | |
73 /* How many screens this X display has. */ | |
74 int x_screen_count; | |
75 | |
76 /* The vendor supporting this X server. */ | |
77 Lisp_Object Vx_vendor; | |
78 | |
79 /* The vendor's release number for this X server. */ | |
80 int x_release; | |
81 | |
82 /* Height of this X screen in pixels. */ | |
83 int x_screen_height; | |
84 | |
85 /* Height of this X screen in millimeters. */ | |
86 int x_screen_height_mm; | |
87 | |
88 /* Width of this X screen in pixels. */ | |
89 int x_screen_width; | |
90 | |
91 /* Width of this X screen in millimeters. */ | |
92 int x_screen_width_mm; | |
93 | |
94 /* Does this X screen do backing store? */ | |
95 Lisp_Object Vx_backing_store; | |
96 | |
97 /* Does this X screen do save-unders? */ | |
98 int x_save_under; | |
99 | |
100 /* Number of planes for this screen. */ | |
101 int x_screen_planes; | |
102 | |
103 /* X Visual type of this screen. */ | |
104 Lisp_Object Vx_screen_visual; | |
105 | |
106 /* Non nil if no window manager is in use. */ | |
107 Lisp_Object Vx_no_window_manager; | |
108 | |
109 static char *x_visual_strings[] = | |
110 { | |
111 "StaticGray", | |
112 "GrayScale", | |
113 "StaticColor", | |
114 "PseudoColor", | |
115 "TrueColor", | |
116 "DirectColor" | |
117 }; | |
118 | |
119 /* `t' if a mouse button is depressed. */ | |
120 | |
121 Lisp_Object Vmouse_depressed; | |
122 | |
123 /* Atom for indicating window state to the window manager. */ | |
124 Atom Xatom_wm_change_state; | |
125 | |
126 /* When emacs became the selection owner. */ | |
127 extern Time x_begin_selection_own; | |
128 | |
129 /* The value of the current emacs selection. */ | |
130 extern Lisp_Object Vx_selection_value; | |
131 | |
132 /* Emacs' selection property identifier. */ | |
133 extern Atom Xatom_emacs_selection; | |
134 | |
135 /* Clipboard selection atom. */ | |
136 extern Atom Xatom_clipboard_selection; | |
137 | |
138 /* Clipboard atom. */ | |
139 extern Atom Xatom_clipboard; | |
140 | |
141 /* Atom for indicating incremental selection transfer. */ | |
142 extern Atom Xatom_incremental; | |
143 | |
144 /* Atom for indicating multiple selection request list */ | |
145 extern Atom Xatom_multiple; | |
146 | |
147 /* Atom for what targets emacs handles. */ | |
148 extern Atom Xatom_targets; | |
149 | |
150 /* Atom for indicating timstamp selection request */ | |
151 extern Atom Xatom_timestamp; | |
152 | |
153 /* Atom requesting we delete our selection. */ | |
154 extern Atom Xatom_delete; | |
155 | |
156 /* Selection magic. */ | |
157 extern Atom Xatom_insert_selection; | |
158 | |
159 /* Type of property for INSERT_SELECTION. */ | |
160 extern Atom Xatom_pair; | |
161 | |
162 /* More selection magic. */ | |
163 extern Atom Xatom_insert_property; | |
164 | |
165 /* Atom for indicating property type TEXT */ | |
166 extern Atom Xatom_text; | |
167 | |
168 #else /* X10 */ | |
169 | |
170 /* Default size of an Emacs window without scroll bar. */ | |
171 static char *default_window = "=80x24+0+0"; | |
172 | |
173 #define MAXICID 80 | |
174 char iconidentity[MAXICID]; | |
175 #define ICONTAG "emacs@" | |
176 char minibuffer_iconidentity[MAXICID]; | |
177 #define MINIBUFFER_ICONTAG "minibuffer@" | |
178 | |
179 #endif /* X10 */ | |
180 | |
181 /* The last 23 bits of the timestamp of the last mouse button event. */ | |
182 Time mouse_timestamp; | |
183 | |
184 Lisp_Object Qundefined_color; | |
185 Lisp_Object Qx_screen_parameter; | |
186 | |
187 extern Lisp_Object Vwindow_system_version; | |
188 | |
189 /* Mouse map for clicks in windows. */ | |
190 extern Lisp_Object Vglobal_mouse_map; | |
191 | |
192 /* Points to table of defined typefaces. */ | |
193 struct face *x_face_table[MAX_FACES_AND_GLYPHS]; | |
194 | |
195 /* Return the Emacs screen-object corresponding to an X window. | |
196 It could be the screen's main window or an icon window. */ | |
197 | |
198 struct screen * | |
199 x_window_to_screen (wdesc) | |
200 int wdesc; | |
201 { | |
202 Lisp_Object tail, screen; | |
203 struct screen *s; | |
204 | |
205 for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr) | |
206 { | |
207 screen = XCONS (tail)->car; | |
208 if (XTYPE (screen) != Lisp_Screen) | |
209 continue; | |
210 s = XSCREEN (screen); | |
211 if (s->display.x->window_desc == wdesc | |
212 || s->display.x->icon_desc == wdesc) | |
213 return s; | |
214 } | |
215 return 0; | |
216 } | |
217 | |
218 /* A symbol indicating which part of the screen the mouse is in. */ | |
219 Lisp_Object Vmouse_screen_part; | |
220 | |
221 Lisp_Object Qtext_part; | |
222 Lisp_Object Qmodeline_part; | |
223 | |
224 Lisp_Object Qvscrollbar_part; | |
225 Lisp_Object Qvslider_part; | |
226 Lisp_Object Qvthumbup_part; | |
227 Lisp_Object Qvthumbdown_part; | |
228 | |
229 Lisp_Object Qhscrollbar_part; | |
230 Lisp_Object Qhslider_part; | |
231 Lisp_Object Qhthumbleft_part; | |
232 Lisp_Object Qhthumbright_part; | |
233 | |
234 /* Map an X window that implements a scroll bar to the Emacs screen it | |
235 belongs to. Also store in *PART a symbol identifying which part of | |
236 the scroll bar it is. */ | |
237 | |
238 struct screen * | |
239 x_window_to_scrollbar (wdesc, part_ptr, prefix_ptr) | |
240 int wdesc; | |
241 Lisp_Object *part_ptr; | |
242 enum scroll_bar_prefix *prefix_ptr; | |
243 { | |
244 Lisp_Object tail, screen; | |
245 struct screen *s; | |
246 | |
247 for (tail = Vscreen_list; CONSP (tail); tail = XCONS (tail)->cdr) | |
248 { | |
249 screen = XCONS (tail)->car; | |
250 if (XTYPE (screen) != Lisp_Screen) | |
251 continue; | |
252 | |
253 s = XSCREEN (screen); | |
254 if (part_ptr == 0 && prefix_ptr == 0) | |
255 return s; | |
256 | |
257 if (s->display.x->v_scrollbar == wdesc) | |
258 { | |
259 *part_ptr = Qvscrollbar_part; | |
260 *prefix_ptr = VSCROLL_BAR_PREFIX; | |
261 return s; | |
262 } | |
263 else if (s->display.x->v_slider == wdesc) | |
264 { | |
265 *part_ptr = Qvslider_part; | |
266 *prefix_ptr = VSCROLL_SLIDER_PREFIX; | |
267 return s; | |
268 } | |
269 else if (s->display.x->v_thumbup == wdesc) | |
270 { | |
271 *part_ptr = Qvthumbup_part; | |
272 *prefix_ptr = VSCROLL_THUMBUP_PREFIX; | |
273 return s; | |
274 } | |
275 else if (s->display.x->v_thumbdown == wdesc) | |
276 { | |
277 *part_ptr = Qvthumbdown_part; | |
278 *prefix_ptr = VSCROLL_THUMBDOWN_PREFIX; | |
279 return s; | |
280 } | |
281 else if (s->display.x->h_scrollbar == wdesc) | |
282 { | |
283 *part_ptr = Qhscrollbar_part; | |
284 *prefix_ptr = HSCROLL_BAR_PREFIX; | |
285 return s; | |
286 } | |
287 else if (s->display.x->h_slider == wdesc) | |
288 { | |
289 *part_ptr = Qhslider_part; | |
290 *prefix_ptr = HSCROLL_SLIDER_PREFIX; | |
291 return s; | |
292 } | |
293 else if (s->display.x->h_thumbleft == wdesc) | |
294 { | |
295 *part_ptr = Qhthumbleft_part; | |
296 *prefix_ptr = HSCROLL_THUMBLEFT_PREFIX; | |
297 return s; | |
298 } | |
299 else if (s->display.x->h_thumbright == wdesc) | |
300 { | |
301 *part_ptr = Qhthumbright_part; | |
302 *prefix_ptr = HSCROLL_THUMBRIGHT_PREFIX; | |
303 return s; | |
304 } | |
305 } | |
306 return 0; | |
307 } | |
308 | |
309 /* Connect the screen-parameter names for X screens | |
310 to the ways of passing the parameter values to the window system. | |
311 | |
312 The name of a parameter, as a Lisp symbol, | |
313 has an `x-screen-parameter' property which is an integer in Lisp | |
314 but can be interpreted as an `enum x_screen_parm' in C. */ | |
315 | |
316 enum x_screen_parm | |
317 { | |
318 X_PARM_FOREGROUND_COLOR, | |
319 X_PARM_BACKGROUND_COLOR, | |
320 X_PARM_MOUSE_COLOR, | |
321 X_PARM_CURSOR_COLOR, | |
322 X_PARM_BORDER_COLOR, | |
323 X_PARM_ICON_TYPE, | |
324 X_PARM_FONT, | |
325 X_PARM_BORDER_WIDTH, | |
326 X_PARM_INTERNAL_BORDER_WIDTH, | |
327 X_PARM_NAME, | |
328 X_PARM_AUTORAISE, | |
329 X_PARM_AUTOLOWER, | |
330 X_PARM_VERT_SCROLLBAR, | |
331 X_PARM_HORIZ_SCROLLBAR, | |
332 }; | |
333 | |
334 | |
335 struct x_screen_parm_table | |
336 { | |
337 char *name; | |
338 void (*setter)( /* struct screen *screen, Lisp_Object val, oldval */ ); | |
339 }; | |
340 | |
341 void x_set_foreground_color (); | |
342 void x_set_background_color (); | |
343 void x_set_mouse_color (); | |
344 void x_set_cursor_color (); | |
345 void x_set_border_color (); | |
346 void x_set_icon_type (); | |
347 void x_set_font (); | |
348 void x_set_border_width (); | |
349 void x_set_internal_border_width (); | |
350 void x_set_name (); | |
351 void x_set_autoraise (); | |
352 void x_set_autolower (); | |
353 void x_set_vertical_scrollbar (); | |
354 void x_set_horizontal_scrollbar (); | |
355 | |
356 static struct x_screen_parm_table x_screen_parms[] = | |
357 { | |
358 "foreground-color", x_set_foreground_color, | |
359 "background-color", x_set_background_color, | |
360 "mouse-color", x_set_mouse_color, | |
361 "cursor-color", x_set_cursor_color, | |
362 "border-color", x_set_border_color, | |
363 "icon-type", x_set_icon_type, | |
364 "font", x_set_font, | |
365 "border-width", x_set_border_width, | |
366 "internal-border-width", x_set_internal_border_width, | |
367 "name", x_set_name, | |
368 "autoraise", x_set_autoraise, | |
369 "autolower", x_set_autolower, | |
370 "vertical-scrollbar", x_set_vertical_scrollbar, | |
371 "horizontal-scrollbar", x_set_horizontal_scrollbar, | |
372 }; | |
373 | |
374 /* Attach the `x-screen-parameter' properties to | |
375 the Lisp symbol names of parameters relevant to X. */ | |
376 | |
377 init_x_parm_symbols () | |
378 { | |
379 int i; | |
380 | |
381 Qx_screen_parameter = intern ("x-screen-parameter"); | |
382 | |
383 for (i = 0; i < sizeof (x_screen_parms)/sizeof (x_screen_parms[0]); i++) | |
384 Fput (intern (x_screen_parms[i].name), Qx_screen_parameter, | |
385 make_number (i)); | |
386 } | |
387 | |
388 /* Report to X that a screen parameter of screen S is being set or changed. | |
389 PARAM is the symbol that says which parameter. | |
390 VAL is the new value. | |
391 OLDVAL is the old value. | |
392 If the parameter is not specially recognized, do nothing; | |
393 otherwise the `x_set_...' function for this parameter. */ | |
394 | |
395 void | |
396 x_set_screen_param (s, param, val, oldval) | |
397 register struct screen *s; | |
398 Lisp_Object param; | |
399 register Lisp_Object val; | |
400 register Lisp_Object oldval; | |
401 { | |
402 register Lisp_Object tem; | |
403 tem = Fget (param, Qx_screen_parameter); | |
404 if (XTYPE (tem) == Lisp_Int | |
405 && XINT (tem) >= 0 | |
406 && XINT (tem) < sizeof (x_screen_parms)/sizeof (x_screen_parms[0])) | |
407 (*x_screen_parms[XINT (tem)].setter)(s, val, oldval); | |
408 } | |
409 | |
410 /* Insert a description of internally-recorded parameters of screen X | |
411 into the parameter alist *ALISTPTR that is to be given to the user. | |
412 Only parameters that are specific to the X window system | |
413 and whose values are not correctly recorded in the screen's | |
414 param_alist need to be considered here. */ | |
415 | |
416 x_report_screen_params (s, alistptr) | |
417 struct screen *s; | |
418 Lisp_Object *alistptr; | |
419 { | |
420 char buf[16]; | |
421 | |
422 store_in_alist (alistptr, "left", make_number (s->display.x->left_pos)); | |
423 store_in_alist (alistptr, "top", make_number (s->display.x->top_pos)); | |
424 store_in_alist (alistptr, "border-width", | |
425 make_number (s->display.x->border_width)); | |
426 store_in_alist (alistptr, "internal-border-width", | |
427 make_number (s->display.x->internal_border_width)); | |
428 sprintf (buf, "%d", s->display.x->window_desc); | |
429 store_in_alist (alistptr, "window-id", | |
430 build_string (buf)); | |
431 } | |
432 | |
433 /* Decide if color named COLOR is valid for the display | |
434 associated with the selected screen. */ | |
435 int | |
436 defined_color (color, color_def) | |
437 char *color; | |
438 Color *color_def; | |
439 { | |
440 register int foo; | |
441 Colormap screen_colormap; | |
442 | |
443 BLOCK_INPUT; | |
444 #ifdef HAVE_X11 | |
445 screen_colormap | |
446 = DefaultColormap (x_current_display, XDefaultScreen (x_current_display)); | |
447 | |
448 foo = XParseColor (x_current_display, screen_colormap, | |
449 color, color_def) | |
450 && XAllocColor (x_current_display, screen_colormap, color_def); | |
451 #else | |
452 foo = XParseColor (color, color_def) && XGetHardwareColor (color_def); | |
453 #endif /* not HAVE_X11 */ | |
454 UNBLOCK_INPUT; | |
455 | |
456 if (foo) | |
457 return 1; | |
458 else | |
459 return 0; | |
460 } | |
461 | |
462 /* Given a string ARG naming a color, compute a pixel value from it | |
463 suitable for screen S. | |
464 If S is not a color screen, return DEF (default) regardless of what | |
465 ARG says. */ | |
466 | |
467 int | |
468 x_decode_color (arg, def) | |
469 Lisp_Object arg; | |
470 int def; | |
471 { | |
472 Color cdef; | |
473 | |
474 CHECK_STRING (arg, 0); | |
475 | |
476 if (strcmp (XSTRING (arg)->data, "black") == 0) | |
477 return BLACK_PIX_DEFAULT; | |
478 else if (strcmp (XSTRING (arg)->data, "white") == 0) | |
479 return WHITE_PIX_DEFAULT; | |
480 | |
481 #ifdef HAVE_X11 | |
482 if (XFASTINT (x_screen_planes) <= 2) | |
483 return def; | |
484 #else | |
485 if (DISPLAY_CELLS <= 2) | |
486 return def; | |
487 #endif | |
488 | |
489 if (defined_color (XSTRING (arg)->data, &cdef)) | |
490 return cdef.pixel; | |
491 else | |
492 Fsignal (Qundefined_color, Fcons (arg, Qnil)); | |
493 } | |
494 | |
495 /* Functions called only from `x_set_screen_param' | |
496 to set individual parameters. | |
497 | |
498 If s->display.x->window_desc is 0, | |
499 the screen is being created and its X-window does not exist yet. | |
500 In that case, just record the parameter's new value | |
501 in the standard place; do not attempt to change the window. */ | |
502 | |
503 void | |
504 x_set_foreground_color (s, arg, oldval) | |
505 struct screen *s; | |
506 Lisp_Object arg, oldval; | |
507 { | |
508 s->display.x->foreground_pixel = x_decode_color (arg, BLACK_PIX_DEFAULT); | |
509 if (s->display.x->window_desc != 0) | |
510 { | |
511 #ifdef HAVE_X11 | |
512 BLOCK_INPUT; | |
513 XSetForeground (x_current_display, s->display.x->normal_gc, | |
514 s->display.x->foreground_pixel); | |
515 XSetBackground (x_current_display, s->display.x->reverse_gc, | |
516 s->display.x->foreground_pixel); | |
517 if (s->display.x->v_scrollbar) | |
518 { | |
519 Pixmap up_arrow_pixmap, down_arrow_pixmap, slider_pixmap; | |
520 | |
521 XSetWindowBorder (x_current_display, s->display.x->v_scrollbar, | |
522 s->display.x->foreground_pixel); | |
523 | |
524 slider_pixmap = | |
525 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
526 gray_bits, 16, 16, | |
527 s->display.x->foreground_pixel, | |
528 s->display.x->background_pixel, | |
529 DefaultDepth (x_current_display, | |
530 XDefaultScreen (x_current_display))); | |
531 up_arrow_pixmap = | |
532 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
533 up_arrow_bits, 16, 16, | |
534 s->display.x->foreground_pixel, | |
535 s->display.x->background_pixel, | |
536 DefaultDepth (x_current_display, | |
537 XDefaultScreen (x_current_display))); | |
538 down_arrow_pixmap = | |
539 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
540 down_arrow_bits, 16, 16, | |
541 s->display.x->foreground_pixel, | |
542 s->display.x->background_pixel, | |
543 DefaultDepth (x_current_display, | |
544 XDefaultScreen (x_current_display))); | |
545 | |
546 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->v_thumbup, | |
547 up_arrow_pixmap); | |
548 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->v_thumbdown, | |
549 down_arrow_pixmap); | |
550 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->v_slider, | |
551 slider_pixmap); | |
552 | |
553 XClearWindow (XDISPLAY s->display.x->v_thumbup); | |
554 XClearWindow (XDISPLAY s->display.x->v_thumbdown); | |
555 XClearWindow (XDISPLAY s->display.x->v_slider); | |
556 | |
557 XFreePixmap (x_current_display, down_arrow_pixmap); | |
558 XFreePixmap (x_current_display, up_arrow_pixmap); | |
559 XFreePixmap (x_current_display, slider_pixmap); | |
560 } | |
561 if (s->display.x->h_scrollbar) | |
562 { | |
563 Pixmap left_arrow_pixmap, right_arrow_pixmap, slider_pixmap; | |
564 | |
565 XSetWindowBorder (x_current_display, s->display.x->h_scrollbar, | |
566 s->display.x->foreground_pixel); | |
567 | |
568 slider_pixmap = | |
569 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
570 gray_bits, 16, 16, | |
571 s->display.x->foreground_pixel, | |
572 s->display.x->background_pixel, | |
573 DefaultDepth (x_current_display, | |
574 XDefaultScreen (x_current_display))); | |
575 | |
576 left_arrow_pixmap = | |
577 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
578 up_arrow_bits, 16, 16, | |
579 s->display.x->foreground_pixel, | |
580 s->display.x->background_pixel, | |
581 DefaultDepth (x_current_display, | |
582 XDefaultScreen (x_current_display))); | |
583 right_arrow_pixmap = | |
584 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
585 down_arrow_bits, 16, 16, | |
586 s->display.x->foreground_pixel, | |
587 s->display.x->background_pixel, | |
588 DefaultDepth (x_current_display, | |
589 XDefaultScreen (x_current_display))); | |
590 | |
591 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->h_slider, | |
592 slider_pixmap); | |
593 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->h_thumbleft, | |
594 left_arrow_pixmap); | |
595 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->h_thumbright, | |
596 right_arrow_pixmap); | |
597 | |
598 XClearWindow (XDISPLAY s->display.x->h_thumbleft); | |
599 XClearWindow (XDISPLAY s->display.x->h_thumbright); | |
600 XClearWindow (XDISPLAY s->display.x->h_slider); | |
601 | |
602 XFreePixmap (x_current_display, slider_pixmap); | |
603 XFreePixmap (x_current_display, left_arrow_pixmap); | |
604 XFreePixmap (x_current_display, right_arrow_pixmap); | |
605 } | |
606 UNBLOCK_INPUT; | |
607 #endif /* HAVE_X11 */ | |
608 if (s->visible) | |
609 redraw_screen (s); | |
610 } | |
611 } | |
612 | |
613 void | |
614 x_set_background_color (s, arg, oldval) | |
615 struct screen *s; | |
616 Lisp_Object arg, oldval; | |
617 { | |
618 Pixmap temp; | |
619 int mask; | |
620 | |
621 s->display.x->background_pixel = x_decode_color (arg, WHITE_PIX_DEFAULT); | |
622 | |
623 if (s->display.x->window_desc != 0) | |
624 { | |
625 BLOCK_INPUT; | |
626 #ifdef HAVE_X11 | |
627 /* The main screen. */ | |
628 XSetBackground (x_current_display, s->display.x->normal_gc, | |
629 s->display.x->background_pixel); | |
630 XSetForeground (x_current_display, s->display.x->reverse_gc, | |
631 s->display.x->background_pixel); | |
632 XSetWindowBackground (x_current_display, s->display.x->window_desc, | |
633 s->display.x->background_pixel); | |
634 | |
635 /* Scroll bars. */ | |
636 if (s->display.x->v_scrollbar) | |
637 { | |
638 Pixmap up_arrow_pixmap, down_arrow_pixmap, slider_pixmap; | |
639 | |
640 XSetWindowBackground (x_current_display, s->display.x->v_scrollbar, | |
641 s->display.x->background_pixel); | |
642 | |
643 slider_pixmap = | |
644 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
645 gray_bits, 16, 16, | |
646 s->display.x->foreground_pixel, | |
647 s->display.x->background_pixel, | |
648 DefaultDepth (x_current_display, | |
649 XDefaultScreen (x_current_display))); | |
650 up_arrow_pixmap = | |
651 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
652 up_arrow_bits, 16, 16, | |
653 s->display.x->foreground_pixel, | |
654 s->display.x->background_pixel, | |
655 DefaultDepth (x_current_display, | |
656 XDefaultScreen (x_current_display))); | |
657 down_arrow_pixmap = | |
658 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
659 down_arrow_bits, 16, 16, | |
660 s->display.x->foreground_pixel, | |
661 s->display.x->background_pixel, | |
662 DefaultDepth (x_current_display, | |
663 XDefaultScreen (x_current_display))); | |
664 | |
665 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->v_thumbup, | |
666 up_arrow_pixmap); | |
667 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->v_thumbdown, | |
668 down_arrow_pixmap); | |
669 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->v_slider, | |
670 slider_pixmap); | |
671 | |
672 XClearWindow (XDISPLAY s->display.x->v_thumbup); | |
673 XClearWindow (XDISPLAY s->display.x->v_thumbdown); | |
674 XClearWindow (XDISPLAY s->display.x->v_slider); | |
675 | |
676 XFreePixmap (x_current_display, down_arrow_pixmap); | |
677 XFreePixmap (x_current_display, up_arrow_pixmap); | |
678 XFreePixmap (x_current_display, slider_pixmap); | |
679 } | |
680 if (s->display.x->h_scrollbar) | |
681 { | |
682 Pixmap left_arrow_pixmap, right_arrow_pixmap, slider_pixmap; | |
683 | |
684 XSetWindowBackground (x_current_display, s->display.x->h_scrollbar, | |
685 s->display.x->background_pixel); | |
686 | |
687 slider_pixmap = | |
688 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
689 gray_bits, 16, 16, | |
690 s->display.x->foreground_pixel, | |
691 s->display.x->background_pixel, | |
692 DefaultDepth (x_current_display, | |
693 XDefaultScreen (x_current_display))); | |
694 | |
695 left_arrow_pixmap = | |
696 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
697 up_arrow_bits, 16, 16, | |
698 s->display.x->foreground_pixel, | |
699 s->display.x->background_pixel, | |
700 DefaultDepth (x_current_display, | |
701 XDefaultScreen (x_current_display))); | |
702 right_arrow_pixmap = | |
703 XCreatePixmapFromBitmapData (XDISPLAY s->display.x->window_desc, | |
704 down_arrow_bits, 16, 16, | |
705 s->display.x->foreground_pixel, | |
706 s->display.x->background_pixel, | |
707 DefaultDepth (x_current_display, | |
708 XDefaultScreen (x_current_display))); | |
709 | |
710 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->h_slider, | |
711 slider_pixmap); | |
712 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->h_thumbleft, | |
713 left_arrow_pixmap); | |
714 XSetWindowBackgroundPixmap (XDISPLAY s->display.x->h_thumbright, | |
715 right_arrow_pixmap); | |
716 | |
717 XClearWindow (XDISPLAY s->display.x->h_thumbleft); | |
718 XClearWindow (XDISPLAY s->display.x->h_thumbright); | |
719 XClearWindow (XDISPLAY s->display.x->h_slider); | |
720 | |
721 XFreePixmap (x_current_display, slider_pixmap); | |
722 XFreePixmap (x_current_display, left_arrow_pixmap); | |
723 XFreePixmap (x_current_display, right_arrow_pixmap); | |
724 } | |
725 #else | |
726 temp = XMakeTile (s->display.x->background_pixel); | |
727 XChangeBackground (s->display.x->window_desc, temp); | |
728 XFreePixmap (temp); | |
729 #endif /* not HAVE_X11 */ | |
730 UNBLOCK_INPUT; | |
731 | |
732 if (s->visible) | |
733 redraw_screen (s); | |
734 } | |
735 } | |
736 | |
737 void | |
738 x_set_mouse_color (s, arg, oldval) | |
739 struct screen *s; | |
740 Lisp_Object arg, oldval; | |
741 { | |
742 Cursor cursor, nontext_cursor, mode_cursor; | |
743 int mask_color; | |
744 | |
745 if (!EQ (Qnil, arg)) | |
746 s->display.x->mouse_pixel = x_decode_color (arg, BLACK_PIX_DEFAULT); | |
747 mask_color = s->display.x->background_pixel; | |
748 /* No invisible pointers. */ | |
749 if (mask_color == s->display.x->mouse_pixel | |
750 && mask_color == s->display.x->background_pixel) | |
751 s->display.x->mouse_pixel = s->display.x->foreground_pixel; | |
752 | |
753 BLOCK_INPUT; | |
754 #ifdef HAVE_X11 | |
755 if (!EQ (Qnil, Vx_pointer_shape)) | |
756 { | |
757 CHECK_NUMBER (Vx_pointer_shape, 0); | |
758 cursor = XCreateFontCursor (x_current_display, XINT (Vx_pointer_shape)); | |
759 } | |
760 else | |
761 cursor = XCreateFontCursor (x_current_display, XC_xterm); | |
762 | |
763 if (!EQ (Qnil, Vx_nontext_pointer_shape)) | |
764 { | |
765 CHECK_NUMBER (Vx_nontext_pointer_shape, 0); | |
766 nontext_cursor = XCreateFontCursor (x_current_display, | |
767 XINT (Vx_nontext_pointer_shape)); | |
768 } | |
769 else | |
770 nontext_cursor = XCreateFontCursor (x_current_display, XC_left_ptr); | |
771 | |
772 if (!EQ (Qnil, Vx_mode_pointer_shape)) | |
773 { | |
774 CHECK_NUMBER (Vx_mode_pointer_shape, 0); | |
775 mode_cursor = XCreateFontCursor (x_current_display, | |
776 XINT (Vx_mode_pointer_shape)); | |
777 } | |
778 else | |
779 mode_cursor = XCreateFontCursor (x_current_display, XC_xterm); | |
780 | |
781 { | |
782 XColor fore_color, back_color; | |
783 | |
784 fore_color.pixel = s->display.x->mouse_pixel; | |
785 back_color.pixel = mask_color; | |
786 XQueryColor (x_current_display, | |
787 DefaultColormap (x_current_display, | |
788 DefaultScreen (x_current_display)), | |
789 &fore_color); | |
790 XQueryColor (x_current_display, | |
791 DefaultColormap (x_current_display, | |
792 DefaultScreen (x_current_display)), | |
793 &back_color); | |
794 XRecolorCursor (x_current_display, cursor, | |
795 &fore_color, &back_color); | |
796 XRecolorCursor (x_current_display, nontext_cursor, | |
797 &fore_color, &back_color); | |
798 XRecolorCursor (x_current_display, mode_cursor, | |
799 &fore_color, &back_color); | |
800 } | |
801 #else /* X10 */ | |
802 cursor = XCreateCursor (16, 16, MouseCursor, MouseMask, | |
803 0, 0, | |
804 s->display.x->mouse_pixel, | |
805 s->display.x->background_pixel, | |
806 GXcopy); | |
807 #endif /* X10 */ | |
808 | |
809 if (s->display.x->window_desc != 0) | |
810 { | |
811 XDefineCursor (XDISPLAY s->display.x->window_desc, cursor); | |
812 } | |
813 | |
814 if (cursor != s->display.x->text_cursor && s->display.x->text_cursor != 0) | |
815 XFreeCursor (XDISPLAY s->display.x->text_cursor); | |
816 s->display.x->text_cursor = cursor; | |
817 #ifdef HAVE_X11 | |
818 if (nontext_cursor != s->display.x->nontext_cursor | |
819 && s->display.x->nontext_cursor != 0) | |
820 XFreeCursor (XDISPLAY s->display.x->nontext_cursor); | |
821 s->display.x->nontext_cursor = nontext_cursor; | |
822 | |
823 if (mode_cursor != s->display.x->modeline_cursor | |
824 && s->display.x->modeline_cursor != 0) | |
825 XFreeCursor (XDISPLAY s->display.x->modeline_cursor); | |
826 s->display.x->modeline_cursor = mode_cursor; | |
827 #endif /* HAVE_X11 */ | |
828 | |
829 XFlushQueue (); | |
830 UNBLOCK_INPUT; | |
831 } | |
832 | |
833 void | |
834 x_set_cursor_color (s, arg, oldval) | |
835 struct screen *s; | |
836 Lisp_Object arg, oldval; | |
837 { | |
838 unsigned long fore_pixel; | |
839 | |
840 if (!EQ (Vx_cursor_fore_pixel, Qnil)) | |
841 fore_pixel = x_decode_color (Vx_cursor_fore_pixel, WHITE_PIX_DEFAULT); | |
842 else | |
843 fore_pixel = s->display.x->background_pixel; | |
844 s->display.x->cursor_pixel = x_decode_color (arg, BLACK_PIX_DEFAULT); | |
845 /* No invisible cursors */ | |
846 if (s->display.x->cursor_pixel == s->display.x->background_pixel) | |
847 { | |
848 s->display.x->cursor_pixel == s->display.x->mouse_pixel; | |
849 if (s->display.x->cursor_pixel == fore_pixel) | |
850 fore_pixel = s->display.x->background_pixel; | |
851 } | |
852 | |
853 if (s->display.x->window_desc != 0) | |
854 { | |
855 #ifdef HAVE_X11 | |
856 BLOCK_INPUT; | |
857 XSetBackground (x_current_display, s->display.x->cursor_gc, | |
858 s->display.x->cursor_pixel); | |
859 XSetForeground (x_current_display, s->display.x->cursor_gc, | |
860 fore_pixel); | |
861 UNBLOCK_INPUT; | |
862 #endif /* HAVE_X11 */ | |
863 | |
864 if (s->visible) | |
865 { | |
866 x_display_cursor (s, 0); | |
867 x_display_cursor (s, 1); | |
868 } | |
869 } | |
870 } | |
871 | |
872 /* Set the border-color of screen S to value described by ARG. | |
873 ARG can be a string naming a color. | |
874 The border-color is used for the border that is drawn by the X server. | |
875 Note that this does not fully take effect if done before | |
876 S has an x-window; it must be redone when the window is created. | |
877 | |
878 Note: this is done in two routines because of the way X10 works. | |
879 | |
880 Note: under X11, this is normally the province of the window manager, | |
881 and so emacs' border colors may be overridden. */ | |
882 | |
883 void | |
884 x_set_border_color (s, arg, oldval) | |
885 struct screen *s; | |
886 Lisp_Object arg, oldval; | |
887 { | |
888 unsigned char *str; | |
889 int pix; | |
890 | |
891 CHECK_STRING (arg, 0); | |
892 str = XSTRING (arg)->data; | |
893 | |
894 #ifndef HAVE_X11 | |
895 if (!strcmp (str, "grey") || !strcmp (str, "Grey") | |
896 || !strcmp (str, "gray") || !strcmp (str, "Gray")) | |
897 pix = -1; | |
898 else | |
899 #endif /* X10 */ | |
900 | |
901 pix = x_decode_color (arg, BLACK_PIX_DEFAULT); | |
902 | |
903 x_set_border_pixel (s, pix); | |
904 } | |
905 | |
906 /* Set the border-color of screen S to pixel value PIX. | |
907 Note that this does not fully take effect if done before | |
908 S has an x-window. */ | |
909 | |
910 x_set_border_pixel (s, pix) | |
911 struct screen *s; | |
912 int pix; | |
913 { | |
914 s->display.x->border_pixel = pix; | |
915 | |
916 if (s->display.x->window_desc != 0 && s->display.x->border_width > 0) | |
917 { | |
918 Pixmap temp; | |
919 int mask; | |
920 | |
921 BLOCK_INPUT; | |
922 #ifdef HAVE_X11 | |
923 XSetWindowBorder (x_current_display, s->display.x->window_desc, | |
924 pix); | |
925 if (s->display.x->h_scrollbar) | |
926 XSetWindowBorder (x_current_display, s->display.x->h_slider, | |
927 pix); | |
928 if (s->display.x->v_scrollbar) | |
929 XSetWindowBorder (x_current_display, s->display.x->v_slider, | |
930 pix); | |
931 #else | |
932 if (pix < 0) | |
933 temp = XMakePixmap ((Bitmap) XStoreBitmap (16, 16, gray_bits), | |
934 BLACK_PIX_DEFAULT, WHITE_PIX_DEFAULT); | |
935 else | |
936 temp = XMakeTile (pix); | |
937 XChangeBorder (s->display.x->window_desc, temp); | |
938 XFreePixmap (XDISPLAY temp); | |
939 #endif /* not HAVE_X11 */ | |
940 UNBLOCK_INPUT; | |
941 | |
942 if (s->visible) | |
943 redraw_screen (s); | |
944 } | |
945 } | |
946 | |
947 void | |
948 x_set_icon_type (s, arg, oldval) | |
949 struct screen *s; | |
950 Lisp_Object arg, oldval; | |
951 { | |
952 Lisp_Object tem; | |
953 int result; | |
954 | |
955 if (EQ (oldval, Qnil) == EQ (arg, Qnil)) | |
956 return; | |
957 | |
958 BLOCK_INPUT; | |
959 if (NULL (arg)) | |
960 result = x_text_icon (s, 0); | |
961 else | |
962 result = x_bitmap_icon (s, 0); | |
963 | |
964 if (result) | |
965 { | |
966 error ("No icon window available."); | |
967 UNBLOCK_INPUT; | |
968 } | |
969 | |
970 /* If the window was unmapped (and its icon was mapped), | |
971 the new icon is not mapped, so map the window in its stead. */ | |
972 if (s->visible) | |
973 XMapWindow (XDISPLAY s->display.x->window_desc); | |
974 | |
975 XFlushQueue (); | |
976 UNBLOCK_INPUT; | |
977 } | |
978 | |
979 void | |
980 x_set_font (s, arg, oldval) | |
981 struct screen *s; | |
982 Lisp_Object arg, oldval; | |
983 { | |
984 unsigned char *name; | |
985 int result; | |
986 | |
987 CHECK_STRING (arg, 1); | |
988 name = XSTRING (arg)->data; | |
989 | |
990 BLOCK_INPUT; | |
991 result = x_new_font (s, name); | |
992 UNBLOCK_INPUT; | |
993 | |
994 if (result) | |
995 error ("Font \"%s\" is not defined", name); | |
996 } | |
997 | |
998 void | |
999 x_set_border_width (s, arg, oldval) | |
1000 struct screen *s; | |
1001 Lisp_Object arg, oldval; | |
1002 { | |
1003 CHECK_NUMBER (arg, 0); | |
1004 | |
1005 if (XINT (arg) == s->display.x->border_width) | |
1006 return; | |
1007 | |
1008 if (s->display.x->window_desc != 0) | |
1009 error ("Cannot change the border width of a window"); | |
1010 | |
1011 s->display.x->border_width = XINT (arg); | |
1012 } | |
1013 | |
1014 void | |
1015 x_set_internal_border_width (s, arg, oldval) | |
1016 struct screen *s; | |
1017 Lisp_Object arg, oldval; | |
1018 { | |
1019 int mask; | |
1020 int old = s->display.x->internal_border_width; | |
1021 | |
1022 CHECK_NUMBER (arg, 0); | |
1023 s->display.x->internal_border_width = XINT (arg); | |
1024 if (s->display.x->internal_border_width < 0) | |
1025 s->display.x->internal_border_width = 0; | |
1026 | |
1027 if (s->display.x->internal_border_width == old) | |
1028 return; | |
1029 | |
1030 if (s->display.x->window_desc != 0) | |
1031 { | |
1032 BLOCK_INPUT; | |
1033 x_set_window_size (s, s->width, s->height); | |
1034 #if 0 | |
1035 x_set_resize_hint (s); | |
1036 #endif | |
1037 XFlushQueue (); | |
1038 UNBLOCK_INPUT; | |
1039 SET_SCREEN_GARBAGED (s); | |
1040 } | |
1041 } | |
1042 | |
1043 void | |
1044 x_set_name (s, arg, oldval) | |
1045 struct screen *s; | |
1046 Lisp_Object arg, oldval; | |
1047 { | |
1048 CHECK_STRING (arg, 0); | |
1049 | |
1050 if (s->display.x->window_desc) | |
1051 { | |
1052 s->name = arg; | |
1053 BLOCK_INPUT; | |
1054 XStoreName (XDISPLAY s->display.x->window_desc, | |
1055 (char *) XSTRING (arg)->data); | |
1056 XSetIconName (XDISPLAY s->display.x->window_desc, | |
1057 (char *) XSTRING (arg)->data); | |
1058 UNBLOCK_INPUT; | |
1059 } | |
1060 } | |
1061 | |
1062 void | |
1063 x_set_autoraise (s, arg, oldval) | |
1064 struct screen *s; | |
1065 Lisp_Object arg, oldval; | |
1066 { | |
1067 s->auto_raise = !EQ (Qnil, arg); | |
1068 } | |
1069 | |
1070 void | |
1071 x_set_autolower (s, arg, oldval) | |
1072 struct screen *s; | |
1073 Lisp_Object arg, oldval; | |
1074 { | |
1075 s->auto_lower = !EQ (Qnil, arg); | |
1076 } | |
1077 | |
1078 #ifdef HAVE_X11 | |
1079 int n_faces; | |
1080 | |
1081 x_set_face (scr, font, background, foreground, stipple) | |
1082 struct screen *scr; | |
1083 XFontStruct *font; | |
1084 unsigned long background, foreground; | |
1085 Pixmap stipple; | |
1086 { | |
1087 XGCValues gc_values; | |
1088 GC temp_gc; | |
1089 unsigned long gc_mask; | |
1090 struct face *new_face; | |
1091 unsigned int width = 16; | |
1092 unsigned int height = 16; | |
1093 | |
1094 if (n_faces == MAX_FACES_AND_GLYPHS) | |
1095 return 1; | |
1096 | |
1097 /* Create the Graphics Context. */ | |
1098 gc_values.font = font->fid; | |
1099 gc_values.foreground = foreground; | |
1100 gc_values.background = background; | |
1101 gc_values.line_width = 0; | |
1102 gc_mask = GCLineWidth | GCFont | GCForeground | GCBackground; | |
1103 if (stipple) | |
1104 { | |
1105 gc_values.stipple | |
1106 = XCreateBitmapFromData (x_current_display, ROOT_WINDOW, | |
1107 (char *) stipple, width, height); | |
1108 gc_mask |= GCStipple; | |
1109 } | |
1110 | |
1111 temp_gc = XCreateGC (x_current_display, scr->display.x->window_desc, | |
1112 gc_mask, &gc_values); | |
1113 if (!temp_gc) | |
1114 return 1; | |
1115 new_face = (struct face *) xmalloc (sizeof (struct face)); | |
1116 if (!new_face) | |
1117 { | |
1118 XFreeGC (x_current_display, temp_gc); | |
1119 return 1; | |
1120 } | |
1121 | |
1122 new_face->font = font; | |
1123 new_face->foreground = foreground; | |
1124 new_face->background = background; | |
1125 new_face->face_gc = temp_gc; | |
1126 if (stipple) | |
1127 new_face->stipple = gc_values.stipple; | |
1128 | |
1129 x_face_table[++n_faces] = new_face; | |
1130 return 1; | |
1131 } | |
1132 | |
1133 x_set_glyph (scr, glyph) | |
1134 { | |
1135 } | |
1136 | |
1137 #if 0 | |
1138 DEFUN ("x-set-face-font", Fx_set_face_font, Sx_set_face_font, 4, 2, 0, | |
1139 "Specify face table entry FACE-CODE to be the font named by FONT,\n\ | |
1140 in colors FOREGROUND and BACKGROUND.") | |
1141 (face_code, font_name, foreground, background) | |
1142 Lisp_Object face_code; | |
1143 Lisp_Object font_name; | |
1144 Lisp_Object foreground; | |
1145 Lisp_Object background; | |
1146 { | |
1147 register struct face *fp; /* Current face info. */ | |
1148 register int fn; /* Face number. */ | |
1149 register FONT_TYPE *f; /* Font data structure. */ | |
1150 unsigned char *newname; | |
1151 int fg, bg; | |
1152 GC temp_gc; | |
1153 XGCValues gc_values; | |
1154 | |
1155 /* Need to do something about this. */ | |
1156 Drawable drawable = selected_screen->display.x->window_desc; | |
1157 | |
1158 CHECK_NUMBER (face_code, 1); | |
1159 CHECK_STRING (font_name, 2); | |
1160 | |
1161 if (EQ (foreground, Qnil) || EQ (background, Qnil)) | |
1162 { | |
1163 fg = selected_screen->display.x->foreground_pixel; | |
1164 bg = selected_screen->display.x->background_pixel; | |
1165 } | |
1166 else | |
1167 { | |
1168 CHECK_NUMBER (foreground, 0); | |
1169 CHECK_NUMBER (background, 1); | |
1170 | |
1171 fg = x_decode_color (XINT (foreground), BLACK_PIX_DEFAULT); | |
1172 bg = x_decode_color (XINT (background), WHITE_PIX_DEFAULT); | |
1173 } | |
1174 | |
1175 fn = XINT (face_code); | |
1176 if ((fn < 1) || (fn > 255)) | |
1177 error ("Invalid face code, %d", fn); | |
1178 | |
1179 newname = XSTRING (font_name)->data; | |
1180 BLOCK_INPUT; | |
1181 f = (*newname == 0 ? 0 : XGetFont (newname)); | |
1182 UNBLOCK_INPUT; | |
1183 if (f == 0) | |
1184 error ("Font \"%s\" is not defined", newname); | |
1185 | |
1186 fp = x_face_table[fn]; | |
1187 if (fp == 0) | |
1188 { | |
1189 x_face_table[fn] = fp = (struct face *) xmalloc (sizeof (struct face)); | |
1190 bzero (fp, sizeof (struct face)); | |
1191 fp->face_type = x_pixmap; | |
1192 } | |
1193 else if (FACE_IS_FONT (fn)) | |
1194 { | |
1195 BLOCK_INPUT; | |
1196 XFreeGC (FACE_FONT (fn)); | |
1197 UNBLOCK_INPUT; | |
1198 } | |
1199 else if (FACE_IS_IMAGE (fn)) /* This should not happen... */ | |
1200 { | |
1201 BLOCK_INPUT; | |
1202 XFreePixmap (x_current_display, FACE_IMAGE (fn)); | |
1203 fp->face_type = x_font; | |
1204 UNBLOCK_INPUT; | |
1205 } | |
1206 else | |
1207 abort (); | |
1208 | |
1209 fp->face_GLYPH.font_desc.font = f; | |
1210 gc_values.font = f->fid; | |
1211 gc_values.foreground = fg; | |
1212 gc_values.background = bg; | |
1213 fp->face_GLYPH.font_desc.face_gc = XCreateGC (x_current_display, | |
1214 drawable, GCFont | GCForeground | |
1215 | GCBackground, &gc_values); | |
1216 fp->face_GLYPH.font_desc.font_width = FONT_WIDTH (f); | |
1217 fp->face_GLYPH.font_desc.font_height = FONT_HEIGHT (f); | |
1218 | |
1219 return face_code; | |
1220 } | |
1221 #endif | |
1222 #else /* X10 */ | |
1223 DEFUN ("x-set-face", Fx_set_face, Sx_set_face, 4, 4, 0, | |
1224 "Specify face table entry FACE-CODE to be the font named by FONT,\n\ | |
1225 in colors FOREGROUND and BACKGROUND.") | |
1226 (face_code, font_name, foreground, background) | |
1227 Lisp_Object face_code; | |
1228 Lisp_Object font_name; | |
1229 Lisp_Object foreground; | |
1230 Lisp_Object background; | |
1231 { | |
1232 register struct face *fp; /* Current face info. */ | |
1233 register int fn; /* Face number. */ | |
1234 register FONT_TYPE *f; /* Font data structure. */ | |
1235 unsigned char *newname; | |
1236 | |
1237 CHECK_NUMBER (face_code, 1); | |
1238 CHECK_STRING (font_name, 2); | |
1239 | |
1240 fn = XINT (face_code); | |
1241 if ((fn < 1) || (fn > 255)) | |
1242 error ("Invalid face code, %d", fn); | |
1243 | |
1244 /* Ask the server to find the specified font. */ | |
1245 newname = XSTRING (font_name)->data; | |
1246 BLOCK_INPUT; | |
1247 f = (*newname == 0 ? 0 : XGetFont (newname)); | |
1248 UNBLOCK_INPUT; | |
1249 if (f == 0) | |
1250 error ("Font \"%s\" is not defined", newname); | |
1251 | |
1252 /* Get the face structure for face_code in the face table. | |
1253 Make sure it exists. */ | |
1254 fp = x_face_table[fn]; | |
1255 if (fp == 0) | |
1256 { | |
1257 x_face_table[fn] = fp = (struct face *) xmalloc (sizeof (struct face)); | |
1258 bzero (fp, sizeof (struct face)); | |
1259 } | |
1260 | |
1261 /* If this face code already exists, get rid of the old font. */ | |
1262 if (fp->font != 0 && fp->font != f) | |
1263 { | |
1264 BLOCK_INPUT; | |
1265 XLoseFont (fp->font); | |
1266 UNBLOCK_INPUT; | |
1267 } | |
1268 | |
1269 /* Store the specified information in FP. */ | |
1270 fp->fg = x_decode_color (foreground, BLACK_PIX_DEFAULT); | |
1271 fp->bg = x_decode_color (background, WHITE_PIX_DEFAULT); | |
1272 fp->font = f; | |
1273 | |
1274 return face_code; | |
1275 } | |
1276 #endif /* X10 */ | |
1277 | |
1278 #if 0 | |
1279 /* This is excluded because there is no painless way | |
1280 to get or to remember the name of the font. */ | |
1281 | |
1282 DEFUN ("x-get-face", Fx_get_face, Sx_get_face, 1, 1, 0, | |
1283 "Get data defining face code FACE. FACE is an integer.\n\ | |
1284 The value is a list (FONT FG-COLOR BG-COLOR).") | |
1285 (face) | |
1286 Lisp_Object face; | |
1287 { | |
1288 register struct face *fp; /* Current face info. */ | |
1289 register int fn; /* Face number. */ | |
1290 | |
1291 CHECK_NUMBER (face, 1); | |
1292 fn = XINT (face); | |
1293 if ((fn < 1) || (fn > 255)) | |
1294 error ("Invalid face code, %d", fn); | |
1295 | |
1296 /* Make sure the face table exists and this face code is defined. */ | |
1297 if (x_face_table == 0 || x_face_table[fn] == 0) | |
1298 return Qnil; | |
1299 | |
1300 fp = x_face_table[fn]; | |
1301 | |
1302 return Fcons (build_string (fp->name), | |
1303 Fcons (make_number (fp->fg), | |
1304 Fcons (make_number (fp->bg), Qnil))); | |
1305 } | |
1306 #endif /* 0 */ | |
1307 | |
1308 /* Subroutines of creating an X screen. */ | |
1309 | |
1310 #ifdef HAVE_X11 | |
1311 extern char *x_get_string_resource (); | |
1312 extern XrmDatabase x_load_resources (); | |
1313 | |
1314 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 1, 3, 0, | |
1315 "Retrieve the value of ATTRIBUTE from the X defaults database. This\n\ | |
1316 searches using a key of the form \"INSTANCE.ATTRIBUTE\", with class\n\ | |
1317 \"Emacs\", where INSTANCE is the name under which Emacs was invoked.\n\ | |
1318 \n\ | |
1319 Optional arguments COMPONENT and CLASS specify the component for which\n\ | |
1320 we should look up ATTRIBUTE. When specified, Emacs searches using a\n\ | |
1321 key of the form INSTANCE.COMPONENT.ATTRIBUTE, with class \"Emacs.CLASS\".") | |
1322 (attribute, name, class) | |
1323 Lisp_Object attribute, name, class; | |
1324 { | |
1325 register char *value; | |
1326 char *name_key; | |
1327 char *class_key; | |
1328 | |
1329 CHECK_STRING (attribute, 0); | |
1330 if (!NULL (name)) | |
1331 CHECK_STRING (name, 1); | |
1332 if (!NULL (class)) | |
1333 CHECK_STRING (class, 2); | |
1334 if (NULL (name) != NULL (class)) | |
1335 error ("x-get-resource: must specify both NAME and CLASS or neither"); | |
1336 | |
1337 if (NULL (name)) | |
1338 { | |
398 | 1339 name_key = (char *) alloca (XSTRING (invocation_name)->size + 1 |
1340 + XSTRING (attribute)->size + 1); | |
1341 | |
389 | 1342 sprintf (name_key, "%s.%s", |
1343 XSTRING (invocation_name)->data, | |
1344 XSTRING (attribute)->data); | |
1345 class_key = EMACS_CLASS; | |
1346 } | |
1347 else | |
1348 { | |
398 | 1349 name_key = (char *) alloca (XSTRING (invocation_name)->size + 1 |
1350 + XSTRING (name)->size + 1 | |
1351 + XSTRING (attribute)->size + 1); | |
1352 | |
389 | 1353 class_key = (char *) alloca (sizeof (EMACS_CLASS) |
1354 + XSTRING (class)->size + 1); | |
1355 | |
1356 sprintf (name_key, "%s.%s.%s", | |
1357 XSTRING (invocation_name)->data, | |
1358 XSTRING (name)->data, | |
1359 XSTRING (attribute)->data); | |
1360 sprintf (class_key, "%s.%s", | |
1361 XSTRING (invocation_name)->data, | |
1362 XSTRING (class)->data); | |
1363 } | |
1364 | |
1365 value = x_get_string_resource (xrdb, name_key, class_key); | |
1366 | |
1367 if (value != (char *) 0) | |
1368 return build_string (value); | |
1369 else | |
1370 return Qnil; | |
1371 } | |
1372 | |
1373 #else /* X10 */ | |
1374 | |
398 | 1375 DEFUN ("x-get-default", Fx_get_default, Sx_get_default, 1, 1, 0, |
389 | 1376 "Get X default ATTRIBUTE from the system, or nil if no default.\n\ |
1377 Value is a string (when not nil) and ATTRIBUTE is also a string.\n\ | |
1378 The defaults are specified in the file `~/.Xdefaults'.") | |
398 | 1379 (arg) |
1380 Lisp_Object arg; | |
389 | 1381 { |
1382 register unsigned char *value; | |
1383 | |
1384 CHECK_STRING (arg, 1); | |
1385 | |
1386 value = (unsigned char *) XGetDefault (XDISPLAY | |
1387 XSTRING (invocation_name)->data, | |
1388 XSTRING (arg)->data); | |
1389 if (value == 0) | |
1390 /* Try reversing last two args, in case this is the buggy version of X. */ | |
1391 value = (unsigned char *) XGetDefault (XDISPLAY | |
1392 XSTRING (arg)->data, | |
1393 XSTRING (invocation_name)->data); | |
1394 if (value != 0) | |
1395 return build_string (value); | |
1396 else | |
1397 return (Qnil); | |
1398 } | |
1399 | |
398 | 1400 #define Fx_get_resource(attribute, name, class) Fx_get_default(attribute) |
389 | 1401 |
1402 #endif /* X10 */ | |
1403 | |
398 | 1404 /* Types we might convert a resource string into. */ |
1405 enum resource_types | |
1406 { | |
1407 number, boolean, string, | |
1408 }; | |
1409 | |
389 | 1410 /* Return the value of parameter PARAM. |
398 | 1411 |
1412 First search ALIST, then Vdefault_screen_alist, then the X defaults | |
1413 database, using SCREEN_NAME as the subcomponent of emacs and | |
1414 ATTRIBUTE as the attribute name. | |
1415 | |
1416 Convert the resource to the type specified by desired_type. | |
1417 | |
1418 If no default is specified, return nil. */ | |
389 | 1419 |
1420 static Lisp_Object | |
398 | 1421 x_get_arg (alist, param, screen_name, attribute, type) |
389 | 1422 Lisp_Object alist, param, screen_name; |
398 | 1423 char *attribute; |
1424 enum resource_types type; | |
389 | 1425 { |
1426 register Lisp_Object tem; | |
436
6e0a136fca4f
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
398
diff
changeset
|
1427 int i; |
389 | 1428 |
1429 tem = Fassq (param, alist); | |
1430 if (EQ (tem, Qnil)) | |
1431 tem = Fassq (param, Vdefault_screen_alist); | |
398 | 1432 if (EQ (tem, Qnil) && attribute) |
389 | 1433 { |
398 | 1434 Lisp_Object sterile_name; |
1435 | |
1436 /* Build a version of screen name that is safe to use as a | |
1437 component name. */ | |
1438 if (XTYPE (screen_name) == Lisp_String) | |
1439 { | |
1440 sterile_name = make_uninit_string (XSTRING (screen_name)->size); | |
1441 | |
1442 for (i = 0; i < XSTRING (sterile_name)->size; i++) | |
389 | 1443 { |
398 | 1444 int c = XSTRING (screen_name)->data[i]; |
1445 if (c == ':' || c == '.' || c == '*' || isspace (c)) | |
1446 c = '_'; | |
1447 XSTRING (sterile_name)->data[i] = c; | |
389 | 1448 } |
398 | 1449 } |
1450 else | |
1451 sterile_name = Qnil; | |
1452 | |
1453 tem = Fx_get_resource (build_string (attribute), | |
1454 sterile_name, | |
1455 (NULL (sterile_name) ? Qnil : screen_class)); | |
1456 | |
1457 if (NULL (tem)) | |
1458 return Qnil; | |
1459 | |
1460 switch (type) | |
1461 { | |
1462 case number: | |
1463 return make_number (atoi (XSTRING (tem)->data)); | |
1464 | |
1465 case boolean: | |
1466 tem = Fdowncase (tem); | |
1467 if (!strcmp (XSTRING (tem)->data, "on") | |
1468 || !strcmp (XSTRING (tem)->data, "true")) | |
1469 return Qt; | |
1470 else | |
1471 return Qnil; | |
1472 | |
1473 case string: | |
1474 return tem; | |
1475 | |
1476 default: | |
1477 abort (); | |
1478 } | |
389 | 1479 } |
1480 return Fcdr (tem); | |
1481 } | |
1482 | |
1483 /* Record in screen S the specified or default value according to ALIST | |
1484 of the parameter named PARAM (a Lisp symbol). | |
1485 If no value is specified for PARAM, look for an X default for XPROP | |
1486 on the screen named NAME. | |
1487 If that is not found either, use the value DEFLT. */ | |
1488 | |
1489 static Lisp_Object | |
398 | 1490 x_default_parameter (s, alist, propname, deflt, xprop, type) |
389 | 1491 struct screen *s; |
1492 Lisp_Object alist; | |
1493 char *propname; | |
1494 Lisp_Object deflt; | |
1495 char *xprop; | |
398 | 1496 enum resource_types type; |
389 | 1497 { |
1498 Lisp_Object propsym = intern (propname); | |
1499 Lisp_Object tem; | |
1500 | |
398 | 1501 tem = x_get_arg (alist, propsym, s->name, xprop, type); |
389 | 1502 if (EQ (tem, Qnil)) |
1503 tem = deflt; | |
1504 store_screen_param (s, propsym, tem); | |
1505 x_set_screen_param (s, propsym, tem, Qnil); | |
1506 return tem; | |
1507 } | |
1508 | |
1509 DEFUN ("x-geometry", Fx_geometry, Sx_geometry, 1, 1, 0, | |
1510 "Parse an X-style geometry string STRING.\n\ | |
1511 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).") | |
1512 (string) | |
1513 { | |
1514 int geometry, x, y; | |
1515 unsigned int width, height; | |
1516 Lisp_Object values[4]; | |
1517 | |
1518 CHECK_STRING (string, 0); | |
1519 | |
1520 geometry = XParseGeometry ((char *) XSTRING (string)->data, | |
1521 &x, &y, &width, &height); | |
1522 | |
1523 switch (geometry & 0xf) /* Mask out {X,Y}Negative */ | |
1524 { | |
1525 case (XValue | YValue): | |
1526 /* What's one pixel among friends? | |
1527 Perhaps fix this some day by returning symbol `extreme-top'... */ | |
1528 if (x == 0 && (geometry & XNegative)) | |
1529 x = -1; | |
1530 if (y == 0 && (geometry & YNegative)) | |
1531 y = -1; | |
1532 values[0] = Fcons (intern ("left"), make_number (x)); | |
1533 values[1] = Fcons (intern ("top"), make_number (y)); | |
1534 return Flist (2, values); | |
1535 break; | |
1536 | |
1537 case (WidthValue | HeightValue): | |
1538 values[0] = Fcons (intern ("width"), make_number (width)); | |
1539 values[1] = Fcons (intern ("height"), make_number (height)); | |
1540 return Flist (2, values); | |
1541 break; | |
1542 | |
1543 case (XValue | YValue | WidthValue | HeightValue): | |
1544 if (x == 0 && (geometry & XNegative)) | |
1545 x = -1; | |
1546 if (y == 0 && (geometry & YNegative)) | |
1547 y = -1; | |
1548 values[0] = Fcons (intern ("width"), make_number (width)); | |
1549 values[1] = Fcons (intern ("height"), make_number (height)); | |
1550 values[2] = Fcons (intern ("left"), make_number (x)); | |
1551 values[3] = Fcons (intern ("top"), make_number (y)); | |
1552 return Flist (4, values); | |
1553 break; | |
1554 | |
1555 case 0: | |
1556 return Qnil; | |
1557 | |
1558 default: | |
1559 error ("Must specify x and y value, and/or width and height"); | |
1560 } | |
1561 } | |
1562 | |
1563 #ifdef HAVE_X11 | |
1564 /* Calculate the desired size and position of this window, | |
1565 or set rubber-band prompting if none. */ | |
1566 | |
1567 #define DEFAULT_ROWS 40 | |
1568 #define DEFAULT_COLS 80 | |
1569 | |
1570 static | |
1571 x_figure_window_size (s, parms) | |
1572 struct screen *s; | |
1573 Lisp_Object parms; | |
1574 { | |
1575 register Lisp_Object tem0, tem1; | |
1576 int height, width, left, top; | |
1577 register int geometry; | |
1578 long window_prompting = 0; | |
1579 | |
1580 /* Default values if we fall through. | |
1581 Actually, if that happens we should get | |
1582 window manager prompting. */ | |
1583 s->width = DEFAULT_COLS; | |
1584 s->height = DEFAULT_ROWS; | |
1585 s->display.x->top_pos = 1; | |
1586 s->display.x->left_pos = 1; | |
1587 | |
398 | 1588 tem0 = x_get_arg (parms, intern ("height"), s->name, 0, 0); |
1589 tem1 = x_get_arg (parms, intern ("width"), s->name, 0, 0); | |
389 | 1590 if (! EQ (tem0, Qnil) && ! EQ (tem1, Qnil)) |
1591 { | |
1592 CHECK_NUMBER (tem0, 0); | |
1593 CHECK_NUMBER (tem1, 0); | |
1594 s->height = XINT (tem0); | |
1595 s->width = XINT (tem1); | |
1596 window_prompting |= USSize; | |
1597 } | |
1598 else if (! EQ (tem0, Qnil) || ! EQ (tem1, Qnil)) | |
1599 error ("Must specify *both* height and width"); | |
1600 | |
1601 s->display.x->pixel_width = (FONT_WIDTH (s->display.x->font) * s->width | |
1602 + 2 * s->display.x->internal_border_width); | |
1603 s->display.x->pixel_height = (FONT_HEIGHT (s->display.x->font) * s->height | |
1604 + 2 * s->display.x->internal_border_width); | |
1605 | |
398 | 1606 tem0 = x_get_arg (parms, intern ("top"), s->name, 0, 0); |
1607 tem1 = x_get_arg (parms, intern ("left"), s->name, 0, 0); | |
389 | 1608 if (! EQ (tem0, Qnil) && ! EQ (tem1, Qnil)) |
1609 { | |
1610 CHECK_NUMBER (tem0, 0); | |
1611 CHECK_NUMBER (tem1, 0); | |
1612 s->display.x->top_pos = XINT (tem0); | |
1613 s->display.x->left_pos = XINT (tem1); | |
1614 x_calc_absolute_position (s); | |
1615 window_prompting |= USPosition; | |
1616 } | |
1617 else if (! EQ (tem0, Qnil) || ! EQ (tem1, Qnil)) | |
1618 error ("Must specify *both* top and left corners"); | |
1619 | |
1620 switch (window_prompting) | |
1621 { | |
1622 case USSize | USPosition: | |
1623 return window_prompting; | |
1624 break; | |
1625 | |
1626 case USSize: /* Got the size, need the position. */ | |
1627 window_prompting |= PPosition; | |
1628 return window_prompting; | |
1629 break; | |
1630 | |
1631 case USPosition: /* Got the position, need the size. */ | |
1632 window_prompting |= PSize; | |
1633 return window_prompting; | |
1634 break; | |
1635 | |
1636 case 0: /* Got nothing, take both from geometry. */ | |
1637 window_prompting |= PPosition | PSize; | |
1638 return window_prompting; | |
1639 break; | |
1640 | |
1641 default: | |
1642 /* Somehow a bit got set in window_prompting that we didn't | |
1643 put there. */ | |
1644 abort (); | |
1645 } | |
1646 } | |
1647 | |
1648 static void | |
1649 x_window (s) | |
1650 struct screen *s; | |
1651 { | |
1652 XSetWindowAttributes attributes; | |
1653 unsigned long attribute_mask; | |
1654 XClassHint class_hints; | |
1655 | |
1656 attributes.background_pixel = s->display.x->background_pixel; | |
1657 attributes.border_pixel = s->display.x->border_pixel; | |
1658 attributes.bit_gravity = StaticGravity; | |
1659 attributes.backing_store = NotUseful; | |
1660 attributes.save_under = True; | |
1661 attributes.event_mask = STANDARD_EVENT_SET; | |
1662 attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | |
1663 #if 0 | |
1664 | CWBackingStore | CWSaveUnder | |
1665 #endif | |
1666 | CWEventMask); | |
1667 | |
1668 BLOCK_INPUT; | |
1669 s->display.x->window_desc | |
1670 = XCreateWindow (x_current_display, ROOT_WINDOW, | |
1671 s->display.x->left_pos, | |
1672 s->display.x->top_pos, | |
1673 PIXEL_WIDTH (s), PIXEL_HEIGHT (s), | |
1674 s->display.x->border_width, | |
1675 CopyFromParent, /* depth */ | |
1676 InputOutput, /* class */ | |
1677 screen_visual, /* set in Fx_open_connection */ | |
1678 attribute_mask, &attributes); | |
1679 | |
398 | 1680 class_hints.res_name = s->name; |
389 | 1681 class_hints.res_class = EMACS_CLASS; |
1682 XSetClassHint (x_current_display, s->display.x->window_desc, &class_hints); | |
1683 | |
1684 XDefineCursor (XDISPLAY s->display.x->window_desc, | |
1685 s->display.x->text_cursor); | |
1686 UNBLOCK_INPUT; | |
1687 | |
1688 if (s->display.x->window_desc == 0) | |
1689 error ("Unable to create window."); | |
1690 } | |
1691 | |
1692 /* Handle the icon stuff for this window. Perhaps later we might | |
1693 want an x_set_icon_position which can be called interactively as | |
1694 well. */ | |
1695 | |
1696 static void | |
1697 x_icon (s, parms) | |
1698 struct screen *s; | |
1699 Lisp_Object parms; | |
1700 { | |
1701 register Lisp_Object tem0,tem1; | |
1702 XWMHints hints; | |
1703 | |
1704 /* Set the position of the icon. Note that twm groups all | |
1705 icons in an icon window. */ | |
398 | 1706 tem0 = x_get_arg (parms, intern ("icon-left"), s->name, 0, 0); |
1707 tem1 = x_get_arg (parms, intern ("icon-top"), s->name, 0, 0); | |
389 | 1708 if (!EQ (tem0, Qnil) && !EQ (tem1, Qnil)) |
1709 { | |
1710 CHECK_NUMBER (tem0, 0); | |
1711 CHECK_NUMBER (tem1, 0); | |
1712 hints.icon_x = XINT (tem0); | |
1713 hints.icon_x = XINT (tem0); | |
1714 } | |
1715 else if (!EQ (tem0, Qnil) || !EQ (tem1, Qnil)) | |
1716 error ("Both left and top icon corners of icon must be specified"); | |
1717 else | |
1718 { | |
1719 hints.icon_x = s->display.x->left_pos; | |
1720 hints.icon_y = s->display.x->top_pos; | |
1721 } | |
1722 | |
1723 /* Start up iconic or window? */ | |
398 | 1724 tem0 = x_get_arg (parms, intern ("iconic-startup"), s->name, 0, 0); |
389 | 1725 if (!EQ (tem0, Qnil)) |
1726 hints.initial_state = IconicState; | |
1727 else | |
1728 hints.initial_state = NormalState; /* the default, actually. */ | |
1729 hints.input = False; | |
1730 | |
1731 BLOCK_INPUT; | |
1732 hints.flags = StateHint | IconPositionHint | InputHint; | |
1733 XSetWMHints (x_current_display, s->display.x->window_desc, &hints); | |
1734 UNBLOCK_INPUT; | |
1735 } | |
1736 | |
1737 /* Make the GC's needed for this window, setting the | |
1738 background, border and mouse colors; also create the | |
1739 mouse cursor and the gray border tile. */ | |
1740 | |
1741 static void | |
1742 x_make_gc (s) | |
1743 struct screen *s; | |
1744 { | |
1745 XGCValues gc_values; | |
1746 GC temp_gc; | |
1747 XImage tileimage; | |
1748 static char cursor_bits[] = | |
1749 { | |
1750 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
1751 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
1752 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
1753 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
1754 }; | |
1755 | |
1756 /* Create the GC's of this screen. | |
1757 Note that many default values are used. */ | |
1758 | |
1759 /* Normal video */ | |
1760 gc_values.font = s->display.x->font->fid; | |
1761 gc_values.foreground = s->display.x->foreground_pixel; | |
1762 gc_values.background = s->display.x->background_pixel; | |
1763 gc_values.line_width = 0; /* Means 1 using fast algorithm. */ | |
1764 s->display.x->normal_gc = XCreateGC (x_current_display, | |
1765 s->display.x->window_desc, | |
1766 GCLineWidth | GCFont | |
1767 | GCForeground | GCBackground, | |
1768 &gc_values); | |
1769 | |
1770 /* Reverse video style. */ | |
1771 gc_values.foreground = s->display.x->background_pixel; | |
1772 gc_values.background = s->display.x->foreground_pixel; | |
1773 s->display.x->reverse_gc = XCreateGC (x_current_display, | |
1774 s->display.x->window_desc, | |
1775 GCFont | GCForeground | GCBackground | |
1776 | GCLineWidth, | |
1777 &gc_values); | |
1778 | |
1779 /* Cursor has cursor-color background, background-color foreground. */ | |
1780 gc_values.foreground = s->display.x->background_pixel; | |
1781 gc_values.background = s->display.x->cursor_pixel; | |
1782 gc_values.fill_style = FillOpaqueStippled; | |
1783 gc_values.stipple | |
1784 = XCreateBitmapFromData (x_current_display, ROOT_WINDOW, | |
1785 cursor_bits, 16, 16); | |
1786 s->display.x->cursor_gc | |
1787 = XCreateGC (x_current_display, s->display.x->window_desc, | |
1788 (GCFont | GCForeground | GCBackground | |
1789 | GCFillStyle | GCStipple | GCLineWidth), | |
1790 &gc_values); | |
1791 | |
1792 /* Create the gray border tile used when the pointer is not in | |
1793 the screen. Since this depends on the screen's pixel values, | |
1794 this must be done on a per-screen basis. */ | |
1795 s->display.x->border_tile = | |
1796 XCreatePixmap (x_current_display, ROOT_WINDOW, 16, 16, | |
1797 DefaultDepth (x_current_display, | |
1798 XDefaultScreen (x_current_display))); | |
1799 gc_values.foreground = s->display.x->foreground_pixel; | |
1800 gc_values.background = s->display.x->background_pixel; | |
1801 temp_gc = XCreateGC (x_current_display, | |
1802 (Drawable) s->display.x->border_tile, | |
1803 GCForeground | GCBackground, &gc_values); | |
1804 | |
1805 /* These are things that should be determined by the server, in | |
1806 Fx_open_connection */ | |
1807 tileimage.height = 16; | |
1808 tileimage.width = 16; | |
1809 tileimage.xoffset = 0; | |
1810 tileimage.format = XYBitmap; | |
1811 tileimage.data = gray_bits; | |
1812 tileimage.byte_order = LSBFirst; | |
1813 tileimage.bitmap_unit = 8; | |
1814 tileimage.bitmap_bit_order = LSBFirst; | |
1815 tileimage.bitmap_pad = 8; | |
1816 tileimage.bytes_per_line = (16 + 7) >> 3; | |
1817 tileimage.depth = 1; | |
1818 XPutImage (x_current_display, s->display.x->border_tile, temp_gc, | |
1819 &tileimage, 0, 0, 0, 0, 16, 16); | |
1820 XFreeGC (x_current_display, temp_gc); | |
1821 } | |
1822 #endif /* HAVE_X11 */ | |
1823 | |
1824 DEFUN ("x-create-screen", Fx_create_screen, Sx_create_screen, | |
1825 1, 1, 0, | |
1826 "Make a new X window, which is considered a \"screen\" in Emacs terms.\n\ | |
1827 Return an Emacs screen object representing the X window.\n\ | |
1828 ALIST is an alist of screen parameters.\n\ | |
1829 The value of ``x-screen-defaults'' is an additional alist\n\ | |
1830 of default parameters which apply when not overridden by ALIST.\n\ | |
1831 If the parameters specify that the screen should not have a minibuffer,\n\ | |
1832 then ``global-minibuffer-screen'' must be a screen whose minibuffer can\n\ | |
1833 be shared by the new screen.") | |
1834 (parms) | |
1835 Lisp_Object parms; | |
1836 { | |
1837 #ifdef HAVE_X11 | |
1838 struct screen *s; | |
1839 Lisp_Object screen, tem; | |
1840 Lisp_Object name; | |
1841 int minibuffer_only = 0; | |
1842 long window_prompting = 0; | |
1843 int width, height; | |
1844 | |
1845 if (x_current_display == 0) | |
1846 error ("X windows are not in use or not initialized"); | |
1847 | |
398 | 1848 name = x_get_arg (parms, intern ("name"), Qnil, "Title", string); |
389 | 1849 if (NULL (name)) |
398 | 1850 name = build_string (x_id_name); |
1851 if (XTYPE (name) != Lisp_String) | |
1852 error ("x-create-screen: name parameter must be a string"); | |
1853 | |
1854 tem = x_get_arg (parms, intern ("minibuffer"), name, 0, 0); | |
389 | 1855 if (EQ (tem, intern ("none"))) |
1856 s = make_screen_without_minibuffer (Qnil); | |
1857 else if (EQ (tem, intern ("only"))) | |
1858 { | |
1859 s = make_minibuffer_screen (); | |
1860 minibuffer_only = 1; | |
1861 } | |
1862 else if (! EQ (tem, Qnil)) | |
1863 s = make_screen_without_minibuffer (tem); | |
1864 else | |
1865 s = make_screen (1); | |
1866 | |
1867 /* Set the name; the functions to which we pass s expect the | |
1868 name to be set. */ | |
1869 XSET (s->name, Lisp_String, name); | |
1870 | |
1871 XSET (screen, Lisp_Screen, s); | |
1872 s->output_method = output_x_window; | |
1873 s->display.x = (struct x_display *) xmalloc (sizeof (struct x_display)); | |
1874 bzero (s->display.x, sizeof (struct x_display)); | |
1875 | |
1876 /* Extract the window parameters from the supplied values | |
1877 that are needed to determine window geometry. */ | |
1878 x_default_parameter (s, parms, "font", | |
398 | 1879 build_string ("9x15"), "font", string); |
389 | 1880 x_default_parameter (s, parms, "background-color", |
398 | 1881 build_string ("white"), "background", string); |
389 | 1882 x_default_parameter (s, parms, "border-width", |
398 | 1883 make_number (2), "BorderWidth", number); |
389 | 1884 x_default_parameter (s, parms, "internal-border-width", |
398 | 1885 make_number (4), "InternalBorderWidth", number); |
389 | 1886 |
1887 /* Also do the stuff which must be set before the window exists. */ | |
1888 x_default_parameter (s, parms, "foreground-color", | |
398 | 1889 build_string ("black"), "foreground", string); |
389 | 1890 x_default_parameter (s, parms, "mouse-color", |
398 | 1891 build_string ("black"), "mouse", string); |
389 | 1892 x_default_parameter (s, parms, "cursor-color", |
398 | 1893 build_string ("black"), "cursor", string); |
389 | 1894 x_default_parameter (s, parms, "border-color", |
398 | 1895 build_string ("black"), "border", string); |
389 | 1896 |
1897 /* Need to do icon type, auto-raise, auto-lower. */ | |
1898 | |
1899 s->display.x->parent_desc = ROOT_WINDOW; | |
1900 window_prompting = x_figure_window_size (s, parms); | |
1901 | |
1902 x_window (s); | |
1903 x_icon (s, parms); | |
1904 x_make_gc (s); | |
1905 | |
1906 /* Dimensions, especially s->height, must be done via change_screen_size. | |
1907 Change will not be effected unless different from the current | |
1908 s->height. */ | |
1909 width = s->width; | |
1910 height = s->height; | |
1911 s->height = s->width = 0; | |
1912 change_screen_size (s, height, width, 1); | |
1913 BLOCK_INPUT; | |
1914 x_wm_set_size_hint (s, window_prompting); | |
1915 UNBLOCK_INPUT; | |
1916 | |
398 | 1917 tem = x_get_arg (parms, intern ("unsplittable"), name, 0, 0); |
389 | 1918 s->no_split = minibuffer_only || EQ (tem, Qt); |
1919 | |
1920 /* Now handle the rest of the parameters. */ | |
1921 x_default_parameter (s, parms, "horizontal-scroll-bar", | |
398 | 1922 Qnil, "?HScrollBar", string); |
389 | 1923 x_default_parameter (s, parms, "vertical-scroll-bar", |
398 | 1924 Qnil, "?VScrollBar", string); |
389 | 1925 |
1926 /* Make the window appear on the screen and enable display. */ | |
398 | 1927 if (!EQ (x_get_arg (parms, intern ("suppress-initial-map"), name, 0, 0), Qt)) |
389 | 1928 x_make_screen_visible (s); |
1929 | |
1930 return screen; | |
1931 #else /* X10 */ | |
1932 struct screen *s; | |
1933 Lisp_Object screen, tem; | |
1934 Lisp_Object name; | |
1935 int pixelwidth, pixelheight; | |
1936 Cursor cursor; | |
1937 int height, width; | |
1938 Window parent; | |
1939 Pixmap temp; | |
1940 int minibuffer_only = 0; | |
1941 Lisp_Object vscroll, hscroll; | |
1942 | |
1943 if (x_current_display == 0) | |
1944 error ("X windows are not in use or not initialized"); | |
1945 | |
1946 name = Fassq (intern ("name"), parms); | |
1947 | |
398 | 1948 tem = x_get_arg (parms, intern ("minibuffer"), name, 0, 0); |
389 | 1949 if (EQ (tem, intern ("none"))) |
1950 s = make_screen_without_minibuffer (Qnil); | |
1951 else if (EQ (tem, intern ("only"))) | |
1952 { | |
1953 s = make_minibuffer_screen (); | |
1954 minibuffer_only = 1; | |
1955 } | |
1956 else if (! EQ (tem, Qnil)) | |
1957 s = make_screen_without_minibuffer (tem); | |
1958 else | |
1959 s = make_screen (1); | |
1960 | |
1961 parent = ROOT_WINDOW; | |
1962 | |
1963 XSET (screen, Lisp_Screen, s); | |
1964 s->output_method = output_x_window; | |
1965 s->display.x = (struct x_display *) xmalloc (sizeof (struct x_display)); | |
1966 bzero (s->display.x, sizeof (struct x_display)); | |
1967 | |
1968 /* Some temprorary default values for height and width. */ | |
1969 width = 80; | |
1970 height = 40; | |
1971 s->display.x->left_pos = -1; | |
1972 s->display.x->top_pos = -1; | |
1973 | |
1974 /* Give the screen a default name (which may be overridden with PARMS). */ | |
1975 | |
1976 strncpy (iconidentity, ICONTAG, MAXICID); | |
1977 if (gethostname (&iconidentity[sizeof (ICONTAG) - 1], | |
1978 (MAXICID - 1) - sizeof (ICONTAG))) | |
1979 iconidentity[sizeof (ICONTAG) - 2] = '\0'; | |
1980 s->name = build_string (iconidentity); | |
1981 | |
1982 /* Extract some window parameters from the supplied values. | |
1983 These are the parameters that affect window geometry. */ | |
1984 | |
398 | 1985 tem = x_get_arg (parms, intern ("font"), name, "BodyFont", string); |
389 | 1986 if (EQ (tem, Qnil)) |
1987 tem = build_string ("9x15"); | |
1988 x_set_font (s, tem); | |
1989 x_default_parameter (s, parms, "border-color", | |
398 | 1990 build_string ("black"), "Border", string); |
389 | 1991 x_default_parameter (s, parms, "background-color", |
398 | 1992 build_string ("white"), "Background", string); |
389 | 1993 x_default_parameter (s, parms, "foreground-color", |
398 | 1994 build_string ("black"), "Foreground", string); |
389 | 1995 x_default_parameter (s, parms, "mouse-color", |
398 | 1996 build_string ("black"), "Mouse", string); |
389 | 1997 x_default_parameter (s, parms, "cursor-color", |
398 | 1998 build_string ("black"), "Cursor", string); |
389 | 1999 x_default_parameter (s, parms, "border-width", |
398 | 2000 make_number (2), "BorderWidth", number); |
389 | 2001 x_default_parameter (s, parms, "internal-border-width", |
398 | 2002 make_number (4), "InternalBorderWidth", number); |
389 | 2003 x_default_parameter (s, parms, "auto-raise", |
398 | 2004 Qnil, "AutoRaise", boolean); |
2005 | |
2006 hscroll = x_get_arg (parms, intern ("horizontal-scroll-bar"), name, 0, 0); | |
2007 vscroll = x_get_arg (parms, intern ("vertical-scroll-bar"), name, 0, 0); | |
389 | 2008 |
2009 if (s->display.x->internal_border_width < 0) | |
2010 s->display.x->internal_border_width = 0; | |
2011 | |
398 | 2012 tem = x_get_arg (parms, intern ("window-id"), name, 0, 0); |
389 | 2013 if (!EQ (tem, Qnil)) |
2014 { | |
2015 WINDOWINFO_TYPE wininfo; | |
2016 int nchildren; | |
2017 Window *children, root; | |
2018 | |
2019 CHECK_STRING (tem, 0); | |
2020 s->display.x->window_desc = (Window) atoi (XSTRING (tem)->data); | |
2021 | |
2022 BLOCK_INPUT; | |
2023 XGetWindowInfo (s->display.x->window_desc, &wininfo); | |
2024 XQueryTree (s->display.x->window_desc, &parent, &nchildren, &children); | |
2025 free (children); | |
2026 UNBLOCK_INPUT; | |
2027 | |
2028 height = (wininfo.height - 2 * s->display.x->internal_border_width) | |
2029 / FONT_HEIGHT (s->display.x->font); | |
2030 width = (wininfo.width - 2 * s->display.x->internal_border_width) | |
2031 / FONT_WIDTH (s->display.x->font); | |
2032 s->display.x->left_pos = wininfo.x; | |
2033 s->display.x->top_pos = wininfo.y; | |
2034 s->visible = wininfo.mapped != 0; | |
2035 s->display.x->border_width = wininfo.bdrwidth; | |
2036 s->display.x->parent_desc = parent; | |
2037 } | |
2038 else | |
2039 { | |
398 | 2040 tem = x_get_arg (parms, intern ("parent-id"), name, 0, 0); |
389 | 2041 if (!EQ (tem, Qnil)) |
2042 { | |
2043 CHECK_STRING (tem, 0); | |
2044 parent = (Window) atoi (XSTRING (tem)->data); | |
2045 } | |
2046 s->display.x->parent_desc = parent; | |
398 | 2047 tem = x_get_arg (parms, intern ("height"), name, 0, 0); |
389 | 2048 if (EQ (tem, Qnil)) |
2049 { | |
398 | 2050 tem = x_get_arg (parms, intern ("width"), name, 0, 0); |
389 | 2051 if (EQ (tem, Qnil)) |
2052 { | |
398 | 2053 tem = x_get_arg (parms, intern ("top"), name, 0, 0); |
389 | 2054 if (EQ (tem, Qnil)) |
398 | 2055 tem = x_get_arg (parms, intern ("left"), name, 0, 0); |
389 | 2056 } |
2057 } | |
2058 /* Now TEM is nil if no edge or size was specified. | |
2059 In that case, we must do rubber-banding. */ | |
2060 if (EQ (tem, Qnil)) | |
2061 { | |
398 | 2062 tem = x_get_arg (parms, intern ("geometry"), name, 0, 0); |
389 | 2063 x_rubber_band (s, |
2064 &s->display.x->left_pos, &s->display.x->top_pos, | |
2065 &width, &height, | |
2066 (XTYPE (tem) == Lisp_String | |
2067 ? (char *) XSTRING (tem)->data : ""), | |
2068 XSTRING (s->name)->data, | |
2069 !NULL (hscroll), !NULL (vscroll)); | |
2070 } | |
2071 else | |
2072 { | |
2073 /* Here if at least one edge or size was specified. | |
2074 Demand that they all were specified, and use them. */ | |
398 | 2075 tem = x_get_arg (parms, intern ("height"), name, 0, 0); |
389 | 2076 if (EQ (tem, Qnil)) |
2077 error ("Height not specified"); | |
2078 CHECK_NUMBER (tem, 0); | |
2079 height = XINT (tem); | |
2080 | |
398 | 2081 tem = x_get_arg (parms, intern ("width"), name, 0, 0); |
389 | 2082 if (EQ (tem, Qnil)) |
2083 error ("Width not specified"); | |
2084 CHECK_NUMBER (tem, 0); | |
2085 width = XINT (tem); | |
2086 | |
398 | 2087 tem = x_get_arg (parms, intern ("top"), name, 0, 0); |
389 | 2088 if (EQ (tem, Qnil)) |
2089 error ("Top position not specified"); | |
2090 CHECK_NUMBER (tem, 0); | |
2091 s->display.x->left_pos = XINT (tem); | |
2092 | |
398 | 2093 tem = x_get_arg (parms, intern ("left"), name, 0, 0); |
389 | 2094 if (EQ (tem, Qnil)) |
2095 error ("Left position not specified"); | |
2096 CHECK_NUMBER (tem, 0); | |
2097 s->display.x->top_pos = XINT (tem); | |
2098 } | |
2099 | |
2100 pixelwidth = (width * FONT_WIDTH (s->display.x->font) | |
2101 + 2 * s->display.x->internal_border_width | |
2102 + (!NULL (vscroll) ? VSCROLL_WIDTH : 0)); | |
2103 pixelheight = (height * FONT_HEIGHT (s->display.x->font) | |
2104 + 2 * s->display.x->internal_border_width | |
2105 + (!NULL (hscroll) ? HSCROLL_HEIGHT : 0)); | |
2106 | |
2107 BLOCK_INPUT; | |
2108 s->display.x->window_desc | |
2109 = XCreateWindow (parent, | |
2110 s->display.x->left_pos, /* Absolute horizontal offset */ | |
2111 s->display.x->top_pos, /* Absolute Vertical offset */ | |
2112 pixelwidth, pixelheight, | |
2113 s->display.x->border_width, | |
2114 BLACK_PIX_DEFAULT, WHITE_PIX_DEFAULT); | |
2115 UNBLOCK_INPUT; | |
2116 if (s->display.x->window_desc == 0) | |
2117 error ("Unable to create window."); | |
2118 } | |
2119 | |
2120 /* Install the now determined height and width | |
2121 in the windows and in phys_lines and desired_lines. */ | |
2122 /* ??? jla version had 1 here instead of 0. */ | |
2123 change_screen_size (s, height, width, 1); | |
2124 XSelectInput (s->display.x->window_desc, KeyPressed | ExposeWindow | |
2125 | ButtonPressed | ButtonReleased | ExposeRegion | ExposeCopy | |
2126 | EnterWindow | LeaveWindow | UnmapWindow ); | |
2127 x_set_resize_hint (s); | |
2128 | |
2129 /* Tell the server the window's default name. */ | |
2130 | |
2131 XStoreName (XDISPLAY s->display.x->window_desc, XSTRING (s->name)->data); | |
2132 /* Now override the defaults with all the rest of the specified | |
2133 parms. */ | |
398 | 2134 tem = x_get_arg (parms, intern ("unsplittable"), name, 0, 0); |
389 | 2135 s->no_split = minibuffer_only || EQ (tem, Qt); |
2136 | |
2137 /* Do not create an icon window if the caller says not to */ | |
398 | 2138 if (!EQ (x_get_arg (parms, intern ("suppress-icon"), name, 0, 0), Qt) |
389 | 2139 || s->display.x->parent_desc != ROOT_WINDOW) |
2140 { | |
2141 x_text_icon (s, iconidentity); | |
398 | 2142 x_default_parameter (s, parms, "icon-type", Qnil, |
2143 "BitmapIcon", boolean); | |
389 | 2144 } |
2145 | |
2146 /* Tell the X server the previously set values of the | |
2147 background, border and mouse colors; also create the mouse cursor. */ | |
2148 BLOCK_INPUT; | |
2149 temp = XMakeTile (s->display.x->background_pixel); | |
2150 XChangeBackground (s->display.x->window_desc, temp); | |
2151 XFreePixmap (temp); | |
2152 UNBLOCK_INPUT; | |
2153 x_set_border_pixel (s, s->display.x->border_pixel); | |
2154 | |
2155 x_set_mouse_color (s, Qnil, Qnil); | |
2156 | |
2157 /* Now override the defaults with all the rest of the specified parms. */ | |
2158 | |
2159 Fmodify_screen_parameters (screen, parms); | |
2160 | |
2161 if (!NULL (vscroll)) | |
2162 install_vertical_scrollbar (s, pixelwidth, pixelheight); | |
2163 if (!NULL (hscroll)) | |
2164 install_horizontal_scrollbar (s, pixelwidth, pixelheight); | |
2165 | |
2166 /* Make the window appear on the screen and enable display. */ | |
2167 | |
398 | 2168 if (!EQ (x_get_arg (parms, intern ("suppress-initial-map"), name, 0, 0), Qt)) |
389 | 2169 x_make_window_visible (s); |
2170 SCREEN_GARBAGED (s); | |
2171 | |
2172 return screen; | |
2173 #endif /* X10 */ | |
2174 } | |
2175 | |
2176 DEFUN ("focus-screen", Ffocus_screen, Sfocus_screen, 1, 1, 0, | |
2177 "Set the focus on SCREEN.") | |
2178 (screen) | |
2179 Lisp_Object screen; | |
2180 { | |
2181 CHECK_SCREEN (screen, 0); | |
2182 | |
2183 if (SCREEN_IS_X (XSCREEN (screen))) | |
2184 { | |
2185 BLOCK_INPUT; | |
2186 x_focus_on_screen (XSCREEN (screen)); | |
2187 UNBLOCK_INPUT; | |
2188 return screen; | |
2189 } | |
2190 | |
2191 return Qnil; | |
2192 } | |
2193 | |
2194 DEFUN ("unfocus-screen", Funfocus_screen, Sunfocus_screen, 0, 0, 0, | |
2195 "If a screen has been focused, release it.") | |
2196 () | |
2197 { | |
2198 if (x_focus_screen) | |
2199 { | |
2200 BLOCK_INPUT; | |
2201 x_unfocus_screen (x_focus_screen); | |
2202 UNBLOCK_INPUT; | |
2203 } | |
2204 | |
2205 return Qnil; | |
2206 } | |
2207 | |
2208 #ifndef HAVE_X11 | |
2209 /* Computes an X-window size and position either from geometry GEO | |
2210 or with the mouse. | |
2211 | |
2212 S is a screen. It specifies an X window which is used to | |
2213 determine which display to compute for. Its font, borders | |
2214 and colors control how the rectangle will be displayed. | |
2215 | |
2216 X and Y are where to store the positions chosen. | |
2217 WIDTH and HEIGHT are where to store the sizes chosen. | |
2218 | |
2219 GEO is the geometry that may specify some of the info. | |
2220 STR is a prompt to display. | |
2221 HSCROLL and VSCROLL say whether we have horiz and vert scroll bars. */ | |
2222 | |
2223 int | |
2224 x_rubber_band (s, x, y, width, height, geo, str, hscroll, vscroll) | |
2225 struct screen *s; | |
2226 int *x, *y, *width, *height; | |
2227 char *geo; | |
2228 char *str; | |
2229 int hscroll, vscroll; | |
2230 { | |
2231 OpaqueFrame frame; | |
2232 Window tempwindow; | |
2233 WindowInfo wininfo; | |
2234 int border_color; | |
2235 int background_color; | |
2236 Lisp_Object tem; | |
2237 int mask; | |
2238 | |
2239 BLOCK_INPUT; | |
2240 | |
2241 background_color = s->display.x->background_pixel; | |
2242 border_color = s->display.x->border_pixel; | |
2243 | |
2244 frame.bdrwidth = s->display.x->border_width; | |
2245 frame.border = XMakeTile (border_color); | |
2246 frame.background = XMakeTile (background_color); | |
2247 tempwindow = XCreateTerm (str, "emacs", geo, default_window, &frame, 10, 5, | |
2248 (2 * s->display.x->internal_border_width | |
2249 + (vscroll ? VSCROLL_WIDTH : 0)), | |
2250 (2 * s->display.x->internal_border_width | |
2251 + (hscroll ? HSCROLL_HEIGHT : 0)), | |
2252 width, height, s->display.x->font, | |
2253 FONT_WIDTH (s->display.x->font), | |
2254 FONT_HEIGHT (s->display.x->font)); | |
2255 XFreePixmap (frame.border); | |
2256 XFreePixmap (frame.background); | |
2257 | |
2258 if (tempwindow != 0) | |
2259 { | |
2260 XQueryWindow (tempwindow, &wininfo); | |
2261 XDestroyWindow (tempwindow); | |
2262 *x = wininfo.x; | |
2263 *y = wininfo.y; | |
2264 } | |
2265 | |
2266 /* Coordinates we got are relative to the root window. | |
2267 Convert them to coordinates relative to desired parent window | |
2268 by scanning from there up to the root. */ | |
2269 tempwindow = s->display.x->parent_desc; | |
2270 while (tempwindow != ROOT_WINDOW) | |
2271 { | |
2272 int nchildren; | |
2273 Window *children; | |
2274 XQueryWindow (tempwindow, &wininfo); | |
2275 *x -= wininfo.x; | |
2276 *y -= wininfo.y; | |
2277 XQueryTree (tempwindow, &tempwindow, &nchildren, &children); | |
2278 free (children); | |
2279 } | |
2280 | |
2281 UNBLOCK_INPUT; | |
2282 return tempwindow != 0; | |
2283 } | |
2284 #endif /* not HAVE_X11 */ | |
2285 | |
2286 /* Set whether screen S has a horizontal scroll bar. | |
2287 VAL is t or nil to specify it. */ | |
2288 | |
2289 static void | |
2290 x_set_horizontal_scrollbar (s, val, oldval) | |
2291 struct screen *s; | |
2292 Lisp_Object val, oldval; | |
2293 { | |
2294 if (!NULL (val)) | |
2295 { | |
2296 if (s->display.x->window_desc != 0) | |
2297 { | |
2298 BLOCK_INPUT; | |
2299 s->display.x->h_scrollbar_height = HSCROLL_HEIGHT; | |
2300 x_set_window_size (s, s->width, s->height); | |
2301 install_horizontal_scrollbar (s); | |
2302 SET_SCREEN_GARBAGED (s); | |
2303 UNBLOCK_INPUT; | |
2304 } | |
2305 } | |
2306 else | |
2307 if (s->display.x->h_scrollbar) | |
2308 { | |
2309 BLOCK_INPUT; | |
2310 s->display.x->h_scrollbar_height = 0; | |
2311 XDestroyWindow (XDISPLAY s->display.x->h_scrollbar); | |
2312 s->display.x->h_scrollbar = 0; | |
2313 x_set_window_size (s, s->width, s->height); | |
2314 s->garbaged++; | |
2315 screen_garbaged++; | |
2316 BLOCK_INPUT; | |
2317 } | |
2318 } | |
2319 | |
2320 /* Set whether screen S has a vertical scroll bar. | |
2321 VAL is t or nil to specify it. */ | |
2322 | |
2323 static void | |
2324 x_set_vertical_scrollbar (s, val, oldval) | |
2325 struct screen *s; | |
2326 Lisp_Object val, oldval; | |
2327 { | |
2328 if (!NULL (val)) | |
2329 { | |
2330 if (s->display.x->window_desc != 0) | |
2331 { | |
2332 BLOCK_INPUT; | |
2333 s->display.x->v_scrollbar_width = VSCROLL_WIDTH; | |
2334 x_set_window_size (s, s->width, s->height); | |
2335 install_vertical_scrollbar (s); | |
2336 SET_SCREEN_GARBAGED (s); | |
2337 UNBLOCK_INPUT; | |
2338 } | |
2339 } | |
2340 else | |
2341 if (s->display.x->v_scrollbar != 0) | |
2342 { | |
2343 BLOCK_INPUT; | |
2344 s->display.x->v_scrollbar_width = 0; | |
2345 XDestroyWindow (XDISPLAY s->display.x->v_scrollbar); | |
2346 s->display.x->v_scrollbar = 0; | |
2347 x_set_window_size (s, s->width, s->height); | |
2348 SET_SCREEN_GARBAGED (s); | |
2349 UNBLOCK_INPUT; | |
2350 } | |
2351 } | |
2352 | |
2353 /* Create the X windows for a vertical scroll bar | |
2354 for a screen X that already has an X window but no scroll bar. */ | |
2355 | |
2356 static void | |
2357 install_vertical_scrollbar (s) | |
2358 struct screen *s; | |
2359 { | |
2360 int ibw = s->display.x->internal_border_width; | |
2361 Window parent; | |
2362 XColor fore_color, back_color; | |
2363 Pixmap up_arrow_pixmap, down_arrow_pixmap, slider_pixmap; | |
2364 int pix_x, pix_y, width, height, border; | |
2365 | |
2366 height = s->display.x->pixel_height - ibw - 2; | |
2367 width = VSCROLL_WIDTH - 2; | |
2368 pix_x = s->display.x->pixel_width - ibw/2; | |
2369 pix_y = ibw / 2; | |
2370 border = 1; | |
2371 | |
2372 #ifdef HAVE_X11 | |
2373 up_arrow_pixmap = | |
2374 XCreatePixmapFromBitmapData (x_current_display, s->display.x->window_desc, | |
2375 up_arrow_bits, 16, 16, | |
2376 s->display.x->foreground_pixel, | |
2377 s->display.x->background_pixel, | |
2378 DefaultDepth (x_current_display, | |
2379 XDefaultScreen (x_current_display))); | |
2380 | |
2381 down_arrow_pixmap = | |
2382 XCreatePixmapFromBitmapData (x_current_display, s->display.x->window_desc, | |
2383 down_arrow_bits, 16, 16, | |
2384 s->display.x->foreground_pixel, | |
2385 s->display.x->background_pixel, | |
2386 DefaultDepth (x_current_display, | |
2387 XDefaultScreen (x_current_display))); | |
2388 | |
2389 slider_pixmap = | |
2390 XCreatePixmapFromBitmapData (x_current_display, s->display.x->window_desc, | |
2391 gray_bits, 16, 16, | |
2392 s->display.x->foreground_pixel, | |
2393 s->display.x->background_pixel, | |
2394 DefaultDepth (x_current_display, | |
2395 XDefaultScreen (x_current_display))); | |
2396 | |
2397 /* These cursor shapes will be installed when the mouse enters | |
2398 the appropriate window. */ | |
2399 | |
2400 up_arrow_cursor = XCreateFontCursor (x_current_display, XC_sb_up_arrow); | |
2401 down_arrow_cursor = XCreateFontCursor (x_current_display, XC_sb_down_arrow); | |
2402 v_double_arrow_cursor = XCreateFontCursor (x_current_display, XC_sb_v_double_arrow); | |
2403 | |
2404 s->display.x->v_scrollbar = | |
2405 XCreateSimpleWindow (x_current_display, s->display.x->window_desc, | |
2406 pix_x, pix_y, width, height, border, | |
2407 s->display.x->foreground_pixel, | |
2408 s->display.x->background_pixel); | |
2409 XFlush (x_current_display); | |
2410 XDefineCursor (x_current_display, s->display.x->v_scrollbar, | |
2411 v_double_arrow_cursor); | |
2412 | |
2413 /* Create slider window */ | |
2414 s->display.x->v_slider = | |
2415 XCreateSimpleWindow (x_current_display, s->display.x->v_scrollbar, | |
2416 0, VSCROLL_WIDTH - 2, | |
2417 VSCROLL_WIDTH - 4, VSCROLL_WIDTH - 4, | |
2418 1, s->display.x->border_pixel, | |
2419 s->display.x->foreground_pixel); | |
2420 XFlush (x_current_display); | |
2421 XDefineCursor (x_current_display, s->display.x->v_slider, | |
2422 v_double_arrow_cursor); | |
2423 XSetWindowBackgroundPixmap (x_current_display, s->display.x->v_slider, | |
2424 slider_pixmap); | |
2425 | |
2426 s->display.x->v_thumbup = | |
2427 XCreateSimpleWindow (x_current_display, s->display.x->v_scrollbar, | |
2428 0, 0, | |
2429 VSCROLL_WIDTH - 2, VSCROLL_WIDTH - 2, | |
2430 0, s->display.x->foreground_pixel, | |
2431 s->display.x-> background_pixel); | |
2432 XFlush (x_current_display); | |
2433 XDefineCursor (x_current_display, s->display.x->v_thumbup, | |
2434 up_arrow_cursor); | |
2435 XSetWindowBackgroundPixmap (x_current_display, s->display.x->v_thumbup, | |
2436 up_arrow_pixmap); | |
2437 | |
2438 s->display.x->v_thumbdown = | |
2439 XCreateSimpleWindow (x_current_display, s->display.x->v_scrollbar, | |
2440 0, height - VSCROLL_WIDTH + 2, | |
2441 VSCROLL_WIDTH - 2, VSCROLL_WIDTH - 2, | |
2442 0, s->display.x->foreground_pixel, | |
2443 s->display.x->background_pixel); | |
2444 XFlush (x_current_display); | |
2445 XDefineCursor (x_current_display, s->display.x->v_thumbdown, | |
2446 down_arrow_cursor); | |
2447 XSetWindowBackgroundPixmap (x_current_display, s->display.x->v_thumbdown, | |
2448 down_arrow_pixmap); | |
2449 | |
2450 fore_color.pixel = s->display.x->mouse_pixel; | |
2451 back_color.pixel = s->display.x->background_pixel; | |
2452 XQueryColor (x_current_display, | |
2453 DefaultColormap (x_current_display, | |
2454 DefaultScreen (x_current_display)), | |
2455 &fore_color); | |
2456 XQueryColor (x_current_display, | |
2457 DefaultColormap (x_current_display, | |
2458 DefaultScreen (x_current_display)), | |
2459 &back_color); | |
2460 XRecolorCursor (x_current_display, up_arrow_cursor, | |
2461 &fore_color, &back_color); | |
2462 XRecolorCursor (x_current_display, down_arrow_cursor, | |
2463 &fore_color, &back_color); | |
2464 XRecolorCursor (x_current_display, v_double_arrow_cursor, | |
2465 &fore_color, &back_color); | |
2466 | |
2467 XFreePixmap (x_current_display, slider_pixmap); | |
2468 XFreePixmap (x_current_display, up_arrow_pixmap); | |
2469 XFreePixmap (x_current_display, down_arrow_pixmap); | |
2470 XFlush (x_current_display); | |
2471 | |
2472 XSelectInput (x_current_display, s->display.x->v_scrollbar, | |
2473 ButtonPressMask | ButtonReleaseMask | |
2474 | PointerMotionMask | PointerMotionHintMask | |
2475 | EnterWindowMask); | |
2476 XSelectInput (x_current_display, s->display.x->v_slider, | |
2477 ButtonPressMask | ButtonReleaseMask); | |
2478 XSelectInput (x_current_display, s->display.x->v_thumbdown, | |
2479 ButtonPressMask | ButtonReleaseMask); | |
2480 XSelectInput (x_current_display, s->display.x->v_thumbup, | |
2481 ButtonPressMask | ButtonReleaseMask); | |
2482 XFlush (x_current_display); | |
2483 | |
2484 /* This should be done at the same time as the main window. */ | |
2485 XMapWindow (x_current_display, s->display.x->v_scrollbar); | |
2486 XMapSubwindows (x_current_display, s->display.x->v_scrollbar); | |
2487 XFlush (x_current_display); | |
2488 #else /* not HAVE_X11 */ | |
2489 Bitmap b; | |
2490 Pixmap fore_tile, back_tile, bord_tile; | |
2491 static short up_arrow_bits[] = { | |
2492 0x0000, 0x0180, 0x03c0, 0x07e0, | |
2493 0x0ff0, 0x1ff8, 0x3ffc, 0x7ffe, | |
2494 0x0180, 0x0180, 0x0180, 0x0180, | |
2495 0x0180, 0x0180, 0x0180, 0xffff}; | |
2496 static short down_arrow_bits[] = { | |
2497 0xffff, 0x0180, 0x0180, 0x0180, | |
2498 0x0180, 0x0180, 0x0180, 0x0180, | |
2499 0x7ffe, 0x3ffc, 0x1ff8, 0x0ff0, | |
2500 0x07e0, 0x03c0, 0x0180, 0x0000}; | |
2501 | |
2502 fore_tile = XMakeTile (s->display.x->foreground_pixel); | |
2503 back_tile = XMakeTile (s->display.x->background_pixel); | |
2504 bord_tile = XMakeTile (s->display.x->border_pixel); | |
2505 | |
2506 b = XStoreBitmap (VSCROLL_WIDTH - 2, VSCROLL_WIDTH - 2, up_arrow_bits); | |
2507 up_arrow_pixmap = XMakePixmap (b, | |
2508 s->display.x->foreground_pixel, | |
2509 s->display.x->background_pixel); | |
2510 XFreeBitmap (b); | |
2511 | |
2512 b = XStoreBitmap (VSCROLL_WIDTH - 2, VSCROLL_WIDTH - 2, down_arrow_bits); | |
2513 down_arrow_pixmap = XMakePixmap (b, | |
2514 s->display.x->foreground_pixel, | |
2515 s->display.x->background_pixel); | |
2516 XFreeBitmap (b); | |
2517 | |
2518 ibw = s->display.x->internal_border_width; | |
2519 | |
2520 s->display.x->v_scrollbar = XCreateWindow (s->display.x->window_desc, | |
2521 width - VSCROLL_WIDTH - ibw/2, | |
2522 ibw/2, | |
2523 VSCROLL_WIDTH - 2, | |
2524 height - ibw - 2, | |
2525 1, bord_tile, back_tile); | |
2526 | |
2527 s->display.x->v_scrollbar_width = VSCROLL_WIDTH; | |
2528 | |
2529 s->display.x->v_thumbup = XCreateWindow (s->display.x->v_scrollbar, | |
2530 0, 0, | |
2531 VSCROLL_WIDTH - 2, | |
2532 VSCROLL_WIDTH - 2, | |
2533 0, 0, up_arrow_pixmap); | |
2534 XTileAbsolute (s->display.x->v_thumbup); | |
2535 | |
2536 s->display.x->v_thumbdown = XCreateWindow (s->display.x->v_scrollbar, | |
2537 0, | |
2538 height - ibw - VSCROLL_WIDTH, | |
2539 VSCROLL_WIDTH - 2, | |
2540 VSCROLL_WIDTH - 2, | |
2541 0, 0, down_arrow_pixmap); | |
2542 XTileAbsolute (s->display.x->v_thumbdown); | |
2543 | |
2544 s->display.x->v_slider = XCreateWindow (s->display.x->v_scrollbar, | |
2545 0, VSCROLL_WIDTH - 2, | |
2546 VSCROLL_WIDTH - 4, | |
2547 VSCROLL_WIDTH - 4, | |
2548 1, back_tile, fore_tile); | |
2549 | |
2550 XSelectInput (s->display.x->v_scrollbar, | |
2551 (ButtonPressed | ButtonReleased | KeyPressed)); | |
2552 XSelectInput (s->display.x->v_thumbup, | |
2553 (ButtonPressed | ButtonReleased | KeyPressed)); | |
2554 | |
2555 XSelectInput (s->display.x->v_thumbdown, | |
2556 (ButtonPressed | ButtonReleased | KeyPressed)); | |
2557 | |
2558 XMapWindow (s->display.x->v_thumbup); | |
2559 XMapWindow (s->display.x->v_thumbdown); | |
2560 XMapWindow (s->display.x->v_slider); | |
2561 XMapWindow (s->display.x->v_scrollbar); | |
2562 | |
2563 XFreePixmap (fore_tile); | |
2564 XFreePixmap (back_tile); | |
2565 XFreePixmap (up_arrow_pixmap); | |
2566 XFreePixmap (down_arrow_pixmap); | |
2567 #endif /* not HAVE_X11 */ | |
2568 } | |
2569 | |
2570 static void | |
2571 install_horizontal_scrollbar (s) | |
2572 struct screen *s; | |
2573 { | |
2574 int ibw = s->display.x->internal_border_width; | |
2575 Window parent; | |
2576 Pixmap left_arrow_pixmap, right_arrow_pixmap, slider_pixmap; | |
2577 int pix_x, pix_y; | |
2578 int width; | |
2579 | |
2580 pix_x = ibw; | |
2581 pix_y = PIXEL_HEIGHT (s) - HSCROLL_HEIGHT - ibw ; | |
2582 width = PIXEL_WIDTH (s) - 2 * ibw; | |
2583 if (s->display.x->v_scrollbar_width) | |
2584 width -= (s->display.x->v_scrollbar_width + 1); | |
2585 | |
2586 #ifdef HAVE_X11 | |
2587 left_arrow_pixmap = | |
2588 XCreatePixmapFromBitmapData (x_current_display, s->display.x->window_desc, | |
2589 left_arrow_bits, 16, 16, | |
2590 s->display.x->foreground_pixel, | |
2591 s->display.x->background_pixel, | |
2592 DefaultDepth (x_current_display, | |
2593 XDefaultScreen (x_current_display))); | |
2594 | |
2595 right_arrow_pixmap = | |
2596 XCreatePixmapFromBitmapData (x_current_display, s->display.x->window_desc, | |
2597 right_arrow_bits, 16, 16, | |
2598 s->display.x->foreground_pixel, | |
2599 s->display.x->background_pixel, | |
2600 DefaultDepth (x_current_display, | |
2601 XDefaultScreen (x_current_display))); | |
2602 | |
2603 slider_pixmap = | |
2604 XCreatePixmapFromBitmapData (x_current_display, s->display.x->window_desc, | |
2605 gray_bits, 16, 16, | |
2606 s->display.x->foreground_pixel, | |
2607 s->display.x->background_pixel, | |
2608 DefaultDepth (x_current_display, | |
2609 XDefaultScreen (x_current_display))); | |
2610 | |
2611 left_arrow_cursor = XCreateFontCursor (x_current_display, XC_sb_left_arrow); | |
2612 right_arrow_cursor = XCreateFontCursor (x_current_display, XC_sb_right_arrow); | |
2613 h_double_arrow_cursor = XCreateFontCursor (x_current_display, XC_sb_h_double_arrow); | |
2614 | |
2615 s->display.x->h_scrollbar = | |
2616 XCreateSimpleWindow (x_current_display, s->display.x->window_desc, | |
2617 pix_x, pix_y, | |
2618 width - ibw - 2, HSCROLL_HEIGHT - 2, 1, | |
2619 s->display.x->foreground_pixel, | |
2620 s->display.x->background_pixel); | |
2621 XDefineCursor (x_current_display, s->display.x->h_scrollbar, | |
2622 h_double_arrow_cursor); | |
2623 | |
2624 s->display.x->h_slider = | |
2625 XCreateSimpleWindow (x_current_display, s->display.x->h_scrollbar, | |
2626 0, 0, | |
2627 HSCROLL_HEIGHT - 4, HSCROLL_HEIGHT - 4, | |
2628 1, s->display.x->foreground_pixel, | |
2629 s->display.x->background_pixel); | |
2630 XDefineCursor (x_current_display, s->display.x->h_slider, | |
2631 h_double_arrow_cursor); | |
2632 XSetWindowBackgroundPixmap (x_current_display, s->display.x->h_slider, | |
2633 slider_pixmap); | |
2634 | |
2635 s->display.x->h_thumbleft = | |
2636 XCreateSimpleWindow (x_current_display, s->display.x->h_scrollbar, | |
2637 0, 0, | |
2638 HSCROLL_HEIGHT - 2, HSCROLL_HEIGHT - 2, | |
2639 0, s->display.x->foreground_pixel, | |
2640 s->display.x->background_pixel); | |
2641 XDefineCursor (x_current_display, s->display.x->h_thumbleft, | |
2642 left_arrow_cursor); | |
2643 XSetWindowBackgroundPixmap (x_current_display, s->display.x->h_thumbleft, | |
2644 left_arrow_pixmap); | |
2645 | |
2646 s->display.x->h_thumbright = | |
2647 XCreateSimpleWindow (x_current_display, s->display.x->h_scrollbar, | |
2648 width - ibw - HSCROLL_HEIGHT, 0, | |
2649 HSCROLL_HEIGHT - 2, HSCROLL_HEIGHT -2, | |
2650 0, s->display.x->foreground_pixel, | |
2651 s->display.x->background_pixel); | |
2652 XDefineCursor (x_current_display, s->display.x->h_thumbright, | |
2653 right_arrow_cursor); | |
2654 XSetWindowBackgroundPixmap (x_current_display, s->display.x->h_thumbright, | |
2655 right_arrow_pixmap); | |
2656 | |
2657 XFreePixmap (x_current_display, slider_pixmap); | |
2658 XFreePixmap (x_current_display, left_arrow_pixmap); | |
2659 XFreePixmap (x_current_display, right_arrow_pixmap); | |
2660 | |
2661 XSelectInput (x_current_display, s->display.x->h_scrollbar, | |
2662 ButtonPressMask | ButtonReleaseMask | |
2663 | PointerMotionMask | PointerMotionHintMask | |
2664 | EnterWindowMask); | |
2665 XSelectInput (x_current_display, s->display.x->h_slider, | |
2666 ButtonPressMask | ButtonReleaseMask); | |
2667 XSelectInput (x_current_display, s->display.x->h_thumbright, | |
2668 ButtonPressMask | ButtonReleaseMask); | |
2669 XSelectInput (x_current_display, s->display.x->h_thumbleft, | |
2670 ButtonPressMask | ButtonReleaseMask); | |
2671 | |
2672 XMapWindow (x_current_display, s->display.x->h_scrollbar); | |
2673 XMapSubwindows (x_current_display, s->display.x->h_scrollbar); | |
2674 #else /* not HAVE_X11 */ | |
2675 Bitmap b; | |
2676 Pixmap fore_tile, back_tile, bord_tile; | |
2677 #endif | |
2678 } | |
2679 | |
2680 #ifndef HAVE_X11 /* X10 */ | |
2681 #define XMoveResizeWindow XConfigureWindow | |
2682 #endif /* not HAVE_X11 */ | |
2683 | |
2684 /* Adjust the displayed position in the scroll bar for window W. */ | |
2685 | |
2686 void | |
2687 adjust_scrollbars (s) | |
2688 struct screen *s; | |
2689 { | |
2690 int pos; | |
2691 int first_char_in_window, char_beyond_window, chars_in_window; | |
2692 int chars_in_buffer, buffer_size; | |
2693 struct window *w = XWINDOW (SCREEN_SELECTED_WINDOW (s)); | |
2694 | |
2695 if (s->output_method != output_x_window) | |
2696 return; | |
2697 | |
2698 if (s->display.x->v_scrollbar != 0) | |
2699 { | |
2700 int h, height; | |
2701 struct buffer *b = XBUFFER (w->buffer); | |
2702 | |
2703 buffer_size = Z - BEG; | |
2704 chars_in_buffer = ZV - BEGV; | |
2705 first_char_in_window = marker_position (w->start); | |
2706 char_beyond_window = buffer_size + 1 - XFASTINT (w->window_end_pos); | |
2707 chars_in_window = char_beyond_window - first_char_in_window; | |
2708 | |
2709 /* Calculate height of scrollbar area */ | |
2710 | |
2711 height = s->height * FONT_HEIGHT (s->display.x->font) | |
2712 + s->display.x->internal_border_width | |
2713 - 2 * (s->display.x->v_scrollbar_width); | |
2714 | |
2715 /* Figure starting position for the scrollbar slider */ | |
2716 | |
2717 if (chars_in_buffer <= 0) | |
2718 pos = 0; | |
2719 else | |
2720 pos = ((first_char_in_window - BEGV - BEG) * height | |
2721 / chars_in_buffer); | |
2722 pos = max (0, pos); | |
2723 pos = min (pos, height - 2); | |
2724 | |
2725 /* Figure length of the slider */ | |
2726 | |
2727 if (chars_in_buffer <= 0) | |
2728 h = height; | |
2729 else | |
2730 h = (chars_in_window * height) / chars_in_buffer; | |
2731 h = min (h, height - pos); | |
2732 h = max (h, 1); | |
2733 | |
2734 /* Add thumbup offset to starting position of slider */ | |
2735 | |
2736 pos += (s->display.x->v_scrollbar_width - 2); | |
2737 | |
2738 XMoveResizeWindow (XDISPLAY | |
2739 s->display.x->v_slider, | |
2740 0, pos, | |
2741 s->display.x->v_scrollbar_width - 4, h); | |
2742 } | |
2743 | |
2744 if (s->display.x->h_scrollbar != 0) | |
2745 { | |
2746 int l, length; /* Length of the scrollbar area */ | |
2747 | |
2748 length = s->width * FONT_WIDTH (s->display.x->font) | |
2749 + s->display.x->internal_border_width | |
2750 - 2 * (s->display.x->h_scrollbar_height); | |
2751 | |
2752 /* Starting position for horizontal slider */ | |
2753 if (! w->hscroll) | |
2754 pos = 0; | |
2755 else | |
2756 pos = (w->hscroll * length) / (w->hscroll + s->width); | |
2757 pos = max (0, pos); | |
2758 pos = min (pos, length - 2); | |
2759 | |
2760 /* Length of slider */ | |
2761 l = length - pos; | |
2762 | |
2763 /* Add thumbup offset */ | |
2764 pos += (s->display.x->h_scrollbar_height - 2); | |
2765 | |
2766 XMoveResizeWindow (XDISPLAY | |
2767 s->display.x->h_slider, | |
2768 pos, 0, | |
2769 l, s->display.x->h_scrollbar_height - 4); | |
2770 } | |
2771 } | |
2772 | |
2773 /* Adjust the size of the scroll bars of screen S, | |
2774 when the screen size has changed. */ | |
2775 | |
2776 void | |
2777 x_resize_scrollbars (s) | |
2778 struct screen *s; | |
2779 { | |
2780 int ibw = s->display.x->internal_border_width; | |
2781 int pixelwidth, pixelheight; | |
2782 | |
2783 if (s == 0 | |
2784 || s->display.x == 0 | |
2785 || (s->display.x->v_scrollbar == 0 | |
2786 && s->display.x->h_scrollbar == 0)) | |
2787 return; | |
2788 | |
2789 /* Get the size of the screen. */ | |
2790 pixelwidth = (s->width * FONT_WIDTH (s->display.x->font) | |
2791 + 2 * ibw + s->display.x->v_scrollbar_width); | |
2792 pixelheight = (s->height * FONT_HEIGHT (s->display.x->font) | |
2793 + 2 * ibw + s->display.x->h_scrollbar_height); | |
2794 | |
2795 if (s->display.x->v_scrollbar_width && s->display.x->v_scrollbar) | |
2796 { | |
2797 BLOCK_INPUT; | |
2798 XMoveResizeWindow (XDISPLAY | |
2799 s->display.x->v_scrollbar, | |
2800 pixelwidth - s->display.x->v_scrollbar_width - ibw/2, | |
2801 ibw/2, | |
2802 s->display.x->v_scrollbar_width - 2, | |
2803 pixelheight - ibw - 2); | |
2804 XMoveWindow (XDISPLAY | |
2805 s->display.x->v_thumbdown, 0, | |
2806 pixelheight - ibw - s->display.x->v_scrollbar_width); | |
2807 UNBLOCK_INPUT; | |
2808 } | |
2809 | |
2810 if (s->display.x->h_scrollbar_height && s->display.x->h_scrollbar) | |
2811 { | |
2812 if (s->display.x->v_scrollbar_width) | |
2813 pixelwidth -= s->display.x->v_scrollbar_width + 1; | |
2814 | |
2815 BLOCK_INPUT; | |
2816 XMoveResizeWindow (XDISPLAY | |
2817 s->display.x->h_scrollbar, | |
2818 ibw / 2, | |
2819 pixelheight - s->display.x->h_scrollbar_height - ibw / 2, | |
2820 pixelwidth - ibw - 2, | |
2821 s->display.x->h_scrollbar_height - 2); | |
2822 XMoveWindow (XDISPLAY | |
2823 s->display.x->h_thumbright, | |
2824 pixelwidth - ibw - s->display.x->h_scrollbar_height, 0); | |
2825 UNBLOCK_INPUT; | |
2826 } | |
2827 } | |
2828 | |
2829 x_pixel_width (s) | |
2830 register struct screen *s; | |
2831 { | |
2832 return PIXEL_WIDTH (s); | |
2833 } | |
2834 | |
2835 x_pixel_height (s) | |
2836 register struct screen *s; | |
2837 { | |
2838 return PIXEL_HEIGHT (s); | |
2839 } | |
2840 | |
2841 DEFUN ("x-defined-color", Fx_defined_color, Sx_defined_color, 1, 1, 0, | |
2842 "Return t if the current X display supports the color named COLOR.") | |
2843 (color) | |
2844 Lisp_Object color; | |
2845 { | |
2846 Color foo; | |
2847 | |
2848 CHECK_STRING (color, 0); | |
2849 | |
2850 if (defined_color (XSTRING (color)->data, &foo)) | |
2851 return Qt; | |
2852 else | |
2853 return Qnil; | |
2854 } | |
2855 | |
2856 DEFUN ("x-color-display-p", Fx_color_display_p, Sx_color_display_p, 0, 0, 0, | |
2857 "Return t if the X display used currently supports color.") | |
2858 () | |
2859 { | |
2860 if (XINT (x_screen_planes) <= 2) | |
2861 return Qnil; | |
2862 | |
2863 switch (screen_visual->class) | |
2864 { | |
2865 case StaticColor: | |
2866 case PseudoColor: | |
2867 case TrueColor: | |
2868 case DirectColor: | |
2869 return Qt; | |
2870 | |
2871 default: | |
2872 return Qnil; | |
2873 } | |
2874 } | |
2875 | |
2876 DEFUN ("x-pixel-width", Fx_pixel_width, Sx_pixel_width, 1, 1, 0, | |
2877 "Return the width in pixels of screen S.") | |
2878 (screen) | |
2879 Lisp_Object screen; | |
2880 { | |
2881 CHECK_SCREEN (screen, 0); | |
2882 return make_number (XSCREEN (screen)->display.x->pixel_width); | |
2883 } | |
2884 | |
2885 DEFUN ("x-pixel-height", Fx_pixel_height, Sx_pixel_height, 1, 1, 0, | |
2886 "Return the height in pixels of screen S.") | |
2887 (screen) | |
2888 Lisp_Object screen; | |
2889 { | |
2890 CHECK_SCREEN (screen, 0); | |
2891 return make_number (XSCREEN (screen)->display.x->pixel_height); | |
2892 } | |
2893 | |
2894 /* Draw a rectangle on the screen with left top corner including | |
2895 the character specified by LEFT_CHAR and TOP_CHAR. The rectangle is | |
2896 CHARS by LINES wide and long and is the color of the cursor. */ | |
2897 | |
2898 void | |
2899 x_rectangle (s, gc, left_char, top_char, chars, lines) | |
2900 register struct screen *s; | |
2901 GC gc; | |
2902 register int top_char, left_char, chars, lines; | |
2903 { | |
2904 int width; | |
2905 int height; | |
2906 int left = (left_char * FONT_WIDTH (s->display.x->font) | |
2907 + s->display.x->internal_border_width); | |
2908 int top = (top_char * FONT_HEIGHT (s->display.x->font) | |
2909 + s->display.x->internal_border_width); | |
2910 | |
2911 if (chars < 0) | |
2912 width = FONT_WIDTH (s->display.x->font) / 2; | |
2913 else | |
2914 width = FONT_WIDTH (s->display.x->font) * chars; | |
2915 if (lines < 0) | |
2916 height = FONT_HEIGHT (s->display.x->font) / 2; | |
2917 else | |
2918 height = FONT_HEIGHT (s->display.x->font) * lines; | |
2919 | |
2920 XDrawRectangle (x_current_display, s->display.x->window_desc, | |
2921 gc, left, top, width, height); | |
2922 } | |
2923 | |
2924 DEFUN ("x-draw-rectangle", Fx_draw_rectangle, Sx_draw_rectangle, 5, 5, 0, | |
2925 "Draw a rectangle on SCREEN between coordinates specified by\n\ | |
2926 numbers X0, Y0, X1, Y1 in the cursor pixel.") | |
2927 (screen, X0, Y0, X1, Y1) | |
2928 register Lisp_Object screen, X0, X1, Y0, Y1; | |
2929 { | |
2930 register int x0, y0, x1, y1, top, left, n_chars, n_lines; | |
2931 | |
2932 CHECK_SCREEN (screen, 0); | |
2933 CHECK_NUMBER (X0, 0); | |
2934 CHECK_NUMBER (Y0, 1); | |
2935 CHECK_NUMBER (X1, 2); | |
2936 CHECK_NUMBER (Y1, 3); | |
2937 | |
2938 x0 = XINT (X0); | |
2939 x1 = XINT (X1); | |
2940 y0 = XINT (Y0); | |
2941 y1 = XINT (Y1); | |
2942 | |
2943 if (y1 > y0) | |
2944 { | |
2945 top = y0; | |
2946 n_lines = y1 - y0 + 1; | |
2947 } | |
2948 else | |
2949 { | |
2950 top = y1; | |
2951 n_lines = y0 - y1 + 1; | |
2952 } | |
2953 | |
2954 if (x1 > x0) | |
2955 { | |
2956 left = x0; | |
2957 n_chars = x1 - x0 + 1; | |
2958 } | |
2959 else | |
2960 { | |
2961 left = x1; | |
2962 n_chars = x0 - x1 + 1; | |
2963 } | |
2964 | |
2965 BLOCK_INPUT; | |
2966 x_rectangle (XSCREEN (screen), XSCREEN (screen)->display.x->cursor_gc, | |
2967 left, top, n_chars, n_lines); | |
2968 UNBLOCK_INPUT; | |
2969 | |
2970 return Qt; | |
2971 } | |
2972 | |
2973 DEFUN ("x-erase-rectangle", Fx_erase_rectangle, Sx_erase_rectangle, 5, 5, 0, | |
2974 "Draw a rectangle drawn on SCREEN between coordinates\n\ | |
2975 X0, Y0, X1, Y1 in the regular background-pixel.") | |
2976 (screen, X0, Y0, X1, Y1) | |
2977 register Lisp_Object screen, X0, Y0, X1, Y1; | |
2978 { | |
2979 register int x0, y0, x1, y1, top, left, n_chars, n_lines; | |
2980 | |
2981 CHECK_SCREEN (screen, 0); | |
2982 CHECK_NUMBER (X0, 0); | |
2983 CHECK_NUMBER (Y0, 1); | |
2984 CHECK_NUMBER (X1, 2); | |
2985 CHECK_NUMBER (Y1, 3); | |
2986 | |
2987 x0 = XINT (X0); | |
2988 x1 = XINT (X1); | |
2989 y0 = XINT (Y0); | |
2990 y1 = XINT (Y1); | |
2991 | |
2992 if (y1 > y0) | |
2993 { | |
2994 top = y0; | |
2995 n_lines = y1 - y0 + 1; | |
2996 } | |
2997 else | |
2998 { | |
2999 top = y1; | |
3000 n_lines = y0 - y1 + 1; | |
3001 } | |
3002 | |
3003 if (x1 > x0) | |
3004 { | |
3005 left = x0; | |
3006 n_chars = x1 - x0 + 1; | |
3007 } | |
3008 else | |
3009 { | |
3010 left = x1; | |
3011 n_chars = x0 - x1 + 1; | |
3012 } | |
3013 | |
3014 BLOCK_INPUT; | |
3015 x_rectangle (XSCREEN (screen), XSCREEN (screen)->display.x->reverse_gc, | |
3016 left, top, n_chars, n_lines); | |
3017 UNBLOCK_INPUT; | |
3018 | |
3019 return Qt; | |
3020 } | |
3021 | |
3022 /* Draw lines around the text region beginning at the character position | |
3023 TOP_X, TOP_Y and ending at BOTTOM_X and BOTTOM_Y. GC specifies the | |
3024 pixel and line characteristics. */ | |
3025 | |
3026 #define line_len(line) (SCREEN_CURRENT_GLYPHS (s)->used[(line)]) | |
3027 | |
3028 static void | |
3029 outline_region (s, gc, top_x, top_y, bottom_x, bottom_y) | |
3030 register struct screen *s; | |
3031 GC gc; | |
3032 int top_x, top_y, bottom_x, bottom_y; | |
3033 { | |
3034 register int ibw = s->display.x->internal_border_width; | |
3035 register int font_w = FONT_WIDTH (s->display.x->font); | |
3036 register int font_h = FONT_HEIGHT (s->display.x->font); | |
3037 int y = top_y; | |
3038 int x = line_len (y); | |
3039 XPoint *pixel_points = (XPoint *) | |
3040 alloca (((bottom_y - top_y + 2) * 4) * sizeof (XPoint)); | |
3041 register XPoint *this_point = pixel_points; | |
3042 | |
3043 /* Do the horizontal top line/lines */ | |
3044 if (top_x == 0) | |
3045 { | |
3046 this_point->x = ibw; | |
3047 this_point->y = ibw + (font_h * top_y); | |
3048 this_point++; | |
3049 if (x == 0) | |
3050 this_point->x = ibw + (font_w / 2); /* Half-size for newline chars. */ | |
3051 else | |
3052 this_point->x = ibw + (font_w * x); | |
3053 this_point->y = (this_point - 1)->y; | |
3054 } | |
3055 else | |
3056 { | |
3057 this_point->x = ibw; | |
3058 this_point->y = ibw + (font_h * (top_y + 1)); | |
3059 this_point++; | |
3060 this_point->x = ibw + (font_w * top_x); | |
3061 this_point->y = (this_point - 1)->y; | |
3062 this_point++; | |
3063 this_point->x = (this_point - 1)->x; | |
3064 this_point->y = ibw + (font_h * top_y); | |
3065 this_point++; | |
3066 this_point->x = ibw + (font_w * x); | |
3067 this_point->y = (this_point - 1)->y; | |
3068 } | |
3069 | |
3070 /* Now do the right side. */ | |
3071 while (y < bottom_y) | |
3072 { /* Right vertical edge */ | |
3073 this_point++; | |
3074 this_point->x = (this_point - 1)->x; | |
3075 this_point->y = ibw + (font_h * (y + 1)); | |
3076 this_point++; | |
3077 | |
3078 y++; /* Horizontal connection to next line */ | |
3079 x = line_len (y); | |
3080 if (x == 0) | |
3081 this_point->x = ibw + (font_w / 2); | |
3082 else | |
3083 this_point->x = ibw + (font_w * x); | |
3084 | |
3085 this_point->y = (this_point - 1)->y; | |
3086 } | |
3087 | |
3088 /* Now do the bottom and connect to the top left point. */ | |
3089 this_point->x = ibw + (font_w * (bottom_x + 1)); | |
3090 | |
3091 this_point++; | |
3092 this_point->x = (this_point - 1)->x; | |
3093 this_point->y = ibw + (font_h * (bottom_y + 1)); | |
3094 this_point++; | |
3095 this_point->x = ibw; | |
3096 this_point->y = (this_point - 1)->y; | |
3097 this_point++; | |
3098 this_point->x = pixel_points->x; | |
3099 this_point->y = pixel_points->y; | |
3100 | |
3101 XDrawLines (x_current_display, s->display.x->window_desc, | |
3102 gc, pixel_points, | |
3103 (this_point - pixel_points + 1), CoordModeOrigin); | |
3104 } | |
3105 | |
3106 DEFUN ("x-contour-region", Fx_contour_region, Sx_contour_region, 1, 1, 0, | |
3107 "Highlight the region between point and the character under the mouse\n\ | |
3108 selected screen.") | |
3109 (event) | |
3110 register Lisp_Object event; | |
3111 { | |
3112 register int x0, y0, x1, y1; | |
3113 register struct screen *s = selected_screen; | |
3114 register int p1, p2; | |
3115 | |
3116 CHECK_CONS (event, 0); | |
3117 | |
3118 BLOCK_INPUT; | |
3119 x0 = XINT (Fcar (Fcar (event))); | |
3120 y0 = XINT (Fcar (Fcdr (Fcar (event)))); | |
3121 | |
3122 /* If the mouse is past the end of the line, don't that area. */ | |
3123 /* ReWrite this... */ | |
3124 | |
3125 x1 = s->cursor_x; | |
3126 y1 = s->cursor_y; | |
3127 | |
3128 if (y1 > y0) /* point below mouse */ | |
3129 outline_region (s, s->display.x->cursor_gc, | |
3130 x0, y0, x1, y1); | |
3131 else if (y1 < y0) /* point above mouse */ | |
3132 outline_region (s, s->display.x->cursor_gc, | |
3133 x1, y1, x0, y0); | |
3134 else /* same line: draw horizontal rectangle */ | |
3135 { | |
3136 if (x1 > x0) | |
3137 x_rectangle (s, s->display.x->cursor_gc, | |
3138 x0, y0, (x1 - x0 + 1), 1); | |
3139 else if (x1 < x0) | |
3140 x_rectangle (s, s->display.x->cursor_gc, | |
3141 x1, y1, (x0 - x1 + 1), 1); | |
3142 } | |
3143 | |
3144 XFlush (x_current_display); | |
3145 UNBLOCK_INPUT; | |
3146 | |
3147 return Qnil; | |
3148 } | |
3149 | |
3150 DEFUN ("x-uncontour-region", Fx_uncontour_region, Sx_uncontour_region, 1, 1, 0, | |
3151 "Erase any highlighting of the region between point and the character\n\ | |
3152 at X, Y on the selected screen.") | |
3153 (event) | |
3154 register Lisp_Object event; | |
3155 { | |
3156 register int x0, y0, x1, y1; | |
3157 register struct screen *s = selected_screen; | |
3158 | |
3159 BLOCK_INPUT; | |
3160 x0 = XINT (Fcar (Fcar (event))); | |
3161 y0 = XINT (Fcar (Fcdr (Fcar (event)))); | |
3162 x1 = s->cursor_x; | |
3163 y1 = s->cursor_y; | |
3164 | |
3165 if (y1 > y0) /* point below mouse */ | |
3166 outline_region (s, s->display.x->reverse_gc, | |
3167 x0, y0, x1, y1); | |
3168 else if (y1 < y0) /* point above mouse */ | |
3169 outline_region (s, s->display.x->reverse_gc, | |
3170 x1, y1, x0, y0); | |
3171 else /* same line: draw horizontal rectangle */ | |
3172 { | |
3173 if (x1 > x0) | |
3174 x_rectangle (s, s->display.x->reverse_gc, | |
3175 x0, y0, (x1 - x0 + 1), 1); | |
3176 else if (x1 < x0) | |
3177 x_rectangle (s, s->display.x->reverse_gc, | |
3178 x1, y1, (x0 - x1 + 1), 1); | |
3179 } | |
3180 UNBLOCK_INPUT; | |
3181 | |
3182 return Qnil; | |
3183 } | |
3184 | |
3185 extern unsigned int x_mouse_x, x_mouse_y, x_mouse_grabbed; | |
3186 extern Lisp_Object unread_command_char; | |
3187 | |
3188 #if 0 | |
3189 int contour_begin_x, contour_begin_y; | |
3190 int contour_end_x, contour_end_y; | |
3191 int contour_npoints; | |
3192 | |
3193 /* Clip the top part of the contour lines down (and including) line Y_POS. | |
3194 If X_POS is in the middle (rather than at the end) of the line, drop | |
3195 down a line at that character. */ | |
3196 | |
3197 static void | |
3198 clip_contour_top (y_pos, x_pos) | |
3199 { | |
3200 register XPoint *begin = contour_lines[y_pos].top_left; | |
3201 register XPoint *end; | |
3202 register int npoints; | |
3203 register struct display_line *line = selected_screen->phys_lines[y_pos + 1]; | |
3204 | |
3205 if (x_pos >= line->len - 1) /* Draw one, straight horizontal line. */ | |
3206 { | |
3207 end = contour_lines[y_pos].top_right; | |
3208 npoints = (end - begin + 1); | |
3209 XDrawLines (x_current_display, contour_window, | |
3210 contour_erase_gc, begin_erase, npoints, CoordModeOrigin); | |
3211 | |
3212 bcopy (end, begin + 1, contour_last_point - end + 1); | |
3213 contour_last_point -= (npoints - 2); | |
3214 XDrawLines (x_current_display, contour_window, | |
3215 contour_erase_gc, begin, 2, CoordModeOrigin); | |
3216 XFlush (x_current_display); | |
3217 | |
3218 /* Now, update contour_lines structure. */ | |
3219 } | |
3220 /* ______. */ | |
3221 else /* |________*/ | |
3222 { | |
3223 register XPoint *p = begin + 1; | |
3224 end = contour_lines[y_pos].bottom_right; | |
3225 npoints = (end - begin + 1); | |
3226 XDrawLines (x_current_display, contour_window, | |
3227 contour_erase_gc, begin_erase, npoints, CoordModeOrigin); | |
3228 | |
3229 p->y = begin->y; | |
3230 p->x = ibw + (font_w * (x_pos + 1)); | |
3231 p++; | |
3232 p->y = begin->y + font_h; | |
3233 p->x = (p - 1)->x; | |
3234 bcopy (end, begin + 3, contour_last_point - end + 1); | |
3235 contour_last_point -= (npoints - 5); | |
3236 XDrawLines (x_current_display, contour_window, | |
3237 contour_erase_gc, begin, 4, CoordModeOrigin); | |
3238 XFlush (x_current_display); | |
3239 | |
3240 /* Now, update contour_lines structure. */ | |
3241 } | |
3242 } | |
3243 | |
3244 /* Erase the top horzontal lines of the contour, and then extend | |
3245 the contour upwards. */ | |
3246 | |
3247 static void | |
3248 extend_contour_top (line) | |
3249 { | |
3250 } | |
3251 | |
3252 static void | |
3253 clip_contour_bottom (x_pos, y_pos) | |
3254 int x_pos, y_pos; | |
3255 { | |
3256 } | |
3257 | |
3258 static void | |
3259 extend_contour_bottom (x_pos, y_pos) | |
3260 { | |
3261 } | |
3262 | |
3263 DEFUN ("x-select-region", Fx_select_region, Sx_select_region, 1, 1, "e", | |
3264 "") | |
3265 (event) | |
3266 Lisp_Object event; | |
3267 { | |
3268 register struct screen *s = selected_screen; | |
3269 register int point_x = s->cursor_x; | |
3270 register int point_y = s->cursor_y; | |
3271 register int mouse_below_point; | |
3272 register Lisp_Object obj; | |
3273 register int x_contour_x, x_contour_y; | |
3274 | |
3275 x_contour_x = x_mouse_x; | |
3276 x_contour_y = x_mouse_y; | |
3277 if (x_contour_y > point_y || (x_contour_y == point_y | |
3278 && x_contour_x > point_x)) | |
3279 { | |
3280 mouse_below_point = 1; | |
3281 outline_region (s, s->display.x->cursor_gc, point_x, point_y, | |
3282 x_contour_x, x_contour_y); | |
3283 } | |
3284 else | |
3285 { | |
3286 mouse_below_point = 0; | |
3287 outline_region (s, s->display.x->cursor_gc, x_contour_x, x_contour_y, | |
3288 point_x, point_y); | |
3289 } | |
3290 | |
3291 while (1) | |
3292 { | |
3293 obj = read_char (-1); | |
3294 if (XTYPE (obj) != Lisp_Cons) | |
3295 break; | |
3296 | |
3297 if (mouse_below_point) | |
3298 { | |
3299 if (x_mouse_y <= point_y) /* Flipped. */ | |
3300 { | |
3301 mouse_below_point = 0; | |
3302 | |
3303 outline_region (s, s->display.x->reverse_gc, point_x, point_y, | |
3304 x_contour_x, x_contour_y); | |
3305 outline_region (s, s->display.x->cursor_gc, x_mouse_x, x_mouse_y, | |
3306 point_x, point_y); | |
3307 } | |
3308 else if (x_mouse_y < x_contour_y) /* Bottom clipped. */ | |
3309 { | |
3310 clip_contour_bottom (x_mouse_y); | |
3311 } | |
3312 else if (x_mouse_y > x_contour_y) /* Bottom extended. */ | |
3313 { | |
3314 extend_bottom_contour (x_mouse_y); | |
3315 } | |
3316 | |
3317 x_contour_x = x_mouse_x; | |
3318 x_contour_y = x_mouse_y; | |
3319 } | |
3320 else /* mouse above or same line as point */ | |
3321 { | |
3322 if (x_mouse_y >= point_y) /* Flipped. */ | |
3323 { | |
3324 mouse_below_point = 1; | |
3325 | |
3326 outline_region (s, s->display.x->reverse_gc, | |
3327 x_contour_x, x_contour_y, point_x, point_y); | |
3328 outline_region (s, s->display.x->cursor_gc, point_x, point_y, | |
3329 x_mouse_x, x_mouse_y); | |
3330 } | |
3331 else if (x_mouse_y > x_contour_y) /* Top clipped. */ | |
3332 { | |
3333 clip_contour_top (x_mouse_y); | |
3334 } | |
3335 else if (x_mouse_y < x_contour_y) /* Top extended. */ | |
3336 { | |
3337 extend_contour_top (x_mouse_y); | |
3338 } | |
3339 } | |
3340 } | |
3341 | |
3342 unread_command_char = obj; | |
3343 if (mouse_below_point) | |
3344 { | |
3345 contour_begin_x = point_x; | |
3346 contour_begin_y = point_y; | |
3347 contour_end_x = x_contour_x; | |
3348 contour_end_y = x_contour_y; | |
3349 } | |
3350 else | |
3351 { | |
3352 contour_begin_x = x_contour_x; | |
3353 contour_begin_y = x_contour_y; | |
3354 contour_end_x = point_x; | |
3355 contour_end_y = point_y; | |
3356 } | |
3357 } | |
3358 #endif | |
3359 | |
3360 DEFUN ("x-horizontal-line", Fx_horizontal_line, Sx_horizontal_line, 1, 1, "e", | |
3361 "") | |
3362 (event) | |
3363 Lisp_Object event; | |
3364 { | |
3365 register Lisp_Object obj; | |
3366 struct screen *s = selected_screen; | |
3367 register struct window *w = XWINDOW (selected_window); | |
3368 register GC line_gc = s->display.x->cursor_gc; | |
3369 register GC erase_gc = s->display.x->reverse_gc; | |
3370 #if 0 | |
3371 char dash_list[] = {6, 4, 6, 4}; | |
3372 int dashes = 4; | |
3373 XGCValues gc_values; | |
3374 #endif | |
3375 register int previous_y; | |
3376 register int line = (x_mouse_y + 1) * FONT_HEIGHT (s->display.x->font) | |
3377 + s->display.x->internal_border_width; | |
3378 register int left = s->display.x->internal_border_width | |
3379 + (w->left | |
3380 * FONT_WIDTH (s->display.x->font)); | |
3381 register int right = left + (w->width | |
3382 * FONT_WIDTH (s->display.x->font)) | |
3383 - s->display.x->internal_border_width; | |
3384 | |
3385 #if 0 | |
3386 BLOCK_INPUT; | |
3387 gc_values.foreground = s->display.x->cursor_pixel; | |
3388 gc_values.background = s->display.x->background_pixel; | |
3389 gc_values.line_width = 1; | |
3390 gc_values.line_style = LineOnOffDash; | |
3391 gc_values.cap_style = CapRound; | |
3392 gc_values.join_style = JoinRound; | |
3393 | |
3394 line_gc = XCreateGC (x_current_display, s->display.x->window_desc, | |
3395 GCLineStyle | GCJoinStyle | GCCapStyle | |
3396 | GCLineWidth | GCForeground | GCBackground, | |
3397 &gc_values); | |
3398 XSetDashes (x_current_display, line_gc, 0, dash_list, dashes); | |
3399 gc_values.foreground = s->display.x->background_pixel; | |
3400 gc_values.background = s->display.x->foreground_pixel; | |
3401 erase_gc = XCreateGC (x_current_display, s->display.x->window_desc, | |
3402 GCLineStyle | GCJoinStyle | GCCapStyle | |
3403 | GCLineWidth | GCForeground | GCBackground, | |
3404 &gc_values); | |
3405 XSetDashes (x_current_display, erase_gc, 0, dash_list, dashes); | |
3406 #endif | |
3407 | |
3408 while (1) | |
3409 { | |
3410 BLOCK_INPUT; | |
3411 if (x_mouse_y >= XINT (w->top) | |
3412 && x_mouse_y < XINT (w->top) + XINT (w->height) - 1) | |
3413 { | |
3414 previous_y = x_mouse_y; | |
3415 line = (x_mouse_y + 1) * FONT_HEIGHT (s->display.x->font) | |
3416 + s->display.x->internal_border_width; | |
3417 XDrawLine (x_current_display, s->display.x->window_desc, | |
3418 line_gc, left, line, right, line); | |
3419 } | |
3420 XFlushQueue (); | |
3421 UNBLOCK_INPUT; | |
3422 | |
3423 do | |
3424 { | |
3425 obj = read_char (-1); | |
3426 if ((XTYPE (obj) != Lisp_Cons) | |
3427 || (! EQ (Fcar (Fcdr (Fcdr (obj))), | |
3428 intern ("vertical-scroll-bar"))) | |
3429 || x_mouse_grabbed) | |
3430 { | |
3431 BLOCK_INPUT; | |
3432 XDrawLine (x_current_display, s->display.x->window_desc, | |
3433 erase_gc, left, line, right, line); | |
3434 UNBLOCK_INPUT; | |
3435 unread_command_char = obj; | |
3436 #if 0 | |
3437 XFreeGC (x_current_display, line_gc); | |
3438 XFreeGC (x_current_display, erase_gc); | |
3439 #endif | |
3440 return Qnil; | |
3441 } | |
3442 } | |
3443 while (x_mouse_y == previous_y); | |
3444 | |
3445 BLOCK_INPUT; | |
3446 XDrawLine (x_current_display, s->display.x->window_desc, | |
3447 erase_gc, left, line, right, line); | |
3448 UNBLOCK_INPUT; | |
3449 } | |
3450 } | |
3451 | |
3452 /* Offset in buffer of character under the pointer, or 0. */ | |
3453 int mouse_buffer_offset; | |
3454 | |
3455 #if 0 | |
3456 /* These keep track of the rectangle following the pointer. */ | |
3457 int mouse_track_top, mouse_track_left, mouse_track_width; | |
3458 | |
3459 DEFUN ("x-track-pointer", Fx_track_pointer, Sx_track_pointer, 0, 0, 0, | |
3460 "Track the pointer.") | |
3461 () | |
3462 { | |
3463 static Cursor current_pointer_shape; | |
3464 SCREEN_PTR s = x_mouse_screen; | |
3465 | |
3466 BLOCK_INPUT; | |
3467 if (EQ (Vmouse_screen_part, Qtext_part) | |
3468 && (current_pointer_shape != s->display.x->nontext_cursor)) | |
3469 { | |
3470 unsigned char c; | |
3471 struct buffer *buf; | |
3472 | |
3473 current_pointer_shape = s->display.x->nontext_cursor; | |
3474 XDefineCursor (x_current_display, | |
3475 s->display.x->window_desc, | |
3476 current_pointer_shape); | |
3477 | |
3478 buf = XBUFFER (XWINDOW (Vmouse_window)->buffer); | |
3479 c = *(BUF_CHAR_ADDRESS (buf, mouse_buffer_offset)); | |
3480 } | |
3481 else if (EQ (Vmouse_screen_part, Qmodeline_part) | |
3482 && (current_pointer_shape != s->display.x->modeline_cursor)) | |
3483 { | |
3484 current_pointer_shape = s->display.x->modeline_cursor; | |
3485 XDefineCursor (x_current_display, | |
3486 s->display.x->window_desc, | |
3487 current_pointer_shape); | |
3488 } | |
3489 | |
3490 XFlushQueue (); | |
3491 UNBLOCK_INPUT; | |
3492 } | |
3493 #endif | |
3494 | |
3495 #if 0 | |
3496 DEFUN ("x-track-pointer", Fx_track_pointer, Sx_track_pointer, 1, 1, "e", | |
3497 "Draw rectangle around character under mouse pointer, if there is one.") | |
3498 (event) | |
3499 Lisp_Object event; | |
3500 { | |
3501 struct window *w = XWINDOW (Vmouse_window); | |
3502 struct screen *s = XSCREEN (WINDOW_SCREEN (w)); | |
3503 struct buffer *b = XBUFFER (w->buffer); | |
3504 Lisp_Object obj; | |
3505 | |
3506 if (! EQ (Vmouse_window, selected_window)) | |
3507 return Qnil; | |
3508 | |
3509 if (EQ (event, Qnil)) | |
3510 { | |
3511 int x, y; | |
3512 | |
3513 x_read_mouse_position (selected_screen, &x, &y); | |
3514 } | |
3515 | |
3516 BLOCK_INPUT; | |
3517 mouse_track_width = 0; | |
3518 mouse_track_left = mouse_track_top = -1; | |
3519 | |
3520 do | |
3521 { | |
3522 if ((x_mouse_x != mouse_track_left | |
3523 && (x_mouse_x < mouse_track_left | |
3524 || x_mouse_x > (mouse_track_left + mouse_track_width))) | |
3525 || x_mouse_y != mouse_track_top) | |
3526 { | |
3527 int hp = 0; /* Horizontal position */ | |
3528 int len = SCREEN_CURRENT_GLYPHS (s)->used[x_mouse_y]; | |
3529 int p = SCREEN_CURRENT_GLYPHS (s)->bufp[x_mouse_y]; | |
3530 int tab_width = XINT (b->tab_width); | |
3531 int ctl_arrow_p = !NULL (b->ctl_arrow); | |
3532 unsigned char c; | |
3533 int mode_line_vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1; | |
3534 int in_mode_line = 0; | |
3535 | |
3536 if (! SCREEN_CURRENT_GLYPHS (s)->enable[x_mouse_y]) | |
3537 break; | |
3538 | |
3539 /* Erase previous rectangle. */ | |
3540 if (mouse_track_width) | |
3541 { | |
3542 x_rectangle (s, s->display.x->reverse_gc, | |
3543 mouse_track_left, mouse_track_top, | |
3544 mouse_track_width, 1); | |
3545 | |
3546 if ((mouse_track_left == s->phys_cursor_x | |
3547 || mouse_track_left == s->phys_cursor_x - 1) | |
3548 && mouse_track_top == s->phys_cursor_y) | |
3549 { | |
3550 x_display_cursor (s, 1); | |
3551 } | |
3552 } | |
3553 | |
3554 mouse_track_left = x_mouse_x; | |
3555 mouse_track_top = x_mouse_y; | |
3556 mouse_track_width = 0; | |
3557 | |
3558 if (mouse_track_left > len) /* Past the end of line. */ | |
3559 goto draw_or_not; | |
3560 | |
3561 if (mouse_track_top == mode_line_vpos) | |
3562 { | |
3563 in_mode_line = 1; | |
3564 goto draw_or_not; | |
3565 } | |
3566 | |
3567 if (tab_width <= 0 || tab_width > 20) tab_width = 8; | |
3568 do | |
3569 { | |
3570 c = FETCH_CHAR (p); | |
3571 if (len == s->width && hp == len - 1 && c != '\n') | |
3572 goto draw_or_not; | |
3573 | |
3574 switch (c) | |
3575 { | |
3576 case '\t': | |
3577 mouse_track_width = tab_width - (hp % tab_width); | |
3578 p++; | |
3579 hp += mouse_track_width; | |
3580 if (hp > x_mouse_x) | |
3581 { | |
3582 mouse_track_left = hp - mouse_track_width; | |
3583 goto draw_or_not; | |
3584 } | |
3585 continue; | |
3586 | |
3587 case '\n': | |
3588 mouse_track_width = -1; | |
3589 goto draw_or_not; | |
3590 | |
3591 default: | |
3592 if (ctl_arrow_p && (c < 040 || c == 0177)) | |
3593 { | |
3594 if (p > ZV) | |
3595 goto draw_or_not; | |
3596 | |
3597 mouse_track_width = 2; | |
3598 p++; | |
3599 hp +=2; | |
3600 if (hp > x_mouse_x) | |
3601 { | |
3602 mouse_track_left = hp - mouse_track_width; | |
3603 goto draw_or_not; | |
3604 } | |
3605 } | |
3606 else | |
3607 { | |
3608 mouse_track_width = 1; | |
3609 p++; | |
3610 hp++; | |
3611 } | |
3612 continue; | |
3613 } | |
3614 } | |
3615 while (hp <= x_mouse_x); | |
3616 | |
3617 draw_or_not: | |
3618 if (mouse_track_width) /* Over text; use text pointer shape. */ | |
3619 { | |
3620 XDefineCursor (x_current_display, | |
3621 s->display.x->window_desc, | |
3622 s->display.x->text_cursor); | |
3623 x_rectangle (s, s->display.x->cursor_gc, | |
3624 mouse_track_left, mouse_track_top, | |
3625 mouse_track_width, 1); | |
3626 } | |
3627 else if (in_mode_line) | |
3628 XDefineCursor (x_current_display, | |
3629 s->display.x->window_desc, | |
3630 s->display.x->modeline_cursor); | |
3631 else | |
3632 XDefineCursor (x_current_display, | |
3633 s->display.x->window_desc, | |
3634 s->display.x->nontext_cursor); | |
3635 } | |
3636 | |
3637 XFlush (x_current_display); | |
3638 UNBLOCK_INPUT; | |
3639 | |
3640 obj = read_char (-1); | |
3641 BLOCK_INPUT; | |
3642 } | |
3643 while (XTYPE (obj) == Lisp_Cons /* Mouse event */ | |
3644 && EQ (Fcar (Fcdr (Fcdr (obj))), Qnil) /* Not scrollbar */ | |
3645 && EQ (Vmouse_depressed, Qnil) /* Only motion events */ | |
3646 && EQ (Vmouse_window, selected_window) /* In this window */ | |
3647 && x_mouse_screen); | |
3648 | |
3649 unread_command_char = obj; | |
3650 | |
3651 if (mouse_track_width) | |
3652 { | |
3653 x_rectangle (s, s->display.x->reverse_gc, | |
3654 mouse_track_left, mouse_track_top, | |
3655 mouse_track_width, 1); | |
3656 mouse_track_width = 0; | |
3657 if ((mouse_track_left == s->phys_cursor_x | |
3658 || mouse_track_left - 1 == s->phys_cursor_x) | |
3659 && mouse_track_top == s->phys_cursor_y) | |
3660 { | |
3661 x_display_cursor (s, 1); | |
3662 } | |
3663 } | |
3664 XDefineCursor (x_current_display, | |
3665 s->display.x->window_desc, | |
3666 s->display.x->nontext_cursor); | |
3667 XFlush (x_current_display); | |
3668 UNBLOCK_INPUT; | |
3669 | |
3670 return Qnil; | |
3671 } | |
3672 #endif | |
3673 | |
3674 #if 0 | |
3675 #include "glyphs.h" | |
3676 | |
3677 /* Draw a pixmap specified by IMAGE_DATA of dimensions WIDTH and HEIGHT | |
3678 on the screen S at position X, Y. */ | |
3679 | |
3680 x_draw_pixmap (s, x, y, image_data, width, height) | |
3681 struct screen *s; | |
3682 int x, y, width, height; | |
3683 char *image_data; | |
3684 { | |
3685 Pixmap image; | |
3686 | |
3687 image = XCreateBitmapFromData (x_current_display, | |
3688 s->display.x->window_desc, image_data, | |
3689 width, height); | |
3690 XCopyPlane (x_current_display, image, s->display.x->window_desc, | |
3691 s->display.x->normal_gc, 0, 0, width, height, x, y); | |
3692 } | |
3693 #endif | |
3694 | |
3695 x_read_mouse_position (s, x, y) | |
3696 struct screen *s; | |
3697 int *x, *y; | |
3698 { | |
3699 Window w; | |
3700 int ix, iy; | |
3701 int ibw = s->display.x->internal_border_width; | |
3702 | |
3703 #ifdef HAVE_X11 | |
3704 Window root_window; | |
3705 int root_x, root_y; | |
3706 unsigned int keys_and_buttons; | |
3707 | |
3708 BLOCK_INPUT; | |
3709 if (XQueryPointer (x_current_display, s->display.x->window_desc, | |
3710 &root_window, &w, &root_x, &root_y, &ix, &iy, | |
3711 &keys_and_buttons) == False) | |
3712 { | |
3713 UNBLOCK_INPUT; | |
3714 error ("Pointer not on same screen as window."); | |
3715 } | |
3716 UNBLOCK_INPUT; | |
3717 #else | |
3718 BLOCK_INPUT; | |
3719 XQueryMouse (s->display.x->window_desc, &ix, &iy, &w); | |
3720 UNBLOCK_INPUT; | |
3721 #endif /* not HAVE_X11 */ | |
3722 | |
3723 x_mouse_x = *x = (ix - ibw) / FONT_WIDTH (s->display.x->font); | |
3724 x_mouse_y = *y = (iy - ibw) / FONT_HEIGHT (s->display.x->font); | |
3725 } | |
3726 | |
3727 #if 0 | |
3728 | |
3729 #ifdef HAVE_X11 | |
3730 #define XMouseEvent XEvent | |
3731 #define WhichMouseButton xbutton.button | |
3732 #define MouseWindow xbutton.window | |
3733 #define MouseX xbutton.x | |
3734 #define MouseY xbutton.y | |
3735 #define MouseTime xbutton.time | |
3736 #define ButtonReleased ButtonRelease | |
3737 #define ButtonPressed ButtonPress | |
3738 #else | |
3739 #define XMouseEvent XButtonEvent | |
3740 #define WhichMouseButton detail | |
3741 #define MouseWindow window | |
3742 #define MouseX x | |
3743 #define MouseY y | |
3744 #define MouseTime time | |
3745 #endif /* X11 */ | |
3746 | |
3747 DEFUN ("x-mouse-events", Fx_mouse_events, Sx_mouse_events, 0, 0, 0, | |
3748 "Return number of pending mouse events from X window system.") | |
3749 () | |
3750 { | |
3751 return make_number (queue_event_count (&x_mouse_queue)); | |
3752 } | |
3753 | |
3754 /* Encode the mouse button events in the form expected by the | |
3755 mouse code in Lisp. For X11, this means moving the masks around. */ | |
3756 | |
3757 static int | |
3758 encode_mouse_button (mouse_event) | |
3759 XMouseEvent mouse_event; | |
3760 { | |
3761 register int event_code; | |
3762 register char key_mask; | |
3763 | |
3764 event_code = mouse_event.detail & 3; | |
3765 key_mask = (mouse_event.detail >> 8) & 0xf0; | |
3766 event_code |= key_mask >> 1; | |
3767 if (mouse_event.type == ButtonReleased) event_code |= 0x04; | |
3768 return event_code; | |
3769 } | |
3770 | |
3771 DEFUN ("x-get-mouse-event", Fx_get_mouse_event, Sx_get_mouse_event, | |
3772 0, 1, 0, | |
3773 "Get next mouse event out of mouse event buffer.\n\ | |
3774 Optional ARG non-nil means return nil immediately if no pending event;\n\ | |
3775 otherwise, wait for an event. Returns a four-part list:\n\ | |
3776 ((X-POS Y-POS) WINDOW SCREEN-PART KEYSEQ TIMESTAMP).\n\ | |
3777 Normally X-POS and Y-POS are the position of the click on the screen\n\ | |
3778 (measured in characters and lines), and WINDOW is the window clicked in.\n\ | |
3779 KEYSEQ is a string, the key sequence to be looked up in the mouse maps.\n\ | |
3780 If SCREEN-PART is non-nil, the event was on a scrollbar;\n\ | |
3781 then Y-POS is really the total length of the scrollbar, while X-POS is\n\ | |
3782 the relative position of the scrollbar's value within that total length,\n\ | |
3783 and a third element OFFSET appears in that list: the height of the thumb-up\n\ | |
3784 area at the top of the scroll bar.\n\ | |
3785 SCREEN-PART is one of the following symbols:\n\ | |
3786 `vertical-scrollbar', `vertical-thumbup', `vertical-thumbdown',\n\ | |
3787 `horizontal-scrollbar', `horizontal-thumbleft', `horizontal-thumbright'.\n\ | |
3788 TIMESTAMP is the lower 23 bits of the X-server's timestamp for\n\ | |
3789 the mouse event.") | |
3790 (arg) | |
3791 Lisp_Object arg; | |
3792 { | |
3793 XMouseEvent xrep; | |
3794 register int com_letter; | |
3795 register Lisp_Object tempx; | |
3796 register Lisp_Object tempy; | |
3797 Lisp_Object part, pos, timestamp; | |
3798 int prefix; | |
3799 struct screen *s; | |
3800 | |
3801 int tem; | |
3802 | |
3803 while (1) | |
3804 { | |
3805 BLOCK_INPUT; | |
3806 tem = dequeue_event (&xrep, &x_mouse_queue); | |
3807 UNBLOCK_INPUT; | |
3808 | |
3809 if (tem) | |
3810 { | |
3811 switch (xrep.type) | |
3812 { | |
3813 case ButtonPressed: | |
3814 case ButtonReleased: | |
3815 | |
3816 com_letter = encode_mouse_button (xrep); | |
3817 mouse_timestamp = xrep.MouseTime; | |
3818 | |
3819 if ((s = x_window_to_screen (xrep.MouseWindow)) != 0) | |
3820 { | |
3821 Lisp_Object screen; | |
3822 | |
3823 if (s->display.x->icon_desc == xrep.MouseWindow) | |
3824 { | |
3825 x_make_screen_visible (s); | |
3826 continue; | |
3827 } | |
3828 | |
3829 XSET (tempx, Lisp_Int, | |
3830 min (s->width-1, max (0, (xrep.MouseX - s->display.x->internal_border_width)/FONT_WIDTH (s->display.x->font)))); | |
3831 XSET (tempy, Lisp_Int, | |
3832 min (s->height-1, max (0, (xrep.MouseY - s->display.x->internal_border_width)/FONT_HEIGHT (s->display.x->font)))); | |
3833 XSET (timestamp, Lisp_Int, (xrep.MouseTime & 0x7fffff)); | |
3834 XSET (screen, Lisp_Screen, s); | |
3835 | |
3836 pos = Fcons (tempx, Fcons (tempy, Qnil)); | |
3837 Vmouse_window | |
3838 = Flocate_window_from_coordinates (screen, pos); | |
3839 | |
3840 Vmouse_event | |
3841 = Fcons (pos, | |
3842 Fcons (Vmouse_window, | |
3843 Fcons (Qnil, | |
3844 Fcons (Fchar_to_string (make_number (com_letter)), | |
3845 Fcons (timestamp, Qnil))))); | |
3846 return Vmouse_event; | |
3847 } | |
3848 else if ((s = x_window_to_scrollbar (xrep.MouseWindow, &part, &prefix)) != 0) | |
3849 { | |
3850 int pos, len; | |
3851 Lisp_Object keyseq; | |
3852 char *partname; | |
3853 | |
3854 keyseq = concat2 (Fchar_to_string (make_number (prefix)), | |
3855 Fchar_to_string (make_number (com_letter))); | |
3856 | |
3857 pos = xrep.MouseY - (s->display.x->v_scrollbar_width - 2); | |
3858 XSET (tempx, Lisp_Int, pos); | |
3859 len = ((FONT_HEIGHT (s->display.x->font) * s->height) | |
3860 + s->display.x->internal_border_width | |
3861 - (2 * (s->display.x->v_scrollbar_width - 2))); | |
3862 XSET (tempy, Lisp_Int, len); | |
3863 XSET (timestamp, Lisp_Int, (xrep.MouseTime & 0x7fffff)); | |
3864 Vmouse_window = s->selected_window; | |
3865 Vmouse_event | |
3866 = Fcons (Fcons (tempx, Fcons (tempy, | |
3867 Fcons (make_number (s->display.x->v_scrollbar_width - 2), | |
3868 Qnil))), | |
3869 Fcons (Vmouse_window, | |
3870 Fcons (intern (part), | |
3871 Fcons (keyseq, Fcons (timestamp, | |
3872 Qnil))))); | |
3873 return Vmouse_event; | |
3874 } | |
3875 else | |
3876 continue; | |
3877 | |
3878 #ifdef HAVE_X11 | |
3879 case MotionNotify: | |
3880 | |
3881 com_letter = x11_encode_mouse_button (xrep); | |
3882 if ((s = x_window_to_screen (xrep.MouseWindow)) != 0) | |
3883 { | |
3884 Lisp_Object screen; | |
3885 | |
3886 XSET (tempx, Lisp_Int, | |
3887 min (s->width-1, | |
3888 max (0, (xrep.MouseX - s->display.x->internal_border_width) | |
3889 / FONT_WIDTH (s->display.x->font)))); | |
3890 XSET (tempy, Lisp_Int, | |
3891 min (s->height-1, | |
3892 max (0, (xrep.MouseY - s->display.x->internal_border_width) | |
3893 / FONT_HEIGHT (s->display.x->font)))); | |
3894 | |
3895 XSET (screen, Lisp_Screen, s); | |
3896 XSET (timestamp, Lisp_Int, (xrep.MouseTime & 0x7fffff)); | |
3897 | |
3898 pos = Fcons (tempx, Fcons (tempy, Qnil)); | |
3899 Vmouse_window | |
3900 = Flocate_window_from_coordinates (screen, pos); | |
3901 | |
3902 Vmouse_event | |
3903 = Fcons (pos, | |
3904 Fcons (Vmouse_window, | |
3905 Fcons (Qnil, | |
3906 Fcons (Fchar_to_string (make_number (com_letter)), | |
3907 Fcons (timestamp, Qnil))))); | |
3908 return Vmouse_event; | |
3909 } | |
3910 | |
3911 break; | |
3912 #endif /* HAVE_X11 */ | |
3913 | |
3914 default: | |
3915 if (s = x_window_to_screen (xrep.MouseWindow)) | |
3916 Vmouse_window = s->selected_window; | |
3917 else if (s = x_window_to_scrollbar (xrep.MouseWindow, &part, &prefix)) | |
3918 Vmouse_window = s->selected_window; | |
3919 return Vmouse_event = Qnil; | |
3920 } | |
3921 } | |
3922 | |
3923 if (!NULL (arg)) | |
3924 return Qnil; | |
3925 | |
3926 /* Wait till we get another mouse event. */ | |
3927 wait_reading_process_input (0, 0, 2, 0); | |
3928 } | |
3929 } | |
3930 #endif | |
3931 | |
3932 | |
3933 #ifndef HAVE_X11 | |
3934 DEFUN ("x-store-cut-buffer", Fx_store_cut_buffer, Sx_store_cut_buffer, | |
3935 1, 1, "sStore text in cut buffer: ", | |
3936 "Store contents of STRING into the cut buffer of the X window system.") | |
3937 (string) | |
3938 register Lisp_Object string; | |
3939 { | |
3940 int mask; | |
3941 | |
3942 CHECK_STRING (string, 1); | |
3943 if (selected_screen->output_method != output_x_window) | |
3944 error ("Selected screen does not understand X protocol."); | |
3945 | |
3946 BLOCK_INPUT; | |
3947 XStoreBytes ((char *) XSTRING (string)->data, XSTRING (string)->size); | |
3948 UNBLOCK_INPUT; | |
3949 | |
3950 return Qnil; | |
3951 } | |
3952 | |
3953 DEFUN ("x-get-cut-buffer", Fx_get_cut_buffer, Sx_get_cut_buffer, 0, 0, 0, | |
3954 "Return contents of cut buffer of the X window system, as a string.") | |
3955 () | |
3956 { | |
3957 int len; | |
3958 register Lisp_Object string; | |
3959 int mask; | |
3960 register char *d; | |
3961 | |
3962 BLOCK_INPUT; | |
3963 d = XFetchBytes (&len); | |
3964 string = make_string (d, len); | |
3965 XFree (d); | |
3966 UNBLOCK_INPUT; | |
3967 return string; | |
3968 } | |
3969 #endif /* X10 */ | |
3970 | |
3971 #ifdef HAVE_X11 | |
3972 DEFUN ("x-rebind-key", Fx_rebind_key, Sx_rebind_key, 3, 3, 0, | |
3973 "Rebind X keysym KEYSYM, with MODIFIERS, to generate NEWSTRING.\n\ | |
3974 KEYSYM is a string which conforms to the X keysym definitions found\n\ | |
3975 in X11/keysymdef.h, sans the initial XK_. MODIFIERS is nil or a\n\ | |
3976 list of strings specifying modifier keys such as Control_L, which must\n\ | |
3977 also be depressed for NEWSTRING to appear.") | |
3978 (x_keysym, modifiers, newstring) | |
3979 register Lisp_Object x_keysym; | |
3980 register Lisp_Object modifiers; | |
3981 register Lisp_Object newstring; | |
3982 { | |
3983 char *rawstring; | |
3984 register KeySym keysym, modifier_list[16]; | |
3985 | |
3986 CHECK_STRING (x_keysym, 1); | |
3987 CHECK_STRING (newstring, 3); | |
3988 | |
3989 keysym = XStringToKeysym ((char *) XSTRING (x_keysym)->data); | |
3990 if (keysym == NoSymbol) | |
3991 error ("Keysym does not exist"); | |
3992 | |
3993 if (NULL (modifiers)) | |
3994 XRebindKeysym (x_current_display, keysym, modifier_list, 0, | |
3995 XSTRING (newstring)->data, XSTRING (newstring)->size); | |
3996 else | |
3997 { | |
3998 register Lisp_Object rest, mod; | |
3999 register int i = 0; | |
4000 | |
4001 for (rest = modifiers; !NULL (rest); rest = Fcdr (rest)) | |
4002 { | |
4003 if (i == 16) | |
4004 error ("Can't have more than 16 modifiers"); | |
4005 | |
4006 mod = Fcar (rest); | |
4007 CHECK_STRING (mod, 3); | |
4008 modifier_list[i] = XStringToKeysym ((char *) XSTRING (mod)->data); | |
4009 if (modifier_list[i] == NoSymbol | |
4010 || !IsModifierKey (modifier_list[i])) | |
4011 error ("Element is not a modifier keysym"); | |
4012 i++; | |
4013 } | |
4014 | |
4015 XRebindKeysym (x_current_display, keysym, modifier_list, i, | |
4016 XSTRING (newstring)->data, XSTRING (newstring)->size); | |
4017 } | |
4018 | |
4019 return Qnil; | |
4020 } | |
4021 | |
4022 DEFUN ("x-rebind-keys", Fx_rebind_keys, Sx_rebind_keys, 2, 2, 0, | |
4023 "Rebind KEYCODE to list of strings STRINGS.\n\ | |
4024 STRINGS should be a list of 16 elements, one for each shift combination.\n\ | |
4025 nil as element means don't change.\n\ | |
4026 See the documentation of `x-rebind-key' for more information.") | |
4027 (keycode, strings) | |
4028 register Lisp_Object keycode; | |
4029 register Lisp_Object strings; | |
4030 { | |
4031 register Lisp_Object item; | |
4032 register unsigned char *rawstring; | |
4033 KeySym rawkey, modifier[1]; | |
4034 int strsize; | |
4035 register unsigned i; | |
4036 | |
4037 CHECK_NUMBER (keycode, 1); | |
4038 CHECK_CONS (strings, 2); | |
4039 rawkey = (KeySym) ((unsigned) (XINT (keycode))) & 255; | |
4040 for (i = 0; i <= 15; strings = Fcdr (strings), i++) | |
4041 { | |
4042 item = Fcar (strings); | |
4043 if (!NULL (item)) | |
4044 { | |
4045 CHECK_STRING (item, 2); | |
4046 strsize = XSTRING (item)->size; | |
4047 rawstring = (unsigned char *) xmalloc (strsize); | |
4048 bcopy (XSTRING (item)->data, rawstring, strsize); | |
4049 modifier[1] = 1 << i; | |
4050 XRebindKeysym (x_current_display, rawkey, modifier, 1, | |
4051 rawstring, strsize); | |
4052 } | |
4053 } | |
4054 return Qnil; | |
4055 } | |
4056 #else | |
4057 DEFUN ("x-rebind-key", Fx_rebind_key, Sx_rebind_key, 3, 3, 0, | |
4058 "Rebind KEYCODE, with shift bits SHIFT-MASK, to new string NEWSTRING.\n\ | |
4059 KEYCODE and SHIFT-MASK should be numbers representing the X keyboard code\n\ | |
4060 and shift mask respectively. NEWSTRING is an arbitrary string of keystrokes.\n\ | |
4061 If SHIFT-MASK is nil, then KEYCODE's key will be bound to NEWSTRING for\n\ | |
4062 all shift combinations.\n\ | |
4063 Shift Lock 1 Shift 2\n\ | |
4064 Meta 4 Control 8\n\ | |
4065 \n\ | |
4066 For values of KEYCODE, see /usr/lib/Xkeymap.txt (remember that the codes\n\ | |
4067 in that file are in octal!)\n\ | |
4068 \n\ | |
4069 NOTE: due to an X bug, this function will not take effect unless one has\n\ | |
4070 a `~/.Xkeymap' file. (See the documentation for the `keycomp' program.)\n\ | |
4071 This problem will be fixed in X version 11.") | |
4072 | |
4073 (keycode, shift_mask, newstring) | |
4074 register Lisp_Object keycode; | |
4075 register Lisp_Object shift_mask; | |
4076 register Lisp_Object newstring; | |
4077 { | |
4078 char *rawstring; | |
4079 int keysym, rawshift; | |
4080 int i, strsize; | |
4081 | |
4082 CHECK_NUMBER (keycode, 1); | |
4083 if (!NULL (shift_mask)) | |
4084 CHECK_NUMBER (shift_mask, 2); | |
4085 CHECK_STRING (newstring, 3); | |
4086 strsize = XSTRING (newstring)->size; | |
4087 rawstring = (char *) xmalloc (strsize); | |
4088 bcopy (XSTRING (newstring)->data, rawstring, strsize); | |
4089 | |
4090 keysym = ((unsigned) (XINT (keycode))) & 255; | |
4091 | |
4092 if (NULL (shift_mask)) | |
4093 { | |
4094 for (i = 0; i <= 15; i++) | |
4095 XRebindCode (keysym, i<<11, rawstring, strsize); | |
4096 } | |
4097 else | |
4098 { | |
4099 rawshift = (((unsigned) (XINT (shift_mask))) & 15) << 11; | |
4100 XRebindCode (keysym, rawshift, rawstring, strsize); | |
4101 } | |
4102 return Qnil; | |
4103 } | |
4104 | |
4105 DEFUN ("x-rebind-keys", Fx_rebind_keys, Sx_rebind_keys, 2, 2, 0, | |
4106 "Rebind KEYCODE to list of strings STRINGS.\n\ | |
4107 STRINGS should be a list of 16 elements, one for each shift combination.\n\ | |
4108 nil as element means don't change.\n\ | |
4109 See the documentation of `x-rebind-key' for more information.") | |
4110 (keycode, strings) | |
4111 register Lisp_Object keycode; | |
4112 register Lisp_Object strings; | |
4113 { | |
4114 register Lisp_Object item; | |
4115 register char *rawstring; | |
4116 KeySym rawkey, modifier[1]; | |
4117 int strsize; | |
4118 register unsigned i; | |
4119 | |
4120 CHECK_NUMBER (keycode, 1); | |
4121 CHECK_CONS (strings, 2); | |
4122 rawkey = (KeySym) ((unsigned) (XINT (keycode))) & 255; | |
4123 for (i = 0; i <= 15; strings = Fcdr (strings), i++) | |
4124 { | |
4125 item = Fcar (strings); | |
4126 if (!NULL (item)) | |
4127 { | |
4128 CHECK_STRING (item, 2); | |
4129 strsize = XSTRING (item)->size; | |
4130 rawstring = (char *) xmalloc (strsize); | |
4131 bcopy (XSTRING (item)->data, rawstring, strsize); | |
4132 XRebindCode (rawkey, i << 11, rawstring, strsize); | |
4133 } | |
4134 } | |
4135 return Qnil; | |
4136 } | |
4137 #endif /* not HAVE_X11 */ | |
4138 | |
4139 #ifdef HAVE_X11 | |
4140 Visual * | |
4141 select_visual (screen, depth) | |
4142 Screen *screen; | |
4143 unsigned int *depth; | |
4144 { | |
4145 Visual *v; | |
4146 XVisualInfo *vinfo, vinfo_template; | |
4147 int n_visuals; | |
4148 | |
4149 v = DefaultVisualOfScreen (screen); | |
4150 vinfo_template.visualid = XVisualIDFromVisual (v); | |
4151 vinfo = XGetVisualInfo (x_current_display, VisualIDMask, &vinfo_template, | |
4152 &n_visuals); | |
4153 if (n_visuals != 1) | |
4154 fatal ("Can't get proper X visual info"); | |
4155 | |
4156 if ((1 << vinfo->depth) == vinfo->colormap_size) | |
4157 *depth = vinfo->depth; | |
4158 else | |
4159 { | |
4160 int i = 0; | |
4161 int n = vinfo->colormap_size - 1; | |
4162 while (n) | |
4163 { | |
4164 n = n >> 1; | |
4165 i++; | |
4166 } | |
4167 *depth = i; | |
4168 } | |
4169 | |
4170 XFree ((char *) vinfo); | |
4171 return v; | |
4172 } | |
4173 #endif /* HAVE_X11 */ | |
4174 | |
4175 DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, | |
4176 1, 2, 0, "Open a connection to an X server.\n\ | |
4177 DISPLAY is the name of the display to connect to. Optional second\n\ | |
4178 arg XRM_STRING is a string of resources in xrdb format.") | |
4179 (display, xrm_string) | |
4180 Lisp_Object display, xrm_string; | |
4181 { | |
4182 unsigned int n_planes; | |
4183 register Screen *x_screen; | |
4184 unsigned char *xrm_option; | |
4185 | |
4186 CHECK_STRING (display, 0); | |
4187 if (x_current_display != 0) | |
4188 error ("X server connection is already initialized"); | |
4189 | |
4190 /* This is what opens the connection and sets x_current_display. | |
4191 This also initializes many symbols, such as those used for input. */ | |
4192 x_term_init (XSTRING (display)->data); | |
4193 | |
4194 Qtext_part = intern ("text-part"); | |
4195 Qmodeline_part = intern ("modeline-part"); | |
4196 Qvscrollbar_part = intern ("vscrollbar-part"); | |
4197 Qvslider_part = intern ("vslider-part"); | |
4198 Qvthumbup_part = intern ("vthumbup-part"); | |
4199 Qvthumbdown_part = intern ("vthumbdown-part"); | |
4200 Qhscrollbar_part = intern ("hscrollbar-part"); | |
4201 Qhslider_part = intern ("hslider-part"); | |
4202 Qhthumbleft_part = intern ("hthumbleft-part"); | |
4203 Qhthumbright_part = intern ("hthumbright-part"); | |
4204 | |
4205 #ifdef HAVE_X11 | |
4206 XFASTINT (Vwindow_system_version) = 11; | |
4207 | |
4208 if (!EQ (xrm_string, Qnil)) | |
4209 { | |
4210 CHECK_STRING (xrm_string, 1); | |
4211 xrm_option = (unsigned char *) XSTRING (xrm_string); | |
4212 } | |
4213 else | |
4214 xrm_option = (unsigned char *) 0; | |
4215 xrdb = x_load_resources (x_current_display, xrm_option, EMACS_CLASS); | |
4216 x_current_display->db = xrdb; | |
4217 | |
4218 x_screen = DefaultScreenOfDisplay (x_current_display); | |
4219 | |
4220 x_screen_count = make_number (ScreenCount (x_current_display)); | |
4221 Vx_vendor = build_string (ServerVendor (x_current_display)); | |
4222 x_release = make_number (VendorRelease (x_current_display)); | |
4223 | |
4224 x_screen_height = make_number (HeightOfScreen (x_screen)); | |
4225 x_screen_height_mm = make_number (HeightMMOfScreen (x_screen)); | |
4226 x_screen_width = make_number (WidthOfScreen (x_screen)); | |
4227 x_screen_width_mm = make_number (WidthMMOfScreen (x_screen)); | |
4228 | |
4229 switch (DoesBackingStore (x_screen)) | |
4230 { | |
4231 case Always: | |
4232 Vx_backing_store = intern ("Always"); | |
4233 break; | |
4234 | |
4235 case WhenMapped: | |
4236 Vx_backing_store = intern ("WhenMapped"); | |
4237 break; | |
4238 | |
4239 case NotUseful: | |
4240 Vx_backing_store = intern ("NotUseful"); | |
4241 break; | |
4242 | |
4243 default: | |
4244 error ("Strange value for BackingStore."); | |
4245 break; | |
4246 } | |
4247 | |
4248 if (DoesSaveUnders (x_screen) == True) | |
4249 x_save_under = Qt; | |
4250 else | |
4251 x_save_under = Qnil; | |
4252 | |
4253 screen_visual = select_visual (x_screen, &n_planes); | |
4254 x_screen_planes = make_number (n_planes); | |
4255 Vx_screen_visual = intern (x_visual_strings [screen_visual->class]); | |
4256 | |
4257 /* X Atoms used by emacs. */ | |
4258 BLOCK_INPUT; | |
4259 Xatom_emacs_selection = XInternAtom (x_current_display, "_EMACS_SELECTION_", | |
4260 False); | |
4261 Xatom_clipboard = XInternAtom (x_current_display, "CLIPBOARD", | |
4262 False); | |
4263 Xatom_clipboard_selection = XInternAtom (x_current_display, "_EMACS_CLIPBOARD_", | |
4264 False); | |
4265 Xatom_wm_change_state = XInternAtom (x_current_display, "WM_CHANGE_STATE", | |
4266 False); | |
4267 Xatom_incremental = XInternAtom (x_current_display, "INCR", | |
4268 False); | |
4269 Xatom_multiple = XInternAtom (x_current_display, "MULTIPLE", | |
4270 False); | |
4271 Xatom_targets = XInternAtom (x_current_display, "TARGETS", | |
4272 False); | |
4273 Xatom_timestamp = XInternAtom (x_current_display, "TIMESTAMP", | |
4274 False); | |
4275 Xatom_delete = XInternAtom (x_current_display, "DELETE", | |
4276 False); | |
4277 Xatom_insert_selection = XInternAtom (x_current_display, "INSERT_SELECTION", | |
4278 False); | |
4279 Xatom_pair = XInternAtom (x_current_display, "XA_ATOM_PAIR", | |
4280 False); | |
4281 Xatom_insert_property = XInternAtom (x_current_display, "INSERT_PROPERTY", | |
4282 False); | |
4283 Xatom_text = XInternAtom (x_current_display, "TEXT", | |
4284 False); | |
4285 UNBLOCK_INPUT; | |
4286 #else /* not HAVE_X11 */ | |
4287 XFASTINT (Vwindow_system_version) = 10; | |
4288 #endif /* not HAVE_X11 */ | |
4289 return Qnil; | |
4290 } | |
4291 | |
4292 DEFUN ("x-close-current-connection", Fx_close_current_connection, | |
4293 Sx_close_current_connection, | |
4294 0, 0, 0, "Close the connection to the current X server.") | |
4295 () | |
4296 { | |
4297 #ifdef HAVE_X11 | |
4298 /* This is ONLY used when killing emacs; For switching displays | |
4299 we'll have to take care of setting CloseDownMode elsewhere. */ | |
4300 | |
4301 if (x_current_display) | |
4302 { | |
4303 BLOCK_INPUT; | |
4304 XSetCloseDownMode (x_current_display, DestroyAll); | |
4305 XCloseDisplay (x_current_display); | |
4306 } | |
4307 else | |
4308 fatal ("No current X display connection to close\n"); | |
4309 #endif | |
4310 return Qnil; | |
4311 } | |
4312 | |
4313 DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, | |
4314 1, 1, 0, "If ON is non-nil, report X errors as soon as the erring request is made.\n\ | |
4315 If ON is nil, allow buffering of requests.\n\ | |
4316 Turning on synchronization prohibits the Xlib routines from buffering\n\ | |
4317 requests and seriously degrades performance, but makes debugging much\n\ | |
4318 easier.") | |
4319 (on) | |
4320 Lisp_Object on; | |
4321 { | |
4322 XSynchronize (x_current_display, !EQ (on, Qnil)); | |
4323 | |
4324 return Qnil; | |
4325 } | |
4326 | |
4327 | |
4328 syms_of_xfns () | |
4329 { | |
4330 init_x_parm_symbols (); | |
4331 | |
4332 /* This is zero if not using X windows. */ | |
4333 x_current_display = 0; | |
4334 | |
4335 Qundefined_color = intern ("undefined-color"); | |
4336 Fput (Qundefined_color, Qerror_conditions, | |
4337 Fcons (Qundefined_color, Fcons (Qerror, Qnil))); | |
4338 Fput (Qundefined_color, Qerror_message, | |
4339 build_string ("Undefined color")); | |
4340 | |
398 | 4341 screen_class = make_pure_string (SCREEN_CLASS, sizeof (SCREEN_CLASS)-1); |
4342 | |
389 | 4343 DEFVAR_INT ("mouse-x-position", &x_mouse_x, |
4344 "The X coordinate of the mouse position, in characters."); | |
4345 x_mouse_x = Qnil; | |
4346 | |
4347 DEFVAR_INT ("mouse-y-position", &x_mouse_y, | |
4348 "The Y coordinate of the mouse position, in characters."); | |
4349 x_mouse_y = Qnil; | |
4350 | |
4351 DEFVAR_INT ("mouse-buffer-offset", &mouse_buffer_offset, | |
4352 "The buffer offset of the character under the pointer."); | |
4353 mouse_buffer_offset = Qnil; | |
4354 | |
4355 DEFVAR_LISP ("mouse-screen-part", &Vmouse_screen_part, | |
4356 "A symbol indicating the part of the screen the mouse is in."); | |
4357 Vmouse_screen_part = Qnil; | |
4358 | |
4359 DEFVAR_INT ("x-pointer-shape", &Vx_pointer_shape, | |
4360 "The shape of the pointer when over text."); | |
4361 Vx_pointer_shape = Qnil; | |
4362 | |
4363 DEFVAR_INT ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape, | |
4364 "The shape of the pointer when not over text."); | |
4365 Vx_nontext_pointer_shape = Qnil; | |
4366 | |
4367 DEFVAR_INT ("x-mode-pointer-shape", &Vx_mode_pointer_shape, | |
4368 "The shape of the pointer when not over text."); | |
4369 Vx_mode_pointer_shape = Qnil; | |
4370 | |
4371 DEFVAR_LISP ("x-bar-cursor", &Vbar_cursor, | |
4372 "*If non-nil, use a vertical bar cursor. Otherwise, use the traditional box."); | |
4373 Vbar_cursor = Qnil; | |
4374 | |
4375 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel, | |
4376 "A string indicating the foreground color of the cursor box."); | |
4377 Vx_cursor_fore_pixel = Qnil; | |
4378 | |
4379 DEFVAR_LISP ("mouse-grabbed", &Vmouse_depressed, | |
4380 "Non-nil if a mouse button is currently depressed."); | |
4381 Vmouse_depressed = Qnil; | |
4382 | |
4383 DEFVAR_INT ("x-screen-count", &x_screen_count, | |
4384 "The number of screens associated with the current display."); | |
4385 DEFVAR_INT ("x-release", &x_release, | |
4386 "The release number of the X server in use."); | |
4387 DEFVAR_LISP ("x-vendor", &Vx_vendor, | |
4388 "The vendor supporting the X server in use."); | |
4389 DEFVAR_INT ("x-screen-height", &x_screen_height, | |
4390 "The height of this X screen in pixels."); | |
4391 DEFVAR_INT ("x-screen-height-mm", &x_screen_height_mm, | |
4392 "The height of this X screen in millimeters."); | |
4393 DEFVAR_INT ("x-screen-width", &x_screen_width, | |
4394 "The width of this X screen in pixels."); | |
4395 DEFVAR_INT ("x-screen-width-mm", &x_screen_width_mm, | |
4396 "The width of this X screen in millimeters."); | |
4397 DEFVAR_LISP ("x-backing-store", &Vx_backing_store, | |
4398 "The backing store capability of this screen.\n\ | |
4399 Values can be the symbols Always, WhenMapped, or NotUseful."); | |
4400 DEFVAR_BOOL ("x-save-under", &x_save_under, | |
4401 "*Non-nil means this X screen supports the SaveUnder feature."); | |
4402 DEFVAR_INT ("x-screen-planes", &x_screen_planes, | |
4403 "The number of planes this monitor supports."); | |
4404 DEFVAR_LISP ("x-screen-visual", &Vx_screen_visual, | |
4405 "The default X visual for this X screen."); | |
4406 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager, | |
4407 "t if no X window manager is in use."); | |
4408 | |
4409 #ifdef HAVE_X11 | |
4410 defsubr (&Sx_get_resource); | |
4411 defsubr (&Sx_pixel_width); | |
4412 defsubr (&Sx_pixel_height); | |
4413 defsubr (&Sx_draw_rectangle); | |
4414 defsubr (&Sx_erase_rectangle); | |
4415 defsubr (&Sx_contour_region); | |
4416 defsubr (&Sx_uncontour_region); | |
4417 defsubr (&Sx_color_display_p); | |
4418 defsubr (&Sx_defined_color); | |
4419 #if 0 | |
4420 defsubr (&Sx_track_pointer); | |
4421 defsubr (&Sx_grab_pointer); | |
4422 defsubr (&Sx_ungrab_pointer); | |
436
6e0a136fca4f
*** empty log message ***
Michael I. Bushnell <mib@gnu.org>
parents:
398
diff
changeset
|
4423 #endif |
389 | 4424 #else |
4425 defsubr (&Sx_get_default); | |
4426 defsubr (&Sx_store_cut_buffer); | |
4427 defsubr (&Sx_get_cut_buffer); | |
4428 defsubr (&Sx_set_face); | |
4429 #endif | |
4430 defsubr (&Sx_geometry); | |
4431 defsubr (&Sx_create_screen); | |
4432 defsubr (&Sfocus_screen); | |
4433 defsubr (&Sunfocus_screen); | |
4434 defsubr (&Sx_horizontal_line); | |
4435 defsubr (&Sx_rebind_key); | |
4436 defsubr (&Sx_rebind_keys); | |
4437 defsubr (&Sx_open_connection); | |
4438 defsubr (&Sx_close_current_connection); | |
4439 defsubr (&Sx_synchronize); | |
4440 | |
4441 /* This was used in the old event interface which used a separate | |
4442 event queue.*/ | |
4443 #if 0 | |
4444 defsubr (&Sx_mouse_events); | |
4445 defsubr (&Sx_get_mouse_event); | |
4446 #endif | |
4447 } | |
4448 | |
4449 #endif /* HAVE_X_WINDOWS */ |