Changeset 44194 in vbox
- Timestamp:
- Dec 21, 2012 10:27:41 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp
r44161 r44194 214 214 215 215 static DWORD EnableAndResizeDispDev(ULONG Id, DWORD aWidth, DWORD aHeight, 216 DWORD aBitsPerPixel, DWORD aPosX, DWORD aPosY, 217 BOOL fEnabled, VBOXDISPLAYCONTEXT *pCtx) 216 DWORD aBitsPerPixel, DWORD aPosX, DWORD aPosY, 217 BOOL fEnabled, BOOL fExtDispSup, 218 VBOXDISPLAYCONTEXT *pCtx) 218 219 { 219 220 DISPLAY_DEVICE DisplayDeviceTmp; 220 221 DISPLAY_DEVICE DisplayDevice; 221 DEVMODE DeviceModeTmp;222 222 DEVMODE DeviceMode; 223 223 DWORD DispNum = 0; … … 225 225 ZeroMemory(&DisplayDeviceTmp, sizeof(DisplayDeviceTmp)); 226 226 DisplayDeviceTmp.cb = sizeof(DisplayDevice); 227 ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));228 DisplayDevice.cb = sizeof(DisplayDevice);229 227 230 228 Log(("EnableDisplayDevice Id=%d, width=%d height=%d \ 231 PosX = %d PosY = %d \n",Id, aWidth, aHeight, aPosX, aPosY)); 229 PosX = %d PosY = %d fEnabled = %d & fExtDisSup = %d \n", 230 Id, aWidth, aHeight, aPosX, aPosY, fEnabled, fExtDispSup)); 232 231 233 232 /* Disable all the devices apart from the device with ID = Id and … … 236 235 while (EnumDisplayDevices (NULL, DispNum, &DisplayDeviceTmp, 0)) 237 236 { 238 if (DispNum == Id) {239 DisplayDevice = DisplayDeviceTmp;240 }241 237 /* Displays which are configured but not enabled, update their 242 238 * registry entries for parameters width , height, posX and 243 239 * posY as 0. This is done so that they are not enabled when 244 * ChangeDisplaySettings(NULL) is called 240 * ChangeDisplaySettings(NULL) is called . 241 * Dont disable the primary monitor or the monitor whose resolution 242 * needs to be changed i.e the monitor with ID = Id. 245 243 */ 246 244 if (DispNum != 0 && DispNum != Id) 247 245 { 248 ZeroMemory(&DeviceModeTmp, sizeof(DEVMODE)); 249 DeviceModeTmp.dmSize = sizeof(DEVMODE); 250 DeviceModeTmp.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION 251 | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ; 252 if (!EnumDisplaySettings((LPSTR)DisplayDeviceTmp.DeviceName, 253 ENUM_REGISTRY_SETTINGS, &DeviceModeTmp)) 254 { 255 Log(("VBoxTray: ResizeDisplayDevice: EnumDisplaySettings error %d\n", GetLastError ())); 256 return FALSE; 257 } 258 if (DeviceModeTmp.dmPelsWidth == 0 || DeviceModeTmp.dmPelsHeight == 0) 259 { 260 /* No ENUM_REGISTRY_SETTINGS yet. Seen on Vista after installation. 261 * Get the current video mode then. 262 */ 263 ZeroMemory(&DeviceModeTmp, sizeof(DEVMODE)); 264 DeviceModeTmp.dmSize = sizeof(DEVMODE); 265 if (!EnumDisplaySettings((LPSTR)DisplayDeviceTmp.DeviceName, 266 ENUM_CURRENT_SETTINGS, &DeviceModeTmp)) 267 { 268 /* ENUM_CURRENT_SETTINGS returns FALSE when the display is not active: 269 * for example a disabled secondary display. 270 * Do not return here, ignore the error and set the display info to 0x0x0. 271 */ 272 Log(("VBoxTray: ResizeDisplayDevice: EnumDisplaySettings(ENUM_CURRENT_SETTINGS) error %d\n", GetLastError ())); 273 ZeroMemory(&DeviceMode, sizeof(DEVMODE)); 274 } 275 } 246 DEVMODE DeviceModeTmp; 276 247 ZeroMemory(&DeviceModeTmp, sizeof(DEVMODE)); 277 248 DeviceModeTmp.dmSize = sizeof(DEVMODE); … … 279 250 | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ; 280 251 ChangeDisplaySettingsEx(DisplayDeviceTmp.DeviceName, &DeviceModeTmp, NULL, 281 252 (CDS_UPDATEREGISTRY | CDS_NORESET), NULL); 282 253 } 283 254 DispNum++; 284 255 } 285 256 286 /* Enable and set position for the monitor with ID = Id */ 257 ZeroMemory(&DisplayDevice, sizeof(DisplayDevice)); 258 DisplayDevice.cb = sizeof(DisplayDevice); 259 287 260 ZeroMemory(&DeviceMode, sizeof(DEVMODE)); 288 261 DeviceMode.dmSize = sizeof(DEVMODE); 262 289 263 EnumDisplayDevices (NULL, Id, &DisplayDevice, 0); 290 264 … … 317 291 318 292 DeviceMode.dmFields = DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ; 319 if (fEnabled) { 293 if (fExtDispSup) /* Extended Display Support possible*/ 294 { 295 Log(("VBoxTray: Extended Display Support. Change Position and Resolution \n")); 296 if (fEnabled) 297 { 298 if (aWidth !=0 && aHeight != 0) 299 { 300 Log(("VBoxTray: Mon ID = %d, Width = %d, Height = %d\n", 301 Id, aWidth, aHeight)); 302 DeviceMode.dmFields |= DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL ; 303 DeviceMode.dmPelsWidth = aWidth; 304 DeviceMode.dmPelsHeight = aHeight; 305 DeviceMode.dmBitsPerPel = aBitsPerPixel; 306 } 307 if (aPosX != 0 || aPosY != 0) 308 { 309 Log(("VBoxTray: Mon ID = %d PosX = %d, PosY = %d\n", 310 Id, aPosX, aPosY)); 311 DeviceMode.dmFields |= DM_POSITION; 312 DeviceMode.dmPosition.x = aPosX; 313 DeviceMode.dmPosition.y = aPosY; 314 } 315 } 316 else 317 { 318 /* Request is there to disable the monitor with ID = Id*/ 319 Log(("VBoxTray: Disable the Monitor ID = %d\n", Id)); 320 ZeroMemory(&DeviceMode, sizeof(DEVMODE)); 321 DeviceMode.dmSize = sizeof(DEVMODE); 322 DeviceMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION 323 | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ; 324 } 325 } 326 else /* Extended display support not possible. Just change the res.*/ 327 { 320 328 if (aWidth !=0 && aHeight != 0) 321 329 { 322 Log(("VBoxTray: Mon ID = %d, Width = %d, Height = %d\n", 323 Id, aWidth, aHeight)); 330 Log(("VBoxTray: No Extended Display Support. Just Change Resolution. \ 331 Mon ID = %d, Width = %d, Height = %d\n", 332 Id, aWidth, aHeight)); 324 333 DeviceMode.dmFields |= DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL ; 325 334 DeviceMode.dmPelsWidth = aWidth; … … 327 336 DeviceMode.dmBitsPerPel = aBitsPerPixel; 328 337 } 329 if (aPosX != 0 || aPosY != 0) 330 { 331 Log(("VBoxTray: Mon ID = %d PoxX = %d, PoxY = %d\n", 332 Id, aWidth, aHeight)); 333 DeviceMode.dmFields |= DM_POSITION; 334 DeviceMode.dmPosition.x = aPosX; 335 DeviceMode.dmPosition.y = aPosY; 336 } 337 } 338 else 339 { 340 /* Request is there to disable the monitor with ID = Id*/ 341 ZeroMemory(&DeviceModeTmp, sizeof(DEVMODE)); 342 DeviceModeTmp.dmSize = sizeof(DEVMODE); 343 DeviceModeTmp.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION 344 | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ; 345 } 346 gCtx.pfnChangeDisplaySettingsEx(DisplayDevice.DeviceName, &DeviceMode, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL); 338 } 339 Log(("VBoxTray: Changing Reslution of Monitor with ID = %d. Params \ 340 PosX = %d, PosY = %d, Width = %d, Height = %d\n", 341 Id, DeviceMode.dmPosition.x, DeviceMode.dmPosition.y, 342 DeviceMode.dmPelsWidth, DeviceMode.dmPelsHeight)); 343 gCtx.pfnChangeDisplaySettingsEx(DisplayDevice.DeviceName, &DeviceMode, 344 NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL); 347 345 Log(("VBoxTray: ChangeDisplay return erroNo = %d\n", GetLastError())); 348 346 DWORD dwStatus = gCtx.pfnChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL); … … 356 354 VBOXDISPLAYCONTEXT *pCtx, BOOL fExtDispSup) 357 355 { 358 BOOL fModeReset = (Width == 0 && Height == 0 && BitsPerPixel == 0); 356 BOOL fModeReset = (Width == 0 && Height == 0 && BitsPerPixel == 0 && 357 dwNewPosX == 0 && dwNewPosY == 0); 358 359 Log(("VBoxTray: ResizeDisplayDevice Width= %d, Height=%d , PosX=%d and PosY=%d \ 360 fEnabled = %d, fExtDisSup = %d\n", 361 Width, Height, dwNewPosX, dwNewPosY, fEnabled, fExtDispSup)); 359 362 360 363 if (!gCtx.fAnyX) … … 477 480 Log(("VBoxTray: Extended Display Support.\n")); 478 481 Log(("VBoxTray: ResizeDisplayDevice1: %dx%dx%d at %d,%d\n", 479 paDeviceModes[DevNum].dmPelsWidth,480 paDeviceModes[DevNum].dmPelsHeight,481 paDeviceModes[DevNum].dmBitsPerPel,482 paDeviceModes[DevNum].dmPosition.x,483 paDeviceModes[DevNum].dmPosition.y));482 paDeviceModes[Id].dmPelsWidth, 483 paDeviceModes[Id].dmPelsHeight, 484 paDeviceModes[Id].dmBitsPerPel, 485 paDeviceModes[Id].dmPosition.x, 486 paDeviceModes[Id].dmPosition.y)); 484 487 if ((DevNum == Id && fEnabled == 1)) 485 488 { … … 532 535 } 533 536 534 /* Check whether a mode reset or a change is requested. */ 535 if ( !fModeReset 537 /* Check whether a mode reset or a change is requested. 538 * Rectangle position is recalculated only if fEnabled is 1. 539 * For non extended supported modes (old Host VMs), fEnabled 540 * is always 1. 541 */ 542 if ( !fModeReset && fEnabled 536 543 && paRects[Id].right - paRects[Id].left == Width 537 544 && paRects[Id].bottom - paRects[Id].top == Height … … 645 652 Log(("VBoxTray: ResizeDisplayDevice: ChangeDisplaySettingsEx position status %d, err %d\n", status, GetLastError ())); 646 653 } 647 if (fExtDispSup) 648 { 649 Log(("VBoxTray: Extended Display Supported. Width=%d Height=%d, \ 650 dwNewPosX=%d, dwNewPosY=%d \n",Width, Height, dwNewPosX, dwNewPosY)); 651 dwStatus = EnableAndResizeDispDev(Id, Width, Height, BitsPerPixel, 652 dwNewPosX, dwNewPosY,fEnabled, pCtx); 653 } 654 else 655 { 656 Log(("VBoxTray: Extended Display Not Supported.")); 657 dwStatus = EnableAndResizeDispDev(Id, Width, Height, BitsPerPixel, 0, 0, 0, pCtx); 658 } 654 655 Log(("VBoxTray: Enable And Resize Device. Id = %d, Width=%d Height=%d, \ 656 dwNewPosX = %d, dwNewPosY = %d fEnabled=%d & fExtDispSupport = %d \n", 657 Id, Width, Height, dwNewPosX, dwNewPosY, fEnabled, fExtDispSup)); 658 dwStatus = EnableAndResizeDispDev(Id, Width, Height, BitsPerPixel, 659 dwNewPosX, dwNewPosY,fEnabled, 660 fExtDispSup, pCtx); 659 661 if (dwStatus == DISP_CHANGE_SUCCESSFUL || dwStatus == DISP_CHANGE_BADMODE) 660 662 { … … 737 739 /* Try if extended mode display information is available from the host. */ 738 740 VMMDevDisplayChangeRequestEx displayChangeRequest = {0}; 741 fExtDispSup = TRUE; 739 742 displayChangeRequest.header.size = sizeof(VMMDevDisplayChangeRequestEx); 740 743 displayChangeRequest.header.version = VMMDEV_REQUEST_HEADER_VERSION; … … 744 747 &displayChangeRequest, sizeof(VMMDevDisplayChangeRequestEx), &cbReturned, NULL); 745 748 746 if (!fDisplayChangeQueried) { 749 if (!fDisplayChangeQueried) 750 { 751 Log(("VBoxTray: Extended Display Not Supported. Trying VMMDevDisplayChangeRequest2\n")); 747 752 fExtDispSup = FALSE; /* Extended display Change request is not supported */ 748 VMMDevDisplayChangeRequest2 displayChangeRequest = {0}; 753 749 754 displayChangeRequest.header.size = sizeof(VMMDevDisplayChangeRequest2); 750 755 displayChangeRequest.header.version = VMMDEV_REQUEST_HEADER_VERSION; … … 753 758 fDisplayChangeQueried = DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevDisplayChangeRequest2)), &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest2), 754 759 &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest2), &cbReturned, NULL); 760 displayChangeRequest.cxOrigin = 0; 761 displayChangeRequest.cyOrigin = 0; 762 displayChangeRequest.fChangeOrigin = 0; 763 displayChangeRequest.fEnabled = 1; /* Always Enabled for old VMs on Host.*/ 755 764 } 756 765 757 766 if (!fDisplayChangeQueried) 758 767 { 768 Log(("VBoxTray: Extended Display Not Supported. Trying VMMDevDisplayChangeRequest\n")); 759 769 fExtDispSup = FALSE; /*Extended display Change request is not supported */ 760 770 /* Try the old version of the request for old VBox hosts. */ … … 766 776 &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest), &cbReturned, NULL); 767 777 displayChangeRequest.display = 0; 778 displayChangeRequest.cxOrigin = 0; 779 displayChangeRequest.cyOrigin = 0; 780 displayChangeRequest.fChangeOrigin = 0; 781 displayChangeRequest.fEnabled = 1; /* Always Enabled for old VMs on Host.*/ 768 782 } 769 783 … … 795 809 Log(("VBoxTray: VBoxDisplayThread: Detected W2K or later\n")); 796 810 /* W2K or later. */ 797 if (!fExtDispSup) { /* Extended display support not query possible */ 798 if (!ResizeDisplayDevice(displayChangeRequest.display, 799 displayChangeRequest.xres, 800 displayChangeRequest.yres, 801 displayChangeRequest.bpp, 802 0, /* NA for Normal Disp Change Req */ 803 0, /* NA for Normal Disp Change Req */ 804 0, /* NA for Normal Disp Change Req */ 805 pCtx, 806 fExtDispSup 807 )) 808 { 809 Log(("ResizeDipspalyDevice return 0\n")); 810 break; 811 } 812 } 813 else /* Extended display support query possible */ 814 { 815 Log(("DisplayChangeReqEx parameters aDisplay=%d x xRes=%d x yRes=%d x bpp=%d x SecondayMonEnb=%d x NewOriginX=%d x NewOriginY=%d x ChangeOrigin=%d\n", 811 Log(("DisplayChangeReqEx parameters aDisplay=%d x xRes=%d x yRes=%d x bpp=%d x SecondayMonEnb=%d x NewOriginX=%d x NewOriginY=%d x ChangeOrigin=%d\n", 816 812 displayChangeRequest.display, 817 813 displayChangeRequest.xres, … … 822 818 displayChangeRequest.cyOrigin, 823 819 displayChangeRequest.fChangeOrigin)); 824 if (!ResizeDisplayDevice(displayChangeRequest.display, 825 displayChangeRequest.xres, 826 displayChangeRequest.yres, 827 displayChangeRequest.bpp, 828 displayChangeRequest.fEnabled, 829 displayChangeRequest.cxOrigin, 830 displayChangeRequest.cyOrigin, 831 pCtx, 832 fExtDispSup 833 )) 834 { 835 Log(("ResizeDipspalyDevice return 0\n")); 836 break; 837 } 820 if (!ResizeDisplayDevice(displayChangeRequest.display, 821 displayChangeRequest.xres, 822 displayChangeRequest.yres, 823 displayChangeRequest.bpp, 824 displayChangeRequest.fEnabled, 825 displayChangeRequest.cxOrigin, 826 displayChangeRequest.cyOrigin, 827 pCtx, 828 fExtDispSup 829 )) 830 { 831 Log(("ResizeDipspalyDevice return 0\n")); 832 break; 838 833 } 834 839 835 } 840 836 else
Note:
See TracChangeset
for help on using the changeset viewer.