--- /dev/null
+/*
+ * app_power - zavai power handling
+ *
+ * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+using GLib;
+
+namespace zavai {
+namespace ui {
+namespace powerbutton {
+
+/*
+public class RaiseIcon : Gtk.StatusIcon
+{
+ public RaiseIcon()
+ {
+ activate += on_activate;
+ zavai.app.visibility_changed += on_visibility_changed;
+ update_icon();
+ }
+
+ private void on_visibility_changed(bool visible)
+ {
+ update_icon();
+ }
+
+ private void on_activate()
+ {
+ zavai.app.toggle_visibility();
+ update_icon();
+ }
+
+ protected void update_icon()
+ {
+ string name = zavai.config.icondir + "/";
+ if (!zavai.app.visibility)
+ name += "zavai_on.png";
+ else
+ name += "zavai_off.png";
+ set_from_file(name);
+ }
+}
+
+public class CloseOrBack : Gtk.StatusIcon
+{
+ public CloseOrBack()
+ {
+ activate += on_activate;
+ zavai.app.visibility_changed += on_visibility_changed;
+ update_icon();
+ }
+
+ private void on_visibility_changed(bool visible)
+ {
+ update_icon();
+ }
+
+ private void on_activate()
+ {
+ if (zavai.app.visibility)
+ {
+ // Back
+ } else {
+ // Close current app
+ Gdk.Window w = zavai.app.get_screen().get_active_window();
+ if (w != zavai.app.window)
+ {
+ w.destroy();
+ }
+ }
+ }
+
+ protected void update_icon()
+ {
+ string name = zavai.config.icondir + "/";
+ if (!zavai.app.visibility)
+ name += "quit_on.png";
+ else
+ name += "quit_off.png";
+ set_from_file(name);
+ }
+}
+
+public class WindowList : Applet
+{
+ Wnck.Tasklist selector;
+
+ public WindowList(string label)
+ {
+ _label = label;
+ selector = new Wnck.Tasklist(Wnck.Screen.get_default());
+ pack_start(selector, true, true, 0);
+ }
+}
+*/
+
+public class CommandButton : Gtk.Button
+{
+ private string command;
+
+ public CommandButton(string name, string command)
+ {
+ label = name;
+ this.command = command;
+ clicked += on_clicked;
+ set_size_request(0, zavai.config.min_button_height);
+ }
+
+ public void on_clicked()
+ {
+ zavai.log.info("Run program: " + command);
+ string[] args = command.split(" ");
+ Pid pid;
+ Process.spawn_async(
+ Environment.get_home_dir(),
+ args,
+ null,
+ SpawnFlags.SEARCH_PATH,
+ null,
+ out pid);
+ }
+}
+
+private bool screen_locked;
+private int screen_lock_fd;
+
+private void set_screen_lock(bool locked)
+{
+ if (locked && screen_locked)
+ return;
+ if (!locked && !screen_locked)
+ return;
+
+ if (locked)
+ {
+ screen_lock_fd = Posix.open("/dev/input/event1", Posix.O_RDWR | Posix.O_NONBLOCK);
+ if (screen_lock_fd < 0)
+ {
+ zavai.log.error("Cannot open /dev/input/event1");
+ return;
+ }
+
+ int EVIOCGRAB = 0x40044590;
+ if (Posix.ioctl(screen_lock_fd, EVIOCGRAB, locked ? 1 : 0) != 0)
+ {
+ zavai.log.error("Cannot EVIOCGRAB /dev/input/event1");
+ Posix.close(screen_lock_fd);
+ return;
+ }
+ } else {
+ Posix.close(screen_lock_fd);
+ }
+ screen_locked = locked;
+}
+
+public class ScreenLockButton : Gtk.Button
+{
+ public ScreenLockButton(string name)
+ {
+ label = name;
+ clicked += on_clicked;
+ set_size_request(0, zavai.config.min_button_height);
+ }
+
+ public void on_clicked()
+ {
+ zavai.log.info("Locking screen");
+ set_screen_lock(true);
+ }
+}
+
+private void on_power_button(Posix.timeval* time, bool pressed)
+{
+ if (!pressed)
+ {
+ if (screen_locked)
+ set_screen_lock(false);
+ else
+ {
+ zavai.app.push_applet("menu.power");
+ zavai.app.ensure_visible();
+ }
+ }
+}
+
+public class BatteryIcon : Gtk.StatusIcon
+{
+ public dynamic DBus.Object battery;
+ protected string last_status;
+ protected int last_capacity;
+
+ public BatteryIcon()
+ {
+ battery = zavai.registry.sbus.get_object(
+ "org.freesmartphone.odeviced",
+ "/org/freesmartphone/Device/PowerSupply/battery",
+ "org.freesmartphone.Device.PowerSupply");
+
+ // activate += on_activate;
+
+ battery.PowerStatus += on_power_status;
+ battery.Capacity += on_capacity;
+
+ last_status = battery.GetPowerStatus();
+ last_capacity = battery.GetCapacity();
+
+ update_icon();
+ }
+
+ private void on_power_status(dynamic DBus.Object bat, string status)
+ {
+ zavai.log.info("New battery status: " + status);
+ last_status = status;
+ update_icon();
+ }
+
+ private void on_capacity(dynamic DBus.Object bat, int val)
+ {
+stderr.printf("NEW CAPACITY: %d\n", val);
+ last_capacity = val;
+ update_icon();
+ }
+
+ /*
+ private void on_activate()
+ {
+ }
+ */
+
+ protected void update_icon()
+ {
+ string name = zavai.config.icondir + "/battery/";
+
+ if (last_status == "charging")
+ name += "%02d0_charging_500.png".printf(last_capacity/10);
+ else
+ name += "%02d0.png".printf(last_capacity/10);
+
+stderr.printf("Loading icon from %s\n", name);
+
+ set_from_file(name);
+ }
+}
+
+BatteryIcon battery_icon;
+
+public void init()
+{
+ screen_locked = false;
+ screen_lock_fd = -1;
+
+ zavai.input.power_button.power_button += on_power_button;
+
+ battery_icon = new BatteryIcon();
+ battery_icon.set_visible(true);
+
+ // Menus
+ var menu_power = new zavai.Menu("Power menu");
+ menu_power.add_widget(new ScreenLockButton("Lock screen"));
+ menu_power.add_widget(new CommandButton("Suspend", "apm -s"));
+ menu_power.add_widget(new CommandButton("Shutdown", "shutdown -h now"));
+ menu_power.add_widget(new CommandButton("Reboot", "shutdown -r now"));
+ zavai.registry.register_menu("menu.power", menu_power);
+
+ zavai.registry.getmenu("menu.main").add_applet("menu.power");
+
+ zavai.registry.gets("input.power_button").request("powerbutton");
+
+ /*
+ raise_icon = new RaiseIcon();
+ raise_icon.set_visible(true);
+
+ close_or_back = new CloseOrBack();
+ close_or_back.set_visible(true);
+
+ window_list = new WindowList("Current apps");
+ zavai.registry.register_applet("wm.list", window_list);
+ zavai.registry.getmenu("menu.main").add_applet("wm.list");
+
+ try {
+ launcher = new Launcher("Run program");
+ } catch (Error e) {
+ zavai.log.error("Not running launcher: " + e.message);
+ launcher = null;
+ }
+
+ if (launcher != null)
+ {
+ zavai.registry.register_applet("wm.launcher", launcher);
+ zavai.registry.getmenu("menu.main").add_applet("wm.launcher");
+ }
+ */
+}
+
+}
+}
+}
+++ /dev/null
-/*
- * app_powerbutton - zavai power button handling
- *
- * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-using GLib;
-
-namespace zavai {
-namespace ui {
-namespace powerbutton {
-
-/*
-public class RaiseIcon : Gtk.StatusIcon
-{
- public RaiseIcon()
- {
- activate += on_activate;
- zavai.app.visibility_changed += on_visibility_changed;
- update_icon();
- }
-
- private void on_visibility_changed(bool visible)
- {
- update_icon();
- }
-
- private void on_activate()
- {
- zavai.app.toggle_visibility();
- update_icon();
- }
-
- protected void update_icon()
- {
- string name = zavai.config.icondir + "/";
- if (!zavai.app.visibility)
- name += "zavai_on.png";
- else
- name += "zavai_off.png";
- set_from_file(name);
- }
-}
-
-public class CloseOrBack : Gtk.StatusIcon
-{
- public CloseOrBack()
- {
- activate += on_activate;
- zavai.app.visibility_changed += on_visibility_changed;
- update_icon();
- }
-
- private void on_visibility_changed(bool visible)
- {
- update_icon();
- }
-
- private void on_activate()
- {
- if (zavai.app.visibility)
- {
- // Back
- } else {
- // Close current app
- Gdk.Window w = zavai.app.get_screen().get_active_window();
- if (w != zavai.app.window)
- {
- w.destroy();
- }
- }
- }
-
- protected void update_icon()
- {
- string name = zavai.config.icondir + "/";
- if (!zavai.app.visibility)
- name += "quit_on.png";
- else
- name += "quit_off.png";
- set_from_file(name);
- }
-}
-
-public class WindowList : Applet
-{
- Wnck.Tasklist selector;
-
- public WindowList(string label)
- {
- _label = label;
- selector = new Wnck.Tasklist(Wnck.Screen.get_default());
- pack_start(selector, true, true, 0);
- }
-}
-*/
-
-public class CommandButton : Gtk.Button
-{
- private string command;
-
- public CommandButton(string name, string command)
- {
- label = name;
- this.command = command;
- clicked += on_clicked;
- set_size_request(0, zavai.config.min_button_height);
- }
-
- public void on_clicked()
- {
- zavai.log.info("Run program: " + command);
- string[] args = command.split(" ");
- Pid pid;
- Process.spawn_async(
- Environment.get_home_dir(),
- args,
- null,
- SpawnFlags.SEARCH_PATH,
- null,
- out pid);
- }
-}
-
-private bool screen_locked;
-private int screen_lock_fd;
-
-private void set_screen_lock(bool locked)
-{
- if (locked && screen_locked)
- return;
- if (!locked && !screen_locked)
- return;
-
- if (locked)
- {
- screen_lock_fd = Posix.open("/dev/input/event1", Posix.O_RDWR | Posix.O_NONBLOCK);
- if (screen_lock_fd < 0)
- {
- zavai.log.error("Cannot open /dev/input/event1");
- return;
- }
-
- int EVIOCGRAB = 0x40044590;
- if (Posix.ioctl(screen_lock_fd, EVIOCGRAB, locked ? 1 : 0) != 0)
- {
- zavai.log.error("Cannot EVIOCGRAB /dev/input/event1");
- Posix.close(screen_lock_fd);
- return;
- }
- } else {
- Posix.close(screen_lock_fd);
- }
- screen_locked = locked;
-}
-
-public class ScreenLockButton : Gtk.Button
-{
- public ScreenLockButton(string name)
- {
- label = name;
- clicked += on_clicked;
- set_size_request(0, zavai.config.min_button_height);
- }
-
- public void on_clicked()
- {
- zavai.log.info("Locking screen");
- set_screen_lock(true);
- }
-}
-
-private void on_power_button(Posix.timeval* time, bool pressed)
-{
- if (!pressed)
- {
- if (screen_locked)
- set_screen_lock(false);
- else
- {
- zavai.app.push_applet("menu.power");
- zavai.app.ensure_visible();
- }
- }
-}
-
-/*
-RaiseIcon raise_icon;
-CloseOrBack close_or_back;
-WindowList window_list;
-Launcher launcher;
-*/
-
-public void init()
-{
- screen_locked = false;
- screen_lock_fd = -1;
-
- zavai.input.power_button.power_button += on_power_button;
-
- // Menus
- var menu_power = new zavai.Menu("Power menu");
- menu_power.add_widget(new ScreenLockButton("Lock screen"));
- menu_power.add_widget(new CommandButton("Suspend", "apm -s"));
- menu_power.add_widget(new CommandButton("Shutdown", "shutdown -h now"));
- menu_power.add_widget(new CommandButton("Reboot", "shutdown -r now"));
- zavai.registry.register_menu("menu.power", menu_power);
-
- zavai.registry.getmenu("menu.main").add_applet("menu.power");
-
- zavai.registry.gets("input.power_button").request("powerbutton");
-
- /*
- raise_icon = new RaiseIcon();
- raise_icon.set_visible(true);
-
- close_or_back = new CloseOrBack();
- close_or_back.set_visible(true);
-
- window_list = new WindowList("Current apps");
- zavai.registry.register_applet("wm.list", window_list);
- zavai.registry.getmenu("menu.main").add_applet("wm.list");
-
- try {
- launcher = new Launcher("Run program");
- } catch (Error e) {
- zavai.log.error("Not running launcher: " + e.message);
- launcher = null;
- }
-
- if (launcher != null)
- {
- zavai.registry.register_applet("wm.launcher", launcher);
- zavai.registry.getmenu("menu.main").add_applet("wm.launcher");
- }
- */
-}
-
-}
-}
-}