static size_t _gfx_x11_init_modes( Screen* scr, XRRScreenResources* res) { /* Split depth */ GFXColorDepth depth; _gfx_split_depth( XDefaultDepthOfScreen(scr), &depth.redBits, &depth.greenBits, &depth.blueBits ); /* Reserve space for all modes */ size_t first = gfx_vector_get_size(&_gfx_x11.modes); gfx_vector_reserve(&_gfx_x11.modes, first + res->nmode); unsigned int i; for(i = 0; i < res->nmode; ++i) { /* Skip refresh rate of zero */ unsigned int refresh = 0; if(res->modes[i].hTotal && res->modes[i].vTotal) { refresh = (unsigned int)lround((double)res->modes[i].dotClock / ((double)res->modes[i].hTotal * (double)res->modes[i].vTotal)); } if(refresh) { /* Create new mode */ GFX_X11_Mode mode; mode.id = res->modes[i].id; mode.mode.width = res->modes[i].width; mode.mode.height = res->modes[i].height; mode.mode.depth = depth; mode.mode.refresh = refresh; gfx_vector_insert(&_gfx_x11.modes, &mode, _gfx_x11.modes.end); } } return first; }
GFX_PlatformWindow _gfx_platform_window_create( const GFX_PlatformAttributes* attributes) { /* Setup the win32 window */ GFX_Win32_Window window; window.monitor = attributes->monitor; window.context = NULL; window.flags = 0; window.flags |= attributes->flags & GFX_WINDOW_RESIZABLE ? GFX_WIN32_RESIZABLE : 0; window.flags |= attributes->flags & GFX_WINDOW_HIDDEN ? GFX_WIN32_HIDDEN : 0; /* Display mode, style and window rectangle */ DWORD styleEx = WS_EX_APPWINDOW; DWORD style = (!(attributes->flags & GFX_WINDOW_HIDDEN) ? WS_VISIBLE : 0); GFXColorDepth depth; RECT rect; rect.left = window.monitor->x; rect.top = window.monitor->y; if(attributes->flags & GFX_WINDOW_FULLSCREEN) { /* Display mode */ window.flags |= GFX_WIN32_FULLSCREEN; window.mode = gfx_vector_at( &_gfx_win32.modes, window.monitor->modes + attributes->mode); _gfx_split_depth( window.mode->dmBitsPerPel, &depth.redBits, &depth.greenBits, &depth.blueBits); /* Style and rectangle */ rect.right = window.mode->dmPelsWidth; rect.bottom = window.mode->dmPelsHeight; styleEx |= WS_EX_TOPMOST; style |= WS_POPUP; } else { /* Color depth and rectangle */ depth = *attributes->depth; rect.right = attributes->w; rect.bottom = attributes->h; rect.left += attributes->x; rect.top += attributes->y; /* Style */ style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; if(!(attributes->flags & GFX_WINDOW_BORDERLESS)) { /* With a border */ styleEx |= WS_EX_WINDOWEDGE; style |= WS_CAPTION | WS_MINIMIZEBOX | WS_OVERLAPPED | WS_SYSMENU; /* With size options */ if(attributes->flags & GFX_WINDOW_RESIZABLE) style |= WS_MAXIMIZEBOX | WS_SIZEBOX; } else { /* Borderless */ styleEx |= WS_EX_TOPMOST; style |= WS_POPUP; } } rect.right += rect.left; rect.bottom += rect.top; /* Make sure the client area is the specified size */ AdjustWindowRectEx(&rect, style, FALSE, styleEx); /* Convert name to UTF-16 */ WCHAR* name = _gfx_win32_utf8_to_utf16(attributes->name); /* Create the actual window */ window.handle = CreateWindowEx( styleEx, GFX_WIN32_WINDOW_CLASS, name, style, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandle(NULL), NULL ); free(name); if(window.handle) { /* Add window to vector */ GFXVectorIterator it = gfx_vector_insert( &_gfx_win32.windows, &window, _gfx_win32.windows.end ); if(it != _gfx_win32.windows.end) { /* Set pixel format */ _gfx_win32_set_pixel_format( window.handle, &depth, attributes->flags & GFX_WINDOW_DOUBLE_BUFFER ); /* Start tracking the mouse */ _gfx_win32_track_mouse(window.handle); /* Enter fullscreen */ if( (attributes->flags & GFX_WINDOW_FULLSCREEN) && !(attributes->flags & GFX_WINDOW_HIDDEN)) { _gfx_win32_enter_fullscreen(window.monitor, window.mode); } return window.handle; } DestroyWindow(window.handle); } return NULL; }