Skip to content

Commit

Permalink
[Keymap] Badger keymaps/userspace (qmk#10239)
Browse files Browse the repository at this point in the history
* Badger keymaps

* bug fix - linter

* code review feedback and ortholinear bugs

* cleanup

* backing out suspect bug after doing additional research

* code review feedback

* code review feedback

* changing default badger keymap and small bugfix
  • Loading branch information
BlueTufa authored Sep 17, 2020
1 parent e44e552 commit cd43c1a
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 0 deletions.
31 changes: 31 additions & 0 deletions users/badger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# A multi-OS keyboard layout with support for both Linux (KDE) and MacOS-specific QWERTY layouts for many 60-ish% keyboards (

## Author: [BlueTufa](https://github.com/BlueTufa)

> Supported Keyboards: 1up RGB and HTE, Clueboard 66, dztech 60 RGB, and partial support for Preonic and Planck ortholinear keyboards.
## Layouts

### QWERTY
Default layer: Standard QWERTY layer with CAPS lock mapped to ESC. ESC is a Layer toggle, when held down it maps to KDE-specific MOVE layer. Dedicated Function key for ADJUST layer. I also take advantage of the AG_SWAP when using this keyboard on Linux, which swaps between ALT and GUI on both sides.

Mac layer: Mostly the same as the default layer, except that the ESC key maps to a MacOS specific set of MOVE layer shortcuts. These leverage a piece of software called Rectangle, which makes up for some of the tiling shortcomings of MacOS.

### MOVE layer
OS-specific convenience shortcuts. Macros are defined to make it easier to adapt these to other operating systems. The macros also help maintain the spacing that helps with the readability of the layers in source control.

The main goal of the MOVE layer is to manage window move and resize, and jump to a specific virtual desktop. The other function is to expose VIM-style move keys as arrow keys to other applications. Some keys from ADJUST layer are also redefined here.

Care was taken to keep the tiling and virtual desktop shortcuts as similar as possible between Linux and MacOS in this MOVE layer. The most notable difference is that I haven't found a good way to do corner tiling in Linux the way that it's supported in MacOS Rectangle.

REMINDER: The 9-key left-hand pattern requires the installation of the MacOS rectangle app:

```bash
brew cask install rectangle
```

### ADJUST layer
Access to function keys as well as media controls and keyboard settings. Some useful OS action keys are defined here as well.

### Config layer
Access to Quantum keyboard controls as well as RGB configuration. If audio is supported it would belong in this layer as well.
49 changes: 49 additions & 0 deletions users/badger/badger.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2020 Dan White <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "badger.h"

bool _capsLockState;

__attribute__ ((weak))
void keyboard_post_init_user(void) {
_capsLockState = false;
}

__attribute__ ((weak))
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case CS_RIGHT:
if (record->event.pressed) {
SEND_STRING(SS_LALT(SS_TAP(X_B)SS_TAP(X_ENTER)));
return false;
}
break;
case CS_DOWN:
if (record->event.pressed) {
SEND_STRING(SS_LALT(SS_TAP(X_V)SS_TAP(X_ENTER)));
return false;
}
break;
case KC_CAPS:
if (record->event.pressed) {
_capsLockState = !_capsLockState;
return true;
}
break;
default:
return true;
}
return true;
}
109 changes: 109 additions & 0 deletions users/badger/badger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright 2020 Dan White <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include QMK_KEYBOARD_H

enum layers {
_QWERTY_MAC,
_MOVE_MAC,
_QWERTY_LINUX,
_MOVE_LINUX,
_ADJUST,
_CONFIG
};

enum CustomKeys {
CS_RIGHT = SAFE_RANGE,
CS_DOWN
};

#define OS_POP LCTL(KC_F10)
#define MAC_POP LCTL(KC_UP)
#define MAC_FRC LGUI(LALT(KC_ESC))
#define OS_COPY LSFT(LCTL(KC_C))
#define OS_PAST LSFT(LCTL(KC_V))
#define MAC_PST LGUI(KC_V)
#define MAC_CPY LGUI(KC_C)
#define KC_BACK LCTL(LSFT(KC_LBRC))
#define KC_NEXT LCTL(LSFT(KC_RBRC))

