Code Monkey home page Code Monkey logo

Comments (2)

stefansundin avatar stefansundin commented on June 23, 2024

Hi. Sorry for late response.

For the Aero Snap behavior, the lines you need to modify is here:

altdrag/hooks.c

Lines 739 to 859 in d433373

if (sharedsettings.Aero) {
// Restore window?
if (maximized
&& ((pt.y >= mon.top+AERO_THRESHOLD)
|| (fmon.left < pt.x && pt.x < mon.left+2*AERO_THRESHOLD)
|| (mon.right-2*AERO_THRESHOLD < pt.x && pt.x < fmon.right))) {
// Restore window
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(state.hwnd, &wndpl);
wndpl.showCmd = SW_RESTORE;
SetWindowPlacement(state.hwnd, &wndpl);
// Update wndwidth and wndheight
wndwidth = wndpl.rcNormalPosition.right-wndpl.rcNormalPosition.left;
wndheight = wndpl.rcNormalPosition.bottom-wndpl.rcNormalPosition.top;
}
// Move window
if (pt.x < mon.left+2*AERO_THRESHOLD && pt.y < mon.top+2*AERO_THRESHOLD) {
// Top left
state.wndentry->restore = 1;
wndwidth = (mon.right-mon.left)/2;
wndheight = (mon.bottom-mon.top)/2;
posx = mon.left;
posy = mon.top;
}
else if (mon.right-2*AERO_THRESHOLD < pt.x && pt.y < mon.top+2*AERO_THRESHOLD) {
// Top right
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left)/2, state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = (mon.bottom-mon.top)/2;
posx = mon.right-wndwidth;
posy = mon.top;
}
else if (pt.x < mon.left+2*AERO_THRESHOLD && mon.bottom-2*AERO_THRESHOLD < pt.y) {
// Bottom left
state.wndentry->restore = 1;
wndwidth = (mon.right-mon.left)/2;
wndheight = max(min((mon.bottom-mon.top)/2, state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.left;
posy = mon.bottom-wndheight;
}
else if (mon.right-2*AERO_THRESHOLD < pt.x && mon.bottom-2*AERO_THRESHOLD < pt.y) {
// Bottom right
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left)/2, state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top)/2, state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.right-wndwidth;
posy = mon.bottom-wndheight;
}
else if (pt.y < mon.top+AERO_THRESHOLD && !state.mdiclient) {
// Top
if (!maximized) {
state.wndentry->restore = 0;
// Center window on monitor and maximize it
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(state.hwnd, &wndpl);
wndpl.rcNormalPosition.left = fmon.left+(mon.right-mon.left)/2-state.origin.width/2;
wndpl.rcNormalPosition.top = fmon.top+(mon.bottom-mon.top)/2-state.origin.height/2;
wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left+state.origin.width;
wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top+state.origin.height;
wndpl.showCmd = SW_MAXIMIZE;
SetWindowPlacement(state.hwnd, &wndpl);
}
return;
}
else if (pt.y < mon.top+2*AERO_THRESHOLD) {
// Top
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left), state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = (mon.bottom-mon.top)/2;
posx = mon.left+(mon.right-mon.left)/2-wndwidth/2; // Center horizontally (if window has a max width)
posy = mon.top;
}
else if (mon.bottom-AERO_THRESHOLD < pt.y) {
// Bottom
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left), state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top)/2, state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.left+(mon.right-mon.left)/2-wndwidth/2; // Center horizontally (if window has a max width)
posy = mon.bottom-wndheight;
}
else if (pt.x < mon.left+AERO_THRESHOLD) {
// Left
state.wndentry->restore = 1;
wndwidth = (mon.right-mon.left)/2;
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.left;
posy = mon.top+(mon.bottom-mon.top)/2-wndheight/2; // Center vertically (if window has a max height)
}
else if (mon.right-AERO_THRESHOLD < pt.x) {
// Right
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left)/2, state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.right-wndwidth;
posy = mon.top+(mon.bottom-mon.top)/2-wndheight/2; // Center vertically (if window has a max height)
}
else if (state.wndentry->restore) {
// Restore original window size
state.wndentry->restore = 0;
wndwidth = state.origin.width;
wndheight = state.origin.height;
}
// Aero-move the window?
if (state.wndentry->restore) {
state.wndentry->width = state.origin.width;
state.wndentry->height = state.origin.height;
// Move
MoveWindow(state.hwnd, posx, posy, wndwidth, wndheight, TRUE);
// Get new size after move
// Doing this since wndwidth and wndheight might be wrong if the window is resized in chunks
GetWindowRect(state.hwnd, &wnd);
state.wndentry->last.width = wnd.right-wnd.left;
state.wndentry->last.height = wnd.bottom-wnd.top;
// We are done
return;
}

For resize double-click, you can change these lines:

altdrag/hooks.c

Lines 1755 to 1800 in d433373

if (GetTickCount()-state.clicktime <= GetDoubleClickTime()) {
sharedstate.action = ACTION_NONE; // Stop resize action
state.clicktime = 0; // Reset double-click time
state.blockmouseup = 1; // Block the mouseup, otherwise it can trigger a context menu (e.g. in explorer, or on the desktop)
// Get and set new position
int posx, posy, wndwidth, wndheight;
wndwidth = max(min((mon.right-mon.left)/2, state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top)/2, state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.left;
posy = mon.top;
if (state.resize.y == RESIZE_CENTER) {
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posy += (mon.bottom-mon.top)/2-wndheight/2;
}
else if (state.resize.y == RESIZE_BOTTOM) {
posy = mon.bottom-wndheight;
}
if (state.resize.x == RESIZE_CENTER && state.resize.y != RESIZE_CENTER) {
wndwidth = max(min((mon.right-mon.left), state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
posx += (mon.right-mon.left)/2-wndwidth/2;
}
else if (state.resize.x == RESIZE_CENTER) {
wndwidth = wnd.right-wnd.left;
posx = wnd.left-mdiclientpt.x;
}
else if (state.resize.x == RESIZE_RIGHT) {
posx = mon.right-wndwidth;
}
MoveWindow(state.hwnd, posx, posy, wndwidth, wndheight, TRUE);
// Get new size after move
// Doing this since wndwidth and wndheight might be wrong if the window is resized in chunks (e.g. PuTTY)
GetWindowRect(state.hwnd, &wnd);
// Update wndentry
state.wndentry->last.width = wnd.right-wnd.left;
state.wndentry->last.height = wnd.bottom-wnd.top;
if (!state.wndentry->restore) {
state.wndentry->width = state.origin.width;
state.wndentry->height = state.origin.height;
state.wndentry->restore = 1;
}
// Prevent mousedown from propagating
return 1;
}

Good luck!

P.S. If you fork the project and commit your changes to your fork, then we can easily see your modifications. In case anyone else wants this too.

from altdrag.

pavelpromin avatar pavelpromin commented on June 23, 2024

Thank you!
I just modify some strings for splitting widescreen lcd view to 3 part:

altdrag/hooks.c

Lines 813 to 818 in d433373

// Bottom
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left), state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top)/2, state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.left+(mon.right-mon.left)/2-wndwidth/2; // Center horizontally (if window has a max width)
posy = mon.bottom-wndheight;
to

// Bottom
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left)/3, state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.right-2*wndwidth;
posy = mon.top+(mon.bottom-mon.top)/3-wndheight/3;

altdrag/hooks.c

Lines 821 to 826 in d433373

// Left
state.wndentry->restore = 1;
wndwidth = (mon.right-mon.left)/2;
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.left;
posy = mon.top+(mon.bottom-mon.top)/2-wndheight/2; // Center vertically (if window has a max height)
to

// Left
state.wndentry->restore = 1;
wndwidth = (mon.right-mon.left)/3;
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.left;
posy = mon.top+(mon.bottom-mon.top)/3-wndheight/3;

altdrag/hooks.c

Lines 829 to 834 in d433373

// Right
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left)/2, state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.right-wndwidth;
posy = mon.top+(mon.bottom-mon.top)/2-wndheight/2; // Center vertically (if window has a max height)
to

// Right
state.wndentry->restore = 1;
wndwidth = max(min((mon.right-mon.left)/3, state.mmi.ptMaxTrackSize.x), state.mmi.ptMinTrackSize.x);
wndheight = max(min((mon.bottom-mon.top), state.mmi.ptMaxTrackSize.y), state.mmi.ptMinTrackSize.y);
posx = mon.right-wndwidth;
posy = mon.top+(mon.bottom-mon.top)/3-wndheight/3;

from altdrag.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.