* The screen saver window is now a kWindowScreenFeel, and thus should always be
in front of all other windows. * Added TODO items where the code is strange or messy. * Big cleanup (renamed files and variables like "fPww" to something more meaningful). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17126 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,11 +2,11 @@ SubDir HAIKU_TOP src bin screen_blanker ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
UsePrivateHeaders screen_saver ;
|
||||
UsePrivateHeaders interface screen_saver ;
|
||||
|
||||
BinCommand screen_blanker :
|
||||
ScreenSaverApp.cpp
|
||||
SSAwindow.cpp
|
||||
ScreenSaverWindow.cpp
|
||||
PasswordWindow.cpp
|
||||
ScreenSaver.cpp
|
||||
: be game libscreensaver.so
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Phipps
|
||||
* Jérôme Duval, [email protected]
|
||||
*/
|
||||
#include "SSAwindow.h"
|
||||
#include <View.h>
|
||||
|
||||
// This is the BDirectWindow subclass that rendering occurs in.
|
||||
// A view is added to it so that BView based screensavers will work.
|
||||
SSAwindow::SSAwindow(BRect frame)
|
||||
: BDirectWindow(frame, "ScreenSaver Window",
|
||||
B_BORDERED_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE) , fSaver(NULL)
|
||||
{
|
||||
frame.OffsetTo(0,0);
|
||||
fView = new BView(frame,"ScreenSaver View",B_FOLLOW_ALL,B_WILL_DRAW);
|
||||
fView->SetViewColor(0,0,0);
|
||||
AddChild(fView);
|
||||
}
|
||||
|
||||
|
||||
SSAwindow::~SSAwindow()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SSAwindow::QuitRequested()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SSAwindow::DirectConnected(direct_buffer_info *info)
|
||||
{
|
||||
if (fSaver)
|
||||
fSaver->DirectConnected(info);
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003, Michael Phipps. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <DirectWindow.h>
|
||||
#include "ScreenSaver.h"
|
||||
|
||||
class SSAwindow : public BDirectWindow {
|
||||
public:
|
||||
SSAwindow(BRect frame);
|
||||
~SSAwindow();
|
||||
virtual bool QuitRequested();
|
||||
virtual void DirectConnected(direct_buffer_info *info);
|
||||
void SetSaver(BScreenSaver *s) {fSaver = s;}
|
||||
|
||||
BView *fView;
|
||||
private:
|
||||
BScreenSaver *fSaver;
|
||||
};
|
||||
|
||||
Executable → Regular
+92
-70
@@ -1,11 +1,15 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Haiku.
|
||||
* Copyright 2003-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Phipps
|
||||
* Jérôme Duval, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#include "ScreenSaverApp.h"
|
||||
|
||||
#include <Debug.h>
|
||||
#include <stdio.h>
|
||||
#include <Screen.h>
|
||||
@@ -18,27 +22,15 @@
|
||||
#include <string.h>
|
||||
#include <Beep.h>
|
||||
|
||||
#include "ScreenSaverApp.h"
|
||||
|
||||
const static int32 RESUME_SAVER = 'RSSV';
|
||||
|
||||
|
||||
// Start the server application. Set pulse to fire once per second.
|
||||
// Run until the application quits.
|
||||
int main(int, char**)
|
||||
{
|
||||
ScreenSaverApp myApplication;
|
||||
myApplication.Run();
|
||||
return(0);
|
||||
}
|
||||
|
||||
// Construct the server app. Doesn't do much, at this point.
|
||||
ScreenSaverApp::ScreenSaverApp()
|
||||
: BApplication(SCREEN_BLANKER_SIG),
|
||||
fWin(NULL),
|
||||
fWindow(NULL),
|
||||
fSaver(NULL),
|
||||
fThrd(NULL),
|
||||
fPww(NULL),
|
||||
fThread(NULL),
|
||||
fPasswordWindow(NULL),
|
||||
fThreadID(-1),
|
||||
fRunner(NULL)
|
||||
{
|
||||
@@ -46,85 +38,98 @@ ScreenSaverApp::ScreenSaverApp()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
void
|
||||
ScreenSaverApp::ReadyToRun()
|
||||
{
|
||||
if (!fPref.LoadSettings()) {
|
||||
if (!fPrefs.LoadSettings()) {
|
||||
fprintf(stderr, "could not load settings\n");
|
||||
exit(1);
|
||||
} else { // If everything works OK, create a BDirectWindow and start the render thread.
|
||||
BScreen theScreen(B_MAIN_SCREEN_ID);
|
||||
fWin = new SSAwindow(theScreen.Frame());
|
||||
fPww = new PasswordWindow();
|
||||
fThrd = new ScreenSaverThread(fWin ,fWin->fView, &fPref);
|
||||
|
||||
fSaver = fThrd->LoadAddOn();
|
||||
if (fSaver) {
|
||||
fWin->SetSaver(fSaver);
|
||||
fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc,"ScreenSaverRenderer", B_LOW_PRIORITY,fThrd);
|
||||
resume_thread(fThreadID);
|
||||
} else {
|
||||
fprintf(stderr, "could not load the screensaver addon\n");
|
||||
}
|
||||
fWin->SetFullScreen(true);
|
||||
fWin->Show();
|
||||
HideCursor();
|
||||
}
|
||||
|
||||
// create a BDirectWindow and start the render thread.
|
||||
BScreen screen(B_MAIN_SCREEN_ID);
|
||||
fWindow = new ScreenSaverWindow(screen.Frame());
|
||||
fPasswordWindow = new PasswordWindow();
|
||||
fThread = new ScreenSaverThread(fWindow, fWindow->ChildAt(0), &fPrefs);
|
||||
|
||||
fSaver = fThread->LoadAddOn();
|
||||
if (fSaver) {
|
||||
fWindow->SetSaver(fSaver);
|
||||
fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc,
|
||||
"ScreenSaverRenderer", B_LOW_PRIORITY, fThread);
|
||||
resume_thread(fThreadID);
|
||||
} else {
|
||||
fprintf(stderr, "could not load the screensaver addon\n");
|
||||
}
|
||||
|
||||
fWindow->SetFullScreen(true);
|
||||
fWindow->Show();
|
||||
HideCursor();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSaverApp::ShowPW()
|
||||
void
|
||||
ScreenSaverApp::_ShowPasswordWindow()
|
||||
{
|
||||
if (fWin->Lock()) {
|
||||
if (fWindow->Lock()) {
|
||||
if (fThreadID > -1)
|
||||
suspend_thread(fThreadID);
|
||||
if (B_OK==fWin->SetFullScreen(false)) {
|
||||
fWin->Sync();
|
||||
|
||||
if (fWindow->SetFullScreen(false) == B_OK) {
|
||||
fWindow->Sync();
|
||||
// TODO: is that needed?
|
||||
ShowCursor();
|
||||
fPww->Show();
|
||||
fPww->Sync();
|
||||
fPasswordWindow->Show();
|
||||
}
|
||||
fWin->Unlock();
|
||||
fWindow->Unlock();
|
||||
}
|
||||
|
||||
_ResumeScreenSaver();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSaverApp::_ResumeScreenSaver()
|
||||
{
|
||||
delete fRunner;
|
||||
fRunner = new BMessageRunner(BMessenger(this), new BMessage(RESUME_SAVER), fPref.BlankTime(), 1);
|
||||
fRunner = new BMessageRunner(BMessenger(this), new BMessage(RESUME_SAVER),
|
||||
fPrefs.BlankTime(), 1);
|
||||
if (fRunner->InitCheck() != B_OK) {
|
||||
fprintf(stderr, "fRunner init failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
void
|
||||
ScreenSaverApp::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what) {
|
||||
switch (message->what) {
|
||||
case UNLOCK_MESSAGE:
|
||||
{
|
||||
if (strcmp(fPref.Password(), crypt(fPww->GetPassword(), fPref.Password())) != 0) {
|
||||
if (strcmp(fPrefs.Password(), crypt(fPasswordWindow->GetPassword(),
|
||||
fPrefs.Password())) != 0) {
|
||||
beep();
|
||||
fPww->SetPassword("");
|
||||
delete fRunner;
|
||||
fRunner = new BMessageRunner(BMessenger(this), new BMessage(RESUME_SAVER), fPref.BlankTime(), 1);
|
||||
if (fRunner->InitCheck()!=B_OK) {
|
||||
fprintf(stderr, "fRunner init failed\n");
|
||||
}
|
||||
fPasswordWindow->SetPassword("");
|
||||
_ResumeScreenSaver();
|
||||
} else {
|
||||
PRINT(("Quitting!\n"));
|
||||
Shutdown();
|
||||
_Shutdown();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case RESUME_SAVER:
|
||||
if (fWin->Lock()) {
|
||||
if (B_OK==fWin->SetFullScreen(true)) {
|
||||
if (fWindow->Lock()) {
|
||||
if (fWindow->SetFullScreen(true) == B_OK) {
|
||||
HideCursor();
|
||||
fPww->Hide();
|
||||
fPasswordWindow->Hide();
|
||||
}
|
||||
if (fThreadID > -1)
|
||||
resume_thread(fThreadID);
|
||||
fWin->Unlock();
|
||||
fWindow->Unlock();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
break;
|
||||
@@ -132,26 +137,43 @@ ScreenSaverApp::MessageReceived(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
bool
|
||||
ScreenSaverApp::QuitRequested()
|
||||
{
|
||||
if (fPref.LockEnable() && (system_time()-fBlankTime > (fPref.PasswordTime()-fPref.BlankTime()))) {
|
||||
ShowPW();
|
||||
if (fPrefs.LockEnable()
|
||||
&& (system_time() - fBlankTime > (fPrefs.PasswordTime() - fPrefs.BlankTime()))) {
|
||||
_ShowPasswordWindow();
|
||||
return false;
|
||||
} else
|
||||
Shutdown();
|
||||
return BApplication::QuitRequested();
|
||||
_Shutdown();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSaverApp::Shutdown(void)
|
||||
void
|
||||
ScreenSaverApp::_Shutdown(void)
|
||||
{
|
||||
if (fWin)
|
||||
fWin->Hide();
|
||||
if (fThreadID > -1)
|
||||
if (fWindow)
|
||||
fWindow->Hide();
|
||||
if (fThreadID > -1) {
|
||||
// TODO: kill_thread()? How about doing this right??
|
||||
kill_thread(fThreadID);
|
||||
if (fThrd)
|
||||
delete fThrd;
|
||||
}
|
||||
if (fThread)
|
||||
delete fThread;
|
||||
|
||||
Quit();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int
|
||||
main(int, char**)
|
||||
{
|
||||
ScreenSaverApp app;
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable → Regular
+31
-26
@@ -1,43 +1,48 @@
|
||||
/*
|
||||
* Copyright 2003-2005, Haiku.
|
||||
* Copyright 2003-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Phipps
|
||||
* Jérôme Duval, jerome.duval@free.fr
|
||||
*/
|
||||
|
||||
#ifndef SCREEN_SAVER_APP_H
|
||||
#define SCREEN_SAVER_APP_H
|
||||
|
||||
#include <Application.h>
|
||||
#include <MessageRunner.h>
|
||||
#include "SSAwindow.h"
|
||||
|
||||
#include "PasswordWindow.h"
|
||||
#include "ScreenSaverPrefs.h"
|
||||
#include "ScreenSaverThread.h"
|
||||
#include "PasswordWindow.h"
|
||||
#include "ScreenSaverWindow.h"
|
||||
|
||||
class ScreenSaverApp : public BApplication
|
||||
{
|
||||
public:
|
||||
ScreenSaverApp();
|
||||
bool LoadAddOn();
|
||||
void ReadyToRun();
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
void ShowPW();
|
||||
private:
|
||||
ScreenSaverPrefs fPref;
|
||||
SSAwindow *fWin;
|
||||
BScreenSaver *fSaver;
|
||||
ScreenSaverThread *fThrd;
|
||||
PasswordWindow *fPww;
|
||||
#include <Application.h>
|
||||
#include <MessageRunner.h>
|
||||
|
||||
thread_id fThreadID;
|
||||
bigtime_t fBlankTime;
|
||||
BMessageRunner *fRunner;
|
||||
|
||||
void Shutdown();
|
||||
class ScreenSaverApp : public BApplication {
|
||||
public:
|
||||
ScreenSaverApp();
|
||||
|
||||
virtual void ReadyToRun();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
private:
|
||||
bool _LoadAddOn();
|
||||
void _ShowPasswordWindow();
|
||||
void _ResumeScreenSaver();
|
||||
void _Shutdown();
|
||||
|
||||
ScreenSaverPrefs fPrefs;
|
||||
ScreenSaverWindow *fWindow;
|
||||
BScreenSaver *fSaver;
|
||||
ScreenSaverThread *fThread;
|
||||
PasswordWindow *fPasswordWindow;
|
||||
|
||||
thread_id fThreadID;
|
||||
bigtime_t fBlankTime;
|
||||
BMessageRunner *fRunner;
|
||||
};
|
||||
|
||||
#endif //SCREEN_SAVER_APP_H
|
||||
#endif // SCREEN_SAVER_APP_H
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2003-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Phipps
|
||||
* Jérôme Duval, jerome.duval@free.fr
|
||||
*/
|
||||
|
||||
|
||||
#include "ScreenSaverWindow.h"
|
||||
|
||||
#include <View.h>
|
||||
#include <WindowPrivate.h>
|
||||
|
||||
|
||||
/*!
|
||||
This is the BDirectWindow subclass that rendering occurs in.
|
||||
A view is added to it so that BView based screensavers will work.
|
||||
*/
|
||||
ScreenSaverWindow::ScreenSaverWindow(BRect frame)
|
||||
: BDirectWindow(frame, "ScreenSaver Window",
|
||||
B_NO_BORDER_WINDOW_LOOK, kWindowScreenFeel, B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
|
||||
fSaver(NULL)
|
||||
{
|
||||
frame.OffsetTo(0, 0);
|
||||
fTopView = new BView(frame, "ScreenSaver View", B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
fTopView->SetViewColor(0, 0, 0);
|
||||
AddChild(fTopView);
|
||||
}
|
||||
|
||||
|
||||
ScreenSaverWindow::~ScreenSaverWindow()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSaverWindow::SetSaver(BScreenSaver *saver)
|
||||
{
|
||||
fSaver = saver;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ScreenSaverWindow::QuitRequested()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSaverWindow::DirectConnected(direct_buffer_info *info)
|
||||
{
|
||||
if (fSaver)
|
||||
fSaver->DirectConnected(info);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2003, Michael Phipps. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef SCREEN_SAVER_WINDOW_H
|
||||
#define SCREEN_SAVER_WINDOW_H
|
||||
|
||||
|
||||
#include "ScreenSaver.h"
|
||||
|
||||
#include <DirectWindow.h>
|
||||
|
||||
|
||||
class ScreenSaverWindow : public BDirectWindow {
|
||||
public:
|
||||
ScreenSaverWindow(BRect frame);
|
||||
~ScreenSaverWindow();
|
||||
|
||||
void SetSaver(BScreenSaver *saver);
|
||||
|
||||
virtual bool QuitRequested();
|
||||
virtual void DirectConnected(direct_buffer_info *info);
|
||||
|
||||
private:
|
||||
BView *fTopView;
|
||||
BScreenSaver *fSaver;
|
||||
};
|
||||
|
||||
#endif // SCREEN_SAVER_WINDOW_H
|
||||
Reference in New Issue
Block a user