~alan-griffiths/mir/migrate-tests-to-miral

« back to all changes in this revision

Viewing changes to examples/server_example_canonical_window_manager.h

  • Committer: Christopher James Halse Rogers
  • Date: 2017-09-07 05:58:13 UTC
  • mfrom: (4242 development-branch)
  • mto: (4243.1.1 mir3)
  • mto: This revision was merged to the branch mainline in revision 4244.
  • Revision ID: christopher.halse.rogers@canonical.com-20170907055813-4qsg25nirybc8jj3
Merge trunk, resolving conflict

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 2 or 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_CANONICAL_WINDOW_MANAGER_H_
20
 
#define MIR_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_
21
 
 
22
 
#include "server_example_basic_window_manager.h"
23
 
 
24
 
#include "mir/geometry/displacement.h"
25
 
 
26
 
#include <atomic>
27
 
#include <set>
28
 
 
29
 
///\example server_example_canonical_window_manager.h
30
 
// Based on "Mir and Unity: Surfaces, input, and displays (v0.3)"
31
 
 
32
 
namespace mir
33
 
{
34
 
namespace shell { class DisplayLayout; }
35
 
namespace graphics
36
 
{
37
 
class GraphicBufferAllocator;
38
 
}
39
 
namespace examples
40
 
{
41
 
// standard window management algorithm:
42
 
//  o Switch apps: tap or click on the corresponding tile
43
 
//  o Move window: Alt-leftmousebutton drag (three finger drag)
44
 
//  o Resize window: Alt-middle_button drag (two finger drag)
45
 
//  o Maximize/restore current window (to display size): Alt-F11
46
 
//  o Maximize/restore current window (to display height): Shift-F11
47
 
//  o Maximize/restore current window (to display width): Ctrl-F11
48
 
//  o client requests to maximize, vertically maximize & restore
49
 
class CanonicalWindowManagerPolicyCopy  : public WindowManagementPolicy
50
 
{
51
 
public:
52
 
 
53
 
    explicit CanonicalWindowManagerPolicyCopy(
54
 
        WindowManagerTools* const tools,
55
 
        std::shared_ptr<shell::DisplayLayout> const& display_layout,
56
 
        std::shared_ptr<graphics::GraphicBufferAllocator> const& allocator);
57
 
 
58
 
    void click(geometry::Point cursor);
59
 
 
60
 
    void handle_session_info_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
61
 
 
62
 
    void handle_displays_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
63
 
 
64
 
    void resize(geometry::Point cursor);
65
 
 
66
 
    auto handle_place_new_surface(
67
 
        std::shared_ptr<scene::Session> const& session,
68
 
        scene::SurfaceCreationParameters const& request_parameters)
69
 
    -> scene::SurfaceCreationParameters;
70
 
 
71
 
    void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
72
 
 
73
 
    void handle_modify_surface(
74
 
        std::shared_ptr<scene::Session> const& session,
75
 
        std::shared_ptr<scene::Surface> const& surface,
76
 
        shell::SurfaceSpecification const& modifications);
77
 
 
78
 
    void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
79
 
 
80
 
    int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirWindowState value);
81
 
 
82
 
    void drag(geometry::Point cursor);
83
 
 
84
 
    bool handle_keyboard_event(MirKeyboardEvent const* event);
85
 
 
86
 
    bool handle_touch_event(MirTouchEvent const* event);
87
 
 
88
 
    bool handle_pointer_event(MirPointerEvent const* event);
89
 
 
90
 
    void handle_raise_surface(
91
 
        std::shared_ptr<scene::Session> const& session,
92
 
        std::shared_ptr<scene::Surface> const& surface);
93
 
 
94
 
    void generate_decorations_for(
95
 
        std::shared_ptr<scene::Session> const& session,
96
 
        std::shared_ptr<scene::Surface> const& surface,
97
 
        SurfaceInfoMap& surface_map,
98
 
        std::function<frontend::SurfaceId(std::shared_ptr<scene::Session> const& session, scene::SurfaceCreationParameters const& params)> const& build);
99
 
 
100
 
private:
101
 
    static const int modifier_mask =
102
 
        mir_input_event_modifier_alt |
103
 
        mir_input_event_modifier_shift |
104
 
        mir_input_event_modifier_sym |
105
 
        mir_input_event_modifier_ctrl |
106
 
        mir_input_event_modifier_meta;
107
 
 
108
 
    void toggle(MirWindowState state);
109
 
 
110
 
    // "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
111
 
    //  *window*,but Mir really only understands surfaces
112
 
    void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
113
 
    auto active_surface() const -> std::shared_ptr<scene::Surface>;
114
 
 
115
 
    bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
116
 
    bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
117
 
    void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
118
 
    void apply_resize(
119
 
        std::shared_ptr<mir::scene::Surface> const& surface,
120
 
        std::shared_ptr<mir::scene::Surface> const& titlebar,
121
 
        geometry::Point const& new_pos,
122
 
        geometry::Size const& new_size) const;
123
 
 
124
 
    WindowManagerTools* const tools;
125
 
    std::shared_ptr<shell::DisplayLayout> const display_layout;
126
 
    std::shared_ptr<graphics::GraphicBufferAllocator> const allocator;
127
 
 
128
 
    geometry::Rectangle display_area;
129
 
    geometry::Point old_cursor{};
130
 
    std::weak_ptr<scene::Surface> active_surface_;
131
 
    using FullscreenSurfaces = std::set<std::weak_ptr<scene::Surface>, std::owner_less<std::weak_ptr<scene::Surface>>>;
132
 
 
133
 
    FullscreenSurfaces fullscreen_surfaces;
134
 
 
135
 
    bool resizing = false;
136
 
    bool left_resize = false;
137
 
    bool top_resize = false;
138
 
};
139
 
}
140
 
}
141
 
 
142
 
#endif /* MIR_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_ */