Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ for m in get_monitors():
**Output**:

```python console
Monitor(x=3840, y=0, width=3840, height=2160, width_mm=1420, height_mm=800, name='HDMI-0', is_primary=False)
Monitor(x=0, y=0, width=3840, height=2160, width_mm=708, height_mm=399, name='DP-0', is_primary=True)
Monitor(x=3840, y=0, width=3840, height=2160, scale=1, width_mm=1420, height_mm=800, ppmm=(2.704225352112676, 2.7), name='HDMI-0', is_primary=False)
Monitor(x=0, y=0, width=3840, height=2160, scale=1, width_mm=708, height_mm=399, ppmm=(5.423728813559322, 5.413533834586466), name='DP-0', is_primary=True)
```

### Forcing environment
Expand Down
97 changes: 65 additions & 32 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages = [{ include = "screeninfo" }]
python = "^3.6.2"
dataclasses = { version = "*", python = "<3.7" }
Cython = { version = "*", platform = "darwin" }
pyobjc-framework-Cocoa = { version = "*", platform = "darwin" }
pyobjc-framework-Quartz = { version = "*", platform = "darwin" }

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
Expand Down
9 changes: 9 additions & 0 deletions screeninfo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ class Monitor:
y: int
width: int
height: int
scale: float = 1
width_mm: T.Optional[int] = None
height_mm: T.Optional[int] = None
name: T.Optional[str] = None
is_primary: T.Optional[bool] = None

@property
def ppmm(self) -> T.Optional[T.Tuple[float, float]]:
if not self.width_mm or not self.height_mm:
return None
return (self.width/self.width_mm, self.height/self.height_mm)

def __repr__(self) -> str:
return (
f"Monitor("
f"x={self.x}, y={self.y}, "
f"width={self.width}, height={self.height}, "
f"scale={self.scale}, "
f"width_mm={self.width_mm}, height_mm={self.height_mm}, "
f"ppmm={self.ppmm!r}, "
f"name={self.name!r}, "
f"is_primary={self.is_primary}"
f")"
Expand Down
13 changes: 10 additions & 3 deletions screeninfo/enumerators/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def check_primary(screens: T.Any, screen: T.Any) -> bool:


def enumerate_monitors() -> T.Iterable[Monitor]:
from AppKit import NSScreen
from AppKit import NSScreen, NSDeviceSize
from Quartz import CGDisplayScreenSize

screens = NSScreen.screens()

Expand All @@ -19,10 +20,16 @@ def enumerate_monitors() -> T.Iterable[Monitor]:
if callable(f):
f = f()

description = screen.deviceDescription()
width, height = description[NSDeviceSize].sizeValue()
width_mm, height_mm = CGDisplayScreenSize(description["NSScreenNumber"])
yield Monitor(
x=int(f.origin.x),
y=int(f.origin.y),
width=int(f.size.width),
height=int(f.size.height),
width=width,
height=height,
scale=screen.backingScaleFactor(),
width_mm=width_mm,
height_mm=height_mm,
is_primary=check_primary(screens, screen),
)
2 changes: 2 additions & 0 deletions tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_documentation(capsys) -> None:
y=0,
width=3840,
height=2160,
scale=1,
width_mm=1420,
height_mm=800,
name="HDMI-0",
Expand All @@ -48,6 +49,7 @@ def test_documentation(capsys) -> None:
y=0,
width=3840,
height=2160,
scale=1,
width_mm=708,
height_mm=399,
name="DP-0",
Expand Down