os.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <SDL2/SDL_syswm.h>
  2. #include "kill.h"
  3. #include "exit_status.h"
  4. #include "sdl_data.h"
  5. #ifdef _WIN32
  6. #include <Windows.h>
  7. #include <Dwmapi.h>
  8. static void config_transparent(const SDL_SysWMinfo* info) {
  9. HWND handle = info->info.win.window;
  10. DWM_BLURBEHIND bb = { 0 };
  11. bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
  12. bb.fEnable = TRUE;
  13. bb.hRgnBlur = CreateRectRgn(0, 0, 1, 1);
  14. DwmEnableBlurBehindWindow(handle, &bb);
  15. }
  16. static void config_overlay(const SDL_SysWMinfo *info) {
  17. HWND handle = info->info.win.window;
  18. SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  19. LONG cur_style = GetWindowLong(handle, GWL_EXSTYLE);
  20. SetWindowLong(handle, GWL_EXSTYLE, cur_style | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE);
  21. }
  22. #else
  23. #error glassdrop does not currently support non-windows systems.
  24. #endif
  25. void os_config() {
  26. SDL_SysWMinfo main_info;
  27. SDL_VERSION(&main_info.version);
  28. SDL_SysWMinfo control_info;
  29. SDL_VERSION(&control_info.version);
  30. if (!SDL_GetWindowWMInfo(main_window, &main_info)) {
  31. kill_sdl("Could not get main system info", EX_ERR_SDL_GET_OS_INFO);
  32. }
  33. if (!SDL_GetWindowWMInfo(control_window, &control_info)) {
  34. kill_sdl("Could not get control system info", EX_ERR_SDL_GET_OS_INFO);
  35. }
  36. config_transparent(&main_info);
  37. config_transparent(&control_info);
  38. config_overlay(&main_info);
  39. }