Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
badbob001
64 discussion posts
I'm trying to create hotkeys to move the window under the mouse to an adjacent split. I don't want just move to next/prev but support up and down. Up and down is a bit harder to do so I just hardcode the destination split dpending on the current split.

But I can't seem to get it to do anything. Maybe I'm using function "Move Window to Monitor X#" wrong?

Code

using System;
using System.Drawing;

// move window under mouse "up"

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
    
    public static void Run(IntPtr windowHandle)
    {
        
        // Get the window under the mouse
        IntPtr windowUnderMouse = BFS.Window.GetWindowUnderMouse();

        uint sourceMonitor = BFS.Monitor.GetMonitorIDByWindow(windowUnderMouse);    
        uint targetMonitor = 1;
        switch(sourceMonitor){
            case 201:
                targetMonitor = 202;
                break;
            case 202:
                targetMonitor = 201;
                break;    
            case 203:
                targetMonitor = 1;
                break;
            case 204:
                targetMonitor = 203;
                break;
            case 205:
                targetMonitor = 1;
                break;
            case 206:
                targetMonitor = 205;
                break;
            case 207:
                targetMonitor = 208;
                break;
            case 208:
                targetMonitor = 207;
                break;
            case 1:
                targetMonitor = 204;
                break;
        }
        
        BFS.DisplayFusion.RunFunction("Move Window to Monitor {targetMonitor}");
        BFS.DisplayFusion.RunFunction("Move Mouse Cursor to Monitor {targetMonitor}");
    }
}
• Attachment: splits.png [23,847 bytes]
splits.png
splits.png
21 days ago (modified 21 days ago)  • #1
Owen Muhlethaler (BFS)'s profile on WallpaperFusion.com
We don't have a built in function for moving the mouse to a target monitor. Try this:

Line 53:

BFS.Window.MoveToMonitor(targetMonitor, windowUnderMouse);

Line 54-57:

uint targetMonitor = 1;
Rectangle targetMonitorBounds = BFS.Monitor.GetMonitorBoundsByID(targetMonitor);
Point targetMousePosition = new Point(targetMonitorBounds.X + (targetMonitorBounds.Width / 2), targetMonitorBounds.Y + (targetMonitorBounds.Height / 2));
BFS.Input.SetMousePosition(targetMousePosition.X, targetMousePosition.Y);
20 days ago  • #2
User Image
badbob001
64 discussion posts
Thanks! See attached for updated function.

Is there a way to pass a parameter to a function? So I have hotkeys for moving the window up,down,left, or right, but for now, I need to duplicate the same function for all four actions and modify a variable to tell the function which direction is invoked.

But perhaps I'm pointlessly over-complicating a simple system. Last thing I want is to reduce responsiveness. I've noticed that if I haven't used a hotkey recently, it takes a few seconds for it to react. Maybe it gets unloaded from memory to reduce memory usage? Maybe all functions with hotkeys should always be in memory?

I'm using this function with an Apple Magic Trackpad on Win10 via github drivers that implement the Windows Precision Touch Protocol. Windows lets me assign custom gestures to keystrokes so now I have four-finger swipe up/down/left/right to match the DF hotkeys of crtl-alt-up/down/left/right to move windows between splits.

Neat thing I just found out is that I can use the SHIFT key to modify the above gestures. So in DF, I have ctrl-alrt-SHIFT-up/down/left/right run functions that expand the window size to include the split in the chosen direction. So without changing the four-finger swipe settings in windows, I can use the same gestures with the SHIFT button to expand a window.

Code

using System;
using System.Drawing;

// move window under mouse up split

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
    
    public static void Run(IntPtr windowHandle)
    {
        string direction = "up";
        
        // Get the window under the mouse
        IntPtr windowUnderMouse = BFS.Window.GetWindowUnderMouse();

        uint sourceMonitor = BFS.Monitor.GetMonitorIDByWindow(windowUnderMouse);    
        uint targetMonitor = 1;
        
        switch(direction){
            case "up":
                switch(sourceMonitor){
                    case 201:
                        targetMonitor = 202;
                        break;
                    case 202:
                        targetMonitor = 201;
                        break;    
                    case 203:
                        targetMonitor = 1;
                        break;
                    case 204:
                        targetMonitor = 203;
                        break;
                    case 205:
                        targetMonitor = 1;
                        break;
                    case 206:
                        targetMonitor = 205;
                        break;
                    case 207:
                        targetMonitor = 208;
                        break;
                    case 208:
                        targetMonitor = 207;
                        break;
                    case 1:
                        targetMonitor = 206;
                        break;
                }
                break;
            case "down":
                switch(sourceMonitor){
                    case 201:
                        targetMonitor = 202;
                        break;
                    case 202:
                        targetMonitor = 201;
                        break;    
                    case 203:
                        targetMonitor = 204;
                        break;
                    case 204:
                        targetMonitor = 1;
                        break;
                    case 205:
                        targetMonitor = 206;
                        break;
                    case 206:
                        targetMonitor = 1;
                        break;
                    case 207:
                        targetMonitor = 208;
                        break;
                    case 208:
                        targetMonitor = 207;
                        break;
                    case 1:
                        targetMonitor = 205;
                        break;
                }
                break;
            case "right":
                switch(sourceMonitor){
                    case 201:
                        targetMonitor = 203;
                        break;
                    case 202:
                        targetMonitor = 204;
                        break;    
                    case 203:
                        targetMonitor = 205;
                        break;
                    case 204:
                        targetMonitor = 206;
                        break;
                    case 205:
                        targetMonitor = 207;
                        break;
                    case 206:
                        targetMonitor = 208;
                        break;
                    case 207:
                        targetMonitor = 201;
                        break;
                    case 208:
                        targetMonitor = 202;
                        break;
                    case 1:
                        targetMonitor = 1;
                        break;
                }
                break;
            case "left":
                switch(sourceMonitor){
                    case 201:
                        targetMonitor = 207;
                        break;
                    case 202:
                        targetMonitor = 208;
                        break;    
                    case 203:
                        targetMonitor = 201;
                        break;
                    case 204:
                        targetMonitor = 202;
                        break;
                    case 205:
                        targetMonitor = 203;
                        break;
                    case 206:
                        targetMonitor = 204;
                        break;
                    case 207:
                        targetMonitor = 205;
                        break;
                    case 208:
                        targetMonitor = 206;
                        break;
                    case 1:
                        targetMonitor = 1;
                        break;
                }
                break;                
        }
                
        BFS.Window.MoveToMonitor(targetMonitor, windowUnderMouse);
        BFS.Window.Maximize(windowUnderMouse);
        Rectangle targetMonitorBounds = BFS.Monitor.GetMonitorBoundsByID(targetMonitor);
        Point targetMousePosition = new Point(targetMonitorBounds.X + (targetMonitorBounds.Width / 2), targetMonitorBounds.Y + (targetMonitorBounds.Height / 2));
        BFS.Input.SetMousePosition(targetMousePosition.X, targetMousePosition.Y);        
    }
}
19 days ago (modified 19 days ago)  • #3
Owen Muhlethaler (BFS)'s profile on WallpaperFusion.com
I don't think there's a way to do what you're looking for all in one script. You'll need to separate them into 4 scripts, with your hotkey for each attached to each direction.
13 days ago  • #4
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)