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
1=== modified file 'debian/control'
2--- debian/control 2014-02-20 07:08:01 +0000
3+++ debian/control 2014-02-21 17:06:30 +0000
4@@ -11,6 +11,7 @@
5 google-mock (>= 1.6.0+svn437),
6 google-mock,
7 gsettings-desktop-schemas-dev,
8+ gsettings-ubuntu-schemas (>= 0.0.1+14.04.20140219),
9 intltool (>= 0.35.0),
10 libatk1.0-dev,
11 libbamf3-dev (>= 0.5.0+13.10.20130731),
12
13=== modified file 'unity-shared/CMakeLists.txt'
14--- unity-shared/CMakeLists.txt 2014-02-17 04:01:26 +0000
15+++ unity-shared/CMakeLists.txt 2014-02-21 17:06:30 +0000
16@@ -19,7 +19,6 @@
17 set (UNITY_SHARED_SOURCES
18 ApplicationManager.cpp
19 BGHash.cpp
20- ConfigParser.cpp
21 CoverArt.cpp
22 BackgroundEffectHelper.cpp
23 DashStyle.cpp
24
25=== removed file 'unity-shared/ConfigParser.cpp'
26--- unity-shared/ConfigParser.cpp 2014-02-03 18:46:31 +0000
27+++ unity-shared/ConfigParser.cpp 1970-01-01 00:00:00 +0000
28@@ -1,287 +0,0 @@
29-/*
30- * Copyright (C) 2014 Canonical Ltd
31- *
32- * This program is free software: you can redistribute it and/or modify
33- * it under the terms of the GNU General Public License version 3 as
34- * published by the Free Software Foundation.
35- *
36- * This program is distributed in the hope that it will be useful,
37- * but WITHOUT ANY WARRANTY; without even the implied warranty of
38- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39- * GNU General Public License for more details.
40- *
41- * You should have received a copy of the GNU General Public License
42- * along with this program. If not, see <http://www.gnu.org/licenses/>.
43- *
44- * Authored by: Eleni Maria Stea <elenimaria.stea@canonical.com>
45- */
46-
47-#include <ctype.h>
48-#include <stdio.h>
49-#include <stdlib.h>
50-#include <string.h>
51-
52-#include "ConfigParser.h"
53-
54-static char *strip_whitespace (char *buf);
55-
56-/* Linked List */
57-
58-struct Node {
59- char *key;
60- char *value;
61-
62- struct Node *next;
63-};
64-
65-/* ConfigString */
66-
67-struct ConfigString {
68- struct Node *list;
69- char *string;
70-};
71-
72-ConfigString *cfgstr_create (const char *orig_str)
73-{
74- char *sptr, *str;
75-
76- str = (char*)alloca(strlen(orig_str) + 1);
77- strcpy(str, orig_str);
78-
79- ConfigString *cfgstr;
80- if (!(cfgstr = (ConfigString*)malloc(sizeof *cfgstr)))
81- return 0;
82-
83- cfgstr->list = NULL;
84- cfgstr->string = NULL;
85-
86- sptr = str;
87- while (sptr && *sptr != 0)
88- {
89- char *key, *value, *end, *start, *vstart;
90- struct Node *node;
91-
92- if (*sptr == ';')
93- {
94- sptr++;
95- continue;
96- }
97-
98- start = sptr;
99- if ((end = strchr(start, ';')))
100- {
101- *end = 0;
102- sptr = end + 1;
103- }
104- else
105- {
106- sptr = NULL;
107- }
108-
109- /* parse key/value from the string */
110- if (!(vstart = strchr(start, '=')))
111- {
112- fprintf(stderr, "%s: invalid key-value pair: %s\n", __func__, start);
113- cfgstr_destroy(cfgstr);
114- return 0;
115- }
116- *vstart++ = 0; /* terminate the key part and move the pointer to the start of the value */
117-
118- start = strip_whitespace(start);
119- vstart = strip_whitespace(vstart);
120-
121- if (!(key = (char*)malloc(strlen(start) + 1)))
122- {
123- cfgstr_destroy(cfgstr);
124- return 0;
125- }
126-
127- if (!(value = (char*)malloc(strlen(vstart) + 1)))
128- {
129- free(key);
130- cfgstr_destroy(cfgstr);
131- return 0;
132- }
133-
134- strcpy(key, start);
135- strcpy(value, vstart);
136-
137- /* create new list node and add to the list */
138- if (!(node = (Node*)malloc(sizeof *node)))
139- {
140- free(key);
141- free(value);
142- cfgstr_destroy(cfgstr);
143- return 0;
144- }
145-
146- node->key = key;
147- node->value = value;
148- node->next = cfgstr->list;
149- cfgstr->list = node;
150- }
151-
152- return cfgstr;
153-}
154-
155-void cfgstr_destroy (ConfigString *cfgstr)
156-{
157- if (!cfgstr)
158- return;
159-
160- while (cfgstr->list)
161- {
162- struct Node *node = cfgstr->list;
163- cfgstr->list = cfgstr->list->next;
164- free(node->key);
165- free(node->value);
166- free(node);
167- }
168- free(cfgstr->string);
169- free(cfgstr);
170-}
171-
172-const char *cfgstr_get_string (const ConfigString *cfgstr)
173-{
174- int len;
175- const struct Node *node;
176- char *end;
177-
178- free(cfgstr->string);
179-
180- /* determine the string size */
181- len = 0;
182- node = cfgstr->list;
183- while (node)
184- {
185- len += strlen(node->key) + strlen(node->value) + 2;
186- node = node->next;
187- }
188-
189- if (!(((ConfigString*)cfgstr)->string = (char*)malloc(len + 1)))
190- return 0;
191-
192- end = cfgstr->string;
193- node = cfgstr->list;
194-
195- while (node)
196- {
197- end += sprintf(end, "%s=%s;", node->key, node->value);
198- node = node->next;
199- }
200-
201- return cfgstr->string;
202-}
203-
204-static struct Node *find_node(struct Node *node, const char *key)
205-{
206- while (node)
207- {
208- if (strcmp(node->key, key) == 0)
209- return node;
210-
211- node = node->next;
212- }
213- return 0;
214-}
215-
216-const char *cfgstr_get (const ConfigString *cfgstr, const char *key)
217-{
218- struct Node *node = find_node(cfgstr->list, key);
219- if (!node)
220- return 0;
221-
222- return node->value;
223-}
224-
225-float cfgstr_get_float (const ConfigString *cfgstr, const char *key)
226-{
227- const char *val_str = cfgstr_get(cfgstr, key);
228- return val_str ? atof(val_str) : 0;
229-}
230-
231-int cfgstr_get_int (const ConfigString *cfgstr, const char *key)
232-{
233- const char *val_str = cfgstr_get(cfgstr, key);
234- return val_str ? atoi(val_str) : 0;
235-}
236-
237-/*
238- * returns:
239- * -1: on error
240- * 0: successfuly updated value
241- * 1: added new key-value pair
242- * */
243-
244-int cfgstr_set (ConfigString *cfgstr, const char *key, const char *value)
245-{
246- char *new_val;
247- struct Node *node = find_node(cfgstr->list, key);
248- if (!node)
249- {
250- if ((!(node = (Node*)malloc(sizeof *node))))
251- return -1;
252-
253- if ((!(node->key = (char*)malloc(strlen(key) + 1))))
254- {
255- free(node);
256- return -1;
257- }
258-
259- if ((!(node->value = (char*)malloc(strlen(value) + 1))))
260- {
261- free(node->key);
262- free(node);
263- return -1;
264- }
265-
266- strcpy(node->key, key);
267- strcpy(node->value, value);
268- node->next = cfgstr->list;
269- cfgstr->list = node;
270-
271- return 1;
272- }
273-
274- if ((!(new_val = (char*)malloc(strlen(value) + 1))))
275- return -1;
276-
277- strcpy(new_val, value);
278- free(node->value);
279- node->value = new_val;
280- return 0;
281-}
282-
283-int cfgstr_set_float (ConfigString *cfgstr, const char *key, float value)
284-{
285- char buf[512];
286- snprintf(buf, sizeof buf, "%f", value);
287- buf[sizeof buf - 1] = 0; /* make sure it's null terminated */
288-
289- return cfgstr_set(cfgstr, key, buf);
290-}
291-
292-int cfgstr_set_int (ConfigString *cfgstr, const char *key, int value)
293-{
294- char buf[32];
295- snprintf(buf, sizeof buf, "%d", value);
296- buf[sizeof buf - 1] = 0; /* make sure it's null terminated */
297-
298- return cfgstr_set(cfgstr, key, buf);
299-}
300-
301-static char *strip_whitespace (char *buf)
302-{
303- while (*buf && isspace(*buf))
304- buf++;
305-
306- if (!*buf)
307- return 0;
308-
309- char *end = buf + strlen(buf) - 1;
310- while (end > buf && isspace(*end))
311- end--;
312-
313- end[1] = 0;
314- return buf;
315-}
316
317=== removed file 'unity-shared/ConfigParser.h'
318--- unity-shared/ConfigParser.h 2014-02-03 10:18:52 +0000
319+++ unity-shared/ConfigParser.h 1970-01-01 00:00:00 +0000
320@@ -1,37 +0,0 @@
321-/*
322- * Copyright (C) 2014 Canonical Ltd
323- *
324- * This program is free software: you can redistribute it and/or modify
325- * it under the terms of the GNU General Public License version 3 as
326- * published by the Free Software Foundation.
327- *
328- * This program is distributed in the hope that it will be useful,
329- * but WITHOUT ANY WARRANTY; without even the implied warranty of
330- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
331- * GNU General Public License for more details.
332- *
333- * You should have received a copy of the GNU General Public License
334- * along with this program. If not, see <http://www.gnu.org/licenses/>.
335- *
336- * Authored by: Eleni Maria Stea <elenimaria.stea@canonical.com>
337- */
338-
339-#ifndef CONFIG_PARSER_H_
340-#define CONFIG_PARSER_H_
341-
342-typedef struct ConfigString ConfigString;
343-
344-ConfigString *cfgstr_create (const char *str);
345-void cfgstr_destroy (ConfigString *cfgstr);
346-
347-const char *cfgstr_get_string(const ConfigString *cfgstr);
348-
349-const char *cfgstr_get (const ConfigString *cfgstr, const char *key);
350-float cfgstr_get_float (const ConfigString *cfgstr, const char *key);
351-int cfgstr_get_int (const ConfigString *cfgstr, const char *key);
352-
353-int cfgstr_set (ConfigString *cfgstr, const char *key, const char *value);
354-int cfgstr_set_float (ConfigString *cfgstr, const char *key, float value);
355-int cfgstr_set_int (ConfigString *cfgstr, const char *key, int value);
356-
357-#endif // CONFIG_PARSER_H_
358
359=== modified file 'unity-shared/UScreen.cpp'
360--- unity-shared/UScreen.cpp 2014-02-19 16:36:04 +0000
361+++ unity-shared/UScreen.cpp 2014-02-21 17:06:30 +0000
362@@ -96,15 +96,27 @@
363 return nux::Geometry(0, 0, width, height);
364 }
365
366-const std::string UScreen::GetMonitorName(int output_number) const
367-{
368- auto const &output_name = glib::gchar_to_string(gdk_screen_get_monitor_plug_name(screen_, output_number));
369- if (output_name.empty())
370- {
371- LOG_ERROR(logger) << "Failed to get monitor name";
372- }
373-
374- return output_name;
375+const std::string UScreen::GetMonitorName(int output_number = 0) const
376+{
377+ if (output_number < 0 || output_number > gdk_screen_get_n_monitors(screen_))
378+ {
379+ LOG_ERROR(logger) << "UScreen::GetMonitorName: Invalid monitor number" << output_number;
380+ return "";
381+ }
382+
383+ char* const output_name = gdk_screen_get_monitor_plug_name(screen_, output_number);
384+ if (!output_name)
385+ {
386+ LOG_ERROR(logger) << "UScreen::GetMonitorName: Failed to get monitor name for monitor" << output_number;
387+ return "";
388+ }
389+
390+ return std::string(output_name);
391+}
392+
393+int UScreen::GetPluggedMonitorsNumber() const
394+{
395+ return monitors_.size();
396 }
397
398 void UScreen::Changed(GdkScreen* screen)
399
400=== modified file 'unity-shared/UScreen.h'
401--- unity-shared/UScreen.h 2014-02-06 10:07:27 +0000
402+++ unity-shared/UScreen.h 2014-02-21 17:06:30 +0000
403@@ -53,6 +53,7 @@
404 sigc::signal<void> resuming;
405
406 const std::string GetMonitorName(int output_number) const;
407+ int GetPluggedMonitorsNumber() const;
408
409 private:
410 void Changed(GdkScreen* screen);
411
412=== modified file 'unity-shared/UnitySettings.cpp'
413--- unity-shared/UnitySettings.cpp 2014-02-19 16:40:07 +0000
414+++ unity-shared/UnitySettings.cpp 2014-02-21 17:06:30 +0000
415@@ -21,6 +21,7 @@
416 #include <gdk/gdk.h>
417 #include <gtk/gtk.h>
418 #include <gio/gio.h>
419+#include <glib.h>
420
421 #include <NuxCore/Logger.h>
422
423@@ -39,15 +40,12 @@
424 const std::string SETTINGS_NAME = "com.canonical.Unity";
425 const std::string FORM_FACTOR = "form-factor";
426 const std::string DOUBLE_CLICK_ACTIVATE = "double-click-activate";
427+const std::string SCALE_FACTOR = "scale-factor";
428 const std::string LIM_KEY = "integrated-menus";
429-
430 const std::string LIM_SETTINGS = "com.canonical.Unity.IntegratedMenus";
431 const std::string CLICK_MOVEMENT_THRESHOLD = "click-movement-threshold";
432 const std::string DOUBLE_CLICK_WAIT = "double-click-wait";
433-
434-// FIXME Update this when hikikos settings changes land in unity
435-const std::string GNOME_SETTINGS = "org.gnome.desktop.interface";
436-const std::string SCALING_FACTOR = "scaling-factor";
437+const std::string UI_SETTINGS = "com.ubuntu.user-interface";
438 }
439
440 //
441@@ -58,9 +56,10 @@
442 public:
443 Impl(Settings* owner)
444 : parent_(owner)
445+ , gsettings_(g_settings_new(SETTINGS_NAME.c_str()))
446+ , ubuntu_settings_(g_settings_new(UI_SETTINGS.c_str()))
447 , usettings_(g_settings_new(SETTINGS_NAME.c_str()))
448 , lim_settings_(g_settings_new(LIM_SETTINGS.c_str()))
449- , gnome_settings_(g_settings_new(GNOME_SETTINGS.c_str()))
450 , cached_form_factor_(FormFactor::DESKTOP)
451 , cached_double_click_activate_(true)
452 , lowGfx_(false)
453@@ -82,6 +81,9 @@
454 CacheDoubleClickActivate();
455 parent_->double_click_activate.changed.emit(cached_double_click_activate_);
456 });
457+ signals_.Add<void, GSettings*, const gchar*>(ubuntu_settings_, "changed::" + SCALE_FACTOR, [this] (GSettings*, const gchar* t) {
458+ UpdateEMConverter();
459+ });
460
461 signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + LIM_KEY, [this] (GSettings*, const gchar*) {
462 UpdateLimSetting();
463@@ -90,10 +92,6 @@
464 signals_.Add<void, GSettings*, const gchar*>(lim_settings_, "changed", [this] (GSettings*, const gchar*) {
465 UpdateLimSetting();
466 });
467-
468- signals_.Add<void, GSettings*, const gchar*>(gnome_settings_, "changed::" + SCALING_FACTOR, [this] (GSettings*, const gchar* t) {
469- UpdateEMConverter();
470- });
471 }
472
473 void CacheFormFactor()
474@@ -154,13 +152,37 @@
475 return font_size / 1024;
476 }
477
478- // FIXME Add in getting the specific dpi scale from each monitor
479+ float GetUIScaleFactor(int monitor = 0) const
480+ {
481+ GVariant* dict;
482+ g_settings_get(ubuntu_settings_, SCALE_FACTOR.c_str(), "@a{si}", &dict);
483+
484+ std::string monitor_name = UScreen::GetDefault()->GetMonitorName(monitor);
485+
486+ int value;
487+ float ui_scale;
488+ if (!g_variant_lookup (dict, monitor_name.c_str(), "i", &value))
489+ {
490+ ui_scale = 1.0;
491+ }
492+ else
493+ {
494+ ui_scale = (float)value / 8.0;
495+ }
496+
497+ return ui_scale;
498+ }
499+
500 int GetDPI(int monitor = 0) const
501 {
502 int dpi = 96;
503- int scale = g_settings_get_uint(gnome_settings_, SCALING_FACTOR.c_str());
504-
505- return dpi * (scale > 0 ? scale : 1);
506+ int valid_monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
507+ if (monitor >= 0 && monitor < valid_monitors)
508+ {
509+ float new_dpi = (float)dpi * GetUIScaleFactor(monitor);
510+ dpi = (int)new_dpi;
511+ }
512+ return dpi;
513 }
514
515 void UpdateFontSize()
516@@ -189,6 +211,8 @@
517 }
518
519 Settings* parent_;
520+ glib::Object<GSettings> gsettings_;
521+ glib::Object<GSettings> ubuntu_settings_;
522 glib::Object<GSettings> usettings_;
523 glib::Object<GSettings> lim_settings_;
524 glib::Object<GSettings> gnome_settings_;