Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0.93, 2026/XX/XX -- ALL: Replaced bare `except:` clauses with `except Exception:`, preventing accidental suppression of system-exit signals (KeyboardInterrupt, SystemExit) during error handling.
0.8, 2023/10/11 -- ALL: Added saveSetup() and restoreSetup(). Fixed / Improved watchdog (especially in Linux). Fixed / improved setPosition() method
LINUX: Added ewmhlib as separate module. Fixed watchdog (freezing randomly invoking screen_resources and get_output_info), fixed workarea crash (some apps/environments do not set it), improved to work almost fine in Manjaro/KDE, avoid crashing in Wayland for "fake" :1 display (though module won't likely work)
WIN32: Fixed dev.StateFlags returning weird values for multi-monitor. Fixed GetAwarenessFromDpiAwarenessContext not supported on Windows Server
Expand Down
8 changes: 4 additions & 4 deletions src/pymonctl/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def restoreSetup(setup: List[Tuple[Monitor, ScreenValue]]):
if not monitor.isAttached:
try:
monitor.attach()
except:
except Exception:
continue
if monitor.isAttached:
if monitor.isSuspended or not monitor.isOn:
Expand Down Expand Up @@ -743,7 +743,7 @@ def getMonitors(self) -> list[Monitor]:
for screen in self._screens.keys():
try:
monitors.append(Monitor(self._screens[screen]["id"]))
except:
except Exception:
pass
return monitors

Expand Down Expand Up @@ -826,7 +826,7 @@ def plugListenerUnregister(monitorCountChanged: Callable[[List[str], dict[str, S
try:
objIndex = _plugListeners.index(monitorCountChanged)
_plugListeners.pop(objIndex)
except:
except Exception:
pass
global _changeListeners
global _updateRequested
Expand Down Expand Up @@ -866,7 +866,7 @@ def changeListenerUnregister(monitorPropsChanged: Callable[[List[str], dict[str,
try:
objIndex = _changeListeners.index(monitorPropsChanged)
_changeListeners.pop(objIndex)
except:
except Exception:
pass
global _plugListeners
global _updateRequested
Expand Down
28 changes: 14 additions & 14 deletions src/pymonctl/_pymonctl_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def setPosition(self, relativePos: Union[int, Position, Point, Tuple[int, int]],
try:
index = monKeys.index(self.name)
monKeys.pop(index)
except:
except Exception:
return
arrangement[self.name] = {"relativePos": relativePos, "relativeTo": None}
xOffset = monitor.width_in_pixels
Expand Down Expand Up @@ -428,7 +428,7 @@ def brightness(self) -> Optional[int]:
if ret:
try:
value = int(float(ret) * 100)
except:
except Exception:
pass
return value

Expand All @@ -448,7 +448,7 @@ def contrast(self) -> Optional[int]:
try:
r, g, b = ret.split(":")
value = int((((1 / (float(r) or 1)) + (1 / (float(g) or 1)) + (1 / (float(b) or 1))) / 3) * 100)
except:
except Exception:
pass
return value

Expand Down Expand Up @@ -608,7 +608,7 @@ def detach(self, permanent: bool = False):
try:
# randr.set_crtc_config() fails in Cinnamon
randr.set_crtc_config(self.display, crtc, Xlib.X.CurrentTime, crtcInfo.x, crtcInfo.y, 0, crtcInfo.rotation, [])
except:
except Exception:
cmd = "xrandr --output %s --mode %sx%s" % (self.name, 0, 0)
_, _ = _runProc(cmd)

Expand Down Expand Up @@ -640,7 +640,7 @@ def _GNOME_isScalingGlobal() -> Optional[bool]:
return bool("scale-monitor-framebuffer" not in proc.stdout)
else:
return bool("x11-randr-fractional-scaling" not in proc.stdout)
except:
except Exception:
pass
return None

Expand All @@ -656,7 +656,7 @@ def _GNOME_setGlobalScaling(setGlobal=True):
proc = subprocess.run("grep -sl mutter /proc/*/maps", text=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if "/maps" in proc.stdout:
cmd = '''gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"'''
except:
except Exception:
pass
else:
cmd = '''gsettings set org.gnome.mutter experimental-features "['x11-randr-fractional-scaling']"'''
Expand All @@ -670,7 +670,7 @@ def _GNOME_getScalingFactor() -> Optional[int]:
if "WindowScalingFactor" in ret:
try:
return int(ret.split("WindowScalingFactor': <")[1][0])
except:
except Exception:
pass
return None

Expand All @@ -696,7 +696,7 @@ def _GNOME_getScalingFactor() -> Optional[int]:
#
# try:
# import dbus
# except:
# except Exception:
# return {}, {}, {}
#
# namespace = "org.gnome.Mutter.DisplayConfig"
Expand Down Expand Up @@ -742,7 +742,7 @@ def _GNOME_getScalingFactor() -> Optional[int]:
#
# try:
# import dbus
# except:
# except Exception:
# return
#
# namespace = "org.gnome.Mutter.DisplayConfig"
Expand Down Expand Up @@ -794,7 +794,7 @@ def _scale(name: str) -> Optional[Tuple[float, float]]:
h = int(b)
r = float(lines[1].replace("+", "").replace("*", ""))
value = DisplayMode(w, h, r)
except:
except Exception:
pass
if value:
monitors = _XgetMonitors(name)
Expand All @@ -817,7 +817,7 @@ def _runProc(cmd: str):
# Some commands will take some time to be executed and return required value
proc = subprocess.run(cmd, text=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #, timeout=3)
return proc.returncode, proc.stdout
except:
except Exception:
pass
return -1, ""

Expand Down Expand Up @@ -845,7 +845,7 @@ def _getMonitorsData(handle: Optional[int] = None) -> (
display, screen, root = rootData
try:
mons = randr.get_monitors(root).monitors
except:
except Exception:
# In Cinnamon randr extension has no get_monitors() method (?!?!?!?)
mons = _RgetAllMonitors()
stopSearching = True
Expand Down Expand Up @@ -885,7 +885,7 @@ def _XgetAllMonitors(name: str = ""):
display, screen, root = rootData
try:
mons = randr.get_monitors(root).monitors
except:
except Exception:
# In Cinnamon randr extension has no get_monitors() method (?!?!?!?)
mons = _RgetAllMonitors()
stopSearching = True
Expand Down Expand Up @@ -940,7 +940,7 @@ def _RgetMonitorsInfo(activeOnly: bool = True):
y = parts[2]
w, h = parts[0].split("x")
monInfo.append((name, primary, int(x), int(y), int(w), int(h)))
except:
except Exception:
pass
return monInfo

Expand Down
34 changes: 17 additions & 17 deletions src/pymonctl/_pymonctl_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _getAllMonitorsDict() -> dict[str, ScreenValue]:

try:
name = screen.localizedName()
except:
except Exception:
# In older macOS, screen doesn't have localizedName() method
name = "Display" + "_" + str(displayId)
is_primary = Quartz.CGDisplayIsMain(displayId) == 1
Expand Down Expand Up @@ -246,7 +246,7 @@ def setPosition(self, relativePos: Union[int, Position, Point, Tuple[int, int]],
try:
index = monKeys.index(self.name)
monKeys.pop(index)
except:
except Exception:
return
arrangement[self.name] = {"relativePos": Position.PRIMARY, "relativeTo": None}
xOffset = self.screen.frame().size.width
Expand Down Expand Up @@ -379,7 +379,7 @@ def setOrientation(self, orientation: Optional[Union[int, Orientation]]):

try:
ret = self._iokit.IOServiceRequestProbe(self._ioservice, options)
except:
except Exception:
ret = 1
if ret != 0:
self._useIOOrientation = False
Expand Down Expand Up @@ -408,7 +408,7 @@ def brightness(self) -> Optional[int]:
value = ctypes.c_float()
try:
ret = self._ds.DisplayServicesGetBrightness(self.handle, ctypes.byref(value))
except:
except Exception:
ret = 1
if ret == 0:
res = value.value
Expand All @@ -423,7 +423,7 @@ def brightness(self) -> Optional[int]:
value = ctypes.c_double()
try:
ret = self._cd.CoreDisplay_Display_GetUserBrightness(self.handle, ctypes.byref(value))
except:
except Exception:
ret = 1
if ret == 0:
res = value.value
Expand All @@ -439,7 +439,7 @@ def brightness(self) -> Optional[int]:
value = ctypes.c_float()
try:
ret = self._iokit.IODisplayGetFloatParameter(self._ioservice, 0, kDisplayBrightnessKey, ctypes.byref(value))
except:
except Exception:
ret = 1
if ret == 0:
res = value.value
Expand All @@ -465,7 +465,7 @@ def setBrightness(self, brightness: Optional[int]):
ret = 0
if self._ds.DisplayServicesCanChangeBrightness(self.handle):
ret = self._ds.DisplayServicesSetBrightness(self.handle, value)
except:
except Exception:
ret = 1
if ret != 0:
self._useDS = False
Expand All @@ -478,7 +478,7 @@ def setBrightness(self, brightness: Optional[int]):
value = ctypes.c_double(brightness / 100)
try:
ret = self._cd.CoreDisplay_Display_SetUserBrightness(self.handle, value)
except:
except Exception:
ret = 1
if ret != 0:
self._useCD = False
Expand All @@ -492,7 +492,7 @@ def setBrightness(self, brightness: Optional[int]):
value = ctypes.c_float(brightness / 100)
try:
ret = self._iokit.IODisplaySetFloatParameter(self._ioservice, 0, kDisplayBrightnessKey, value)
except:
except Exception:
ret = 1
if ret != 0:
self._useIOBrightness = False
Expand All @@ -508,7 +508,7 @@ def contrast(self) -> Optional[int]:
CG.CGGetDisplayTransferByFormula(self.handle, None, None, None, None, None, None, None, None, None))
if ret == 0:
contrast = int((float(redGamma) + float(greenGamma) + float(blueGamma)) / 3 * 100)
except:
except Exception:
pass
return contrast

Expand Down Expand Up @@ -608,7 +608,7 @@ def turnOn(self):
cmd = "caffeinate -u -t 2"
try:
_ = subprocess.run(cmd, text=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1)
except:
except Exception:
pass

def turnOff(self):
Expand All @@ -623,7 +623,7 @@ def suspend(self):
cmd = "pmset displaysleepnow"
try:
_ = subprocess.run(cmd, text=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1)
except:
except Exception:
pass

@property
Expand Down Expand Up @@ -651,7 +651,7 @@ def _getName(displayId: int, screen: Optional[AppKit.NSScreen] = None):
break
try:
scrName = cast(AppKit.NSScreen, screen).localizedName() + "_" + str(displayId)
except:
except Exception:
# In older macOS, screen doesn't have localizedName() method
scrName = "Display" + "_" + str(displayId)
return scrName
Expand Down Expand Up @@ -711,7 +711,7 @@ def _loadDisplayServices():
# Display Services Framework can be used in modern systems. It takes A LOT to load
try:
ds: ctypes.CDLL = ctypes.cdll.LoadLibrary('/System/Library/PrivateFrameworks/DisplayServices.framework/DisplayServices')
except:
except Exception:
return None
return ds

Expand All @@ -725,7 +725,7 @@ def _loadCoreDisplay():
cd: ctypes.CDLL = ctypes.cdll.LoadLibrary(lib)
cd.CoreDisplay_Display_SetUserBrightness.argtypes = [ctypes.c_int, ctypes.c_double]
cd.CoreDisplay_Display_GetUserBrightness.argtypes = [ctypes.c_int, ctypes.c_void_p]
except:
except Exception:
return None
return cd

Expand Down Expand Up @@ -762,7 +762,7 @@ class _CFString(ctypes.Structure):

try:
service: int = Quartz.CGDisplayIOServicePort(displayID)
except:
except Exception:
service = 0

# Check if this works in an actual macOS (preferably in several versions)
Expand Down Expand Up @@ -800,7 +800,7 @@ class _CFString(ctypes.Structure):

if service:
return iokit, CF, service
except:
except Exception:
pass

return None, None, None
Expand Down
Loading
Loading