Skip to content

def3r/haka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haka

Simply select text, press the key combination, and it's added to your file! Without cluttering your clipboard buffer with one-time-use text.

All using Haka, a low level global keyboard event listener for Wayland.
Haka demo

Project Aim

This project aims to solve a problem I face when making notes: efficiently creating and organizing notes when you have a large volume of resources and limited time.

The Problem with Existing Solutions

  1. Highlighting important points across different sources (web pages, PDFs, ebooks) makes it hard to search for a specific point in a centralized way.
  2. Manual Copy Pasta is extremely slow with many steps involved,
    1. Select the point with your mouse
    2. Hit the <C-c>
    3. Switch to the editor
    4. Hit the <C-v>
    5. Switch back to the resource
    This may not look a lot but this breaks the flow and I do get annoyed hitting so many keystrokes.

The Solution

What if life was as simple as:

  1. Select the point with your mouse (unfortunately)
  2. Hit a <Key-Combo>
By eliminating the redundant steps, Haka allows you to capture key points without breaking your concentration and also allows you to fuzzy find notes later.

build

Dependencies

build.sh includes the installation of all the dependencies, but only for arch and debian based distros. For any other distribution, kindly install the aforementioned dependencies. Or simply use the based Makefile

For Arch / Debian based distros:

From your favourite terminal, execute the build.sh script for installation

chmod +x build.sh
./build.sh

Permissions

To access the input group and access the event devices using libevdev, one needs root privileges. Although running haka as the root user has many issues, the most critiacl being the current user session, including the primary clipboard, is not available when running as root.

To resolve this issue, we use the capabilities(7) to grant haka the permission to change its group ID to input. Now haka can run as a user process and still be able to access the evdev. Credit for this workaround goes to this blog.

Note

build.sh handles this implicitly. If you used build.sh to build haka, this has been performed already.

sudo setcap "cap_setgid=eip" ./haka.out
./haka.out     # no sudo required while running

haka.service

If you want to use haka as a new-style systemd daemon to run in the background, use daemon.sh to generate the unit file for systemd.

daemon.sh creates the unit file required to run as a --user daemon and it creates a symlink of the unit file to ~/.config/systemd/user/

Note

Make sure to execute daemon.sh from the directory containing haka.out. If you renamed the executable, edit the HAKA variable in daemon.sh

chmod +x daemon.sh
./daemon.sh

Check logs:

journalctl --user -u haka.service -f

Config

Config file for haka must be named haka.cfg which must be present in the same directory as the haka executable. The haka config parser allows you to use command substitution for configuration values. For example, you can specify the editor dynamically using:

editor=$(which emacs)

Config Options

Option Value Description
editor /path/to/editor/bin Specify the editor to open files in
terminal /path/to/terminal/bin Specify the terminal to open editor in
notes-dir /path/to/notes/dir Custom path to notes dir
tofi-cfg /path/to/tofi/cfg Custom path for tofi.cfg file

Guide

  • The files displayed in the selection menu is the notes/ directory and can be found in the directory containing haka executable
  • The file is opened by default in neovim
  • haka currently supports the first 249 KEY_NAME defined in linux/input-event-codes.h

KeyBinds

  • The defualt ActivationCombo is Ctr+Alt
  • The default keybinds and activation combo are set in the src/bindings.c.
  • To make custom keybinds, create a function with this prototype: void func(struct hakaStatus *haka). Add its declaration in include/hakaEventHandler.h and implement it in src/hakaEventHandler.c. Now bind your action to a key in src/bindings.c using the Bind(function, KEY_TOBIND...) macro. Refer linux/input-event-codes.h for KEY_NAME macros.

Important

Do not use open or close on haka->fdNotesFile, since state is internally managed by eventHandlerEpilogue, use wrappers around it like openNotesFile and closeNotesFile.

Key Combination Binded Task
Ctrl+Alt + C Paste the current selection to the current file
Ctrl+Alt + . Paste the current selection as an unordered list item to the current file
Ctrl+Alt + N Send a Blank Line to the current file
Ctrl+Alt + M Opens the file selection menu
Ctrl+Alt + O Opens the file in neovim

TODO

  • Switch to gtk(?): to reduce dependencies.
  • Add a config file option for vars.
  • Ignore newlines in selection(?)
  • Improve bindings implementation