Skip to content

Commit

Permalink
add shrink down
Browse files Browse the repository at this point in the history
  • Loading branch information
GrylledCheez committed Jun 25, 2023
1 parent 94a3f39 commit 81ab917
Showing 1 changed file with 55 additions and 39 deletions.
94 changes: 55 additions & 39 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function sendMove(direction) {
// We are not in a tile. Reset and find the most logical position
_log('sendMove) Not in tile.');
if (colCount === 2) {
// Normal 2x2 grid
// 2 col grid
switch (direction) {
case 'left':
// Move to the left most column at full height
Expand All @@ -348,7 +348,7 @@ function sendMove(direction) {
case 'right':
// Move to the right most column at full height
initApp(app);
moveApp(app, {'row': 0, 'col': 1, 'height': rowCount, 'width': 1});
moveApp(app, {'row': 0, 'col': colCount - 1, 'height': rowCount, 'width': 1});
break;
case 'up':
// 1st Maximize
Expand All @@ -361,7 +361,7 @@ function sendMove(direction) {
break;
}
} else if (colCount === 3) {
// Ultrawide 3x2 grid
// 3 col grid
switch (direction) {
case 'left':
// Move to the left most column at full height
Expand All @@ -371,7 +371,7 @@ function sendMove(direction) {
case 'right':
// Move to the right most column at full height
initApp(app);
moveApp(app, {'row': 0, 'col': 2, 'height': rowCount, 'width': 1});
moveApp(app, {'row': 0, 'col': colCount - 1, 'height': rowCount, 'width': 1});
break;
case 'up':
// 1st Maximize
Expand All @@ -384,7 +384,7 @@ function sendMove(direction) {
break;
}
} else {
// Ultrawide 4x2 grid
// 4 col grid
switch (direction) {
case 'left':
// Move to the left half at full height
Expand Down Expand Up @@ -412,13 +412,13 @@ function sendMove(direction) {
_log('sendMove) Already in a tile.');
_log(JSON.stringify(app.wintile));
if (colCount === 2) {
// Normal 2x2 grid
// 2 col grid
switch (direction) {
case 'left':
_log('sendMove) left');
if (app.wintile.col > 0) {
// We can move left on this monitor and keep our size
_log('sendMove) left - 1');
_log('sendMove) left - move');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col - 1, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.width === colCount) {
// We are full width top or bottom, shrink
Expand All @@ -432,7 +432,7 @@ function sendMove(direction) {
} else {
// There is a monitor to the left, so let's go there
app.move_to_monitor(monitorToLeft);
_log('sendMove) left - 4');
_log('sendMove) left - monitor');
moveApp(app, {'row': app.wintile.row, 'col': colCount - 1, 'height': app.wintile.height, 'width': app.wintile.width});
}
break;
Expand All @@ -446,19 +446,19 @@ function sendMove(direction) {
// We are a top or bottom half, shrink
_log('sendMove) right - 2');
moveApp(app, {'row': app.wintile.row, 'col': 1, 'height': rowCount, 'width': 1});
} else if (app.wintile.col < 1) {
} else if (app.wintile.col < colCount - 1) {
// We can move right on this monitor and keep our size
_log('sendMove) right - 3');
_log('sendMove) right - move');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col + 1, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (monitorToRight === -1) {
// We are already on the right, and there is no other monitor to the right
// Move to the right most column at full height
_log('sendMove) right - 4');
moveApp(app, {'row': 0, 'col': 1, 'height': rowCount, 'width': 1});
moveApp(app, {'row': 0, 'col': colCount - 1, 'height': rowCount, 'width': 1});
} else {
// There is a monitor to the right, so let's go there
app.move_to_monitor(monitorToRight);
_log('sendMove) right - 5');
_log('sendMove) right - monitor');
moveApp(app, {'row': app.wintile.row, 'col': 0, 'height': app.wintile.height, 'width': app.wintile.width});
}
break;
Expand All @@ -468,6 +468,10 @@ function sendMove(direction) {
// We are already on the top, shrink
_log('sendMove) up - shrink');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col, 'height': app.wintile.height - 1, 'width': app.wintile.width});
} else if (app.wintile.row > 0) {
// We can move up on this monitor and keep our size
_log('sendMove) up - move');
moveApp(app, {'row': app.wintile.row - 1, 'col': app.wintile.col, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.height === rowCount && app.wintile.width === 1) {
// We are full height and not maximized, go to half height
_log('sendMove) up - 1');
Expand All @@ -492,6 +496,14 @@ function sendMove(direction) {
// We are maximized, restore
_log('sendMove) down - 1');
restoreApp(app);
} else if (app.wintile.row + app.wintile.height < rowCount){
// We can move down on this monitor and keep our size
_log('sendMove) down - move');
moveApp(app, {'row': app.wintile.row + 1, 'col': app.wintile.col, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.row + app.wintile.height === rowCount && app.wintile.height > 1) {
// We are already at the bottom, shrink
_log('sendMove) down - shrink');
moveApp(app, {'row': app.wintile.row + 1, 'col': app.wintile.col, 'height': app.wintile.height - 1, 'width': app.wintile.width});
} else if (app.wintile.col === 0 && app.wintile.width === colCount && app.wintile.row === 0) {
// We are top half, go to bottom half
_log('sendMove) down - 2');
Expand All @@ -516,21 +528,21 @@ function sendMove(direction) {
break;
}
} else if (colCount === 3) {
// Ultrawide 3x2 grid
// 3 col grid
switch (direction) {
case 'left':
_log('sendMove) left');
if (app.wintile.col > 0) {
// We can move left on this monitor and keep our size
_log('sendMove) left - 1');
_log('sendMove) left - move');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col - 1, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.col === 0 && app.wintile.width > 1) {
// We are not yet to smallest width, so shrink
_log('sendMove) left - 2');
_log('sendMove) left - shrink');
moveApp(app, {'row': app.wintile.row, 'col': 0, 'height': app.wintile.height, 'width': app.wintile.width - 1});
} else if (monitorToLeft !== -1) {
// There is a monitor to the left, so let's go there
_log('sendMove) left - 3');
_log('sendMove) left - monitor');
app.move_to_monitor(monitorToLeft);
moveApp(app, {'row': app.wintile.row, 'col': colCount - 1, 'height': app.wintile.height, 'width': 1});
} else {
Expand All @@ -544,15 +556,15 @@ function sendMove(direction) {
_log('sendMove) right');
if (app.wintile.col + app.wintile.width - 1 < colCount - 1) {
// We can move right on this monitor and keep our size
_log('sendMove) right - 1');
_log('sendMove) right - move');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col + 1, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.col + app.wintile.width - 1 === colCount - 1 && app.wintile.width > 1) {
// We are not yet to smallest width, so shrink
_log('sendMove) right - 2');
_log('sendMove) right - shrink');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col + 1, 'height': app.wintile.height, 'width': app.wintile.width - 1});
} else if (monitorToRight !== -1) {
// There is a monitor to the right, so let's go there
_log('sendMove) right - 3');
_log('sendMove) right - monitor');
app.move_to_monitor(monitorToRight);
moveApp(app, {'row': app.wintile.row, 'col': 0, 'height': app.wintile.height, 'width': 1});
} else {
Expand Down Expand Up @@ -588,6 +600,10 @@ function sendMove(direction) {
// We are maximized, restore
_log('sendMove) down - 1');
restoreApp(app);
} else if (app.wintile.row + app.wintile.height === rowCount && app.wintile.height > 1) {
// We are already at the bottom, shrink
_log('sendMove) down - shrink');
moveApp(app, {'row': app.wintile.row + 1, 'col': app.wintile.col, 'height': app.wintile.height - 1, 'width': app.wintile.width});
} else if (app.wintile.col === 0 && app.wintile.width === colCount && app.wintile.row === 0) {
// We are top half, go to bottom half
_log('sendMove) down - 2');
Expand All @@ -612,21 +628,21 @@ function sendMove(direction) {
break;
}
} else {
// Ultrawide 4x2 grid
// 4 col grid
switch (direction) {
case 'left':
_log('sendMove) left');
if (app.wintile.col > 0) {
// We can move left on this monitor and keep our size
_log('sendMove) left - 1');
_log('sendMove) left - move');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col - 1, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.col === 0 && app.wintile.width > 1) {
// We are not yet to smallest width, so shrink
_log('sendMove) left - 2');
moveApp(app, {'row': app.wintile.row, 'col': 0, 'height': app.wintile.height, 'width': app.wintile.width - 1});
} else if (monitorToLeft !== -1) {
// There is a monitor to the left, so let's go there
_log('sendMove) left - 3');
_log('sendMove) left - monitor');
app.move_to_monitor(monitorToLeft);
moveApp(app, {'row': app.wintile.row, 'col': colCount - 1, 'height': app.wintile.height, 'width': 1});
} else {
Expand All @@ -640,15 +656,15 @@ function sendMove(direction) {
_log('sendMove) right');
if (app.wintile.col + app.wintile.width - 1 < colCount - 1) {
// We can move right on this monitor and keep our size
_log('sendMove) right - 1');
_log('sendMove) right - move');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col + 1, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.col + app.wintile.width - 1 === colCount - 1 && app.wintile.width > 1) {
// We are not yet to smallest width, so shrink
_log('sendMove) right - 2');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col + 1, 'height': app.wintile.height, 'width': app.wintile.width - 1});
} else if (monitorToRight !== -1) {
// There is a monitor to the right, so let's go there
_log('sendMove) right - 3');
_log('sendMove) right - monitor');
app.move_to_monitor(monitorToRight);
moveApp(app, {'row': app.wintile.row, 'col': 0, 'height': app.wintile.height, 'width': 1});
} else {
Expand All @@ -660,14 +676,14 @@ function sendMove(direction) {
break;
case 'up':
_log('sendMove) up');
if (app.wintile.row === 0 && app.wintile.height > 1) {
// We are already on the top, shrink
_log('sendMove) up - shrink');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col, 'height': app.wintile.height - 1, 'width': app.wintile.width});
} else if (app.wintile.height === rowCount && app.wintile.width === 2 && app.wintile.col === 1) {
if (app.wintile.height === rowCount && app.wintile.width === 2 && app.wintile.col === 1) {
// We are in 1st maximize, go to full maximize
_log('sendMove) up - 1');
moveApp(app, {'row': 0, 'col': 0, 'height': rowCount, 'width': colCount});
} else if (app.wintile.row === 0 && app.wintile.height > 1) {
// We are already on the top, shrink
_log('sendMove) up - shrink');
moveApp(app, {'row': app.wintile.row, 'col': app.wintile.col, 'height': app.wintile.height - 1, 'width': app.wintile.width});
} else if (app.wintile.height === rowCount) {
// We are full height on half, go to top while keeping width
_log('sendMove) up - 2');
Expand Down Expand Up @@ -696,18 +712,18 @@ function sendMove(direction) {
// We are 1st maximized, restore
_log('sendMove) down - 3');
restoreApp(app);
} else if (app.wintile.height === rowCount) {
// We are full height, go to half height
_log('sendMove) down - 4');
moveApp(app, {'row': 1, 'col': app.wintile.col, 'height': 1, 'width': app.wintile.width});
} else if (app.wintile.row === 0) {
// We are top half, go to full height
_log('sendMove) down - 5');
moveApp(app, {'row': 0, 'col': app.wintile.col, 'height': rowCount, 'width': app.wintile.width});
} else if (app.wintile.width !== colCount) {
} else if (app.wintile.row + app.wintile.height < rowCount){
// We can move down on this monitor and keep our size
_log('sendMove) down - move');
moveApp(app, {'row': app.wintile.row + 1, 'col': app.wintile.col, 'height': app.wintile.height, 'width': app.wintile.width});
} else if (app.wintile.row + app.wintile.height === rowCount && app.wintile.height > 1) {
// We are already at the bottom, shrink
_log('sendMove) down - shrink');
moveApp(app, {'row': app.wintile.row + 1, 'col': app.wintile.col, 'height': app.wintile.height - 1, 'width': app.wintile.width});
} else if (app.wintile.row === rowCount - 1 && app.wintile.width !== colCount) {
// We are not full bottom but are a tile, go full width
_log('sendMove) down - 6');
moveApp(app, {'row': 1, 'col': 0, 'height': 1, 'width': colCount});
moveApp(app, {'row': app.wintile.row, 'col': 0, 'height': 1, 'width': colCount});
} else {
// We are bottom half, minimize
_log('sendMove) down - 7');
Expand Down

0 comments on commit 81ab917

Please sign in to comment.