mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-09 04:38:10 -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:
parent
aea1b16ddd
commit
94b4883cd2
@ -77,7 +77,7 @@ int Application::Run(LPCTSTR lpstrCmdLine, int nCmdShow)
|
|||||||
EnableServerEvents(true);
|
EnableServerEvents(true);
|
||||||
|
|
||||||
if (ShowDialogAtStart(lpstrCmdLine, nCmdShow))
|
if (ShowDialogAtStart(lpstrCmdLine, nCmdShow))
|
||||||
Configure();
|
Configure(false);
|
||||||
|
|
||||||
int nRet = theLoop.Run();
|
int nRet = theLoop.Run();
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ void Application::Exit()
|
|||||||
::PostQuitMessage(0);
|
::PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Configure()
|
void Application::Configure(bool move_window)
|
||||||
{
|
{
|
||||||
if (m_dlg)
|
if (m_dlg)
|
||||||
{
|
{
|
||||||
@ -112,7 +112,7 @@ void Application::Configure()
|
|||||||
CheckCanConfigure();
|
CheckCanConfigure();
|
||||||
|
|
||||||
// Other people may need to talk to the dialog while it exists.
|
// Other people may need to talk to the dialog while it exists.
|
||||||
CMainDlg dlg;
|
CMainDlg dlg(move_window);
|
||||||
m_dlg = &dlg;
|
m_dlg = &dlg;
|
||||||
dlg.DoModal();
|
dlg.DoModal();
|
||||||
m_dlg = NULL;
|
m_dlg = NULL;
|
||||||
|
@ -74,8 +74,9 @@ public:
|
|||||||
return m_registered_activation_message;
|
return m_registered_activation_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
// User actions
|
// Pass true to move the window so it is near the mouse
|
||||||
void Configure();
|
// cursor.
|
||||||
|
void Configure(bool move_window);
|
||||||
void Exit();
|
void Exit();
|
||||||
|
|
||||||
// Service control
|
// Service control
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
#include "MainDlg.h"
|
#include "MainDlg.h"
|
||||||
#include "FireflyShell.h"
|
#include "FireflyShell.h"
|
||||||
|
|
||||||
CMainDlg::CMainDlg()
|
CMainDlg::CMainDlg(bool move_window)
|
||||||
|
: m_window_move_required(move_window)
|
||||||
{
|
{
|
||||||
this->AddPage(m_pageConfig);
|
this->AddPage(m_pageConfig);
|
||||||
this->AddPage(m_pageAdvanced);
|
this->AddPage(m_pageAdvanced);
|
||||||
@ -57,3 +58,53 @@ LRESULT CMainDlg::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHand
|
|||||||
|
|
||||||
return result;
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -32,16 +32,23 @@ class CMainDlg : public CPropertySheetImpl<CMainDlg>
|
|||||||
CAdvancedPage m_pageAdvanced;
|
CAdvancedPage m_pageAdvanced;
|
||||||
CLogPage m_pageLog;
|
CLogPage m_pageLog;
|
||||||
CAboutPage m_pageAbout;
|
CAboutPage m_pageAbout;
|
||||||
|
bool m_window_move_required;
|
||||||
|
|
||||||
BEGIN_MSG_MAP(CMainDlg)
|
BEGIN_MSG_MAP(CMainDlg)
|
||||||
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
|
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
|
||||||
|
MSG_WM_MOVE(OnMove)
|
||||||
CHAIN_MSG_MAP(base)
|
CHAIN_MSG_MAP(base)
|
||||||
END_MSG_MAP()
|
END_MSG_MAP()
|
||||||
|
|
||||||
LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
|
||||||
|
void OnMove(CPoint);
|
||||||
|
void PositionWindow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMainDlg();
|
// Pass true if you want the window to be moved to near the mouse pointer.
|
||||||
|
// This is usually only the case if the window is displayed as a result of
|
||||||
|
// clicking on the shell notification icon.
|
||||||
|
CMainDlg(bool move_window);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINDLG_H
|
#endif // MAINDLG_H
|
@ -139,7 +139,7 @@ LRESULT CNotifyIcon::OnNotifyIconMessage(UINT uMsg, WPARAM wParam, LPARAM lParam
|
|||||||
switch (lParam)
|
switch (lParam)
|
||||||
{
|
{
|
||||||
case WM_LBUTTONDBLCLK:
|
case WM_LBUTTONDBLCLK:
|
||||||
GetApplication()->Configure();
|
GetApplication()->Configure(true);
|
||||||
bHandled = true;
|
bHandled = true;
|
||||||
return 0L;
|
return 0L;
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
@ -175,7 +175,7 @@ void CNotifyIcon::OnContextMenu()
|
|||||||
|
|
||||||
LRESULT CNotifyIcon::OnConfigure(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
LRESULT CNotifyIcon::OnConfigure(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
||||||
{
|
{
|
||||||
GetApplication()->Configure();
|
GetApplication()->Configure(true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ LRESULT CNotifyIcon::OnRegisteredActivation(UINT, WPARAM, LPARAM, BOOL &bHandled
|
|||||||
{
|
{
|
||||||
ATLTRACE(_T("Activate\n"));
|
ATLTRACE(_T("Activate\n"));
|
||||||
bHandled = true;
|
bHandled = true;
|
||||||
GetApplication()->Configure();
|
GetApplication()->Configure(false);
|
||||||
|
|
||||||
// We return a magic number so that the caller knows we've been found
|
// We return a magic number so that the caller knows we've been found
|
||||||
// and can give up.
|
// and can give up.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user