Merge lp:~3v1n0/unity/lowgfx-profile-setter into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4233
Proposed branch: lp:~3v1n0/unity/lowgfx-profile-setter
Merge into: lp:unity
Prerequisite: lp:~hikiko/unity/unity.lowgfx-2017
Diff against target: 434 lines (+284/-22)
7 files modified
debian/unity.install (+1/-0)
tests/test_thumbnail_generator.cpp (+1/-1)
tools/CMakeLists.txt (+5/-0)
tools/compiz-profile-selector.in (+7/-4)
tools/compiz_config_profile_setter.c (+228/-0)
tools/unity.cmake (+17/-10)
unity-shared/UnitySettings.cpp (+25/-7)
To merge this branch: bzr merge lp:~3v1n0/unity/lowgfx-profile-setter
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: [email protected]

This proposal supersedes a proposal from 2017-04-04.

Commit message

compiz-profile-setter: tool to update the current profile and use in systemd and Unity settings

Added a compiz-profile-setter tool that allows to change compiz profile, so we use
this to set the right profile when starting unity and when the gsettings key has changed.

So we can just toggle lowgfx profile on the fly by just doing
  gsettings set com.canonical.Unity lowgfx true|false

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 'debian/unity.install'
2--- debian/unity.install 2016-09-05 10:46:49 +0000
3+++ debian/unity.install 2017-04-25 17:53:40 +0000
4@@ -2,6 +2,7 @@
5 usr/bin
6 usr/lib/*/compiz/libunity*.so
7 usr/lib/*/unity/unity-active-plugins-safety-check
8+usr/lib/*/unity/compiz-config-profile-setter
9 usr/lib/*/unity/compiz-profile-selector
10 usr/lib/*/unity/*-prestart-check
11 usr/lib/systemd/user/unity7.service
12
13=== modified file 'tests/test_thumbnail_generator.cpp'
14--- tests/test_thumbnail_generator.cpp 2016-03-31 02:03:55 +0000
15+++ tests/test_thumbnail_generator.cpp 2017-04-25 17:53:40 +0000
16@@ -149,7 +149,7 @@
17 results[i].cancelled = true;
18 }
19
20- CheckResults(results, 15000);
21+ CheckResults(results, 30000);
22 }
23
24
25
26=== modified file 'tools/CMakeLists.txt'
27--- tools/CMakeLists.txt 2016-09-05 10:46:49 +0000
28+++ tools/CMakeLists.txt 2017-04-25 17:53:40 +0000
29@@ -19,6 +19,7 @@
30
31 string (REPLACE ";" " " CFLAGS "${CFLAGS}")
32 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS}")
33+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}")
34
35 set(LIBS ${UAPSC_DEPS_LIBRARIES})
36
37@@ -29,6 +30,10 @@
38 target_link_libraries(unity-active-plugins-safety-check ${LIBS})
39 install(TARGETS unity-active-plugins-safety-check DESTINATION ${UNITY_INSTALL_LIBDIR})
40
41+add_executable(compiz-config-profile-setter compiz_config_profile_setter.c)
42+target_link_libraries(compiz-config-profile-setter ${LIBS})
43+install(TARGETS compiz-config-profile-setter DESTINATION ${UNITY_INSTALL_LIBDIR})
44+
45 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/compiz-profile-selector.in ${CMAKE_CURRENT_BINARY_DIR}/compiz-profile-selector @ONLY)
46 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/compiz-profile-selector DESTINATION ${UNITY_INSTALL_LIBDIR})
47
48
49=== modified file 'tools/compiz-profile-selector.in' (properties changed: +x to -x)
50--- tools/compiz-profile-selector.in 2017-04-25 17:53:40 +0000
51+++ tools/compiz-profile-selector.in 2017-04-25 17:53:40 +0000
52@@ -13,16 +13,17 @@
53 fi
54
55 compiz_profile="ubuntu"
56+settings_profile="unity"
57
58 if ! /usr/lib/nux/unity_support_test -p; then
59- compiz_profile="ubuntu-lowgfx"
60+ settings_profile="unity-lowgfx"
61 fi
62
63 if [ "$(gsettings get com.canonical.Unity lowgfx)" == "true" ]; then
64- compiz_profile="ubuntu-lowgfx"
65+ settings_profile="unity-lowgfx"
66 fi
67
68-echo "Using compiz profile '$compiz_profile'"
69+echo "Using compiz profile '$compiz_profile:$settings_profile'"
70
71 if [ -n "$UPSTART_SESSION" ]; then
72 initctl set-env -g COMPIZ_CONFIG_PROFILE="$compiz_profile"
73@@ -31,4 +32,6 @@
74 dbus-update-activation-environment --verbose --systemd COMPIZ_CONFIG_PROFILE="$compiz_profile"
75
76 export COMPIZ_CONFIG_PROFILE="$compiz_profile"
77-exec @UNITY_LIBDIR@/unity-active-plugins-safety-check
78+
79+@UNITY_LIBDIR@/compiz-config-profile-setter $settings_profile
80+@UNITY_LIBDIR@/unity-active-plugins-safety-check
81
82=== added file 'tools/compiz_config_profile_setter.c'
83--- tools/compiz_config_profile_setter.c 1970-01-01 00:00:00 +0000
84+++ tools/compiz_config_profile_setter.c 2017-04-25 17:53:40 +0000
85@@ -0,0 +1,228 @@
86+/*
87+ * Copyright (C) 2017 Canonical Ltd
88+ *
89+ * This program is free software: you can redistribute it and/or modify
90+ * it under the terms of the GNU General Public License version 3 as
91+ * published by the Free Software Foundation.
92+ *
93+ * This program is distributed in the hope that it will be useful,
94+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
95+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96+ * GNU General Public License for more details.
97+ *
98+ * You should have received a copy of the GNU General Public License
99+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
100+ *
101+ * Authored by: Marco Trevisan <[email protected]>
102+ */
103+
104+#include <ccs.h>
105+#include <gio/gio.h>
106+
107+#define COMPIZ_CONFIG_PROFILE_ENV "COMPIZ_CONFIG_PROFILE"
108+#define COMPIZ_CONFIG_DEFAULT_PROFILE "ubuntu"
109+
110+extern const CCSInterfaceTable ccsDefaultInterfaceTable;
111+
112+static gchar *
113+get_ccs_profile_env_from_env_list (const gchar **env_vars)
114+{
115+ gchar *var = NULL;
116+
117+ for (; env_vars && *env_vars; ++env_vars)
118+ {
119+ if (g_str_has_prefix (*env_vars, COMPIZ_CONFIG_PROFILE_ENV "="))
120+ {
121+ var = g_strdup (*env_vars + G_N_ELEMENTS (COMPIZ_CONFIG_PROFILE_ENV));
122+ break;
123+ }
124+ }
125+
126+ return var;
127+}
128+
129+static gchar *
130+get_ccs_profile_env_from_session_manager ()
131+{
132+ GDBusConnection *bus;
133+ GVariant *environment_prop, *environment_prop_list;
134+ const gchar **env_vars;
135+ gchar *profile;
136+
137+ profile = NULL;
138+ bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
139+
140+ environment_prop = g_dbus_connection_call_sync (bus,
141+ "org.freedesktop.systemd1",
142+ "/org/freedesktop/systemd1",
143+ "org.freedesktop.DBus.Properties",
144+ "Get",
145+ g_variant_new ("(ss)",
146+ "org.freedesktop.systemd1.Manager",
147+ "Environment"),
148+ G_VARIANT_TYPE ("(v)"),
149+ G_DBUS_CALL_FLAGS_NONE,
150+ -1,
151+ NULL,
152+ NULL);
153+
154+ if (!environment_prop)
155+ goto out;
156+
157+ g_variant_get (environment_prop, "(v)", &environment_prop_list, NULL);
158+ env_vars = g_variant_get_strv (environment_prop_list, NULL);
159+ profile = get_ccs_profile_env_from_env_list (env_vars);
160+
161+ g_clear_pointer (&environment_prop, g_variant_unref);
162+ g_clear_pointer (&environment_prop_list, g_variant_unref);
163+
164+ if (!profile && g_getenv ("UPSTART_SESSION"))
165+ {
166+ const gchar * const * empty_array[] = {0};
167+ environment_prop_list = g_dbus_connection_call_sync (bus,
168+ "com.ubuntu.Upstart",
169+ "/com/ubuntu/Upstart",
170+ "com.ubuntu.Upstart0_6",
171+ "ListEnv",
172+ g_variant_new("(@as)",
173+ g_variant_new_strv (NULL, 0)),
174+ NULL,
175+ G_DBUS_CALL_FLAGS_NONE,
176+ -1,
177+ NULL,
178+ NULL);
179+ if (!environment_prop_list)
180+ goto out;
181+
182+ g_variant_get (environment_prop_list, "(^a&s)", &env_vars);
183+ profile = get_ccs_profile_env_from_env_list (env_vars);
184+
185+ g_variant_unref (environment_prop_list);
186+ }
187+
188+out:
189+ g_object_unref (bus);
190+
191+ return profile;
192+}
193+
194+static gboolean
195+is_compiz_profile_available (const gchar *profile)
196+{
197+ gboolean is_available;
198+ gchar *profile_path;
199+
200+ profile_path = g_strdup_printf ("%s/compiz-1/compizconfig/%s.ini",
201+ g_get_user_config_dir (), profile);
202+ is_available = g_file_test (profile_path, G_FILE_TEST_EXISTS);
203+ g_free (profile_path);
204+
205+ if (!is_available)
206+ {
207+ profile_path = g_strdup_printf ("/etc/compizconfig/%s.ini", profile);
208+ is_available = g_file_test (profile_path, G_FILE_TEST_EXISTS);
209+ g_free (profile_path);
210+ }
211+
212+ return is_available;
213+}
214+
215+static gboolean
216+set_compiz_profile (CCSContext *ccs_context, const gchar *profile_name)
217+{
218+ CCSPluginList plugins;
219+ const char *ccs_backend;
220+
221+ ccs_backend = ccsGetBackend (ccs_context);
222+
223+ ccsSetProfile (ccs_context, profile_name);
224+ ccsReadSettings (ccs_context);
225+ ccsWriteSettings (ccs_context);
226+
227+ if (g_strcmp0 (ccs_backend, "gsettings") == 0)
228+ g_settings_sync ();
229+
230+ plugins = ccsContextGetPlugins (ccs_context);
231+
232+ for (CCSPluginList p = plugins; p; p = p->next)
233+ {
234+ CCSPlugin* plugin = p->data;
235+ ccsReadPluginSettings (plugin);
236+ }
237+
238+ return TRUE;
239+}
240+
241+int main(int argc, char *argv[])
242+{
243+ CCSContext *context;
244+ const gchar *profile, *current_profile, *ccs_profile_env;
245+ gchar *session_manager_ccs_profile;
246+
247+ if (argc < 2)
248+ {
249+ g_warning ("You need to pass a valid profile as argument\n");
250+ return 1;
251+ }
252+
253+ session_manager_ccs_profile = get_ccs_profile_env_from_session_manager ();
254+
255+ if (session_manager_ccs_profile)
256+ {
257+ g_setenv (COMPIZ_CONFIG_PROFILE_ENV, session_manager_ccs_profile, TRUE);
258+ g_clear_pointer (&session_manager_ccs_profile, g_free);
259+ }
260+ else
261+ {
262+ ccs_profile_env = g_getenv (COMPIZ_CONFIG_PROFILE_ENV);
263+
264+ if (!ccs_profile_env || ccs_profile_env[0] == '\0')
265+ {
266+ g_setenv (COMPIZ_CONFIG_PROFILE_ENV, COMPIZ_CONFIG_DEFAULT_PROFILE, TRUE);
267+ }
268+ }
269+
270+ profile = argv[1];
271+
272+ if (!is_compiz_profile_available (profile))
273+ {
274+ g_warning ("Compiz profile '%s' not found", profile);
275+ return 1;
276+ }
277+
278+ context = ccsContextNew (0, &ccsDefaultInterfaceTable);
279+
280+ if (!context)
281+ {
282+ g_warning ("Impossible to get Compiz config context\n");
283+ return -1;
284+ }
285+
286+ g_debug ("Setting profile to '%s' (for environment '%s')",
287+ profile, g_getenv (COMPIZ_CONFIG_PROFILE_ENV));
288+
289+ current_profile = ccsGetProfile (context);
290+
291+ if (g_strcmp0 (current_profile, profile) == 0)
292+ {
293+ g_print("We're already using profile '%s', no need to switch\n", profile);
294+ return 0;
295+ }
296+
297+ if (!set_compiz_profile (context, profile))
298+ {
299+ ccsFreeContext (context);
300+ return 1;
301+ }
302+
303+ ccsFreeContext (context);
304+
305+ g_print ("Switched to profile '%s' (for environment '%s')\n",
306+ profile, g_getenv (COMPIZ_CONFIG_PROFILE_ENV));
307+
308+ /* This is for printing debug informations */
309+ context = ccsContextNew (0, &ccsDefaultInterfaceTable);
310+ ccsFreeContext (context);
311+
312+ return 0;
313+}
314
315=== modified file 'tools/unity.cmake'
316--- tools/unity.cmake 2017-04-25 17:53:40 +0000
317+++ tools/unity.cmake 2017-04-25 17:53:40 +0000
318@@ -58,19 +58,26 @@
319 def set_unity_env ():
320 '''set variable environnement for unity to run'''
321
322+ compiz_config_profile = 'unity'
323 os.environ['COMPIZ_CONFIG_PROFILE'] = 'ubuntu'
324
325 try:
326- if subprocess.call('/usr/lib/nux/unity_support_test -f'.split()) > 0:
327- os.environ['COMPIZ_CONFIG_PROFILE'] = 'ubuntu-lowgfx'
328- except:
329- pass
330-
331- try:
332- if subprocess.check_output('gsettings get com.canonical.Unity lowgfx'.split()) == b'true\n':
333- os.environ['COMPIZ_CONFIG_PROFILE'] = 'ubuntu-lowgfx'
334- except:
335- pass
336+ if subprocess.call('/usr/lib/nux/unity_support_test -f'.split()) > 0:
337+ compiz_config_profile += '-lowgfx'
338+ except:
339+ pass
340+
341+ try:
342+ if subprocess.check_output('gsettings get com.canonical.Unity lowgfx'.split()) == b'true\n':
343+ compiz_config_profile += '-lowgfx'
344+ except:
345+ pass
346+
347+ try:
348+ subprocess.call('@UNITY_LIBDIR@/compiz-config-profile-setter {}'.format(
349+ compiz_config_profile).split())
350+ except:
351+ pass
352
353 if not 'DISPLAY' in os.environ:
354 # take an optimistic chance and warn about it :)
355
356=== modified file 'unity-shared/UnitySettings.cpp'
357--- unity-shared/UnitySettings.cpp 2017-04-25 17:53:40 +0000
358+++ unity-shared/UnitySettings.cpp 2017-04-25 17:53:40 +0000
359@@ -18,6 +18,8 @@
360 * Andrea Azzarone <[email protected]>
361 */
362
363+#include "config.h"
364+
365 #include <glib.h>
366 #include <NuxCore/Logger.h>
367 #include <UnityCore/GLibSource.h>
368@@ -73,6 +75,10 @@
369 const std::string DASH_TAP = "dash-tap";
370 const std::string WINDOWS_DRAG_PINCH = "windows-drag-pinch";
371
372+const std::string CCS_PROFILE_CHANGER_TOOL = "compiz-config-profile-setter";
373+const std::string CCS_PROFILE_DEFAULT = "unity";
374+const std::string CCS_PROFILE_LOWGFX = CCS_PROFILE_DEFAULT + "-lowgfx";
375+
376 const int DEFAULT_LAUNCHER_SIZE = 64;
377 const int MINIMUM_DESKTOP_HEIGHT = 800;
378 const int GNOME_SETTINGS_CHANGED_WAIT_SECONDS = 1;
379@@ -113,6 +119,7 @@
380 parent_->launcher_position.SetSetterFunction(sigc::mem_fun(this, &Impl::SetLauncherPosition));
381 parent_->desktop_type.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDesktopType));
382 parent_->pam_check_account_type.SetGetterFunction(sigc::mem_fun(this, &Impl::GetPamCheckAccountType));
383+ parent_->low_gfx.changed.connect(sigc::mem_fun(this, &Impl::UpdateCompizProfile));
384
385 for (unsigned i = 0; i < monitors::MAX; ++i)
386 em_converters_.emplace_back(std::make_shared<EMConverter>());
387@@ -184,9 +191,11 @@
388
389 UScreen::GetDefault()->changed.connect(sigc::hide(sigc::hide(sigc::mem_fun(this, &Impl::UpdateDPI))));
390
391- // The order is important here, DPI is the last thing to be updated
392 UpdateLowGfx();
393+ UpdateCompizProfile(parent_->low_gfx());
394 UpdateLimSetting();
395+
396+ // The order is important here, DPI is the last thing to be updated
397 UpdateGesturesSetting();
398 UpdateTextScaleFactor();
399 UpdateCursorScaleFactor();
400@@ -237,7 +246,21 @@
401
402 void UpdateLowGfx()
403 {
404- parent_->low_gfx = GetLowGfx();
405+ parent_->low_gfx = g_settings_get_boolean(usettings_, LOWGFX.c_str()) != FALSE;
406+ }
407+
408+ void UpdateCompizProfile(bool lowgfx)
409+ {
410+ auto const& profile = lowgfx ? CCS_PROFILE_LOWGFX : CCS_PROFILE_DEFAULT;
411+ auto profile_change_cmd = (std::string(UNITY_LIBDIR G_DIR_SEPARATOR_S) + CCS_PROFILE_CHANGER_TOOL + " " + profile);
412+
413+ glib::Error error;
414+ g_spawn_command_line_async(profile_change_cmd.c_str(), &error);
415+
416+ if (error)
417+ {
418+ LOG_ERROR(logger) << "Failed to switch compiz profile: " << error;
419+ }
420 }
421
422 void UpdateLimSetting()
423@@ -292,11 +315,6 @@
424 return g_settings_get_boolean(usettings_, PAM_CHECK_ACCOUNT_TYPE.c_str());
425 }
426
427- bool GetLowGfx() const
428- {
429- return g_settings_get_boolean(usettings_, LOWGFX.c_str());
430- }
431-
432 int GetFontSize() const
433 {
434 gint font_size;