Changed to register for WM_INPUT only when needed

This commit is contained in:
Birunthan Mohanathas 2012-11-23 21:59:24 +02:00
parent ed9f27ba38
commit 0c89989d5a
3 changed files with 52 additions and 11 deletions

View File

@ -83,6 +83,8 @@ CMeterWindow::CMeterWindow(const std::wstring& folderPath, const std::wstring& f
m_BackgroundSize(),
m_Window(),
m_MouseOver(false),
m_MouseInputRegistered(false),
m_HasMouseScrollAction(false),
m_BackgroundMargins(),
m_DragMargins(),
m_WindowX(1, L'0'),
@ -185,6 +187,8 @@ CMeterWindow::~CMeterWindow()
KillTimer(m_Window, TIMER_FADE);
KillTimer(m_Window, TIMER_TRANSITION);
UnregisterMouseInput();
// Destroy the meters
std::vector<CMeter*>::iterator j = m_Meters.begin();
for ( ; j != m_Meters.end(); ++j)
@ -272,16 +276,6 @@ void CMeterWindow::Initialize()
FadeWindow(0, m_AlphaValue);
}
}
RAWINPUTDEVICE raw[1];
raw[0].usUsagePage = 0x01;
raw[0].usUsage = 0x02;
raw[0].dwFlags = RIDEV_INPUTSINK;
raw[0].hwndTarget = m_Window;
if (!RegisterRawInputDevices(raw, 1, sizeof(raw[0])))
{
Log(LOG_WARNING, L"Error registering raw input mouse device.");
}
}
/*
@ -297,6 +291,40 @@ void CMeterWindow::IgnoreAeroPeek()
}
}
/*
** Registers to receive WM_INPUT for the mouse events.
**
*/
void CMeterWindow::RegisterMouseInput()
{
if (!m_MouseInputRegistered && m_HasMouseScrollAction)
{
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.usUsage = 0x02; // HID mouse
rid.dwFlags = RIDEV_INPUTSINK;
rid.hwndTarget = m_Window;
if (RegisterRawInputDevices(&rid, 1, sizeof(rid)))
{
m_MouseInputRegistered = true;
}
}
}
void CMeterWindow::UnregisterMouseInput()
{
if (m_MouseInputRegistered)
{
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.usUsage = 0x02; // HID mouse
rid.dwFlags = RIDEV_REMOVE;
rid.hwndTarget = m_Window;
RegisterRawInputDevices(&rid, 1, sizeof(rid));
m_MouseInputRegistered = false;
}
}
void CMeterWindow::AddWindowExStyle(LONG_PTR flag)
{
LONG_PTR style = GetWindowLongPtr(m_Window, GWL_EXSTYLE);
@ -4309,6 +4337,7 @@ bool CMeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
//LogWithArgs(LOG_DEBUG, L"@Enter: %s", m_FolderPath.c_str());
m_MouseOver = true;
SetMouseLeaveEvent(false);
RegisterMouseInput();
if (!m_Mouse.GetOverAction().empty())
{
@ -4392,6 +4421,7 @@ bool CMeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
//LogWithArgs(LOG_DEBUG, L"Enter: %s", m_FolderPath.c_str());
m_MouseOver = true;
SetMouseLeaveEvent(false);
RegisterMouseInput();
if (!m_Mouse.GetOverAction().empty())
{
@ -4412,6 +4442,7 @@ bool CMeterWindow::DoMoveAction(int x, int y, MOUSEACTION action)
//LogWithArgs(LOG_DEBUG, L"Leave: %s", m_FolderPath.c_str());
m_MouseOver = false;
SetMouseLeaveEvent(true);
UnregisterMouseInput();
if (!m_Mouse.GetLeaveAction().empty())
{

View File

@ -179,6 +179,7 @@ public:
void SetOption(const std::wstring& section, const std::wstring& option, const std::wstring& value, bool group);
void SetMouseLeaveEvent(bool cancel);
void SetHasMouseScrollAction() { m_HasMouseScrollAction = true; }
void MoveWindow(int x, int y);
void ChangeZPos(ZPOSITION zPos, bool all = false);
@ -334,6 +335,8 @@ private:
bool DoMoveAction(int x, int y, MOUSEACTION action);
bool ResizeWindow(bool reset);
void IgnoreAeroPeek();
void RegisterMouseInput();
void UnregisterMouseInput();
void AddWindowExStyle(LONG_PTR flag);
void RemoveWindowExStyle(LONG_PTR flag);
void BlurBehindWindow(BOOL fEnable);
@ -360,6 +363,8 @@ private:
CMouse m_Mouse;
bool m_MouseOver;
bool m_MouseInputRegistered;
bool m_HasMouseScrollAction;
std::wstring m_OnRefreshAction;
std::wstring m_OnCloseAction;
@ -402,7 +407,7 @@ private:
bool m_SavePosition;
bool m_SnapEdges;
int m_AlphaValue;
int m_FadeDuration;
int m_FadeDuration;
ZPOSITION m_WindowZPosition;
bool m_DynamicWindowSize;
bool m_ClickThrough;

View File

@ -51,6 +51,11 @@ void CMouse::ReadOptions(CConfigParser& parser, const WCHAR* section, CMeterWind
m_LeaveAction = parser.ReadString(section, L"MouseLeaveAction", L"", false);
m_MouseScrollDownAction = parser.ReadString(section, L"MouseScrollDownAction", L"", false);
m_MouseScrollUpAction = parser.ReadString(section, L"MouseScrollUpAction", L"", false);
if (!m_MouseScrollDownAction.empty() || !m_MouseScrollUpAction.empty())
{
meterWindow->SetHasMouseScrollAction();
}
m_MouseScrollLeftAction = parser.ReadString(section, L"MouseScrollLeftAction", L"", false);
m_MouseScrollRightAction = parser.ReadString(section, L"MouseScrollRightAction", L"", false);
m_X1DownAction = parser.ReadString(section, L"X1MouseDownAction", L"", false);