Mir
tiling_window_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015-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  * 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 "spinner/splash.h"
23 
24 #include <miral/application.h>
27 #include <miral/active_outputs.h>
28 
30 #include <miral/internal_client.h>
31 
32 
33 #include <functional>
34 #include <vector>
35 
36 using namespace mir::geometry;
37 
38 // Demonstrate implementing a simple tiling algorithm
39 
40 // simple tiling algorithm:
41 // o Switch apps: tap or click on the corresponding tile
42 // o Move window: Alt-leftmousebutton drag (three finger drag)
43 // o Resize window: Alt-middle_button drag (four finger drag)
44 // o Maximize/restore current window (to tile size): Alt-F11
45 // o Maximize/restore current window (to tile height): Shift-F11
46 // o Maximize/restore current window (to tile width): Ctrl-F11
47 // o client requests to maximize, vertically maximize & restore
50 {
51 public:
52  explicit TilingWindowManagerPolicy(miral::WindowManagerTools const& tools, SpinnerSplash const& spinner,
53  miral::InternalClientLauncher const& launcher, miral::ActiveOutputsMonitor& outputs_monitor);
54 
56 
57  auto place_new_window(
58  miral::ApplicationInfo const& app_info,
59  miral::WindowSpecification const& request_parameters)
60  -> miral::WindowSpecification override;
61 
62  void handle_window_ready(miral::WindowInfo& window_info) override;
63  void handle_modify_window(miral::WindowInfo& window_info, miral::WindowSpecification const& modifications) override;
64  bool handle_keyboard_event(MirKeyboardEvent const* event) override;
65  bool handle_touch_event(MirTouchEvent const* event) override;
66  bool handle_pointer_event(MirPointerEvent const* event) override;
67  void handle_raise_window(miral::WindowInfo& window_info) override;
68 
69  void advise_end() override;
70 
71  void advise_new_window(miral::WindowInfo const& window_info) override;
72  void advise_focus_gained(miral::WindowInfo const& info) override;
73  void advise_new_app(miral::ApplicationInfo& application) override;
74  void advise_delete_app(miral::ApplicationInfo const& application) override;
75 
76  auto confirm_inherited_move(miral::WindowInfo const& window_info, Displacement movement) -> Rectangle override;
77 
78 private:
79  void advise_output_create(miral::Output const& output) override;
80  void advise_output_update(miral::Output const& updated, miral::Output const& original) override;
81  void advise_output_delete(miral::Output const& output) override;
82  void advise_output_end() override;
83 
84  static const int modifier_mask =
90 
91  void click(Point cursor);
92  void resize(Point cursor);
93  void drag(Point cursor);
94  void toggle(MirWindowState state);
95 
96  miral::Application application_under(Point position);
97 
98  void update_tiles(Rectangles const& outputs);
99  void update_surfaces(miral::ApplicationInfo& info, Rectangle const& old_tile, Rectangle const& new_tile);
100 
101  auto transform_set_state(MirWindowState value) -> MirWindowState;
102 
103  static void clip_to_tile(miral::WindowSpecification& parameters, Rectangle const& tile);
104  static void resize(miral::Window window, Point cursor, Point old_cursor, Rectangle bounds);
105 
106  void constrain_size_and_place(miral::WindowSpecification& mods, miral::Window const& window, Rectangle const& tile) const;
107 
109  SpinnerSplash spinner;
110  miral::InternalClientLauncher const launcher;
111  Point old_cursor{};
112  miral::ActiveOutputsMonitor& outputs_monitor;
113  Rectangles displays;
114  bool dirty_tiles = false;
115 
116  class MRUTileList
117  {
118  public:
119 
120  void push(std::shared_ptr<void> const& tile);
121  void erase(std::shared_ptr<void> const& tile);
122 
123  using Enumerator = std::function<void(std::shared_ptr<void> const& tile)>;
124 
125  void enumerate(Enumerator const& enumerator) const;
126  auto count() -> size_t { return tiles.size(); }
127 
128  private:
129  std::vector<std::shared_ptr<void>> tiles;
130  };
131 
132  MRUTileList tiles;
133 
134  // These two variables are used by the advise_display methods which are
135  // NOT guarded by the usual WM mutex
136  bool dirty_displays = false;
137  Rectangles live_displays;
138 };
139 
140 #endif /* MIRAL_SHELL_TILING_WINDOW_MANAGER_H */
Definition: input_event.h:49
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: splash.h:30
Definition: point.h:30
Definition: active_outputs.h:53
Definition: active_outputs.h:32
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:60
Definition: window_info.h:32
Definition: output.h:35
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:36
Definition: input_event.h:52
Definition: displacement.h:32
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
Definition: tiling_window_manager.h:48
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:139

Copyright © 2012-2018 Canonical Ltd.
Generated on Tue Feb 20 03:16:44 UTC 2018