Commit 6ef660f5 authored by Jonas Dreßler's avatar Jonas Dreßler
Browse files

layout: Add a property to tell whether we're running on a smartphone

We're going to adjust a few things in the shell UI to allow running
gnome-shell on smartphones. To do this, it will be necessary to detect
whether we're running on a phone, so add a property to layoutManager
that tells us.

Note that the heuristics to detect phones here is obviously quite
subjective and a bit tricky, right now it's simply checking whether the
primary monitor size is smaller than 500x1000, which works fairly well
and excludes smaller tablets. Given that the whole web seems to rely
only on checking the screen size in pixels, this seems to be not as bad
as one might think.
parent 3e7ce18d
Pipeline #401076 failed with stages
in 2 minutes and 48 seconds
......@@ -184,6 +184,12 @@ const defaultParams = {
};
var LayoutManager = GObject.registerClass({
Properties: {
'is-phone': GObject.ParamSpec.boolean(
'is-phone', 'is-phone', 'is-phone',
GObject.ParamFlags.READABLE,
false),
},
Signals: {
'hot-corners-changed': {},
'startup-complete': {},
......@@ -566,6 +572,7 @@ var LayoutManager = GObject.registerClass({
_monitorsChanged() {
this._updateMonitors();
this._updateIsPhone(),
this._updateBoxes();
this._updateHotCorners();
this._updateBackgrounds();
......@@ -1088,6 +1095,36 @@ var LayoutManager = GObject.registerClass({
// so queue an update now.
this._queueUpdateRegions();
}
get is_phone() {
return this._isPhone;
}
_checkIsPhone() {
if (!this.primaryMonitor)
return false;
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
const width = this.primaryMonitor.width / scaleFactor;
const height = this.primaryMonitor.height / scaleFactor;
if ((width < 500 && height < 1000) ||
(height < 500 && width < 1000))
return true;
return false;
}
_updateIsPhone() {
const isPhone = this._checkIsPhone();
if (this._isPhone === isPhone)
return;
this._isPhone = isPhone;
this.notify('is-phone');
}
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment