diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 34dedb724a..8f9b5845b8 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -3,9 +3,11 @@ install( DIRECTORY videowall DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/script install( DIRECTORY synchronizeskipswitcher DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/scripts ) install( DIRECTORY desktopchangeosd DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/scripts ) install( DIRECTORY enforcedeco DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/scripts ) +install( DIRECTORY minimizeall DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/scripts ) # service files install( FILES videowall/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-videowall.desktop ) install( FILES synchronizeskipswitcher/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-synchronizeskipswitcher.desktop ) install( FILES desktopchangeosd/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-desktopchangeosd.desktop ) install( FILES enforcedeco/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-enforcedeco.desktop ) +install( FILES minimizeall/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-minimizeall.desktop ) diff --git a/scripts/minimizeall/contents/code/main.js b/scripts/minimizeall/contents/code/main.js new file mode 100644 index 0000000000..30b26b2be8 --- /dev/null +++ b/scripts/minimizeall/contents/code/main.js @@ -0,0 +1,48 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + + Copyright (C) 2014 Thomas Lübking + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ + +function isRelevant(client) { + return client.minimizable && + (client.onAllDesktops || client.desktop === workspace.currentDesktop); + (!client.activities.length || client.activities.indexOf(workspace.currentActivity.toString()) > -1); +} + +var minimizeAllWindows = function() { + var allClients = workspace.clientList(); + var clients = []; + var minimize = true; + for (var i = 0; i < allClients.length; ++i) { + if (isRelevant(allClients[i])) { + clients.push(allClients[i]); + if (allClients[i].minimizedForMinimizeAll === true) { + minimize = false; + } + } + } + for (var i = 0; i < clients.length; ++i) { + if (minimize && clients[i].minimized) + continue; + clients[i].minimized = minimize; + clients[i].minimizedForMinimizeAll = minimize; + } + clients = []; +} + +registerShortcut("MinimizeAll", "MinimizeAll", "Meta+Shift+D", minimizeAllWindows); diff --git a/scripts/minimizeall/metadata.desktop b/scripts/minimizeall/metadata.desktop new file mode 100644 index 0000000000..6a0fe325a1 --- /dev/null +++ b/scripts/minimizeall/metadata.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Name=MinimizeAll +Comment=Adds a shortcut to minimize all windows or unminize all such way minimized windows +Icon=preferences-system-windows-script-test + +Type=Service + +X-Plasma-API=javascript +X-Plasma-MainScript=code/main.js + +X-KDE-PluginInfo-Author=Thomas Lübking +X-KDE-PluginInfo-Email=thomas.luebking@gmail.com +X-KDE-PluginInfo-Name=minimizeall +X-KDE-PluginInfo-Version=1.0 + +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-ServiceTypes=KWin/Script +X-KDE-PluginKeyword=minimizeall