mirror of
https://github.com/nix-community/plasma-manager.git
synced 2024-11-30 01:39:16 +03:00
Various bug fixes (#68)
* Minor refactoring * Add support for multiple bindings for one action * Fix encoding bug for escaping some unicode symbols
This commit is contained in:
parent
290cd65b65
commit
4e56cfeb95
@ -91,7 +91,7 @@ let
|
||||
# last_run and is located in $XDG_DATA_HOME/plasma-manager. When we
|
||||
# reset all the other config-files these startup-scripts should be
|
||||
# re-ran, so we delete these files to ensure they are.
|
||||
++ [ "for file in ${config.xdg.dataHome}/plasma-manager/last_run*; do ${removeFileIfExistsCmd "$file"}; done" ]));
|
||||
++ [ "for file in ${config.xdg.dataHome}/plasma-manager/last_run_*; do ${removeFileIfExistsCmd "$file"}; done" ]));
|
||||
in
|
||||
{
|
||||
options.programs.plasma = {
|
||||
@ -153,7 +153,7 @@ in
|
||||
(lib.mkRenamedOptionModule [ "programs" "plasma" "files" ] [ "programs" "plasma" "configFile" ])
|
||||
];
|
||||
|
||||
config = lib.mkIf (plasmaCfg.enable && (builtins.length (builtins.attrNames cfg) > 0)) {
|
||||
config = lib.mkIf plasmaCfg.enable {
|
||||
home.activation.configure-plasma = (lib.hm.dag.entryAfter [ "writeBoundary" ]
|
||||
''
|
||||
$DRY_RUN_CMD ${if plasmaCfg.overrideConfig then (createResetScript plasmaCfg) else ""}
|
||||
|
@ -33,17 +33,21 @@ let
|
||||
|
||||
# Gets a list with long names and turns it into short names
|
||||
getShortNames = wantedButtons:
|
||||
lists.forEach (
|
||||
lists.flatten (
|
||||
lists.forEach wantedButtons (currentButton:
|
||||
lists.remove null (
|
||||
lists.imap0 ( index: value:
|
||||
if value == currentButton then "${toString index}" else null
|
||||
) validTitlebarButtons.longNames
|
||||
lists.forEach
|
||||
(
|
||||
lists.flatten (
|
||||
lists.forEach wantedButtons (currentButton:
|
||||
lists.remove null (
|
||||
lists.imap0
|
||||
(index: value:
|
||||
if value == currentButton then "${toString index}" else null
|
||||
)
|
||||
validTitlebarButtons.longNames
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
) getShortNameFromIndex;
|
||||
getShortNameFromIndex;
|
||||
|
||||
# Gets the index and returns the short name in that position
|
||||
getShortNameFromIndex = position: builtins.elemAt validTitlebarButtons.shortNames (strings.toInt position);
|
||||
@ -68,7 +72,7 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (cfg.enable) {
|
||||
config = mkIf cfg.enable {
|
||||
# Titlebar buttons
|
||||
programs.plasma.configFile."kwinrc"."org\\.kde\\.kdecoration2" = mkMerge [
|
||||
(
|
||||
@ -83,4 +87,4 @@ in
|
||||
)
|
||||
];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,15 @@ let
|
||||
# Keys are expected to be a list:
|
||||
keys =
|
||||
if builtins.isList skey
|
||||
then (if builtins.length skey == 0 then [ "none" ] else skey)
|
||||
then
|
||||
(if ((builtins.length skey) == 0) then [ "none" ] else skey)
|
||||
else [ skey ];
|
||||
|
||||
# Don't allow un-escaped commas:
|
||||
escape = lib.escape [ "," ];
|
||||
in
|
||||
lib.concatStringsSep "," [
|
||||
(lib.concatStringsSep "\t" (map escape keys))
|
||||
(if ((builtins.length keys) == 1) then (escape (builtins.head keys)) else "\t" + (lib.concatStringsSep "\t" (map escape keys)))
|
||||
"" # List of default keys, not needed.
|
||||
"" # Display string, not needed.
|
||||
];
|
||||
@ -42,7 +43,7 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
config = lib.mkIf (cfg.enable && builtins.attrNames cfg.shortcuts != 0) {
|
||||
config = lib.mkIf cfg.enable {
|
||||
programs.plasma.configFile."kglobalshortcutsrc" =
|
||||
shortcutsToSettings cfg.shortcuts;
|
||||
};
|
||||
|
@ -69,7 +69,7 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf (cfg.enable) {
|
||||
config = lib.mkIf cfg.enable {
|
||||
programs.plasma.shortcuts."org.kde.spectacle.desktop" = lib.mkMerge [
|
||||
(
|
||||
lib.mkIf (cfg.spectacle.shortcuts.captureActiveWindow != null) {
|
||||
|
@ -85,7 +85,7 @@ in
|
||||
}
|
||||
];
|
||||
|
||||
xdg.configFile."autostart/plasma-manager-apply-themes.desktop".text = ''
|
||||
xdg.configFile."autostart/plasma-manager-autostart.desktop".text = ''
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Plasma Manager theme application
|
||||
|
@ -16,7 +16,7 @@ class KConfParser:
|
||||
"""Read the config from the path specified on instantiation. If the
|
||||
path doesn't exist, do nothing"""
|
||||
try:
|
||||
with open(self.filepath, "r") as f:
|
||||
with open(self.filepath, "r", encoding="utf-8") as f:
|
||||
current_group = 0
|
||||
for l in f:
|
||||
# Checks if the current line indicates a group.
|
||||
@ -39,9 +39,15 @@ class KConfParser:
|
||||
|
||||
# Escapes symbols like \t, \n and so on if escape_value is True. This
|
||||
# should be true when reading from the nix json, but not when reading
|
||||
# from file (as reading from file already is escaped).
|
||||
# from file (as reading from a file that is already escaped).
|
||||
if escape_value:
|
||||
value = value.encode("unicode_escape").decode()
|
||||
to_escape = ["\t", "\n"]
|
||||
# value = value.encode("unicode_escape").decode()
|
||||
for escape_char in to_escape:
|
||||
value = value.replace(
|
||||
escape_char, escape_char.encode("unicode_escape").decode()
|
||||
)
|
||||
|
||||
self.data[group][key] = value
|
||||
|
||||
def remove_value(self, group, key):
|
||||
@ -61,7 +67,7 @@ class KConfParser:
|
||||
if not os.path.exists(dir):
|
||||
os.makedirs(dir)
|
||||
|
||||
with open(self.filepath, "w") as f:
|
||||
with open(self.filepath, "w", encoding="utf-8") as f:
|
||||
# We skip a newline before the first category
|
||||
skip_newline = True
|
||||
|
||||
@ -83,7 +89,7 @@ class KConfParser:
|
||||
f.write(f"{self.key_value_to_line(key, value)}\n")
|
||||
|
||||
@staticmethod
|
||||
def get_key_value(line: str) -> tuple[str, str]:
|
||||
def get_key_value(line: str) -> tuple[str, str | None]:
|
||||
line_splitted = line.split("=", 1)
|
||||
key = line_splitted[0].strip()
|
||||
value = line_splitted[1].strip() if len(line_splitted) > 1 else None
|
||||
|
Loading…
Reference in New Issue
Block a user