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

[Feature] Force Numpad to act like a Mac #743

Open
RedBearAK opened this issue Aug 18, 2022 · 1 comment
Open

[Feature] Force Numpad to act like a Mac #743

RedBearAK opened this issue Aug 18, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@RedBearAK
Copy link
Contributor

RedBearAK commented Aug 18, 2022

I'm in the process of making a feature I've been thinking about for a long time: Forced Numpad. (Edit: Renamed to "Mac Numpad").

On a Mac, the numeric keypad is always a numeric keypad, and the Numlock key is "Clear" (Escape key), used for clearing the display of a calculator app. I think you can actually toggle real Numlock on a Mac with Fn+Numlock. I'll use Option+Numlock (physical Super+Numlock, logical Alt+Numlock on a PC keyboard) as a toggle to turn this "Forced Numpad" feature on and off, but we can also support Fn+Numlock for Apple keyboards where Kinto can actually "see" the Fn key.

This maps onto the non-keypad keys for Linux because GTK apps may not interpret the keys as numbers otherwise.

Here is a working version of this for Linux. Will post a Windows/AHK version when I get a chance to put it together, and then combine them into a PR.

#########################################################
###########   START OF MAC NUMPAD FEATURE   #############
#########################################################
# Force the numpad to always be a numpad, like a Mac keyboard on macOS
# Numlock key becomes "Clear" key for use with calculator (sends Escape)
# Toggle feature on/off with Option+Numlock (Fn+Numlock might work on Apple keyboards)
# Set _mac_numpad var to "False" (no quotes) to disable by default
_mac_numpad = True
_mac_numpad_first_run = True

def mac_numpad_alert():
    global _mac_numpad_first_run
    if _mac_numpad:
        run('notify-send -u critical ALERT "Kinto Mac Numpad is now ENABLED.\
            \rNumlock == Clear (Escape)\
            \rDisable with Option+Numlock."', shell=True)
        print("(DD) Kinto Mac Numpad is now ENABLED.", flush=True)
    # Don't show pointless alert on startup if feature is set to be disabled by default
    if not _mac_numpad and not _mac_numpad_first_run:
        run('notify-send ALERT "Kinto Mac Numpad is now DISABLED.\
            \rRe-enable with Option+Numlock."', shell=True)
        print("(DD) Kinto Mac Numpad is now DISABLED.", flush=True)
    _mac_numpad_first_run = False


mac_numpad_alert()


def toggle_mac_numpad():
    """Toggle the value of the _optspecialchars variable"""
    from subprocess import run
    def _toggle_mac_numpad():
        global _mac_numpad
        _mac_numpad = not _mac_numpad
        mac_numpad_alert()

    return _toggle_mac_numpad


define_keymap(lambda wm_class: wm_class.casefold() not in remotes,{
    C("Alt-Numlock"):       toggle_mac_numpad(),
    C("Fn-Numlock"):        toggle_mac_numpad(),
},"Mac Numpad toggle")

define_keymap(lambda wm_class: wm_class.casefold() not in remotes and _mac_numpad is True,{
    C("KP1"):               C("1"),
    C("KP2"):               C("2"),
    C("KP3"):               C("3"),
    C("KP4"):               C("4"),
    C("KP5"):               C("5"),
    C("KP6"):               C("6"),
    C("KP7"):               C("7"),
    C("KP8"):               C("8"),
    C("KP9"):               C("9"),
    C("KP0"):               C("0"),
    C("KPDot"):             C("Dot"),
    C("Numlock"):           C("Esc"),
},"Mac Numpad")

#######################################################
###########   END OF MAC NUMPAD FEATURE   #############
#######################################################
@RedBearAK RedBearAK added the enhancement New feature or request label Aug 18, 2022
@RedBearAK
Copy link
Contributor Author

@rbreaves

Bundled the Linux and Windows versions together in PR #744.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants