mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
Screensaver: Disable double buffering and hide cursor
This commit is contained in:
parent
92fe63fbec
commit
41c4ce3c58
1 changed files with 21 additions and 20 deletions
|
@ -24,8 +24,6 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibCore/ElapsedTimer.h>
|
|
||||||
#include <LibGUI/Action.h>
|
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/Event.h>
|
#include <LibGUI/Event.h>
|
||||||
#include <LibGUI/Icon.h>
|
#include <LibGUI/Icon.h>
|
||||||
|
@ -36,17 +34,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define WIDTH 64
|
|
||||||
#define HEIGHT 48
|
|
||||||
#define INTERVAL 10000
|
|
||||||
|
|
||||||
class Screensaver final : public GUI::Widget {
|
class Screensaver final : public GUI::Widget {
|
||||||
C_OBJECT(Screensaver)
|
C_OBJECT(Screensaver)
|
||||||
public:
|
public:
|
||||||
virtual ~Screensaver() override;
|
virtual ~Screensaver() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Screensaver();
|
Screensaver(int width = 64, int height = 48, int interval = 10000);
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
@ -57,12 +51,12 @@ private:
|
||||||
virtual void mousemove_event(GUI::MouseEvent& event) override;
|
virtual void mousemove_event(GUI::MouseEvent& event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
Screensaver::Screensaver()
|
Screensaver::Screensaver(int width, int height, int interval)
|
||||||
{
|
{
|
||||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT });
|
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { width, height });
|
||||||
srand(time(nullptr));
|
srand(time(nullptr));
|
||||||
stop_timer();
|
stop_timer();
|
||||||
start_timer(INTERVAL);
|
start_timer(interval);
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +87,8 @@ void Screensaver::paint_event(GUI::PaintEvent& event)
|
||||||
|
|
||||||
void Screensaver::timer_event(Core::TimerEvent&)
|
void Screensaver::timer_event(Core::TimerEvent&)
|
||||||
{
|
{
|
||||||
Core::ElapsedTimer timer;
|
|
||||||
timer.start();
|
|
||||||
draw();
|
draw();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screensaver::draw()
|
void Screensaver::draw()
|
||||||
|
@ -104,7 +97,6 @@ void Screensaver::draw()
|
||||||
Color::Blue,
|
Color::Blue,
|
||||||
Color::Cyan,
|
Color::Cyan,
|
||||||
Color::Green,
|
Color::Green,
|
||||||
Color::LightGray,
|
|
||||||
Color::Magenta,
|
Color::Magenta,
|
||||||
Color::Red,
|
Color::Red,
|
||||||
Color::Yellow,
|
Color::Yellow,
|
||||||
|
@ -128,12 +120,15 @@ void Screensaver::draw()
|
||||||
m_bitmap->rect(),
|
m_bitmap->rect(),
|
||||||
colors[start_color_index],
|
colors[start_color_index],
|
||||||
colors[end_color_index]);
|
colors[end_color_index]);
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
if (pledge("stdio rpath wpath cpath shared_buffer cpath unix fattr", nullptr) < 0) {
|
||||||
|
perror("pledge");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
auto app = GUI::Application::construct(argc, argv);
|
auto app = GUI::Application::construct(argc, argv);
|
||||||
|
|
||||||
if (pledge("stdio rpath shared_buffer", nullptr) < 0) {
|
if (pledge("stdio rpath shared_buffer", nullptr) < 0) {
|
||||||
|
@ -151,19 +146,25 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto app_icon = GUI::Icon::default_icon("app-screensaver");
|
||||||
auto window = GUI::Window::construct();
|
auto window = GUI::Window::construct();
|
||||||
window->set_double_buffering_enabled(true);
|
window->set_double_buffering_enabled(false);
|
||||||
window->set_title("Screensaver");
|
window->set_title("Screensaver");
|
||||||
window->set_resizable(false);
|
window->set_resizable(false);
|
||||||
|
window->set_frameless(true);
|
||||||
window->set_fullscreen(true);
|
window->set_fullscreen(true);
|
||||||
|
window->set_minimizable(false);
|
||||||
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
||||||
auto& screensaver_window = window->set_main_widget<Screensaver>();
|
auto& screensaver_window = window->set_main_widget<Screensaver>(64, 48, 10000);
|
||||||
|
screensaver_window.set_fill_with_background_color(false);
|
||||||
|
screensaver_window.set_override_cursor(Gfx::StandardCursor::Hidden);
|
||||||
screensaver_window.update();
|
screensaver_window.update();
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
|
window->move_to_front();
|
||||||
auto app_icon = GUI::Icon::default_icon("app-screensaver");
|
window->set_cursor(Gfx::StandardCursor::Hidden);
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->update();
|
||||||
|
|
||||||
return app->exec();
|
return app->exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue