| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright © 2025 Pierre Le Marre <[email protected]> |
| 4 |
# SPDX-License-Identifier: MIT |
| 5 |
|
| 6 |
""" |
| 7 |
This script generate tests for merge modes. |
| 8 |
""" |
| 9 |
|
| 10 |
from __future__ import annotations |
| 11 |
|
| 12 |
from abc import ABCMeta, abstractmethod |
| 13 |
import argparse |
| 14 |
from collections import defaultdict |
| 15 |
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence |
| 16 |
import dataclasses |
| 17 |
import itertools |
| 18 |
import re |
| 19 |
import textwrap |
| 20 |
from dataclasses import dataclass |
| 21 |
from enum import Flag, IntFlag, StrEnum, auto, unique |
| 22 |
from pathlib import Path |
| 23 |
from string import Template |
| 24 |
from typing import Any, ClassVar, NewType, Self |
| 25 |
|
| 26 |
import jinja2 |
| 27 |
|
| 28 |
SCRIPT = Path(__file__) |
| 29 |
# Root of the project |
| 30 |
ROOT = SCRIPT.parent.parent |
| 31 |
|
| 32 |
################################################################################ |
| 33 |
# |
| 34 |
# XKB compiler |
| 35 |
# |
| 36 |
################################################################################ |
| 37 |
|
| 38 |
|
| 39 |
@dataclass |
| 40 |
class XkbCompiler: |
| 41 |
name: str |
| 42 |
extended_syntax: bool |
| 43 |
|
| 44 |
default: ClassVar[str] = "xkbcommon" |
| 45 |
|
| 46 |
@property |
| 47 |
def is_default(self) -> bool: |
| 48 |
return self.name == self.default |
| 49 |
|
| 50 |
@property |
| 51 |
def suffix(self) -> str: |
| 52 |
return "" if self.is_default else "-" + self.name |
| 53 |
|
| 54 |
@classmethod |
| 55 |
def parse(cls, name: str) -> Self: |
| 56 |
match name: |
| 57 |
case cls.default: |
| 58 |
return cls(name=name, extended_syntax=True) |
| 59 |
case "xkbcomp": |
| 60 |
return cls(name=name, extended_syntax=False) |
| 61 |
case "kbvm": |
| 62 |
return cls(name=name, extended_syntax=True) |
| 63 |
case _: |
| 64 |
raise ValueError(f"Invalid XKB compiler: {name}") |
| 65 |
|
| 66 |
|
| 67 |
################################################################################ |
| 68 |
# |
| 69 |
# Merge modes |
| 70 |
# |
| 71 |
################################################################################ |
| 72 |
|
| 73 |
|
| 74 |
@unique |
| 75 |
class MergeMode(StrEnum): |
| 76 |
Default = auto() |
| 77 |
Augment = auto() |
| 78 |
Override = auto() |
| 79 |
Replace = auto() |
| 80 |
|
| 81 |
@property |
| 82 |
def include(self) -> str: |
| 83 |
if self is self.__class__.Default: |
| 84 |
return "include" |
| 85 |
else: |
| 86 |
return self |
| 87 |
|
| 88 |
@property |
| 89 |
def char(self) -> str: |
| 90 |
match self: |
| 91 |
case self.__class__.Default: |
| 92 |
return "+" |
| 93 |
case self.__class__.Augment: |
| 94 |
return "|" |
| 95 |
case self.__class__.Override: |
| 96 |
return "+" |
| 97 |
case self.__class__.Replace: |
| 98 |
return "^" |
| 99 |
case _: |
| 100 |
raise ValueError(self) |
| 101 |
|
| 102 |
|
| 103 |
INDENT = "\t" |
| 104 |
|
| 105 |
|
| 106 |
################################################################################ |
| 107 |
# |
| 108 |
# Components |
| 109 |
# |
| 110 |
################################################################################ |
| 111 |
|
| 112 |
|
| 113 |
@unique |
| 114 |
class Component(StrEnum): |
| 115 |
keycodes = auto() |
| 116 |
types = auto() |
| 117 |
compat = auto() |
| 118 |
symbols = auto() |
| 119 |
|
| 120 |
def render_keymap(self, content) -> Generator[str]: |
| 121 |
yield "xkb_keymap {" |
| 122 |
for component in self.__class__: |
| 123 |
yield from ( |
| 124 |
textwrap.indent(t, INDENT) |
| 125 |
for t in self.render(component, content if component is self else "") |
| 126 |
) |
| 127 |
yield "};" |
| 128 |
|
| 129 |
@classmethod |
| 130 |
def render(cls, component: Self, content: str, name: str = "") -> Generator[str]: |
| 131 |
if not content: |
| 132 |
match component: |
| 133 |
case cls.keycodes: |
| 134 |
pass |
| 135 |
case cls.types: |
| 136 |
pass |
| 137 |
case cls.compat: |
| 138 |
content = "interpret.repeat= True;" |
| 139 |
case cls.symbols: |
| 140 |
pass |
| 141 |
if name: |
| 142 |
name = f' "{name}"' |
| 143 |
if content: |
| 144 |
yield f'xkb_{component}{name} "" {{' |
| 145 |
yield textwrap.indent(content, INDENT) |
| 146 |
yield "};" |
| 147 |
else: |
| 148 |
yield f'xkb_{component}{name} "" {{}};' |
| 149 |
|
| 150 |
|
| 151 |
class ComponentTemplate(Template): |
| 152 |
def __init__(self, template) -> Self: |
| 153 |
super().__init__(textwrap.dedent(template).strip()) |
| 154 |
|
| 155 |
def __bool__(self) -> bool: |
| 156 |
return bool(self.template) |
| 157 |
|
| 158 |
def render(self, merge: MergeMode) -> str: |
| 159 |
mode = "" if merge is MergeMode.Default else f"{merge} " |
| 160 |
return self.substitute(mode=mode) |
| 161 |
|
| 162 |
def __add__(self, other: Any) -> Self: |
| 163 |
if isinstance(other, str): |
| 164 |
return self.__class__(self.template + "\n" + other) |
| 165 |
elif isinstance(other, Template): |
| 166 |
return self.__class__(self.template + "\n" + other.template) |
| 167 |
else: |
| 168 |
return NotImplemented |
| 169 |
|
| 170 |
def __radd__(self, other: Any) -> Self: |
| 171 |
if isinstance(other, str): |
| 172 |
return self.__class__(other + "\n" + self.template) |
| 173 |
elif isinstance(other, Template): |
| 174 |
return self.__class__(other.template + "\n" + self.template) |
| 175 |
else: |
| 176 |
return NotImplemented |
| 177 |
|
| 178 |
|
| 179 |
################################################################################ |
| 180 |
# |
| 181 |
# Test templates |
| 182 |
# |
| 183 |
################################################################################ |
| 184 |
|
| 185 |
|
| 186 |
@dataclass |
| 187 |
class Test: |
| 188 |
title: str |
| 189 |
file: Path |
| 190 |
content: str |
| 191 |
expected: str |
| 192 |
|
| 193 |
|
| 194 |
@dataclass |
| 195 |
class TestGroup: |
| 196 |
title: str |
| 197 |
tests: Sequence[Test] |
| 198 |
|
| 199 |
c_template: ClassVar[Path] = Path("test/merge_modes.c.jinja") |
| 200 |
|
| 201 |
SLUG_PATTERN: ClassVar[re.Pattern[str]] = re.compile(r"[^-\w()]+") |
| 202 |
|
| 203 |
@classmethod |
| 204 |
def file(cls, title: str) -> Path: |
| 205 |
return Path(cls.SLUG_PATTERN.sub("-", title.lower().replace(" ", "_"))) |
| 206 |
|
| 207 |
@classmethod |
| 208 |
def _write( |
| 209 |
cls, |
| 210 |
root: Path, |
| 211 |
jinja_env: jinja2.Environment, |
| 212 |
path: Path, |
| 213 |
**kwargs, |
| 214 |
) -> None: |
| 215 |
template_path = root / cls.c_template |
| 216 |
template = jinja_env.get_template(template_path.relative_to(root).as_posix()) |
| 217 |
|
| 218 |
with path.open("wt", encoding="utf-8") as fd: |
| 219 |
fd.writelines(template.generate(script=SCRIPT.relative_to(ROOT), **kwargs)) |
| 220 |
|
| 221 |
@classmethod |
| 222 |
def write_c( |
| 223 |
cls, |
| 224 |
root: Path, |
| 225 |
jinja_env: jinja2.Environment, |
| 226 |
path: Path, |
| 227 |
compiler: XkbCompiler, |
| 228 |
tests: Sequence[TestGroup], |
| 229 |
) -> None: |
| 230 |
return cls._write( |
| 231 |
root=root, jinja_env=jinja_env, path=path, compiler=compiler, tests=tests |
| 232 |
) |
| 233 |
|
| 234 |
@classmethod |
| 235 |
def write_data( |
| 236 |
cls, |
| 237 |
root: Path, |
| 238 |
compiler: XkbCompiler, |
| 239 |
tests: Sequence[TestGroup], |
| 240 |
) -> None: |
| 241 |
tests_: dict[Path, list[Test]] = defaultdict(list) |
| 242 |
suffix = compiler.suffix |
| 243 |
for group in tests: |
| 244 |
for test in group.tests: |
| 245 |
file = test.file.parent |
| 246 |
file = file.with_name(file.name + suffix) |
| 247 |
tests_[file].append(test) |
| 248 |
for file, group_ in tests_.items(): |
| 249 |
path = root / "test" / "data" / file |
| 250 |
with path.open("wt", encoding="utf-8") as fd: |
| 251 |
fd.write( |
| 252 |
"// WARNING: This file was auto-generated by: " |
| 253 |
f"{SCRIPT.relative_to(ROOT)}\n" |
| 254 |
) |
| 255 |
for test in group_: |
| 256 |
fd.write(test.content) |
| 257 |
|
| 258 |
|
| 259 |
@dataclass |
| 260 |
class TestTemplate(metaclass=ABCMeta): |
| 261 |
title: str |
| 262 |
|
| 263 |
_plain: ClassVar[str] = "plain" |
| 264 |
_include: ClassVar[str] = "include" |
| 265 |
_base: ClassVar[str] = "base" |
| 266 |
_update: ClassVar[str] = "update" |
| 267 |
_file: ClassVar[str] = "merge_modes" |
| 268 |
|
| 269 |
def make_title(self, name: str) -> str: |
| 270 |
return f"{self.title}: {name}" |
| 271 |
|
| 272 |
@classmethod |
| 273 |
def make_file(cls, name: str) -> Path: |
| 274 |
return TestGroup.file(name) |
| 275 |
|
| 276 |
@abstractmethod |
| 277 |
def generate_tests(self) -> TestGroup: ... |
| 278 |
|
| 279 |
@abstractmethod |
| 280 |
def generate_data(self) -> TestGroup: ... |
| 281 |
|
| 282 |
@classmethod |
| 283 |
@abstractmethod |
| 284 |
def write( |
| 285 |
cls, |
| 286 |
root: Path, |
| 287 |
jinja_env: jinja2.Environment, |
| 288 |
c_file: Path | None, |
| 289 |
xkb: bool, |
| 290 |
compiler: XkbCompiler, |
| 291 |
tests: Sequence[Self], |
| 292 |
debug: bool, |
| 293 |
): ... |
| 294 |
|
| 295 |
|
| 296 |
@dataclass |
| 297 |
class ComponentTestTemplate(TestTemplate): |
| 298 |
component: Component |
| 299 |
# Templates to test |
| 300 |
base_template: ComponentTemplate |
| 301 |
update_template: ComponentTemplate |
| 302 |
# Expected result |
| 303 |
augment: str |
| 304 |
override: str |
| 305 |
replace: str = "" |
| 306 |
|
| 307 |
def __post_init__(self): |
| 308 |
self.augment = textwrap.dedent(self.augment).strip() |
| 309 |
self.override = textwrap.dedent(self.override).strip() |
| 310 |
if not self.replace: |
| 311 |
self.replace = self.override |
| 312 |
else: |
| 313 |
self.replace = textwrap.dedent(self.replace).strip() |
| 314 |
|
| 315 |
def expected(self, mode: MergeMode) -> str: |
| 316 |
match mode: |
| 317 |
case MergeMode.Default: |
| 318 |
return self.override |
| 319 |
case MergeMode.Augment: |
| 320 |
return self.augment |
| 321 |
case MergeMode.Override: |
| 322 |
return self.override |
| 323 |
case MergeMode.Replace: |
| 324 |
return self.replace |
| 325 |
case _: |
| 326 |
raise ValueError(mode) |
| 327 |
|
| 328 |
def _make_section_name(self, type: str, mode: MergeMode) -> str: |
| 329 |
file = self.make_file(f"{self.title}-{mode}" if self.title else mode) |
| 330 |
return f"{type}-{file}" |
| 331 |
|
| 332 |
def _make_file(self, type: str, mode: MergeMode) -> Path: |
| 333 |
section_name = self._make_section_name(type, mode) |
| 334 |
return Path(self.component) / self._file / section_name |
| 335 |
|
| 336 |
def render_section(self, content: str, name: str = "") -> str: |
| 337 |
return "\n".join(self.component.render(self.component, content, name)) |
| 338 |
|
| 339 |
def render_keymap(self, content: str) -> str: |
| 340 |
return "\n".join(self.component.render_keymap(content)) |
| 341 |
|
| 342 |
def _generate_tests( |
| 343 |
self, render: Callable[[str], str], compiler: XkbCompiler |
| 344 |
) -> Generator[Test]: |
| 345 |
include_suffix = compiler.suffix |
| 346 |
for base_mode, update_mode in itertools.product(MergeMode, MergeMode): |
| 347 |
# Plain |
| 348 |
content = ( |
| 349 |
self.base_template.render(base_mode) |
| 350 |
+ ("\n" if self.base_template else "") |
| 351 |
+ self.update_template.render(update_mode) |
| 352 |
) |
| 353 |
yield Test( |
| 354 |
title=self.make_title( |
| 355 |
f"{self._plain} ({base_mode}) - {self._plain} ({update_mode})" |
| 356 |
), |
| 357 |
file=self.make_file(self.title) / self.make_file(update_mode), |
| 358 |
content=render(content), |
| 359 |
expected=render(self.expected(update_mode)), |
| 360 |
) |
| 361 |
|
| 362 |
for base_mode, update_mode in itertools.product( |
| 363 |
(MergeMode.Default,), MergeMode |
| 364 |
): |
| 365 |
# Plain + Include |
| 366 |
file = self._make_file(self._update, update_mode) |
| 367 |
section = file.name |
| 368 |
file = file.parent.name |
| 369 |
for mode in MergeMode: |
| 370 |
yield Test( |
| 371 |
title=self.make_title( |
| 372 |
f"{self._plain} ({base_mode}) - {mode.include} ({update_mode})" |
| 373 |
), |
| 374 |
file=self.make_file(self.title) / self.make_file(mode), |
| 375 |
content=render( |
| 376 |
self.base_template.render(base_mode) |
| 377 |
+ ( |
| 378 |
f'\n{mode.include} "{file}{include_suffix}({section})"' |
| 379 |
if self.base_template |
| 380 |
else "" |
| 381 |
) |
| 382 |
), |
| 383 |
# Include does not leak local merge modes |
| 384 |
expected=render(self.expected(mode)), |
| 385 |
) |
| 386 |
|
| 387 |
# for base_mode, update_mode in itertools.product(MergeMode, MergeMode): |
| 388 |
# # Include + Plain |
| 389 |
# file = self._make_file(self.base, base_mode) |
| 390 |
# section = file.name |
| 391 |
# file = file.parent.name |
| 392 |
# for mode in (MergeMode.default,): |
| 393 |
# yield Test( |
| 394 |
# title=self.make_title( |
| 395 |
# f"{mode.include} ({base_mode}) - {self.plain} ({update_mode})" |
| 396 |
# ), |
| 397 |
# file=self.make_file(self.title) |
| 398 |
# / self.make_file( |
| 399 |
# f"{mode.include}({base_mode})-{self.plain}({update_mode})" |
| 400 |
# ), |
| 401 |
# content=render( |
| 402 |
# f'{mode.include} "{file}{include_suffix}({section})"\n' |
| 403 |
# + self.update_template.render(update_mode) |
| 404 |
# ), |
| 405 |
# expected=render(self.expected(update_mode)), |
| 406 |
# ) |
| 407 |
|
| 408 |
# for base_mode, update_mode in itertools.product((MergeMode.Default,), MergeMode): |
| 409 |
# # Include + Include |
| 410 |
# mode = MergeMode.Default |
| 411 |
# base_file = self._make_file(self.base, mode) |
| 412 |
# base_section = base_file.name |
| 413 |
# base_file = base_file.parent.name |
| 414 |
# update_file = self._make_file(self.update, mode) |
| 415 |
# update_section = update_file.name |
| 416 |
# update_file = update_file.parent.name |
| 417 |
# yield Test( |
| 418 |
# title=self.make_title( |
| 419 |
# f"{base_mode.include} ({mode}) - {update_mode.include} ({mode})" |
| 420 |
# ), |
| 421 |
# file=self.make_file(self.title) |
| 422 |
# / self.make_file( |
| 423 |
# f"{base_mode.include}({mode})-{update_mode.include}({mode})" |
| 424 |
# ), |
| 425 |
# content=render( |
| 426 |
# f'{base_mode.include} "{base_file}{include_suffix}({base_section})"\n' |
| 427 |
# + f'{update_mode.include} "{update_file}{include_suffix}({update_section})"' |
| 428 |
# ), |
| 429 |
# expected=render(self.expected(update_mode)), |
| 430 |
# ) |
| 431 |
|
| 432 |
for base_mode, update_mode in itertools.product(MergeMode, MergeMode): |
| 433 |
# Multi-include |
| 434 |
base_file = self._make_file(self._base, base_mode) |
| 435 |
base_section = base_file.name |
| 436 |
base_file = base_file.parent.name |
| 437 |
update_file = self._make_file(self._update, update_mode) |
| 438 |
update_section = update_file.name |
| 439 |
update_file = update_file.parent.name |
| 440 |
for mode in (MergeMode.Override, MergeMode.Augment, MergeMode.Replace): |
| 441 |
yield Test( |
| 442 |
title=self.make_title( |
| 443 |
f"{self._include} ({base_mode} {mode.char} {update_mode})" |
| 444 |
), |
| 445 |
file=self.make_file(self.title) / self.make_file(mode), |
| 446 |
content=render( |
| 447 |
f'{base_mode.include} "{base_file}{include_suffix}({base_section})' |
| 448 |
+ mode.char |
| 449 |
+ f'{update_file}{include_suffix}({update_section})"' |
| 450 |
), |
| 451 |
expected=render(self.expected(mode)), |
| 452 |
) |
| 453 |
|
| 454 |
def _generate_data(self) -> Generator[Test]: |
| 455 |
for type, template in ( |
| 456 |
(self._base, self.base_template), |
| 457 |
(self._update, self.update_template), |
| 458 |
): |
| 459 |
for mode in MergeMode: |
| 460 |
section_name = self._make_section_name(type, mode) |
| 461 |
file = self._make_file(type, mode) |
| 462 |
content = template.render(mode) |
| 463 |
content = self.render_section(content=content, name=section_name) + "\n" |
| 464 |
yield Test(title="", file=file, content=content, expected="") |
| 465 |
|
| 466 |
def generate_tests( |
| 467 |
self, compiler: XkbCompiler, as_keymap: bool = False |
| 468 |
) -> TestGroup: |
| 469 |
if as_keymap: |
| 470 |
|
| 471 |
def render(content: str) -> str: |
| 472 |
return self.render_keymap(content) |
| 473 |
else: |
| 474 |
|
| 475 |
def render(content: str) -> str: |
| 476 |
return self.render_section(content) |
| 477 |
|
| 478 |
return TestGroup(self.title, tuple(self._generate_tests(render, compiler))) |
| 479 |
|
| 480 |
def generate_data(self) -> TestGroup: |
| 481 |
return TestGroup(self.title, tuple(self._generate_data())) |
| 482 |
|
| 483 |
@classmethod |
| 484 |
def write( |
| 485 |
cls, |
| 486 |
root: Path, |
| 487 |
jinja_env: jinja2.Environment, |
| 488 |
c_file: Path | None, |
| 489 |
xkb: bool, |
| 490 |
compiler: XkbCompiler, |
| 491 |
tests: Sequence[Self], |
| 492 |
debug: bool = False, |
| 493 |
): |
| 494 |
if c_file is not None and c_file.name: |
| 495 |
c_data = tuple( |
| 496 |
t.generate_tests(as_keymap=True, compiler=compiler) for t in tests |
| 497 |
) |
| 498 |
TestGroup.write_c( |
| 499 |
root=root, |
| 500 |
jinja_env=jinja_env, |
| 501 |
path=c_file, |
| 502 |
compiler=compiler, |
| 503 |
tests=c_data, |
| 504 |
) |
| 505 |
if xkb: |
| 506 |
xkb_data = tuple(t.generate_data() for t in tests) |
| 507 |
TestGroup.write_data(root=root, compiler=compiler, tests=xkb_data) |
| 508 |
|
| 509 |
|
| 510 |
KeymapTemplate = Template( |
| 511 |
"""\ |
| 512 |
xkb_keymap { |
| 513 |
${keycodes} |
| 514 |
${types} |
| 515 |
${compat} |
| 516 |
${symbols} |
| 517 |
};""" |
| 518 |
) |
| 519 |
|
| 520 |
|
| 521 |
@dataclass |
| 522 |
class KeymapTestTemplate(TestTemplate): |
| 523 |
keycodes: ComponentTestTemplate | None = None |
| 524 |
types: ComponentTestTemplate | None = None |
| 525 |
compat: ComponentTestTemplate | None = None |
| 526 |
symbols: ComponentTestTemplate | None = None |
| 527 |
|
| 528 |
def __post_init__(self): |
| 529 |
if self.keycodes: |
| 530 |
self.keycodes = dataclasses.replace(self.keycodes, title="") |
| 531 |
if self.types: |
| 532 |
self.types = dataclasses.replace(self.types, title="") |
| 533 |
if self.compat: |
| 534 |
self.compat = dataclasses.replace(self.compat, title="") |
| 535 |
if self.symbols: |
| 536 |
self.symbols = dataclasses.replace(self.symbols, title="") |
| 537 |
|
| 538 |
def __iter__(self) -> Generator[ComponentTestTemplate]: |
| 539 |
def make_empty_template(component: Component) -> ComponentTestTemplate: |
| 540 |
return ComponentTestTemplate( |
| 541 |
title="", |
| 542 |
component=component, |
| 543 |
base_template=ComponentTemplate(""), |
| 544 |
update_template=ComponentTemplate(""), |
| 545 |
augment="", |
| 546 |
override="", |
| 547 |
) |
| 548 |
|
| 549 |
yield self.keycodes or make_empty_template(Component.keycodes) |
| 550 |
yield self.types or make_empty_template(Component.types) |
| 551 |
yield self.compat or make_empty_template(Component.compat) |
| 552 |
yield self.symbols or make_empty_template(Component.symbols) |
| 553 |
|
| 554 |
def _generate_tests(self, compiler: XkbCompiler) -> Generator[Test]: |
| 555 |
groups = tuple( |
| 556 |
c.generate_tests(as_keymap=False, compiler=compiler) for c in self |
| 557 |
) |
| 558 |
keycodes: Test |
| 559 |
types: Test |
| 560 |
compat: Test |
| 561 |
symbols: Test |
| 562 |
for keycodes, types, compat, symbols in zip(*(g.tests for g in groups)): |
| 563 |
title = self.title + keycodes.title |
| 564 |
file = keycodes.file |
| 565 |
content = KeymapTemplate.substitute( |
| 566 |
keycodes=textwrap.indent(keycodes.content, INDENT), |
| 567 |
types=textwrap.indent(types.content, INDENT), |
| 568 |
compat=textwrap.indent(compat.content, INDENT), |
| 569 |
symbols=textwrap.indent(symbols.content, INDENT), |
| 570 |
) |
| 571 |
expected = KeymapTemplate.substitute( |
| 572 |
keycodes=textwrap.indent(keycodes.expected, INDENT), |
| 573 |
types=textwrap.indent(types.expected, INDENT), |
| 574 |
compat=textwrap.indent(compat.expected, INDENT), |
| 575 |
symbols=textwrap.indent(symbols.expected, INDENT), |
| 576 |
) |
| 577 |
yield Test(title=title, file=file, content=content, expected=expected) |
| 578 |
|
| 579 |
def generate_tests(self, compiler: XkbCompiler) -> TestGroup: |
| 580 |
return TestGroup(self.title, tuple(self._generate_tests(compiler))) |
| 581 |
|
| 582 |
def _generate_data(self) -> Generator[Test]: |
| 583 |
for component in self: |
| 584 |
yield from component.generate_data().tests |
| 585 |
|
| 586 |
def generate_data(self) -> TestGroup: |
| 587 |
return TestGroup(self.title, tuple(self._generate_data())) |
| 588 |
|
| 589 |
@classmethod |
| 590 |
def write( |
| 591 |
cls, |
| 592 |
root: Path, |
| 593 |
jinja_env: jinja2.Environment, |
| 594 |
c_file: Path | None, |
| 595 |
xkb: bool, |
| 596 |
compiler: XkbCompiler, |
| 597 |
tests: Sequence[Self], |
| 598 |
debug: bool = False, |
| 599 |
): |
| 600 |
if c_file is not None and c_file.name: |
| 601 |
c_data = tuple(t.generate_tests(compiler) for t in tests) |
| 602 |
TestGroup.write_c( |
| 603 |
root=root, |
| 604 |
jinja_env=jinja_env, |
| 605 |
path=c_file, |
| 606 |
compiler=compiler, |
| 607 |
tests=c_data, |
| 608 |
) |
| 609 |
if xkb: |
| 610 |
xkb_data = tuple(t.generate_data() for t in tests) |
| 611 |
TestGroup.write_data(root=root, compiler=compiler, tests=xkb_data) |
| 612 |
|
| 613 |
|
| 614 |
################################################################################ |
| 615 |
# |
| 616 |
# Key types tests |
| 617 |
# |
| 618 |
################################################################################ |
| 619 |
|
| 620 |
TYPES_TESTS = ComponentTestTemplate( |
| 621 |
"Types", |
| 622 |
component=Component.types, |
| 623 |
base_template=ComponentTemplate( |
| 624 |
""" |
| 625 |
${mode}virtual_modifiers NumLock, LevelThree=none, LevelFive=Mod3; |
| 626 |
${mode}virtual_modifiers U1, U2, U3; |
| 627 |
// ${mode}virtual_modifiers U4, U5, U6; |
| 628 |
${mode}virtual_modifiers Z1=none, Z2=none, Z3=none; |
| 629 |
// ${mode}virtual_modifiers Z4=none, Z5=none, Z6=none; |
| 630 |
${mode}virtual_modifiers M1=0x1000, M2=0x2000, M3=0x3000; |
| 631 |
// ${mode}virtual_modifiers M4=0x4000, M5=0x5000, M6=0x6000; |
| 632 |
|
| 633 |
${mode}type "ONE_LEVEL" { |
| 634 |
modifiers = None; |
| 635 |
map[None] = Level1; |
| 636 |
level_name[Level1]= "Any"; |
| 637 |
}; |
| 638 |
|
| 639 |
${mode}type "TWO_LEVEL" { |
| 640 |
modifiers = Shift; |
| 641 |
map[Shift] = Level2; |
| 642 |
level_name[Level1] = "Base"; |
| 643 |
level_name[Level2] = "Shift"; |
| 644 |
}; |
| 645 |
|
| 646 |
${mode}type "ALPHABETIC" { |
| 647 |
modifiers = Shift+Lock; |
| 648 |
map[Shift] = Level2; |
| 649 |
map[Lock] = Level2; |
| 650 |
level_name[Level1] = "Base"; |
| 651 |
level_name[Level2] = "Caps"; |
| 652 |
}; |
| 653 |
|
| 654 |
${mode}type "KEYPAD" { |
| 655 |
modifiers = Shift+NumLock; |
| 656 |
map[None] = Level1; |
| 657 |
map[Shift] = Level2; |
| 658 |
map[NumLock] = Level2; |
| 659 |
map[Shift+NumLock] = Level1; |
| 660 |
level_name[Level1] = "Base"; |
| 661 |
level_name[Level2] = "Number"; |
| 662 |
}; |
| 663 |
|
| 664 |
${mode}type "FOUR_LEVEL" { |
| 665 |
modifiers = Shift+LevelThree; |
| 666 |
map[None] = Level1; |
| 667 |
map[Shift] = Level2; |
| 668 |
map[LevelThree] = Level3; |
| 669 |
map[Shift+LevelThree] = Level4; |
| 670 |
level_name[Level1] = "Base"; |
| 671 |
level_name[Level2] = "Shift"; |
| 672 |
level_name[Level3] = "Alt Base"; |
| 673 |
level_name[Level4] = "Shift Alt"; |
| 674 |
}; |
| 675 |
|
| 676 |
${mode}type "FOUR_LEVEL_ALPHABETIC" { |
| 677 |
modifiers = Shift+Lock+LevelThree; |
| 678 |
map[None] = Level1; |
| 679 |
map[Shift] = Level2; |
| 680 |
map[Lock] = Level2; |
| 681 |
map[LevelThree] = Level3; |
| 682 |
map[Shift+LevelThree] = Level4; |
| 683 |
map[Lock+LevelThree] = Level4; |
| 684 |
map[Lock+Shift+LevelThree] = Level3; |
| 685 |
level_name[Level1] = "Base"; |
| 686 |
level_name[Level2] = "Shift"; |
| 687 |
level_name[Level3] = "Alt Base"; |
| 688 |
level_name[Level4] = "Shift Alt"; |
| 689 |
}; |
| 690 |
|
| 691 |
${mode}type "FOUR_LEVEL_SEMIALPHABETIC" { |
| 692 |
modifiers = Shift+Lock+LevelThree; |
| 693 |
map[None] = Level1; |
| 694 |
map[Shift] = Level2; |
| 695 |
map[Lock] = Level2; |
| 696 |
map[LevelThree] = Level3; |
| 697 |
map[Shift+LevelThree] = Level4; |
| 698 |
map[Lock+LevelThree] = Level3; |
| 699 |
map[Lock+Shift+LevelThree] = Level4; |
| 700 |
preserve[Lock+LevelThree] = Lock; |
| 701 |
preserve[Lock+Shift+LevelThree] = Lock; |
| 702 |
level_name[Level1] = "Base"; |
| 703 |
level_name[Level2] = "Shift"; |
| 704 |
level_name[Level3] = "Alt Base"; |
| 705 |
level_name[Level4] = "Shift Alt"; |
| 706 |
}; |
| 707 |
|
| 708 |
${mode}type "XXX" { |
| 709 |
modifiers = Shift+Lock+LevelThree; |
| 710 |
map[None] = 1; |
| 711 |
map[Shift] = 2; |
| 712 |
map[Lock] = 2; |
| 713 |
map[LevelThree] = 3; |
| 714 |
level_name[1] = "1"; |
| 715 |
level_name[2] = "2"; |
| 716 |
level_name[3] = "3"; |
| 717 |
}; |
| 718 |
""" |
| 719 |
), |
| 720 |
update_template=ComponentTemplate( |
| 721 |
"""\ |
| 722 |
${mode}virtual_modifiers NumLock=Mod2; // Changed: now mapped |
| 723 |
${mode}virtual_modifiers LevelThree=Mod5; // Changed: altered mapping (from 0) |
| 724 |
${mode}virtual_modifiers LevelFive=Mod3; // Unhanged: same mapping |
| 725 |
|
| 726 |
${mode}virtual_modifiers U7, Z7=0, M7=0x700000; // Changed: new |
| 727 |
|
| 728 |
${mode}virtual_modifiers U1; // Unchanged (unmapped) |
| 729 |
${mode}virtual_modifiers U2 = none; // Changed: now mapped |
| 730 |
${mode}virtual_modifiers U3 = 0x300000; // Changed: now mapped |
| 731 |
// ${mode}virtual_modifiers U4; // Unchanged (unmapped) |
| 732 |
// ${mode}virtual_modifiers U5 = none; // Changed: now mapped |
| 733 |
// ${mode}virtual_modifiers U6 = 0x600000; // Changed: now mapped |
| 734 |
${mode}virtual_modifiers Z1; // Unchanged (= 0) |
| 735 |
${mode}virtual_modifiers Z2 = none; // Unchanged (same mapping) |
| 736 |
${mode}virtual_modifiers Z3 = 0x310000; // Changed: altered mapping (from 0) |
| 737 |
// ${mode}virtual_modifiers Z4; // Unchanged (= 0) |
| 738 |
// ${mode}virtual_modifiers Z5 = none; // Unchanged (same mapping) |
| 739 |
// ${mode}virtual_modifiers Z6 = 0x610000; // Changed: altered mapping (from 0) |
| 740 |
${mode}virtual_modifiers M1; // Unchanged (≠ 0) |
| 741 |
${mode}virtual_modifiers M2 = none; // Changed: reset |
| 742 |
${mode}virtual_modifiers M3 = 0x320000; // Changed: altered mapping (from ≠ 0) |
| 743 |
// ${mode}virtual_modifiers M4; // Unchanged (≠ 0) |
| 744 |
// ${mode}virtual_modifiers M5 = none; // Changed: reset |
| 745 |
// ${mode}virtual_modifiers M6 = 0x620000; // Changed: altered mapping (from ≠ 0) |
| 746 |
|
| 747 |
${mode}type "ONE_LEVEL" { |
| 748 |
modifiers = None; |
| 749 |
map[None] = Level1; |
| 750 |
level_name[Level1]= "New"; // Change name |
| 751 |
}; |
| 752 |
|
| 753 |
${mode}type "TWO_LEVEL" { |
| 754 |
modifiers = Shift+M1; // Changed |
| 755 |
map[Shift] = Level2; |
| 756 |
map[M1] = Level2; // Changed |
| 757 |
level_name[Level1] = "Base"; |
| 758 |
level_name[Level2] = "Shift"; |
| 759 |
}; |
| 760 |
|
| 761 |
${mode}type "ALPHABETIC" { |
| 762 |
modifiers = Lock; // Changed |
| 763 |
map[None] = Level2; // Changed |
| 764 |
map[Lock] = Level1; // Changed |
| 765 |
level_name[Level1] = "Base"; |
| 766 |
level_name[Level2] = "Caps"; |
| 767 |
}; |
| 768 |
|
| 769 |
${mode}type "KEYPAD" { |
| 770 |
modifiers = Shift+NumLock; |
| 771 |
map[None] = Level1; |
| 772 |
map[Shift] = Level2; // Changed |
| 773 |
map[NumLock] = Level2; |
| 774 |
map[Shift+NumLock] = Level1; |
| 775 |
level_name[Level1] = "Base"; |
| 776 |
level_name[Level2] = "Number"; |
| 777 |
}; |
| 778 |
|
| 779 |
// Unchanged |
| 780 |
${mode}type "FOUR_LEVEL" { |
| 781 |
modifiers = Shift+LevelThree; |
| 782 |
map[None] = Level1; |
| 783 |
map[Shift] = Level2; |
| 784 |
map[LevelThree] = Level3; |
| 785 |
map[Shift+LevelThree] = Level4; |
| 786 |
level_name[Level1] = "Base"; |
| 787 |
level_name[Level2] = "Shift"; |
| 788 |
level_name[Level3] = "Alt Base"; |
| 789 |
level_name[Level4] = "Shift Alt"; |
| 790 |
}; |
| 791 |
|
| 792 |
${mode}type "FOUR_LEVEL_ALPHABETIC" { |
| 793 |
modifiers = Shift+Lock+LevelThree; |
| 794 |
map[None] = Level1; |
| 795 |
map[Shift] = Level2; |
| 796 |
map[Lock] = Level2; |
| 797 |
map[LevelThree] = Level3; |
| 798 |
map[Shift+LevelThree] = Level4; |
| 799 |
map[Lock+LevelThree] = Level4; |
| 800 |
map[Lock+Shift+LevelThree] = Level3; |
| 801 |
level_name[Level1] = "Base"; |
| 802 |
level_name[Level2] = "Shift"; |
| 803 |
level_name[Level3] = "Alt Base"; |
| 804 |
level_name[Level4] = "Shift Alt"; |
| 805 |
}; |
| 806 |
|
| 807 |
${mode}type "FOUR_LEVEL_SEMIALPHABETIC" { |
| 808 |
modifiers = Shift+Lock+LevelThree; |
| 809 |
map[None] = Level1; |
| 810 |
map[Shift] = Level2; |
| 811 |
map[Lock] = Level2; |
| 812 |
map[LevelThree] = Level3; |
| 813 |
map[Shift+LevelThree] = Level4; |
| 814 |
map[Lock+LevelThree] = Level3; |
| 815 |
map[Lock+Shift+LevelThree] = Level4; |
| 816 |
preserve[Lock+LevelThree] = Lock; |
| 817 |
preserve[Lock+Shift+LevelThree] = Lock; |
| 818 |
level_name[Level1] = "Base"; |
| 819 |
level_name[Level2] = "Shift"; |
| 820 |
level_name[Level3] = "Alt Base"; |
| 821 |
level_name[Level4] = "Shift Alt"; |
| 822 |
}; |
| 823 |
|
| 824 |
${mode}type "XXX" { |
| 825 |
modifiers = Shift+Lock+LevelThree; |
| 826 |
map[None] = 1; |
| 827 |
map[Shift] = 2; |
| 828 |
// map[Lock] = 2; // Changed |
| 829 |
// map[LevelThree] = 3; |
| 830 |
map[LevelThree] = 1; // Changed |
| 831 |
map[Shift+LevelThree] = 4; // Changed |
| 832 |
level_name[1] = "A"; // Changed |
| 833 |
level_name[2] = "2"; |
| 834 |
level_name[3] = "3"; |
| 835 |
level_name[4] = "4"; // Changed |
| 836 |
}; |
| 837 |
|
| 838 |
// New |
| 839 |
${mode}type "YYY" { |
| 840 |
modifiers = None; |
| 841 |
map[None] = Level1; |
| 842 |
level_name[Level1]= "New"; |
| 843 |
}; |
| 844 |
""" |
| 845 |
), |
| 846 |
augment=""" |
| 847 |
virtual_modifiers NumLock=Mod2,LevelThree=none,LevelFive=Mod3; |
| 848 |
|
| 849 |
virtual_modifiers U1,U2=0,U3=0x300000; |
| 850 |
// virtual_modifiers U4,U5=0,U6=0x600000; |
| 851 |
virtual_modifiers Z1=0,Z2=0,Z3=0; |
| 852 |
// virtual_modifiers Z4=0,Z5=0,Z6=0; |
| 853 |
virtual_modifiers M1=0x1000,M2=0x2000,M3=0x3000; |
| 854 |
// virtual_modifiers M4=0x4000,M5=0x5000,M6=0x6000; |
| 855 |
virtual_modifiers U7,Z7=0,M7=0x700000; |
| 856 |
|
| 857 |
type "ONE_LEVEL" { |
| 858 |
modifiers= none; |
| 859 |
map[none]= 1; |
| 860 |
level_name[1]= "Any"; |
| 861 |
}; |
| 862 |
type "TWO_LEVEL" { |
| 863 |
modifiers= Shift; |
| 864 |
map[Shift]= 2; |
| 865 |
level_name[1]= "Base"; |
| 866 |
level_name[2]= "Shift"; |
| 867 |
}; |
| 868 |
type "ALPHABETIC" { |
| 869 |
modifiers= Shift+Lock; |
| 870 |
map[Shift]= 2; |
| 871 |
map[Lock]= 2; |
| 872 |
level_name[1]= "Base"; |
| 873 |
level_name[2]= "Caps"; |
| 874 |
}; |
| 875 |
type "KEYPAD" { |
| 876 |
modifiers= Shift+NumLock; |
| 877 |
map[Shift]= 2; |
| 878 |
map[NumLock]= 2; |
| 879 |
level_name[1]= "Base"; |
| 880 |
level_name[2]= "Number"; |
| 881 |
}; |
| 882 |
type "FOUR_LEVEL" { |
| 883 |
modifiers= Shift+LevelThree; |
| 884 |
map[none]= 1; |
| 885 |
map[Shift]= 2; |
| 886 |
map[LevelThree]= 3; |
| 887 |
map[Shift+LevelThree]= 4; |
| 888 |
level_name[1]= "Base"; |
| 889 |
level_name[2]= "Shift"; |
| 890 |
level_name[3]= "Alt Base"; |
| 891 |
level_name[4]= "Shift Alt"; |
| 892 |
}; |
| 893 |
type "FOUR_LEVEL_ALPHABETIC" { |
| 894 |
modifiers= Shift+Lock+LevelThree; |
| 895 |
map[none]= 1; |
| 896 |
map[Shift]= 2; |
| 897 |
map[Lock]= 2; |
| 898 |
map[LevelThree]= 3; |
| 899 |
map[Shift+LevelThree]= 4; |
| 900 |
map[Lock+LevelThree]= 4; |
| 901 |
map[Shift+Lock+LevelThree]= 3; |
| 902 |
level_name[1]= "Base"; |
| 903 |
level_name[2]= "Shift"; |
| 904 |
level_name[3]= "Alt Base"; |
| 905 |
level_name[4]= "Shift Alt"; |
| 906 |
}; |
| 907 |
type "FOUR_LEVEL_SEMIALPHABETIC" { |
| 908 |
modifiers= Shift+Lock+LevelThree; |
| 909 |
map[None]= 1; |
| 910 |
map[Shift]= 2; |
| 911 |
map[Lock]= 2; |
| 912 |
map[LevelThree]= 3; |
| 913 |
map[Shift+LevelThree]= 4; |
| 914 |
map[Lock+LevelThree]= 3; |
| 915 |
preserve[Lock+LevelThree]= Lock; |
| 916 |
map[Shift+Lock+LevelThree]= 4; |
| 917 |
preserve[Shift+Lock+LevelThree]= Lock; |
| 918 |
level_name[1]= "Base"; |
| 919 |
level_name[2]= "Shift"; |
| 920 |
level_name[3]= "Alt Base"; |
| 921 |
level_name[4]= "Shift Alt"; |
| 922 |
}; |
| 923 |
type "XXX" { |
| 924 |
modifiers = Shift+Lock+LevelThree; |
| 925 |
map[None] = 1; |
| 926 |
map[Shift] = 2; |
| 927 |
map[Lock] = 2; |
| 928 |
map[LevelThree] = 3; |
| 929 |
level_name[1] = "1"; |
| 930 |
level_name[2] = "2"; |
| 931 |
level_name[3] = "3"; |
| 932 |
}; |
| 933 |
type "YYY" { |
| 934 |
modifiers = None; |
| 935 |
map[None] = Level1; |
| 936 |
level_name[Level1]= "New"; |
| 937 |
}; |
| 938 |
""", |
| 939 |
override=""" |
| 940 |
virtual_modifiers NumLock=Mod2,LevelThree=Mod5,LevelFive=Mod3; |
| 941 |
|
| 942 |
virtual_modifiers U1,U2=0,U3=0x300000; |
| 943 |
// virtual_modifiers U4,U5=0,U6=0x600000; |
| 944 |
virtual_modifiers Z1=0,Z2=0,Z3=0x310000; |
| 945 |
// virtual_modifiers Z4=0,Z5=0,Z6=0x610000; |
| 946 |
virtual_modifiers M1=0x1000,M2=0,M3=0x320000; |
| 947 |
// virtual_modifiers M4=0x4000,M5=0,M6=0x620000; |
| 948 |
virtual_modifiers U7,Z7=0,M7=0x700000; |
| 949 |
|
| 950 |
type "ONE_LEVEL" { |
| 951 |
modifiers= none; |
| 952 |
map[None] = Level1; |
| 953 |
level_name[1]= "New"; |
| 954 |
}; |
| 955 |
type "TWO_LEVEL" { |
| 956 |
modifiers= Shift+M1; |
| 957 |
map[Shift]= 2; |
| 958 |
map[M1]= 2; |
| 959 |
level_name[1]= "Base"; |
| 960 |
level_name[2]= "Shift"; |
| 961 |
}; |
| 962 |
type "ALPHABETIC" { |
| 963 |
modifiers= Lock; |
| 964 |
map[none]= 2; |
| 965 |
map[Lock]= 1; |
| 966 |
level_name[1]= "Base"; |
| 967 |
level_name[2]= "Caps"; |
| 968 |
}; |
| 969 |
type "KEYPAD" { |
| 970 |
modifiers= Shift+NumLock; |
| 971 |
map[Shift] = Level2; |
| 972 |
map[NumLock]= 2; |
| 973 |
level_name[1]= "Base"; |
| 974 |
level_name[2]= "Number"; |
| 975 |
}; |
| 976 |
type "FOUR_LEVEL" { |
| 977 |
modifiers= Shift+LevelThree; |
| 978 |
map[None]= 1; |
| 979 |
map[Shift]= 2; |
| 980 |
map[LevelThree]= 3; |
| 981 |
map[Shift+LevelThree] = Level4; |
| 982 |
level_name[1]= "Base"; |
| 983 |
level_name[2]= "Shift"; |
| 984 |
level_name[3]= "Alt Base"; |
| 985 |
level_name[4]= "Shift Alt"; |
| 986 |
}; |
| 987 |
type "FOUR_LEVEL_ALPHABETIC" { |
| 988 |
modifiers= Shift+Lock+LevelThree; |
| 989 |
map[Shift]= 2; |
| 990 |
map[Lock]= 2; |
| 991 |
map[LevelThree]= 3; |
| 992 |
map[Shift+LevelThree]= 4; |
| 993 |
map[Lock+LevelThree]= 4; |
| 994 |
map[Shift+Lock+LevelThree]= 3; |
| 995 |
level_name[1]= "Base"; |
| 996 |
level_name[2]= "Shift"; |
| 997 |
level_name[3]= "Alt Base"; |
| 998 |
level_name[4]= "Shift Alt"; |
| 999 |
}; |
| 1000 |
type "FOUR_LEVEL_SEMIALPHABETIC" { |
| 1001 |
modifiers= Shift+Lock+LevelThree; |
| 1002 |
map[None]= 1; |
| 1003 |
map[Shift]= 2; |
| 1004 |
map[Lock]= 2; |
| 1005 |
map[LevelThree]= 3; |
| 1006 |
map[Shift+LevelThree]= 4; |
| 1007 |
map[Lock+LevelThree]= 3; |
| 1008 |
preserve[Lock+LevelThree]= Lock; |
| 1009 |
map[Shift+Lock+LevelThree]= 4; |
| 1010 |
preserve[Shift+Lock+LevelThree]= Lock; |
| 1011 |
level_name[1]= "Base"; |
| 1012 |
level_name[2]= "Shift"; |
| 1013 |
level_name[3]= "Alt Base"; |
| 1014 |
level_name[4]= "Shift Alt"; |
| 1015 |
}; |
| 1016 |
type "XXX" { |
| 1017 |
modifiers = Shift+Lock+LevelThree; |
| 1018 |
map[None] = 1; |
| 1019 |
map[Shift] = 2; |
| 1020 |
// map[LevelThree] = 3; |
| 1021 |
map[LevelThree] = 1; |
| 1022 |
map[Shift+LevelThree] = 4; |
| 1023 |
level_name[1] = "A"; |
| 1024 |
level_name[2] = "2"; |
| 1025 |
level_name[3] = "3"; |
| 1026 |
level_name[4] = "4"; |
| 1027 |
}; |
| 1028 |
type "YYY" { |
| 1029 |
modifiers = None; |
| 1030 |
map[None] = Level1; |
| 1031 |
level_name[Level1]= "New"; |
| 1032 |
}; |
| 1033 |
""", |
| 1034 |
) |
| 1035 |
|
| 1036 |
|
| 1037 |
################################################################################ |
| 1038 |
# |
| 1039 |
# Compat tests |
| 1040 |
# |
| 1041 |
################################################################################ |
| 1042 |
|
| 1043 |
COMPAT_TESTS = ComponentTestTemplate( |
| 1044 |
"Compat", |
| 1045 |
component=Component.compat, |
| 1046 |
base_template=ComponentTemplate( |
| 1047 |
""" |
| 1048 |
${mode}virtual_modifiers NumLock; |
| 1049 |
|
| 1050 |
interpret.repeat= False; |
| 1051 |
setMods.clearLocks= True; |
| 1052 |
latchMods.clearLocks= True; |
| 1053 |
latchMods.latchToLock= True; |
| 1054 |
|
| 1055 |
${mode}interpret Any + Any { |
| 1056 |
action= SetMods(modifiers=modMapMods); |
| 1057 |
}; |
| 1058 |
|
| 1059 |
${mode}interpret Caps_Lock { |
| 1060 |
action = LockMods(modifiers = Lock); |
| 1061 |
}; |
| 1062 |
|
| 1063 |
${mode}indicator "Caps Lock" { |
| 1064 |
!allowExplicit; |
| 1065 |
whichModState= Locked; |
| 1066 |
modifiers= Lock; |
| 1067 |
}; |
| 1068 |
|
| 1069 |
${mode}indicator "Num Lock" { |
| 1070 |
!allowExplicit; |
| 1071 |
whichModState= Locked; |
| 1072 |
modifiers= NumLock; |
| 1073 |
}; |
| 1074 |
""" |
| 1075 |
), |
| 1076 |
update_template=ComponentTemplate( |
| 1077 |
""" |
| 1078 |
${mode}virtual_modifiers NumLock; |
| 1079 |
|
| 1080 |
${mode}interpret.repeat= False; |
| 1081 |
${mode}setMods.clearLocks= False; // Changed |
| 1082 |
|
| 1083 |
// Unchanged |
| 1084 |
${mode}interpret Any + Any { |
| 1085 |
action= SetMods(modifiers=modMapMods); |
| 1086 |
}; |
| 1087 |
|
| 1088 |
// Changed |
| 1089 |
${mode}interpret Caps_Lock { |
| 1090 |
action = LockMods(modifiers = NumLock); |
| 1091 |
}; |
| 1092 |
|
| 1093 |
// Unchanged |
| 1094 |
${mode}indicator "Caps Lock" { |
| 1095 |
!allowExplicit; |
| 1096 |
whichModState= Locked; |
| 1097 |
modifiers= Lock; |
| 1098 |
}; |
| 1099 |
|
| 1100 |
// Changed |
| 1101 |
${mode}indicator "Num Lock" { |
| 1102 |
!allowExplicit; |
| 1103 |
whichModState= Base; |
| 1104 |
modifiers= Lock; |
| 1105 |
}; |
| 1106 |
|
| 1107 |
// New |
| 1108 |
${mode}indicator "Kana" { |
| 1109 |
!allowExplicit; |
| 1110 |
whichModState= Locked; |
| 1111 |
modifiers= Control; |
| 1112 |
}; |
| 1113 |
""" |
| 1114 |
), |
| 1115 |
augment=""" |
| 1116 |
virtual_modifiers NumLock; |
| 1117 |
|
| 1118 |
interpret.useModMapMods= AnyLevel; |
| 1119 |
interpret.repeat= False; |
| 1120 |
interpret Caps_Lock+AnyOfOrNone(all) { |
| 1121 |
action= LockMods(modifiers=Lock); |
| 1122 |
}; |
| 1123 |
interpret Any+AnyOf(all) { |
| 1124 |
action= SetMods(modifiers=modMapMods,clearLocks); |
| 1125 |
}; |
| 1126 |
indicator "Caps Lock" { |
| 1127 |
whichModState= locked; |
| 1128 |
modifiers= Lock; |
| 1129 |
}; |
| 1130 |
indicator "Num Lock" { |
| 1131 |
whichModState= locked; |
| 1132 |
modifiers= NumLock; |
| 1133 |
}; |
| 1134 |
indicator "Kana" { |
| 1135 |
whichModState= locked; |
| 1136 |
modifiers= Control; |
| 1137 |
}; |
| 1138 |
""", |
| 1139 |
override=""" |
| 1140 |
virtual_modifiers NumLock; |
| 1141 |
|
| 1142 |
interpret.repeat= False; |
| 1143 |
setMods.clearLocks= False; |
| 1144 |
interpret Caps_Lock+AnyOfOrNone(all) { |
| 1145 |
action= LockMods(modifiers=NumLock); |
| 1146 |
}; |
| 1147 |
interpret Any+AnyOf(all) { |
| 1148 |
action= SetMods(modifiers=modMapMods); |
| 1149 |
}; |
| 1150 |
indicator "Caps Lock" { |
| 1151 |
whichModState= locked; |
| 1152 |
modifiers= Lock; |
| 1153 |
}; |
| 1154 |
indicator "Kana" { |
| 1155 |
whichModState= locked; |
| 1156 |
modifiers= Control; |
| 1157 |
}; |
| 1158 |
indicator "Num Lock" { |
| 1159 |
whichModState= base; |
| 1160 |
modifiers= Lock; |
| 1161 |
}; |
| 1162 |
""", |
| 1163 |
) |
| 1164 |
|
| 1165 |
|
| 1166 |
################################################################################ |
| 1167 |
# |
| 1168 |
# Symbols tests |
| 1169 |
# |
| 1170 |
################################################################################ |
| 1171 |
|
| 1172 |
|
| 1173 |
LINUX_EVENT_CODES = ( |
| 1174 |
None, |
| 1175 |
"ESC", |
| 1176 |
"1", |
| 1177 |
"2", |
| 1178 |
"3", |
| 1179 |
"4", |
| 1180 |
"5", |
| 1181 |
"6", |
| 1182 |
"7", |
| 1183 |
"8", |
| 1184 |
"9", |
| 1185 |
"0", |
| 1186 |
"MINUS", |
| 1187 |
"EQUAL", |
| 1188 |
"BACKSPACE", |
| 1189 |
"TAB", |
| 1190 |
"Q", |
| 1191 |
"W", |
| 1192 |
"E", |
| 1193 |
"R", |
| 1194 |
"T", |
| 1195 |
"Y", |
| 1196 |
"U", |
| 1197 |
"I", |
| 1198 |
"O", |
| 1199 |
"P", |
| 1200 |
"LEFTBRACE", |
| 1201 |
"RIGHTBRACE", |
| 1202 |
"ENTER", |
| 1203 |
"LEFTCTRL", |
| 1204 |
"A", |
| 1205 |
"S", |
| 1206 |
"D", |
| 1207 |
"F", |
| 1208 |
"G", |
| 1209 |
"H", |
| 1210 |
"J", |
| 1211 |
"K", |
| 1212 |
"L", |
| 1213 |
"SEMICOLON", |
| 1214 |
"APOSTROPHE", |
| 1215 |
"GRAVE", |
| 1216 |
"LEFTSHIFT", |
| 1217 |
"BACKSLASH", |
| 1218 |
"Z", |
| 1219 |
"X", |
| 1220 |
"C", |
| 1221 |
"V", |
| 1222 |
"B", |
| 1223 |
"N", |
| 1224 |
"M", |
| 1225 |
"COMMA", |
| 1226 |
"DOT", |
| 1227 |
"SLASH", |
| 1228 |
"RIGHTSHIFT", |
| 1229 |
"KPASTERISK", |
| 1230 |
"LEFTALT", |
| 1231 |
"SPACE", |
| 1232 |
"CAPSLOCK", |
| 1233 |
"F1", |
| 1234 |
"F2", |
| 1235 |
"F3", |
| 1236 |
"F4", |
| 1237 |
"F5", |
| 1238 |
"F6", |
| 1239 |
"F7", |
| 1240 |
"F8", |
| 1241 |
"F9", |
| 1242 |
"F10", |
| 1243 |
"NUMLOCK", |
| 1244 |
"SCROLLLOCK", |
| 1245 |
"KP7", |
| 1246 |
"KP8", |
| 1247 |
"KP9", |
| 1248 |
"KPMINUS", |
| 1249 |
"KP4", |
| 1250 |
"KP5", |
| 1251 |
"KP6", |
| 1252 |
"KPPLUS", |
| 1253 |
"KP1", |
| 1254 |
"KP2", |
| 1255 |
"KP3", |
| 1256 |
"KP0", |
| 1257 |
"KPDOT", |
| 1258 |
None, |
| 1259 |
"ZENKAKUHANKAKU", |
| 1260 |
"102ND", |
| 1261 |
"F11", |
| 1262 |
"F12", |
| 1263 |
"RO", |
| 1264 |
"KATAKANA", |
| 1265 |
"HIRAGANA", |
| 1266 |
"HENKAN", |
| 1267 |
"KATAKANAHIRAGANA", |
| 1268 |
"MUHENKAN", |
| 1269 |
"KPJPCOMMA", |
| 1270 |
"KPENTER", |
| 1271 |
"RIGHTCTRL", |
| 1272 |
"KPSLASH", |
| 1273 |
"SYSRQ", |
| 1274 |
"RIGHTALT", |
| 1275 |
"LINEFEED", |
| 1276 |
"HOME", |
| 1277 |
"UP", |
| 1278 |
"PAGEUP", |
| 1279 |
"LEFT", |
| 1280 |
"RIGHT", |
| 1281 |
"END", |
| 1282 |
"DOWN", |
| 1283 |
"PAGEDOWN", |
| 1284 |
"INSERT", |
| 1285 |
"DELETE", |
| 1286 |
"MACRO", |
| 1287 |
"MUTE", |
| 1288 |
"VOLUMEDOWN", |
| 1289 |
"VOLUMEUP", |
| 1290 |
"POWER", |
| 1291 |
"KPEQUAL", |
| 1292 |
"KPPLUSMINUS", |
| 1293 |
"PAUSE", |
| 1294 |
"SCALE", |
| 1295 |
"KPCOMMA", |
| 1296 |
"HANGEUL", |
| 1297 |
"HANJA", |
| 1298 |
"YEN", |
| 1299 |
"LEFTMETA", |
| 1300 |
"RIGHTMETA", |
| 1301 |
"COMPOSE", |
| 1302 |
"STOP", |
| 1303 |
"AGAIN", |
| 1304 |
"PROPS", |
| 1305 |
"UNDO", |
| 1306 |
"FRONT", |
| 1307 |
"COPY", |
| 1308 |
"OPEN", |
| 1309 |
"PASTE", |
| 1310 |
"FIND", |
| 1311 |
"CUT", |
| 1312 |
"HELP", |
| 1313 |
"MENU", |
| 1314 |
"CALC", |
| 1315 |
"SETUP", |
| 1316 |
"SLEEP", |
| 1317 |
"WAKEUP", |
| 1318 |
"FILE", |
| 1319 |
"SENDFILE", |
| 1320 |
"DELETEFILE", |
| 1321 |
"XFER", |
| 1322 |
"PROG1", |
| 1323 |
"PROG2", |
| 1324 |
"WWW", |
| 1325 |
"MSDOS", |
| 1326 |
"COFFEE", |
| 1327 |
"DIRECTION", |
| 1328 |
"CYCLEWINDOWS", |
| 1329 |
"MAIL", |
| 1330 |
"BOOKMARKS", |
| 1331 |
"COMPUTER", |
| 1332 |
"BACK", |
| 1333 |
"FORWARD", |
| 1334 |
"CLOSECD", |
| 1335 |
"EJECTCD", |
| 1336 |
"EJECTCLOSECD", |
| 1337 |
"NEXTSONG", |
| 1338 |
"PLAYPAUSE", |
| 1339 |
"PREVIOUSSONG", |
| 1340 |
"STOPCD", |
| 1341 |
"RECORD", |
| 1342 |
"REWIND", |
| 1343 |
"PHONE", |
| 1344 |
"ISO", |
| 1345 |
"CONFIG", |
| 1346 |
"HOMEPAGE", |
| 1347 |
"REFRESH", |
| 1348 |
"EXIT", |
| 1349 |
"MOVE", |
| 1350 |
"EDIT", |
| 1351 |
"SCROLLUP", |
| 1352 |
"SCROLLDOWN", |
| 1353 |
"KPLEFTPAREN", |
| 1354 |
"KPRIGHTPAREN", |
| 1355 |
"NEW", |
| 1356 |
"REDO", |
| 1357 |
"F13", |
| 1358 |
"F14", |
| 1359 |
"F15", |
| 1360 |
"F16", |
| 1361 |
"F17", |
| 1362 |
"F18", |
| 1363 |
"F19", |
| 1364 |
"F20", |
| 1365 |
"F21", |
| 1366 |
"F22", |
| 1367 |
"F23", |
| 1368 |
"F24", |
| 1369 |
None, |
| 1370 |
None, |
| 1371 |
None, |
| 1372 |
None, |
| 1373 |
None, |
| 1374 |
"PLAYCD", |
| 1375 |
"PAUSECD", |
| 1376 |
"PROG3", |
| 1377 |
"PROG4", |
| 1378 |
"DASHBOARD", |
| 1379 |
"SUSPEND", |
| 1380 |
"CLOSE", |
| 1381 |
"PLAY", |
| 1382 |
"FASTFORWARD", |
| 1383 |
"BASSBOOST", |
| 1384 |
"PRINT", |
| 1385 |
"HP", |
| 1386 |
"CAMERA", |
| 1387 |
"SOUND", |
| 1388 |
"QUESTION", |
| 1389 |
) |
| 1390 |
|
| 1391 |
Comment = NewType("Comment", str) |
| 1392 |
|
| 1393 |
|
| 1394 |
@dataclass(frozen=True) |
| 1395 |
class KeyCode: |
| 1396 |
_evdev: str |
| 1397 |
_xkb: str |
| 1398 |
|
| 1399 |
@property |
| 1400 |
def c(self) -> str: |
| 1401 |
return f"KEY_{self._evdev}" |
| 1402 |
|
| 1403 |
@property |
| 1404 |
def xkb(self) -> str: |
| 1405 |
return f"<{self._xkb}>" |
| 1406 |
|
| 1407 |
|
| 1408 |
class Keysym(str): |
| 1409 |
@property |
| 1410 |
def c(self) -> str: |
| 1411 |
return f"XKB_KEY_{self}" |
| 1412 |
|
| 1413 |
@classmethod |
| 1414 |
def parse(cls, raw: str | None) -> Self: |
| 1415 |
if not raw: |
| 1416 |
return cls("NoSymbol") |
| 1417 |
else: |
| 1418 |
return cls(raw) |
| 1419 |
|
| 1420 |
|
| 1421 |
NoSymbol = Keysym("NoSymbol") |
| 1422 |
|
| 1423 |
|
| 1424 |
class Modifier(IntFlag): |
| 1425 |
NoModifier = 0 |
| 1426 |
Shift = 1 << 0 |
| 1427 |
Lock = 1 << 1 |
| 1428 |
Control = 1 << 2 |
| 1429 |
Mod1 = 1 << 3 |
| 1430 |
Mod2 = 1 << 4 |
| 1431 |
Mod3 = 1 << 5 |
| 1432 |
Mod4 = 1 << 6 |
| 1433 |
Mod5 = 1 << 7 |
| 1434 |
LevelThree = Mod5 |
| 1435 |
|
| 1436 |
def __iter__(self) -> Iterator[Self]: |
| 1437 |
for m in self.__class__: |
| 1438 |
if m & self: |
| 1439 |
yield m |
| 1440 |
|
| 1441 |
def __str__(self) -> str: |
| 1442 |
return "+".join(m.name for m in self) |
| 1443 |
|
| 1444 |
|
| 1445 |
class Action(metaclass=ABCMeta): |
| 1446 |
@abstractmethod |
| 1447 |
def __bool__(self) -> bool: ... |
| 1448 |
|
| 1449 |
@classmethod |
| 1450 |
def parse(cls, raw: Any) -> Self: |
| 1451 |
if raw is None: |
| 1452 |
return GroupAction.parse(None) |
| 1453 |
elif isinstance(raw, Modifier): |
| 1454 |
return ModAction.parse(raw) |
| 1455 |
elif isinstance(raw, int): |
| 1456 |
return GroupAction.parse(raw) |
| 1457 |
else: |
| 1458 |
raise ValueError(raw) |
| 1459 |
|
| 1460 |
@abstractmethod |
| 1461 |
def action_to_keysym(self, index: int, level: int) -> Keysym: ... |
| 1462 |
|
| 1463 |
|
| 1464 |
@dataclass |
| 1465 |
class GroupAction(Action): |
| 1466 |
""" |
| 1467 |
SetGroup or NoAction |
| 1468 |
""" |
| 1469 |
|
| 1470 |
group: int |
| 1471 |
keysyms: ClassVar[dict[tuple[int, int, int], Keysym]] = { |
| 1472 |
(2, 0, 0): Keysym("a"), |
| 1473 |
(2, 0, 1): Keysym("A"), |
| 1474 |
(2, 1, 0): Keysym("b"), |
| 1475 |
(2, 1, 1): Keysym("B"), |
| 1476 |
(3, 0, 0): Keysym("Greek_alpha"), |
| 1477 |
(3, 0, 1): Keysym("Greek_ALPHA"), |
| 1478 |
(3, 1, 0): Keysym("Greek_beta"), |
| 1479 |
(3, 1, 1): Keysym("Greek_BETA"), |
| 1480 |
} |
| 1481 |
|
| 1482 |
def __str__(self) -> str: |
| 1483 |
if self.group > 0: |
| 1484 |
return f"SetGroup(group={self.group})" |
| 1485 |
else: |
| 1486 |
return "NoAction()" |
| 1487 |
|
| 1488 |
def __bool__(self) -> bool: |
| 1489 |
return bool(self.group) |
| 1490 |
|
| 1491 |
@classmethod |
| 1492 |
def parse(cls, raw: int | None) -> Self: |
| 1493 |
if not raw: |
| 1494 |
return cls(0) |
| 1495 |
else: |
| 1496 |
return cls(raw) |
| 1497 |
|
| 1498 |
def action_to_keysym(self, index: int, level: int) -> Keysym: |
| 1499 |
if not self.group: |
| 1500 |
return NoSymbol |
| 1501 |
else: |
| 1502 |
if ( |
| 1503 |
keysym := self.keysyms.get((self.group % 4, index % 2, level % 2)) |
| 1504 |
) is None: |
| 1505 |
raise ValueError((self, index, level)) |
| 1506 |
return keysym |
| 1507 |
|
| 1508 |
|
| 1509 |
@dataclass |
| 1510 |
class ModAction(Action): |
| 1511 |
""" |
| 1512 |
SetMod or NoAction |
| 1513 |
""" |
| 1514 |
|
| 1515 |
mods: Modifier |
| 1516 |
keysyms: ClassVar[dict[tuple[Modifier, int, int], Keysym]] = { |
| 1517 |
(Modifier.Control, 0, 0): Keysym("x"), |
| 1518 |
(Modifier.Control, 0, 1): Keysym("X"), |
| 1519 |
(Modifier.Control, 1, 0): Keysym("y"), |
| 1520 |
(Modifier.Control, 1, 1): Keysym("Y"), |
| 1521 |
(Modifier.Mod5, 0, 0): Keysym("Greek_xi"), |
| 1522 |
(Modifier.Mod5, 0, 1): Keysym("Greek_XI"), |
| 1523 |
(Modifier.Mod5, 1, 0): Keysym("Greek_upsilon"), |
| 1524 |
(Modifier.Mod5, 1, 1): Keysym("Greek_UPSILON"), |
| 1525 |
} |
| 1526 |
|
| 1527 |
def __str__(self) -> str: |
| 1528 |
if self.mods is Modifier.NoModifier: |
| 1529 |
return "NoAction()" |
| 1530 |
else: |
| 1531 |
return f"SetMods(mods={self.mods})" |
| 1532 |
|
| 1533 |
def __bool__(self) -> bool: |
| 1534 |
return self.mods is Modifier.NoModifier |
| 1535 |
|
| 1536 |
@classmethod |
| 1537 |
def parse(cls, raw: Modifier | None) -> Self: |
| 1538 |
if not raw: |
| 1539 |
return cls(Modifier.NoModifier) |
| 1540 |
else: |
| 1541 |
return cls(raw) |
| 1542 |
|
| 1543 |
def action_to_keysym(self, index: int, level: int) -> Keysym: |
| 1544 |
if self.mods is Modifier.NoModifier: |
| 1545 |
return NoSymbol |
| 1546 |
else: |
| 1547 |
if (keysym := self.keysyms.get((self.mods, index % 2, level % 2))) is None: |
| 1548 |
raise ValueError((self, index, level)) |
| 1549 |
return keysym |
| 1550 |
|
| 1551 |
|
| 1552 |
@dataclass |
| 1553 |
class Level: |
| 1554 |
keysyms: tuple[Keysym, ...] |
| 1555 |
actions: tuple[Action, ...] |
| 1556 |
|
| 1557 |
@staticmethod |
| 1558 |
def _c(default: str, xs: Iterable[Any]) -> str: |
| 1559 |
match len(xs): |
| 1560 |
case 0: |
| 1561 |
return default |
| 1562 |
case 1: |
| 1563 |
return xs[0].c |
| 1564 |
case _: |
| 1565 |
return ", ".join(map(lambda x: x.c, xs)) |
| 1566 |
|
| 1567 |
@staticmethod |
| 1568 |
def _xkb(default: str, xs: Iterable[Any]) -> str: |
| 1569 |
match len(xs): |
| 1570 |
case 0: |
| 1571 |
return default |
| 1572 |
case 1: |
| 1573 |
return str(xs[0]) |
| 1574 |
case _: |
| 1575 |
return "{" + ", ".join(map(str, xs)) + "}" |
| 1576 |
|
| 1577 |
@classmethod |
| 1578 |
def has_empty_symbols(cls, keysyms: tuple[Keysym, ...]) -> bool: |
| 1579 |
return all(ks == NoSymbol for ks in keysyms) |
| 1580 |
|
| 1581 |
@property |
| 1582 |
def empty_symbols(self) -> bool: |
| 1583 |
return self.has_empty_symbols(self.keysyms) |
| 1584 |
|
| 1585 |
@property |
| 1586 |
def keysyms_c(self) -> str: |
| 1587 |
if not self.keysyms and self.actions: |
| 1588 |
return self._c( |
| 1589 |
NoSymbol.c, tuple(itertools.repeat(NoSymbol, len(self.actions))) |
| 1590 |
) |
| 1591 |
return self._c(NoSymbol.c, self.keysyms) |
| 1592 |
|
| 1593 |
@property |
| 1594 |
def keysyms_xkb(self) -> str: |
| 1595 |
return self._xkb(NoSymbol, self.keysyms) |
| 1596 |
|
| 1597 |
@classmethod |
| 1598 |
def has_empty_actions(cls, actions: tuple[Action, ...]) -> bool: |
| 1599 |
return not any(actions) |
| 1600 |
|
| 1601 |
@property |
| 1602 |
def empty_actions(self) -> bool: |
| 1603 |
return self.has_empty_actions(self.actions) |
| 1604 |
|
| 1605 |
@property |
| 1606 |
def actions_xkb(self) -> str: |
| 1607 |
return self._xkb("NoAction()", self.actions) |
| 1608 |
|
| 1609 |
@classmethod |
| 1610 |
def Keysyms(cls, *keysyms: str | None) -> Self: |
| 1611 |
return cls.Mix(keysyms, ()) |
| 1612 |
|
| 1613 |
@classmethod |
| 1614 |
def Actions(cls, *actions: int | Modifier | None) -> Self: |
| 1615 |
return cls.Mix((), actions) |
| 1616 |
|
| 1617 |
@classmethod |
| 1618 |
def Mix( |
| 1619 |
cls, keysyms: tuple[str | None, ...], actions: tuple[int | Modifier | None,] |
| 1620 |
) -> Self: |
| 1621 |
return cls(tuple(map(Keysym.parse, keysyms)), tuple(map(Action.parse, actions))) |
| 1622 |
|
| 1623 |
def add_keysyms(self, keep_actions: bool, level: int) -> Self: |
| 1624 |
return self.__class__( |
| 1625 |
keysyms=tuple( |
| 1626 |
a.action_to_keysym(index=k, level=level) |
| 1627 |
for k, a in enumerate(self.actions) |
| 1628 |
), |
| 1629 |
actions=self.actions if keep_actions else (), |
| 1630 |
) |
| 1631 |
|
| 1632 |
@property |
| 1633 |
def target_group(self) -> int: |
| 1634 |
for a in self.actions: |
| 1635 |
if isinstance(a, GroupAction) and a.group > 1: |
| 1636 |
return a.group |
| 1637 |
else: |
| 1638 |
return 0 |
| 1639 |
|
| 1640 |
@property |
| 1641 |
def target_level(self) -> int: |
| 1642 |
for a in self.actions: |
| 1643 |
if isinstance(a, ModAction) and a.mods: |
| 1644 |
match a.mods: |
| 1645 |
case Modifier.LevelThree: |
| 1646 |
return 2 |
| 1647 |
case _: |
| 1648 |
return 0 |
| 1649 |
else: |
| 1650 |
return 0 |
| 1651 |
|
| 1652 |
|
| 1653 |
@dataclass |
| 1654 |
class KeyEntry: |
| 1655 |
levels: tuple[Level, ...] |
| 1656 |
|
| 1657 |
def __init__(self, *levels: Level): |
| 1658 |
self.levels = levels |
| 1659 |
|
| 1660 |
@property |
| 1661 |
def xkb(self) -> Iterator[str]: |
| 1662 |
if not self.levels: |
| 1663 |
yield "" |
| 1664 |
return |
| 1665 |
keysyms = tuple(l.keysyms for l in self.levels) |
| 1666 |
has_keysyms = any(not Level.has_empty_symbols(s) for s in keysyms) |
| 1667 |
no_keysyms = all(not s for s in keysyms) |
| 1668 |
actions = tuple(l.actions for l in self.levels) |
| 1669 |
has_actions = any(not Level.has_empty_actions(a) for a in actions) |
| 1670 |
if has_keysyms or (not no_keysyms and not has_actions): |
| 1671 |
yield "[" |
| 1672 |
yield ", ".join(l.keysyms_xkb for l in self.levels) |
| 1673 |
yield "]" |
| 1674 |
if has_actions or no_keysyms: |
| 1675 |
if has_keysyms: |
| 1676 |
yield ", " |
| 1677 |
yield "[" |
| 1678 |
yield ", ".join(l.actions_xkb for l in self.levels) |
| 1679 |
yield "]" |
| 1680 |
|
| 1681 |
def add_keysyms(self, keep_actions: bool) -> Self: |
| 1682 |
return self.__class__( |
| 1683 |
*( |
| 1684 |
l.add_keysyms(keep_actions=keep_actions, level=k) |
| 1685 |
for k, l in enumerate(self.levels) |
| 1686 |
) |
| 1687 |
) |
| 1688 |
|
| 1689 |
|
| 1690 |
class TestType(IntFlag): |
| 1691 |
KeysymsOnly = auto() |
| 1692 |
ActionsOnly = auto() |
| 1693 |
KeysymsAndActions = auto() |
| 1694 |
All = ActionsOnly | KeysymsOnly | KeysymsAndActions |
| 1695 |
|
| 1696 |
|
| 1697 |
@dataclass |
| 1698 |
class TestId: |
| 1699 |
type: TestType |
| 1700 |
base: int = 0 |
| 1701 |
_last_base: ClassVar[int] = 0 |
| 1702 |
_max_type: ClassVar[int] = TestType.KeysymsAndActions >> 1 |
| 1703 |
_forbidden_keys: tuple[str, ...] = ("LEFTSHIFT", "RIGHTALT") |
| 1704 |
|
| 1705 |
def __post_init__(self): |
| 1706 |
if self.base == -1: |
| 1707 |
self.base = self.__class__._last_base |
| 1708 |
elif self.base < 0: |
| 1709 |
raise ValueError(self.base) |
| 1710 |
elif self.base == 0: |
| 1711 |
self.__class__._last_base += 1 |
| 1712 |
self.base = self.__class__._last_base |
| 1713 |
while not self.check_linux_keys(self._base_id): |
| 1714 |
self.__class__._last_base += 1 |
| 1715 |
self.base = self.__class__._last_base |
| 1716 |
else: |
| 1717 |
self.__class__._last_base = max(self.__class__._last_base, self.base) |
| 1718 |
assert self.linux_key, self |
| 1719 |
# print(self.base, self.id, self.xkb_key) |
| 1720 |
|
| 1721 |
def __hash__(self) -> int: |
| 1722 |
return self.id |
| 1723 |
|
| 1724 |
@property |
| 1725 |
def _base_id(self) -> int: |
| 1726 |
return (self.base - 1) * (self._max_type + 1) + 1 |
| 1727 |
|
| 1728 |
@property |
| 1729 |
def id(self) -> int: |
| 1730 |
# return (self.base << 2) | (self.type >> 1) |
| 1731 |
return self._base_id + (self.type >> 1) |
| 1732 |
|
| 1733 |
def with_type(self, type: TestType) -> Self: |
| 1734 |
return dataclasses.replace(self, type=type) |
| 1735 |
|
| 1736 |
@property |
| 1737 |
def xkb_key(self) -> str: |
| 1738 |
return f"T{self.id:0>3}" |
| 1739 |
|
| 1740 |
@classmethod |
| 1741 |
def check_linux_key(cls, idx: int) -> bool: |
| 1742 |
if idx >= len(LINUX_EVENT_CODES): |
| 1743 |
raise ValueError("Not enough Linux keys available!") |
| 1744 |
key: str | None = LINUX_EVENT_CODES[idx] |
| 1745 |
return bool(key) and key not in cls._forbidden_keys |
| 1746 |
|
| 1747 |
@classmethod |
| 1748 |
def check_linux_keys(cls, base_id) -> bool: |
| 1749 |
return all( |
| 1750 |
cls.check_linux_key(base_id + k) for k in range(0, cls._max_type + 1) |
| 1751 |
) |
| 1752 |
|
| 1753 |
@property |
| 1754 |
def linux_key(self) -> str: |
| 1755 |
if self.id >= len(LINUX_EVENT_CODES): |
| 1756 |
raise ValueError("Not enough Linux keys available!") |
| 1757 |
return LINUX_EVENT_CODES[self.id] |
| 1758 |
|
| 1759 |
@property |
| 1760 |
def key(self) -> KeyCode: |
| 1761 |
return KeyCode(self.linux_key, self.xkb_key) |
| 1762 |
|
| 1763 |
|
| 1764 |
@unique |
| 1765 |
class Implementation(Flag): |
| 1766 |
x11 = auto() |
| 1767 |
xkbcommon = auto() |
| 1768 |
all = x11 | xkbcommon |
| 1769 |
|
| 1770 |
|
| 1771 |
@dataclass |
| 1772 |
class TestEntry: |
| 1773 |
id: TestId |
| 1774 |
key: KeyCode = dataclasses.field(init=False) |
| 1775 |
base: KeyEntry |
| 1776 |
update: KeyEntry |
| 1777 |
augment: KeyEntry |
| 1778 |
override: KeyEntry |
| 1779 |
replace: KeyEntry |
| 1780 |
types: TestType |
| 1781 |
implementations: Implementation |
| 1782 |
|
| 1783 |
group_keysyms: ClassVar[tuple[tuple[str, str], ...]] = ( |
| 1784 |
("Ukrainian_i", "Ukrainian_I", "Ukrainian_yi", "Ukrainian_YI"), |
| 1785 |
("ch", "Ch", "c_h", "C_h"), |
| 1786 |
) |
| 1787 |
|
| 1788 |
def __init__( |
| 1789 |
self, |
| 1790 |
id: TestId | None, |
| 1791 |
base: KeyEntry, |
| 1792 |
update: KeyEntry, |
| 1793 |
augment: KeyEntry, |
| 1794 |
override: KeyEntry, |
| 1795 |
types: TestType = TestType.All, |
| 1796 |
replace: KeyEntry | None = None, |
| 1797 |
implementations: Implementation = Implementation.all, |
| 1798 |
): |
| 1799 |
self.id = TestId(0, 0) if id is None else id |
| 1800 |
self.key = id.key |
| 1801 |
self.base = base |
| 1802 |
self.update = update |
| 1803 |
self.augment = augment |
| 1804 |
self.override = override |
| 1805 |
self.types = types |
| 1806 |
self.replace = self.update if replace is None else replace |
| 1807 |
self.implementations = implementations |
| 1808 |
|
| 1809 |
@property |
| 1810 |
def default(self) -> KeyEntry: |
| 1811 |
return self.override |
| 1812 |
|
| 1813 |
def add_keysyms(self, keep_actions: bool) -> Self: |
| 1814 |
types = TestType.KeysymsAndActions if keep_actions else TestType.KeysymsOnly |
| 1815 |
return dataclasses.replace( |
| 1816 |
self, |
| 1817 |
id=self.id.with_type(types), |
| 1818 |
base=self.base.add_keysyms(keep_actions=keep_actions), |
| 1819 |
update=self.update.add_keysyms(keep_actions=keep_actions), |
| 1820 |
augment=self.augment.add_keysyms(keep_actions=keep_actions), |
| 1821 |
override=self.override.add_keysyms(keep_actions=keep_actions), |
| 1822 |
replace=self.replace.add_keysyms(keep_actions=keep_actions), |
| 1823 |
types=types, |
| 1824 |
) |
| 1825 |
|
| 1826 |
@classmethod |
| 1827 |
def alt_keysym(cls, group: int, level: int) -> Keysym: |
| 1828 |
return Keysym(cls.group_keysyms[group % 2][level % 4]) |
| 1829 |
|
| 1830 |
@classmethod |
| 1831 |
def alt_keysyms(cls, group: int) -> Iterator[Keysym]: |
| 1832 |
for keysym in cls.group_keysyms[group % 2]: |
| 1833 |
yield Keysym(keysym) |
| 1834 |
|
| 1835 |
|
| 1836 |
@dataclass |
| 1837 |
class SymbolsTestGroup: |
| 1838 |
name: str |
| 1839 |
tests: tuple[TestEntry | Comment, ...] |
| 1840 |
|
| 1841 |
def _with_implementation( |
| 1842 |
self, implementation: Implementation |
| 1843 |
) -> Iterable[TestEntry | Comment]: |
| 1844 |
pending_comment: Comment | None = None |
| 1845 |
for t in self.tests: |
| 1846 |
if not isinstance(t, TestEntry): |
| 1847 |
pending_comment = t |
| 1848 |
elif t.implementations & implementation: |
| 1849 |
if pending_comment is not None: |
| 1850 |
yield pending_comment |
| 1851 |
pending_comment = None |
| 1852 |
yield t |
| 1853 |
|
| 1854 |
def with_implementation(self, implementation: Implementation) -> Self: |
| 1855 |
return dataclasses.replace( |
| 1856 |
self, tests=tuple(self._with_implementation(implementation)) |
| 1857 |
) |
| 1858 |
|
| 1859 |
@staticmethod |
| 1860 |
def _add_keysyms(entry: TestEntry | Comment) -> Iterable[TestEntry | Comment]: |
| 1861 |
if isinstance(entry, TestEntry) and entry.id.type is TestType.ActionsOnly: |
| 1862 |
if entry.types & TestType.KeysymsOnly: |
| 1863 |
yield entry.add_keysyms(keep_actions=False) |
| 1864 |
yield entry |
| 1865 |
if entry.types & TestType.KeysymsAndActions: |
| 1866 |
yield entry.add_keysyms(keep_actions=True) |
| 1867 |
else: |
| 1868 |
yield entry |
| 1869 |
|
| 1870 |
def add_keysyms(self, name: str = "") -> Self: |
| 1871 |
return dataclasses.replace( |
| 1872 |
self, |
| 1873 |
name=name or self.name, |
| 1874 |
tests=tuple(t for ts in self.tests for t in self._add_keysyms(ts)), |
| 1875 |
) |
| 1876 |
|
| 1877 |
def __add__(self, other: Any) -> Self: |
| 1878 |
if isinstance(other, tuple): |
| 1879 |
return dataclasses.replace(self, tests=self.tests + other) |
| 1880 |
elif isinstance(other, self.__class__): |
| 1881 |
return dataclasses.replace(self, tests=self.tests + other.tests) |
| 1882 |
else: |
| 1883 |
return NotImplemented |
| 1884 |
|
| 1885 |
def get_keycodes(self, base: ComponentTestTemplate) -> ComponentTestTemplate: |
| 1886 |
ids: set[TestId] = set(t.id for t in self.tests if isinstance(t, TestEntry)) |
| 1887 |
|
| 1888 |
base_template = Template( |
| 1889 |
"\n".join(f"${{mode}}<{id.xkb_key}> = {id.id + 8};" for id in ids) + "\n" |
| 1890 |
) |
| 1891 |
keycodes = base_template.substitute(mode="") |
| 1892 |
|
| 1893 |
return dataclasses.replace( |
| 1894 |
base, |
| 1895 |
base_template=base_template + base.base_template, |
| 1896 |
update_template=base.update_template, |
| 1897 |
augment=keycodes + base.augment, |
| 1898 |
override=keycodes + base.override, |
| 1899 |
replace=keycodes + base.replace, |
| 1900 |
) |
| 1901 |
|
| 1902 |
def _get_symbols(self, type: str, debug: bool) -> Generator[str]: |
| 1903 |
for entry in self.tests: |
| 1904 |
if isinstance(entry, str): |
| 1905 |
if type == "update": |
| 1906 |
yield f"\n////// {entry} //////" |
| 1907 |
else: |
| 1908 |
data: KeyEntry = getattr(entry, type) |
| 1909 |
if debug: |
| 1910 |
yield f"// base: {''.join(entry.base.xkb) or '(empty)'}" |
| 1911 |
yield "// key to merge / replace result" |
| 1912 |
yield f"${{mode}}key {entry.key.xkb} {{ {''.join(data.xkb)} }};" |
| 1913 |
if debug: |
| 1914 |
yield f"// override: {''.join(entry.override.xkb) or '(empty)'}" |
| 1915 |
yield f"// augment: {''.join(entry.augment.xkb) or '(empty)'}" |
| 1916 |
|
| 1917 |
def get_symbols(self, debug: bool = False) -> ComponentTestTemplate: |
| 1918 |
base_template = ComponentTemplate("\n".join(self._get_symbols("base", False))) |
| 1919 |
update_template = ComponentTemplate( |
| 1920 |
"\n".join(self._get_symbols("update", debug)) |
| 1921 |
) |
| 1922 |
augment = ComponentTemplate( |
| 1923 |
"\n".join(self._get_symbols("augment", False)) |
| 1924 |
).substitute(mode="") |
| 1925 |
override = ComponentTemplate( |
| 1926 |
"\n".join(self._get_symbols("override", False)) |
| 1927 |
).substitute(mode="") |
| 1928 |
replace = ComponentTemplate( |
| 1929 |
"\n".join(self._get_symbols("replace", False)) |
| 1930 |
).substitute(mode="") |
| 1931 |
return ComponentTestTemplate( |
| 1932 |
title=self.name, |
| 1933 |
component=Component.symbols, |
| 1934 |
base_template=base_template, |
| 1935 |
update_template=update_template, |
| 1936 |
augment=augment, |
| 1937 |
override=override, |
| 1938 |
replace=replace, |
| 1939 |
) |
| 1940 |
|
| 1941 |
|
| 1942 |
SYMBOLS_TESTS_BOTH = SymbolsTestGroup( |
| 1943 |
"", |
| 1944 |
( |
| 1945 |
Comment("Trivial cases"), |
| 1946 |
TestEntry( |
| 1947 |
TestId(TestType.ActionsOnly), |
| 1948 |
KeyEntry(), |
| 1949 |
update=KeyEntry(), |
| 1950 |
augment=KeyEntry(), |
| 1951 |
override=KeyEntry(), |
| 1952 |
), |
| 1953 |
TestEntry( |
| 1954 |
TestId(TestType.ActionsOnly), |
| 1955 |
KeyEntry(), |
| 1956 |
update=KeyEntry(Level.Actions(3)), |
| 1957 |
augment=KeyEntry(Level.Actions(3)), |
| 1958 |
override=KeyEntry(Level.Actions(3)), |
| 1959 |
), |
| 1960 |
TestEntry( |
| 1961 |
TestId(TestType.ActionsOnly), |
| 1962 |
KeyEntry(Level.Actions(2)), |
| 1963 |
update=KeyEntry(), |
| 1964 |
augment=KeyEntry(Level.Actions(2)), |
| 1965 |
override=KeyEntry(Level.Actions(2)), |
| 1966 |
), |
| 1967 |
Comment("Same key"), |
| 1968 |
TestEntry( |
| 1969 |
TestId(TestType.ActionsOnly), |
| 1970 |
KeyEntry(Level.Actions(2)), |
| 1971 |
update=KeyEntry(Level.Actions(2)), |
| 1972 |
augment=KeyEntry(Level.Actions(2)), |
| 1973 |
override=KeyEntry(Level.Actions(2)), |
| 1974 |
), |
| 1975 |
TestEntry( |
| 1976 |
TestId(TestType.ActionsOnly), |
| 1977 |
KeyEntry(Level.Actions(2), Level.Actions(2, Modifier.Control)), |
| 1978 |
update=KeyEntry(Level.Actions(2), Level.Actions(2, Modifier.Control)), |
| 1979 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2, Modifier.Control)), |
| 1980 |
override=KeyEntry(Level.Actions(2), Level.Actions(2, Modifier.Control)), |
| 1981 |
implementations=Implementation.xkbcommon, |
| 1982 |
), |
| 1983 |
Comment("Mismatch levels count"), |
| 1984 |
( |
| 1985 |
TEST_BOTH_Q := TestEntry( |
| 1986 |
TestId(TestType.ActionsOnly), |
| 1987 |
KeyEntry(Level.Actions(None), Level.Actions(2)), |
| 1988 |
update=KeyEntry( |
| 1989 |
Level.Actions(3), Level.Actions(None), Level.Actions(None) |
| 1990 |
), |
| 1991 |
augment=KeyEntry( |
| 1992 |
Level.Actions(3), Level.Actions(2), Level.Actions(None) |
| 1993 |
), |
| 1994 |
override=KeyEntry( |
| 1995 |
Level.Actions(3), Level.Actions(2), Level.Actions(None) |
| 1996 |
), |
| 1997 |
# X11 and xkbcommon handle keysyms-only case differently |
| 1998 |
types=TestType.ActionsOnly | TestType.KeysymsAndActions, |
| 1999 |
) |
| 2000 |
), |
| 2001 |
# Trailing NoSymbols are discarded in xkbcomp |
| 2002 |
dataclasses.replace( |
| 2003 |
TEST_BOTH_Q, |
| 2004 |
augment=KeyEntry(Level.Actions(3), Level.Actions(2)), |
| 2005 |
override=KeyEntry(Level.Actions(3), Level.Actions(2)), |
| 2006 |
replace=KeyEntry(Level.Actions(3)), |
| 2007 |
implementations=Implementation.x11, |
| 2008 |
).add_keysyms(keep_actions=False), |
| 2009 |
dataclasses.replace( |
| 2010 |
TEST_BOTH_Q, implementations=Implementation.xkbcommon |
| 2011 |
).add_keysyms(keep_actions=False), |
| 2012 |
TestEntry( |
| 2013 |
TestId(TestType.ActionsOnly), |
| 2014 |
KeyEntry(Level.Actions(None), Level.Actions(2)), |
| 2015 |
update=KeyEntry(Level.Actions(3), Level.Actions(None), Level.Actions(None)), |
| 2016 |
augment=KeyEntry(Level.Actions(3), Level.Actions(2), Level.Actions(None)), |
| 2017 |
override=KeyEntry(Level.Actions(3), Level.Actions(2), Level.Actions(None)), |
| 2018 |
# X11 and xkbcommon handle keysyms-only case differently |
| 2019 |
types=TestType.ActionsOnly | TestType.KeysymsAndActions, |
| 2020 |
), |
| 2021 |
( |
| 2022 |
TEST_BOTH_W := TestEntry( |
| 2023 |
TestId(TestType.ActionsOnly), |
| 2024 |
KeyEntry(Level.Actions(None), Level.Actions(2), Level.Actions(None)), |
| 2025 |
update=KeyEntry(Level.Actions(3), Level.Actions(None)), |
| 2026 |
augment=KeyEntry( |
| 2027 |
Level.Actions(3), Level.Actions(2), Level.Actions(None) |
| 2028 |
), |
| 2029 |
override=KeyEntry( |
| 2030 |
Level.Actions(3), Level.Actions(2), Level.Actions(None) |
| 2031 |
), |
| 2032 |
# X11 and xkbcommon handle keysyms-only case differently |
| 2033 |
types=TestType.ActionsOnly | TestType.KeysymsAndActions, |
| 2034 |
) |
| 2035 |
), |
| 2036 |
dataclasses.replace( |
| 2037 |
TEST_BOTH_W, |
| 2038 |
augment=KeyEntry(Level.Actions(3), Level.Actions(2)), |
| 2039 |
override=KeyEntry(Level.Actions(3), Level.Actions(2)), |
| 2040 |
replace=KeyEntry(Level.Actions(3)), |
| 2041 |
implementations=Implementation.x11, |
| 2042 |
).add_keysyms(keep_actions=False), |
| 2043 |
dataclasses.replace( |
| 2044 |
TEST_BOTH_W, implementations=Implementation.xkbcommon |
| 2045 |
).add_keysyms(keep_actions=False), |
| 2046 |
TestEntry( |
| 2047 |
TestId(TestType.ActionsOnly), |
| 2048 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2049 |
update=KeyEntry(Level.Actions(3), Level.Actions(3), Level.Actions(3)), |
| 2050 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2), Level.Actions(3)), |
| 2051 |
override=KeyEntry(Level.Actions(3), Level.Actions(3), Level.Actions(3)), |
| 2052 |
), |
| 2053 |
TestEntry( |
| 2054 |
TestId(TestType.ActionsOnly), |
| 2055 |
KeyEntry(Level.Actions(2), Level.Actions(2), Level.Actions(2)), |
| 2056 |
update=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2057 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2), Level.Actions(2)), |
| 2058 |
override=KeyEntry(Level.Actions(3), Level.Actions(3), Level.Actions(2)), |
| 2059 |
), |
| 2060 |
Comment("Single keysyms -> single keysyms"), |
| 2061 |
TestEntry( |
| 2062 |
TestId(TestType.ActionsOnly), |
| 2063 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2064 |
update=KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2065 |
augment=KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2066 |
override=KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2067 |
), |
| 2068 |
( |
| 2069 |
TEST_BOTH_Y := TestEntry( |
| 2070 |
TestId(TestType.ActionsOnly), |
| 2071 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2072 |
update=KeyEntry(Level.Actions(3), Level.Actions(None)), |
| 2073 |
augment=KeyEntry(Level.Actions(3), Level.Actions(None)), |
| 2074 |
override=KeyEntry(Level.Actions(3), Level.Actions(None)), |
| 2075 |
# X11 and xkbcommon handle keysyms-only case differently |
| 2076 |
types=TestType.ActionsOnly | TestType.KeysymsAndActions, |
| 2077 |
) |
| 2078 |
), |
| 2079 |
dataclasses.replace( |
| 2080 |
TEST_BOTH_Y, |
| 2081 |
augment=KeyEntry(Level.Actions(3)), |
| 2082 |
override=KeyEntry(Level.Actions(3)), |
| 2083 |
replace=KeyEntry(Level.Actions(3)), |
| 2084 |
implementations=Implementation.x11, |
| 2085 |
).add_keysyms(keep_actions=False), |
| 2086 |
dataclasses.replace( |
| 2087 |
TEST_BOTH_Y, implementations=Implementation.xkbcommon |
| 2088 |
).add_keysyms(keep_actions=False), |
| 2089 |
TestEntry( |
| 2090 |
TestId(TestType.ActionsOnly), |
| 2091 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2092 |
update=KeyEntry(Level.Actions(None), Level.Actions(3)), |
| 2093 |
augment=KeyEntry(Level.Actions(None), Level.Actions(3)), |
| 2094 |
override=KeyEntry(Level.Actions(None), Level.Actions(3)), |
| 2095 |
), |
| 2096 |
TestEntry( |
| 2097 |
TestId(TestType.ActionsOnly), |
| 2098 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2099 |
update=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2100 |
augment=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2101 |
override=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2102 |
), |
| 2103 |
TestEntry( |
| 2104 |
TestId(TestType.ActionsOnly), |
| 2105 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2106 |
update=KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2107 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2108 |
override=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2109 |
), |
| 2110 |
( |
| 2111 |
TEST_BOTH_P := TestEntry( |
| 2112 |
TestId(TestType.ActionsOnly), |
| 2113 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2114 |
update=KeyEntry(Level.Actions(3), Level.Actions(None)), |
| 2115 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2116 |
override=KeyEntry(Level.Actions(3), Level.Actions(2)), |
| 2117 |
# X11 and xkbcommon handle keysyms-only case differently |
| 2118 |
types=TestType.ActionsOnly | TestType.KeysymsAndActions, |
| 2119 |
) |
| 2120 |
), |
| 2121 |
dataclasses.replace( |
| 2122 |
TEST_BOTH_P, |
| 2123 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2124 |
override=KeyEntry(Level.Actions(3), Level.Actions(2)), |
| 2125 |
replace=KeyEntry(Level.Actions(3)), |
| 2126 |
implementations=Implementation.x11, |
| 2127 |
).add_keysyms(keep_actions=False), |
| 2128 |
dataclasses.replace( |
| 2129 |
TEST_BOTH_P, implementations=Implementation.xkbcommon |
| 2130 |
).add_keysyms(keep_actions=False), |
| 2131 |
TestEntry( |
| 2132 |
TestId(TestType.ActionsOnly), |
| 2133 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2134 |
update=KeyEntry(Level.Actions(None), Level.Actions(3)), |
| 2135 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2136 |
override=KeyEntry(Level.Actions(2), Level.Actions(3)), |
| 2137 |
), |
| 2138 |
TestEntry( |
| 2139 |
TestId(TestType.ActionsOnly), |
| 2140 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2141 |
update=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2142 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2143 |
override=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2144 |
), |
| 2145 |
TestEntry( |
| 2146 |
TestId(TestType.KeysymsAndActions), |
| 2147 |
KeyEntry(Level.Keysyms("a"), Level.Actions(2)), |
| 2148 |
update=KeyEntry(Level.Actions(3), Level.Keysyms("X")), |
| 2149 |
augment=KeyEntry(Level.Mix(("a"), (3,)), Level.Mix(("X",), (2,))), |
| 2150 |
override=KeyEntry(Level.Mix(("a"), (3,)), Level.Mix(("X",), (2,))), |
| 2151 |
), |
| 2152 |
Comment("Single keysyms -> multiple keysyms"), |
| 2153 |
TestEntry( |
| 2154 |
TestId(TestType.ActionsOnly), |
| 2155 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2156 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(None)), |
| 2157 |
augment=KeyEntry(Level.Actions(3, None), Level.Actions(None)), |
| 2158 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(None)), |
| 2159 |
implementations=Implementation.xkbcommon, |
| 2160 |
), |
| 2161 |
TestEntry( |
| 2162 |
TestId(TestType.ActionsOnly), |
| 2163 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2164 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(None, None)), |
| 2165 |
augment=KeyEntry(Level.Actions(3, None), Level.Actions(None)), |
| 2166 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(None)), |
| 2167 |
implementations=Implementation.xkbcommon, |
| 2168 |
), |
| 2169 |
TestEntry( |
| 2170 |
TestId(TestType.ActionsOnly), |
| 2171 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2172 |
update=KeyEntry(Level.Actions(None), Level.Actions(3, None)), |
| 2173 |
augment=KeyEntry(Level.Actions(None), Level.Actions(3, None)), |
| 2174 |
override=KeyEntry(Level.Actions(None), Level.Actions(3, None)), |
| 2175 |
implementations=Implementation.xkbcommon, |
| 2176 |
), |
| 2177 |
TestEntry( |
| 2178 |
TestId(TestType.ActionsOnly), |
| 2179 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2180 |
update=KeyEntry(Level.Actions(None, None), Level.Actions(3, None)), |
| 2181 |
augment=KeyEntry(Level.Actions(None), Level.Actions(3, None)), |
| 2182 |
override=KeyEntry(Level.Actions(None), Level.Actions(3, None)), |
| 2183 |
implementations=Implementation.xkbcommon, |
| 2184 |
), |
| 2185 |
TestEntry( |
| 2186 |
TestId(TestType.ActionsOnly), |
| 2187 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2188 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(3, None)), |
| 2189 |
augment=KeyEntry(Level.Actions(3, None), Level.Actions(3, None)), |
| 2190 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(3, None)), |
| 2191 |
implementations=Implementation.xkbcommon, |
| 2192 |
), |
| 2193 |
TestEntry( |
| 2194 |
TestId(TestType.ActionsOnly), |
| 2195 |
KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2196 |
update=KeyEntry( |
| 2197 |
Level.Actions(3, Modifier.LevelThree), |
| 2198 |
Level.Actions(3, Modifier.LevelThree), |
| 2199 |
), |
| 2200 |
augment=KeyEntry( |
| 2201 |
Level.Actions(3, Modifier.LevelThree), |
| 2202 |
Level.Actions(3, Modifier.LevelThree), |
| 2203 |
), |
| 2204 |
override=KeyEntry( |
| 2205 |
Level.Actions(3, Modifier.LevelThree), |
| 2206 |
Level.Actions(3, Modifier.LevelThree), |
| 2207 |
), |
| 2208 |
implementations=Implementation.xkbcommon, |
| 2209 |
), |
| 2210 |
TestEntry( |
| 2211 |
TestId(TestType.ActionsOnly), |
| 2212 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2213 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(None)), |
| 2214 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2215 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(2)), |
| 2216 |
implementations=Implementation.xkbcommon, |
| 2217 |
), |
| 2218 |
TestEntry( |
| 2219 |
TestId(TestType.ActionsOnly), |
| 2220 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2221 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(None, None)), |
| 2222 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2223 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(2)), |
| 2224 |
implementations=Implementation.xkbcommon, |
| 2225 |
), |
| 2226 |
TestEntry( |
| 2227 |
TestId(TestType.ActionsOnly), |
| 2228 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2229 |
update=KeyEntry(Level.Actions(None), Level.Actions(3, None)), |
| 2230 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2231 |
override=KeyEntry(Level.Actions(2), Level.Actions(3, None)), |
| 2232 |
implementations=Implementation.xkbcommon, |
| 2233 |
), |
| 2234 |
TestEntry( |
| 2235 |
TestId(TestType.ActionsOnly), |
| 2236 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2237 |
update=KeyEntry(Level.Actions(None, None), Level.Actions(3, None)), |
| 2238 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2239 |
override=KeyEntry(Level.Actions(2), Level.Actions(3, None)), |
| 2240 |
implementations=Implementation.xkbcommon, |
| 2241 |
), |
| 2242 |
TestEntry( |
| 2243 |
TestId(TestType.ActionsOnly), |
| 2244 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2245 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(3, None)), |
| 2246 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2247 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(3, None)), |
| 2248 |
implementations=Implementation.xkbcommon, |
| 2249 |
), |
| 2250 |
TestEntry( |
| 2251 |
TestId(TestType.ActionsOnly), |
| 2252 |
KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2253 |
update=KeyEntry( |
| 2254 |
Level.Actions(3, Modifier.LevelThree), |
| 2255 |
Level.Actions(3, Modifier.LevelThree), |
| 2256 |
), |
| 2257 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2)), |
| 2258 |
override=KeyEntry( |
| 2259 |
Level.Actions(3, Modifier.LevelThree), |
| 2260 |
Level.Actions(3, Modifier.LevelThree), |
| 2261 |
), |
| 2262 |
implementations=Implementation.xkbcommon, |
| 2263 |
), |
| 2264 |
Comment("Multiple keysyms -> multiple keysyms"), |
| 2265 |
TestEntry( |
| 2266 |
TestId(TestType.ActionsOnly), |
| 2267 |
KeyEntry(Level.Actions(None, None), Level.Actions(None, None)), |
| 2268 |
update=KeyEntry( |
| 2269 |
Level.Actions(None, None), Level.Actions(3, Modifier.LevelThree) |
| 2270 |
), |
| 2271 |
augment=KeyEntry( |
| 2272 |
Level.Actions(None, None), Level.Actions(3, Modifier.LevelThree) |
| 2273 |
), |
| 2274 |
override=KeyEntry( |
| 2275 |
Level.Actions(None, None), Level.Actions(3, Modifier.LevelThree) |
| 2276 |
), |
| 2277 |
implementations=Implementation.xkbcommon, |
| 2278 |
), |
| 2279 |
TestEntry( |
| 2280 |
TestId(TestType.ActionsOnly), |
| 2281 |
KeyEntry(Level.Actions(None, None), Level.Actions(None, None)), |
| 2282 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(None, 3)), |
| 2283 |
augment=KeyEntry(Level.Actions(3, None), Level.Actions(None, 3)), |
| 2284 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(None, 3)), |
| 2285 |
implementations=Implementation.xkbcommon, |
| 2286 |
), |
| 2287 |
TestEntry( |
| 2288 |
TestId(TestType.ActionsOnly), |
| 2289 |
KeyEntry(Level.Actions(None, None), Level.Actions(2, Modifier.Control)), |
| 2290 |
update=KeyEntry( |
| 2291 |
Level.Actions(3, Modifier.LevelThree), |
| 2292 |
Level.Actions(3, Modifier.LevelThree), |
| 2293 |
), |
| 2294 |
augment=KeyEntry( |
| 2295 |
Level.Actions(3, Modifier.LevelThree), |
| 2296 |
Level.Actions(2, Modifier.Control), |
| 2297 |
), |
| 2298 |
override=KeyEntry( |
| 2299 |
Level.Actions(3, Modifier.LevelThree), |
| 2300 |
Level.Actions(3, Modifier.LevelThree), |
| 2301 |
), |
| 2302 |
implementations=Implementation.xkbcommon, |
| 2303 |
), |
| 2304 |
TestEntry( |
| 2305 |
TestId(TestType.ActionsOnly), |
| 2306 |
KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2307 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(None, 3)), |
| 2308 |
augment=KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2309 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(None, 3)), |
| 2310 |
implementations=Implementation.xkbcommon, |
| 2311 |
), |
| 2312 |
TestEntry( |
| 2313 |
TestId(TestType.ActionsOnly), |
| 2314 |
KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2315 |
update=KeyEntry( |
| 2316 |
Level.Actions(3, Modifier.LevelThree), |
| 2317 |
Level.Actions(Modifier.LevelThree, 3), |
| 2318 |
), |
| 2319 |
augment=KeyEntry( |
| 2320 |
Level.Actions(2, None), |
| 2321 |
Level.Actions(None, 2), |
| 2322 |
), |
| 2323 |
override=KeyEntry( |
| 2324 |
Level.Actions(3, Modifier.LevelThree), |
| 2325 |
Level.Actions(Modifier.LevelThree, 3), |
| 2326 |
), |
| 2327 |
implementations=Implementation.xkbcommon, |
| 2328 |
), |
| 2329 |
TestEntry( |
| 2330 |
TestId(TestType.ActionsOnly), |
| 2331 |
KeyEntry( |
| 2332 |
Level.Actions(2, Modifier.Control), Level.Actions(2, Modifier.Control) |
| 2333 |
), |
| 2334 |
update=KeyEntry( |
| 2335 |
Level.Actions(None, None), Level.Actions(3, Modifier.LevelThree) |
| 2336 |
), |
| 2337 |
augment=KeyEntry( |
| 2338 |
Level.Actions(2, Modifier.Control), Level.Actions(2, Modifier.Control) |
| 2339 |
), |
| 2340 |
override=KeyEntry( |
| 2341 |
Level.Actions(2, Modifier.Control), |
| 2342 |
Level.Actions(3, Modifier.LevelThree), |
| 2343 |
), |
| 2344 |
implementations=Implementation.xkbcommon, |
| 2345 |
), |
| 2346 |
TestEntry( |
| 2347 |
TestId(TestType.ActionsOnly), |
| 2348 |
KeyEntry( |
| 2349 |
Level.Actions(2, Modifier.Control), Level.Actions(Modifier.Control, 2) |
| 2350 |
), |
| 2351 |
update=KeyEntry(Level.Actions(3, None), Level.Actions(None, 3)), |
| 2352 |
augment=KeyEntry( |
| 2353 |
Level.Actions(2, Modifier.Control), Level.Actions(Modifier.Control, 2) |
| 2354 |
), |
| 2355 |
override=KeyEntry(Level.Actions(3, None), Level.Actions(None, 3)), |
| 2356 |
implementations=Implementation.xkbcommon, |
| 2357 |
), |
| 2358 |
TestEntry( |
| 2359 |
TestId(TestType.ActionsOnly), |
| 2360 |
KeyEntry(Level.Actions(None, None), Level.Actions(None, None, None)), |
| 2361 |
update=KeyEntry(Level.Actions(None, None, None), Level.Actions(None, None)), |
| 2362 |
augment=KeyEntry( |
| 2363 |
Level.Actions(None, None), Level.Actions(None, None, None) |
| 2364 |
), |
| 2365 |
override=KeyEntry( |
| 2366 |
Level.Actions(None, None), Level.Actions(None, None, None) |
| 2367 |
), |
| 2368 |
implementations=Implementation.xkbcommon, |
| 2369 |
), |
| 2370 |
TestEntry( |
| 2371 |
TestId(TestType.ActionsOnly), |
| 2372 |
KeyEntry(Level.Actions(None, None), Level.Actions(None, None, None)), |
| 2373 |
update=KeyEntry( |
| 2374 |
Level.Actions(3, None, Modifier.LevelThree), |
| 2375 |
Level.Actions(Modifier.LevelThree, 3), |
| 2376 |
), |
| 2377 |
augment=KeyEntry( |
| 2378 |
Level.Actions(3, None, Modifier.LevelThree), |
| 2379 |
Level.Actions(Modifier.LevelThree, 3), |
| 2380 |
), |
| 2381 |
override=KeyEntry( |
| 2382 |
Level.Actions(3, None, Modifier.LevelThree), |
| 2383 |
Level.Actions(Modifier.LevelThree, 3), |
| 2384 |
), |
| 2385 |
implementations=Implementation.xkbcommon, |
| 2386 |
), |
| 2387 |
TestEntry( |
| 2388 |
TestId(TestType.ActionsOnly), |
| 2389 |
KeyEntry( |
| 2390 |
Level.Actions(2, Modifier.Control), |
| 2391 |
Level.Actions(Modifier.Control, None, 2), |
| 2392 |
), |
| 2393 |
update=KeyEntry(Level.Actions(None, None, None), Level.Actions(None, None)), |
| 2394 |
augment=KeyEntry( |
| 2395 |
Level.Actions(2, Modifier.Control), |
| 2396 |
Level.Actions(Modifier.Control, None, 2), |
| 2397 |
), |
| 2398 |
override=KeyEntry( |
| 2399 |
Level.Actions(2, Modifier.Control), |
| 2400 |
Level.Actions(Modifier.Control, None, 2), |
| 2401 |
), |
| 2402 |
implementations=Implementation.xkbcommon, |
| 2403 |
), |
| 2404 |
TestEntry( |
| 2405 |
TestId(TestType.ActionsOnly), |
| 2406 |
KeyEntry( |
| 2407 |
Level.Actions(2, Modifier.Control), |
| 2408 |
Level.Actions(Modifier.Control, None, 2), |
| 2409 |
), |
| 2410 |
update=KeyEntry( |
| 2411 |
Level.Actions(3, None, Modifier.LevelThree), |
| 2412 |
Level.Actions(Modifier.LevelThree, 3), |
| 2413 |
), |
| 2414 |
augment=KeyEntry( |
| 2415 |
Level.Actions(2, Modifier.Control), |
| 2416 |
Level.Actions(Modifier.Control, None, 2), |
| 2417 |
), |
| 2418 |
override=KeyEntry( |
| 2419 |
Level.Actions(3, None, Modifier.LevelThree), |
| 2420 |
Level.Actions(Modifier.LevelThree, 3), |
| 2421 |
), |
| 2422 |
implementations=Implementation.xkbcommon, |
| 2423 |
), |
| 2424 |
Comment("Multiple keysyms -> single keysyms"), |
| 2425 |
TestEntry( |
| 2426 |
TestId(TestType.ActionsOnly), |
| 2427 |
KeyEntry(Level.Actions(None, None), Level.Actions(2, Modifier.Control)), |
| 2428 |
update=KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2429 |
augment=KeyEntry( |
| 2430 |
Level.Actions(None, None), Level.Actions(2, Modifier.Control) |
| 2431 |
), |
| 2432 |
override=KeyEntry( |
| 2433 |
Level.Actions(None, None), Level.Actions(2, Modifier.Control) |
| 2434 |
), |
| 2435 |
implementations=Implementation.xkbcommon, |
| 2436 |
), |
| 2437 |
TestEntry( |
| 2438 |
TestId(TestType.ActionsOnly), |
| 2439 |
KeyEntry(Level.Actions(None, None), Level.Actions(2, Modifier.Control)), |
| 2440 |
update=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2441 |
augment=KeyEntry(Level.Actions(3), Level.Actions(2, Modifier.Control)), |
| 2442 |
override=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2443 |
implementations=Implementation.xkbcommon, |
| 2444 |
), |
| 2445 |
TestEntry( |
| 2446 |
TestId(TestType.ActionsOnly), |
| 2447 |
KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2448 |
update=KeyEntry(Level.Actions(None), Level.Actions(None)), |
| 2449 |
augment=KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2450 |
override=KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2451 |
implementations=Implementation.xkbcommon, |
| 2452 |
), |
| 2453 |
TestEntry( |
| 2454 |
TestId(TestType.ActionsOnly), |
| 2455 |
KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2456 |
update=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2457 |
augment=KeyEntry(Level.Actions(2, None), Level.Actions(None, 2)), |
| 2458 |
override=KeyEntry(Level.Actions(3), Level.Actions(3)), |
| 2459 |
implementations=Implementation.xkbcommon, |
| 2460 |
), |
| 2461 |
Comment("Mix"), |
| 2462 |
TestEntry( |
| 2463 |
TestId(TestType.KeysymsAndActions), |
| 2464 |
KeyEntry(Level.Actions(2)), |
| 2465 |
update=KeyEntry( |
| 2466 |
Level.Actions(3, Modifier.LevelThree), |
| 2467 |
Level.Actions(3, Modifier.LevelThree), |
| 2468 |
), |
| 2469 |
augment=KeyEntry(Level.Actions(2), Level.Actions(3, Modifier.LevelThree)), |
| 2470 |
override=KeyEntry( |
| 2471 |
Level.Actions(3, Modifier.LevelThree), |
| 2472 |
Level.Actions(3, Modifier.LevelThree), |
| 2473 |
), |
| 2474 |
implementations=Implementation.xkbcommon, |
| 2475 |
), |
| 2476 |
TestEntry( |
| 2477 |
TestId(TestType.KeysymsAndActions), |
| 2478 |
KeyEntry(Level.Actions(2, Modifier.Control)), |
| 2479 |
update=KeyEntry(Level.Actions(3, Modifier.LevelThree), Level.Actions(3)), |
| 2480 |
augment=KeyEntry(Level.Actions(2, Modifier.Control), Level.Actions(3)), |
| 2481 |
override=KeyEntry(Level.Actions(3, Modifier.LevelThree), Level.Actions(3)), |
| 2482 |
implementations=Implementation.xkbcommon, |
| 2483 |
), |
| 2484 |
TestEntry( |
| 2485 |
TestId(TestType.KeysymsAndActions), |
| 2486 |
KeyEntry(Level.Actions(2), Level.Actions(2, Modifier.Control)), |
| 2487 |
update=KeyEntry(Level.Actions(3, Modifier.LevelThree), Level.Actions(3)), |
| 2488 |
augment=KeyEntry(Level.Actions(2), Level.Actions(2, Modifier.Control)), |
| 2489 |
override=KeyEntry(Level.Actions(3, Modifier.LevelThree), Level.Actions(3)), |
| 2490 |
implementations=Implementation.xkbcommon, |
| 2491 |
), |
| 2492 |
Comment("Mix"), |
| 2493 |
TestEntry( |
| 2494 |
TestId(TestType.KeysymsAndActions), |
| 2495 |
KeyEntry(Level.Keysyms("a"), Level.Actions(2)), |
| 2496 |
update=KeyEntry( |
| 2497 |
Level.Actions(3, Modifier.LevelThree), Level.Keysyms("X", "Y") |
| 2498 |
), |
| 2499 |
augment=KeyEntry( |
| 2500 |
Level.Mix(("a",), (3, Modifier.LevelThree)), |
| 2501 |
Level.Mix(("X", "Y"), (2,)), |
| 2502 |
), |
| 2503 |
override=KeyEntry( |
| 2504 |
Level.Mix(("a",), (3, Modifier.LevelThree)), |
| 2505 |
Level.Mix(("X", "Y"), (2,)), |
| 2506 |
), |
| 2507 |
implementations=Implementation.xkbcommon, |
| 2508 |
), |
| 2509 |
Comment("Multiple keysyms/actions –> single"), |
| 2510 |
TestEntry( |
| 2511 |
TestId(TestType.KeysymsAndActions), |
| 2512 |
KeyEntry(Level.Keysyms("a", "b"), Level.Actions(2, Modifier.Control)), |
| 2513 |
update=KeyEntry(Level.Actions(3), Level.Keysyms("X")), |
| 2514 |
augment=KeyEntry( |
| 2515 |
Level.Mix(("a", "b"), (3,)), |
| 2516 |
Level.Mix(("X",), (2, Modifier.Control)), |
| 2517 |
), |
| 2518 |
override=KeyEntry( |
| 2519 |
Level.Mix(("a", "b"), (3,)), |
| 2520 |
Level.Mix(("X",), (2, Modifier.Control)), |
| 2521 |
), |
| 2522 |
implementations=Implementation.xkbcommon, |
| 2523 |
), |
| 2524 |
Comment("Multiple keysyms/actions –> multiple (xor)"), |
| 2525 |
TestEntry( |
| 2526 |
TestId(TestType.KeysymsAndActions), |
| 2527 |
KeyEntry(Level.Keysyms("a", "b"), Level.Actions(2, Modifier.Control)), |
| 2528 |
update=KeyEntry( |
| 2529 |
Level.Actions(3, Modifier.LevelThree), Level.Keysyms("X", "Y") |
| 2530 |
), |
| 2531 |
augment=KeyEntry( |
| 2532 |
Level.Mix(("a", "b"), (3, Modifier.LevelThree)), |
| 2533 |
Level.Mix(("X", "Y"), (2, Modifier.Control)), |
| 2534 |
), |
| 2535 |
override=KeyEntry( |
| 2536 |
Level.Mix(("a", "b"), (3, Modifier.LevelThree)), |
| 2537 |
Level.Mix(("X", "Y"), (2, Modifier.Control)), |
| 2538 |
), |
| 2539 |
implementations=Implementation.xkbcommon, |
| 2540 |
), |
| 2541 |
Comment("Multiple keysyms/actions –> multiple (mix)"), |
| 2542 |
TestEntry( |
| 2543 |
TestId(TestType.KeysymsAndActions), |
| 2544 |
KeyEntry(Level.Keysyms("a", None), Level.Actions(2, None)), |
| 2545 |
update=KeyEntry( |
| 2546 |
Level.Mix(("x", "y"), (3, Modifier.LevelThree)), |
| 2547 |
Level.Mix(("X", "Y"), (3, Modifier.LevelThree)), |
| 2548 |
), |
| 2549 |
augment=KeyEntry( |
| 2550 |
Level.Mix(("a", None), (3, Modifier.LevelThree)), |
| 2551 |
Level.Mix(("X", "Y"), (2, None)), |
| 2552 |
), |
| 2553 |
override=KeyEntry( |
| 2554 |
Level.Mix(("x", "y"), (3, Modifier.LevelThree)), |
| 2555 |
Level.Mix(("X", "Y"), (3, Modifier.LevelThree)), |
| 2556 |
), |
| 2557 |
implementations=Implementation.xkbcommon, |
| 2558 |
), |
| 2559 |
TestEntry( |
| 2560 |
TestId(TestType.KeysymsAndActions), |
| 2561 |
KeyEntry(Level.Keysyms("a", "b"), Level.Actions(2, Modifier.Control)), |
| 2562 |
update=KeyEntry( |
| 2563 |
Level.Mix(("x", None), (3, Modifier.LevelThree)), |
| 2564 |
Level.Mix(("X", "Y"), (3, None)), |
| 2565 |
), |
| 2566 |
augment=KeyEntry( |
| 2567 |
Level.Mix(("a", "b"), (3, Modifier.LevelThree)), |
| 2568 |
Level.Mix(("X", "Y"), (2, Modifier.Control)), |
| 2569 |
), |
| 2570 |
override=KeyEntry( |
| 2571 |
Level.Mix(("x", None), (3, Modifier.LevelThree)), |
| 2572 |
Level.Mix(("X", "Y"), (3, None)), |
| 2573 |
), |
| 2574 |
implementations=Implementation.xkbcommon, |
| 2575 |
), |
| 2576 |
Comment("Multiple (mix) –> multiple keysyms/actions"), |
| 2577 |
TestEntry( |
| 2578 |
TestId(TestType.KeysymsAndActions), |
| 2579 |
KeyEntry( |
| 2580 |
Level.Mix(("a", "b"), (2, Modifier.Control)), |
| 2581 |
Level.Mix(("A", "B"), (2, Modifier.Control)), |
| 2582 |
), |
| 2583 |
update=KeyEntry(Level.Keysyms("x", None), Level.Actions(3, None)), |
| 2584 |
augment=KeyEntry( |
| 2585 |
Level.Mix(("a", "b"), (2, Modifier.Control)), |
| 2586 |
Level.Mix(("A", "B"), (2, Modifier.Control)), |
| 2587 |
), |
| 2588 |
override=KeyEntry( |
| 2589 |
Level.Mix(("x", None), (2, Modifier.Control)), |
| 2590 |
Level.Mix(("A", "B"), (3, None)), |
| 2591 |
), |
| 2592 |
implementations=Implementation.xkbcommon, |
| 2593 |
), |
| 2594 |
TestEntry( |
| 2595 |
TestId(TestType.KeysymsAndActions), |
| 2596 |
KeyEntry( |
| 2597 |
Level.Mix(("a", None), (2, Modifier.Control)), |
| 2598 |
Level.Mix(("A", "B"), (2, None)), |
| 2599 |
), |
| 2600 |
update=KeyEntry( |
| 2601 |
Level.Keysyms("x", "y"), Level.Actions(3, Modifier.LevelThree) |
| 2602 |
), |
| 2603 |
augment=KeyEntry( |
| 2604 |
Level.Mix(("a", None), (2, Modifier.Control)), |
| 2605 |
Level.Mix(("A", "B"), (2, None)), |
| 2606 |
), |
| 2607 |
override=KeyEntry( |
| 2608 |
Level.Mix(("x", "y"), (2, Modifier.Control)), |
| 2609 |
Level.Mix(("A", "B"), (3, Modifier.LevelThree)), |
| 2610 |
), |
| 2611 |
implementations=Implementation.xkbcommon, |
| 2612 |
), |
| 2613 |
Comment("Multiple (mix) –> multiple (mix)"), |
| 2614 |
TestEntry( |
| 2615 |
TestId(TestType.KeysymsAndActions), |
| 2616 |
KeyEntry( |
| 2617 |
Level.Mix(("a", "b"), (2, Modifier.Control)), |
| 2618 |
Level.Mix((None, "B"), (2, None)), |
| 2619 |
), |
| 2620 |
update=KeyEntry( |
| 2621 |
Level.Mix((None, "y"), (3, None)), |
| 2622 |
Level.Mix(("X", "Y"), (3, Modifier.LevelThree)), |
| 2623 |
), |
| 2624 |
augment=KeyEntry( |
| 2625 |
Level.Mix(("a", "b"), (2, Modifier.Control)), |
| 2626 |
Level.Mix((None, "B"), (2, None)), |
| 2627 |
), |
| 2628 |
override=KeyEntry( |
| 2629 |
Level.Mix((None, "y"), (3, None)), |
| 2630 |
Level.Mix(("X", "Y"), (3, Modifier.LevelThree)), |
| 2631 |
), |
| 2632 |
implementations=Implementation.xkbcommon, |
| 2633 |
), |
| 2634 |
TestEntry( |
| 2635 |
TestId(TestType.KeysymsAndActions), |
| 2636 |
KeyEntry( |
| 2637 |
Level.Mix(("a", None), (2, None)), |
| 2638 |
Level.Mix((None, "B"), (None, Modifier.Control)), |
| 2639 |
), |
| 2640 |
update=KeyEntry( |
| 2641 |
Level.Mix((None, "y"), (None, Modifier.LevelThree)), |
| 2642 |
Level.Mix(("X", None), (3, None)), |
| 2643 |
), |
| 2644 |
augment=KeyEntry( |
| 2645 |
Level.Mix(("a", None), (2, None)), |
| 2646 |
Level.Mix((None, "B"), (None, Modifier.Control)), |
| 2647 |
), |
| 2648 |
override=KeyEntry( |
| 2649 |
Level.Mix((None, "y"), (None, Modifier.LevelThree)), |
| 2650 |
Level.Mix(("X", None), (3, None)), |
| 2651 |
), |
| 2652 |
implementations=Implementation.xkbcommon, |
| 2653 |
), |
| 2654 |
Comment("Mismatch count with mix"), |
| 2655 |
TestEntry( |
| 2656 |
TestId(TestType.KeysymsAndActions), |
| 2657 |
KeyEntry( |
| 2658 |
Level.Keysyms("a"), |
| 2659 |
Level.Keysyms("A", "B"), |
| 2660 |
), |
| 2661 |
update=KeyEntry( |
| 2662 |
Level.Actions(3, Modifier.LevelThree), |
| 2663 |
Level.Actions(3), |
| 2664 |
), |
| 2665 |
augment=KeyEntry( |
| 2666 |
Level.Mix(("a"), (3, Modifier.LevelThree)), |
| 2667 |
Level.Mix(("A", "B"), (3,)), |
| 2668 |
), |
| 2669 |
override=KeyEntry( |
| 2670 |
Level.Mix(("a"), (3, Modifier.LevelThree)), |
| 2671 |
Level.Mix(("A", "B"), (3,)), |
| 2672 |
), |
| 2673 |
implementations=Implementation.xkbcommon, |
| 2674 |
), |
| 2675 |
TestEntry( |
| 2676 |
TestId(TestType.KeysymsAndActions), |
| 2677 |
KeyEntry( |
| 2678 |
Level.Actions(3), |
| 2679 |
Level.Actions(3, Modifier.LevelThree), |
| 2680 |
), |
| 2681 |
update=KeyEntry( |
| 2682 |
Level.Keysyms("A", "B"), |
| 2683 |
Level.Keysyms("a"), |
| 2684 |
), |
| 2685 |
augment=KeyEntry( |
| 2686 |
Level.Mix(("A", "B"), (3,)), |
| 2687 |
Level.Mix(("a"), (3, Modifier.LevelThree)), |
| 2688 |
), |
| 2689 |
override=KeyEntry( |
| 2690 |
Level.Mix(("A", "B"), (3,)), |
| 2691 |
Level.Mix(("a"), (3, Modifier.LevelThree)), |
| 2692 |
), |
| 2693 |
implementations=Implementation.xkbcommon, |
| 2694 |
), |
| 2695 |
TestEntry( |
| 2696 |
TestId(TestType.KeysymsAndActions), |
| 2697 |
KeyEntry( |
| 2698 |
Level.Mix(("a",), (2,)), |
| 2699 |
Level.Mix(("A", "B"), (2, Modifier.Control)), |
| 2700 |
), |
| 2701 |
update=KeyEntry( |
| 2702 |
Level.Mix(("x", "y"), (3, Modifier.LevelThree)), |
| 2703 |
Level.Mix(("X",), (3,)), |
| 2704 |
), |
| 2705 |
augment=KeyEntry( |
| 2706 |
Level.Mix(("a",), (2,)), |
| 2707 |
Level.Mix(("A", "B"), (2, Modifier.Control)), |
| 2708 |
), |
| 2709 |
override=KeyEntry( |
| 2710 |
Level.Mix(("x", "y"), (3, Modifier.LevelThree)), |
| 2711 |
Level.Mix(("X",), (3,)), |
| 2712 |
), |
| 2713 |
implementations=Implementation.xkbcommon, |
| 2714 |
), |
| 2715 |
Comment("Issue #564"), |
| 2716 |
TestEntry( |
| 2717 |
TestId(TestType.KeysymsAndActions), |
| 2718 |
KeyEntry(Level.Keysyms("A")), |
| 2719 |
update=KeyEntry(Level.Mix(("A", "A"), (3, Modifier.LevelThree))), |
| 2720 |
augment=KeyEntry(Level.Mix(("A",), (3, Modifier.LevelThree))), |
| 2721 |
override=KeyEntry(Level.Mix(("A", "A"), (3, Modifier.LevelThree))), |
| 2722 |
implementations=Implementation.xkbcommon, |
| 2723 |
), |
| 2724 |
Comment("Drop NoSymbol/NoAction"), |
| 2725 |
TestEntry( |
| 2726 |
TestId(TestType.KeysymsAndActions), |
| 2727 |
KeyEntry(Level.Mix(("A",), (2,))), |
| 2728 |
update=KeyEntry(Level.Mix((None, "Y", None), (None, 3, None))), |
| 2729 |
augment=KeyEntry(Level.Mix(("A",), (2,))), |
| 2730 |
override=KeyEntry(Level.Mix(("Y",), (3,))), |
| 2731 |
implementations=Implementation.xkbcommon, |
| 2732 |
), |
| 2733 |
Comment("Drop NoSymbol/NoAction and invalid keysyms"), |
| 2734 |
TestEntry( |
| 2735 |
TestId(TestType.KeysymsAndActions), |
| 2736 |
KeyEntry(Level.Mix(("notAKeysym", None, "thisEither"), (None, None))), |
| 2737 |
update=KeyEntry(Level.Mix((None, None), (None, None))), |
| 2738 |
augment=KeyEntry(Level.Keysyms(None)), |
| 2739 |
override=KeyEntry(Level.Keysyms(None)), |
| 2740 |
replace=KeyEntry(Level.Keysyms(None)), |
| 2741 |
implementations=Implementation.xkbcommon, |
| 2742 |
), |
| 2743 |
), |
| 2744 |
).add_keysyms() |
| 2745 |
|
| 2746 |
|
| 2747 |
################################################################################ |
| 2748 |
# |
| 2749 |
# Keycodes tests |
| 2750 |
# |
| 2751 |
################################################################################ |
| 2752 |
|
| 2753 |
KEYCODES_TESTS_BASE = ComponentTestTemplate( |
| 2754 |
"Keycodes", |
| 2755 |
component=Component.keycodes, |
| 2756 |
base_template=ComponentTemplate( |
| 2757 |
""" |
| 2758 |
${mode}<1> = 241; |
| 2759 |
${mode}<2> = 242; |
| 2760 |
|
| 2761 |
${mode}alias <A> = <1>; |
| 2762 |
${mode}alias <B> = <2>; |
| 2763 |
|
| 2764 |
${mode}indicator 1 = "Caps Lock"; |
| 2765 |
${mode}indicator 2 = "Num Lock"; |
| 2766 |
${mode}indicator 3 = "Scroll Lock"; |
| 2767 |
${mode}indicator 4 = "Compose"; |
| 2768 |
${mode}indicator 5 = "Kana"; |
| 2769 |
""" |
| 2770 |
), |
| 2771 |
update_template=ComponentTemplate( |
| 2772 |
""" |
| 2773 |
${mode}<1> = 241; // Unchanged |
| 2774 |
${mode}<2> = 244; // Changed |
| 2775 |
${mode}<3> = 243; // New |
| 2776 |
|
| 2777 |
${mode}alias <A> = <1>; // Unchanged |
| 2778 |
${mode}alias <B> = <3>; // Changed |
| 2779 |
${mode}alias <C> = <3>; // New |
| 2780 |
|
| 2781 |
${mode}indicator 1 = "Caps Lock"; // Unchanged |
| 2782 |
${mode}indicator 6 = "Num Lock"; // Changed index (free) |
| 2783 |
${mode}indicator 5 = "Scroll Lock"; // Changed index (not free) |
| 2784 |
${mode}indicator 4 = "XXXX"; // Changed name |
| 2785 |
${mode}indicator 7 = "Suspend"; // New |
| 2786 |
""" |
| 2787 |
), |
| 2788 |
augment=""" |
| 2789 |
<1> = 241; |
| 2790 |
<2> = 242; |
| 2791 |
<3> = 243; |
| 2792 |
alias <A> = <1>; |
| 2793 |
alias <B> = <2>; |
| 2794 |
alias <C> = <3>; |
| 2795 |
indicator 1 = "Caps Lock"; |
| 2796 |
indicator 2 = "Num Lock"; |
| 2797 |
indicator 3 = "Scroll Lock"; |
| 2798 |
indicator 4 = "Compose"; |
| 2799 |
indicator 5 = "Kana"; |
| 2800 |
indicator 7 = "Suspend"; |
| 2801 |
""", |
| 2802 |
override=""" |
| 2803 |
<1> = 241; |
| 2804 |
<2> = 244; |
| 2805 |
<3> = 243; |
| 2806 |
alias <A> = <1>; |
| 2807 |
alias <B> = <3>; |
| 2808 |
alias <C> = <3>; |
| 2809 |
indicator 1 = "Caps Lock"; |
| 2810 |
indicator 4 = "XXXX"; |
| 2811 |
indicator 5 = "Scroll Lock"; |
| 2812 |
indicator 6 = "Num Lock"; |
| 2813 |
indicator 7 = "Suspend"; |
| 2814 |
""", |
| 2815 |
) |
| 2816 |
|
| 2817 |
|
| 2818 |
################################################################################ |
| 2819 |
# |
| 2820 |
# Main |
| 2821 |
# |
| 2822 |
################################################################################ |
| 2823 |
|
| 2824 |
if __name__ == "__main__": |
| 2825 |
# Parse commands |
| 2826 |
parser = argparse.ArgumentParser(description="Generate merge mode tests") |
| 2827 |
parser.add_argument( |
| 2828 |
"compiler", |
| 2829 |
type=XkbCompiler.parse, |
| 2830 |
nargs="?", |
| 2831 |
default="xkbcommon", |
| 2832 |
help="XKB compiler to use", |
| 2833 |
) |
| 2834 |
parser.add_argument( |
| 2835 |
"--root", |
| 2836 |
type=Path, |
| 2837 |
default=ROOT, |
| 2838 |
help="Path to the root of the project (default: %(default)s)", |
| 2839 |
) |
| 2840 |
parser.add_argument( |
| 2841 |
"--c-out", |
| 2842 |
type=Path, |
| 2843 |
# default=ROOT / TestGroup.c_template.stem, |
| 2844 |
help="Path to the output C test file (default: %(default)s)", |
| 2845 |
) |
| 2846 |
parser.add_argument("--no-xkb", action="store_true", help="Do not update XKB data") |
| 2847 |
parser.add_argument("--debug", action="store_true", help="Activate debug mode") |
| 2848 |
args = parser.parse_args() |
| 2849 |
|
| 2850 |
# Prepare data |
| 2851 |
template_loader = jinja2.FileSystemLoader(args.root, encoding="utf-8") |
| 2852 |
jinja_env = jinja2.Environment( |
| 2853 |
loader=template_loader, |
| 2854 |
keep_trailing_newline=True, |
| 2855 |
trim_blocks=True, |
| 2856 |
lstrip_blocks=True, |
| 2857 |
) |
| 2858 |
|
| 2859 |
def escape_quotes(s: str) -> str: |
| 2860 |
return s.replace('"', '\\"') |
| 2861 |
|
| 2862 |
jinja_env.filters["escape_quotes"] = escape_quotes |
| 2863 |
compiler: XkbCompiler = args.compiler |
| 2864 |
|
| 2865 |
SYMBOLS_TESTS = SYMBOLS_TESTS_BOTH.with_implementation( |
| 2866 |
Implementation.xkbcommon if compiler.extended_syntax else Implementation.x11 |
| 2867 |
) |
| 2868 |
|
| 2869 |
KEYCODES_TESTS = SYMBOLS_TESTS.get_keycodes(KEYCODES_TESTS_BASE) |
| 2870 |
|
| 2871 |
TESTS = ( |
| 2872 |
KeymapTestTemplate( |
| 2873 |
title="", |
| 2874 |
keycodes=KEYCODES_TESTS, |
| 2875 |
types=TYPES_TESTS, |
| 2876 |
compat=COMPAT_TESTS, |
| 2877 |
symbols=SYMBOLS_TESTS.get_symbols(debug=args.debug), |
| 2878 |
), |
| 2879 |
) |
| 2880 |
|
| 2881 |
# Write tests |
| 2882 |
TESTS[0].write( |
| 2883 |
root=args.root, |
| 2884 |
jinja_env=jinja_env, |
| 2885 |
c_file=args.c_out, |
| 2886 |
xkb=not args.no_xkb, |
| 2887 |
compiler=compiler, |
| 2888 |
tests=TESTS, |
| 2889 |
) |