Skip to content

Commit

Permalink
KeepAbove button for the applet (#38)
Browse files Browse the repository at this point in the history
* Added KeepAbove button.
  • Loading branch information
Gribs authored and psifidotos committed May 6, 2019
1 parent 45baac9 commit 6026210
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -5,6 +5,9 @@
# Ignore hidden files
.directory

# Ignore patches
*.patch~

# build directory
build/

Expand Down
Empty file modified install.sh 100644 → 100755
Empty file.
26 changes: 26 additions & 0 deletions libappletdecoration/previewbutton.cpp
Expand Up @@ -153,6 +153,32 @@ void PreviewButtonItem::setIsOnAllDesktops(bool onalldesktops)
emit isOnAllDesktopsChanged();
}

bool PreviewButtonItem::isKeepAbove() const
{
return m_isKeepAbove;
}

void PreviewButtonItem::setIsKeepAbove(bool keepabove)
{
if (m_isKeepAbove == keepabove){
return;
}

m_isKeepAbove = keepabove;

if (m_client && m_button && m_type == KDecoration2::DecorationButtonType::KeepAbove) {
if (m_isKeepAbove){
m_client->setKeepAbove(true);
} else {
m_client->setKeepAbove(false);
}
if (m_decoration) {
m_decoration->init();
}
}
emit isKeepAboveChanged();
}

KDecoration2::DecorationButtonType PreviewButtonItem::type() const
{
return m_type;
Expand Down
6 changes: 6 additions & 0 deletions libappletdecoration/previewbutton.h
Expand Up @@ -50,6 +50,7 @@ class PreviewButtonItem : public QQuickPaintedItem
Q_PROPERTY(bool isActive READ isActive WRITE setIsActive NOTIFY isActiveChanged);
Q_PROPERTY(bool isMaximized READ isMaximized WRITE setIsMaximized NOTIFY isMaximizedChanged);
Q_PROPERTY(bool isOnAllDesktops READ isOnAllDesktops WRITE setIsOnAllDesktops NOTIFY isOnAllDesktopsChanged);
Q_PROPERTY(bool isKeepAbove READ isKeepAbove WRITE setIsKeepAbove NOTIFY isKeepAboveChanged);
Q_PROPERTY(int type READ typeAsInt WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QString scheme READ scheme WRITE setScheme NOTIFY schemeChanged)
Q_PROPERTY(Decoration::Applet::Padding *padding READ padding NOTIFY paddingChanged)
Expand All @@ -75,6 +76,9 @@ class PreviewButtonItem : public QQuickPaintedItem

bool isOnAllDesktops() const;
void setIsOnAllDesktops(bool onalldesktops);

bool isKeepAbove() const;
void setIsKeepAbove(bool keepabove);

KDecoration2::DecorationButtonType type() const;
int typeAsInt() const;
Expand All @@ -91,6 +95,7 @@ class PreviewButtonItem : public QQuickPaintedItem
void isActiveChanged();
void isMaximizedChanged();
void isOnAllDesktopsChanged();
void isKeepAboveChanged();
void paddingChanged();
void schemeChanged();
void settingsChanged();
Expand Down Expand Up @@ -123,6 +128,7 @@ class PreviewButtonItem : public QQuickPaintedItem
bool m_isActive{true};
bool m_isMaximized{false};
bool m_isOnAllDesktops{false};
bool m_isKeepAbove{false};

QString m_scheme;
QRect m_internalGeometry;
Expand Down
5 changes: 2 additions & 3 deletions libappletdecoration/previewclient.cpp
Expand Up @@ -78,7 +78,7 @@ PreviewClient::PreviewClient(KDecoration2::DecoratedClient *c, KDecoration2::Dec
connect(this, &PreviewClient::shadeableChanged, c, &KDecoration2::DecoratedClient::shadeableChanged);
connect(this, &PreviewClient::shadedChanged, c, &KDecoration2::DecoratedClient::shadedChanged);
connect(this, &PreviewClient::providesContextHelpChanged, c, &KDecoration2::DecoratedClient::providesContextHelpChanged);
connect(this, &PreviewClient::onAllDesktopsChanged, c, &KDecoration2::DecoratedClient::onAllDesktopsChanged);
// connect(this, &PreviewClient::onAllDesktopsChanged, c, &KDecoration2::DecoratedClient::onAllDesktopsChanged);
connect(this, &PreviewClient::widthChanged, c, &KDecoration2::DecoratedClient::widthChanged);
connect(this, &PreviewClient::heightChanged, c, &KDecoration2::DecoratedClient::heightChanged);
connect(this, &PreviewClient::iconChanged, c, &KDecoration2::DecoratedClient::iconChanged);
Expand All @@ -101,7 +101,7 @@ PreviewClient::PreviewClient(KDecoration2::DecoratedClient *c, KDecoration2::Dec
}
);
connect(this, &PreviewClient::desktopChanged, this,
[this]() {
[this](int) {
emit onAllDesktopsChanged(isOnAllDesktops());
}
);
Expand Down Expand Up @@ -467,7 +467,6 @@ void PreviewClient::requestToggleShade()
if (m_##variable == variable) { \
return; \
} \
qDebug() << "Setting " << #variable << ":" << variable;\
m_##variable = variable; \
emit variable##Changed(m_##variable); \
}
Expand Down
7 changes: 6 additions & 1 deletion libappletdecoration/qml/AuroraeButton.qml
Expand Up @@ -30,10 +30,14 @@ MouseArea{

property bool isActive: true
property bool isOnAllDesktops: false
property bool isKeepAbove: false
property bool isMaximized: false
readonly property bool isToggledActivated: {
return (isOnAllDesktops && buttonType === AppletDecoration.Types.OnAllDesktops);
return ((isOnAllDesktops && buttonType === AppletDecoration.Types.OnAllDesktops) ||
(isKeepAbove && buttonType === AppletDecoration.Types.KeepAbove)
);
}


property int topPadding: 0
property int bottomPadding: 0
Expand All @@ -52,6 +56,7 @@ MouseArea{
case AppletDecoration.Types.Minimize: return "minimize";
case AppletDecoration.Types.Maximize: return "maximize";
case AppletDecoration.Types.OnAllDesktops: return "alldesktops";
case AppletDecoration.Types.KeepAbove: return "keepabove"
default: return "close";
}
}
Expand Down
3 changes: 2 additions & 1 deletion libappletdecoration/types.h
Expand Up @@ -56,7 +56,8 @@ class Types
ActionClose = 0,
ToggleMinimize,
ToggleMaximize,
TogglePinToAllDesktops
TogglePinToAllDesktops,
ToggleKeepAbove
};
Q_ENUM(Actions)

