Skip to content

Instantly share code, notes, and snippets.

@Zren
Last active November 16, 2019 02:17
Show Gist options
  • Select an option

  • Save Zren/3b91803eca99bb4f63856c917a8ea3cb to your computer and use it in GitHub Desktop.

Select an option

Save Zren/3b91803eca99bb4f63856c917a8ea3cb to your computer and use it in GitHub Desktop.
/*
* Copyright 2012 Marco Martin <[email protected]>
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.taskmanager 0.1 as TaskManager
Item {
id: root
property Item containment
readonly property bool verticalPanel: containment && containment.formFactor === PlasmaCore.Types.Vertical
onContainmentChanged: {
if (!containment) {
return;
}
containment.parent = containmentParent;
containment.visible = true;
containment.anchors.fill = containmentParent;
containment.locationChanged.connect(frame.adjustPrefix);
frame.adjustPrefix();
}
//--- active-window-control start
Component.onCompleted: maximizedWindowModel.doCheck()
TaskManager.VirtualDesktopInfo { id: virtualDesktopInfo }
TaskManager.ActivityInfo { id: activityInfo }
TaskManager.TasksModel {
id: tasksModel
sortMode: TaskManager.TasksModel.SortVirtualDesktop
groupMode: TaskManager.TasksModel.GroupDisabled
virtualDesktop: virtualDesktopInfo.currentDesktop
activity: activityInfo.currentActivity
filterByVirtualDesktop: true
filterByScreen: true
filterByActivity: true
onActiveTaskChanged: {
maximizedWindowModel.sourceModel = tasksModel
}
onDataChanged: { maximizedWindowModel.doCheck(); }
onCountChanged: { maximizedWindowModel.doCheck(); }
}
Binding {
target: tasksModel
property: "screenGeometry"
when: containment
value: {
if (!containment) {
return;
}
return containment.screenGeometry
}
}
PlasmaCore.SortFilterModel {
id: maximizedWindowModel
filterRole: 'IsMaximized'
filterRegExp: 'true'
sourceModel: tasksModel
property bool maximizedWindowOnScreen: count > 0
onDataChanged: { maximizedWindowModel.doCheck(); }
onCountChanged: { maximizedWindowModel.doCheck(); }
function doCheck() {
var screenHasMaximized = false
for (var i = 0; i < maximizedWindowModel.count; i++) {
var task = maximizedWindowModel.get(i)
if (task.IsMaximized && !task.IsMinimized) {
screenHasMaximized = true
break
}
}
if (maximizedWindowOnScreen != screenHasMaximized) {
maximizedWindowOnScreen = screenHasMaximized
}
}
}
//--- active-window-control end
PlasmaCore.FrameSvgItem {
id: frame
anchors.fill: parent
imagePath: containment && containment.backgroundHints === PlasmaCore.Types.NoBackground ? "" : "widgets/panel-background"
onRepaintNeeded: adjustPrefix();
enabledBorders: panel.enabledBorders
opacity: maximizedWindowModel.maximizedWindowOnScreen ? 1 : 0
Behavior on opacity { NumberAnimation { duration: 300 } }
function adjustPrefix() {
if (!containment) {
return "";
}
var pre;
switch (containment.location) {
case PlasmaCore.Types.LeftEdge:
pre = "west";
break;
case PlasmaCore.Types.TopEdge:
pre = "north";
break;
case PlasmaCore.Types.RightEdge:
pre = "east";
break;
case PlasmaCore.Types.BottomEdge:
pre = "south";
break;
default:
prefix = "";
}
if (hasElementPrefix(pre)) {
prefix = pre;
} else {
prefix = "";
}
}
}
Binding {
target: panel
property: "length"
when: containment
value: {
if (!containment) {
return;
}
if (verticalPanel) {
return containment.Layout.preferredHeight
} else {
return containment.Layout.preferredWidth
}
}
}
Binding {
target: panel
property: "backgroundHints"
when: containment
value: {
if (!containment) {
return;
}
return containment.backgroundHints;
}
}
Item {
id: containmentParent
anchors {
fill: parent
//Margins are either the size of the margins in the SVG, unless that prevents the panel from being at least half a smallMedium icon + smallSpace) tall at which point we set the margin to whatever allows it to be that...or if it still won't fit, 1.
//the size a margin should be to force a panel to be the required size above
readonly property real spacingAtMinSize: Math.max(1, (verticalPanel ? frame.width : frame.height) - units.iconSizes.smallMedium - units.smallSpacing*2)/2
topMargin: Math.round(Math.min(frame.fixedMargins.top, spacingAtMinSize));
bottomMargin: Math.round(Math.min(frame.fixedMargins.bottom, spacingAtMinSize));
//Base the left/right fixedMargins on height as well, to have a good radial symmetry
leftMargin: Math.round(Math.min(frame.fixedMargins.left, spacingAtMinSize));
rightMargin: Math.round(Math.min(frame.fixedMargins.right, spacingAtMinSize));
}
}
}
@hughwilliams94
Copy link

hughwilliams94 commented Aug 30, 2017

Hey I have used this gist to give the transparent panel effect I was wondering if it would be possible to apply the same changes to the drop down menus from panel plasmoids (e.g. calendar) when windows are not maximised? In my setup I have replaced the translucent/dialogs/background.svgz from breeze-alphablack with the same file from the default theme. This leads to slight mismatch when windows are not maximised as can be seen in the screeshot below. Is there some way to remove that change in colour?

panelvsdrop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment