void praat_reportGraphicalProperties () {
	MelderInfo_open ();
	MelderInfo_writeLine (U"Graphical properties of this edition of Praat on this computer:\n");
	double x, y, width, height;
	Gui_getWindowPositioningBounds (& x, & y, & width, & height);
	MelderInfo_writeLine (U"Window positioning area: x = ", x, U", y = ", y,
		U", width = ", width, U", height = ", height);
	#if defined (macintosh)
		CGDirectDisplayID screen = CGMainDisplayID ();
		CGSize screenSize_mm = CGDisplayScreenSize (screen);
		double diagonal_mm = sqrt (screenSize_mm. width * screenSize_mm. width + screenSize_mm. height * screenSize_mm. height);
		double diagonal_inch = diagonal_mm / 25.4;
		MelderInfo_writeLine (U"\nScreen size: ", screenSize_mm. width, U" x ", screenSize_mm. height,
			U" mm (diagonal ", Melder_fixed (diagonal_mm, 1), U" mm = ", Melder_fixed (diagonal_inch, 1), U" inch)");
		size_t screenWidth_pixels = CGDisplayPixelsWide (screen);
		size_t screenHeight_pixels = CGDisplayPixelsHigh (screen);
		MelderInfo_writeLine (U"Screen \"resolution\": ", screenWidth_pixels, U" x ", screenHeight_pixels, U" pixels");
		double resolution = 25.4 * screenWidth_pixels / screenSize_mm. width;
		MelderInfo_writeLine (U"Screen resolution: ", Melder_fixed (resolution, 1), U" pixels/inch");
	#elif defined (_WIN32)
		/*for (int i = 0; i <= 88; i ++)
			MelderInfo_writeLine (U"System metric ", i, U": ", GetSystemMetrics (i));*/
	#endif
	MelderInfo_close ();
}
Esempio n. 2
0
void wxDisplaySizeMM(int *width, int *height)
{
    CGSize size = CGDisplayScreenSize(CGMainDisplayID());
    if ( width )
        *width = (int)size.width ;
    if ( height )
        *height = (int)size.height;
}
Esempio n. 3
0
Status GetMonitorSize(int& width_mm, int& height_mm)
{
	CGSize screenSize = CGDisplayScreenSize(kCGDirectMainDisplay);

	if (screenSize.width == 0 || screenSize.height == 0)
		return ERR::FAIL;

	width_mm = screenSize.width;
	height_mm = screenSize.height;

	return INFO::OK;
}
Esempio n. 4
0
// Pixels-pr-mm.
SbVec2f
SoOffscreenCGData::getResolution(void)
{
#ifdef COIN_MACOS_10_3
  CGDirectDisplayID display = CGMainDisplayID();
  CGSize size = CGDisplayScreenSize(display);
  return SbVec2f(CGDisplayPixelsWide(display)/size.width,
                 CGDisplayPixelsHigh(display)/size.height)l
#else
  return SbVec2f(72.0f / 25.4f, 72.0f / 25.4f); // fall back to 72dpi
#endif
}
Esempio n. 5
0
QSize UIDisplay::GetPhysicalSizePriv(void)
{
    CocoaAutoReleasePool pool;

    QSize size(0, 0);

    CGDirectDisplayID disp = GetOSXDisplay(m_widget->winId());
    if (!disp)
        return size;

    CGSize size_in_mm = CGDisplayScreenSize(disp);
    return QSize((uint)size_in_mm.width, (uint)size_in_mm.height);
}
Esempio n. 6
0
File: gdi.c Progetto: AndreRH/wine
/**********************************************************************
 *              device_init
 *
 * Perform initializations needed upon creation of the first device.
 */
static void device_init(void)
{
    CGDirectDisplayID mainDisplay = CGMainDisplayID();
    CGSize size_mm = CGDisplayScreenSize(mainDisplay);
    CGDisplayModeRef mode = CGDisplayCopyDisplayMode(mainDisplay);

    check_retina_status();

    /* Initialize device caps */
    horz_size = size_mm.width;
    vert_size = size_mm.height;

    bits_per_pixel = 32;
    if (mode)
    {
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);

        horz_res = CGDisplayModeGetWidth(mode);
        vert_res = CGDisplayModeGetHeight(mode);

        if (pixelEncoding)
        {
            if (CFEqual(pixelEncoding, CFSTR(IO32BitDirectPixels)))
                bits_per_pixel = 32;
            else if (CFEqual(pixelEncoding, CFSTR(IO16BitDirectPixels)))
                bits_per_pixel = 16;
            else if (CFEqual(pixelEncoding, CFSTR(IO8BitIndexedPixels)))
                bits_per_pixel = 8;
            CFRelease(pixelEncoding);
        }

        CGDisplayModeRelease(mode);
    }
    else
    {
        horz_res = CGDisplayPixelsWide(mainDisplay);
        vert_res = CGDisplayPixelsHigh(mainDisplay);
    }

    if (retina_on)
    {
        horz_res *= 2;
        vert_res *= 2;
    }

    compute_desktop_rect();
    desktop_horz_res = desktop_rect.size.width;
    desktop_vert_res = desktop_rect.size.height;

    device_data_valid = TRUE;
}
Esempio n. 7
0
//--------------------------------------------------------------
// initialize display.  
void mgOSXServices::initDisplay()
{
  // build error string if library is unknown choice
  mgString libraryChoices;

  // for each supported library, try to initialize it
  m_support = NULL;
  BOOL triedLibrary = false;

#ifdef SUPPORT_GL33
  libraryChoices += "\"OpenGL3.3\" ";
  if (m_support == NULL && (m_library.equalsIgnoreCase("OpenGL3.3") || m_library.isEmpty()))
  {
    triedLibrary = true;
    mgOSXGL33Support* gl33 = new mgOSXGL33Support();

    // requested gl33 attributes
    gl33->m_fullscreen = m_fullscreen;
    gl33->m_multiSample = m_multiSample;
    gl33->m_swapImmediate = m_swapImmediate;

    if (gl33->initDisplay())
    {
      m_libraryFound = MG_LIBRARY_OPENGL33;
      m_support = gl33;
    }
    else delete gl33;
  }
#endif

#ifdef SUPPORT_GL21
  libraryChoices += "\"OpenGL2.1\" ";
  if (m_support == NULL && (m_library.equalsIgnoreCase("OpenGL2.1") || m_library.isEmpty()))
  {
    triedLibrary = true;
    mgOSXGL21Support* gl21 = new mgOSXGL21Support();

    // requested gl21 attributes
    gl21->m_fullscreen = m_fullscreen;
    gl21->m_multiSample = m_multiSample;
    gl21->m_swapImmediate = m_swapImmediate;

    if (gl21->initDisplay())
    {
      m_libraryFound = MG_LIBRARY_OPENGL21;
      m_support = gl21;
    }
    else delete gl21;
  }
#endif

  // if display initialization failed, throw exception
  if (m_support == NULL)
  {
    // if no library specified
    if (m_library.isEmpty())
      throw new mgErrorMsg("winNoLibrary", "libraries", "%s", (const char*) libraryChoices);

    // library specified could not be initialized
    if (triedLibrary)
      throw new mgErrorMsg("winBadLibrary", "library", "%s", (const char*) m_library);

    // library specified was not supported
    throw new mgErrorMsg("winWrongLibrary", "library,libraries", "%s,%s", 
      (const char*) m_library, (const char*) libraryChoices);
  }

  // save actual gl33 attributes
  m_depthBits = m_support->m_depthBits;
  m_fullscreen = m_support->m_fullscreen;
  m_multiSample = m_support->m_multiSample;
  m_swapImmediate = m_support->m_swapImmediate;

  m_support->setGraphicsSize(m_windowWidth, m_windowHeight);

  // finish display init from system state
  size_t width = CGDisplayPixelsWide(CGMainDisplayID());
  CGSize size = CGDisplayScreenSize(CGMainDisplayID());
  m_DPI = (int) ((width * 25.4) / size.width);
  mgDebug("screen is %d pixels/%d mm = %d dpi", (int) width, (int) size.width, m_DPI);
  m_DPI = max(m_DPI, 72);  // in case monitor info wrong

  mgDebug("");
  mgDebug("------ display initialized.  Return to app: %s", (const char *) m_windowTitle);
}
Esempio n. 8
0
DisplayInfo MythDisplay::GetDisplayInfo(int video_rate)
{
    DisplayInfo ret;

#if defined(Q_WS_MAC)
    CGDirectDisplayID disp = GetOSXDisplay(GetWindowID());
    if (!disp)
        return ret;

    CFDictionaryRef ref = CGDisplayCurrentMode(disp);
    float rate = 0.0f;
    if (ref)
        rate = get_float_CF(ref, kCGDisplayRefreshRate);

    if (VALID_RATE(rate))
        ret.rate = 1000000.0f / rate;
    else
        ret.rate = fix_rate(video_rate);

    CGSize size_in_mm = CGDisplayScreenSize(disp);
    ret.size = QSize((uint) size_in_mm.width, (uint) size_in_mm.height);

    uint width  = (uint)CGDisplayPixelsWide(disp);
    uint height = (uint)CGDisplayPixelsHigh(disp);
    ret.res     = QSize(width, height);

#elif defined(Q_WS_WIN)
    HDC hdc = GetDC(GetWindowID());
    int rate = 0;
    if (hdc)
    {
        rate       = GetDeviceCaps(hdc, VREFRESH);
        int width  = GetDeviceCaps(hdc, HORZSIZE);
        int height = GetDeviceCaps(hdc, VERTSIZE);
        ret.size   = QSize((uint)width, (uint)height);
        width      = GetDeviceCaps(hdc, HORZRES);
        height     = GetDeviceCaps(hdc, VERTRES);
        ret.res    = QSize((uint)width, (uint)height);
    }

    if (VALID_RATE(rate))
    {
        // see http://support.microsoft.com/kb/2006076
        switch (rate)
        {
        case 23:
            ret.rate = 41708;
            break; // 23.976Hz
        case 29:
            ret.rate = 33367;
            break; // 29.970Hz
        case 47:
            ret.rate = 20854;
            break; // 47.952Hz
        case 59:
            ret.rate = 16683;
            break; // 59.940Hz
        case 71:
            ret.rate = 13903;
            break; // 71.928Hz
        case 119:
            ret.rate = 8342;
            break; // 119.880Hz
        default:
            ret.rate = 1000000.0f / (float)rate;
        }
    }
    else
        ret.rate = fix_rate(video_rate);

#elif USING_X11
    MythXDisplay *disp = OpenMythXDisplay();
    if (!disp)
        return ret;

    float rate = disp->GetRefreshRate();
    if (VALID_RATE(rate))
        ret.rate = 1000000.0f / rate;
    else
        ret.rate = fix_rate(video_rate);
    ret.res  = disp->GetDisplaySize();
    ret.size = disp->GetDisplayDimensions();
    delete disp;
#endif
    return ret;
}
Esempio n. 9
0
int main( int argc, char ** argv)
{
	CGSize mainScreenSize = CGDisplayScreenSize (CGMainDisplayID ());
	CGDirectDisplayID currentDisplayID = CGMainDisplayID ();
	CGSize currentDisplaySize = mainScreenSize;
	CGRect displayRect;
	CGPoint newloc;
	Point pt;
	CGEventRef eventRef;
	
	InputEvent event;
	pInputEvent pEvent = &event;

	SOCKET s, s_accept;
	struct sockaddr_in s_add; //from anyone!
	struct sockaddr s_client;
	socklen_t s_client_size = sizeof( struct sockaddr );
	int port = PORT;
	int recvsize;
	char reuse = 1;//SO_REUSEADDR

	int xDelta=0, yDelta=0;

//network stuff
	//configure socket
	if ( ( s = socket( PF_INET, SOCK_STREAM, 0 ) ) == -1 ) 
	{
		perror ( "Failed to create socket :(" ); 
		exit( 2 );

	}

	if ( setsockopt( s, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof( reuse ) ) == -1 )
	{
		perror( "Failed to set reuseaddr! Trying to continue..." );
	}

	memset( &s_add, 0, sizeof( struct sockaddr_in ) );
	s_add.sin_family = AF_INET;
	s_add.sin_port = htons( port );
	s_add.sin_addr.s_addr = INADDR_ANY;

	if ( bind( s, (struct sockaddr * )&s_add, sizeof( struct sockaddr_in ) ) == -1 )
	{
		perror( "Failed to bind socket" );
		exit( 2 );
	}

	if( listen( s , 1 ) )
	{
		perror( "Can't listen!" );
		exit( 2 );
	}

	while( 1 )
	{

		s_accept = accept( s, &s_client, &s_client_size );

		if ( s_accept == -1 )
		{
			perror( "failed to accept!" );
			return -1;
		}

		while( 1 )
		{
			recvsize = recv( s_accept, pEvent, sizeof( InputEvent ), MSG_WAITALL );
			if ( recvsize == sizeof( InputEvent ) )//got data
			{

				switch( pEvent->event_t )
				{
					case EVENT_TYPE_MOUSE_MOVE:
						if(debug) printf("Mouse move\n");
						GetGlobalMouse( &pt );//get cursor pos
						//update x/y
						
						newloc.x = pt.h + pEvent->move_info.dx * 2;
						newloc.y = pt.v + pEvent->move_info.dy * 2;
						
						CGDisplayCount displayCount = 0;
						//check if we've crossed outside the x bounds
						
						CGDirectDisplayID tempDisplayID;
						
						CGGetDisplaysWithPoint (
							newloc,
							1,
							&tempDisplayID,
							&displayCount);
							
						
						if (displayCount != 0) {
							currentDisplayID = tempDisplayID;
						}
						
						displayRect = CGDisplayBounds(currentDisplayID);
						
						if (newloc.x < displayRect.origin.x) {
							newloc.x = displayRect.origin.x;
						}
						else if (newloc.x > displayRect.origin.x +
								 displayRect.size.width - 1) {
							newloc.x = displayRect.origin.x + displayRect.size.width - 1;
						}
						if (newloc.y < displayRect.origin.y) {
							newloc.y = displayRect.origin.y;
						}
						else if (newloc.y > displayRect.origin.y +
								 displayRect.size.height - 1) {
							newloc.y = displayRect.origin.y + displayRect.size.height - 1;
						}
												
						if(debug) 
						{
							printf("Current mouse location: {%d,%d}\n", pt.h, pt.v);
							printf("newloc: {%f,%f}\n", newloc.x, newloc.y);
							printf("Screen size: {%f,%f}\n", currentDisplaySize.width, currentDisplaySize.height);
							fflush( stdout );
						}
						//CGPostMouseEvent( newloc, true /*yes move there*/, 0 , false); 
						
						eventRef = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, newloc,
																   kCGMouseButtonCenter);
						CGEventSetType(eventRef, kCGEventMouseMoved); // Apple bug... need to set the type manually
											
						CGEventPost(kCGSessionEventTap, eventRef);
						CFRelease(eventRef);
						break;

					case EVENT_TYPE_MOUSE_SCROLL_MOVE:
						if(debug) 
						{
							printf( "Scrolling\n" );
							fflush( stdout );
						}
						
						xDelta += pEvent->move_info.dx;
						yDelta += pEvent->move_info.dy;

						//TODO: mac osx has a api to get the exact scroll amount, look into that
						if ( ( yDelta/SCROLL_AMT != 0 )  || ( xDelta/SCROLL_AMT != 0 ) )
						{//if any clicks need to be made...
							
							//send the number of whole clicks....
							CGPostScrollWheelEvent( 2, -yDelta/SCROLL_AMT, -xDelta/SCROLL_AMT ); 

							//remove them from our counter
							xDelta %=SCROLL_AMT;
							yDelta %=SCROLL_AMT;
						}

						break;
					case EVENT_TYPE_MOUSE_DOWN:
						if(debug) printf("Mouse down\n");
						GetGlobalMouse( &pt );//get cursor pos
						//update x/y
						
						
						
						if(debug) 
						{
							printf("Current mouse location: {%d,%d}", pt.h, pt.v);
							fflush( stdout );
						}
						//CGPostMouseEvent( newloc, true /*yes move there*/, 0 , false); 
						
						newloc.x = pt.h;
						newloc.y = pt.v;
						
						eventRef = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown , newloc,
																   kCGMouseButtonCenter);
						CGEventSetType(eventRef, kCGEventLeftMouseDown); // Apple bug... need to set the type manually
											
						CGEventPost(kCGSessionEventTap, eventRef);
						CFRelease(eventRef);
						break;

					case EVENT_TYPE_MOUSE_UP:	
						if(debug) printf("Mouse up\n");
						GetGlobalMouse( &pt );//get cursor pos
						//update x/y
						
						
						
						if(debug) 
						{
							printf("Current mouse location: {%d,%d}", pt.h, pt.v);
							fflush( stdout );
						}
						//CGPostMouseEvent( newloc, true /*yes move there*/, 0 , false); 
						
						newloc.x = pt.h;
						newloc.y = pt.v;
						
						eventRef = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp , newloc,
																   kCGMouseButtonCenter);
						CGEventSetType(eventRef, kCGEventLeftMouseUp); // Apple bug... need to set the type manually
											
						CGEventPost(kCGSessionEventTap, eventRef);
						CFRelease(eventRef);
						break;

					/* TODO:
					 * so far this will only work for basic keycodes, and will probably fail on anything non-ascii,
					 * and that has yet to be tested, etc.  Right now I'm mostly interested in having the events properly
					 * generated and support ascii keys.  We will handle the rest later.
					 */
					case EVENT_TYPE_KEY_DOWN:
						if ( debug )
						{
							printf( "Key down: %c\n", pEvent->key_info.keycode );
							fflush( stdout );
						}

						eventRef = CGEventCreateKeyboardEvent( NULL, (CGKeyCode)( pEvent->key_info.keycode - 1 ), true );

						CGEventSetType( eventRef, kCGEventKeyDown );

						CGEventPost( kCGSessionEventTap, eventRef );
						CFRelease( eventRef );
						break;

					case EVENT_TYPE_KEY_UP:
						if ( debug )
						{
							printf( "Key Up: %c\n", pEvent->key_info.keycode );
							fflush( stdout );
						}

						eventRef = CGEventCreateKeyboardEvent( NULL, (CGKeyCode)( pEvent->key_info.keycode - 1 ), false );

						CGEventSetType( eventRef, kCGEventKeyUp );

						CGEventPost( kCGSessionEventTap, eventRef );
						CFRelease( eventRef );
						break;

					default:
						fprintf( stderr, "unknown message type: %d\n", pEvent->event_t );
						fflush( stdout );
						break;
				}

				//flush events, if needed in macosx
			
			}
			else if ( recvsize > 0 )
			{
				fprintf( stderr, "partial recv!" );
			}
			else if ( recvsize == 0 )
			{
				//connection terminated
				close( s_accept );
				break; //exit this while loop, wait for another connection
			}
			else
			{
				perror( "error in recv" );
			}
		}

	}

	//shouldn't get here!

	return 0;
}
Esempio n. 10
0
/**********************************************************************
 *              device_init
 *
 * Perform initializations needed upon creation of the first device.
 */
