Skip to content

Commit

Permalink
Added "Game mode"
Browse files Browse the repository at this point in the history
Note: This does the following:
* This unloads all skins and dialogs
* Prevents activating any skins and dialogs
* Pauses any tray icon animations
  • Loading branch information
brianferguson committed Nov 5, 2019
1 parent 1205e35 commit 7225d40
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 18 deletions.
1 change: 1 addition & 0 deletions Language/Resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ STRINGTABLE
ID_STR_BUILTINPLUGINS, STR_BUILTINPLUGINS
ID_STR_LANGUAGEOBSOLETE, STR_LANGUAGEOBSOLETE
ID_STR_HARDWAREACCELERATED, "Use hardware acceleration (Requires restart)"
ID_STR_GAMEMODE, "Game mode"
}
58 changes: 41 additions & 17 deletions Library/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,55 @@ void ContextMenu::ShowMenu(POINT pos, Skin* skin)
MENU_ITEM(IDM_DELETELOGFILE, ID_STR_DELETELOGFILE),
MENU_ITEM(IDM_DEBUGLOG, ID_STR_DEBUGMODE)),
MENU_SEPARATOR(),
MENU_ITEM(IDM_TOGGLE_GAMEMODE, ID_STR_GAMEMODE),
MENU_SEPARATOR(),
MENU_ITEM(IDM_QUIT, ID_STR_EXIT)
};

static const MenuTemplate s_GameModeMenu[] =
{
MENU_ITEM(IDM_TOGGLE_GAMEMODE, ID_STR_GAMEMODE),
MENU_SEPARATOR(),
MENU_ITEM(IDM_QUIT, ID_STR_EXIT)
};

if (m_MenuActive || (skin && skin->IsClosing())) return;

Rainmeter& rainmeter = GetRainmeter();

// Show context menu, if no actions were executed
HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
HMENU menu = rainmeter.IsInGameMode() ?
MenuTemplate::CreateMenu(s_GameModeMenu, _countof(s_GameModeMenu), GetString) :
MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
if (!menu) return;

m_MenuActive = true;
Rainmeter& rainmeter = GetRainmeter();

auto displayMenu = [&]() -> void
{
HWND hWnd = WindowFromPoint(pos);
if (hWnd != nullptr)
{
Skin* s = rainmeter.GetSkin(hWnd);
if (s)
{
// Cancel the mouse event beforehand
s->SetMouseLeaveEvent(true);
}
}

DisplayMenu(pos, menu, skin ? skin->GetWindow() : rainmeter.m_TrayIcon->GetWindow());
DestroyMenu(menu);

m_MenuActive = false;
};

if (rainmeter.IsInGameMode())
{
CheckMenuItem(menu, IDM_TOGGLE_GAMEMODE, MF_BYCOMMAND | MF_CHECKED);
displayMenu();
return;
}

SetMenuDefaultItem(menu, IDM_MANAGE, MF_BYCOMMAND);

Expand Down Expand Up @@ -163,21 +201,7 @@ void ContextMenu::ShowMenu(POINT pos, Skin* skin)
}
}

HWND hWnd = WindowFromPoint(pos);
if (hWnd != nullptr)
{
Skin* skin = rainmeter.GetSkin(hWnd);
if (skin)
{
// Cancel the mouse event beforehand
skin->SetMouseLeaveEvent(true);
}
}

DisplayMenu(pos, menu, skin ? skin->GetWindow() : rainmeter.m_TrayIcon->GetWindow());
DestroyMenu(menu);

m_MenuActive = false;
displayMenu();
}

void ContextMenu::ShowSkinCustomMenu(POINT pos, Skin* skin)
Expand Down
23 changes: 22 additions & 1 deletion Library/Rainmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Rainmeter::Rainmeter() :
m_NormalStayDesktop(true),
m_DisableRDP(false),
m_DisableDragging(false),
m_GameMode(false),
m_CurrentParser(),
m_Window(),
m_Mutex(),
Expand Down Expand Up @@ -595,7 +596,7 @@ LRESULT CALLBACK Rainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
case WM_COPYDATA:
{
COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
if (cds)
if (cds && !GetRainmeter().IsInGameMode()) // Disallow any bangs while in "Game mode"
{
const WCHAR* data = (const WCHAR*)cds->lpData;
if (cds->dwData == 1 && (cds->cbData > 0))
Expand Down Expand Up @@ -1026,6 +1027,26 @@ void Rainmeter::ToggleSkinWithID(UINT id)
}
}

