| 109 | | #endif /* __MAKEDEPEND__ */ |
|---|
| 110 | | |
|---|
| 111 | | |
|---|
| 112 | | /* |
|---|
| 113 | | * Include some helpful X11 code. |
|---|
| 114 | | */ |
|---|
| 115 | | #include "maid-x11.h" |
|---|
| | 106 | |
|---|
| | 107 | #include "main.h" |
|---|
| | 108 | |
|---|
| | 109 | #ifndef IsModifierKey |
|---|
| | 110 | |
|---|
| | 111 | /* |
|---|
| | 112 | * Keysym macros, used on Keysyms to test for classes of symbols |
|---|
| | 113 | * These were stolen from one of the X11 header files |
|---|
| | 114 | */ |
|---|
| | 115 | |
|---|
| | 116 | #define IsKeypadKey(keysym) \ |
|---|
| | 117 | (((unsigned)(keysym) >= XK_KP_Space) && ((unsigned)(keysym) <= XK_KP_Equal)) |
|---|
| | 118 | |
|---|
| | 119 | #define IsCursorKey(keysym) \ |
|---|
| | 120 | (((unsigned)(keysym) >= XK_Home) && ((unsigned)(keysym) < XK_Select)) |
|---|
| | 121 | |
|---|
| | 122 | #define IsPFKey(keysym) \ |
|---|
| | 123 | (((unsigned)(keysym) >= XK_KP_F1) && ((unsigned)(keysym) <= XK_KP_F4)) |
|---|
| | 124 | |
|---|
| | 125 | #define IsFunctionKey(keysym) \ |
|---|
| | 126 | (((unsigned)(keysym) >= XK_F1) && ((unsigned)(keysym) <= XK_F35)) |
|---|
| | 127 | |
|---|
| | 128 | #define IsMiscFunctionKey(keysym) \ |
|---|
| | 129 | (((unsigned)(keysym) >= XK_Select) && ((unsigned)(keysym) < XK_KP_Space)) |
|---|
| | 130 | |
|---|
| | 131 | #define IsModifierKey(keysym) \ |
|---|
| | 132 | (((unsigned)(keysym) >= XK_Shift_L) && ((unsigned)(keysym) <= XK_Hyper_R)) |
|---|
| | 133 | |
|---|
| | 134 | #endif /* IsModifierKey */ |
|---|
| | 135 | |
|---|
| | 136 | |
|---|
| | 137 | /* |
|---|
| | 138 | * Checks if the keysym is a special key or a normal key |
|---|
| | 139 | * Assume that XK_MISCELLANY keysyms are special |
|---|
| | 140 | */ |
|---|
| | 141 | #define IsSpecialKey(keysym) \ |
|---|
| | 142 | ((unsigned)(keysym) >= 0xFF00) |
|---|
| | 488 | |
|---|
| | 489 | |
|---|
| | 490 | |
|---|
| | 491 | /**** Code imported from the old maid-x11.c ****/ |
|---|
| | 492 | |
|---|
| | 493 | #ifdef SUPPORT_GAMMA |
|---|
| | 494 | static bool gamma_table_ready = FALSE; |
|---|
| | 495 | static int gamma_val = 0; |
|---|
| | 496 | #endif /* SUPPORT_GAMMA */ |
|---|
| | 497 | |
|---|
| | 498 | |
|---|
| | 499 | /* |
|---|
| | 500 | * Hack -- Convert an RGB value to an X11 Pixel, or die. |
|---|
| | 501 | */ |
|---|
| | 502 | u32b create_pixel(Display *dpy, byte red, byte green, byte blue) |
|---|
| | 503 | { |
|---|
| | 504 | Colormap cmap = DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)); |
|---|
| | 505 | |
|---|
| | 506 | XColor xcolour; |
|---|
| | 507 | |
|---|
| | 508 | #ifdef SUPPORT_GAMMA |
|---|
| | 509 | |
|---|
| | 510 | if (!gamma_table_ready) |
|---|
| | 511 | { |
|---|
| | 512 | cptr str = getenv("ANGBAND_X11_GAMMA"); |
|---|
| | 513 | if (str != NULL) gamma_val = atoi(str); |
|---|
| | 514 | |
|---|
| | 515 | gamma_table_ready = TRUE; |
|---|
| | 516 | |
|---|
| | 517 | /* Only need to build the table if gamma exists */ |
|---|
| | 518 | if (gamma_val) build_gamma_table(gamma_val); |
|---|
| | 519 | } |
|---|
| | 520 | |
|---|
| | 521 | /* Hack -- Gamma Correction */ |
|---|
| | 522 | if (gamma_val > 0) |
|---|
| | 523 | { |
|---|
| | 524 | red = gamma_table[red]; |
|---|
| | 525 | green = gamma_table[green]; |
|---|
| | 526 | blue = gamma_table[blue]; |
|---|
| | 527 | } |
|---|
| | 528 | |
|---|
| | 529 | #endif /* SUPPORT_GAMMA */ |
|---|
| | 530 | |
|---|
| | 531 | /* Build the color */ |
|---|
| | 532 | |
|---|
| | 533 | xcolour.red = red * 255; |
|---|
| | 534 | xcolour.green = green * 255; |
|---|
| | 535 | xcolour.blue = blue * 255; |
|---|
| | 536 | xcolour.flags = DoRed | DoGreen | DoBlue; |
|---|
| | 537 | |
|---|
| | 538 | /* Attempt to Allocate the Parsed color */ |
|---|
| | 539 | if (!(XAllocColor(dpy, cmap, &xcolour))) |
|---|
| | 540 | { |
|---|
| | 541 | quit_fmt("Couldn't allocate bitmap color #%04x%04x%04x\n", |
|---|
| | 542 | xcolour.red, xcolour.green, xcolour.blue); |
|---|
| | 543 | } |
|---|
| | 544 | |
|---|
| | 545 | return (xcolour.pixel); |
|---|
| | 546 | } |
|---|
| | 547 | |
|---|
| | 548 | |
|---|
| | 549 | /* |
|---|
| | 550 | * Get the name of the default font to use for the term. |
|---|
| | 551 | */ |
|---|
| | 552 | const char *get_default_font(int term_num) |
|---|
| | 553 | { |
|---|
| | 554 | const char *font; |
|---|
| | 555 | char buf[80]; |
|---|
| | 556 | |
|---|
| | 557 | /* Window specific font name */ |
|---|
| | 558 | strnfmt(buf, sizeof(buf), "ANGBAND_X11_FONT_%d", term_num); |
|---|
| | 559 | |
|---|
| | 560 | /* Check environment for that font */ |
|---|
| | 561 | font = getenv(buf); |
|---|
| | 562 | if (font) return font; |
|---|
| | 563 | |
|---|
| | 564 | /* Check environment for "base" font */ |
|---|
| | 565 | font = getenv("ANGBAND_X11_FONT"); |
|---|
| | 566 | if (font) return font; |
|---|
| | 567 | |
|---|
| | 568 | switch (term_num) |
|---|
| | 569 | { |
|---|
| | 570 | case 0: |
|---|
| | 571 | return DEFAULT_X11_FONT_0; |
|---|
| | 572 | case 1: |
|---|
| | 573 | return DEFAULT_X11_FONT_1; |
|---|
| | 574 | case 2: |
|---|
| | 575 | return DEFAULT_X11_FONT_2; |
|---|
| | 576 | case 3: |
|---|
| | 577 | return DEFAULT_X11_FONT_3; |
|---|
| | 578 | case 4: |
|---|
| | 579 | return DEFAULT_X11_FONT_4; |
|---|
| | 580 | case 5: |
|---|
| | 581 | return DEFAULT_X11_FONT_5; |
|---|
| | 582 | case 6: |
|---|
| | 583 | return DEFAULT_X11_FONT_6; |
|---|
| | 584 | case 7: |
|---|
| | 585 | return DEFAULT_X11_FONT_7; |
|---|
| | 586 | } |
|---|
| | 587 | |
|---|
| | 588 | return DEFAULT_X11_FONT; |
|---|
| | 589 | } |
|---|