~alan-griffiths/mir/fix-1654023

« back to all changes in this revision

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

  • Committer: Daniel van Vugt
  • Date: 2015-04-28 07:54:10 UTC
  • mfrom: (2517 development-branch)
  • mto: This revision was merged to the branch mainline in revision 2673.
  • Revision ID: daniel.van.vugt@canonical.com-20150428075410-rwskshfuar7voesp
Merge latest trunk and fix conflicts.

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
};
 
54
 
 
55
// standard window management algorithm:
 
56
//  o Switch apps: tap or click on the corresponding tile
 
57
//  o Move window: Alt-leftmousebutton drag
 
58
//  o Resize window: Alt-middle_button drag
 
59
//  o Maximize/restore current window (to display size): Alt-F11
 
60
//  o Maximize/restore current window (to display height): Shift-F11
 
61
//  o Maximize/restore current window (to display width): Ctrl-F11
 
62
//  o client requests to maximize, vertically maximize & restore
 
63
class CanonicalWindowManagerPolicy
 
64
{
 
65
public:
 
66
    using Tools = BasicWindowManagerTools<CanonicalSessionInfo, CanonicalSurfaceInfo>;
 
67
    using CanonicalSessionInfoMap = typename SessionTo<CanonicalSessionInfo>::type;
 
68
 
 
69
    explicit CanonicalWindowManagerPolicy(
 
70
        Tools* const tools,
 
71
        std::shared_ptr<shell::DisplayLayout> const& display_layout);
 
72
 
 
73
    void click(geometry::Point cursor);
 
74
 
 
75
    void handle_session_info_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
 
76
 
 
77
    void handle_displays_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
 
78
 
 
79
    void resize(geometry::Point cursor);
 
80
 
 
81
    auto handle_place_new_surface(
 
82
        std::shared_ptr<scene::Session> const& session,
 
83
        scene::SurfaceCreationParameters const& request_parameters)
 
84
    -> scene::SurfaceCreationParameters;
 
85
 
 
86
    void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
 
87
 
 
88
    void handle_modify_surface(
 
89
        std::shared_ptr<scene::Session> const& session,
 
90
        std::shared_ptr<scene::Surface> const& surface,
 
91
        SurfaceSpecification const& modifications);
 
92
 
 
93
    void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
 
94
 
 
95
    int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
 
96
 
 
97
    void drag(geometry::Point cursor);
 
98
 
 
99
    bool handle_keyboard_event(MirKeyboardEvent const* event);
 
100
 
 
101
    bool handle_touch_event(MirTouchEvent const* event);
 
102
 
 
103
    bool handle_pointer_event(MirPointerEvent const* event);
 
104
 
 
105
    std::vector<std::shared_ptr<scene::Surface>> generate_decorations_for(
 
106
        std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
 
107
 
 
108
private:
 
109
    static const int modifier_mask =
 
110
        mir_input_event_modifier_alt |
 
111
        mir_input_event_modifier_shift |
 
112
        mir_input_event_modifier_sym |
 
113
        mir_input_event_modifier_ctrl |
 
114
        mir_input_event_modifier_meta;
 
115
 
 
116
    void toggle(MirSurfaceState state);
 
117
 
 
118
    // "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
 
119
    //  *window*,but Mir really only understands surfaces
 
120
    void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
 
121
    auto active_surface() const -> std::shared_ptr<scene::Surface>;
 
122
 
 
123
    bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
 
124
    bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
 
125
    void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
 
126
    void raise_tree(std::shared_ptr<scene::Surface> const& root) const;
 
127
    bool constrained_resize(
 
128
        std::shared_ptr<scene::Surface> const& surface,
 
129
        geometry::Point new_pos,
 
130
        geometry::Size new_size,
 
131
        const bool left_resize,
 
132
        const bool top_resize,
 
133
        geometry::Rectangle const& bounds);
 
134
 
 
135
    Tools* const tools;
 
136
    std::shared_ptr<DisplayLayout> const display_layout;
 
137
 
 
138
    geometry::Rectangle display_area;
 
139
    geometry::Point old_cursor{};
 
140
    std::weak_ptr<scene::Surface> active_surface_;
 
141
};
 
142
 
 
143
using CanonicalWindowManager = BasicWindowManager<CanonicalWindowManagerPolicy, CanonicalSessionInfo, CanonicalSurfaceInfo>;
 
144
}
 
145
}
 
146
 
 
147
#endif /* MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_ */