void Rainmeter::ToggleGameMode()
{
if (m_GameMode)
{
ActivateActiveSkins();
}
else
{
// Close dialogs if open
DialogManage::CloseDialog();
DialogAbout::CloseDialog();
DialogNewSkin::CloseDialog();

DeleteAllUnmanagedSkins();
DeleteAllSkins();
DeleteAllUnmanagedSkins(); // Redelete unmanaged windows caused by OnCloseAction
}
m_GameMode = !m_GameMode;
}

void Rainmeter::SetSkinPath(const std::wstring& skinPath)
{
WritePrivateProfileString(L"Rainmeter", L"SkinPath", skinPath.c_str(), m_IniFile.c_str());
Expand Down
5 changes: 5 additions & 0 deletions Library/Rainmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class Rainmeter
void ToggleSkin(int folderIndex, int fileIndex);
void ToggleSkinWithID(UINT id);

bool IsInGameMode() { return m_GameMode; }
void ToggleGameMode();

const std::wstring& GetPath() { return m_Path; }
const std::wstring& GetIniFile() { return m_IniFile; }
const std::wstring& GetDataFile() { return m_DataFile; }
Expand Down Expand Up @@ -258,6 +261,8 @@ class Rainmeter

bool m_DisableDragging;

bool m_GameMode;

std::wstring m_SkinEditor;

D2D1_COLOR_F m_DefaultSelectedColor;
Expand Down
46 changes: 46 additions & 0 deletions Library/TrayIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,48 @@ LRESULT CALLBACK TrayIcon::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
{
TrayIcon* tray = GetRainmeter().GetTrayIcon();

// In "Game mode", only allow its menu (toggle game mode & exit),
// and access to the context menu
if (GetRainmeter().IsInGameMode())
{
switch (uMsg)
{
case WM_COMMAND:
switch (wParam)
{
case IDM_TOGGLE_GAMEMODE:
GetRainmeter().ToggleGameMode();
break;

case IDM_QUIT:
PostQuitMessage(0);
break;
}
break;

case WM_TRAY_NOTIFYICON:
{
UINT uMouseMsg = (UINT)lParam;
switch (uMouseMsg)
{
case WM_RBUTTONDOWN:
tray->m_TrayContextMenuEnabled = true;
break;

case WM_RBUTTONUP:
if (tray->m_TrayContextMenuEnabled)
{
POINT pos = System::GetCursorPosition();
GetRainmeter().ShowContextMenu(pos, nullptr);
}
break;
}
}
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

switch (uMsg)
{
case WM_COMMAND:
Expand All @@ -477,6 +519,10 @@ LRESULT CALLBACK TrayIcon::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
CommandHandler::RunFile(RAINMETER_HELP);
break;

case IDM_TOGGLE_GAMEMODE:
GetRainmeter().ToggleGameMode();
break;

case IDM_NEW_VERSION:
CommandHandler::RunFile(RAINMETER_OFFICIAL);
break;
Expand Down
2 changes: 2 additions & 0 deletions Library/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
#define ID_STR_SKININSTALLER 2151
#define ID_STR_ARCHIVEPLUGINS 2152
#define ID_STR_HARDWAREACCELERATED 2153
#define ID_STR_GAMEMODE 2154

#define ID_STR_CREATENEWSKIN 2999
#define ID_STR_NEWSKIN 3000
Expand Down Expand Up @@ -334,6 +335,7 @@
#define IDM_COPYSTRINGVALUE 4072
#define IDM_COPYRANGE 4073
#define IDM_LANGUAGEOBSOLETE 4074
#define IDM_TOGGLE_GAMEMODE 4075

#define IDM_SKIN_CUSTOMCONTEXTMENU_FIRST 9000
#define IDM_SKIN_CUSTOMCONTEXTMENU_LAST 9024
Expand Down

0 comments on commit 7225d40

Please sign in to comment.