parent
a1ac78a4af
commit
82fcf900bd
|
@ -111,7 +111,8 @@ int_get(const char *buf)
|
|||
const char *p = strchr(buf, ':');
|
||||
if (!p) return 0;
|
||||
p++;
|
||||
while (*p == ' ') p++;
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
return atoi(p);
|
||||
}
|
||||
|
||||
|
@ -124,10 +125,12 @@ str_get(const char *buf)
|
|||
|
||||
if (!p) return NULL;
|
||||
p++;
|
||||
while (*p == ' ') p++;
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
|
||||
q = p + strlen(p) - 1;
|
||||
while ((q > p) && ((*q == ' ') || (*q == '\n'))) q--;
|
||||
while ((q > p) && ((*q == ' ') || (*q == '\n')))
|
||||
q--;
|
||||
|
||||
if (q < p) return NULL;
|
||||
q++;
|
||||
|
@ -139,7 +142,7 @@ str_get(const char *buf)
|
|||
}
|
||||
|
||||
static char *
|
||||
file_str_entry_get(FILE *f,
|
||||
file_str_entry_get(FILE *f,
|
||||
const char *entry)
|
||||
{
|
||||
char buf[4096];
|
||||
|
@ -283,10 +286,10 @@ bsd_apm_check(void)
|
|||
if ((apm_fd != -1) && (ioctl(apm_fd, APMIO_GETINFO, &info) != -1))
|
||||
{
|
||||
/* set values */
|
||||
ac_stat = info.ai_acline;
|
||||
bat_stat = info.ai_batt_stat;
|
||||
bat_val = info.ai_batt_life;
|
||||
time_val = info.ai_batt_time;
|
||||
ac_stat = info.ai_acline;
|
||||
bat_stat = info.ai_batt_stat;
|
||||
bat_val = info.ai_batt_life;
|
||||
time_val = info.ai_batt_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -425,7 +428,7 @@ darwin_check(void)
|
|||
/* new linux power class api to get power info - brand new and this code
|
||||
* may have bugs, but it is a good attempt to get it right */
|
||||
#if 0
|
||||
static Eina_Bool linux_sys_class_power_supply_cb_event_fd_active(void *data,
|
||||
static Eina_Bool linux_sys_class_power_supply_cb_event_fd_active(void *data,
|
||||
Ecore_Fd_Handler *fd_handler);
|
||||
static void linux_sys_class_power_supply_check(void);
|
||||
#endif
|
||||
|
@ -481,8 +484,8 @@ linux_sys_class_power_supply_cb_re_init(void *data)
|
|||
// if (sysev->fd_handler)
|
||||
// ecore_main_fd_handler_del(sysev->fd_handler);
|
||||
// if (sysev->fd >= 0) close(sysev->fd);
|
||||
free(sysev->name);
|
||||
free(sysev);
|
||||
free(sysev->name);
|
||||
free(sysev);
|
||||
}
|
||||
}
|
||||
linux_sys_class_power_supply_init();
|
||||
|
@ -491,7 +494,7 @@ linux_sys_class_power_supply_cb_re_init(void *data)
|
|||
}
|
||||
|
||||
static Eina_Bool
|
||||
linux_sys_class_power_supply_cb_event_fd_active(void *data,
|
||||
linux_sys_class_power_supply_cb_event_fd_active(void *data,
|
||||
Ecore_Fd_Handler *fd_handler)
|
||||
{
|
||||
Sys_Class_Power_Supply_Uevent *sysev;
|
||||
|
@ -807,7 +810,7 @@ linux_sys_class_power_supply_check(void)
|
|||
else if (sysev->basis == BASIS_ENERGY)
|
||||
snprintf(buf, sizeof(buf), "%s/%s/energy_now", dir, name);
|
||||
else if (sysev->basis == BASIS_VOLTAGE)
|
||||
snprintf(buf, sizeof(buf), "%s/%s/voltage_now", dir, name);
|
||||
snprintf(buf, sizeof(buf), "%s/%s/voltage_now", dir, name);
|
||||
pwr_now = int_file_get(buf);
|
||||
pwr_empty = sysev->basis_empty;
|
||||
pwr_full = sysev->basis_full;
|
||||
|
@ -829,9 +832,9 @@ linux_sys_class_power_supply_check(void)
|
|||
else
|
||||
{
|
||||
if (pwr_now < 0)
|
||||
pwr_now = (((long long)capacity * ((long long)pwr_full - (long long)pwr_empty)) / 100) + pwr_empty;
|
||||
pwr_now = (((long long)capacity * ((long long)pwr_full - (long long)pwr_empty)) / 100) + pwr_empty;
|
||||
}
|
||||
|
||||
|
||||
if (sysev->present) have_battery = 1;
|
||||
if (charging)
|
||||
{
|
||||
|
@ -840,13 +843,13 @@ linux_sys_class_power_supply_check(void)
|
|||
if (time_to_full >= 0)
|
||||
{
|
||||
if (time_to_full > time_left)
|
||||
time_left = time_to_full;
|
||||
time_left = time_to_full;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (current == 0) time_left = 0;
|
||||
else if (current < 0)
|
||||
time_left = -1;
|
||||
time_left = -1;
|
||||
else
|
||||
{
|
||||
pwr = (((long long)pwr_full - (long long)pwr_now) * 3600) / -current;
|
||||
|
@ -897,16 +900,16 @@ linux_sys_class_power_supply_check(void)
|
|||
* power class api to poll for power stuff
|
||||
*/
|
||||
static Eina_Bool linux_acpi_cb_acpid_add(void *data,
|
||||
int type,
|
||||
int type,
|
||||
void *event);
|
||||
static Eina_Bool linux_acpi_cb_acpid_del(void *data,
|
||||
int type,
|
||||
int type,
|
||||
void *event);
|
||||
static Eina_Bool linux_acpi_cb_acpid_data(void *data,
|
||||
int type,
|
||||
int type,
|
||||
void *event);
|
||||
static void linux_acpi_init(void);
|
||||
static void linux_acpi_check(void);
|
||||
static void linux_acpi_init(void);
|
||||
static void linux_acpi_check(void);
|
||||
|
||||
static int acpi_max_full = -1;
|
||||
static int acpi_max_design = -1;
|
||||
|
@ -1026,7 +1029,7 @@ linux_acpi_init(void)
|
|||
{
|
||||
char *tmp;
|
||||
|
||||
/* state */
|
||||
/* state */
|
||||
tmp = fgets(buf, sizeof(buf), f);
|
||||
if (tmp) tmp = str_get(tmp);
|
||||
if (tmp)
|
||||
|
@ -1034,7 +1037,7 @@ linux_acpi_init(void)
|
|||
if (!strcmp(tmp, "on-line")) have_power = 1;
|
||||
free(tmp);
|
||||
}
|
||||
fclose(f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
eina_iterator_free(powers);
|
||||
|
@ -1055,7 +1058,7 @@ linux_acpi_init(void)
|
|||
{
|
||||
char *tmp;
|
||||
|
||||
/* present */
|
||||
/* present */
|
||||
tmp = fgets(buf, sizeof(buf), f);
|
||||
if (tmp) tmp = str_get(tmp);
|
||||
if (tmp)
|
||||
|
@ -1063,7 +1066,7 @@ linux_acpi_init(void)
|
|||
if (!strcmp(tmp, "yes")) have_battery = 1;
|
||||
free(tmp);
|
||||
}
|
||||
/* design cap */
|
||||
/* design cap */
|
||||
tmp = fgets(buf, sizeof(buf), f);
|
||||
if (tmp) tmp = str_get(tmp);
|
||||
if (tmp)
|
||||
|
@ -1071,7 +1074,7 @@ linux_acpi_init(void)
|
|||
if (strcmp(tmp, "unknown")) acpi_max_design += atoi(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
/* last full cap */
|
||||
/* last full cap */
|
||||
tmp = fgets(buf, sizeof(buf), f);
|
||||
if (tmp) tmp = str_get(tmp);
|
||||
if (tmp)
|
||||
|
@ -1379,17 +1382,17 @@ fclose_and_continue:
|
|||
fclose(f);
|
||||
if (!current)
|
||||
{
|
||||
/* Neither charging nor discharging */
|
||||
/* Neither charging nor discharging */
|
||||
}
|
||||
else if (!ac)
|
||||
{
|
||||
/* When on dc, we are discharging */
|
||||
seconds += timeleft;
|
||||
/* When on dc, we are discharging */
|
||||
seconds += timeleft;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Charging - works in parallel */
|
||||
seconds = MAX(timeleft, seconds);
|
||||
/* Charging - works in parallel */
|
||||
seconds = MAX(timeleft, seconds);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1561,7 +1564,7 @@ poll_cb(void *data __UNUSED__)
|
|||
}
|
||||
|
||||
int
|
||||
main(int argc,
|
||||
main(int argc,
|
||||
char *argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
|
|
|
@ -18,32 +18,32 @@ struct _E_Config_Dialog_Data
|
|||
#ifdef HAVE_ENOTIFY
|
||||
int desktop_notifications;
|
||||
#endif
|
||||
struct
|
||||
{
|
||||
Evas_Object *show_alert_label;
|
||||
Evas_Object *show_alert_time;
|
||||
Evas_Object *show_alert_percent;
|
||||
Evas_Object *dismiss_alert_label;
|
||||
Evas_Object *alert_timeout;
|
||||
struct
|
||||
{
|
||||
Evas_Object *show_alert_label;
|
||||
Evas_Object *show_alert_time;
|
||||
Evas_Object *show_alert_percent;
|
||||
Evas_Object *dismiss_alert_label;
|
||||
Evas_Object *alert_timeout;
|
||||
#ifdef HAVE_EEZE
|
||||
Evas_Object *fuzzy;
|
||||
Evas_Object *fuzzy;
|
||||
#endif
|
||||
} ui;
|
||||
} ui;
|
||||
};
|
||||
|
||||
/* Protos */
|
||||
static void *_create_data(E_Config_Dialog *cfd);
|
||||
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static void *_create_data(E_Config_Dialog *cfd);
|
||||
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
|
||||
static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static int _basic_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static int _basic_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static Evas_Object *_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
|
||||
static int _advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static int _advanced_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static void _cb_radio_changed(void *data, Evas_Object *obj __UNUSED__);
|
||||
static int _advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static int _advanced_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static void _cb_radio_changed(void *data, Evas_Object *obj __UNUSED__);
|
||||
|
||||
E_Config_Dialog *
|
||||
e_int_config_battery_module(E_Container *con, const char *params __UNUSED__)
|
||||
e_int_config_battery_module(E_Container *con, const char *params __UNUSED__)
|
||||
{
|
||||
E_Config_Dialog *cfd;
|
||||
E_Config_Dialog_View *v;
|
||||
|
@ -59,17 +59,17 @@ e_int_config_battery_module(E_Container *con, const char *params __UNUSED__)
|
|||
v->advanced.create_widgets = _advanced_create_widgets;
|
||||
v->advanced.check_changed = _advanced_check_changed;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/e-module-battery.edj",
|
||||
snprintf(buf, sizeof(buf), "%s/e-module-battery.edj",
|
||||
e_module_dir_get(battery_config->module));
|
||||
cfd = e_config_dialog_new(con, _("Battery Monitor Settings"),
|
||||
"E", "_e_mod_battery_config_dialog",
|
||||
buf, 0, v, NULL);
|
||||
cfd = e_config_dialog_new(con, _("Battery Monitor Settings"),
|
||||
"E", "_e_mod_battery_config_dialog",
|
||||
buf, 0, v, NULL);
|
||||
battery_config->config_dialog = cfd;
|
||||
return cfd;
|
||||
}
|
||||
|
||||
static void
|
||||
_fill_data(E_Config_Dialog_Data *cfdata)
|
||||
_fill_data(E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
if (!battery_config) return;
|
||||
cfdata->alert_time = battery_config->alert;
|
||||
|
@ -86,9 +86,9 @@ _fill_data(E_Config_Dialog_Data *cfdata)
|
|||
cfdata->desktop_notifications = battery_config->desktop_notifications;
|
||||
#endif
|
||||
|
||||
if ((cfdata->alert_time > 0) || (cfdata->alert_percent > 0))
|
||||
if ((cfdata->alert_time > 0) || (cfdata->alert_percent > 0))
|
||||
cfdata->show_alert = 1;
|
||||
else
|
||||
else
|
||||
cfdata->show_alert = 0;
|
||||
|
||||
if (cfdata->alert_timeout > 0)
|
||||
|
@ -149,7 +149,7 @@ _basic_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
|
|||
|
||||
if (cfdata->show_alert)
|
||||
{
|
||||
_ensure_alert_time(cfdata);
|
||||
_ensure_alert_time(cfdata);
|
||||
battery_config->alert = cfdata->alert_time;
|
||||
battery_config->alert_p = cfdata->alert_percent;
|
||||
#ifdef HAVE_ENOTIFY
|
||||
|
@ -175,7 +175,7 @@ _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfda
|
|||
{
|
||||
Eina_Bool ret;
|
||||
int old_show_alert = ((battery_config->alert > 0) ||
|
||||
(battery_config->alert_p > 0));
|
||||
(battery_config->alert_p > 0));
|
||||
|
||||
ret = (cfdata->show_alert != old_show_alert);
|
||||
#ifdef HAVE_ENOTIFY
|
||||
|
@ -208,8 +208,8 @@ _cb_dismiss_alert_changed(void *data, Evas_Object *obj __UNUSED__)
|
|||
e_widget_disabled_set(cfdata->ui.alert_timeout, !dismiss_alert);
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_radio_changed(void *data, Evas_Object *obj __UNUSED__)
|
||||
static void
|
||||
_cb_radio_changed(void *data, Evas_Object *obj __UNUSED__)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
Eina_Bool fuzzy;
|
||||
|
@ -234,10 +234,10 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_D
|
|||
|
||||
ob = e_widget_label_add(evas, _("Check every:"));
|
||||
e_widget_table_object_append(o, ob, 0, 0, 1, 1, 1, 0, 1, 0);
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f ticks"), 1, 256, 4, 0,
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f ticks"), 1, 256, 4, 0,
|
||||
NULL, &(cfdata->poll_interval), 100);
|
||||
e_widget_table_object_append(o, ob, 0, 1, 1, 1, 1, 0, 1, 0);
|
||||
|
||||
|
||||
rg = e_widget_radio_group_new(&(cfdata->suspend_method));
|
||||
ob = e_widget_radio_add(evas, _("Suspend when below:"), 0, rg);
|
||||
e_widget_on_change_hook_set(ob, _cb_radio_changed, cfdata);
|
||||
|
@ -248,11 +248,11 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_D
|
|||
ob = e_widget_radio_add(evas, _("Shutdown when below:"), 2, rg);
|
||||
e_widget_on_change_hook_set(ob, _cb_radio_changed, cfdata);
|
||||
e_widget_table_object_append(o, ob, 0, 4, 1, 1, 1, 0, 1, 0);
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f %%"), 0, 50, 1, 0,
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f %%"), 0, 50, 1, 0,
|
||||
NULL, &(cfdata->suspend_below), 100);
|
||||
e_widget_table_object_append(o, ob, 0, 5, 1, 1, 1, 0, 1, 0);
|
||||
|
||||
e_widget_toolbook_page_append(otb, NULL, _("Polling"), o, 1, 0, 1, 0,
|
||||
|
||||
e_widget_toolbook_page_append(otb, NULL, _("Polling"), o, 1, 0, 1, 0,
|
||||
0.5, 0.0);
|
||||
|
||||
o = e_widget_table_add(evas, 0);
|
||||
|
@ -263,11 +263,11 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_D
|
|||
ob = e_widget_label_add(evas, _("Alert when at:"));
|
||||
cfdata->ui.show_alert_label = ob;
|
||||
e_widget_table_object_append(o, ob, 0, 1, 1, 1, 1, 0, 1, 1);
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f min"), 0, 60, 1, 0, NULL,
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f min"), 0, 60, 1, 0, NULL,
|
||||
&(cfdata->alert_time), 100);
|
||||
cfdata->ui.show_alert_time = ob;
|
||||
e_widget_table_object_append(o, ob, 0, 2, 1, 1, 1, 0, 1, 0);
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f %%"), 0, 100, 1, 0, NULL,
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f %%"), 0, 100, 1, 0, NULL,
|
||||
&(cfdata->alert_percent), 100);
|
||||
cfdata->ui.show_alert_percent = ob;
|
||||
e_widget_table_object_append(o, ob, 0, 3, 1, 1, 1, 0, 1, 0);
|
||||
|
@ -283,7 +283,7 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_D
|
|||
|
||||
_cb_show_alert_changed(cfdata, NULL);
|
||||
|
||||
e_widget_toolbook_page_append(otb, NULL, _("Alert"), o, 1, 0, 1, 0,
|
||||
e_widget_toolbook_page_append(otb, NULL, _("Alert"), o, 1, 0, 1, 0,
|
||||
0.5, 0.0);
|
||||
|
||||
o = e_widget_list_add(evas, 0, 0);
|
||||
|
@ -308,7 +308,7 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_D
|
|||
#endif
|
||||
e_widget_list_object_append(o, ob, 1, 0, 0.0);
|
||||
|
||||
e_widget_toolbook_page_append(otb, NULL, _("Hardware"), o, 1, 0, 1, 0,
|
||||
e_widget_toolbook_page_append(otb, NULL, _("Hardware"), o, 1, 0, 1, 0,
|
||||
0.5, 0.0);
|
||||
|
||||
e_widget_toolbook_page_show(otb, 0);
|
||||
|
@ -327,7 +327,7 @@ _advanced_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfda
|
|||
|
||||
if (cfdata->show_alert)
|
||||
{
|
||||
_ensure_alert_time(cfdata);
|
||||
_ensure_alert_time(cfdata);
|
||||
battery_config->alert = cfdata->alert_time;
|
||||
battery_config->alert_p = cfdata->alert_percent;
|
||||
}
|
||||
|
@ -355,20 +355,20 @@ static int
|
|||
_advanced_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
int old_show_alert = ((battery_config->alert > 0) ||
|
||||
(battery_config->alert_p > 0));
|
||||
(battery_config->alert_p > 0));
|
||||
int old_dismiss_alert = (battery_config->alert_timeout > 0);
|
||||
|
||||
return ((cfdata->alert_time != battery_config->alert) ||
|
||||
(cfdata->alert_percent != battery_config->alert_p) ||
|
||||
(cfdata->poll_interval != battery_config->poll_interval) ||
|
||||
(cfdata->alert_timeout != battery_config->alert_timeout) ||
|
||||
(cfdata->suspend_below != battery_config->suspend_below) ||
|
||||
(cfdata->suspend_method != battery_config->suspend_method) ||
|
||||
return (cfdata->alert_time != battery_config->alert) ||
|
||||
(cfdata->alert_percent != battery_config->alert_p) ||
|
||||
(cfdata->poll_interval != battery_config->poll_interval) ||
|
||||
(cfdata->alert_timeout != battery_config->alert_timeout) ||
|
||||
(cfdata->suspend_below != battery_config->suspend_below) ||
|
||||
(cfdata->suspend_method != battery_config->suspend_method) ||
|
||||
#ifdef HAVE_EEZE
|
||||
(cfdata->fuzzy != battery_config->fuzzy) ||
|
||||
#endif
|
||||
(cfdata->force_mode != battery_config->force_mode) ||
|
||||
(cfdata->show_alert != old_show_alert) ||
|
||||
(cfdata->dismiss_alert != old_dismiss_alert));
|
||||
(cfdata->fuzzy != battery_config->fuzzy) ||
|
||||
#endif
|
||||
(cfdata->force_mode != battery_config->force_mode) ||
|
||||
(cfdata->show_alert != old_show_alert) ||
|
||||
(cfdata->dismiss_alert != old_dismiss_alert);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,12 +31,12 @@ _battery_dbus_start(void)
|
|||
(e_dbus_conn, "battery", _battery_dbus_find_battery, NULL);
|
||||
e_hal_manager_find_device_by_capability
|
||||
(e_dbus_conn, "ac_adapter", _battery_dbus_find_ac, NULL);
|
||||
battery_config->dbus.dev_add =
|
||||
battery_config->dbus.dev_add =
|
||||
e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER,
|
||||
E_HAL_MANAGER_PATH,
|
||||
E_HAL_MANAGER_INTERFACE,
|
||||
"DeviceAdded", _battery_dbus_dev_add, NULL);
|
||||
battery_config->dbus.dev_del =
|
||||
battery_config->dbus.dev_del =
|
||||
e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER,
|
||||
E_HAL_MANAGER_PATH,
|
||||
E_HAL_MANAGER_INTERFACE,
|
||||
|
@ -45,7 +45,6 @@ _battery_dbus_start(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_battery_dbus_stop(void)
|
||||
{
|
||||
|
@ -53,7 +52,7 @@ _battery_dbus_stop(void)
|
|||
Battery *bat;
|
||||
|
||||
if (!e_dbus_conn) return;
|
||||
|
||||
|
||||
if (battery_config->dbus.have)
|
||||
{
|
||||
dbus_pending_call_cancel(battery_config->dbus.have);
|
||||
|
@ -110,16 +109,16 @@ _battery_dbus_battery_props(void *data, void *reply_data, DBusError *error __UNU
|
|||
#undef GET_INT
|
||||
#undef GET_STR
|
||||
#define GET_BOOL(val, s) bat->val = e_hal_property_bool_get(ret, s, &err)
|
||||
#define GET_INT(val, s) bat->val = e_hal_property_int_get(ret, s, &err)
|
||||
#define GET_STR(val, s) \
|
||||
if (bat->val) eina_stringshare_del(bat->val); \
|
||||
bat->val = NULL; \
|
||||
str = e_hal_property_string_get(ret, s, &err); \
|
||||
if (str) \
|
||||
{ \
|
||||
bat->val = eina_stringshare_ref(str); \
|
||||
}
|
||||
|
||||
#define GET_INT(val, s) bat->val = e_hal_property_int_get(ret, s, &err)
|
||||
#define GET_STR(val, s) \
|
||||
if (bat->val) eina_stringshare_del(bat->val); \
|
||||
bat->val = NULL; \
|
||||
str = e_hal_property_string_get(ret, s, &err); \
|
||||
if (str) \
|
||||
{ \
|
||||
bat->val = eina_stringshare_ref(str); \
|
||||
}
|
||||
|
||||
GET_BOOL(present, "battery.present");
|
||||
GET_STR(technology, "battery.reporting.technology");
|
||||
GET_STR(model, "battery.model");
|
||||
|
@ -162,19 +161,19 @@ _battery_dbus_ac_adapter_props(void *data, void *reply_data, DBusError *error __
|
|||
return;
|
||||
}
|
||||
if (!ret) return;
|
||||
|
||||
|
||||
#undef GET_BOOL
|
||||
#undef GET_STR
|
||||
#define GET_BOOL(val, s) ac->val = e_hal_property_bool_get(ret, s, &err)
|
||||
#define GET_STR(val, s) \
|
||||
if (ac->val) eina_stringshare_del(ac->val); \
|
||||
ac->val = NULL; \
|
||||
str = e_hal_property_string_get(ret, s, &err); \
|
||||
if (str) \
|
||||
{ \
|
||||
ac->val = eina_stringshare_ref(str); \
|
||||
}
|
||||
|
||||
#define GET_STR(val, s) \
|
||||
if (ac->val) eina_stringshare_del(ac->val); \
|
||||
ac->val = NULL; \
|
||||
str = e_hal_property_string_get(ret, s, &err); \
|
||||
if (str) \
|
||||
{ \
|
||||
ac->val = eina_stringshare_ref(str); \
|
||||
}
|
||||
|
||||
GET_BOOL(present, "ac_adapter.present");
|
||||
GET_STR(product, "info.product");
|
||||
_battery_device_update();
|
||||
|
@ -209,13 +208,13 @@ _battery_dbus_battery_add(const char *udi)
|
|||
bat->udi = eina_stringshare_add(udi);
|
||||
device_batteries = eina_list_append(device_batteries, bat);
|
||||
bat->prop_change =
|
||||
e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER, udi,
|
||||
E_HAL_DEVICE_INTERFACE, "PropertyModified",
|
||||
_battery_dbus_battery_property_changed,
|
||||
bat);
|
||||
e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER, udi,
|
||||
E_HAL_DEVICE_INTERFACE, "PropertyModified",
|
||||
_battery_dbus_battery_property_changed,
|
||||
bat);
|
||||
}
|
||||
// FIXME: e_dbus doesn't allow us to track this pending call
|
||||
e_hal_device_get_all_properties(e_dbus_conn, udi,
|
||||
e_hal_device_get_all_properties(e_dbus_conn, udi,
|
||||
_battery_dbus_battery_props, bat);
|
||||
|
||||
_battery_device_update();
|
||||
|
@ -225,12 +224,12 @@ static void
|
|||
_battery_dbus_battery_del(const char *udi)
|
||||
{
|
||||
Battery *bat;
|
||||
|
||||
|
||||
bat = _battery_battery_find(udi);
|
||||
if (bat)
|
||||
{
|
||||
e_dbus_signal_handler_del(e_dbus_conn, bat->prop_change);
|
||||
device_batteries = eina_list_remove(device_batteries, bat);
|
||||
device_batteries = eina_list_remove(device_batteries, bat);
|
||||
eina_stringshare_del(bat->udi);
|
||||
eina_stringshare_del(bat->technology);
|
||||
eina_stringshare_del(bat->type);
|
||||
|
@ -255,10 +254,10 @@ _battery_dbus_ac_adapter_add(const char *udi)
|
|||
ac->prop_change =
|
||||
e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER, udi,
|
||||
E_HAL_DEVICE_INTERFACE, "PropertyModified",
|
||||
_battery_dbus_ac_adapter_property_changed,
|
||||
_battery_dbus_ac_adapter_property_changed,
|
||||
ac);
|
||||
// FIXME: e_dbus doesn't allow us to track this pending call
|
||||
e_hal_device_get_all_properties(e_dbus_conn, udi,
|
||||
e_hal_device_get_all_properties(e_dbus_conn, udi,
|
||||
_battery_dbus_ac_adapter_props, ac);
|
||||
_battery_device_update();
|
||||
}
|
||||
|
@ -267,12 +266,12 @@ static void
|
|||
_battery_dbus_ac_adapter_del(const char *udi)
|
||||
{
|
||||
Ac_Adapter *ac;
|
||||
|
||||
|
||||
ac = _battery_ac_adapter_find(udi);
|
||||
if (ac)
|
||||
{
|
||||
e_dbus_signal_handler_del(e_dbus_conn, ac->prop_change);
|
||||
device_ac_adapters = eina_list_remove(device_ac_adapters, ac);
|
||||
device_ac_adapters = eina_list_remove(device_ac_adapters, ac);
|
||||
eina_stringshare_del(ac->udi);
|
||||
eina_stringshare_del(ac->product);
|
||||
free(ac);
|
||||
|
@ -308,7 +307,6 @@ _battery_dbus_find_ac(void *user_data __UNUSED__, void *reply_data, DBusError *e
|
|||
char *device;
|
||||
E_Hal_Manager_Find_Device_By_Capability_Return *ret;
|
||||
|
||||
|
||||
ret = reply_data;
|
||||
if (dbus_error_is_set(err))
|
||||
{
|
||||
|
@ -320,7 +318,6 @@ _battery_dbus_find_ac(void *user_data __UNUSED__, void *reply_data, DBusError *e
|
|||
if (eina_list_count(ret->strings) < 1) return;
|
||||
EINA_LIST_FOREACH(ret->strings, l, device)
|
||||
_battery_dbus_ac_adapter_add(device);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -329,7 +326,6 @@ _battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err)
|
|||
char *udi = user_data;
|
||||
E_Hal_Device_Query_Capability_Return *ret;
|
||||
|
||||
|
||||
ret = reply_data;
|
||||
if (dbus_error_is_set(err))
|
||||
{
|
||||
|
@ -339,7 +335,7 @@ _battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err)
|
|||
if (!ret) goto error;
|
||||
if (ret->boolean)
|
||||
_battery_dbus_battery_add(udi);
|
||||
error:
|
||||
error:
|
||||
eina_stringshare_del(udi);
|
||||
}
|
||||
|
||||
|
@ -349,7 +345,6 @@ _battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err)
|
|||
char *udi = user_data;
|
||||
E_Hal_Device_Query_Capability_Return *ret;
|
||||
|
||||
|
||||
ret = reply_data;
|
||||
if (dbus_error_is_set(err))
|
||||
{
|
||||
|
@ -360,7 +355,7 @@ _battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err)
|
|||
|
||||
if (ret->boolean)
|
||||
_battery_dbus_ac_adapter_add(udi);
|
||||
error:
|
||||
error:
|
||||
eina_stringshare_del(udi);
|
||||
}
|
||||
|
||||
|
@ -369,15 +364,15 @@ _battery_dbus_dev_add(void *data __UNUSED__, DBusMessage *msg)
|
|||
{
|
||||
DBusError err;
|
||||
char *udi = NULL;
|
||||
|
||||
|
||||
dbus_error_init(&err);
|
||||
dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
|
||||
if (!udi) return;
|
||||
// FIXME: e_dbus doesn't allow us to track this pending call
|
||||
e_hal_device_query_capability(e_dbus_conn, udi, "battery",
|
||||
_battery_dbus_is_battery, (void*)eina_stringshare_add(udi));
|
||||
_battery_dbus_is_battery, (void *)eina_stringshare_add(udi));
|
||||
e_hal_device_query_capability(e_dbus_conn, udi, "ac_adapter",
|
||||
_battery_dbus_is_ac_adapter, (void*)eina_stringshare_add(udi));
|
||||
_battery_dbus_is_ac_adapter, (void *)eina_stringshare_add(udi));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -385,10 +380,11 @@ _battery_dbus_dev_del(void *data __UNUSED__, DBusMessage *msg)
|
|||
{
|
||||
DBusError err;
|
||||
char *udi = NULL;
|
||||
|
||||
|
||||
dbus_error_init(&err);
|
||||
dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
|
||||
if (!udi) return;
|
||||
_battery_dbus_battery_del(udi);
|
||||
_battery_dbus_ac_adapter_del(udi);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
/* gadcon requirements */
|
||||
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
|
||||
static void _gc_shutdown(E_Gadcon_Client *gcc);
|
||||
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
|
||||
static const char *_gc_label(const E_Gadcon_Client_Class *client_class);
|
||||
static Evas_Object *_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas);
|
||||
static const char *_gc_id_new(const E_Gadcon_Client_Class *client_class);
|
||||
static void _gc_shutdown(E_Gadcon_Client *gcc);
|
||||
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
|
||||
static const char *_gc_label(const E_Gadcon_Client_Class *client_class);
|
||||
static Evas_Object *_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas);
|
||||
static const char *_gc_id_new(const E_Gadcon_Client_Class *client_class);
|
||||
|
||||
Eina_List *device_batteries;
|
||||
Eina_List *device_ac_adapters;
|
||||
|
@ -20,10 +20,10 @@ double init_time;
|
|||
static const E_Gadcon_Client_Class _gadcon_class =
|
||||
{
|
||||
GADCON_CLIENT_CLASS_VERSION,
|
||||
"battery",
|
||||
{
|
||||
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
|
||||
},
|
||||
"battery",
|
||||
{
|
||||
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
|
||||
},
|
||||
E_GADCON_CLIENT_STYLE_PLAIN
|
||||
};
|
||||
|
||||
|
@ -38,19 +38,19 @@ struct _Instance
|
|||
E_Gadcon_Popup *warning;
|
||||
};
|
||||
|
||||
static void _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery, Eina_Bool have_power);
|
||||
static void _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery, Eina_Bool have_power);
|
||||
static Eina_Bool _battery_cb_exe_data(void *data, int type, void *event);
|
||||
static Eina_Bool _battery_cb_exe_del(void *data, int type, void *event);
|
||||
static void _button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static void _menu_cb_post(void *data, E_Menu *m);
|
||||
static void _battery_face_level_set(Evas_Object *battery, double level);
|
||||
static void _battery_face_time_set(Evas_Object *battery, int time);
|
||||
static void _battery_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi);
|
||||
static void _button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static void _menu_cb_post(void *data, E_Menu *m);
|
||||
static void _battery_face_level_set(Evas_Object *battery, double level);
|
||||
static void _battery_face_time_set(Evas_Object *battery, int time);
|
||||
static void _battery_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi);
|
||||
|
||||
static Eina_Bool _battery_cb_warning_popup_timeout(void *data);
|
||||
static void _battery_cb_warning_popup_hide(void *data, Evas *e, Evas_Object *obj, void *event);
|
||||
static void _battery_warning_popup_destroy(Instance *inst);
|
||||
static void _battery_warning_popup(Instance *inst, int time, double percent);
|
||||
static Eina_Bool _battery_cb_warning_popup_timeout(void *data);
|
||||
static void _battery_cb_warning_popup_hide(void *data, Evas *e, Evas_Object *obj, void *event);
|
||||
static void _battery_warning_popup_destroy(Instance *inst);
|
||||
static void _battery_warning_popup(Instance *inst, int time, double percent);
|
||||
|
||||
static Eina_Bool _powersave_cb_config_update(void *data, int type, void *event);
|
||||
|
||||
|
@ -76,13 +76,13 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
|
|||
|
||||
o = edje_object_add(gc->evas);
|
||||
e_theme_edje_object_set(o, "base/theme/modules/battery",
|
||||
"e/modules/battery/main");
|
||||
"e/modules/battery/main");
|
||||
|
||||
gcc = e_gadcon_client_new(gc, name, id, style, o);
|
||||
gcc->data = inst;
|
||||
|
||||
inst->gcc = gcc;
|
||||
inst->o_battery = o;
|
||||
inst->o_battery = o;
|
||||
inst->warning = NULL;
|
||||
inst->popup_battery = NULL;
|
||||
|
||||
|
@ -94,8 +94,8 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
|
|||
#endif
|
||||
|
||||
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
|
||||
_button_cb_mouse_down, inst);
|
||||
battery_config->instances =
|
||||
_button_cb_mouse_down, inst);
|
||||
battery_config->instances =
|
||||
eina_list_append(battery_config->instances, inst);
|
||||
_battery_config_updated();
|
||||
|
||||
|
@ -115,7 +115,7 @@ _gc_shutdown(E_Gadcon_Client *gcc)
|
|||
#endif
|
||||
|
||||
inst = gcc->data;
|
||||
battery_config->instances =
|
||||
battery_config->instances =
|
||||
eina_list_remove(battery_config->instances, inst);
|
||||
evas_object_del(inst->o_battery);
|
||||
if (inst->warning)
|
||||
|
@ -137,7 +137,7 @@ _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__)
|
|||
edje_object_size_min_get(inst->o_battery, &mw, &mh);
|
||||
edje_object_size_max_get(inst->o_battery, &mxw, &mxh);
|
||||
if ((mw < 1) || (mh < 1))
|
||||
edje_object_size_min_calc(inst->o_battery, &mw, &mh);
|
||||
edje_object_size_min_calc(inst->o_battery, &mw, &mh);
|
||||
if (mw < 4) mw = 4;
|
||||
if (mh < 4) mh = 4;
|
||||
if ((mxw > 0) && (mxh > 0))
|
||||
|
@ -159,7 +159,7 @@ _gc_icon(const E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
|
|||
|
||||
o = edje_object_add(evas);
|
||||
snprintf(buf, sizeof(buf), "%s/e-module-battery.edj",
|
||||
e_module_dir_get(battery_config->module));
|
||||
e_module_dir_get(battery_config->module));
|
||||
edje_object_file_set(o, buf, "icon");
|
||||
return o;
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ _gc_id_new(const E_Gadcon_Client_Class *client_class)
|
|||
{
|
||||
static char buf[PATH_MAX];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s.%d", client_class->name,
|
||||
snprintf(buf, sizeof(buf), "%s.%d", client_class->name,
|
||||
eina_list_count(battery_config->instances) + 1);
|
||||
return buf;
|
||||
}
|
||||
|
@ -184,26 +184,26 @@ _button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
|||
ev = event_info;
|
||||
if ((ev->button == 3) && (!battery_config->menu))
|
||||
{
|
||||
E_Menu *m;
|
||||
E_Menu_Item *mi;
|
||||
int cx, cy;
|
||||
E_Menu *m;
|
||||
E_Menu_Item *mi;
|
||||
int cx, cy;
|
||||
|
||||
m = e_menu_new();
|
||||
mi = e_menu_item_new(m);
|
||||
e_menu_item_label_set(mi, _("Settings"));
|
||||
e_util_menu_item_theme_icon_set(mi, "configure");
|
||||
e_menu_item_callback_set(mi, _battery_face_cb_menu_configure, NULL);
|
||||
m = e_menu_new();
|
||||
mi = e_menu_item_new(m);
|
||||
e_menu_item_label_set(mi, _("Settings"));
|
||||
e_util_menu_item_theme_icon_set(mi, "configure");
|
||||
e_menu_item_callback_set(mi, _battery_face_cb_menu_configure, NULL);
|
||||
|
||||
m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
|
||||
e_menu_post_deactivate_callback_set(m, _menu_cb_post, inst);
|
||||
battery_config->menu = m;
|
||||
m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
|
||||
e_menu_post_deactivate_callback_set(m, _menu_cb_post, inst);
|
||||
battery_config->menu = m;
|
||||
|
||||
e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon,
|
||||
&cx, &cy, NULL, NULL);
|
||||
e_menu_activate_mouse(m,
|
||||
e_util_zone_current_get(e_manager_current_get()),
|
||||
cx + ev->output.x, cy + ev->output.y, 1, 1,
|
||||
E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
|
||||
e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon,
|
||||
&cx, &cy, NULL, NULL);
|
||||
e_menu_activate_mouse(m,
|
||||
e_util_zone_current_get(e_manager_current_get()),
|
||||
cx + ev->output.x, cy + ev->output.y, 1, 1,
|
||||
E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
|
||||
}
|
||||
if (ev->button == 1)
|
||||
_battery_cb_warning_popup_hide(data, e, obj, event_info);
|
||||
|
@ -223,16 +223,17 @@ _battery_face_level_set(Evas_Object *battery, double level)
|
|||
Edje_Message_Float msg;
|
||||
char buf[256];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%i%%", (int)(level*100.0));
|
||||
snprintf(buf, sizeof(buf), "%i%%", (int)(level * 100.0));
|
||||
edje_object_part_text_set(battery, "e.text.reading", buf);
|
||||
|
||||
if (level < 0.0) level = 0.0;
|
||||
else if (level > 1.0) level = 1.0;
|
||||
else if (level > 1.0)
|
||||
level = 1.0;
|
||||
msg.val = level;
|
||||
edje_object_message_send(battery, EDJE_MESSAGE_FLOAT, 1, &msg);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_face_time_set(Evas_Object *battery, int t)
|
||||
{
|
||||
char buf[256];
|
||||
|
@ -256,18 +257,17 @@ _battery_face_cb_menu_configure(void *data __UNUSED__, E_Menu *m, E_Menu_Item *m
|
|||
e_int_config_battery_module(m->zone->container, NULL);
|
||||
}
|
||||
|
||||
|
||||
Battery *
|
||||
_battery_battery_find(const char *udi)
|
||||
{
|
||||
Eina_List *l;
|
||||
Battery *bat;
|
||||
EINA_LIST_FOREACH(device_batteries, l, bat)
|
||||
{/* these are always stringshared */
|
||||
if (udi == bat->udi) return bat;
|
||||
{ /* these are always stringshared */
|
||||
if (udi == bat->udi) return bat;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Ac_Adapter *
|
||||
|
@ -276,11 +276,11 @@ _battery_ac_adapter_find(const char *udi)
|
|||
Eina_List *l;
|
||||
Ac_Adapter *ac;
|
||||
EINA_LIST_FOREACH(device_ac_adapters, l, ac)
|
||||
{/* these are always stringshared */
|
||||
if (udi == ac->udi) return ac;
|
||||
{ /* these are always stringshared */
|
||||
if (udi == ac->udi) return ac;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -298,9 +298,9 @@ _battery_device_update(void)
|
|||
|
||||
int batnum = 0;
|
||||
int acnum = 0;
|
||||
|
||||
|
||||
EINA_LIST_FOREACH(device_ac_adapters, l, ac)
|
||||
if (ac->present) acnum++;
|
||||
if (ac->present) acnum++;
|
||||
|
||||
EINA_LIST_FOREACH(device_batteries, l, bat)
|
||||
{
|
||||
|
@ -330,7 +330,7 @@ _battery_device_update(void)
|
|||
}
|
||||
|
||||
if ((device_batteries) && (batnum == 0))
|
||||
return; /* not ready yet, no properties received for any battery */
|
||||
return; /* not ready yet, no properties received for any battery */
|
||||
|
||||
if (batnum > 0) full /= batnum;
|
||||
if ((full == 100) && have_power)
|
||||
|
@ -340,11 +340,10 @@ _battery_device_update(void)
|
|||
}
|
||||
if (time_left < 1) time_left = -1;
|
||||
if (time_full < 1) time_full = -1;
|
||||
|
||||
|
||||
_battery_update(full, time_left, time_full, have_battery, have_power);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_battery_config_updated(void)
|
||||
{
|
||||
|
@ -373,7 +372,7 @@ _battery_config_updated(void)
|
|||
#ifdef HAVE_EEZE
|
||||
ok = _battery_udev_start();
|
||||
#elif defined __OpenBSD__
|
||||
ok = _battery_openbsd_start();
|
||||
ok = _battery_openbsd_start();
|
||||
#else
|
||||
ok = _battery_dbus_start();
|
||||
#endif
|
||||
|
@ -386,8 +385,8 @@ _battery_config_updated(void)
|
|||
snprintf(buf, sizeof(buf), "%s/%s/batget %i",
|
||||
e_module_dir_get(battery_config->module), MODULE_ARCH,
|
||||
battery_config->poll_interval);
|
||||
|
||||
battery_config->batget_exe =
|
||||
|
||||
battery_config->batget_exe =
|
||||
ecore_exe_pipe_run(buf, ECORE_EXE_PIPE_READ |
|
||||
ECORE_EXE_PIPE_READ_LINE_BUFFERED |
|
||||
ECORE_EXE_NOT_LEADER, NULL);
|
||||
|
@ -434,7 +433,7 @@ _battery_warning_popup(Instance *inst, int t, double percent)
|
|||
{
|
||||
Evas *e = NULL;
|
||||
Evas_Object *rect = NULL, *popup_bg = NULL;
|
||||
int x,y,w,h;
|
||||
int x, y, w, h;
|
||||
#ifdef HAVE_ENOTIFY
|
||||
static E_Notification *notification;
|
||||
#endif
|
||||
|
@ -447,12 +446,12 @@ _battery_warning_popup(Instance *inst, int t, double percent)
|
|||
if (notification) return;
|
||||
notification = e_notification_full_new
|
||||
(
|
||||
_("Battery"),
|
||||
0,
|
||||
"battery-low",
|
||||
_("Your battery is low!"),
|
||||
_("AC power is recommended."),
|
||||
(battery_config->alert_timeout * 1000)
|
||||
_("Battery"),
|
||||
0,
|
||||
"battery-low",
|
||||
_("Your battery is low!"),
|
||||
_("AC power is recommended."),
|
||||
(battery_config->alert_timeout * 1000)
|
||||
);
|
||||
e_notification_send(notification, NULL, NULL);
|
||||
e_notification_unref(notification);
|
||||
|
@ -467,7 +466,7 @@ _battery_warning_popup(Instance *inst, int t, double percent)
|
|||
|
||||
popup_bg = edje_object_add(e);
|
||||
inst->popup_battery = edje_object_add(e);
|
||||
|
||||
|
||||
if ((!popup_bg) || (!inst->popup_battery))
|
||||
{
|
||||
e_object_free(E_OBJECT(inst->warning));
|
||||
|
@ -476,15 +475,15 @@ _battery_warning_popup(Instance *inst, int t, double percent)
|
|||
}
|
||||
|
||||
e_theme_edje_object_set(popup_bg, "base/theme/modules/battery/popup",
|
||||
"e/modules/battery/popup");
|
||||
"e/modules/battery/popup");
|
||||
e_theme_edje_object_set(inst->popup_battery, "base/theme/modules/battery",
|
||||
"e/modules/battery/main");
|
||||
"e/modules/battery/main");
|
||||
edje_object_part_swallow(popup_bg, "battery", inst->popup_battery);
|
||||
|
||||
edje_object_part_text_set(popup_bg, "e.text.title",
|
||||
_("Your battery is low!"));
|
||||
_("Your battery is low!"));
|
||||
edje_object_part_text_set(popup_bg, "e.text.label",
|
||||
_("AC power is recommended."));
|
||||
_("AC power is recommended."));
|
||||
|
||||
e_gadcon_popup_content_set(inst->warning, popup_bg);
|
||||
e_gadcon_popup_show(inst->warning);
|
||||
|
@ -497,7 +496,7 @@ _battery_warning_popup(Instance *inst, int t, double percent)
|
|||
evas_object_move(rect, x, y);
|
||||
evas_object_resize(rect, w, h);
|
||||
evas_object_color_set(rect, 255, 255, 255, 0);
|
||||
evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN ,
|
||||
evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN,
|
||||
_battery_cb_warning_popup_hide, inst);
|
||||
evas_object_repeat_events_set(rect, 1);
|
||||
evas_object_show(rect);
|
||||
|
@ -511,7 +510,7 @@ _battery_warning_popup(Instance *inst, int t, double percent)
|
|||
(!battery_config->alert_timer))
|
||||
{
|
||||
battery_config->alert_timer =
|
||||
ecore_timer_add(battery_config->alert_timeout,
|
||||
ecore_timer_add(battery_config->alert_timeout,
|
||||
_battery_cb_warning_popup_timeout, inst);
|
||||
}
|
||||
}
|
||||
|
@ -541,22 +540,22 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
|
|||
Eina_List *l;
|
||||
Instance *inst;
|
||||
static double debounce_time = 0.0;
|
||||
|
||||
|
||||
EINA_LIST_FOREACH(battery_config->instances, l, inst)
|
||||
{
|
||||
if (have_power != battery_config->have_power)
|
||||
{
|
||||
if (have_power && (full < 100))
|
||||
edje_object_signal_emit(inst->o_battery,
|
||||
"e,state,charging",
|
||||
edje_object_signal_emit(inst->o_battery,
|
||||
"e,state,charging",
|
||||
"e");
|
||||
else
|
||||
{
|
||||
edje_object_signal_emit(inst->o_battery,
|
||||
"e,state,discharging",
|
||||
edje_object_signal_emit(inst->o_battery,
|
||||
"e,state,discharging",
|
||||
"e");
|
||||
if (inst->popup_battery)
|
||||
edje_object_signal_emit(inst->popup_battery,
|
||||
edje_object_signal_emit(inst->popup_battery,
|
||||
"e,state,discharging", "e");
|
||||
}
|
||||
}
|
||||
|
@ -565,7 +564,7 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
|
|||
if (battery_config->full != full)
|
||||
{
|
||||
double val;
|
||||
|
||||
|
||||
if (full >= 100) val = 1.0;
|
||||
else val = (double)full / 100.0;
|
||||
_battery_face_level_set(inst->o_battery, val);
|
||||
|
@ -576,43 +575,43 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
|
|||
else
|
||||
{
|
||||
_battery_face_level_set(inst->o_battery, 0.0);
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.reading",
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.reading",
|
||||
_("N/A"));
|
||||
}
|
||||
|
||||
|
||||
if ((time_full < 0) && (time_left != battery_config->time_left))
|
||||
{
|
||||
_battery_face_time_set(inst->o_battery, time_left);
|
||||
if (inst->popup_battery)
|
||||
_battery_face_time_set(inst->popup_battery,
|
||||
_battery_face_time_set(inst->popup_battery,
|
||||
time_left);
|
||||
}
|
||||
else if ((time_left < 0) && (time_full != battery_config->time_full))
|
||||
{
|
||||
_battery_face_time_set(inst->o_battery, time_full);
|
||||
if (inst->popup_battery)
|
||||
_battery_face_time_set(inst->popup_battery,
|
||||
_battery_face_time_set(inst->popup_battery,
|
||||
time_full);
|
||||
}
|
||||
if (have_battery &&
|
||||
(!have_power) &&
|
||||
if (have_battery &&
|
||||
(!have_power) &&
|
||||
(full < 100) &&
|
||||
(
|
||||
(
|
||||
(time_left > 0) &&
|
||||
battery_config->alert &&
|
||||
((time_left / 60) <= battery_config->alert)
|
||||
) ||
|
||||
(
|
||||
battery_config->alert_p &&
|
||||
(full <= battery_config->alert_p)
|
||||
)
|
||||
(
|
||||
(time_left > 0) &&
|
||||
battery_config->alert &&
|
||||
((time_left / 60) <= battery_config->alert)
|
||||
) ||
|
||||
(
|
||||
battery_config->alert_p &&
|
||||
(full <= battery_config->alert_p)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
double t;
|
||||
|
||||
|
||||
printf("-------------------------------------- bat warn .. why below\n");
|
||||
printf("have_battery = %i\n", (int)have_battery);
|
||||
printf("have_power = %i\n", (int)have_power);
|
||||
|
@ -634,14 +633,14 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
|
|||
if ((have_battery) && (!have_power) && (full >= 0) &&
|
||||
(battery_config->suspend_below > 0) &&
|
||||
(full < battery_config->suspend_below))
|
||||
{
|
||||
if (battery_config->suspend_method == SUSPEND)
|
||||
{
|
||||
if (battery_config->suspend_method == SUSPEND)
|
||||
e_sys_action_do(E_SYS_SUSPEND, NULL);
|
||||
else if (battery_config->suspend_method == HIBERNATE)
|
||||
e_sys_action_do(E_SYS_HIBERNATE, NULL);
|
||||
else if (battery_config->suspend_method == SHUTDOWN)
|
||||
e_sys_action_do(E_SYS_HALT, NULL);
|
||||
}
|
||||
else if (battery_config->suspend_method == HIBERNATE)
|
||||
e_sys_action_do(E_SYS_HIBERNATE, NULL);
|
||||
else if (battery_config->suspend_method == SHUTDOWN)
|
||||
e_sys_action_do(E_SYS_HALT, NULL);
|
||||
}
|
||||
}
|
||||
if (!have_battery)
|
||||
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
|
||||
|
@ -674,39 +673,37 @@ _battery_cb_exe_data(void *data __UNUSED__, int type __UNUSED__, void *event)
|
|||
if (ev->exe != battery_config->batget_exe) return ECORE_CALLBACK_PASS_ON;
|
||||
if ((ev->lines) && (ev->lines[0].line))
|
||||
{
|
||||
|
||||
|
||||
for (i = 0; ev->lines[i].line; i++)
|
||||
{
|
||||
if (!strcmp(ev->lines[i].line, "ERROR"))
|
||||
EINA_LIST_FOREACH(battery_config->instances, l, inst)
|
||||
{
|
||||
edje_object_signal_emit(inst->o_battery,
|
||||
"e,state,unknown", "e");
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.reading", _("ERROR"));
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.time", _("ERROR"));
|
||||
EINA_LIST_FOREACH(battery_config->instances, l, inst)
|
||||
{
|
||||
edje_object_signal_emit(inst->o_battery,
|
||||
"e,state,unknown", "e");
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.reading", _("ERROR"));
|
||||
edje_object_part_text_set(inst->o_battery,
|
||||
"e.text.time", _("ERROR"));
|
||||
|
||||
if (inst->popup_battery)
|
||||
{
|
||||
edje_object_signal_emit(inst->popup_battery,
|
||||
"e,state,unknown", "e");
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.reading", _("ERROR"));
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.time", _("ERROR"));
|
||||
}
|
||||
}
|
||||
if (inst->popup_battery)
|
||||
{
|
||||
edje_object_signal_emit(inst->popup_battery,
|
||||
"e,state,unknown", "e");
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.reading", _("ERROR"));
|
||||
edje_object_part_text_set(inst->popup_battery,
|
||||
"e.text.time", _("ERROR"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int full = 0;
|
||||
int time_left = 0;
|
||||
int time_full = 0;
|
||||
int time_full = 0;
|
||||
int have_battery = 0;
|
||||
int have_power = 0;
|
||||
|
||||
if (sscanf(ev->lines[i].line, "%i %i %i %i %i", &full, &time_left, &time_full,
|
||||
|
||||
if (sscanf(ev->lines[i].line, "%i %i %i %i %i", &full, &time_left, &time_full,
|
||||
&have_battery, &have_power) == 5)
|
||||
_battery_update(full, time_left, time_full,
|
||||
have_battery, have_power);
|
||||
|
@ -730,7 +727,7 @@ _battery_cb_exe_del(void *data __UNUSED__, int type __UNUSED__, void *event)
|
|||
}
|
||||
|
||||
/* module setup */
|
||||
EAPI E_Module_Api e_modapi =
|
||||
EAPI E_Module_Api e_modapi =
|
||||
{
|
||||
E_MODULE_API_VERSION, "Battery"
|
||||
};
|
||||
|
@ -765,18 +762,18 @@ e_modapi_init(E_Module *m)
|
|||
battery_config = e_config_domain_load("module.battery", conf_edd);
|
||||
if (!battery_config)
|
||||
{
|
||||
battery_config = E_NEW(Config, 1);
|
||||
battery_config->poll_interval = 512;
|
||||
battery_config->alert = 30;
|
||||
battery_config->alert_p = 10;
|
||||
battery_config->alert_timeout = 0;
|
||||
battery_config->suspend_below = 0;
|
||||
battery_config->force_mode = 0;
|
||||
battery_config = E_NEW(Config, 1);
|
||||
battery_config->poll_interval = 512;
|
||||
battery_config->alert = 30;
|
||||
battery_config->alert_p = 10;
|
||||
battery_config->alert_timeout = 0;
|
||||
battery_config->suspend_below = 0;
|
||||
battery_config->force_mode = 0;
|
||||
#if defined HAVE_EEZE || defined __OpenBSD__
|
||||
battery_config->fuzzy = 0;
|
||||
battery_config->fuzzy = 0;
|
||||
#endif
|
||||
#ifdef HAVE_ENOTIFY
|
||||
battery_config->desktop_notifications = 0;
|
||||
battery_config->desktop_notifications = 0;
|
||||
#endif
|
||||
}
|
||||
E_CONFIG_LIMIT(battery_config->poll_interval, 4, 4096);
|
||||
|
@ -798,19 +795,19 @@ e_modapi_init(E_Module *m)
|
|||
|
||||
battery_config->batget_data_handler =
|
||||
ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
|
||||
_battery_cb_exe_data, NULL);
|
||||
_battery_cb_exe_data, NULL);
|
||||
battery_config->batget_del_handler =
|
||||
ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
|
||||
_battery_cb_exe_del, NULL);
|
||||
_battery_cb_exe_del, NULL);
|
||||
_handler = ecore_event_handler_add(E_EVENT_POWERSAVE_CONFIG_UPDATE,
|
||||
_powersave_cb_config_update, NULL);
|
||||
|
||||
e_gadcon_provider_register(&_gadcon_class);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/e-module-battery.edj", e_module_dir_get(m));
|
||||
e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL,
|
||||
e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL,
|
||||
"preferences-advanced");
|
||||
e_configure_registry_item_add("advanced/battery", 100, _("Battery Meter"),
|
||||
e_configure_registry_item_add("advanced/battery", 100, _("Battery Meter"),
|
||||
NULL, buf, e_int_config_battery_module);
|
||||
|
||||
return m;
|
||||
|
@ -825,23 +822,23 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
|
|||
|
||||
if (battery_config->alert_timer)
|
||||
ecore_timer_del(battery_config->alert_timer);
|
||||
|
||||
|
||||
if (battery_config->batget_exe)
|
||||
{
|
||||
ecore_exe_terminate(battery_config->batget_exe);
|
||||
ecore_exe_free(battery_config->batget_exe);
|
||||
battery_config->batget_exe = NULL;
|
||||
ecore_exe_terminate(battery_config->batget_exe);
|
||||
ecore_exe_free(battery_config->batget_exe);
|
||||
battery_config->batget_exe = NULL;
|
||||
}
|
||||
|
||||
if (battery_config->batget_data_handler)
|
||||
{
|
||||
ecore_event_handler_del(battery_config->batget_data_handler);
|
||||
battery_config->batget_data_handler = NULL;
|
||||
ecore_event_handler_del(battery_config->batget_data_handler);
|
||||
battery_config->batget_data_handler = NULL;
|
||||
}
|
||||
if (battery_config->batget_del_handler)
|
||||
{
|
||||
ecore_event_handler_del(battery_config->batget_del_handler);
|
||||
battery_config->batget_del_handler = NULL;
|
||||
ecore_event_handler_del(battery_config->batget_del_handler);
|
||||
battery_config->batget_del_handler = NULL;
|
||||
}
|
||||
|
||||
if (battery_config->config_dialog)
|
||||
|
@ -849,10 +846,10 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
|
|||
if (battery_config->menu)
|
||||
{
|
||||
e_menu_post_deactivate_callback_set(battery_config->menu, NULL, NULL);
|
||||
e_object_del(E_OBJECT(battery_config->menu));
|
||||
battery_config->menu = NULL;
|
||||
e_object_del(E_OBJECT(battery_config->menu));
|
||||
battery_config->menu = NULL;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_EEZE
|
||||
_battery_udev_stop();
|
||||
#elif defined __OpenBSD__
|
||||
|
@ -860,7 +857,6 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
|
|||
#else
|
||||
_battery_dbus_stop();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_ENOTIFY
|
||||
e_notification_shutdown();
|
||||
|
@ -878,3 +874,4 @@ e_modapi_save(E_Module *m __UNUSED__)
|
|||
e_config_domain_save("module.battery", conf_edd, battery_config);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "e_mod_main.h"
|
||||
|
||||
static Eina_Bool _battery_openbsd_battery_update_poll(void *data);
|
||||
static void _battery_openbsd_battery_update();
|
||||
static void _battery_openbsd_battery_update();
|
||||
|
||||
extern Eina_List *device_batteries;
|
||||
extern Eina_List *device_ac_adapters;
|
||||
|
@ -18,54 +18,57 @@ extern double init_time;
|
|||
Ac_Adapter *ac;
|
||||
Battery *bat;
|
||||
|
||||
int
|
||||
int
|
||||
_battery_openbsd_start(void)
|
||||
{
|
||||
Eina_List *devices;
|
||||
int mib[] = {CTL_HW, HW_SENSORS, 0, 0 ,0};
|
||||
int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
||||
int devn;
|
||||
struct sensordev snsrdev;
|
||||
size_t sdlen = sizeof(struct sensordev);
|
||||
struct sensor s;
|
||||
size_t slen = sizeof(struct sensor);
|
||||
|
||||
for (devn = 0 ; ; devn++) {
|
||||
mib[2] = devn;
|
||||
if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) {
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
if (errno == ENOENT)
|
||||
break;
|
||||
}
|
||||
for (devn = 0;; devn++) {
|
||||
mib[2] = devn;
|
||||
if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1)
|
||||
{
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
if (errno == ENOENT)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp("acpibat0", snsrdev.xname)) {
|
||||
if (!(bat = E_NEW(Battery, 1)))
|
||||
return 0;
|
||||
bat->udi = eina_stringshare_add("acpibat0"),
|
||||
bat->mib = malloc(sizeof(int) * 5);
|
||||
bat->mib[0] = mib[0];
|
||||
bat->mib[1] = mib[1];
|
||||
bat->mib[2] = mib[2];
|
||||
bat->technology = eina_stringshare_add("Unknow");
|
||||
bat->model = eina_stringshare_add("Unknow");
|
||||
bat->vendor = eina_stringshare_add("Unknow");
|
||||
bat->last_update = ecore_time_get();
|
||||
bat->poll = ecore_poller_add(ECORE_POLLER_CORE,
|
||||
battery_config->poll_interval,
|
||||
_battery_openbsd_battery_update_poll, NULL);
|
||||
device_batteries = eina_list_append(device_batteries, bat);
|
||||
}
|
||||
else if (!strcmp("acpiac0", snsrdev.xname)) {
|
||||
if (!(ac = E_NEW(Ac_Adapter, 1)))
|
||||
return 0;
|
||||
ac->udi = eina_stringshare_add("acpiac0");
|
||||
ac->mib = malloc(sizeof(int) * 5);
|
||||
ac->mib[0] = mib[0];
|
||||
ac->mib[1] = mib[1];
|
||||
ac->mib[2] = mib[2];
|
||||
device_ac_adapters = eina_list_append(device_ac_adapters, ac);
|
||||
}
|
||||
}
|
||||
if (!strcmp("acpibat0", snsrdev.xname))
|
||||
{
|
||||
if (!(bat = E_NEW(Battery, 1)))
|
||||
return 0;
|
||||
bat->udi = eina_stringshare_add("acpibat0"),
|
||||
bat->mib = malloc(sizeof(int) * 5);
|
||||
bat->mib[0] = mib[0];
|
||||
bat->mib[1] = mib[1];
|
||||
bat->mib[2] = mib[2];
|
||||
bat->technology = eina_stringshare_add("Unknow");
|
||||
bat->model = eina_stringshare_add("Unknow");
|
||||
bat->vendor = eina_stringshare_add("Unknow");
|
||||
bat->last_update = ecore_time_get();
|
||||
bat->poll = ecore_poller_add(ECORE_POLLER_CORE,
|
||||
battery_config->poll_interval,
|
||||
_battery_openbsd_battery_update_poll, NULL);
|
||||
device_batteries = eina_list_append(device_batteries, bat);
|
||||
}
|
||||
else if (!strcmp("acpiac0", snsrdev.xname))
|
||||
{
|
||||
if (!(ac = E_NEW(Ac_Adapter, 1)))
|
||||
return 0;
|
||||
ac->udi = eina_stringshare_add("acpiac0");
|
||||
ac->mib = malloc(sizeof(int) * 5);
|
||||
ac->mib[0] = mib[0];
|
||||
ac->mib[1] = mib[1];
|
||||
ac->mib[2] = mib[2];
|
||||
device_ac_adapters = eina_list_append(device_ac_adapters, ac);
|
||||
}
|
||||
}
|
||||
|
||||
_battery_openbsd_battery_update();
|
||||
|
||||
|
@ -73,108 +76,112 @@ _battery_openbsd_start(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
_battery_openbsd_stop(void)
|
||||
{
|
||||
if (ac)
|
||||
free(ac);
|
||||
if (bat) {
|
||||
eina_stringshare_del(bat->udi);
|
||||
eina_stringshare_del(bat->technology);
|
||||
eina_stringshare_del(bat->model);
|
||||
eina_stringshare_del(bat->vendor);
|
||||
ecore_poller_del(bat->poll);
|
||||
free(bat->mib);
|
||||
free(bat);
|
||||
}
|
||||
free(ac);
|
||||
if (bat)
|
||||
{
|
||||
eina_stringshare_del(bat->udi);
|
||||
eina_stringshare_del(bat->technology);
|
||||
eina_stringshare_del(bat->model);
|
||||
eina_stringshare_del(bat->vendor);
|
||||
ecore_poller_del(bat->poll);
|
||||
free(bat->mib);
|
||||
free(bat);
|
||||
}
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
static Eina_Bool
|
||||
_battery_openbsd_battery_update_poll(void *data)
|
||||
{
|
||||
_battery_openbsd_battery_update();
|
||||
return EINA_TRUE;
|
||||
_battery_openbsd_battery_update();
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_openbsd_battery_update()
|
||||
{
|
||||
double time, charge;
|
||||
struct sensor s;
|
||||
size_t slen = sizeof(struct sensor);
|
||||
|
||||
/* update the poller interval */
|
||||
ecore_poller_poller_interval_set(bat->poll,
|
||||
battery_config->poll_interval);
|
||||
double time, charge;
|
||||
struct sensor s;
|
||||
size_t slen = sizeof(struct sensor);
|
||||
|
||||
/* last full capacity */
|
||||
bat->mib[3] = 8;
|
||||
bat->mib[4] = 0;
|
||||
if (sysctl(bat->mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||
bat->last_full_charge = (double)s.value;
|
||||
}
|
||||
|
||||
/* remaining capcity */
|
||||
bat->mib[3] = 8;
|
||||
bat->mib[4] = 3;
|
||||
if (sysctl(bat->mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||
charge = (double)s.value;
|
||||
}
|
||||
/* update the poller interval */
|
||||
ecore_poller_poller_interval_set(bat->poll,
|
||||
battery_config->poll_interval);
|
||||
|
||||
time = ecore_time_get();
|
||||
if ((bat->got_prop) && (charge != bat->current_charge))
|
||||
bat->charge_rate = ((charge - bat->current_charge) / (time - bat->last_update));
|
||||
bat->last_update = time;
|
||||
bat->current_charge = charge;
|
||||
bat->percent = 100 * (bat->current_charge / bat->last_full_charge);
|
||||
if (bat->got_prop)
|
||||
/* last full capacity */
|
||||
bat->mib[3] = 8;
|
||||
bat->mib[4] = 0;
|
||||
if (sysctl(bat->mib, 5, &s, &slen, NULL, 0) != -1)
|
||||
{
|
||||
bat->last_full_charge = (double)s.value;
|
||||
}
|
||||
|
||||
/* remaining capcity */
|
||||
bat->mib[3] = 8;
|
||||
bat->mib[4] = 3;
|
||||
if (sysctl(bat->mib, 5, &s, &slen, NULL, 0) != -1)
|
||||
{
|
||||
charge = (double)s.value;
|
||||
}
|
||||
|
||||
time = ecore_time_get();
|
||||
if ((bat->got_prop) && (charge != bat->current_charge))
|
||||
bat->charge_rate = ((charge - bat->current_charge) / (time - bat->last_update));
|
||||
bat->last_update = time;
|
||||
bat->current_charge = charge;
|
||||
bat->percent = 100 * (bat->current_charge / bat->last_full_charge);
|
||||
if (bat->got_prop)
|
||||
{
|
||||
if (bat->charge_rate > 0)
|
||||
{
|
||||
if (bat->charge_rate > 0)
|
||||
{
|
||||
if (battery_config->fuzzy && (++battery_config->fuzzcount <= 10) && (bat->time_full > 0))
|
||||
bat->time_full = (((bat->last_full_charge - bat->current_charge) / bat->charge_rate) + bat->time_full) / 2;
|
||||
else
|
||||
bat->time_full = (bat->last_full_charge - bat->current_charge) / bat->charge_rate;
|
||||
bat->time_left = -1;
|
||||
}
|
||||
if (battery_config->fuzzy && (++battery_config->fuzzcount <= 10) && (bat->time_full > 0))
|
||||
bat->time_full = (((bat->last_full_charge - bat->current_charge) / bat->charge_rate) + bat->time_full) / 2;
|
||||
else
|
||||
{
|
||||
if (battery_config->fuzzy && (battery_config->fuzzcount <= 10) && (bat->time_left > 0))
|
||||
bat->time_left = (((0 - bat->current_charge) / bat->charge_rate) + bat->time_left) / 2;
|
||||
else
|
||||
bat->time_left = (0 - bat->current_charge) / bat->charge_rate;
|
||||
bat->time_full = -1;
|
||||
}
|
||||
bat->time_full = (bat->last_full_charge - bat->current_charge) / bat->charge_rate;
|
||||
bat->time_left = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (battery_config->fuzzy && (battery_config->fuzzcount <= 10) && (bat->time_left > 0))
|
||||
bat->time_left = (((0 - bat->current_charge) / bat->charge_rate) + bat->time_left) / 2;
|
||||
else
|
||||
bat->time_left = (0 - bat->current_charge) / bat->charge_rate;
|
||||
bat->time_full = -1;
|
||||
bat->time_left = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bat->time_full = -1;
|
||||
bat->time_left = -1;
|
||||
}
|
||||
|
||||
/* battery state 1: discharge, 2: charge */
|
||||
bat->mib[3] = 10;
|
||||
bat->mib[4] = 0;
|
||||
if (sysctl(bat->mib, 5, &s, &slen, NULL, 0) == -1) {
|
||||
if (s.value == 2)
|
||||
bat->charging = 1;
|
||||
else
|
||||
bat->charging = 0;
|
||||
}
|
||||
/* battery state 1: discharge, 2: charge */
|
||||
bat->mib[3] = 10;
|
||||
bat->mib[4] = 0;
|
||||
if (sysctl(bat->mib, 5, &s, &slen, NULL, 0) == -1)
|
||||
{
|
||||
if (s.value == 2)
|
||||
bat->charging = 1;
|
||||
else
|
||||
bat->charging = 0;
|
||||
}
|
||||
|
||||
/* AC State */
|
||||
ac->mib[3] = 9;
|
||||
ac->mib[4] = 0;
|
||||
if (sysctl(ac->mib, 5, &s, &slen, NULL, 0) == -1) {
|
||||
if (s.value)
|
||||
ac->present = 1;
|
||||
else
|
||||
ac->present = 0;
|
||||
}
|
||||
/* AC State */
|
||||
ac->mib[3] = 9;
|
||||
ac->mib[4] = 0;
|
||||
if (sysctl(ac->mib, 5, &s, &slen, NULL, 0) == -1)
|
||||
{
|
||||
if (s.value)
|
||||
ac->present = 1;
|
||||
else
|
||||
ac->present = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (bat->got_prop)
|
||||
_battery_device_update();
|
||||
bat->got_prop = 1;
|
||||
if (bat->got_prop)
|
||||
_battery_device_update();
|
||||
bat->got_prop = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
#include "e.h"
|
||||
#include "e_mod_main.h"
|
||||
|
||||
static void _battery_udev_event_battery(const char *syspath, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch);
|
||||
static void _battery_udev_event_ac(const char *syspath, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch);
|
||||
static void _battery_udev_battery_add(const char *syspath);
|
||||
static void _battery_udev_ac_add(const char *syspath);
|
||||
static void _battery_udev_battery_del(const char *syspath);
|
||||
static void _battery_udev_ac_del(const char *syspath);
|
||||
static void _battery_udev_event_battery(const char *syspath, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch);
|
||||
static void _battery_udev_event_ac(const char *syspath, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch);
|
||||
static void _battery_udev_battery_add(const char *syspath);
|
||||
static void _battery_udev_ac_add(const char *syspath);
|
||||
static void _battery_udev_battery_del(const char *syspath);
|
||||
static void _battery_udev_ac_del(const char *syspath);
|
||||
#if 0
|
||||
static Eina_Bool _battery_udev_battery_update_poll(void *data);
|
||||
#endif
|
||||
static void _battery_udev_battery_update(const char *syspath, Battery *bat);
|
||||
static void _battery_udev_ac_update(const char *syspath, Ac_Adapter *ac);
|
||||
static void _battery_udev_battery_update(const char *syspath, Battery *bat);
|
||||
static void _battery_udev_ac_update(const char *syspath, Ac_Adapter *ac);
|
||||
|
||||
extern Eina_List *device_batteries;
|
||||
extern Eina_List *device_ac_adapters;
|
||||
extern double init_time;
|
||||
|
||||
int
|
||||
int
|
||||
_battery_udev_start(void)
|
||||
{
|
||||
Eina_List *devices;
|
||||
const char *dev;
|
||||
|
||||
|
||||
devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_BAT, NULL);
|
||||
EINA_LIST_FREE(devices, dev)
|
||||
_battery_udev_battery_add(dev);
|
||||
|
@ -40,7 +40,7 @@ _battery_udev_start(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
_battery_udev_stop(void)
|
||||
{
|
||||
Ac_Adapter *ac;
|
||||
|
@ -68,8 +68,7 @@ _battery_udev_stop(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_udev_event_battery(const char *syspath, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch __UNUSED__)
|
||||
{
|
||||
if ((event & EEZE_UDEV_EVENT_ADD) ||
|
||||
|
@ -82,7 +81,7 @@ _battery_udev_event_battery(const char *syspath, Eeze_Udev_Event event, void *da
|
|||
_battery_udev_battery_update(syspath, data);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_udev_event_ac(const char *syspath, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch __UNUSED__)
|
||||
{
|
||||
if ((event & EEZE_UDEV_EVENT_ADD) ||
|
||||
|
@ -95,7 +94,7 @@ _battery_udev_event_ac(const char *syspath, Eeze_Udev_Event event, void *data, E
|
|||
_battery_udev_ac_update(syspath, data);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_udev_battery_add(const char *syspath)
|
||||
{
|
||||
Battery *bat;
|
||||
|
@ -115,15 +114,15 @@ _battery_udev_battery_add(const char *syspath)
|
|||
bat->last_update = ecore_time_get();
|
||||
bat->udi = eina_stringshare_add(syspath);
|
||||
#if 0
|
||||
bat->poll = ecore_poller_add(ECORE_POLLER_CORE,
|
||||
battery_config->poll_interval,
|
||||
bat->poll = ecore_poller_add(ECORE_POLLER_CORE,
|
||||
battery_config->poll_interval,
|
||||
_battery_udev_battery_update_poll, bat);
|
||||
#endif
|
||||
device_batteries = eina_list_append(device_batteries, bat);
|
||||
_battery_udev_battery_update(syspath, bat);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_udev_ac_add(const char *syspath)
|
||||
{
|
||||
Ac_Adapter *ac;
|
||||
|
@ -145,7 +144,7 @@ _battery_udev_ac_add(const char *syspath)
|
|||
_battery_udev_ac_update(syspath, ac);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_udev_battery_del(const char *syspath)
|
||||
{
|
||||
Battery *bat;
|
||||
|
@ -168,7 +167,7 @@ _battery_udev_battery_del(const char *syspath)
|
|||
free(bat);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_udev_ac_del(const char *syspath)
|
||||
{
|
||||
Ac_Adapter *ac;
|
||||
|
@ -186,31 +185,32 @@ _battery_udev_ac_del(const char *syspath)
|
|||
}
|
||||
|
||||
#if 0
|
||||
static Eina_Bool
|
||||
static Eina_Bool
|
||||
_battery_udev_battery_update_poll(void *data)
|
||||
{
|
||||
_battery_udev_battery_update(NULL, data);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define GET_NUM(TYPE, VALUE, PROP) test = eeze_udev_syspath_get_property(TYPE->udi, #PROP); \
|
||||
do \
|
||||
if (test) \
|
||||
{ \
|
||||
TYPE->VALUE = strtod(test, NULL); \
|
||||
} \
|
||||
do \
|
||||
if (test) \
|
||||
{ \
|
||||
TYPE->VALUE = strtod(test, NULL); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define GET_STR(TYPE, VALUE, PROP) TYPE->VALUE = eeze_udev_syspath_get_property(TYPE->udi, #PROP)
|
||||
|
||||
static void
|
||||
|
||||
static void
|
||||
_battery_udev_battery_update(const char *syspath, Battery *bat)
|
||||
{
|
||||
const char *test;
|
||||
double t, charge;
|
||||
|
||||
|
||||
if (!bat)
|
||||
{
|
||||
if (!(bat = _battery_battery_find(syspath)))
|
||||
|
@ -220,10 +220,10 @@ _battery_udev_battery_update(const char *syspath, Battery *bat)
|
|||
#if 0
|
||||
ecore_poller_poller_interval_set(bat->poll, battery_config->poll_interval);
|
||||
#endif
|
||||
|
||||
|
||||
GET_NUM(bat, present, POWER_SUPPLY_PRESENT);
|
||||
if (!bat->got_prop)
|
||||
{/* only need to get these once */
|
||||
if (!bat->got_prop) /* only need to get these once */
|
||||
{
|
||||
GET_STR(bat, technology, POWER_SUPPLY_TECHNOLOGY);
|
||||
GET_STR(bat, model, POWER_SUPPLY_MODEL_NAME);
|
||||
GET_STR(bat, vendor, POWER_SUPPLY_MANUFACTURER);
|
||||
|
@ -295,7 +295,7 @@ _battery_udev_battery_update(const char *syspath, Battery *bat)
|
|||
if (!strcmp(test, "Charging"))
|
||||
bat->charging = 1;
|
||||
else if ((!strcmp(test, "Unknown")) && (bat->charge_rate > 0))
|
||||
bat->charging = 1;
|
||||
bat->charging = 1;
|
||||
else
|
||||
bat->charging = 0;
|
||||
eina_stringshare_del(test);
|
||||
|
@ -307,11 +307,11 @@ _battery_udev_battery_update(const char *syspath, Battery *bat)
|
|||
bat->got_prop = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
_battery_udev_ac_update(const char *syspath, Ac_Adapter *ac)
|
||||
{
|
||||
const char *test;
|
||||
|
||||
|
||||
if (!ac)
|
||||
{
|
||||
if (!(ac = _battery_ac_adapter_find(syspath)))
|
||||
|
@ -323,3 +323,4 @@ _battery_udev_ac_update(const char *syspath, Ac_Adapter *ac)
|
|||
|
||||
_battery_device_update();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue