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
))
172 cbValue
= sizeof(awcBuffer
);
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 */
196 cbValue
= sizeof(awcDeviceName
);
197 Status
= RegQueryValue(hkey
, L
"VgaCompatible", REG_SZ
, awcDeviceName
, &cbValue
);
198 if (NT_SUCCESS(Status
))
200 iVGACompatible
= _wtoi(&awcDeviceName
[sizeof("\\Device\\Video")-1]);
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
;
285 return STATUS_SUCCESS
;
289 UserRefreshDisplay(IN PPDEVOBJ ppdev
)
292 // PVOID pvOldCursor;
294 // TODO: Re-enable the cursor reset code once this function becomes called
295 // from within a Win32 thread... Indeed UserSetCursor() requires this, but
296 // at the moment this function is directly called from a separate thread
297 // from within videoprt, instead of by a separate win32k system thread.
302 PDEVOBJ_vReference(ppdev
);
304 /* Remove mouse pointer */
305 // pvOldCursor = UserSetCursor(NULL, TRUE);
307 /* Do the mode switch -- Use the actual same current mode */
308 ulResult
= PDEVOBJ_bSwitchMode(ppdev
, ppdev
->pdmwDev
);
311 /* Restore mouse pointer, no hooks called */
312 // pvOldCursor = UserSetCursor(pvOldCursor, TRUE);
313 // ASSERT(pvOldCursor == NULL);
315 /* Update the system metrics */
318 /* Set new size of the monitor */
319 // UserUpdateMonitorSize((HDEV)ppdev);
321 //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
324 PDEVOBJ_vRelease(ppdev
);
329 UserEnumDisplayDevices(
330 PUNICODE_STRING pustrDevice
,
332 PDISPLAY_DEVICEW pdispdev
,
335 PGRAPHICS_DEVICE pGraphicsDevice
;
340 /* Ask gdi for the GRAPHICS_DEVICE */
341 pGraphicsDevice
= EngpFindGraphicsDevice(pustrDevice
, iDevNum
, 0);
342 if (!pGraphicsDevice
)
344 /* No device found */
345 ERR("No GRAPHICS_DEVICE found\n");
346 return STATUS_UNSUCCESSFUL
;
349 /* Open the device map registry key */
350 Status
= RegOpenKey(KEY_VIDEO
, &hkey
);
351 if (!NT_SUCCESS(Status
))
353 /* No device found */
354 ERR("Could not open reg key\n");
355 return STATUS_UNSUCCESSFUL
;
358 /* Query the registry path */
359 cbSize
= sizeof(pdispdev
->DeviceKey
);
361 pGraphicsDevice
->szNtDeviceName
,
366 /* Close registry key */
369 /* Copy device name, device string and StateFlags */
370 RtlStringCbCopyW(pdispdev
->DeviceName
, sizeof(pdispdev
->DeviceName
), pGraphicsDevice
->szWinDeviceName
);
371 RtlStringCbCopyW(pdispdev
->DeviceString
, sizeof(pdispdev
->DeviceString
), pGraphicsDevice
->pwszDescription
);
372 pdispdev
->StateFlags
= pGraphicsDevice
->StateFlags
;
373 // FIXME: fill in DEVICE ID
374 pdispdev
->DeviceID
[0] = UNICODE_NULL
;
376 return STATUS_SUCCESS
;
382 NtUserEnumDisplayDevices(
383 PUNICODE_STRING pustrDevice
,
385 PDISPLAY_DEVICEW pDisplayDevice
,
388 UNICODE_STRING ustrDevice
;
389 WCHAR awcDevice
[CCHDEVICENAME
];
390 DISPLAY_DEVICEW dispdev
;
393 TRACE("Enter NtUserEnumDisplayDevices(%wZ, %lu)\n",
394 pustrDevice
, iDevNum
);
396 dispdev
.cb
= sizeof(dispdev
);
400 /* Initialize destination string */
401 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
405 /* Probe the UNICODE_STRING and the buffer */
406 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
407 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
409 /* Copy the string */
410 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
412 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
414 // _SEH2_YIELD(return _SEH2_GetExceptionCode());
415 _SEH2_YIELD(return NT_SUCCESS(_SEH2_GetExceptionCode()));
419 if (ustrDevice
.Length
> 0)
420 pustrDevice
= &ustrDevice
;
425 /* If name is given only iDevNum==0 gives results */
426 if (pustrDevice
&& iDevNum
!= 0)
429 /* Acquire global USER lock */
432 /* Call the internal function */
433 Status
= UserEnumDisplayDevices(pustrDevice
, iDevNum
, &dispdev
, dwFlags
);
438 /* On success copy data to caller */
439 if (NT_SUCCESS(Status
))
444 /* First probe the cb field */
445 ProbeForWrite(&pDisplayDevice
->cb
, sizeof(DWORD
), 1);
447 /* Check the buffer size */
448 if (pDisplayDevice
->cb
)
450 /* Probe the output buffer */
451 pDisplayDevice
->cb
= min(pDisplayDevice
->cb
, sizeof(dispdev
));
452 ProbeForWrite(pDisplayDevice
, pDisplayDevice
->cb
, 1);
454 /* Copy as much as the given buffer allows */
455 RtlCopyMemory(pDisplayDevice
, &dispdev
, pDisplayDevice
->cb
);
458 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
460 Status
= _SEH2_GetExceptionCode();
465 TRACE("Leave NtUserEnumDisplayDevices, Status = 0x%lx\n", Status
);
466 /* Return the result */
468 return NT_SUCCESS(Status
); // FIXME
473 UserEnumCurrentDisplaySettings(
474 PUNICODE_STRING pustrDevice
,
479 /* Get the PDEV for the device */
480 ppdev
= EngpGetPDEV(pustrDevice
);
483 /* No device found */
484 ERR("No PDEV found!\n");
485 return STATUS_INVALID_PARAMETER_1
;
488 *ppdm
= ppdev
->pdmwDev
;
489 PDEVOBJ_vRelease(ppdev
);
491 return STATUS_SUCCESS
;
496 UserEnumDisplaySettings(
497 PUNICODE_STRING pustrDevice
,
502 PGRAPHICS_DEVICE pGraphicsDevice
;
503 PDEVMODEENTRY pdmentry
;
507 TRACE("Enter UserEnumDisplaySettings('%wZ', %lu)\n",
508 pustrDevice
, iModeNum
);
510 /* Ask GDI for the GRAPHICS_DEVICE */
511 pGraphicsDevice
= EngpFindGraphicsDevice(pustrDevice
, 0, 0);
512 ppdev
= EngpGetPDEV(pustrDevice
);
514 if (!pGraphicsDevice
|| !ppdev
)
516 /* No device found */
517 ERR("No device found!\n");
518 return STATUS_INVALID_PARAMETER_1
;
521 /* let's politely ask the driver for an updated mode list,
522 just in case there's something new in there (vbox) */
524 PDEVOBJ_vRefreshModeList(ppdev
);
525 PDEVOBJ_vRelease(ppdev
);
528 for (i
= 0; i
< pGraphicsDevice
->cDevModes
; i
++)
530 pdmentry
= &pGraphicsDevice
->pDevModeList
[i
];
532 /* FIXME: Consider EDS_RAWMODE */
534 if ((!(dwFlags
& EDS_RAWMODE
) && (pdmentry
->dwFlags
& 1)) ||!
535 (dwFlags
& EDS_RAWMODE
))
538 /* Is this the one we want? */
539 if (iFoundMode
== iModeNum
)
541 *ppdm
= pdmentry
->pdm
;
542 return STATUS_SUCCESS
;
545 /* Increment number of found modes */
550 /* Nothing was found */
551 return STATUS_INVALID_PARAMETER_2
;
556 UserOpenDisplaySettingsKey(
558 IN PUNICODE_STRING pustrDevice
,
562 DISPLAY_DEVICEW dispdev
;
565 /* Get device info */
566 Status
= UserEnumDisplayDevices(pustrDevice
, 0, &dispdev
, 0);
567 if (!NT_SUCCESS(Status
))
572 // FIXME: Need to fix the registry key somehow
575 /* Open the registry key */
576 Status
= RegOpenKey(dispdev
.DeviceKey
, &hkey
);
577 if (!NT_SUCCESS(Status
))
587 UserEnumRegistryDisplaySettings(
588 IN PUNICODE_STRING pustrDevice
,
592 NTSTATUS Status
= UserOpenDisplaySettingsKey(&hkey
, pustrDevice
, 0);
593 if(NT_SUCCESS(Status
))
595 RegReadDisplaySettings(hkey
, pdm
);
597 return STATUS_SUCCESS
;
604 NtUserEnumDisplaySettings(
605 IN PUNICODE_STRING pustrDevice
,
607 OUT LPDEVMODEW lpDevMode
,
610 UNICODE_STRING ustrDevice
;
611 WCHAR awcDevice
[CCHDEVICENAME
];
613 ULONG cbSize
, cbExtra
;
614 DEVMODEW dmReg
, *pdm
;
616 TRACE("Enter NtUserEnumDisplaySettings(%wZ, %lu, %p, 0x%lx)\n",
617 pustrDevice
, iModeNum
, lpDevMode
, dwFlags
);
621 ProbeForRead(lpDevMode
, sizeof(DEVMODEW
), sizeof(UCHAR
));
623 cbSize
= lpDevMode
->dmSize
;
624 cbExtra
= lpDevMode
->dmDriverExtra
;
626 ProbeForWrite(lpDevMode
, cbSize
+ cbExtra
, sizeof(UCHAR
));
628 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
630 _SEH2_YIELD(return _SEH2_GetExceptionCode());
634 if (lpDevMode
->dmSize
!= sizeof(DEVMODEW
))
636 return STATUS_BUFFER_TOO_SMALL
;
641 /* Initialize destination string */
642 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
646 /* Probe the UNICODE_STRING and the buffer */
647 ProbeForReadUnicodeString(pustrDevice
);
649 if (!pustrDevice
->Length
|| !pustrDevice
->Buffer
)
650 ExRaiseStatus(STATUS_NO_MEMORY
);
652 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, sizeof(UCHAR
));
654 /* Copy the string */
655 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
657 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
659 _SEH2_YIELD(return STATUS_INVALID_PARAMETER_1
);
663 pustrDevice
= &ustrDevice
;
666 /* Acquire global USER lock */
669 if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
671 /* Get the registry settings */
672 Status
= UserEnumRegistryDisplaySettings(pustrDevice
, &dmReg
);
674 pdm
->dmSize
= sizeof(DEVMODEW
);
676 else if (iModeNum
== ENUM_CURRENT_SETTINGS
)
678 /* Get the current settings */
679 Status
= UserEnumCurrentDisplaySettings(pustrDevice
, &pdm
);
683 /* Get specified settings */
684 Status
= UserEnumDisplaySettings(pustrDevice
, iModeNum
, &pdm
, dwFlags
);
690 /* Did we succeed? */
691 if (NT_SUCCESS(Status
))
693 /* Copy some information back */
696 /* Output what we got */
697 RtlCopyMemory(lpDevMode
, pdm
, min(cbSize
, pdm
->dmSize
));
699 /* Output private/extra driver data */
700 if (cbExtra
> 0 && pdm
->dmDriverExtra
> 0)
702 RtlCopyMemory((PCHAR
)lpDevMode
+ cbSize
,
703 (PCHAR
)pdm
+ pdm
->dmSize
,
704 min(cbExtra
, pdm
->dmDriverExtra
));
707 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
709 Status
= _SEH2_GetExceptionCode();
718 UserUpdateFullscreen(
721 if (flags
& CDS_FULLSCREEN
)
722 gpFullscreen
= gptiCurrent
->ppi
;
729 UserChangeDisplaySettings(
730 PUNICODE_STRING pustrDevice
,
736 LONG lResult
= DISP_CHANGE_SUCCESSFUL
;
743 /* If no DEVMODE is given, use registry settings */
746 /* Get the registry settings */
747 Status
= UserEnumRegistryDisplaySettings(pustrDevice
, &dm
);
748 if (!NT_SUCCESS(Status
))
750 ERR("Could not load registry settings\n");
751 return DISP_CHANGE_BADPARAM
;
754 else if (pdm
->dmSize
< FIELD_OFFSET(DEVMODEW
, dmFields
))
756 return DISP_CHANGE_BADMODE
; /* This is what WinXP SP3 returns */
763 /* Save original bit count */
764 OrigBC
= gpsi
->BitCount
;
767 if ((dm
.dmFields
& (DM_PELSWIDTH
| DM_PELSHEIGHT
)) != (DM_PELSWIDTH
| DM_PELSHEIGHT
))
769 ERR("Devmode doesn't specify the resolution.\n");
770 return DISP_CHANGE_BADMODE
;
774 ppdev
= EngpGetPDEV(pustrDevice
);
777 ERR("Failed to get PDEV\n");
778 return DISP_CHANGE_BADPARAM
;
782 if (dm
.dmBitsPerPel
== 0 || !(dm
.dmFields
& DM_BITSPERPEL
))
784 dm
.dmBitsPerPel
= ppdev
->pdmwDev
->dmBitsPerPel
;
785 dm
.dmFields
|= DM_BITSPERPEL
;
788 if ((dm
.dmFields
& DM_DISPLAYFREQUENCY
) && (dm
.dmDisplayFrequency
== 0))
789 dm
.dmDisplayFrequency
= ppdev
->pdmwDev
->dmDisplayFrequency
;
791 /* Look for the requested DEVMODE */
792 pdm
= PDEVOBJ_pdmMatchDevMode(ppdev
, &dm
);
795 ERR("Could not find a matching DEVMODE\n");
796 lResult
= DISP_CHANGE_BADMODE
;
799 else if (flags
& CDS_TEST
)
801 /* It's possible, go ahead! */
802 lResult
= DISP_CHANGE_SUCCESSFUL
;
806 /* Shall we update the registry? */
807 if (flags
& CDS_UPDATEREGISTRY
)
809 /* Open the local or global settings key */
810 Status
= UserOpenDisplaySettingsKey(&hkey
, pustrDevice
, flags
& CDS_GLOBAL
);
811 if (NT_SUCCESS(Status
))
813 /* Store the settings */
814 RegWriteDisplaySettings(hkey
, pdm
);
816 /* Close the registry key */
821 ERR("Could not open registry key\n");
822 lResult
= DISP_CHANGE_NOTUPDATED
;
826 /* Check if DEVMODE matches the current mode */
827 if (pdm
== ppdev
->pdmwDev
&& !(flags
& CDS_RESET
))
829 ERR("DEVMODE matches, nothing to do\n");
833 /* Shall we apply the settings? */
834 if (!(flags
& CDS_NORESET
))
840 /* Remove mouse pointer */
841 pvOldCursor
= UserSetCursor(NULL
, TRUE
);
843 /* Do the mode switch */
844 ulResult
= PDEVOBJ_bSwitchMode(ppdev
, pdm
);
846 /* Restore mouse pointer, no hooks called */
847 pvOldCursor
= UserSetCursor(pvOldCursor
, TRUE
);
848 ASSERT(pvOldCursor
== NULL
);
850 /* Check for success or failure */
853 /* Setting mode failed */
854 ERR("Failed to set mode\n");
856 /* Set the correct return value */
857 if ((flags
& CDS_UPDATEREGISTRY
) && (lResult
!= DISP_CHANGE_NOTUPDATED
))
858 lResult
= DISP_CHANGE_RESTART
;
860 lResult
= DISP_CHANGE_FAILED
;
864 /* Setting mode succeeded */
865 lResult
= DISP_CHANGE_SUCCESSFUL
;
867 UserUpdateFullscreen(flags
);
869 /* Update the system metrics */
872 /* Set new size of the monitor */
873 UserUpdateMonitorSize((HDEV
)ppdev
);
875 /* Update the SERVERINFO */
876 gpsi
->dmLogPixels
= ppdev
->gdiinfo
.ulLogPixelsY
;
877 gpsi
->Planes
= ppdev
->gdiinfo
.cPlanes
;
878 gpsi
->BitsPixel
= ppdev
->gdiinfo
.cBitsPixel
;
879 gpsi
->BitCount
= gpsi
->Planes
* gpsi
->BitsPixel
;
880 gpsi
->aiSysMet
[SM_CXSCREEN
] = ppdev
->gdiinfo
.ulHorzRes
;
881 gpsi
->aiSysMet
[SM_CYSCREEN
] = ppdev
->gdiinfo
.ulVertRes
;
882 if (ppdev
->gdiinfo
.flRaster
& RC_PALETTE
)
884 gpsi
->PUSIFlags
|= PUSIF_PALETTEDISPLAY
;
888 gpsi
->PUSIFlags
&= ~PUSIF_PALETTEDISPLAY
;
890 // Font is realized and this dc was previously set to internal DC_ATTR.
891 gpsi
->cxSysFontChar
= IntGetCharDimensions(hSystemBM
, &tmw
, (DWORD
*)&gpsi
->cySysFontChar
);
892 gpsi
->tmSysFont
= tmw
;
896 * Refresh the display on success and even on failure,
897 * since the display may have been messed up.
900 /* Remove all cursor clipping */
901 UserClipCursor(NULL
);
903 //pdesk = IntGetActiveDesktop();
904 //IntHideDesktop(pdesk);
906 /* Send WM_DISPLAYCHANGE to all toplevel windows */
907 co_IntSendMessageTimeout( HWND_BROADCAST
,
910 MAKELONG(gpsi
->aiSysMet
[SM_CXSCREEN
], gpsi
->aiSysMet
[SM_CYSCREEN
]),
915 ERR("BitCount New %d Orig %d ChkNew %d\n",gpsi
->BitCount
,OrigBC
,ppdev
->gdiinfo
.cBitsPixel
);
917 /* Not full screen and different bit count, send messages */
918 if (!(flags
& CDS_FULLSCREEN
) &&
919 gpsi
->BitCount
!= OrigBC
)
921 ERR("Detect settings changed.\n");
922 UserSendNotifyMessage(HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, 0);
923 UserSendNotifyMessage(HWND_BROADCAST
, WM_SYSCOLORCHANGE
, 0, 0);
926 //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
932 /* Release the PDEV */
933 PDEVOBJ_vRelease(ppdev
);
939 UserDisplayNotifyShutdown(
940 PPROCESSINFO ppiCurrent
)
942 if (ppiCurrent
== gpFullscreen
)
944 UserChangeDisplaySettings(NULL
, NULL
, 0, NULL
);
946 ERR("Failed to restore display mode!\n");
952 NtUserChangeDisplaySettings(
953 PUNICODE_STRING pustrDevice
,
954 LPDEVMODEW lpDevMode
,
958 WCHAR awcDevice
[CCHDEVICENAME
];
959 UNICODE_STRING ustrDevice
;
963 /* Check arguments */
964 if ((dwflags
!= CDS_VIDEOPARAMETERS
) && (lParam
!= NULL
))
966 EngSetLastError(ERROR_INVALID_PARAMETER
);
967 return DISP_CHANGE_BADPARAM
;
971 if ((dwflags
& (CDS_GLOBAL
|CDS_NORESET
)) && !(dwflags
& CDS_UPDATEREGISTRY
))
973 return DISP_CHANGE_BADFLAGS
;
976 if ((dwflags
& CDS_RESET
) && (dwflags
& CDS_NORESET
))
978 return DISP_CHANGE_BADFLAGS
;
981 /* Copy the device name */
984 /* Initialize destination string */
985 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
989 /* Probe the UNICODE_STRING and the buffer */
990 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
991 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
993 /* Copy the string */
994 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
996 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
998 /* Set and return error */
999 SetLastNtError(_SEH2_GetExceptionCode());
1000 _SEH2_YIELD(return DISP_CHANGE_BADPARAM
);
1004 pustrDevice
= &ustrDevice
;
1012 /* Probe the size field of the structure */
1013 ProbeForRead(lpDevMode
, sizeof(dmLocal
.dmSize
), 1);
1015 /* Calculate usable size */
1016 dmLocal
.dmSize
= min(sizeof(dmLocal
), lpDevMode
->dmSize
);
1018 /* Probe and copy the full DEVMODE */
1019 ProbeForRead(lpDevMode
, dmLocal
.dmSize
, 1);
1020 RtlCopyMemory(&dmLocal
, lpDevMode
, dmLocal
.dmSize
);
1022 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1024 /* Set and return error */
1025 SetLastNtError(_SEH2_GetExceptionCode());
1026 _SEH2_YIELD(return DISP_CHANGE_BADPARAM
);
1030 /* Check for extra parameters */
1031 if (dmLocal
.dmDriverExtra
> 0)
1034 ERR("lpDevMode->dmDriverExtra is IGNORED!\n");
1035 dmLocal
.dmDriverExtra
= 0;
1038 /* Use the local structure */
1039 lpDevMode
= &dmLocal
;
1042 // FIXME: Copy videoparameters
1044 /* Acquire global USER lock */
1045 UserEnterExclusive();
1047 /* Call internal function */
1048 lRet
= UserChangeDisplaySettings(pustrDevice
, lpDevMode
, dwflags
, NULL
);