#define MOVE LT(_MOVE_LINUX, KC_ESC)
#define MOVE_MAC LT(_MOVE_MAC, KC_ESC)
#define ADJUST MO(_ADJUST)
#define CFG_MAC LT(_CONFIG, MAC_POP)
#define CFG_LNX LT(_CONFIG, OS_POP)

#define WD_BACK LALT(KC_LEFT)
#define WD_FRWD LALT(KC_RIGHT)

#define VD_1 LCTL(KC_F1)
#define VD_2 LCTL(KC_F2)
#define VD_3 LCTL(KC_F3)

#define WM_UH LGUI(KC_UP)
#define WM_BH LGUI(KC_DOWN)
#define WM_LH LGUI(KC_LEFT)
#define WM_RH LGUI(KC_RIGHT)
#define WM_MAX LGUI(KC_PGUP)

#define CM_RIGHT LGUI(KC_D)
#define CM_DOWN LGUI(LSFT(KC_D))

/* THESE are not defaults in KDE and must be set manually */
#define WM_VD1 HYPR(KC_1)
#define WM_VD2 HYPR(KC_2)
#define WM_VD3 HYPR(KC_3)

/* IntelliJ / JetBrains shortcuts with Mac keymap */
#define IJ_BACK LGUI(LALT(KC_LEFT))
#define IJ_FWD LGUI(LALT(KC_RIGHT))
#define IJ_UP LGUI(LALT(KC_UP))
#define IJ_DOWN LGUI(LALT(KC_DOWN))
#define IJ_IMPL LGUI(LALT(KC_B))
#define IJ_DECL LGUI(KC_B)
#define IJ_REN LSFT(KC_F6)
#define IJ_USAG LALT(KC_F7)
#define IJ_RUN KC_F9
#define IJ_STEP KC_F8
#define IJ_INTO LSFT(KC_F7)
#define IJ_OUT LSFT(KC_F8)
#define IJ_STOP LGUI(KC_F2)
#define IJ_IMPS LCTL(LALT(LSFT(KC_EQUAL)))
#define IJ_IMPH LCTL(LALT(LSFT(KC_MINUS)))
#define IJ_TOP LGUI(KC_HOME)
#define IJ_BOTT LGUI(KC_END)
#define IJ_FIND LGUI(LSFT(KC_F))

/* MacOS virtual desktop shortcuts */
#define M_VD1 LCTL(KC_1)
#define M_VD2 LCTL(KC_2)
#define M_VD3 LCTL(KC_3)

/* rectangle shortcuts */
#define MM_ULCN LCTL(LGUI(KC_LEFT))
#define MM_URCN LCTL(LGUI(KC_RIGHT))
#define MM_LLCN LCTL(LSFT(LGUI(KC_LEFT)))
#define MM_LRCN LCTL(LSFT(LGUI(KC_RIGHT)))
#define MM_MAX LALT(LGUI(KC_F))
#define MM_LH HYPR(KC_LBRC)
#define MM_RH HYPR(KC_RBRC)
#define MM_UH LALT(LGUI(KC_UP))
#define MM_BH LALT(LGUI(KC_DOWN))
#define MM_LEFT LCTL(LALT(LGUI(KC_LEFT)))
#define MM_RGHT LCTL(LALT(LGUI(KC_RIGHT)))

#define DF_1 DF(_QWERTY_MAC)
#define DF_2 DF(_QWERTY_LINUX)
151 changes: 151 additions & 0 deletions users/badger/ortho.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
Copyright 2020 Dan White <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ortho.h"
#include "badger.h"

int _currentLayer;
bool _capsLock;

