~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to src/server/shell/canonical_window_manager.h

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
Import upstream version 0.13.0+15.10.20150512

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_SHELL_CANONICAL_WINDOW_MANAGER_H_
 
20
#define MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_
 
21
 
 
22
#include "basic_window_manager.h"
 
23
 
 
24
#include "mir/geometry/displacement.h"
 
25
 
 
26
namespace mir
 
27
{
 
28
namespace shell
 
29
{
 
30
class DisplayLayout;
 
31
 
 
32
struct CanonicalSessionInfo
 
33
{
 
34
    int surfaces{0};
 
35
};
 
36
 
 
37
struct CanonicalSurfaceInfo
 
38
{
 
39
    CanonicalSurfaceInfo(
 
40
        std::shared_ptr<scene::Session> const& session,
 
41
        std::shared_ptr<scene::Surface> const& surface,
 
42
        scene::SurfaceCreationParameters const& params);
 
43
 
 
44
    MirSurfaceState state;
 
45
    geometry::Rectangle restore_rect;
 
46
    std::weak_ptr<scene::Session> session;
 
47
    std::weak_ptr<scene::Surface> parent;
 
48
    std::vector<std::weak_ptr<scene::Surface>> children;
 
49
    optional_value<geometry::Width> min_width;
 
50
    optional_value<geometry::Height> min_height;
 
51
    optional_value<geometry::Width> max_width;
 
52
    optional_value<geometry::Height> max_height;
 
53
    mir::optional_value<geometry::DeltaX> width_inc;
 
54
    mir::optional_value<geometry::DeltaY> height_inc;
 
55
    mir::optional_value<SurfaceAspectRatio> min_aspect;
 
56
    mir::optional_value<SurfaceAspectRatio> max_aspect;
 
57
};
 
58
 
 
59
// standard window management algorithm:
 
60
//  o Switch apps: tap or click on the corresponding tile
 
61
//  o Move window: Alt-leftmousebutton drag
 
62
//  o Resize window: Alt-middle_button drag
 
63
//  o Maximize/restore current window (to display size): Alt-F11
 
64
//  o Maximize/restore current window (to display height): Shift-F11
 
65
//  o Maximize/restore current window (to display width): Ctrl-F11
 
66
//  o client requests to maximize, vertically maximize & restore
 
67
class CanonicalWindowManagerPolicy
 
68
{
 
69
public:
 
70
    using Tools = BasicWindowManagerTools<CanonicalSessionInfo, CanonicalSurfaceInfo>;
 
71
    using CanonicalSessionInfoMap = typename SessionTo<CanonicalSessionInfo>::type;
 
72
 
 
73
    explicit CanonicalWindowManagerPolicy(
 
74
        Tools* const tools,
 
75
        std::shared_ptr<shell::DisplayLayout> const& display_layout);
 
76
 
 
77
    void click(geometry::Point cursor);
 
78
 
 
79
    void handle_session_info_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
 
80
 
 
81
    void handle_displays_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
 
82
 
 
83
    void resize(geometry::Point cursor);
 
84
 
 
85
    auto handle_place_new_surface(
 
86
        std::shared_ptr<scene::Session> const& session,
 
87
        scene::SurfaceCreationParameters const& request_parameters)
 
88
    -> scene::SurfaceCreationParameters;
 
89
 
 
90
    void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
 
91
 
 
92
    void handle_modify_surface(
 
93
        std::shared_ptr<scene::Session> const& session,
 
94
        std::shared_ptr<scene::Surface> const& surface,
 
95
        SurfaceSpecification const& modifications);
 
96
 
 
97
    void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
 
98
 
 
99
    int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
 
100
 
 
101
    void drag(geometry::Point cursor);
 
102
 
 
103
    bool handle_keyboard_event(MirKeyboardEvent const* event);
 
104
 
 
105
    bool handle_touch_event(MirTouchEvent const* event);
 
106
 
 
107
    bool handle_pointer_event(MirPointerEvent const* event);
 
108
 
 
109
    std::vector<std::shared_ptr<scene::Surface>> generate_decorations_for(
 
110
        std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
 
111
 
 
112
private:
 
113
    static const int modifier_mask =
 
114
        mir_input_event_modifier_alt |
 
115
        mir_input_event_modifier_shift |
 
116
        mir_input_event_modifier_sym |
 
117
        mir_input_event_modifier_ctrl |
 
118
        mir_input_event_modifier_meta;
 
119
 
 
120
    void toggle(MirSurfaceState state);
 
121
 
 
122
    // "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
 
123
    //  *window*,but Mir really only understands surfaces
 
124
    void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
 
125
    auto active_surface() const -> std::shared_ptr<scene::Surface>;
 
126
 
 
127
    bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
 
128
    bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
 
129
    void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
 
130
    void raise_tree(std::shared_ptr<scene::Surface> const& root) const;
 
131
    bool constrained_resize(
 
132
        std::shared_ptr<scene::Surface> const& surface,
 
133
        geometry::Point const& requested_pos,
 
134
        geometry::Size const& requested_size,
 
135
        const bool left_resize,
 
136
        const bool top_resize,
 
137
        geometry::Rectangle const& bounds);
 
138
 
 
139
    Tools* const tools;
 
140
    std::shared_ptr<DisplayLayout> const display_layout;
 
141
 
 
142
    geometry::Rectangle display_area;
 
143
    geometry::Point old_cursor{};
 
144
    std::weak_ptr<scene::Surface> active_surface_;
 
145
};
 
146
 
 
147
using CanonicalWindowManager = BasicWindowManager<CanonicalWindowManagerPolicy, CanonicalSessionInfo, CanonicalSurfaceInfo>;
 
148
}
 
149
}
 
150
 
 
151
#endif /* MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_ */