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.
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);
}
}