Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.autosave.xopp
*~
config.lua
14 changes: 14 additions & 0 deletions config.lua.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Configuration for vi-xournalpp plugin
-- Copy this file to config.lua and customize

local layouts = require('layouts')

-- Set your keyboard layout: 'qwerty', 'dvorak', or 'colemak'
layouts.active_layout = 'qwerty'

-- Optional: Override specific keys
-- layouts.key_overrides = {
-- ['w'] = 'j',
-- }

return layouts
126 changes: 126 additions & 0 deletions layouts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
-- Keyboard layout mappings for vi-xournalpp plugin
-- This file contains default layout definitions
-- To customize, copy config.lua.example to config.lua and modify it

local config = {}

-- Active keyboard layout
-- Options: 'qwerty', 'dvorak', 'colemak', or your custom layout name
config.active_layout = 'qwerty'

-- Custom key overrides (optional)
-- Use this to override specific keys for your personal preference
-- This applies AFTER layout mapping
-- Example: config.key_overrides = { ['w'] = 'j', ['s'] = 'k' }
config.key_overrides = {}

-- Keyboard layout mappings
-- Maps QWERTY keys to their physical equivalents on other layouts
-- This preserves hand movement and muscle memory across layouts
config.layout_map = {
qwerty = {},

dvorak = {
['q'] = 'apostrophe',
['w'] = 'comma',
['e'] = 'period',
['r'] = 'p',
['t'] = 'y',
['y'] = 'f',
['u'] = 'g',
['i'] = 'c',
['o'] = 'r',
['p'] = 'l',
['a'] = 'a',
['s'] = 'o',
['d'] = 'e',
['f'] = 'u',
['g'] = 'i',
['h'] = 'd',
['j'] = 'h',
['k'] = 't',
['l'] = 'n',
['z'] = 'semicolon',
['x'] = 'q',
['c'] = 'j',
['v'] = 'k',
['b'] = 'x',
['n'] = 'b',
['m'] = 'm',
['comma'] = 'w',
['period'] = 'v',
['slash'] = 'z',
['less'] = '<Shift>w',
['greater'] = '<Shift>v',
['question'] = '<Shift>z',
},

colemak = {
['q'] = 'q',
['w'] = 'w',
['e'] = 'f',
['r'] = 'p',
['t'] = 'g',
['y'] = 'j',
['u'] = 'l',
['i'] = 'u',
['o'] = 'y',
['p'] = 'semicolon',
['a'] = 'a',
['s'] = 'r',
['d'] = 's',
['f'] = 't',
['g'] = 'd',
['h'] = 'h',
['j'] = 'n',
['k'] = 'e',
['l'] = 'i',
['z'] = 'z',
['x'] = 'x',
['c'] = 'c',
['v'] = 'v',
['b'] = 'b',
['n'] = 'k',
['m'] = 'm',
},
}

-- Helper function to map keys with modifiers dynamically
function config.map_key(key, layout_map)
if not key or key == '' or not layout_map then
return key
end

-- Extract modifiers and base key
local modifiers = {}
local base_key = key

for modifier in key:gmatch('<([^>]+)>') do
table.insert(modifiers, modifier)
end

-- Get base key (everything after last >)
if #modifiers > 0 then
base_key = key:match('[^>]+$') or ''
end

if base_key == '' then
return key
end

-- Map the base key
local mapped_base = layout_map[base_key] or base_key

-- Reconstruct with modifiers
if #modifiers > 0 then
local result = ''
for _, mod in ipairs(modifiers) do
result = result .. '<' .. mod .. '>'
end
return result .. mapped_base
end

return mapped_base
end

return config
35 changes: 35 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@ require('modes')

f = {}

-- Apply config if it exists
local function apply_config()
local success, config = pcall(require, 'config')
if not success or type(config) ~= 'table' then
if success and type(config) ~= 'table' then
print('vi-xournalpp: config.lua exists but does not return a table')
end
return
end

local layout = config.active_layout or 'qwerty'
local layout_map = config.layout_map and config.layout_map[layout]
local key_overrides = config.key_overrides or {}

if not layout_map and layout ~= 'qwerty' then
print("vi-xournalpp: Unknown layout '" .. layout .. "', using qwerty.")
layout_map = config.layout_map and config.layout_map.qwerty
end

for _, binding in pairs(keybindings) do
local new_buttons = {}
for _, button in ipairs(binding.buttons) do
local mapped_button = button
if layout_map and layout ~= 'qwerty' then
mapped_button = config.map_key(button, layout_map)
end
mapped_button = key_overrides[mapped_button] or mapped_button
table.insert(new_buttons, mapped_button)
end
binding.buttons = new_buttons
end
end

apply_config()

function initUi()
index = 1
for _, binding in pairs(keybindings) do
Expand Down
Loading