How to make floating toolbar align its top edge with the mouse (not center on Y)?

Hi everyone,

When I use a custom button to show a floating toolbar, I use the following command:

cmd.RunCommand('Toolbar NAME="F4menu-Doc文档" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');

But with this command, the toolbar always appears with the mouse pointer centered vertically (Y axis) on the toolbar, instead of having the mouse at the top edge like a context menu.
This is especially inconvenient when the mouse is near the edge of the screen, as part of the toolbar can go off the screen.

Is there any way to make the toolbar align its top edge to the mouse Y position, similar to how the right-click context menu works? Or any workaround to achieve this behavior, including preventing the toolbar from going off-screen?

Thank you!

You can specify X,Y coordinates for the POS argument.

Scripts can get the mouse position via SysInfo [Directory Opus Manual]

Hi,

I tried using the object to get the mouse position and used these coordinates to display a floating toolbar, like :SysInfo

However, when the toolbar is shown, it appears centered on the mouse position vertically (Y axis), rather than aligning the top edge of the toolbar with the mouse pointer.
This behavior is the same as using or .POS=mouselPOS=MousePosX,MousePosY

My goal is for the toolbar to appear with its top edge aligned exactly to the mouse Y position, similar to how the right-click context menu works in Windows.
Is there currently any way to achieve this? If not, would you consider adding a parameter or option to allow toolbars to align their top edge to the mouse position when popping up?

Here is my code

function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.deselect = false;

if (clickData.func.sourcetab.selected.count == 0) {
    cmd.RunCommand('Toolbar NAME="常用软件" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=200,150 APPBAR=off TOGGLE AUTOCLOSE');
    return;
}

var item = clickData.func.sourcetab.selected(0);

if (item.is_dir) {
    DOpus.SendKey("shift+f10");
    
} else {

    var iGroups = item.groups;

    if (iGroups.empty) {
        cmd.RunCommand('Toolbar NAME="F4menu-文本" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=200,150 APPBAR=off TOGGLE AUTOCLOSE');
    } 
    else if (iGroups(0) == "Images") {
        cmd.RunCommand('Toolbar NAME="F4menu-图片" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=200,150 APPBAR=off TOGGLE AUTOCLOSE');
    } 
    else if (iGroups(0) == "Music") {
        cmd.RunCommand('Toolbar NAME="F4menu-视频" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
    } 
    else if (iGroups(0) == "Movie") {
        cmd.RunCommand('Toolbar NAME="F4menu-视频" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
    } 
    else if (iGroups(0).display_name == "Doc文档") {
        cmd.RunCommand('Toolbar NAME="F4menu-Doc文档" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
    } 
    else if (iGroups(0).display_name == "PDF文档") {
        cmd.RunCommand('Toolbar NAME="F4menu-PDF文档" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
    } 
    else if (iGroups(0) == "Archives") {
        cmd.RunCommand('Toolbar NAME="F4menu-压缩" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=200,150 APPBAR=off TOGGLE AUTOCLOSE');
    } 
    else {
        cmd.RunCommand('Toolbar NAME="F4menu-文本" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=200,150 APPBAR=off TOGGLE AUTOCLOSE');
    }
}

}

Thank you!

Assuming the toolbar isn’t changing height, can’t you just add an offset to the position?

Hi leo,

Thank you for your suggestion!

I understand your point: if the toolbar height is fixed, I can subtract the toolbar height from the Y coordinate when opening the toolbar, so that the top edge aligns with the mouse position. Each of my toolbars has a fixed height, and I can set a separate offset for each one.

However, when I tried to set the offset in my script, it did not work as expected—the toolbar still appears centered on the mouse Y coordinate, instead of aligning the top edge.

Could you please show me, based on my code below, how to set a different offset for each toolbar so that the top edge of the toolbar appears at the mouse position?

Thank you very much!

Here is my code:

function OnClick(clickData)
{
    var cmd = clickData.func.command;
    cmd.deselect = false;

    if (clickData.func.sourcetab.selected.count == 0) {
        cmd.RunCommand('Toolbar NAME="常用软件" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        return;
    }

    var item = clickData.func.sourcetab.selected(0);

    if (item.is_dir) {
        DOpus.SendKey("shift+f10");
    } else {
        var iGroups = item.groups;

        if (iGroups.empty) {
            cmd.RunCommand('Toolbar NAME="F4menu-文本" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        } 
        else if (iGroups(0) == "Images") {
            cmd.RunCommand('Toolbar NAME="F4menu-图片" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        } 
        else if (iGroups(0) == "Music") {
            cmd.RunCommand('Toolbar NAME="F4menu-视频" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        } 
        else if (iGroups(0) == "Movie") {
            cmd.RunCommand('Toolbar NAME="F4menu-视频" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        } 
        else if (iGroups(0).display_name == "Doc文档") {
            cmd.RunCommand('Toolbar NAME="F4menu-Doc文档" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        } 
        else if (iGroups(0).display_name == "PDF文档") {
            cmd.RunCommand('Toolbar NAME="F4menu-PDF文档" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        } 
        else if (iGroups(0) == "Archives") {
            cmd.RunCommand('Toolbar NAME="F4menu-压缩" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        } 
        else {
            cmd.RunCommand('Toolbar NAME="F4menu-文本" FLOAT=active,vertical,toplevel,hotkeys,frame,roundededges,locked POS=mousel APPBAR=off TOGGLE AUTOCLOSE');
        }
    }
}

Thanks again for your help!

In the next beta, we'll add support for POS=mouselt (or POS=mousetl; the order of the l and t doesn't matter) for the top-left, as well as similar for aligning to the bottom edge.

2 Likes

Thank you very much for implementing this feature!
I'm looking forward to the next beta.