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