2 * Copyright 2003-2014, Haiku.
3 * Distributed under the terms of the MIT License.
7 * Jérôme Duval, jerome.duval@free.fr
8 * Ryan Leavengood, leavengood@gmail.com
9 * Puck Meerburg, puck@puckipedia.nl
13 #include "ScreenBlanker.h"
14 #include "ScreenSaverWindow.h"
16 #include <Application.h>
19 #include <WindowPrivate.h>
24 // #pragma mark - ScreenSaverFilter
27 /* This message filter is what will close the screensaver upon user activity. */
29 ScreenSaverFilter::Filter(BMessage
* message
, BHandler
** target
)
31 // This guard is used to avoid sending multiple B_QUIT_REQUESTED messages
33 switch (message
->what
) {
36 // ignore the initial B_MOUSE_MOVED sent by the app_server
37 // in test mode, all mouse move events are ignored
38 bool transitOnly
= false;
40 || (message
->FindBool("be:transit_only", &transitOnly
)
41 == B_OK
&& transitOnly
))
42 return B_DISPATCH_MESSAGE
;
48 // we ignore the Print-Screen key to make screen shots of
49 // screen savers possible
51 if (message
->FindInt32("key", &key
) == B_OK
&& key
== 0xe)
52 return B_DISPATCH_MESSAGE
;
56 case B_MODIFIERS_CHANGED
:
57 case B_UNMAPPED_KEY_DOWN
:
60 be_app
->PostMessage(B_QUIT_REQUESTED
);
63 } else if (message
->what
== B_KEY_DOWN
) {
64 ScreenBlanker
* app
= dynamic_cast<ScreenBlanker
*>(be_app
);
65 if (app
!= NULL
&& app
->IsPasswordWindowShown()) {
66 // Handle the escape key when the password window is showing
67 const char* string
= NULL
;
68 if (message
->FindString("bytes", &string
) == B_OK
69 && string
[0] == B_ESCAPE
) {
70 be_app
->PostMessage(kMsgResumeSaver
);
75 return B_DISPATCH_MESSAGE
;
79 // #pragma mark - ScreenSaverWindow
83 This is the BDirectWindow subclass that rendering occurs in.
84 A view is added to it so that BView based screensavers will work.
86 ScreenSaverWindow::ScreenSaverWindow(BRect frame
, bool test
)
88 BDirectWindow(frame
, "ScreenSaver Window",
89 B_NO_BORDER_WINDOW_LOOK
, kWindowScreenFeel
,
90 B_NOT_RESIZABLE
| B_NOT_MOVABLE
| B_NOT_MINIMIZABLE
91 | B_NOT_ZOOMABLE
| B_NOT_CLOSABLE
, B_ALL_WORKSPACES
),
97 fTopView
= new BView(frame
, "ScreenSaver View", B_FOLLOW_ALL
,
99 fTopView
->SetViewColor(B_TRANSPARENT_COLOR
);
101 fFilter
= new ScreenSaverFilter(test
);
102 fTopView
->AddFilter(fFilter
);
106 // Ensure that this view receives keyboard and mouse input
107 fTopView
->MakeFocus(true);
108 fTopView
->SetEventMask(B_KEYBOARD_EVENTS
| B_POINTER_EVENTS
,
109 B_NO_POINTER_HISTORY
);
113 ScreenSaverWindow::~ScreenSaverWindow()
120 ScreenSaverWindow::MessageReceived(BMessage
* message
)
122 switch (message
->what
) {
123 case kMsgEnableFilter
:
124 fFilter
->SetEnabled(true);
128 BWindow::MessageReceived(message
);
134 ScreenSaverWindow::QuitRequested()
136 be_app
->PostMessage(B_QUIT_REQUESTED
);
142 ScreenSaverWindow::DirectConnected(direct_buffer_info
* info
)
144 BScreenSaver
* saver
= _ScreenSaver();
146 saver
->DirectConnected(info
);
151 ScreenSaverWindow::SetSaverRunner(ScreenSaverRunner
* runner
)
153 fSaverRunner
= runner
;
158 ScreenSaverWindow::_ScreenSaver()
160 if (fSaverRunner
!= NULL
)
161 return fSaverRunner
->ScreenSaver();