Toolbar Position Based on Monitor Resolution

I use an external 4K monitor with a laptop set to 1920x1080.

My primary lister has two toolbars positioned next to each other at the top. I want toolbar Two to ALWAYS start 500 pixels from the right edge of the monitor. I this placement per the manual:

Toolbar One LINE 0
Toolbar Two LINE 0, 1420

This works fine on my laptop, but falls apart when I open the lister on my 4K monitor.

What means could I potentially use to always set Toolbar Two to ALWAYS start 500 pixels from the right edge of the lister, regardless of monitor resolution?

Scripting can give you the coordinates of any open lister windows, as well as of the monitors. You could use that to position things.

I have the scripting ability of a 5-year-old, but will give it a go.

@Leo @Jon @lxp

Here's my starting script that does NOT work as intended. Would appreciate any hints or insight.

function OnInit(initData) {
    initData.name = "Change Toolbar Position";
    initData.version = "0.1";
    initData.copyright = "(c) 2022 Chuck";
    initData.desc = "Adjust toolbar positions based on lister width";
    initData.default_enable = true;
    initData.min_version = "12.27";
}

function OnListerResize(ListerResizeData) {

	var factory = DOpus.Create();
	var cmd = factory.Command;
	var wid = ListerResizeData.width - 500;
	
	if (ListerResizeData.width >= 1920) {
		cmd.RunCommand("Toolbar ToolbarOne STATE=top LINE=0");
		cmd.RunCommand("Toolbar ToolbarTwo STATE=top LINE=0," + wid);
		}
	else {
		cmd.RunCommand("Toolbar ToolbarOne STATE=top LINE=0");
		cmd.RunCommand("Toolbar ToolbarTwo STATE=top LINE=0,1420");
	}
}

Is the lister always maximised?

This should work. Not sure why the toolbar needs to be closed and the delay is necessary.

function OnListerResize(ListerResizeData) {
    var cmd = DOpus.Create().Command;
    cmd.SetSourceTab(ListerResizeData.lister.activetab);
    cmd.RunCommand('Toolbar NAME=ToolbarTwo CLOSE');
    DOpus.Delay(100);
    cmd.RunCommand('Toolbar NAME=ToolbarTwo LINE=0,' + (ListerResizeData.width - 500));
}

@Leo The lister is NOT always maximized. I sometimes maximize DOpus on my big monitor based on workflow.

@lxp This works VERY well...

I might explore expanding this a bit.

THANK YOU!

If you want the toolbar 500 pixels from the monitor edge then you'd need to use the monitor coordinates somewhere in the script, and work out where the lister window is relative to the edge of the monitor. You can get the monitor coordinates via the SysInfo object.

I'm not sure what you'd want to happen if the lister is more than 500 pixels away from the edge of the screen, though.

@Leo, thanks for the information. I should have restated my intent better: I want toolbar two to always be 500 pixels from the right edge of the lister. lxp's solution resolves this!

1 Like