2019-01-16 16:03:50 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/InlineLinkedList.h>
|
2019-12-02 09:33:37 +01:00
|
|
|
#include <AK/String.h>
|
2019-04-14 05:15:22 +02:00
|
|
|
#include <LibCore/CObject.h>
|
2019-07-18 10:15:00 +02:00
|
|
|
#include <LibDraw/DisjointRectSet.h>
|
|
|
|
#include <LibDraw/GraphicsBitmap.h>
|
|
|
|
#include <LibDraw/Rect.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <WindowServer/WSWindowFrame.h>
|
|
|
|
#include <WindowServer/WSWindowType.h>
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-02-17 08:54:57 +01:00
|
|
|
class WSClientConnection;
|
2019-03-31 23:52:02 +02:00
|
|
|
class WSCursor;
|
2019-02-11 09:47:10 +01:00
|
|
|
class WSMenu;
|
2019-03-24 15:01:56 +01:00
|
|
|
class WSMouseEvent;
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-12-02 09:33:37 +01:00
|
|
|
enum WSWMEventMask {
|
|
|
|
WindowRectChanges = 1 << 0,
|
|
|
|
WindowStateChanges = 1 << 1,
|
|
|
|
WindowIconChanges = 1 << 2,
|
|
|
|
WindowRemovals = 1 << 3,
|
|
|
|
};
|
|
|
|
|
2020-01-01 17:24:14 +00:00
|
|
|
enum class WindowTileType {
|
|
|
|
None = 0,
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
};
|
|
|
|
|
2019-05-28 11:53:16 +02:00
|
|
|
class WSWindow final : public CObject
|
|
|
|
, public InlineLinkedListNode<WSWindow> {
|
2019-07-25 19:49:28 +02:00
|
|
|
C_OBJECT(WSWindow)
|
2019-01-16 16:03:50 +01:00
|
|
|
public:
|
2019-05-17 21:33:44 +02:00
|
|
|
WSWindow(WSClientConnection&, WSWindowType, int window_id, bool modal, bool resizable, bool fullscreen);
|
2019-04-14 05:15:22 +02:00
|
|
|
WSWindow(CObject&, WSWindowType);
|
2019-01-16 16:03:50 +01:00
|
|
|
virtual ~WSWindow() override;
|
|
|
|
|
2019-06-21 11:03:43 +02:00
|
|
|
void popup_window_menu(const Point&);
|
|
|
|
void request_close();
|
|
|
|
|
2019-04-20 14:40:38 +02:00
|
|
|
unsigned wm_event_mask() const { return m_wm_event_mask; }
|
|
|
|
void set_wm_event_mask(unsigned mask) { m_wm_event_mask = mask; }
|
|
|
|
|
2019-04-05 22:32:00 +02:00
|
|
|
bool is_minimized() const { return m_minimized; }
|
|
|
|
void set_minimized(bool);
|
|
|
|
|
2019-05-12 21:32:02 +02:00
|
|
|
bool is_maximized() const { return m_maximized; }
|
|
|
|
void set_maximized(bool);
|
|
|
|
|
2019-05-17 21:33:44 +02:00
|
|
|
bool is_fullscreen() const { return m_fullscreen; }
|
2019-09-16 18:38:42 +02:00
|
|
|
void set_fullscreen(bool);
|
2019-05-17 21:33:44 +02:00
|
|
|
|
2020-01-01 17:24:14 +00:00
|
|
|
WindowTileType tiled() const { return m_tiled; }
|
|
|
|
void set_tiled(WindowTileType);
|
|
|
|
|
2019-12-27 11:34:40 +01:00
|
|
|
bool is_occluded() const { return m_occluded; }
|
|
|
|
void set_occluded(bool);
|
|
|
|
|
2019-05-24 14:37:23 -07:00
|
|
|
bool show_titlebar() const { return m_show_titlebar; }
|
|
|
|
void set_show_titlebar(bool show) { m_show_titlebar = show; }
|
|
|
|
|
2019-07-31 17:49:40 +02:00
|
|
|
bool is_movable() const
|
|
|
|
{
|
2019-11-11 13:11:31 +01:00
|
|
|
return m_type == WSWindowType::Normal;
|
2019-07-31 17:49:40 +02:00
|
|
|
}
|
|
|
|
|
2019-04-05 15:54:56 +02:00
|
|
|
WSWindowFrame& frame() { return m_frame; }
|
|
|
|
const WSWindowFrame& frame() const { return m_frame; }
|
|
|
|
|
2019-03-19 00:52:39 +01:00
|
|
|
bool is_blocked_by_modal_window() const;
|
|
|
|
|
2019-04-04 01:44:35 +02:00
|
|
|
bool listens_to_wm_events() const { return m_listens_to_wm_events; }
|
|
|
|
|
2019-02-17 08:54:57 +01:00
|
|
|
WSClientConnection* client() { return m_client; }
|
|
|
|
const WSClientConnection* client() const { return m_client; }
|
2019-02-13 00:19:21 +01:00
|
|
|
|
2019-02-12 11:53:45 +01:00
|
|
|
WSWindowType type() const { return m_type; }
|
2019-01-16 16:03:50 +01:00
|
|
|
int window_id() const { return m_window_id; }
|
|
|
|
|
|
|
|
String title() const { return m_title; }
|
2019-05-12 14:57:15 +02:00
|
|
|
void set_title(const String&);
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-02-19 01:42:53 +01:00
|
|
|
float opacity() const { return m_opacity; }
|
2019-12-27 11:34:40 +01:00
|
|
|
void set_opacity(float);
|
2019-02-19 01:42:53 +01:00
|
|
|
|
2019-01-16 16:03:50 +01:00
|
|
|
int x() const { return m_rect.x(); }
|
|
|
|
int y() const { return m_rect.y(); }
|
|
|
|
int width() const { return m_rect.width(); }
|
|
|
|
int height() const { return m_rect.height(); }
|
|
|
|
|
2019-03-03 15:17:05 +01:00
|
|
|
bool is_active() const;
|
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
bool is_visible() const { return m_visible; }
|
|
|
|
void set_visible(bool);
|
|
|
|
|
2019-03-19 00:52:39 +01:00
|
|
|
bool is_modal() const { return m_modal; }
|
|
|
|
|
2019-05-17 21:33:44 +02:00
|
|
|
bool is_resizable() const { return m_resizable && !m_fullscreen; }
|
2019-03-19 00:52:39 +01:00
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
Rect rect() const { return m_rect; }
|
2019-01-16 16:03:50 +01:00
|
|
|
void set_rect(const Rect&);
|
2019-02-11 09:47:10 +01:00
|
|
|
void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
|
2019-04-05 15:54:56 +02:00
|
|
|
void set_rect_without_repaint(const Rect& rect)
|
|
|
|
{
|
|
|
|
if (m_rect == rect)
|
|
|
|
return;
|
|
|
|
auto old_rect = m_rect;
|
|
|
|
m_rect = rect;
|
|
|
|
m_frame.notify_window_rect_changed(old_rect, rect);
|
|
|
|
}
|
|
|
|
|
2019-02-20 15:34:55 +01:00
|
|
|
void set_rect_from_window_manager_resize(const Rect&);
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-12-03 21:34:34 +01:00
|
|
|
void set_taskbar_rect(const Rect& rect) { m_taskbar_rect = rect; }
|
|
|
|
const Rect& taskbar_rect() const { return m_taskbar_rect; }
|
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
void move_to(const Point& position) { set_rect({ position, size() }); }
|
|
|
|
void move_to(int x, int y) { move_to({ x, y }); }
|
|
|
|
|
2019-01-16 16:03:50 +01:00
|
|
|
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() }); }
|
|
|
|
|
2019-02-11 09:47:10 +01:00
|
|
|
Size size() const { return m_rect.size(); }
|
|
|
|
|
|
|
|
void invalidate();
|
2019-12-30 01:18:38 +01:00
|
|
|
void invalidate(const Rect&);
|
2019-02-11 09:47:10 +01:00
|
|
|
|
2019-04-14 05:15:22 +02:00
|
|
|
virtual void event(CEvent&) override;
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-12-16 15:05:45 +01:00
|
|
|
// Only used by WSWindowType::MenuApplet. Perhaps it could be a WSWindow subclass? I don't know.
|
|
|
|
void set_rect_in_menubar(const Rect& rect) { m_rect_in_menubar = rect; }
|
|
|
|
const Rect& rect_in_menubar() const { return m_rect_in_menubar; }
|
|
|
|
|
|
|
|
const GraphicsBitmap* backing_store() const { return m_backing_store.ptr(); }
|
2019-02-20 21:59:13 +01:00
|
|
|
GraphicsBitmap* backing_store() { return m_backing_store.ptr(); }
|
2019-12-16 15:05:45 +01:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
void set_backing_store(RefPtr<GraphicsBitmap>&& backing_store)
|
2019-03-18 20:52:23 +01:00
|
|
|
{
|
|
|
|
m_last_backing_store = move(m_backing_store);
|
|
|
|
m_backing_store = move(backing_store);
|
|
|
|
}
|
2019-12-16 15:05:45 +01:00
|
|
|
|
2019-03-18 20:52:23 +01:00
|
|
|
void swap_backing_stores()
|
|
|
|
{
|
|
|
|
swap(m_backing_store, m_last_backing_store);
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsBitmap* last_backing_store() { return m_last_backing_store.ptr(); }
|
2019-01-16 16:03:50 +01:00
|
|
|
|
2019-01-27 08:48:34 +01:00
|
|
|
void set_global_cursor_tracking_enabled(bool);
|
2019-03-24 15:01:56 +01:00
|
|
|
void set_automatic_cursor_tracking_enabled(bool enabled) { m_automatic_cursor_tracking_enabled = enabled; }
|
|
|
|
bool global_cursor_tracking() const { return m_global_cursor_tracking_enabled || m_automatic_cursor_tracking_enabled; }
|
2019-01-27 08:48:34 +01:00
|
|
|
|
2019-02-19 01:42:53 +01:00
|
|
|
bool has_alpha_channel() const { return m_has_alpha_channel; }
|
|
|
|
void set_has_alpha_channel(bool value) { m_has_alpha_channel = value; }
|
|
|
|
|
2019-02-21 00:21:23 +01:00
|
|
|
Size size_increment() const { return m_size_increment; }
|
|
|
|
void set_size_increment(const Size& increment) { m_size_increment = increment; }
|
|
|
|
|
|
|
|
Size base_size() const { return m_base_size; }
|
|
|
|
void set_base_size(const Size& size) { m_base_size = size; }
|
|
|
|
|
2019-03-06 23:03:36 +01:00
|
|
|
const GraphicsBitmap& icon() const { return *m_icon; }
|
2019-07-28 10:18:49 +02:00
|
|
|
void set_icon(NonnullRefPtr<GraphicsBitmap>&& icon) { m_icon = move(icon); }
|
|
|
|
|
2019-04-13 16:59:55 +02:00
|
|
|
void set_default_icon();
|
2019-03-06 23:03:36 +01:00
|
|
|
|
2019-03-31 23:52:02 +02:00
|
|
|
const WSCursor* override_cursor() const { return m_override_cursor.ptr(); }
|
2019-06-21 18:37:47 +02:00
|
|
|
void set_override_cursor(RefPtr<WSCursor>&& cursor) { m_override_cursor = move(cursor); }
|
2019-03-31 23:52:02 +02:00
|
|
|
|
2019-04-20 17:19:56 +02:00
|
|
|
void request_update(const Rect&);
|
|
|
|
DisjointRectSet take_pending_paint_rects() { return move(m_pending_paint_rects); }
|
|
|
|
|
2019-12-03 21:34:34 +01:00
|
|
|
bool in_minimize_animation() const { return m_minimize_animation_step != -1; }
|
|
|
|
|
|
|
|
int minimize_animation_index() const { return m_minimize_animation_step; }
|
|
|
|
void step_minimize_animation() { m_minimize_animation_step += 1; }
|
|
|
|
void start_minimize_animation() { m_minimize_animation_step = 0; }
|
|
|
|
void end_minimize_animation() { m_minimize_animation_step = -1; }
|
|
|
|
|
2019-01-16 16:03:50 +01:00
|
|
|
// For InlineLinkedList.
|
|
|
|
// FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that.
|
|
|
|
WSWindow* m_next { nullptr };
|
|
|
|
WSWindow* m_prev { nullptr };
|
|
|
|
|
|
|
|
private:
|
2019-03-24 15:01:56 +01:00
|
|
|
void handle_mouse_event(const WSMouseEvent&);
|
|
|
|
|
2019-02-17 08:54:57 +01:00
|
|
|
WSClientConnection* m_client { nullptr };
|
2019-01-16 16:03:50 +01:00
|
|
|
String m_title;
|
|
|
|
Rect m_rect;
|
2019-09-16 18:38:42 +02:00
|
|
|
Rect m_saved_nonfullscreen_rect;
|
2019-12-03 21:34:34 +01:00
|
|
|
Rect m_taskbar_rect;
|
2019-02-12 11:53:45 +01:00
|
|
|
WSWindowType m_type { WSWindowType::Normal };
|
2019-01-27 08:48:34 +01:00
|
|
|
bool m_global_cursor_tracking_enabled { false };
|
2019-03-24 15:01:56 +01:00
|
|
|
bool m_automatic_cursor_tracking_enabled { false };
|
2019-02-11 09:47:10 +01:00
|
|
|
bool m_visible { true };
|
2019-02-19 01:42:53 +01:00
|
|
|
bool m_has_alpha_channel { false };
|
2019-03-19 00:52:39 +01:00
|
|
|
bool m_modal { false };
|
|
|
|
bool m_resizable { false };
|
2019-04-04 01:44:35 +02:00
|
|
|
bool m_listens_to_wm_events { false };
|
2019-04-05 22:32:00 +02:00
|
|
|
bool m_minimized { false };
|
2019-05-12 21:32:02 +02:00
|
|
|
bool m_maximized { false };
|
2019-05-17 21:33:44 +02:00
|
|
|
bool m_fullscreen { false };
|
2020-01-01 17:24:14 +00:00
|
|
|
WindowTileType m_tiled { WindowTileType::None };
|
|
|
|
Rect m_untiled_rect;
|
2019-12-27 11:34:40 +01:00
|
|
|
bool m_occluded { false };
|
2019-05-24 14:37:23 -07:00
|
|
|
bool m_show_titlebar { true };
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<GraphicsBitmap> m_backing_store;
|
|
|
|
RefPtr<GraphicsBitmap> m_last_backing_store;
|
2019-01-16 16:03:50 +01:00
|
|
|
int m_window_id { -1 };
|
2019-02-19 01:42:53 +01:00
|
|
|
float m_opacity { 1 };
|
2019-02-21 00:21:23 +01:00
|
|
|
Size m_size_increment;
|
|
|
|
Size m_base_size;
|
2019-06-21 18:37:47 +02:00
|
|
|
NonnullRefPtr<GraphicsBitmap> m_icon;
|
|
|
|
RefPtr<WSCursor> m_override_cursor;
|
2019-04-05 15:54:56 +02:00
|
|
|
WSWindowFrame m_frame;
|
2019-04-20 14:40:38 +02:00
|
|
|
unsigned m_wm_event_mask { 0 };
|
2019-04-20 17:19:56 +02:00
|
|
|
DisjointRectSet m_pending_paint_rects;
|
2019-05-12 21:32:02 +02:00
|
|
|
Rect m_unmaximized_rect;
|
2019-12-16 15:05:45 +01:00
|
|
|
Rect m_rect_in_menubar;
|
2019-09-22 00:17:53 +02:00
|
|
|
RefPtr<WSMenu> m_window_menu;
|
2019-12-03 21:34:34 +01:00
|
|
|
int m_minimize_animation_step { -1 };
|
2019-01-16 16:03:50 +01:00
|
|
|
};
|