Exemplo n.º 1
0
def cmd_mirror(args):
        load_quartz()

        # Find the default values for _id and _mid
        ids = get_online_display_ids()
        main_id = Q.CGMainDisplayID()
        if len(ids) == 1:
                print 'There is only one display'
                return -6
        if args.master is None:
                _mid = main_id
        else:
                _mid = ids[args.master]
        if args.display is None:
                if _mid != main_id:
                        _id = main_id
                else:
                        _id = [i for i in ids if i != _mid][0]
        else:
                _id = ids[args.display]

        # Do the mirroring
        r, config = Q.CGBeginDisplayConfiguration(None)
        if(r != 0):
                print 'CGBeginDisplayConfiguration failed'
                return -3
        if(Q.CGConfigureDisplayMirrorOfDisplay(config, _id, _mid) != 0):
                print 'CGConfigureDisplayMirrorOfDisplay failed'
                return -7
        if(Q.CGCompleteDisplayConfiguration(
                        config,
                        Q.kCGConfigurePermanently if args.permanently
                                else Q.kCGConfigureForSession)):
                print 'CGCompleteDisplayConfiguration failed'
                return -8
Exemplo n.º 2
0
    def testFunctions(self):
        err, config = Quartz.CGBeginDisplayConfiguration(None)
        self.assertEqual(err, 0)
        self.assertIsInstance(config, Quartz.CGDisplayConfigRef)

        err = Quartz.CGConfigureDisplayFadeEffect(config, 0.1, 0.1, 1.0, 1.0,
                                                  1.0)
        self.assertEqual(err, 0)

        err, token = Quartz.CGAcquireDisplayFadeReservation(1.0, None)
        if err == 0:
            self.assertEqual(err, 0)
            self.assertIsInstance(token, int)

            err = Quartz.CGDisplayFade(token, 0.5, 0.0, 1.0, 1.0, 1.0, 1.0, 1)
            self.assertEqual(err, 0)

            err = Quartz.CGReleaseDisplayFadeReservation(token)

            # Testing if the api actually works as intended is not necessary,
            # don't bail out if the function is unhappy.
            # self.assertEqual(err, 0)
            self.assertIsInstance(err, int)

        v = Quartz.CGDisplayFadeOperationInProgress()
        self.assertIsInstance(v, int)
Exemplo n.º 3
0
def swapDisplays(display1, display2):
    """
    Swaps the position of two displays in global coordinate space.
    One display must be the Main display at the origin.  Both displays
    must be neigbors (share a common edge)
    """
    #   check to see if the two displays are neighbors
    #   ensure one display is the main display
    if display1.isMain:
        main = display1
        other = display2
    elif display2.isMain:
        main = display2
        other = display1
    else:
        raise DisplayError("neither display is primary display")

    #   determine relative location of secondary display
    mainOrigin = main.boundsOrigin
    otherOrigin = other.boundsOrigin
    mainSize = main.boundsSize
    otherSize = other.boundsSize

    if mainOrigin.x == otherOrigin.x:
        #   verically stacked
        if otherOrigin.y > mainOrigin.y:
            mainNewOrigin = (mainOrigin.x, otherSize.height)
        else:
            mainNewOrigin = (mainOrigin.x, -mainSize.height)
    elif mainOrigin.y == otherOrigin.y:
        #   horizontally stacked
        if otherOrigin.x > mainOrigin.x:
            mainNewOrigin = (otherSize.width, mainOrigin.y)
        else:
            mainNewOrigin = (-mainSize.width, mainOrigin.y)

    (error, configRef) = Quartz.CGBeginDisplayConfiguration(None)
    if error:
        raise DisplayError("Can not begin display configuration")

    error = Quartz.CGConfigureDisplayOrigin(configRef, main.displayID, *mainNewOrigin)
    if error:
        Quartz.CGCancelDisplayConfiguration(configRef)
        raise DisplayError(
            "Display \"{}\"\'s origin cannot be set to ({}, {})".format(
                main.tag, *mainNewOrigin))

    error = Quartz.CGConfigureDisplayOrigin(configRef, other.displayID, 0, 0)
    if error:
        Quartz.CGCancelDisplayConfiguration(configRef)
        raise DisplayError(
            "Display \"{}\"\'s origin cannot be set to ({}, {})".format(
                other.tag, 0, 0))

    Quartz.CGCompleteDisplayConfiguration(configRef, Quartz.kCGConfigurePermanently)
Exemplo n.º 4
0
    def setMirrorSource(self, mirrorDisplay):
        """
        :param mirrorDisplay: The Display which this Display will mirror.
            Input a NoneType to stop mirroring.
        """
        (error, configRef) = Quartz.CGBeginDisplayConfiguration(None)
        if error:
            raise DisplayError(
                "Display \"{}\" cannot be set to mirror display \"{}\"".format(self.tag, mirrorDisplay.tag))

        # Will be passed a None mirrorDisplay to disable mirroring. Cannot mirror self.
        if mirrorDisplay is None or mirrorDisplay.displayID == self.displayID:
            Quartz.CGConfigureDisplayMirrorOfDisplay(configRef, self.displayID, Quartz.kCGNullDirectDisplay)
        else:
            Quartz.CGConfigureDisplayMirrorOfDisplay(configRef, self.displayID, mirrorDisplay.displayID)

        Quartz.CGCompleteDisplayConfiguration(configRef, Quartz.kCGConfigurePermanently)
