1 #ifndef COMPOSITOR_VIEW_HPP
2 #define COMPOSITOR_VIEW_HPP
3 
4 #include "wayfire/compositor-surface.hpp"
5 #include "wayfire/view.hpp"
6 #include <wayfire/config/types.hpp>
7 
8 namespace wf
9 {
10 /**
11  * Base class for compositor views that need to interact with the keyboard
12  */
13 class compositor_interactive_view_t
14 {
15   public:
handle_keyboard_enter()16     void handle_keyboard_enter()
17     {}
handle_keyboard_leave()18     void handle_keyboard_leave()
19     {}
handle_key(uint32_t key,uint32_t state)20     void handle_key(uint32_t key, uint32_t state)
21     {}
22 };
23 
24 compositor_interactive_view_t *interactive_view_from_view(
25     wf::view_interface_t *view);
26 
27 /**
28  * mirror_view_t is a specialized type of views.
29  *
30  * They have the same contents as another view. A mirror view's size is
31  * determined by the bounding box of the mirrored view. However, the mirror view
32  * itself can be on another position, output, etc. and can have additional
33  * transforms.
34  *
35  * A mirror view is mapped as long as its base view is mapped. Afterwards, the
36  * view becomes unmapped, until it is destroyed.
37  */
38 class mirror_view_t : public wf::view_interface_t, wf::compositor_surface_t
39 {
40   protected:
41     signal_callback_t base_view_unmapped, base_view_damaged;
42     wayfire_view base_view;
43     int x;
44     int y;
45 
46   public:
47     /**
48      * Create a new mirror view for the given base view. When using mirror
49      * views, the view should be manually added to the appropriate layer in
50      * workspace-manager.
51      *
52      * Note: a map event is not emitted for mirror views by default.
53      */
54     mirror_view_t(wayfire_view base_view);
55     virtual ~mirror_view_t();
56 
57     /**
58      * Close the view. This means unsetting the base view and setting the state
59      * of the view to unmapped.
60      *
61      * This will also fire the unmap event on the mirror view.
62      */
63     virtual void close() override;
64 
65     /* surface_interface_t implementation */
66     virtual bool is_mapped() const override;
67     virtual wf::dimensions_t get_size() const override;
68     virtual void simple_render(const wf::framebuffer_t& fb, int x, int y,
69         const wf::region_t& damage) override;
70 
71     /* view_interface_t implementation */
72     virtual void move(int x, int y) override;
73     virtual wf::geometry_t get_output_geometry() override;
74 
75     virtual wlr_surface *get_keyboard_focus_surface() override;
76     virtual bool is_focuseable() const override;
77     virtual bool should_be_decorated() override;
78 };
79 
80 /**
81  * color_rect_view_t represents another common type of compositor view - a
82  * view which is simply a colored rectangle with a border.
83  */
84 class color_rect_view_t : public wf::view_interface_t, wf::compositor_surface_t
85 {
86   protected:
87     wf::color_t _color;
88     wf::color_t _border_color;
89     int border;
90 
91     wf::geometry_t geometry;
92     bool _is_mapped;
93 
94   public:
95     /**
96      * Create a colored rect view. The map signal is not fired by default.
97      * The creator of the colored view should also add it to the desired layer.
98      */
99     color_rect_view_t();
100 
101     /**
102      * Emit the unmap signal and then drop the internal reference.
103      */
104     virtual void close() override;
105 
106     /** Set the view color. Color's alpha is not premultiplied */
107     virtual void set_color(wf::color_t color);
108     /** Set the view border color. Color's alpha is not premultiplied */
109     virtual void set_border_color(wf::color_t border);
110     /** Set the border width. */
111     virtual void set_border(int width);
112 
113     /* required for surface_interface_t */
114     virtual bool is_mapped() const override;
115     virtual wf::dimensions_t get_size() const override;
116     virtual void simple_render(const wf::framebuffer_t& fb, int x, int y,
117         const wf::region_t& damage) override;
118 
119     /* required for view_interface_t */
120     virtual void move(int x, int y) override;
121     virtual void resize(int w, int h) override;
122     virtual wf::geometry_t get_output_geometry() override;
123 
124     virtual wlr_surface *get_keyboard_focus_surface() override;
125     virtual bool is_focuseable() const override;
126     virtual bool should_be_decorated() override;
127 };
128 }
129 
130 #endif /* end of include guard: COMPOSITOR_VIEW_HPP */
131