comparison src/xterm.c @ 9654:41681efe1086

Use FRAME_X_DISPLAY instead of x_current_display and XDISPLAY. (x_make_frame_visible, x_make_frame_invisible): Pass a frame ptr to x_sync. (x_term_init): Init all the components of dpyinfo. (x_display_info_for_display): New function. (x_*_mod_mask): Variables deleted. (x_x_to_emacs_modifiers, x_emacs_to_x_modifiers): New arg dpyinfo; all callers changed. Store the masks in that structure. (icon_bitmap): Variable deleted. (x_bitmap_icon): Use icon_bitmap_id in x_display_info. (icon_font_info): Variable deleted. (x_term_init): Set up `connection' field. (x_find_modifier_meanings): Arg is now struct x_display_info *. (x_term_init): Return an x_display_info *. Store all the data in it, including X atoms and xrdb. Put the x_display_info structure on x_display_list. Pass name as Lisp_Object. (the_x_screen): Variable moved here. (syms_of_xterm): Staticpro parts of the_x_screen. (windowinfo): Variable deleted. (Xatom_*): Variables deleted. (x_iconify_frame, XTread_socket): Get atoms from the x_display_info, (XTread_socket): Don't update Vmouse_depressed. (x_mouse_grabbed): Variable deleted. (note_mouse_highlight): Use grabbed field instead. (XTmouse_position, XTread_socket): Likewise. (x_calc_absolute_position, x_wm_set_size_hint): Get screen height, width from the x_display_info structure.
author Richard M. Stallman <rms@gnu.org>
date Sat, 22 Oct 1994 04:34:16 +0000
parents 3bf81e215f18
children 39b34bbe59c9
comparison
equal deleted inserted replaced
9653:cfc5e15e0baf 9654:41681efe1086
142 142
143 #if defined (SIGIO) && defined (FIONREAD) 143 #if defined (SIGIO) && defined (FIONREAD)
144 int BLOCK_INPUT_mask; 144 int BLOCK_INPUT_mask;
145 #endif /* ! defined (SIGIO) && defined (FIONREAD) */ 145 #endif /* ! defined (SIGIO) && defined (FIONREAD) */
146 146
147 /* The id of a bitmap used for icon windows, in frames
148 for which no specific bitmap was specified.
149 This is 0 if we have not yet had a need to create the bitmap. */
150
151 static int icon_bitmap;
152
153 /* Font used for text icons. */
154
155 static FONT_TYPE *icon_font_info;
156
157 /* Stuff for dealing with the main icon title. */ 147 /* Stuff for dealing with the main icon title. */
158 148
159 extern Lisp_Object Vcommand_line_args, Vsystem_name; 149 extern Lisp_Object Vcommand_line_args, Vsystem_name;
160 char *x_id_name; 150 char *x_id_name;
161 151
162 /* Initial values of argv and argc. */ 152 /* Initial values of argv and argc. */
163 extern char **initial_argv; 153 extern char **initial_argv;
164 extern int initial_argc; 154 extern int initial_argc;
165 155
166 /* This is the X connection that we are using. */ 156 /* For now, we have just one x_display structure since we only support
167 157 one X display. */
168 Display *x_current_display; 158 static struct x_display_info the_x_screen;
159
160 /* This is a chain of structures for all the X displays currently in use. */
161 struct x_display_info *x_display_list;
169 162
170 /* The cursor to use for vertical scroll bars on x_current_display. */ 163 /* The cursor to use for vertical scroll bars on x_current_display. */
171 static Cursor x_vertical_scroll_bar_cursor; 164 static Cursor x_vertical_scroll_bar_cursor;
172 165
173 /* Frame being updated by update_frame. This is declared in term.c. 166 /* Frame being updated by update_frame. This is declared in term.c.
253 246
254 If the last X motion event didn't occur in a scroll bar, we set this 247 If the last X motion event didn't occur in a scroll bar, we set this
255 to Qnil, to tell XTmouse_position to return an ordinary motion event. */ 248 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
256 static Lisp_Object last_mouse_scroll_bar; 249 static Lisp_Object last_mouse_scroll_bar;
257 250
258 /* Record which buttons are currently pressed. */
259 unsigned int x_mouse_grabbed;
260
261 /* This is a hack. We would really prefer that XTmouse_position would 251 /* This is a hack. We would really prefer that XTmouse_position would
262 return the time associated with the position it returns, but there 252 return the time associated with the position it returns, but there
263 doesn't seem to be any way to wrest the timestamp from the server 253 doesn't seem to be any way to wrest the timestamp from the server
264 along with the position query. So, we just keep track of the time 254 along with the position query. So, we just keep track of the time
265 of the last movement we received, and return that in hopes that 255 of the last movement we received, and return that in hopes that
293 static int volatile input_signal_count; 283 static int volatile input_signal_count;
294 #else 284 #else
295 static int input_signal_count; 285 static int input_signal_count;
296 #endif 286 #endif
297 287
298 /* `t' if a mouse button is depressed. */
299
300 extern Lisp_Object Vmouse_depressed;
301
302 /* Tells if a window manager is present or not. */ 288 /* Tells if a window manager is present or not. */
303 289
304 extern Lisp_Object Vx_no_window_manager; 290 extern Lisp_Object Vx_no_window_manager;
305 291
306 /* Timestamp that we requested selection data was made. */ 292 /* Timestamp that we requested selection data was made. */
314 300
315 extern Lisp_Object Qface, Qmouse_face; 301 extern Lisp_Object Qface, Qmouse_face;
316 302
317 static int x_noop_count; 303 static int x_noop_count;
318 304
319
320 /* From time to time we get info on an Emacs window, here. */
321
322 static WINDOWINFO_TYPE windowinfo;
323
324 extern int errno; 305 extern int errno;
325 306
326 /* A mask of extra modifier bits to put into every keyboard char. */ 307 /* A mask of extra modifier bits to put into every keyboard char. */
327 extern int extra_keyboard_modifiers; 308 extern int extra_keyboard_modifiers;
328 309
329 extern Display *XOpenDisplay (); 310 extern Display *XOpenDisplay ();
330 extern Window XCreateWindow (); 311 extern Window XCreateWindow ();
331 312
332 extern Cursor XCreateCursor (); 313 extern Cursor XCreateCursor ();
333 extern FONT_TYPE *XOpenFont (); 314 extern XFontStruct *XOpenFont ();
315 extern XrmDatabase x_load_resources ();
334 316
335 static void flashback (); 317 static void flashback ();
336 static void redraw_previous_char (); 318 static void redraw_previous_char ();
337 static void redraw_following_char (); 319 static void redraw_following_char ();
338 static unsigned int x_x_to_emacs_modifiers (); 320 static unsigned int x_x_to_emacs_modifiers ();
344 static void do_line_dance (); 326 static void do_line_dance ();
345 327
346 void dumpborder (); 328 void dumpborder ();
347 static int XTcursor_to (); 329 static int XTcursor_to ();
348 static int XTclear_end_of_line (); 330 static int XTclear_end_of_line ();
349 331
332 /* Return the struct x_display_info corresponding to DPY. */
333
334 struct x_display_info *
335 x_display_info_for_display (dpy)
336 Display *dpy;
337 {
338 struct x_display_info *dpyinfo;
339
340 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
341 if (dpyinfo->display == dpy)
342 return dpyinfo;
343
344 return 0;
345 }
350 346
351 /* Starting and ending updates. 347 /* Starting and ending updates.
352 348
353 These hooks are called by update_frame at the beginning and end 349 These hooks are called by update_frame at the beginning and end
354 of a frame update. We record in `updating_frame' the identity 350 of a frame update. We record in `updating_frame' the identity
430 for that case. window_end_valid isn't set up yet. */ 426 for that case. window_end_valid isn't set up yet. */
431 if (f == mouse_face_mouse_frame) 427 if (f == mouse_face_mouse_frame)
432 note_mouse_highlight (f, mouse_face_mouse_x, mouse_face_mouse_y); 428 note_mouse_highlight (f, mouse_face_mouse_x, mouse_face_mouse_y);
433 #endif 429 #endif
434 430
435 XFlushQueue (); 431 XFlush (FRAME_X_DISPLAY (f));
436 UNBLOCK_INPUT; 432 UNBLOCK_INPUT;
437 } 433 }
438 434
439 /* This is called after a redisplay on frame F. */ 435 /* This is called after a redisplay on frame F. */
440 436
507 503
508 if (updating_frame == 0) 504 if (updating_frame == 0)
509 { 505 {
510 BLOCK_INPUT; 506 BLOCK_INPUT;
511 x_display_cursor (selected_frame, 1); 507 x_display_cursor (selected_frame, 1);
512 XFlushQueue (); 508 XFlush (FRAME_X_DISPLAY (selected_frame));
513 UNBLOCK_INPUT; 509 UNBLOCK_INPUT;
514 } 510 }
515 } 511 }
516 512
517 /* Display a sequence of N glyphs found at GP. 513 /* Display a sequence of N glyphs found at GP.
579 575
580 /* Now output this run of chars, with the font and pixel values 576 /* Now output this run of chars, with the font and pixel values
581 determined by the face code CF. */ 577 determined by the face code CF. */
582 { 578 {
583 struct face *face = FRAME_DEFAULT_FACE (f); 579 struct face *face = FRAME_DEFAULT_FACE (f);
584 FONT_TYPE *font = FACE_FONT (face); 580 XFontStruct *font = FACE_FONT (face);
585 GC gc = FACE_GC (face); 581 GC gc = FACE_GC (face);
586 int stippled = 0; 582 int stippled = 0;
587 583
588 /* HL = 3 means use a mouse face previously chosen. */ 584 /* HL = 3 means use a mouse face previously chosen. */
589 if (hl == 3) 585 if (hl == 3)
661 } 657 }
662 xgcv.font = face->font->fid; 658 xgcv.font = face->font->fid;
663 xgcv.graphics_exposures = 0; 659 xgcv.graphics_exposures = 0;
664 mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures; 660 mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;
665 if (scratch_cursor_gc) 661 if (scratch_cursor_gc)
666 XChangeGC (x_current_display, scratch_cursor_gc, mask, &xgcv); 662 XChangeGC (FRAME_X_DISPLAY (f), scratch_cursor_gc, mask, &xgcv);
667 else 663 else
668 scratch_cursor_gc 664 scratch_cursor_gc
669 = XCreateGC (x_current_display, window, mask, &xgcv); 665 = XCreateGC (FRAME_X_DISPLAY (f), window, mask, &xgcv);
670 gc = scratch_cursor_gc; 666 gc = scratch_cursor_gc;
671 #if 0 667 #if 0
672 /* If this code is restored, it must also reset to the default stipple 668 /* If this code is restored, it must also reset to the default stipple
673 if necessary. */ 669 if necessary. */
674 if (face->stipple && face->stipple != FACE_DEFAULT) 670 if (face->stipple && face->stipple != FACE_DEFAULT)
675 XSetStipple (x_current_display, gc, face->stipple); 671 XSetStipple (FRAME_X_DISPLAY (f), gc, face->stipple);
676 #endif 672 #endif
677 } 673 }
678 } 674 }
679 675
680 if ((int) font == FACE_DEFAULT) 676 if ((int) font == FACE_DEFAULT)
681 font = f->display.x->font; 677 font = f->display.x->font;
682 678
683 if (just_foreground) 679 if (just_foreground)
684 XDrawString (x_current_display, window, gc, 680 XDrawString (FRAME_X_DISPLAY (f), window, gc,
685 left, top + FONT_BASE (font), buf, len); 681 left, top + FONT_BASE (font), buf, len);
686 else 682 else
687 { 683 {
688 if (stippled) 684 if (stippled)
689 { 685 {
690 /* Turn stipple on. */ 686 /* Turn stipple on. */
691 XSetFillStyle (FRAME_X_DISPLAY (f), gc, FillOpaqueStippled); 687 XSetFillStyle (FRAME_X_DISPLAY (f), gc, FillOpaqueStippled);
692 688
693 /* Draw stipple on background. */ 689 /* Draw stipple on background. */
694 XFillRectangle (x_current_display, window, gc, 690 XFillRectangle (FRAME_X_DISPLAY (f), window, gc,
695 left, top, 691 left, top,
696 FONT_WIDTH (font) * len, 692 FONT_WIDTH (font) * len,
697 FONT_HEIGHT (font)); 693 FONT_HEIGHT (font));
698 694
699 /* Turn stipple off. */ 695 /* Turn stipple off. */
700 XSetFillStyle (FRAME_X_DISPLAY (f), gc, FillSolid); 696 XSetFillStyle (FRAME_X_DISPLAY (f), gc, FillSolid);
701 697
702 /* Draw the text, solidly, onto the stipple pattern. */ 698 /* Draw the text, solidly, onto the stipple pattern. */
703 XDrawString (x_current_display, window, gc, 699 XDrawString (FRAME_X_DISPLAY (f), window, gc,
704 left, top + FONT_BASE (font), buf, len); 700 left, top + FONT_BASE (font), buf, len);
705 } 701 }
706 else 702 else
707 XDrawImageString (x_current_display, window, gc, 703 XDrawImageString (FRAME_X_DISPLAY (f), window, gc,
708 left, top + FONT_BASE (font), buf, len); 704 left, top + FONT_BASE (font), buf, len);
709 705
710 /* Clear the rest of the line's height. */ 706 /* Clear the rest of the line's height. */
711 if (f->display.x->line_height != FONT_HEIGHT (font)) 707 if (f->display.x->line_height != FONT_HEIGHT (font))
712 XClearArea (x_current_display, window, left, 708 XClearArea (FRAME_X_DISPLAY (f), window, left,
713 top + FONT_HEIGHT (font), 709 top + FONT_HEIGHT (font),
714 FONT_WIDTH (font) * len, 710 FONT_WIDTH (font) * len,
715 /* This is how many pixels of height 711 /* This is how many pixels of height
716 we have to clear. */ 712 we have to clear. */
717 f->display.x->line_height - FONT_HEIGHT (font), 713 f->display.x->line_height - FONT_HEIGHT (font),
739 735
740 if (font->descent <= underline_position) 736 if (font->descent <= underline_position)
741 underline_position = font->descent - 1; 737 underline_position = font->descent - 1;
742 738
743 if (face->underline) 739 if (face->underline)
744 XFillRectangle (x_current_display, FRAME_X_WINDOW (f), 740 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
745 FACE_GC (face), 741 FACE_GC (face),
746 left, (top 742 left, (top
747 + FONT_BASE (font) 743 + FONT_BASE (font)
748 + underline_position), 744 + underline_position),
749 len * FONT_WIDTH (font), 1); 745 len * FONT_WIDTH (font), 1);
763 struct frame *f; 759 struct frame *f;
764 int left, top; 760 int left, top;
765 register GLYPH *gp; /* Points to first GLYPH. */ 761 register GLYPH *gp; /* Points to first GLYPH. */
766 register int n; /* Number of glyphs to display. */ 762 register int n; /* Number of glyphs to display. */
767 int hl; 763 int hl;
768 FONT_TYPE *font; 764 XFontStruct *font;
769 { 765 {
770 register int len; 766 register int len;
771 Window window = FRAME_X_WINDOW (f); 767 Window window = FRAME_X_WINDOW (f);
772 GC drawing_gc = (hl == 2 ? f->display.x->cursor_gc 768 GC drawing_gc = (hl == 2 ? f->display.x->cursor_gc
773 : (hl ? f->display.x->reverse_gc 769 : (hl ? f->display.x->reverse_gc
774 : f->display.x->normal_gc)); 770 : f->display.x->normal_gc));
775 771
776 if (sizeof (GLYPH) == sizeof (XChar2b)) 772 if (sizeof (GLYPH) == sizeof (XChar2b))
777 XDrawImageString16 (x_current_display, window, drawing_gc, 773 XDrawImageString16 (FRAME_X_DISPLAY (f), window, drawing_gc,
778 left, top + FONT_BASE (font), (XChar2b *) gp, n); 774 left, top + FONT_BASE (font), (XChar2b *) gp, n);
779 else if (sizeof (GLYPH) == sizeof (unsigned char)) 775 else if (sizeof (GLYPH) == sizeof (unsigned char))
780 XDrawImageString (x_current_display, window, drawing_gc, 776 XDrawImageString (FRAME_X_DISPLAY (f), window, drawing_gc,
781 left, top + FONT_BASE (font), (char *) gp, n); 777 left, top + FONT_BASE (font), (char *) gp, n);
782 else 778 else
783 /* What size of glyph ARE you using? And does X have a function to 779 /* What size of glyph ARE you using? And does X have a function to
784 draw them? */ 780 draw them? */
785 abort (); 781 abort ();
867 if (curs_y == f->phys_cursor_y 863 if (curs_y == f->phys_cursor_y
868 && curs_x <= f->phys_cursor_x 864 && curs_x <= f->phys_cursor_x
869 && f->phys_cursor_x < first_unused) 865 && f->phys_cursor_x < first_unused)
870 f->phys_cursor_x = -1; 866 f->phys_cursor_x = -1;
871 867
872 XClearArea (x_current_display, FRAME_X_WINDOW (f), 868 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
873 CHAR_TO_PIXEL_COL (f, curs_x), 869 CHAR_TO_PIXEL_COL (f, curs_x),
874 CHAR_TO_PIXEL_ROW (f, curs_y), 870 CHAR_TO_PIXEL_ROW (f, curs_y),
875 FONT_WIDTH (f->display.x->font) * (first_unused - curs_x), 871 FONT_WIDTH (f->display.x->font) * (first_unused - curs_x),
876 f->display.x->line_height, False); 872 f->display.x->line_height, False);
877 #if 0 873 #if 0
894 curs_x = 0; /* Nominal cursor position is top left. */ 890 curs_x = 0; /* Nominal cursor position is top left. */
895 curs_y = 0; 891 curs_y = 0;
896 892
897 BLOCK_INPUT; 893 BLOCK_INPUT;
898 894
899 XClear (FRAME_X_WINDOW (f)); 895 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
900 896
901 /* We have to clear the scroll bars, too. If we have changed 897 /* We have to clear the scroll bars, too. If we have changed
902 colors or something like that, then they should be notified. */ 898 colors or something like that, then they should be notified. */
903 x_scroll_bar_clear (f); 899 x_scroll_bar_clear (f);
904 900
905 XFlushQueue (); 901 XFlush (FRAME_X_DISPLAY (f));
906 UNBLOCK_INPUT; 902 UNBLOCK_INPUT;
907 } 903 }
908 904
909 #if 0 905 #if 0
910 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't 906 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
934 if (x > 0) 930 if (x > 0)
935 { 931 {
936 int start_x = x - 2; 932 int start_x = x - 2;
937 if (start_x < 0) 933 if (start_x < 0)
938 start_x = 0; 934 start_x = 0;
939 XClearArea (x_current_display, FRAME_X_WINDOW (f), 935 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
940 CHAR_TO_PIXEL_COL (f, x - 1), 936 CHAR_TO_PIXEL_COL (f, x - 1),
941 CHAR_TO_PIXEL_ROW (f, y), 937 CHAR_TO_PIXEL_ROW (f, y),
942 FONT_WIDTH (f->display.x->font), 938 FONT_WIDTH (f->display.x->font),
943 f->display.x->line_height, False); 939 f->display.x->line_height, False);
944 940
970 && FRAME_CURRENT_GLYPHS (f)->glyphs[y][x] != SPACEGLYPH) 966 && FRAME_CURRENT_GLYPHS (f)->glyphs[y][x] != SPACEGLYPH)
971 { 967 {
972 int end_x = x + 2; 968 int end_x = x + 2;
973 if (end_x > limit) 969 if (end_x > limit)
974 end_x = limit; 970 end_x = limit;
975 XClearArea (x_current_display, FRAME_X_WINDOW (f), 971 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
976 CHAR_TO_PIXEL_COL (f, x), 972 CHAR_TO_PIXEL_COL (f, x),
977 CHAR_TO_PIXEL_ROW (f, y), 973 CHAR_TO_PIXEL_ROW (f, y),
978 FONT_WIDTH (f->display.x->font), 974 FONT_WIDTH (f->display.x->font),
979 f->display.x->line_height, False); 975 f->display.x->line_height, False);
980 976
1132 1128
1133 values.function = GXxor; 1129 values.function = GXxor;
1134 values.foreground = (f->display.x->foreground_pixel 1130 values.foreground = (f->display.x->foreground_pixel
1135 ^ f->display.x->background_pixel); 1131 ^ f->display.x->background_pixel);
1136 1132
1137 gc = XCreateGC (x_current_display, FRAME_X_WINDOW (f), 1133 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1138 GCFunction | GCForeground, &values); 1134 GCFunction | GCForeground, &values);
1139 } 1135 }
1140 1136
1141 { 1137 {
1142 int width = PIXEL_WIDTH (f); 1138 int width = PIXEL_WIDTH (f);
1143 int height = PIXEL_HEIGHT (f); 1139 int height = PIXEL_HEIGHT (f);
1144 1140
1145 XFillRectangle (x_current_display, FRAME_X_WINDOW (f), gc, 1141 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1146 width/4, height/4, width/2, height/2); 1142 width/4, height/4, width/2, height/2);
1147 XFlush (x_current_display); 1143 XFlush (FRAME_X_DISPLAY (f));
1148 1144
1149 { 1145 {
1150 struct timeval wakeup, now; 1146 struct timeval wakeup, now;
1151 1147
1152 EMACS_GET_TIME (wakeup); 1148 EMACS_GET_TIME (wakeup);
1171 /* Try to wait that long--but we might wake up sooner. */ 1167 /* Try to wait that long--but we might wake up sooner. */
1172 select (0, 0, 0, 0, &timeout); 1168 select (0, 0, 0, 0, &timeout);
1173 } 1169 }
1174 } 1170 }
1175 1171
1176 XFillRectangle (x_current_display, FRAME_X_WINDOW (f), gc, 1172 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1177 width/4, height/4, width/2, height/2); 1173 width/4, height/4, width/2, height/2);
1178 XFreeGC (x_current_display, gc); 1174 XFreeGC (FRAME_X_DISPLAY (f), gc);
1179 XFlush (x_current_display); 1175 XFlush (FRAME_X_DISPLAY (f));
1180 } 1176 }
1181 } 1177 }
1182 1178
1183 UNBLOCK_INPUT; 1179 UNBLOCK_INPUT;
1184 } 1180 }
1186 #endif 1182 #endif
1187 1183
1188 1184
1189 /* Make audible bell. */ 1185 /* Make audible bell. */
1190 1186
1191 #define XRINGBELL XBell (x_current_display, 0) 1187 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1192 1188
1193 XTring_bell () 1189 XTring_bell ()
1194 { 1190 {
1195 if (x_current_display == 0) 1191 if (FRAME_X_DISPLAY (selected_frame) == 0)
1196 return; 1192 return;
1197 1193
1198 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) 1194 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1199 if (visible_bell) 1195 if (visible_bell)
1200 XTflash (selected_frame); 1196 XTflash (selected_frame);
1201 else 1197 else
1202 #endif 1198 #endif
1203 { 1199 {
1204 BLOCK_INPUT; 1200 BLOCK_INPUT;
1205 XRINGBELL; 1201 XRINGBELL;
1206 XFlushQueue (); 1202 XFlush (FRAME_X_DISPLAY (selected_frame));
1207 UNBLOCK_INPUT; 1203 UNBLOCK_INPUT;
1208 } 1204 }
1209 } 1205 }
1210 1206
1211 /* Insert and delete character. 1207 /* Insert and delete character.
1328 if (line_dance[i] != -1 && (distance = line_dance[i]-i) > 0) 1324 if (line_dance[i] != -1 && (distance = line_dance[i]-i) > 0)
1329 { 1325 {
1330 for (j = i; (j < ht && line_dance[j] != -1 1326 for (j = i; (j < ht && line_dance[j] != -1
1331 && line_dance[j]-j == distance); ++j); 1327 && line_dance[j]-j == distance); ++j);
1332 /* Copy [i,j) upward from [i+distance,j+distance) */ 1328 /* Copy [i,j) upward from [i+distance,j+distance) */
1333 XCopyArea (x_current_display, FRAME_X_WINDOW (f), 1329 XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1334 FRAME_X_WINDOW (f), f->display.x->normal_gc, 1330 FRAME_X_WINDOW (f), f->display.x->normal_gc,
1335 intborder, CHAR_TO_PIXEL_ROW (f, i+distance), 1331 intborder, CHAR_TO_PIXEL_ROW (f, i+distance),
1336 f->width * FONT_WIDTH (f->display.x->font), 1332 f->width * FONT_WIDTH (f->display.x->font),
1337 (j-i) * f->display.x->line_height, 1333 (j-i) * f->display.x->line_height,
1338 intborder, CHAR_TO_PIXEL_ROW (f, i)); 1334 intborder, CHAR_TO_PIXEL_ROW (f, i));
1343 if (line_dance[i] != -1 && (distance = line_dance[i]-i) < 0) 1339 if (line_dance[i] != -1 && (distance = line_dance[i]-i) < 0)
1344 { 1340 {
1345 for (j = i; (--j >= 0 && line_dance[j] != -1 1341 for (j = i; (--j >= 0 && line_dance[j] != -1
1346 && line_dance[j]-j == distance);); 1342 && line_dance[j]-j == distance););
1347 /* Copy (j,i] downward from (j+distance, i+distance] */ 1343 /* Copy (j,i] downward from (j+distance, i+distance] */
1348 XCopyArea (x_current_display, FRAME_X_WINDOW (f), 1344 XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1349 FRAME_X_WINDOW (f), f->display.x->normal_gc, 1345 FRAME_X_WINDOW (f), f->display.x->normal_gc,
1350 intborder, CHAR_TO_PIXEL_ROW (f, j+1+distance), 1346 intborder, CHAR_TO_PIXEL_ROW (f, j+1+distance),
1351 f->width * FONT_WIDTH (f->display.x->font), 1347 f->width * FONT_WIDTH (f->display.x->font),
1352 (i-j) * f->display.x->line_height, 1348 (i-j) * f->display.x->line_height,
1353 intborder, CHAR_TO_PIXEL_ROW (f, j+1)); 1349 intborder, CHAR_TO_PIXEL_ROW (f, j+1));
1357 for (i = 0; i < ht; ++i) 1353 for (i = 0; i < ht; ++i)
1358 if (line_dance[i] == -1) 1354 if (line_dance[i] == -1)
1359 { 1355 {
1360 for (j = i; j < ht && line_dance[j] == -1; ++j); 1356 for (j = i; j < ht && line_dance[j] == -1; ++j);
1361 /* Clear [i,j) */ 1357 /* Clear [i,j) */
1362 XClearArea (x_current_display, FRAME_X_WINDOW (f), 1358 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1363 intborder, CHAR_TO_PIXEL_ROW (f, i), 1359 intborder, CHAR_TO_PIXEL_ROW (f, i),
1364 f->width * FONT_WIDTH (f->display.x->font), 1360 f->width * FONT_WIDTH (f->display.x->font),
1365 (j-i) * f->display.x->line_height, False); 1361 (j-i) * f->display.x->line_height, False);
1366 i = j-1; 1362 i = j-1;
1367 } 1363 }
1451 if (cursor_cleared) 1447 if (cursor_cleared)
1452 x_display_cursor (f, 1); 1448 x_display_cursor (f, 1);
1453 } 1449 }
1454 1450
1455 static void 1451 static void
1456 frame_highlight (frame) 1452 frame_highlight (f)
1457 struct frame *frame; 1453 struct frame *f;
1458 { 1454 {
1459 /* We used to only do this if Vx_no_window_manager was non-nil, but 1455 /* We used to only do this if Vx_no_window_manager was non-nil, but
1460 the ICCCM (section 4.1.6) says that the window's border pixmap 1456 the ICCCM (section 4.1.6) says that the window's border pixmap
1461 and border pixel are window attributes which are "private to the 1457 and border pixel are window attributes which are "private to the
1462 client", so we can always change it to whatever we want. */ 1458 client", so we can always change it to whatever we want. */
1463 BLOCK_INPUT; 1459 BLOCK_INPUT;
1464 XSetWindowBorder (x_current_display, FRAME_X_WINDOW (frame), 1460 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1465 frame->display.x->border_pixel); 1461 f->display.x->border_pixel);
1466 UNBLOCK_INPUT; 1462 UNBLOCK_INPUT;
1467 x_display_cursor (frame, 1); 1463 x_display_cursor (f, 1);
1468 } 1464 }
1469 1465
1470 static void 1466 static void
1471 frame_unhighlight (frame) 1467 frame_unhighlight (f)
1472 struct frame *frame; 1468 struct frame *f;
1473 { 1469 {
1474 /* We used to only do this if Vx_no_window_manager was non-nil, but 1470 /* We used to only do this if Vx_no_window_manager was non-nil, but
1475 the ICCCM (section 4.1.6) says that the window's border pixmap 1471 the ICCCM (section 4.1.6) says that the window's border pixmap
1476 and border pixel are window attributes which are "private to the 1472 and border pixel are window attributes which are "private to the
1477 client", so we can always change it to whatever we want. */ 1473 client", so we can always change it to whatever we want. */
1478 BLOCK_INPUT; 1474 BLOCK_INPUT;
1479 XSetWindowBorderPixmap (x_current_display, FRAME_X_WINDOW (frame), 1475 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1480 frame->display.x->border_tile); 1476 f->display.x->border_tile);
1481 UNBLOCK_INPUT; 1477 UNBLOCK_INPUT;
1482 x_display_cursor (frame, 1); 1478 x_display_cursor (f, 1);
1483 } 1479 }
1484 1480
1485 static void XTframe_rehighlight (); 1481 static void XTframe_rehighlight ();
1486 1482
1487 /* The focus has changed. Update the frames as necessary to reflect 1483 /* The focus has changed. Update the frames as necessary to reflect
1556 } 1552 }
1557 } 1553 }
1558 1554
1559 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */ 1555 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1560 1556
1561 /* Which modifier keys are on which modifier bits?
1562
1563 With each keystroke, X returns eight bits indicating which modifier
1564 keys were held down when the key was pressed. The interpretation
1565 of the top five modifier bits depends on what keys are attached
1566 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
1567 is the meta bit.
1568
1569 x_meta_mod_mask is a mask containing the bits used for the meta key.
1570 It may have more than one bit set, if more than one modifier bit
1571 has meta keys on it. Basically, if EVENT is a KeyPress event,
1572 the meta key is pressed if (EVENT.state & x_meta_mod_mask) != 0.
1573
1574 x_shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
1575 lock modifier bit, or zero otherwise. Non-alphabetic keys should
1576 only be affected by the lock modifier bit if XK_Shift_Lock is in
1577 use; XK_Caps_Lock should only affect alphabetic keys. With this
1578 arrangement, the lock modifier should shift the character if
1579 (EVENT.state & x_shift_lock_mask) != 0. */
1580 static int x_meta_mod_mask, x_shift_lock_mask;
1581
1582 /* These are like x_meta_mod_mask, but for different modifiers. */
1583 static int x_alt_mod_mask, x_super_mod_mask, x_hyper_mod_mask;
1584
1585 /* Initialize mode_switch_bit and modifier_meaning. */ 1557 /* Initialize mode_switch_bit and modifier_meaning. */
1586 static void 1558 static void
1587 x_find_modifier_meanings () 1559 x_find_modifier_meanings (dpyinfo)
1560 struct x_display_info *dpyinfo;
1588 { 1561 {
1589 int min_code, max_code; 1562 int min_code, max_code;
1590 KeySym *syms; 1563 KeySym *syms;
1591 int syms_per_code; 1564 int syms_per_code;
1592 XModifierKeymap *mods; 1565 XModifierKeymap *mods;
1593 1566
1594 x_meta_mod_mask = 0; 1567 dpyinfo->meta_mod_mask = 0;
1595 x_shift_lock_mask = 0; 1568 dpyinfo->shift_lock_mask = 0;
1596 x_alt_mod_mask = 0; 1569 dpyinfo->alt_mod_mask = 0;
1597 x_super_mod_mask = 0; 1570 dpyinfo->super_mod_mask = 0;
1598 x_hyper_mod_mask = 0; 1571 dpyinfo->hyper_mod_mask = 0;
1599 1572
1600 #ifdef HAVE_X11R4 1573 #ifdef HAVE_X11R4
1601 XDisplayKeycodes (x_current_display, &min_code, &max_code); 1574 XDisplayKeycodes (dpyinfo->display, &min_code, &max_code);
1602 #else 1575 #else
1603 min_code = x_current_display->min_keycode; 1576 min_code = display->min_keycode;
1604 max_code = x_current_display->max_keycode; 1577 max_code = display->max_keycode;
1605 #endif 1578 #endif
1606 1579
1607 syms = XGetKeyboardMapping (x_current_display, 1580 syms = XGetKeyboardMapping (dpyinfo->display,
1608 min_code, max_code - min_code + 1, 1581 min_code, max_code - min_code + 1,
1609 &syms_per_code); 1582 &syms_per_code);
1610 mods = XGetModifierMapping (x_current_display); 1583 mods = XGetModifierMapping (dpyinfo->display);
1611 1584
1612 /* Scan the modifier table to see which modifier bits the Meta and 1585 /* Scan the modifier table to see which modifier bits the Meta and
1613 Alt keysyms are on. */ 1586 Alt keysyms are on. */
1614 { 1587 {
1615 int row, col; /* The row and column in the modifier table. */ 1588 int row, col; /* The row and column in the modifier table. */
1634 1607
1635 switch (sym) 1608 switch (sym)
1636 { 1609 {
1637 case XK_Meta_L: 1610 case XK_Meta_L:
1638 case XK_Meta_R: 1611 case XK_Meta_R:
1639 x_meta_mod_mask |= (1 << row); 1612 dpyinfo->meta_mod_mask |= (1 << row);
1640 break; 1613 break;
1641 1614
1642 case XK_Alt_L: 1615 case XK_Alt_L:
1643 case XK_Alt_R: 1616 case XK_Alt_R:
1644 x_alt_mod_mask |= (1 << row); 1617 dpyinfo->alt_mod_mask |= (1 << row);
1645 break; 1618 break;
1646 1619
1647 case XK_Hyper_L: 1620 case XK_Hyper_L:
1648 case XK_Hyper_R: 1621 case XK_Hyper_R:
1649 x_hyper_mod_mask |= (1 << row); 1622 dpyinfo->hyper_mod_mask |= (1 << row);
1650 break; 1623 break;
1651 1624
1652 case XK_Super_L: 1625 case XK_Super_L:
1653 case XK_Super_R: 1626 case XK_Super_R:
1654 x_super_mod_mask |= (1 << row); 1627 dpyinfo->super_mod_mask |= (1 << row);
1655 break; 1628 break;
1656 1629
1657 case XK_Shift_Lock: 1630 case XK_Shift_Lock:
1658 /* Ignore this if it's not on the lock modifier. */ 1631 /* Ignore this if it's not on the lock modifier. */
1659 if ((1 << row) == LockMask) 1632 if ((1 << row) == LockMask)
1660 x_shift_lock_mask = LockMask; 1633 dpyinfo->shift_lock_mask = LockMask;
1661 break; 1634 break;
1662 } 1635 }
1663 } 1636 }
1664 } 1637 }
1665 } 1638 }
1666 } 1639 }
1667 1640
1668 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */ 1641 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
1669 if (! x_meta_mod_mask) 1642 if (! dpyinfo->meta_mod_mask)
1670 { 1643 {
1671 x_meta_mod_mask = x_alt_mod_mask; 1644 dpyinfo->meta_mod_mask = dpyinfo->alt_mod_mask;
1672 x_alt_mod_mask = 0; 1645 dpyinfo->alt_mod_mask = 0;
1673 } 1646 }
1674 1647
1675 /* If some keys are both alt and meta, 1648 /* If some keys are both alt and meta,
1676 make them just meta, not alt. */ 1649 make them just meta, not alt. */
1677 if (x_alt_mod_mask & x_meta_mod_mask) 1650 if (dpyinfo->alt_mod_mask & dpyinfo->meta_mod_mask)
1678 { 1651 {
1679 x_alt_mod_mask &= ~x_meta_mod_mask; 1652 dpyinfo->alt_mod_mask &= ~dpyinfo->meta_mod_mask;
1680 } 1653 }
1681 1654
1682 XFree ((char *) syms); 1655 XFree ((char *) syms);
1683 XFreeModifiermap (mods); 1656 XFreeModifiermap (mods);
1684 } 1657 }
1685 1658
1686 /* Convert between the modifier bits X uses and the modifier bits 1659 /* Convert between the modifier bits X uses and the modifier bits
1687 Emacs uses. */ 1660 Emacs uses. */
1688 static unsigned int 1661 static unsigned int
1689 x_x_to_emacs_modifiers (state) 1662 x_x_to_emacs_modifiers (dpyinfo, state)
1663 struct x_display_info *dpyinfo;
1690 unsigned int state; 1664 unsigned int state;
1691 { 1665 {
1692 return ( ((state & (ShiftMask | x_shift_lock_mask)) ? shift_modifier : 0) 1666 return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0)
1693 | ((state & ControlMask) ? ctrl_modifier : 0) 1667 | ((state & ControlMask) ? ctrl_modifier : 0)
1694 | ((state & x_meta_mod_mask) ? meta_modifier : 0) 1668 | ((state & dpyinfo->meta_mod_mask) ? meta_modifier : 0)
1695 | ((state & x_alt_mod_mask) ? alt_modifier : 0) 1669 | ((state & dpyinfo->alt_mod_mask) ? alt_modifier : 0)
1696 | ((state & x_super_mod_mask) ? super_modifier : 0) 1670 | ((state & dpyinfo->super_mod_mask) ? super_modifier : 0)
1697 | ((state & x_hyper_mod_mask) ? hyper_modifier : 0)); 1671 | ((state & dpyinfo->hyper_mod_mask) ? hyper_modifier : 0));
1698 } 1672 }
1699 1673
1700 static unsigned int 1674 static unsigned int
1701 x_emacs_to_x_modifiers (state) 1675 x_emacs_to_x_modifiers (dpyinfo, state)
1676 struct x_display_info *dpyinfo;
1702 unsigned int state; 1677 unsigned int state;
1703 { 1678 {
1704 return ( ((state & alt_modifier) ? x_alt_mod_mask : 0) 1679 return ( ((state & alt_modifier) ? dpyinfo->alt_mod_mask : 0)
1705 | ((state & super_modifier) ? x_super_mod_mask : 0) 1680 | ((state & super_modifier) ? dpyinfo->super_mod_mask : 0)
1706 | ((state & hyper_modifier) ? x_hyper_mod_mask : 0) 1681 | ((state & hyper_modifier) ? dpyinfo->hyper_mod_mask : 0)
1707 | ((state & shift_modifier) ? ShiftMask : 0) 1682 | ((state & shift_modifier) ? ShiftMask : 0)
1708 | ((state & ctrl_modifier) ? ControlMask : 0) 1683 | ((state & ctrl_modifier) ? ControlMask : 0)
1709 | ((state & meta_modifier) ? x_meta_mod_mask : 0)); 1684 | ((state & meta_modifier) ? dpyinfo->meta_mod_mask : 0));
1710 } 1685 }
1711 1686
1712 /* Mouse clicks and mouse movement. Rah. */ 1687 /* Mouse clicks and mouse movement. Rah. */
1713 1688
1714 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return 1689 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
1783 /* Make the event type no_event; we'll change that when we decide 1758 /* Make the event type no_event; we'll change that when we decide
1784 otherwise. */ 1759 otherwise. */
1785 result->kind = mouse_click; 1760 result->kind = mouse_click;
1786 result->code = event->button - Button1; 1761 result->code = event->button - Button1;
1787 result->timestamp = event->time; 1762 result->timestamp = event->time;
1788 result->modifiers = (x_x_to_emacs_modifiers (event->state) 1763 result->modifiers = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
1764 event->state)
1789 | (event->type == ButtonRelease 1765 | (event->type == ButtonRelease
1790 ? up_modifier 1766 ? up_modifier
1791 : down_modifier)); 1767 : down_modifier));
1792 1768
1793 { 1769 {
1815 /* Make the event type no_event; we'll change that when we decide 1791 /* Make the event type no_event; we'll change that when we decide
1816 otherwise. */ 1792 otherwise. */
1817 result->kind = mouse_click; 1793 result->kind = mouse_click;
1818 XSETINT (result->code, event->button - Button1); 1794 XSETINT (result->code, event->button - Button1);
1819 result->timestamp = event->time; 1795 result->timestamp = event->time;
1820 result->modifiers = (x_x_to_emacs_modifiers (event->state) 1796 result->modifiers = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
1797 event->state)
1821 | (event->type == ButtonRelease 1798 | (event->type == ButtonRelease
1822 ? up_modifier 1799 ? up_modifier
1823 : down_modifier)); 1800 : down_modifier));
1824 1801
1825 XSETINT (result->x, event->x); 1802 XSETINT (result->x, event->x);
1932 return; 1909 return;
1933 } 1910 }
1934 1911
1935 /* Find out which glyph the mouse is on. */ 1912 /* Find out which glyph the mouse is on. */
1936 pixel_to_glyph_coords (f, x, y, &column, &row, 1913 pixel_to_glyph_coords (f, x, y, &column, &row,
1937 &new_glyph, x_mouse_grabbed); 1914 &new_glyph, FRAME_X_DISPLAY_INFO (f)->grabbed);
1938 1915
1939 /* Which window is that in? */ 1916 /* Which window is that in? */
1940 window = window_from_coordinates (f, column, row, &portion); 1917 window = window_from_coordinates (f, column, row, &portion);
1941 w = XWINDOW (window); 1918 w = XWINDOW (window);
1942 1919
2193 curs_x = old_curs_x; 2170 curs_x = old_curs_x;
2194 curs_y = old_curs_y; 2171 curs_y = old_curs_y;
2195 2172
2196 /* Change the mouse cursor according to the value of HL. */ 2173 /* Change the mouse cursor according to the value of HL. */
2197 if (hl > 0) 2174 if (hl > 0)
2198 XDefineCursor (XDISPLAY FRAME_X_WINDOW (f), f->display.x->cross_cursor); 2175 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2176 f->display.x->cross_cursor);
2199 else 2177 else
2200 XDefineCursor (XDISPLAY FRAME_X_WINDOW (f), f->display.x->text_cursor); 2178 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2179 f->display.x->text_cursor);
2201 } 2180 }
2202 2181
2203 /* Clear out the mouse-highlighted active region. 2182 /* Clear out the mouse-highlighted active region.
2204 Redraw it unhighlighted first. */ 2183 Redraw it unhighlighted first. */
2205 2184
2237 movement. This also calls XQueryPointer, which will cause the 2216 movement. This also calls XQueryPointer, which will cause the
2238 server to give us another MotionNotify when the mouse moves 2217 server to give us another MotionNotify when the mouse moves
2239 again. */ 2218 again. */
2240 2219
2241 static void 2220 static void
2242 XTmouse_position (f, bar_window, part, x, y, time) 2221 XTmouse_position (fp, bar_window, part, x, y, time)
2243 FRAME_PTR *f; 2222 FRAME_PTR *fp;
2244 Lisp_Object *bar_window; 2223 Lisp_Object *bar_window;
2245 enum scroll_bar_part *part; 2224 enum scroll_bar_part *part;
2246 Lisp_Object *x, *y; 2225 Lisp_Object *x, *y;
2247 unsigned long *time; 2226 unsigned long *time;
2248 { 2227 {
2249 FRAME_PTR f1; 2228 FRAME_PTR f1;
2250 2229
2251 BLOCK_INPUT; 2230 BLOCK_INPUT;
2252 2231
2253 if (! NILP (last_mouse_scroll_bar)) 2232 if (! NILP (last_mouse_scroll_bar))
2254 x_scroll_bar_report_motion (f, bar_window, part, x, y, time); 2233 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
2255 else 2234 else
2256 { 2235 {
2257 Window root; 2236 Window root;
2258 int root_x, root_y; 2237 int root_x, root_y;
2259 2238
2262 2241
2263 mouse_moved = 0; 2242 mouse_moved = 0;
2264 last_mouse_scroll_bar = Qnil; 2243 last_mouse_scroll_bar = Qnil;
2265 2244
2266 /* Figure out which root window we're on. */ 2245 /* Figure out which root window we're on. */
2267 XQueryPointer (x_current_display, 2246 XQueryPointer (FRAME_X_DISPLAY (*fp),
2268 DefaultRootWindow (x_current_display), 2247 DefaultRootWindow (FRAME_X_DISPLAY (*fp)),
2269 2248
2270 /* The root window which contains the pointer. */ 2249 /* The root window which contains the pointer. */
2271 &root, 2250 &root,
2272 2251
2273 /* Trash which we can't trust if the pointer is on 2252 /* Trash which we can't trust if the pointer is on
2291 int win_x, win_y; 2270 int win_x, win_y;
2292 int parent_x, parent_y; 2271 int parent_x, parent_y;
2293 2272
2294 win = root; 2273 win = root;
2295 2274
2296 if (x_mouse_grabbed && last_mouse_frame 2275 if (FRAME_X_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame
2297 && FRAME_LIVE_P (last_mouse_frame)) 2276 && FRAME_LIVE_P (last_mouse_frame))
2298 { 2277 {
2299 /* If mouse was grabbed on a frame, give coords for that frame 2278 /* If mouse was grabbed on a frame, give coords for that frame
2300 even if the mouse is now outside it. */ 2279 even if the mouse is now outside it. */
2301 XTranslateCoordinates (x_current_display, 2280 XTranslateCoordinates (FRAME_X_DISPLAY (*fp),
2302 2281
2303 /* From-window, to-window. */ 2282 /* From-window, to-window. */
2304 root, FRAME_X_WINDOW (last_mouse_frame), 2283 root, FRAME_X_WINDOW (last_mouse_frame),
2305 2284
2306 /* From-position, to-position. */ 2285 /* From-position, to-position. */
2312 } 2291 }
2313 else 2292 else
2314 { 2293 {
2315 while (1) 2294 while (1)
2316 { 2295 {
2317 XTranslateCoordinates (x_current_display, 2296 XTranslateCoordinates (FRAME_X_DISPLAY (*fp),
2318 2297
2319 /* From-window, to-window. */ 2298 /* From-window, to-window. */
2320 root, win, 2299 root, win,
2321 2300
2322 /* From-position, to-position. */ 2301 /* From-position, to-position. */
2366 int ignore1, ignore2; 2345 int ignore1, ignore2;
2367 2346
2368 /* Ok, we found a frame. Store all the values. */ 2347 /* Ok, we found a frame. Store all the values. */
2369 2348
2370 pixel_to_glyph_coords (f1, win_x, win_y, &ignore1, &ignore2, 2349 pixel_to_glyph_coords (f1, win_x, win_y, &ignore1, &ignore2,
2371 &last_mouse_glyph, x_mouse_grabbed); 2350 &last_mouse_glyph,
2351 FRAME_X_DISPLAY_INFO (f1)->grabbed);
2372 2352
2373 *bar_window = Qnil; 2353 *bar_window = Qnil;
2374 *part = 0; 2354 *part = 0;
2375 *f = f1; 2355 *fp = f1;
2376 XSETINT (*x, win_x); 2356 XSETINT (*x, win_x);
2377 XSETINT (*y, win_y); 2357 XSETINT (*y, win_y);
2378 *time = last_mouse_movement_time; 2358 *time = last_mouse_movement_time;
2379 } 2359 }
2380 } 2360 }
2427 static struct scroll_bar * 2407 static struct scroll_bar *
2428 x_scroll_bar_create (window, top, left, width, height) 2408 x_scroll_bar_create (window, top, left, width, height)
2429 struct window *window; 2409 struct window *window;
2430 int top, left, width, height; 2410 int top, left, width, height;
2431 { 2411 {
2432 FRAME_PTR frame = XFRAME (WINDOW_FRAME (window)); 2412 FRAME_PTR f = XFRAME (WINDOW_FRAME (window));
2433 struct scroll_bar *bar = 2413 struct scroll_bar *bar
2434 XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); 2414 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
2435 2415
2436 BLOCK_INPUT; 2416 BLOCK_INPUT;
2437 2417
2438 { 2418 {
2439 XSetWindowAttributes a; 2419 XSetWindowAttributes a;
2440 unsigned long mask; 2420 unsigned long mask;
2441 a.background_pixel = frame->display.x->background_pixel; 2421 a.background_pixel = f->display.x->background_pixel;
2442 a.event_mask = (ButtonPressMask | ButtonReleaseMask 2422 a.event_mask = (ButtonPressMask | ButtonReleaseMask
2443 | ButtonMotionMask | PointerMotionHintMask 2423 | ButtonMotionMask | PointerMotionHintMask
2444 | ExposureMask); 2424 | ExposureMask);
2445 a.cursor = x_vertical_scroll_bar_cursor; 2425 a.cursor = x_vertical_scroll_bar_cursor;
2446 2426
2454 XtSetArg (al[ac], XtNwidth, width); ac++; 2434 XtSetArg (al[ac], XtNwidth, width); ac++;
2455 XtSetArg (al[ac], XtNheight, height); ac++; 2435 XtSetArg (al[ac], XtNheight, height); ac++;
2456 XtSetArg (al[ac], XtNborderWidth, 0); ac++; 2436 XtSetArg (al[ac], XtNborderWidth, 0); ac++;
2457 sb_widget = XtCreateManagedWidget ("box", 2437 sb_widget = XtCreateManagedWidget ("box",
2458 boxWidgetClass, 2438 boxWidgetClass,
2459 frame->display.x->edit_widget, al, ac); 2439 f->display.x->edit_widget, al, ac);
2460 SET_SCROLL_BAR_X_WINDOW 2440 SET_SCROLL_BAR_X_WINDOW
2461 (bar, sb_widget->core.window); 2441 (bar, sb_widget->core.window);
2462 #endif 2442 #endif
2463 SET_SCROLL_BAR_X_WINDOW 2443 SET_SCROLL_BAR_X_WINDOW
2464 (bar, 2444 (bar,
2465 XCreateWindow (x_current_display, FRAME_X_WINDOW (frame), 2445 XCreateWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2466 2446
2467 /* Position and size of scroll bar. */ 2447 /* Position and size of scroll bar. */
2468 left, top, width, height, 2448 left, top, width, height,
2469 2449
2470 /* Border width, depth, class, and visual. */ 2450 /* Border width, depth, class, and visual. */
2482 XSETINT (bar->start, 0); 2462 XSETINT (bar->start, 0);
2483 XSETINT (bar->end, 0); 2463 XSETINT (bar->end, 0);
2484 bar->dragging = Qnil; 2464 bar->dragging = Qnil;
2485 2465
2486 /* Add bar to its frame's list of scroll bars. */ 2466 /* Add bar to its frame's list of scroll bars. */
2487 bar->next = FRAME_SCROLL_BARS (frame); 2467 bar->next = FRAME_SCROLL_BARS (f);
2488 bar->prev = Qnil; 2468 bar->prev = Qnil;
2489 XSETVECTOR (FRAME_SCROLL_BARS (frame), bar); 2469 XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
2490 if (! NILP (bar->next)) 2470 if (! NILP (bar->next))
2491 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); 2471 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
2492 2472
2493 XMapWindow (x_current_display, SCROLL_BAR_X_WINDOW (bar)); 2473 XMapWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
2494 2474
2495 UNBLOCK_INPUT; 2475 UNBLOCK_INPUT;
2496 2476
2497 return bar; 2477 return bar;
2498 } 2478 }
2514 int start, end; 2494 int start, end;
2515 int rebuild; 2495 int rebuild;
2516 { 2496 {
2517 int dragging = ! NILP (bar->dragging); 2497 int dragging = ! NILP (bar->dragging);
2518 Window w = SCROLL_BAR_X_WINDOW (bar); 2498 Window w = SCROLL_BAR_X_WINDOW (bar);
2519 GC gc = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))->display.x->normal_gc; 2499 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
2500 GC gc = f->display.x->normal_gc;
2520 2501
2521 /* If the display is already accurate, do nothing. */ 2502 /* If the display is already accurate, do nothing. */
2522 if (! rebuild 2503 if (! rebuild
2523 && start == XINT (bar->start) 2504 && start == XINT (bar->start)
2524 && end == XINT (bar->end)) 2505 && end == XINT (bar->end))
2562 end += VERTICAL_SCROLL_BAR_MIN_HANDLE; 2543 end += VERTICAL_SCROLL_BAR_MIN_HANDLE;
2563 2544
2564 /* Draw the empty space above the handle. Note that we can't clear 2545 /* Draw the empty space above the handle. Note that we can't clear
2565 zero-height areas; that means "clear to end of window." */ 2546 zero-height areas; that means "clear to end of window." */
2566 if (0 < start) 2547 if (0 < start)
2567 XClearArea (x_current_display, w, 2548 XClearArea (FRAME_X_DISPLAY (f), w,
2568 2549
2569 /* x, y, width, height, and exposures. */ 2550 /* x, y, width, height, and exposures. */
2570 VERTICAL_SCROLL_BAR_LEFT_BORDER, 2551 VERTICAL_SCROLL_BAR_LEFT_BORDER,
2571 VERTICAL_SCROLL_BAR_TOP_BORDER, 2552 VERTICAL_SCROLL_BAR_TOP_BORDER,
2572 inside_width, start, 2553 inside_width, start,
2573 False); 2554 False);
2574 2555
2575 /* Draw the handle itself. */ 2556 /* Draw the handle itself. */
2576 XFillRectangle (x_current_display, w, gc, 2557 XFillRectangle (FRAME_X_DISPLAY (f), w, gc,
2577 2558
2578 /* x, y, width, height */ 2559 /* x, y, width, height */
2579 VERTICAL_SCROLL_BAR_LEFT_BORDER, 2560 VERTICAL_SCROLL_BAR_LEFT_BORDER,
2580 VERTICAL_SCROLL_BAR_TOP_BORDER + start, 2561 VERTICAL_SCROLL_BAR_TOP_BORDER + start,
2581 inside_width, end - start); 2562 inside_width, end - start);
2582 2563
2583 2564
2584 /* Draw the empty space below the handle. Note that we can't 2565 /* Draw the empty space below the handle. Note that we can't
2585 clear zero-height areas; that means "clear to end of window." */ 2566 clear zero-height areas; that means "clear to end of window." */
2586 if (end < inside_height) 2567 if (end < inside_height)
2587 XClearArea (x_current_display, w, 2568 XClearArea (FRAME_X_DISPLAY (f), w,
2588 2569
2589 /* x, y, width, height, and exposures. */ 2570 /* x, y, width, height, and exposures. */
2590 VERTICAL_SCROLL_BAR_LEFT_BORDER, 2571 VERTICAL_SCROLL_BAR_LEFT_BORDER,
2591 VERTICAL_SCROLL_BAR_TOP_BORDER + end, 2572 VERTICAL_SCROLL_BAR_TOP_BORDER + end,
2592 inside_width, inside_height - end, 2573 inside_width, inside_height - end,
2602 static void 2583 static void
2603 x_scroll_bar_move (bar, top, left, width, height) 2584 x_scroll_bar_move (bar, top, left, width, height)
2604 struct scroll_bar *bar; 2585 struct scroll_bar *bar;
2605 int top, left, width, height; 2586 int top, left, width, height;
2606 { 2587 {
2588 Window w = SCROLL_BAR_X_WINDOW (bar);
2589 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
2590
2607 BLOCK_INPUT; 2591 BLOCK_INPUT;
2608 2592
2609 { 2593 {
2610 XWindowChanges wc; 2594 XWindowChanges wc;
2611 unsigned int mask = 0; 2595 unsigned int mask = 0;
2619 if (top != XINT (bar->top)) mask |= CWY; 2603 if (top != XINT (bar->top)) mask |= CWY;
2620 if (width != XINT (bar->width)) mask |= CWWidth; 2604 if (width != XINT (bar->width)) mask |= CWWidth;
2621 if (height != XINT (bar->height)) mask |= CWHeight; 2605 if (height != XINT (bar->height)) mask |= CWHeight;
2622 2606
2623 if (mask) 2607 if (mask)
2624 XConfigureWindow (x_current_display, SCROLL_BAR_X_WINDOW (bar), 2608 XConfigureWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar),
2625 mask, &wc); 2609 mask, &wc);
2626 } 2610 }
2627 2611
2628 XSETINT (bar->left, left); 2612 XSETINT (bar->left, left);
2629 XSETINT (bar->top, top); 2613 XSETINT (bar->top, top);
2642 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 2626 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
2643 2627
2644 BLOCK_INPUT; 2628 BLOCK_INPUT;
2645 2629
2646 /* Destroy the window. */ 2630 /* Destroy the window. */
2647 XDestroyWindow (x_current_display, SCROLL_BAR_X_WINDOW (bar)); 2631 XDestroyWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
2648 2632
2649 /* Disassociate this scroll bar from its window. */ 2633 /* Disassociate this scroll bar from its window. */
2650 XWINDOW (bar->window)->vertical_scroll_bar = Qnil; 2634 XWINDOW (bar->window)->vertical_scroll_bar = Qnil;
2651 2635
2652 UNBLOCK_INPUT; 2636 UNBLOCK_INPUT;
2821 x_scroll_bar_expose (bar, event) 2805 x_scroll_bar_expose (bar, event)
2822 struct scroll_bar *bar; 2806 struct scroll_bar *bar;
2823 XEvent *event; 2807 XEvent *event;
2824 { 2808 {
2825 Window w = SCROLL_BAR_X_WINDOW (bar); 2809 Window w = SCROLL_BAR_X_WINDOW (bar);
2826 GC gc = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))->display.x->normal_gc; 2810 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
2811 GC gc = f->display.x->normal_gc;
2827 2812
2828 BLOCK_INPUT; 2813 BLOCK_INPUT;
2829 2814
2830 x_scroll_bar_set_handle (bar, XINT (bar->start), XINT (bar->end), 1); 2815 x_scroll_bar_set_handle (bar, XINT (bar->start), XINT (bar->end), 1);
2831 2816
2832 /* Draw a one-pixel border just inside the edges of the scroll bar. */ 2817 /* Draw a one-pixel border just inside the edges of the scroll bar. */
2833 XDrawRectangle (x_current_display, w, gc, 2818 XDrawRectangle (FRAME_X_DISPLAY (f), w, gc,
2834 2819
2835 /* x, y, width, height */ 2820 /* x, y, width, height */
2836 0, 0, XINT (bar->width) - 1, XINT (bar->height) - 1); 2821 0, 0, XINT (bar->width) - 1, XINT (bar->height) - 1);
2837 2822
2838 UNBLOCK_INPUT; 2823 UNBLOCK_INPUT;
2853 abort (); 2838 abort ();
2854 2839
2855 emacs_event->kind = scroll_bar_click; 2840 emacs_event->kind = scroll_bar_click;
2856 emacs_event->code = event->xbutton.button - Button1; 2841 emacs_event->code = event->xbutton.button - Button1;
2857 emacs_event->modifiers = 2842 emacs_event->modifiers =
2858 (x_x_to_emacs_modifiers (event->xbutton.state) 2843 (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))),
2844 event->xbutton.state)
2859 | (event->type == ButtonRelease 2845 | (event->type == ButtonRelease
2860 ? up_modifier 2846 ? up_modifier
2861 : down_modifier)); 2847 : down_modifier));
2862 emacs_event->frame_or_window = bar->window; 2848 emacs_event->frame_or_window = bar->window;
2863 emacs_event->timestamp = event->xbutton.time; 2849 emacs_event->timestamp = event->xbutton.time;
2958 } 2944 }
2959 2945
2960 /* Return information to the user about the current position of the mouse 2946 /* Return information to the user about the current position of the mouse
2961 on the scroll bar. */ 2947 on the scroll bar. */
2962 static void 2948 static void
2963 x_scroll_bar_report_motion (f, bar_window, part, x, y, time) 2949 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
2964 FRAME_PTR *f; 2950 FRAME_PTR *fp;
2965 Lisp_Object *bar_window; 2951 Lisp_Object *bar_window;
2966 enum scroll_bar_part *part; 2952 enum scroll_bar_part *part;
2967 Lisp_Object *x, *y; 2953 Lisp_Object *x, *y;
2968 unsigned long *time; 2954 unsigned long *time;
2969 { 2955 {
2970 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 2956 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
2957 Window w = SCROLL_BAR_X_WINDOW (bar);
2958 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
2971 int win_x, win_y; 2959 int win_x, win_y;
2972 Window dummy_window; 2960 Window dummy_window;
2973 int dummy_coord; 2961 int dummy_coord;
2974 unsigned int dummy_mask; 2962 unsigned int dummy_mask;
2975 2963
2976 BLOCK_INPUT; 2964 BLOCK_INPUT;
2977 2965
2978 /* Get the mouse's position relative to the scroll bar window, and 2966 /* Get the mouse's position relative to the scroll bar window, and
2979 report that. */ 2967 report that. */
2980 if (! XQueryPointer (x_current_display, 2968 if (! XQueryPointer (FRAME_X_DISPLAY (f), w,
2981 SCROLL_BAR_X_WINDOW (bar),
2982 2969
2983 /* Root, child, root x and root y. */ 2970 /* Root, child, root x and root y. */
2984 &dummy_window, &dummy_window, 2971 &dummy_window, &dummy_window,
2985 &dummy_coord, &dummy_coord, 2972 &dummy_coord, &dummy_coord,
2986 2973
2987 /* Position relative to scroll bar. */ 2974 /* Position relative to scroll bar. */
2988 &win_x, &win_y, 2975 &win_x, &win_y,
2989 2976
2990 /* Mouse buttons and modifier keys. */ 2977 /* Mouse buttons and modifier keys. */
2991 &dummy_mask)) 2978 &dummy_mask))
2992 *f = 0; 2979 *fp = 0;
2993 else 2980 else
2994 { 2981 {
2995 int inside_height 2982 int inside_height
2996 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar->height)); 2983 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar->height));
2997 int top_range 2984 int top_range
3005 if (win_y < 0) 2992 if (win_y < 0)
3006 win_y = 0; 2993 win_y = 0;
3007 if (win_y > top_range) 2994 if (win_y > top_range)
3008 win_y = top_range; 2995 win_y = top_range;
3009 2996
3010 *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 2997 *fp = f;
3011 *bar_window = bar->window; 2998 *bar_window = w;
3012 2999
3013 if (! NILP (bar->dragging)) 3000 if (! NILP (bar->dragging))
3014 *part = scroll_bar_handle; 3001 *part = scroll_bar_handle;
3015 else if (win_y < XINT (bar->start)) 3002 else if (win_y < XINT (bar->start))
3016 *part = scroll_bar_above_handle; 3003 *part = scroll_bar_above_handle;
3042 { 3029 {
3043 Lisp_Object bar; 3030 Lisp_Object bar;
3044 3031
3045 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); 3032 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
3046 bar = XSCROLL_BAR (bar)->next) 3033 bar = XSCROLL_BAR (bar)->next)
3047 XClearArea (x_current_display, SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)), 3034 XClearArea (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)),
3048 0, 0, 0, 0, True); 3035 0, 0, 0, 0, True);
3049 } 3036 }
3050 3037
3051 /* This processes Expose events from the menubar specific X event 3038 /* This processes Expose events from the menubar specific X event
3052 loop in menubar.c. This allows to redisplay the frame if necessary 3039 loop in menubar.c. This allows to redisplay the frame if necessary
3102 static int x_queue_selection_requests; 3089 static int x_queue_selection_requests;
3103 3090
3104 /* Queue up an X event *EVENT, to be processed later. */ 3091 /* Queue up an X event *EVENT, to be processed later. */
3105 3092
3106 static void 3093 static void
3107 x_queue_event (event) 3094 x_queue_event (f, event)
3095 FRAME_PTR f;
3108 XEvent *event; 3096 XEvent *event;
3109 { 3097 {
3110 struct selection_event_queue *queue_tmp 3098 struct selection_event_queue *queue_tmp
3111 = (struct selection_event_queue *) malloc (sizeof (struct selection_event_queue)); 3099 = (struct selection_event_queue *) malloc (sizeof (struct selection_event_queue));
3112 3100
3120 3108
3121 /* Take all the queued events and put them back 3109 /* Take all the queued events and put them back
3122 so that they get processed afresh. */ 3110 so that they get processed afresh. */
3123 3111
3124 static void 3112 static void
3125 x_unqueue_events () 3113 x_unqueue_events (f)
3114 FRAME_PTR f;
3126 { 3115 {
3127 while (queue != NULL) 3116 while (queue != NULL)
3128 { 3117 {
3129 struct selection_event_queue *queue_tmp = queue; 3118 struct selection_event_queue *queue_tmp = queue;
3130 XPutBackEvent (XDISPLAY &queue_tmp->event); 3119 XPutBackEvent (FRAME_X_DISPLAY (f), &queue_tmp->event);
3131 queue = queue_tmp->next; 3120 queue = queue_tmp->next;
3132 free ((char *)queue_tmp); 3121 free ((char *)queue_tmp);
3133 } 3122 }
3134 } 3123 }
3135 3124
3136 /* Start queuing SelectionRequest events. */ 3125 /* Start queuing SelectionRequest events. */
3137 3126
3138 void 3127 void
3139 x_start_queuing_selection_requests () 3128 x_start_queuing_selection_requests (f)
3129 FRAME_PTR f;
3140 { 3130 {
3141 x_queue_selection_requests++; 3131 x_queue_selection_requests++;
3142 } 3132 }
3143 3133
3144 /* Stop queuing SelectionRequest events. */ 3134 /* Stop queuing SelectionRequest events. */
3145 3135
3146 void 3136 void
3147 x_stop_queuing_selection_requests () 3137 x_stop_queuing_selection_requests (f)
3138 FRAME_PTR f;
3148 { 3139 {
3149 x_queue_selection_requests--; 3140 x_queue_selection_requests--;
3150 x_unqueue_events (); 3141 x_unqueue_events (f);
3151 } 3142 }
3152 3143
3153 /* The main X event-reading loop - XTread_socket. */ 3144 /* The main X event-reading loop - XTread_socket. */
3154 3145
3155 /* Timestamp of enter window event. This is only used by XTread_socket, 3146 /* Timestamp of enter window event. This is only used by XTread_socket,
3163 me that letting the compiler initialize it to zeros will work okay. 3154 me that letting the compiler initialize it to zeros will work okay.
3164 3155
3165 This must be defined outside of XTread_socket, for the same reasons 3156 This must be defined outside of XTread_socket, for the same reasons
3166 given for enter_timestamp, above. */ 3157 given for enter_timestamp, above. */
3167 static XComposeStatus compose_status; 3158 static XComposeStatus compose_status;
3168
3169 /* Communication with window managers. */
3170 Atom Xatom_wm_protocols;
3171
3172 /* Kinds of protocol things we may receive. */
3173 Atom Xatom_wm_take_focus;
3174 Atom Xatom_wm_save_yourself;
3175 Atom Xatom_wm_delete_window;
3176
3177 /* Other WM communication */
3178 Atom Xatom_wm_configure_denied; /* When our config request is denied */
3179 Atom Xatom_wm_window_moved; /* When the WM moves us. */
3180
3181 /* Window manager communication. */
3182 Atom Xatom_wm_change_state;
3183
3184 /* EditRes protocol */
3185 Atom Xatom_editres_name;
3186 3159
3187 /* Record the last 100 characters stored 3160 /* Record the last 100 characters stored
3188 to help debug the loss-of-chars-during-GC problem. */ 3161 to help debug the loss-of-chars-during-GC problem. */
3189 int temp_index; 3162 int temp_index;
3190 short temp_buffer[100]; 3163 short temp_buffer[100];
3216 XEvent event; 3189 XEvent event;
3217 struct frame *f; 3190 struct frame *f;
3218 int event_found = 0; 3191 int event_found = 0;
3219 int prefix; 3192 int prefix;
3220 Lisp_Object part; 3193 Lisp_Object part;
3194 struct x_display_info *dpyinfo;
3221 3195
3222 if (interrupt_input_blocked) 3196 if (interrupt_input_blocked)
3223 { 3197 {
3224 interrupt_input_pending = 1; 3198 interrupt_input_pending = 1;
3225 return -1; 3199 return -1;
3226 } 3200 }
3227 3201
3228 interrupt_input_pending = 0; 3202 interrupt_input_pending = 0;
3229 BLOCK_INPUT; 3203 BLOCK_INPUT;
3204
3205 /* Find the display we are supposed to read input for.
3206 It's the one communicating on descriptor SD. */
3207 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
3208 if (dpyinfo->connection == sd)
3209 break;
3210 if (dpyinfo == 0)
3211 abort ();
3230 3212
3231 /* So people can tell when we have read the available input. */ 3213 /* So people can tell when we have read the available input. */
3232 input_signal_count++; 3214 input_signal_count++;
3233 3215
3234 if (numchars <= 0) 3216 if (numchars <= 0)
3237 #ifdef FIOSNBIO 3219 #ifdef FIOSNBIO
3238 /* If available, Xlib uses FIOSNBIO to make the socket 3220 /* If available, Xlib uses FIOSNBIO to make the socket
3239 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set, 3221 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3240 FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK, 3222 FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK,
3241 a read returns 0, which Xlib interprets as equivalent to EPIPE. */ 3223 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3242 fcntl (fileno (stdin), F_SETFL, 0); 3224 fcntl (sd, F_SETFL, 0);
3243 #endif /* ! defined (FIOSNBIO) */ 3225 #endif /* ! defined (FIOSNBIO) */
3244 3226
3245 #ifndef SIGIO 3227 #ifndef SIGIO
3246 #ifndef HAVE_SELECT 3228 #ifndef HAVE_SELECT
3247 if (! (fcntl (fileno (stdin), F_GETFL, 0) & O_NDELAY)) 3229 if (! (fcntl (sd, F_GETFL, 0) & O_NDELAY))
3248 { 3230 {
3249 extern int read_alarm_should_throw; 3231 extern int read_alarm_should_throw;
3250 read_alarm_should_throw = 1; 3232 read_alarm_should_throw = 1;
3251 XPeekEvent (XDISPLAY &event); 3233 XPeekEvent (dpyinfo->display, &event);
3252 read_alarm_should_throw = 0; 3234 read_alarm_should_throw = 0;
3253 } 3235 }
3254 #endif /* HAVE_SELECT */ 3236 #endif /* HAVE_SELECT */
3255 #endif /* SIGIO */ 3237 #endif /* SIGIO */
3256 3238
3257 while (XStuffPending () != 0) 3239 while (XPending (dpyinfo->display) != 0)
3258 { 3240 {
3259 XNextEvent (XDISPLAY &event); 3241 XNextEvent (dpyinfo->display, &event);
3260 event_found = 1; 3242 event_found = 1;
3261 3243
3262 switch (event.type) 3244 switch (event.type)
3263 { 3245 {
3264 case ClientMessage: 3246 case ClientMessage:
3265 { 3247 {
3266 if (event.xclient.message_type == Xatom_wm_protocols 3248 if (event.xclient.message_type
3249 == dpyinfo->Xatom_wm_protocols
3267 && event.xclient.format == 32) 3250 && event.xclient.format == 32)
3268 { 3251 {
3269 if (event.xclient.data.l[0] == Xatom_wm_take_focus) 3252 if (event.xclient.data.l[0]
3253 == dpyinfo->Xatom_wm_take_focus)
3270 { 3254 {
3271 f = x_window_to_frame (event.xclient.window); 3255 f = x_window_to_frame (event.xclient.window);
3272 /* Since we set WM_TAKE_FOCUS, we must call 3256 /* Since we set WM_TAKE_FOCUS, we must call
3273 XSetInputFocus explicitly. But not if f is null, 3257 XSetInputFocus explicitly. But not if f is null,
3274 since that might be an event for a deleted frame. */ 3258 since that might be an event for a deleted frame. */
3277 event.xclient.window, 3261 event.xclient.window,
3278 RevertToPointerRoot, 3262 RevertToPointerRoot,
3279 event.xclient.data.l[1]); 3263 event.xclient.data.l[1]);
3280 /* Not certain about handling scroll bars here */ 3264 /* Not certain about handling scroll bars here */
3281 } 3265 }
3282 else if (event.xclient.data.l[0] == Xatom_wm_save_yourself) 3266 else if (event.xclient.data.l[0]
3267 == dpyinfo->Xatom_wm_save_yourself)
3283 { 3268 {
3284 /* Save state modify the WM_COMMAND property to 3269 /* Save state modify the WM_COMMAND property to
3285 something which can reinstate us. This notifies 3270 something which can reinstate us. This notifies
3286 the session manager, who's looking for such a 3271 the session manager, who's looking for such a
3287 PropertyNotify. Can restart processing when 3272 PropertyNotify. Can restart processing when
3288 a keyboard or mouse event arrives. */ 3273 a keyboard or mouse event arrives. */
3289 if (numchars > 0) 3274 if (numchars > 0)
3290 { 3275 {
3276 f = x_top_window_to_frame (event.xclient.window);
3277
3291 /* This is just so we only give real data once 3278 /* This is just so we only give real data once
3292 for a single Emacs process. */ 3279 for a single Emacs process. */
3293 if (x_top_window_to_frame (event.xclient.window) 3280 if (f == selected_frame)
3294 == selected_frame) 3281 XSetCommand (FRAME_X_DISPLAY (f),
3295 XSetCommand (x_current_display,
3296 event.xclient.window, 3282 event.xclient.window,
3297 initial_argv, initial_argc); 3283 initial_argv, initial_argc);
3298 else 3284 else
3299 XSetCommand (x_current_display, 3285 XSetCommand (FRAME_X_DISPLAY (f),
3300 event.xclient.window, 3286 event.xclient.window,
3301 0, 0); 3287 0, 0);
3302 } 3288 }
3303 } 3289 }
3304 else if (event.xclient.data.l[0] == Xatom_wm_delete_window) 3290 else if (event.xclient.data.l[0]
3291 == dpyinfo->Xatom_wm_delete_window)
3305 { 3292 {
3306 struct frame *f = x_any_window_to_frame (event.xclient.window); 3293 struct frame *f = x_any_window_to_frame (event.xclient.window);
3307 3294
3308 if (f) 3295 if (f)
3309 { 3296 {
3317 count += 1; 3304 count += 1;
3318 numchars -= 1; 3305 numchars -= 1;
3319 } 3306 }
3320 } 3307 }
3321 } 3308 }
3322 else if (event.xclient.message_type == Xatom_wm_configure_denied) 3309 else if (event.xclient.message_type
3310 == dpyinfo->Xatom_wm_configure_denied)
3323 { 3311 {
3324 } 3312 }
3325 else if (event.xclient.message_type == Xatom_wm_window_moved) 3313 else if (event.xclient.message_type
3314 == dpyinfo->Xatom_wm_window_moved)
3326 { 3315 {
3327 int new_x, new_y; 3316 int new_x, new_y;
3328 struct frame *f = x_window_to_frame (event.xclient.window); 3317 struct frame *f = x_window_to_frame (event.xclient.window);
3329 3318
3330 new_x = event.xclient.data.s[0]; 3319 new_x = event.xclient.data.s[0];
3335 f->display.x->left_pos = new_x; 3324 f->display.x->left_pos = new_x;
3336 f->display.x->top_pos = new_y; 3325 f->display.x->top_pos = new_y;
3337 } 3326 }
3338 } 3327 }
3339 #if defined (USE_X_TOOLKIT) && defined (HAVE_X11R5) 3328 #if defined (USE_X_TOOLKIT) && defined (HAVE_X11R5)
3340 else if (event.xclient.message_type == Xatom_editres_name) 3329 else if (event.xclient.message_type
3330 == dpyinfo->Xatom_editres)
3341 { 3331 {
3342 struct frame *f = x_any_window_to_frame (event.xclient.window); 3332 struct frame *f = x_any_window_to_frame (event.xclient.window);
3343 _XEditResCheckMessages (f->display.x->widget, NULL, &event, NULL); 3333 _XEditResCheckMessages (f->display.x->widget, NULL, &event, NULL);
3344 } 3334 }
3345 #endif /* USE_X_TOOLKIT and HAVE_X11R5 */ 3335 #endif /* USE_X_TOOLKIT and HAVE_X11R5 */
3380 #ifdef USE_X_TOOLKIT 3370 #ifdef USE_X_TOOLKIT
3381 if (!x_window_to_frame (event.xselectionrequest.owner)) 3371 if (!x_window_to_frame (event.xselectionrequest.owner))
3382 goto OTHER; 3372 goto OTHER;
3383 #endif /* USE_X_TOOLKIT */ 3373 #endif /* USE_X_TOOLKIT */
3384 if (x_queue_selection_requests) 3374 if (x_queue_selection_requests)
3385 x_queue_event (&event); 3375 x_queue_event (x_window_to_frame (event.xselectionrequest.owner),
3376 &event);
3386 else 3377 else
3387 { 3378 {
3388 XSelectionRequestEvent *eventp = (XSelectionRequestEvent *) &event; 3379 XSelectionRequestEvent *eventp = (XSelectionRequestEvent *) &event;
3389 3380
3390 if (numchars == 0) 3381 if (numchars == 0)
3528 80 fixed a bug whereby meta chars made his Emacs hang. */ 3519 80 fixed a bug whereby meta chars made his Emacs hang. */
3529 unsigned char copy_buffer[81]; 3520 unsigned char copy_buffer[81];
3530 int modifiers; 3521 int modifiers;
3531 3522
3532 event.xkey.state 3523 event.xkey.state
3533 |= x_emacs_to_x_modifiers (extra_keyboard_modifiers); 3524 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f),
3525 extra_keyboard_modifiers);
3534 modifiers = event.xkey.state; 3526 modifiers = event.xkey.state;
3535 3527
3536 /* This will have to go some day... */ 3528 /* This will have to go some day... */
3537 3529
3538 /* make_lispy_event turns chars into control chars. 3530 /* make_lispy_event turns chars into control chars.
3616 temp_index = 0; 3608 temp_index = 0;
3617 temp_buffer[temp_index++] = keysym; 3609 temp_buffer[temp_index++] = keysym;
3618 bufp->kind = non_ascii_keystroke; 3610 bufp->kind = non_ascii_keystroke;
3619 bufp->code = keysym; 3611 bufp->code = keysym;
3620 XSETFRAME (bufp->frame_or_window, f); 3612 XSETFRAME (bufp->frame_or_window, f);
3621 bufp->modifiers = x_x_to_emacs_modifiers (modifiers); 3613 bufp->modifiers
3614 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
3615 modifiers);
3622 bufp->timestamp = event.xkey.time; 3616 bufp->timestamp = event.xkey.time;
3623 bufp++; 3617 bufp++;
3624 count++; 3618 count++;
3625 numchars--; 3619 numchars--;
3626 } 3620 }
3634 temp_index = 0; 3628 temp_index = 0;
3635 temp_buffer[temp_index++] = copy_buffer[i]; 3629 temp_buffer[temp_index++] = copy_buffer[i];
3636 bufp->kind = ascii_keystroke; 3630 bufp->kind = ascii_keystroke;
3637 bufp->code = copy_buffer[i]; 3631 bufp->code = copy_buffer[i];
3638 XSETFRAME (bufp->frame_or_window, f); 3632 XSETFRAME (bufp->frame_or_window, f);
3639 bufp->modifiers = x_x_to_emacs_modifiers (modifiers); 3633 bufp->modifiers
3634 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
3635 modifiers);
3640 bufp->timestamp = event.xkey.time; 3636 bufp->timestamp = event.xkey.time;
3641 bufp++; 3637 bufp++;
3642 } 3638 }
3643 3639
3644 count += nbytes; 3640 count += nbytes;
3736 #endif /* USE_X_TOOLKIT */ 3732 #endif /* USE_X_TOOLKIT */
3737 break; 3733 break;
3738 3734
3739 case MotionNotify: 3735 case MotionNotify:
3740 { 3736 {
3741 if (x_mouse_grabbed && last_mouse_frame 3737 if (dpyinfo->grabbed && last_mouse_frame
3742 && FRAME_LIVE_P (last_mouse_frame)) 3738 && FRAME_LIVE_P (last_mouse_frame))
3743 f = last_mouse_frame; 3739 f = last_mouse_frame;
3744 else 3740 else
3745 f = x_window_to_frame (event.xmotion.window); 3741 f = x_window_to_frame (event.xmotion.window);
3746 if (f) 3742 if (f)
3783 /* Find the position of the outside upper-left corner of 3779 /* Find the position of the outside upper-left corner of
3784 the window, in the root coordinate system. Don't 3780 the window, in the root coordinate system. Don't
3785 refer to the parent window here; we may be processing 3781 refer to the parent window here; we may be processing
3786 this event after the window manager has changed our 3782 this event after the window manager has changed our
3787 parent, but before we have reached the ReparentNotify. */ 3783 parent, but before we have reached the ReparentNotify. */
3788 XTranslateCoordinates (x_current_display, 3784 XTranslateCoordinates (FRAME_X_DISPLAY (f),
3789 3785
3790 /* From-window, to-window. */ 3786 /* From-window, to-window. */
3791 XtWindow (f->display.x->widget), 3787 XtWindow (f->display.x->widget),
3792 ROOT_WINDOW, 3788 FRAME_X_DISPLAY_INFO (f)->root_window,
3793 3789
3794 /* From-position, to-position. */ 3790 /* From-position, to-position. */
3795 -event.xconfigure.border_width, 3791 -event.xconfigure.border_width,
3796 -event.xconfigure.border_width, 3792 -event.xconfigure.border_width,
3797 &win_x, &win_y, 3793 &win_x, &win_y,
3842 /* Find the position of the outside upper-left corner of 3838 /* Find the position of the outside upper-left corner of
3843 the window, in the root coordinate system. Don't 3839 the window, in the root coordinate system. Don't
3844 refer to the parent window here; we may be processing 3840 refer to the parent window here; we may be processing
3845 this event after the window manager has changed our 3841 this event after the window manager has changed our
3846 parent, but before we have reached the ReparentNotify. */ 3842 parent, but before we have reached the ReparentNotify. */
3847 XTranslateCoordinates (x_current_display, 3843 XTranslateCoordinates (FRAME_X_DISPLAY (f),
3848 3844
3849 /* From-window, to-window. */ 3845 /* From-window, to-window. */
3850 f->display.x->window_desc, 3846 f->display.x->window_desc,
3851 ROOT_WINDOW, 3847 FRAME_X_DISPLAY_INFO (f)->root_window,
3852 3848
3853 /* From-position, to-position. */ 3849 /* From-position, to-position. */
3854 -event.xconfigure.border_width, 3850 -event.xconfigure.border_width,
3855 -event.xconfigure.border_width, 3851 -event.xconfigure.border_width,
3856 &win_x, &win_y, 3852 &win_x, &win_y,
3919 #endif /* USE_X_TOOLKIT */ 3915 #endif /* USE_X_TOOLKIT */
3920 } 3916 }
3921 3917
3922 if (event.type == ButtonPress) 3918 if (event.type == ButtonPress)
3923 { 3919 {
3924 x_mouse_grabbed |= (1 << event.xbutton.button); 3920 dpyinfo->grabbed |= (1 << event.xbutton.button);
3925 Vmouse_depressed = Qt;
3926 last_mouse_frame = f; 3921 last_mouse_frame = f;
3927 } 3922 }
3928 else 3923 else
3929 { 3924 {
3930 x_mouse_grabbed &= ~(1 << event.xbutton.button); 3925 dpyinfo->grabbed &= ~(1 << event.xbutton.button);
3931 if (!x_mouse_grabbed)
3932 Vmouse_depressed = Qnil;
3933 } 3926 }
3934 3927
3935 if (numchars >= 1 && emacs_event.kind != no_event) 3928 if (numchars >= 1 && emacs_event.kind != no_event)
3936 { 3929 {
3937 bcopy (&emacs_event, bufp, sizeof (struct input_event)); 3930 bcopy (&emacs_event, bufp, sizeof (struct input_event));
3955 /* Someone has changed the keyboard mapping - update the 3948 /* Someone has changed the keyboard mapping - update the
3956 local cache. */ 3949 local cache. */
3957 switch (event.xmapping.request) 3950 switch (event.xmapping.request)
3958 { 3951 {
3959 case MappingModifier: 3952 case MappingModifier:
3960 x_find_modifier_meanings (); 3953 x_find_modifier_meanings (dpyinfo);
3961 /* This is meant to fall through. */ 3954 /* This is meant to fall through. */
3962 case MappingKeyboard: 3955 case MappingKeyboard:
3963 XRefreshKeyboardMapping (&event.xmapping); 3956 XRefreshKeyboardMapping (&event.xmapping);
3964 } 3957 }
3965 #ifdef USE_X_TOOLKIT 3958 #ifdef USE_X_TOOLKIT
3987 B. Bretthauer, 1994 */ 3980 B. Bretthauer, 1994 */
3988 x_noop_count++; 3981 x_noop_count++;
3989 if (x_noop_count >= 100) 3982 if (x_noop_count >= 100)
3990 { 3983 {
3991 x_noop_count=0; 3984 x_noop_count=0;
3992 XNoOp (x_current_display); 3985 XNoOp (dpyinfo->display);
3993 } 3986 }
3994 } 3987 }
3995 3988
3996 #if 0 /* This fails for serial-line connections to the X server, 3989 #if 0 /* This fails for serial-line connections to the X server,
3997 because the characters arrive one by one, and a partial 3990 because the characters arrive one by one, and a partial
4002 if (expected && ! event_found) 3995 if (expected && ! event_found)
4003 { 3996 {
4004 /* AOJ 880406: if select returns true but XPending doesn't, it means that 3997 /* AOJ 880406: if select returns true but XPending doesn't, it means that
4005 there is an EOF condition; in other words, that X has died. 3998 there is an EOF condition; in other words, that X has died.
4006 Act as if there had been a hangup. */ 3999 Act as if there had been a hangup. */
4007 int fd = ConnectionNumber (x_current_display); 4000 int fd = ConnectionNumber (dpyinfo->display);
4008 SELECT_TYPE mask, junk1, junk2; 4001 SELECT_TYPE mask, junk1, junk2;
4009 EMACS_TIME timeout; 4002 EMACS_TIME timeout;
4010 4003
4011 FD_ZERO (&mask); 4004 FD_ZERO (&mask);
4012 FD_SET (fd, &mask); 4005 FD_SET (fd, &mask);
4013 EMACS_SET_SECS_USECS (timeout, 0, 0); 4006 EMACS_SET_SECS_USECS (timeout, 0, 0);
4014 FD_ZERO (&junk1); 4007 FD_ZERO (&junk1);
4015 FD_ZERO (&junk2); 4008 FD_ZERO (&junk2);
4016 if (0 != select (fd + 1, &mask, &junk1, &junk2, &timeout) 4009 if (0 != select (fd + 1, &mask, &junk1, &junk2, &timeout)
4017 && !XStuffPending ()) 4010 && !XPending (dpyinfo->display))
4018 kill (getpid (), SIGHUP); 4011 kill (getpid (), SIGHUP);
4019 } 4012 }
4020 #endif /* HAVE_SELECT */ 4013 #endif /* HAVE_SELECT */
4021 #endif /* 0 */ 4014 #endif /* 0 */
4022 4015
4044 int left = CHAR_TO_PIXEL_COL (f, curs_x); 4037 int left = CHAR_TO_PIXEL_COL (f, curs_x);
4045 int top = CHAR_TO_PIXEL_ROW (f, curs_y); 4038 int top = CHAR_TO_PIXEL_ROW (f, curs_y);
4046 int width = FONT_WIDTH (f->display.x->font); 4039 int width = FONT_WIDTH (f->display.x->font);
4047 int height = f->display.x->line_height; 4040 int height = f->display.x->line_height;
4048 4041
4049 XDrawRectangle (x_current_display, FRAME_X_WINDOW (f), 4042 XDrawRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4050 f->display.x->cursor_gc, 4043 f->display.x->cursor_gc,
4051 left, top, width - 1, height - 1); 4044 left, top, width - 1, height - 1);
4052 } 4045 }
4053 4046
4054 /* Clear the cursor of frame F to background color, 4047 /* Clear the cursor of frame F to background color,
4133 f->phys_cursor_glyph 4126 f->phys_cursor_glyph
4134 = ((current_glyphs->enable[curs_y] 4127 = ((current_glyphs->enable[curs_y]
4135 && curs_x < current_glyphs->used[curs_y]) 4128 && curs_x < current_glyphs->used[curs_y])
4136 ? current_glyphs->glyphs[curs_y][curs_x] 4129 ? current_glyphs->glyphs[curs_y][curs_x]
4137 : SPACEGLYPH); 4130 : SPACEGLYPH);
4138 XFillRectangle (x_current_display, FRAME_X_WINDOW (f), 4131 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4139 f->display.x->cursor_gc, 4132 f->display.x->cursor_gc,
4140 CHAR_TO_PIXEL_COL (f, curs_x), 4133 CHAR_TO_PIXEL_COL (f, curs_x),
4141 CHAR_TO_PIXEL_ROW (f, curs_y), 4134 CHAR_TO_PIXEL_ROW (f, curs_y),
4142 1, f->display.x->line_height); 4135 1, f->display.x->line_height);
4143 4136
4146 4139
4147 f->display.x->current_cursor = bar_cursor; 4140 f->display.x->current_cursor = bar_cursor;
4148 } 4141 }
4149 4142
4150 if (updating_frame != f) 4143 if (updating_frame != f)
4151 XFlushQueue (); 4144 XFlush (FRAME_X_DISPLAY (f));
4152 } 4145 }
4153 4146
4154 4147
4155 /* Turn the displayed cursor of frame F on or off according to ON. 4148 /* Turn the displayed cursor of frame F on or off according to ON.
4156 If ON is nonzero, where to put the cursor is specified 4149 If ON is nonzero, where to put the cursor is specified
4208 mouse_face_here = 1; 4201 mouse_face_here = 1;
4209 4202
4210 /* If the font is not as tall as a whole line, 4203 /* If the font is not as tall as a whole line,
4211 we must explicitly clear the line's whole height. */ 4204 we must explicitly clear the line's whole height. */
4212 if (FONT_HEIGHT (f->display.x->font) != f->display.x->line_height) 4205 if (FONT_HEIGHT (f->display.x->font) != f->display.x->line_height)
4213 XClearArea (x_current_display, FRAME_X_WINDOW (f), 4206 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4214 CHAR_TO_PIXEL_COL (f, f->phys_cursor_x), 4207 CHAR_TO_PIXEL_COL (f, f->phys_cursor_x),
4215 CHAR_TO_PIXEL_ROW (f, f->phys_cursor_y), 4208 CHAR_TO_PIXEL_ROW (f, f->phys_cursor_y),
4216 FONT_WIDTH (f->display.x->font), 4209 FONT_WIDTH (f->display.x->font),
4217 f->display.x->line_height, False); 4210 f->display.x->line_height, False);
4218 /* Erase the cursor by redrawing the character underneath it. */ 4211 /* Erase the cursor by redrawing the character underneath it. */
4252 f->phys_cursor_x = curs_x; 4245 f->phys_cursor_x = curs_x;
4253 f->phys_cursor_y = curs_y; 4246 f->phys_cursor_y = curs_y;
4254 } 4247 }
4255 4248
4256 if (updating_frame != f) 4249 if (updating_frame != f)
4257 XFlushQueue (); 4250 XFlush (FRAME_X_DISPLAY (f));
4258 } 4251 }
4259 4252
4260 x_display_cursor (f, on) 4253 x_display_cursor (f, on)
4261 struct frame *f; 4254 struct frame *f;
4262 int on; 4255 int on;
4306 if (STRINGP (file)) 4299 if (STRINGP (file))
4307 bitmap_id = x_create_bitmap_from_file (f, file); 4300 bitmap_id = x_create_bitmap_from_file (f, file);
4308 else 4301 else
4309 { 4302 {
4310 /* Create the GNU bitmap if necessary. */ 4303 /* Create the GNU bitmap if necessary. */
4311 if (!icon_bitmap) 4304 if (!FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id < 0)
4312 icon_bitmap = x_create_bitmap_from_data (f, gnu_bits, 4305 FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id
4313 gnu_width, gnu_height); 4306 = x_create_bitmap_from_data (f, gnu_bits,
4307 gnu_width, gnu_height);
4314 4308
4315 /* The first time we create the GNU bitmap, 4309 /* The first time we create the GNU bitmap,
4316 this increments the refcount one extra time. 4310 this increments the refcount one extra time.
4317 As a result, the GNU bitmap is never freed. 4311 As a result, the GNU bitmap is never freed.
4318 That way, we don't have to worry about allocating it again. */ 4312 That way, we don't have to worry about allocating it again. */
4319 x_reference_bitmap (f, icon_bitmap); 4313 x_reference_bitmap (f, FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id);
4320 4314
4321 bitmap_id = icon_bitmap; 4315 bitmap_id = FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id;
4322 } 4316 }
4323 4317
4324 x_wm_set_icon_pixmap (f, bitmap_id); 4318 x_wm_set_icon_pixmap (f, bitmap_id);
4325 f->display.x->icon_bitmap = bitmap_id; 4319 f->display.x->icon_bitmap = bitmap_id;
4326 4320
4343 else 4337 else
4344 if (! f->display.x->icon_label) 4338 if (! f->display.x->icon_label)
4345 f->display.x->icon_label = " *emacs* "; 4339 f->display.x->icon_label = " *emacs* ";
4346 4340
4347 #if 0 4341 #if 0
4348 XSetIconName (x_current_display, FRAME_X_WINDOW (f), 4342 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4349 (char *) f->display.x->icon_label); 4343 (char *) f->display.x->icon_label);
4350 #endif 4344 #endif
4351 4345
4352 if (f->display.x->icon_bitmap > 0) 4346 if (f->display.x->icon_bitmap > 0)
4353 x_destroy_bitmap (f, f->display.x->icon_bitmap); 4347 x_destroy_bitmap (f, f->display.x->icon_bitmap);
4433 XGetErrorText (display, error->error_code, 4427 XGetErrorText (display, error->error_code,
4434 x_caught_error_message, X_CAUGHT_ERROR_MESSAGE_SIZE); 4428 x_caught_error_message, X_CAUGHT_ERROR_MESSAGE_SIZE);
4435 } 4429 }
4436 4430
4437 4431
4438 /* Begin trapping X errors. 4432 /* Begin trapping X errors for frame F.
4433 Actually we trap X errors for all frames, but F should be the frame
4434 you are actually operating on.
4439 4435
4440 After calling this function, X protocol errors no longer cause 4436 After calling this function, X protocol errors no longer cause
4441 Emacs to exit; instead, they are recorded in x_cfc_error_message. 4437 Emacs to exit; instead, they are recorded in x_cfc_error_message.
4442 4438
4443 Calling x_check_errors signals an Emacs error if an X error has 4439 Calling x_check_errors signals an Emacs error if an X error has
4446 Calling x_uncatch_errors resumes the normal error handling. */ 4442 Calling x_uncatch_errors resumes the normal error handling. */
4447 4443
4448 void x_catch_errors (), x_check_errors (), x_uncatch_errors (); 4444 void x_catch_errors (), x_check_errors (), x_uncatch_errors ();
4449 4445
4450 void 4446 void
4451 x_catch_errors () 4447 x_catch_errors (f)
4448 FRAME_PTR f;
4452 { 4449 {
4453 /* Make sure any errors from previous requests have been dealt with. */ 4450 /* Make sure any errors from previous requests have been dealt with. */
4454 XSync (x_current_display, False); 4451 XSync (FRAME_X_DISPLAY (f), False);
4455 4452
4456 /* Set up the error buffer. */ 4453 /* Set up the error buffer. */
4457 x_caught_error_message 4454 x_caught_error_message
4458 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE); 4455 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE);
4459 x_caught_error_message[0] = '\0'; 4456 x_caught_error_message[0] = '\0';
4460 4457
4461 /* Install our little error handler. */ 4458 /* Install our little error handler. */
4462 XHandleError (x_error_catcher); 4459 XSetErrorHandler (x_error_catcher);
4463 } 4460 }
4464 4461
4465 /* If any X protocol errors have arrived since the last call to 4462 /* If any X protocol errors have arrived since the last call to
4466 x_catch_errors or x_check_errors, signal an Emacs error using 4463 x_catch_errors or x_check_errors, signal an Emacs error using
4467 sprintf (a buffer, FORMAT, the x error message text) as the text. */ 4464 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4468 4465
4469 void 4466 void
4470 x_check_errors (format) 4467 x_check_errors (f, format)
4468 FRAME_PTR f;
4471 char *format; 4469 char *format;
4472 { 4470 {
4473 /* Make sure to catch any errors incurred so far. */ 4471 /* Make sure to catch any errors incurred so far. */
4474 XSync (x_current_display, False); 4472 XSync (FRAME_X_DISPLAY (f), False);
4475 4473
4476 if (x_caught_error_message[0]) 4474 if (x_caught_error_message[0])
4477 { 4475 {
4478 char buf[X_CAUGHT_ERROR_MESSAGE_SIZE + 56]; 4476 char buf[X_CAUGHT_ERROR_MESSAGE_SIZE + 56];
4479 4477
4480 sprintf (buf, format, x_caught_error_message); 4478 sprintf (buf, format, x_caught_error_message);
4481 x_uncatch_errors (); 4479 x_uncatch_errors (f);
4482 error (buf); 4480 error (buf);
4483 } 4481 }
4484 } 4482 }
4485 4483
4486 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */ 4484 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */
4487 4485
4488 int 4486 int
4489 x_had_errors_p () 4487 x_had_errors_p (f)
4488 FRAME_PTR f;
4490 { 4489 {
4491 /* Make sure to catch any errors incurred so far. */ 4490 /* Make sure to catch any errors incurred so far. */
4492 XSync (x_current_display, False); 4491 XSync (FRAME_X_DISPLAY (f), False);
4493 4492
4494 return x_caught_error_message[0] != 0; 4493 return x_caught_error_message[0] != 0;
4495 } 4494 }
4496 4495
4497 /* Stop catching X protocol errors and let them make Emacs die. */ 4496 /* Stop catching X protocol errors and let them make Emacs die. */
4498 4497
4499 void 4498 void
4500 x_uncatch_errors () 4499 x_uncatch_errors (f)
4500 FRAME_PTR f;
4501 { 4501 {
4502 xfree (x_caught_error_message); 4502 xfree (x_caught_error_message);
4503 x_caught_error_message = 0; 4503 x_caught_error_message = 0;
4504 XHandleError (x_error_quitter); 4504 XSetErrorHandler (x_error_quitter);
4505 } 4505 }
4506 4506
4507 #if 0 4507 #if 0
4508 static unsigned int x_wire_count; 4508 static unsigned int x_wire_count;
4509 x_trace_wire () 4509 x_trace_wire ()
4553 char **font_names; 4553 char **font_names;
4554 4554
4555 /* Get a list of all the fonts that match this name. Once we 4555 /* Get a list of all the fonts that match this name. Once we
4556 have a list of matching fonts, we compare them against the fonts 4556 have a list of matching fonts, we compare them against the fonts
4557 we already have by comparing font ids. */ 4557 we already have by comparing font ids. */
4558 font_names = (char **) XListFonts (x_current_display, fontname, 4558 font_names = (char **) XListFonts (FRAME_X_DISPLAY (f), fontname,
4559 1024, &n_matching_fonts); 4559 1024, &n_matching_fonts);
4560 /* Apparently it doesn't set n_matching_fonts to zero when it can't 4560 /* Apparently it doesn't set n_matching_fonts to zero when it can't
4561 find any matches; font_names == 0 is the only clue. */ 4561 find any matches; font_names == 0 is the only clue. */
4562 if (! font_names) 4562 if (! font_names)
4563 n_matching_fonts = 0; 4563 n_matching_fonts = 0;
4606 4606
4607 /* See comment above. */ 4607 /* See comment above. */
4608 if (n_matching_fonts != 0) 4608 if (n_matching_fonts != 0)
4609 fontname = font_names[i]; 4609 fontname = font_names[i];
4610 4610
4611 font = (XFontStruct *) XLoadQueryFont (x_current_display, fontname); 4611 font = (XFontStruct *) XLoadQueryFont (FRAME_X_DISPLAY (f), fontname);
4612 if (! font) 4612 if (! font)
4613 { 4613 {
4614 /* Free the information from XListFonts. */ 4614 /* Free the information from XListFonts. */
4615 if (n_matching_fonts) 4615 if (n_matching_fonts)
4616 XFreeFontNames (font_names); 4616 XFreeFontNames (font_names);
4638 /* Try to get the full name of FONT. Put it in full_name. */ 4638 /* Try to get the full name of FONT. Put it in full_name. */
4639 full_name = 0; 4639 full_name = 0;
4640 for (i = 0; i < font->n_properties; i++) 4640 for (i = 0; i < font->n_properties; i++)
4641 { 4641 {
4642 char *atom 4642 char *atom
4643 = XGetAtomName (x_current_display, font->properties[i].name); 4643 = XGetAtomName (FRAME_X_DISPLAY (f), font->properties[i].name);
4644 if (!strcmp (atom, "FONT")) 4644 if (!strcmp (atom, "FONT"))
4645 { 4645 {
4646 char *name = XGetAtomName (x_current_display, 4646 char *name = XGetAtomName (FRAME_X_DISPLAY (f),
4647 (Atom) (font->properties[i].card32)); 4647 (Atom) (font->properties[i].card32));
4648 char *p = name; 4648 char *p = name;
4649 int dashes = 0; 4649 int dashes = 0;
4650 4650
4651 /* Count the number of dashes in the "full name". 4651 /* Count the number of dashes in the "full name".
4691 f->scroll_bar_cols = 2; 4691 f->scroll_bar_cols = 2;
4692 4692
4693 /* Now make the frame display the given font. */ 4693 /* Now make the frame display the given font. */
4694 if (FRAME_X_WINDOW (f) != 0) 4694 if (FRAME_X_WINDOW (f) != 0)
4695 { 4695 {
4696 XSetFont (x_current_display, f->display.x->normal_gc, 4696 XSetFont (FRAME_X_DISPLAY (f), f->display.x->normal_gc,
4697 f->display.x->font->fid); 4697 f->display.x->font->fid);
4698 XSetFont (x_current_display, f->display.x->reverse_gc, 4698 XSetFont (FRAME_X_DISPLAY (f), f->display.x->reverse_gc,
4699 f->display.x->font->fid); 4699 f->display.x->font->fid);
4700 XSetFont (x_current_display, f->display.x->cursor_gc, 4700 XSetFont (FRAME_X_DISPLAY (f), f->display.x->cursor_gc,
4701 f->display.x->font->fid); 4701 f->display.x->font->fid);
4702 4702
4703 frame_update_line_height (f); 4703 frame_update_line_height (f);
4704 x_set_window_size (f, 0, f->width, f->height); 4704 x_set_window_size (f, 0, f->width, f->height);
4705 } 4705 }
4728 int win_x = 0, win_y = 0; 4728 int win_x = 0, win_y = 0;
4729 int flags = f->display.x->size_hint_flags; 4729 int flags = f->display.x->size_hint_flags;
4730 4730
4731 /* Find the position of the outside upper-left corner of 4731 /* Find the position of the outside upper-left corner of
4732 the inner window, with respect to the outer window. */ 4732 the inner window, with respect to the outer window. */
4733 if (f->display.x->parent_desc != ROOT_WINDOW) 4733 if (f->display.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window)
4734 { 4734 {
4735 BLOCK_INPUT; 4735 BLOCK_INPUT;
4736 XTranslateCoordinates (x_current_display, 4736 XTranslateCoordinates (FRAME_X_DISPLAY (f),
4737 4737
4738 /* From-window, to-window. */ 4738 /* From-window, to-window. */
4739 f->display.x->window_desc, 4739 f->display.x->window_desc,
4740 f->display.x->parent_desc, 4740 f->display.x->parent_desc,
4741 4741
4748 } 4748 }
4749 4749
4750 /* Treat negative positions as relative to the leftmost bottommost 4750 /* Treat negative positions as relative to the leftmost bottommost
4751 position that fits on the screen. */ 4751 position that fits on the screen. */
4752 if (flags & XNegative) 4752 if (flags & XNegative)
4753 f->display.x->left_pos = (x_screen_width 4753 f->display.x->left_pos = (FRAME_X_DISPLAY_INFO (f)->width
4754 - 2 * f->display.x->border_width - win_x 4754 - 2 * f->display.x->border_width - win_x
4755 - PIXEL_WIDTH (f) 4755 - PIXEL_WIDTH (f)
4756 + f->display.x->left_pos); 4756 + f->display.x->left_pos);
4757 4757
4758 if (flags & YNegative) 4758 if (flags & YNegative)
4759 f->display.x->top_pos = (x_screen_height 4759 f->display.x->top_pos = (FRAME_X_DISPLAY_INFO (f)->height
4760 - 2 * f->display.x->border_width - win_y 4760 - 2 * f->display.x->border_width - win_y
4761 - PIXEL_HEIGHT (f) 4761 - PIXEL_HEIGHT (f)
4762 + f->display.x->top_pos); 4762 + f->display.x->top_pos);
4763 /* The left_pos and top_pos 4763 /* The left_pos and top_pos
4764 are now relative to the top and left screen edges, 4764 are now relative to the top and left screen edges,
4791 4791
4792 BLOCK_INPUT; 4792 BLOCK_INPUT;
4793 x_wm_set_size_hint (f, 0, 0); 4793 x_wm_set_size_hint (f, 0, 0);
4794 4794
4795 #ifdef USE_X_TOOLKIT 4795 #ifdef USE_X_TOOLKIT
4796 XMoveWindow (XDISPLAY XtWindow (f->display.x->widget), 4796 XMoveWindow (FRAME_X_DISPLAY (f), XtWindow (f->display.x->widget),
4797 f->display.x->left_pos, f->display.x->top_pos); 4797 f->display.x->left_pos, f->display.x->top_pos);
4798 #else /* not USE_X_TOOLKIT */ 4798 #else /* not USE_X_TOOLKIT */
4799 XMoveWindow (XDISPLAY FRAME_X_WINDOW (f), 4799 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4800 f->display.x->left_pos, f->display.x->top_pos); 4800 f->display.x->left_pos, f->display.x->top_pos);
4801 #endif /* not USE_X_TOOLKIT */ 4801 #endif /* not USE_X_TOOLKIT */
4802 UNBLOCK_INPUT; 4802 UNBLOCK_INPUT;
4803 } 4803 }
4804 4804
4845 pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows); 4845 pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows);
4846 4846
4847 f->display.x->win_gravity = NorthWestGravity; 4847 f->display.x->win_gravity = NorthWestGravity;
4848 x_wm_set_size_hint (f, 0, 0); 4848 x_wm_set_size_hint (f, 0, 0);
4849 4849
4850 XSync (x_current_display, False); 4850 XSync (FRAME_X_DISPLAY (f), False);
4851 XChangeWindowSize (FRAME_X_WINDOW (f), pixelwidth, pixelheight); 4851 XResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4852 pixelwidth, pixelheight);
4852 4853
4853 /* Now, strictly speaking, we can't be sure that this is accurate, 4854 /* Now, strictly speaking, we can't be sure that this is accurate,
4854 but the window manager will get around to dealing with the size 4855 but the window manager will get around to dealing with the size
4855 change request eventually, and we'll hear how it went when the 4856 change request eventually, and we'll hear how it went when the
4856 ConfigureNotify event gets here. 4857 ConfigureNotify event gets here.
4876 receive in the ConfigureNotify event; if we get what we asked 4877 receive in the ConfigureNotify event; if we get what we asked
4877 for, then the event won't cause the screen to become garbaged, so 4878 for, then the event won't cause the screen to become garbaged, so
4878 we have to make sure to do it here. */ 4879 we have to make sure to do it here. */
4879 SET_FRAME_GARBAGED (f); 4880 SET_FRAME_GARBAGED (f);
4880 4881
4881 XFlushQueue (); 4882 XFlush (FRAME_X_DISPLAY (f));
4882 UNBLOCK_INPUT; 4883 UNBLOCK_INPUT;
4883 #endif /* not USE_X_TOOLKIT */ 4884 #endif /* not USE_X_TOOLKIT */
4884 } 4885 }
4885 4886
4886 /* Mouse warping, focus shifting, raising and lowering. */ 4887 /* Mouse warping, focus shifting, raising and lowering. */
4901 if (pix_y < 0) pix_y = 0; 4902 if (pix_y < 0) pix_y = 0;
4902 if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f); 4903 if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f);
4903 4904
4904 BLOCK_INPUT; 4905 BLOCK_INPUT;
4905 4906
4906 XWarpMousePointer (FRAME_X_WINDOW (f), pix_x, pix_y); 4907 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f),
4908 0, 0, 0, 0, pix_x, pix_y);
4907 UNBLOCK_INPUT; 4909 UNBLOCK_INPUT;
4908 } 4910 }
4909 4911
4910 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */ 4912 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
4911 4913
4914 struct frame *f; 4916 struct frame *f;
4915 int pix_x, pix_y; 4917 int pix_x, pix_y;
4916 { 4918 {
4917 BLOCK_INPUT; 4919 BLOCK_INPUT;
4918 4920
4919 XWarpMousePointer (FRAME_X_WINDOW (f), pix_x, pix_y); 4921 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f),
4922 0, 0, 0, 0, pix_x, pix_y);
4920 UNBLOCK_INPUT; 4923 UNBLOCK_INPUT;
4921 } 4924 }
4922 4925
4923 x_focus_on_frame (f) 4926 x_focus_on_frame (f)
4924 struct frame *f; 4927 struct frame *f;
4928 #endif 4931 #endif
4929 #if 0 4932 #if 0
4930 /* I don't think that the ICCCM allows programs to do things like this 4933 /* I don't think that the ICCCM allows programs to do things like this
4931 without the interaction of the window manager. Whatever you end up 4934 without the interaction of the window manager. Whatever you end up
4932 doing with this code, do it to x_unfocus_frame too. */ 4935 doing with this code, do it to x_unfocus_frame too. */
4933 XSetInputFocus (x_current_display, FRAME_X_WINDOW (f), 4936 XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4934 RevertToPointerRoot, CurrentTime); 4937 RevertToPointerRoot, CurrentTime);
4935 #endif /* ! 0 */ 4938 #endif /* ! 0 */
4936 } 4939 }
4937 4940
4938 x_unfocus_frame (f) 4941 x_unfocus_frame (f)
4939 struct frame *f; 4942 struct frame *f;
4940 { 4943 {
4941 #if 0 4944 #if 0
4942 /* Look at the remarks in x_focus_on_frame. */ 4945 /* Look at the remarks in x_focus_on_frame. */
4943 if (x_focus_frame == f) 4946 if (x_focus_frame == f)
4944 XSetInputFocus (x_current_display, PointerRoot, 4947 XSetInputFocus (FRAME_X_DISPLAY (f), PointerRoot,
4945 RevertToPointerRoot, CurrentTime); 4948 RevertToPointerRoot, CurrentTime);
4946 #endif /* ! 0 */ 4949 #endif /* ! 0 */
4947 } 4950 }
4948 4951
4949 /* Raise frame F. */ 4952 /* Raise frame F. */
4953 { 4956 {
4954 if (f->async_visible) 4957 if (f->async_visible)
4955 { 4958 {
4956 BLOCK_INPUT; 4959 BLOCK_INPUT;
4957 #ifdef USE_X_TOOLKIT 4960 #ifdef USE_X_TOOLKIT
4958 XRaiseWindow (XDISPLAY XtWindow (f->display.x->widget)); 4961 XRaiseWindow (FRAME_X_DISPLAY (f), XtWindow (f->display.x->widget));
4959 #else /* not USE_X_TOOLKIT */ 4962 #else /* not USE_X_TOOLKIT */
4960 XRaiseWindow (XDISPLAY FRAME_X_WINDOW (f)); 4963 XRaiseWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
4961 #endif /* not USE_X_TOOLKIT */ 4964 #endif /* not USE_X_TOOLKIT */
4962 XFlushQueue (); 4965 XFlush (FRAME_X_DISPLAY (f));
4963 UNBLOCK_INPUT; 4966 UNBLOCK_INPUT;
4964 } 4967 }
4965 } 4968 }
4966 4969
4967 /* Lower frame F. */ 4970 /* Lower frame F. */
4971 { 4974 {
4972 if (f->async_visible) 4975 if (f->async_visible)
4973 { 4976 {
4974 BLOCK_INPUT; 4977 BLOCK_INPUT;
4975 #ifdef USE_X_TOOLKIT 4978 #ifdef USE_X_TOOLKIT
4976 XLowerWindow (XDISPLAY XtWindow (f->display.x->widget)); 4979 XLowerWindow (FRAME_X_DISPLAY (f), XtWindow (f->display.x->widget));
4977 #else /* not USE_X_TOOLKIT */ 4980 #else /* not USE_X_TOOLKIT */
4978 XLowerWindow (XDISPLAY FRAME_X_WINDOW (f)); 4981 XLowerWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
4979 #endif /* not USE_X_TOOLKIT */ 4982 #endif /* not USE_X_TOOLKIT */
4980 XFlushQueue (); 4983 XFlush (FRAME_X_DISPLAY (f));
4981 UNBLOCK_INPUT; 4984 UNBLOCK_INPUT;
4982 } 4985 }
4983 } 4986 }
4984 4987
4985 static void 4988 static void
5019 x_wm_set_window_state (f, NormalState); 5022 x_wm_set_window_state (f, NormalState);
5020 #ifdef USE_X_TOOLKIT 5023 #ifdef USE_X_TOOLKIT
5021 /* This was XtPopup, but that did nothing for an iconified frame. */ 5024 /* This was XtPopup, but that did nothing for an iconified frame. */
5022 XtMapWidget (f->display.x->widget); 5025 XtMapWidget (f->display.x->widget);
5023 #else /* not USE_X_TOOLKIT */ 5026 #else /* not USE_X_TOOLKIT */
5024 XMapWindow (XDISPLAY FRAME_X_WINDOW (f)); 5027 XMapWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5025 #endif /* not USE_X_TOOLKIT */ 5028 #endif /* not USE_X_TOOLKIT */
5026 #if 0 /* This seems to bring back scroll bars in the wrong places 5029 #if 0 /* This seems to bring back scroll bars in the wrong places
5027 if the window configuration has changed. They seem 5030 if the window configuration has changed. They seem
5028 to come back ok without this. */ 5031 to come back ok without this. */
5029 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) 5032 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
5030 XMapSubwindows (x_current_display, FRAME_X_WINDOW (f)); 5033 XMapSubwindows (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5031 #endif 5034 #endif
5032 } 5035 }
5033 5036
5034 XFlushQueue (); 5037 XFlush (FRAME_X_DISPLAY (f));
5035 5038
5036 /* Synchronize to ensure Emacs knows the frame is visible 5039 /* Synchronize to ensure Emacs knows the frame is visible
5037 before we do anything else. We do this loop with input not blocked 5040 before we do anything else. We do this loop with input not blocked
5038 so that incoming events are handled. */ 5041 so that incoming events are handled. */
5039 { 5042 {
5045 5048
5046 XSETFRAME (frame, f); 5049 XSETFRAME (frame, f);
5047 5050
5048 while (1) 5051 while (1)
5049 { 5052 {
5050 x_sync (frame); 5053 x_sync (f);
5051 /* Once we have handled input events, 5054 /* Once we have handled input events,
5052 we should have received the MapNotify if one is coming. 5055 we should have received the MapNotify if one is coming.
5053 So if we have not got it yet, stop looping. 5056 So if we have not got it yet, stop looping.
5054 Some window managers make their own decisions 5057 Some window managers make their own decisions
5055 about visibility. */ 5058 about visibility. */
5112 by hand again (they have already done that once for this window.) */ 5115 by hand again (they have already done that once for this window.) */
5113 x_wm_set_size_hint (f, 0, 1); 5116 x_wm_set_size_hint (f, 0, 1);
5114 5117
5115 #ifdef HAVE_X11R4 5118 #ifdef HAVE_X11R4
5116 5119
5117 if (! XWithdrawWindow (x_current_display, window, 5120 if (! XWithdrawWindow (FRAME_X_DISPLAY (f), window,
5118 DefaultScreen (x_current_display))) 5121 DefaultScreen (FRAME_X_DISPLAY (f))))
5119 { 5122 {
5120 UNBLOCK_INPUT_RESIGNAL; 5123 UNBLOCK_INPUT_RESIGNAL;
5121 error ("Can't notify window manager of window withdrawal"); 5124 error ("Can't notify window manager of window withdrawal");
5122 } 5125 }
5123 #else /* ! defined (HAVE_X11R4) */ 5126 #else /* ! defined (HAVE_X11R4) */
5127 { 5130 {
5128 XEvent unmap; 5131 XEvent unmap;
5129 5132
5130 unmap.xunmap.type = UnmapNotify; 5133 unmap.xunmap.type = UnmapNotify;
5131 unmap.xunmap.window = window; 5134 unmap.xunmap.window = window;
5132 unmap.xunmap.event = DefaultRootWindow (x_current_display); 5135 unmap.xunmap.event = DefaultRootWindow (FRAME_X_DISPLAY (f));
5133 unmap.xunmap.from_configure = False; 5136 unmap.xunmap.from_configure = False;
5134 if (! XSendEvent (x_current_display, 5137 if (! XSendEvent (FRAME_X_DISPLAY (f),
5135 DefaultRootWindow (x_current_display), 5138 DefaultRootWindow (FRAME_X_DISPLAY (f)),
5136 False, 5139 False,
5137 SubstructureRedirectMask|SubstructureNotifyMask, 5140 SubstructureRedirectMask|SubstructureNotifyMask,
5138 &unmap)) 5141 &unmap))
5139 { 5142 {
5140 UNBLOCK_INPUT_RESIGNAL; 5143 UNBLOCK_INPUT_RESIGNAL;
5141 error ("Can't notify window manager of withdrawal"); 5144 error ("Can't notify window manager of withdrawal");
5142 } 5145 }
5143 } 5146 }
5144 5147
5145 /* Unmap the window ourselves. Cheeky! */ 5148 /* Unmap the window ourselves. Cheeky! */
5146 XUnmapWindow (x_current_display, window); 5149 XUnmapWindow (FRAME_X_DISPLAY (f), window);
5147 #endif /* ! defined (HAVE_X11R4) */ 5150 #endif /* ! defined (HAVE_X11R4) */
5148 5151
5149 /* We can't distinguish this from iconification 5152 /* We can't distinguish this from iconification
5150 just by the event that we get from the server. 5153 just by the event that we get from the server.
5151 So we can't win using the usual strategy of letting 5154 So we can't win using the usual strategy of letting
5154 f->visible = 0; 5157 f->visible = 0;
5155 FRAME_ICONIFIED_P (f) = 0; 5158 FRAME_ICONIFIED_P (f) = 0;
5156 f->async_visible = 0; 5159 f->async_visible = 0;
5157 f->async_iconified = 0; 5160 f->async_iconified = 0;
5158 5161
5159 x_sync (); 5162 x_sync (f);
5160 5163
5161 UNBLOCK_INPUT; 5164 UNBLOCK_INPUT;
5162 } 5165 }
5163 5166
5164 /* Change window state from mapped to iconified. */ 5167 /* Change window state from mapped to iconified. */
5193 XtMapWidget (f->display.x->widget); 5196 XtMapWidget (f->display.x->widget);
5194 UNBLOCK_INPUT; 5197 UNBLOCK_INPUT;
5195 return; 5198 return;
5196 } 5199 }
5197 5200
5198 result = XIconifyWindow (x_current_display, 5201 result = XIconifyWindow (FRAME_X_DISPLAY (f),
5199 XtWindow (f->display.x->widget), 5202 XtWindow (f->display.x->widget),
5200 DefaultScreen (x_current_display)); 5203 DefaultScreen (FRAME_X_DISPLAY (f)));
5201 UNBLOCK_INPUT; 5204 UNBLOCK_INPUT;
5202 5205
5203 if (!result) 5206 if (!result)
5204 error ("Can't notify window manager of iconification"); 5207 error ("Can't notify window manager of iconification");
5205 5208
5206 f->async_iconified = 1; 5209 f->async_iconified = 1;
5207 5210
5208 BLOCK_INPUT; 5211 BLOCK_INPUT;
5209 XFlushQueue (); 5212 XFlush (FRAME_X_DISPLAY (f));
5210 UNBLOCK_INPUT; 5213 UNBLOCK_INPUT;
5211 #else /* not USE_X_TOOLKIT */ 5214 #else /* not USE_X_TOOLKIT */
5212 5215
5213 /* Make sure the X server knows where the window should be positioned, 5216 /* Make sure the X server knows where the window should be positioned,
5214 in case the user deiconifies with the window manager. */ 5217 in case the user deiconifies with the window manager. */
5223 { 5226 {
5224 XEvent message; 5227 XEvent message;
5225 5228
5226 message.xclient.window = FRAME_X_WINDOW (f); 5229 message.xclient.window = FRAME_X_WINDOW (f);
5227 message.xclient.type = ClientMessage; 5230 message.xclient.type = ClientMessage;
5228 message.xclient.message_type = Xatom_wm_change_state; 5231 message.xclient.message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_change_state;
5229 message.xclient.format = 32; 5232 message.xclient.format = 32;
5230 message.xclient.data.l[0] = IconicState; 5233 message.xclient.data.l[0] = IconicState;
5231 5234
5232 if (! XSendEvent (x_current_display, 5235 if (! XSendEvent (FRAME_X_DISPLAY (f),
5233 DefaultRootWindow (x_current_display), 5236 DefaultRootWindow (FRAME_X_DISPLAY (f)),
5234 False, 5237 False,
5235 SubstructureRedirectMask | SubstructureNotifyMask, 5238 SubstructureRedirectMask | SubstructureNotifyMask,
5236 &message)) 5239 &message))
5237 { 5240 {
5238 UNBLOCK_INPUT_RESIGNAL; 5241 UNBLOCK_INPUT_RESIGNAL;
5245 x_wm_set_window_state (f, IconicState); 5248 x_wm_set_window_state (f, IconicState);
5246 5249
5247 if (!FRAME_VISIBLE_P (f)) 5250 if (!FRAME_VISIBLE_P (f))
5248 { 5251 {
5249 /* If the frame was withdrawn, before, we must map it. */ 5252 /* If the frame was withdrawn, before, we must map it. */
5250 XMapWindow (XDISPLAY FRAME_X_WINDOW (f)); 5253 XMapWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5251 #if 0 /* We don't have subwindows in the icon. */ 5254 #if 0 /* We don't have subwindows in the icon. */
5252 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) 5255 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
5253 XMapSubwindows (x_current_display, FRAME_X_WINDOW (f)); 5256 XMapSubwindows (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5254 #endif 5257 #endif
5255 } 5258 }
5256 5259
5257 f->async_iconified = 1; 5260 f->async_iconified = 1;
5258 5261
5259 XFlushQueue (); 5262 XFlush (FRAME_X_DISPLAY (f));
5260 UNBLOCK_INPUT; 5263 UNBLOCK_INPUT;
5261 #endif /* not USE_X_TOOLKIT */ 5264 #endif /* not USE_X_TOOLKIT */
5262 } 5265 }
5263 5266
5264 /* Destroy the X window of frame F. */ 5267 /* Destroy the X window of frame F. */
5267 struct frame *f; 5270 struct frame *f;
5268 { 5271 {
5269 BLOCK_INPUT; 5272 BLOCK_INPUT;
5270 5273
5271 if (f->display.x->icon_desc != 0) 5274 if (f->display.x->icon_desc != 0)
5272 XDestroyWindow (XDISPLAY f->display.x->icon_desc); 5275 XDestroyWindow (FRAME_X_DISPLAY (f), f->display.x->icon_desc);
5273 XDestroyWindow (XDISPLAY f->display.x->window_desc); 5276 XDestroyWindow (FRAME_X_DISPLAY (f), f->display.x->window_desc);
5274 #ifdef USE_X_TOOLKIT 5277 #ifdef USE_X_TOOLKIT
5275 XtDestroyWidget (f->display.x->widget); 5278 XtDestroyWidget (f->display.x->widget);
5276 free_frame_menubar (f); 5279 free_frame_menubar (f);
5277 #endif /* USE_X_TOOLKIT */ 5280 #endif /* USE_X_TOOLKIT */
5278 5281
5279 free_frame_faces (f); 5282 free_frame_faces (f);
5280 XFlushQueue (); 5283 XFlush (FRAME_X_DISPLAY (f));
5281 5284
5282 FRAME_X_SCREEN (f)->reference_count--; 5285 FRAME_X_DISPLAY_INFO (f)->reference_count--;
5283 #if 0 5286 #if 0
5284 if (FRAME_X_SCREEN (f)->reference_count == 0) 5287 if (FRAME_X_DISPLAY_INFO (f)->reference_count == 0)
5285 free (FRAME_X_SCREEN (f)); 5288 free (FRAME_X_DISPLAY_INFO (f));
5286 #endif 5289 #endif
5287 5290
5288 xfree (f->display.x); 5291 xfree (f->display.x);
5289 f->display.x = 0; 5292 f->display.x = 0;
5290 if (f == x_focus_frame) 5293 if (f == x_focus_frame)
5345 size_hints.width = PIXEL_WIDTH (f); 5348 size_hints.width = PIXEL_WIDTH (f);
5346 #endif /* not USE_X_TOOLKIT */ 5349 #endif /* not USE_X_TOOLKIT */
5347 5350
5348 size_hints.width_inc = FONT_WIDTH (f->display.x->font); 5351 size_hints.width_inc = FONT_WIDTH (f->display.x->font);
5349 size_hints.height_inc = f->display.x->line_height; 5352 size_hints.height_inc = f->display.x->line_height;
5350 size_hints.max_width = x_screen_width - CHAR_TO_PIXEL_WIDTH (f, 0); 5353 size_hints.max_width
5351 size_hints.max_height = x_screen_height - CHAR_TO_PIXEL_HEIGHT (f, 0); 5354 = FRAME_X_DISPLAY_INFO (f)->width - CHAR_TO_PIXEL_WIDTH (f, 0);
5355 size_hints.max_height
5356 = FRAME_X_DISPLAY_INFO (f)->height - CHAR_TO_PIXEL_HEIGHT (f, 0);
5352 5357
5353 { 5358 {
5354 int base_width, base_height; 5359 int base_width, base_height;
5355 int min_rows = 0, min_cols = 0; 5360 int min_rows = 0, min_cols = 0;
5356 5361
5388 XSizeHints hints; /* Sometimes I hate X Windows... */ 5393 XSizeHints hints; /* Sometimes I hate X Windows... */
5389 long supplied_return; 5394 long supplied_return;
5390 int value; 5395 int value;
5391 5396
5392 #ifdef HAVE_X11R4 5397 #ifdef HAVE_X11R4
5393 value = XGetWMNormalHints (x_current_display, window, &hints, 5398 value = XGetWMNormalHints (FRAME_X_DISPLAY (f), window, &hints,
5394 &supplied_return); 5399 &supplied_return);
5395 #else 5400 #else
5396 value = XGetNormalHints (x_current_display, window, &hints); 5401 value = XGetNormalHints (FRAME_X_DISPLAY (f), window, &hints);
5397 #endif 5402 #endif
5398 5403
5399 if (value == 0) 5404 if (value == 0)
5400 hints.flags = 0; 5405 hints.flags = 0;
5401 if (hints.flags & PSize) 5406 if (hints.flags & PSize)
5418 size_hints.flags |= USPosition; 5423 size_hints.flags |= USPosition;
5419 } 5424 }
5420 #endif /* PWinGravity */ 5425 #endif /* PWinGravity */
5421 5426
5422 #ifdef HAVE_X11R4 5427 #ifdef HAVE_X11R4
5423 XSetWMNormalHints (x_current_display, window, &size_hints); 5428 XSetWMNormalHints (FRAME_X_DISPLAY (f), window, &size_hints);
5424 #else 5429 #else
5425 XSetNormalHints (x_current_display, window, &size_hints); 5430 XSetNormalHints (FRAME_X_DISPLAY (f), window, &size_hints);
5426 #endif 5431 #endif
5427 } 5432 }
5428 5433
5429 /* Used for IconicState or NormalState */ 5434 /* Used for IconicState or NormalState */
5430 x_wm_set_window_state (f, state) 5435 x_wm_set_window_state (f, state)
5440 Window window = FRAME_X_WINDOW (f); 5445 Window window = FRAME_X_WINDOW (f);
5441 5446
5442 f->display.x->wm_hints.flags |= StateHint; 5447 f->display.x->wm_hints.flags |= StateHint;
5443 f->display.x->wm_hints.initial_state = state; 5448 f->display.x->wm_hints.initial_state = state;
5444 5449
5445 XSetWMHints (x_current_display, window, &f->display.x->wm_hints); 5450 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints);
5446 #endif /* not USE_X_TOOLKIT */ 5451 #endif /* not USE_X_TOOLKIT */
5447 } 5452 }
5448 5453
5449 x_wm_set_icon_pixmap (f, pixmap_id) 5454 x_wm_set_icon_pixmap (f, pixmap_id)
5450 struct frame *f; 5455 struct frame *f;
5466 { 5471 {
5467 f->display.x->wm_hints.icon_pixmap = None; 5472 f->display.x->wm_hints.icon_pixmap = None;
5468 f->display.x->wm_hints.flags &= ~IconPixmapHint; 5473 f->display.x->wm_hints.flags &= ~IconPixmapHint;
5469 } 5474 }
5470 5475
5471 XSetWMHints (x_current_display, window, &f->display.x->wm_hints); 5476 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints);
5472 } 5477 }
5473 5478
5474 x_wm_set_icon_position (f, icon_x, icon_y) 5479 x_wm_set_icon_position (f, icon_x, icon_y)
5475 struct frame *f; 5480 struct frame *f;
5476 int icon_x, icon_y; 5481 int icon_x, icon_y;
5483 5488
5484 f->display.x->wm_hints.flags |= IconPositionHint; 5489 f->display.x->wm_hints.flags |= IconPositionHint;
5485 f->display.x->wm_hints.icon_x = icon_x; 5490 f->display.x->wm_hints.icon_x = icon_x;
5486 f->display.x->wm_hints.icon_y = icon_y; 5491 f->display.x->wm_hints.icon_y = icon_y;
5487 5492
5488 XSetWMHints (x_current_display, window, &f->display.x->wm_hints); 5493 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints);
5489 } 5494 }
5490 5495
5491 5496
5492 /* Initialization. */ 5497 /* Initialization. */
5493 5498
5508 {"-mc", "*pointerColor", XrmoptionSepArg, (XtPointer) NULL}, 5513 {"-mc", "*pointerColor", XrmoptionSepArg, (XtPointer) NULL},
5509 {"-cr", "*cursorColor", XrmoptionSepArg, (XtPointer) NULL} 5514 {"-cr", "*cursorColor", XrmoptionSepArg, (XtPointer) NULL}
5510 }; 5515 };
5511 #endif /* USE_X_TOOLKIT */ 5516 #endif /* USE_X_TOOLKIT */
5512 5517
5513 void 5518 struct x_display_info *
5514 x_term_init (display_name, xrm_option, resource_name) 5519 x_term_init (display_name, xrm_option, resource_name)
5515 char *display_name; 5520 Lisp_Object display_name;
5516 char *xrm_option; 5521 char *xrm_option;
5517 char *resource_name; 5522 char *resource_name;
5518 { 5523 {
5519 Lisp_Object frame; 5524 Lisp_Object frame;
5520 char *defaultvalue; 5525 char *defaultvalue;
5521 int argc = 0; 5526 int argc = 0;
5522 char** argv = 0; 5527 char** argv = 0;
5528 int connection;
5529 struct x_display_info *dpyinfo;
5530 XrmDatabase xrdb;
5531
5523 #ifndef F_SETOWN_BUG 5532 #ifndef F_SETOWN_BUG
5524 #ifdef F_SETOWN 5533 #ifdef F_SETOWN
5525 extern int old_fcntl_owner; 5534 extern int old_fcntl_owner;
5526 #endif /* ! defined (F_SETOWN) */ 5535 #endif /* ! defined (F_SETOWN) */
5527 #endif /* F_SETOWN_BUG */ 5536 #endif /* F_SETOWN_BUG */
5528 5537
5538 dpyinfo = &the_x_screen;
5539
5540 /* Put our one and only display on the chain. */
5541 x_display_list = dpyinfo;
5542 dpyinfo->next = 0;
5543
5544 dpyinfo->name = display_name;
5545
5529 x_noop_count = 0; 5546 x_noop_count = 0;
5530 5547
5531 x_focus_frame = x_highlight_frame = 0; 5548 x_focus_frame = x_highlight_frame = 0;
5532 5549
5533 #ifdef USE_X_TOOLKIT 5550 #ifdef USE_X_TOOLKIT
5536 #endif 5553 #endif
5537 5554
5538 argv = (char **) XtMalloc (7 * sizeof (char *)); 5555 argv = (char **) XtMalloc (7 * sizeof (char *));
5539 argv[0] = ""; 5556 argv[0] = "";
5540 argv[1] = "-display"; 5557 argv[1] = "-display";
5541 argv[2] = display_name; 5558 argv[2] = XSTRING (display_name)->data;
5542 argv[3] = "-name"; 5559 argv[3] = "-name";
5543 /* Usually `emacs', but not always. */ 5560 /* Usually `emacs', but not always. */
5544 argv[4] = resource_name; 5561 argv[4] = resource_name;
5545 argc = 5; 5562 argc = 5;
5546 if (xrm_option) 5563 if (xrm_option)
5551 Xt_app_shell = XtAppInitialize (&Xt_app_con, "Emacs", 5568 Xt_app_shell = XtAppInitialize (&Xt_app_con, "Emacs",
5552 emacs_options, XtNumber (emacs_options), 5569 emacs_options, XtNumber (emacs_options),
5553 &argc, argv, 5570 &argc, argv,
5554 NULL, NULL, 0); 5571 NULL, NULL, 0);
5555 XtFree ((char *)argv); 5572 XtFree ((char *)argv);
5556 x_current_display = XtDisplay (Xt_app_shell); 5573 dpyinfo->display = XtDisplay (Xt_app_shell);
5557 5574
5558 #else /* not USE_X_TOOLKIT */ 5575 #else /* not USE_X_TOOLKIT */
5559 #ifdef HAVE_X11R5 5576 #ifdef HAVE_X11R5
5560 XSetLocaleModifiers (""); 5577 XSetLocaleModifiers ("");
5561 #endif 5578 #endif
5562 x_current_display = XOpenDisplay (display_name); 5579 dpyinfo->display = XOpenDisplay (XSTRING (display_name)->data);
5563 #endif /* not USE_X_TOOLKIT */ 5580 #endif /* not USE_X_TOOLKIT */
5564 if (x_current_display == 0) 5581
5582 if (dpyinfo->display == 0)
5565 fatal ("X server %s not responding.\n\ 5583 fatal ("X server %s not responding.\n\
5566 Check the DISPLAY environment variable or use \"-d\"\n", 5584 Check the DISPLAY environment variable or use \"-d\"\n",
5567 display_name); 5585 XSTRING (display_name)->data);
5568 5586
5569 { 5587 {
5570 #if 0 5588 #if 0
5571 XSetAfterFunction (x_current_display, x_trace_wire); 5589 XSetAfterFunction (x_current_display, x_trace_wire);
5572 #endif /* ! 0 */ 5590 #endif /* ! 0 */
5576 sprintf (x_id_name, "%s@%s", 5594 sprintf (x_id_name, "%s@%s",
5577 XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data); 5595 XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data);
5578 } 5596 }
5579 5597
5580 /* Figure out which modifier bits mean what. */ 5598 /* Figure out which modifier bits mean what. */
5581 x_find_modifier_meanings (); 5599 x_find_modifier_meanings (dpyinfo);
5582 5600
5583 /* Get the scroll bar cursor. */ 5601 /* Get the scroll bar cursor. */
5584 x_vertical_scroll_bar_cursor 5602 x_vertical_scroll_bar_cursor
5585 = XCreateFontCursor (x_current_display, XC_sb_v_double_arrow); 5603 = XCreateFontCursor (dpyinfo->display, XC_sb_v_double_arrow);
5586 5604
5587 #if 0 5605 #if 0
5588 /* Watch for PropertyNotify events on the root window; we use them 5606 /* Watch for PropertyNotify events on the root window; we use them
5589 to figure out when to invalidate our cache of the cut buffers. */ 5607 to figure out when to invalidate our cache of the cut buffers. */
5590 x_watch_cut_buffer_cache (); 5608 x_watch_cut_buffer_cache ();
5591 #endif 5609 #endif
5592 5610
5611 xrdb = x_load_resources (dpyinfo->display, xrm_option,
5612 resource_name, EMACS_CLASS);
5613 #ifdef HAVE_XRMSETDATABASE
5614 XrmSetDatabase (dpyinfo->display, xrdb);
5615 #else
5616 dpyinfo->display->db = xrdb;
5617 #endif
5618
5619 dpyinfo->screen = ScreenOfDisplay (dpyinfo->display,
5620 DefaultScreen (dpyinfo->display));
5621 dpyinfo->visual = select_visual (dpyinfo->display, dpyinfo->screen,
5622 &dpyinfo->n_planes);
5623 dpyinfo->height = HeightOfScreen (dpyinfo->screen);
5624 dpyinfo->width = WidthOfScreen (dpyinfo->screen);
5625 dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen);
5626 dpyinfo->grabbed = 0;
5627 dpyinfo->reference_count = 0;
5628 dpyinfo->icon_bitmap_id = -1;
5629
5630 dpyinfo->Xatom_wm_protocols
5631 = XInternAtom (dpyinfo->display, "WM_PROTOCOLS", False);
5632 dpyinfo->Xatom_wm_take_focus
5633 = XInternAtom (dpyinfo->display, "WM_TAKE_FOCUS", False);
5634 dpyinfo->Xatom_wm_save_yourself
5635 = XInternAtom (dpyinfo->display, "WM_SAVE_YOURSELF", False);
5636 dpyinfo->Xatom_wm_delete_window
5637 = XInternAtom (dpyinfo->display, "WM_DELETE_WINDOW", False);
5638 dpyinfo->Xatom_wm_change_state
5639 = XInternAtom (dpyinfo->display, "WM_CHANGE_STATE", False);
5640 dpyinfo->Xatom_wm_configure_denied
5641 = XInternAtom (dpyinfo->display, "WM_CONFIGURE_DENIED", False);
5642 dpyinfo->Xatom_wm_window_moved
5643 = XInternAtom (dpyinfo->display, "WM_MOVED", False);
5644 dpyinfo->Xatom_editres
5645 = XInternAtom (dpyinfo->display, "Editres", False);
5646 dpyinfo->Xatom_CLIPBOARD
5647 = XInternAtom (dpyinfo->display, "CLIPBOARD", False);
5648 dpyinfo->Xatom_TIMESTAMP
5649 = XInternAtom (dpyinfo->display, "TIMESTAMP", False);
5650 dpyinfo->Xatom_TEXT
5651 = XInternAtom (dpyinfo->display, "TEXT", False);
5652 dpyinfo->Xatom_DELETE
5653 = XInternAtom (dpyinfo->display, "DELETE", False);
5654 dpyinfo->Xatom_MULTIPLE
5655 = XInternAtom (dpyinfo->display, "MULTIPLE", False);
5656 dpyinfo->Xatom_INCR
5657 = XInternAtom (dpyinfo->display, "INCR", False);
5658 dpyinfo->Xatom_EMACS_TMP
5659 = XInternAtom (dpyinfo->display, "_EMACS_TMP_", False);
5660 dpyinfo->Xatom_TARGETS
5661 = XInternAtom (dpyinfo->display, "TARGETS", False);
5662 dpyinfo->Xatom_NULL
5663 = XInternAtom (dpyinfo->display, "NULL", False);
5664 dpyinfo->Xatom_ATOM_PAIR
5665 = XInternAtom (dpyinfo->display, "ATOM_PAIR", False);
5666
5667 connection = ConnectionNumber (dpyinfo->display);
5668 dpyinfo->connection = connection;
5669
5593 #ifdef subprocesses 5670 #ifdef subprocesses
5594 /* This is only needed for distinguishing keyboard and process input. */ 5671 /* This is only needed for distinguishing keyboard and process input. */
5595 if (ConnectionNumber (x_current_display) != 0) 5672 if (connection != 0)
5596 change_keyboard_wait_descriptor (ConnectionNumber (x_current_display)); 5673 change_keyboard_wait_descriptor (connection);
5597 #endif 5674 #endif
5598 change_input_fd (ConnectionNumber (x_current_display)); 5675 change_input_fd (connection);
5599 5676
5600 #ifndef F_SETOWN_BUG 5677 #ifndef F_SETOWN_BUG
5601 #ifdef F_SETOWN 5678 #ifdef F_SETOWN
5602 old_fcntl_owner = fcntl (ConnectionNumber (x_current_display), F_GETOWN, 0); 5679 old_fcntl_owner = fcntl (connection, F_GETOWN, 0);
5603 #ifdef F_SETOWN_SOCK_NEG 5680 #ifdef F_SETOWN_SOCK_NEG
5604 /* stdin is a socket here */ 5681 /* stdin is a socket here */
5605 fcntl (ConnectionNumber (x_current_display), F_SETOWN, -getpid ()); 5682 fcntl (connection, F_SETOWN, -getpid ());
5606 #else /* ! defined (F_SETOWN_SOCK_NEG) */ 5683 #else /* ! defined (F_SETOWN_SOCK_NEG) */
5607 fcntl (ConnectionNumber (x_current_display), F_SETOWN, getpid ()); 5684 fcntl (connection, F_SETOWN, getpid ());
5608 #endif /* ! defined (F_SETOWN_SOCK_NEG) */ 5685 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
5609 #endif /* ! defined (F_SETOWN) */ 5686 #endif /* ! defined (F_SETOWN) */
5610 #endif /* F_SETOWN_BUG */ 5687 #endif /* F_SETOWN_BUG */
5611 5688
5612 #ifdef SIGIO 5689 #ifdef SIGIO
5651 /* Try to use interrupt input; if we can't, then start polling. */ 5728 /* Try to use interrupt input; if we can't, then start polling. */
5652 Fset_input_mode (Qt, Qnil, Qt, Qnil); 5729 Fset_input_mode (Qt, Qnil, Qt, Qnil);
5653 5730
5654 /* Note that there is no real way portable across R3/R4 to get the 5731 /* Note that there is no real way portable across R3/R4 to get the
5655 original error handler. */ 5732 original error handler. */
5656 XHandleError (x_error_quitter); 5733 XSetErrorHandler (x_error_quitter);
5657 XHandleIOError (x_io_error_quitter); 5734 XSetIOErrorHandler (x_io_error_quitter);
5658 5735
5659 /* Disable Window Change signals; they are handled by X events. */ 5736 /* Disable Window Change signals; they are handled by X events. */
5660 #ifdef SIGWINCH 5737 #ifdef SIGWINCH
5661 signal (SIGWINCH, SIG_DFL); 5738 signal (SIGWINCH, SIG_DFL);
5662 #endif /* ! defined (SIGWINCH) */ 5739 #endif /* ! defined (SIGWINCH) */
5665 } 5742 }
5666 5743
5667 void 5744 void
5668 syms_of_xterm () 5745 syms_of_xterm ()
5669 { 5746 {
5747 the_x_screen.font_list_cache = Qnil;
5748 the_x_screen.name = Qnil;
5749 staticpro (&the_x_screen.font_list_cache);
5750 staticpro (&the_x_screen.name);
5751
5670 staticpro (&last_mouse_scroll_bar); 5752 staticpro (&last_mouse_scroll_bar);
5671 last_mouse_scroll_bar = Qnil; 5753 last_mouse_scroll_bar = Qnil;
5672 staticpro (&mouse_face_window); 5754 staticpro (&mouse_face_window);
5673 mouse_face_window = Qnil; 5755 mouse_face_window = Qnil;
5674 } 5756 }