Mir

Merge lp:~robert-ancell/mir/vt-switch-keys into lp:~mir-team/mir/trunk

Proposed by Robert Ancell
Status: Merged
Approved by: Robert Ancell
Approved revision: no longer in the source branch.
Merged at revision: 943
Proposed branch: lp:~robert-ancell/mir/vt-switch-keys
Merge into: lp:~mir-team/mir/trunk
Diff against target: 204 lines (+137/-2)
5 files modified
include/server/mir/default_server_configuration.h (+3/-0)
src/server/default_server_configuration.cpp (+9/-2)
src/server/input/CMakeLists.txt (+1/-0)
src/server/input/vt_filter.cpp (+83/-0)
src/server/input/vt_filter.h (+41/-0)
To merge this branch: bzr merge lp:~robert-ancell/mir/vt-switch-keys
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt Approve
Chris Halse Rogers Approve
Review via email: mp+179067@code.launchpad.net

Commit message

VT switch on alt+ctrl+Fn

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

This looks good to me, and does what it says on the tin.

It has to land after https://code.launchpad.net/~mlankhorst/mir/setsid/+merge/177800, though.

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

1. Wrote year:
77 + * Copyright © 2012 Canonical Ltd.
165 + * Copyright © 2012 Canonical Ltd.

2. The giant switch statement looks "suboptimal". But it's clear and it works.

3. Missing error checking:
auto console_fd = open("/dev/console", O_RDONLY | O_NDELAY);

Tested with setsid and works nicely. So I'm not going to block on the above issues, but you might want to consider them.

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

"Wrote"? I mean "Wrong" year.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

