Rolling back a commit.

main
Shinyzenith 2 years ago
parent 704d1f1e47
commit 6ce03e1bc3
No known key found for this signature in database
GPG Key ID: 6DD485917B553B7B

1
.gitignore vendored

@ -1,2 +1 @@
__pycache__
config.json

@ -1 +0,0 @@
libevdev

@ -6,11 +6,10 @@ import os
import pwd
import signal
import sys
from pathlib import Path
from utils.config import CONFIG_PARSER
from utils.input import INPUT_UTILS
from utils.log import LOG_UTILS
from utils.input import INPUT_UTILS
from utils.config import CONFIG_PARSER
class SWHKD:
@ -40,27 +39,14 @@ class SWHKD:
sys.exit(1)
# Config parsing
paths = []
if os.environ.get("XDG_CONFIG_HOME") is not None:
paths.append(Path(os.environ.get("XDG_CONFIG_HOME")) / "swhkd/config.json")
paths.append(Path("~/.config/swhkd/config.json"))
paths.append(Path.cwd() / "config.json")
paths.append(Path.cwd().parent / "config.json")
config = None
# Try every config and break on first success
for path in paths:
try:
config = await self.config_parser.parse("{0}swhkd/config.json".format(os.environ.get("XDG_CONFIG_HOME")))
except FileNotFoundError:
try:
config = await self.config_parser.parse(path)
config = await self.config_parser.parse("~/.config/swhkd/config.json")
except FileNotFoundError:
continue
else:
break
# No config file found
if config is None:
await self.log_util.log_error("No valid configuration file found.")
sys.exit(1)
await self.log_util.log_error("Failed to parse config files.")
sys.exit(1)
# Fetch events
keyboards = await self.input_util.get_keyboard_devices()

@ -0,0 +1,14 @@
SAMPLE JSON CONFIG
First XDG_CONFIG_HOME/swhkd/config.json is checked
and then ~/.config/swhkd/config.json
Delete the first 4 lines before using this file.
[
{
"combo": ["KEY_ENTER", "KEY_LEFTMETA"],
"action": "foot -e ranger"
},
{
"combo": ["KEY_ENTER", "KEY_LEFTCTRL"],
"action": "pcmanfm"
}
]

@ -8,19 +8,8 @@ class CONFIG_PARSER:
async def parse(self,config_file):
output=[]
with open(config_file, 'rt') as file:
text = file.read()
# Remove comments
# Remove \r if found for some reason
text = text.replace("\r", "")
text_lines = text.split("\n")
cleaned_text_lines = []
for line in text_lines:
if not line.startswith("//"):
cleaned_text_lines.append(line)
cleaned_text = "\n".join(cleaned_text_lines).strip()
# Parse the text without lines beginning with //
contents = json.loads(cleaned_text)["config"]
with open(config_file, 'r') as file:
contents = json.loads(file.read())
for arr in contents:
pair=[]
for key, value in arr.items():

Loading…
Cancel
Save