Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak joysticks and add CSS variables #63

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

medape
Copy link
Contributor

@medape medape commented Jan 8, 2022

Sorry I had this project abandoned for a long time (again). I did notice the latest issues and PR filed and I will look at them when I find the time. As usual, I come with more changes after a long hiatus.

This PR mixes several small changes with big changes; the most drastic one is that all settings hardcoded in the JavaScript side are now moved to the CSS side, along with the layouts and their style options. This allows us to potentially have different settings for different controls and/or different layouts.

Here is an excerpt from current base.css. Currently it's way too verbose and could possibly be better organized:

.control { /* Do not modify this line: */ z-index: 2;

    /* Default Yoke configuration follows.
     * Times can be given as milliseconds (8ms) or seconds (8s).
     * Boolean options can be given as yes/true or no/none/false.
     * Numbers can be given as-is, or as percentages.
     * Most options may be disabled setting all values to 0/no/none/false. */

    /* The area that a joystick or knob covers is divided in 8 octants.
     * Yoke can vibrate when the finger changes octants. */
    --vibrate-on-octant-edge: 20ms;
    /* Vibration pattern when the finger is over the joystick edge.
     * The first value is the vibration time,
     * the second value is the relaxation time. */
    --vibrate-on-edge: 9ms 11ms;
    /* If `yes` or `true`, the vibration becomes stronger the
     * farther the joystick is pushed beyond its borders. */
    --vibrate-proportionally-to-distance: no;
    /* Tactile feedback when a control "clicks", for example:
     * thumbstick is pressed down to simulate L3/R3 button;
     * a button or a D-pad leg is clicked.
     * (Yoke never vibrates on finger release to avoid crosstalk). */
    --vibrate-on-click: 40ms;
    /* Tactile feedback when a knob or joystick is touched: */
    --vibrate-on-touch: 40ms;
    /* Width and height of a central deadzone:
     * (round or square, depending on the shape of the control itself). */
    --center-deadzone: 10% 10%;
    /* Calibration for pressure-sensitive controls.
     * The first value is the minimum pressure that will engage it,
     * while the second value is the pressure that will saturate it.
     * The meaning for joysticks is slightly different; see below. */
    --force-thresholds: 10% 40%;
    /* The controller always is centered in the area assigned to it.
     * Some controls can have different shapes:
     * - rectangle (covers the whole area);
     * - square (covers the maximum square that fits in the area)
     * - ellipse (whose axes match the area's width and height)
     * - circle (covers the maximum circle that fits in the area)
     * Not all of the controllers accept all shapes. Some of them will
     * be rectangular in spite of this setting: */
    --shape: rectangle;
}

/* Variables after this line override the defaults above for specific controls.
 * Some variables only are defined for one specific type of control (like D-pads.) */

/* Joysticks */
.joystick {
    --vibrate-on-click: 45ms;
    /* Calibration for finger pressure.
     * On joysticks, the first value has no effect yet.
     * The second value is only used on joysticks with a L3/R3 button below,
     * and determines at which pressure is it considered pressed. */
    --force-thresholds: 10% 20%;
    /* Determines the shape of both the joystick itself and the central deadzone, if any.
     * If circle or ellipse, specify only one percentage (from center to edge).
     * If rectangle or square, specify the percentage per axis */
    --shape: rectangle;
    --center-deadzone: 10% 10%;
}

This also allows us to fine-tune the behaviour of joysticks. For the moment, default options for the joysticks are:

  • s, rectangular joysticks with a lineal, scaled dead zone per axis, and a joystick which doesn't auto-centre when released
  • j, same as above, but the joystick auto-centres.
  • t, same as above, but the joystick is now round and the dead zone is radial. The controller will start to vibrate and the input will be rescaled when the joystick goes beyond this round border.

These defaults can be changed through the options --shape and --center-deadzone. In the future, I will probably add a --sticky flag and extend the --shape parameter to more types of control (for example, to better control the aesthetics of buttons).

Also, controls are reported in a different order; this avoids unexpected behaviours such as the first and more important button being under the thumb joysticks by default. (All programs that depend on Yoke, and some programs on Linux can't look at the event codes in events.py.)

In a future update, I can add a flag to yoke so that the D-Pad will be reported as a hat switch. This should improve the auto-detection of the D-Pad in both OSs (because, again, programs cannot or will not notice the BTN_DPAD scancodes). This still requires some testing and changes that would conflict with PR #62 by JingMatrix, so I decided to postpone working on this.

This commit adds CSS variables and a codebase that for now, is unused.
In a future commit, most variables will be read from the CSS instead of
hardcoded in the JavaScript.
This allows users to both fine-tune Yoke more easily, and also to fix
settings per layout and per control (for example, the first button from
a given layout might need extra force to be pushed).

CSS blocks have also been moved around for the user's convenience.
Critical parameters that users should not touch are now at the bottom of
the file.
Parameters at the top will be overridden by parameters at the bottom,
following normal CSS priority rules.
No examples are given for this, but parameters bound to any specific
control by ID (e.g. "#j1") would be given a higher priority.
Joysticks can now be elliptical, square, round or rectangular.
A central deadzone is also supported, which depends on the joystick shape:
rectangular joysticks have axial deadzones (evaluated separately for each
component), while round joysticks have a single radial deadzone.

Both deadzones are scaled, meaning that output grows gradually from the
edge of the deadzone to the edge of the joystick.
- D-pad and knobs are compatible now with all four shapes
- D-pads, knobs, and joysticks use similar CSS and JS
- Knobs have now an image (made with Inkscape and manually trimmed down),
- D-pads use now CSS filters instead of hardcoded shadows
Also, remove bg.svg, bm.svg, bs.svg, which have been superseded by
button.svg#bg, #bm and #bs.
Several programs on Linux (and all programs in Windows, due to a design
decision on Yoke) ignore the semantics of every button and only look at
the order in which they are reported.

Because of this, the JavaScript side now reorders controls to simplify
most configurations (face buttons should go first, then in-game menu
buttons, then thumbstick buttons, and then special buttons like the
branded key to open the system menu, which is even less used in this
scenario).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant