[Goodies-commits] r7248 - in xfce4-power-manager/trunk: . settings src

Ali Abdallah aliov at xfce.org
Mon Apr 20 10:24:20 CEST 2009


Author: aliov
Date: 2009-04-20 08:24:20 +0000 (Mon, 20 Apr 2009)
New Revision: 7248

Modified:
   xfce4-power-manager/trunk/ChangeLog
   xfce4-power-manager/trunk/settings/xfpm-settings.c
   xfce4-power-manager/trunk/settings/xfpm-settings.glade
   xfce4-power-manager/trunk/src/xfpm-config.h
   xfce4-power-manager/trunk/src/xfpm-cpu.c
   xfce4-power-manager/trunk/src/xfpm-cpu.h
   xfce4-power-manager/trunk/src/xfpm-engine.c
   xfce4-power-manager/trunk/src/xfpm-xfconf.c
Log:
Provide the possibility to disable CPU freq control+don't compile the cpu governor code if we aren't on Linux

Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/ChangeLog	2009-04-20 08:24:20 UTC (rev 7248)
@@ -1,4 +1,7 @@
 
+2009-04-20 10:24 Ali aliov at xfce.org 
+	 * : Provide the possibility to disable CPU freq control+don't compile the cpu governor code if we aren't on Linux
+
 2009-04-20  9:22 Ali aliov at xfce.org 
 	 * : Remove all encoding keys from the desktop file thanks to Yves for pointing out
 

Modified: xfce4-power-manager/trunk/settings/xfpm-settings.c
===================================================================
--- xfce4-power-manager/trunk/settings/xfpm-settings.c	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/settings/xfpm-settings.c	2009-04-20 08:24:20 UTC (rev 7248)
@@ -520,7 +520,20 @@
     }
 }
 
+#ifdef SYSTEM_IS_LINUX
 static void
