diff --git a/client/win/wingui_mainwindow.cpp b/client/win/wingui_mainwindow.cpp index 20df511c14..8538371a03 100755 --- a/client/win/wingui_mainwindow.cpp +++ b/client/win/wingui_mainwindow.cpp @@ -104,11 +104,8 @@ CMainWindow::CMainWindow() CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL); - m_nScreenSaverMsg = RegisterWindowMessage(START_SS_MSG); m_nShowMsg = RegisterWindowMessage(SHOW_WIN_MSG); m_nNetActivityMsg = RegisterWindowMessage(NET_ACTIVITY_MSG); - m_nSetMsg = RegisterWindowMessage(APP_SET_MSG); - m_nGetMsg = RegisterWindowMessage(APP_GET_MSG); } ////////// @@ -666,6 +663,18 @@ void CMainWindow::LoadUserSettings() rt.right = nBuf + rt.left; nBuf = GetPrivateProfileInt("WINDOW", "height", 400, szPath); rt.bottom = nBuf + rt.top; + + CRect rtScreen, rtInt; + HDC screenDC=::GetDC(NULL); + rtScreen.left = rtScreen.top = 0; + rtScreen.right=GetDeviceCaps(screenDC, HORZRES); + rtScreen.bottom=GetDeviceCaps(screenDC, VERTRES); + ::ReleaseDC(NULL, screenDC); + + rtInt.IntersectRect(&rt, &rtScreen); + if(rtInt.IsRectEmpty()) { + rt.SetRect(100, 100, 600, 400); + } SetWindowPos(&wndNoTopMost, rt.left, rt.top, rt.Width(), rt.Height(), 0); // load selected tab @@ -876,45 +885,6 @@ void CMainWindow::Syncronize(CProgressListCtrl* pProg, vector* pVect) } } -////////// -// CMainWindow::CheckAppWnd -// arguments: void -// returns: void -// function: polls application windows to see if the currently shown -// window needs to be switched, or if an app has closed -void CMainWindow::CheckAppWnd() -{ - CWnd* pAppWnd; - - if (m_dwAppId == 0) { - if(gstate.active_tasks.active_tasks.size() == 0) return; - m_dwAppId = gstate.active_tasks.active_tasks[0]->pid; - pAppWnd = GetWndFromProcId(m_dwAppId); - if(pAppWnd) { - int mode = m_pSSWnd->SendMessage(m_nGetMsg, 0, 0); - pAppWnd->PostMessage(m_nSetMsg, LOWORD(mode), HIWORD(mode)); - m_pSSWnd->SendMessage(m_nSetMsg, MODE_NO_GRAPHICS, MODE_DEFAULT); - } else { - m_dwAppId = 0; - } - } else { - pAppWnd = GetWndFromProcId(m_dwAppId); - if(!pAppWnd || !IsWindow(pAppWnd->m_hWnd)) { - m_dwAppId = 0; - if(gstate.active_tasks.active_tasks.size() > 0) { - m_dwAppId = gstate.active_tasks.active_tasks[0]->pid; - } - pAppWnd = GetWndFromProcId(m_dwAppId); - if(!pAppWnd || !IsWindow(pAppWnd->m_hWnd)) { - m_dwAppId = 0; - pAppWnd = m_pSSWnd; - } - pAppWnd->PostMessage(m_nSetMsg, LOWORD(m_AppMode), HIWORD(m_AppMode)); - } - return; - } -} - ////////// // CMainWindow::PostNcDestroy // arguments: void @@ -938,20 +908,9 @@ LRESULT CMainWindow::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) ShowWindow(SW_SHOW); SetForegroundWindow(); return 0; - } else if(m_nScreenSaverMsg == message) { - CWnd* pAppWnd = GetWndFromProcId(m_dwAppId); - if(pAppWnd) { - pAppWnd->SendMessage(m_nSetMsg, MODE_FULLSCREEN, MODE_DEFAULT); - return 0; - } - m_pSSWnd->SetMode(MODE_FULLSCREEN, MODE_DEFAULT); - return 0; } else if(m_nNetActivityMsg == message) { gstate.net_sleep(0); return 0; - } else if(message == RegisterWindowMessage("BOINC_APP_MODE")) { - if(lParam == m_dwAppId) m_AppMode = wParam; - return 0; } return CWnd::DefWindowProc(message, wParam, lParam); @@ -1036,12 +995,7 @@ void CMainWindow::OnCommandHelpAbout() // broadcasting a message void CMainWindow::OnCommandFileShowGraphics() { - CWnd* pAppWnd = GetWndFromProcId(m_dwAppId); - if(pAppWnd) { - pAppWnd->SendMessage(m_nSetMsg, MODE_WINDOW, MODE_DEFAULT); - return; - } - m_pSSWnd->SetMode(MODE_WINDOW, MODE_DEFAULT); + m_pSSWnd->ShowGraphics(); } ////////// @@ -1239,7 +1193,6 @@ void CMainWindow::OnCommandExit() gstate.cleanup_and_exit(); PostQuitMessage(0); KillTimer(m_nGuiTimerID); - KillTimer(m_nAppTimerID); // status icon in taskbar SetStatusIcon(ICON_OFF); @@ -1296,7 +1249,6 @@ int CMainWindow::OnCreate(LPCREATESTRUCT lpcs) m_bRequest = false; m_nContextItem = -1; m_pSSWnd = new CSSWindow(); - m_dwAppId = 0; // load menus m_ContextMenu.LoadMenu(IDR_CONTEXT); @@ -1426,7 +1378,6 @@ int CMainWindow::OnCreate(LPCREATESTRUCT lpcs) } m_nGuiTimerID = SetTimer(GUI_TIMER, GUI_WAIT, (TIMERPROC) NULL); - m_nAppTimerID = SetTimer(APP_TIMER, APP_WAIT, (TIMERPROC) NULL); // load dll and start idle detection m_hIdleDll = LoadLibrary("boinc.dll"); @@ -1679,8 +1630,4 @@ void CMainWindow::OnTimer(UINT uEventID) // Start the timer again m_nGuiTimerID = SetTimer(GUI_TIMER, GUI_WAIT, (TIMERPROC) NULL); } - - if(uEventID == m_nAppTimerID) { - CheckAppWnd(); - } } diff --git a/client/win/wingui_mainwindow.h b/client/win/wingui_mainwindow.h index 55f35ce78b..d5a26ba08b 100755 --- a/client/win/wingui_mainwindow.h +++ b/client/win/wingui_mainwindow.h @@ -43,9 +43,7 @@ #define EDGE_BUFFER 2 // buffer pixels around edge of client #define GUI_TIMER 104 // gui refresh -#define APP_TIMER 105 // app check #define GUI_WAIT 1000 // timeout sleep time (in milliseconds) -#define APP_WAIT 100 // timeout sleep time (in milliseconds) #define STATUS_ICON_ID (WM_USER + 1) // id for notifications from status icon @@ -110,16 +108,8 @@ protected: BOOL m_bRequest; // does the user have a net connection request? int m_nContextItem; // item selected for context menu UINT m_nGuiTimerID; // ID of current GUI timer - UINT m_nAppTimerID; // ID of current app timer CSSWindow* m_pSSWnd; // default graphics window - UINT m_nScreenSaverMsg; // ID of screensaver message UINT m_nShowMsg; // ID of show window request message - UINT m_nSetMsg; - UINT m_nGetMsg; - - DWORD m_dwAppId; - CRect m_AppRect; - int m_AppMode; COLORREF GetPieColor(int); void ShowTab(int); @@ -131,7 +121,6 @@ protected: void LoadLanguage(); DWORD GetUserIdleTime(); void Syncronize(CProgressListCtrl*, vector*); - void CheckAppWnd(); virtual void PostNcDestroy(); LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam); diff --git a/client/win/wingui_sswindow.cpp b/client/win/wingui_sswindow.cpp index 6970f88f24..449fb35719 100755 --- a/client/win/wingui_sswindow.cpp +++ b/client/win/wingui_sswindow.cpp @@ -34,7 +34,7 @@ END_MESSAGE_MAP() // CSSWindow::CSSWindow // arguments: void // returns: void -// function: sets initial rect for window and refresh timer +// function: sets initial rect for window and other members CSSWindow::CSSWindow() { int nX = rand() % 50; @@ -43,6 +43,11 @@ CSSWindow::CSSWindow() SetMode(MODE_NO_GRAPHICS, MODE_NO_GRAPHICS); m_hBOINCIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON)); + m_uScreenSaverMsg = RegisterWindowMessage(START_SS_MSG); + m_uSetMsg = RegisterWindowMessage(APP_SET_MSG); + m_uGetMsg = RegisterWindowMessage(APP_GET_MSG); + m_dwAppId = 0; + m_uStartTime = 0; } // CMainWindow::SetMode @@ -58,7 +63,7 @@ void CSSWindow::SetMode(int nMode, int nPrev) m_nMode = nMode; if(GetSafeHwnd()) { - if((m_nPrevMode != MODE_FULLSCREEN) && (m_nPrevMode != MODE_BLANK_SCREEN)) + if(m_nPrevMode != MODE_FULLSCREEN) GetWindowRect(&m_Rect); DestroyWindow(); } @@ -67,7 +72,7 @@ void CSSWindow::SetMode(int nMode, int nPrev) DWORD dwExStyle; DWORD dwStyle; - if (nMode == MODE_FULLSCREEN || nMode == MODE_BLANK_SCREEN) { + if (nMode == MODE_FULLSCREEN) { HDC screenDC=::GetDC(NULL); WindowRect.left = WindowRect.top = 0; WindowRect.right=GetDeviceCaps(screenDC, HORZRES); @@ -77,6 +82,7 @@ void CSSWindow::SetMode(int nMode, int nPrev) dwStyle=WS_POPUP; while(ShowCursor(false) >= 0); } else { + m_uStartTime = 0; if(m_Rect.IsRectEmpty()) m_Rect.SetRect(CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT); WindowRect = m_Rect; dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE; @@ -88,9 +94,9 @@ void CSSWindow::SetMode(int nMode, int nPrev) dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect, NULL, 0, NULL); - if(nMode == MODE_FULLSCREEN || nMode == MODE_WINDOW || nMode == MODE_BLANK_SCREEN) { + if(nMode == MODE_FULLSCREEN || nMode == MODE_WINDOW) { ShowWindow(SW_SHOW); - if(nMode == MODE_FULLSCREEN || nMode == MODE_BLANK_SCREEN) SetForegroundWindow(); + if(nMode == MODE_FULLSCREEN) SetForegroundWindow(); } else { ShowWindow(SW_HIDE); } @@ -115,18 +121,69 @@ int CSSWindow::GetPrevMode() return m_nPrevMode; } -void CSSWindow::PaintDefault() +////////// +// CSSWindow::CheckAppWnd +// arguments: void +// returns: void +// function: polls application windows to see if the currently shown +// window needs to be switched, or if an app has closed +void CSSWindow::CheckAppWnd() { - PAINTSTRUCT ps; - CDC* pdc; - RECT winRect; - CBrush cb; - cb.CreateSolidBrush(RGB(0,0,0)); + CWnd* pAppWnd; - pdc = BeginPaint(&ps); - GetClientRect(&winRect); - pdc->FillRect(&winRect, &cb); - EndPaint(&ps); + if (m_dwAppId == 0) { + if(BlankScreen()) return; + if(gstate.active_tasks.active_tasks.size() == 0) return; + m_dwAppId = gstate.active_tasks.active_tasks[0]->pid; + pAppWnd = GetWndFromProcId(m_dwAppId); + if(pAppWnd) { + int mode = SendMessage(m_uGetMsg, 0, 0); + pAppWnd->PostMessage(m_uSetMsg, LOWORD(mode), HIWORD(mode)); + SendMessage(m_uSetMsg, MODE_NO_GRAPHICS, MODE_DEFAULT); + } else { + m_dwAppId = 0; + } + } else { + if(BlankScreen()) { + pAppWnd = GetWndFromProcId(m_dwAppId); + if(pAppWnd && IsWindow(pAppWnd->m_hWnd)) { + pAppWnd->PostMessage(m_uSetMsg, MODE_NO_GRAPHICS, MODE_NO_GRAPHICS); + } + m_dwAppId = 0; + SendMessage(m_uSetMsg, MODE_FULLSCREEN, MODE_DEFAULT); + } else { + pAppWnd = GetWndFromProcId(m_dwAppId); + if(!pAppWnd || !IsWindow(pAppWnd->m_hWnd)) { + m_dwAppId = 0; + if(gstate.active_tasks.active_tasks.size() > 0) { + m_dwAppId = gstate.active_tasks.active_tasks[0]->pid; + } + pAppWnd = GetWndFromProcId(m_dwAppId); + if(!pAppWnd || !IsWindow(pAppWnd->m_hWnd)) { + m_dwAppId = 0; + pAppWnd = this; + } + pAppWnd->PostMessage(m_uSetMsg, LOWORD(m_AppMode), HIWORD(m_AppMode)); + } + } + return; + } +} + +////////// +// CSSWindow::ShowGraphics +// arguments: void +// returns: void +// function: brings up the current app's graphics window by +// broadcasting a message +void CSSWindow::ShowGraphics() +{ + CWnd* pAppWnd = GetWndFromProcId(m_dwAppId); + if(pAppWnd) { + pAppWnd->SendMessage(m_uSetMsg, MODE_WINDOW, MODE_DEFAULT); + return; + } + SetMode(MODE_WINDOW, MODE_DEFAULT); } // CMainWindow::DefWindowProc @@ -144,11 +201,11 @@ LRESULT CSSWindow::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: - if(m_nMode == MODE_FULLSCREEN || m_nMode == MODE_BLANK_SCREEN) + if(m_nMode == MODE_FULLSCREEN) SetMode(m_nPrevMode, MODE_DEFAULT); return 0; case WM_MOUSEMOVE: - if(m_nMode == MODE_FULLSCREEN || m_nMode == MODE_BLANK_SCREEN) { + if(m_nMode == MODE_FULLSCREEN) { GetCursorPos(&mousePos); if(mousePos != m_MousePos) SetMode(m_nPrevMode, MODE_DEFAULT); } @@ -158,10 +215,23 @@ LRESULT CSSWindow::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) if(m_uSetMsg == message) { SetMode(wParam, lParam); return 0; - } - - if(m_uGetMsg == message) { + } else if(m_uGetMsg == message) { return MAKELONG(GetMode(), GetPrevMode()); + } else if(m_uScreenSaverMsg == message) { + m_uStartTime = time(0); + CWnd* pAppWnd = GetWndFromProcId(m_dwAppId); + if(pAppWnd) { + pAppWnd->SendMessage(m_uSetMsg, MODE_FULLSCREEN, MODE_DEFAULT); + return 0; + } + SetMode(MODE_FULLSCREEN, MODE_DEFAULT); + return 0; + } else if(message == RegisterWindowMessage("BOINC_APP_MODE")) { + if(lParam == m_dwAppId) { + m_AppMode = wParam; + if(m_AppMode != MODE_FULLSCREEN) m_uStartTime = 0; + } + return 0; } return CWnd::DefWindowProc(message, wParam, lParam); @@ -187,19 +257,17 @@ int CSSWindow::OnCreate(LPCREATESTRUCT lpcs) if (CWnd::OnCreate(lpcs) == -1) { return -1; } - m_uSetMsg = RegisterWindowMessage("BOINC_APP_SET"); - m_uGetMsg = RegisterWindowMessage("BOINC_APP_GET"); GetCursorPos(&m_MousePos); - SetTimer(1, 100, NULL); + m_uPaintTimerID = SetTimer(PAINT_TIMER, PAINT_WAIT, (TIMERPROC) NULL); + m_uAppTimerID = SetTimer(APP_TIMER, APP_WAIT, (TIMERPROC) NULL); m_nPosX = m_nPosY = 0; m_nDX = m_nDY = 5; UtilGetRegKey("Blank", m_bBlankScreen); UtilGetRegKey("Blank Time", m_uBlankTime); - m_uBlankTime *= 10; - m_uBlankTime += time(0); + m_uBlankTime *= 60; return 0; } @@ -211,7 +279,8 @@ int CSSWindow::OnCreate(LPCREATESTRUCT lpcs) // function: kills timer void CSSWindow::OnDestroy() { - KillTimer(1); + KillTimer(m_uPaintTimerID); + KillTimer(m_uAppTimerID); } ////////// @@ -231,7 +300,7 @@ void CSSWindow::OnPaint() GetClientRect(&winRect); pdc->FillRect(&winRect, &cb); - if (m_nMode == MODE_FULLSCREEN || m_nMode == MODE_WINDOW) { + if ((m_nMode == MODE_FULLSCREEN || m_nMode == MODE_WINDOW) && !BlankScreen()) { pdc->DrawIcon(m_nPosX, m_nPosY, m_hBOINCIcon); m_nPosX += m_nDX; m_nPosY += m_nDY; @@ -254,18 +323,22 @@ void CSSWindow::OnPaint() bool CSSWindow::BlankScreen() { return (m_bBlankScreen) && - (m_nMode == MODE_FULLSCREEN) && - (time(0) >= m_uBlankTime); + (m_uStartTime != 0) && + (time(0) >= m_uBlankTime + m_uStartTime); } ////////// // CSSWindow::OnTimer -// arguments: null +// arguments: uEventID: id of timer signaling event // returns: null // function: redraw the window if needed -void CSSWindow::OnTimer() +void CSSWindow::OnTimer(UINT uEventID) { - if (m_nMode == MODE_FULLSCREEN || m_nMode == MODE_WINDOW) { + if(uEventID == m_uAppTimerID) { + CheckAppWnd(); + } + + if(uEventID == m_uPaintTimerID) { Invalidate(); OnPaint(); } diff --git a/client/win/wingui_sswindow.h b/client/win/wingui_sswindow.h index b20146f85f..9736910d18 100755 --- a/client/win/wingui_sswindow.h +++ b/client/win/wingui_sswindow.h @@ -26,6 +26,13 @@ #include // Header File For The OpenGL32 Library #include // Header File For The GLu32 Library +// constants + +#define APP_TIMER 104 // app check +#define APP_WAIT 100 // timeout sleep time (in milliseconds) +#define PAINT_TIMER 105 // paint timer +#define PAINT_WAIT 100 // timeout sleep time (in milliseconds) + ////////// // class: CSSWindow // parent: CWnd @@ -37,34 +44,40 @@ public: void SetMode(int, int); int GetMode(); int GetPrevMode(); + void CheckAppWnd(); bool BlankScreen(); + void ShowGraphics(); private: int m_nMode; int m_nPrevMode; CPoint m_MousePos; CRect m_Rect; - UINT m_uSetMsg; - UINT m_uGetMsg; unsigned long m_bBlankScreen; unsigned long m_uBlankTime; + unsigned long m_uStartTime; + + UINT m_uAppTimerID; // ID of current app timer + UINT m_uPaintTimerID; // ID of current app timer + UINT m_uScreenSaverMsg; // ID of screensaver message + UINT m_uSetMsg; + UINT m_uGetMsg; + + DWORD m_dwAppId; + CRect m_AppRect; + int m_AppMode; HICON m_hBOINCIcon; int m_nPosX, m_nPosY; int m_nDX, m_nDY; - HDC hdc; - HGLRC hrc; - - - void PaintDefault(); LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam); afx_msg int OnCreate(LPCREATESTRUCT); afx_msg void OnDestroy(); afx_msg void OnClose(); afx_msg void OnPaint(); - afx_msg void OnTimer(); + afx_msg void OnTimer(UINT); DECLARE_MESSAGE_MAP() };