* Big time cleanup of the screen saver stuff, not yet finished yet, though.

Renamed lots of things, like ScreenSaverThread to ScreenSaverRunner,
  refactored code, etc. Much cleaner interfaces and code.
* Fixed a couple of bugs and in the add-on handling, especially some settings
  related bugs (ie. testing a screen saver will now use its latest settings,
  etc.).
* Correctly implemented DPMS support in ScreenSaverPrefs and the ScreenSaver
  preferences application - screen_blanker still ignores them, though.
* It's not yet font sensitive either.
* Changed the input_server add-on to not switch to the screen blanker immediately
  when it's in the "blank corner" - doesn't seem to work yet, though (only tested
  under Qemu).
* Correctly implemented the "preview" function (before, a screen saver would
  never know it rendered a preview).
* Evaluates the return value of BScreenSaver::StartSaver().
* The screen saver thread is no longer killed without notice - it's now
  always shut down properly.
* Made the code more robust against failure.
* Introduced some new bugs as well (the screen saver list view doesn't jump to
  the selection anymore, for some reason), those will be fixed later (as the
  remaining issues).
* Probably some more I forgot about.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17731 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-06-06 08:16:46 +00:00
parent ef1974cb9d
commit 7cae4a1ee0
23 changed files with 1478 additions and 1211 deletions
+50 -57
View File
@@ -1,82 +1,75 @@
#if ! defined _SCREENSAVER_H
/*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SCREENSAVER_H
#define _SCREENSAVER_H
#include <BeBuild.h>
#include <DirectWindow.h> // for direct_buffer_info
#include <DirectWindow.h>
#include <image.h>
#include <Message.h>
class BView;
class BScreenSaver
{
public:
BScreenSaver(BMessage *archive, image_id);
virtual ~BScreenSaver();
// Return an error if something goes wrong or if you don't
// like the running environment (lack of 3D acceleration,
// lack of sound, ...).
virtual status_t InitCheck();
class BScreenSaver {
public:
BScreenSaver(BMessage* archive, image_id thisImage);
virtual ~BScreenSaver();
// Animation start and stop. The view is not yet visible when
// StartSaver is called.
virtual status_t StartSaver(BView *view, bool preview);
virtual void StopSaver();
virtual status_t InitCheck();
// This hook is called periodically, you should
// override it to do the drawing. Notice that you
// should clear the screen when frame == 0 if you
// don't want to paint over the desktop.
virtual void Draw(BView *view, int32 frame);
virtual status_t StartSaver(BView* view, bool preview);
virtual void StopSaver();
// These hooks are for direct screen access, the first is
// called every time the settings change, the second is
// the equivalent of Draw to be called to access the screen
// directly. Draw and DirectDraw can be used at the same time.
virtual void DirectConnected(direct_buffer_info *info);
virtual void DirectDraw(int32 frame);
virtual void Draw(BView* view, int32 frame);
// configuration dialog methods
virtual void StartConfig(BView *configView);
virtual void StopConfig();
// direct screen access
virtual void DirectConnected(direct_buffer_info* info);
virtual void DirectDraw(int32 frame);
// Module should fill this in with metadata
// example: randomizable = true
virtual void SupplyInfo(BMessage *info) const;
// configuration dialog methods
virtual void StartConfig(BView* configView);
virtual void StopConfig();
// Send all the metadata info to the module
virtual void ModulesChanged(const BMessage *info);
// Module should fill this in with metadata
// example: randomizable = true
virtual void SupplyInfo(BMessage* info) const;
// BArchivable like parameter saver method
virtual status_t SaveState(BMessage *into) const;
// Send all the metadata info to the module
virtual void ModulesChanged(const BMessage* info);
// These methods can be used to control drawing frequency.
void SetTickSize(bigtime_t ts);
bigtime_t TickSize() const;
// BArchivable like parameter saver method
virtual status_t SaveState(BMessage* into) const;
// These methods can be used to control animation loop cycles
void SetLoop(int32 on_count, int32 off_count);
int32 LoopOnCount() const;
int32 LoopOffCount() const;
// These methods can be used to control drawing frequency.
void SetTickSize(bigtime_t tickSize);
bigtime_t TickSize() const;
private:
virtual void _ReservedScreenSaver1();
virtual void _ReservedScreenSaver2();
virtual void _ReservedScreenSaver3();
virtual void _ReservedScreenSaver4();
virtual void _ReservedScreenSaver5();
virtual void _ReservedScreenSaver6();
virtual void _ReservedScreenSaver7();
virtual void _ReservedScreenSaver8();
// These methods can be used to control animation loop cycles
void SetLoop(int32 onCount, int32 offCount);
int32 LoopOnCount() const;
int32 LoopOffCount() const;
bigtime_t ticksize;
int32 looponcount;
int32 loopoffcount;
private:
virtual void _ReservedScreenSaver1();
virtual void _ReservedScreenSaver2();
virtual void _ReservedScreenSaver3();
virtual void _ReservedScreenSaver4();
virtual void _ReservedScreenSaver5();
virtual void _ReservedScreenSaver6();
virtual void _ReservedScreenSaver7();
virtual void _ReservedScreenSaver8();
uint32 _reservedScreenSaver[6];
bigtime_t fTickSize;
int32 fLoopOnCount;
int32 fLoopOffCount;
uint32 _reserved[6];
};
extern "C" _EXPORT BScreenSaver *instantiate_screen_saver(BMessage *msg, image_id id);
#endif
#endif // _SCREENSAVER_H
+80 -65
View File
@@ -1,15 +1,17 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Copyright 2003-2006, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef SCREEN_SAVER_PREFS_H
#define SCREEN_SAVER_PREFS_H
#include <Message.h>
#include <Path.h>
#include <String.h>
enum arrowDirection {
enum screen_corner {
NONE = -1,
UPLEFT,
UPRIGHT,
@@ -18,69 +20,82 @@ enum arrowDirection {
CENTER
};
#define SCREEN_BLANKER_SIG "application/x-vnd.Haiku.screenblanker"
// time flags
enum {
SAVER_DISABLED = 0x00,
ENABLE_SAVER = 0x01,
ENABLE_DPMS_STAND_BY = 0x02,
ENABLE_DPMS_SUSPEND = 0x04,
ENABLE_DPMS_OFF = 0x08,
class ScreenSaverPrefs
{
public:
ScreenSaverPrefs();
bool LoadSettings();
void Defaults();
BPath & GetPath() { return fSSPath;}
BRect WindowFrame() {return fWindowFrame;}
int32 WindowTab() {return fWindowTab;}
int32 TimeFlags() {return fTimeFlags;}
bigtime_t BlankTime() {return fBlankTime;}
bigtime_t StandbyTime() {return fStandByTime;}
bigtime_t SuspendTime() {return fSuspendTime;}
bigtime_t OffTime() {return fOffTime;}
arrowDirection GetBlankCorner() {return fBlankCorner;}
arrowDirection GetNeverBlankCorner() {return fNeverBlankCorner;}
bool LockEnable() {return fLockEnabled;}
bigtime_t PasswordTime() {return fPasswordTime;}
const char *Password() { return fPassword.String(); }
const char *LockMethod() { return fLockMethod.String(); }
bool IsNetworkPassword() {return (strcmp(fLockMethod.String(), "custom") != 0);}
const char *ModuleName() {return fModuleName.String();}
status_t GetState(const char *name, BMessage *stateMsg);
void SetWindowFrame(const BRect &fr) { fWindowFrame = fr;}
void SetWindowTab(int32 tab) { fWindowTab = tab;}
void SetTimeFlags(int32 tf) {fTimeFlags = tf;}
void SetBlankTime(bigtime_t bt) {fBlankTime = bt;}
void SetStandbyTime(bigtime_t time) {fStandByTime = time;}
void SetSuspendTime(bigtime_t time) {fSuspendTime = time;}
void SetOffTime(bigtime_t intime) {fOffTime = intime;}
void SetBlankCorner(arrowDirection in) {fBlankCorner = in;}
void SetNeverBlankCorner(arrowDirection in) {fNeverBlankCorner = in;}
void SetLockEnable(bool en) {fLockEnabled = en;}
void SetPasswordTime(bigtime_t pt) {fPasswordTime = pt;}
void SetPassword(const char *pw) {fPassword = pw;} // Can not set network password from here.
void SetLockMethod(const char *method) {fLockMethod = method;}
void SetModuleName(const char *mn) {fModuleName = mn;}
void SetState(const char *name, BMessage *stateMsg);
void SaveSettings();
BMessage & GetSettings();
private:
BRect fWindowFrame;
int32 fWindowTab;
int32 fTimeFlags;
bigtime_t fBlankTime;
bigtime_t fStandByTime;
bigtime_t fSuspendTime;
bigtime_t fOffTime;
arrowDirection fBlankCorner;
arrowDirection fNeverBlankCorner;
bool fLockEnabled;
bigtime_t fPasswordTime;
BString fPassword;
BString fModuleName;
BString fLockMethod;
BMessage fSettings;
BPath fSSPath, fNetworkPath;
ENABLE_DPMS_MASK = ENABLE_DPMS_STAND_BY | ENABLE_DPMS_SUSPEND | ENABLE_DPMS_OFF
};
#define SCREEN_BLANKER_SIG "application/x-vnd.Haiku.screenblanker"
#endif //SCREEN_SAVER_PREFS_H
class ScreenSaverPrefs {
public:
ScreenSaverPrefs();
bool LoadSettings();
void Defaults();
BPath& Path() { return fSettingsPath; }
BRect WindowFrame() { return fWindowFrame; }
int32 WindowTab() { return fWindowTab; }
int32 TimeFlags() { return fTimeFlags; }
bigtime_t BlankTime() { return fBlankTime; }
bigtime_t StandbyTime() { return fStandByTime; }
bigtime_t SuspendTime() { return fSuspendTime; }
bigtime_t OffTime() { return fOffTime; }
screen_corner GetBlankCorner() { return fBlankCorner; }
screen_corner GetNeverBlankCorner() { return fNeverBlankCorner; }
bool LockEnable() { return fLockEnabled; }
bigtime_t PasswordTime() { return fPasswordTime; }
const char *Password() { return fPassword.String(); }
const char *LockMethod() { return fLockMethod.String(); }
bool IsNetworkPassword() { return strcmp(fLockMethod.String(), "custom") != 0; }
const char *ModuleName() { return fModuleName.String(); }
status_t GetState(const char *name, BMessage *stateMsg);
void SetWindowFrame(const BRect &fr) { fWindowFrame = fr; }
void SetWindowTab(int32 tab) { fWindowTab = tab; }
void SetTimeFlags(int32 tf) { fTimeFlags = tf; }
void SetBlankTime(bigtime_t bt) { fBlankTime = bt; }
void SetStandbyTime(bigtime_t time) { fStandByTime = time; }
void SetSuspendTime(bigtime_t time) { fSuspendTime = time; }
void SetOffTime(bigtime_t intime) { fOffTime = intime; }
void SetBlankCorner(screen_corner in) { fBlankCorner = in; }
void SetNeverBlankCorner(screen_corner in) { fNeverBlankCorner = in; }
void SetLockEnable(bool en) { fLockEnabled = en; }
void SetPasswordTime(bigtime_t pt) { fPasswordTime = pt; }
void SetPassword(const char *pw) { fPassword = pw; }
// Cannot set network password from here.
void SetLockMethod(const char *method) { fLockMethod = method; }
void SetModuleName(const char *mn) { fModuleName = mn; }
void SetState(const char *name, BMessage *stateMsg);
void SaveSettings();
BMessage& GetSettings();
private:
BRect fWindowFrame;
int32 fWindowTab;
int32 fTimeFlags;
bigtime_t fBlankTime;
bigtime_t fStandByTime;
bigtime_t fSuspendTime;
bigtime_t fOffTime;
screen_corner fBlankCorner;
screen_corner fNeverBlankCorner;
bool fLockEnabled;
bigtime_t fPasswordTime;
BString fPassword;
BString fModuleName;
BString fLockMethod;
BMessage fSettings;
BPath fSettingsPath, fNetworkPath;
};
#endif // SCREEN_SAVER_PREFS_H
@@ -0,0 +1,56 @@
/*
* Copyright 2003-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Phipps
* Jérôme Duval, [email protected]
* Axel Dörfler, [email protected]
*/
#ifndef SCREEN_SAVER_RUNNER_H
#define SCREEN_SAVER_RUNNER_H
#include <SupportDefs.h>
#include <DirectWindow.h>
class BScreenSaver;
class BView;
class ScreenSaverPrefs;
class ScreenSaverRunner {
public:
ScreenSaverRunner(BWindow* window, BView* view,
bool preview, ScreenSaverPrefs& prefs);
~ScreenSaverRunner();
BScreenSaver* ScreenSaver() const;
bool HasStarted() const;
status_t Run();
void Quit();
void Suspend();
void Resume();
private:
void _LoadAddOn();
void _CleanUp();
static status_t _ThreadFunc(void* data);
void _Run();
BScreenSaver* fSaver;
BWindow* fWindow;
BDirectWindow* fDirectWindow;
BView* fView;
ScreenSaverPrefs& fPrefs;
bool fPreview;
bool fHasStarted;
image_id fAddonImage;
thread_id fThread;
volatile bool fQuitting;
};
#endif //SCREEN_SAVER_THREAD_H
@@ -1,43 +0,0 @@
/*
* Copyright 2003, Michael Phipps. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef SCREEN_SAVER_THREAD_H
#define SCREEN_SAVER_THREAD_H
#include <SupportDefs.h>
#include <DirectWindow.h>
class BScreenSaver;
class BView;
class ScreenSaverPrefs;
class ScreenSaverThread {
public:
ScreenSaverThread(BWindow* window,
BView* view,
ScreenSaverPrefs* prefs);
~ScreenSaverThread();
void Thread();
BScreenSaver* LoadAddOn();
void Quit(thread_id thread);
static int32 ThreadFunc(void* data);
private:
void _CleanUp();
BScreenSaver* fSaver;
BWindow* fWin;
BDirectWindow* fDWin;
BView* fView;
ScreenSaverPrefs* fPref;
long fFrame;
int fSnoozeCount;
image_id fAddonImage;
volatile bool fQuitting;
};
#endif //SCREEN_SAVER_THREAD_H
@@ -5,22 +5,29 @@
* Authors:
* Michael Phipps
* Jérôme Duval, [email protected]
* Axel Dörfler, [email protected]
*/
#include "ScreenSaverFilter.h"
#include <Application.h>
#include <MessageRunner.h>
#include <NodeMonitor.h>
#include <OS.h>
#include <Roster.h>
#include <Screen.h>
#include <Application.h>
#include "ScreenSaverFilter.h"
#include <Debug.h>
#define CALLED() SERIAL_PRINT(("%s\n", __PRETTY_FUNCTION__))
static const int kCornerSize = 10;
static const int32 kNeverBlankCornerSize = 10;
static const int32 kBlankCornerSize = 5;
static const int32 kMsgCheckTime = 'SSCT';
static const int32 kMsgCornerInvoke = 'Scin';
extern "C" _EXPORT BInputServerFilter* instantiate_input_filter();
@@ -68,10 +75,18 @@ ScreenSaverController::MessageReceived(BMessage *message)
break;
}
case kMsgSuspendScreenSaver:
//fFilter->Suspend(msg);
break;
case kMsgCheckTime:
fFilter->CheckTime();
break;
case kMsgCornerInvoke:
fFilter->CheckCornerInvoke();
break;
default:
BLooper::MessageReceived(message);
}
@@ -82,15 +97,16 @@ ScreenSaverController::MessageReceived(BMessage *message)
ScreenSaverFilter::ScreenSaverFilter()
: fLastEventTime(0),
fBlankTime(0),
fSnoozeTime(0),
fCurrent(NONE),
fEnabled(false),
fFrameNum(0),
fRunner(NULL),
fWatchingDirectory(false),
fWatchingFile(false)
:
fLastEventTime(0),
fBlankTime(0),
fSnoozeTime(0),
fCurrentCorner(NONE),
fEnabled(false),
fFrameNum(0),
fRunner(NULL),
fWatchingDirectory(false),
fWatchingFile(false)
{
CALLED();
fController = new ScreenSaverController(this);
@@ -116,9 +132,9 @@ ScreenSaverFilter::~ScreenSaverFilter()
void
ScreenSaverFilter::WatchPreferences()
ScreenSaverFilter::_WatchPreferences()
{
BEntry entry(fPrefs.GetPath().Path());
BEntry entry(fPrefs.Path().Path());
if (entry.Exists()) {
if (fWatchingFile)
return;
@@ -145,24 +161,21 @@ ScreenSaverFilter::WatchPreferences()
}
void
ScreenSaverFilter::Invoke()
void
ScreenSaverFilter::_Invoke()
{
CALLED();
if ((fKeep != NONE && fCurrent == fKeep)
|| fEnabled
if (fCurrentCorner == fNeverBlankCorner || fEnabled
|| fPrefs.TimeFlags() != 1
|| be_roster->IsRunning(SCREEN_BLANKER_SIG)) {
// If mouse is in this corner, never invoke.
|| be_roster->IsRunning(SCREEN_BLANKER_SIG))
return;
}
SERIAL_PRINT(("we run screenblanker\n"));
be_roster->Launch(SCREEN_BLANKER_SIG);
}
void
void
ScreenSaverFilter::ReloadSettings()
{
CALLED();
@@ -170,24 +183,24 @@ ScreenSaverFilter::ReloadSettings()
SERIAL_PRINT(("preferences loading failed: going to defaults\n"));
}
fBlank = fPrefs.GetBlankCorner();
fKeep = fPrefs.GetNeverBlankCorner();
fBlankCorner = fPrefs.GetBlankCorner();
fNeverBlankCorner = fPrefs.GetNeverBlankCorner();
fBlankTime = fSnoozeTime = fPrefs.BlankTime();
CheckTime();
delete fRunner;
fRunner = new BMessageRunner(BMessenger(NULL, fController),
new BMessage(kMsgCheckTime), fSnoozeTime, -1);
new BMessage(kMsgCheckTime), fSnoozeTime);
if (fRunner->InitCheck() != B_OK) {
SERIAL_PRINT(("fRunner init failed\n"));
}
WatchPreferences();
_WatchPreferences();
}
void
ScreenSaverFilter::Banish()
void
ScreenSaverFilter::_Banish()
{
CALLED();
if (!fEnabled)
@@ -201,13 +214,13 @@ ScreenSaverFilter::Banish()
}
void
void
ScreenSaverFilter::CheckTime()
{
CALLED();
bigtime_t now = system_time();
if (now >= fLastEventTime + fBlankTime)
Invoke();
_Invoke();
// TODO: this doesn't work correctly - since the BMessageRunner is not
// restarted, the next check will be too far away
@@ -226,35 +239,55 @@ ScreenSaverFilter::CheckTime()
}
void
ScreenSaverFilter::UpdateRectangles()
void
ScreenSaverFilter::CheckCornerInvoke()
{
if (fCurrentCorner == fBlankCorner)
_Invoke();
}
void
ScreenSaverFilter::_UpdateRectangles()
{
// TODO: make this better if possible at all (in a clean way)
CALLED();
fBlankRect = _ScreenCorner(fBlankCorner, kBlankCornerSize);
fNeverBlankRect = _ScreenCorner(fNeverBlankCorner, kNeverBlankCornerSize);
}
BRect
ScreenSaverFilter::_ScreenCorner(screen_corner corner, uint32 cornerSize)
{
BRect frame = BScreen().Frame();
fTopLeft.Set(frame.left, frame.top,
frame.left + kCornerSize, frame.top + kCornerSize);
fTopRight.Set(frame.right - kCornerSize, frame.top,
frame.right, frame.top + kCornerSize);
fBottomLeft.Set(frame.left, frame.bottom - kCornerSize,
frame.left + kCornerSize, frame.bottom);
fBottomRight.Set(frame.right - kCornerSize, frame.bottom - kCornerSize,
frame.right, frame.bottom);
switch (corner) {
case UPLEFT:
return BRect(frame.left, frame.top, frame.left + cornerSize - 1,
frame.top + cornerSize - 1);
case UPRIGHT:
return BRect(frame.right, frame.top, frame.right - cornerSize + 1,
frame.top + cornerSize - 1);
case DOWNRIGHT:
return BRect(frame.right, frame.bottom, frame.right - cornerSize + 1,
frame.bottom - cornerSize + 1);
case DOWNLEFT:
return BRect(frame.left, frame.bottom, frame.left + cornerSize - 1,
frame.bottom - cornerSize + 1);
default:
// return an invalid rectangle
return BRect(-1, -1, -2, -2);
}
}
void
ScreenSaverFilter::Cornered(arrowDirection pos)
{
//CALLED();
fCurrent = pos;
if (fBlank != NONE && pos == fBlank)
Invoke();
}
filter_result
filter_result
ScreenSaverFilter::Filter(BMessage *message, BList *outList)
{
fLastEventTime = system_time();
@@ -264,21 +297,28 @@ ScreenSaverFilter::Filter(BMessage *message, BList *outList)
{
BPoint pos;
message->FindPoint("where", &pos);
if ((fFrameNum++ % 32) == 0) // Every so many frames, update
UpdateRectangles();
if (fTopLeft.Contains(pos))
Cornered(UPLEFT);
else if (fTopRight.Contains(pos))
Cornered(UPRIGHT);
else if (fBottomLeft.Contains(pos))
Cornered(DOWNLEFT);
else if (fBottomRight.Contains(pos))
Cornered(DOWNRIGHT);
else {
Cornered(NONE);
Banish();
if ((fFrameNum++ % 32) == 0) {
// Every so many frames, update
// Used so that we don't update the screen coord's so often
// Ideally, we would get a message when the screen changes.
// R5 doesn't do this.
_UpdateRectangles();
}
if (fBlankRect.Contains(pos)) {
fCurrentCorner = fBlankCorner;
// start screen blanker after one second
BMessage invoke(kMsgCornerInvoke);
if (BMessageRunner::StartSending(fController, &invoke, 1000000ULL, 1) != B_OK)
_Invoke();
break;
}
if (fNeverBlankRect.Contains(pos))
fCurrentCorner = fNeverBlankCorner;
else
fCurrentCorner = NONE;
break;
}
@@ -289,15 +329,11 @@ ScreenSaverFilter::Filter(BMessage *message, BList *outList)
// screen savers possible
int32 key;
if (fEnabled && message->FindInt32("key", &key) == B_OK && key == 0xe)
break;
// supposed to fall through
return B_DISPATCH_MESSAGE;
}
default:
Banish();
break;
}
_Banish();
return B_DISPATCH_MESSAGE;
}
@@ -1,25 +1,26 @@
/*
* 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]
* Axel Dörfler, [email protected]
*/
#ifndef SCREEN_SAVER_FILTER_H
#define SCREEN_SAVER_FILTER_H
#include <InputServerFilter.h>
#include <Rect.h>
#include <Region.h>
#include <Messenger.h>
#include <MessageFilter.h>
#include <MessageRunner.h>
#include <Node.h>
#include "ScreenSaverPrefs.h"
#include <InputServerFilter.h>
#include <Looper.h>
#include <Node.h>
static const uint32 kMsgSuspendScreenSaver = 'susp';
class BMessageRunner;
class ScreenSaverFilter;
class ScreenSaverController : public BLooper {
@@ -38,32 +39,34 @@ class ScreenSaverFilter : public BInputServerFilter {
virtual filter_result Filter(BMessage *message, BList *outList);
void Suspend(BMessage *message);
void CheckTime();
void CheckCornerInvoke();
uint32 SnoozeTime() {return fSnoozeTime;}
void ReloadSettings();
void SetEnabled(bool enabled) { fEnabled = enabled; }
private:
bigtime_t fLastEventTime, fBlankTime, fSnoozeTime;
arrowDirection fBlank, fKeep, fCurrent;
bool fEnabled;
BRect fTopLeft, fTopRight, fBottomLeft, fBottomRight;
ScreenSaverPrefs fPrefs;
uint32 fFrameNum;
// Used so that we don't update the screen coord's so often
// Ideally, we would get a message when the screen changes.
// R5 doesn't do this.
void _WatchPreferences();
void _UpdateRectangles();
BRect _ScreenCorner(screen_corner pos, uint32 cornerSize);
ScreenSaverController *fController;
node_ref fPrefsNodeRef, fPrefsDirNodeRef;
BMessageRunner *fRunner;
bool fWatchingDirectory, fWatchingFile;
void WatchPreferences();
void UpdateRectangles();
void Cornered(arrowDirection pos);
void Invoke();
void Banish();
void _Invoke();
void _Banish();
bigtime_t fLastEventTime, fBlankTime, fSnoozeTime;
screen_corner fBlankCorner, fNeverBlankCorner, fCurrentCorner;
BRect fBlankRect, fNeverBlankRect;
bool fEnabled;
ScreenSaverPrefs fPrefs;
uint32 fFrameNum;
ScreenSaverController* fController;
node_ref fPrefsNodeRef, fPrefsDirNodeRef;
BMessageRunner* fRunner;
bool fWatchingDirectory, fWatchingFile;
};
#endif /* SCREEN_SAVER_FILTER_H */
+1 -6
View File
@@ -5,18 +5,13 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders interface screen_saver ;
BinCommand screen_blanker :
ScreenSaverApp.cpp
ScreenBlanker.cpp
ScreenSaverWindow.cpp
PasswordWindow.cpp
ScreenSaver.cpp
: be game libscreensaver.so
: screen_blanker.rdef
;
SEARCH on [ FGristFiles
ScreenSaver.cpp
] = [ FDirName $(HAIKU_TOP) src kits screensaver ] ;
Package haiku-screensaverkit-cvs :
screen_blanker :
boot home config bin ;
@@ -8,38 +8,45 @@
*/
#include "ScreenSaverApp.h"
#include "ScreenBlanker.h"
#include <Debug.h>
#include <stdio.h>
#include <Screen.h>
#include <image.h>
#include <StorageDefs.h>
#include <FindDirectory.h>
#include <SupportDefs.h>
#include <File.h>
#include <Path.h>
#include <string.h>
#include <Beep.h>
#include <Debug.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
#include <Screen.h>
#include <StorageDefs.h>
#include <SupportDefs.h>
#include <image.h>
#include <stdio.h>
#include <string.h>
const static int32 RESUME_SAVER = 'RSSV';
ScreenSaverApp::ScreenSaverApp()
ScreenBlanker::ScreenBlanker()
: BApplication(SCREEN_BLANKER_SIG),
fWindow(NULL),
fSaver(NULL),
fThread(NULL),
fRunner(NULL),
fPasswordWindow(NULL),
fThreadID(-1),
fRunner(NULL)
fResumeRunner(NULL)
{
fBlankTime = system_time();
}
ScreenBlanker::~ScreenBlanker()
{
delete fResumeRunner;
}
void
ScreenSaverApp::ReadyToRun()
ScreenBlanker::ReadyToRun()
{
if (!fPrefs.LoadSettings()) {
fprintf(stderr, "could not load settings\n");
@@ -50,14 +57,12 @@ ScreenSaverApp::ReadyToRun()
BScreen screen(B_MAIN_SCREEN_ID);
fWindow = new ScreenSaverWindow(screen.Frame());
fPasswordWindow = new PasswordWindow();
fThread = new ScreenSaverThread(fWindow, fWindow->ChildAt(0), &fPrefs);
fRunner = new ScreenSaverRunner(fWindow, fWindow->ChildAt(0), false, fPrefs);
fSaver = fThread->LoadAddOn();
fSaver = fRunner->ScreenSaver();
if (fSaver) {
fWindow->SetSaver(fSaver);
fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc,
"ScreenSaverRenderer", B_LOW_PRIORITY, fThread);
resume_thread(fThreadID);
fRunner->Run();
} else {
fprintf(stderr, "could not load the screensaver addon\n");
}
@@ -69,11 +74,10 @@ ScreenSaverApp::ReadyToRun()
void
ScreenSaverApp::_ShowPasswordWindow()
ScreenBlanker::_ShowPasswordWindow()
{
if (fWindow->Lock()) {
if (fThreadID > -1)
suspend_thread(fThreadID);
fRunner->Suspend();
if (fWindow->SetFullScreen(false) == B_OK) {
fWindow->Sync();
@@ -89,19 +93,19 @@ ScreenSaverApp::_ShowPasswordWindow()
void
ScreenSaverApp::_ResumeScreenSaver()
ScreenBlanker::_ResumeScreenSaver()
{
delete fRunner;
fRunner = new BMessageRunner(BMessenger(this), new BMessage(RESUME_SAVER),
delete fResumeRunner;
fResumeRunner = new BMessageRunner(BMessenger(this), new BMessage(RESUME_SAVER),
fPrefs.BlankTime(), 1);
if (fRunner->InitCheck() != B_OK) {
if (fResumeRunner->InitCheck() != B_OK) {
fprintf(stderr, "fRunner init failed\n");
}
}
void
ScreenSaverApp::MessageReceived(BMessage *message)
ScreenBlanker::MessageReceived(BMessage *message)
{
switch (message->what) {
case UNLOCK_MESSAGE:
@@ -125,8 +129,8 @@ ScreenSaverApp::MessageReceived(BMessage *message)
HideCursor();
fPasswordWindow->Hide();
}
if (fThreadID > -1)
resume_thread(fThreadID);
fRunner->Resume();
fWindow->Unlock();
}
break;
@@ -139,10 +143,10 @@ ScreenSaverApp::MessageReceived(BMessage *message)
bool
ScreenSaverApp::QuitRequested()
ScreenBlanker::QuitRequested()
{
if (fPrefs.LockEnable()
&& (system_time() - fBlankTime > (fPrefs.PasswordTime() - fPrefs.BlankTime()))) {
&& system_time() - fBlankTime > fPrefs.PasswordTime() - fPrefs.BlankTime()) {
_ShowPasswordWindow();
return false;
}
@@ -153,18 +157,9 @@ ScreenSaverApp::QuitRequested()
void
ScreenSaverApp::_Shutdown()
ScreenBlanker::_Shutdown()
{
if (fThread) {
fThread->Quit(fThreadID);
delete fThread;
} else if (fThreadID > -1) {
// ?!?
kill_thread(fThreadID);
}
fThread = NULL;
fThreadID = -1;
delete fRunner;
if (fWindow)
fWindow->Hide();
@@ -177,7 +172,7 @@ ScreenSaverApp::_Shutdown()
int
main(int, char**)
{
ScreenSaverApp app;
ScreenBlanker app;
app.Run();
return 0;
}
@@ -12,21 +12,22 @@
#include "PasswordWindow.h"
#include "ScreenSaverPrefs.h"
#include "ScreenSaverThread.h"
#include "ScreenSaverRunner.h"
#include "ScreenSaverWindow.h"
#include <Application.h>
#include <MessageRunner.h>
class ScreenSaverApp : public BApplication {
class ScreenBlanker : public BApplication {
public:
ScreenSaverApp();
ScreenBlanker();
~ScreenBlanker();
virtual void ReadyToRun();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void MessageReceived(BMessage* message);
private:
bool _LoadAddOn();
@@ -37,12 +38,11 @@ class ScreenSaverApp : public BApplication {
ScreenSaverPrefs fPrefs;
ScreenSaverWindow *fWindow;
BScreenSaver *fSaver;
ScreenSaverThread *fThread;
ScreenSaverRunner *fRunner;
PasswordWindow *fPasswordWindow;
thread_id fThreadID;
bigtime_t fBlankTime;
BMessageRunner *fRunner;
BMessageRunner *fResumeRunner;
};
#endif // SCREEN_SAVER_APP_H
+4 -62
View File
@@ -1,66 +1,9 @@
#ifndef __CONSTANTS__
#define __CONSTANTS__
int secondsToSlider(int val);
inline BPoint
scaleDirect(float x, float y,BRect area)
{
return BPoint(area.Width()*x+area.left,area.Height()*y+area.top);
}
#ifndef CONSTANTS_H
#define CONSTANTS_H
inline BRect scaleDirect (float x1,float x2,float y1,float y2,BRect area)
{
return BRect(area.Width()*x1+area.left,area.Height()*y1+area.top, area.Width()*x2+area.left,area.Height()*y2+area.top);
}
#include <GraphicsDefs.h>
static const float kPositionalX[]= {0,.1,.25,.3,.7,.75,.9,1.0};
static const float kPositionalY[]= {0,.1,.7,.8,.9,1.0};
inline BPoint
scale(int x, int y,BRect area)
{
return scaleDirect(kPositionalX[x],kPositionalY[y],area);
}
inline BRect
scale(int x1, int x2, int y1, int y2,BRect area)
{
return scaleDirect(kPositionalX[x1],kPositionalX[x2],kPositionalY[y1],kPositionalY[y2],area);
}
inline BPoint
scale3(int x, int y,BRect area,bool invertX,bool invertY)
{
float arrowX[]= {0,.25,.5,.66667,.90,.9};
float arrowY[]= {0,.15,.25,.3333333,.6666667,1.0};
return scaleDirect(((invertX)?1-arrowX[x]:arrowX[x]),((invertY)?1-arrowY[y]:arrowY[y]),area);
}
const int32 kTab1_chg ='TAB1';
const int32 kTab2_chg ='TAB2';
const int32 kPwbutton ='PWBT';
const int32 kDone_clicked ='DONE';
const int32 kCancel_clicked ='CNCL';
const int32 kButton_changed ='BTNC';
const int32 kShow ='SHOW';
const int32 kPopulate ='POPU';
const int32 kUtilize ='UTIL';
const int32 kSaver_sel ='SSEL';
const int32 kTest_btn ='TEST';
const int32 kAdd_btn ='ADD ';
const int32 kUpdatelist ='UPDL';
const int32 kPasswordCheckbox = 'PWCB';
const int32 kRunSliderChanged = 'RSCG';
const int32 kPasswordSliderChanged = 'PWCG';
const int32 kTurnOffSliderChanged = 'TUCG';
const int32 kEnableScreenSaverChanged = 'ESCH';
const rgb_color kBlack = {0,0,0,0};
const rgb_color kDarkGrey = {150,150,150,0};
@@ -68,5 +11,4 @@ const rgb_color kGrey = {200,200,200,0};
const rgb_color kLightBlue = {200,200,255,0};
const rgb_color kLightGreen = {255,200,200,0};
#endif
#endif // CONSTANTS_H
+1 -7
View File
@@ -6,21 +6,15 @@ UsePrivateHeaders screen_saver ;
SubDirSysHdrs $(SUBDIR) ;
Preference ScreenSaver :
ScreenSaverPrefsApp.cpp
ScreenSaverApp.cpp
ScreenSaverWindow.cpp
PasswordWindow.cpp
PreviewView.cpp
MouseAreaView.cpp
ScreenSaver.cpp
: tracker libscreensaver.so be $(TARGET_LIBSTDC++)
: ScreenSaver.rdef
;
SEARCH on [ FGristFiles
ScreenSaver.cpp
] = [ FDirName $(HAIKU_TOP) src kits screensaver ] ;
Package haiku-screensaverkit-cvs :
ScreenSaver :
# boot beos preferences ;
boot home Desktop haiku-screensaverkit ;
+95 -59
View File
@@ -1,40 +1,59 @@
/*
* Copyright 2003, Haiku.
* Copyright 2003-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Phipps
* Michael Phipps
*/
#include "MouseAreaView.h"
#include "Constants.h"
#include "Utility.h"
#include <Rect.h>
#include <Point.h>
#include <Shape.h>
#include <stdio.h>
MouseAreaView::MouseAreaView(BRect frame, const char *name)
: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW)
inline BPoint
scale_arrow(int x, int y, BRect area, bool invertX, bool invertY)
{
SetViewColor(216,216,216);
fCurrentDirection = NONE;
float arrowX[] = {0, .25, .5, .66667, .90, .9};
float arrowY[] = {0, .15, .25, .3333333, .6666667, 1.0};
return scale_direct(invertX ? 1 - arrowX[x] : arrowX[x],
invertY ? 1 - arrowY[y] : arrowY[y], area);
}
void
// #pragma mark -
MouseAreaView::MouseAreaView(BRect frame, const char *name)
: BView (frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
fCurrentCorner(NONE)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
void
MouseAreaView::Draw(BRect update)
{
SetViewColor(216,216,216);
// Top of monitor
SetHighColor(kGrey);
FillRoundRect(scale(0,7,0,3,Bounds()),4,4);
FillRoundRect(scale(0, 7, 0, 3, Bounds()), 4, 4);
SetHighColor(kBlack);
StrokeRoundRect(scale(0,7,0,3,Bounds()),4,4);
StrokeRoundRect(scale(0, 7, 0, 3, Bounds()), 4, 4);
SetHighColor(kLightBlue);
fScreenArea=scale(1,6,1,2,Bounds());
FillRect(fScreenArea);
fMonitorFrame = scale(1, 6, 1, 2, Bounds());
FillRect(fMonitorFrame);
SetHighColor(kDarkGrey);
StrokeRect(fScreenArea);
StrokeRect(fMonitorFrame);
// Base of monitor
SetHighColor(kGrey);
FillTriangle(scale(1,5,Bounds()),scale(3,4,Bounds()),scale(3,5,Bounds()));
@@ -50,68 +69,85 @@ MouseAreaView::Draw(BRect update)
}
BRect
getArrowSize(BRect area,bool isCentered)
void
MouseAreaView::SetCorner(screen_corner corner)
{
int areaWidth=area.IntegerWidth();
int areaHeight=area.IntegerHeight();
if (areaHeight<areaWidth)
areaWidth=areaHeight;
areaWidth /= 3;
BRect foo(0,0,areaWidth,areaWidth);
if (isCentered)
foo.OffsetBy(area.left+area.Width()/2-(areaWidth/2),area.top+area.Height()/2-(areaWidth/2));
return (foo);
fCurrentCorner = corner;
Invalidate();
}
void
MouseAreaView::DrawArrow(void)
BRect
MouseAreaView::_ArrowSize(BRect monitorRect, bool isCentered)
{
if (fCurrentDirection!=NONE) {
BRect area(getArrowSize(fScreenArea,false));
bool invertX=(fCurrentDirection==UPRIGHT||fCurrentDirection==DOWNRIGHT);
bool invertY=(fCurrentDirection==UPRIGHT||fCurrentDirection==UPLEFT);
float size=area.Width();
MovePenTo(((invertX)?fScreenArea.right-size-2:2+fScreenArea.left),((!invertY)?fScreenArea.bottom-size-2:2+fScreenArea.top));
int arrowSize = monitorRect.IntegerWidth();
if (monitorRect.IntegerHeight() < arrowSize)
arrowSize = monitorRect.IntegerHeight();
arrowSize /= 3;
BRect arrowRect(0, 0, arrowSize, arrowSize);
if (isCentered) {
arrowRect.OffsetBy(monitorRect.left + (monitorRect.Width() - arrowSize) / 2,
monitorRect.top + (monitorRect.Height() - arrowSize) / 2);
}
return arrowRect;
}
void
MouseAreaView::DrawArrow()
{
PushState();
BRect rect(_ArrowSize(fMonitorFrame, fCurrentCorner == NONE));
if (fCurrentCorner != NONE) {
bool invertX = fCurrentCorner == UPRIGHT || fCurrentCorner == DOWNRIGHT;
bool invertY = fCurrentCorner == UPRIGHT || fCurrentCorner == UPLEFT;
float size = rect.Width();
MovePenTo(invertX ? fMonitorFrame.right - size - 2 : 2 + fMonitorFrame.left,
!invertY ? fMonitorFrame.bottom - size - 2 : 2 + fMonitorFrame.top);
BShape arrow;
arrow.MoveTo(scale3(0,1,area,invertX,invertY));
arrow.LineTo(scale3(0,5,area,invertX,invertY));
arrow.LineTo(scale3(4,5,area,invertX,invertY));
arrow.LineTo(scale3(3,4,area,invertX,invertY));
arrow.LineTo(scale3(5,3,area,invertX,invertY));
arrow.LineTo(scale3(2,0,area,invertX,invertY));
arrow.LineTo(scale3(1,2,area,invertX,invertY));
arrow.LineTo(scale3(0,1,area,invertX,invertY));
arrow.MoveTo(scale_arrow(0, 1, rect, invertX, invertY));
arrow.LineTo(scale_arrow(0, 5, rect, invertX, invertY));
arrow.LineTo(scale_arrow(4, 5, rect, invertX, invertY));
arrow.LineTo(scale_arrow(3, 4, rect, invertX, invertY));
arrow.LineTo(scale_arrow(5, 3, rect, invertX, invertY));
arrow.LineTo(scale_arrow(2, 0, rect, invertX, invertY));
arrow.LineTo(scale_arrow(1, 2, rect, invertX, invertY));
arrow.LineTo(scale_arrow(0, 1, rect, invertX, invertY));
arrow.Close();
SetHighColor(kBlack);
FillShape(&arrow,B_SOLID_HIGH);
FillShape(&arrow, B_SOLID_HIGH);
} else {
PushState();
BRect area(getArrowSize(fScreenArea,true));
SetHighColor(255,0,0);
SetHighColor(255, 0, 0);
SetPenSize(2);
StrokeEllipse(area);
StrokeLine(BPoint(area.right,area.top),BPoint(area.left,area.bottom));
PopState();
StrokeEllipse(rect);
StrokeLine(BPoint(rect.right, rect.top), BPoint(rect.left, rect.bottom));
}
PopState();
}
void MouseAreaView::MouseUp(BPoint point)
void
MouseAreaView::MouseUp(BPoint point)
{
if (fScreenArea.Contains(point)) {
if (getArrowSize(fScreenArea,true).Contains(point))
fCurrentDirection=NONE;
if (fMonitorFrame.Contains(point)) {
if (_ArrowSize(fMonitorFrame, true).Contains(point))
fCurrentCorner = NONE;
else {
float centerX=fScreenArea.left+(fScreenArea.Width()/2);
float centerY=fScreenArea.top+(fScreenArea.Height()/2);
if (point.x<centerX)
fCurrentDirection=((point.y<centerY)?UPLEFT:DOWNLEFT);
float centerX = fMonitorFrame.left + fMonitorFrame.Width() / 2;
float centerY = fMonitorFrame.top + fMonitorFrame.Height() / 2;
if (point.x < centerX)
fCurrentCorner = point.y < centerY ? UPLEFT : DOWNLEFT;
else
fCurrentDirection=((point.y<centerY)?UPRIGHT:DOWNRIGHT);
}
Draw(fScreenArea);
fCurrentCorner = point.y < centerY ? UPRIGHT : DOWNRIGHT;
}
Draw(fMonitorFrame);
}
}
+22 -16
View File
@@ -1,29 +1,35 @@
/*
* Copyright 2003, Haiku.
* Copyright 2003-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Phipps
* Michael Phipps
*/
#ifndef MOUSEAREAVIEW_H
#define MOUSEAREAVIEW_H
#include <View.h>
#include "ScreenSaverPrefs.h"
class MouseAreaView : public BView
{
public:
MouseAreaView(BRect frame, const char *name);
#include <View.h>
virtual void Draw(BRect update);
virtual void MouseUp(BPoint point);
void DrawArrow();
inline arrowDirection getDirection(void) { return fCurrentDirection;}
void setDirection(arrowDirection direction) { fCurrentDirection = direction; Invalidate(); }
private:
BRect fScreenArea;
arrowDirection fCurrentDirection;
class MouseAreaView : public BView {
public:
MouseAreaView(BRect frame, const char *name);
virtual void Draw(BRect update);
virtual void MouseUp(BPoint point);
void DrawArrow();
inline screen_corner Corner() { return fCurrentCorner; }
void SetCorner(screen_corner direction);
private:
BRect _ArrowSize(BRect monitorRect, bool isCentered);
BRect fMonitorFrame;
screen_corner fCurrentCorner;
};
#endif // MOUSEAREAVIEW_H
#endif // MOUSEAREAVIEW_H
+71 -56
View File
@@ -1,26 +1,37 @@
/*
* 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
* Michael Phipps
* Jérôme Duval, jerome.duval@free.fr
*/
#include "PasswordWindow.h"
#include <stdio.h>
#include <unistd.h>
#include <Alert.h>
#include <Box.h>
#include <Button.h>
#include <RadioButton.h>
#include <Screen.h>
#include <TextControl.h>
#include <stdio.h>
#include <unistd.h>
const uint32 kMsgDone = 'done';
const uint32 kMsgPasswordTypeChanged = 'pwtp';
PasswordWindow::PasswordWindow(ScreenSaverPrefs &prefs)
: BWindow(BRect(100,100,380,249),"",B_MODAL_WINDOW_LOOK,B_MODAL_APP_WINDOW_FEEL,B_NOT_RESIZABLE),
: BWindow(BRect(100, 100, 380, 249), "Password Window", B_MODAL_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
fPrefs(prefs)
{
Setup();
_Setup();
BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame();
BPoint point;
point.x = (screenFrame.Width() - Bounds().Width()) / 2;
@@ -32,34 +43,38 @@ PasswordWindow::PasswordWindow(ScreenSaverPrefs &prefs)
void
PasswordWindow::Setup()
PasswordWindow::_Setup()
{
BBox *owner=new BBox(Bounds(),"ownerView",B_FOLLOW_NONE,B_WILL_DRAW, B_PLAIN_BORDER);
AddChild(owner);
fUseNetwork=new BRadioButton(BRect(14,10,159,20),"useNetwork","Use Network password",new BMessage(kButton_changed),B_FOLLOW_NONE);
owner->AddChild(fUseNetwork);
fUseCustom=new BRadioButton(BRect(30,50,130,60),"fUseCustom","Use custom password",new BMessage(kButton_changed),B_FOLLOW_NONE);
BView* topView = new BView(Bounds(), "mainView", B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
fUseNetwork=new BRadioButton(BRect(14,10,159,20),"useNetwork","Use Network password",new BMessage(kMsgPasswordTypeChanged),B_FOLLOW_NONE);
topView->AddChild(fUseNetwork);
fUseCustom=new BRadioButton(BRect(30,50,130,60),"fUseCustom","Use custom password",new BMessage(kMsgPasswordTypeChanged),B_FOLLOW_NONE);
BBox *customBox=new BBox(BRect(9,30,269,105),"custBeBox",B_FOLLOW_NONE);
customBox->SetLabel(fUseCustom);
fPassword=new BTextControl(BRect(10,20,251,35),"pwdCntrl","Password:",NULL,B_FOLLOW_NONE);
fConfirm=new BTextControl(BRect(10,45,251,60),"fConfirmCntrl","Confirm password:",NULL,B_FOLLOW_NONE);
fPassword->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
fPasswordControl=new BTextControl(BRect(10,20,251,35),"pwdCntrl","Password:",NULL,B_FOLLOW_NONE);
fConfirmControl=new BTextControl(BRect(10,45,251,60),"fConfirmCntrl","Confirm password:",NULL,B_FOLLOW_NONE);
fPasswordControl->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
float divider = be_plain_font->StringWidth("Confirm password:") + 5.0;
fPassword->SetDivider(divider);
fPassword->TextView()->HideTyping(true);
fConfirm->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
fConfirm->SetDivider(divider);
fConfirm->TextView()->HideTyping(true);
customBox->AddChild(fPassword);
customBox->AddChild(fConfirm);
owner->AddChild(customBox);
fPasswordControl->SetDivider(divider);
fPasswordControl->TextView()->HideTyping(true);
fConfirmControl->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT);
fConfirmControl->SetDivider(divider);
fConfirmControl->TextView()->HideTyping(true);
customBox->AddChild(fPasswordControl);
customBox->AddChild(fConfirmControl);
topView->AddChild(customBox);
BButton* button = new BButton(BRect(194,118,269,129),"done","Done",new BMessage(kMsgDone),B_FOLLOW_NONE);
topView->AddChild(button);
button->MakeDefault(true);
button = new BButton(BRect(109,118,184,129),"cancel","Cancel",new BMessage(B_CANCEL),B_FOLLOW_NONE);
topView->AddChild(button);
fDone = new BButton(BRect(194,118,269,129),"done","Done",new BMessage (kDone_clicked),B_FOLLOW_NONE);
fCancel = new BButton(BRect(109,118,184,129),"cancel","Cancel",new BMessage (kCancel_clicked),B_FOLLOW_NONE);
owner->AddChild(fDone);
owner->AddChild(fCancel);
fDone->MakeDefault(true);
Update();
}
@@ -72,43 +87,43 @@ PasswordWindow::Update()
else
fUseCustom->SetValue(B_CONTROL_ON);
bool useNetPassword=(fUseCustom->Value()>0);
fConfirm->SetEnabled(useNetPassword);
fPassword->SetEnabled(useNetPassword);
fConfirmControl->SetEnabled(useNetPassword);
fPasswordControl->SetEnabled(useNetPassword);
}
void
PasswordWindow::MessageReceived(BMessage *message)
{
switch(message->what) {
case kDone_clicked:
fPrefs.SetLockMethod(fUseCustom->Value() ? "custom" : "network");
if (fUseCustom->Value()) {
if (strcmp(fPassword->Text(),fConfirm->Text())) {
BAlert *alert=new BAlert("noMatch","Passwords don't match. Try again.","OK");
alert->Go();
break;
}
fPrefs.SetPassword(crypt(fPassword->Text(), fPassword->Text()));
} else {
fPrefs.SetPassword("");
}
fPassword->SetText("");
fConfirm->SetText("");
switch (message->what) {
case kMsgDone:
fPrefs.SetLockMethod(fUseCustom->Value() ? "custom" : "network");
if (fUseCustom->Value()) {
if (strcmp(fPasswordControl->Text(),fConfirmControl->Text())) {
BAlert *alert=new BAlert("noMatch","Passwords don't match. Try again.","OK");
alert->Go();
break;
}
fPrefs.SetPassword(crypt(fPasswordControl->Text(), fPasswordControl->Text()));
} else {
fPrefs.SetPassword("");
}
fPasswordControl->SetText("");
fConfirmControl->SetText("");
Hide();
break;
case B_CANCEL:
fPasswordControl->SetText("");
fConfirmControl->SetText("");
Hide();
break;
case kCancel_clicked:
fPassword->SetText("");
fConfirm->SetText("");
Hide();
break;
case kButton_changed:
fPrefs.SetLockMethod(fUseCustom->Value()>0 ? "custom" : "network");
case kMsgPasswordTypeChanged:
fPrefs.SetLockMethod(fUseCustom->Value() > 0 ? "custom" : "network");
Update();
break;
case kShow:
Show();
break;
default:
BWindow::MessageReceived(message);
break;
+19 -21
View File
@@ -1,38 +1,36 @@
/*
* 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
* Michael Phipps
* Jérôme Duval, jerome.duval@free.fr
*/
#ifndef PASSWORDWINDOW_H
#define PASSWORDWINDOW_H
#include <Button.h>
#include <Constants.h>
#include <RadioButton.h>
#include <String.h>
#include <TextControl.h>
#include <Window.h>
#include "ScreenSaverPrefs.h"
class PasswordWindow : public BWindow
{
#include <Window.h>
class BRadioButton;
class BTextControl;
class PasswordWindow : public BWindow {
public:
PasswordWindow(ScreenSaverPrefs &prefs);
void Setup();
void Update();
virtual void MessageReceived(BMessage *message);
private:
BRadioButton *fUseNetwork,*fUseCustom;
BTextControl *fPassword,*fConfirm;
BButton *fCancel,*fDone;
BString fThePassword;
ScreenSaverPrefs &fPrefs;
void Update();
private:
void _Setup();
BRadioButton *fUseNetwork, *fUseCustom;
BTextControl *fPasswordControl, *fConfirmControl;
ScreenSaverPrefs &fPrefs;
};
#endif // PASSWORDWINDOW_H
#endif // PASSWORDWINDOW_H
+54 -62
View File
@@ -1,107 +1,99 @@
/*
* 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
* Michael Phipps
* Jérôme Duval, jerome.duval@free.fr
*/
#include "PreviewView.h"
#include "Constants.h"
#include <Rect.h>
#include "Utility.h"
#include <Point.h>
#include <Shape.h>
#include <iostream>
#include <ScreenSaver.h>
#include <Errors.h>
#include <Rect.h>
#include <Screen.h>
#include <ScreenSaver.h>
#include <Shape.h>
#include <String.h>
#include <iostream>
static float sampleX[]= {0,.05,.15,.7,.725,.8,.825,.85,.950,1.0};
static float sampleY[]= {0,.05,.90,.95,.966,.975,1.0};
inline BPoint
scale2(int x, int y,BRect area)
{
return scaleDirect(sampleX[x],sampleY[y],area);
return scale_direct(sampleX[x],sampleY[y],area);
}
inline BRect
scale2(int x1, int x2, int y1, int y2,BRect area)
{
return scaleDirect(sampleX[x1],sampleX[x2],sampleY[y1],sampleY[y2],area);
return scale_direct(sampleX[x1],sampleX[x2],sampleY[y1],sampleY[y2],area);
}
PreviewView::PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp)
: BView (frame,name,B_FOLLOW_NONE,B_WILL_DRAW),
fSaver(NULL),
fConfigView(NULL),
fSst(NULL),
fThreadID(-1),
fPrefPtr(prefp)
PreviewView::PreviewView(BRect frame, const char *name)
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
fSaverView(NULL)
{
SetViewColor(216,216,216);
}
PreviewView::~PreviewView()
{
if (fThreadID>=0)
kill_thread(fThreadID);
delete fSst;
}
void
PreviewView::SetScreenSaver(BString name)
{
if (fThreadID>=0) {
kill_thread(fThreadID);
fThreadID = -1;
}
if (fSst)
delete fSst;
if (fConfigView) {
RemoveChild(fConfigView);
delete fConfigView;
}
fConfigView = new BView(scale2(1,8,1,2,Bounds()),"previewArea",B_FOLLOW_NONE,B_WILL_DRAW);
fConfigView->SetViewColor(0,0,0);
AddChild(fConfigView);
fSst = new ScreenSaverThread(Window(),fConfigView,fPrefPtr);
fSaver = fSst->LoadAddOn();
if (fSaver) {
fThreadID = spawn_thread(ScreenSaverThread::ThreadFunc, "ScreenSaverRenderer", B_LOW_PRIORITY, fSst);
resume_thread(fThreadID);
}
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
void
PreviewView::Draw(BRect update)
{
SetViewColor(216,216,216);
SetHighColor(184,184,184);
PreviewView::~PreviewView()
{
}
BView*
PreviewView::AddPreview()
{
fSaverView = new BView(scale2(1,8,1,2,Bounds()),"previewArea",B_FOLLOW_NONE,B_WILL_DRAW);
fSaverView->SetViewColor(0, 0, 0);
AddChild(fSaverView);
return fSaverView;
}
BView*
PreviewView::RemovePreview()
{
if (fSaverView != NULL)
RemoveChild(fSaverView);
return fSaverView;
}
void
PreviewView::Draw(BRect update)
{
SetHighColor(184, 184, 184);
FillRoundRect(scale2(0,9,0,3,Bounds()),4,4);// Outer shape
FillRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
SetHighColor(96,96,96);
SetHighColor(96, 96, 96);
StrokeRoundRect(scale2(2,7,3,6,Bounds()),2,2);// control console outline
StrokeRoundRect(scale2(0,9,0,3,Bounds()),4,4); // Outline outer shape
SetHighColor(kBlack);
SetHighColor(184,184,184);
SetHighColor(184, 184, 184);
BRect outerShape = scale2(2,7,2,6,Bounds());
outerShape.InsetBy(1,1);
FillRoundRect(outerShape,4,4);// Outer shape
SetHighColor(0,255,0);
SetHighColor(0, 255, 0);
FillRect(scale2(3,4,4,5,Bounds()));
SetHighColor(96,96,96);
FillRect(scale2(5,6,4,5,Bounds()));
}
+21 -23
View File
@@ -1,37 +1,35 @@
/*
* 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
* Michael Phipps
* Jérôme Duval, jerome.duval@free.fr
*/
#ifndef PREVIEW_VIEW_H
#define PREVIEW_VIEW_H
#ifndef PREVIEWVIEW_H
#define PREVIEWVIEW_H
#include <View.h>
#include <Box.h>
#include <ScreenSaverThread.h>
#include <ScreenSaverRunner.h>
#include <ScreenSaverPrefs.h>
class BScreenSaver;
class PreviewView : public BView
{
public:
PreviewView(BRect frame, const char *name,ScreenSaverPrefs *prefp);
~PreviewView();
void Draw(BRect update);
void SetScreenSaver(BString name);
BScreenSaver *ScreenSaver() {return fSaver;}
private:
BScreenSaver* fSaver;
BView *fConfigView;
ScreenSaverThread *fSst;
thread_id fThreadID;
ScreenSaverPrefs *fPrefPtr;
}; // end class PreviewView
#endif // PREVIEWVIEW_H
class PreviewView : public BView {
public:
PreviewView(BRect frame, const char *name);
virtual ~PreviewView();
virtual void Draw(BRect update);
BView* AddPreview();
BView* RemovePreview();
private:
BView* fSaverView;
};
#endif // PREVIEW_VIEW_H
@@ -0,0 +1,78 @@
/*
* 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 <Application.h>
#include <Entry.h>
#include <Path.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
class ScreenSaverApp : public BApplication {
public:
ScreenSaverApp();
virtual void RefsReceived(BMessage *message);
private:
BWindow *fScreenSaverWindow;
};
ScreenSaverApp::ScreenSaverApp()
: BApplication("application/x-vnd.haiku.ScreenSaver")
{
fScreenSaverWindow = new ScreenSaverWindow();
fScreenSaverWindow->Show();
}
void
ScreenSaverApp::RefsReceived(BMessage *message)
{
entry_ref ref;
if (message->FindRef("refs", &ref) != B_OK)
return;
// Install the screen saver by copying it to the add-ons directory
// TODO: the translator have a similar mechanism - this could be cleaned
// up and have one nicely working solution
// TODO: should test if the dropped ref is really a screen saver!
// TODO: you can receive more than one ref at a time...
BEntry entry;
entry.SetTo(&ref, true);
if (entry.InitCheck() != B_OK)
return;
BPath path;
entry.GetPath(&path);
// TODO: find_directory() anyone??
char temp[2*B_PATH_NAME_LENGTH];
sprintf(temp,"cp %s '/boot/home/config/add-ons/Screen Savers/'\n", path.Path());
system(temp);
fScreenSaverWindow->PostMessage(kMsgUpdateList);
}
// #pragma mark -
int
main()
{
ScreenSaverApp app;
app.Run();
return 0;
}
@@ -1,49 +0,0 @@
/*
* Copyright 2003-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Phipps
* Jérôme Duval, jerome.duval@free.fr
*/
#include <Application.h>
#include <Entry.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <Path.h>
#include "ScreenSaverPrefsApp.h"
const char *APP_SIG = "application/x-vnd.haiku.ScreenSaver";
ScreenSaverPrefsApp::ScreenSaverPrefsApp() : BApplication(APP_SIG)
{
fScreenSaverWin = new ScreenSaverWin();
fScreenSaverWin->Show();
}
void
ScreenSaverPrefsApp::RefsReceived(BMessage *msg)
{
entry_ref ref;
BEntry e;
BPath p;
msg->FindRef("refs", &ref);
e.SetTo(&ref, true);
e.GetPath(&p);
char temp[2*B_PATH_NAME_LENGTH];
sprintf (temp,"cp %s '/boot/home/config/add-ons/Screen Savers/'\n",p.Path());
system(temp);
fScreenSaverWin->PostMessage(kUpdatelist);
}
int main(void) {
ScreenSaverPrefsApp app;
app.Run();
return 0;
}
@@ -1,23 +0,0 @@
/*
* Copyright 2003-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Phipps
* Jérôme Duval, jerome.duval@free.fr
*/
#ifndef _ScreenSaverPrefsApp_H
#define _ScreenSaverPrefsApp_H
#include "ScreenSaverWindow.h"
class ScreenSaverPrefsApp : public BApplication
{
public:
ScreenSaverPrefsApp();
virtual void RefsReceived(BMessage *);
private:
ScreenSaverWin *fScreenSaverWin;
};
#endif // _ScreenSaverPrefsApp_H
File diff suppressed because it is too large Load Diff
+56 -62
View File
@@ -1,82 +1,76 @@
/*
* 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
* Michael Phipps
* Jérôme Duval, jerome.duval@free.fr
* Axel Dörfler, axeld@pinc-software.de
*/
#ifndef SCREEN_SAVER_WINDOW_H
#define SCREEN_SAVER_WINDOW_H
#include "PasswordWindow.h"
#include "ScreenSaverPrefs.h"
#ifndef _ScreenSaverWindow_H
#define _ScreenSaverWindow_H
#include <Box.h>
#include <CheckBox.h>
#include <FilePanel.h>
#include <Slider.h>
#include <ListView.h>
#include <StringView.h>
#include "PasswordWindow.h"
#include "ScreenSaverPrefs.h"
class BButton;
class ModulesView;
class MouseAreaView;
class PreviewView;
class ScreenSaverRunner;
class TimeSlider;
class ScreenSaverWin: public BWindow {
public:
ScreenSaverWin();
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested();
void PopulateScreenSaverList();
void LoadSettings();
virtual ~ScreenSaverWin();
void SelectCurrentModule();
private:
void SetupForm();
void SetupTab1();
void SetupTab2();
void UpdateStatus();
void SaverSelected();
class ScreenSaverWindow : public BWindow {
public:
ScreenSaverWindow();
virtual ~ScreenSaverWindow();
static int CompareScreenSaverItems(const void* left, const void* right);
virtual void MessageReceived(BMessage *message);
virtual void ScreenChanged(BRect frame, color_space colorSpace);
virtual bool QuitRequested();
ScreenSaverPrefs fPrefs;
int fFadeState,fNoFadeState;
BView *fSampleView;
BView *fTab1,*fTab2;
BTabView *fTabView;
BBox *fModuleSettingsBox;
void LoadSettings();
PreviewView *fPreviewDisplay;
BListView *fListView1;
BString fSelectedAddonFileName;
image_id fCurrentAddon;
BButton *fTestButton;
BButton *fAddButton;
BBox *fEnableScreenSaverBox;
BSlider *fPasswordSlider;
BSlider *fTurnOffSlider;
BSlider *fRunSlider;
BStringView *fStringView1;
BCheckBox *fEnableCheckbox;
BCheckBox *fPasswordCheckbox;
BCheckBox *fTurnOffScreenCheckBox;
BStringView *fTurnOffMinutes;
BStringView *fRunMinutes;
BStringView *fPasswordMinutes;
BButton *fPasswordButton;
BStringView *fFadeNowString;
BStringView *fFadeNowString2;
BStringView *fDontFadeString;
BStringView *fDontFadeString2;
MouseAreaView *fFadeNow,*fFadeNever;
PasswordWindow *fPwWin;
BMessenger *fPwMessenger;
BMessage fSettings;
BFilePanel *fFilePanel;
BView *fSettingsArea;
private:
void _SetupFadeTab(BRect frame);
void _UpdateTurnOffScreen();
void _UpdateStatus();
ScreenSaverPrefs fPrefs;
uint32 fTurnOffScreenFlags;
BView* fFadeView;
ModulesView* fModulesView;
BTabView* fTabView;
BCheckBox* fEnableCheckBox;
TimeSlider* fRunSlider;
BCheckBox* fTurnOffCheckBox;
TimeSlider* fTurnOffSlider;
BCheckBox* fPasswordCheckBox;
TimeSlider* fPasswordSlider;
BButton* fPasswordButton;
PasswordWindow* fPasswordWindow;
BStringView *fFadeNowString;
BStringView *fFadeNowString2;
BStringView *fDontFadeString;
BStringView *fDontFadeString2;
MouseAreaView* fFadeNow;
MouseAreaView* fFadeNever;
};
#endif // _ScreenSaverWindow_H
static const int32 kMsgUpdateList = 'UPDL';
#endif // SCREEN_SAVER_WINDOW_H
+40
View File
@@ -0,0 +1,40 @@
#ifndef UTILITY_H
#define UTILITY_H
#include <Rect.h>
int secondsToSlider(int val);
inline BPoint
scale_direct(float x, float y, BRect area)
{
return BPoint(area.Width()*x+area.left,area.Height()*y+area.top);
}
inline BRect
scale_direct(float x1,float x2,float y1,float y2,BRect area)
{
return BRect(area.Width()*x1+area.left,area.Height()*y1+area.top, area.Width()*x2+area.left,area.Height()*y2+area.top);
}
static const float kPositionalX[] = {0,.1,.25,.3,.7,.75,.9,1.0};
static const float kPositionalY[] = {0,.1,.7,.8,.9,1.0};
inline BPoint
scale(int x, int y,BRect area)
{
return scale_direct(kPositionalX[x],kPositionalY[y],area);
}
inline BRect
scale(int x1, int x2, int y1, int y2,BRect area)
{
return scale_direct(kPositionalX[x1], kPositionalX[x2],
kPositionalY[y1], kPositionalY[y2], area);
}
#endif // UTILITY_H