@@ -250,22 +250,16 @@ class USEROBJECTFLAGS(ctypes.Structure):
250
250
# process not running under the same user id as the current console
251
251
# user. To avoid that, raise an exception if the window manager
252
252
# connection is not available.
253
- from ctypes import cdll , c_int , pointer , Structure
254
- from ctypes . util import find_library
255
-
256
- app_services = cdll . LoadLibrary ( find_library ( "ApplicationServices" ) )
257
-
258
- if app_services . CGMainDisplayID () == 0 :
259
- reason = "gui tests cannot run without OS X window manager"
253
+ import subprocess
254
+ try :
255
+ rc = subprocess . run ([ "launchctl" , "managername" ],
256
+ capture_output = True , check = True )
257
+ managername = rc . stdout . decode ( "utf-8" ). strip ()
258
+ except subprocess . CalledProcessError :
259
+ reason = "unable to detect macOS launchd job manager"
260
260
else :
261
- class ProcessSerialNumber (Structure ):
262
- _fields_ = [("highLongOfPSN" , c_int ),
263
- ("lowLongOfPSN" , c_int )]
264
- psn = ProcessSerialNumber ()
265
- psn_p = pointer (psn )
266
- if ( (app_services .GetCurrentProcess (psn_p ) < 0 ) or
267
- (app_services .SetFrontProcess (psn_p ) < 0 ) ):
268
- reason = "cannot run without OS X gui process"
261
+ if managername != "Aqua" :
262
+ reason = f"{ managername = } -- can only run in a macOS GUI session"
269
263
270
264
# check on every platform whether tkinter can actually do anything
271
265
if not reason :
0 commit comments