Expand Down
5 changes: 5 additions & 0 deletions package/contents/code/tools.js
Expand Up @@ -43,6 +43,11 @@ function addButton(preparedArray, buttonType) {
buttonType: AppletDecoration.Types.Custom,
windowOperation: -1
});
} else if (buttonType === AppletDecoration.Types.KeepAbove){
preparedArray.push({
buttonType: AppletDecoration.Types.KeepAbove,
windowOperation: AppletDecoration.Types.ToggleKeepAbove
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion package/contents/config/main.xml
Expand Up @@ -22,7 +22,7 @@
<label>user preferred theme to use with the selected plugin</label>
</entry>
<entry name="buttons" type="String">
<default>5|4|3|10|2</default>
<default>5|4|3|10|2|9</default>
<label>buttons to show in applet</label>
</entry>
<entry name="visibility" type="Enum">
Expand Down
21 changes: 20 additions & 1 deletion package/contents/ui/main.qml
Expand Up @@ -133,9 +133,11 @@ Item {
|| containmentIdentifierTimer.running
readonly property bool isActiveWindowPinned: activeTaskItem && existsWindowActive && activeTaskItem.isOnAllDesktops
readonly property bool isActiveWindowMaximized: activeTaskItem && existsWindowActive && activeTaskItem.isMaximized
readonly property bool isActiveWindowKeepAbove: activeTaskItem && existsWindowActive && activeTaskItem.isKeepAbove

property bool hasDesktopsButton: false
property bool hasMaximizedButton: false
property bool hasKeepAboveButton: false

property Item activeTaskItem
// END Window properties
Expand Down Expand Up @@ -259,6 +261,7 @@ Item {
readonly property bool isMaximized: IsMaximized === true ? true : false
readonly property bool isActive: IsActive === true ? true : false
readonly property bool isOnAllDesktops: IsOnAllVirtualDesktops === true ? true : false
readonly property bool isKeepAbove: IsKeepAbove === true ? true : false

onIsActiveChanged: {
if (isActive) {
Expand Down Expand Up @@ -314,17 +317,21 @@ Item {
function discoverButtons() {
var hasMax = false;
var hasPin = false;
var hasKeepAbove = false;

for (var i=0; i<tasksPreparedArray.length; ++i) {
if (tasksPreparedArray[i].buttonType === AppletDecoration.Types.Maximize) {
hasMax = true;
} else if (tasksPreparedArray[i].buttonType === AppletDecoration.Types.OnAllDesktops) {
hasPin = true;
} else if (tasksPreparedArray[i].buttonType === AppletDecoration.Types.KeepAbove) {
hasKeepAbove = true;
}
}

hasMaximizedButton = hasMax;
hasDesktopsButton = hasPin;
hasKeepAboveButton = hasKeepAbove;
}

function performActiveWindowAction(windowOperation) {
Expand All @@ -336,6 +343,8 @@ Item {
toggleMinimized();
} else if (windowOperation === AppletDecoration.Types.TogglePinToAllDesktops) {
togglePinToAllDesktops();
} else if (windowOperation === AppletDecoration.Types.ToggleKeepAbove){
toggleKeepAbove();
}
}

Expand All @@ -352,7 +361,15 @@ Item {
}

function togglePinToAllDesktops() {
tasksModel.requestVirtualDesktop(tasksModel.activeTask, 0);
if (root.plasma515) {
tasksModel.requestVirtualDesktops(tasksModel.activeTask, 0);
} else {
tasksModel.requestVirtualDesktop(tasksModel.activeTask, 0);
}
}

function toggleKeepAbove(){
tasksModel.requestToggleKeepAbove(tasksModel.activeTask);
}

///START Visual Items
Expand Down Expand Up @@ -405,6 +422,7 @@ Item {
}
isOnAllDesktops: root.isActiveWindowPinned
isMaximized: root.isActiveWindowMaximized
isKeepAbove: root.isActiveWindowKeepAbove

readonly property int firstPadding: {
if (index === 0) {
Expand Down Expand Up @@ -493,6 +511,7 @@ Item {
isActive: true
isOnAllDesktops: root.isActiveWindowPinned
isMaximized: root.isActiveWindowMaximized
isKeepAbove: root.isActiveWindowKeepAbove
buttonType: model.buttonType
auroraeTheme: auroraeThemeEngine

Expand Down

0 comments on commit 6026210

Please sign in to comment.