Merge ~santoshbit2007/oxide:GetShellMode_Implementation into oxide:master

Proposed by Santosh
Status: Merged
Merge reported by: Santosh
Merged at revision: not available
Proposed branch: ~santoshbit2007/oxide:GetShellMode_Implementation
Merge into: oxide:master
Diff against target: 404 lines (+176/-9)
13 files modified
build/cmake/ChromiumBuildShim.cmake (+13/-0)
build/config/Qt5/BUILD.gn (+8/-0)
build/config/Qt5/moc.gni (+12/-3)
build/config/Qt5/moc.py (+6/-1)
build/config/build_flags.gni (+2/-0)
build/config/linux/qt/BUILD.gn (+7/-0)
qt/core/BUILD.gn (+14/-0)
qt/core/browser/qt_screen.cc (+90/-0)
qt/core/browser/qt_screen.h (+18/-0)
shared/browser/oxide_content_browser_client.cc (+1/-1)
shared/browser/screen.h (+1/-1)
shared/browser/screen_observer.h (+1/-0)
shared/browser/screen_unittest.cc (+3/-3)
Reviewer Review Type Date Requested Status
Chris Coulson Approve
Review via email: mp+306388@code.launchpad.net

Description of the change

Implement shell mode change detection based on
scanning of input devices.

To post a comment you must log in.
Revision history for this message
Santosh (santoshbit2007) wrote :

Just to note, QtSystemInfo is not yet in ubuntu image, but silo to include it in image is in testing phase, so we might get it with ubuntu Image.

For images, QtsystemInfo is not available, user need install package libqt5systeminfo5

May be we should use declare some #define to check availability for package and write code within that check. Any suggestion is welcomed.
 e.g all the code below should put within
#if defined QT5_SYSTEM_INFO
  // code
#endif

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks, I've left a few comments inline.

This does also need to be optional at build time - I don't mind if this is a build option or an automatic check (there are some CMake macros that could help here, eg https://cmake.org/cmake/help/v3.0/module/CheckCXXSymbolExists.html)

review: Needs Fixing
Revision history for this message
Santosh (santoshbit2007) :
Revision history for this message
Chris Coulson (chrisccoulson) :
Revision history for this message
Santosh (santoshbit2007) :
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks, I've left some comments inline

