Skip to content

mouse_grid

The community/core/mouse_grid directory contains the code for a mouse grid system in Talon. This system allows users to quickly move the mouse cursor to specific locations on the screen using a grid-based approach. The core logic is in mouse_grid.py, with supporting Talon files for commands and tags.

  • mouse_grid_always.talon defines commands that are always available for interacting with the mouse grid. These commands include:

    • mouse grid: Activates the grid on the primary screen.
    • grid win: Places the grid on the current window.
    • grid <user.number_key>+: Activates the grid and narrows it to the specified number.
    • grid screen [<number>]: Activates the grid on the specified screen number.
  • mouse_grid.talon defines a command M grid that is no longer recommended, and instead directs the user to use the mouse grid command. It also adds the user.mouse_grid_enabled tag, which is deprecated.

  • mouse_grid_open.talon contains commands that are available when the mouse grid is active, indicated by the user.mouse_grid_showing tag. These commands include:

    • <user.number_key>: Narrows the grid to the corresponding number.
    • grid (off | close | hide): Closes the grid.
    • grid reset: Resets the grid to the full screen.
    • grid back: Moves the grid back to the previous state.
  • mouse_grid.py contains the core Python logic for the mouse grid. It defines the MouseSnapNine class, which handles the grid's state, drawing, and interaction. Key functions include:

    • setup: Initializes the grid, setting the screen and rect based on the arguments or defaults.
    • show: Activates the grid by registering the draw function with the canvas, and disabling tracking control if active.
    • close: Deactivates the grid, and re-enables tracking control.
    • draw: Draws the grid on the canvas, including lines, numbers, and an optional zoomed view.
    • calc_narrow: Calculates the new rectangle for a given grid number.
    • narrow: Narrows the grid to a specific section and moves the mouse cursor to the center of that section.
    • update_screenshot: Updates the image used for the zoom view.
    • draw_zoom: Draws the zoomed in view of the current selection.
    • save_state: Saves the current state so the user can go back to it.
    • go_back: Sets the grid back to a previous state. The GridActions class defines the actions called by the talon files to implement the features.

The files work together to provide a fully functional mouse grid system: mouse_grid_always.talon and mouse_grid.talon provide the initial commands to activate the grid, while mouse_grid_open.talon contains the commands for when the grid is showing. The mouse_grid.py script handles the drawing and logic of the grid based on the commands from the .talon files. The files are set up to be easily customizable using user settings.