From fa9da4f7eb9cc5e19456fbdbef11910e37e6e3ba Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Fri, 3 Dec 1999 02:31:33 +0000 Subject: [PATCH] Thu Dec 2 22:18:51 PST 1999 Michael Jennings A good number of changes here. First off, since nobody reported any bugs with the new font stuff, I switched the multibyte fonts over to use it as well. They do use the same font index, however, in order to keep the sizes matched up. I also fixed up the modifier stuff so that Meta and Alt are matched by KeySym rather than assuming Mod1. I also took care of the action dispatcher so it would keep up with these changes. To go along with this, I added 3 new options and config file attributes which allow you to set the modifier that should represent Meta, Alt, and NumLock. This overrides the automatically-detected X server settings. I also applied some fixes to the XIM code from Sung-Hyun Nam . SVN revision: 1482 --- ChangeLog | 20 ++++++++++ configure.in | 8 ++-- src/actions.c | 25 +++++++----- src/actions.h | 14 ++++--- src/command.c | 29 +++++++++++--- src/command.h | 22 +++++------ src/events.c | 1 - src/font.c | 13 ++++-- src/font.h | 2 +- src/menus.c | 2 +- src/options.c | 107 ++++++++++++++++++++++++++++++++++++++++++-------- src/startup.c | 2 + src/term.c | 72 +++++++++++++++++++++++++++++++-- src/term.h | 3 ++ 14 files changed, 256 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4b50e8..df88945 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2852,3 +2852,23 @@ Fri Nov 19 23:05:31 PST 1999 Michael Jennings :-] ------------------------------------------------------------------------------- +Thu Dec 2 22:18:51 PST 1999 Michael Jennings + + A good number of changes here. First off, since nobody reported any + bugs with the new font stuff, I switched the multibyte fonts over to + use it as well. They do use the same font index, however, in order to + keep the sizes matched up. + + I also fixed up the modifier stuff so that Meta and Alt are matched + by KeySym rather than assuming Mod1. I also took care of the action + dispatcher so it would keep up with these changes. + + To go along with this, I added 3 new options and config file + attributes which allow you to set the modifier that should represent + Meta, Alt, and NumLock. This overrides the automatically-detected + X server settings. + + I also applied some fixes to the XIM code from Sung-Hyun Nam + . + +------------------------------------------------------------------------------- diff --git a/configure.in b/configure.in index 07856e2..df1c1e1 100644 --- a/configure.in +++ b/configure.in @@ -304,11 +304,11 @@ AC_ARG_ENABLE(multi-charset, AC_MSG_RESULT(utf-8) AC_DEFINE(MULTI_CHARSET) AC_DEFINE_UNQUOTED(DEF_FONT_IDX, 2) - AC_DEFINE_UNQUOTED(MFONT0, "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1") - AC_DEFINE_UNQUOTED(MFONT1, "-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso10646-1") - AC_DEFINE_UNQUOTED(MFONT2, "-misc-fixed-medium-r-normal--10-100-75-75-c-60-iso10646-1") + AC_DEFINE_UNQUOTED(MFONT0, "-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso10646-1") + AC_DEFINE_UNQUOTED(MFONT1, "-misc-fixed-medium-r-normal--10-100-75-75-c-60-iso10646-1") + AC_DEFINE_UNQUOTED(MFONT2, "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1") AC_DEFINE_UNQUOTED(MFONT3, "-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1") - AC_DEFINE_UNQUOTED(MFONT4, "-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso10646-1") + AC_DEFINE_UNQUOTED(MFONT4, "-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1") AC_DEFINE_UNQUOTED(FONT0, "5x7") AC_DEFINE_UNQUOTED(FONT1, "6x10") AC_DEFINE_UNQUOTED(FONT2, "fixed") diff --git a/src/actions.c b/src/actions.c index 22f5330..9990b0f 100644 --- a/src/actions.c +++ b/src/actions.c @@ -80,6 +80,7 @@ unsigned char action_dispatch(event_t *ev, KeySym keysym) { action_t *action; + unsigned int m = (AltMask | MetaMask | NumLockMask); ASSERT(ev != NULL); for (action = action_list; action; action = action->next) { @@ -102,19 +103,25 @@ action_dispatch(event_t *ev, KeySym keysym) { if (LOGICAL_XOR((action->mod & MOD_LOCK), (ev->xkey.state & LockMask))) { continue; } - if (LOGICAL_XOR((action->mod & MOD_MOD1), (ev->xkey.state & Mod1Mask))) { + if (LOGICAL_XOR((action->mod & MOD_META), (ev->xkey.state & MetaMask))) { continue; } - if (LOGICAL_XOR((action->mod & MOD_MOD2), (ev->xkey.state & Mod2Mask))) { + if (LOGICAL_XOR((action->mod & MOD_ALT), (ev->xkey.state & AltMask))) { continue; } - if (LOGICAL_XOR((action->mod & MOD_MOD3), (ev->xkey.state & Mod3Mask))) { - continue; - } - if (LOGICAL_XOR((action->mod & MOD_MOD4), (ev->xkey.state & Mod4Mask))) { - continue; - } - if (LOGICAL_XOR((action->mod & MOD_MOD5), (ev->xkey.state & Mod5Mask))) { + if (((action->mod & MOD_MOD1) && !(ev->xkey.state & Mod1Mask)) || (!(action->mod & MOD_MOD1) && (ev->xkey.state & Mod1Mask) && !(Mod1Mask & m))) { + continue; + } + if (((action->mod & MOD_MOD2) && !(ev->xkey.state & Mod2Mask)) || (!(action->mod & MOD_MOD2) && (ev->xkey.state & Mod2Mask) && !(Mod2Mask & m))) { + continue; + } + if (((action->mod & MOD_MOD3) && !(ev->xkey.state & Mod3Mask)) || (!(action->mod & MOD_MOD3) && (ev->xkey.state & Mod3Mask) && !(Mod3Mask & m))) { + continue; + } + if (((action->mod & MOD_MOD4) && !(ev->xkey.state & Mod4Mask)) || (!(action->mod & MOD_MOD4) && (ev->xkey.state & Mod4Mask) && !(Mod4Mask & m))) { + continue; + } + if (((action->mod & MOD_MOD5) && !(ev->xkey.state & Mod5Mask)) || (!(action->mod & MOD_MOD5) && (ev->xkey.state & Mod5Mask) && !(Mod5Mask & m))) { continue; } } diff --git a/src/actions.h b/src/actions.h index 52ff0b6..45996cc 100644 --- a/src/actions.h +++ b/src/actions.h @@ -44,12 +44,14 @@ typedef enum { #define MOD_CTRL (1UL << 0) #define MOD_SHIFT (1UL << 1) #define MOD_LOCK (1UL << 2) -#define MOD_MOD1 (1UL << 3) -#define MOD_MOD2 (1UL << 4) -#define MOD_MOD3 (1UL << 5) -#define MOD_MOD4 (1UL << 6) -#define MOD_MOD5 (1UL << 7) -#define MOD_ANY (1UL << 8) +#define MOD_META (1UL << 3) +#define MOD_ALT (1UL << 4) +#define MOD_MOD1 (1UL << 5) +#define MOD_MOD2 (1UL << 6) +#define MOD_MOD3 (1UL << 7) +#define MOD_MOD4 (1UL << 8) +#define MOD_MOD5 (1UL << 9) +#define MOD_ANY (1UL << 10) #define BUTTON_NONE (0) #define BUTTON_ANY (0xff) diff --git a/src/command.c b/src/command.c index 7d50205..ab566ae 100644 --- a/src/command.c +++ b/src/command.c @@ -160,6 +160,9 @@ static Atom DndProtocol, DndSelection; #ifdef USE_XIM XIC xim_input_context = NULL; /* input context */ static XIMStyle xim_input_style = 0; +# ifndef XSetIMValues +extern char *XSetIMValues(XIM im, ...); +# endif #endif /* Substitutes for missing system functions */ @@ -1693,15 +1696,15 @@ init_locale(void) { char *locale = NULL; - locale = setlocale(LC_CTYPE, ""); + locale = setlocale(LC_ALL, ""); TermWin.fontset = (XFontSet) -1; if (locale == NULL) { print_error("Setting locale failed."); } else { #ifdef MULTI_CHARSET - TermWin.fontset = create_fontset(etfonts[0], rs_mfont[0]); + TermWin.fontset = create_fontset(etfonts[def_font_idx], etmfonts[def_font_idx]); #else - TermWin.fontset = create_fontset(etfonts[0], "-misc-fixed-medium-r-semicondensed--13-*-75-*-c-*-iso10646-1"); + TermWin.fontset = create_fontset(etfonts[def_font_idx], "-misc-fixed-medium-r-semicondensed--13-*-75-*-c-*-iso10646-1"); #endif #ifdef USE_XIM # ifdef MULTI_CHARSET @@ -1971,16 +1974,30 @@ xim_set_status_position(void) void xim_set_fontset(void) { - XVaNestedList preedit_attr; - XVaNestedList status_attr; + XVaNestedList preedit_attr = NULL; + XVaNestedList status_attr = NULL; REQUIRE(xim_input_context != NULL); + if (xim_input_style & XIMStatusArea) { + status_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL); + } if (xim_input_style & (XIMPreeditArea | XIMPreeditPosition)) { preedit_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL); - status_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL); + } + + if (status_attr && preedit_attr) { XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL); + } else if (preedit_attr) { + XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL); + } else if (status_attr) { + XSetICValues(xim_input_context, XNStatusAttributes, status_attr, NULL); + } + + if (preedit_attr) { XFree(preedit_attr); + } + if (status_attr) { XFree(status_attr); } } diff --git a/src/command.h b/src/command.h index 02862bf..e8a8ca5 100644 --- a/src/command.h +++ b/src/command.h @@ -56,10 +56,10 @@ # define scrollbar_esc 30 /* Motif window hints */ -#define MWM_HINTS_FUNCTIONS (1L << 0) -#define MWM_HINTS_DECORATIONS (1L << 1) -#define MWM_HINTS_INPUT_MODE (1L << 2) -#define MWM_HINTS_STATUS (1L << 3) +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_INPUT_MODE (1L << 2) +#define MWM_HINTS_STATUS (1L << 3) /* bit definitions for MwmHints.functions */ #define MWM_FUNC_ALL (1L << 0) #define MWM_FUNC_RESIZE (1L << 1) @@ -68,13 +68,13 @@ #define MWM_FUNC_MAXIMIZE (1L << 4) #define MWM_FUNC_CLOSE (1L << 5) /* bit definitions for MwmHints.decorations */ -#define MWM_DECOR_ALL (1L << 0) -#define MWM_DECOR_BORDER (1L << 1) -#define MWM_DECOR_RESIZEH (1L << 2) -#define MWM_DECOR_TITLE (1L << 3) -#define MWM_DECOR_MENU (1L << 4) -#define MWM_DECOR_MINIMIZE (1L << 5) -#define MWM_DECOR_MAXIMIZE (1L << 6) +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) /* bit definitions for MwmHints.inputMode */ #define MWM_INPUT_MODELESS 0 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 diff --git a/src/events.c b/src/events.c index 0acb4d4..2def7b0 100644 --- a/src/events.c +++ b/src/events.c @@ -509,7 +509,6 @@ handle_expose(event_t * ev) REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); if (ev->xany.window == TermWin.vt) { if (refresh_type == NO_REFRESH) { - print_warning("Received Expose event while obscured. Possible X server bug!"); refresh_type = FAST_REFRESH; } scr_expose(ev->xexpose.x, ev->xexpose.y, ev->xexpose.width, ev->xexpose.height); diff --git a/src/font.c b/src/font.c index 66b36d4..dcb73eb 100644 --- a/src/font.c +++ b/src/font.c @@ -50,6 +50,7 @@ unsigned char font_idx = DEF_FONT_IDX, def_font_idx = DEF_FONT_IDX, font_cnt = 0 char *rs_font[NFONTS]; #ifdef MULTI_CHARSET char *rs_mfont[NFONTS]; +char **etmfonts = NULL; const char *def_mfontName[] = {MFONT0, MFONT1, MFONT2, MFONT3, MFONT4}; #endif const char *def_fontName[] = {FONT0, FONT1, FONT2, FONT3, FONT4}; @@ -309,6 +310,10 @@ change_font(int init, const char *fontname) font_idx = def_font_idx; ASSERT(etfonts != NULL); ASSERT(etfonts[font_idx] != NULL); +#ifdef MULTI_CHARSET + ASSERT(etmfonts != NULL); + ASSERT(etmfonts[font_idx] != NULL); +#endif } else { ASSERT(fontname != NULL); @@ -372,19 +377,19 @@ change_font(int init, const char *fontname) #ifdef MULTI_CHARSET if (TermWin.mfont) { - if (font_cache_find_info(rs_mfont[idx], FONT_TYPE_X) != TermWin.mfont) { + if (font_cache_find_info(etmfonts[font_idx], FONT_TYPE_X) != TermWin.mfont) { free_font(TermWin.mfont); - TermWin.mfont = load_font(rs_mfont[idx], "k14", FONT_TYPE_X); + TermWin.mfont = load_font(etmfonts[font_idx], "k14", FONT_TYPE_X); } } else { - TermWin.mfont = load_font(rs_mfont[idx], "k14", FONT_TYPE_X); + TermWin.mfont = load_font(etmfonts[font_idx], "k14", FONT_TYPE_X); } # ifdef USE_XIM if (xim_input_context) { if (TermWin.fontset) { XFreeFontSet(Xdisplay, TermWin.fontset); } - TermWin.fontset = create_fontset(etfonts[font_idx], rs_mfont[idx]); + TermWin.fontset = create_fontset(etfonts[font_idx], etmfonts[font_idx]); xim_set_fontset(); } # endif diff --git a/src/font.h b/src/font.h index 1880d50..cd6aabf 100644 --- a/src/font.h +++ b/src/font.h @@ -64,7 +64,7 @@ typedef struct cachefont_struct { extern unsigned char font_idx, def_font_idx, font_cnt; extern const char *def_fontName[]; extern char *rs_font[NFONTS]; -extern char **etfonts; +extern char **etfonts, **etmfonts; # ifdef MULTI_CHARSET extern const char *def_mfontName[]; extern char *rs_mfont[NFONTS]; diff --git a/src/menus.c b/src/menus.c index 4f1c437..146f5b7 100644 --- a/src/menus.c +++ b/src/menus.c @@ -449,7 +449,7 @@ menu_set_font(menu_t * menu, const char *fontname) font = (XFontStruct *) load_font(fontname, "fixed", FONT_TYPE_X); #ifdef MULTI_CHARSET - menu->fontset = create_fontset(fontname, rs_mfont[0]); + menu->fontset = create_fontset(fontname, etmfonts[def_font_idx]); #endif menu->font = font; diff --git a/src/options.c b/src/options.c index 3541c6b..69eab7d 100644 --- a/src/options.c +++ b/src/options.c @@ -235,6 +235,7 @@ static char *rs_pixmaps[image_max]; char *rs_theme = NULL; char *rs_config_file = NULL; unsigned int rs_line_space = 0; +unsigned int rs_meta_mod = 0, rs_alt_mod = 0, rs_numlock_mod = 0; #ifdef KEYSYM_ATTRIBUTE unsigned char *KeySym_map[256]; /* probably mostly empty */ #endif @@ -402,6 +403,9 @@ static const struct { OPT_LONG("big-font-key", "keysym for font size increase", &rs_bigfont_key), OPT_LONG("small-font-key", "keysym for font size decrease", &rs_smallfont_key), #endif + OPT_ILONG("meta-mod", "modifier to interpret as the Meta key", &rs_meta_mod), + OPT_ILONG("alt-mod", "modifier to interpret as the Alt key", &rs_alt_mod), + OPT_ILONG("numlock-mod", "modifier to interpret as the NumLock key", &rs_numlock_mod), #ifdef GREEK_SUPPORT OPT_LONG("greek-keyboard", "greek keyboard mapping (iso or ibm)", &rs_greek_keyboard), #endif @@ -1654,7 +1658,7 @@ parse_color(char *buff) n = NumWords(buff); if (n < 3) { print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for " - "attribute color", file_peek_path(), file_peek_line(), (tmp ? tmp : "")); + "attribute color", file_peek_path(), file_peek_line(), NONULL(tmp)); return; } tmp = PWord(2, buff); @@ -1687,14 +1691,14 @@ parse_color(char *buff) } else { tmp = Word(1, tmp); print_error("Parse error in file %s, line %lu: Invalid color index \"%s\"", - file_peek_path(), file_peek_line(), (tmp ? tmp : "")); + file_peek_path(), file_peek_line(), NONULL(tmp)); FREE(tmp); } } } if (n != 5) { print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for " - "attribute color", file_peek_path(), file_peek_line(), (tmp ? tmp : "")); + "attribute color", file_peek_path(), file_peek_line(), NONULL(tmp)); return; } g1 = PWord(4, buff); @@ -1742,7 +1746,7 @@ parse_color(char *buff) } else { tmp = Word(1, tmp); print_error("Parse error in file %s, line %lu: Invalid color index \"%s\"", - file_peek_path(), file_peek_line(), (tmp ? tmp : "")); + file_peek_path(), file_peek_line(), NONULL(tmp)); FREE(tmp); } } else { @@ -1785,7 +1789,7 @@ parse_attributes(char *buff) if (NumWords(buff) != 3) { print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for " - "attribute font", file_peek_path(), file_peek_line(), (tmp ? tmp : "")); + "attribute font", file_peek_path(), file_peek_line(), NONULL(tmp)); return; } if (isdigit(*tmp)) { @@ -1809,7 +1813,7 @@ parse_attributes(char *buff) } else { tmp = Word(1, tmp); print_error("Parse error in file %s, line %lu: Invalid font index \"%s\"", - file_peek_path(), file_peek_line(), (tmp ? tmp : "")); + file_peek_path(), file_peek_line(), NONULL(tmp)); FREE(tmp); } @@ -2060,6 +2064,36 @@ parse_keyboard(char *buff) print_warning("Support for the keysym attributes was not compiled in, ignoring"); #endif + } else if (!BEG_STRCASECMP(buff, "meta_mod ")) { + char *tmp = PWord(2, buff); + + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing modifier value for attribute meta_mod", + file_peek_path(), file_peek_line()); + return; + } + rs_meta_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); + + } else if (!BEG_STRCASECMP(buff, "alt_mod ")) { + char *tmp = PWord(2, buff); + + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing modifier value for attribute alt_mod", + file_peek_path(), file_peek_line()); + return; + } + rs_alt_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); + + } else if (!BEG_STRCASECMP(buff, "numlock_mod ")) { + char *tmp = PWord(2, buff); + + if (!tmp) { + print_error("Parse error in file %s, line %lu: Missing modifier value for attribute numlock_mod", + file_peek_path(), file_peek_line()); + return; + } + rs_numlock_mod = (unsigned int) strtoul(tmp, (char **) NULL, 0); + } else if (!BEG_STRCASECMP(buff, "greek ")) { #ifdef GREEK_SUPPORT @@ -2552,7 +2586,11 @@ parse_actions(char *buff) mod |= MOD_SHIFT; } else if (!BEG_STRCASECMP(str, "lock")) { mod |= MOD_LOCK; - } else if (!BEG_STRCASECMP(str, "mod1") || !BEG_STRCASECMP(str, "alt") || !BEG_STRCASECMP(str, "meta")) { + } else if (!BEG_STRCASECMP(str, "meta")) { + mod |= MOD_META; + } else if (!BEG_STRCASECMP(str, "alt")) { + mod |= MOD_ALT; + } else if (!BEG_STRCASECMP(str, "mod1")) { mod |= MOD_MOD1; } else if (!BEG_STRCASECMP(str, "mod2")) { mod |= MOD_MOD2; @@ -2754,14 +2792,14 @@ parse_multichar(char *buff) unsigned char n; if (NumWords(buff) != 3) { - print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for attribute font", - file_peek_path(), file_peek_line(), (tmp ? tmp : "")); + print_error("Parse error in file %s, line %lu: Invalid parameter list \"%s\" for " + "attribute font", file_peek_path(), file_peek_line(), NONULL(tmp)); return; } if (isdigit(*tmp)) { n = (unsigned char) strtoul(tmp, (char **) NULL, 0); - if (n <= 4) { - RESET_AND_ASSIGN(rs_mfont[n], Word(2, tmp)); + if (n <= 255) { + eterm_font_add(&etmfonts, PWord(2, tmp), n); } else { print_error("Parse error in file %s, line %lu: Invalid font index %d", file_peek_path(), file_peek_line(), n); @@ -3187,8 +3225,14 @@ post_parse(void) } } #ifdef MULTI_CHARSET - if (!rs_mfont[i]) { - rs_mfont[i] = StrDup(def_mfontName[i]); + if (rs_mfont[i]) { + if (def_font_idx == 0) { + eterm_font_add(&etmfonts, rs_mfont[i], i); + RESET_AND_ASSIGN(rs_mfont[i], NULL); + } else { + eterm_font_add(&etmfonts, rs_mfont[i], ((i == 0) ? def_font_idx : ((i <= def_font_idx) ? (i - 1) : i))); + RESET_AND_ASSIGN(rs_mfont[i], NULL); + } } #endif } @@ -3331,6 +3375,16 @@ post_parse(void) color_aliases(pointerColor); color_aliases(borderColor); + if (rs_meta_mod) { + MetaMask = modmasks[rs_meta_mod - 1]; + } + if (rs_alt_mod) { + AltMask = modmasks[rs_alt_mod - 1]; + } + if (rs_numlock_mod) { + NumLockMask = modmasks[rs_numlock_mod - 1]; + } + #ifdef BACKGROUND_CYCLING_SUPPORT if (rs_anim_pixmap_list != NULL) { rs_anim_delay = strtoul(rs_anim_pixmap_list, (char **) NULL, 0); @@ -3469,7 +3523,9 @@ save_config(char *path) fprintf(fp, " scrollbar_width %d\n", scrollbar_anchor_width()); fprintf(fp, " font default %u\n", (unsigned int) font_idx); for (i = 0; i < font_cnt; i++) { - fprintf(fp, " font %d %s\n", i, etfonts[i]); + if (etfonts[i]) { + fprintf(fp, " font %d %s\n", i, etfonts[i]); + } } #ifndef NO_BOLDFONT if (rs_boldFont) { @@ -3715,6 +3771,12 @@ save_config(char *path) if (action->mod & MOD_LOCK) { fprintf(fp, "lock "); } + if (action->mod & MOD_META) { + fprintf(fp, "meta "); + } + if (action->mod & MOD_ALT) { + fprintf(fp, "alt "); + } if (action->mod & MOD_MOD1) { fprintf(fp, "mod1 "); } @@ -3763,8 +3825,10 @@ save_config(char *path) if (rs_multichar_encoding) { fprintf(fp, " encoding %s\n", rs_multichar_encoding); } - for (i = 0; i < 5; i++) { - fprintf(fp, " font %d %s\n", i, rs_mfont[i]); + for (i = 0; i < font_cnt; i++) { + if (etmfonts[i]) { + fprintf(fp, " font %d %s\n", i, etmfonts[i]); + } } fprintf(fp, " end multichar\n\n"); #endif @@ -3811,7 +3875,16 @@ save_config(char *path) } tmp_str = XKeysymToString(ks_bigfont); if (tmp_str) { - fprintf(fp, " bigfont_key %s\n", XKeysymToString(ks_bigfont)); + fprintf(fp, " bigfont_key %s\n", tmp_str); + } + if (rs_meta_mod) { + fprintf(fp, " meta_mod %d\n", rs_meta_mod); + } + if (rs_alt_mod) { + fprintf(fp, " alt_mod %d\n", rs_alt_mod); + } + if (rs_numlock_mod) { + fprintf(fp, " numlock_mod %d\n", rs_numlock_mod); } for (i = 0; i < 256; i++) { if (KeySym_map[i]) { diff --git a/src/startup.c b/src/startup.c index 36a98d9..52358fc 100644 --- a/src/startup.c +++ b/src/startup.c @@ -150,6 +150,8 @@ eterm_bootstrap(int argc, char *argv[]) } #endif + get_modifiers(); /* Set up modifier masks before parsing config files. */ + read_config(THEME_CFG); read_config((rs_config_file ? rs_config_file : USER_CFG)); diff --git a/src/term.c b/src/term.c index 448370f..5b50a0b 100644 --- a/src/term.c +++ b/src/term.c @@ -93,6 +93,70 @@ char *def_colorName[] = }; char *rs_color[NRS_COLORS]; Pixel PixColors[NRS_COLORS + NSHADOWCOLORS]; +unsigned int MetaMask = 0, AltMask = 0, NumLockMask = 0; +unsigned int modmasks[] = { Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask }; + +void +get_modifiers(void) +{ + + unsigned short i; + XModifierKeymap *modmap; + KeyCode *kc; + + modmap = XGetModifierMapping(Xdisplay); + kc = modmap->modifiermap; + for (i = Mod5MapIndex; i >= Mod1MapIndex; i--) { + unsigned short j; + register unsigned short k, l; + + k = i * modmap->max_keypermod; + l = i - Mod1MapIndex; + + for (j = 0; j < modmap->max_keypermod; j++, k++) { + unsigned char match = 0; + + if (kc[k] == 0) { + break; + } + switch (XKeycodeToKeysym(Xdisplay, kc[k], 0)) { + case XK_Meta_L: + case XK_Meta_R: + D_X11(("get_modifiers() found Meta key as mod %d\n", l + 1)); + match = MetaMask = modmasks[l]; + break; + case XK_Alt_L: + case XK_Alt_R: + D_X11(("get_modifiers() found Alt key as mod %d\n", l + 1)); + match = AltMask = modmasks[l]; + break; + case XK_Num_Lock: + D_X11(("get_modifiers() found NumLock key as mod %d\n", l + 1)); + match = NumLockMask = modmasks[l]; + break; + default: + break; + } + if (match) { + break; + } + } + } + XFreeModifiermap(modmap); + if (MetaMask == 0) { + if (AltMask != 0) { + D_X11(("get_modifiers() defaulted Meta key to match Alt mask\n")); + MetaMask = AltMask; + } else { + D_X11(("get_modifiers() defaulted Meta key to mod 1\n")); + MetaMask = Mod1Mask; + } + } + if (AltMask == 0) { + D_X11(("get_modifiers() defaulted Alt key to match Meta mask\n")); + AltMask = MetaMask; /* MetaMask will always be defined at this point. */ + } +} /* To handle buffer overflows properly, we must malloc a buffer. Free it when done. */ #ifdef USE_XIM @@ -131,9 +195,9 @@ lookup_key(XEvent * ev) */ shft = (ev->xkey.state & ShiftMask); ctrl = (ev->xkey.state & ControlMask); - meta = (ev->xkey.state & Mod1Mask); - if (numlock_state || (ev->xkey.state & Mod5Mask)) { - numlock_state = (ev->xkey.state & Mod5Mask); /* numlock toggle */ + meta = (ev->xkey.state & MetaMask); + if (numlock_state || (ev->xkey.state & NumLockMask)) { + numlock_state = (ev->xkey.state & NumLockMask); PrivMode((!numlock_state), PrivMode_aplKP); } #ifdef USE_XIM @@ -646,7 +710,7 @@ sprintf((char *) kbuf,"\033[%02d~", (int)((n) + (keysym - fkey))); \ char *p; int i; - fprintf(stderr, "key 0x%04X[%d]: `", (unsigned int) keysym, len); + fprintf(stderr, "key 0x%04x[%d]: `", (unsigned int) keysym, len); for (i = 0, p = (char *) kbuf; i < len; i++, p++) fprintf(stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p); fprintf(stderr, "'\n"); diff --git a/src/term.h b/src/term.h index 5c68fef..d606078 100644 --- a/src/term.h +++ b/src/term.h @@ -162,10 +162,13 @@ extern unsigned long SavedModes; extern char *def_colorName[]; extern char *rs_color[NRS_COLORS]; extern Pixel PixColors[NRS_COLORS + NSHADOWCOLORS]; +extern unsigned int MetaMask, AltMask, NumLockMask; +extern unsigned int modmasks[]; /************ Function Prototypes ************/ _XFUNCPROTOBEGIN +extern void get_modifiers(void); extern void lookup_key(XEvent *); #ifdef PRINTPIPE extern FILE *popen_printer(void);