+cpu_freq_control_changed_cb (GtkWidget *w, XfconfChannel *channel)
+{
+    gboolean val = (gint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
+    
+    if ( !xfconf_channel_set_bool (channel, CPU_FREQ_CONTROL, val) )
+    {
+	g_critical ("Unable to set value for property %s\n", CPU_FREQ_CONTROL);
+    }
+}
+#endif
+
+static void
 xfpm_settings_on_battery (XfconfChannel *channel, gboolean user_privilege, gboolean can_suspend, 
 			 gboolean can_hibernate, gboolean has_lcd_brightness, gboolean has_lid)
 {
@@ -1128,7 +1141,7 @@
 }
 
 static void
-xfpm_settings_advanced (XfconfChannel *channel, gboolean system_latop, gboolean user_privilege,
+xfpm_settings_advanced (XfconfChannel *channel, gboolean system_laptop, gboolean user_privilege,
 			gboolean can_suspend, gboolean can_hibernate)
 {
     guint val;
@@ -1197,7 +1210,7 @@
      * Critical battery level
      */
     GtkWidget *critical_level = glade_xml_get_widget (xml, "critical-spin");
-    if ( system_latop )
+    if ( system_laptop )
     {
 	gtk_widget_set_tooltip_text (critical_level, 
 				     _("When all the power sources of the computer reach this charge level"));
@@ -1240,6 +1253,23 @@
     g_signal_connect (lock, "toggled",
 		      G_CALLBACK(lock_screen_toggled_cb), channel);
  
+    GtkWidget *cpu;
+    cpu = glade_xml_get_widget (xml, "cpu-freq");
+    
+#ifdef SYSTEM_IS_LINUX
+    if ( system_laptop )
+    {
+	val = xfconf_channel_get_bool (channel, CPU_FREQ_CONTROL, TRUE);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(cpu), val);
+	g_signal_connect (cpu, "toggled",
+		          G_CALLBACK(cpu_freq_control_changed_cb), channel);
+    }
+    else
+	gtk_widget_hide (cpu);
+#else
+    gtk_widget_hide (cpu);
+#endif
+
 }
 
 static void

Modified: xfce4-power-manager/trunk/settings/xfpm-settings.glade
===================================================================
--- xfce4-power-manager/trunk/settings/xfpm-settings.glade	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/settings/xfpm-settings.glade	2009-04-20 08:24:20 UTC (rev 7248)
@@ -907,7 +907,7 @@
                                 <child>
                                   <widget class="GtkTable" id="table1">
                                     <property name="visible">True</property>
-                                    <property name="n_rows">2</property>
+                                    <property name="n_rows">3</property>
                                     <property name="n_columns">2</property>
                                     <property name="row_spacing">8</property>
                                     <child>
@@ -1018,41 +1018,64 @@
                                         <property name="bottom_attach">2</property>
                                       </packing>
                                     </child>
-                                  </widget>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="position">0</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <widget class="GtkHBox" id="hbox2">
-                                    <property name="visible">True</property>
-                                    <property name="spacing">10</property>
                                     <child>
-                                      <widget class="GtkLabel" id="critical-level-label">
+                                      <widget class="GtkHBox" id="hbox2">
                                         <property name="visible">True</property>
-                                        <property name="label" translatable="yes">Consider the computer on low power at:</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="critical-level-label">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">Consider the computer on low power at:</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
                                       </widget>
                                       <packing>
-                                        <property name="expand">False</property>
-                                        <property name="position">0</property>
+                                        <property name="top_attach">2</property>
+                                        <property name="bottom_attach">3</property>
                                       </packing>
                                     </child>
                                     <child>
-                                      <widget class="GtkSpinButton" id="critical-spin">
+                                      <widget class="GtkHBox" id="hbox8">
                                         <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="invisible_char">&#x25CF;</property>
-                                        <property name="adjustment">5 5 20 1 0 0</property>
+                                        <child>
+                                          <widget class="GtkSpinButton" id="critical-spin">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="invisible_char">&#x25CF;</property>
+                                            <property name="adjustment">5 5 20 1 0 0</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
                                       </widget>
                                       <packing>
-                                        <property name="expand">False</property>
-                                        <property name="position">1</property>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">2</property>
+                                        <property name="bottom_attach">3</property>
                                       </packing>
                                     </child>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkCheckButton" id="cpu-freq">
+                                    <property name="label" translatable="yes">Enable CPU frequency control</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="draw_indicator">True</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
                                     <property name="position">1</property>
                                   </packing>
                                 </child>

Modified: xfce4-power-manager/trunk/src/xfpm-config.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-config.h	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/src/xfpm-config.h	2009-04-20 08:24:20 UTC (rev 7248)
@@ -26,6 +26,10 @@
 #include <config.h>
 #endif
 
+#if defined(__linux__)
+#define SYSTEM_IS_LINUX 1
+#endif
+
 G_BEGIN_DECLS
 
 /* Configuration */
@@ -34,7 +38,7 @@
 #define         CRITICAL_POWER_LEVEL        "/xfce4-power-manager/critical-power-level"
 
 #define 	POWER_SAVE_ON_BATTERY       "/xfce4-power-manager/power-save-on-battery"
-
+#define         CPU_FREQ_CONTROL            "/xfce4-power-manager/cpu-freq-control"
 #define         LOCK_SCREEN_ON_SLEEP        "/xfce4-power-manager/lock-screen-suspend-hibernate"
 
 #define 	LCD_BRIGHTNESS_CFG          "/xfce4-power-manager/lcd-brightness"
@@ -68,7 +72,7 @@
 #define 	ON_BATT_DPMS_OFF	     "/xfce4-power-manager/on-battery-dpms-off"
 #define 	ON_AC_DPMS_SLEEP 	     "/xfce4-power-manager/on-ac-dpms-sleep"
 #define 	ON_AC_DPMS_OFF	     	     "/xfce4-power-manager/on-ac-dpms-off"
-#define         DPMS_SLEEP_MODE		     "/xfce4-power-manager/dpms-sleep-mode"	/* 0= sleep, 1=suspend */
+#define         DPMS_SLEEP_MODE		     "/xfce4-power-manager/dpms-sleep-mode"		/* 0= sleep, 1=suspend */
 #endif
 
 #define         ENABLE_BRIGHTNESS_CONTROL    "/xfce4-power-manager/change-brightness-on-key-events"

Modified: xfce4-power-manager/trunk/src/xfpm-cpu.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-cpu.c	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/src/xfpm-cpu.c	2009-04-20 08:24:20 UTC (rev 7248)
@@ -41,6 +41,8 @@
 #include "xfpm-config.h"
 #include "xfpm-enum.h"
 
+#ifdef SYSTEM_IS_LINUX /* the end if at the end of the file */
+
 /* Init */
 static void xfpm_cpu_class_init (XfpmCpuClass *klass);
 static void xfpm_cpu_init       (XfpmCpu *cpu);
@@ -277,37 +279,51 @@
     
     xfpm_cpu_get_available_governors (cpu);
     
-    if ( !cpu->priv->cpu_governors & CPU_POWERSAVE || 
-	 !cpu->priv->cpu_governors & CPU_ONDEMAND  ||
-	 !cpu->priv->cpu_governors & CPU_PERFORMANCE )
-    {
-	g_warning ("No convenient cpu governors found on the system, cpu frequency control will be disabled");
-	return FALSE;
-    }
-    return TRUE;
+    if ( (cpu->priv->cpu_governors & CPU_ONDEMAND || cpu->priv->cpu_governors & CPU_PERFORMANCE)
+	 && (cpu->priv->cpu_governors & CPU_POWERSAVE) )
+	return TRUE;
+    
+    g_warning ("No convenient cpu governors found on the system, cpu frequency control will be disabled");
+    return FALSE;
 }
 
 static void
 xfpm_cpu_set_power_save (XfpmCpu *cpu)
 {
-    if ( xfpm_cpu_get_current_governor (cpu) != CPU_POWERSAVE )
+    if ( xfpm_cpu_get_current_governor (cpu) != CPU_POWERSAVE && cpu->priv->cpu_governors & CPU_POWERSAVE )
 	xfpm_cpu_set_governor (cpu, "powersave");
 }
 
 static void
 xfpm_cpu_set_performance_ondemand (XfpmCpu *cpu)
 {
-    if ( xfpm_cpu_get_current_governor (cpu) != CPU_ONDEMAND )
+    XfpmCpuGovernor gov;
+    
+    gov = xfpm_cpu_get_current_governor (cpu);
+    
+    if ( gov == CPU_ONDEMAND )
+	return;
+	
+    if ( (gov != CPU_ONDEMAND) && (cpu->priv->cpu_governors & CPU_ONDEMAND) )
 	xfpm_cpu_set_governor (cpu, "ondemand");
+    else if ( (gov != CPU_PERFORMANCE) && (cpu->priv->cpu_governors & CPU_PERFORMANCE) )
+	xfpm_cpu_set_governor (cpu, "performance");
 }
 
 static void
 xfpm_cpu_refresh (XfpmCpu *cpu)
 {
     gboolean power_save = xfpm_xfconf_get_property_bool (cpu->priv->conf, POWER_SAVE_ON_BATTERY);
+    gboolean enable_cpu_freq = xfpm_xfconf_get_property_bool (cpu->priv->conf, CPU_FREQ_CONTROL);
     
-    if (!power_save)
+    if ( enable_cpu_freq == FALSE )
 	return;
+    
+    if (power_save == FALSE)
+    {
+	xfpm_cpu_set_performance_ondemand (cpu);
+	return;
+    }
 	
     if ( cpu->priv->on_battery )
 	xfpm_cpu_set_power_save (cpu);
@@ -400,3 +416,5 @@
     cpu->priv->cpu_governors = 0;
     xfpm_cpu_check_iface (cpu);
 }
+
+#endif /*SYSTEM_IS_LINUX*/

Modified: xfce4-power-manager/trunk/src/xfpm-cpu.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-cpu.h	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/src/xfpm-cpu.h	2009-04-20 08:24:20 UTC (rev 7248)
@@ -23,8 +23,12 @@
 
 #include <glib-object.h>
 
+#include "xfpm-config.h"
+
 G_BEGIN_DECLS
 
+#ifdef SYSTEM_IS_LINUX
+
 #define XFPM_TYPE_CPU        (xfpm_cpu_get_type () )
 #define XFPM_CPU(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_CPU, XfpmCpu))
 #define XFPM_IS_CPU(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_CPU))
@@ -48,6 +52,8 @@
 XfpmCpu       *xfpm_cpu_new             (void);
 void           xfpm_cpu_reload          (XfpmCpu *cpu);
 
+#endif /*SYSTEM_IS_LINUX*/
+
 G_END_DECLS
 
 #endif /* __XFPM_CPU_H */

Modified: xfce4-power-manager/trunk/src/xfpm-engine.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-engine.c	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/src/xfpm-engine.c	2009-04-20 08:24:20 UTC (rev 7248)
@@ -71,8 +71,9 @@
     XfpmXfconf 		*conf;
     XfpmSupply 		*supply;
     XfpmNotify 		*notify;
-
+#ifdef SYSTEM_IS_LINUX
     XfpmCpu 		*cpu;
+#endif
     XfpmBacklight 	*bk;
     XfpmAdapter 	*adapter;
     XfpmInhibit 	*inhibit;
@@ -280,8 +281,11 @@
 #ifdef HAVE_DPMS
     engine->priv->dpms = xfpm_dpms_new ();
 #endif
+
+#ifdef SYSTEM_IS_LINUX
     if (engine->priv->is_laptop)
 	engine->priv->cpu = xfpm_cpu_new ();
+#endif
 
     engine->priv->supply = xfpm_supply_new (engine->priv->power_management);
     g_signal_connect (G_OBJECT (engine->priv->supply), "shutdown-request",
@@ -428,7 +432,11 @@
 #ifdef HAVE_DPMS
     engine->priv->dpms = NULL;
 #endif
+
+#ifdef SYSTEM_IS_LINUX
     engine->priv->cpu = NULL;
+#endif
+
     engine->priv->button = NULL;
     engine->priv->bk = NULL;
 
@@ -477,8 +485,10 @@
 	g_object_unref (engine->priv->dpms);
 #endif
 
+#ifdef SYSTEM_IS_LINUX
     if (engine->priv->cpu)
 	g_object_unref (engine->priv->cpu);
+#endif
 
     g_object_unref (engine->priv->shutdown);
 
@@ -554,7 +564,9 @@
     if ( engine->priv->is_laptop )
     {
 	xfpm_backlight_reload (engine->priv->bk);
+#ifdef SYSTEM_IS_LINUX
 	xfpm_cpu_reload       (engine->priv->cpu);
+#endif
     }
 }
 

Modified: xfce4-power-manager/trunk/src/xfpm-xfconf.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-xfconf.c	2009-04-20 07:46:02 UTC (rev 7247)
+++ xfce4-power-manager/trunk/src/xfpm-xfconf.c	2009-04-20 08:24:20 UTC (rev 7248)
@@ -70,6 +70,9 @@
     gboolean         	 sleep_dpms_mode; /*TRUE = standby FALSE = suspend*/
 #endif
     gboolean             power_save_on_battery;
+#ifdef SYSTEM_IS_LINUX
+    gboolean             cpu_freq_control;
+#endif
     
     guint16              brightness_on_ac_timeout;
     guint16              brightness_on_battery_timeout;
@@ -229,6 +232,13 @@
 	conf->priv->power_save_on_battery = g_value_get_boolean (value);
 	g_signal_emit (G_OBJECT(conf), signals[POWER_SAVE_SETTINGS_CHANGED], 0);
     }
