Updated end session and power button screen

This commit is contained in:
Victor Tran 2016-10-10 18:04:52 +11:00
parent 4a1f58b281
commit ed5fb29eab
10 changed files with 247 additions and 77 deletions

View file

@ -186,6 +186,7 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
this->parentWidget()->setFixedSize(rect.width(), y + lineHeight);
return y + lineHeight - rect.y() + bottom;
}
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
{
QObject *parent = this->parent();

View file

@ -1,6 +1,8 @@
#include "endsessionwait.h"
#include "ui_endsessionwait.h"
extern void sendMessageToRootWindow(const char* message, Window window, long data0 = 0, long data1 = 0, long data2 = 0, long data3 = 0, long data4 = 0);
EndSessionWait::EndSessionWait(shutdownType type, QWidget *parent) :
QDialog(parent),
ui(new Ui::EndSessionWait)
@ -39,15 +41,25 @@ EndSessionWait::~EndSessionWait()
void EndSessionWait::close() {
QPropertyAnimation* anim = new QPropertyAnimation(this, "windowOpacity");
anim->setDuration(250);
anim->setStartValue(1.0);
anim->setStartValue(this->windowOpacity());
anim->setEndValue(0.0);
connect(anim, &QPropertyAnimation::finished, [=]() {
QDialog::close();
anim->deleteLater();
});
anim->start(QAbstractAnimation::DeleteWhenStopped);
anim->start();
}
void EndSessionWait::showFullScreen() {
QPropertyAnimation* anim = new QPropertyAnimation(this, "windowOpacity");
anim->setDuration(250);
anim->setStartValue(this->windowOpacity());
if (this->type == ask) {
anim->setEndValue(1.0);
} else {
anim->setEndValue(0.8);
}
if (!alreadyShowing) {
alreadyShowing = true;
this->setWindowOpacity(0.0);
@ -57,15 +69,53 @@ void EndSessionWait::showFullScreen() {
ui->terminateAppFrame->setVisible(false);
ui->ExitFrameTop->resize(ui->ExitFrameTop->sizeHint());
ui->ExitFrameBottom->resize(ui->ExitFrameBottom->sizeHint());
QPropertyAnimation* anim = new QPropertyAnimation(this, "windowOpacity");
anim->setDuration(250);
anim->setStartValue(0.0);
anim->setEndValue(1.0);
anim->start(QAbstractAnimation::DeleteWhenStopped);
} else {
QParallelAnimationGroup* parallelAnimGroup = new QParallelAnimationGroup;
QSequentialAnimationGroup* animGroup = new QSequentialAnimationGroup;
{
//Animate the "End Session" dialog out
QGraphicsOpacityEffect *fadeEffect = new QGraphicsOpacityEffect(this);
ui->askWhatToDo->setGraphicsEffect(fadeEffect);
QPropertyAnimation *a = new QPropertyAnimation(fadeEffect, "opacity");
a->setDuration(250);
a->setStartValue(1);
a->setEndValue(0);
animGroup->addAnimation(a);
}
{
//Animate the "Ending Session" dialog in
QGraphicsOpacityEffect *fadeEffect = new QGraphicsOpacityEffect(this);
ui->poweringOff->setGraphicsEffect(fadeEffect);
QPropertyAnimation *a = new QPropertyAnimation(fadeEffect, "opacity");
a->setDuration(250);
a->setStartValue(0);
a->setEndValue(1);
animGroup->addAnimation(a);
}
connect(animGroup, &QSequentialAnimationGroup::currentAnimationChanged, [=](QAbstractAnimation* current) {
if (animGroup->indexOfAnimation(current) == 1) {
ui->askWhatToDo->setVisible(false);
ui->poweringOff->setVisible(true);
}
});
parallelAnimGroup->addAnimation(animGroup);
parallelAnimGroup->addAnimation(anim);
connect(parallelAnimGroup, SIGNAL(finished()), parallelAnimGroup, SLOT(deleteLater()));
parallelAnimGroup->start();
while (parallelAnimGroup->state() == QSequentialAnimationGroup::Running) {
QApplication::processEvents();
}
}
if (this->type != dummy && this->type != ask) {
QProcess p;
/*QProcess p;
p.start("wmctrl -lp");
p.waitForStarted();
while (p.state() != 0) {
@ -92,19 +142,111 @@ void EndSessionWait::showFullScreen() {
wlist->append(w);
}
}
}*/
//Prepare a window list
QList<WmWindow> wlist;
//Get the current display
Display* d = QX11Info::display();
//Create list of all top windows and populate it
QList<Window> TopWindows;
Atom WindowListType;
int format;
unsigned long items, bytes;
unsigned char *data;
XGetWindowProperty(d, RootWindow(d, 0), XInternAtom(d, "_NET_CLIENT_LIST", true), 0L, (~0L),
False, AnyPropertyType, &WindowListType, &format, &items, &bytes, &data);
quint64 *windows = (quint64*) data;
for (unsigned long i = 0; i < items; i++) {
TopWindows.append((Window) windows[i]);
}
XFree(data);
for (Window win : TopWindows) {
XWindowAttributes attributes;
int retval = XGetWindowAttributes(d, win, &attributes);
unsigned long items, bytes;
unsigned char *netWmName;
XTextProperty wmName;
int format;
Atom ReturnType;
retval = XGetWindowProperty(d, win, XInternAtom(d, "_NET_WM_VISIBLE_NAME", False), 0, 1024, False,
XInternAtom(d, "UTF8_STRING", False), &ReturnType, &format, &items, &bytes, &netWmName);
if (retval != 0 || netWmName == 0x0) {
retval = XGetWindowProperty(d, win, XInternAtom(d, "_NET_WM_NAME", False), 0, 1024, False,
AnyPropertyType, &ReturnType, &format, &items, &bytes, &netWmName);
if (retval != 0) {
retval = XGetWMName(d, win, &wmName);
if (retval == 1) {
retval = 0;
} else {
retval = 1;
}
}
}
if (retval == 0) {
WmWindow w;
w.setWID(win);
QString title;
if (netWmName) {
title = QString::fromLocal8Bit((char *) netWmName);
XFree(netWmName);
} else if (wmName.value) {
title = QString::fromLatin1((char *) wmName.value);
//XFree(wmName);
}
unsigned long *pidPointer;
unsigned long pitems, pbytes;
int pformat;
Atom pReturnType;
int retval = XGetWindowProperty(d, win, XInternAtom(d, "_NET_WM_PID", False), 0, 1024, False,
XA_CARDINAL, &pReturnType, &pformat, &pitems, &pbytes, (unsigned char**) &pidPointer);
if (retval == 0) {
if (pidPointer != 0) {
unsigned long pid = *pidPointer;
w.setPID(pid);
}
}
XFree(pidPointer);
//Set the title of the window
w.setTitle(title);
//Make sure PID is not current application PID
if (w.PID() != QCoreApplication::applicationPid()) {
wlist.append(w);
}
}
}
for (WmWindow window : wlist) {
for (WmWindow* window : *wlist) {
p.start("wmctrl -c " + window->title());
if (QApplication::arguments().contains("--debug")) {
if (!window.title().toLower().contains("theterminal") && !window.title().toLower().contains("qt creator")) {
sendMessageToRootWindow("_NET_CLOSE_WINDOW", window.WID());
}
} else {
sendMessageToRootWindow("_NET_CLOSE_WINDOW", window.WID());
}
/*p.start("wmctrl -c " + window.title());
p.waitForStarted();
while (p.state() != 0) {
QApplication::processEvents();
}
}*/
}
bool appsOpen = true;
QProcess p;
while (appsOpen) {
appsOpen = false;
p.start("wmctrl -lp");
@ -164,8 +306,6 @@ void EndSessionWait::on_pushButton_clicked()
}
void EndSessionWait::performEndSession() {
QFile(QDir::home().absolutePath() + "/.theshell.lck").remove();
QSettings settings;
QString logoutSoundPath = settings.value("sounds/logout", "").toString();
if (logoutSoundPath == "") {
@ -185,13 +325,22 @@ void EndSessionWait::performEndSession() {
sound->setMedia(QUrl::fromLocalFile(logoutSoundPath));
sound->play();
QParallelAnimationGroup* animGroup = new QParallelAnimationGroup();
QGraphicsOpacityEffect *fadeEffect = new QGraphicsOpacityEffect(this);
ui->poweringOff->setGraphicsEffect(fadeEffect);
QPropertyAnimation *a = new QPropertyAnimation(fadeEffect, "opacity");
a->setDuration(500);
a->setStartValue(1);
a->setEndValue(0);
a->start();
animGroup->addAnimation(a);
QPropertyAnimation* opacity = new QPropertyAnimation(this, "windowOpacity");
opacity->setDuration(250);
opacity->setStartValue(this->windowOpacity());
opacity->setEndValue(1.0);
animGroup->addAnimation(opacity);
animGroup->start();
connect(a, &QPropertyAnimation::finished, [=]() {
ui->poweringOff->setVisible(false);
@ -204,12 +353,14 @@ void EndSessionWait::EndSessionNow() {
arguments.append(true);
switch (type) {
case powerOff:
//Power off the PC
message = QDBusMessage::createMethodCall("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PowerOff");
message.setArguments(arguments);
QDBusConnection::systemBus().send(message);
break;
case reboot:
//Reboot the PC
message = QDBusMessage::createMethodCall("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Reboot");
message.setArguments(arguments);
QDBusConnection::systemBus().send(message);
@ -231,8 +382,8 @@ void EndSessionWait::on_CancelAsk_clicked()
void EndSessionWait::on_PowerOff_clicked()
{
ui->askWhatToDo->setVisible(false);
ui->poweringOff->setVisible(true);
//ui->askWhatToDo->setVisible(false);
//ui->poweringOff->setVisible(true);
this->type = powerOff;
ui->label->setText("Power Off");
this->showFullScreen();
@ -240,8 +391,8 @@ void EndSessionWait::on_PowerOff_clicked()
void EndSessionWait::on_Reboot_clicked()
{
ui->askWhatToDo->setVisible(false);
ui->poweringOff->setVisible(true);
//ui->askWhatToDo->setVisible(false);
//ui->poweringOff->setVisible(true);
this->type = reboot;
ui->label->setText("Reboot");
this->showFullScreen();
@ -249,8 +400,8 @@ void EndSessionWait::on_Reboot_clicked()
void EndSessionWait::on_LogOut_clicked()
{
ui->askWhatToDo->setVisible(false);
ui->poweringOff->setVisible(true);
//ui->askWhatToDo->setVisible(false);
//ui->poweringOff->setVisible(true);
this->type = logout;
ui->label->setText("Log Out");
this->showFullScreen();
@ -289,7 +440,7 @@ void EndSessionWait::on_terminateApp_clicked()
topAnim->setEasingCurve(QEasingCurve::OutCubic);
topAnim->setDuration(250);
connect(topAnim, &QVariantAnimation::valueChanged, [=](QVariant value) {
ui->ExitFrameTop->resize(width, value.toInt());
ui->ExitFrameTop->setFixedHeight(value.toInt());
});
QVariantAnimation* bottomAnim = new QVariantAnimation();
@ -298,16 +449,16 @@ void EndSessionWait::on_terminateApp_clicked()
bottomAnim->setEasingCurve(QEasingCurve::OutCubic);
bottomAnim->setDuration(250);
connect(bottomAnim, &QVariantAnimation::valueChanged, [=](QVariant value) {
ui->ExitFrameBottom->resize(width, value.toInt());
ui->ExitFrameBottom->setFixedHeight(value.toInt());
});
QVariantAnimation* midAnim = new QVariantAnimation();
midAnim->setStartValue(ui->terminateAppFrame->height());
midAnim->setEndValue(ui->terminateAppFrame->sizeHint().height());
midAnim->setEasingCurve(QEasingCurve::OutCubic);
midAnim->setDuration(500);
midAnim->setDuration(250);
connect(midAnim, &QVariantAnimation::valueChanged, [=](QVariant value) {
ui->terminateAppFrame->resize(width, value.toInt());
ui->terminateAppFrame->setFixedHeight(value.toInt());
});
group->addAnimation(midAnim);
@ -317,9 +468,9 @@ void EndSessionWait::on_terminateApp_clicked()
group->start();
connect(group, &QParallelAnimationGroup::finished, [=]() {
ui->terminateAppFrame->resize(width, ui->terminateAppFrame->sizeHint().height());
ui->ExitFrameTop->resize(width, 0);
ui->ExitFrameBottom->resize(width, 0);
ui->terminateAppFrame->setFixedHeight(ui->terminateAppFrame->sizeHint().height());
ui->ExitFrameTop->setFixedHeight(0);
ui->ExitFrameBottom->setFixedHeight(0);
});
ui->terminateAppFrame->setVisible(true);
@ -488,7 +639,7 @@ void EndSessionWait::on_exitTerminate_clicked()
topAnim->setDuration(500);
topAnim->setKeyValueAt(0.5, 0);
connect(topAnim, &QVariantAnimation::valueChanged, [=](QVariant value) {
ui->ExitFrameTop->resize(width, value.toInt());
ui->ExitFrameTop->setFixedHeight(value.toInt());
});
QVariantAnimation* bottomAnim = new QVariantAnimation();
@ -498,7 +649,7 @@ void EndSessionWait::on_exitTerminate_clicked()
bottomAnim->setDuration(500);
bottomAnim->setKeyValueAt(0.5, 0);
connect(bottomAnim, &QVariantAnimation::valueChanged, [=](QVariant value) {
ui->ExitFrameBottom->resize(width, value.toInt());
ui->ExitFrameBottom->setFixedHeight(value.toInt());
});
QVariantAnimation* midAnim = new QVariantAnimation();
@ -507,7 +658,7 @@ void EndSessionWait::on_exitTerminate_clicked()
midAnim->setEasingCurve(QEasingCurve::OutCubic);
midAnim->setDuration(500);
connect(midAnim, &QVariantAnimation::valueChanged, [=](QVariant value) {
ui->terminateAppFrame->resize(width, value.toInt());
ui->terminateAppFrame->setFixedHeight(value.toInt());
});
group->addAnimation(midAnim);
@ -517,9 +668,9 @@ void EndSessionWait::on_exitTerminate_clicked()
group->start();
connect(group, &QParallelAnimationGroup::finished, [=]() {
ui->terminateAppFrame->resize(ui->ExitFrameTop->width(), 0);
ui->ExitFrameTop->resize(ui->ExitFrameTop->width(), ui->ExitFrameTop->sizeHint().height());
ui->ExitFrameBottom->resize(ui->ExitFrameBottom->width(), ui->ExitFrameTop->sizeHint().height());
ui->terminateAppFrame->setFixedHeight(0);
ui->ExitFrameTop->setFixedHeight(ui->ExitFrameTop->sizeHint().height());
ui->ExitFrameBottom->setFixedHeight(ui->ExitFrameBottom->sizeHint().height());
ui->terminateAppFrame->setVisible(false);
});
}

View file

@ -32,6 +32,7 @@
#include <QPropertyAnimation>
#include <QVariantAnimation>
#include <QParallelAnimationGroup>
#include <QSequentialAnimationGroup>
#include <QX11Info>
#include <QThread>
#include "window.h"

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<height>801</height>
<width>783</width>
<height>983</height>
</rect>
</property>
<property name="palette">
@ -516,7 +516,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Closing all programs and getting ready to exit. Please wait...</string>
<string>Closing all open applications. Please wait...</string>
</property>
</widget>
</item>
@ -621,9 +621,6 @@
<property name="text">
<string>End Session</string>
</property>
<property name="buddy">
<cstring></cstring>
</property>
</widget>
</item>
<item>
@ -631,9 +628,6 @@
<property name="text">
<string>You're about to power off your PC. Are you sure?</string>
</property>
<property name="buddy">
<cstring></cstring>
</property>
</widget>
</item>
<item>
@ -641,7 +635,8 @@
<item row="0" column="1">
<widget class="QPushButton" name="Reboot">
<property name="styleSheet">
<string notr="true">background-color: #A00;</string>
<string notr="true">background-color: #A00;
color: #FFF;</string>
</property>
<property name="text">
<string>Reboot</string>
@ -666,7 +661,8 @@
<item row="0" column="0">
<widget class="QPushButton" name="PowerOff">
<property name="styleSheet">
<string notr="true">background-color: #A00;</string>
<string notr="true">background-color: #A00;
color: #FFF;</string>
</property>
<property name="text">
<string>Power Off</string>
@ -702,7 +698,8 @@
<item row="1" column="2">
<widget class="QPushButton" name="terminateApp">
<property name="styleSheet">
<string notr="true">background-color: #A00;</string>
<string notr="true">background-color: #A00;
color: #FFF;</string>
</property>
<property name="text">
<string>Terminate App</string>
@ -755,9 +752,6 @@
<property name="text">
<string>Terminate App</string>
</property>
<property name="buddy">
<cstring></cstring>
</property>
</widget>
</item>
<item>
@ -765,9 +759,6 @@
<property name="text">
<string>Select the app that you want to terminate</string>
</property>
<property name="buddy">
<cstring></cstring>
</property>
</widget>
</item>
<item>

View file

@ -269,3 +269,22 @@ QString calculateSize(quint64 size) {
return ret;
}
void sendMessageToRootWindow(const char* message, Window window, long data0, long data1, long data2, long data3, long data4) {
XEvent event;
event.xclient.type = ClientMessage;
event.xclient.serial = 0;
event.xclient.send_event = True;
event.xclient.message_type = XInternAtom(QX11Info::display(), message, False);
event.xclient.window = window;
event.xclient.format = 32;
event.xclient.data.l[0] = data0;
event.xclient.data.l[1] = data1;
event.xclient.data.l[2] = data2;
event.xclient.data.l[3] = data3;
event.xclient.data.l[4] = data4;
XSendEvent(QX11Info::display(), DefaultRootWindow(QX11Info::display()), False, SubstructureRedirectMask | SubstructureNotifyMask, &event);
}

View file

@ -3,6 +3,7 @@
extern void playSound(QUrl, bool = false);
extern QIcon getIconFromTheme(QString name, QColor textColor);
extern void sendMessageToRootWindow(const char* message, Window window, long data0 = 0, long data1 = 0, long data2 = 0, long data3 = 0, long data4 = 0);
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@ -372,7 +373,16 @@ void MainWindow::doUpdate() {
w.setTitle(title);
w.setWID(win);
if (w.PID() != QCoreApplication::applicationPid()) {
bool addToList = true;
if (w.PID() == QApplication::applicationPid()) {
addToList = false;
if (w.title() == "Ending Session") {
hideTop = 0;
lockHide = false;
}
}
if (addToList) {
bool skipTaskbar = false;
{
@ -509,7 +519,7 @@ void MainWindow::doUpdate() {
if (ui->desktopsFrame->isVisible()) {
adjustLeft = adjustLeft + ui->openMenu->width();
}
ui->windowList->layout()->setGeometry(ui->horizontalLayout_4->geometry().adjusted(adjustLeft, 0, 0, 0));
//ui->windowList->layout()->setGeometry(ui->horizontalLayout_4->geometry().adjusted(adjustLeft, 0, 0, 0));
});
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
anim->start();
@ -540,7 +550,7 @@ void MainWindow::doUpdate() {
if (ui->desktopsFrame->isVisible()) {
adjustLeft = adjustLeft + ui->openMenu->width();
}
ui->windowList->layout()->setGeometry(ui->horizontalLayout_4->geometry().adjusted(adjustLeft, 0, 0, 0));
//ui->windowList->layout()->setGeometry(ui->horizontalLayout_4->geometry().adjusted(adjustLeft, 0, 0, 0));
hiding = false;
});
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
@ -686,24 +696,6 @@ void MainWindow::ActivateWindow() {
XMapRaised(QX11Info::display(), winId);
}
void MainWindow::sendMessageToRootWindow(const char* message, Window window, long data0, long data1, long data2, long data3, long data4) {
XEvent event;
event.xclient.type = ClientMessage;
event.xclient.serial = 0;
event.xclient.send_event = True;
event.xclient.message_type = XInternAtom(QX11Info::display(), message, False);
event.xclient.window = window;
event.xclient.format = 32;
event.xclient.data.l[0] = data0;
event.xclient.data.l[1] = data1;
event.xclient.data.l[2] = data2;
event.xclient.data.l[3] = data3;
event.xclient.data.l[4] = data4;
XSendEvent(QX11Info::display(), DefaultRootWindow(QX11Info::display()), False, SubstructureRedirectMask | SubstructureNotifyMask, &event);
}
void MainWindow::setGeometry(int x, int y, int w, int h) { //Use wmctrl command because KWin has a problem with moving windows offscreen.
QMainWindow::setGeometry(x, y, w, h);
QProcess::execute("wmctrl -r " + this->windowTitle() + " -e 0," +

View file

@ -176,9 +176,6 @@ private:
void paintEvent(QPaintEvent *event);
InfoPaneDropdown *infoPane;
void sendMessageToRootWindow(const char* message, Window window, long data0 = 0, long data1 = 0,
long data2 = 0, long data3 = 0, long data4 = 0);
};
#endif // MAINWINDOW_H

View file

@ -31,6 +31,7 @@ Menu::Menu(QWidget *parent) :
if (!QApplication::arguments().contains("--debug")) {
ui->exitButton->setVisible(false);
ui->fakeEndButton->setVisible(false);
}
this->setMouseTracking(true);
@ -1428,3 +1429,8 @@ void Menu::on_exitButton_clicked()
void Menu::reject() {
this->close();
}
void Menu::on_fakeEndButton_clicked()
{
EndSession(EndSessionWait::dummy);
}

2
menu.h
View file

@ -167,6 +167,8 @@ private slots:
void on_exitButton_clicked();
void on_fakeEndButton_clicked();
private:
Ui::Menu *ui;

16
menu.ui
View file

@ -300,17 +300,26 @@
<string>Exit theShell</string>
</property>
<property name="icon">
<iconset theme="application-exit"/>
<iconset theme="application-exit">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="description">
<string>Exits theShell, leaving everything else open</string>
</property>
</widget>
</item>
<item>
<widget class="QCommandLinkButton" name="fakeEndButton">
<property name="text">
<string>Fake Exit</string>
</property>
</widget>
</item>
<item>
<widget class="QCommandLinkButton" name="commandLinkButton">
<property name="styleSheet">
<string notr="true">background-color: #A00;</string>
<string notr="true">background-color: #A00;
color: #FFF;</string>
</property>
<property name="text">
<string>Power Off</string>
@ -333,7 +342,8 @@
<item>
<widget class="QCommandLinkButton" name="commandLinkButton_2">
<property name="styleSheet">
<string notr="true">background-color: #A00;</string>
<string notr="true">background-color: #A00;
color: #FFF;</string>
</property>
<property name="text">
<string>Reboot</string>