Fix HDMI recovery dispatches for Lua Hyprland sessions
This commit is contained in:
1 parent
d963224cb7
commit
34bae045c3
7 files changed
+163
-10
No files matched your search
+73
-1
@@ -32,8 +32,35 @@ elif name == 'hyprctl':
|
||||
print('invalid')
|
||||
else:
|
||||
print(json.dumps([{'name': os.environ.get('OUTPUT', 'HDMI-A-2')}]))
|
||||
else:
|
||||
elif args == ['-j', 'status']:
|
||||
if os.environ.get('OLD_HYPRLAND'):
|
||||
print('unknown request')
|
||||
sys.exit(int(os.environ.get('STATUS_EXIT', '0')))
|
||||
print(json.dumps({'configProvider': os.environ.get('CONFIG_PROVIDER', 'hyprlang')}))
|
||||
elif args[0] == 'dispatch':
|
||||
monitor = os.environ.get('OUTPUT', 'HDMI-A-2')
|
||||
if os.environ.get('CONFIG_PROVIDER') == 'lua':
|
||||
commands = {
|
||||
('dispatch', f'hl.dsp.dpms({{ action = "on", monitor = "{monitor}" }})'): 'DPMS',
|
||||
('dispatch', f'hl.dsp.focus({{ monitor = "{monitor}" }})'): 'focus',
|
||||
}
|
||||
else:
|
||||
commands = {
|
||||
('dispatch', 'dpms', 'on', monitor): 'DPMS',
|
||||
('dispatch', 'focusmonitor', monitor): 'focus',
|
||||
}
|
||||
action = commands.get(tuple(args))
|
||||
if action is None:
|
||||
print('error: invalid dispatch syntax')
|
||||
sys.exit(7)
|
||||
if os.environ.get('DISPATCH_FAIL') == action and (
|
||||
not os.environ.get('FINAL_REFRESH_FAIL') or (state / 'away').exists()):
|
||||
print(f'error: {action} rejected for {monitor}')
|
||||
sys.exit(int(os.environ.get('DISPATCH_EXIT', '7')))
|
||||
print('ok')
|
||||
else:
|
||||
print('unexpected hyprctl call', file=sys.stderr)
|
||||
sys.exit(99)
|
||||
elif name == 'sleep':
|
||||
if os.environ.get('CHANGE_SESSION'):
|
||||
(state / 'inactive').touch()
|
||||
@@ -105,6 +132,51 @@ class RecoveryTests(unittest.TestCase):
|
||||
self.assertEqual(self.switches(), ['2', '1'])
|
||||
self.assertIn('Recovery completed', r.stderr)
|
||||
|
||||
def test_lua_session_refreshes_before_and_after_vt_switch(self):
|
||||
r = self.run_script(CONFIG_PROVIDER='lua')
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.switches(), ['2', '1'])
|
||||
self.assertIn('Using lua dispatch syntax', r.stderr)
|
||||
dispatches = [a for a in self.calls('hyprctl') if a[0] == 'dispatch']
|
||||
self.assertEqual(dispatches, [
|
||||
['dispatch', 'hl.dsp.dpms({ action = "on", monitor = "HDMI-A-2" })'],
|
||||
['dispatch', 'hl.dsp.focus({ monitor = "HDMI-A-2" })'],
|
||||
] * 2)
|
||||
|
||||
def test_legacy_without_status_command(self):
|
||||
for code in ('0', '1'):
|
||||
with self.subTest(code=code):
|
||||
r = self.run_script(OLD_HYPRLAND='1', STATUS_EXIT=code)
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertIn('Using hyprlang dispatch syntax', r.stderr)
|
||||
|
||||
def test_unknown_config_provider_aborts(self):
|
||||
r = self.run_script(CONFIG_PROVIDER='unknown')
|
||||
self.assertNotEqual(r.returncode, 0)
|
||||
self.assertIn('Unsupported Hyprland config provider', r.stderr)
|
||||
self.assertEqual(self.switches(), [])
|
||||
|
||||
def test_dispatch_errors_reported_before_switch(self):
|
||||
for provider in ('lua', 'hyprlang'):
|
||||
for action in ('DPMS', 'focus'):
|
||||
for code in ('0', '7', '124'):
|
||||
with self.subTest(provider=provider, action=action, code=code):
|
||||
r = self.run_script(CONFIG_PROVIDER=provider,
|
||||
DISPATCH_FAIL=action, DISPATCH_EXIT=code)
|
||||
self.assertNotEqual(r.returncode, 0)
|
||||
self.assertIn(f'Hyprland {action} failed (exit {code})', r.stderr)
|
||||
self.assertIn(f'error: {action} rejected for HDMI-A-2', r.stderr)
|
||||
self.assertNotIn('Recovery completed', r.stderr)
|
||||
self.assertEqual(self.switches(), [])
|
||||
|
||||
def test_final_lua_refresh_failure_not_reported_as_success(self):
|
||||
r = self.run_script(CONFIG_PROVIDER='lua', DISPATCH_FAIL='focus', FINAL_REFRESH_FAIL='1')
|
||||
self.assertNotEqual(r.returncode, 0)
|
||||
self.assertEqual(self.switches(), ['2', '1'])
|
||||
self.assertIn('Final Hyprland refresh failed', r.stderr)
|
||||
self.assertIn('error: focus rejected for HDMI-A-2', r.stderr)
|
||||
self.assertNotIn('Recovery completed', r.stderr)
|
||||
|
||||
def test_invalid_vt(self):
|
||||
for vt in ('', '0', '64', '01', 'word', '99999999999999999'):
|
||||
with self.subTest(vt=vt):
|
||||
|
||||
Reference in new issue
Block a user