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-09 22:16:30 +00:00
|
|
|
"""Path constants to be used."""
|
2020-10-26 22:45:22 +00:00
|
|
|
|
|
|
|
|
2020-11-02 00:25:43 +00:00
|
|
|
import os
|
2020-10-26 22:45:22 +00:00
|
|
|
|
2020-11-10 22:14:28 +00:00
|
|
|
# the path that contains ALL symbols, not just ours
|
|
|
|
X11_SYMBOLS = '/usr/share/X11/xkb/symbols'
|
2020-11-02 21:06:05 +00:00
|
|
|
|
2020-11-02 22:14:11 +00:00
|
|
|
# should not contain spaces
|
2020-11-15 19:27:06 +00:00
|
|
|
# getlogin gets the user who ran sudo
|
2020-11-10 22:14:28 +00:00
|
|
|
USERS_SYMBOLS = os.path.join(
|
2020-11-02 22:14:11 +00:00
|
|
|
'/usr/share/X11/xkb/symbols/key-mapper',
|
2020-11-08 18:50:30 +00:00
|
|
|
os.getlogin().replace(' ', '_')
|
2020-11-02 22:14:11 +00:00
|
|
|
)
|
2020-11-02 21:06:05 +00:00
|
|
|
|
2020-11-15 11:11:35 +00:00
|
|
|
# those are the same for every preset and user, they are needed to make the
|
|
|
|
# presets work.
|
2020-11-02 22:14:11 +00:00
|
|
|
KEYCODES_PATH = '/usr/share/X11/xkb/keycodes/key-mapper'
|
2020-11-02 21:06:05 +00:00
|
|
|
|
|
|
|
|
2020-11-15 11:11:35 +00:00
|
|
|
def get_usr_path(device=None, preset=None):
|
2020-11-02 22:14:11 +00:00
|
|
|
"""Get the path to the config file in /usr.
|
|
|
|
|
2020-11-08 15:27:26 +00:00
|
|
|
This folder is a symlink and the files are in ~/.config/key-mapper
|
|
|
|
|
2020-11-02 22:14:11 +00:00
|
|
|
If preset is omitted, returns the folder for the device.
|
|
|
|
"""
|
2020-11-15 11:11:35 +00:00
|
|
|
if device is None:
|
|
|
|
return USERS_SYMBOLS
|
|
|
|
|
2020-11-04 00:49:22 +00:00
|
|
|
device = device.strip()
|
2020-11-15 11:11:35 +00:00
|
|
|
|
2020-11-02 22:14:11 +00:00
|
|
|
if preset is not None:
|
2020-11-04 00:49:22 +00:00
|
|
|
preset = preset.strip()
|
2020-11-10 22:14:28 +00:00
|
|
|
return os.path.join(USERS_SYMBOLS, device, preset).replace(' ', '_')
|
2020-11-15 11:11:35 +00:00
|
|
|
|
|
|
|
if device is not None:
|
2020-11-10 22:14:28 +00:00
|
|
|
return os.path.join(USERS_SYMBOLS, device.replace(' ', '_'))
|
2020-11-15 19:27:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_SYMBOLS = get_usr_path('default')
|
2020-11-17 22:40:39 +00:00
|
|
|
EMPTY_SYMBOLS = get_usr_path('empty')
|