Mir
tiling_window_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015-2018 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  * Authored By: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIRAL_SHELL_TILING_WINDOW_MANAGER_H
20 #define MIRAL_SHELL_TILING_WINDOW_MANAGER_H
21 
22 #include "sw_splash.h"
23 
24 #include <miral/application.h>
27 
29 #include <miral/internal_client.h>
30 
31 
32 #include <functional>
33 #include <vector>
34 
35 using namespace mir::geometry;
36 
37 // Demonstrate implementing a simple tiling algorithm
38 
39 // simple tiling algorithm:
40 // o Switch apps: tap or click on the corresponding tile
41 // o Move window: Alt-leftmousebutton drag (three finger drag)
42 // o Resize window: Alt-middle_button drag (four finger drag)
43 // o Maximize/restore current window (to tile size): Alt-F11
44 // o Maximize/restore current window (to tile height): Shift-F11
45 // o Maximize/restore current window (to tile width): Ctrl-F11
46 // o client requests to maximize, vertically maximize & restore
50 {
51 public:
52  explicit TilingWindowManagerPolicy(miral::WindowManagerTools const& tools, std::shared_ptr<SplashSession> const& spinner,
53  miral::InternalClientLauncher const& launcher);
54 
55  auto place_new_window(
56  miral::ApplicationInfo const& app_info,
57  miral::WindowSpecification const& request_parameters)
58  -> miral::WindowSpecification override;
59 
60  void handle_window_ready(miral::WindowInfo& window_info) override;
61  void handle_modify_window(miral::WindowInfo& window_info, miral::WindowSpecification const& modifications) override;
62  bool handle_keyboard_event(MirKeyboardEvent const* event) override;
63  bool handle_touch_event(MirTouchEvent const* event) override;
64  bool handle_pointer_event(MirPointerEvent const* event) override;
65  void handle_raise_window(miral::WindowInfo& window_info) override;
66 
67  void advise_end() override;
68 
69  void advise_new_window(miral::WindowInfo const& window_info) override;
70  void advise_focus_gained(miral::WindowInfo const& info) override;
71  void advise_new_app(miral::ApplicationInfo& application) override;
72  void advise_delete_app(miral::ApplicationInfo const& application) override;
73 
74  void handle_request_drag_and_drop(miral::WindowInfo& window_info) override;
75  void handle_request_move(miral::WindowInfo& window_info, MirInputEvent const* input_event) override;
76  void handle_request_resize(miral::WindowInfo& window_info, MirInputEvent const* input_event, MirResizeEdge edge) override;
77 
78  auto confirm_inherited_move(miral::WindowInfo const& window_info, Displacement movement) -> Rectangle override;
79 
80  Rectangle confirm_placement_on_display(const miral::WindowInfo& window_info, MirWindowState new_state,
81  Rectangle const& new_placement) override;
82 
83 private:
84  void advise_application_zone_create(miral::Zone const& zone) override;
85  void advise_application_zone_update(miral::Zone const& updated, miral::Zone const& original) override;
86  void advise_application_zone_delete(miral::Zone const& zone) override;
87 
88  static const int modifier_mask =
94 
95  void click(Point cursor);
96  void resize(Point cursor);
97  void drag(Point cursor);
98  void toggle(MirWindowState state);
99 
100  miral::Application application_under(Point position);
101 
102  void update_tiles(Rectangles const& outputs);
103  void update_surfaces(miral::ApplicationInfo& info, Rectangle const& old_tile, Rectangle const& new_tile);
104 
105  auto transform_set_state(MirWindowState value) -> MirWindowState;
106 
107  static void clip_to_tile(miral::WindowSpecification& parameters, Rectangle const& tile);
108  static void resize(miral::Window window, Point cursor, Point old_cursor, Rectangle bounds);
109 
110  void constrain_size_and_place(miral::WindowSpecification& mods, miral::Window const& window, Rectangle const& tile) const;
111 
113  std::shared_ptr<SplashSession> spinner;
114  miral::InternalClientLauncher const launcher;
115  Point old_cursor{};
116  Rectangles displays;
117  bool dirty_tiles = false;
118 
119  class MRUTileList
120  {
121  public:
122 
123  void push(std::shared_ptr<void> const& tile);
124  void erase(std::shared_ptr<void> const& tile);
125 
126  using Enumerator = std::function<void(std::shared_ptr<void> const& tile)>;
127 
128  void enumerate(Enumerator const& enumerator) const;
129  auto count() -> size_t { return tiles.size(); }
130 
131  private:
132  std::vector<std::shared_ptr<void>> tiles;
133  };
134 
135  MRUTileList tiles;
136 };
137 
138 #endif /* MIRAL_SHELL_TILING_WINDOW_MANAGER_H */
Definition: input_event.h:49
MirResizeEdge
Hints for resizing a window.
Definition: common.h:413
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: point.h:30
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
Definition: application_info.h:31
Definition: input_event.h:60
Definition: internal_client.h:70
Definition: window_info.h:32
Definition: window_specification.h:43
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
Handle class to manage a Mir surface. It may be null (e.g. default initialized)
Definition: window.h:37
std::shared_ptr< mir::scene::Session > Application
Definition: application.h:34
The interface through which the window management policy is determined.
Definition: window_management_policy.h:46
Definition: input_event.h:52
Handle additional requests related to application zones.
Definition: window_management_policy.h:284
A rectangular area of the display. Not tied to a specific output.
Definition: zone.h:35
Definition: displacement.h:33
Window management functions for querying and updating MirAL&#39;s model.
Definition: window_manager_tools.h:58
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:41
Definition: rectangle.h:33
struct MirInputEvent MirInputEvent
Definition: event.h:70
Definition: tiling_window_manager.h:47
Definition: input_event.h:55
Basic geometry types. Types for dimensions, displacements, etc. and the operations that they support...
Definition: dimensions.h:30
Definition: input_event.h:57
MirWindowState
Definition: common.h:141

Copyright © 2012-2022 Canonical Ltd.
Generated on Thu Jan 27 21:45:55 UTC 2022
This documentation is licensed under the GPL version 2 or 3.