Mir
tiling_window_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015-2020 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_SHELL_TILING_WINDOW_MANAGER_H
18 #define MIRAL_SHELL_TILING_WINDOW_MANAGER_H
19 
20 #include "sw_splash.h"
21 
22 #include <miral/application.h>
23 #include <miral/window_management_policy.h>
24 #include <miral/window_manager_tools.h>
25 
26 #include <mir/geometry/displacement.h>
27 #include <miral/internal_client.h>
28 
29 #include <mir_toolkit/events/enums.h>
30 
31 #include <functional>
32 #include <vector>
33 
34 using namespace mir::geometry;
35 
36 // Demonstrate implementing a simple tiling algorithm
37 
38 // simple tiling algorithm:
39 // o Switch apps: tap or click on the corresponding tile
40 // o Move window: Alt-leftmousebutton drag (three finger drag)
41 // o Resize window: Alt-middle_button drag (four finger drag)
42 // o Maximize/restore current window (to tile size): Alt-F11
43 // o Maximize/restore current window (to tile height): Shift-F11
44 // o Maximize/restore current window (to tile width): Ctrl-F11
45 // o client requests to maximize, vertically maximize & restore
48 {
49 public:
50  explicit TilingWindowManagerPolicy(miral::WindowManagerTools const& tools, std::shared_ptr<SplashSession> const& spinner,
51  miral::InternalClientLauncher const& launcher);
52 
53  auto place_new_window(
54  miral::ApplicationInfo const& app_info,
55  miral::WindowSpecification const& request_parameters)
56  -> miral::WindowSpecification override;
57 
58  void handle_window_ready(miral::WindowInfo& window_info) override;
59  void handle_modify_window(miral::WindowInfo& window_info, miral::WindowSpecification const& modifications) override;
60  bool handle_keyboard_event(MirKeyboardEvent const* event) override;
61  bool handle_touch_event(MirTouchEvent const* event) override;
62  bool handle_pointer_event(MirPointerEvent const* event) override;
63  void handle_raise_window(miral::WindowInfo& window_info) override;
64 
65  void advise_end() override;
66 
67  void advise_new_window(miral::WindowInfo const& window_info) override;
68  void advise_focus_gained(miral::WindowInfo const& info) override;
69  void advise_new_app(miral::ApplicationInfo& application) override;
70  void advise_delete_app(miral::ApplicationInfo const& application) override;
71 
72  void handle_request_drag_and_drop(miral::WindowInfo& window_info) override;
73  void handle_request_move(miral::WindowInfo& window_info, MirInputEvent const* input_event) override;
74  void handle_request_resize(miral::WindowInfo& window_info, MirInputEvent const* input_event, MirResizeEdge edge) override;
75 
76  auto confirm_inherited_move(miral::WindowInfo const& window_info, Displacement movement) -> Rectangle override;
77 
78  Rectangle confirm_placement_on_display(const miral::WindowInfo& window_info, MirWindowState new_state,
79  Rectangle const& new_placement) override;
80 
81 private:
82  void advise_application_zone_create(miral::Zone const& zone) override;
83  void advise_application_zone_update(miral::Zone const& updated, miral::Zone const& original) override;
84  void advise_application_zone_delete(miral::Zone const& zone) override;
85 
86  static const int modifier_mask =
92 
93  void click(Point cursor);
94  void resize(Point cursor);
95  void drag(Point cursor);
96  void toggle(MirWindowState state);
97 
98  miral::Application application_under(Point position);
99 
100  void update_tiles(Rectangles const& outputs);
101  void update_surfaces(miral::ApplicationInfo& info, Rectangle const& old_tile, Rectangle const& new_tile);
102 
103  auto transform_set_state(MirWindowState value) -> MirWindowState;
104 
105  static void clip_to_tile(miral::WindowSpecification& parameters, Rectangle const& tile);
106  static void resize(miral::Window window, Point cursor, Point old_cursor, Rectangle bounds);
107 
108  void constrain_size_and_place(miral::WindowSpecification& mods, miral::Window const& window, Rectangle const& tile) const;
109 
110  miral::WindowManagerTools tools;
111  std::shared_ptr<SplashSession> spinner;
112  miral::InternalClientLauncher const launcher;
113  Point old_cursor{};
114  Rectangles displays;
115  bool dirty_tiles = false;
116 
117  class MRUTileList
118  {
119  public:
120 
121  void push(std::shared_ptr<void> const& tile);
122  void erase(std::shared_ptr<void> const& tile);
123 
124  using Enumerator = std::function<void(std::shared_ptr<void> const& tile)>;
125 
126  void enumerate(Enumerator const& enumerator) const;
127  auto count() -> size_t { return tiles.size(); }
128 
129  private:
130  std::vector<std::shared_ptr<void>> tiles;
131  };
132 
133  MRUTileList tiles;
134 };
135 
136 #endif /* MIRAL_SHELL_TILING_WINDOW_MANAGER_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.