Exemplo n.º 5
0
def set_mode(display_id, mode, permanently=False):
        r, config = Q.CGBeginDisplayConfiguration(None) 
        if(r != 0):
                print 'CGBeginDisplayConfiguration failed'
                return -3
        if(Q.CGConfigureDisplayWithDisplayMode(
                        config,
                        display_id,
                        mode,
                        None) != 0):
                print 'CGConfigureDisplayWithDisplayMode failed'
                return -4
        if(Q.CGCompleteDisplayConfiguration(
                        config,
                        Q.kCGConfigurePermanently if permanently
                                else Q.kCGConfigureForSession)):
                print 'CGCompleteDisplayConfiguration failed'
                return -5
Exemplo n.º 6
0
    def setMode(self, mode):
        """
        :param mode: The Quartz "DisplayMode" interface to set this display to.
        """
        (error, configRef) = Quartz.CGBeginDisplayConfiguration(None)
        if error:
            raise DisplayError(
                "Display \"{}\"\'s resolution cannot be set to {}x{} at {} Hz".format(
                    self.tag, mode.width, mode.height, mode.refresh))

        error = Quartz.CGConfigureDisplayWithDisplayMode(configRef, self.displayID, mode.raw, None)
        if error:
            Quartz.CGCancelDisplayConfiguration(configRef)
            raise DisplayError(
                "Display \"{}\"\'s resolution cannot be set to {}x{} at {} Hz".format(
                    self.tag, mode.width, mode.height, mode.refresh))

        Quartz.CGCompleteDisplayConfiguration(configRef, Quartz.kCGConfigurePermanently)
Exemplo n.º 7
0
    def setOrigin(self, x, y):
        """
        This function may not make sense by itself.  The origin of
        all displays should be set at once.
        :param x: The desired x-coordinate for the upper-left corner of the display.
        :param y: The desired y-coordinate for the upper-left corner of the display.
        """
        (error, configRef) = Quartz.CGBeginDisplayConfiguration(None)
        if error:
            raise DisplayError(
                "Display \"{}\"\'s origin cannot be set to ({}, {})".format(
                    self.tag, x, y))

        error = Quartz.CGConfigureDisplayOrigin(configRef, self.displayID, x, y)
        if error:
            Quartz.CGCancelDisplayConfiguration(configRef)
            raise DisplayError(
                "Display \"{}\"\'s origin cannot be set to ({}, {})".format(
                    self.tag, x, y))

        Quartz.CGCompleteDisplayConfiguration(configRef, Quartz.kCGConfigurePermanently)
Exemplo n.º 8
0
def cmd_unmirror(args):
        load_quartz()
        
        # Find the display to be unmirrored
        ids = [i for i in get_online_display_ids()
                        if Q.CGDisplayIsInMirrorSet(i)]
        if len(ids) == 0:
                print 'There are no mirrored displays'
                return -9
        if args.display is None:
                main_id = Q.CGMainDisplayID()
                if main_id in ids:
                        _id = main_id
                else:
                        _id = ids[0]
        else:
                _id = get_online_display_ids()[args.display]
                if _id not in ids:
                        print 'The specified display is not in a mirroring set'
                        return -10

        # Do it
        r, config = Q.CGBeginDisplayConfiguration(None)
        if(r != 0):
                print 'CGBeginDisplayConfiguration failed'
                return -3
        if(Q.CGConfigureDisplayMirrorOfDisplay(config, _id,
                        Q.kCGNullDirectDisplay) != 0):
                print 'CGConfigureDisplayMirrorOfDisplay failed'
                return -11
        if(Q.CGCompleteDisplayConfiguration(
                        config,
                        Q.kCGConfigurePermanently if args.permanently
                                else Q.kCGConfigureForSession)):
                print 'CGCompleteDisplayConfiguration failed'
                return -12
