-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# kwin-screen-shortcuts | ||
KWin script for consistently ordered screen shortcuts | ||
KWin provides shortcuts to send windows to specific screens ("Window to Screen | ||
N") and to set focus on specific screens when "Separate screen focus" is enabled | ||
("Switch to Screen N"). However, the ordering of the screens is not predictable | ||
or consistent across different screen configurations. | ||
|
||
This KWin script adds shortcuts with the same name and functionality, but with | ||
predictable screen ordering from left to right. So no matter what your screen | ||
configuration is, triggering "Window to Screen 0" will always send to window to | ||
the leftmost screen. | ||
|
||
Ultimately, I think this should be fixed in KWin, but for now a script does the | ||
trick. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Install the package | ||
PKGTOOL="kpackagetool5 --type KWin/Script" | ||
PKGNAME=screen_shortcuts | ||
if $PKGTOOL --show $PKGNAME >/dev/null 2>&1 | ||
then | ||
$PKGTOOL --upgrade src | ||
else | ||
$PKGTOOL --install src | ||
fi | ||
|
||
# In case it was already loaded, disable it here so that it will restart when we | ||
# enable it | ||
sleep 0.5 | ||
kwriteconfig5 --file kwinrc --group Plugins --key $PKGNAME false | ||
sleep 0.5 | ||
qdbus org.kde.KWin /KWin reconfigure | ||
|
||
# Clean any stale shortcuts | ||
sleep 0.5 | ||
qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.cleanUp > /dev/null | ||
|
||
# Enable it | ||
sleep 0.5 | ||
kwriteconfig5 --file kwinrc --group Plugins --key $PKGNAME true | ||
sleep 0.5 | ||
qdbus org.kde.KWin /KWin reconfigure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Given two screen bounds, a < b if a's left edge is left of b's. If left edges | ||
// are equal, a < b if a's top edge is below b's. | ||
function screenSort(a, b) { | ||
var x = a[1].x - b[1].x | ||
if (x != 0) { | ||
return x; | ||
} | ||
var y = a[1].y - b[1].y | ||
if (y != 0) { | ||
return -y; | ||
} | ||
return 0; | ||
} | ||
|
||
// Convert a logical screen number (based on above sorting) into its KWin | ||
// internal index. | ||
function logicalToPhysicalScreen(logicalScreen) { | ||
var screens = []; | ||
for (var i = 0; i < workspace.numScreens; ++i) { | ||
var screen = | ||
workspace.clientArea(KWin.ScreenArea, i, workspace.currentDesktop); | ||
screens.push([ i, screen ]) | ||
} | ||
screens.sort(screenSort) | ||
return screens[logicalScreen][0] | ||
} | ||
|
||
// Return the topmost client window on the given screen. | ||
function topClientOnScreen(physicalScreen) { | ||
const allClients = workspace.clientList(); | ||
var topClient = null; | ||
for (var i = 0; i < allClients.length; ++i) { | ||
var c = allClients[i]; | ||
if (c.specialWindow || c.screen != physicalScreen || | ||
(c.desktop != workspace.currentDesktop && c.desktop != -1)) { | ||
continue; | ||
} | ||
|
||
if (!topClient || c.stackingOrder > topClient.stackingOrder) { | ||
topClient = c; | ||
} | ||
} | ||
return topClient; | ||
} | ||
|
||
function setupShortcuts() { | ||
const scriptName = "screen-shortcuts"; | ||
for (let i = 0; i < 3; ++i) { | ||
let title = `_Switch to Screen ${i}_`; | ||
let text = `Switch to Screen ${i} (${scriptName})`; | ||
let shortcut = "Alt+" + [ "Q", "W", "E" ][i]; | ||
registerShortcut(title, text, shortcut, function() { | ||
var newClient = topClientOnScreen(logicalToPhysicalScreen(i)); | ||
if (newClient !== null) { | ||
workspace.activeClient = newClient; | ||
} | ||
}); | ||
|
||
title = `_Window to Screen ${i}_`; | ||
text = `Window to Screen ${i} (${scriptName})`; | ||
shortcut = "Alt+Shift+" + [ "Q", "W", "E" ][i]; | ||
registerShortcut(title, text, shortcut, function() { | ||
workspace.sendClientToScreen(workspace.activeClient, | ||
logicalToPhysicalScreen(i)); | ||
}); | ||
} | ||
} | ||
|
||
setupShortcuts(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"KPlugin": { | ||
"Name": "Screen Shortcuts", | ||
"Description": "Fix KDE's screen shortcut ordering", | ||
"Icon": "preferences-system-windows", | ||
"Authors": [ | ||
{ | ||
"Email": "jonathan.doman@gmail.com", | ||
"Name": "Jonathan Doman" | ||
} | ||
], | ||
"Id": "screen-shortcuts", | ||
"Version": "1.0", | ||
"License": "Unlicense", | ||
"Website": "https://github.com/jrmrjnck/kwin-screen-shortcuts" | ||
}, | ||
"X-Plasma-API": "javascript", | ||
"X-Plasma-MainScript": "code/main.js", | ||
"KPackageStructure": "KWin/Script" | ||
} |