Mir
server_example_tiling_window_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 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 3,
6  * as 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 MIR_EXAMPLE_TILING_WINDOW_MANAGER_H_
20 #define MIR_EXAMPLE_TILING_WINDOW_MANAGER_H_
21 
23 
26 
27 namespace mir
28 {
29 namespace examples
30 {
32 {
34  std::vector<std::weak_ptr<scene::Surface>> surfaces;
35 };
36 
38 {
40  std::shared_ptr<scene::Session> const& session,
41  std::shared_ptr<scene::Surface> const& surface,
42  scene::SurfaceCreationParameters const& params);
43 
44  std::weak_ptr<scene::Session> session;
47 };
48 
49 // simple tiling algorithm:
50 // o Switch apps: tap or click on the corresponding tile
51 // o Move window: Alt-leftmousebutton drag
52 // o Resize window: Alt-middle_button drag
53 // o Maximize/restore current window (to tile size): Alt-F11
54 // o Maximize/restore current window (to tile height): Shift-F11
55 // o Maximize/restore current window (to tile width): Ctrl-F11
56 // o client requests to maximize, vertically maximize & restore
58 {
59 public:
63 
64  explicit TilingWindowManagerPolicy(Tools* const tools);
65 
66  void click(geometry::Point cursor);
67 
68  void handle_session_info_updated(TilingSessionInfoMap& session_info, geometry::Rectangles const& displays);
69 
70  void handle_displays_updated(TilingSessionInfoMap& session_info, geometry::Rectangles const& displays);
71 
72  void resize(geometry::Point cursor);
73 
75  std::shared_ptr<scene::Session> const& session,
76  scene::SurfaceCreationParameters const& request_parameters)
78 
79  void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
80 
82  std::shared_ptr<scene::Session> const& session,
83  std::shared_ptr<scene::Surface> const& surface,
84  shell::SurfaceSpecification const& modifications);
85 
86  void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
87 
88  int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
89 
90  void drag(geometry::Point cursor);
91 
92  bool handle_keyboard_event(MirKeyboardEvent const* event);
93 
94  bool handle_touch_event(MirTouchEvent const* event);
95 
96  bool handle_pointer_event(MirPointerEvent const* event);
97 
99  std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface,
100  TilingSurfaceInfoMap& surface_info,
101  std::function<frontend::SurfaceId(std::shared_ptr<scene::Session> const&, scene::SurfaceCreationParameters const&)> const& build);
102 
103 private:
104  static const int modifier_mask =
110 
111  void toggle(MirSurfaceState state);
112 
113  std::shared_ptr<scene::Session> session_under(geometry::Point position);
114 
115  void update_tiles(
116  TilingSessionInfoMap& session_info,
117  geometry::Rectangles const& displays);
118 
119  void update_surfaces(std::weak_ptr<scene::Session> const& session, geometry::Rectangle const& old_tile, geometry::Rectangle const& new_tile);
120 
121  static void clip_to_tile(scene::SurfaceCreationParameters& parameters, geometry::Rectangle const& tile);
122 
123  static void fit_to_new_tile(scene::Surface& surface, geometry::Rectangle const& old_tile, geometry::Rectangle const& new_tile);
124 
125  static bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
126 
127  static bool resize(std::shared_ptr<scene::Surface> surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
128 
129  Tools* const tools;
130 
131  geometry::Point old_cursor{};
132 };
133 }
134 }
135 
136 #endif /* MIR_EXAMPLE_TILING_WINDOW_MANAGER_H_ */
Definition: input_event.h:47
All things Mir.
Definition: atomic_callback.h:25
void handle_delete_surface(std::shared_ptr< scene::Session > const &session, std::weak_ptr< scene::Surface > const &surface)
Definition: server_example_tiling_window_manager.cpp:140
void generate_decorations_for(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, TilingSurfaceInfoMap &surface_info, std::function< frontend::SurfaceId(std::shared_ptr< scene::Session > const &, scene::SurfaceCreationParameters const &)> const &build)
Definition: server_example_tiling_window_manager.cpp:118
MirSurfaceState state
Definition: server_example_tiling_window_manager.h:45
Definition: server_example_tiling_window_manager.h:37
std::map< std::weak_ptr< scene::Surface >, Info, std::owner_less< std::weak_ptr< scene::Surface >>> type
Definition: server_example_basic_window_manager.h:44
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: point.h:30
TilingSurfaceInfo(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, scene::SurfaceCreationParameters const &params)
Definition: server_example_tiling_window_manager.cpp:37
bool handle_keyboard_event(MirKeyboardEvent const *event)
Definition: server_example_tiling_window_manager.cpp:249
void drag(geometry::Point cursor)
Definition: server_example_tiling_window_manager.cpp:218
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
Definition: server_example_tiling_window_manager.h:57
int handle_set_state(std::shared_ptr< scene::Surface > const &surface, MirSurfaceState value)
Definition: server_example_tiling_window_manager.cpp:161
Definition: input_event.h:58
std::map< std::weak_ptr< scene::Session >, Info, std::owner_less< std::weak_ptr< scene::Session >>> type
Definition: server_example_basic_window_manager.h:50
geometry::Rectangle tile
Definition: server_example_tiling_window_manager.h:33
bool handle_pointer_event(MirPointerEvent const *event)
Definition: server_example_tiling_window_manager.cpp:370
std::weak_ptr< scene::Session > session
Definition: server_example_tiling_window_manager.h:44
The interface through which the policy instructs the controller. These functions assume that the Basi...
Definition: server_example_basic_window_manager.h:58
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
MirSurfaceState
Definition: common.h:64
auto handle_place_new_surface(std::shared_ptr< scene::Session > const &session, scene::SurfaceCreationParameters const &request_parameters) -> scene::SurfaceCreationParameters
Definition: server_example_tiling_window_manager.cpp:104
typename SessionTo< TilingSessionInfo >::type TilingSessionInfoMap
Definition: server_example_tiling_window_manager.h:61
std::vector< std::weak_ptr< scene::Surface > > surfaces
Definition: server_example_tiling_window_manager.h:34
void handle_new_surface(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface)
Definition: server_example_tiling_window_manager.cpp:126
Definition: input_event.h:50
bool handle_touch_event(MirTouchEvent const *event)
Definition: server_example_tiling_window_manager.cpp:327
void handle_modify_surface(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, shell::SurfaceSpecification const &modifications)
Definition: server_example_tiling_window_manager.cpp:131
TilingWindowManagerPolicy(Tools *const tools)
Definition: server_example_tiling_window_manager.cpp:47
typename SurfaceTo< TilingSurfaceInfo >::type TilingSurfaceInfoMap
Definition: server_example_tiling_window_manager.h:62
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:44
geometry::Rectangle restore_rect
Definition: server_example_tiling_window_manager.h:46
Definition: surface_creation_parameters.h:42
void click(geometry::Point cursor)
Definition: server_example_tiling_window_manager.cpp:52
Definition: rectangle.h:33
void resize(geometry::Point cursor)
Definition: server_example_tiling_window_manager.cpp:72
Definition: input_event.h:53
Specification of surface properties requested by client.
Definition: surface_specification.h:50
void handle_displays_updated(TilingSessionInfoMap &session_info, geometry::Rectangles const &displays)
Definition: server_example_tiling_window_manager.cpp:67
Definition: input_event.h:55
void handle_session_info_updated(TilingSessionInfoMap &session_info, geometry::Rectangles const &displays)
Definition: server_example_tiling_window_manager.cpp:62
Definition: surface.h:47
Definition: server_example_tiling_window_manager.h:31

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015