1
0

fullscreen.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. HWND hFSMonitorWindow;
  10. extern "C"
  11. {
  12. int g_fsapp = 0;
  13. int g_restoreaot_timer_set = 0;
  14. int g_dropaot_timer_set = 0;
  15. }
  16. #define APPBAR_CALLBACK WM_USER + 1010
  17. #define appbartag L"wa_fsmonitorclass"
  18. LRESULT CALLBACK fsMonitorWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  19. void BeginFullscreenAppMonitor()
  20. {
  21. // this lets us receive appbar messages.
  22. // we're interested in ABN_FULLSCREENAPP so we can turn AOT off temporarily
  23. APPBARDATA abd;
  24. WNDCLASSW wc;
  25. if (!GetClassInfoW(hMainInstance, appbartag, &wc))
  26. {
  27. memset(&wc, 0, sizeof(wc));
  28. wc.lpfnWndProc = fsMonitorWndProc;
  29. wc.hInstance = hMainInstance;
  30. wc.lpszClassName = appbartag;
  31. wc.style = 0;
  32. RegisterClassW(&wc);
  33. }
  34. hFSMonitorWindow = CreateWindowExW(0, appbartag, L"", 0, 0, 0, 1, 1, NULL, NULL, hMainInstance, NULL);
  35. abd.cbSize = sizeof(APPBARDATA);
  36. abd.hWnd = hFSMonitorWindow;
  37. abd.uCallbackMessage = APPBAR_CALLBACK;
  38. abd.uEdge = ABE_TOP;
  39. memset(&abd.rc, 0, sizeof(RECT));
  40. SHAppBarMessage(ABM_NEW, &abd);
  41. }
  42. void EndFullscreenAppMonitor()
  43. {
  44. APPBARDATA abd;
  45. abd.cbSize = sizeof(APPBARDATA);
  46. abd.hWnd = hFSMonitorWindow;
  47. SHAppBarMessage(ABM_REMOVE, &abd);
  48. if (IsWindow(hFSMonitorWindow))
  49. DestroyWindow(hFSMonitorWindow);
  50. }
  51. void OnFullscreenApp()
  52. {
  53. // ignore this event if the window going fullscreen is a winamp window
  54. if (!is_fullscreen_video && !vis_fullscreen)
  55. {
  56. if (g_restoreaot_timer_set)
  57. {
  58. g_restoreaot_timer_set = 0;
  59. KillTimer(hMainWindow, 100);
  60. }
  61. else
  62. {
  63. g_dropaot_timer_set = 1;
  64. SetTimer(hMainWindow, 99, 250, NULL);
  65. }
  66. }
  67. }
  68. void OnCancelFullscreenApp()
  69. {
  70. if (!is_fullscreen_video && !vis_fullscreen)
  71. {
  72. if (g_dropaot_timer_set)
  73. {
  74. KillTimer(hMainWindow, 99);
  75. g_dropaot_timer_set = 0;
  76. }
  77. else
  78. {
  79. SetTimer(hMainWindow, 100, 250, NULL);
  80. g_restoreaot_timer_set = 1;
  81. }
  82. }
  83. }
  84. LRESULT CALLBACK fsMonitorWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  85. {
  86. switch (uMsg)
  87. {
  88. case APPBAR_CALLBACK:
  89. switch (wParam)
  90. {
  91. case ABN_FULLSCREENAPP:
  92. if (lParam && !g_fsapp)
  93. {
  94. g_fsapp = 1;
  95. OnFullscreenApp();
  96. }
  97. else if (!lParam && g_fsapp)
  98. {
  99. g_fsapp = 0;
  100. OnCancelFullscreenApp();
  101. }
  102. }
  103. return 0;
  104. }
  105. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  106. }
  107. void dropAOT()
  108. {
  109. if (!config_dropaotfs) return ;
  110. set_aot(0);
  111. if (config_aot)
  112. {
  113. SetWindowPos(hMainWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  114. SetWindowPos(hMainWindow, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  115. }
  116. }
  117. void restoreAOT()
  118. {
  119. if (!config_dropaotfs) return ;
  120. if (config_aot)
  121. {
  122. // normally, changing hMainWindow's ONTOP flag should be enough to change all the owned window' z-orders too,
  123. // but for some reason I cannot figure out, it does not work unless WA has been clicked away and back in focus.
  124. // if that hasn't been done, then reseting the flag on each window is necessary.
  125. // now for the fun part: the above is true for classic skin, but in modern skins, reseting the flag
  126. // on those windows actually prevents the player from coming back ONTOP! FUN!
  127. if (GetParent(hPLWindow) == NULL)
  128. {
  129. SetWindowPos(hPLWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  130. SetWindowPos(hVideoWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  131. SetWindowPos(hEQWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  132. }
  133. SetWindowPos(hMainWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  134. SetWindowPos(hMainWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  135. }
  136. set_aot(0);
  137. }