Page 1 of 2

Dual-monitor management

Posted: 27 Jul 2014 18:21
by lian00
Sorry if the topic does not belong here.

I have two monitors with different resolutions and it's a little boring whent I have to move XYplorer because the window must be resized to fit my need. In XnViewMP, you can save the disposition of the window (wich monitor and wich size) and call it with a menu (four different dispositions). If you have solutions to solve this - tips, freeware - I will be glad to hear about it.

Re: Dual-monitor management

Posted: 27 Jul 2014 19:27
by highend
Autohotkey...

Check on which monitor XY is and resize the window appropriately.

A rather simple solution:

E.g.:

Code: Select all

#NoTrayIcon
#SingleInstance force
#Persistent

xyClass := "ThunderRT6FormDC"

SysGet, m, MonitorCount
Loop, %m%
	SysGet, mon%A_Index%, Monitor, %A_Index%

leftX := 120
leftY := 10
leftWidth = 1550
leftHeigth = 1000

rightX := mon2Left + 120
rightY := 10
rightWidth = 1550
rightHeigth = 1000

SetTimer, MoveXY, 250
return

MoveXY:
if WinExist("ahk_class" . xyClass)
{
	WinGetPos, xPos, , , , ahk_class %xyClass%
	if (xPos >= mon2Left) {
		WinMove, ahk_class %xyClass%, , rightX, rightY, rightWidth, rightHeigth
	} else {
		WinMove, ahk_class %xyClass%, , leftX, leftY, leftWidth, leftHeigth
	}
}
return
You could also let the ahk script read values from an .ini file to use more than just a fixed position.

Re: Dual-monitor management

Posted: 27 Jul 2014 19:41
by lian00
Thanks. I will look at this. I use AutoIt for some script so I will look if I can manage this this way.

Re: Dual-monitor management

Posted: 27 Jul 2014 20:10
by highend
It would be better to enhance the script to let it create / update and read settings to / from an .ini file.

XY could display the necessary content parts and let you choose the one you like...

Re: Dual-monitor management

Posted: 27 Jul 2014 23:21
by lian00
highend wrote:It would be better to enhance the script to let it create / update and read settings to / from an .ini file.

XY could display the necessary content parts and let you choose the one you like...
Is there an example of such ini file in help file ? Or on the forum ?

Re: Dual-monitor management

Posted: 28 Jul 2014 13:00
by highend
A better way (the former resized all XYplorer windows which is probably not what everybody wants)...

Edit:
Script was updated, look further down to find the current version...

Re: Dual-monitor management

Posted: 28 Jul 2014 13:30
by lian00
Thanks. I will take a look at this.

Re: Dual-monitor management

Posted: 28 Jul 2014 14:34
by lian00
@Highend: How do I manage your exe file ?

Re: Dual-monitor management

Posted: 28 Jul 2014 15:44
by highend
You either extract it into the same path where you store the script or if you place it in a different path you adjust the variable in the script.

Re: Dual-monitor management

Posted: 28 Jul 2014 16:23
by lian00
OK, thanks.

Re: Dual-monitor management

Posted: 29 Jul 2014 17:06
by highend
I've changed a few things...

- The popup menu shows the current values (x, y, width, height) for the "Save" entry
- All entries can be executed by "s" (for "Save") | by their number (1 for the first entry, 2 for second, etc.)
- If the $posLimit variable is changed any superfluous windows positions are removed

All entries are stored INSIDE the script from now on. You can delete the old .ini file...

The .exe file was changed, too. The new version of the script only works with the new .exe!

Code: Select all

    $posLimit = 4;
    end $posLimit > 9, "Do not set the position limit to a value greater then 9!";
    $helperApp = self("path") . "\XYplorer_ManageWindowPosition.exe";

    $winPositions = <<<>>>
>>>;

    $curPosition = runret("""$helperApp"" /get");
    $saveCurPosMenuEntry = "&Save (" . trim(replace($curPosition, "|", " "), "<crlf>") . ")";
    $winPositionCount = gettoken(trim($winPositions, "<crlf>"), "count", "<crlf>"); // How many stored positions?

    // Purge entries if $posLimit was changed
    if ($winPositionCount > $posLimit) {
        $i = 1;
        $tmpWinPositions = "";
        foreach($item, $winPositions, "<crlf>") {
            if ($i > $posLimit) {
                break;
            } else {
                $tmpWinPositions = $tmpWinPositions . $item . "<crlf>";
            }
            $i++;
        }
        $tmpWinPositions = trim($tmpWinPositions, "<crlf>");
        $content = regexreplace(readfile(self("file")), "(\$[w]inPositions = <<<>>>)([\s\S]+?)(>>>;)", "$1<crlf>$tmpWinPositions<crlf>$3");
        writefile(self("file"), $content);
        $winPositions = $tmpWinPositions;
    }

    // Display position entries through popup menu
    $popupEntries = "";
    if ($winPositionCount == 0) {
        $popupEntries = "No positions to restore...";
    } else {
        $i = 1;
        foreach($pos, $winPositions, "<crlf>") {
            $popupEntries = $popupEntries . "&" . $i++ . " - " . replace($pos, "|", " ") . "|";
        }
    }
    $popup = popupmenu("$saveCurPosMenuEntry|-|$popupEntries", -1, -1);

    if (strpos($popup, "save") != -1) { // Save a new entry
        $i = 2;
        $tmpWinPositions = trim($curPosition, "<crlf>");
        if ($winPositionCount >= 1) {
            foreach ($item, $winPositions, "<crlf>") {
                if ($i <= $posLimit) {
                    $tmpWinPositions = $tmpWinPositions . "<crlf>" . $item;
                }
                $i++;
            }
        }
        $content = regexreplace(readfile(self("file")), "(\$[w]inPositions = <<<>>>)([\s\S]+?)(>>>;)", "$1<crlf>$tmpWinPositions<crlf>$3");
        writefile(self("file"), $content);
        status "Current position saved!", "006400", "ready";

    } elseif (strpos($popup, "-") != -1) { // Move window
        $newPosition = regexreplace($popup, "^.*?(?=x)|[xywh]:");
        run """$helperApp"" /move $newPosition", , 2, 0;
    }
XYplorer_ManageWindowPosition.zip

Re: Dual-monitor management

Posted: 29 Jul 2014 17:19
by lian00
I did find a simple solution for my problem - as the dual monitor is considered as a single monitor by Autoit, the WinMove() function is enough (so two buttons for two exe files with one line of script each). But I would be curious to test your solution - much more complete as I understand.
I'm new to XYplorer scripting and a little lost. I have to copy your script in a xys file, put it in the script directory, copy the exe file in the same directory and create a button with open exe ? Am I right ?

Re: Dual-monitor management

Posted: 29 Jul 2014 17:30
by highend
so two buttons for two exe files with one line of script each
And >1 MB filesize? (for two .exes, non upx compressed) xD

The xy script is much more flexible, needs only a single .exe (which is only 8kb large).
I have to copy your script in a xys file, put it in the script directory, copy the exe file in the same directory and create a button with open exe
A button with "open exe"? No, the button has to invoke the script, not the .exe file.

Re: Dual-monitor management

Posted: 29 Jul 2014 17:53
by lian00
I tried this after reading the page http://www.xyplorer.com/tour/?page=scripting

I copy the script in a file "dual-monitor.xys" in scripts directory, I copy the exe file in the same directory, I create a button with load "dual-monitor.xys". When I click it, I've got an error.

Re: Dual-monitor management

Posted: 29 Jul 2014 18:39
by highend
And now we are supposed to guess what error message you got?