+#ifdef SYSTEM_IS_LINUX
+    else if ( xfpm_strequal(property, CPU_FREQ_CONTROL) )
+    {
+	conf->priv->cpu_freq_control = g_value_get_boolean (value);
+	g_signal_emit (G_OBJECT(conf), signals[POWER_SAVE_SETTINGS_CHANGED], 0);
+    }
+#endif
     else if ( xfpm_strequal (property, BRIGHTNESS_ON_AC ) )
     {
 	conf->priv->brightness_on_ac_timeout = g_value_get_uint (value);
@@ -321,6 +331,8 @@
     }
     else if ( xfpm_strequal (property, ENABLE_BRIGHTNESS_CONTROL) )
 	conf->priv->enable_brightness = g_value_get_boolean (value);
+    else
+	g_warn_if_reached ();
 }
 
 static void
@@ -433,7 +445,10 @@
 #endif /* HAVE_DPMS */
     conf->priv->power_save_on_battery =
     	xfconf_channel_get_bool (conf->priv->channel, POWER_SAVE_ON_BATTERY, TRUE);
-	
+#ifdef SYSTEM_IS_LINUX
+    conf->priv->cpu_freq_control =
+	xfconf_channel_get_bool (conf->priv->channel, CPU_FREQ_CONTROL, TRUE);
+#endif
     conf->priv->brightness_on_ac_timeout =
 	xfconf_channel_get_uint (conf->priv->channel, BRIGHTNESS_ON_AC, 9);
 	
@@ -622,6 +637,10 @@
 	return conf->priv->lock_screen;
     else if ( xfpm_strequal (property, POWER_SAVE_ON_BATTERY ) )
 	return conf->priv->power_save_on_battery;
+#ifdef SYSTEM_IS_LINUX
+    else if ( xfpm_strequal (property, CPU_FREQ_CONTROL) )
+	return conf->priv->cpu_freq_control;
+#endif
     else if ( xfpm_strequal (property, GENERAL_NOTIFICATION_CFG ) )
 	return conf->priv->general_notification;
 #ifdef HAVE_DPMS




More information about the Goodies-commits mailing list