-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathssWebKit.cpp
More file actions
189 lines (168 loc) · 6.1 KB
/
ssWebKit.cpp
File metadata and controls
189 lines (168 loc) · 6.1 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* ssWebKit - WebKit based Windows screensaver
* Copyright (C) 20011 Alexey Vishentsev
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*
*/
#include "webkitwidget.h"
#include "screensaver.h"
WId previewWId(QString s);
int main(int argc, char* argv[]) {
QApplication app(argc,argv);
QStringList args = app.arguments();
int screenNo = -1;
enum Mode{
TEST,
Preview,
Config,
Show
};
Mode mode = TEST;
bool noErrors = (args.size() == 1);
WId preview_parent_WId = 0;
for(int i = 1, arglen = args.size(); i < arglen; i++) {
if (args[i].size() < 2) {
//assuming: noErrors = false;
break;
}
switch(args[i][1].toLatin1()) {
case 'c':
case 'C':
mode = Config;
noErrors=true;
break;
case 's':
case 'S':
mode = Show;
noErrors = true;
break;
case 'p':
case 'P':
mode = Preview;
if(args[i].size()>=4 && args[i][2]==':') {
args[i].mid(3);
preview_parent_WId = previewWId(args[i].mid(3));
} else if(args.size()>i) {
preview_parent_WId = previewWId(args[i+1]);
i++;
} else {
preview_parent_WId = 0;
}
if (preview_parent_WId) {
noErrors = true;
}
break;
case '0':
screenNo = 0;
noErrors = QApplication::desktop()->numScreens() > 0;
break;
case '1':
screenNo = 1;
noErrors = QApplication::desktop()->numScreens() > 1;
break;
case '2':
screenNo = 2;
noErrors = QApplication::desktop()->numScreens() > 2;
break;
case '3':
screenNo = 3;
noErrors = QApplication::desktop()->numScreens() > 3;
break;
}
}
if (!noErrors) {
QMessageBox::critical(0,"ScreenSaver Error","Could not parse arguments:\n"
+ args.join("\n")
+"\n Valid args are:\n"
+ " /0 - test mode on screen 0\n"
+ " /1 - test mode on screen 1\n"
+ " /2 - test mode on screen 2\n"
+ " /3 - test mode on screen 3\n"
+ " /S - screensaver mode\n"
+ " /P windowPid| /P:windowPid - preview mode\n"
+ " /C - config mode\n");
return -1;
}
ScreenSaver* ss = 0;
WebkitWidget* w = new WebkitWidget();
w->setAttribute(Qt::WA_DeleteOnClose);
QObject::connect(w,SIGNAL(destroyed()), &app, SLOT(quit()));
switch(mode) {
case TEST:
ss = new ScreenSaver(&app,screenNo);
break;
case Show:
ss = new ScreenSaver(&app,screenNo);
app.setOverrideCursor(QCursor(Qt::BlankCursor));
ss->closeOnMouseAndKeyboardEvents();
break;
case Preview:
//return 0;
//something is really wrong with preview
ss = new ScreenSaver(&app,preview_parent_WId);
break;
case Config:
QSettings settings("QT","ssWebKit");
QString urlString = settings.value("url","qrc://res/web-content/html/slides.html").toString();
urlString = QInputDialog::getText(0,"Configure Webkit Screensaver","Set url", QLineEdit::Normal, urlString);
if (urlString != 0 && urlString.size()>0) {
settings.setValue("url",urlString);
}
return 0;
}
int result = app.exec();
if (ss) {
delete ss;
}
return result;
}
#include <tchar.h>
WId previewWId(QString s) {
if (s == "Scrprev") {
return (WId)FindWindow(L"Scrprev",NULL);
} else {
bool convertedOk;
WId result = (WId)s.toUInt(&convertedOk);
if (convertedOk) {
return result;
} else {
return 0;
}
}
}
/*
HWND CheckForScrprev() {
HWND hwnd=FindWindow(_T("Scrprev"),NULL); // looks for the Scrprev class
if (hwnd==NULL) // try to load it
{
STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si,sizeof(si)); ZeroMemory(&pi,sizeof(pi));
si.cb=sizeof(si);
TCHAR cmd[MAX_PATH]; _tcscpy(cmd,_T("Scrprev")); // unicode CreateProcess requires it writeable
BOOL cres=CreateProcess(NULL,cmd,0,0,FALSE,CREATE_NEW_PROCESS_GROUP | CREATE_DEFAULT_ERROR_MODE,
0,0,&si,&pi);
if (!cres) {Debug(_T("Error creating scrprev process")); return NULL;}
DWORD wres=WaitForInputIdle(pi.hProcess,2000);
if (wres==WAIT_TIMEOUT) {Debug(_T("Scrprev never becomes idle")); return NULL;}
if (wres==0xFFFFFFFF) {Debug(_T("ScrPrev, misc error after ScrPrev execution"));return NULL;}
hwnd=FindWindow(_T("Scrprev"),NULL);
}
if (hwnd==NULL) {Debug(_T("Unable to find Scrprev window")); return NULL;}
::SetForegroundWindow(hwnd);
hwnd=GetWindow(hwnd,GW_CHILD);
if (hwnd==NULL) {Debug(_T("Couldn't find Scrprev child")); return NULL;}
return hwnd;
}
*/