hyprconf2lua 1.6.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.6.0/src/hyprconf2lua.egg-info → hyprconf2lua-1.7.0}/PKG-INFO +1 -1
  2. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/pyproject.toml +1 -1
  3. hyprconf2lua-1.7.0/src/hyprconf2lua/__init__.py +1 -0
  4. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/ast.py +1 -0
  5. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/codegen.py +142 -72
  6. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/mappings.py +2 -0
  7. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/parser.py +33 -11
  8. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0/src/hyprconf2lua.egg-info}/PKG-INFO +1 -1
  9. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/tests/test_converter.py +115 -0
  10. hyprconf2lua-1.6.0/src/hyprconf2lua/__init__.py +0 -1
  11. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/LICENSE +0 -0
  12. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/README.md +0 -0
  13. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/setup.cfg +0 -0
  14. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/__main__.py +0 -0
  15. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/cli.py +0 -0
  16. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/converter.py +0 -0
  17. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua/lexer.py +0 -0
  18. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/SOURCES.txt +0 -0
  19. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/dependency_links.txt +0 -0
  20. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/entry_points.txt +0 -0
  21. {hyprconf2lua-1.6.0 → hyprconf2lua-1.7.0}/src/hyprconf2lua.egg-info/requires.txt +0 -0
  22. {hyprconf2lua-1.6.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.6.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.6.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):
@@ -280,6 +282,20 @@ class Codegen:
280
282
  if not values or all(not v.strip() for v in values):
281
283
  return
282
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
283
299
  if len(values) == 1 and self._is_gradient(values[0]):
284
300
  self.translated_count += 1
285
301
  self.emit(f"{key} = {self._format_gradient(values[0])},")
@@ -311,6 +327,8 @@ class Codegen:
311
327
  if not directives:
312
328
  return
313
329
 
330
+ deferred: List[BlockStmt] = []
331
+
314
332
  self.emit(f"hl.config({{")
315
333
  self.indent()
316
334
  self.emit(f"{section_name} = {{")
@@ -336,16 +354,23 @@ class Codegen:
336
354
  k = self._normalize_key(ssd.key)
337
355
  vv = self.to_lua_val(ssd.value[0]) if ssd.value else "true"
338
356
  self.emit(f"{k} = {vv},")
357
+ elif isinstance(sd, (AnimationDirective, BezierDirective, GestureDirective)):
358
+ deferred.append(sd)
339
359
  self.dedent()
340
360
  self.emit("},")
341
361
  elif isinstance(d, Directive):
342
362
  self._emit_directive(d.key, d.value)
363
+ elif isinstance(d, (AnimationDirective, BezierDirective, GestureDirective)):
364
+ deferred.append(d)
343
365
 
344
366
  self.dedent()
345
367
  self.emit("},")
346
368
  self.dedent()
347
369
  self.emit("})")
348
370
 
371
+ for node in deferred:
372
+ self.visit(node)
373
+
349
374
  def flush_subsection(self, name: str, directives: List[Directive]):
350
375
  if not directives:
351
376
  return
@@ -408,6 +433,7 @@ class Codegen:
408
433
  self.emit_section_config(stmt.name, stmt.body)
409
434
  else:
410
435
  self.translated_count += 1
436
+ deferred: List[BlockStmt] = []
411
437
  self.emit(f"hl.config({{")
412
438
  self.indent()
413
439
  self.emit(f"{stmt.name} = {{")
@@ -417,10 +443,14 @@ class Codegen:
417
443
  self.emit(f"--{child.text[1:]}")
418
444
  elif isinstance(child, Directive):
419
445
  self._emit_directive(child.key, child.value)
446
+ elif isinstance(child, (AnimationDirective, BezierDirective, GestureDirective)):
447
+ deferred.append(child)
420
448
  self.dedent()
421
449
  self.emit("},")
422
450
  self.dedent()
423
451
  self.emit("})")
452
+ for node in deferred:
453
+ self.visit(node)
424
454
  self.emit(f"-- NOTE: Section '{stmt.name}' may be a plugin or custom section; verify the output")
425
455
 
426
456
  def visit_directive(self, stmt: Directive):
@@ -565,12 +595,22 @@ class Codegen:
565
595
  return f'{func}({{ next = false }})'
566
596
  return f'{func}()'
567
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
+
568
608
  if dispatcher == "movewindow":
569
609
  if params and params[0].startswith("into_group:"):
570
610
  return f'{func}({{ into_group = {self.quote(params[0][len("into_group:"):])} }})'
571
611
  if params and params[0] == "out_of_group":
572
612
  return f'{func}({{ out_of_group = true }})'
573
- return self.build_dispatcher_args(params, needs_args, func)
613
+ return f'{func}({self.build_dispatcher_args(params, needs_args, func)})'
574
614
 
575
615
  if dispatcher == "swapwindow":
576
616
  if params and params[0] in ("l", "r", "u", "d"):
@@ -622,6 +662,9 @@ class Codegen:
622
662
  return f'{func}({self._build_concat_expr(resolved)})'
