From b1d21a434cc8dcce2794acdc660d054e3c90b757 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Mon, 7 Dec 2009 21:45:40 +0100 Subject: [PATCH] Implemented brightness slider in power menu --- configure.ac | 4 ++++ src/Makefile.am | 8 +++++--- src/app_debug.vala | 23 +++++++++++++++++++++++ src/app_power.vala | 39 ++++++++++++++++++++++++++++++++++++++- src/config.vala | 2 ++ src/omhacks.vapi | 16 ++++++++++++++++ 6 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 src/omhacks.vapi diff --git a/configure.ac b/configure.ac index 188dcd7..78429f4 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/src/Makefile.am b/src/Makefile.am index af2a6ac..268e104 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) \ diff --git a/src/app_debug.vala b/src/app_debug.vala index ec585ce..3e053f9 100644 --- a/src/app_debug.vala +++ b/src/app_debug.vala @@ -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); diff --git a/src/app_power.vala b/src/app_power.vala index d2c1f74..c4af85c 100644 --- a/src/app_power.vala +++ b/src/app_power.vala @@ -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 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(); diff --git a/src/config.vala b/src/config.vala index ded93e9..4aaede5 100644 --- a/src/config.vala +++ b/src/config.vala @@ -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 index 0000000..b244fde --- /dev/null +++ b/src/omhacks.vapi @@ -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); + } + } +} -- 2.30.2