Mir
floating_window_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2016-2019 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 
17 #ifndef MIRAL_SHELL_FLOATING_WINDOW_MANAGER_H
18 #define MIRAL_SHELL_FLOATING_WINDOW_MANAGER_H
19 
20 #include <miral/minimal_window_manager.h>
21 
22 #include "splash_session.h"
23 
24 #include <mir_toolkit/events/enums.h>
25 
26 #include <chrono>
27 #include <map>
28 
29 namespace miral { class InternalClientLauncher; }
30 
31 using namespace mir::geometry;
32 
33 class DecorationProvider;
34 
36 {
37 public:
39  miral::WindowManagerTools const& tools,
40  std::shared_ptr<SplashSession> const& spinner,
41  miral::InternalClientLauncher const& launcher,
42  std::function<void()>& shutdown_hook);
44 
46  miral::ApplicationInfo const& app_info, miral::WindowSpecification const& request_parameters) override;
47 
48  /** @name example event handling:
49  * o Switch apps: Alt+Tab, tap or click on the corresponding window
50  * o Switch window: Alt+`, tap or click on the corresponding window
51  * o Move window: Alt-leftmousebutton drag (three finger drag)
52  * o Resize window: Alt-middle_button drag (three finger pinch)
53  * o Maximize/restore current window (to display size): Alt-F11
54  * o Maximize/restore current window (to display height): Shift-F11
55  * o Maximize/restore current window (to display width): Ctrl-F11
56  * o Switch workspace . . . . . . . . . . : Meta-Alt-[F1|F2|F3|F4]
57  * o Switch workspace taking active window: Meta-Ctrl-[F1|F2|F3|F4]
58  * @{ */
59  bool handle_pointer_event(MirPointerEvent const* event) override;
60  bool handle_touch_event(MirTouchEvent const* event) override;
61  bool handle_keyboard_event(MirKeyboardEvent const* event) override;
62  /** @} */
63 
64  /** @name track events that affect titlebar
65  * @{ */
66  void advise_new_window(miral::WindowInfo const& window_info) override;
67  void handle_window_ready(miral::WindowInfo& window_info) override;
68  void advise_focus_gained(miral::WindowInfo const& info) override;
69 
70  void handle_modify_window(miral::WindowInfo& window_info, miral::WindowSpecification const& modifications) override;
71  /** @} */
72 
73 protected:
74  static const int modifier_mask =
80 
81 private:
82  void toggle(MirWindowState state);
83 
84  int old_touch_pinch_top = 0;
85  int old_touch_pinch_left = 0;
86  int old_touch_pinch_width = 0;
87  int old_touch_pinch_height = 0;
88  bool pinching = false;
89 
90  std::shared_ptr<SplashSession> const spinner;
91 
92  std::unique_ptr<DecorationProvider> const decoration_provider;
93 
94  void keep_window_within_constraints(
95  miral::WindowInfo const& window_info,
96  Displacement& movement,
97  Width& new_width,
98  Height& new_height) const;
99 
100  // Workaround for lp:1627697
101  std::chrono::steady_clock::time_point last_resize;
102 
103  void advise_adding_to_workspace(
104  std::shared_ptr<miral::Workspace> const& workspace,
105  std::vector<miral::Window> const& windows) override;
106 
107  auto confirm_placement_on_display(
108  miral::WindowInfo const& window_info,
109  MirWindowState new_state,
110  Rectangle const& new_placement) -> Rectangle override;
111 
112  // Switch workspace, taking window (if not null)
113  void switch_workspace_to(
114  std::shared_ptr<miral::Workspace> const& workspace,
115  miral::Window const& window = miral::Window{});
116 
117  std::shared_ptr<miral::Workspace> active_workspace;
118  std::map<int, std::shared_ptr<miral::Workspace>> key_to_workspace;
119  std::map<std::shared_ptr<miral::Workspace>, miral::Window> workspace_to_active;
120 
121  void apply_workspace_visible_to(miral::Window const& window);
122 
123  void apply_workspace_hidden_to(miral::Window const& window);
124 
125  void keep_spinner_on_top();
126 };
127 
128 #endif //MIRAL_SHELL_FLOATING_WINDOW_MANAGER_H

Copyright © 2012-2022 Canonical Ltd.
Generated on Tue Sep 13 03:20:30 UTC 2022
This documentation is licensed under the GPL version 2 or 3.