1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

Add ability to switch video modes from the system menu.

I had to change PhysicalPage around a bit for this. Physical pages can now
be instantiated for any arbitrary physical address without worrying that
such pages end up in the kernel page allocator when released.

Most of the pieces were already in place, I just glued everything together.
This commit is contained in:
Andreas Kling 2019-02-17 13:12:59 +01:00
parent 8321908abe
commit 0730b3c15f
7 changed files with 91 additions and 26 deletions

View file

@ -187,12 +187,12 @@ WSWindowManager::WSWindowManager()
m_system_menu = make<WSMenu>(nullptr, -1, String((const char*)system_menu_name));
m_system_menu->add_item(make<WSMenuItem>(0, "Launch Terminal"));
m_system_menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
m_system_menu->add_item(make<WSMenuItem>(1, "Hello again"));
m_system_menu->add_item(make<WSMenuItem>(2, "To all my friends"));
m_system_menu->add_item(make<WSMenuItem>(3, "Together we can play some rock&roll"));
m_system_menu->add_item(make<WSMenuItem>(1, "640x480"));
m_system_menu->add_item(make<WSMenuItem>(2, "800x600"));
m_system_menu->add_item(make<WSMenuItem>(3, "1024x768"));
m_system_menu->add_item(make<WSMenuItem>(WSMenuItem::Separator));
m_system_menu->add_item(make<WSMenuItem>(4, "About..."));
m_system_menu->on_item_activation = [] (WSMenuItem& item) {
m_system_menu->on_item_activation = [this] (WSMenuItem& item) {
if (item.identifier() == 0) {
if (fork() == 0) {
execl("/bin/Terminal", "/bin/Terminal", nullptr);
@ -200,6 +200,11 @@ WSWindowManager::WSWindowManager()
}
return;
}
switch (item.identifier()) {
case 1: set_resolution(640, 480); break;
case 2: set_resolution(800, 600); break;
case 3: set_resolution(1024, 768); break;
}
if (item.identifier() == 4) {
if (fork() == 0) {
execl("/bin/About", "/bin/About", nullptr);
@ -231,6 +236,21 @@ WSWindowManager::~WSWindowManager()
{
}
void WSWindowManager::set_resolution(int width, int height)
{
if (m_screen_rect.width() == width && m_screen_rect.height() == height)
return;
m_screen.set_resolution(width, height);
m_screen_rect = m_screen.rect();
m_front_bitmap = GraphicsBitmap::create_wrapper({ width, height }, m_screen.scanline(0));
m_back_bitmap = GraphicsBitmap::create_wrapper({ width, height }, m_screen.scanline(height));
m_front_painter = make<Painter>(*m_front_bitmap);
m_back_painter = make<Painter>(*m_back_bitmap);
m_buffers_are_flipped = false;
invalidate();
compose();
}
template<typename Callback>
void WSWindowManager::for_each_active_menubar_menu(Callback callback)
{
@ -767,7 +787,13 @@ void WSWindowManager::invalidate()
invalidate(m_screen_rect);
}
void WSWindowManager::invalidate(const Rect& a_rect)
void WSWindowManager::recompose_immediately()
{
m_dirty_rects.clear_with_capacity();
invalidate(m_screen_rect, false);
}
void WSWindowManager::invalidate(const Rect& a_rect, bool should_schedule_compose_event)
{
auto rect = Rect::intersection(a_rect, m_screen_rect);
if (rect.is_empty())
@ -786,7 +812,7 @@ void WSWindowManager::invalidate(const Rect& a_rect)
m_dirty_rects.append(rect);
if (!m_pending_compose_event) {
if (should_schedule_compose_event && !m_pending_compose_event) {
WSMessageLoop::the().post_message(this, make<WSMessage>(WSMessage::WM_DeferredCompose));
m_pending_compose_event = true;
}