解决 gnome-power-manager 没有低电量提示的问题
首先,我得说一下我是 Linux 新手,这个解决方法只是能用而已。

gnome-power-manager 没低电量提示的问题困扰了我将近半个月的时间,期间曾按网上大多数人提供的方法修改 gconf 配置中的 /apps/gnome-power-manager/general/use_time_for_policy 的值为 false,让 gnome-power-manager 使用电量百分比作为判断依据,但没有效果。

后来仔细得浏览了一下这个页面,发现 Joakim Andersson 所写的回复,非常明确得指出了问题所在。但继续往后浏览,发现有管理者说这个问题已于去年9月修复。而这个页面讨论的似乎是 Ubuntu 库里的版本,经过检验发现我这 Arch Linux 里装的 gnome-power-manager 虽然是最新的 2.24.4 版,但是这个问题依然没有解决。

运行 gconf-editor,修改 /apps/gnome-power-manager/general/debug 的值为 true,开启额外的调试信息输出。执行

$ gnome-power-manager --verbose

观察其详细信息,会发现当电量百分比低于设定值时,会有一句

profile is not accurate. Not doing policy action

这就是 bugs 反应页面里提到的那个原因。

到 gnome 的 ftp 里下载一份 2.24.4 版本的 gnome-power-manager,解压缩。经过搜索,发现上面提到的那个除错信息在 src/gpm-cell-array.c 的 gpm_cell_array_emit_system_action() 函数内

  1. static gboolean
  2. gpm_cell_array_emit_system_action (GpmCellArray    *cell_array,
  3.                    GpmWarningsState warnings_state)
  4. {
  5.     gfloat accuracy;
  6.     GpmCellUnit *unit;
  7.  
  8.     g_return_val_if_fail (GPM_IS_CELL_ARRAY (cell_array), FALSE);
  9.  
  10.     /* do we trust the profile enough to make a decision? */
  11.     unit = &(cell_array->priv->unit);
  12.     if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
  13.         accuracy = gpm_profile_get_accuracy_average (cell_array->priv->profile,
  14.                                  unit->is_discharging);
  15.         if (accuracy < GPM_PROFILE_GOOD_TRUST) {
  16.             egg_debug ("profile is not accurate. Not doing policy action");
  17.             return FALSE;
  18.         }
  19.     }
  20.  
  21.     /* we are not primary, or we are primary with a trusted profile */
  22.     if (warnings_state == GPM_WARNINGS_ACTION) {
  23.         egg_debug ("** EMIT: charge-action");
  24.         g_signal_emit (cell_array, signals [CHARGE_ACTION], 0, unit->percentage);
  25.     } else if (warnings_state == GPM_WARNINGS_CRITICAL) {
  26.         egg_debug ("** EMIT: charge-critical");
  27.         g_signal_emit (cell_array, signals [CHARGE_CRITICAL], 0, unit->percentage);
  28.     } else if (warnings_state == GPM_WARNINGS_LOW) {
  29.         egg_debug ("** EMIT: charge-low");
  30.         g_signal_emit (cell_array, signals [CHARGE_LOW], 0, unit->percentage);
  31.     }
  32.     return TRUE;
  33. }

而经过搜索 CHARGE_LOW,发现似乎低电量的信号只能由这个函数发出,但很明显当 accuracy < GPM_PROFILE_GOOD_TRUST 时,就直接 return FALSE 了,所以不管 use_time_for_policy 是 true 还是 false,只要 accuracy 的值不够高,低电量提示就不可能出现。知道了这些,下面的工作就好办了,把涉及到 profile 准确度的几行注释掉,同时保证 /apps/gnome-power-manager/general/use_time_for_policy 的值为 false,程序就能正常工作了。

将定义 accuracy 变量的语句和为 unit 赋值的语句下方的 if 语句都注释掉

  1. static gboolean
  2. gpm_cell_array_emit_system_action (GpmCellArray    *cell_array,
  3.                    GpmWarningsState warnings_state)
  4. {
  5.     // gfloat accuracy;
  6.     GpmCellUnit *unit;
  7.  
  8.     g_return_val_if_fail (GPM_IS_CELL_ARRAY (cell_array), FALSE);
  9.  
  10.     /* do we trust the profile enough to make a decision? */
  11.     unit = &(cell_array->priv->unit);
  12.     /*
  13.     if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
  14.         accuracy = gpm_profile_get_accuracy_average (cell_array->priv->profile,
  15.                                  unit->is_discharging);
  16.         if (accuracy < GPM_PROFILE_GOOD_TRUST) {
  17.             egg_debug ("profile is not accurate. Not doing policy action");
  18.             return FALSE;
  19.         }
  20.     }
  21.     */

然后编译安装。经过测试,低电量提示可以正常显示了。


参考:
1. Bug #135548 in gnome-power-manager...
2. Brian Jones - Re: Autoconf problems?
3. Charles Wilson - Re: 'can not find install-sh' when running configure
4. Re: difficulties with gnome-doc-utils.make
5. automake: 7.3.9.1 required file `./ltmain.sh' not found
6. Automake(1) - 一蓑烟雨任平生 Le blogspot de Leizhige - CSDNBlog
当前语言: 中文 (简体)
发表留言
昵称 (必需)
邮件 (必需,不会被发布出来)
网站 (可选)
留言
可以使用类似维基标记的语法,参看指南