static void device_init(void)
{
    CGDirectDisplayID mainDisplay = CGMainDisplayID();
    CGSize size_mm = CGDisplayScreenSize(mainDisplay);
    CGDisplayModeRef mode = CGDisplayCopyDisplayMode(mainDisplay);
    CGDirectPaletteRef palette;

    /* Initialize device caps */
    log_pixels_x = log_pixels_y = get_dpi();
    if (!log_pixels_x)
    {
        size_t width = CGDisplayPixelsWide(mainDisplay);
        size_t height = CGDisplayPixelsHigh(mainDisplay);
        log_pixels_x = MulDiv(width, 254, size_mm.width * 10);
        log_pixels_y = MulDiv(height, 254, size_mm.height * 10);
    }

    horz_size = size_mm.width;
    vert_size = size_mm.height;

    bits_per_pixel = 32;
    if (mode)
    {
        CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);

        horz_res = CGDisplayModeGetWidth(mode);
        vert_res = CGDisplayModeGetHeight(mode);

        if (pixelEncoding)
        {
            if (CFEqual(pixelEncoding, CFSTR(IO32BitDirectPixels)))
                bits_per_pixel = 32;
            else if (CFEqual(pixelEncoding, CFSTR(IO16BitDirectPixels)))
                bits_per_pixel = 16;
            else if (CFEqual(pixelEncoding, CFSTR(IO8BitIndexedPixels)))
                bits_per_pixel = 8;
            CFRelease(pixelEncoding);
        }

        CGDisplayModeRelease(mode);
    }
    else
    {
        horz_res = CGDisplayPixelsWide(mainDisplay);
        vert_res = CGDisplayPixelsHigh(mainDisplay);
    }

    macdrv_get_desktop_rect();
    desktop_horz_res = desktop_rect.size.width;
    desktop_vert_res = desktop_rect.size.height;

    palette = CGPaletteCreateWithDisplay(mainDisplay);
    if (palette)
    {
        palette_size = CGPaletteGetNumberOfSamples(palette);
        CGPaletteRelease(palette);
    }
    else
        palette_size = 0;

    device_data_valid = TRUE;
}