LowPowerModeNotifierGLib.cpp [plain text]
#include "config.h"
#include "LowPowerModeNotifier.h"
#if USE(UPOWER)
namespace WebCore {
LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&& callback)
: m_upClient(adoptGRef(up_client_new()))
, m_device(adoptGRef(up_client_get_display_device(m_upClient.get())))
, m_callback(WTFMove(callback))
{
updateState();
g_signal_connect_swapped(m_device.get(), "notify::warning-level", G_CALLBACK(warningLevelCallback), this);
}
void LowPowerModeNotifier::updateState()
{
UpDeviceLevel warningLevel;
g_object_get(G_OBJECT(m_device.get()), "warning-level", &warningLevel, nullptr);
m_lowPowerModeEnabled = warningLevel > UP_DEVICE_LEVEL_NONE && warningLevel <= UP_DEVICE_LEVEL_ACTION;
}
void LowPowerModeNotifier::warningLevelCallback(LowPowerModeNotifier* notifier)
{
notifier->updateState();
notifier->m_callback(notifier->m_lowPowerModeEnabled);
}
LowPowerModeNotifier::~LowPowerModeNotifier()
{
g_signal_handlers_disconnect_by_data(m_device.get(), this);
}
bool LowPowerModeNotifier::isLowPowerModeEnabled() const
{
return m_lowPowerModeEnabled;
}
}
#endif