2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Video initialization and display settings
5 * FILE: win32ss/user/ntuser/display.c
6 * PROGRAMER: Timo Kreuzer (timo.kreuzer@reactos.org)
10 DBG_DEFAULT_CHANNEL(UserDisplay
);
13 static PPROCESSINFO gpFullscreen
= NULL
;
15 static const PWCHAR KEY_VIDEO
= L
"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO";
18 RegWriteDisplaySettings(HKEY hkey
, PDEVMODEW pdm
)
20 RegWriteDWORD(hkey
, L
"DefaultSettings.BitsPerPel", pdm
->dmBitsPerPel
);
21 RegWriteDWORD(hkey
, L
"DefaultSettings.XResolution", pdm
->dmPelsWidth
);
22 RegWriteDWORD(hkey
, L
"DefaultSettings.YResolution", pdm
->dmPelsHeight
);
23 RegWriteDWORD(hkey
, L
"DefaultSettings.Flags", pdm
->dmDisplayFlags
);
24 RegWriteDWORD(hkey
, L
"DefaultSettings.VRefresh", pdm
->dmDisplayFrequency
);
25 RegWriteDWORD(hkey
, L
"DefaultSettings.XPanning", pdm
->dmPanningWidth
);
26 RegWriteDWORD(hkey
, L
"DefaultSettings.YPanning", pdm
->dmPanningHeight
);
27 RegWriteDWORD(hkey
, L
"DefaultSettings.Orientation", pdm
->dmDisplayOrientation
);
28 RegWriteDWORD(hkey
, L
"DefaultSettings.FixedOutput", pdm
->dmDisplayFixedOutput
);
29 RegWriteDWORD(hkey
, L
"Attach.RelativeX", pdm
->dmPosition
.x
);
30 RegWriteDWORD(hkey
, L
"Attach.RelativeY", pdm
->dmPosition
.y
);
31 // RegWriteDWORD(hkey, L"Attach.ToDesktop, pdm->dmBitsPerPel", pdm->);
35 RegReadDisplaySettings(HKEY hkey
, PDEVMODEW pdm
)
39 /* Zero out the structure */
40 RtlZeroMemory(pdm
, sizeof(DEVMODEW
));
43 #define READ(field, str, flag) \
44 if (RegReadDWORD(hkey, L##str, &dwValue)) \
46 pdm->field = dwValue; \
47 pdm->dmFields |= flag; \
50 /* Read all present settings */
51 READ(dmBitsPerPel
, "DefaultSettings.BitsPerPel", DM_BITSPERPEL
);
52 READ(dmPelsWidth
, "DefaultSettings.XResolution", DM_PELSWIDTH
);
53 READ(dmPelsHeight
, "DefaultSettings.YResolution", DM_PELSHEIGHT
);
54 READ(dmDisplayFlags
, "DefaultSettings.Flags", DM_DISPLAYFLAGS
);
55 READ(dmDisplayFrequency
, "DefaultSettings.VRefresh", DM_DISPLAYFREQUENCY
);
56 READ(dmPanningWidth
, "DefaultSettings.XPanning", DM_PANNINGWIDTH
);
57 READ(dmPanningHeight
, "DefaultSettings.YPanning", DM_PANNINGHEIGHT
);
58 READ(dmDisplayOrientation
, "DefaultSettings.Orientation", DM_DISPLAYORIENTATION
);
59 READ(dmDisplayFixedOutput
, "DefaultSettings.FixedOutput", DM_DISPLAYFIXEDOUTPUT
);
60 READ(dmPosition
.x
, "Attach.RelativeX", DM_POSITION
);
61 READ(dmPosition
.y
, "Attach.RelativeY", DM_POSITION
);
67 IN PWSTR pwszDeviceName
,
70 PGRAPHICS_DEVICE pGraphicsDevice
;
71 UNICODE_STRING ustrDeviceName
, ustrDisplayDrivers
, ustrDescription
;
79 TRACE("InitDisplayDriver(%S, %S);\n",
80 pwszDeviceName
, pwszRegKey
);
82 /* Open the driver's registry key */
83 Status
= RegOpenKey(pwszRegKey
, &hkey
);
84 if (!NT_SUCCESS(Status
))
86 ERR("Failed to open registry key: %ls\n", pwszRegKey
);
90 /* Query the diplay drivers */
91 cbSize
= sizeof(awcBuffer
) - 10;
92 Status
= RegQueryValue(hkey
,
93 L
"InstalledDisplayDrivers",
97 if (!NT_SUCCESS(Status
))
99 ERR("Didn't find 'InstalledDisplayDrivers', status = 0x%lx\n", Status
);
104 /* Initialize the UNICODE_STRING */
105 ustrDisplayDrivers
.Buffer
= awcBuffer
;
106 ustrDisplayDrivers
.MaximumLength
= (USHORT
)cbSize
;
107 ustrDisplayDrivers
.Length
= (USHORT
)cbSize
;
109 /* Set Buffer for description and size of remaining buffer */
110 ustrDescription
.Buffer
= awcBuffer
+ (cbSize
/ sizeof(WCHAR
));
111 cbSize
= sizeof(awcBuffer
) - cbSize
;
113 /* Query the device string */
114 Status
= RegQueryValue(hkey
,
115 L
"Device Description",
117 ustrDescription
.Buffer
,
119 if (NT_SUCCESS(Status
))
121 ustrDescription
.MaximumLength
= (USHORT
)cbSize
;
122 ustrDescription
.Length
= (USHORT
)cbSize
;
126 RtlInitUnicodeString(&ustrDescription
, L
"<unknown>");
129 /* Query the default settings */
130 RegReadDisplaySettings(hkey
, &dmDefault
);
132 /* Query if this is a VGA compatible driver */
133 cbSize
= sizeof(DWORD
);
134 Status
= RegQueryValue(hkey
, L
"VgaCompatible", REG_DWORD
, &dwVga
, &cbSize
);
135 if (!NT_SUCCESS(Status
)) dwVga
= 0;
137 /* Close the registry key */
140 /* Register the device with GDI */
141 RtlInitUnicodeString(&ustrDeviceName
, pwszDeviceName
);
142 pGraphicsDevice
= EngpRegisterGraphicsDevice(&ustrDeviceName
,
146 if (pGraphicsDevice
&& dwVga
)
148 pGraphicsDevice
->StateFlags
|= DISPLAY_DEVICE_VGA_COMPATIBLE
;
151 return pGraphicsDevice
;
158 ULONG iDevNum
, iVGACompatible
= -1, ulMaxObjectNumber
= 0;
159 WCHAR awcDeviceName
[20];
160 WCHAR awcBuffer
[256];
162 PGRAPHICS_DEVICE pGraphicsDevice
;
166 TRACE("----------------------------- InitVideo() -------------------------------\n");
168 /* Open the key for the boot command line */
169 Status
= RegOpenKey(L
"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control", &hkey
);
170 if (NT_SUCCESS(Status
))
173 Status
= RegQueryValue(hkey
, L
"SystemStartOptions", REG_SZ
, awcBuffer
, &cbValue
);
174 if (NT_SUCCESS(Status
))
176 /* Check if VGA mode is requested. */
177 if (wcsstr(awcBuffer
, L
"BASEVIDEO") != 0)
179 ERR("VGA mode requested.\n");
187 /* Open the key for the adapters */
188 Status
= RegOpenKey(KEY_VIDEO
, &hkey
);
189 if (!NT_SUCCESS(Status
))
191 ERR("Could not open HARDWARE\\DEVICEMAP\\VIDEO registry key:0x%lx\n", Status
);
195 /* Read the name of the VGA adapter */
197 Status
= RegQueryValue(hkey
, L
"VgaCompatible", REG_SZ
, awcDeviceName
, &cbValue
);
198 if (NT_SUCCESS(Status
))
200 iVGACompatible
= _wtoi(&awcDeviceName
[13]);
201 ERR("VGA adapter = %lu\n", iVGACompatible
);
204 /* Get the maximum mumber of adapters */
205 if (!RegReadDWORD(hkey
, L
"MaxObjectNumber", &ulMaxObjectNumber
))
207 ERR("Could not read MaxObjectNumber, defaulting to 0.\n");
210 TRACE("Found %lu devices\n", ulMaxObjectNumber
+ 1);
212 /* Loop through all adapters */
213 for (iDevNum
= 0; iDevNum
<= ulMaxObjectNumber
; iDevNum
++)
215 /* Create the adapter's key name */
216 swprintf(awcDeviceName
, L
"\\Device\\Video%lu", iDevNum
);
218 /* Read the reg key name */
219 cbValue
= sizeof(awcBuffer
);
220 Status
= RegQueryValue(hkey
, awcDeviceName
, REG_SZ
, awcBuffer
, &cbValue
);
221 if (!NT_SUCCESS(Status
))
223 ERR("failed to query the registry path:0x%lx\n", Status
);
227 /* Initialize the driver for this device */
228 pGraphicsDevice
= InitDisplayDriver(awcDeviceName
, awcBuffer
);
229 if (!pGraphicsDevice
) continue;
231 /* Check if this is a VGA compatible adapter */
232 if (pGraphicsDevice
->StateFlags
& DISPLAY_DEVICE_VGA_COMPATIBLE
)
234 /* Save this as the VGA adapter */
235 if (!gpVgaGraphicsDevice
)
236 gpVgaGraphicsDevice
= pGraphicsDevice
;
237 TRACE("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice
);
241 /* Set the first one as primary device */
242 if (!gpPrimaryGraphicsDevice
)
243 gpPrimaryGraphicsDevice
= pGraphicsDevice
;
244 TRACE("gpPrimaryGraphicsDevice = %p\n", gpPrimaryGraphicsDevice
);
248 /* Close the device map registry key */
251 /* Was VGA mode requested? */
254 /* Check if we found a VGA compatible device */
255 if (gpVgaGraphicsDevice
)
257 /* Set the VgaAdapter as primary */
258 gpPrimaryGraphicsDevice
= gpVgaGraphicsDevice
;
263 ERR("Could not find VGA compatible driver. Trying normal.\n");
267 /* Check if we had any success */
268 if (!gpPrimaryGraphicsDevice
)
270 /* Check if there is a VGA device we skipped */
271 if (gpVgaGraphicsDevice
)
273 /* There is, use the VGA device */
274 gpPrimaryGraphicsDevice
= gpVgaGraphicsDevice
;
278 ERR("No usable display driver was found.\n");
279 return STATUS_UNSUCCESSFUL
;
290 UserEnumDisplayDevices(
291 PUNICODE_STRING pustrDevice
,
293 PDISPLAY_DEVICEW pdispdev
,
296 PGRAPHICS_DEVICE pGraphicsDevice
;
301 /* Ask gdi for the GRAPHICS_DEVICE */
302 pGraphicsDevice
= EngpFindGraphicsDevice(pustrDevice
, iDevNum
, 0);
303 if (!pGraphicsDevice
)
305 /* No device found */
306 ERR("No GRAPHICS_DEVICE found\n");
307 return STATUS_UNSUCCESSFUL
;
310 /* Open the device map registry key */
311 Status
= RegOpenKey(KEY_VIDEO
, &hkey
);
312 if (!NT_SUCCESS(Status
))
314 /* No device found */
315 ERR("Could not open reg key\n");
316 return STATUS_UNSUCCESSFUL
;
319 /* Query the registry path */
320 cbSize
= sizeof(pdispdev
->DeviceKey
);
322 pGraphicsDevice
->szNtDeviceName
,
327 /* Close registry key */
330 /* Copy device name, device string and StateFlags */
331 RtlStringCbCopyW(pdispdev
->DeviceName
, sizeof(pdispdev
->DeviceName
), pGraphicsDevice
->szWinDeviceName
);
332 RtlStringCbCopyW(pdispdev
->DeviceString
, sizeof(pdispdev
->DeviceString
), pGraphicsDevice
->pwszDescription
);
333 pdispdev
->StateFlags
= pGraphicsDevice
->StateFlags
;
334 // FIXME: fill in DEVICE ID
335 pdispdev
->DeviceID
[0] = UNICODE_NULL
;
337 return STATUS_SUCCESS
;
343 NtUserEnumDisplayDevices(
344 PUNICODE_STRING pustrDevice
,
346 PDISPLAY_DEVICEW pDisplayDevice
,
349 UNICODE_STRING ustrDevice
;
350 WCHAR awcDevice
[CCHDEVICENAME
];
351 DISPLAY_DEVICEW dispdev
;
354 TRACE("Enter NtUserEnumDisplayDevices(%wZ, %lu)\n",
355 pustrDevice
, iDevNum
);
357 dispdev
.cb
= sizeof(dispdev
);
361 /* Initialize destination string */
362 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
366 /* Probe the UNICODE_STRING and the buffer */
367 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
368 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
370 /* Copy the string */
371 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
373 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
375 // _SEH2_YIELD(return _SEH2_GetExceptionCode());
376 _SEH2_YIELD(return NT_SUCCESS(_SEH2_GetExceptionCode()));
380 if (ustrDevice
.Length
> 0)
381 pustrDevice
= &ustrDevice
;
386 /* If name is given only iDevNum==0 gives results */
387 if (pustrDevice
&& iDevNum
!= 0)
390 /* Acquire global USER lock */
393 /* Call the internal function */
394 Status
= UserEnumDisplayDevices(pustrDevice
, iDevNum
, &dispdev
, dwFlags
);
399 /* On success copy data to caller */
400 if (NT_SUCCESS(Status
))
405 /* First probe the cb field */
406 ProbeForWrite(&pDisplayDevice
->cb
, sizeof(DWORD
), 1);
408 /* Check the buffer size */
409 if (pDisplayDevice
->cb
)
411 /* Probe the output buffer */
412 pDisplayDevice
->cb
= min(pDisplayDevice
->cb
, sizeof(dispdev
));
413 ProbeForWrite(pDisplayDevice
, pDisplayDevice
->cb
, 1);
415 /* Copy as much as the given buffer allows */
416 RtlCopyMemory(pDisplayDevice
, &dispdev
, pDisplayDevice
->cb
);
419 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
421 Status
= _SEH2_GetExceptionCode();
426 TRACE("Leave NtUserEnumDisplayDevices, Status = 0x%lx\n", Status
);
427 /* Return the result */
429 return NT_SUCCESS(Status
); // FIXME
434 UserEnumCurrentDisplaySettings(
435 PUNICODE_STRING pustrDevice
,
440 /* Get the PDEV for the device */
441 ppdev
= EngpGetPDEV(pustrDevice
);
444 /* No device found */
445 ERR("No PDEV found!\n");
446 return STATUS_INVALID_PARAMETER_1
;
449 *ppdm
= ppdev
->pdmwDev
;
450 PDEVOBJ_vRelease(ppdev
);
452 return STATUS_SUCCESS
;
457 UserEnumDisplaySettings(
458 PUNICODE_STRING pustrDevice
,
463 PGRAPHICS_DEVICE pGraphicsDevice
;
464 PDEVMODEENTRY pdmentry
;
467 TRACE("Enter UserEnumDisplaySettings('%wZ', %lu)\n",
468 pustrDevice
, iModeNum
);
470 /* Ask GDI for the GRAPHICS_DEVICE */
471 pGraphicsDevice
= EngpFindGraphicsDevice(pustrDevice
, 0, 0);
473 if (!pGraphicsDevice
)
475 /* No device found */
476 ERR("No device found!\n");
477 return STATUS_INVALID_PARAMETER_1
;
481 for (i
= 0; i
< pGraphicsDevice
->cDevModes
; i
++)
483 pdmentry
= &pGraphicsDevice
->pDevModeList
[i
];
485 /* FIXME: Consider EDS_RAWMODE */
487 if ((!(dwFlags
& EDS_RAWMODE
) && (pdmentry
->dwFlags
& 1)) ||!
488 (dwFlags
& EDS_RAWMODE
))
491 /* Is this the one we want? */
492 if (iFoundMode
== iModeNum
)
494 *ppdm
= pdmentry
->pdm
;
495 return STATUS_SUCCESS
;
498 /* Increment number of found modes */
503 /* Nothing was found */
504 return STATUS_INVALID_PARAMETER_2
;
509 UserOpenDisplaySettingsKey(
511 IN PUNICODE_STRING pustrDevice
,
515 DISPLAY_DEVICEW dispdev
;
518 /* Get device info */
519 Status
= UserEnumDisplayDevices(pustrDevice
, 0, &dispdev
, 0);
520 if (!NT_SUCCESS(Status
))
525 // FIXME: Need to fix the registry key somehow
528 /* Open the registry key */
529 Status
= RegOpenKey(dispdev
.DeviceKey
, &hkey
);
530 if (!NT_SUCCESS(Status
))
540 UserEnumRegistryDisplaySettings(
541 IN PUNICODE_STRING pustrDevice
,
545 NTSTATUS Status
= UserOpenDisplaySettingsKey(&hkey
, pustrDevice
, 0);
546 if(NT_SUCCESS(Status
))
548 RegReadDisplaySettings(hkey
, pdm
);
550 return STATUS_SUCCESS
;
557 NtUserEnumDisplaySettings(
558 IN PUNICODE_STRING pustrDevice
,
560 OUT LPDEVMODEW lpDevMode
,
563 UNICODE_STRING ustrDevice
;
564 WCHAR awcDevice
[CCHDEVICENAME
];
566 ULONG cbSize
, cbExtra
;
567 DEVMODEW dmReg
, *pdm
;
569 TRACE("Enter NtUserEnumDisplaySettings(%wZ, %lu, %p, 0x%lx)\n",
570 pustrDevice
, iModeNum
, lpDevMode
, dwFlags
);
574 ProbeForRead(lpDevMode
, sizeof(DEVMODEW
), sizeof(UCHAR
));
576 cbSize
= lpDevMode
->dmSize
;
577 cbExtra
= lpDevMode
->dmDriverExtra
;
579 ProbeForWrite(lpDevMode
, cbSize
+ cbExtra
, sizeof(UCHAR
));
581 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
583 _SEH2_YIELD(return _SEH2_GetExceptionCode());
587 if (lpDevMode
->dmSize
!= sizeof(DEVMODEW
))
589 return STATUS_BUFFER_TOO_SMALL
;
594 /* Initialize destination string */
595 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
599 /* Probe the UNICODE_STRING and the buffer */
600 ProbeForReadUnicodeString(pustrDevice
);
602 if (!pustrDevice
->Length
|| !pustrDevice
->Buffer
)
603 ExRaiseStatus(STATUS_NO_MEMORY
);
605 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, sizeof(UCHAR
));
607 /* Copy the string */
608 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
610 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
612 _SEH2_YIELD(return STATUS_INVALID_PARAMETER_1
);
616 pustrDevice
= &ustrDevice
;
619 /* Acquire global USER lock */
622 if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
624 /* Get the registry settings */
625 Status
= UserEnumRegistryDisplaySettings(pustrDevice
, &dmReg
);
627 pdm
->dmSize
= sizeof(DEVMODEW
);
629 else if (iModeNum
== ENUM_CURRENT_SETTINGS
)
631 /* Get the current settings */
632 Status
= UserEnumCurrentDisplaySettings(pustrDevice
, &pdm
);
636 /* Get specified settings */
637 Status
= UserEnumDisplaySettings(pustrDevice
, iModeNum
, &pdm
, dwFlags
);
643 /* Did we succeed? */
644 if (NT_SUCCESS(Status
))
646 /* Copy some information back */
649 /* Output what we got */
650 RtlCopyMemory(lpDevMode
, pdm
, min(cbSize
, pdm
->dmSize
));
652 /* Output private/extra driver data */
653 if (cbExtra
> 0 && pdm
->dmDriverExtra
> 0)
655 RtlCopyMemory((PCHAR
)lpDevMode
+ cbSize
,
656 (PCHAR
)pdm
+ pdm
->dmSize
,
657 min(cbExtra
, pdm
->dmDriverExtra
));
660 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
662 Status
= _SEH2_GetExceptionCode();
670 UserUpdateFullscreen(
673 if (flags
& CDS_FULLSCREEN
)
674 gpFullscreen
= gptiCurrent
->ppi
;
681 UserChangeDisplaySettings(
682 PUNICODE_STRING pustrDevice
,
688 LONG lResult
= DISP_CHANGE_SUCCESSFUL
;
694 /* If no DEVMODE is given, use registry settings */
697 /* Get the registry settings */
698 Status
= UserEnumRegistryDisplaySettings(pustrDevice
, &dm
);
699 if (!NT_SUCCESS(Status
))
701 ERR("Could not load registry settings\n");
702 return DISP_CHANGE_BADPARAM
;
705 else if (pdm
->dmSize
< FIELD_OFFSET(DEVMODEW
, dmFields
))
706 return DISP_CHANGE_BADMODE
; /* This is what winXP SP3 returns */
711 if ((dm
.dmFields
& (DM_PELSWIDTH
| DM_PELSHEIGHT
)) != (DM_PELSWIDTH
| DM_PELSHEIGHT
))
713 ERR("Devmode doesn't specify the resolution.\n");
714 return DISP_CHANGE_BADMODE
;
718 ppdev
= EngpGetPDEV(pustrDevice
);
721 ERR("Failed to get PDEV\n");
722 return DISP_CHANGE_BADPARAM
;
726 if(dm
.dmBitsPerPel
== 0 || !(dm
.dmFields
& DM_BITSPERPEL
))
728 dm
.dmBitsPerPel
= ppdev
->pdmwDev
->dmBitsPerPel
;
729 dm
.dmFields
|= DM_BITSPERPEL
;
732 if((dm
.dmFields
& DM_DISPLAYFREQUENCY
) && (dm
.dmDisplayFrequency
== 0))
733 dm
.dmDisplayFrequency
= ppdev
->pdmwDev
->dmDisplayFrequency
;
735 /* Look for the requested DEVMODE */
736 pdm
= PDEVOBJ_pdmMatchDevMode(ppdev
, &dm
);
739 ERR("Could not find a matching DEVMODE\n");
740 lResult
= DISP_CHANGE_BADMODE
;
743 else if (flags
& CDS_TEST
)
745 /* It's possible, go ahead! */
746 lResult
= DISP_CHANGE_SUCCESSFUL
;
750 /* Shall we update the registry? */
751 if (flags
& CDS_UPDATEREGISTRY
)
753 /* Open the local or global settings key */
754 Status
= UserOpenDisplaySettingsKey(&hkey
, pustrDevice
, flags
& CDS_GLOBAL
);
755 if (NT_SUCCESS(Status
))
757 /* Store the settings */
758 RegWriteDisplaySettings(hkey
, pdm
);
760 /* Close the registry key */
765 ERR("Could not open registry key\n");
766 lResult
= DISP_CHANGE_NOTUPDATED
;
770 /* Check if DEVMODE matches the current mode */
771 if (pdm
== ppdev
->pdmwDev
&& !(flags
& CDS_RESET
))
773 ERR("DEVMODE matches, nothing to do\n");
777 /* Shall we apply the settings? */
778 if (!(flags
& CDS_NORESET
))
783 /* Remove mouse pointer */
784 pvOldCursor
= UserSetCursor(NULL
, TRUE
);
786 /* Do the mode switch */
787 ulResult
= PDEVOBJ_bSwitchMode(ppdev
, pdm
);
789 /* Restore mouse pointer, no hooks called */
790 pvOldCursor
= UserSetCursor(pvOldCursor
, TRUE
);
791 ASSERT(pvOldCursor
== NULL
);
793 /* Check for failure */
796 ERR("Failed to set mode\n");
797 lResult
= (lResult
== DISP_CHANGE_NOTUPDATED
) ?
798 DISP_CHANGE_FAILED
: DISP_CHANGE_RESTART
;
803 UserUpdateFullscreen(flags
);
805 /* Update the system metrics */
808 //IntvGetDeviceCaps(&PrimarySurface, &GdiHandleTable->DevCaps);
810 /* Set new size of the monitor */
811 UserUpdateMonitorSize((HDEV
)ppdev
);
813 /* Remove all cursor clipping */
814 UserClipCursor(NULL
);
816 //pdesk = IntGetActiveDesktop();
817 //IntHideDesktop(pdesk);
819 /* Send WM_DISPLAYCHANGE to all toplevel windows */
820 co_IntSendMessageTimeout(HWND_BROADCAST
,
822 (WPARAM
)ppdev
->gdiinfo
.cBitsPixel
,
823 (LPARAM
)(ppdev
->gdiinfo
.ulHorzRes
+ (ppdev
->gdiinfo
.ulVertRes
<< 16)),
828 //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
834 /* Release the PDEV */
835 PDEVOBJ_vRelease(ppdev
);
841 UserDisplayNotifyShutdown(
842 PPROCESSINFO ppiCurrent
)
844 if (ppiCurrent
== gpFullscreen
)
846 UserChangeDisplaySettings(NULL
, NULL
, 0, NULL
);
848 ERR("Failed to restore display mode!\n");
854 NtUserChangeDisplaySettings(
855 PUNICODE_STRING pustrDevice
,
856 LPDEVMODEW lpDevMode
,
860 WCHAR awcDevice
[CCHDEVICENAME
];
861 UNICODE_STRING ustrDevice
;
865 /* Check arguments */
866 if ((dwflags
!= CDS_VIDEOPARAMETERS
) && (lParam
!= NULL
))
868 EngSetLastError(ERROR_INVALID_PARAMETER
);
869 return DISP_CHANGE_BADPARAM
;
873 if ((dwflags
& (CDS_GLOBAL
|CDS_NORESET
)) && !(dwflags
& CDS_UPDATEREGISTRY
))
875 return DISP_CHANGE_BADFLAGS
;
878 /* Copy the device name */
881 /* Initialize destination string */
882 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
886 /* Probe the UNICODE_STRING and the buffer */
887 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
888 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
890 /* Copy the string */
891 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
893 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
895 /* Set and return error */
896 SetLastNtError(_SEH2_GetExceptionCode());
897 _SEH2_YIELD(return DISP_CHANGE_BADPARAM
);
901 pustrDevice
= &ustrDevice
;
909 /* Probe the size field of the structure */
910 ProbeForRead(lpDevMode
, sizeof(dmLocal
.dmSize
), 1);
912 /* Calculate usable size */
913 dmLocal
.dmSize
= min(sizeof(dmLocal
), lpDevMode
->dmSize
);
915 /* Probe and copy the full DEVMODE */
916 ProbeForRead(lpDevMode
, dmLocal
.dmSize
, 1);
917 RtlCopyMemory(&dmLocal
, lpDevMode
, dmLocal
.dmSize
);
919 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
921 /* Set and return error */
922 SetLastNtError(_SEH2_GetExceptionCode());
923 _SEH2_YIELD(return DISP_CHANGE_BADPARAM
);
927 /* Check for extra parameters */
928 if (dmLocal
.dmDriverExtra
> 0)
931 ERR("lpDevMode->dmDriverExtra is IGNORED!\n");
932 dmLocal
.dmDriverExtra
= 0;
935 /* Use the local structure */
936 lpDevMode
= &dmLocal
;
939 // FIXME: Copy videoparameters
941 /* Acquire global USER lock */
942 UserEnterExclusive();
944 /* Call internal function */
945 lRet
= UserChangeDisplaySettings(pustrDevice
, lpDevMode
, dwflags
, NULL
);