hyprconf2lua 1.5.0__tar.gz → 1.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {hyprconf2lua-1.5.0/src/hyprconf2lua.egg-info → hyprconf2lua-1.7.0}/PKG-INFO +1 -1
  2. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/pyproject.toml +1 -1
  3. hyprconf2lua-1.7.0/src/hyprconf2lua/__init__.py +1 -0
  4. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/ast.py +1 -0
  5. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/codegen.py +186 -72
  6. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/lexer.py +5 -0
  7. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/mappings.py +2 -0
  8. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/parser.py +49 -19
  9. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0/src/hyprconf2lua.egg-info}/PKG-INFO +1 -1
  10. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/tests/test_converter.py +191 -0
  11. hyprconf2lua-1.5.0/src/hyprconf2lua/__init__.py +0 -1
  12. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/LICENSE +0 -0
  13. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/README.md +0 -0
  14. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/setup.cfg +0 -0
  15. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/__main__.py +0 -0
  16. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/cli.py +0 -0
  17. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/converter.py +0 -0
  18. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/SOURCES.txt +0 -0
  19. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/dependency_links.txt +0 -0
  20. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/entry_points.txt +0 -0
  21. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/requires.txt +0 -0
  22. {hyprconf2lua-1.5.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyprconf2lua
3
- Version: 1.5.0
3
+ Version: 1.7.0
4
4
  Summary: Convert Hyprland hyprlang .conf files to Lua .lua config format (v0.55+)
5
5
  Author: hyprconf2lua contributors
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hyprconf2lua"
7
- version = "1.5.0"
7
+ version = "1.7.0"
8
8
  description = "Convert Hyprland hyprlang .conf files to Lua .lua config format (v0.55+)"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -0,0 +1 @@
1
+ __version__ = "1.7.0"
@@ -79,6 +79,7 @@ class AnimationDirective:
79
79
  speed: str
80
80
  curve: str
81
81
  line: int
82
+ enabled: str = "1"
82
83
 
83
84
 
84
85
  @dataclass
@@ -16,6 +16,8 @@ KNOWN_SECTIONS = {
16
16
  "autostart", "window", "monitor", "workspace", "layer",
17
17
  }
18
18
 
19
+ MULTI_VALUE_EFFECT_KEYS = {"move", "size", "opacity", "alpha"}
20
+
19
21
 
20
22
  class Codegen:
21
23
  def __init__(self):
@@ -129,6 +131,16 @@ class Codegen:
129
131
  return "local_var_" + var_name
130
132
  return re.sub(r'\$(\w+)', _repl, val)
131
133
 
134
+ def resolve_val_exec(self, val: str) -> str:
135
+ def _repl(m: re.Match) -> str:
136
+ var_name = m.group(1)
137
+ if var_name in self.variables:
138
+ return self.variables[var_name]
139
+ if var_name in os.environ:
140
+ return f'os.getenv("{var_name}")'
141
+ return m.group(0)
142
+ return re.sub(r'\$(\w+)', _repl, val)
143
+
132
144
  def _build_concat_expr(self, val: str) -> str:
133
145
  parts = re.split(r'(os\.getenv\([^)]+\))', val)
134
146
  expr_parts = []
@@ -209,7 +221,7 @@ class Codegen:
209
221
  break
210
222
 
211
223
  def _exec_lua_expr(self, cmd: str) -> str:
212
- resolved = self.resolve_val_with_env(cmd)
224
+ resolved = self.resolve_val_exec(cmd)
213
225
  if resolved.startswith("$") and resolved[1:] in self.variables:
214
226
  return resolved[1:]
215
227
  if "os.getenv(" in resolved:
@@ -267,7 +279,23 @@ class Codegen:
267
279
  return f"{{ colors = {{ {', '.join(colors)} }}, angle = {angle} }}"
268
280
 
269
281
  def _emit_directive(self, key: str, values: List[str]):
282
+ if not values or all(not v.strip() for v in values):
283
+ return
270
284
  key = self._normalize_key(key)
285
+ if len(values) > 1 and key == "enabled":
286
+ values = values[:1]
287
+ if ":" in key:
288
+ parts = [self._normalize_key(p) for p in key.split(":")]
289
+ inner = f"{parts[-1]} = {{ {', '.join(self.to_lua_val(v) for v in values)} }}"
290
+ if len(values) == 1 and self._is_gradient(values[0]):
291
+ inner = f"{parts[-1]} = {self._format_gradient(values[0])}"
292
+ elif len(values) == 1:
293
+ inner = f"{parts[-1]} = {self.to_lua_val(values[0])}"
294
+ for p in reversed(parts[:-1]):
295
+ inner = f"{p} = {{ {inner} }}"
296
+ self.translated_count += 1
297
+ self.emit(f"{inner},")
298
+ return
271
299
  if len(values) == 1 and self._is_gradient(values[0]):
272
300
  self.translated_count += 1
273
301
  self.emit(f"{key} = {self._format_gradient(values[0])},")
@@ -299,6 +327,8 @@ class Codegen:
299
327
  if not directives:
300
328
  return
301
329
 
330
+ deferred: List[BlockStmt] = []
331
+
302
332
  self.emit(f"hl.config({{")
303
333
  self.indent()
304
334
  self.emit(f"{section_name} = {{")
@@ -320,20 +350,27 @@ class Codegen:
320
350
  self.passthrough_count += 1
321
351
  self.emit(f"-- Nested subsection {sd.name}:")
322
352
  for ssd in sd.body:
323
- if isinstance(ssd, Directive):
353
+ if isinstance(ssd, Directive) and ssd.value and ssd.value[0].strip():
324
354
  k = self._normalize_key(ssd.key)
325
355
  vv = self.to_lua_val(ssd.value[0]) if ssd.value else "true"
326
356
  self.emit(f"{k} = {vv},")
357
+ elif isinstance(sd, (AnimationDirective, BezierDirective, GestureDirective)):
358
+ deferred.append(sd)
327
359
  self.dedent()
328
360
  self.emit("},")
329
361
  elif isinstance(d, Directive):
330
362
  self._emit_directive(d.key, d.value)
363
+ elif isinstance(d, (AnimationDirective, BezierDirective, GestureDirective)):
364
+ deferred.append(d)
331
365
 
332
366
  self.dedent()
333
367
  self.emit("},")
334
368
  self.dedent()
335
369
  self.emit("})")
336
370
 
371
+ for node in deferred:
372
+ self.visit(node)
373
+
337
374
  def flush_subsection(self, name: str, directives: List[Directive]):
338
375
  if not directives:
339
376
  return
@@ -341,6 +378,8 @@ class Codegen:
341
378
  self.indent()
342
379
  for d in directives:
343
380
  key = self._normalize_key(d.key)
381
+ if not d.value or not d.value[0].strip():
382
+ continue
344
383
  if len(d.value) == 1:
345
384
  val = self.to_lua_val(d.value[0])
346
385
  self.emit(f"{key} = {val},")
@@ -394,6 +433,7 @@ class Codegen:
394
433
  self.emit_section_config(stmt.name, stmt.body)
395
434
  else:
396
435
  self.translated_count += 1
436
+ deferred: List[BlockStmt] = []
397
437
  self.emit(f"hl.config({{")
398
438
  self.indent()
399
439
  self.emit(f"{stmt.name} = {{")
@@ -403,10 +443,14 @@ class Codegen:
403
443
  self.emit(f"--{child.text[1:]}")
404
444
  elif isinstance(child, Directive):
405
445
  self._emit_directive(child.key, child.value)
446
+ elif isinstance(child, (AnimationDirective, BezierDirective, GestureDirective)):
447
+ deferred.append(child)
406
448
  self.dedent()
407
449
  self.emit("},")
408
450
  self.dedent()
409
451
  self.emit("})")
452
+ for node in deferred:
453
+ self.visit(node)
410
454
  self.emit(f"-- NOTE: Section '{stmt.name}' may be a plugin or custom section; verify the output")
411
455
 
412
456
  def visit_directive(self, stmt: Directive):
@@ -551,12 +595,22 @@ class Codegen:
551
595
  return f'{func}({{ next = false }})'
552
596
  return f'{func}()'
553
597
 
598
+ if dispatcher == "resizeactive":
599
+ nums = params[0].split() if params else []
600
+ x = nums[0] if len(nums) > 0 else "0"
601
+ y = nums[1] if len(nums) > 1 else "0"
602
+ return f'{func}({{ x = {x}, y = {y}, relative = true }})'
603
+
604
+ if dispatcher == "movecurrentworkspacetomonitor":
605
+ mon = self.quote(params[0]) if params else '"l"'
606
+ return f'{func}({{ monitor = {mon} }})'
607
+
554
608
  if dispatcher == "movewindow":
555
609
  if params and params[0].startswith("into_group:"):
556
610
  return f'{func}({{ into_group = {self.quote(params[0][len("into_group:"):])} }})'
557
611
  if params and params[0] == "out_of_group":
558
612
  return f'{func}({{ out_of_group = true }})'
559
- return self.build_dispatcher_args(params, needs_args, func)
613
+ return f'{func}({self.build_dispatcher_args(params, needs_args, func)})'
560
614
 
561
615
  if dispatcher == "swapwindow":
562
616
  if params and params[0] in ("l", "r", "u", "d"):
@@ -603,11 +657,14 @@ class Codegen:
603
657
 
604
658
  if dispatcher in ("exec", "execr"):
605
659
  raw = params[0] if params else ""
606
- resolved = self.resolve_val_with_env(raw)
660
+ resolved = self.resolve_val_exec(raw)
607
661
  if "os.getenv(" in resolved:
608
662
  return f'{func}({self._build_concat_expr(resolved)})'
609
663
  return f'{func}({self.quote(resolved)})'
610
664
 
665
+ if needs_args and not params:
666
+ return None
667
+
611
668
  args = self.build_dispatcher_args(params, needs_args, func)
612
669
  return f'{func}({args})' if needs_args else f'{func}()'
613
670
 
@@ -656,10 +713,15 @@ class Codegen:
656
713
  if len(params) == 1:
657
714
  p = params[0]
658
715
  if func and func == "hl.dsp.window.move":
716
+ dir_map = {"l": "left", "r": "right", "u": "up", "d": "down"}
659
717
  if p.startswith("special"):
660
718
  return f'{{ workspace = {self.quote(p)} }}'
661
719
  if p.isdigit():
662
720
  return f'{{ workspace = {p} }}'
721
+ if re.match(r'^[+-]\d+$', p):
722
+ return f'{{ workspace = "{p}" }}'
723
+ if p in dir_map:
724
+ return f'{{ direction = "{dir_map[p]}" }}'
663
725
  return f'{{ direction = {self.quote(p)} }}'
664
726
  return self.quote(self.resolve_val(p))
665
727
 
@@ -682,36 +744,79 @@ class Codegen:
682
744
  self.dedent()
683
745
  self.emit("})")
684
746
 
747
+ def _emit_rule_effect(self, prop: str) -> bool:
748
+ words = prop.strip().replace("=", " ").split()
749
+ if not words:
750
+ return False
751
+ key = words[0].lower()
752
+ rest_words = words[1:]
753
+ if key in WINDOW_RULE_MAP:
754
+ k, v = WINDOW_RULE_MAP[key]
755
+ self.emit(f"{k} = {v},")
756
+ return True
757
+ if key in WINDOW_RULE_PARAM_MAP:
758
+ k, needs_val = WINDOW_RULE_PARAM_MAP[key]
759
+ if needs_val and rest_words:
760
+ if key in MULTI_VALUE_EFFECT_KEYS:
761
+ lua_parts = ", ".join(self.to_lua_val(w) for w in rest_words)
762
+ self.emit(f"{k} = {{ {lua_parts} }},")
763
+ elif len(rest_words) == 1:
764
+ self.emit(f"{k} = {self.to_lua_val(rest_words[0])},")
765
+ else:
766
+ self.emit(f"{k} = {self.quote(' '.join(rest_words))},")
767
+ else:
768
+ self.emit(f"{k} = true,")
769
+ return True
770
+ return False
771
+
685
772
  def visit_windowrule(self, stmt: WindowRule):
686
773
  self.translated_count += 1
687
774
  rule = stmt.rule
688
775
  match_params = stmt.match_params
689
776
 
690
- match = {}
691
- effects = {}
777
+ all_params = [rule.strip()] + [mp.strip() for mp in match_params]
778
+ explicit = [p for p in all_params if p.lower().startswith("match:")]
779
+ others = [p for p in all_params if p and p not in explicit]
692
780
 
693
- for mp in match_params:
694
- colon_idx = mp.find(":")
695
- if colon_idx > 0:
696
- prefix = mp[:colon_idx].strip()
697
- value = mp[colon_idx + 1:].strip()
698
- match_key = prefix
781
+ match = {}
782
+ if explicit:
783
+ props = others
784
+ for mp in explicit:
785
+ rest = mp[len("match:"):].strip()
786
+ m = re.match(r'^([a-zA-Z0-9_-]+)(?:\s*=\s*|\s*:\s*|\s+)(.*)$', rest)
787
+ if m:
788
+ match_key, value = m.group(1), m.group(2).strip()
789
+ else:
790
+ match_key, value = rest, "true"
699
791
  if value.lower() == "true":
700
792
  match[match_key] = "true"
701
793
  elif value.lower() == "false":
702
794
  match[match_key] = "false"
703
795
  else:
704
796
  match[match_key] = self.quote(value)
705
-
706
- if not match and not stmt.is_v2:
707
- if match_params:
708
- class_val = match_params[0]
709
- match["class"] = self.quote(class_val)
710
-
797
+ else:
798
+ props = [rule]
799
+ for mp in match_params:
800
+ colon_idx = mp.find(":")
801
+ if colon_idx > 0:
802
+ prefix = mp[:colon_idx].strip()
803
+ value = mp[colon_idx + 1:].strip()
804
+ if value.lower() == "true":
805
+ match[prefix] = "true"
806
+ elif value.lower() == "false":
807
+ match[prefix] = "false"
808
+ else:
809
+ match[prefix] = self.quote(value)
810
+
811
+ if not match and not stmt.is_v2:
812
+ if match_params:
813
+ match["class"] = self.quote(match_params[0])
814
+
815
+ name_source = props[0] if props else rule
711
816
  self.emit("hl.window_rule({")
712
817
  self.indent()
713
818
 
714
- name_str = re.sub(r'[^a-zA-Z0-9_-]', '_', rule[:20].lower())
819
+ name_str = re.sub(r'[^a-zA-Z0-9_-]', '_', name_source[:20].lower())
715
820
  self.emit(f'name = "{name_str}",')
716
821
 
717
822
  self.emit("match = {")
@@ -721,29 +826,10 @@ class Codegen:
721
826
  self.dedent()
722
827
  self.emit("},")
723
828
 
724
- rule_lower = rule.lower().strip()
725
- applied = False
726
-
727
- if rule_lower in WINDOW_RULE_MAP:
728
- k, v = WINDOW_RULE_MAP[rule_lower]
729
- self.emit(f"{k} = {v},")
730
- applied = True
731
- else:
732
- parts = rule.split(None, 1)
733
- if parts and parts[0] in WINDOW_RULE_PARAM_MAP:
734
- k, needs_val = WINDOW_RULE_PARAM_MAP[parts[0]]
735
- if needs_val and len(parts) > 1:
736
- val = self.to_lua_val(parts[1])
737
- self.emit(f"{k} = {val},")
738
- elif needs_val:
739
- self.emit(f"{k} = true,")
740
- else:
741
- self.emit(f"{k} = true,")
742
- applied = True
743
-
744
- if not applied:
745
- self.flag_count += 1
746
- self.emit(f'-- TODO: review rule: {self.quote(rule)}')
829
+ for prop in props:
830
+ if not self._emit_rule_effect(prop):
831
+ self.flag_count += 1
832
+ self.emit(f'-- TODO: review rule: {self.quote(prop)}')
747
833
 
748
834
  self.dedent()
749
835
  self.emit("})")
@@ -766,7 +852,11 @@ class Codegen:
766
852
 
767
853
  for key, vals in stmt.effects.items():
768
854
  key = self._normalize_key(key)
769
- if len(vals) == 1:
855
+ if not vals or not vals[0].strip():
856
+ continue
857
+ if len(vals) == 1 and key not in MULTI_VALUE_EFFECT_KEYS:
858
+ self.emit(f"{key} = {self.to_lua_val(vals[0].strip())},")
859
+ elif len(vals) == 1:
770
860
  parts = vals[0].split()
771
861
  if len(parts) == 1:
772
862
  self.emit(f"{key} = {self.to_lua_val(parts[0])},")
@@ -796,6 +886,7 @@ class Codegen:
796
886
  style = stmt.style
797
887
  speed = stmt.speed
798
888
  curve = stmt.curve
889
+ enabled = "true" if stmt.enabled.strip().lower() in ("1", "yes", "on", "true") else "false"
799
890
 
800
891
  try:
801
892
  float(speed)
@@ -805,11 +896,7 @@ class Codegen:
805
896
 
806
897
  style_extra = ""
807
898
  if style and style != "default":
808
- if " " in style:
809
- style_name, *style_args = style.split()
810
- style_extra = f', style = {self.quote(style)}'
811
- else:
812
- style_extra = f', style = {self.quote(style)}'
899
+ style_extra = f', style = {self.quote(style)}'
813
900
 
814
901
  if curve and curve != "default":
815
902
  if re.match(r'^\d+(\.\d+)?$', curve):
@@ -819,13 +906,13 @@ class Codegen:
819
906
  spring_parts = curve.split()
820
907
  if len(spring_parts) >= 4:
821
908
  self.passthrough_count += 1
822
- self.emit(f'hl.animation({{ leaf = "{name}", enabled = true, speed = {speed_lit}, spring = {self.quote(curve)}{style_extra} }})')
909
+ self.emit(f'hl.animation({{ leaf = "{name}", enabled = {enabled}, speed = {speed_lit}, spring = {self.quote(curve)}{style_extra} }})')
823
910
  else:
824
- self.emit(f'hl.animation({{ leaf = "{name}", enabled = true, speed = {speed_lit}, spring = {self.quote(curve)}{style_extra} }})')
911
+ self.emit(f'hl.animation({{ leaf = "{name}", enabled = {enabled}, speed = {speed_lit}, spring = {self.quote(curve)}{style_extra} }})')
825
912
  else:
826
- self.emit(f'hl.animation({{ leaf = "{name}", enabled = true, speed = {speed_lit}, bezier = {self.quote(curve)}{style_extra} }})')
913
+ self.emit(f'hl.animation({{ leaf = "{name}", enabled = {enabled}, speed = {speed_lit}, bezier = {self.quote(curve)}{style_extra} }})')
827
914
  else:
828
- self.emit(f'hl.animation({{ leaf = "{name}", enabled = true, speed = {speed_lit}{style_extra} }})')
915
+ self.emit(f'hl.animation({{ leaf = "{name}", enabled = {enabled}, speed = {speed_lit}{style_extra} }})')
829
916
 
830
917
  def visit_bezier(self, stmt: BezierDirective):
831
918
  self.translated_count += 1
@@ -843,25 +930,35 @@ class Codegen:
843
930
  val_expr = self.to_lua_val(stmt.value)
844
931
  self.emit(f"hl.env({name_q}, {val_expr})")
845
932
 
933
+ @staticmethod
934
+ def _sanitize_ident(s: str) -> str:
935
+ return re.sub(r"[^a-zA-Z0-9_]", "_", s)
936
+
937
+ def _source_module_path(self, path: str) -> str:
938
+ p = path.strip()
939
+ for marker in ("/.config/hypr/", "/.config/", "$XDG_CONFIG_HOME/", "$HOME/", "~/"):
940
+ if marker in p:
941
+ p = p.split(marker, 1)[1]
942
+ break
943
+ else:
944
+ p = p.lstrip("/")
945
+ p = p.replace(".conf", "")
946
+ return ".".join(self._sanitize_ident(part) for part in p.split("/") if part)
947
+
846
948
  def visit_source(self, stmt: SourceDirective):
847
949
  self.passthrough_count += 1
848
950
  path = stmt.path
849
951
 
850
- lua_path = path.replace(".conf", "")
851
- lua_path = lua_path.replace("~", "os.getenv(\"HOME\")")
852
- lua_path = lua_path.replace("/", ".")
853
-
854
952
  if path.endswith("/*.conf"):
855
953
  self.emit(f'-- source = {path}')
856
954
  self.emit(f"-- NOTE: glob sources need manual handling")
857
955
  self.emit(f"-- Directory contents must be required individually")
858
956
  return
859
957
 
958
+ module = self._source_module_path(path)
959
+ local_name = module.split(".")[-1]
860
960
  self.emit(f'-- source = {path} -> requires manual conversion')
861
-
862
- import os as _os
863
- just_name = _os.path.splitext(_os.path.basename(path))[0]
864
- self.emit(f'-- local {just_name} = require("{just_name}")')
961
+ self.emit(f'-- local {local_name} = require("{module}")')
865
962
  self.emit(f'-- TODO: convert {path} to .lua and use require()')
866
963
 
867
964
  def visit_device(self, stmt: DeviceSection):
@@ -870,7 +967,7 @@ class Codegen:
870
967
  self.indent()
871
968
  self.emit(f'name = {self.quote(stmt.name)},')
872
969
  for d in stmt.body:
873
- if isinstance(d, Directive):
970
+ if isinstance(d, Directive) and d.value and d.value[0].strip():
874
971
  key = self._normalize_key(d.key)
875
972
  val = self.to_lua_val(d.value[0]) if d.value else "true"
876
973
  self.emit(f"{key} = {val},")
@@ -930,8 +1027,18 @@ class Codegen:
930
1027
 
931
1028
  def visit_layerrule(self, stmt: LayerRuleDirective):
932
1029
  self.translated_count += 1
933
- rule_lower = stmt.rule.lower()
934
- ns = stmt.namespace
1030
+ rule_raw = stmt.rule.strip()
1031
+ ns = stmt.namespace.strip()
1032
+
1033
+ if ns.lower().startswith("match:"):
1034
+ ns = ns[len("match:"):].strip()
1035
+ m = re.match(r'^namespace\s*(?:=|:)?\s*(.+)$', ns, re.IGNORECASE)
1036
+ if m:
1037
+ ns = m.group(1).strip()
1038
+
1039
+ norm_words = rule_raw.replace("=", " ").split()
1040
+ key = norm_words[0].lower() if norm_words else ""
1041
+ value = " ".join(norm_words[1:]) if len(norm_words) > 1 else None
935
1042
 
936
1043
  self.emit("hl.layer_rule({")
937
1044
  self.indent()
@@ -941,16 +1048,19 @@ class Codegen:
941
1048
  self.dedent()
942
1049
  self.emit("},")
943
1050
 
944
- if rule_lower in LAYER_RULE_MAP:
945
- k, v = LAYER_RULE_MAP[rule_lower]
946
- if v == "true":
1051
+ applied = False
1052
+ if key in LAYER_RULE_MAP:
1053
+ k, v = LAYER_RULE_MAP[key]
1054
+ if isinstance(v, str) and v in ("true", "false"):
947
1055
  self.emit(f"{k} = {v},")
1056
+ elif value:
1057
+ self.emit(f"{k} = {self.to_lua_val(value)},")
948
1058
  else:
949
- self.emit(f"{k} = {self.to_lua_val(v)},")
950
- else:
951
- parts = rule_lower.split(None, 1)
952
- if parts:
953
- self.emit(f"{parts[0]} = {self.quote(parts[1]) if len(parts) > 1 else 'true'},")
1059
+ self.emit(f"{k} = true,")
1060
+ applied = True
1061
+
1062
+ if not applied and key:
1063
+ self.emit(f"{norm_words[0]} = {self.quote(' '.join(norm_words[1:])) if len(norm_words) > 1 else 'true'},")
954
1064
 
955
1065
  self.dedent()
956
1066
  self.emit("})")
@@ -972,7 +1082,11 @@ class Codegen:
972
1082
 
973
1083
  for key, vals in stmt.effects.items():
974
1084
  key = self._normalize_key(key)
975
- if len(vals) == 1:
1085
+ if not vals or not vals[0].strip():
1086
+ continue
1087
+ if len(vals) == 1 and key not in MULTI_VALUE_EFFECT_KEYS:
1088
+ self.emit(f"{key} = {self.to_lua_val(vals[0].strip())},")
1089
+ elif len(vals) == 1:
976
1090
  parts = vals[0].split()
977
1091
  if len(parts) == 1:
978
1092
  self.emit(f"{key} = {self.to_lua_val(parts[0])},")
@@ -12,8 +12,10 @@ TOKEN_SPECS = [
12
12
  ("COMMA", r","),
13
13
  ("DOT", r"\."),
14
14
  ("COLON", r":"),
15
+ ("SHELL_EXP", r"\$\{[^}\n]*\}"),
15
16
  ("DOLLAR", r"\$"),
16
17
  ("STRING", r'"([^"\\]|\\.)*"'),
18
+ ("CONT", r"\\[ \t]*\n"),
17
19
  ("IDENT", r'[^\s#"={},:!]+'),
18
20
  ("NEWLINE", r"\n"),
19
21
  ("SKIP", r"[ \t]+"),
@@ -59,6 +61,9 @@ def tokenize(source: str) -> List[Token]:
59
61
  line += 1
60
62
  last_line_start = pos + 1
61
63
  tokens.append(Token("NEWLINE", value, line - 1, _col(pos)))
64
+ elif kind == "CONT":
65
+ line += 1
66
+ last_line_start = m.end()
62
67
  elif kind == "SKIP":
63
68
  pass
64
69
  elif kind == "COMMENT":
@@ -52,6 +52,8 @@ DISPATCHER_MAP = {
52
52
  "focusurgentorlast": ("hl.dsp.focus", True),
53
53
  "focusonemonitor": ("hl.dsp.focus", True),
54
54
  "forcekillactive": ("hl.dsp.window.kill", False),
55
+ "resizeactive": ("hl.dsp.window.resize", True),
56
+ "movecurrentworkspacetomonitor": ("hl.dsp.workspace.move", True),
55
57
  }
56
58
 
57
59
  BIND_FLAGS_TO_OPTIONS = {
@@ -136,22 +136,34 @@ class Parser:
136
136
  return VariableDef(name_t.value, val, name_t.line)
137
137
 
138
138
  def parse_value_rest(self) -> str:
139
- parts = []
140
- while self.peek().type in ("IDENT", "STRING", "DOLLAR", "DOT", "COLON") or \
139
+ parts: List[tuple] = []
140
+ prev_end: Optional[int] = None
141
+ while self.peek().type in ("IDENT", "STRING", "SHELL_EXP", "DOLLAR", "DOT", "COLON", "COMMA") or \
141
142
  (self.peek().type == "EQUALS" and parts):
142
143
  if self.peek().type == "COMMENT":
143
144
  break
145
+ gap = prev_end is not None and self.peek().col > prev_end
144
146
  t = self.advance()
145
147
  if t.type == "DOLLAR":
146
148
  var_t = self.expect("IDENT")
147
- parts.append("$" + var_t.value)
149
+ parts.append(("$" + var_t.value, gap))
150
+ prev_end = var_t.col + len(var_t.value)
148
151
  else:
149
- parts.append(t.value)
152
+ parts.append((t.value, gap))
153
+ prev_end = t.col + len(t.value)
150
154
  if self.peek().type == "DOT":
155
+ dt = self.peek()
156
+ dgap = dt.col > prev_end
151
157
  self.advance()
152
- parts.append(".")
158
+ parts.append((".", dgap))
159
+ prev_end = dt.col + 1
153
160
 
154
- return self._join_tokens(parts)
161
+ if not parts:
162
+ return ""
163
+ result = parts[0][0]
164
+ for text, had_gap in parts[1:]:
165
+ result += (" " + text) if had_gap else text
166
+ return result.strip()
155
167
 
156
168
  @staticmethod
157
169
  def _join_tokens(tokens: List[str]) -> str:
@@ -159,15 +171,15 @@ class Parser:
159
171
  return ""
160
172
  result = tokens[0]
161
173
  for t in tokens[1:]:
162
- no_space_before = {":", ",", "=", "+", "-", "%", "@", "^", "*", "|", "~"}
163
- no_space_after = {":", ",", "="}
164
- if t in no_space_before or result[-1:] in no_space_after:
174
+ no_space_before = {":", ",", "=", "+", "%", "@", "^", "*", "~"}
175
+ no_space_after = {":", ",", "=", "."}
176
+ if t in no_space_before or result[-1:] in no_space_after or t.startswith(("/", ".")):
165
177
  result += t
166
178
  else:
167
179
  result += " " + t
168
180
  return result.strip()
169
181
 
170
- def parse_comma_values(self) -> List[str]:
182
+ def parse_comma_values(self, keep_string_quotes: bool = False) -> List[str]:
171
183
  values = []
172
184
  current = []
173
185
  while self.peek().type not in ("NEWLINE", "EOF") and \
@@ -200,7 +212,10 @@ class Parser:
200
212
  current.append("$" + var_t.value)
201
213
  else:
202
214
  t = self.advance()
203
- current.append(t.value)
215
+ if keep_string_quotes and t.type == "STRING":
216
+ current.append('"' + t.value + '"')
217
+ else:
218
+ current.append(t.value)
204
219
  remaining = self._join_tokens(current)
205
220
  if remaining:
206
221
  values.append(remaining)
@@ -257,7 +272,7 @@ class Parser:
257
272
  if directive == "gesture":
258
273
  if self.peek().type == "BLOCK_OPEN":
259
274
  return self.parse_gesture(t.line)
260
- return self.parse_general_directive(directive, t.line)
275
+ return self.parse_gesture_inline(t.line)
261
276
  if directive == "workspace":
262
277
  return self.parse_workspace(t.line)
263
278
  if directive == "layerrule":
@@ -296,6 +311,8 @@ class Parser:
296
311
  if t.type == "EQUALS":
297
312
  self.advance()
298
313
  values = self.parse_comma_values()
314
+ if not values or all(not v.strip() for v in values):
315
+ return None
299
316
  return Directive(directive, values, line, 0)
300
317
  if t.type == "BLOCK_OPEN":
301
318
  self.advance()
@@ -308,7 +325,7 @@ class Parser:
308
325
  flags = _parse_combined_bind(directive)
309
326
  self.expect("EQUALS")
310
327
  self.skip_newlines()
311
- values = self.parse_comma_values()
328
+ values = self.parse_comma_values(keep_string_quotes=True)
312
329
  if len(values) < 3:
313
330
  raise ParserError(f"bind needs at least 3 arguments (mods, key, dispatcher), got {len(values)}", Token("IDENT", directive, line, 0))
314
331
  mods_str = values[0].strip()
@@ -416,10 +433,10 @@ class Parser:
416
433
 
417
434
  def parse_exec(self, directive: str, line: int) -> ExecDirective:
418
435
  self.expect("EQUALS")
419
- command = self.parse_line_rest()
436
+ command = self.parse_line_rest(keep_string_quotes=True)
420
437
  return ExecDirective(directive, command, line)
421
438
 
422
- def parse_line_rest(self) -> str:
439
+ def parse_line_rest(self, keep_string_quotes: bool = False) -> str:
423
440
  parts = []
424
441
  while self.peek().type not in ("NEWLINE", "EOF", "COMMENT", "BLOCK_CLOSE"):
425
442
  if self.peek().type == "DOLLAR":
@@ -428,17 +445,21 @@ class Parser:
428
445
  parts.append("$" + var_t.value)
429
446
  else:
430
447
  t = self.advance()
431
- parts.append(t.value)
448
+ if keep_string_quotes and t.type == "STRING":
449
+ parts.append('"' + t.value + '"')
450
+ else:
451
+ parts.append(t.value)
432
452
  return self._join_tokens(parts)
433
453
 
434
454
  def parse_animation(self, line: int) -> AnimationDirective:
435
455
  self.expect("EQUALS")
436
456
  values = self.parse_comma_values()
437
457
  name = values[0].strip() if len(values) > 0 else ""
438
- style = values[1].strip() if len(values) > 1 else ""
458
+ enabled = values[1].strip() if len(values) > 1 else "1"
439
459
  speed = values[2].strip() if len(values) > 2 else "1"
440
460
  curve = values[3].strip() if len(values) > 3 else "default"
441
- return AnimationDirective(name, style, speed, curve, line)
461
+ style = " ".join(v.strip() for v in values[4:] if v.strip())
462
+ return AnimationDirective(name, style, speed, curve, line, enabled)
442
463
 
443
464
  def parse_bezier(self, line: int) -> BezierDirective:
444
465
  self.expect("EQUALS")
@@ -480,13 +501,22 @@ class Parser:
480
501
  key_t = self.advance()
481
502
  self.expect("EQUALS")
482
503
  val = self.parse_value_rest()
483
- body.append(Directive(key_t.value, [val], key_t.line, 0))
504
+ if val.strip():
505
+ body.append(Directive(key_t.value, [val], key_t.line, 0))
484
506
  else:
485
507
  self.advance()
486
508
  self.skip_newlines()
487
509
  self.expect("BLOCK_CLOSE")
488
510
  return GestureDirective(body, line)
489
511
 
512
+ def parse_gesture_inline(self, line: int) -> GestureDirective:
513
+ self.expect("EQUALS")
514
+ values = self.parse_comma_values()
515
+ names = ["fingers", "direction", "action"]
516
+ body = [Directive(names[i], [v], line, 0)
517
+ for i, v in enumerate(values) if v.strip() and i < len(names)]
518
+ return GestureDirective(body, line)
519
+
490
520
  def parse_device(self, name: str, line: int) -> DeviceSection:
491
521
  self.skip_newlines()
492
522
  self.expect("BLOCK_OPEN")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyprconf2lua
3
- Version: 1.5.0
3
+ Version: 1.7.0
4
4
  Summary: Convert Hyprland hyprlang .conf files to Lua .lua config format (v0.55+)
5
5
  Author: hyprconf2lua contributors
6
6
  License: MIT
@@ -662,6 +662,30 @@ def test_nested_subsection_in_decoration():
662
662
  assert "size = 3" in result.lua
663
663
 
664
664
 
665
+ def test_windowrule_match_class():
666
+ result = convert("windowrule = workspace special:T silent, match:class ^(T)$\n")
667
+ assert result.success
668
+ assert "class = \"^(T)$\"" in result.lua
669
+ assert "workspace = \"special:T silent\"" in result.lua
670
+
671
+
672
+ def test_windowrule_match_class_with_equals():
673
+ result = convert("windowrule = workspace special:T silent, match:class = ^(T)$\n")
674
+ assert result.success
675
+ assert "class = \"^(T)$\"" in result.lua
676
+ assert "workspace = \"special:T silent\"" in result.lua
677
+
678
+
679
+ def test_windowrule_match_class_complex():
680
+ result = convert("windowrule = workspace special:T silent, match:class ^foo=bar$\n")
681
+ assert result.success
682
+ assert "class = \"^foo=bar$\"" in result.lua
683
+
684
+ result2 = convert("windowrule = workspace special:T silent, match:class:^(T)$\n")
685
+ assert result2.success
686
+ assert "class = \"^(T)$\"" in result2.lua
687
+
688
+
665
689
  def test_env_var_resolution():
666
690
  result = convert('env = AQ_DRM_DEVICES,$HOME/.config/hypr/cards/intelcard:$HOME/.config/hypr/cards/nvidiacard\n')
667
691
  assert result.success
@@ -681,3 +705,170 @@ def test_hyphen_to_underscore_in_general():
681
705
  assert result.success
682
706
  assert "no_cursor" in result.lua
683
707
  assert "no-cursor" not in result.lua
708
+
709
+
710
+ def test_leading_dot_float():
711
+ result = convert("input {\n scale = .97\n}\n")
712
+ assert result.success
713
+ assert "scale = .97," in result.lua
714
+ assert '". 97"' not in result.lua
715
+
716
+
717
+ def test_empty_value_skipped():
718
+ result = convert("input {\n kb_layout = es\n kb_variant =\n kb_model =\n}\n")
719
+ assert result.success
720
+ assert "kb_layout" in result.lua
721
+ assert "kb_variant" not in result.lua
722
+ assert "kb_model" not in result.lua
723
+ assert "{ }" not in result.lua
724
+
725
+
726
+ def test_source_filename_hyphens_sanitized():
727
+ result = convert("source = ~/.config/hypr/media-binds.conf\n")
728
+ assert result.success
729
+ assert 'require("media_binds")' in result.lua
730
+ assert "local media-binds" not in result.lua
731
+
732
+
733
+ def test_source_path_mapped_to_module():
734
+ result = convert("source = $HOME/.config/hypr/modules/keybinds.conf\n")
735
+ assert result.success
736
+ assert 'require("modules.keybinds")' in result.lua
737
+
738
+
739
+ def test_shell_brace_expansion():
740
+ result = convert("exec-once = xrdb ${XDG_CONFIG_HOME:-$HOME/.config}/x11/xresources\n")
741
+ assert result.success
742
+ assert "xrdb ${XDG_CONFIG_HOME:-" in result.lua
743
+ assert "os.getenv(\"HOME\")" in result.lua
744
+ assert "/x11/xresources" in result.lua
745
+
746
+
747
+ def test_multiline_exec_continuation():
748
+ src = (
749
+ "bind = ,print, exec, \\\n"
750
+ ' FILE=~/Pictures/screenshot_$(date +%s).png; \\\n'
751
+ ' grim -g "$(slurp)" "$FILE" && wl-copy < "$FILE" && \\\n'
752
+ ' notify-send "Screenshot saved" -i "$FILE"\n'
753
+ )
754
+ result = convert(src)
755
+ assert result.success
756
+ assert 'hl.dsp.exec_cmd("FILE=~/Pictures/screenshot_$(date +%s).png;' in result.lua
757
+ assert '\\"$(slurp)\\"' in result.lua
758
+ assert "$FILE" in result.lua
759
+ assert "local_var_FILE" not in result.lua
760
+
761
+
762
+ def test_movecurrentworkspacetomonitor_dispatcher():
763
+ result = convert("bind = CTRL $mainMod SHIFT, comma, movecurrentworkspacetomonitor, l\n")
764
+ assert result.success
765
+ assert 'hl.dsp.workspace.move({ monitor = "l" })' in result.lua
766
+
767
+
768
+ def test_stdin_hyphen_whitespace_preserved():
769
+ src = 'bind = , Print, exec, grim -c -g "$(slurp)" - | satty --filename -\n'
770
+ result = convert(src)
771
+ assert result.success
772
+ assert 'grim -c -g \\"$(slurp)\\" - | satty --filename -' in result.lua
773
+
774
+
775
+ def test_animations_inside_section_translated():
776
+ src = (
777
+ "animations {\n"
778
+ " enabled = yes, please :)\n"
779
+ " bezier = easeOutQuint, 0.23, 1, 0.32, 1\n"
780
+ " animation = windowsIn, 1, 4.1, easeOutQuint, popin 87%\n"
781
+ "}\n"
782
+ )
783
+ result = convert(src)
784
+ assert result.success
785
+ assert "enabled = true," in result.lua
786
+ assert 'hl.curve("easeOutQuint"' in result.lua
787
+ assert 'leaf = "windowsIn"' in result.lua
788
+ assert 'style = "popin 87%"' in result.lua
789
+ # statements must be outside the hl.config table (valid Lua)
790
+ cfg_end = result.lua.index("})")
791
+ assert "hl.animation" in result.lua[cfg_end:]
792
+
793
+
794
+ def test_animation_disabled_flag():
795
+ result = convert("animation = fadeOut, 0, 1.46, linear\n")
796
+ assert result.success
797
+ assert "enabled = false" in result.lua
798
+
799
+
800
+ def test_windowrule_block_multword_string():
801
+ result = convert('windowrule {\n name = w\n workspace = 3 silent\n}\n')
802
+ assert result.success
803
+ assert 'workspace = "3 silent"' in result.lua
804
+ assert "{ 3," not in result.lua
805
+
806
+
807
+ def test_windowrule_match_prefix_style():
808
+ result = convert("windowrule = match:class ^(pavucontrol)$, float on\n")
809
+ assert result.success
810
+ assert 'class = "^(pavucontrol)$"' in result.lua
811
+ assert "float = true" in result.lua
812
+
813
+
814
+ def test_windowrule_multi_match_and_move():
815
+ result = convert("windowrule = match:class ^(wofi)$, match:title ^(clippick)$, move 100%-433 53\n")
816
+ assert result.success
817
+ assert 'class = "^(wofi)$"' in result.lua
818
+ assert 'title = "^(clippick)$"' in result.lua
819
+ assert '{ "100%-433", 53 }' in result.lua
820
+
821
+
822
+ def test_layerrule_keyvalue_and_match_namespace():
823
+ result = convert("layerrule = blur=on, match:namespace ^(swaylock)$\n")
824
+ assert result.success
825
+ assert 'namespace = "^(swaylock)$"' in result.lua
826
+ assert "blur = true" in result.lua
827
+
828
+
829
+ def test_gesture_inline_in_section():
830
+ result = convert("gestures {\n workspace_swipe_invert = true\n gesture = 3, horizontal, workspace\n}\n")
831
+ assert result.success
832
+ assert "hl.gesture({" in result.lua
833
+ assert '"horizontal"' in result.lua
834
+ gest_pos = result.lua.index("hl.gesture")
835
+ cfg_pos = result.lua.index("})")
836
+ assert gest_pos > cfg_pos
837
+
838
+
839
+ def test_movewindow_direction_expanded():
840
+ result = convert("bind = SUPER SHIFT, L, movewindow, l\n")
841
+ assert result.success
842
+ assert 'hl.dsp.window.move({ direction = "left" })' in result.lua
843
+
844
+
845
+ def test_resizeactive_dispatcher():
846
+ result = convert("bind = SUPER SHIFT, H, resizeactive, -40 0\n")
847
+ assert result.success
848
+ assert "hl.dsp.window.resize({ x = -40, y = 0, relative = true })" in result.lua
849
+
850
+
851
+ def test_movewindow_workspace_delta():
852
+ result = convert("bind = SUPER, W, movewindow, +0\n")
853
+ assert result.success
854
+ assert '{ workspace = "+0" }' in result.lua
855
+
856
+
857
+ def test_layoutmsg_without_args_flagged():
858
+ result = convert("bind = SUPER, J, layoutmsg\n")
859
+ assert result.success
860
+ assert "TODO" in result.lua
861
+ assert "nil)" not in result.lua.replace("-- hl.bind", "")
862
+
863
+
864
+ def test_comma_in_variable_value():
865
+ result = convert("$kbNextWs = Ctrl+Super, right\n")
866
+ assert result.success
867
+ assert '"Ctrl+Super, right"' in result.lua
868
+
869
+
870
+ def test_rgba_color_values():
871
+ result = convert("decoration:shadow:color = rgba(0,0,0,0.85)\n")
872
+ assert result.success
873
+ assert '"rgba(0,0,0,0.85)"' in result.lua
874
+ assert "shadow = { color =" in result.lua
@@ -1 +0,0 @@
1
- __version__ = "1.5.0"
File without changes
File without changes
File without changes