Skip to content
20 changes: 18 additions & 2 deletions src/dll/src/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "Include/stb_image_write.h"

using namespace Nilesoft::Diagnostics;

// Defined in Main.cpp: true while the self-built taskbar "app button" menu is open (global namespace)
extern bool in_taskbar_button_menu;
#include <mutex>

extern Logger &_log;
Expand Down Expand Up @@ -1108,6 +1111,9 @@ namespace Nilesoft

std::vector<MenuItemInfo *> bottom_items;

// New menu(...)/item(...) entries from the config are added here. The button menu uses the same path:
// it has its own context type (FSO_TASKBAR_BUTTON), so plain taskbar items do not match it and no
// in_taskbar_button_menu guard is needed here any more.
if(_settings.new_items.enabled)
{
if(!(owner && owner->is_disabled()))
Expand Down Expand Up @@ -1195,7 +1201,7 @@ namespace Nilesoft
else
{
bool rb = !Selected.Background && (Selected.Window.id == WINDOW_RECYCLEBIN);
if(!Selected.Types[FSO_TASKBAR] && !rb)
if(!Selected.Types[FSO_TASKBAR] && !Selected.Types[FSO_TASKBAR_BUTTON] && !rb)
{
dynamic_pos = items.size() == 0 ? 1 : findpos();
}
Expand Down Expand Up @@ -4393,7 +4399,15 @@ namespace Nilesoft
switch(Selected.Window.id)
{
case WINDOW_TASKBAR:
Selected.Types[FSO_TASKBAR] = TRUE;
// The self-built taskbar "app button" menu (see in_taskbar_button_menu in Main.cpp) uses its own type bit:
// it is a taskbar context, but flagged as FSO_TASKBAR_BUTTON rather than FSO_TASKBAR, so items
// written for type='taskbar'/window.is_taskbar ("Go to", imports/taskbar.nss) do not flood the
// button menu; use where=window.is_taskbar_button to target it.
if(in_taskbar_button_menu)
Selected.Types[FSO_TASKBAR_BUTTON] = TRUE;
else
Selected.Types[FSO_TASKBAR] = TRUE;
// 'front' stays FSO_TASKBAR: the button menu had this value before, keeping display logic intact.
Selected.front = FSO_TASKBAR;
Selected.Directory = Path::GetKnownFolder(FOLDERID_Desktop).move();
break;
Expand Down Expand Up @@ -4470,6 +4484,8 @@ namespace Nilesoft
if(0 == ::GetPropW(hwnd.owner, UxSubclass))
build_system_menuitems(_hMenu_original, __system_menu_tree, true);

// modify(...) rules that alter existing items may also apply to the button menu (it has its own
// type, so generic taskbar rules cannot hit it), hence no in_taskbar_button_menu guard here.
if(_settings.modify_items.enabled)
build_main_system_menuitems(__system_menu_tree, true);

Expand Down
24 changes: 23 additions & 1 deletion src/dll/src/Expression/FuncExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

#include <regex>

// Defined in Main.cpp: kills the process tree of the windows of the current taskbar button menu.
extern bool kill_taskbar_button_process_tree();
// Defined in Main.cpp: top-level windows matched by the current button menu (window.taskbar_button_windows).
extern std::vector<HWND> taskbar_button_windows;

//#include <filesystem>

namespace Nilesoft
Expand Down Expand Up @@ -1461,7 +1466,20 @@ namespace Nilesoft
_result = sel->Window.desktop;
break;
case IDENT_IS_TASKBAR:
_result = sel->Window.parent == WINDOW_TASKBAR;
// The button menu also lives on the taskbar but has its own context type
// (FSO_TASKBAR_BUTTON), so return false here to keep items written for
// type='taskbar' / window.is_taskbar (such as "Go to")
// out of the button menu.
_result = (sel->Window.parent == WINDOW_TASKBAR) && !(sel->Types[FSO_TASKBAR_BUTTON] > 0);
break;
case IDENT_IS_TASKBAR_BUTTON:
// True only for the self-built taskbar "app button" menu (see the WINDOW_TASKBAR branch).
_result = sel->Types[FSO_TASKBAR_BUTTON] > 0;
break;
case IDENT_TASKBAR_BUTTON_WINDOWS:
// Number of windows matched by the current button menu: 0 means the button has no usable target
// (window not recognized / app exited); config items can use it to hide dead entries.
_result = static_cast<int>(taskbar_button_windows.size());
break;
case IDENT_IS_EXPLORER:
_result = sel->Window.explorer;
Expand Down Expand Up @@ -1718,6 +1736,10 @@ namespace Nilesoft
case IDENT_COMMAND_RESTART_EXPLORER:
_result = Windows::Explorer::Restart();
break;
case IDENT_COMMAND_KILL_PROCESS_TREE:
// Kill the process tree of the windows of this taskbar button (menu item provided by command.kill_process_tree)
_result = kill_taskbar_button_process_tree();
break;
case IDENT_COMMAND_TOGGLEHIDDEN:
Explorer::ToggleHiddenFiles();
break;
Expand Down
Loading