#ifdef AUDIO_ENABLE
float capsOnSong[][2] = SONG(CAPS_ON);
float capsOffSong[][2] = SONG(CAPS_OFF);
float defaultLayerSong[][2] = SONG(QWERTY_LAYER_SONG);
float moveLayerSong[][2] = SONG(MOVE_LAYER_SONG);
float macLayerSong[][2] = SONG(MAC_LAYER_SONG);
float raiseLayerSong[][2] = SONG(RAISE_LAYER_SONG);
float lowerLayerSong[][2] = SONG(LOWER_LAYER_SONG);
float agSwapSong[][2] = SONG(LONG_AG_SWAP);
float agNormSong[][2] = SONG(LONG_AG_NORM);
#endif

__attribute__ ((weak))
void keyboard_post_init_user(void) {
_capsLock = false;
_currentLayer = _QWERTY_MAC_ORTHO;
layer_on(_currentLayer);
}

__attribute__ ((weak))
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
dprintf("Key event recorded. KEYCODE: %u , event: %u\n", keycode, record->event.pressed);
switch (keycode) {
case CS_RIGHT:
if (record->event.pressed) {
SEND_STRING(SS_LALT(SS_TAP(X_B)SS_TAP(X_ENTER)));
return false;
}
break;
case CS_DOWN:
if (record->event.pressed) {
SEND_STRING(SS_LALT(SS_TAP(X_V)SS_TAP(X_ENTER)));
return false;
}
break;
case KC_CAPS:
if (record->event.pressed) {
dprintf("CAPS_LOCK state: %u\n", _capsLock);
_capsLock = !_capsLock;
#ifdef AUDIO_ENABLE
_capsLock ? PLAY_SONG(capsOnSong) : PLAY_SONG(capsOffSong);
#endif
return true;
}
break;
case AG_SWAP:
#ifdef AUDIO_ENABLE
PLAY_SONG(agSwapSong);
#endif
return true;
break;
case AG_NORM:
#ifdef AUDIO_ENABLE
PLAY_SONG(agNormSong);
#endif
return true;
break;
case KC_MAC2:
if (record->event.pressed) {
SEND_STRING("ll\n");
return false;
}
break;
case KC_MAC1:
if (record->event.pressed) {
SEND_STRING("open https://www.reddit.com/r/mechanicalkeyboards\n");
return false;
}
break;
case KC_FIRST:
if (record->event.pressed) {
// don't turn off the QWERTY layer
if (_currentLayer != _QWERTY_MAC_ORTHO) {
layer_off(_currentLayer);
}
_currentLayer = _QWERTY_MAC_ORTHO;
layer_on(_currentLayer);
playSongForLayer(_currentLayer);
return false;
}
break;
case KC_LYRC:
if (record->event.pressed) {
dprintf("LYR CYCLE pressed %u, CURRENT_LAYER: %u\n", keycode, _currentLayer);
// don't turn off the QWERTY layer or the ADJUST layer
if (_currentLayer != _QWERTY_MAC_ORTHO) {
layer_off(_currentLayer);
}
// don't lock the ADJUST layer
// since this key is accessible via the ADJUST
// layer, as it will require tricky state management
if (++_currentLayer == _ADJUST_ORTHO) {
_currentLayer = _QWERTY_MAC_ORTHO;
} else {
layer_on(_currentLayer);
}

playSongForLayer(_currentLayer);
return false;
}
break;
}
return true;
}

void playSongForLayer(int currentLayer) {
#ifdef AUDIO_ENABLE
switch (currentLayer) {
case _QWERTY_LINUX:
PLAY_SONG(defaultLayerSong);
break;
case _MOVE_LINUX:
PLAY_SONG(moveLayerSong);
break;
case _QWERTY_MAC:
PLAY_SONG(macLayerSong);
break;
case _MOVE_MAC:
PLAY_SONG(moveLayerSong);
break;
case _RAISE:
PLAY_SONG(raiseLayerSong);
break;
case _LOWER:
PLAY_SONG(lowerLayerSong);
break;
default:
break;
}
#endif
}
Loading

0 comments on commit cd43c1a

Please sign in to comment.