~jbicha/unity/gd-rebuild

« back to all changes in this revision

Viewing changes to tools/migration-scripts/06_unity_set_lowgfx_mode_settings_v1

  • Committer: Bileto Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2017-11-16 03:24:21 UTC
  • mfrom: (4263.1.1 migrate-lowgfx-settings)
  • Revision ID: ci-train-bot@canonical.com-20171116032421-vtji66qfjqis1qog
tools: add migration script to set the default values for unity-lowgfx profile

Compiz migration scripts are tricky and non always functional, this is safer
and known to work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
# -*- coding: utf-8 -*-
 
3
# Copyright (C) 2017 Canonical
 
4
#
 
5
# Authors:
 
6
#  Marco Trevisan <marco.trevisan@canonical.com>
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify it under
 
9
# the terms of the GNU General Public License as published by the Free Software
 
10
# Foundation; version 3.
 
11
#
 
12
# This program is distributed in the hope that it will be useful, but WITHOUTa
 
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
15
# details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License along with
 
18
# this program; if not, write to the Free Software Foundation, Inc.,
 
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
20
 
 
21
from gi.repository import Gio, GLib
 
22
import sys
 
23
 
 
24
COMPIZ_SCHEMA = "org.compiz"
 
25
COMPIZ_PROFILE_PATH = "/org/compiz/profiles/unity-lowgfx/plugins/{}/"
 
26
LOWGFX_OPTIONS = {
 
27
    "ezoom": {"speed": 100.0},
 
28
 
 
29
    "expo": {"expo-animation": 3},
 
30
 
 
31
    "fade": {"fade-mode": 1,
 
32
             "fade-time": 1},
 
33
 
 
34
    "grid": {"animation-duration": 0,
 
35
             "draw-stretched-window": False},
 
36
 
 
37
    "move": {"mode": 2,
 
38
             "lazy-positioning": True,
 
39
             "increase-border-contrast": True},
 
40
 
 
41
    "resize": {"mode": 2,
 
42
               "increase-border-contrast": True},
 
43
 
 
44
    "opengl": {"texture-filter": 0},
 
45
 
 
46
    "scale": {"skip-animation": True},
 
47
 
 
48
    "unityshell": {"dash-blur-experimental": 0,
 
49
                   "override-decoration-theme": True,
 
50
                   "shadow-x-offset": 1,
 
51
                   "shadow-y-offset": 1,
 
52
                   "active-shadow-radius": 3,
 
53
                   "inactive-shadow-radius": 2,
 
54
                   "menus-fadein": 0,
 
55
                   "menus-fadeout": 0,
 
56
                   "menus-discovery-fadein": 0,
 
57
                   "menus-discovery-fadeout": 0,
 
58
                   "autohide-animation": 1},
 
59
 
 
60
    "wall": {"slide-duration": 0.0},
 
61
 
 
62
    "showdesktop": {"skip-animation": True},
 
63
}
 
64
 
 
65
 
 
66
def get_variant_from_python(value):
 
67
    if type(value) == str:
 
68
        return GLib.Variant.new_string(value)
 
69
    elif type(value) == bool:
 
70
        return GLib.Variant.new_boolean(value)
 
71
    elif type(value) == int:
 
72
        return GLib.Variant.new_int32(value)
 
73
    elif type(value) == float:
 
74
        return GLib.Variant.new_double(value)
 
75
 
 
76
 
 
77
if COMPIZ_SCHEMA not in Gio.Settings.list_schemas():
 
78
    print("No compiz schemas found, no migration needed")
 
79
    sys.exit(0)
 
80
 
 
81
for plugin in LOWGFX_OPTIONS:
 
82
    plugin_options = LOWGFX_OPTIONS[plugin]
 
83
    plugin_path = COMPIZ_PROFILE_PATH.format(plugin)
 
84
 
 
85
    try:
 
86
      plugin_settings = Gio.Settings(
 
87
          schema=COMPIZ_SCHEMA + ".{}".format(plugin), path=plugin_path)
 
88
 
 
89
      for setting in plugin_options:
 
90
          value = get_variant_from_python(plugin_options[setting])
 
91
          plugin_settings.set_value(setting, value)
 
92
    except:
 
93
      print("Can't update settings for plugin '{}".format(plugin))
 
94
 
 
95
Gio.Settings.sync()