Skip to content

Commit

Permalink
Implement command to center current window in screen
Browse files Browse the repository at this point in the history
Updated suggested configuration accordingly
  • Loading branch information
lucmos committed Dec 1, 2018
1 parent dbb3fe8 commit 431a9b4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ My suggestion is to use the following configuration:
| ------------------------------------ | ---------------------------------------------------- |
| <kbd>Meta</kbd> + <kbd>Numpad0</kbd> | <kbd>UltrawideWindows: Maximize Window</kbd> |
| <kbd>Alt</kbd> + <kbd>Numpad0</kbd> | <kbd>UltrawideWindows: Maximize Window (copy)</kbd> |
| <kbd>Alt</kbd> + <kbd>Numpad5</kbd> | <kbd>UltrawideWindows: Maximize Window (copy)</kbd> |
| <kbd>Ctrl</kbd> + <kbd>Numpad0</kbd> | <kbd>UltrawideWindows: Maximize Window (copy2)</kbd> |
| <kbd>Ctrl</kbd> + <kbd>Numpad5</kbd> | <kbd>UltrawideWindows: Maximize Window (copy2)</kbd> |
| <kbd>Alt</kbd> + <kbd>Numpad5</kbd> | <kbd>UltrawideWindows: Center Window</kbd> |
| <kbd>Ctrl</kbd> + <kbd>Numpad5</kbd> | <kbd>UltrawideWindows: Center Window (copy)</kbd> |



Expand Down
41 changes: 36 additions & 5 deletions contents/code/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function getPosition(workspace, client, numberXslots, numberYslots, x, y, xSlotToFill, ySlotToFill) {
function newSlotPosition(workspace, client, numberXslots, numberYslots, x, y, xSlotToFill, ySlotToFill) {
var maxArea = workspace.clientArea(KWin.MaximizeArea, client);
var width;
if (x == numberXslots) {
Expand All @@ -22,7 +22,7 @@ function getPosition(workspace, client, numberXslots, numberYslots, x, y, xSlotT
function move(workspace, numberXslots, numberYslots, x, y, xSlotToFill, ySlotToFill) {
var client = workspace.activeClient;
if (client.moveable) {
arr = getPosition(workspace, client, numberXslots, numberYslots, x, y, xSlotToFill, ySlotToFill);
arr = newSlotPosition(workspace, client, numberXslots, numberYslots, x, y, xSlotToFill, ySlotToFill);
var newX = arr[0],
newY = arr[1],
w = arr[2],
Expand All @@ -36,6 +36,22 @@ function move(workspace, numberXslots, numberYslots, x, y, xSlotToFill, ySlotToF
}
}

function center(workspace) {
var client = workspace.activeClient;
if (client.moveable) {
var maxArea = workspace.clientArea(KWin.MaximizeArea, client);
var newX = maxArea.x + ((maxArea.width - client.width) / 2);
var newY = maxArea.y + ((maxArea.height - client.height) / 2);
client.geometry = {
x: newX,
y: newY,
width: client.width,
height: client.height
};
}
}


// function isInPosition(workspace, numberXslots, numberYslots, x, y, xSlotToFill, ySlotToFill) {
// var client = workspace.activeClient;
// if (client.moveable) {
Expand Down Expand Up @@ -125,14 +141,22 @@ registerShortcut("MoveWindowToUpLeft23", "UltrawideWindows: Move Window to fit u
move(workspace, 3, 2, 0, 0, 2, 1)
});

registerShortcut("MoveWindowToFitDownLeft23", "UltrawideWindows: Move Window to fit down-left 2/3 width ", "alt+Num+1", function () {
move(workspace, 3, 2, 0, 1, 2, 1)
registerShortcut("MoveWindowToUpCenter23", "UltrawideWindows: Move Window to up-width 2/3", "alt+Num+8", function () {
move(workspace, 1, 2, 0, 0, 1, 1)
});

registerShortcut("MoveWindowToUpRight23", "UltrawideWindows: Move Window to fit up-right 2/3 width ", "alt+Num+9", function () {
move(workspace, 3, 2, 1, 0, 2, 1)
});

registerShortcut("MoveWindowToFitDownLeft23", "UltrawideWindows: Move Window to fit down-left 2/3 width ", "alt+Num+1", function () {
move(workspace, 3, 2, 0, 1, 2, 1)
});

registerShortcut("MoveWindowToDownCenter23", "UltrawideWindows: Move Window to down-width 2/3", "alt+Num+2", function () {
move(workspace, 1, 2, 0, 1, 1, 1)
});

registerShortcut("MoveWindowToFitDownRight23", "UltrawideWindows: Move Window to fit down-right 2/3 width ", "alt+Num+3", function () {
move(workspace, 3, 2, 1, 1, 2, 1)
});
Expand All @@ -146,7 +170,7 @@ registerShortcut("MoveWindowToRightHeight23", "UltrawideWindows: Move Window to
});

// General
registerShortcut("MoveWindowToMaximize", "UltrawideWindows: Maximize Window", "alt+Num+5", function () {
registerShortcut("MoveWindowToMaximize", "UltrawideWindows: Maximize Window", "Meta+Num+0", function () {
move(workspace, 1, 1, 0, 0, 1, 1)
});

Expand All @@ -158,3 +182,10 @@ registerShortcut("MoveWindowToMaximize2", "UltrawideWindows: Maximize Window (co
move(workspace, 1, 1, 0, 0, 1, 1)
});

registerShortcut("MoveWindowToCenter", "UltrawideWindows: Center Window", "ctrl+Num+5", function () {
center(workspace)
});

registerShortcut("MoveWindowToCenter1", "UltrawideWindows: Center Window (copy)", "alt+Num+5", function () {
center(workspace)
});
2 changes: 1 addition & 1 deletion metadata.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ X-Plasma-MainScript=code/main.js
X-KDE-PluginInfo-Author=Luca Moschella
X-KDE-PluginInfo-Email[email protected]
X-KDE-PluginInfo-Name=ultrawidewindows
X-KDE-PluginInfo-Version=2.0
X-KDE-PluginInfo-Version=3.0
X-KDE-PluginInfo-EnabledByDefault=true

X-KDE-PluginInfo-Depends=
Expand Down
Binary file modified movewindowtocenter.kwinscript
Binary file not shown.

0 comments on commit 431a9b4

Please sign in to comment.