Merge lp:~3v1n0/unity/lowgfx-setting-sync into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4250
Proposed branch: lp:~3v1n0/unity/lowgfx-setting-sync
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/unity-settings-signal-blocking
Diff against target: 309 lines (+105/-33)
6 files modified
plugins/unityshell/src/unityshell.cpp (+6/-12)
tests/data/external.gschema.xml (+7/-1)
tools/compiz-profile-selector.in (+19/-7)
tools/unity.cmake (+7/-4)
unity-shared/UnitySettings.cpp (+65/-9)
unity-shared/UnitySettings.h (+1/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/lowgfx-setting-sync
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+327523@code.launchpad.net

Commit message

UnitySettings: listen to compiz profile status in order to set low_gfx value

Instead of changing this value back and forth multiple times, just wait
this to be really changed in compiz, and update our internal variable
accordingly.
Also take care of the gsettings unity's lowgfx value only if the user has
set it.

This fixes an infinite loop when starting compiz in a lowgfx environment.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/unityshell.cpp'
2--- plugins/unityshell/src/unityshell.cpp 2017-07-03 13:27:51 +0000
3+++ plugins/unityshell/src/unityshell.cpp 2017-07-21 00:49:50 +0000
4@@ -293,23 +293,17 @@
5 }
6
7 //In case of software rendering then enable lowgfx mode.
8+ std::string lowgfx_env = glib::gchar_to_string(getenv("UNITY_LOW_GFX_MODE"));
9 std::string renderer = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_RENDERER)));
10 if (renderer.find("Software Rasterizer") != std::string::npos ||
11 renderer.find("Mesa X11") != std::string::npos ||
12 renderer.find("llvmpipe") != std::string::npos ||
13 renderer.find("softpipe") != std::string::npos ||
14- (getenv("UNITY_LOW_GFX_MODE") != NULL && atoi(getenv("UNITY_LOW_GFX_MODE")) == 1))
15- {
16- unity_settings_.low_gfx = true;
17- }
18-
19- if (getenv("UNITY_LOW_GFX_MODE") != NULL && atoi(getenv("UNITY_LOW_GFX_MODE")) == 0)
20- {
21- unity_settings_.low_gfx = false;
22- }
23-
24- if (unity_settings_.low_gfx())
25- BackgroundEffectHelper::blur_type = BLUR_NONE;
26+ atoi(lowgfx_env.c_str()) == 1)
27+ {
28+ if (lowgfx_env.empty() || atoi(lowgfx_env.c_str()) != 0)
29+ unity_settings_.supports_3d = false;
30+ }
31
32 Settings::Instance().low_gfx.changed.connect(sigc::track_obj([this] (bool low_gfx) {
33 BackgroundEffectHelper::blur_type = low_gfx ? BLUR_NONE : (unity::BlurType) optionGetDashBlurExperimental();
34
35=== modified file 'tests/data/external.gschema.xml'
36--- tests/data/external.gschema.xml 2014-04-18 11:45:59 +0000
37+++ tests/data/external.gschema.xml 2017-07-21 00:49:50 +0000
38@@ -8,6 +8,12 @@
39 </key>
40 </schema>
41
42+ <schema id="org.compiz" path="/org/compiz/">
43+ <key type="s" name="current-profile">
44+ <default>'unity'</default>
45+ </key>
46+ </schema>
47+
48 <schema id="org.compiz.unityshell" gettext-domain="compiz">
49 <key type="s" name="panel-first-menu">
50 <default>'&lt;Alt&gt;F10'</default>
51@@ -18,7 +24,7 @@
52 <key type="s" name="show-hud">
53 <default>'&lt;Alt&gt;'</default>
54 </key>
55- </schema>
56+ </schema>
57
58 <enum id='com.canonical.desktop.interface.ScrollbarMode'>
59 <value nick='normal' value='0'/>
60
61=== modified file 'tools/compiz-profile-selector.in'
62--- tools/compiz-profile-selector.in 2017-04-05 07:58:57 +0000
63+++ tools/compiz-profile-selector.in 2017-07-21 00:49:50 +0000
64@@ -14,24 +14,36 @@
65
66 compiz_profile="ubuntu"
67 settings_profile="unity"
68+supports_3d=true
69
70 if ! /usr/lib/nux/unity_support_test -p; then
71- settings_profile="unity-lowgfx"
72+ supports_3d=false
73 fi
74
75-if [ "$(gsettings get com.canonical.Unity lowgfx)" == "true" ]; then
76- settings_profile="unity-lowgfx"
77+if [ "$UNITY_LOW_GFX_MODE" != 0 ]; then
78+ if [ "$supports_3d" == false ] ||
79+ [ "$(gsettings get com.canonical.Unity lowgfx)" == "true" ]; then
80+ settings_profile="unity-lowgfx"
81+ fi
82 fi
83
84 echo "Using compiz profile '$compiz_profile:$settings_profile'"
85
86+export COMPIZ_CONFIG_PROFILE="$compiz_profile"
87+export UNITY_HAS_3D_SUPPORT="$supports_3d"
88+export UNITY_DEFAULT_PROFILE="$settings_profile"
89+
90 if [ -n "$UPSTART_SESSION" ]; then
91- initctl set-env -g COMPIZ_CONFIG_PROFILE="$compiz_profile"
92+ initctl set-env -g COMPIZ_CONFIG_PROFILE=$COMPIZ_CONFIG_PROFILE
93+ initctl set-env -g UNITY_HAS_3D_SUPPORT=$UNITY_HAS_3D_SUPPORT
94+ initctl set-env -g UNITY_DEFAULT_PROFILE=$UNITY_DEFAULT_PROFILE
95+else
96+ update_env_args="--systemd"
97 fi
98
99-dbus-update-activation-environment --verbose --systemd COMPIZ_CONFIG_PROFILE="$compiz_profile"
100-
101-export COMPIZ_CONFIG_PROFILE="$compiz_profile"
102+dbus-update-activation-environment $update_env_args --verbose COMPIZ_CONFIG_PROFILE
103+dbus-update-activation-environment $update_env_args --verbose UNITY_HAS_3D_SUPPORT
104+dbus-update-activation-environment $update_env_args --verbose UNITY_DEFAULT_PROFILE
105
106 @UNITY_LIBDIR@/compiz-config-profile-setter $settings_profile
107 @UNITY_LIBDIR@/unity-active-plugins-safety-check
108
109=== modified file 'tools/unity.cmake'
110--- tools/unity.cmake 2017-03-27 19:34:26 +0000
111+++ tools/unity.cmake 2017-07-21 00:49:50 +0000
112@@ -30,6 +30,9 @@
113 import xdg.BaseDirectory
114
115 DEFAULT_COMMAND = "compiz --replace"
116+COMPIZ_CONFIG_PROFILE = "ubuntu"
117+UNITY_DEFAULT_PROFILE = "unity"
118+UNITY_LOWGFX_PROFILE = UNITY_DEFAULT_PROFILE + "-lowgfx"
119 home_dir = os.path.expanduser("~%s" % os.getenv("SUDO_USER"))
120 supported_prefix = "/usr/local"
121
122@@ -58,18 +61,18 @@
123 def set_unity_env ():
124 '''set variable environnement for unity to run'''
125
126- compiz_config_profile = 'unity'
127- os.environ['COMPIZ_CONFIG_PROFILE'] = 'ubuntu'
128+ compiz_config_profile = UNITY_DEFAULT_PROFILE
129+ os.environ['COMPIZ_CONFIG_PROFILE'] = COMPIZ_CONFIG_PROFILE
130
131 try:
132 if subprocess.call('/usr/lib/nux/unity_support_test -f'.split()) > 0:
133- compiz_config_profile += '-lowgfx'
134+ compiz_config_profile = UNITY_LOWGFX_PROFILE
135 except:
136 pass
137
138 try:
139 if subprocess.check_output('gsettings get com.canonical.Unity lowgfx'.split()) == b'true\n':
140- compiz_config_profile += '-lowgfx'
141+ compiz_config_profile = UNITY_LOWGFX_PROFILE
142 except:
143 pass
144
145
146=== modified file 'unity-shared/UnitySettings.cpp'
147--- unity-shared/UnitySettings.cpp 2017-07-21 00:49:49 +0000
148+++ unity-shared/UnitySettings.cpp 2017-07-21 00:49:50 +0000
149@@ -58,6 +58,9 @@
150 const std::string APP_SCALE_MONITOR = "app-scale-factor-monitor";
151 const std::string APP_USE_MAX_SCALE = "app-fallback-to-maximum-scale-factor";
152
153+const std::string COMPIZ_SETTINGS = "org.compiz";
154+const std::string COMPIZ_PROFILE = "current-profile";
155+
156 const std::string UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface";
157 const std::string SCALE_FACTOR = "scale-factor";
158
159@@ -96,6 +99,7 @@
160 Impl(Settings* owner)
161 : parent_(owner)
162 , usettings_(g_settings_new(SETTINGS_NAME.c_str()))
163+ , compiz_settings_(g_settings_new(COMPIZ_SETTINGS.c_str()))
164 , launcher_settings_(g_settings_new(LAUNCHER_SETTINGS.c_str()))
165 , lim_settings_(g_settings_new(LIM_SETTINGS.c_str()))
166 , gestures_settings_(g_settings_new(GESTURES_SETTINGS.c_str()))
167@@ -110,6 +114,8 @@
168 , cached_double_click_activate_(true)
169 , remote_content_enabled_(true)
170 {
171+ InitializeLowGfx();
172+
173 parent_->form_factor.SetGetterFunction(sigc::mem_fun(this, &Impl::GetFormFactor));
174 parent_->form_factor.SetSetterFunction(sigc::mem_fun(this, &Impl::SetFormFactor));
175 parent_->double_click_activate.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDoubleClickActivate));
176@@ -118,13 +124,18 @@
177 parent_->launcher_position.SetSetterFunction(sigc::mem_fun(this, &Impl::SetLauncherPosition));
178 parent_->desktop_type.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDesktopType));
179 parent_->pam_check_account_type.SetGetterFunction(sigc::mem_fun(this, &Impl::GetPamCheckAccountType));
180+ parent_->supports_3d.changed.connect(sigc::mem_fun(this, &Impl::OnSupports3DChanged));
181 parent_->low_gfx.changed.connect(sigc::mem_fun(this, &Impl::UpdateCompizProfile));
182
183 for (unsigned i = 0; i < monitors::MAX; ++i)
184 em_converters_.emplace_back(std::make_shared<EMConverter>());
185
186+ signals_.Add<void, GSettings*, const gchar*>(compiz_settings_, "changed::" + COMPIZ_PROFILE, [this] (GSettings*, const gchar *) {
187+ parent_->low_gfx = (GetCurrentCompizProfile() == CCS_PROFILE_LOWGFX);
188+ });
189+
190 signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + LOWGFX, [this] (GSettings*, const gchar *) {
191- UpdateLowGfx();
192+ UpdateCompizProfile(GetLowGfxSetting());
193 });
194
195 signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + FORM_FACTOR, [this] (GSettings*, const gchar*) {
196@@ -187,11 +198,8 @@
197
198 UScreen::GetDefault()->changed.connect(sigc::hide(sigc::hide(sigc::mem_fun(this, &Impl::UpdateDPI))));
199
200- UpdateLowGfx();
201- UpdateCompizProfile(parent_->low_gfx());
202+ // The order is important here, DPI is the last thing to be updated
203 UpdateLimSetting();
204-
205- // The order is important here, DPI is the last thing to be updated
206 UpdateGesturesSetting();
207 UpdateTextScaleFactor();
208 UpdateCursorScaleFactor();
209@@ -240,14 +248,54 @@
210 cached_launcher_position_ = static_cast<LauncherPosition>(g_settings_get_enum(launcher_settings_, LAUNCHER_POSITION.c_str()));
211 }
212
213- void UpdateLowGfx()
214- {
215- parent_->low_gfx = g_settings_get_boolean(usettings_, LOWGFX.c_str()) != FALSE;
216+ void InitializeLowGfx()
217+ {
218+ parent_->low_gfx = GetLowGfxSetting();
219+ UpdateCompizProfile(parent_->low_gfx());
220+ }
221+
222+ std::string GetCurrentCompizProfile()
223+ {
224+ return glib::String(g_settings_get_string(compiz_settings_, COMPIZ_PROFILE.c_str())).Str();
225+ }
226+
227+ glib::Variant GetUserLowGfxSetting()
228+ {
229+ return glib::Variant(g_settings_get_user_value(usettings_, LOWGFX.c_str()), glib::StealRef());
230+ }
231+
232+ bool GetLowGfxSetting()
233+ {
234+ if (glib::Variant const& user_setting = GetUserLowGfxSetting())
235+ {
236+ return user_setting.GetBool();
237+ }
238+ else
239+ {
240+ auto default_profile = glib::gchar_to_string(g_getenv("UNITY_DEFAULT_PROFILE"));
241+ if (!default_profile.empty())
242+ {
243+ return (default_profile == CCS_PROFILE_LOWGFX);
244+ }
245+ else if (!parent_->supports_3d() ||
246+ glib::gchar_to_string(getenv("UNITY_HAS_3D_SUPPORT")) == "false")
247+ {
248+ return true;
249+ }
250+ else
251+ {
252+ return (GetCurrentCompizProfile() == CCS_PROFILE_LOWGFX);
253+ }
254+ }
255 }
256
257 void UpdateCompizProfile(bool lowgfx)
258 {
259 auto const& profile = lowgfx ? CCS_PROFILE_LOWGFX : CCS_PROFILE_DEFAULT;
260+
261+ if (GetCurrentCompizProfile() == profile)
262+ return;
263+
264 auto profile_change_cmd = (std::string(UNITY_LIBDIR G_DIR_SEPARATOR_S) + CCS_PROFILE_CHANGER_TOOL + " " + profile);
265
266 glib::Error error;
267@@ -259,6 +307,12 @@
268 }
269 }
270
271+ void OnSupports3DChanged(bool supports_3d)
272+ {
273+ if (!GetUserLowGfxSetting())
274+ parent_->low_gfx = !supports_3d;
275+ }
276+
277 void UpdateLimSetting()
278 {
279 parent_->lim_movement_thresold = g_settings_get_uint(lim_settings_, CLICK_MOVEMENT_THRESHOLD.c_str());
280@@ -486,6 +540,7 @@
281
282 Settings* parent_;
283 glib::Object<GSettings> usettings_;
284+ glib::Object<GSettings> compiz_settings_;
285 glib::Object<GSettings> launcher_settings_;
286 glib::Object<GSettings> lim_settings_;
287 glib::Object<GSettings> gestures_settings_;
288@@ -509,7 +564,8 @@
289 //
290
291 Settings::Settings()
292- : is_standalone(false)
293+ : supports_3d(glib::gchar_to_string(getenv("UNITY_HAS_3D_SUPPORT")) != "false")
294+ , is_standalone(false)
295 , pimpl(new Impl(this))
296 {
297 if (settings_instance)
298
299=== modified file 'unity-shared/UnitySettings.h'
300--- unity-shared/UnitySettings.h 2017-03-16 16:34:33 +0000
301+++ unity-shared/UnitySettings.h 2017-07-21 00:49:50 +0000
302@@ -60,6 +60,7 @@
303 int LauncherSize(int mointor) const;
304
305 nux::Property<bool> low_gfx;
306+ nux::Property<bool> supports_3d;
307 nux::RWProperty<FormFactor> form_factor;
308 nux::Property<bool> is_standalone;
309 nux::ROProperty<DesktopType> desktop_type;