Skip to content

Commit f2fbfe0

Browse files
committed
add xsettingsd changes for hot reloading of screen scaling
1 parent 553b869 commit f2fbfe0

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

src/selkies/selkies.py

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,13 @@ def parse_dri_node_to_index(node_path: str) -> int:
450450
return -1
451451

452452
async def _run_xrdb(dpi_value, logger):
453-
"""Helper function to apply DPI via xrdb."""
453+
"""Helper function to apply DPI via xrdb and xsettingsd."""
454454
if not which("xrdb"):
455455
logger.debug("xrdb not found. Skipping Xresources DPI setting.")
456456
return False
457-
457+
458458
xresources_path_str = os.path.expanduser("~/.Xresources")
459-
try:
459+
try:
460460
with open(xresources_path_str, "w") as f:
461461
f.write(f"Xft.dpi: {dpi_value}\n")
462462
logger.info(f"Wrote 'Xft.dpi: {dpi_value}' to {xresources_path_str}.")
@@ -468,14 +468,58 @@ async def _run_xrdb(dpi_value, logger):
468468
stderr=subprocess.PIPE
469469
)
470470
stdout, stderr = await process.communicate()
471-
if process.returncode == 0:
471+
472+
xrdb_success = process.returncode == 0
473+
if xrdb_success:
472474
logger.info(f"Successfully loaded {xresources_path_str} using xrdb.")
473-
return True
474475
else:
475476
logger.warning(f"Failed to load {xresources_path_str} using xrdb. RC: {process.returncode}, Error: {stderr.decode().strip()}")
476-
return False
477+
478+
xsettingsd_config_path = os.path.expanduser("~/.xsettingsd")
479+
xsettings_dpi = dpi_value * 1024
480+
481+
config_content = (
482+
"Xft/Antialias 1\n"
483+
"Xft/Hinting 1\n"
484+
"Xft/HintStyle \"hintfull\"\n"
485+
"Xft/RGBA \"rgb\"\n"
486+
f"Xft/DPI {xsettings_dpi}\n"
487+
)
488+
489+
with open(xsettingsd_config_path, "w") as f:
490+
f.write(config_content)
491+
logger.info(f"Wrote font and DPI settings to {xsettingsd_config_path}.")
492+
493+
if not which("pgrep") or not which("kill"):
494+
logger.debug("pgrep or kill not found. Skipping xsettingsd reload.")
495+
else:
496+
pgrep_proc = await subprocess.create_subprocess_exec(
497+
"pgrep", "xsettingsd",
498+
stdout=subprocess.PIPE, stderr=subprocess.PIPE
499+
)
500+
pgrep_stdout, _ = await pgrep_proc.communicate()
501+
502+
if pgrep_proc.returncode == 0:
503+
pid_output = pgrep_stdout.decode().strip()
504+
if pid_output:
505+
pid = pid_output.splitlines()[0]
506+
logger.info(f"Found xsettingsd process with PID: {pid}.")
507+
kill_proc = await subprocess.create_subprocess_exec(
508+
"kill", "-1", pid,
509+
stdout=subprocess.PIPE, stderr=subprocess.PIPE
510+
)
511+
_, kill_stderr = await kill_proc.communicate()
512+
if kill_proc.returncode == 0:
513+
logger.info(f"Sent SIGHUP to xsettingsd process {pid} to reload config.")
514+
else:
515+
logger.warning(f"Failed to send SIGHUP to xsettingsd process {pid}. Error: {kill_stderr.decode().strip()}")
516+
else:
517+
logger.info("xsettingsd process not found. Skipping reload.")
518+
519+
return xrdb_success
520+
477521
except Exception as e:
478-
logger.error(f"Error updating or loading Xresources: {e}")
522+
logger.error(f"Error updating or loading DPI settings: {e}")
479523
return False
480524

481525
async def _run_xfconf(dpi_value, logger):

0 commit comments

Comments
 (0)