4. Is O_RDONLY correct for ioctl usage?

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/server/mir/default_server_configuration.h'
2--- include/server/mir/default_server_configuration.h 2013-08-07 20:04:16 +0000
3+++ include/server/mir/default_server_configuration.h 2013-08-08 01:41:29 +0000
4@@ -97,6 +97,7 @@
5 class InputConfiguration;
6 class CursorListener;
7 class InputRegion;
8+class VTFilter;
9 }
10
11 namespace logging
12@@ -234,8 +235,10 @@
13
14
15 std::shared_ptr<input::InputConfiguration> input_configuration;
16+ std::shared_ptr<input::VTFilter> vt_filter;
17
18 CachedPtr<input::InputReport> input_report;
19+ CachedPtr<input::CompositeEventFilter> composite_event_filter;
20 CachedPtr<input::InputManager> input_manager;
21 CachedPtr<input::InputRegion> input_region;
22 CachedPtr<surfaces::InputRegistrar> input_registrar;
23
24=== modified file 'src/server/default_server_configuration.cpp'
25--- src/server/default_server_configuration.cpp 2013-08-07 20:04:16 +0000
26+++ src/server/default_server_configuration.cpp 2013-08-08 01:41:29 +0000
27@@ -62,6 +62,7 @@
28 #include "mir/input/null_input_report.h"
29 #include "mir/input/display_input_region.h"
30 #include "mir/input/event_filter_chain.h"
31+#include "input/vt_filter.h"
32 #include "input/android/default_android_input_configuration.h"
33 #include "input/android/android_input_manager.h"
34 #include "input/android/android_input_targeter.h"
35@@ -99,7 +100,6 @@
36
37 namespace
38 {
39-std::initializer_list<std::shared_ptr<mi::EventFilter> const> empty_filter_list{};
40 mir::SharedLibrary const* load_library(std::string const& libname);
41 }
42
43@@ -483,7 +483,14 @@
44 std::shared_ptr<mi::CompositeEventFilter>
45 mir::DefaultServerConfiguration::the_composite_event_filter()
46 {
47- return std::make_shared<mi::EventFilterChain>(empty_filter_list);
48+ return composite_event_filter(
49+ [this]() -> std::shared_ptr<mi::CompositeEventFilter>
50+ {
51+ if (!vt_filter)
52+ vt_filter = std::make_shared<mi::VTFilter>();
53+ std::initializer_list<std::shared_ptr<mi::EventFilter> const> filter_list {vt_filter};
54+ return std::make_shared<mi::EventFilterChain>(filter_list);
55+ });
56 }
57
58 std::shared_ptr<mi::InputReport>
59
60=== modified file 'src/server/input/CMakeLists.txt'
61--- src/server/input/CMakeLists.txt 2013-07-22 02:18:21 +0000
62+++ src/server/input/CMakeLists.txt 2013-08-08 01:41:29 +0000
63@@ -6,6 +6,7 @@
64 null_input_configuration.cpp
65 null_input_report.cpp
66 display_input_region.cpp
67+ vt_filter.cpp
68 )
69
70 add_subdirectory(android)
71
72=== added file 'src/server/input/vt_filter.cpp'
73--- src/server/input/vt_filter.cpp 1970-01-01 00:00:00 +0000
74+++ src/server/input/vt_filter.cpp 2013-08-08 01:41:29 +0000
75@@ -0,0 +1,83 @@
76+/*
77+ * Copyright © 2012 Canonical Ltd.
78+ *
79+ * This program is free software: you can redistribute it and/or modify it
80+ * under the terms of the GNU General Public License version 3,
81+ * as published by the Free Software Foundation.
82+ *
83+ * This program is distributed in the hope that it will be useful,
84+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
85+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86+ * GNU General Public License for more details.
87+ *
88+ * You should have received a copy of the GNU General Public License
89+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
90+ *
91+ * Authored by: Robert Ancell <robert.ancell@canonical.com>
92+ */
93+
94+#include "vt_filter.h"
95+
96+#include <linux/input.h>
97+#include <linux/vt.h>
98+#include <sys/ioctl.h>
99+#include <fcntl.h>
100+#include <unistd.h>
101+
102+bool mir::input::VTFilter::handle(MirEvent const& event)
103+{
104+ if (event.type == mir_event_type_key &&
105+ event.key.action == mir_key_action_down &&
106+ (event.key.modifiers & mir_key_modifier_alt) &&
107+ (event.key.modifiers & mir_key_modifier_ctrl))
108+ {
109+ switch (event.key.scan_code)
110+ {
111+ case KEY_F1:
112+ set_active_vt(1);
113+ return true;
114+ case KEY_F2:
115+ set_active_vt(2);
116+ return true;
117+ case KEY_F3:
118+ set_active_vt(3);
119+ return true;
120+ case KEY_F4:
121+ set_active_vt(4);
122+ return true;
123+ case KEY_F5:
124+ set_active_vt(5);
125+ return true;
126+ case KEY_F6:
127+ set_active_vt(6);
128+ return true;
129+ case KEY_F7:
130+ set_active_vt(7);
131+ return true;
132+ case KEY_F8:
133+ set_active_vt(8);
134+ return true;
135+ case KEY_F9:
136+ set_active_vt(9);
137+ return true;
138+ case KEY_F10:
139+ set_active_vt(10);
140+ return true;
141+ case KEY_F11:
142+ set_active_vt(11);
143+ return true;
144+ case KEY_F12:
145+ set_active_vt(12);
146+ return true;
147+ }
148+ }
149+
150+ return false;
151+}
152+
153+void mir::input::VTFilter::set_active_vt(int vt)
154+{
155+ auto console_fd = open("/dev/console", O_RDONLY | O_NDELAY);
156+ ioctl(console_fd, VT_ACTIVATE, vt);
157+ close(console_fd);
158+}
159
160=== added file 'src/server/input/vt_filter.h'
161--- src/server/input/vt_filter.h 1970-01-01 00:00:00 +0000
162+++ src/server/input/vt_filter.h 2013-08-08 01:41:29 +0000
163@@ -0,0 +1,41 @@
164+/*
165+ * Copyright © 2012 Canonical Ltd.
166+ *
167+ * This program is free software: you can redistribute it and/or modify it
168+ * under the terms of the GNU General Public License version 3,
169+ * as published by the Free Software Foundation.
170+ *
171+ * This program is distributed in the hope that it will be useful,
172+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
173+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174+ * GNU General Public License for more details.
175+ *
176+ * You should have received a copy of the GNU General Public License
177+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
178+ *
179+ * Authored by: Robert Ancell <robert.ancell@canonical.com>
180+ */
181+
182+#ifndef MIR_INPUT_VT_FILTER_H_
183+#define MIR_INPUT_VT_FILTER_H_
184+
185+#include "mir/input/event_filter.h"
186+
187+namespace mir
188+{
189+namespace input
190+{
191+
192+class VTFilter : public EventFilter
193+{
194+public:
195+ bool handle(MirEvent const& event) override;
196+
197+private:
198+ void set_active_vt(int vt);
199+};
200+
201+}
202+}
203+
204+#endif // MIR_INPUT_VT_FILTER_H_

Subscribers

People subscribed via source and target branches