mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-10 05:59:45 -05:00
Make the configuration dialog appear near the mouse pointer if
launched from the shell notification icon as requested by Roku's Anthony Wood.
This commit is contained in:
@@ -20,7 +20,8 @@
|
||||
#include "MainDlg.h"
|
||||
#include "FireflyShell.h"
|
||||
|
||||
CMainDlg::CMainDlg()
|
||||
CMainDlg::CMainDlg(bool move_window)
|
||||
: m_window_move_required(move_window)
|
||||
{
|
||||
this->AddPage(m_pageConfig);
|
||||
this->AddPage(m_pageAdvanced);
|
||||
@@ -57,3 +58,53 @@ LRESULT CMainDlg::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHand
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CMainDlg::PositionWindow()
|
||||
{
|
||||
POINT cursor_pt;
|
||||
GetCursorPos(&cursor_pt);
|
||||
|
||||
CRect desktop_rect;
|
||||
if (SystemParametersInfo(SPI_GETWORKAREA, 0, &desktop_rect, 0))
|
||||
{
|
||||
// Don't put it hard against the edge of the screen or task bar.
|
||||
desktop_rect.DeflateRect(CSize(4, 4));
|
||||
|
||||
CRect window_rect;
|
||||
GetWindowRect(&window_rect);
|
||||
|
||||
// First move the window so that it's middle is at the cursor position.
|
||||
CPoint pos;
|
||||
|
||||
pos.x = cursor_pt.x - window_rect.Width()/2;
|
||||
pos.y = cursor_pt.y - window_rect.Height()/2;
|
||||
|
||||
// Now make that window appear on the work area but in case it doesn't fit prefer to fit the
|
||||
// top left.
|
||||
if (pos.x + window_rect.Width() > desktop_rect.right)
|
||||
pos.x = desktop_rect.right - window_rect.Width();
|
||||
if (pos.y + window_rect.Height() > desktop_rect.bottom)
|
||||
pos.y = desktop_rect.bottom - window_rect.Height();
|
||||
|
||||
if (pos.x < desktop_rect.left)
|
||||
pos.x = desktop_rect.left;
|
||||
if (pos.y < desktop_rect.top)
|
||||
pos.y = desktop_rect.top;
|
||||
|
||||
SetWindowPos(NULL, pos.x, pos.y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||
}
|
||||
}
|
||||
|
||||
void CMainDlg::OnMove(CPoint pt)
|
||||
{
|
||||
if (m_window_move_required)
|
||||
{
|
||||
// We don't want to recurse.
|
||||
m_window_move_required = false;
|
||||
PositionWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetMsgHandled(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user