Skip to content

Instantly share code, notes, and snippets.

@Zren
Last active February 7, 2024 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zren/8335be3157a8230514d8f03427af7e66 to your computer and use it in GitHub Desktop.
Save Zren/8335be3157a8230514d8f03427af7e66 to your computer and use it in GitHub Desktop.
KWin Scripts
function onClientAdded(client) {
if (client.resourceName == "navigator" && client.resourceClass == "firefox") {
client.activeChanged.connect(function quickTileClientOnFocus(){
workspace.slotWindowQuickTileLeft()
client.activeChanged.disconnect(quickTileClientOnFocus)
})
}
}
workspace.clientAdded.connect(onClientAdded)
function onClientAdded(client) {
client.clientStartUserMovedResized.connect(function startMove(){
if (client.shadeable) {
client.shade = true
}
})
client.clientFinishUserMovedResized.connect(function finishMove(){
if (client.shadeable) {
client.shade = false
}
})
}
// Bind events for new windows
workspace.clientAdded.connect(onClientAdded)
// Bind events for windows already open when script is activated
var clients = workspace.clientList()
for (var i = 0; i < clients.length; i++) {
var client = clients[i]
onClientAdded(client)
}
var ignoredClientList = [
'lutris', // "lutris", "Lutris"
'Steam', // "Steam", "Steam"
];
function isIgnoredClient(client) {
var clients = workspace.clientList();
for (var i = 0; i < ignoredClientList.length; i++) {
var ignoredClient = ignoredClientList[i];
if (client.resourceClass == ignoredClient) {
return true;
}
}
return false;
}
function isBorderlessFullscreen(client) {
var screenArea = workspace.clientArea(KWin.ScreenArea, client);
// Note that we use >= here.
// CS:GO appears to not remove the window decorations... or something.
// The window was 1920x1109 on a 1920x1080 screen.
return client.width >= screenArea.width && client.height >= screenArea.height;
}
function onCurrentDesktopChanged(oldDesktop, movingClient) {
var numClientsOnDesktop = 0;
var fullScreenClient = null;
var clients = workspace.clientList();
for (var i = 0; i < clients.length; i++) {
var client = clients[i];
if (client.desktop == workspace.currentDesktop) {
if (!isIgnoredClient(client)) {
numClientsOnDesktop += 1;
}
if (client.fullScreen || isBorderlessFullscreen(client)) {
fullScreenClient = client;
}
}
}
if (numClientsOnDesktop == 1 && fullScreenClient && fullScreenClient.minimized) {
workspace.activeClient = fullScreenClient; // focus the window
// fullScreenClient.minimized = false;
}
}
workspace.currentDesktopChanged.connect(onCurrentDesktopChanged);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment