1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
//===========================================
// Lumina-DE source code
// Copyright (c) 2015, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "LScreenSaver.h"
#include <QScreen>
#include <QApplication>
LScreenSaver::LScreenSaver() : QWidget(0,Qt::BypassWindowManagerHint | Qt::WindowStaysOnTopHint){
starttimer = new QTimer(this);
starttimer->setSingleShot(true);
locktimer = new QTimer(this);
locktimer->setSingleShot(true);
hidetimer = new QTimer(this);
hidetimer->setSingleShot(true);
settings = new QSettings("LuminaDE","lumina-screensaver",this);
SSRunning = SSLocked = false;
this->setObjectName("LSCREENSAVERBASE");
this->setStyleSheet("LScreenSaver#LSCREENSAVERBASE{ background: black; }");
connect(starttimer, SIGNAL(timeout()), this, SLOT(ShowScreenSaver()) );
}
LScreenSaver::~LScreenSaver(){
}
bool LScreenSaver::isLocked(){
return SSLocked;
}
// ===========
// PUBLIC SLOTS
// ===========
void LScreenSaver::start(){
reloadSettings(); //setup all the initial time frames
}
void LScreenSaver::reloadSettings(){
settings->sync();
starttimer->setInterval( settings->value("timedelaymin",10).toInt() * 60000 );
locktimer->setInterval( settings->value("lockdelaymin",1).toInt() * 60000 );
hidetimer->setInterval( settings->value("hidesecs",15).toInt() * 1000 );
}
void LScreenSaver::newInputEvent(){
//First stop any timers that are running
if(starttimer->isActive()){ starttimer->stop();}
if(locktimer->isActive()){ locktimer->stop(); }
if(hidetimer->isActive()){ hidetimer->stop(); }
if(SSRunning && SSLocked){
//Running and locked
// Hide the running setting, and display the lock screen
HideScreenSaver();
ShowLockScreen();
//Start the timer for restarting the SS and hiding the lockscreen
hidetimer->start();
}else if(SSRunning){
//Only running, not locked
//De-activate the screensaver and start the main timer
HideScreenSaver();
starttimer->start();
}else if(SSLocked){
//Only locked, not running
hidetimer->start(); //restart the time to hide the lock screen
}else{
//Neither running nor locked
if( settings->value("timedelaymin",10).toInt() > 0 ){ starttimer->start(); }
}
}
// ===========
// PRIVATE SLOTS
// ===========
void LScreenSaver::ShowScreenSaver(){
SSRunning = true;
//Start the lock timer if necessary
if(!SSLocked && (settings->value("lockdelaymin",10).toInt()>0) ){ locktimer->start(); }
//Now go through and create/show all the various widgets
QList<QScreen*> SCREENS = QApplication::screens();
QRect bounds;
for(int i=0; i<SCREENS.length(); i++){
bounds = bounds.united(SCREENS[i]->geometry());
if( (BASES.length()-1) < i){
//Nothing for this screen yet - go ahead and create one
BASES << new SSBaseWidget(this, settings);
}
//Setup the geometry of the base to match the screen
BASES[i]->setGeometry(SCREENS[i]->geometry()); //match this screen geometry
BASES[i]->setPlugin(settings->value("screenplugin"+QString::number(i+1), settings->value("defaultscreenplugin","random").toString() ).toString() );
}
//Now remove any extra Base widgets (in case a screen was removed)
for(int i=SCREENS.length(); i<BASES.length(); i++){
delete BASES.takeAt(i); i--;
}
//Now set the overall parent widget geometry and show everything
this->setGeometry(bounds); //overall background widget
this->raise();
this->show();
this->activateWindow();
for(int i=0; i<BASES.length(); i++){
BASES[i]->show();
QTimer::singleShot(100, BASES[i], SLOT(startPainting()) ); //start in 1/2 second
}
}
void LScreenSaver::ShowLockScreen(){
SSLocked = true;
//Start the timer for hiding the lock screen due to inactivity
if(settings->value("hidesecs",15).toInt() > 0 ){ hidetimer->start(); }
}
void LScreenSaver::HideScreenSaver(){
SSRunning = false;
if(!SSLocked){
this->hide();
emit ClosingScreenSaver();
}
for(int i=0; i<BASES.length(); i++){ QTimer::singleShot(0,BASES[i], SLOT(stopPainting())); }
}
void LScreenSaver::HideLockScreen(){
//Leave the Locked flag set (still locked, just not visible)
}
|