From 291922b1af60db106e4576f8b504a5702a66d320 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 21 Jan 2019 02:42:29 +0100 Subject: [PATCH] WindowServer: Show PID and window ID in title bars for now. This is useful for debugging since I'm often wondering which process some window belongs to (and what the window ID is.) --- SharedGraphics/Painter.cpp | 3 +++ SharedGraphics/Painter.h | 2 +- WindowServer/WSWindow.cpp | 1 + WindowServer/WSWindow.h | 3 +++ WindowServer/WSWindowManager.cpp | 5 +++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index 94aaee364b..19586bc12b 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -138,6 +138,9 @@ void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alig point = rect.location(); } else if (alignment == TextAlignment::CenterLeft) { point = { rect.x(), rect.center().y() - (font().glyph_height() / 2) }; + } else if (alignment == TextAlignment::CenterRight) { + int text_width = text.length() * font().glyph_width(); + point = { rect.right() - text_width, rect.center().y() - (font().glyph_height() / 2) }; } else if (alignment == TextAlignment::Center) { int textWidth = text.length() * font().glyph_width(); point = rect.center(); diff --git a/SharedGraphics/Painter.h b/SharedGraphics/Painter.h index c8f3413802..7deb386af9 100644 --- a/SharedGraphics/Painter.h +++ b/SharedGraphics/Painter.h @@ -30,7 +30,7 @@ public: void draw_focus_rect(const Rect&); void blit(const Point&, const GraphicsBitmap&, const Rect& src_rect); - enum class TextAlignment { TopLeft, CenterLeft, Center }; + enum class TextAlignment { TopLeft, CenterLeft, Center, CenterRight }; void draw_text(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, Color = Color()); void draw_glyph(const Point&, char, Color); diff --git a/WindowServer/WSWindow.cpp b/WindowServer/WSWindow.cpp index d2bb7f5177..606fb1e24c 100644 --- a/WindowServer/WSWindow.cpp +++ b/WindowServer/WSWindow.cpp @@ -7,6 +7,7 @@ WSWindow::WSWindow(Process& process, int window_id) : m_process(process) , m_window_id(window_id) + , m_pid(process.pid()) { WSWindowManager::the().add_window(*this); } diff --git a/WindowServer/WSWindow.h b/WindowServer/WSWindow.h index 2e1beb52eb..0a771140e9 100644 --- a/WindowServer/WSWindow.h +++ b/WindowServer/WSWindow.h @@ -38,6 +38,8 @@ public: GraphicsBitmap* backing() { return m_backing.ptr(); } + pid_t pid() const { return m_pid; } + // For InlineLinkedList. // FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that. WSWindow* m_next { nullptr }; @@ -51,5 +53,6 @@ private: RetainPtr m_backing; Process& m_process; int m_window_id { -1 }; + pid_t m_pid { -1 }; }; diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index 549d089cbc..2e9e15ec16 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -179,6 +179,11 @@ void WSWindowManager::paint_window_frame(WSWindow& window) m_back_painter->draw_rect(outerRect, border_color); m_back_painter->draw_rect(inner_border_rect, border_color); m_back_painter->draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, title_color); + + Color metadata_color(204, 204, 204); + char buffer[64]; + ksprintf(buffer, "%d:%d", window.pid(), window.window_id()); + m_back_painter->draw_text(titleBarTitleRect, buffer, Painter::TextAlignment::CenterRight, metadata_color); } void WSWindowManager::add_window(WSWindow& window)