2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-10-21 11:32:21 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/atom_browser_main_parts.h"
|
|
|
|
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/strings/string_number_conversions.h"
|
|
|
|
#include "library_loaders/libgio.h"
|
|
|
|
#include "ui/gfx/switches.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char* kInterfaceSchema = "org.gnome.desktop.interface";
|
2014-10-21 11:48:08 +00:00
|
|
|
const char* kScaleFactor = "scaling-factor";
|
2014-10-21 11:32:21 +00:00
|
|
|
|
2014-10-21 12:06:54 +00:00
|
|
|
bool SchemaExists(const LibGioLoader& libgio_loader, const char* schema_name) {
|
|
|
|
const gchar* const* schemas = libgio_loader.g_settings_list_schemas();
|
|
|
|
while (*schemas) {
|
|
|
|
if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0)
|
|
|
|
return true;
|
|
|
|
schemas++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-21 12:45:50 +00:00
|
|
|
bool KeyExists(const LibGioLoader& libgio_loader, GSettings* client,
|
|
|
|
const char* key) {
|
|
|
|
gchar** keys = libgio_loader.g_settings_list_keys(client);
|
|
|
|
if (!keys)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
gchar** iter = keys;
|
|
|
|
while (*iter) {
|
|
|
|
if (strcmp(*iter, key) == 0)
|
|
|
|
break;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool exists = *iter != NULL;
|
|
|
|
g_strfreev(keys);
|
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
|
2014-10-21 11:48:08 +00:00
|
|
|
void GetDPIFromGSettings(guint* scale_factor) {
|
2014-10-21 11:32:21 +00:00
|
|
|
LibGioLoader libgio_loader;
|
|
|
|
|
|
|
|
// Try also without .0 at the end; on some systems this may be required.
|
|
|
|
if (!libgio_loader.Load("libgio-2.0.so.0") &&
|
|
|
|
!libgio_loader.Load("libgio-2.0.so")) {
|
|
|
|
VLOG(1) << "Cannot load gio library. Will fall back to gconf.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-21 12:06:54 +00:00
|
|
|
GSettings* client = nullptr;
|
|
|
|
if (!SchemaExists(libgio_loader, kInterfaceSchema) ||
|
|
|
|
!(client = libgio_loader.g_settings_new(kInterfaceSchema))) {
|
2014-10-21 11:32:21 +00:00
|
|
|
VLOG(1) << "Cannot create gsettings client.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-21 12:45:50 +00:00
|
|
|
if (KeyExists(libgio_loader, client, kScaleFactor))
|
2014-10-21 11:48:08 +00:00
|
|
|
*scale_factor = libgio_loader.g_settings_get_uint(client, kScaleFactor);
|
2014-10-21 11:32:21 +00:00
|
|
|
|
|
|
|
g_object_unref(client);
|
|
|
|
}
|
|
|
|
|
2014-10-21 11:48:08 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void AtomBrowserMainParts::SetDPIFromGSettings() {
|
|
|
|
guint scale_factor = 1;
|
|
|
|
GetDPIFromGSettings(&scale_factor);
|
|
|
|
if (scale_factor == 0)
|
|
|
|
scale_factor = 1;
|
|
|
|
|
|
|
|
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
|
|
|
switches::kForceDeviceScaleFactor, base::UintToString(scale_factor));
|
|
|
|
}
|
|
|
|
|
2014-10-21 11:32:21 +00:00
|
|
|
} // namespace atom
|