2020-10-26 22:45:22 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2020-10-31 13:43:09 +00:00
|
|
|
# key-mapper - GUI for device specific keyboard mappings
|
2020-10-26 22:45:22 +00:00
|
|
|
# Copyright (C) 2020 sezanzeb <proxima@hip70890b.de>
|
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# This file is part of key-mapper.
|
2020-10-26 22:45:22 +00:00
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# key-mapper is free software: you can redistribute it and/or modify
|
2020-10-26 22:45:22 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# key-mapper is distributed in the hope that it will be useful,
|
2020-10-26 22:45:22 +00:00
|
|
|
# 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
|
2020-10-31 13:02:59 +00:00
|
|
|
# along with key-mapper. If not, see <https://www.gnu.org/licenses/>.
|
2020-10-26 22:45:22 +00:00
|
|
|
|
|
|
|
|
2020-11-02 00:25:43 +00:00
|
|
|
"""Path constants to be used.
|
2020-10-26 22:45:22 +00:00
|
|
|
|
2020-11-02 00:25:43 +00:00
|
|
|
Is a module so that tests can modify them.
|
|
|
|
"""
|
2020-10-26 22:45:22 +00:00
|
|
|
|
|
|
|
|
2020-11-02 00:25:43 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2020-10-26 22:45:22 +00:00
|
|
|
|
2020-10-31 14:22:58 +00:00
|
|
|
|
2020-11-02 21:06:05 +00:00
|
|
|
# should not contain spaces
|
2020-11-02 00:25:43 +00:00
|
|
|
SYMBOLS_PATH = '/usr/share/X11/xkb/symbols/key-mapper'
|
2020-11-02 18:17:28 +00:00
|
|
|
KEYCODES_PATH = '/usr/share/X11/xkb/keycodes/key-mapper'
|
|
|
|
|
2020-11-02 00:25:43 +00:00
|
|
|
# since this needs to run as sudo,
|
|
|
|
# get the home dir of the user who called sudo.
|
|
|
|
who = subprocess.check_output('who').decode().split()[0]
|
|
|
|
CONFIG_PATH = os.path.join('/home', who, '.config/key-mapper')
|
2020-11-02 21:06:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_home_path(device, preset=''):
|
|
|
|
"""Get the path to the config file in /usr."""
|
|
|
|
return os.path.join(CONFIG_PATH, device, preset)
|
|
|
|
|
|
|
|
|
|
|
|
def get_usr_path(device, preset=''):
|
|
|
|
"""Get the path to the config file in /usr."""
|
|
|
|
return os.path.join(
|
|
|
|
SYMBOLS_PATH,
|
|
|
|
device.replace(' ', '_'),
|
|
|
|
preset.replace(' ', '_')
|
|
|
|
)
|