Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlwaysActive #4140

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
27 changes: 26 additions & 1 deletion Sandboxie/core/dll/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ _FX VOID Gui_ProtectScreen(HWND hWnd)
// Gui_WindowProcW
//---------------------------------------------------------------------------


static HWND Gui_PreviousActiveWindow = NULL;
_FX LRESULT Gui_WindowProcW(
HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
Expand All @@ -1668,6 +1668,19 @@ _FX LRESULT Gui_WindowProcW(
return TRUE;
}

//if (uMsg == WM_KILLFOCUS) {
// if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE))
// return FALSE;
//}
if (uMsg == WM_ACTIVATE) {
if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE))
if (wParam == WA_INACTIVE)
return 0;
else {
Gui_PreviousActiveWindow = (HWND)hWnd;
}
}

wndproc = __sys_GetPropW(hWnd, (LPCWSTR)Gui_WindowProcOldW_Atom);
if (DLL_IMAGE_OFFICE_EXCEL == Dll_ImageType) {

Expand Down Expand Up @@ -1729,6 +1742,18 @@ _FX LRESULT Gui_WindowProcA(
if (SbieApi_QueryConfBool(NULL, L"BlockInterferePower", FALSE))
return TRUE;
}
//if (uMsg == WM_KILLFOCUS) {
// if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE))
// return FALSE;
//}
if (uMsg == WM_ACTIVATE) {
if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE))
if (wParam == WA_INACTIVE)
return 0;
else {
Gui_PreviousActiveWindow = (HWND)hWnd;
}
}
wndproc = __sys_GetPropW(hWnd, (LPCWSTR)Gui_WindowProcOldA_Atom);
lResult = __sys_CallWindowProcA(wndproc, hWnd, uMsg, wParam, new_lParam);

Expand Down
4 changes: 4 additions & 0 deletions Sandboxie/core/dll/gui_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ typedef BOOL (*P_SwitchDesktop)(HDESK hDesktop);
typedef BOOL (*P_UserHandleGrantAccess)(
HANDLE hUserHandle, HANDLE hJob, BOOL bGrant);

typedef HWND (*P_GetActiveWindow)();

//---------------------------------------------------------------------------

typedef HMONITOR (*P_MonitorFromWindow)(HWND hWnd, DWORD dwFlags);
Expand Down Expand Up @@ -634,6 +636,8 @@ GUI_SYS_VAR(GetWindowRect)
GUI_SYS_VAR(GetForegroundWindow)
GUI_SYS_VAR(SetForegroundWindow)

GUI_SYS_VAR(GetActiveWindow)

GUI_SYS_VAR(MonitorFromWindow)
GUI_SYS_VAR_2(DdeInitialize)

Expand Down
25 changes: 25 additions & 0 deletions Sandboxie/core/dll/guimisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ static BOOL Gui_BlockInput(BOOL fBlockIt);

static UINT Gui_SendInput(ULONG nInputs, LPINPUT pInputs, ULONG cbInput);

static HWND Gui_GetActiveWindow();

static HWND Gui_GetForegroundWindow();

static HDESK Gui_OpenInputDesktop(
DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);

Expand Down Expand Up @@ -208,6 +212,11 @@ _FX BOOLEAN Gui_InitMisc(HMODULE module)
SBIEDLL_HOOK_GUI(BringWindowToTop);
SBIEDLL_HOOK_GUI(SwitchToThisWindow);
SBIEDLL_HOOK_GUI(SetActiveWindow);

if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) {
SBIEDLL_HOOK_GUI(GetForegroundWindow);
SBIEDLL_HOOK_GUI(GetActiveWindow);
}

if (Gui_UseBlockCapture) {
SBIEDLL_HOOK_GUI(GetWindowDC);
Expand Down Expand Up @@ -1707,3 +1716,19 @@ _FX void Gui_SwitchToThisWindow(HWND hWnd, BOOL fAlt)
return;
__sys_SwitchToThisWindow(hWnd, fAlt);
}

//---------------------------------------------------------------------------
//Gui_GetActiveWindow
//---------------------------------------------------------------------------
static HWND Gui_PreviousActiveWindow;
static HWND Gui_GetActiveWindow() {
//if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE))
// return (Gui_PreviousActiveWindow == NULL ? __sys_GetActiveWindow() : Gui_PreviousActiveWindow);
return __sys_GetActiveWindow();
}

static HWND Gui_GetForegroundWindow() {
if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE))
return (Gui_PreviousActiveWindow == NULL ? __sys_GetActiveWindow() : Gui_PreviousActiveWindow);
return __sys_GetActiveWindow();
}