623
663
  return f'{func}({self.quote(resolved)})'
624
664
 
665
+ if needs_args and not params:
666
+ return None
667
+
625
668
  args = self.build_dispatcher_args(params, needs_args, func)
626
669
  return f'{func}({args})' if needs_args else f'{func}()'
627
670
 
@@ -670,10 +713,15 @@ class Codegen:
670
713
  if len(params) == 1:
671
714
  p = params[0]
672
715
  if func and func == "hl.dsp.window.move":
716
+ dir_map = {"l": "left", "r": "right", "u": "up", "d": "down"}
673
717
  if p.startswith("special"):
674
718
  return f'{{ workspace = {self.quote(p)} }}'
675
719
  if p.isdigit():
676
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]}" }}'
677
725
  return f'{{ direction = {self.quote(p)} }}'
678
726
  return self.quote(self.resolve_val(p))
679
727
 
@@ -696,52 +744,79 @@ class Codegen:
696
744
  self.dedent()
697
745
  self.emit("})")
698
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
+
699
772
  def visit_windowrule(self, stmt: WindowRule):
700
773
  self.translated_count += 1
701
774
  rule = stmt.rule
702
775
  match_params = stmt.match_params
703
776
 
704
- match = {}
705
- 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]
706
780
 
707
- for mp in match_params:
708
- if mp.startswith("match:"):
781
+ match = {}
782
+ if explicit:
783
+ props = others
784
+ for mp in explicit:
709
785
  rest = mp[len("match:"):].strip()
710
786
  m = re.match(r'^([a-zA-Z0-9_-]+)(?:\s*=\s*|\s*:\s*|\s+)(.*)$', rest)
711
787
  if m:
712
- match_key, value = m.groups()
788
+ match_key, value = m.group(1), m.group(2).strip()
713
789
  else:
714
- match_key = rest
715
- value = "true"
790
+ match_key, value = rest, "true"
716
791
  if value.lower() == "true":
717
792
  match[match_key] = "true"
718
793
  elif value.lower() == "false":
719
794
  match[match_key] = "false"
720
795
  else:
721
796
  match[match_key] = self.quote(value)
722
- continue
723
-
724
- colon_idx = mp.find(":")
725
- if colon_idx > 0:
726
- prefix = mp[:colon_idx].strip()
727
- value = mp[colon_idx + 1:].strip()
728
- match_key = prefix
729
- if value.lower() == "true":
730
- match[match_key] = "true"
731
- elif value.lower() == "false":
732
- match[match_key] = "false"
733
- else:
734
- match[match_key] = self.quote(value)
735
-
736
- if not match and not stmt.is_v2:
737
- if match_params:
738
- class_val = match_params[0]
739
- match["class"] = self.quote(class_val)
740
-
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
741
816
  self.emit("hl.window_rule({")
742
817
  self.indent()
743
818
 
744
- 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())
745
820
  self.emit(f'name = "{name_str}",')
746
821
 
747
822
  self.emit("match = {")
@@ -751,29 +826,10 @@ class Codegen:
751
826
  self.dedent()
752
827
  self.emit("},")
753
828
 
754
- rule_lower = rule.lower().strip()
755
- applied = False
756
-
757
- if rule_lower in WINDOW_RULE_MAP:
758
- k, v = WINDOW_RULE_MAP[rule_lower]
759
- self.emit(f"{k} = {v},")
760
- applied = True
761
- else:
762
- parts = rule.split(None, 1)
763
- if parts and parts[0] in WINDOW_RULE_PARAM_MAP:
764
- k, needs_val = WINDOW_RULE_PARAM_MAP[parts[0]]
765
- if needs_val and len(parts) > 1:
766
- val = self.to_lua_val(parts[1])
767
- self.emit(f"{k} = {val},")
768
- elif needs_val:
769
- self.emit(f"{k} = true,")
770
- else:
771
- self.emit(f"{k} = true,")
772
- applied = True
773
-
774
- if not applied:
775
- self.flag_count += 1
776
- 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)}')
777
833
 
778
834
  self.dedent()
779
835
  self.emit("})")
@@ -798,7 +854,9 @@ class Codegen:
798
854
  key = self._normalize_key(key)
799
855
  if not vals or not vals[0].strip():
800
856
  continue
801
- if len(vals) == 1:
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:
802
860
  parts = vals[0].split()
803
861
  if len(parts) == 1:
804
862
  self.emit(f"{key} = {self.to_lua_val(parts[0])},")
@@ -828,6 +886,7 @@ class Codegen:
828
886
  style = stmt.style
829
887
  speed = stmt.speed
830
888
  curve = stmt.curve
889
+ enabled = "true" if stmt.enabled.strip().lower() in ("1", "yes", "on", "true") else "false"
831
890
 
832
891
  try:
833
892
  float(speed)
@@ -837,11 +896,7 @@ class Codegen:
837
896
 
838
897
  style_extra = ""
