comparison win/dw.c @ 2136:bbd81ee0ca9a

Win: Changes to allow composition to be the default on supported versions of Windows. Enable layered top-level windows when using Aero on Windows Vista and higher. Set the windows opaque if DW_FCF_COMPOSITED is not set, otherwise set transparecy key.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 09 Jul 2020 01:33:12 +0000
parents d9720d48d61e
children e780c68cf5b1
comparison
equal deleted inserted replaced
2135:d9720d48d61e 2136:bbd81ee0ca9a
2019 * which when clicked will display the window's menubar menu. Since the menubar cannot be 2019 * which when clicked will display the window's menubar menu. Since the menubar cannot be
2020 * made dark, hide it and add the button to the titlebar instead. 2020 * made dark, hide it and add the button to the titlebar instead.
2021 */ 2021 */
2022 if(msg == WM_NCCALCSIZE && mp2 && _DW_DARK_MODE_ENABLED && _DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC) 2022 if(msg == WM_NCCALCSIZE && mp2 && _DW_DARK_MODE_ENABLED && _DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC)
2023 { 2023 {
2024 MARGINS *margins = dw_window_get_data(hWnd, "_dw_margins");
2025 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd); 2024 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
2026 2025
2027 if(margins && cinfo) 2026 if(cinfo)
2028 { 2027 {
2029 NCCALCSIZE_PARAMS* sz = (NCCALCSIZE_PARAMS*)mp2; 2028 /*NCCALCSIZE_PARAMS* sz = (NCCALCSIZE_PARAMS*)mp2;
2030 2029
2031 sz->rgrc[0].left += cinfo->rect.left; 2030 sz->rgrc[0].left += cinfo->rect.left;
2032 sz->rgrc[0].right -= cinfo->rect.right; 2031 sz->rgrc[0].right -= cinfo->rect.right;
2033 sz->rgrc[0].bottom -= cinfo->rect.bottom; 2032 sz->rgrc[0].bottom -= cinfo->rect.bottom;;*/
2034
2035 if (_DwmExtendFrameIntoClientArea)
2036 _DwmExtendFrameIntoClientArea(hWnd, margins);
2037 SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
2038 return 0; 2033 return 0;
2039 } 2034 }
2040 } 2035 }
2041 else if(msg == WM_NCHITTEST && _DW_DARK_MODE_ENABLED && _DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC) 2036 else if(msg == WM_NCHITTEST && _DW_DARK_MODE_ENABLED && _DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC)
2042 { 2037 {
2048 2043
2049 /* Do default processing, except change the result for caption area */ 2044 /* Do default processing, except change the result for caption area */
2050 lResult = DefWindowProc(hWnd, msg, mp1, mp2); 2045 lResult = DefWindowProc(hWnd, msg, mp1, mp2);
2051 if(lResult == HTCLIENT) 2046 if(lResult == HTCLIENT)
2052 { 2047 {
2053 MARGINS *margins = dw_window_get_data(hWnd, "_dw_margins");
2054 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd); 2048 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
2055 2049
2056 if(margins && cinfo) 2050 if(cinfo)
2057 { 2051 {
2058 POINT pt = { LOWORD(mp2), HIWORD(mp2) }; 2052 POINT pt = { LOWORD(mp2), HIWORD(mp2) };
2059 2053
2060 ScreenToClient(hWnd, &pt); 2054 ScreenToClient(hWnd, &pt);
2061 if (pt.y < cinfo->rect.top) return HTTOP; 2055 if (pt.y < cinfo->rect.top) return HTTOP;
2062 if (pt.y < margins->cyTopHeight) return HTCAPTION; 2056 /*if (pt.y < margins->cyTopHeight) return HTCAPTION;*/
2063 } 2057 }
2064 } 2058 }
2065 return lResult; 2059 return lResult;
2066 } 2060 }
2067 #endif 2061 #endif
2569 switch( msg ) 2563 switch( msg )
2570 { 2564 {
2571 #ifdef AEROGLASS 2565 #ifdef AEROGLASS
2572 case WM_DWMCOMPOSITIONCHANGED: 2566 case WM_DWMCOMPOSITIONCHANGED:
2573 { 2567 {
2574 LONG_PTR styleex = GetWindowLongPtr(hWnd, GWL_EXSTYLE); 2568 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
2575 2569
2576 if(_DwmIsCompositionEnabled) 2570 if(_DwmIsCompositionEnabled)
2577 _DwmIsCompositionEnabled(&_dw_composition); 2571 _DwmIsCompositionEnabled(&_dw_composition);
2578 2572
2579 /* If we are no longer compositing... disable layered windows */ 2573 if(cinfo && (cinfo->style & DW_FCF_COMPOSITED))
2580 if(!_dw_composition && (styleex & WS_EX_LAYERED))
2581 { 2574 {
2582 MARGINS *mar = dw_window_get_data(hWnd, "_dw_margins"); 2575 /* If we are no longer compositing... */
2583 2576 if(!_dw_composition)
2584 SetWindowLongPtr(hWnd, GWL_EXSTYLE, styleex & ~WS_EX_LAYERED); 2577 {
2585 if(_DwmExtendFrameIntoClientArea && mar) 2578 MARGINS mar = {0};
2586 _DwmExtendFrameIntoClientArea(hWnd, mar); 2579
2580 SetLayeredWindowAttributes(hWnd, _dw_transparencykey, 255, LWA_ALPHA);
2581 if(_DwmExtendFrameIntoClientArea)
2582 _DwmExtendFrameIntoClientArea(hWnd, &mar);
2583 }
2584 /* If we have started compositing... */
2585 else
2586 {
2587 MARGINS mar = {-1};
2588
2589 SetLayeredWindowAttributes(hWnd, _dw_transparencykey, 0, LWA_COLORKEY);
2590 if(_DwmExtendFrameIntoClientArea)
2591 _DwmExtendFrameIntoClientArea(hWnd, &mar);
2592 }
2587 } 2593 }
2588 } 2594 }
2589 break; 2595 break;
2590 case WM_SETTINGCHANGE: 2596 case WM_SETTINGCHANGE:
2591 { 2597 {
2824 SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)_DW_GetSysColorBrush(COLOR_3DFACE)); 2830 SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)_DW_GetSysColorBrush(COLOR_3DFACE));
2825 InvalidateRect(hWnd, NULL, TRUE); 2831 InvalidateRect(hWnd, NULL, TRUE);
2826 } 2832 }
2827 break; 2833 break;
2828 case WM_ERASEBKGND: 2834 case WM_ERASEBKGND:
2829 if(_dw_composition && (GetWindowLongPtr(_toplevel_window(hWnd), GWL_EXSTYLE) & WS_EX_LAYERED)) 2835 if(_dw_composition)
2830 { 2836 {
2831 static HBRUSH hbrush = 0; 2837 ColorInfo *cinfo = _dw_window_get_cinfo(_toplevel_window(hWnd));
2832 RECT rect; 2838
2833 2839 if(cinfo && cinfo->style & DW_FCF_COMPOSITED)
2834 if(!hbrush) 2840 {
2835 hbrush = CreateSolidBrush(_dw_transparencykey); 2841 static HBRUSH hbrush = 0;
2836 2842 RECT rect;
2837 GetClientRect(hWnd, &rect); 2843
2838 FillRect((HDC)mp1, &rect, hbrush); 2844 if(!hbrush)
2839 return TRUE; 2845 hbrush = CreateSolidBrush(_dw_transparencykey);
2846
2847 GetClientRect(hWnd, &rect);
2848 FillRect((HDC)mp1, &rect, hbrush);
2849 return TRUE;
2850 }
2840 } 2851 }
2841 break; 2852 break;
2842 #endif 2853 #endif
2843 case WM_PAINT: 2854 case WM_PAINT:
2844 { 2855 {
3313 { 3324 {
3314 case WM_CTLCOLORSTATIC: 3325 case WM_CTLCOLORSTATIC:
3315 case WM_CTLCOLORBTN: 3326 case WM_CTLCOLORBTN:
3316 case WM_CTLCOLORDLG: 3327 case WM_CTLCOLORDLG:
3317 { 3328 {
3318 3329 ColorInfo *tlcinfo = _dw_window_get_cinfo(_toplevel_window(hWnd));
3319 if((_dw_composition && GetWindowLongPtr(_toplevel_window(hWnd), GWL_EXSTYLE) & WS_EX_LAYERED) && 3330
3331 if((_dw_composition && tlcinfo && (tlcinfo->style & DW_FCF_COMPOSITED)) &&
3320 (!thiscinfo || (thiscinfo && (thiscinfo->back == -1 || thiscinfo->back == DW_RGB_TRANSPARENT)))) 3332 (!thiscinfo || (thiscinfo && (thiscinfo->back == -1 || thiscinfo->back == DW_RGB_TRANSPARENT))))
3321 { 3333 {
3322 if(!(msg == WM_CTLCOLORSTATIC && SendMessage((HWND)mp2, STM_GETIMAGE, IMAGE_BITMAP, 0))) 3334 if(!(msg == WM_CTLCOLORSTATIC && SendMessage((HWND)mp2, STM_GETIMAGE, IMAGE_BITMAP, 0)))
3323 { 3335 {
3324 SetBkColor((HDC)mp1, _dw_transparencykey); 3336 SetBkColor((HDC)mp1, _dw_transparencykey);
3958 3970
3959 #ifdef AEROGLASS 3971 #ifdef AEROGLASS
3960 /* Window procedure to handle drawing themed text when in composited mode */ 3972 /* Window procedure to handle drawing themed text when in composited mode */
3961 LRESULT CALLBACK _staticwndproc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) 3973 LRESULT CALLBACK _staticwndproc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2)
3962 { 3974 {
3963 ColorInfo *parentcinfo, *cinfo = _dw_window_get_cinfo(hwnd); 3975 ColorInfo *parentcinfo, *tlcinfo, *cinfo = _dw_window_get_cinfo(hwnd);
3964 WNDPROC pOldProc; 3976 WNDPROC pOldProc;
3965 3977
3966 if (!cinfo) 3978 if (!cinfo)
3967 return DefWindowProc(hwnd, msg, mp1, mp2); 3979 return DefWindowProc(hwnd, msg, mp1, mp2);
3968 3980
3969 /* Need the parent to do the check completely */ 3981 /* Need the parent to do the check completely */
3970 parentcinfo = _dw_window_get_cinfo(GetParent(hwnd)); 3982 parentcinfo = _dw_window_get_cinfo(GetParent(hwnd));
3983 tlcinfo = _dw_window_get_cinfo(_toplevel_window(hwnd));
3971 3984
3972 /* If we don't require themed drawing */ 3985 /* If we don't require themed drawing */
3973 if(((cinfo->back != -1 && cinfo->back != DW_RGB_TRANSPARENT) || (parentcinfo && parentcinfo->back != -1)) 3986 if(((cinfo->back != -1 && cinfo->back != DW_RGB_TRANSPARENT) || (parentcinfo && parentcinfo->back != -1))
3974 || !_dw_composition || !(GetWindowLongPtr(_toplevel_window(hwnd), GWL_EXSTYLE) & WS_EX_LAYERED)) 3987 || !_dw_composition || !tlcinfo || !(tlcinfo->style & DW_FCF_COMPOSITED))
3975 return _colorwndproc(hwnd, msg, mp1, mp2); 3988 return _colorwndproc(hwnd, msg, mp1, mp2);
3976 3989
3977 pOldProc = cinfo->pOldProc; 3990 pOldProc = cinfo->pOldProc;
3978 3991
3979 switch(msg) 3992 switch(msg)
5639 { 5652 {
5640 HWND hwndframe; 5653 HWND hwndframe;
5641 Box *newbox = calloc(sizeof(Box), 1); 5654 Box *newbox = calloc(sizeof(Box), 1);
5642 ULONG flStyleEx = 0; 5655 ULONG flStyleEx = 0;
5643 #ifdef AEROGLASS 5656 #ifdef AEROGLASS
5644 MARGINS *margins = calloc(1, sizeof(MARGINS)); 5657 flStyleEx = WS_EX_LAYERED;
5645
5646 if (_dw_composition && (flStyle & DW_FCF_COMPOSITED))
5647 flStyleEx = WS_EX_LAYERED;
5648 #endif 5658 #endif
5649 5659
5650 newbox->type = DW_VERT; 5660 newbox->type = DW_VERT;
5651 newbox->vsize = newbox->hsize = SIZEEXPAND; 5661 newbox->vsize = newbox->hsize = SIZEEXPAND;
5652 newbox->cinfo.fore = newbox->cinfo.back = -1; 5662 newbox->cinfo.fore = newbox->cinfo.back = -1;
5678 /* Determine the borders of the default window frame */ 5688 /* Determine the borders of the default window frame */
5679 AdjustWindowRectEx(&(newbox->cinfo.rect), flStyle, FALSE, 0); 5689 AdjustWindowRectEx(&(newbox->cinfo.rect), flStyle, FALSE, 0);
5680 newbox->cinfo.rect.left *= -1; 5690 newbox->cinfo.rect.left *= -1;
5681 newbox->cinfo.rect.top *= -1; 5691 newbox->cinfo.rect.top *= -1;
5682 5692
5683 /* With the DW_FCF_COMPOSITED flag, expand it to the entire window */ 5693 if(flStyle & DW_FCF_COMPOSITED)
5684 if (flStyle & DW_FCF_COMPOSITED) 5694 {
5685 { 5695 /* Attempt to enable Aero glass background on the entire window */
5686 MARGINS fullmar = { -1 }; 5696 if(_DwmExtendFrameIntoClientArea && _dw_composition)
5687 *margins = fullmar; 5697 {
5698 MARGINS fullmar = { -1 };
5699
5700 _DwmExtendFrameIntoClientArea(hwndframe, &fullmar);
5701 }
5702 SetLayeredWindowAttributes(hwndframe, _dw_transparencykey, 0, LWA_COLORKEY);
5688 } 5703 }
5689 else 5704 else
5690 { 5705 SetLayeredWindowAttributes(hwndframe, _dw_transparencykey, 255, LWA_ALPHA);
5691 /* Otherwise use the calculated border sizes */
5692 margins->cyTopHeight = newbox->cinfo.rect.top;
5693 }
5694
5695 dw_window_set_data(hwndframe, "_dw_margins", margins);
5696
5697 /* Attempt to enable Aero glass background on the entire window */
5698 if(_DwmExtendFrameIntoClientArea && _dw_composition &&
5699 ((flStyle & DW_FCF_COMPOSITED) || (_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED)))
5700 {
5701 SetLayeredWindowAttributes(hwndframe, _dw_transparencykey, 0, LWA_COLORKEY);
5702 _DwmExtendFrameIntoClientArea(hwndframe, margins);
5703 }
5704 #endif 5706 #endif
5705 5707
5706 return hwndframe; 5708 return hwndframe;
5707 } 5709 }
5708 5710
8266 { 8268 {
8267 tmp = tmp & 0xffff0000; 8269 tmp = tmp & 0xffff0000;
8268 #ifdef AEROGLASS 8270 #ifdef AEROGLASS
8269 if(mask & DW_FCF_COMPOSITED && _DwmExtendFrameIntoClientArea && _dw_composition) 8271 if(mask & DW_FCF_COMPOSITED && _DwmExtendFrameIntoClientArea && _dw_composition)
8270 { 8272 {
8271 LONG_PTR styleex = GetWindowLongPtr(handle, GWL_EXSTYLE);
8272
8273 if(style & DW_FCF_COMPOSITED) 8273 if(style & DW_FCF_COMPOSITED)
8274 { 8274 {
8275 MARGINS mar = {-1}; 8275 MARGINS mar = {-1};
8276 8276
8277 /* Attempt to enable Aero glass background on the entire window */ 8277 /* Attempt to enable Aero glass background on the entire window */
8278 SetWindowLongPtr(handle, GWL_EXSTYLE, styleex | WS_EX_LAYERED);
8279 SetLayeredWindowAttributes(handle, _dw_transparencykey, 0, LWA_COLORKEY); 8278 SetLayeredWindowAttributes(handle, _dw_transparencykey, 0, LWA_COLORKEY);
8280 _DwmExtendFrameIntoClientArea(handle, &mar); 8279 _DwmExtendFrameIntoClientArea(handle, &mar);
8281 } 8280 }
8282 else 8281 else
8283 { 8282 {
8284 MARGINS mar = {0}; 8283 MARGINS mar = {0};
8285 8284
8286 /* Remove Aero Glass */ 8285 /* Remove Aero Glass */
8287 SetWindowLongPtr(handle, GWL_EXSTYLE, styleex & ~WS_EX_LAYERED); 8286 SetLayeredWindowAttributes(handle, _dw_transparencykey, 255, LWA_ALPHA);
8288 _DwmExtendFrameIntoClientArea(handle, &mar); 8287 _DwmExtendFrameIntoClientArea(handle, &mar);
8289 } 8288 }
8290 } 8289 }
8291 #endif 8290 #endif
8292 } 8291 }