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
30
31
32#include <functional>
33#include <vector>
34
35using 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{
51public:
52 explicit TilingWindowManagerPolicy(miral::WindowManagerTools const& tools, std::shared_ptr<SplashSession> const& spinner,
53 miral::InternalClientLauncher const& launcher);
54
56 miral::ApplicationInfo const& app_info,
57 miral::WindowSpecification const& request_parameters)
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
81 Rectangle const& new_placement) override;
82
83private:
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: tiling_window_manager.h:50
Rectangle confirm_placement_on_display(const miral::WindowInfo &window_info, MirWindowState new_state, Rectangle const &new_placement) override
Confirm (and optionally adjust) the placement of a window on the display.
Definition: tiling_window_manager.cpp:698
void handle_request_move(miral::WindowInfo &window_info, MirInputEvent const *input_event) override
request from client to initiate move
Definition: tiling_window_manager.cpp:690
void advise_focus_gained(miral::WindowInfo const &info) override
Notification that a window has gained focus.
Definition: tiling_window_manager.cpp:602
void advise_new_window(miral::WindowInfo const &window_info) override
Notification that a window has been created.
Definition: tiling_window_manager.cpp:143
void handle_request_resize(miral::WindowInfo &window_info, MirInputEvent const *input_event, MirResizeEdge edge) override
request from client to initiate resize
Definition: tiling_window_manager.cpp:694
bool handle_touch_event(MirTouchEvent const *event) override
touch event handler
Definition: tiling_window_manager.cpp:355
void advise_new_app(miral::ApplicationInfo &application) override
Notification that a new application has connected.
Definition: tiling_window_manager.cpp:620
void handle_raise_window(miral::WindowInfo &window_info) override
request from client to raise the window
Definition: tiling_window_manager.cpp:279
void handle_request_drag_and_drop(miral::WindowInfo &window_info) override
request from client to initiate drag and drop
Definition: tiling_window_manager.cpp:686
bool handle_pointer_event(MirPointerEvent const *event) override
pointer event handler
Definition: tiling_window_manager.cpp:413
auto place_new_window(miral::ApplicationInfo const &app_info, miral::WindowSpecification const &request_parameters) -> miral::WindowSpecification override
Customize initial window placement.
Definition: tiling_window_manager.cpp:104
void advise_delete_app(miral::ApplicationInfo const &application) override
Notification that an application has disconnected.
Definition: tiling_window_manager.cpp:634
bool handle_keyboard_event(MirKeyboardEvent const *event) override
keyboard event handler
Definition: tiling_window_manager.cpp:284
void advise_end() override
after any related calls end
Definition: tiling_window_manager.cpp:655
void handle_window_ready(miral::WindowInfo &window_info) override
notification that the first buffer has been posted
Definition: tiling_window_manager.cpp:159
auto confirm_inherited_move(miral::WindowInfo const &window_info, Displacement movement) -> Rectangle override
Confirm (and optionally adjust) the motion of a child window when the parent is moved.
Definition: tiling_window_manager.cpp:643
void handle_modify_window(miral::WindowInfo &window_info, miral::WindowSpecification const &modifications) override
request from client to modify the window specification.
Definition: tiling_window_manager.cpp:180
TilingWindowManagerPolicy(miral::WindowManagerTools const &tools, std::shared_ptr< SplashSession > const &spinner, miral::InternalClientLauncher const &launcher)
Definition: tiling_window_manager.cpp:74
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:35
Definition: internal_client.h:71
Handle class to manage a Mir surface. It may be null (e.g. default initialized)
Definition: window.h:38
Handle additional requests related to application zones.
Definition: window_management_policy.h:285
The interface through which the window management policy is determined.
Definition: window_management_policy.h:47
Window management functions for querying and updating MirAL's model.
Definition: window_manager_tools.h:59
Definition: window_specification.h:44
A rectangular area of the display. Not tied to a specific output.
Definition: zone.h:36
MirResizeEdge
Hints for resizing a window.
Definition: common.h:413
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
MirWindowState
Definition: common.h:142
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:41
struct MirInputEvent MirInputEvent
Definition: event.h:70
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
@ mir_input_event_modifier_ctrl
Definition: input_event.h:57
@ mir_input_event_modifier_meta
Definition: input_event.h:60
@ mir_input_event_modifier_alt
Definition: input_event.h:49
@ mir_input_event_modifier_shift
Definition: input_event.h:52
@ mir_input_event_modifier_sym
Definition: input_event.h:55
Basic geometry types. Types for dimensions, displacements, etc. and the operations that they support.
Definition: dimensions.h:31
std::shared_ptr< mir::scene::Session > Application
Definition: application.h:34
Definition: displacement.h:34
Definition: point.h:31
Definition: rectangle.h:34
Definition: application_info.h:32
Definition: window_info.h:33

Copyright © 2012-2022 Canonical Ltd.
Generated on Sun Oct 9 06:13:38 UTC 2022
This documentation is licensed under the GPL version 2 or 3.