File indexing completed on 2024-11-10 04:57:03
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2014 Thomas Lübking <thomas.luebking@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 var registeredBorders = []; 0011 0012 function isRelevant(client) { 0013 return client.minimizable && 0014 (!client.desktops.length || client.desktops.indexOf(workspace.currentDesktop) != -1); 0015 (!client.activities.length || client.activities.indexOf(workspace.currentActivity.toString()) > -1); 0016 } 0017 0018 function minimizeAllWindows() { 0019 var allClients = workspace.windowList(); 0020 var relevantClients = []; 0021 var minimize = false; 0022 0023 for (var i = 0; i < allClients.length; ++i) { 0024 if (!isRelevant(allClients[i])) { 0025 continue; 0026 } 0027 if (!allClients[i].minimized) { 0028 minimize = true; 0029 } 0030 relevantClients.push(allClients[i]); 0031 } 0032 0033 // Try to preserve last active window by sorting windows. 0034 relevantClients.sort((a, b) => { 0035 if (a.active) { 0036 return 1; 0037 } else if (b.active) { 0038 return -1; 0039 } 0040 return a.stackingOrder - b.stackingOrder; 0041 }); 0042 0043 for (var i = 0; i < relevantClients.length; ++i) { 0044 var wasMinimizedByScript = relevantClients[i].minimizedByScript; 0045 delete relevantClients[i].minimizedByScript; 0046 0047 if (minimize) { 0048 if (relevantClients[i].minimized) { 0049 continue; 0050 } 0051 relevantClients[i].minimized = true; 0052 relevantClients[i].minimizedByScript = true; 0053 } else { 0054 if (!wasMinimizedByScript) { 0055 continue; 0056 } 0057 relevantClients[i].minimized = false; 0058 } 0059 } 0060 } 0061 0062 function init() { 0063 for (var i in registeredBorders) { 0064 unregisterScreenEdge(registeredBorders[i]); 0065 } 0066 0067 registeredBorders = []; 0068 0069 var borders = readConfig("BorderActivate", "").toString().split(","); 0070 for (var i in borders) { 0071 var border = parseInt(borders[i]); 0072 if (isFinite(border)) { 0073 registeredBorders.push(border); 0074 registerScreenEdge(border, minimizeAllWindows); 0075 } 0076 } 0077 } 0078 0079 options.configChanged.connect(init); 0080 0081 registerShortcut("MinimizeAll", "MinimizeAll", "Meta+Shift+D", minimizeAllWindows); 0082 init();