A Computer Scientist alumnus with a passion for the open-source community… no wonder I’m here!

  • 1 Post
  • 2 Comments
Joined 1 year ago
cake
Cake day: June 12th, 2023

help-circle

  • The results have made me realize that the bash way of doing this is just not worth attempting, and a Python script is much more simple. At the end of the day, I ended up using this GIST with a custom handler function:

    https://gist.github.com/dperelman/c1d3c966d397ff884abb8b3baf7990db

    class MouseProfile(Enum):
        DEFAULT = 0
        BLOONS = 1
        GAMING_COMMON = 2
        CALL_OF_DUTY = 3
        REALM_GRINDER = 4
    
    def handle_change(new_state: dict):
        """
        Using `libratbag`, switch the profile of the mouse based on the active window title.
        """
        # Get the title of the active window
        title: str = new_state['title']
        profile: MouseProfile = MouseProfile.DEFAULT
        match title:
            case "BloonsTD6":
                profile = MouseProfile.BLOONS
            case "Realm Grinder":
                profile = MouseProfile.REALM_GRINDER
            case _:
                if title:
                  if search(r"^Call of Duty.*", title):
                      profile = MouseProfile.CALL_OF_DUTY
                  elif search(r"^Deep Rock Galactic.*", title):
                      profile = MouseProfile.GAMING_COMMON
        # Send the ratbag command to switch the profile
        run(["ratbagctl", "Logitech", "profile", "active", "set", str(profile.value)], stdout=PIPE, stderr=PIPE)