review: Needs Fixing
Revision history for this message
Chris Coulson (chrisccoulson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/build/cmake/ChromiumBuildShim.cmake b/build/cmake/ChromiumBuildShim.cmake
index b6fe9ba..30a2288 100644
--- a/build/cmake/ChromiumBuildShim.cmake
+++ b/build/cmake/ChromiumBuildShim.cmake
@@ -267,6 +267,19 @@ function(run_generate_ninja)
267 list(APPEND MAKE_GN_ARGS_CMD -Dqt_moc_executable=${QT_MOC_EXECUTABLE})267 list(APPEND MAKE_GN_ARGS_CMD -Dqt_moc_executable=${QT_MOC_EXECUTABLE})
268 endif()268 endif()
269269
270
271 find_package(Qt5SystemInfo QUIET)
272 if(Qt5SystemInfo_FOUND)
273 set(CMAKE_REQUIRED_FLAGS "-fPIC")
274 set(CMAKE_REQUIRED_INCLUDES ${Qt5SystemInfo_INCLUDE_DIRS})
275 CHECK_INCLUDE_FILE_CXX("QInputDevice" HAVE_QINPUTDEVICE)
276 if (HAVE_QINPUTDEVICE EQUAL 1)
277 list(APPEND MAKE_GN_ARGS_CMD -Duse_qinputdevice=true)
278 endif()
279 else()
280 list(APPEND MAKE_GN_ARGS_CMD -Duse_qinputdevice=false)
281 endif()
282
270 if(BOOTSTRAP_GN)283 if(BOOTSTRAP_GN)
271 list(APPEND MAKE_GN_ARGS_CMD -Denable_gn_build=true)284 list(APPEND MAKE_GN_ARGS_CMD -Denable_gn_build=true)
272 else()285 else()
diff --git a/build/config/Qt5/BUILD.gn b/build/config/Qt5/BUILD.gn
index 677df5d..e38c131 100644
--- a/build/config/Qt5/BUILD.gn
+++ b/build/config/Qt5/BUILD.gn
@@ -16,6 +16,8 @@
16# License along with this library; if not, write to the Free Software16# License along with this library; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
19import("//oxide/build/config/build_flags.gni")
20
19assert(is_linux)21assert(is_linux)
2022
21group("Core") {23group("Core") {
@@ -45,3 +47,9 @@ group("Network") {
45group("Positioning") {47group("Positioning") {
46 public_configs = [ "//oxide/build/config/linux/qt:Qt5Positioning" ]48 public_configs = [ "//oxide/build/config/linux/qt:Qt5Positioning" ]
47}49}
50
51group("SystemInfo") {
52 if (use_qinputdevice) {
53 public_configs = [ "//oxide/build/config/linux/qt:Qt5SystemInfo" ]
54 }
55}
diff --git a/build/config/Qt5/moc.gni b/build/config/Qt5/moc.gni
index e981bf5..2bf2fa2 100644
--- a/build/config/Qt5/moc.gni
+++ b/build/config/Qt5/moc.gni
@@ -34,9 +34,15 @@ template("moc_action_foreach") {
34 output = "${root_gen_dir}/{{source_root_relative_dir}}/${invoker.output_prefix}{{source_name_part}}.${invoker.output_extension}"34 output = "${root_gen_dir}/{{source_root_relative_dir}}/${invoker.output_prefix}{{source_name_part}}.${invoker.output_extension}"
35 outputs = [ output ]35 outputs = [ output ]
3636
37 args = [37 args = [ "-m", "$qt_moc_executable" ]
38 "-m", "$qt_moc_executable", "{{source}}", rebase_path("$output", "", ".")38 if (defined(invoker.defines)) {
39 ]39 define_flags = ""
40 foreach(define, invoker.defines) {
41 define_flags += "-D" + define + " "
42 }
43 args += [ "-f", "$define_flags" ]
44 }
45 args += [ "{{source}}", rebase_path("$output", "", ".") ]
40 }46 }
41}47}
4248
@@ -60,6 +66,9 @@ template("qtmoc") {
60 }66 }
6167
62 targets = []68 targets = []
69 if (defined(invoker.defines)) {
70 defines = invoker.defines
71 }
6372
64 if (defined(sources_cc)) {73 if (defined(sources_cc)) {
65 name = "${target_name}_cc"74 name = "${target_name}_cc"
diff --git a/build/config/Qt5/moc.py b/build/config/Qt5/moc.py
index af0ed8d..abbb113 100644
--- a/build/config/Qt5/moc.py
+++ b/build/config/Qt5/moc.py
@@ -27,6 +27,7 @@ import sys
27def main(argv):27def main(argv):
28 parser = OptionParser(usage="usage: %prog [options] input output")28 parser = OptionParser(usage="usage: %prog [options] input output")
29 parser.add_option("-m", dest="moc")29 parser.add_option("-m", dest="moc")
30 parser.add_option("-f", dest="defs")
3031
31 (options, args) = parser.parse_args(argv)32 (options, args) = parser.parse_args(argv)
3233
@@ -44,7 +45,11 @@ def main(argv):
44 print("moc is not executable", file=sys.stderr)45 print("moc is not executable", file=sys.stderr)
45 return 146 return 1
4647
47 subprocess.check_call([moc, "-o", args[1], args[0]])48 cmd_line = [moc, "-o", args[1], args[0]]
49 if options.defs != None:
50 cmd_line += options.defs.strip().split();
51
52 subprocess.check_call(cmd_line)
4853
49if __name__ == "__main__":54if __name__ == "__main__":
50 sys.exit(main(sys.argv[1:]))55 sys.exit(main(sys.argv[1:]))
diff --git a/build/config/build_flags.gni b/build/config/build_flags.gni
index 0474b7d..487e4b0 100644
--- a/build/config/build_flags.gni
+++ b/build/config/build_flags.gni
@@ -23,6 +23,8 @@ declare_args() {
2323
24 enable_mediahub = false24 enable_mediahub = false
2525
26 use_qinputdevice = false
27
26 oxide_gettext_domain = false28 oxide_gettext_domain = false
2729
28 oxide_libexec_subdir = ""30 oxide_libexec_subdir = ""
diff --git a/build/config/linux/qt/BUILD.gn b/build/config/linux/qt/BUILD.gn
index a413d69..c96ce0e 100644
--- a/build/config/linux/qt/BUILD.gn
+++ b/build/config/linux/qt/BUILD.gn
@@ -17,6 +17,7 @@
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
19import("//build/config/linux/pkg_config.gni")19import("//build/config/linux/pkg_config.gni")
20import("//oxide/build/config/build_flags.gni")
2021
21template("qt_private_includes") {22template("qt_private_includes") {
22 module = invoker.module23 module = invoker.module
@@ -88,3 +89,9 @@ pkg_config("Qt5Positioning") {
88 visibility = [ "//oxide/build/config/Qt5:Positioning" ]89 visibility = [ "//oxide/build/config/Qt5:Positioning" ]
89 packages = [ "Qt5Positioning" ]90 packages = [ "Qt5Positioning" ]
90}91}
92
93if (use_qinputdevice) {
94 pkg_config("Qt5SystemInfo") {
95 packages = [ "Qt5SystemInfo" ]
96 }
97}
diff --git a/qt/core/BUILD.gn b/qt/core/BUILD.gn
index 06d58d2..08eac79 100644
--- a/qt/core/BUILD.gn
+++ b/qt/core/BUILD.gn
@@ -38,6 +38,10 @@ config("core_api_include_dir") {
38}38}
3939
40qtmoc("core_moc_gen") {40qtmoc("core_moc_gen") {
41 if (use_qinputdevice) {
42 defines = [ "USE_QINPUTDEVICE" ]
43 }
44
41 sources = [45 sources = [
42 "api/oxideqcertificateerror.h",46 "api/oxideqcertificateerror.h",
43 "api/oxideqdownloadrequest.h",47 "api/oxideqdownloadrequest.h",
@@ -118,6 +122,11 @@ source_set("core_sources") {
118 "//url"122 "//url"
119 ]123 ]
120124
125 if (use_qinputdevice) {
126 deps += [ "//oxide/build/config/Qt5:SystemInfo" ]
127 defines += [ "USE_QINPUTDEVICE" ]
128 }
129
121 sources = [130 sources = [
122 "$target_gen_dir/api/moc_oxideqcertificateerror.cc",131 "$target_gen_dir/api/moc_oxideqcertificateerror.cc",
123 "$target_gen_dir/api/moc_oxideqdownloadrequest.cc",132 "$target_gen_dir/api/moc_oxideqdownloadrequest.cc",
@@ -386,6 +395,11 @@ test_executable("core_screen_unittests") {
386 "//ui/display",395 "//ui/display",
387 ]396 ]
388397
398 if (use_qinputdevice) {
399 deps += [ "//oxide/build/config/Qt5:SystemInfo" ]
400 defines += [ "USE_QINPUTDEVICE" ]
401 }
402
389 sources = [403 sources = [
390 "browser/qt_screen_unittest.cc",404 "browser/qt_screen_unittest.cc",
391 "test/run_all_unittests.cc",405 "test/run_all_unittests.cc",
diff --git a/qt/core/browser/qt_screen.cc b/qt/core/browser/qt_screen.cc
index 8273885..fa9f3ba 100644
--- a/qt/core/browser/qt_screen.cc
+++ b/qt/core/browser/qt_screen.cc
@@ -31,6 +31,7 @@
3131
32#include "shared/browser/display_form_factor.h"32#include "shared/browser/display_form_factor.h"
33#include "shared/browser/hybris_utils.h"33#include "shared/browser/hybris_utils.h"
34#include "shared/browser/shell_mode.h"
3435
35#include "oxide_qt_dpi_utils.h"36#include "oxide_qt_dpi_utils.h"
36#include "oxide_qt_screen_utils.h"37#include "oxide_qt_screen_utils.h"
@@ -192,6 +193,83 @@ void Screen::OnPrimaryScreenChanged(QScreen* screen) {
192 NotifyPrimaryDisplayChanged();193 NotifyPrimaryDisplayChanged();
193}194}
194195
196#if defined(USE_QINPUTDEVICE)
197void Screen::OnInputDeviceAdded(QInputDevice* device) {
198 DCHECK(input_device_manager_.count() > 0);
199 VLOG(1) << "Input Device ADDED : " << device->name().toStdString();
200 ShellMode mode = GetShellMode();
201 if (mode != current_shell_mode_) {
202 current_shell_mode_ = mode;
203 NotifyShellModeChanged();
204 }
205}
206
207void Screen::OnInputDeviceRemoved(const QString& deviceid) {
208 VLOG(1) << "Input Device REMOVED : " << deviceid.toStdString();
209 ShellMode mode = GetShellMode();
210 if (mode != current_shell_mode_) {
211 current_shell_mode_ = mode;
212 NotifyShellModeChanged();
213 }
214}
215
216void Screen::OnInputDevicesReady() {
217 VLOG(2) << "Input Devices READY";
218 current_shell_mode_ = GetShellMode();
219 NotifyShellModeChanged();
220}
221
222bool Screen::GetShellModeFromInputDevices(ShellMode* mode) {
223 QMap<QString, QInputDevice*> device_map;
224 device_map = input_device_manager_.deviceMap();
225 bool mouse = false, keyboard = false, touchpad = false, touchscreen = false;
226 for (auto i = device_map.begin(); i != device_map.end(); ++i) {
227 const QInputDevice::InputTypeFlags type = i.value()->types();
228 if (type & QInputDevice::InputType::Mouse) {
229 mouse = true;
230 }
231 if (type & QInputDevice::InputType::Keyboard) {
232 keyboard = true;
233 }
234 if (type & QInputDevice::InputType::TouchPad) {
235 touchpad = true;
236 }
237 if (type & QInputDevice::InputType::TouchScreen) {
238 touchscreen = true;
239 }
240 }
241 if (mouse || keyboard || touchpad) {
242 *mode = ShellMode::Windowed;
243 return true;
244 }
245 if (touchscreen) {
246 *mode = ShellMode::NonWindowed;
247 return true;
248 }
249
250 return false;
251}
252#endif
253
254ShellMode Screen::GetShellMode() {
255 ShellMode mode;
256 // Qt input devices state heuristics to detect mode.
257 bool ret = false;
258#if defined(USE_QINPUTDEVICE)
259 ret = GetShellModeFromInputDevices(&mode);
260#endif
261
262 if (!ret) {
263 // oxide heuristics to detect mode form factor, hybris.
264 mode = oxide::Screen::GetShellMode();
265 }
266
267 // other heuristics to determine like connecting
268 // device to Monitor.
269 // mode = .....
270 return mode;
271}
272
195void Screen::OnPlatformScreenPropertyChanged(QPlatformScreen* screen,273void Screen::OnPlatformScreenPropertyChanged(QPlatformScreen* screen,
196 const QString& property_name) {274 const QString& property_name) {
197 if (property_name == QStringLiteral("scale") ||275 if (property_name == QStringLiteral("scale") ||
@@ -261,6 +339,18 @@ Screen::Screen() {
261 SLOT(OnPrimaryScreenChanged(QScreen*)));339 SLOT(OnPrimaryScreenChanged(QScreen*)));
262 }340 }
263#endif341#endif
342#if defined(USE_QINPUTDEVICE)
343 input_device_manager_.setFilter(QInputDevice::InputType::Mouse |
344 QInputDevice::InputType::Keyboard |
345 QInputDevice::InputType::TouchPad |
346 QInputDevice::InputType::TouchScreen);
347 connect(&input_device_manager_, SIGNAL(ready()),
348 SLOT(OnInputDevicesReady()));
349 connect(&input_device_manager_, SIGNAL(deviceAdded(QInputDevice*)),
350 SLOT(OnInputDeviceAdded(QInputDevice*)));
351 connect(&input_device_manager_, SIGNAL(deviceRemoved(const QString&)),
352 SLOT(OnInputDeviceRemoved(const QString&)));
353#endif
264354
265 QString platform = QGuiApplication::platformName();355 QString platform = QGuiApplication::platformName();
266 if ((platform.startsWith("ubuntu") || platform == "mirserver" ||356 if ((platform.startsWith("ubuntu") || platform == "mirserver" ||
diff --git a/qt/core/browser/qt_screen.h b/qt/core/browser/qt_screen.h
index 2e68d30..a67c798 100644
--- a/qt/core/browser/qt_screen.h
+++ b/qt/core/browser/qt_screen.h
@@ -22,6 +22,9 @@
2222
23#include <QObject>23#include <QObject>
24#include <QtGlobal>24#include <QtGlobal>
25#if defined(USE_QINPUTDEVICE)
26#include <QInputDevice>
27#endif
2528
26#include "base/macros.h"29#include "base/macros.h"
2730
@@ -57,20 +60,35 @@ class OXIDE_QT_EXPORT Screen : public QObject,
5760
58 static void SetEnableQtUbuntuIntegrationForTesting(bool enable);61 static void SetEnableQtUbuntuIntegrationForTesting(bool enable);
5962
63 protected :
64 ShellMode GetShellMode() override;
65
60 private Q_SLOTS:66 private Q_SLOTS:
61 void OnScreenAdded(QScreen* screen);67 void OnScreenAdded(QScreen* screen);
62 void OnScreenRemoved(QScreen* screen);68 void OnScreenRemoved(QScreen* screen);
63 void OnPrimaryScreenChanged(QScreen* screen);69 void OnPrimaryScreenChanged(QScreen* screen);
70#if defined(USE_QINPUTDEVICE)
71 void OnInputDeviceAdded(QInputDevice* device);
72 void OnInputDeviceRemoved(const QString& deviceId);
73 void OnInputDevicesReady();
74#endif
64 void OnPlatformScreenPropertyChanged(QPlatformScreen* screen,75 void OnPlatformScreenPropertyChanged(QPlatformScreen* screen,
65 const QString& property_name);76 const QString& property_name);
6677
67 private:78 private:
68 QScreen* QScreenFromDisplay(const display::Display& display) const;79 QScreen* QScreenFromDisplay(const display::Display& display) const;
69 void UpdateDisplayForScreen(QScreen* screen);80 void UpdateDisplayForScreen(QScreen* screen);
81#if defined(USE_QINPUTDEVICE)
82 bool GetShellModeFromInputDevices(ShellMode* mode);
83#endif
7084
71#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)85#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
72 std::map<QScreen*, display::Display> displays_;86 std::map<QScreen*, display::Display> displays_;
73#endif87#endif
88#if defined(USE_QINPUTDEVICE)
89 QInputInfoManager input_device_manager_;
90#endif
91 oxide::ShellMode current_shell_mode_;
74};92};
7593
76} // namespace qt94} // namespace qt
diff --git a/shared/browser/oxide_content_browser_client.cc b/shared/browser/oxide_content_browser_client.cc
index f588268..eeef6ab 100644
--- a/shared/browser/oxide_content_browser_client.cc
+++ b/shared/browser/oxide_content_browser_client.cc
@@ -299,7 +299,7 @@ void ContentBrowserClient::OverrideWebkitPrefs(
299 break;299 break;
300 };300 };
301301
302 if (Screen::GetShellMode() == ShellMode::NonWindowed) {302 if (Screen::GetInstance()->GetShellMode() == ShellMode::NonWindowed) {
303 prefs->shrinks_viewport_contents_to_fit = true;303 prefs->shrinks_viewport_contents_to_fit = true;
304 prefs->viewport_enabled = true;304 prefs->viewport_enabled = true;
305 prefs->main_frame_resizes_are_orientation_changes = true;305 prefs->main_frame_resizes_are_orientation_changes = true;
diff --git a/shared/browser/screen.h b/shared/browser/screen.h
index 61307fb..514f65b 100644
--- a/shared/browser/screen.h
+++ b/shared/browser/screen.h
@@ -51,7 +51,7 @@ class OXIDE_SHARED_EXPORT Screen {
51 virtual DisplayFormFactor GetDisplayFormFactor(51 virtual DisplayFormFactor GetDisplayFormFactor(
52 const display::Display& display);52 const display::Display& display);
5353
54 static ShellMode GetShellMode();54 virtual ShellMode GetShellMode();
5555
56 protected:56 protected:
57 Screen();57 Screen();
diff --git a/shared/browser/screen_observer.h b/shared/browser/screen_observer.h
index c887942..f730eda 100644
--- a/shared/browser/screen_observer.h
+++ b/shared/browser/screen_observer.h
@@ -27,6 +27,7 @@ class Display;
27namespace oxide {27namespace oxide {
2828
29class Screen;29class Screen;
30enum class ShellMode;
3031
31class OXIDE_SHARED_EXPORT ScreenObserver {32class OXIDE_SHARED_EXPORT ScreenObserver {
32 public:33 public:
diff --git a/shared/browser/screen_unittest.cc b/shared/browser/screen_unittest.cc
index 552c1ba..9782c17 100644
--- a/shared/browser/screen_unittest.cc
+++ b/shared/browser/screen_unittest.cc
@@ -195,15 +195,15 @@ TEST_F(ScreenTest, GetShellMode) {
195#if defined(ENABLE_HYBRIS)195#if defined(ENABLE_HYBRIS)
196 {196 {
197 FakeHybrisUtils hybris_utils(false);197 FakeHybrisUtils hybris_utils(false);
198 EXPECT_EQ(ShellMode::Windowed, Screen::GetShellMode());198 EXPECT_EQ(ShellMode::Windowed, Screen::GetInstance()->GetShellMode());
199 }199 }
200200
201 {201 {
202 FakeHybrisUtils hybris_utils(true);202 FakeHybrisUtils hybris_utils(true);
203 EXPECT_EQ(ShellMode::NonWindowed, Screen::GetShellMode());203 EXPECT_EQ(ShellMode::NonWindowed, Screen::GetInstance()->GetShellMode());
204 }204 }
205#else205#else
206 EXPECT_EQ(ShellMode::Windowed, Screen::GetShellMode());206 EXPECT_EQ(ShellMode::Windowed, Screen::GetInstance()->GetShellMode());
207#endif207#endif
208}208}
209209

Subscribers

People subscribed via source and target branches

to all changes: