mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:12:45 +00:00 
			
		
		
		
	More window manager hacking. FocusIn/FocusOut events.
This commit is contained in:
		
							parent
							
								
									7577ee0c67
								
							
						
					
					
						commit
						ceb373cf71
					
				
					 8 changed files with 20 additions and 22 deletions
				
			
		|  | @ -65,9 +65,9 @@ public: | |||
| 
 | ||||
|     bool is_null() const { return !m_impl; } | ||||
|     bool is_empty() const { return length() == 0; } | ||||
|     unsigned length() const { return m_impl ? m_impl->length() : 0; } | ||||
|     size_t length() const { return m_impl ? m_impl->length() : 0; } | ||||
|     const char* characters() const { return m_impl ? m_impl->characters() : nullptr; } | ||||
|     char operator[](unsigned i) const { ASSERT(m_impl); return (*m_impl)[i]; } | ||||
|     char operator[](size_t i) const { ASSERT(m_impl); return (*m_impl)[i]; } | ||||
| 
 | ||||
|     bool operator==(const String&) const; | ||||
|     bool operator!=(const String& other) const { return !(*this == other); } | ||||
|  |  | |||
|  | @ -37,6 +37,8 @@ public: | |||
|         DeferredDestroy, | ||||
|         WindowBecameInactive, | ||||
|         WindowBecameActive, | ||||
|         FocusIn, | ||||
|         FocusOut, | ||||
|     }; | ||||
| 
 | ||||
|     Event() { } | ||||
|  |  | |||
|  | @ -18,13 +18,6 @@ RootWidget::~RootWidget() | |||
| 
 | ||||
| void RootWidget::paintEvent(PaintEvent& event) | ||||
| { | ||||
|     Widget::paintEvent(event); | ||||
| 
 | ||||
|     printf("RootWidget::paintEvent: %d,%d %dx%d\n", | ||||
|             event.rect().x(), | ||||
|             event.rect().y(), | ||||
|             event.rect().width(), | ||||
|             event.rect().height()); | ||||
|     Painter painter(*this); | ||||
|     painter.fillRect(event.rect(), Color(0, 72, 96)); | ||||
| } | ||||
|  |  | |||
|  | @ -35,13 +35,13 @@ void TextBox::paintEvent(PaintEvent&) | |||
|     Rect innerRect = rect(); | ||||
|     innerRect.shrink(6, 6); | ||||
| 
 | ||||
|     unsigned maxCharsToPaint = innerRect.width() / font().glyphWidth(); | ||||
|     size_t maxCharsToPaint = innerRect.width() / font().glyphWidth(); | ||||
| 
 | ||||
|     int firstVisibleChar = max((int)m_cursorPosition - (int)maxCharsToPaint, 0); | ||||
|     unsigned charsToPaint = min(m_text.length() - firstVisibleChar, maxCharsToPaint); | ||||
|     size_t charsToPaint = min(m_text.length() - firstVisibleChar, maxCharsToPaint); | ||||
| 
 | ||||
|     int y = innerRect.center().y() - font().glyphHeight() / 2; | ||||
|     for (unsigned i = 0; i < charsToPaint; ++i) { | ||||
|     for (size_t i = 0; i < charsToPaint; ++i) { | ||||
|         char ch = m_text[firstVisibleChar + i]; | ||||
|         if (ch == ' ') | ||||
|             continue; | ||||
|  |  | |||
|  | @ -37,13 +37,13 @@ void Widget::event(Event& event) | |||
| { | ||||
|     switch (event.type()) { | ||||
|     case Event::Paint: | ||||
|         m_hasPendingPaintEvent = false; | ||||
|         if (auto* win = window()) { | ||||
|             if (win->isBeingDragged()) | ||||
|                 return; | ||||
|             if (!win->isVisible()) | ||||
|                 return; | ||||
|         } | ||||
|         m_hasPendingPaintEvent = false; | ||||
|         return paintEvent(static_cast<PaintEvent&>(event)); | ||||
|     case Event::Show: | ||||
|         return showEvent(static_cast<ShowEvent&>(event)); | ||||
|  | @ -77,7 +77,7 @@ void Widget::paintEvent(PaintEvent& event) | |||
|     } | ||||
|     for (auto* ch : children()) { | ||||
|         auto* child = (Widget*)ch; | ||||
|         child->paintEvent(event); | ||||
|         child->event(event); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -117,7 +117,7 @@ void Widget::update() | |||
|     if (m_hasPendingPaintEvent) | ||||
|         return; | ||||
|     m_hasPendingPaintEvent = true; | ||||
|     EventLoop::main().postEvent(w, make<PaintEvent>(rect())); | ||||
|     EventLoop::main().postEvent(w, make<PaintEvent>(relativeRect())); | ||||
| } | ||||
| 
 | ||||
| Widget::HitTestResult Widget::hitTest(int x, int y) | ||||
|  |  | |||
|  | @ -74,7 +74,7 @@ void Window::event(Event& event) | |||
| 
 | ||||
|     if (event.isPaintEvent()) { | ||||
|         auto& pe = static_cast<PaintEvent&>(event); | ||||
|         printf("Window[\"%s\"]: paintEvent %d,%d %dx%d\n", class_name(), | ||||
|         printf("Window[\"%s\"]: paintEvent %d,%d %dx%d\n", title().characters(), | ||||
|                 pe.rect().x(), | ||||
|                 pe.rect().y(), | ||||
|                 pe.rect().width(), | ||||
|  | @ -123,15 +123,15 @@ void Window::setFocusedWidget(Widget* widget) | |||
| { | ||||
|     if (m_focusedWidget.ptr() == widget) | ||||
|         return; | ||||
|     auto* previouslyFocusedWidget = m_focusedWidget.ptr(); | ||||
|     if (!widget) { | ||||
|     auto* previously_focused_widget = m_focusedWidget.ptr(); | ||||
|     if (!widget) | ||||
|         m_focusedWidget = nullptr; | ||||
|     } else { | ||||
|     else { | ||||
|         m_focusedWidget = widget->makeWeakPtr(); | ||||
|         m_focusedWidget->repaint(Rect()); | ||||
|         EventLoop::main().postEvent(m_focusedWidget.ptr(), make<Event>(Event::FocusIn)); | ||||
|     } | ||||
|     if (previouslyFocusedWidget) | ||||
|         previouslyFocusedWidget->repaint(Rect()); | ||||
|     if (previously_focused_widget) | ||||
|         EventLoop::main().postEvent(previously_focused_widget, make<Event>(Event::FocusOut)); | ||||
| } | ||||
| 
 | ||||
| void Window::close() | ||||
|  |  | |||
|  | @ -139,6 +139,7 @@ void WindowManager::did_paint(Window& window) | |||
|     if (m_windows_in_order.tail() == &window) { | ||||
|         ASSERT(window.backing()); | ||||
|         framebuffer.blit(window.position(), *window.backing()); | ||||
|         framebuffer.flush(); | ||||
|         printf("[WM] frontmost_only_compose_count: %u\n", ++m_frontmost_only_compose_count); | ||||
|         return; | ||||
|     } | ||||
|  |  | |||
|  | @ -100,10 +100,12 @@ int main(int argc, char** argv) | |||
|     win->setMainWidget(t); | ||||
|     t->setFocus(true); | ||||
| 
 | ||||
| #if 0 | ||||
|     auto* clockWin = new Window; | ||||
|     clockWin->setTitle("Clock"); | ||||
|     clockWin->setRect({ 500, 50, 100, 40 }); | ||||
|     clockWin->setMainWidget(new ClockWidget); | ||||
| #endif | ||||
| 
 | ||||
|     MsgBox(nullptr, "This is a message box!"); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling