1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2010 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
*/
#include "gdk/gdk.h"
#include "DashSettings.h"
#include "UScreen.h"
#define FORM_FACTOR "form-factor"
static DashSettings* _places_settings = NULL;
DashSettings::DashSettings()
: _settings(NULL),
_raw_from_factor(0),
_form_factor(DESKTOP)
{
_settings = g_settings_new("com.canonical.Unity");
g_signal_connect(_settings, "changed",
(GCallback)(DashSettings::Changed), this);
Refresh();
}
DashSettings::~DashSettings()
{
g_object_unref(_settings);
}
void
DashSettings::Refresh()
{
_raw_from_factor = g_settings_get_enum(_settings, FORM_FACTOR);
if (_raw_from_factor == 0) //Automatic
{
UScreen *uscreen = UScreen::GetDefault();
int primary_monitor = uscreen->GetPrimaryMonitor();
auto geo = uscreen->GetMonitorGeometry(primary_monitor);
_form_factor = geo.height > 799 ? DESKTOP : NETBOOK;
}
else
{
_form_factor = (FormFactor)_raw_from_factor;
}
changed.emit();
}
void
DashSettings::Changed(GSettings* settings, char* key, DashSettings* self)
{
self->Refresh();
}
DashSettings*
DashSettings::GetDefault()
{
if (G_UNLIKELY(!_places_settings))
_places_settings = new DashSettings();
return _places_settings;
}
DashSettings::FormFactor
DashSettings::GetFormFactor()
{
return _form_factor;
}
void
DashSettings::SetFormFactor(FormFactor factor)
{
_form_factor = factor;
g_settings_set_enum(_settings, FORM_FACTOR, factor);
}
|