Exemplo n.º 9
0
    def testTypes(self):
        self.assertIsOpaquePointer(Quartz.CGDisplayConfigRef)

        err, config = Quartz.CGBeginDisplayConfiguration(None)
        self.assertEqual(err, 0)
        self.assertIsInstance(config, Quartz.CGDisplayConfigRef)

        err = Quartz.CGConfigureDisplayOrigin(config, Quartz.CGMainDisplayID(),
                                              0, 0)
        self.assertEqual(err, 0)

        err = Quartz.CGConfigureDisplayMode(
            config,
            Quartz.CGMainDisplayID(),
            Quartz.CGDisplayAvailableModes(Quartz.CGMainDisplayID())[0],
        )
        self.assertEqual(err, 0)

        err = Quartz.CGConfigureDisplayStereoOperation(
            config, Quartz.CGMainDisplayID(), False, False)
        self.assertEqual(err, 0)

        err = Quartz.CGConfigureDisplayMirrorOfDisplay(
            config, Quartz.CGMainDisplayID(), Quartz.CGMainDisplayID())
        self.assertIsInstance(err, int)

        err = Quartz.CGCancelDisplayConfiguration(config)
        self.assertEqual(err, 0)
        config = None

        myInfo = object()
        info = []

        def reconfig(display, flags, userInfo):
            self.assertIsInstance(display, int)
            self.assertIsInstance(flags, int)
            self.assertTrue(userInfo is myInfo)
            info.append((display, flags, userInfo))

        try:
            err, config = Quartz.CGBeginDisplayConfiguration(None)
            self.assertEqual(err, 0)
            self.assertIsInstance(config, Quartz.CGDisplayConfigRef)

            err = Quartz.CGDisplayRegisterReconfigurationCallback(
                reconfig, myInfo)
            self.assertEqual(err, 0)

            err = Quartz.CGConfigureDisplayMode(
                config,
                Quartz.CGMainDisplayID(),
                Quartz.CGDisplayAvailableModes(Quartz.CGMainDisplayID())[0],
            )

            Quartz.CGCompleteDisplayConfiguration(
                config, Quartz.kCGConfigureForAppOnly)

        finally:
            err = Quartz.CGDisplayRemoveReconfigurationCallback(
                reconfig, myInfo)
            self.assertEqual(err, 0)
            ln = len(info)

            Quartz.CGRestorePermanentDisplayConfiguration()

            self.assertEqual(len(info), ln)

        err = Quartz.CGDisplaySetStereoOperation(Quartz.CGMainDisplayID(),
                                                 False, False,
                                                 Quartz.kCGConfigureForAppOnly)
        self.assertIsInstance(err, int)

        v = Quartz.CGDisplayIsActive(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsAsleep(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsOnline(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsMain(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsBuiltin(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsInMirrorSet(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsAlwaysInMirrorSet(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsInHWMirrorSet(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayUsesOpenGLAcceleration(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayMirrorsDisplay(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIsStereo(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayPrimaryDisplay(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayUnitNumber(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayVendorNumber(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayModelNumber(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplaySerialNumber(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayIOServicePort(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, int)

        v = Quartz.CGDisplayScreenSize(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, Quartz.CGSize)

        v = Quartz.CGDisplayRotation(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, float)

        v = Quartz.CGDisplayCopyColorSpace(Quartz.CGMainDisplayID())
        self.assertIsInstance(v, Quartz.CGColorSpaceRef)
Exemplo n.º 10
0
    )
    if Quartz.CGDisplayIsBuiltin(id):
        builtinDisplayId = id
    elif id != mainExternalDisplayId:
        otherExternalDisplayId = id

print(
    "Swapping external monitor #"
    + str(mainExternalDisplayId)
    + " with #"
    + str(otherExternalDisplayId)
    + ", builtin is #"
    + str(builtinDisplayId)
)

(configErr, config) = Quartz.CGBeginDisplayConfiguration(None)

# Move the non-main display to 0,0
Quartz.CGConfigureDisplayOrigin(config, int(otherExternalDisplayId), 0, 0)

# Move the main display to the right
Quartz.CGConfigureDisplayOrigin(
    config,
    int(mainExternalDisplayId),
    int(Quartz.CGDisplayPixelsWide(int(otherExternalDisplayId))),
    0,
)

# It doesn't seem to be necessary to reposition the laptop display
# so I've commented this out.
# # Move the laptop below and to the left
Exemplo n.º 11
0
#!/usr/bin/python
# Must use system python
import sys  # make decisions based on system configuration
import warnings  # control warning settings for
import abc  # allows use of abstract classes
import objc  # access Objective-C functions and variables
import CoreFoundation  # work with Objective-C data types
import Quartz  # work with system graphics

(error, config_ref) = Quartz.CGBeginDisplayConfiguration(None)

(error, display_ids, count) = Quartz.CGGetOnlineDisplayList(32, None, None)
for display_id in display_ids:
    print(display_id)
    print(str(
        Quartz.CGDisplayCopyColorSpace(display_id))).split("; ")[2].replace(
            ")", "")
    print(Quartz.CGDisplayPixelsWide(display_id))
    print(Quartz.CGDisplayBounds(display_id))
    print("")

for display_id in display_ids:
    if Quartz.CGDisplayIsBuiltin(display_id):
        print("Built-in Display")
        print(display_id)
        Quartz.CGConfigureDisplayOrigin(config_ref, display_id, -1440, 900)
    else:
        if Quartz.CGDisplayIsMain(display_id):
            print("Main Display< Move it")
            print(display_id)
            Quartz.CGConfigureDisplayOrigin(config_ref, display_id, 3200, 0)