From 287216dac2371f8c91774f02e316ef96a66a6a8d Mon Sep 17 00:00:00 2001 From: Myryk Date: Mon, 10 Jun 2024 23:27:50 +0200 Subject: [PATCH 1/5] added option to change path to keybinds --- .../modules/.configuration/user_options.js | 3 +++ .config/ags/modules/cheatsheet/keybinds.js | 21 +++++++++++++------ .config/ags/scripts/hyprland/get_keybinds.py | 5 +++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.config/ags/modules/.configuration/user_options.js b/.config/ags/modules/.configuration/user_options.js index ab3d2a3e1..caad98284 100644 --- a/.config/ags/modules/.configuration/user_options.js +++ b/.config/ags/modules/.configuration/user_options.js @@ -56,6 +56,9 @@ let configOptions = { 'default': "auto", }, }, + 'configPaths': { + 'keybinds': "", + }, 'gaming': { 'crosshair': { 'size': 20, diff --git a/.config/ags/modules/cheatsheet/keybinds.js b/.config/ags/modules/cheatsheet/keybinds.js index 42618c19d..76b606253 100644 --- a/.config/ags/modules/cheatsheet/keybinds.js +++ b/.config/ags/modules/cheatsheet/keybinds.js @@ -5,13 +5,22 @@ import Widget from "resource:///com/github/Aylur/ags/widget.js"; import { IconTabContainer } from "../.commonwidgets/tabcontainer.js"; const { Box, Label, Scrollable } = Widget; -const HYPRLAND_KEYBIND_CONFIG_FILE = `${GLib.get_user_config_dir()}/hypr/hyprland/keybinds.conf`; +const HYPRLAND_KEYBIND_CONFIG_FILE = userOptions.configPaths.keybinds ? + userOptions.configPaths.keybinds : `${GLib.get_user_config_dir()}/hypr/hyprland/keybinds.conf`; const KEYBIND_SECTIONS_PER_PAGE = 3; -const keybindList = JSON.parse( - Utils.exec( - `${App.configDir}/scripts/hyprland/get_keybinds.py --path ${HYPRLAND_KEYBIND_CONFIG_FILE}`, - ), -); +const keybindListfunc = () => { + let data = Utils.exec(`${App.configDir}/scripts/hyprland/get_keybinds.py --path ${HYPRLAND_KEYBIND_CONFIG_FILE}`); + if (data == "\"error\"") { + Utils.timeout(2000, () => Utils.execAsync(['notify-send', + 'Update path to keybinds', + 'Keybinds hyprland config file not found. Check your user options.', + '-a', 'ags', + ]).catch(print)) + return { children: [] }; + } + return JSON.parse(data); +}; +const keybindList = keybindListfunc(); const keySubstitutions = { "Super": "󰖳", diff --git a/.config/ags/scripts/hyprland/get_keybinds.py b/.config/ags/scripts/hyprland/get_keybinds.py index 00bacdc21..eeb4b7ead 100755 --- a/.config/ags/scripts/hyprland/get_keybinds.py +++ b/.config/ags/scripts/hyprland/get_keybinds.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import argparse import re +import os from os.path import expandvars as os_expandvars from typing import Dict, List @@ -34,6 +35,8 @@ class Section(dict): def read_content(path: str) -> str: + if (not os.access(os_expandvars(path), os.R_OK)): + return ("error") with open(os_expandvars(path), "r") as file: return file.read() @@ -201,6 +204,8 @@ def get_binds_recursive(current_content, scope): def parse_keys(path: str) -> Dict[str, List[KeyBinding]]: global content_lines content_lines = read_content(path).splitlines() + if content_lines[0] == "error": + return "error" return get_binds_recursive(Section([], [], ""), 0) From 10a1eb5dd14c4933fb38cbd28820acd4cea7da3c Mon Sep 17 00:00:00 2001 From: Myryk Date: Mon, 10 Jun 2024 23:58:38 +0200 Subject: [PATCH 2/5] keybind path now works with ~ --- .config/ags/scripts/hyprland/get_keybinds.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/ags/scripts/hyprland/get_keybinds.py b/.config/ags/scripts/hyprland/get_keybinds.py index eeb4b7ead..bc1c7d1b9 100755 --- a/.config/ags/scripts/hyprland/get_keybinds.py +++ b/.config/ags/scripts/hyprland/get_keybinds.py @@ -35,9 +35,9 @@ class Section(dict): def read_content(path: str) -> str: - if (not os.access(os_expandvars(path), os.R_OK)): + if (not os.access(os.path.expanduser(os.path.expandvars(path)), os.R_OK)): return ("error") - with open(os_expandvars(path), "r") as file: + with open(os.path.expanduser(os.path.expandvars(path)), "r") as file: return file.read() From 800e434d5cd0104f9339add012996a0ea0fc2707 Mon Sep 17 00:00:00 2001 From: Myryk Date: Tue, 11 Jun 2024 00:02:32 +0200 Subject: [PATCH 3/5] added documentation --- .config/ags/modules/.configuration/user_options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/ags/modules/.configuration/user_options.js b/.config/ags/modules/.configuration/user_options.js index caad98284..17b2d502d 100644 --- a/.config/ags/modules/.configuration/user_options.js +++ b/.config/ags/modules/.configuration/user_options.js @@ -57,7 +57,7 @@ let configOptions = { }, }, 'configPaths': { - 'keybinds': "", + 'keybinds': "", //custom path to keybinds.conf for the cheatsheet }, 'gaming': { 'crosshair': { From 1c2ec63ae93275982e1e033cdf6adfabb995c67d Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Tue, 11 Jun 2024 19:30:17 +0700 Subject: [PATCH 4/5] cheatsheet: rename keybindListFunc -> getKeybindList --- .config/ags/modules/cheatsheet/keybinds.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/ags/modules/cheatsheet/keybinds.js b/.config/ags/modules/cheatsheet/keybinds.js index 76b606253..af3076fa3 100644 --- a/.config/ags/modules/cheatsheet/keybinds.js +++ b/.config/ags/modules/cheatsheet/keybinds.js @@ -8,7 +8,7 @@ const { Box, Label, Scrollable } = Widget; const HYPRLAND_KEYBIND_CONFIG_FILE = userOptions.configPaths.keybinds ? userOptions.configPaths.keybinds : `${GLib.get_user_config_dir()}/hypr/hyprland/keybinds.conf`; const KEYBIND_SECTIONS_PER_PAGE = 3; -const keybindListfunc = () => { +const getKeybindList = () => { let data = Utils.exec(`${App.configDir}/scripts/hyprland/get_keybinds.py --path ${HYPRLAND_KEYBIND_CONFIG_FILE}`); if (data == "\"error\"") { Utils.timeout(2000, () => Utils.execAsync(['notify-send', @@ -20,7 +20,7 @@ const keybindListfunc = () => { } return JSON.parse(data); }; -const keybindList = keybindListfunc(); +const keybindList = getKeybindList(); const keySubstitutions = { "Super": "󰖳", From 728e00c3824e72de85a8642f3cc959dfb3932224 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:43:24 +0700 Subject: [PATCH 5/5] change user option name for cheatsheet keybind path --- .config/ags/modules/.configuration/user_options.js | 6 ++++-- .config/ags/modules/cheatsheet/keybinds.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.config/ags/modules/.configuration/user_options.js b/.config/ags/modules/.configuration/user_options.js index 17b2d502d..418c352c4 100644 --- a/.config/ags/modules/.configuration/user_options.js +++ b/.config/ags/modules/.configuration/user_options.js @@ -56,8 +56,10 @@ let configOptions = { 'default': "auto", }, }, - 'configPaths': { - 'keybinds': "", //custom path to keybinds.conf for the cheatsheet + 'cheatsheet': { + 'keybinds': { + 'configPath': "" // Path to hyprland keybind config file. Leave empty for default (~/.config/hypr/hyprland/keybinds.conf) + } }, 'gaming': { 'crosshair': { diff --git a/.config/ags/modules/cheatsheet/keybinds.js b/.config/ags/modules/cheatsheet/keybinds.js index af3076fa3..838d95309 100644 --- a/.config/ags/modules/cheatsheet/keybinds.js +++ b/.config/ags/modules/cheatsheet/keybinds.js @@ -5,8 +5,8 @@ import Widget from "resource:///com/github/Aylur/ags/widget.js"; import { IconTabContainer } from "../.commonwidgets/tabcontainer.js"; const { Box, Label, Scrollable } = Widget; -const HYPRLAND_KEYBIND_CONFIG_FILE = userOptions.configPaths.keybinds ? - userOptions.configPaths.keybinds : `${GLib.get_user_config_dir()}/hypr/hyprland/keybinds.conf`; +const HYPRLAND_KEYBIND_CONFIG_FILE = userOptions.cheatsheet.keybinds.configPath ? + userOptions.cheatsheet.keybinds.configPath : `${GLib.get_user_config_dir()}/hypr/hyprland/keybinds.conf`; const KEYBIND_SECTIONS_PER_PAGE = 3; const getKeybindList = () => { let data = Utils.exec(`${App.configDir}/scripts/hyprland/get_keybinds.py --path ${HYPRLAND_KEYBIND_CONFIG_FILE}`);