Implemented brightness slider in power menu
authorEnrico Zini <enrico@enricozini.org>
Mon, 7 Dec 2009 20:45:40 +0000 (21:45 +0100)
committerEnrico Zini <enrico@enricozini.org>
Mon, 7 Dec 2009 20:45:40 +0000 (21:45 +0100)
configure.ac
src/Makefile.am
src/app_debug.vala
src/app_power.vala
src/config.vala
src/omhacks.vapi [new file with mode: 0644]

index 188dcd78a73e4a5ebc26ced16da2a32ca5468453..78429f484e32b492224a7e9b5da0428dfc623b8e 100644 (file)
@@ -43,6 +43,10 @@ PKG_CHECK_MODULES(DEVKITPOWER, devkit-power-gobject >= 010)
 AC_SUBST(DEVKITPOWER_CFLAGS)
 AC_SUBST(DEVKITPOWER_LIBS)
 
+PKG_CHECK_MODULES(OMHACKS, libomhacks)
+AC_SUBST(OMHACKS_CFLAGS)
+AC_SUBST(OMHACKS_LIBS)
+
 AC_CONFIG_FILES([Makefile
            src/Makefile])
 
index af2a6ac7f27878164709c3a45b439cd400d0639e..268e1048e30c1e2f995e57620d045e73cd0675a5 100644 (file)
@@ -1,4 +1,4 @@
-VFLAGS=-g --pkg gee-1.0 --pkg dbus-glib-1 --pkg gtk+-2.0 --pkg posix --pkg libwnck-1.0 --vapidir=. --pkg linux-input --pkg dbus-extra --pkg devkit-power-gobject
+VFLAGS=-g --pkg gee-1.0 --pkg dbus-glib-1 --pkg gtk+-2.0 --pkg posix --pkg libwnck-1.0 --vapidir=. --pkg linux-input --pkg dbus-extra --pkg devkit-power-gobject --pkg omhacks
 
 #zavai: $(SOURCES)
 #      valac -o zavai $(VFLAGS) $^
@@ -21,10 +21,11 @@ AM_CPPFLAGS = \
        $(GTK_CFLAGS) \
        $(WNCK_CFLAGS) \
        $(DEVKITPOWER_CFLAGS) \
+       $(OMHACKS_CFLAGS) \
        -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
        -DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE
 
-zavai_VAPIS = linux-input.vapi dbus-extra.vapi devkit-power-gobject.vapi
+zavai_VAPIS = linux-input.vapi dbus-extra.vapi devkit-power-gobject.vapi omhacks.vapi
 
 BUILT_SOURCES = zavai.vala.stamp zavai-calendar.vala.stamp \
                $(zavai_VALASOURCES:.vala=.c) $(zavai_calendar_VALASOURCES:.vala=.c)
@@ -88,7 +89,8 @@ zavai_LDADD = \
        $(GEE_LIBS) \
        $(GTK_LIBS) \
        $(WNCK_LIBS) \
-       $(DEVKITPOWER_LIBS)
+       $(DEVKITPOWER_LIBS) \
+       $(OMHACKS_LIBS)
 
 zavai_calendar_LDADD = \
        $(GLIB_LIBS) \
index ec585ceb2fc627089a1c680beba7ca68203e2a27..3e053f9c02805ccb6044ab3743cce308b4c5a4c8 100644 (file)
@@ -52,6 +52,24 @@ public class Quitter : Applet
     }
 }
 
