Skip to content

Commit

Permalink
Experimental screen scaling code, to adjust QT_SCALE_FACTOR env var a…
Browse files Browse the repository at this point in the history
…utomatically when changing screen DPI. This can be disabled in the "adjust_scaling_factor" settings file.
  • Loading branch information
jonoomph committed May 28, 2024
1 parent 170a51f commit 887049f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/settings/_default.settings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
"category": "General",
"setting": "unique_install_id"
},
{
"value": true,
"title": "",
"type": "hidden",
"category": "General",
"setting": "adjust_scaling_factor"
},
{
"value": "smileys-emotion",
"title": "",
Expand Down
24 changes: 24 additions & 0 deletions src/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3167,6 +3167,22 @@ def eventFilter(self, obj, event):
event.accept()
return super(MainWindow, self).eventFilter(obj, event)

def adjust_scaling(self):
"""Adjust scaling factor for new screen. This is primarily to adjust our
scaling factor to match the OS display scaling on the primary screen where
OpenShot is displayed."""
screen = get_app().primaryScreen()
logical_dpi = screen.logicalDotsPerInch()
physical_dpi = screen.physicalDotsPerInch()
scale_factor = logical_dpi / physical_dpi
os.environ['QT_SCALE_FACTOR'] = str(scale_factor)
log.info(f"Adjusted QT_SCALE_FACTOR factor dynamically to: {scale_factor}")

def on_screen_changed(self, new_screen):
"""Listen for screen changes"""
log.info(f"Detected screen change: {new_screen}")
self.adjust_scaling()

def __init__(self, *args):

# Create main window base class
Expand Down Expand Up @@ -3451,6 +3467,14 @@ def __init__(self, *args):
# Save settings
s.save()

# Listen for screen changes (i.e. High DPI to Low DPI screen)
if s.get("adjust_scaling_factor"):
log.info("Listen to screen display scaling changes...")
for screen in app.screens():
screen.logicalDotsPerInchChanged.connect(self.on_screen_changed)
else:
log.info("Ignore screen display scaling changes...")

# Refresh frame
QTimer.singleShot(100, self.refreshFrameSignal.emit)

Expand Down

0 comments on commit 887049f

Please sign in to comment.