StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob  
#1 Posted : Saturday, March 16, 2019 9:28:09 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 455
United States

Thanks: 5 times
Was thanked: 88 time(s) in 76 post(s)
Put this script inside the Global Actions > Mouse Events > Left Click Script to allow Alt+Drag to move window (which is not maximized).
FYI, the click event scripts do not interfere with input, so the Alt key down and release are still received by the window.

Note, this only works starting with version 0.2.9.2, prior versions only executed the click scripts on mouse up.

IMPORTANT: Do not use this (or any timer script, really) without having the Use Script Engine Pool option enabled and a pool size of at least two. I will likely be removing that option, so if I forget to update this post and you don't see the option, don't worry about it!

Code:
if(click.Down) {
    if((sp.GetKeyState(vk.LMENU) & 0x8000) && !sp.GetStoredBool("MoveWindowActive")) {
        if(!click.Window.Maximized) {
            sp.StoreBool("MoveWindowActive", true);
            sp.StoreHandle("MoveWindowHandle", click.Window.HWnd);
            sp.StorePoint("MoveWindowMouseStart", sp.GetCurrentMousePoint());
            sp.StorePoint("MoveWindowStart", click.Window.Location);
            sp.CreateTimer("MoveWindow", 20, 10, String.raw`
                                    var wnd = sp.WindowFromHandle(sp.GetStoredHandle("MoveWindowHandle"));
                                    if(sp.GetKeyState(vk.ESCAPE) & 0x8000) {
                                        wnd.Location = sp.GetStoredPoint("MoveWindowStart");
                                        sp.DeleteTimer("MoveWindow");
                                    }
                                    var startMousePt = sp.GetStoredPoint("MoveWindowMouseStart");
                                    var currMousePt = sp.GetCurrentMousePoint();
                                    var currWinPt = wnd.Location;
                                    if(sp.GetStoredBool("MoveWindowActive")) {
                                        wnd.Location = new Point(currWinPt.X + currMousePt.X - startMousePt.X, currWinPt.Y + currMousePt.Y - startMousePt.Y);
                                    }
                                    sp.StorePoint("MoveWindowMouseStart", currMousePt);
                                `);
        }
    }
} else {
    if(sp.GetStoredBool("MoveWindowActive")) 
    {
        sp.DeleteStoredHandle("MoveWindowHandle");
        sp.DeleteStoredBool("MoveWindowActive");
        sp.DeleteTimer("MoveWindow");
        sp.DeleteStoredPoint("MoveWindowMouseStart");
        sp.DeleteStoredPoint("MoveWindowStart");
    }
}

Edited by user Monday, September 9, 2019 8:34:50 PM(UTC)  | Reason: Not specified

2014218866  
#2 Posted : Friday, September 6, 2019 8:36:58 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
Dear Rob,

This script doesn't work properly.

When I release the Alt key, the window still moves with the mouse. When I execute the script for the second or third time, the window will not be moved
Rob  
#3 Posted : Friday, September 6, 2019 9:08:33 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 455
United States

Thanks: 5 times
Was thanked: 88 time(s) in 76 post(s)
Hmm, I just copied the script into my left click script and it works fine. Are you able to provide any additional details which might allow me to reproduce the issue? What other settings do you have, anything like having the Alt be as the ignore key, etc?
2014218866  
#4 Posted : Monday, September 9, 2019 7:17:25 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
Dear Rob, this is my configuration file. You can test it.

https://sendit.cloud/dnuqsp181ikt
Rob  
#5 Posted : Monday, September 9, 2019 8:33:14 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 455
United States

Thanks: 5 times
Was thanked: 88 time(s) in 76 post(s)
Okay, I was able to reproduce the issue.

Under Options > Advanced, check the Use Script Engine Pool checkbox and enter 2 for Max Script Pool Size.
I use 3, but each engine take a little more memory and system resources, but at least two will ensure you can have multiple scripts able to quickly execute in parallel without trying to use an excessive amount of resources by creating a new one for each execution.

NOTE: You must close and restart S+ after saving that option.

I will look into whether this option should remain or if restrictions need to be applied.

Your config had that unchecked which means every single script execution is spinning up an entire new script engine, loading all of the objects/plug-ins, then executing the script.

The problem is, this script is using a timer which executes every 10 milliseconds. This causes a very large load on the system and is creating a lot of contention, with dozens of script engines being created in less than a half second. I opened Task Manager while doing the Alt+Drag (without the script engine pool checked) and you could see the memory growing very fast.

There is really no good reason to have that option unchecked. I like to give people options, so I wanted to have it available...but I'm thinking that it may not be a good idea. At a minimum, I should probably make it a hidden settings...but even then, it can create a bad user experience and I really think I remove it.
thanks 1 user thanked Rob for this useful post.
2014218866 on 9/9/2019(UTC)
2014218866  
#6 Posted : Monday, September 9, 2019 8:53:38 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
Well, you know, for users who don't have script engines, it always prompts "No script engine available; quit the script." Please try again. It really affects experience.
Rob  
#7 Posted : Monday, September 9, 2019 10:32:56 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 455
United States

Thanks: 5 times
Was thanked: 88 time(s) in 76 post(s)
Increase your script lock attempts (can't remember exact name, not at the computer). It's a very brief delay between attempts, so you should use a high value. I have mine set to 500 and I only get that message if I'm trying to make it happen.
2014218866  
#8 Posted : Monday, September 9, 2019 11:34:17 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
OK, you are right. Thanks a lot.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.