+public class PowerMenuService : Service
+{
+    public PowerMenuService()
+    {
+        Object(name: "app.debug.power_menu_service");
+    }
+    public override void start()
+    {
+       zavai.ui.power.power_menu.toggle();
+    }
+    public override void stop()
+    {
+       zavai.ui.power.power_menu.toggle();
+    }
+}
+
+
+
 /*
 class Quitter(gtk.Action):
     def __init__(self, **kw):
@@ -76,6 +94,11 @@ void init()
     var menu_debug = new zavai.Menu("Debug");
     menu_debug.add_applet("app.debug.useless");
     menu_debug.add_service_toggle("app.debug.useless_service", "Start useless service", "Stop useless service");
+
+    var power_menu_service = new PowerMenuService();
+    zavai.registry.register_service(power_menu_service);
+    menu_debug.add_service_toggle("app.debug.power_menu_service", "Toggle power menu", "Toggle power menu");
+
     menu_debug.add_applet("app.debug.quit");
 
     zavai.registry.register_menu("menu.debug", menu_debug);
index d2c1f74cf654034aa39bf8baa0f585713481ca0d..c4af85c27de5b411146d15783311092198edea80 100644 (file)
@@ -464,14 +464,42 @@ public class Backlight: zavai.Service
        }
 }
 
+public class BrightnessAdjustment : Gtk.Adjustment
+{
+       public BrightnessAdjustment()
+       {
+               lower = 0;
+               upper = Omhacks.Screen.Brightness.get_max();
+               value = Omhacks.Screen.Brightness.get();
+               step_increment = 1;
+               page_increment = upper/10;
+               page_size = upper/10;
+               value_changed += on_value_changed;
+
+               /*
+               Gtk.Adjustment(
+                       zavai.config.backlight_max/2,
+                       0, zavai.config.backlight_max,
+                       1, zavai.config.backlight_max/10, zavai.config.backlight_max/10);
+               */
+       }
+
+       protected void on_value_changed()
+       {
+               Omhacks.Screen.Brightness.set((int)value);
+       }
+}
+
 public class PowerMenu : zavai.Resource, Gtk.Window
 {
        protected Gtk.VBox vbox;
+       protected Gtk.HBox hbox;
        protected ScreenLockButton act_screen_lock;
        protected SuspendButton act_suspend;
        protected ShutdownButton act_shutdown;
        protected RebootButton act_reboot;
        protected ServiceRequestLink act_backlight_on;
+       protected Gtk.VScrollbar bscroll;
        protected bool shown;
 
        public PowerMenu()
@@ -487,8 +515,15 @@ public class PowerMenu : zavai.Resource, Gtk.Window
                set_position(Gtk.WindowPosition.CENTER_ON_PARENT);
                set_size_request(300, 500);
 
+               hbox = new Gtk.HBox(false, 0);
+               add(hbox);
+
                vbox = new Gtk.VBox(false, 0);
-               add(vbox);
+               hbox.pack_start(vbox, true, true, 0);
+
+               bscroll = new Gtk.VScrollbar(brightness);
+               bscroll.inverted = true;
+               hbox.pack_start(bscroll, false, false, 0);
 
                //destroy += Gtk.main_quit;
                //set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK);
@@ -563,6 +598,7 @@ Power power;
 PowerMenu power_menu;
 Gee.ArrayList<BatteryIcon> battery_icons;
 Backlight backlight;
+BrightnessAdjustment brightness;
 //TogglePowerMenu tpm;
 
 public void init()
@@ -570,6 +606,7 @@ public void init()
        power = new Power();
        backlight = new Backlight();
        zavai.registry.register_service(backlight);
+       brightness = new BrightnessAdjustment();
        
        try {
                battery_icons = new Gee.ArrayList<BatteryIcon>();
index ded93e9b56a4db30f4586a83554b978f6bf418f1..4aaede53c8d26f4b96725a5ad5f703099f628ad1 100644 (file)
@@ -29,6 +29,7 @@ public class Config
     public string gprs_apn { get; set; }
     public string gprs_user { get; set; }
     public string gprs_pass { get; set; }
+    public int backlight_max { get; set; }
     private string _argv0;
     public string argv0 {
            get { return _argv0; }
@@ -47,6 +48,7 @@ public class Config
         gprs_apn = "general.t-mobile.uk";
         gprs_user = "x";
         gprs_pass = "x";
+       backlight_max = 15;
     }
 
 /*
diff --git a/src/omhacks.vapi b/src/omhacks.vapi
new file mode 100644 (file)
index 0000000..b244fde
--- /dev/null
@@ -0,0 +1,16 @@
+[CCode (lower_case_cprefix="", cprefix="", cheader_filename="omhacks/all.h")]
+namespace Omhacks
+{
+       namespace Screen
+       {
+               namespace Brightness
+               {
+                       [CCode (cname = "om_screen_brightness_get")]
+                       public int get();
+                       [CCode (cname = "om_screen_brightness_get_max")]
+                       public int get_max();
+                       [CCode (cname = "om_screen_brightness_set")]
+                       public int set(int val);
+               }
+       }       
+}