qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

pointing_device_auto_mouse.h (5162B)


      1 /* Copyright 2022 Alabastard
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #pragma once
     18 
     19 #include <stdint.h>
     20 #include <stdbool.h>
     21 #include "pointing_device.h"
     22 #include "keycodes.h"
     23 #include "action.h"
     24 #include "report.h"
     25 #include "action_layer.h"
     26 #include "action_tapping.h"
     27 
     28 /* check settings and set defaults */
     29 #ifndef POINTING_DEVICE_AUTO_MOUSE_ENABLE
     30 #    error "POINTING_DEVICE_AUTO_MOUSE_ENABLE not defined! check config settings"
     31 #endif
     32 
     33 #ifndef AUTO_MOUSE_DEFAULT_LAYER
     34 #    define AUTO_MOUSE_DEFAULT_LAYER 1
     35 #endif
     36 #ifndef AUTO_MOUSE_TIME
     37 #    define AUTO_MOUSE_TIME 650
     38 #endif
     39 #ifndef AUTO_MOUSE_DELAY
     40 #    define AUTO_MOUSE_DELAY GET_TAPPING_TERM(QK_MOUSE_BUTTON_1, &(keyrecord_t){})
     41 #endif
     42 #ifndef AUTO_MOUSE_DEBOUNCE
     43 #    define AUTO_MOUSE_DEBOUNCE 25
     44 #endif
     45 #ifndef AUTO_MOUSE_THRESHOLD
     46 #    define AUTO_MOUSE_THRESHOLD 10
     47 #endif
     48 
     49 /* data structure */
     50 typedef struct {
     51     mouse_xy_report_t x;
     52     mouse_xy_report_t y;
     53     int8_t            v;
     54     int8_t            h;
     55 } total_mouse_movement_t;
     56 typedef struct {
     57     struct {
     58         bool     is_enabled;
     59         uint8_t  layer;
     60         uint16_t timeout;
     61         uint8_t  debounce;
     62     } config;
     63     struct {
     64         uint16_t active;
     65         uint16_t delay;
     66     } timer;
     67     struct {
     68         bool   is_activated;
     69         bool   is_toggled;
     70         int8_t mouse_key_tracker;
     71     } status;
     72     total_mouse_movement_t total_mouse_movement;
     73 } auto_mouse_context_t;
     74 
     75 /* ----------Set up and control------------------------------------------------------------------------------ */
     76 void          set_auto_mouse_enable(bool enable);                       // enable/disable auto mouse feature
     77 bool          get_auto_mouse_enable(void);                              // get auto_mouse_enable
     78 void          set_auto_mouse_layer(uint8_t layer);                      // set target layer by index
     79 uint8_t       get_auto_mouse_layer(void);                               // get target layer index
     80 void          set_auto_mouse_timeout(uint16_t timeout);                 // set layer timeout
     81 uint16_t      get_auto_mouse_timeout(void);                             // get layer timeout
     82 void          set_auto_mouse_debounce(uint8_t debounce);                // set debounce
     83 uint8_t       get_auto_mouse_debounce(void);                            // get debounce
     84 void          set_auto_mouse_key_tracker(int8_t key_tracker);           // set key tracker
     85 int8_t        get_auto_mouse_key_tracker(void);                         // get key tracker
     86 void          auto_mouse_layer_off(void);                               // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!)
     87 layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force); // remove auto mouse target layer from state if appropriate (can be forced)
     88 bool          is_auto_mouse_active(void);                               // check if target layer is active
     89 /* ----------For custom pointing device activation----------------------------------------------------------- */
     90 bool auto_mouse_activation(report_mouse_t mouse_report); // handles pointing device trigger conditions for target layer activation (overwritable)
     91 
     92 /* ----------Handling keyevents------------------------------------------------------------------------------ */
     93 void auto_mouse_keyevent(bool pressed);      // trigger auto mouse keyevent: mouse_keytracker increment/decrement on press/release
     94 void auto_mouse_reset_trigger(bool pressed); // trigger non mouse keyevent: reset and start delay timer (DO NOT USE in layer_state_set stack!!)
     95 void auto_mouse_toggle(void);                // toggle mouse layer flag disables mouse layer deactivation while on (meant for tap toggle or toggle of target)
     96 bool get_auto_mouse_toggle(void);            // get toggle mouse layer flag value
     97 
     98 /* ----------Callbacks for adding keycodes to mouse record checking------------------------------------------ */
     99 bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record);
    100 bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record);
    101 
    102 /* ----------Core functions (only used in custom pointing devices or key processing)------------------------- */
    103 void pointing_device_task_auto_mouse(report_mouse_t mouse_report); // add to pointing_device_task_*
    104 bool process_auto_mouse(uint16_t keycode, keyrecord_t* record);    // add to process_record_*
    105 
    106 /* ----------Macros/Aliases---------------------------------------------------------------------------------- */
    107 #define AUTO_MOUSE_TARGET_LAYER get_auto_mouse_layer()
    108 #define AUTO_MOUSE_ENABLED get_auto_mouse_enable()