[sdl][S/O/FA/other]Alt and Meta keypress modifiers are ignored.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jsv
    Scout
    • Feb 2010
    • 27

    [sdl][S/O/FA/other]Alt and Meta keypress modifiers are ignored.

    Greetings.

    There is a bug in the SDL port that prevents alt/meta modifiers from being recognized. As the code in question is shared by many variants, I think here is a good place for a bug report. Correct me if I'm wrong.

    In the sdl_keypress function (main-sdl.c) we find this innocently looking code:

    Code:
            /* Store the value of various modifier keys */
            bool mc = (bool)(keysym.mod & (KMOD_CTRL));
            bool ms = (bool)(keysym.mod & (KMOD_SHIFT));
            bool ma = (bool)(keysym.mod & (KMOD_ALT));
            bool mm = (bool)(keysym.mod & (KMOD_META));
    It looks correct and it would work correctly if only there were built-in bool type in (pre-C99) C. But there is none and in many *bands bool is defined as char (Vanilla uses built-in boolean type when it's available, so it is not affected by this bug -- but only if compiled with something conforming to C99 standard). Values of KMOD_ALT and KMOD_META exceed 0x100. When cast to char they are truncated, so ma and mm are always zero.

    This can be fixed either by using int instead of bool for flags:
    Code:
        ...
        int mc = (keysym.mod & (KMOD_CTRL));
        ...
    or by explicit comparison with KMOD_NONE:
    Code:
        ...
        bool mc = (bool)((keysym.mod & (KMOD_CTRL) != KMOD_NONE);
        ...
    IMHO, even better solution would be to get rid of bool type entirely, removing it both from *band code and C standards -- the language just do not need it. But that would be too much work.
    S(1.0.0 final lf3+) W "Dagrin" L:100 DL:4500' A++ *R* Sp+ w:Mace of Disruption (adamant)
    O+/S+/Cr L H++ D/+ c f- PV+ s/- d@ P- M+
    C-- !S I- So+ B? ac GHB- SQ RQ+ V/- F:haggling!
  • Nick
    Vanilla maintainer
    • Apr 2007
    • 9637

    #2
    Thanks - fixed in FA and O dev versions.
    One for the Dark Lord on his dark throne
    In the Land of Mordor where the Shadows lie.

    Comment

    • Magnate
      Angband Devteam member
      • May 2007
      • 5110

      #3
      Finally fixed in V (staging branch - will be in nightlies shortly).
      "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

      Comment

      • camlost
        Sangband 1.x Maintainer
        • Apr 2007
        • 523

        #4
        I guess I'm slow on the uptake; I guess I can fix this tonight when I get home
        a chunk of Bronze {These look tastier than they are. !E}
        3 blank Parchments (Vellum) {No french novels please.}

        Comment

        Working...
        😀
        😂
        🥰
        😘
        🤢
        😎
        😞
        😡
        👍
        👎