839
898
  if style and style != "default":
840
- if " " in style:
841
- style_name, *style_args = style.split()
842
- style_extra = f', style = {self.quote(style)}'
843
- else:
844
- style_extra = f', style = {self.quote(style)}'
899
+ style_extra = f', style = {self.quote(style)}'
845
900
 
846
901
  if curve and curve != "default":
847
902
  if re.match(r'^\d+(\.\d+)?$', curve):
@@ -851,13 +906,13 @@ class Codegen:
851
906
  spring_parts = curve.split()
852
907
  if len(spring_parts) >= 4:
853
908
  self.passthrough_count += 1
854
- 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} }})')
855
910
  else:
856
- 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} }})')
857
912
  else:
858
- 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} }})')
859
914
  else:
860
- 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} }})')
861
916
 
862
917
  def visit_bezier(self, stmt: BezierDirective):
863
918
  self.translated_count += 1
@@ -972,8 +1027,18 @@ class Codegen:
972
1027
 
973
1028
  def visit_layerrule(self, stmt: LayerRuleDirective):
974
1029
  self.translated_count += 1
975
- rule_lower = stmt.rule.lower()
976
- 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
977
1042
 
978
1043
  self.emit("hl.layer_rule({")
979
1044
  self.indent()
@@ -983,16 +1048,19 @@ class Codegen:
983
1048
  self.dedent()
984
1049
  self.emit("},")
985
1050
 
986
- if rule_lower in LAYER_RULE_MAP:
987
- k, v = LAYER_RULE_MAP[rule_lower]
988
- 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"):
989
1055
  self.emit(f"{k} = {v},")
1056
+ elif value:
1057
+ self.emit(f"{k} = {self.to_lua_val(value)},")
990
1058
  else:
991
- self.emit(f"{k} = {self.to_lua_val(v)},")
992
- else:
993
- parts = rule_lower.split(None, 1)
994
- if parts:
995
- 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'},")
996
1064
 
997
1065
  self.dedent()
998
1066
  self.emit("})")
@@ -1016,7 +1084,9 @@ class Codegen:
1016
1084
  key = self._normalize_key(key)
1017
1085
  if not vals or not vals[0].strip():
1018
1086
  continue
1019
- if len(vals) == 1:
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:
1020
1090
  parts = vals[0].split()
1021
1091
  if len(parts) == 1:
1022
1092
  self.emit(f"{key} = {self.to_lua_val(parts[0])},")
@@ -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", "SHELL_EXP", "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,7 +171,7 @@ class Parser:
159
171
  return ""
160
172
  result = tokens[0]
161
173
  for t in tokens[1:]:
162
- no_space_before = {":", ",", "=", "+", "-", "%", "@", "^", "*", "|", "~"}
174
+ no_space_before = {":", ",", "=", "+", "%", "@", "^", "*", "~"}
163
175
  no_space_after = {":", ",", "=", "."}
164
176
  if t in no_space_before or result[-1:] in no_space_after or t.startswith(("/", ".")):
165
177
  result += t
@@ -260,7 +272,7 @@ class Parser:
260
272
  if directive == "gesture":
261
273
  if self.peek().type == "BLOCK_OPEN":
262
274
  return self.parse_gesture(t.line)
263
- return self.parse_general_directive(directive, t.line)
275
+ return self.parse_gesture_inline(t.line)
264
276
  if directive == "workspace":
265
277
  return self.parse_workspace(t.line)
266
278
  if directive == "layerrule":
@@ -443,10 +455,11 @@ class Parser:
443
455
  self.expect("EQUALS")
444
456
  values = self.parse_comma_values()
445
457
  name = values[0].strip() if len(values) > 0 else ""
446
- style = values[1].strip() if len(values) > 1 else ""
458
+ enabled = values[1].strip() if len(values) > 1 else "1"
447
459
  speed = values[2].strip() if len(values) > 2 else "1"
448
460
  curve = values[3].strip() if len(values) > 3 else "default"
449
- 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)
450
463
 
451
464
  def parse_bezier(self, line: int) -> BezierDirective:
452
465
  self.expect("EQUALS")
@@ -488,13 +501,22 @@ class Parser:
488
501
  key_t = self.advance()
489
502
  self.expect("EQUALS")
490
503
  val = self.parse_value_rest()
491
- 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))
492
506
  else:
493
507
  self.advance()
494
508
  self.skip_newlines()
495
509
  self.expect("BLOCK_CLOSE")
496
510
  return GestureDirective(body, line)
497
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
+
498
520
  def parse_device(self, name: str, line: int) -> DeviceSection:
499
521
  self.skip_newlines()
500
522
  self.expect("BLOCK_OPEN")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyprconf2lua
3
- Version: 1.6.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
@@ -757,3 +757,118 @@ def test_multiline_exec_continuation():
757
757
  assert '\\"$(slurp)\\"' in result.lua
758
758
  assert "$FILE" in result.lua
759
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.6.0"
File without changes
File without changes
File without changes