Mir
window.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 or 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef MIRAL_WINDOW_H
18 #define MIRAL_WINDOW_H
19 
20 #include "miral/application.h"
21 
22 #include <mir/geometry/point.h>
23 #include <mir/geometry/size.h>
24 
25 #include <memory>
26 
27 namespace mir
28 {
29 namespace scene { class Surface; }
30 }
31 
32 namespace miral
33 {
34 /// Handle class to manage a Mir surface. It may be null (e.g. default initialized)
35 class Window
36 {
37 public:
38  Window();
39  Window(Application const& application, std::shared_ptr<mir::scene::Surface> const& surface);
40  ~Window();
41 
42  /// The position of the top-left corner of the window frame
43  auto top_left() const -> mir::geometry::Point;
44  /// The size of the window frame. Units are logical screen coordinates (not necessarily device pixels). Any
45  /// decorations are included in the size.
46  auto size() const -> mir::geometry::Size;
47  /// The application that created this window
48  auto application() const -> Application;
49 
50  /// Indicates that the Window isn't null
51  operator bool() const;
52 
53  /// Not for external use, use WindowManagerTools::modify_window() instead
54  /// @{
55  void resize(mir::geometry::Size const& size);
56  void move_to(mir::geometry::Point top_left);
57  /// @}
58 
59  /// Access to the underlying Mir surface
60  /// @{
61  operator std::weak_ptr<mir::scene::Surface>() const;
62  operator std::shared_ptr<mir::scene::Surface>() const;
63  /// @}
64 
65 private:
66  struct Self;
67  std::shared_ptr <Self> self;
68 
69  friend bool operator==(Window const& lhs, Window const& rhs);
70  friend bool operator==(std::shared_ptr<mir::scene::Surface> const& lhs, Window const& rhs);
71  friend bool operator==(Window const& lhs, std::shared_ptr<mir::scene::Surface> const& rhs);
72  friend bool operator<(Window const& lhs, Window const& rhs);
73 };
74 
75 bool operator==(Window const& lhs, Window const& rhs);
76 bool operator==(std::shared_ptr<mir::scene::Surface> const& lhs, Window const& rhs);
77 bool operator==(Window const& lhs, std::shared_ptr<mir::scene::Surface> const& rhs);
78 bool operator<(Window const& lhs, Window const& rhs);
79 
80 inline bool operator!=(Window const& lhs, Window const& rhs) { return !(lhs == rhs); }
81 inline bool operator!=(std::shared_ptr<mir::scene::Surface> const& lhs, Window const& rhs) { return !(lhs == rhs); }
82 inline bool operator!=(Window const& lhs, std::shared_ptr<mir::scene::Surface> const& rhs) { return !(lhs == rhs); }
83 inline bool operator>(Window const& lhs, Window const& rhs) { return rhs < lhs; }
84 inline bool operator<=(Window const& lhs, Window const& rhs) { return !(lhs > rhs); }
85 inline bool operator>=(Window const& lhs, Window const& rhs) { return !(lhs < rhs); }
86 
87 /// Customization for Google test (to print surface name in errors)
88 /// \see https://github.com/google/googletest/blob/main/docs/advanced.md#teaching-googletest-how-to-print-your-values
89 /// \remark Since MirAL 3.3
90 void PrintTo(Window const& bar, std::ostream* os);
91 }
92 
93 #endif //MIRAL_WINDOW_H

Copyright © 2012-2022 Canonical Ltd.
Generated on Thu Sep 8 12:37:23 UTC 2022
This documentation is licensed under the GPL version 2 or 3.