4 * Copyright (c) 1997 Ben Harrison, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
14 * ÆüËܸì(EUC-JAPAN)Âбþ (-DJP)
15 * ¡¦´Á»ú¥Õ¥©¥ó¥È¤Î°·¤¤¤òÄɲÃ
16 * ¡¦ÆüËܸì¤ò´Þ¤àʸ»úÎó¤Îɽ¼¨¥ë¡¼¥Á¥ó XDrawMultiString() ¤ÎÄɲÃ
17 * ¡¦ÆüËܸì¤Îɽ¼¨Éý¤Ï¡¤¥Õ¥©¥ó¥È¤Î¾ðÊó¤Ë¤è¤é¤¹ASCII¥Õ¥©¥ó¥È¤Î2Çܤ˸ÇÄê
22 * 1996/6/7 Íû ¹¸¿ (ri@kuis.kyoto-u.ac.jp)
26 * This file helps Angband work with UNIX/X11 computers.
28 * To use this file, compile with "USE_X11" defined, and link against all
29 * the various "X11" libraries which may be needed.
31 * See also "main-xaw.c".
33 * Part of this file provides a user interface package composed of several
34 * pseudo-objects, including "metadpy" (a display), "infowin" (a window),
35 * "infoclr" (a color), and "infofnt" (a font). Actually, the package was
36 * originally much more interesting, but it was bastardized to keep this
39 * The rest of this file is an implementation of "main-xxx.c" for X11.
41 * Most of this file is by Ben Harrison (benh@phial.com).
45 * The following shell script can be used to launch Angband, assuming that
46 * it was extracted into "~/Angband", and compiled using "USE_X11", on a
47 * Linux machine, with a 1280x1024 screen, using 6 windows (with the given
48 * characteristics), with gamma correction of 1.8 -> (1 / 1.8) * 256 = 142,
49 * and without graphics (add "-g" for graphics). Just copy this comment
50 * into a file, remove the leading " * " characters (and the head/tail of
51 * this comment), and make the file executable.
57 * echo "Launching angband..."
61 * setenv ANGBAND_X11_FONT_0 10x20
62 * setenv ANGBAND_X11_AT_X_0 5
63 * setenv ANGBAND_X11_AT_Y_0 510
66 * setenv ANGBAND_X11_FONT_1 8x13
67 * setenv ANGBAND_X11_AT_X_1 5
68 * setenv ANGBAND_X11_AT_Y_1 22
69 * setenv ANGBAND_X11_ROWS_1 35
72 * setenv ANGBAND_X11_FONT_2 8x13
73 * setenv ANGBAND_X11_AT_X_2 635
74 * setenv ANGBAND_X11_AT_Y_2 182
75 * setenv ANGBAND_X11_ROWS_3 23
78 * setenv ANGBAND_X11_FONT_3 8x13
79 * setenv ANGBAND_X11_AT_X_3 635
80 * setenv ANGBAND_X11_AT_Y_3 22
81 * setenv ANGBAND_X11_ROWS_3 12
83 * # Monster recall window
84 * setenv ANGBAND_X11_FONT_4 6x13
85 * setenv ANGBAND_X11_AT_X_4 817
86 * setenv ANGBAND_X11_AT_Y_4 847
87 * setenv ANGBAND_X11_COLS_4 76
88 * setenv ANGBAND_X11_ROWS_4 11
90 * # Object recall window
91 * setenv ANGBAND_X11_FONT_5 6x13
92 * setenv ANGBAND_X11_AT_X_5 817
93 * setenv ANGBAND_X11_AT_Y_5 520
94 * setenv ANGBAND_X11_COLS_5 76
95 * setenv ANGBAND_X11_ROWS_5 24
97 * # The build directory
101 * setenv ANGBAND_X11_GAMMA 142
104 * ./src/angband -mx11 -- -n6 &
115 #ifndef __MAKEDEPEND__
116 #include <X11/Xlib.h>
117 #include <X11/Xutil.h>
118 #include <X11/keysym.h>
119 #include <X11/keysymdef.h>
121 #include <X11/Xlocale.h>
124 char *XSetIMValues(XIM, ...); /* Hack for XFree86 4.0 */
126 #endif /* __MAKEDEPEND__ */
130 * Include some helpful X11 code.
132 #include "maid-x11.c"
136 * Hack -- avoid some compiler warnings
138 #define IGNORE_UNUSED_FUNCTIONS
144 * 1) On a monochrome (or "fake-monochrome") display, all colors
145 * will be "cast" to "fg," except for the bg color, which is,
146 * obviously, cast to "bg". Thus, one can ignore this setting.
148 * 2) Because of the inner functioning of the color allocation
149 * routines, colors may be specified as (a) a typical color name,
150 * (b) a hexidecimal color specification (preceded by a pound sign),
151 * or (c) by strings such as "fg", "bg", "zg".
153 * 3) Due to the workings of the init routines, many colors
154 * may also be dealt with by their actual pixel values. Note that
155 * the pixel with all bits set is "zg = (1<<metadpy->depth)-1", which
156 * is not necessarily either black or white.
161 /**** Generic Types ****/
165 * An X11 pixell specifier
167 typedef unsigned long Pixell;
170 * The structures defined below
172 typedef struct metadpy metadpy;
173 typedef struct infowin infowin;
174 typedef struct infoclr infoclr;
175 typedef struct infofnt infofnt;
179 * A structure summarizing a given Display.
181 * - The Display itself
182 * - The default Screen for the display
183 * - The virtual root (usually just the root)
184 * - The default colormap (from a macro)
186 * - The "name" of the display
188 * - The socket to listen to for events
190 * - The width of the display screen (from a macro)
191 * - The height of the display screen (from a macro)
192 * - The bit depth of the display screen (from a macro)
194 * - The black Pixell (from a macro)
195 * - The white Pixell (from a macro)
197 * - The background Pixell (default: black)
198 * - The foreground Pixell (default: white)
199 * - The maximal Pixell (Equals: ((2 ^ depth)-1), is usually ugly)
201 * - Bit Flag: Force all colors to black and white (default: !color)
202 * - Bit Flag: Allow the use of color (default: depth > 1)
203 * - Bit Flag: We created 'dpy', and so should nuke it when done.
238 * A Structure summarizing Window Information.
240 * I assume that a window is at most 30000 pixels on a side.
241 * I assume that the root windw is also at most 30000 square.
244 * - The current Input Event Mask
246 * - The location of the window
247 * - The width, height of the window
248 * - The border width of this window
250 * - Byte: 1st Extra byte
252 * - Bit Flag: This window is currently Mapped
253 * - Bit Flag: This window needs to be redrawn
254 * - Bit Flag: This window has been resized
256 * - Bit Flag: We should nuke 'win' when done with it
258 * - Bit Flag: 1st extra flag
259 * - Bit Flag: 2nd extra flag
260 * - Bit Flag: 3rd extra flag
261 * - Bit Flag: 4th extra flag
299 * A Structure summarizing Operation+Color Information
301 * - The actual GC corresponding to this info
303 * - The Foreground Pixell Value
304 * - The Background Pixell Value
306 * - Num (0-15): The operation code (As in Clear, Xor, etc)
307 * - Bit Flag: The GC is in stipple mode
308 * - Bit Flag: Destroy 'gc' at Nuke time.
325 * A Structure to Hold Font Information
327 * - The 'XFontStruct*' (yields the 'Font')
331 * - The default character width
332 * - The default character height
333 * - The default character ascent
335 * - Byte: Pixel offset used during fake mono
337 * - Flag: Force monospacing via 'wid'
338 * - Flag: Nuke info when done
363 /**** Generic Macros ****/
367 /* Set current metadpy (Metadpy) to 'M' */
368 #define Metadpy_set(M) \
372 /* Initialize 'M' using Display 'D' */
373 #define Metadpy_init_dpy(D) \
374 Metadpy_init_2(D,cNULL)
376 /* Initialize 'M' using a Display named 'N' */
377 #define Metadpy_init_name(N) \
378 Metadpy_init_2((Display*)(NULL),N)
380 /* Initialize 'M' using the standard Display */
381 #define Metadpy_init() \
382 Metadpy_init_name("")
385 /* Init an infowin by giving father as an (info_win*) (or NULL), and data */
386 #define Infowin_init_dad(D,X,Y,W,H,B,FG,BG) \
387 Infowin_init_data(((D) ? ((D)->win) : (Window)(None)), \
391 /* Init a top level infowin by pos,size,bord,Colors */
392 #define Infowin_init_top(X,Y,W,H,B,FG,BG) \
393 Infowin_init_data(None,X,Y,W,H,B,FG,BG)
396 /* Request a new standard window by giving Dad infowin and X,Y,W,H */
397 #define Infowin_init_std(D,X,Y,W,H,B) \
398 Infowin_init_dad(D,X,Y,W,H,B,Metadpy->fg,Metadpy->bg)
401 /* Set the current Infowin */
402 #define Infowin_set(I) \
406 /* Set the current Infoclr */
407 #define Infoclr_set(C) \
411 #define Infoclr_init_ppo(F,B,O,M) \
412 Infoclr_init_data(F,B,O,M)
414 #define Infoclr_init_cco(F,B,O,M) \
415 Infoclr_init_ppo(Infoclr_Pixell(F),Infoclr_Pixell(B),O,M)
417 #define Infoclr_init_ppn(F,B,O,M) \
418 Infoclr_init_ppo(F,B,Infoclr_Opcode(O),M)
420 #define Infoclr_init_ccn(F,B,O,M) \
421 Infoclr_init_cco(F,B,Infoclr_Opcode(O),M)
424 /* Set the current infofnt */
425 #define Infofnt_set(I) \
429 /* Errr: Expose Infowin */
430 #define Infowin_expose() \
431 (!(Infowin->redraw = 1))
433 /* Errr: Unxpose Infowin */
434 #define Infowin_unexpose() \
435 (Infowin->redraw = 0)
439 /**** Generic Globals ****/
443 * The "default" values
445 static metadpy metadpy_default;
449 * The "current" variables
451 static metadpy *Metadpy = &metadpy_default;
452 static infowin *Infowin = (infowin*)(NULL);
454 static infowin *Focuswin = (infowin*)(NULL);
456 static infoclr *Infoclr = (infoclr*)(NULL);
458 static infofnt *Infofnt = (infofnt*)(NULL);
459 static infofnt *Infokfnt = (infofnt*)(NULL);
461 static infofnt *Infofnt = (infofnt*)(NULL);
467 /**** Generic code ****/
471 #define Infokfnt_set(I) \
475 * Init the current metadpy, with various initialization stuff.
478 * dpy: The Display* to use (if NULL, create it)
479 * name: The name of the Display (if NULL, the current)
482 * If 'name' is NULL, but 'dpy' is set, extract name from dpy
483 * If 'dpy' is NULL, then Create the named Display
484 * If 'name' is NULL, and so is 'dpy', use current Display
486 * Return -1 if no Display given, and none can be opened.
488 static errr Metadpy_init_2(Display *dpy, cptr name)
490 metadpy *m = Metadpy;
492 /*** Open the display if needed ***/
494 /* If no Display given, attempt to Create one */
497 /* Attempt to open the display */
498 dpy = XOpenDisplay(name);
501 if (!dpy) return (-1);
503 /* We will have to nuke it when done */
507 /* Since the Display was given, use it */
510 /* We will not have to nuke it when done */
515 /*** Save some information ***/
517 /* Save the Display itself */
520 /* Get the Screen and Virtual Root Window */
521 m->screen = DefaultScreenOfDisplay(dpy);
522 m->root = RootWindowOfScreen(m->screen);
524 /* Get the default colormap */
525 m->cmap = DefaultColormapOfScreen(m->screen);
527 /* Extract the true name of the display */
528 m->name = DisplayString(dpy);
531 m->fd = ConnectionNumber(Metadpy->dpy);
533 /* Save the Size and Depth of the screen */
534 m->width = WidthOfScreen(m->screen);
535 m->height = HeightOfScreen(m->screen);
536 m->depth = DefaultDepthOfScreen(m->screen);
538 /* Save the Standard Colors */
539 m->black = BlackPixelOfScreen(m->screen);
540 m->white = WhitePixelOfScreen(m->screen);
542 /*** Make some clever Guesses ***/
544 /* Guess at the desired 'fg' and 'bg' Pixell's */
548 /* Calculate the Maximum allowed Pixel value. */
549 m->zg = (1 << m->depth) - 1;
551 /* Save various default Flag Settings */
552 m->color = ((m->depth > 1) ? 1 : 0);
553 m->mono = ((m->color) ? 0 : 1);
555 /* Return "success" */
560 #ifndef IGNORE_UNUSED_FUNCTIONS
563 * Nuke the current metadpy
565 static errr Metadpy_nuke(void)
567 metadpy *m = Metadpy;
570 /* If required, Free the Display */
573 /* Close the Display */
574 XCloseDisplay(m->dpy);
576 /* Forget the Display */
577 m->dpy = (Display*)(NULL);
579 /* Do not nuke it again */
587 #endif /* IGNORE_UNUSED_FUNCTIONS */
591 * General Flush/ Sync/ Discard routine
593 static errr Metadpy_update(int flush, int sync, int discard)
595 /* Flush if desired */
596 if (flush) XFlush(Metadpy->dpy);
598 /* Sync if desired, using 'discard' */
599 if (sync) XSync(Metadpy->dpy, discard);
609 static errr Metadpy_do_beep(void)
611 /* Make a simple beep */
612 XBell(Metadpy->dpy, 100);
620 * Set the name (in the title bar) of Infowin
622 static errr Infowin_set_name(cptr name)
629 st = XStringListToTextProperty(&bp, 1, &tp);
630 if (st) XSetWMName(Metadpy->dpy, Infowin->win, &tp);
635 #ifndef IGNORE_UNUSED_FUNCTIONS
638 * Set the icon name of Infowin
640 static errr Infowin_set_icon_name(cptr name)
647 st = XStringListToTextProperty(&bp, 1, &tp);
648 if (st) XSetWMIconName(Metadpy->dpy, Infowin->win, &tp);
656 static errr Infowin_nuke(void)
658 infowin *iwin = Infowin;
660 /* Nuke if requested */
663 /* Destory the old window */
664 XDestroyWindow(Metadpy->dpy, iwin->win);
671 #endif /* IGNORE_UNUSED_FUNCTIONS */
675 * Prepare a new 'infowin'.
677 static errr Infowin_prepare(Window xid)
679 infowin *iwin = Infowin;
682 XWindowAttributes xwa;
684 unsigned int w, h, b, d;
689 /* Check For Error XXX Extract some ACTUAL data from 'xid' */
690 XGetGeometry(Metadpy->dpy, xid, &tmp_win, &x, &y, &w, &h, &b, &d);
692 /* Apply the above info */
699 /* Check Error XXX Extract some more ACTUAL data */
700 XGetWindowAttributes(Metadpy->dpy, xid, &xwa);
702 /* Apply the above info */
703 iwin->mask = xwa.your_event_mask;
704 iwin->mapped = ((xwa.map_state == IsUnmapped) ? 0 : 1);
706 /* And assume that we are exposed */
714 #ifndef IGNORE_UNUSED_FUNCTIONS
717 * Initialize a new 'infowin'.
719 static errr Infowin_init_real(Window xid)
722 (void)WIPE(Infowin, infowin);
724 /* Start out non-nukable */
727 /* Attempt to Prepare ourself */
728 return (Infowin_prepare(xid));
731 #endif /* IGNORE_UNUSED_FUNCTIONS */
735 * Init an infowin by giving some data.
738 * dad: The Window that should own this Window (if any)
739 * x,y: The position of this Window
740 * w,h: The size of this Window
741 * b,d: The border width and pixel depth
744 * If 'dad == None' assume 'dad == root'
746 static errr Infowin_init_data(Window dad, int x, int y, int w, int h,
747 int b, Pixell fg, Pixell bg)
752 (void)WIPE(Infowin, infowin);
755 /*** Error Check XXX ***/
758 /*** Create the Window 'xid' from data ***/
760 /* What happened here? XXX XXX XXX */
762 /* If no parent given, depend on root */
765 /* #ifdef USE_GRAPHICS
767 xid = XCreateWindow(Metadpy->dpy, Metadpy->root, x, y, w, h, b, 8, InputOutput, CopyFromParent, 0, 0);
778 /* Create the Window XXX Error Check */
779 xid = XCreateSimpleWindow(Metadpy->dpy, dad, x, y, w, h, b, fg, bg);
781 /* Start out selecting No events */
782 XSelectInput(Metadpy->dpy, xid, 0L);
785 /*** Prepare the new infowin ***/
787 /* Mark it as nukable */
790 /* Attempt to Initialize the infowin */
791 return (Infowin_prepare(xid));
797 * Modify the event mask of an Infowin
799 static errr Infowin_set_mask(long mask)
801 /* Save the new setting */
802 Infowin->mask = mask;
804 /* Execute the Mapping */
805 XSelectInput(Metadpy->dpy, Infowin->win, Infowin->mask);
813 * Request that Infowin be mapped
815 static errr Infowin_map(void)
817 /* Execute the Mapping */
818 XMapWindow(Metadpy->dpy, Infowin->win);
825 #ifndef IGNORE_UNUSED_FUNCTIONS
828 * Request that Infowin be unmapped
830 static errr Infowin_unmap(void)
832 /* Execute the Un-Mapping */
833 XUnmapWindow(Metadpy->dpy, Infowin->win);
839 #endif /* IGNORE_UNUSED_FUNCTIONS */
843 * Request that Infowin be raised
845 static errr Infowin_raise(void)
847 /* Raise towards visibility */
848 XRaiseWindow(Metadpy->dpy, Infowin->win);
855 #ifndef IGNORE_UNUSED_FUNCTIONS
858 * Request that Infowin be lowered
860 static errr Infowin_lower(void)
862 /* Lower towards invisibility */
863 XLowerWindow(Metadpy->dpy, Infowin->win);
869 #endif /* IGNORE_UNUSED_FUNCTIONS */
873 * Request that Infowin be moved to a new location
875 static errr Infowin_impell(int x, int y)
877 /* Execute the request */
878 XMoveWindow(Metadpy->dpy, Infowin->win, x, y);
888 static errr Infowin_resize(int w, int h)
890 /* Execute the request */
891 XResizeWindow(Metadpy->dpy, Infowin->win, w, h);
898 #ifndef IGNORE_UNUSED_FUNCTIONS
901 * Move and Resize an infowin
903 static errr Infowin_locate(int x, int y, int w, int h)
905 /* Execute the request */
906 XMoveResizeWindow(Metadpy->dpy, Infowin->win, x, y, w, h);
912 #endif /* IGNORE_UNUSED_FUNCTIONS */
916 * Visually clear Infowin
918 static errr Infowin_wipe(void)
920 /* Execute the request */
921 XClearWindow(Metadpy->dpy, Infowin->win);
928 #ifndef IGNORE_UNUSED_FUNCTIONS
931 * Visually Paint Infowin with the current color
933 static errr Infowin_fill(void)
935 /* Execute the request */
936 XFillRectangle(Metadpy->dpy, Infowin->win, Infoclr->gc,
937 0, 0, Infowin->w, Infowin->h);
943 #endif /* IGNORE_UNUSED_FUNCTIONS */
947 * A NULL terminated pair list of legal "operation names"
949 * Pairs of values, first is texttual name, second is the string
950 * holding the decimal value that the operation corresponds to.
952 static cptr opcode_pairs[] =
971 "+copyInverted", "12",
979 * Parse a word into an operation "code"
982 * str: A string, hopefully representing an Operation
985 * 0-15: if 'str' is a valid Operation
986 * -1: if 'str' could not be parsed
988 static int Infoclr_Opcode(cptr str)
992 /* Scan through all legal operation names */
993 for (i = 0; opcode_pairs[i*2]; ++i)
995 /* Is this the right oprname? */
996 if (streq(opcode_pairs[i*2], str))
998 /* Convert the second element in the pair into a Code */
999 return (atoi(opcode_pairs[i*2+1]));
1003 /* The code was not found, return -1 */
1008 #ifndef IGNORE_UNUSED_FUNCTIONS
1011 * Request a Pixell by name. Note: uses 'Metadpy'.
1014 * name: The name of the color to try to load (see below)
1017 * The Pixell value that metched the given name
1018 * 'Metadpy->fg' if the name was unparseable
1020 * Valid forms for 'name':
1021 * 'fg', 'bg', 'zg', '<name>' and '#<code>'
1023 static Pixell Infoclr_Pixell(cptr name)
1027 /* Attempt to Parse the name */
1028 if (name && name[0])
1030 /* The 'bg' color is available */
1031 if (streq(name, "bg")) return (Metadpy->bg);
1033 /* The 'fg' color is available */
1034 if (streq(name, "fg")) return (Metadpy->fg);
1036 /* The 'zg' color is available */
1037 if (streq(name, "zg")) return (Metadpy->zg);
1039 /* The 'white' color is available */
1040 if (streq(name, "white")) return (Metadpy->white);
1042 /* The 'black' color is available */
1043 if (streq(name, "black")) return (Metadpy->black);
1045 /* Attempt to parse 'name' into 'scrn' */
1046 if (!(XParseColor(Metadpy->dpy, Metadpy->cmap, name, &scrn)))
1048 plog_fmt("Warning: Couldn't parse color '%s'\n", name);
1051 /* Attempt to Allocate the Parsed color */
1052 if (!(XAllocColor(Metadpy->dpy, Metadpy->cmap, &scrn)))
1054 plog_fmt("Warning: Couldn't allocate color '%s'\n", name);
1057 /* The Pixel was Allocated correctly */
1058 else return (scrn.pixel);
1061 /* Warn about the Default being Used */
1062 plog_fmt("Warning: Using 'fg' for unknown color '%s'\n", name);
1064 /* Default to the 'Foreground' color */
1065 return (Metadpy->fg);
1070 * Initialize a new 'infoclr' with a real GC.
1072 static errr Infoclr_init_1(GC gc)
1074 infoclr *iclr = Infoclr;
1076 /* Wipe the iclr clean */
1077 (void)WIPE(iclr, infoclr);
1088 * Nuke an old 'infoclr'.
1090 static errr Infoclr_nuke(void)
1092 infoclr *iclr = Infoclr;
1094 /* Deal with 'GC' */
1098 XFreeGC(Metadpy->dpy, iclr->gc);
1101 /* Forget the current */
1102 Infoclr = (infoclr*)(NULL);
1108 #endif /* IGNORE_UNUSED_FUNCTIONS */
1112 * Initialize an infoclr with some data
1115 * fg: The Pixell for the requested Foreground (see above)
1116 * bg: The Pixell for the requested Background (see above)
1117 * op: The Opcode for the requested Operation (see above)
1118 * stip: The stipple mode
1120 static errr Infoclr_init_data(Pixell fg, Pixell bg, int op, int stip)
1122 infoclr *iclr = Infoclr;
1126 unsigned long gc_mask;
1130 /*** Simple error checking of opr and clr ***/
1132 /* Check the 'Pixells' for realism */
1133 if (bg > Metadpy->zg) return (-1);
1134 if (fg > Metadpy->zg) return (-1);
1136 /* Check the data for trueness */
1137 if ((op < 0) || (op > 15)) return (-1);
1140 /*** Create the requested 'GC' ***/
1142 /* Assign the proper GC function */
1145 /* Assign the proper GC background */
1146 gcv.background = bg;
1148 /* Assign the proper GC foreground */
1149 gcv.foreground = fg;
1151 /* Hack -- Handle XOR (xor is code 6) by hacking bg and fg */
1152 if (op == 6) gcv.background = 0;
1153 if (op == 6) gcv.foreground = (bg ^ fg);
1155 /* Assign the proper GC Fill Style */
1156 gcv.fill_style = (stip ? FillStippled : FillSolid);
1158 /* Turn off 'Give exposure events for pixmap copying' */
1159 gcv.graphics_exposures = False;
1161 /* Set up the GC mask */
1162 gc_mask = (GCFunction | GCBackground | GCForeground |
1163 GCFillStyle | GCGraphicsExposures);
1165 /* Create the GC detailed above */
1166 gc = XCreateGC(Metadpy->dpy, Metadpy->root, gc_mask, &gcv);
1169 /*** Initialize ***/
1171 /* Wipe the iclr clean */
1172 (void)WIPE(iclr, infoclr);
1177 /* Nuke it when done */
1180 /* Assign the parms */
1184 iclr->stip = stip ? 1 : 0;
1193 * Change the 'fg' for an infoclr
1196 * fg: The Pixell for the requested Foreground (see above)
1198 static errr Infoclr_change_fg(Pixell fg)
1200 infoclr *iclr = Infoclr;
1203 /*** Simple error checking of opr and clr ***/
1205 /* Check the 'Pixells' for realism */
1206 if (fg > Metadpy->zg) return (-1);
1212 XSetForeground(Metadpy->dpy, iclr->gc, fg);
1220 #ifndef IGNORE_UNUSED_FUNCTIONS
1223 * Nuke an old 'infofnt'.
1225 static errr Infofnt_nuke(void)
1227 infofnt *ifnt = Infofnt;
1230 infofnt *ikfnt = Infokfnt;
1232 /* Deal with 'name' */
1236 string_free(ifnt->name);
1243 string_free(ikfnt->name);
1246 /* Nuke info if needed */
1250 XFreeFont(Metadpy->dpy, ifnt->info);
1257 XFreeFont(Metadpy->dpy, ikfnt->info);
1264 #endif /* IGNORE_UNUSED_FUNCTIONS */
1268 * Prepare a new 'infofnt'
1271 static errr Infofnt_prepare(XFontStruct *info, XFontStruct *kinfo)
1274 static errr Infofnt_prepare(XFontSet info)
1276 static errr Infofnt_prepare(XFontStruct *info)
1281 infofnt *ifnt = Infofnt;
1284 infofnt *ikfnt = Infokfnt;
1288 XFontStruct **fontinfo;
1291 int ascent, descent, width;
1294 /* Assign the struct */
1298 n_fonts = XFontsOfFontSet(info, &fontinfo, &fontname);
1300 ascent = descent = width = 0;
1301 while(n_fonts-- > 0){
1302 cs = &((*fontinfo)->max_bounds);
1303 if(ascent < (*fontinfo)->ascent) ascent = (*fontinfo)->ascent;
1304 if(descent < (*fontinfo)->descent) descent = (*fontinfo)->descent;
1305 if(((*fontinfo)->max_byte1) > 0){
1306 /* ¿¥Ð¥¤¥Èʸ»ú¤Î¾ì¹ç¤ÏÉýȾʬ(ü¿ôÀÚ¤ê¾å¤²)¤Çɾ²Á¤¹¤ë */
1307 if(width < (cs->width+1)/2) width = (cs->width+1)/2;
1309 if(width < cs->width) width = cs->width;
1315 ifnt->hgt = ascent + descent;
1318 /* Jump into the max bouonds thing */
1319 cs = &(info->max_bounds);
1321 /* Extract default sizing info */
1322 ifnt->asc = info->ascent;
1323 ifnt->hgt = info->ascent + info->descent;
1324 ifnt->wid = cs->width;
1328 /* Assign the struct */
1329 ikfnt->info = kinfo;
1331 /* Jump into the max bouonds thing */
1332 cs = &(kinfo->max_bounds);
1334 /* Extract default sizing info */
1335 ikfnt->asc = kinfo->ascent;
1336 ikfnt->hgt = kinfo->ascent + kinfo->descent;
1337 ikfnt->wid = cs->width;
1340 #ifdef OBSOLETE_SIZING_METHOD
1341 /* Extract default sizing info */
1342 ifnt->asc = cs->ascent;
1343 ifnt->hgt = (cs->ascent + cs->descent);
1344 ifnt->wid = cs->width;
1353 #ifndef IGNORE_UNUSED_FUNCTIONS
1356 * Initialize a new 'infofnt'.
1359 static errr Infofnt_init_real(XFontStruct *info, XFontStruct *kinfo)
1362 static errr Infofnt_init_real(XFontSet info)
1364 static errr Infofnt_init_real(XFontStruct *info)
1369 /* Wipe the thing */
1370 (void)WIPE(Infofnt, infofnt);
1373 WIPE(Infokfnt, infofnt);
1381 /* Attempt to prepare it */
1383 return (Infofnt_prepare (info, kinfo));
1385 return (Infofnt_prepare(info));
1390 #endif /* IGNORE_UNUSED_FUNCTIONS */
1394 * Init an infofnt by its Name
1397 * name: The name of the requested Font
1400 static errr Infofnt_init_data(cptr name, cptr kname)
1402 static errr Infofnt_init_data(cptr name)
1408 char **missing_list;
1419 /*** Load the info Fresh, using the name ***/
1421 /* If the name is not given, report an error */
1422 if (!name) return (-1);
1425 if (!kname) return (-1);
1427 /* Attempt to load the font */
1429 info = XCreateFontSet(Metadpy->dpy, name, &missing_list, &missing_count, &default_font);
1430 if(missing_count > 0){
1431 printf("missing font(s): \n");
1432 while(missing_count-- > 0){
1433 printf("\t%s\n", missing_list[missing_count]);
1435 XFreeStringList(missing_list);
1438 info = XLoadQueryFont(Metadpy->dpy, name);
1440 kinfo = XLoadQueryFont(Metadpy->dpy, kname);
1445 /* The load failed, try to recover */
1446 if (!info) return (-1);
1448 if (!kinfo) return (-1);
1453 /*** Init the font ***/
1455 /* Wipe the thing */
1456 (void)WIPE(Infofnt, infofnt);
1459 WIPE(Infokfnt, infofnt);
1461 /* Attempt to prepare it */
1463 if (Infofnt_prepare(info, kinfo))
1465 if (Infofnt_prepare(info))
1471 XFreeFontSet(Metadpy->dpy, info);
1473 XFreeFont(Metadpy->dpy, info);
1475 XFreeFont(Metadpy->dpy, kinfo);
1482 /* Save a copy of the font name */
1483 Infofnt->name = string_make(name);
1485 Infokfnt->name = string_make(kname);
1488 /* Mark it as nukable */
1501 * EUCÆüËܸ쥳¡¼¥É¤ò´Þ¤àʸ»úÎó¤òɽ¼¨¤¹¤ë (Xlib)
1504 XDrawMultiString(display,d,gc, x, y, string, len, afont,
1505 afont_width, afont_height, afont_ascent, kfont, kfont_width)
1513 int afont_width, afont_height, afont_ascent;
1520 unsigned char *endp;
1523 endp = string + len;
1525 while ( str < endp && *str ) {
1528 if ( (*str) == 0x7f ) {
1530 /* 0x7F¤Ï¢£¤Ç·è¤áÂǤÁ */
1532 /* Ϣ³¤¹¤ë0x7F¤ÎŤµ¤ò¸¡½Ð */
1534 while ( str < endp && (*str) == 0x7f ) {
1540 XFillRectangle( display, d, gc, x, y-afont_ascent,
1541 slen * afont_width, afont_height);
1543 /* ¥Ý¥¤¥ó¥¿¤ò¿Ê¤á¤ë */
1544 x += afont_width * slen;
1548 if ( iskanji(*str) ) {
1552 /* Ϣ³¤¹¤ëUJISʸ»ú¤ÎŤµ¤ò¸¡½Ð */
1554 while ( str < endp && *str && iskanji(*str) ) {
1555 kanji[slen].byte1 = *str++ & 0x7f;
1556 kanji[slen++].byte2 = *str++ & 0x7f;
1560 XSetFont( display, gc, kfont->fid );
1561 XDrawImageString16( display, d, gc, x, y, kanji, slen );
1564 /* ¥Ý¥¤¥ó¥¿¤ò¿Ê¤á¤ë */
1565 x += kfont_width * slen;
1569 /* Èó´Á»ú(=ASCII¤È²¾Äê)¤Î»Ï¤Þ¤ê */
1571 /* Ϣ³¤¹¤ëASCIIʸ»ú¤ò¸¡½Ð */
1574 while ( str < endp && *str && !iskanji(*str) ) {
1576 if (*str == 0x7f)break;
1583 XSetFont( display, gc, afont->fid );
1584 XDrawImageString( display, d, gc, x, y, p, slen );
1586 /* ¥Ý¥¤¥ó¥¿¤ò¿Ê¤á¤ë */
1587 x += afont_width * slen;
1596 static errr Infofnt_text_std(int x, int y, cptr str, int len)
1601 /*** Do a brief info analysis ***/
1603 /* Do nothing if the string is null */
1604 if (!str || !*str) return (-1);
1606 /* Get the length of the string */
1607 if (len < 0) len = strlen(str);
1610 /*** Decide where to place the string, vertically ***/
1612 /* Ignore Vertical Justifications */
1613 y = (y * Infofnt->hgt) + Infofnt->asc + Infowin->oy;
1616 /*** Decide where to place the string, horizontally ***/
1618 /* Line up with x at left edge of column 'x' */
1619 x = (x * Infofnt->wid) + Infowin->ox;
1622 /*** Actually draw 'str' onto the infowin ***/
1626 /* Be sure the correct font is ready */
1627 XSetFont(Metadpy->dpy, Infoclr->gc, Infofnt->info->fid);
1631 /*** Handle the fake mono we can enforce on fonts ***/
1633 /* Monotize the font */
1637 /* Be sure the correct font is ready */
1638 XSetFont(Metadpy->dpy, Infoclr->gc, Infofnt->info->fid);
1640 /* Do each character */
1641 for (i = 0; i < len; ++i)
1643 /* Note that the Infoclr is set up to contain the Infofnt */
1644 XDrawImageString(Metadpy->dpy, Infowin->win, Infoclr->gc,
1645 x + i * Infofnt->wid + Infofnt->off, y, str + i, 1);
1649 /* Assume monoospaced font */
1652 /* Note that the Infoclr is set up to contain the Infofnt */
1654 /* ´Á»ú¥Õ¥©¥ó¥È¤Îɽ¼¨Éý¤Ï ASCII¥Õ¥©¥ó¥È¤Î2Çܤ˸ÇÄê */
1655 XDrawMultiString(Metadpy->dpy, Infowin->win, Infoclr->gc,
1657 Infofnt->info, Infofnt->wid, Infofnt->hgt,
1659 Infokfnt->info, Infofnt->wid * 2);
1662 XmbDrawImageString(Metadpy->dpy, Infowin->win, Infofnt->info,
1663 Infoclr->gc, x, y, str, len);
1665 XDrawImageString(Metadpy->dpy, Infowin->win, Infoclr->gc,
1679 * Painting where text would be
1681 static errr Infofnt_text_non(int x, int y, cptr str, int len)
1686 /*** Find the width ***/
1688 /* Negative length is a flag to count the characters in str */
1689 if (len < 0) len = strlen(str);
1691 /* The total width will be 'len' chars * standard width */
1692 w = len * Infofnt->wid;
1695 /*** Find the X dimensions ***/
1697 /* Line up with x at left edge of column 'x' */
1698 x = x * Infofnt->wid + Infowin->ox;
1701 /*** Find other dimensions ***/
1703 /* Simply do 'Infofnt->hgt' (a single row) high */
1706 /* Simply do "at top" in row 'y' */
1707 y = y * h + Infowin->oy;
1710 /*** Actually 'paint' the area ***/
1712 /* Just do a Fill Rectangle */
1713 XFillRectangle(Metadpy->dpy, Infowin->win, Infoclr->gc, x, y, w, h);
1721 /*************************************************************************/
1725 * Angband specific code follows... (ANGBAND)
1730 * Hack -- cursor color
1732 static infoclr *xor;
1735 * Actual color table
1737 static infoclr *clr[256];
1740 * Color info (unused, red, green, blue).
1742 static byte color_table[256][4];
1747 typedef struct term_data term_data;
1750 * A structure for each "term"
1768 #ifdef USE_TRANSPARENCY
1770 /* Tempory storage for overlaying tiles. */
1781 * The number of term data structures
1783 #define MAX_TERM_DATA 8
1786 * The array of term data structures
1788 static term_data data[MAX_TERM_DATA];
1793 * Process a keypress event
1795 * Also appears in "main-xaw.c".
1797 static void react_keypress(XKeyEvent *xev)
1799 int i, n, mc, ms, mo, mx;
1803 XKeyEvent *ev = (XKeyEvent*)(xev);
1811 int valid_keysym = TRUE;
1814 /* Check for "normal" keypresses */
1816 if(Focuswin && Focuswin->xic){
1818 n = XmbLookupString(Focuswin->xic, ev, buf, 125, &ks, &status);
1819 if(status == XBufferOverflow){
1820 printf("Input is too long, and dropped\n");
1823 if(status != XLookupKeySym && status != XLookupBoth){
1824 valid_keysym = FALSE;
1827 n = XLookupString(ev, buf, 125, &ks, NULL);
1830 n = XLookupString(ev, buf, 125, &ks, NULL);
1838 /* Enqueue the normal key(s) */
1839 for (i = 0; buf[i]; i++) Term_keypress(buf[i]);
1846 /* Hack -- Ignore "modifier keys" */
1847 if (IsModifierKey(ks)) return;
1850 /* Hack -- convert into an unsigned int */
1853 /* Extract four "modifier flags" */
1854 mc = (ev->state & ControlMask) ? TRUE : FALSE;
1855 ms = (ev->state & ShiftMask) ? TRUE : FALSE;
1856 mo = (ev->state & Mod1Mask) ? TRUE : FALSE;
1857 mx = (ev->state & Mod2Mask) ? TRUE : FALSE;
1860 /* Normal keys with no modifiers */
1861 if (n && !mo && !mx && !IsSpecialKey(ks))
1863 /* Enqueue the normal key(s) */
1864 for (i = 0; buf[i]; i++) Term_keypress(buf[i]);
1871 /* Handle a few standard keys (bypass modifiers) XXX XXX XXX */
1876 Term_keypress(ESCAPE);
1882 Term_keypress('\r');
1888 Term_keypress('\t');
1895 Term_keypress('\010');
1901 /* Hack -- Use the KeySym */
1904 sprintf(msg, "%c%s%s%s%s_%lX%c", 31,
1905 mc ? "N" : "", ms ? "S" : "",
1906 mo ? "O" : "", mx ? "M" : "",
1907 (unsigned long)(ks), 13);
1910 /* Hack -- Use the Keycode */
1913 sprintf(msg, "%c%s%s%s%sK_%X%c", 31,
1914 mc ? "N" : "", ms ? "S" : "",
1915 mo ? "O" : "", mx ? "M" : "",
1919 /* Enqueue the "macro trigger" string */
1920 for (i = 0; msg[i]; i++) Term_keypress(msg[i]);
1923 /* Hack -- auto-define macros as needed */
1924 if (n && (macro_find_exact(msg) < 0))
1926 /* Create a macro */
1927 macro_add(msg, buf);
1937 static errr CheckEvent(bool wait)
1939 term_data *old_td = (term_data*)(Term->data);
1941 XEvent xev_body, *xev = &xev_body;
1943 term_data *td = NULL;
1944 infowin *iwin = NULL;
1952 /* Do not wait unless requested */
1953 if (!wait && !XPending(Metadpy->dpy)) return (1);
1955 /* Load the Event */
1956 XNextEvent(Metadpy->dpy, xev);
1959 /* #define DEBUG_EVENT */
1962 printf("event: type=%d", xev->type);
1965 printf("(KeyPress), keycode=%X", xev->xkey.keycode);
1968 printf("(FocusIn)");
1971 printf("(FocusOut)");
1973 case ReparentNotify:
1974 printf("(ReparentNotify)");
1976 case ConfigureNotify:
1977 printf("(ConfigureNotify)");
1980 printf("(MapNotify)");
1986 printf("(ClientMessage)");
1992 if (XFilterEvent(xev, xev->xany.window)
1993 /*XFilterEvent(xev, (data[0].win)->win)*/){
1995 printf(", [filtered by IM]\n");
1997 goto redo_checkevent;
2004 /* Notice new keymaps */
2005 if (xev->type == MappingNotify)
2007 XRefreshKeyboardMapping(&xev->xmapping);
2012 /* Scan the windows */
2013 for (i = 0; i < MAX_TERM_DATA; i++)
2015 if (!data[i].win) continue;
2016 if (xev->xany.window == data[i].win->win)
2024 /* Unknown window */
2025 if (!td || !iwin) return (0);
2028 /* Hack -- activate the Term */
2029 Term_activate(&td->t);
2031 /* Hack -- activate the window */
2035 /* Switch on the Type */
2046 /* Which button is involved */
2047 if (xev->xbutton.button == Button1) z = 1;
2048 else if (xev->xbutton.button == Button2) z = 2;
2049 else if (xev->xbutton.button == Button3) z = 3;
2050 else if (xev->xbutton.button == Button4) z = 4;
2051 else if (xev->xbutton.button == Button5) z = 5;
2053 /* Where is the mouse */
2065 /* Where is the mouse */
2066 x = xev->xcrossing.x;
2067 y = xev->xcrossing.y;
2076 /* Where is the mouse */
2095 /* Save the mouse location */
2099 /* Hack -- use "old" term */
2100 Term_activate(&old_td->t);
2102 /* Process the key */
2103 react_keypress(&(xev->xkey));
2112 /* Ignore "extra" exposes */
2113 /*if (xev->xexpose.count) break;*/
2115 /* Clear the window */
2118 x1 = (xev->xexpose.x - Infowin->ox)/Infofnt->wid;
2119 x2 = (xev->xexpose.x + xev->xexpose.width -
2120 Infowin->ox)/Infofnt->wid;
2122 y1 = (xev->xexpose.y - Infowin->oy)/Infofnt->hgt;
2123 y2 = (xev->xexpose.y + xev->xexpose.height -
2124 Infowin->oy)/Infofnt->hgt;
2126 Term_redraw_section(x1, y1, x2, y2);
2136 Infowin->mapped = 1;
2137 Term->mapped_flag = TRUE;
2143 Infowin->mapped = 0;
2144 Term->mapped_flag = FALSE;
2148 /* Move and/or Resize */
2149 case ConfigureNotify:
2151 int cols, rows, wid, hgt;
2153 int ox = Infowin->ox;
2154 int oy = Infowin->oy;
2156 /* Save the new Window Parms */
2157 Infowin->x = xev->xconfigure.x;
2158 Infowin->y = xev->xconfigure.y;
2159 Infowin->w = xev->xconfigure.width;
2160 Infowin->h = xev->xconfigure.height;
2162 /* Determine "proper" number of rows/cols */
2163 cols = ((Infowin->w - (ox + ox)) / td->fnt->wid);
2164 rows = ((Infowin->h - (oy + oy)) / td->fnt->hgt);
2167 if (td == &data[0]) cols = 80;
2168 if (td == &data[0]) rows = 24;
2170 /* Hack -- minimal size */
2171 if (cols < 1) cols = 1;
2172 if (rows < 1) rows = 1;
2174 /* Desired size of window */
2175 wid = cols * td->fnt->wid + (ox + ox);
2176 hgt = rows * td->fnt->hgt + (oy + oy);
2178 /* Resize the Term (if needed) */
2179 Term_resize(cols, rows);
2181 /* Resize the windows if any "change" is needed */
2182 if ((Infowin->w != wid) || (Infowin->h != hgt))
2185 Infowin_set(td->win);
2186 Infowin_resize(wid, hgt);
2195 XSetICFocus(iwin->xic);
2203 XUnsetICFocus(iwin->xic);
2205 /* Focuswin = NULL;*/
2212 /* Hack -- Activate the old term */
2213 Term_activate(&old_td->t);
2215 /* Hack -- Activate the proper window */
2216 Infowin_set(old_td->win);
2225 * Handle "activation" of a term
2227 static errr Term_xtra_x11_level(int v)
2229 term_data *td = (term_data*)(Term->data);
2231 /* Handle "activate" */
2234 /* Activate the window */
2235 Infowin_set(td->win);
2237 /* Activate the font */
2238 Infofnt_set(td->fnt);
2240 Infokfnt_set(td->kfnt);
2252 static errr Term_xtra_x11_react(void)
2258 /* Check the colors */
2259 for (i = 0; i < 256; i++)
2261 if ((color_table[i][0] != angband_color_table[i][0]) ||
2262 (color_table[i][1] != angband_color_table[i][1]) ||
2263 (color_table[i][2] != angband_color_table[i][2]) ||
2264 (color_table[i][3] != angband_color_table[i][3]))
2268 /* Save new values */
2269 color_table[i][0] = angband_color_table[i][0];
2270 color_table[i][1] = angband_color_table[i][1];
2271 color_table[i][2] = angband_color_table[i][2];
2272 color_table[i][3] = angband_color_table[i][3];
2275 pixel = create_pixel(Metadpy->dpy,
2280 /* Change the foreground */
2281 Infoclr_set(clr[i]);
2282 Infoclr_change_fg(pixel);
2293 * Handle a "special request"
2295 static errr Term_xtra_x11(int n, int v)
2297 /* Handle a subset of the legal requests */
2301 case TERM_XTRA_NOISE: Metadpy_do_beep(); return (0);
2303 /* Flush the output XXX XXX */
2304 case TERM_XTRA_FRESH: Metadpy_update(1, 0, 0); return (0);
2306 /* Process random events XXX */
2307 case TERM_XTRA_BORED: return (CheckEvent(0));
2309 /* Process Events XXX */
2310 case TERM_XTRA_EVENT: return (CheckEvent(v));
2312 /* Flush the events XXX */
2313 case TERM_XTRA_FLUSH: while (!CheckEvent(FALSE)); return (0);
2315 /* Handle change in the "level" */
2316 case TERM_XTRA_LEVEL: return (Term_xtra_x11_level(v));
2318 /* Clear the screen */
2319 case TERM_XTRA_CLEAR: Infowin_wipe(); return (0);
2321 /* Delay for some milliseconds */
2322 case TERM_XTRA_DELAY: usleep(1000 * v); return (0);
2324 /* React to changes */
2325 case TERM_XTRA_REACT: return (Term_xtra_x11_react());
2334 * Draw the cursor as an inverted rectangle.
2336 * Consider a rectangular outline like "main-mac.c". XXX XXX
2338 static errr Term_curs_x11(int x, int y)
2340 /* Draw the cursor */
2343 /* Hilite the cursor character */
2344 Infofnt_text_non(x, y, " ", 1);
2352 * Erase some characters.
2354 static errr Term_wipe_x11(int x, int y, int n)
2356 /* Erase (use black) */
2357 Infoclr_set(clr[TERM_DARK]);
2359 /* Mega-Hack -- Erase some space */
2360 Infofnt_text_non(x, y, "", n);
2368 * Draw some textual characters.
2370 static errr Term_text_x11(int x, int y, int n, byte a, cptr s)
2373 Infoclr_set(clr[a]);
2376 Infofnt_text_std(x, y, s, n);
2386 * Draw some graphical characters.
2388 # ifdef USE_TRANSPARENCY
2389 static errr Term_pict_x11(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2390 # else /* USE_TRANSPARENCY */
2391 static errr Term_pict_x11(int x, int y, int n, const byte *ap, const char *cp)
2392 # endif /* USE_TRANSPARENCY */
2400 #ifdef USE_TRANSPARENCY
2407 unsigned long pixel, blank;
2408 #endif /* USE_TRANSPARENCY */
2410 term_data *td = (term_data*)(Term->data);
2415 /* Add in affect of window boundaries */
2419 for (i = 0; i < n; ++i)
2424 /* For extra speed - cache these values */
2425 x1 = (c&0x7F) * td->fnt->wid;
2426 y1 = (a&0x7F) * td->fnt->hgt;
2428 #ifdef USE_TRANSPARENCY
2433 /* For extra speed - cache these values */
2434 x2 = (tc&0x7F) * td->fnt->wid;
2435 y2 = (ta&0x7F) * td->fnt->hgt;
2437 /* Optimise the common case */
2438 if ((x1 == x2) && (y1 == y2))
2440 /* Draw object / terrain */
2441 XPutImage(Metadpy->dpy, td->win->win,
2446 td->fnt->wid, td->fnt->hgt);
2451 /* Mega Hack^2 - assume the top left corner is "black" */
2452 blank = XGetPixel(td->tiles, 0, td->fnt->hgt * 6);
2454 for (k = 0; k < td->fnt->wid; k++)
2456 for (l = 0; l < td->fnt->hgt; l++)
2458 /* If mask set... */
2459 if ((pixel = XGetPixel(td->tiles, x1 + k, y1 + l)) == blank)
2461 /* Output from the terrain */
2462 pixel = XGetPixel(td->tiles, x2 + k, y2 + l);
2465 /* Store into the temp storage. */
2466 XPutPixel(td->TmpImage, k, l, pixel);
2471 /* Draw to screen */
2473 XPutImage(Metadpy->dpy, td->win->win,
2477 td->fnt->wid, td->fnt->hgt);
2480 #else /* USE_TRANSPARENCY */
2482 /* Draw object / terrain */
2483 XPutImage(Metadpy->dpy, td->win->win,
2488 td->fnt->wid, td->fnt->hgt);
2490 #endif /* USE_TRANSPARENCY */
2498 #endif /* USE_GRAPHICS */
2501 static void IMDestroyCallback(XIM, XPointer, XPointer);
2504 IMInstantiateCallback(Display *display, XPointer unused1, XPointer unused2)
2507 XIMCallback ximcallback;
2508 XIMStyles *xim_styles = NULL;
2511 xim = XOpenIM(display, NULL, NULL, NULL);
2513 printf("can't open IM\n");
2517 /* initialize destroy callback */
2518 ximcallback.callback = IMDestroyCallback;
2519 ximcallback.client_data = NULL;
2520 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
2522 /* set style (only "Root" is supported yet...) */
2523 XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
2524 for (i = 0; i < xim_styles->count_styles; i++){
2525 if(xim_styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) break;
2527 if(i >= xim_styles->count_styles){
2528 printf("Sorry, your IM does not support 'Root' preedit style...\n");
2536 for (i = 0; i < MAX_TERM_DATA; i++)
2538 infowin *iwin = data[i].win;
2539 if (!iwin) continue;
2540 iwin->xic = XCreateIC(xim, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), XNClientWindow, iwin->win, XNFocusWindow, iwin->win, NULL);
2542 printf("Can't create input context for Term%d\n", i);
2545 if(XGetICValues(iwin->xic, XNFilterEvents, &iwin->xic_mask, NULL) != NULL){
2546 /* printf("Can't get XNFilterEvents\n"); */
2547 iwin->xic_mask = 0L;
2549 XSelectInput(Metadpy->dpy, iwin->win, iwin->mask | iwin->xic_mask);
2555 static void IMDestroyCallback(XIM xim, XPointer client_data, XPointer call_data)
2559 if (call_data == NULL){
2560 XRegisterIMInstantiateCallback(Metadpy->dpy, NULL, NULL, NULL, IMInstantiateCallback, NULL);
2563 for(i = 0; i < MAX_TERM_DATA; i++)
2565 infowin *iwin = data[i].win;
2568 XSelectInput(Metadpy->dpy, iwin->win, iwin->mask);
2569 iwin->xic_mask = 0L;
2574 Metadpy->xim = NULL;
2579 * Initialize a term_data
2581 static errr term_data_init(term_data *td, int i)
2585 bool fixed = (i == 0);
2587 cptr name = angband_term_name[i];
2622 /* Window specific font name */
2623 sprintf(buf, "ANGBAND_X11_FONT_%d", i);
2625 /* Check environment for that font */
2628 /* Check environment for "base" font */
2629 if (!font) font = getenv("ANGBAND_X11_FONT");
2631 /* No environment variables, use default font */
2638 font = DEFAULT_X11_FONT_0;
2643 font = DEFAULT_X11_FONT_1;
2648 font = DEFAULT_X11_FONT_2;
2653 font = DEFAULT_X11_FONT_3;
2658 font = DEFAULT_X11_FONT_4;
2663 font = DEFAULT_X11_FONT_5;
2668 font = DEFAULT_X11_FONT_6;
2673 font = DEFAULT_X11_FONT_7;
2678 font = DEFAULT_X11_FONT;
2684 /* Window specific font name */
2685 sprintf(buf, "ANGBAND_X11_KFONT_%d", i);
2687 /* Check environment for that font */
2688 kfont = getenv(buf);
2690 /* Check environment for "base" font */
2691 if (!kfont) kfont = getenv("ANGBAND_X11_KFONT");
2693 /* No environment variables, use default font */
2700 kfont = DEFAULT_X11_KFONT_0;
2705 kfont = DEFAULT_X11_KFONT_1;
2710 kfont = DEFAULT_X11_KFONT_2;
2715 kfont = DEFAULT_X11_KFONT_3;
2720 kfont = DEFAULT_X11_KFONT_4;
2725 kfont = DEFAULT_X11_KFONT_5;
2730 kfont = DEFAULT_X11_KFONT_6;
2735 kfont = DEFAULT_X11_KFONT_7;
2740 kfont = DEFAULT_X11_KFONT;
2745 /* Window specific location (x) */
2746 sprintf(buf, "ANGBAND_X11_AT_X_%d", i);
2748 x = (str != NULL) ? atoi(str) : -1;
2750 /* Window specific location (y) */
2751 sprintf(buf, "ANGBAND_X11_AT_Y_%d", i);
2753 y = (str != NULL) ? atoi(str) : -1;
2758 /* Window specific cols */
2759 sprintf(buf, "ANGBAND_X11_COLS_%d", i);
2761 val = (str != NULL) ? atoi(str) : -1;
2762 if (val > 0) cols = val;
2764 /* Window specific rows */
2765 sprintf(buf, "ANGBAND_X11_ROWS_%d", i);
2767 val = (str != NULL) ? atoi(str) : -1;
2768 if (val > 0) rows = val;
2772 /* Window specific inner border offset (ox) */
2773 sprintf(buf, "ANGBAND_X11_IBOX_%d", i);
2775 val = (str != NULL) ? atoi(str) : -1;
2776 if (val > 0) ox = val;
2778 /* Window specific inner border offset (oy) */
2779 sprintf(buf, "ANGBAND_X11_IBOY_%d", i);
2781 val = (str != NULL) ? atoi(str) : -1;
2782 if (val > 0) oy = val;
2785 /* Prepare the standard font */
2787 MAKE(td->fnt, infofnt);
2788 Infofnt_set(td->fnt);
2789 MAKE(td->kfnt, infofnt);
2790 Infokfnt_set(td->kfnt);
2791 Infofnt_init_data(font, kfont);
2793 MAKE(td->fnt, infofnt);
2794 Infofnt_set(td->fnt);
2795 Infofnt_init_data(font);
2799 /* Hack -- key buffer size */
2800 num = (fixed ? 1024 : 16);
2802 /* Assume full size windows */
2803 wid = cols * td->fnt->wid + (ox + ox);
2804 hgt = rows * td->fnt->hgt + (oy + oy);
2806 /* Create a top-window */
2807 MAKE(td->win, infowin);
2808 Infowin_set(td->win);
2809 Infowin_init_top(x, y, wid, hgt, 0,
2810 Metadpy->fg, Metadpy->bg);
2812 /* Ask for certain events */
2813 #if defined(USE_XIM)
2815 /* XIM ¤¬Í¸ú¤Ê¤Î¤Ï¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤Î¤ß¤Ê¤Î¤Ç¡¢¼óÈø¤ò°ì´Ó¤µ¤»¤ë¤¿¤á
2816 Ä̾ï¤Î¥¡¼ÆþÎϤâ̵¸ú¤Ë¤¹¤ë */
2818 Infowin_set_mask(ExposureMask | StructureNotifyMask | KeyPressMask);
2820 Infowin_set_mask(ExposureMask | StructureNotifyMask);
2823 Infowin_set_mask(ExposureMask | StructureNotifyMask | KeyPressMask | FocusChangeMask);
2826 Infowin_set_mask(ExposureMask | StructureNotifyMask | KeyPressMask);
2829 /* Set the window name */
2830 Infowin_set_name(name);
2832 /* Save the inner border */
2836 /* Make Class Hints */
2837 ch = XAllocClassHint();
2839 if (ch == NULL) quit("XAllocClassHint failed");
2841 strcpy(res_name, name);
2842 res_name[0] = FORCELOWER(res_name[0]);
2843 ch->res_name = res_name;
2845 strcpy(res_class, "Angband");
2846 ch->res_class = res_class;
2848 XSetClassHint(Metadpy->dpy, Infowin->win, ch);
2850 /* Make Size Hints */
2851 sh = XAllocSizeHints();
2854 if (sh == NULL) quit("XAllocSizeHints failed");
2856 /* Fixed window size */
2860 sh->flags = PMinSize | PMaxSize;
2861 sh->min_width = sh->max_width = wid;
2862 sh->min_height = sh->max_height = hgt;
2865 /* Variable window size */
2869 sh->flags = PMinSize | PMaxSize;
2870 sh->min_width = td->fnt->wid + (ox + ox);
2871 sh->min_height = td->fnt->hgt + (oy + oy);
2872 sh->max_width = 256 * td->fnt->wid + (ox + ox);
2873 sh->max_height = 256 * td->fnt->hgt + (oy + oy);
2876 /* Resize increment */
2877 sh->flags |= PResizeInc;
2878 sh->width_inc = td->fnt->wid;
2879 sh->height_inc = td->fnt->hgt;
2881 /* Base window size */
2882 sh->flags |= PBaseSize;
2883 sh->base_width = (ox + ox);
2884 sh->base_height = (oy + oy);
2886 /* Use the size hints */
2887 XSetWMNormalHints(Metadpy->dpy, Infowin->win, sh);
2889 /* Map the window */
2894 wh = XAllocWMHints();
2895 if(wh == NULL) quit("XAllocWMHints failed");
2896 wh->flags = InputHint;
2898 XSetWMHints(Metadpy->dpy, Infowin->win, wh);
2901 /* Move the window to requested location */
2902 if ((x >= 0) && (y >= 0)) Infowin_impell(x, y);
2905 /* Initialize the term */
2906 term_init(t, cols, rows, num);
2908 /* Use a "soft" cursor */
2909 t->soft_cursor = TRUE;
2911 /* Erase with "white space" */
2912 t->attr_blank = TERM_WHITE;
2913 t->char_blank = ' ';
2916 t->xtra_hook = Term_xtra_x11;
2917 t->curs_hook = Term_curs_x11;
2918 t->wipe_hook = Term_wipe_x11;
2919 t->text_hook = Term_text_x11;
2924 /* Activate (important) */
2933 * Initialization function for an "X11" module to Angband
2935 errr init_x11(int argc, char *argv[])
2941 int num_term = MAX_TERM_DATA;
2945 char filename[1024];
2950 #ifdef USE_TRANSPARENCY
2953 #endif /* USE_TRANSPARENCY */
2955 #endif /* USE_GRAPHICS */
2959 for (i = 1; i < argc; i++)
2961 if (prefix(argv[i], "-d"))
2963 dpy_name = &argv[i][2];
2968 if (prefix(argv[i], "-s"))
2970 smoothRescaling = FALSE;
2973 #endif /* USE_GRAPHICS */
2975 if (prefix(argv[i], "-n"))
2977 num_term = atoi(&argv[i][2]);
2978 if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA;
2979 else if (num_term < 1) num_term = 1;
2983 plog_fmt("Ignoring option: %s", argv[i]);
2987 setlocale(LC_ALL, "");
2988 #ifdef DEFAULT_LOCALE
2989 if(!strcmp(setlocale(LC_ALL, NULL), "C")){
2990 printf("try default locale \"%s\"\n", DEFAULT_LOCALE);
2991 setlocale(LC_ALL, DEFAULT_LOCALE);
2995 char *current_locale = setlocale(LC_ALL, NULL);
2996 /* printf("set locale to \"%s\"\n", current_locale); */
2997 if(!strcmp(current_locale, "C")){
2998 printf("WARNING: Locale is not supported. Non-english font may be displayed incorrectly.\n");
3002 if(!XSupportsLocale()){
3003 printf("can't support locale in X\n");
3004 setlocale(LC_ALL, "C");
3006 #endif /* USE_LOCALE */
3009 /* Init the Metadpy if possible */
3010 if (Metadpy_init_name(dpy_name)) return (-1);
3013 /* Prepare cursor color */
3016 Infoclr_init_ppn(Metadpy->fg, Metadpy->bg, "xor", 0);
3019 /* Prepare normal colors */
3020 for (i = 0; i < 256; ++i)
3024 MAKE(clr[i], infoclr);
3026 Infoclr_set(clr[i]);
3028 /* Acquire Angband colors */
3029 color_table[i][0] = angband_color_table[i][0];
3030 color_table[i][1] = angband_color_table[i][1];
3031 color_table[i][2] = angband_color_table[i][2];
3032 color_table[i][3] = angband_color_table[i][3];
3034 /* Default to monochrome */
3035 pixel = ((i == 0) ? Metadpy->bg : Metadpy->fg);
3041 pixel = create_pixel(Metadpy->dpy,
3047 /* Initialize the color */
3048 Infoclr_init_ppn(pixel, Metadpy->bg, "cpy", 0);
3052 /* Initialize the windows */
3053 for (i = 0; i < num_term; i++)
3055 term_data *td = &data[i];
3057 /* Initialize the term_data */
3058 term_data_init(td, i);
3060 /* Save global entry */
3061 angband_term[i] = Term;
3064 /* Raise the "Angband" window */
3065 Infowin_set(data[0].win);
3068 /* Activate the "Angband" window screen */
3069 Term_activate(&data[0].t);
3074 p = XSetLocaleModifiers("");
3076 p = XSetLocaleModifiers("@im=");
3078 /* printf("XMODIFIERS=\"%s\"\n", p); */
3080 XRegisterIMInstantiateCallback(Metadpy->dpy, NULL, NULL, NULL, IMInstantiateCallback, NULL);
3088 /* Try the "16x16.bmp" file */
3089 path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/16x16.bmp");
3091 /* Use the "16x16.bmp" file if it exists */
3092 if (0 == fd_close(fd_open(filename, O_RDONLY)))
3095 use_graphics = TRUE;
3097 use_transparency = TRUE;
3099 pict_wid = pict_hgt = 16;
3101 ANGBAND_GRAF = "new";
3105 /* Try the "8x8.bmp" file */
3106 path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/8x8.bmp");
3108 /* Use the "8x8.bmp" file if it exists */
3109 if (0 == fd_close(fd_open(filename, O_RDONLY)))
3112 use_graphics = TRUE;
3114 pict_wid = pict_hgt = 8;
3116 ANGBAND_GRAF = "old";
3124 Display *dpy = Metadpy->dpy;
3128 /* Load the graphical tiles */
3129 tiles_raw = ReadBMP(dpy, filename);
3131 /* Initialize the windows */
3132 for (i = 0; i < num_term; i++)
3134 term_data *td = &data[i];
3139 t->pict_hook = Term_pict_x11;
3141 /* Use graphics sometimes */
3142 t->higher_pict = TRUE;
3146 ResizeImage(dpy, tiles_raw,
3148 td->fnt->wid, td->fnt->hgt);
3151 #ifdef USE_TRANSPARENCY
3152 /* Initialize the transparency masks */
3153 for (i = 0; i < num_term; i++)
3155 term_data *td = &data[i];
3157 int depth = DefaultDepth(dpy, DefaultScreen(dpy));
3158 Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
3162 /* Determine total bytes needed for image */
3164 jj = (depth - 1) >> 2;
3165 while (jj >>= 1) ii <<= 1;
3166 total = td->fnt->wid * td->fnt->hgt * ii;
3169 TmpData = (char *)malloc(total);
3171 td->TmpImage = XCreateImage(dpy,visual,depth,
3172 ZPixmap, 0, TmpData,
3173 td->fnt->wid, td->fnt->hgt, 8, 0);
3176 #endif /* USE_TRANSPARENCY */
3179 /* Free tiles_raw? XXX XXX */
3182 #endif /* USE_GRAPHICS */
3189 #endif /* USE_X11 */