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

Various improvements #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
63 changes: 54 additions & 9 deletions contents/code/main.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,83 @@
/**
*Cheap little script to provide Quake-style quick window toggle supprt
*Cheap little script to provide Quake-style quick window toggle support
**/

const centerHorizontal = true;
const horizontalScale = 0.9;
const verticalScale = 0.9;
const targetScreen = 0; // use -1 to always show on the active screen
const minimizeOnBlur = true;

function toggleMaximized(client) {
var maxBounds = workspace.clientArea(KWin.MaximizeArea, workspace.activeScreen, workspace.currentDesktop);
let screen;
if (targetScreen < 0) {
screen = workspace.activeScreen;
} else {
screen = workspace.screens[targetScreen];
}
var maxBounds = workspace.clientArea(KWin.MaximizeArea, screen, workspace.currentDesktop);

client.desktop = workspace.currentDesktop;
client.geometry = maxBounds;

let screenWidth = maxBounds.width;
maxBounds.height *= verticalScale;
maxBounds.width *= horizontalScale;
if (centerHorizontal) {
maxBounds.x += (screenWidth - maxBounds.width) / 2;
}

client.frameGeometry = maxBounds;

if (client.minimized) {
client.minimized = false;
client.keepAbove = true;
client.noBorder= true;
client.onAllDesktops = true;
workspace.activeWindow = client;
} else {
client.keepAbove = false;
client.minimized = true;
closeWindow(client);
}

client.skipSwitcher = true;
client.skipPager = true;
client.skipTaskbar = true;
}

function closeWindow(client) {
client.keepAbove = false;
client.minimized = true;
}

function shortcutHook() {
var clients = workspace.windowList();
let client = getWindow();

for (var i = 0; i < clients.length; i++) {
var client = clients[i];
if (client) {
toggleMaximized(client);
}
}

function getWindow() {
let clients = workspace.windowList();

for (let i=0; i < clients.length; i++) {
let client = clients[i];

if (client.resourceClass === target) {
toggleMaximized(client);
return client;
}
}
return null;
}

function onBlur(client) {
if (workspace.activeWindow && workspace.activeWindow.resourceClass !== target && minimizeOnBlur) {
let targetClient = getWindow();
if (targetClient) {
closeWindow(targetClient);
}
}
}
workspace.windowActivated.connect(onBlur);

var target = "terminator";

Expand Down