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

Support cycling through windows #10

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions ww
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,43 @@ fi
SCRIPT_TEMPLATE=$(
cat <<EOF
function kwinactivateclient(clientClass, clientCaption, toggle) {
var clients = workspace.clientList();
var compareToCaption = new RegExp(clientCaption || '', 'i');
var compareToClass = clientClass;
var isCompareToClass = clientClass.length > 0
for (var i=0; i<clients.length; i++) {
var client = clients[i];
var classCompare = (isCompareToClass && client.resourceClass == compareToClass)
var captionCompare = (!isCompareToClass && compareToCaption.exec(client.caption))
if (classCompare || captionCompare) {
if (workspace.activeClient != client) {
workspace.activeClient = client;
} else if (toggle) {
client.minimized = true;
}
break;
}
}
var clients = workspace.clientList();
var compareToCaption = new RegExp(clientCaption || '', 'i');
var compareToClass = clientClass;
var isCompareToClass = clientClass.length > 0;
var matchingClients = [];

for (var i = 0; i < clients.length; i++) {
var client = clients[i];
var classCompare = (isCompareToClass && client.resourceClass == compareToClass)
var captionCompare = (!isCompareToClass && compareToCaption.exec(client.caption))
if (classCompare || captionCompare) {
matchingClients.push(client);
}
}

if (matchingClients.length === 1) {
var client = matchingClients[0];
if (workspace.activeClient !== client) {
workspace.activeClient = client;
} else if (toggle) {
client.minimized = !client.minimized;
}
} else if (matchingClients.length > 1) {
matchingWindows.sort(function (a, b) {
return a.stackingOrder - b.stackingOrder;
});

var currentIndex = matchingClients.length - 2;
for (var i = 0; i < matchingClients.length; i++) {
if (workspace.activeClient === matchingClients[i]) {
currentIndex = i;
break;
}
}
var nextIndex = (currentIndex + 1) % matchingClients.length;
workspace.activeClient = matchingClients[nextIndex];
}
}
kwinactivateclient('CLASS_NAME', 'CAPTION_NAME', TOGGLE);
EOF
Expand Down