Exemplo n.º 1
0
int main ( int argc, const char * argv[])
{
    CGDirectDisplayID displays[ MAX_DISPLAYS ];
    CGDisplayCount    displayCount = 0;
    
    CGDisplayErr err =
    CGGetOnlineDisplayList( MAX_DISPLAYS, displays, &displayCount );
    
    if ( err == kCGErrorSuccess ) {
        int i;
        
        for ( i = 0; i < displayCount; i++ ) {
            io_service_t service = CGDisplayIOServicePort( displays[ i ]);
            
            if ( service )
                IOServiceRequestProbe( service, kIOFBUserRequestProbe );
        }
    } else {
        fprintf( stderr, "CGGetOnlineDisplayList returned error code %d\n",
                 ( int )err );
        return ( int )err;
    }

    
    return EXIT_SUCCESS;
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
    int  i;
    long angle = 0;
   
    io_service_t      service;
    CGDisplayErr      dErr;
    CGDirectDisplayID targetDisplay = 0;
    IOOptionBits      options;
   
    while ((i = getopt(argc, argv, "d:limr:")) != -1) {
        switch (i) {
        case 'd':
            targetDisplay = (CGDirectDisplayID)strtol(optarg, NULL, 16);
            if (targetDisplay == 0)
                targetDisplay = CGMainDisplayID();
            break;
        case 'l':
            listDisplays();
            break;
        case 'i':
            infoDisplays();
            break;
        case 'm':
            setMainDisplay(targetDisplay);
            break;
        case 'r':
            angle = strtol(optarg, NULL, 10);
            break;
        default:
            break;
        }
    }
   
    if (targetDisplay == 0)
        usage();
   
    options = angle2options(angle);
   
    // Get the I/O Kit service port of the target display
    // Since the port is owned by the graphics system, we should not destroy it
    service = CGDisplayIOServicePort(targetDisplay);
   
    // We will get an error if the target display doesn't support the
    // kIOFBSetTransform option for IOServiceRequestProbe()
    dErr = IOServiceRequestProbe(service, options);
    if (dErr != kCGErrorSuccess) {
        fprintf(stderr, "IOServiceRequestProbe: error %d\n", dErr);
        exit(1);
    }
   
    exit(0);
}
Exemplo n.º 3
0
int main(int argc, char * argv[])
{
    io_service_t        service;
    CGError             err;
    int                 i;
    CGDisplayCount      max;
    CGDirectDisplayID   displayIDs[8];
    uint32_t            mask;
    IOOptionBits        options;
    CFNumberRef         num;
    SInt32              value;

    err = CGGetOnlineDisplayList(8, displayIDs, &max);
    if(err != kCGErrorSuccess)
        exit(1);
    if(max > 8)
        max = 8;

    if( argc < 2)
        options = kIOFBUserRequestProbe;
    else
        options = strtol( argv[1], 0, 0 );

    if (strstr(argv[0], "rotate"))
    {
        switch (options)
        {
            case 90:
              options = kIOFBSetTransform | (kIOScaleRotate90 << 16);
              break;
            case 180:
              options = kIOFBSetTransform | (kIOScaleRotate180 << 16);
              break;
            case 270:
              options = kIOFBSetTransform | (kIOScaleRotate270 << 16);
              break;
            case 0:
            default:
              options = kIOFBSetTransform | (kIOScaleRotate0 << 16);
              break;
        }
    }

    if( argc < 3)
        mask = 0xffffffff;
    else
        mask = strtol( argv[2], 0, 0 );

    for(i = 0; i < max; i++ )
    {
        if (!(mask & (1 << i)))
            continue;

        service = CGDisplayIOServicePort(displayIDs[i]);


        num = (CFNumberRef) IORegistryEntryCreateCFProperty( service, 
                                                                CFSTR(kIOFBTransformKey),
                                                                kCFAllocatorDefault, kNilOptions);
        if (num)
          CFNumberGetValue( num, kCFNumberSInt32Type, (SInt32 *) &value );
        else
          value = 0;

        value &= kIOScaleRotateFlags;

        printf("Display %p: current transform: ", displayIDs[i]);

        switch (value)
        {
            case kIOScaleRotate90:
              printf("90\n");
              break;

            case kIOScaleRotate180:
              printf("180\n");
              break;

            case kIOScaleRotate270:
              printf("270\n");
              break;

            case kIOScaleRotate0:
            default:
              printf("0\n");
              break;
        }


        num = (CFNumberRef) IORegistryEntryCreateCFProperty( service, 
                                                                CFSTR(kIOFBProbeOptionsKey),
                                                                kCFAllocatorDefault, kNilOptions);
        if (num)
          CFNumberGetValue( num, kCFNumberSInt32Type, (SInt32 *) &value );
        else
          value = 0;
        printf("Display %p: does %ssupport kIOFBSetTransform\n", displayIDs[i], value & kIOFBSetTransform ? "" : "not ");

        if (value & kIOFBSetTransform)
        {
          err = IOServiceRequestProbe(service, options );
          printf("Display %p: IOServiceRequestProbe(%d)\n", displayIDs[i], err);
        }
    }
    
    exit(0);
    return(0);
}