1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:57:35 +00:00

WindowServer: Add support for alpha channel based hit testing

This enables implementing non-rectangular window shapes, including
non-rectangular window frames.
This commit is contained in:
Tom 2021-02-14 16:42:37 -07:00 committed by Andreas Kling
parent b3f0a5c917
commit d590e0c946
12 changed files with 107 additions and 12 deletions

View file

@ -147,6 +147,7 @@ void Window::show()
m_frameless,
m_accessory,
m_opacity_when_windowless,
m_alpha_hit_threshold,
m_base_size,
m_size_increment,
m_resize_aspect_ratio,
@ -673,6 +674,20 @@ void Window::set_opacity(float opacity)
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowOpacity>(m_window_id, opacity);
}
void Window::set_alpha_hit_threshold(float threshold)
{
if (threshold < 0.0f)
threshold = 0.0f;
else if (threshold > 1.0f)
threshold = 1.0f;
if (m_alpha_hit_threshold == threshold)
return;
m_alpha_hit_threshold = threshold;
if (!is_visible())
return;
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowAlphaHitThreshold>(m_window_id, threshold);
}
void Window::set_hovered_widget(Widget* widget)
{
if (widget == m_hovered_widget)

View file

@ -72,6 +72,9 @@ public:
void set_opacity(float);
float opacity() const { return m_opacity_when_windowless; }
void set_alpha_hit_threshold(float);
float alpha_hit_threshold() const { return m_alpha_hit_threshold; }
WindowType window_type() const { return m_window_type; }
void set_window_type(WindowType);
@ -238,6 +241,7 @@ private:
RefPtr<Gfx::Bitmap> m_custom_cursor;
int m_window_id { 0 };
float m_opacity_when_windowless { 1.0f };
float m_alpha_hit_threshold { 0.0f };
RefPtr<Widget> m_main_widget;
WeakPtr<Widget> m_focused_widget;
WeakPtr<Widget> m_global_cursor_tracking_widget;

View file

@ -52,6 +52,7 @@ public:
{
return compute_frame_colors(state, palette).uses_alpha();
}
virtual float frame_alpha_hit_threshold(WindowState) const override { return 1.0f; }
private:
struct FrameColors {

View file

@ -63,6 +63,7 @@ public:
virtual Vector<IntRect> layout_buttons(WindowType, const IntRect& window_rect, const Palette&, size_t buttons) const = 0;
virtual bool is_simple_rect_frame() const = 0;
virtual bool frame_uses_alpha(WindowState, const Palette&) const = 0;
virtual float frame_alpha_hit_threshold(WindowState) const = 0;
protected:
WindowTheme() { }