Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Resize windows width to 1/3 of screen #8

Open
pavelpromin opened this issue Jul 18, 2014 · 2 comments
Open

Question: Resize windows width to 1/3 of screen #8

pavelpromin opened this issue Jul 18, 2014 · 2 comments

Comments

@pavelpromin
Copy link

I'm sorry, I'm not programmer and I don't understand C
I need resize windows to 1/3 of screen by width. How can i do it?
Is it lines 566-579 code block of hooks.c file?

@stefansundin
Copy link
Owner

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.

@pavelpromin
Copy link
Author

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants