/ src / modules / alwaysontop / AlwaysOnTop / WindowCornersUtil.cpp
WindowCornersUtil.cpp
 1  #include "pch.h"
 2  #include "WindowCornersUtil.h"
 3  
 4  #include <common/utils/winapi_error.h>
 5  
 6  #include <dwmapi.h>
 7  
 8  int WindowCornerUtils::CornerPreference(HWND window) noexcept
 9  {
10      int cornerPreference = -1;
11      auto res = DwmGetWindowAttribute(window, DWMWA_WINDOW_CORNER_PREFERENCE, &cornerPreference, sizeof(cornerPreference));
12      if (res != S_OK)
13      {
14          // no need to spam with error log if arg is invalid (on Windows 10)
15          if (res != E_INVALIDARG)
16          {
17              Logger::error(L"Get corner preference error: {}", get_last_error_or_default(res)); 
18          }
19      }
20  
21      return cornerPreference;
22  }
23  
24  int WindowCornerUtils::CornersRadius(HWND window) noexcept
25  {
26      int cornerPreference = CornerPreference(window);
27  
28      switch (cornerPreference)
29      {
30      case DWM_WINDOW_CORNER_PREFERENCE::DWMWCP_ROUND:
31          return 8;
32      case DWM_WINDOW_CORNER_PREFERENCE::DWMWCP_ROUNDSMALL:
33          return 4;
34      case DWM_WINDOW_CORNER_PREFERENCE::DWMWCP_DEFAULT:
35          return 8;
36      default:
37          return 0;
38      }
39  }