Merge lp:~hikiko/unity/unity.ui-scale-factor into lp:unity

Proposed by Eleni Maria Stea
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3681
Proposed branch: lp:~hikiko/unity/unity.ui-scale-factor
Merge into: lp:unity
Diff against target: 524 lines (+61/-348)
7 files modified
debian/control (+1/-0)
unity-shared/CMakeLists.txt (+0/-1)
unity-shared/ConfigParser.cpp (+0/-287)
unity-shared/ConfigParser.h (+0/-37)
unity-shared/UScreen.cpp (+21/-9)
unity-shared/UScreen.h (+1/-0)
unity-shared/UnitySettings.cpp (+38/-14)
To merge this branch: bzr merge lp:~hikiko/unity/unity.ui-scale-factor
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot (community) continuous-integration Approve
Stephen M. Webb (community) Approve
Brandon Schaefer Pending
Review via email: mp+207610@code.launchpad.net

Commit message

scaling desktop according to a scale factor

Description of the change

scaling desktop according to a scale factor

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Can you revert that changes in po/*?

Revision history for this message
Stephen M. Webb (bregma) wrote :

Needs .po file changes reverted and merge with trunk.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stephen M. Webb (bregma) wrote :

OK, works getting the gsetting to affect Unity, LGTM and build on it.

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

474 + g_object_unref(gsettings_);
475 + g_object_unref(ubuntu_settings_);
476 + g_object_unref(usettings_);
477 + g_object_unref(lim_settings_);

Please get rid of them, we're already doing it as they're glib::Object

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2014-02-20 07:08:01 +0000
+++ debian/control 2014-02-21 17:06:30 +0000
@@ -11,6 +11,7 @@
11 google-mock (>= 1.6.0+svn437),11 google-mock (>= 1.6.0+svn437),
12 google-mock,12 google-mock,
13 gsettings-desktop-schemas-dev,13 gsettings-desktop-schemas-dev,
14 gsettings-ubuntu-schemas (>= 0.0.1+14.04.20140219),
14 intltool (>= 0.35.0),15 intltool (>= 0.35.0),
15 libatk1.0-dev,16 libatk1.0-dev,
16 libbamf3-dev (>= 0.5.0+13.10.20130731),17 libbamf3-dev (>= 0.5.0+13.10.20130731),
1718
=== modified file 'unity-shared/CMakeLists.txt'
--- unity-shared/CMakeLists.txt 2014-02-17 04:01:26 +0000
+++ unity-shared/CMakeLists.txt 2014-02-21 17:06:30 +0000
@@ -19,7 +19,6 @@
19set (UNITY_SHARED_SOURCES19set (UNITY_SHARED_SOURCES
20 ApplicationManager.cpp20 ApplicationManager.cpp
21 BGHash.cpp21 BGHash.cpp
22 ConfigParser.cpp
23 CoverArt.cpp22 CoverArt.cpp
24 BackgroundEffectHelper.cpp23 BackgroundEffectHelper.cpp
25 DashStyle.cpp24 DashStyle.cpp
2625
=== removed file 'unity-shared/ConfigParser.cpp'
--- unity-shared/ConfigParser.cpp 2014-02-03 18:46:31 +0000
+++ unity-shared/ConfigParser.cpp 1970-01-01 00:00:00 +0000
@@ -1,287 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Eleni Maria Stea <elenimaria.stea@canonical.com>
17 */
18
19#include <ctype.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include "ConfigParser.h"
25
26static char *strip_whitespace (char *buf);
27
28/* Linked List */
29
30struct Node {
31 char *key;
32 char *value;
33
34 struct Node *next;
35};
36
37/* ConfigString */
38
39struct ConfigString {
40 struct Node *list;
41 char *string;
42};
43
44ConfigString *cfgstr_create (const char *orig_str)
45{
46 char *sptr, *str;
47
48 str = (char*)alloca(strlen(orig_str) + 1);
49 strcpy(str, orig_str);
50
51 ConfigString *cfgstr;
52 if (!(cfgstr = (ConfigString*)malloc(sizeof *cfgstr)))
53 return 0;
54
55 cfgstr->list = NULL;
56 cfgstr->string = NULL;
57
58 sptr = str;
59 while (sptr && *sptr != 0)
60 {
61 char *key, *value, *end, *start, *vstart;
62 struct Node *node;
63
64 if (*sptr == ';')
65 {
66 sptr++;
67 continue;
68 }
69
70 start = sptr;
71 if ((end = strchr(start, ';')))
72 {
73 *end = 0;
74 sptr = end + 1;
75 }
76 else
77 {
78 sptr = NULL;
79 }
80
81 /* parse key/value from the string */
82 if (!(vstart = strchr(start, '=')))
83 {
84 fprintf(stderr, "%s: invalid key-value pair: %s\n", __func__, start);
85 cfgstr_destroy(cfgstr);
86 return 0;
87 }
88 *vstart++ = 0; /* terminate the key part and move the pointer to the start of the value */
89
90 start = strip_whitespace(start);
91 vstart = strip_whitespace(vstart);
92
93 if (!(key = (char*)malloc(strlen(start) + 1)))
94 {
95 cfgstr_destroy(cfgstr);
96 return 0;
97 }
98
99 if (!(value = (char*)malloc(strlen(vstart) + 1)))
100 {
101 free(key);
102 cfgstr_destroy(cfgstr);
103 return 0;
104 }
105
106 strcpy(key, start);
107 strcpy(value, vstart);
108
109 /* create new list node and add to the list */
110 if (!(node = (Node*)malloc(sizeof *node)))
111 {
112 free(key);
113 free(value);
114 cfgstr_destroy(cfgstr);
115 return 0;
116 }
117
118 node->key = key;
119 node->value = value;
120 node->next = cfgstr->list;
121 cfgstr->list = node;
122 }
123
124 return cfgstr;
125}
126
127void cfgstr_destroy (ConfigString *cfgstr)
128{
129 if (!cfgstr)
130 return;
131
132 while (cfgstr->list)
133 {
134 struct Node *node = cfgstr->list;
135 cfgstr->list = cfgstr->list->next;
136 free(node->key);
137 free(node->value);
138 free(node);
139 }
140 free(cfgstr->string);
141 free(cfgstr);
142}
143
144const char *cfgstr_get_string (const ConfigString *cfgstr)
145{
146 int len;
147 const struct Node *node;
148 char *end;
149
150 free(cfgstr->string);
151
152 /* determine the string size */
153 len = 0;
154 node = cfgstr->list;
155 while (node)
156 {
157 len += strlen(node->key) + strlen(node->value) + 2;
158 node = node->next;
159 }
160
161 if (!(((ConfigString*)cfgstr)->string = (char*)malloc(len + 1)))
162 return 0;
163
164 end = cfgstr->string;
165 node = cfgstr->list;
166
167 while (node)
168 {
169 end += sprintf(end, "%s=%s;", node->key, node->value);
170 node = node->next;
171 }
172
173 return cfgstr->string;
174}
175
176static struct Node *find_node(struct Node *node, const char *key)
177{
178 while (node)
179 {
180 if (strcmp(node->key, key) == 0)
181 return node;
182
183 node = node->next;
184 }
185 return 0;
186}
187
188const char *cfgstr_get (const ConfigString *cfgstr, const char *key)
189{
190 struct Node *node = find_node(cfgstr->list, key);
191 if (!node)
192 return 0;
193
194 return node->value;
195}
196
197float cfgstr_get_float (const ConfigString *cfgstr, const char *key)
198{
199 const char *val_str = cfgstr_get(cfgstr, key);
200 return val_str ? atof(val_str) : 0;
201}
202
203int cfgstr_get_int (const ConfigString *cfgstr, const char *key)
204{
205 const char *val_str = cfgstr_get(cfgstr, key);
206 return val_str ? atoi(val_str) : 0;
207}
208
209/*
210 * returns:
211 * -1: on error
212 * 0: successfuly updated value
213 * 1: added new key-value pair
214 * */
215
216int cfgstr_set (ConfigString *cfgstr, const char *key, const char *value)
217{
218 char *new_val;
219 struct Node *node = find_node(cfgstr->list, key);
220 if (!node)
221 {
222 if ((!(node = (Node*)malloc(sizeof *node))))
223 return -1;
224
225 if ((!(node->key = (char*)malloc(strlen(key) + 1))))
226 {
227 free(node);
228 return -1;
229 }
230
231 if ((!(node->value = (char*)malloc(strlen(value) + 1))))
232 {
233 free(node->key);
234 free(node);
235 return -1;
236 }
237
238 strcpy(node->key, key);
239 strcpy(node->value, value);
240 node->next = cfgstr->list;
241 cfgstr->list = node;
242
243 return 1;
244 }
245
246 if ((!(new_val = (char*)malloc(strlen(value) + 1))))
247 return -1;
248
249 strcpy(new_val, value);
250 free(node->value);
251 node->value = new_val;
252 return 0;
253}
254
255int cfgstr_set_float (ConfigString *cfgstr, const char *key, float value)
256{
257 char buf[512];
258 snprintf(buf, sizeof buf, "%f", value);
259 buf[sizeof buf - 1] = 0; /* make sure it's null terminated */
260
261 return cfgstr_set(cfgstr, key, buf);
262}
263
264int cfgstr_set_int (ConfigString *cfgstr, const char *key, int value)
265{
266 char buf[32];
267 snprintf(buf, sizeof buf, "%d", value);
268 buf[sizeof buf - 1] = 0; /* make sure it's null terminated */
269
270 return cfgstr_set(cfgstr, key, buf);
271}
272
273static char *strip_whitespace (char *buf)
274{
275 while (*buf && isspace(*buf))
276 buf++;
277
278 if (!*buf)
279 return 0;
280
281 char *end = buf + strlen(buf) - 1;
282 while (end > buf && isspace(*end))
283 end--;
284
285 end[1] = 0;
286 return buf;
287}
2880
=== removed file 'unity-shared/ConfigParser.h'
--- unity-shared/ConfigParser.h 2014-02-03 10:18:52 +0000
+++ unity-shared/ConfigParser.h 1970-01-01 00:00:00 +0000
@@ -1,37 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Eleni Maria Stea <elenimaria.stea@canonical.com>
17 */
18
19#ifndef CONFIG_PARSER_H_
20#define CONFIG_PARSER_H_
21
22typedef struct ConfigString ConfigString;
23
24ConfigString *cfgstr_create (const char *str);
25void cfgstr_destroy (ConfigString *cfgstr);
26
27const char *cfgstr_get_string(const ConfigString *cfgstr);
28
29const char *cfgstr_get (const ConfigString *cfgstr, const char *key);
30float cfgstr_get_float (const ConfigString *cfgstr, const char *key);
31int cfgstr_get_int (const ConfigString *cfgstr, const char *key);
32
33int cfgstr_set (ConfigString *cfgstr, const char *key, const char *value);
34int cfgstr_set_float (ConfigString *cfgstr, const char *key, float value);
35int cfgstr_set_int (ConfigString *cfgstr, const char *key, int value);
36
37#endif // CONFIG_PARSER_H_
380
=== modified file 'unity-shared/UScreen.cpp'
--- unity-shared/UScreen.cpp 2014-02-19 16:36:04 +0000
+++ unity-shared/UScreen.cpp 2014-02-21 17:06:30 +0000
@@ -96,15 +96,27 @@
96 return nux::Geometry(0, 0, width, height); 96 return nux::Geometry(0, 0, width, height);
97}97}
9898
99const std::string UScreen::GetMonitorName(int output_number) const99const std::string UScreen::GetMonitorName(int output_number = 0) const
100{100{
101 auto const &output_name = glib::gchar_to_string(gdk_screen_get_monitor_plug_name(screen_, output_number));101 if (output_number < 0 || output_number > gdk_screen_get_n_monitors(screen_))
102 if (output_name.empty())102 {
103 {103 LOG_ERROR(logger) << "UScreen::GetMonitorName: Invalid monitor number" << output_number;
104 LOG_ERROR(logger) << "Failed to get monitor name";104 return "";
105 }105 }
106106
107 return output_name;107 char* const output_name = gdk_screen_get_monitor_plug_name(screen_, output_number);
108 if (!output_name)
109 {
110 LOG_ERROR(logger) << "UScreen::GetMonitorName: Failed to get monitor name for monitor" << output_number;
111 return "";
112 }
113
114 return std::string(output_name);
115}
116
117int UScreen::GetPluggedMonitorsNumber() const
118{
119 return monitors_.size();
108}120}
109121
110void UScreen::Changed(GdkScreen* screen)122void UScreen::Changed(GdkScreen* screen)
111123
=== modified file 'unity-shared/UScreen.h'
--- unity-shared/UScreen.h 2014-02-06 10:07:27 +0000
+++ unity-shared/UScreen.h 2014-02-21 17:06:30 +0000
@@ -53,6 +53,7 @@
53 sigc::signal<void> resuming;53 sigc::signal<void> resuming;
5454
55 const std::string GetMonitorName(int output_number) const;55 const std::string GetMonitorName(int output_number) const;
56 int GetPluggedMonitorsNumber() const;
5657
57private:58private:
58 void Changed(GdkScreen* screen);59 void Changed(GdkScreen* screen);
5960
=== modified file 'unity-shared/UnitySettings.cpp'
--- unity-shared/UnitySettings.cpp 2014-02-19 16:40:07 +0000
+++ unity-shared/UnitySettings.cpp 2014-02-21 17:06:30 +0000
@@ -21,6 +21,7 @@
21#include <gdk/gdk.h>21#include <gdk/gdk.h>
22#include <gtk/gtk.h>22#include <gtk/gtk.h>
23#include <gio/gio.h>23#include <gio/gio.h>
24#include <glib.h>
2425
25#include <NuxCore/Logger.h>26#include <NuxCore/Logger.h>
2627
@@ -39,15 +40,12 @@
39const std::string SETTINGS_NAME = "com.canonical.Unity";40const std::string SETTINGS_NAME = "com.canonical.Unity";
40const std::string FORM_FACTOR = "form-factor";41const std::string FORM_FACTOR = "form-factor";
41const std::string DOUBLE_CLICK_ACTIVATE = "double-click-activate";42const std::string DOUBLE_CLICK_ACTIVATE = "double-click-activate";
43const std::string SCALE_FACTOR = "scale-factor";
42const std::string LIM_KEY = "integrated-menus";44const std::string LIM_KEY = "integrated-menus";
43
44const std::string LIM_SETTINGS = "com.canonical.Unity.IntegratedMenus";45const std::string LIM_SETTINGS = "com.canonical.Unity.IntegratedMenus";
45const std::string CLICK_MOVEMENT_THRESHOLD = "click-movement-threshold";46const std::string CLICK_MOVEMENT_THRESHOLD = "click-movement-threshold";
46const std::string DOUBLE_CLICK_WAIT = "double-click-wait";47const std::string DOUBLE_CLICK_WAIT = "double-click-wait";
4748const std::string UI_SETTINGS = "com.ubuntu.user-interface";
48// FIXME Update this when hikikos settings changes land in unity
49const std::string GNOME_SETTINGS = "org.gnome.desktop.interface";
50const std::string SCALING_FACTOR = "scaling-factor";
51}49}
5250
53//51//
@@ -58,9 +56,10 @@
58public:56public:
59 Impl(Settings* owner)57 Impl(Settings* owner)
60 : parent_(owner)58 : parent_(owner)
59 , gsettings_(g_settings_new(SETTINGS_NAME.c_str()))
60 , ubuntu_settings_(g_settings_new(UI_SETTINGS.c_str()))
61 , usettings_(g_settings_new(SETTINGS_NAME.c_str()))61 , usettings_(g_settings_new(SETTINGS_NAME.c_str()))
62 , lim_settings_(g_settings_new(LIM_SETTINGS.c_str()))62 , lim_settings_(g_settings_new(LIM_SETTINGS.c_str()))
63 , gnome_settings_(g_settings_new(GNOME_SETTINGS.c_str()))
64 , cached_form_factor_(FormFactor::DESKTOP)63 , cached_form_factor_(FormFactor::DESKTOP)
65 , cached_double_click_activate_(true)64 , cached_double_click_activate_(true)
66 , lowGfx_(false)65 , lowGfx_(false)
@@ -82,6 +81,9 @@
82 CacheDoubleClickActivate();81 CacheDoubleClickActivate();
83 parent_->double_click_activate.changed.emit(cached_double_click_activate_);82 parent_->double_click_activate.changed.emit(cached_double_click_activate_);
84 });83 });
84 signals_.Add<void, GSettings*, const gchar*>(ubuntu_settings_, "changed::" + SCALE_FACTOR, [this] (GSettings*, const gchar* t) {
85 UpdateEMConverter();
86 });
8587
86 signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + LIM_KEY, [this] (GSettings*, const gchar*) {88 signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + LIM_KEY, [this] (GSettings*, const gchar*) {
87 UpdateLimSetting();89 UpdateLimSetting();
@@ -90,10 +92,6 @@
90 signals_.Add<void, GSettings*, const gchar*>(lim_settings_, "changed", [this] (GSettings*, const gchar*) {92 signals_.Add<void, GSettings*, const gchar*>(lim_settings_, "changed", [this] (GSettings*, const gchar*) {
91 UpdateLimSetting();93 UpdateLimSetting();
92 });94 });
93
94 signals_.Add<void, GSettings*, const gchar*>(gnome_settings_, "changed::" + SCALING_FACTOR, [this] (GSettings*, const gchar* t) {
95 UpdateEMConverter();
96 });
97 }95 }
9896
99 void CacheFormFactor()97 void CacheFormFactor()
@@ -154,13 +152,37 @@
154 return font_size / 1024;152 return font_size / 1024;
155 }153 }
156154
157 // FIXME Add in getting the specific dpi scale from each monitor155 float GetUIScaleFactor(int monitor = 0) const
156 {
157 GVariant* dict;
158 g_settings_get(ubuntu_settings_, SCALE_FACTOR.c_str(), "@a{si}", &dict);
159
160 std::string monitor_name = UScreen::GetDefault()->GetMonitorName(monitor);
161
162 int value;
163 float ui_scale;
164 if (!g_variant_lookup (dict, monitor_name.c_str(), "i", &value))
165 {
166 ui_scale = 1.0;
167 }
168 else
169 {
170 ui_scale = (float)value / 8.0;
171 }
172
173 return ui_scale;
174 }
175
158 int GetDPI(int monitor = 0) const176 int GetDPI(int monitor = 0) const
159 {177 {
160 int dpi = 96;178 int dpi = 96;
161 int scale = g_settings_get_uint(gnome_settings_, SCALING_FACTOR.c_str());179 int valid_monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
162180 if (monitor >= 0 && monitor < valid_monitors)
163 return dpi * (scale > 0 ? scale : 1);181 {
182 float new_dpi = (float)dpi * GetUIScaleFactor(monitor);
183 dpi = (int)new_dpi;
184 }
185 return dpi;
164 }186 }
165187
166 void UpdateFontSize()188 void UpdateFontSize()
@@ -189,6 +211,8 @@
189 }211 }
190212
191 Settings* parent_;213 Settings* parent_;
214 glib::Object<GSettings> gsettings_;
215 glib::Object<GSettings> ubuntu_settings_;
192 glib::Object<GSettings> usettings_;216 glib::Object<GSettings> usettings_;
193 glib::Object<GSettings> lim_settings_;217 glib::Object<GSettings> lim_settings_;
194 glib::Object<GSettings> gnome_settings_;218 glib::Object<GSettings> gnome_settings_;