diff options
Diffstat (limited to 'Widgets')
-rw-r--r-- | Widgets/AbstractScreen.cpp | 119 | ||||
-rw-r--r-- | Widgets/AbstractScreen.h | 43 | ||||
-rw-r--r-- | Widgets/FrameBuffer.cpp | 46 | ||||
-rw-r--r-- | Widgets/FrameBuffer.h | 25 | ||||
-rw-r--r-- | Widgets/GUIEventDevice.cpp | 38 | ||||
-rw-r--r-- | Widgets/GUIEventDevice.h | 16 | ||||
-rw-r--r-- | Widgets/GraphicsBitmap.cpp | 10 | ||||
-rw-r--r-- | Widgets/Window.h | 1 | ||||
-rw-r--r-- | Widgets/WindowManager.cpp | 409 | ||||
-rw-r--r-- | Widgets/WindowManager.h | 96 |
10 files changed, 5 insertions, 798 deletions
diff --git a/Widgets/AbstractScreen.cpp b/Widgets/AbstractScreen.cpp deleted file mode 100644 index 10993e6363..0000000000 --- a/Widgets/AbstractScreen.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "AbstractScreen.h" -#include "EventLoop.h" -#include "Event.h" -#include "Widget.h" -#include "WindowManager.h" -#include <AK/Assertions.h> - -static AbstractScreen* s_the; - -void AbstractScreen::initialize() -{ - s_the = nullptr; -} - -AbstractScreen& AbstractScreen::the() -{ - ASSERT(s_the); - return *s_the; -} - -AbstractScreen::AbstractScreen(unsigned width, unsigned height) - : Object(nullptr) - , m_width(width) - , m_height(height) -{ - ASSERT(!s_the); - s_the = this; - - m_cursor_location = rect().center(); - - Keyboard::the().set_client(this); -} - -AbstractScreen::~AbstractScreen() -{ -} - -void AbstractScreen::on_receive_mouse_data(int dx, int dy, bool left_button, bool right_button) -{ - auto prev_location = m_cursor_location; - m_cursor_location.moveBy(dx, dy); - m_cursor_location.constrain(rect()); - if (m_cursor_location.x() >= width()) - m_cursor_location.setX(width() - 1); - if (m_cursor_location.y() >= height()) - m_cursor_location.setY(height() - 1); - if (m_cursor_location != prev_location) { - auto event = make<MouseEvent>(Event::MouseMove, m_cursor_location.x(), m_cursor_location.y()); - EventLoop::main().postEvent(&WindowManager::the(), move(event)); - } - bool prev_left_button = m_left_mouse_button_pressed; - bool prev_right_button = m_right_mouse_button_pressed; - m_left_mouse_button_pressed = left_button; - m_right_mouse_button_pressed = right_button; - if (prev_left_button != left_button) { - auto event = make<MouseEvent>(left_button ? Event::MouseDown : Event::MouseUp, m_cursor_location.x(), m_cursor_location.y(), MouseButton::Left); - EventLoop::main().postEvent(&WindowManager::the(), move(event)); - } - if (prev_right_button != right_button) { - auto event = make<MouseEvent>(right_button ? Event::MouseDown : Event::MouseUp, m_cursor_location.x(), m_cursor_location.y(), MouseButton::Right); - EventLoop::main().postEvent(&WindowManager::the(), move(event)); - } - if (m_cursor_location != prev_location || prev_left_button != left_button) - WindowManager::the().draw_cursor(); -} - -void AbstractScreen::on_key_pressed(Keyboard::Key key) -{ - auto event = make<KeyEvent>(Event::KeyDown, 0); - int key_code = 0; - - switch (key.character) { - case 8: key_code = KeyboardKey::Backspace; break; - case 10: key_code = KeyboardKey::Return; break; - } - event->m_key = key_code; - - if (key.character) { - char buf[] = { 0, 0 }; - char& ch = buf[0]; - ch = key.character; - if (key.shift()) { - if (ch >= 'a' && ch <= 'z') { - ch &= ~0x20; - } else { - switch (ch) { - case '1': ch = '!'; break; - case '2': ch = '@'; break; - case '3': ch = '#'; break; - case '4': ch = '$'; break; - case '5': ch = '%'; break; - case '6': ch = '^'; break; - case '7': ch = '&'; break; - case '8': ch = '*'; break; - case '9': ch = '('; break; - case '0': ch = ')'; break; - case '-': ch = '_'; break; - case '=': ch = '+'; break; - case '`': ch = '~'; break; - case ',': ch = '<'; break; - case '.': ch = '>'; break; - case '/': ch = '?'; break; - case '[': ch = '{'; break; - case ']': ch = '}'; break; - case '\\': ch = '|'; break; - case '\'': ch = '"'; break; - case ';': ch = ':'; break; - } - } - } - event->m_text = buf; - } - - event->m_shift = key.shift(); - event->m_ctrl = key.ctrl(); - event->m_alt = key.alt(); - - EventLoop::main().postEvent(&WindowManager::the(), move(event)); -} diff --git a/Widgets/AbstractScreen.h b/Widgets/AbstractScreen.h deleted file mode 100644 index 444b1efcb3..0000000000 --- a/Widgets/AbstractScreen.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "Object.h" -#include "Rect.h" -#include "Size.h" -#include "Keyboard.h" -#include "PS2MouseDevice.h" - -class AbstractScreen : public Object, public KeyboardClient { -public: - virtual ~AbstractScreen(); - - int width() const { return m_width; } - int height() const { return m_height; } - - static AbstractScreen& the(); - - Size size() const { return { width(), height() }; } - Rect rect() const { return { 0, 0, width(), height() }; } - - static void initialize(); - - Point cursor_location() const { return m_cursor_location; } - bool left_mouse_button_pressed() const { return m_left_mouse_button_pressed; } - bool right_mouse_button_pressed() const { return m_right_mouse_button_pressed; } - - void on_receive_mouse_data(int dx, int dy, bool left_button, bool right_button); - -protected: - AbstractScreen(unsigned width, unsigned height); - -private: - // ^KeyboardClient - virtual void on_key_pressed(Keyboard::Key) final; - - int m_width { 0 }; - int m_height { 0 }; - - Point m_cursor_location; - bool m_left_mouse_button_pressed { false }; - bool m_right_mouse_button_pressed { false }; -}; - diff --git a/Widgets/FrameBuffer.cpp b/Widgets/FrameBuffer.cpp deleted file mode 100644 index dc93460a07..0000000000 --- a/Widgets/FrameBuffer.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "FrameBuffer.h" -#include "GraphicsBitmap.h" -#include <AK/Assertions.h> - -FrameBuffer* s_the; - -void FrameBuffer::initialize() -{ - s_the = nullptr; -} - -FrameBuffer& FrameBuffer::the() -{ - ASSERT(s_the); - return *s_the; -} - -FrameBuffer::FrameBuffer(unsigned width, unsigned height) - : AbstractScreen(width, height) -{ - ASSERT(!s_the); - s_the = this; -} - -FrameBuffer::FrameBuffer(RGBA32* data, unsigned width, unsigned height) - : AbstractScreen(width, height) - , m_data(data) -{ - ASSERT(!s_the); - s_the = this; -} - - -FrameBuffer::~FrameBuffer() -{ -} - -void FrameBuffer::show() -{ -} - -RGBA32* FrameBuffer::scanline(int y) -{ - unsigned pitch = sizeof(RGBA32) * width(); - return reinterpret_cast<RGBA32*>(((byte*)m_data) + (y * pitch)); -} diff --git a/Widgets/FrameBuffer.h b/Widgets/FrameBuffer.h deleted file mode 100644 index c0758f19a6..0000000000 --- a/Widgets/FrameBuffer.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "AbstractScreen.h" -#include "Color.h" - -class GraphicsBitmap; - -class FrameBuffer final : public AbstractScreen { -public: - FrameBuffer(unsigned width, unsigned height); - FrameBuffer(RGBA32*, unsigned width, unsigned height); - virtual ~FrameBuffer() override; - - void show(); - - static FrameBuffer& the(); - - RGBA32* scanline(int y); - - static void initialize(); - -private: - RGBA32* m_data { nullptr }; -}; - diff --git a/Widgets/GUIEventDevice.cpp b/Widgets/GUIEventDevice.cpp deleted file mode 100644 index 20ba6c917b..0000000000 --- a/Widgets/GUIEventDevice.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "GUIEventDevice.h" -#include <Kernel/Process.h> -#include <AK/Lock.h> -#include <LibC/errno_numbers.h> - -//#define GUIEVENTDEVICE_DEBUG - -GUIEventDevice::GUIEventDevice() - : CharacterDevice(66, 1) -{ -} - -GUIEventDevice::~GUIEventDevice() -{ -} - -bool GUIEventDevice::can_read(Process& process) const -{ - return !process.gui_events().is_empty(); -} - -ssize_t GUIEventDevice::read(Process& process, byte* buffer, size_t size) -{ -#ifdef GUIEVENTDEVICE_DEBUG - dbgprintf("GUIEventDevice::read(): %s<%u>, size=%u, sizeof(GUI_Event)=%u\n", process.name().characters(), process.pid(), size, sizeof(GUI_Event)); -#endif - if (process.gui_events().is_empty()) - return 0; - LOCKER(process.gui_events_lock()); - ASSERT(size == sizeof(GUI_Event)); - *reinterpret_cast<GUI_Event*>(buffer) = process.gui_events().take_first(); - return size; -} - -ssize_t GUIEventDevice::write(Process&, const byte*, size_t) -{ - return -EINVAL; -} diff --git a/Widgets/GUIEventDevice.h b/Widgets/GUIEventDevice.h deleted file mode 100644 index e98b208f05..0000000000 --- a/Widgets/GUIEventDevice.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include <VirtualFileSystem/CharacterDevice.h> - -class GUIEventDevice final : public CharacterDevice { -public: - GUIEventDevice(); - virtual ~GUIEventDevice() override; - -private: - // ^CharacterDevice - virtual ssize_t read(Process&, byte* buffer, size_t bufferSize) override; - virtual ssize_t write(Process&, const byte* buffer, size_t bufferSize) override; - virtual bool can_read(Process&) const override; - virtual bool can_write(Process&) const override { return true; } -}; diff --git a/Widgets/GraphicsBitmap.cpp b/Widgets/GraphicsBitmap.cpp index 6fc98447f9..3dbc47cf47 100644 --- a/Widgets/GraphicsBitmap.cpp +++ b/Widgets/GraphicsBitmap.cpp @@ -1,10 +1,10 @@ #include "GraphicsBitmap.h" -#include "EventLoop.h" #include <AK/kmalloc.h> #ifdef KERNEL -#include "Process.h" -#include "MemoryManager.h" +#include <Kernel/Process.h> +#include <Kernel/MemoryManager.h> +#include <WindowServer/WSEventLoop.h> #endif #ifdef KERNEL @@ -24,7 +24,7 @@ GraphicsBitmap::GraphicsBitmap(Process& process, const Size& size) m_client_region->commit(process); { - auto& server = EventLoop::main().server_process(); + auto& server = WSEventLoop::the().server_process(); ProcessInspectionHandle composer_handle(server); m_server_region = server.allocate_region_with_vmo(LinearAddress(), size_in_bytes, move(vmo), 0, "GraphicsBitmap (shared)", true, true); } @@ -50,7 +50,7 @@ GraphicsBitmap::~GraphicsBitmap() if (m_client_region) m_client_process->deallocate_region(*m_client_region); if (m_server_region) - EventLoop::main().server_process().deallocate_region(*m_server_region); + WSEventLoop::the().server_process().deallocate_region(*m_server_region); #endif m_data = nullptr; } diff --git a/Widgets/Window.h b/Widgets/Window.h index 3da05c3c97..1bbe354eb1 100644 --- a/Widgets/Window.h +++ b/Widgets/Window.h @@ -28,7 +28,6 @@ public: void set_rect_without_repaint(const Rect& rect) { m_rect = rect; } Point position() const { return m_rect.location(); } - void set_position(const Point& position) { set_rect({ position.x(), position.y(), width(), height() }); } void set_position_without_repaint(const Point& position) { set_rect_without_repaint({ position.x(), position.y(), width(), height() }); } virtual void event(Event&) override; diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp deleted file mode 100644 index 2b77912277..0000000000 --- a/Widgets/WindowManager.cpp +++ /dev/null @@ -1,409 +0,0 @@ -#include "WindowManager.h" -#include "Painter.h" -#include "Widget.h" -#include "Window.h" -#include "AbstractScreen.h" -#include "EventLoop.h" -#include "FrameBuffer.h" -#include "Process.h" -#include "MemoryManager.h" - -//#define DEBUG_FLUSH_YELLOW - -static const int windowTitleBarHeight = 16; - -static inline Rect titleBarRectForWindow(const Rect& window) -{ - return { - window.x() - 1, - window.y() - windowTitleBarHeight, - window.width() + 2, - windowTitleBarHeight - }; -} - -static inline Rect titleBarTitleRectForWindow(const Rect& window) -{ - auto titleBarRect = titleBarRectForWindow(window); - return { - titleBarRect.x() + 2, - titleBarRect.y(), - titleBarRect.width() - 4, - titleBarRect.height() - }; -} - -static inline Rect borderRectForWindow(const Rect& window) -{ - auto titleBarRect = titleBarRectForWindow(window); - return { titleBarRect.x() - 1, - titleBarRect.y() - 1, - titleBarRect.width() + 2, - windowTitleBarHeight + window.height() + 3 - }; -} - -static inline Rect outerRectForWindow(const Rect& window) -{ - auto rect = borderRectForWindow(window); - rect.inflate(2, 2); - return rect; -} - -static WindowManager* s_the_window_manager; - -WindowManager& WindowManager::the() -{ - if (!s_the_window_manager) - s_the_window_manager = new WindowManager; - return *s_the_window_manager; -} - -void WindowManager::initialize() -{ - s_the_window_manager = nullptr; -} - -static const char* cursor_bitmap_inner_ascii = { - " # " - " ## " - " ### " - " #### " - " ##### " - " ###### " - " ####### " - " ######## " - " ######### " - " ########## " - " ###### " - " ## ## " - " # ## " - " ## " - " ## " - " ## " - " " -}; - -static const char* cursor_bitmap_outer_ascii = { - "## " - "# # " - "# # " - "# # " - "# # " - "# # " - "# # " - "# # " - "# # " - "# # " - "# #### " - "# ## # " - "# # # # " - "## # # " - " # # " - " # # " - " ## " -}; - -WindowManager::WindowManager() - : m_framebuffer(FrameBuffer::the()) - , m_screen_rect(m_framebuffer.rect()) -{ - auto size = m_screen_rect.size(); - m_front_bitmap = GraphicsBitmap::create_wrapper(size, m_framebuffer.scanline(0)); - auto* region = current->allocate_region(LinearAddress(), size.width() * size.height() * sizeof(RGBA32), "BackBitmap", true, true, true); - m_back_bitmap = GraphicsBitmap::create_wrapper(m_screen_rect.size(), (RGBA32*)region->linearAddress.get()); - - m_front_painter = make<Painter>(*m_front_bitmap); - m_back_painter = make<Painter>(*m_back_bitmap); - - m_activeWindowBorderColor = Color(0, 64, 192); - m_activeWindowTitleColor = Color::White; - - m_inactiveWindowBorderColor = Color(64, 64, 64); - m_inactiveWindowTitleColor = Color::White; - - m_cursor_bitmap_inner = CharacterBitmap::createFromASCII(cursor_bitmap_inner_ascii, 12, 17); - m_cursor_bitmap_outer = CharacterBitmap::createFromASCII(cursor_bitmap_outer_ascii, 12, 17); - - invalidate(); - compose(); -} - -WindowManager::~WindowManager() -{ -} - -void WindowManager::paintWindowFrame(Window& window) -{ - //printf("[WM] paintWindowFrame {%p}, rect: %d,%d %dx%d\n", &window, window.rect().x(), window.rect().y(), window.rect().width(), window.rect().height()); - - auto titleBarRect = titleBarRectForWindow(window.rect()); - auto titleBarTitleRect = titleBarTitleRectForWindow(window.rect()); - auto outerRect = outerRectForWindow(window.rect()); - auto borderRect = borderRectForWindow(window.rect()); - - Rect inner_border_rect { - window.x() - 1, - window.y() - 1, - window.width() + 2, - window.height() + 2 - }; - - auto titleColor = &window == activeWindow() ? m_activeWindowTitleColor : m_inactiveWindowTitleColor; - auto borderColor = &window == activeWindow() ? m_activeWindowBorderColor : m_inactiveWindowBorderColor; - - m_back_painter->draw_rect(borderRect, Color::MidGray); - m_back_painter->draw_rect(outerRect, borderColor); - m_back_painter->fill_rect(titleBarRect, borderColor); - m_back_painter->draw_rect(inner_border_rect, borderColor); - m_back_painter->draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor); -} - -void WindowManager::addWindow(Window& window) -{ - m_windows.set(&window); - m_windows_in_order.append(&window); - if (!activeWindow()) - setActiveWindow(&window); -} - -void WindowManager::move_to_front(Window& window) -{ - m_windows_in_order.remove(&window); - m_windows_in_order.append(&window); -} - -void WindowManager::did_paint(Window& window) -{ - invalidate(window); -} - -void WindowManager::removeWindow(Window& window) -{ - if (!m_windows.contains(&window)) - return; - - invalidate(window); - m_windows.remove(&window); - m_windows_in_order.remove(&window); - if (!activeWindow() && !m_windows.is_empty()) - setActiveWindow(*m_windows.begin()); -} - -void WindowManager::notifyTitleChanged(Window& window) -{ - printf("[WM] Window{%p} title set to '%s'\n", &window, window.title().characters()); -} - -void WindowManager::notifyRectChanged(Window& window, const Rect& old_rect, const Rect& new_rect) -{ - printf("[WM] Window %p rect changed (%d,%d %dx%d) -> (%d,%d %dx%d)\n", &window, old_rect.x(), old_rect.y(), old_rect.width(), old_rect.height(), new_rect.x(), new_rect.y(), new_rect.width(), new_rect.height()); - invalidate(outerRectForWindow(old_rect)); - invalidate(outerRectForWindow(new_rect)); -} - -void WindowManager::handleTitleBarMouseEvent(Window& window, MouseEvent& event) -{ - if (event.type() == Event::MouseDown && event.button() == MouseButton::Left) { - printf("[WM] Begin dragging Window{%p}\n", &window); - m_dragWindow = window.makeWeakPtr();; - m_dragOrigin = event.position(); - m_dragWindowOrigin = window.position(); - m_dragStartRect = outerRectForWindow(window.rect()); - window.set_is_being_dragged(true); - return; - } -} - -void WindowManager::processMouseEvent(MouseEvent& event) -{ - if (event.type() == Event::MouseUp && event.button() == MouseButton::Left) { - if (m_dragWindow) { - printf("[WM] Finish dragging Window{%p}\n", m_dragWindow.ptr()); - invalidate(m_dragStartRect); - invalidate(*m_dragWindow); - m_dragWindow->set_is_being_dragged(false); - m_dragEndRect = outerRectForWindow(m_dragWindow->rect()); - m_dragWindow = nullptr; - return; - } - } - - if (event.type() == Event::MouseMove) { - if (m_dragWindow) { - auto old_window_rect = m_dragWindow->rect(); - Point pos = m_dragWindowOrigin; - printf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_dragOrigin.x(), m_dragOrigin.y(), event.x(), event.y()); - pos.moveBy(event.x() - m_dragOrigin.x(), event.y() - m_dragOrigin.y()); - m_dragWindow->set_position_without_repaint(pos); - invalidate(outerRectForWindow(old_window_rect)); - invalidate(outerRectForWindow(m_dragWindow->rect())); - return; - } - } - - for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) { - if (titleBarRectForWindow(window->rect()).contains(event.position())) { - if (event.type() == Event::MouseDown) { - move_to_front(*window); - setActiveWindow(window); - } - handleTitleBarMouseEvent(*window, event); - return; - } - - if (window->rect().contains(event.position())) { - if (event.type() == Event::MouseDown) { - move_to_front(*window); - setActiveWindow(window); - } - // FIXME: Re-use the existing event instead of crafting a new one? - auto localEvent = make<MouseEvent>(event.type(), event.x() - window->rect().x(), event.y() - window->rect().y(), event.button()); - window->event(*localEvent); - return; - } - } -} - -void WindowManager::compose() -{ - auto invalidated_rects = move(m_invalidated_rects); - printf("[WM] compose #%u (%u rects)\n", ++m_recompose_count, invalidated_rects.size()); - - dbgprintf("kmalloc stats: alloc:%u free:%u eternal:%u\n", sum_alloc, sum_free, kmalloc_sum_eternal); - - auto any_window_contains_rect = [this] (const Rect& r) { - for (auto* window = m_windows_in_order.head(); window; window = window->next()) { - if (outerRectForWindow(window->rect()).contains(r)) - return true; - } - return false; - }; - - for (auto& r : invalidated_rects) { - if (any_window_contains_rect(r)) - continue; - //dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height()); - m_back_painter->fill_rect(r, Color(0, 72, 96)); - } - for (auto* window = m_windows_in_order.head(); window; window = window->next()) { - if (!window->backing()) - continue; - paintWindowFrame(*window); - m_back_painter->blit(window->position(), *window->backing()); - } - for (auto& r : invalidated_rects) - flush(r); - draw_cursor(); -} - -void WindowManager::draw_cursor() -{ - auto cursor_location = m_framebuffer.cursor_location(); - Rect cursor_rect { cursor_location.x(), cursor_location.y(), (int)m_cursor_bitmap_inner->width(), (int)m_cursor_bitmap_inner->height() }; - flush(m_last_cursor_rect.united(cursor_rect)); - Color inner_color = Color::White; - Color outer_color = Color::Black; - if (m_framebuffer.left_mouse_button_pressed()) - swap(inner_color, outer_color); - m_front_painter->draw_bitmap(cursor_location, *m_cursor_bitmap_inner, inner_color); - m_front_painter->draw_bitmap(cursor_location, *m_cursor_bitmap_outer, outer_color); - m_last_cursor_rect = cursor_rect; -} - -void WindowManager::event(Event& event) -{ - if (event.isMouseEvent()) - return processMouseEvent(static_cast<MouseEvent&>(event)); - - if (event.isKeyEvent()) { - // FIXME: This is a good place to hook key events globally. :) - if (m_activeWindow) - return m_activeWindow->event(event); - return Object::event(event); - } - - if (event.type() == Event::WM_Compose) { - m_pending_compose_event = false; - compose(); - return; - } - - return Object::event(event); -} - -void WindowManager::setActiveWindow(Window* window) -{ - if (window == m_activeWindow.ptr()) - return; - - if (auto* previously_active_window = m_activeWindow.ptr()) { - invalidate(*previously_active_window); - EventLoop::main().postEvent(previously_active_window, make<Event>(Event::WindowBecameInactive)); - } - m_activeWindow = window->makeWeakPtr(); - if (m_activeWindow) { - invalidate(*m_activeWindow); - EventLoop::main().postEvent(m_activeWindow.ptr(), make<Event>(Event::WindowBecameActive)); - } -} - -bool WindowManager::isVisible(Window& window) const -{ - return m_windows.contains(&window); -} - -void WindowManager::invalidate() -{ - m_invalidated_rects.clear_with_capacity(); - m_invalidated_rects.append(m_screen_rect); -} - -void WindowManager::invalidate(const Rect& a_rect) -{ - auto rect = Rect::intersection(a_rect, m_screen_rect); - if (rect.is_empty()) - return; - - for (auto& r : m_invalidated_rects) { - if (r.contains(rect)) - return; - if (r.intersects(rect)) { - // Unite with the existing dirty rect. - // FIXME: It would be much nicer to compute the exact rects needing repaint. - r = r.united(rect); - return; - } - } - - m_invalidated_rects.append(rect); - - if (!m_pending_compose_event) { - EventLoop::main().postEvent(this, make<Event>(Event::WM_Compose)); - m_pending_compose_event = true; - } -} - -void WindowManager::invalidate(const Window& window) -{ - invalidate(outerRectForWindow(window.rect())); -} - -void WindowManager::flush(const Rect& a_rect) -{ - auto rect = Rect::intersection(a_rect, m_screen_rect); - - RGBA32* front_ptr = m_front_bitmap->scanline(rect.y()) + rect.x(); - const RGBA32* back_ptr = m_back_bitmap->scanline(rect.y()) + rect.x(); - size_t pitch = m_back_bitmap->pitch(); - -#ifdef DEBUG_FLUSH_YELLOW - m_front_painter->fill_rect(rect, Color::Yellow); -#endif - - for (int y = 0; y < rect.height(); ++y) { - fast_dword_copy(front_ptr, back_ptr, rect.width()); - front_ptr = (RGBA32*)((byte*)front_ptr + pitch); - back_ptr = (const RGBA32*)((const byte*)back_ptr + pitch); - } -} diff --git a/Widgets/WindowManager.h b/Widgets/WindowManager.h deleted file mode 100644 index a5277861f4..0000000000 --- a/Widgets/WindowManager.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include "Object.h" -#include "Rect.h" -#include "Color.h" -#include "Painter.h" -#include <AK/HashTable.h> -#include <AK/InlineLinkedList.h> -#include <AK/WeakPtr.h> - -class FrameBuffer; -class MouseEvent; -class PaintEvent; -class Widget; -class Window; -class CharacterBitmap; -class GraphicsBitmap; - -class WindowManager : public Object { -public: - static WindowManager& the(); - void addWindow(Window&); - void removeWindow(Window&); - - void notifyTitleChanged(Window&); - void notifyRectChanged(Window&, const Rect& oldRect, const Rect& newRect); - - Window* activeWindow() { return m_activeWindow.ptr(); } - void setActiveWindow(Window*); - - bool isVisible(Window&) const; - - void did_paint(Window&); - - void move_to_front(Window&); - - static void initialize(); - - void draw_cursor(); - - void invalidate(const Window&); - void invalidate(const Rect&); - void invalidate(); - void flush(const Rect&); - -private: - WindowManager(); - virtual ~WindowManager() override; - - void processMouseEvent(MouseEvent&); - void handleTitleBarMouseEvent(Window&, MouseEvent&); - - virtual void event(Event&) override; - - void compose(); - void paintWindowFrame(Window&); - - FrameBuffer& m_framebuffer; - Rect m_screen_rect; - - Color m_activeWindowBorderColor; - Color m_activeWindowTitleColor; - - Color m_inactiveWindowBorderColor; - Color m_inactiveWindowTitleColor; - - HashTable<Window*> m_windows; - InlineLinkedList<Window> m_windows_in_order; - - WeakPtr<Window> m_activeWindow; - - WeakPtr<Window> m_dragWindow; - - Point m_dragOrigin; - Point m_dragWindowOrigin; - Rect m_lastDragRect; - Rect m_dragStartRect; - Rect m_dragEndRect; - - Rect m_last_cursor_rect; - - unsigned m_recompose_count { 0 }; - - RetainPtr<GraphicsBitmap> m_front_bitmap; - RetainPtr<GraphicsBitmap> m_back_bitmap; - - Vector<Rect> m_invalidated_rects; - - bool m_pending_compose_event { false }; - - RetainPtr<CharacterBitmap> m_cursor_bitmap_inner; - RetainPtr<CharacterBitmap> m_cursor_bitmap_outer; - - OwnPtr<Painter> m_back_painter; - OwnPtr<Painter> m_front_painter; -}; |