diff --git a/README.md b/README.md
index 6677d0f..b739737 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,9 @@ Actions are performed using [`dbus-send`](https://dbus.freedesktop.org/doc/dbus-
- `Restart` computer. Search strings: _reboot_, _restart_
- `PowerOff` computer. Search strings: _shutdown_, _power-off_
- `Lock` computer. Search strings: _lock_
+ - `LogOut` from current sesstion. Search string: _logout_
- `DND`, toggle Do Not Disturb mode. Search strings: _dnd_
+ - `Show/Hide battery %`, toggle battery percentage. Search string: _battery_
![screenshot](images/screenshot.png)
diff --git a/images/battery.svg b/images/battery.svg
new file mode 100644
index 0000000..14d67c1
--- /dev/null
+++ b/images/battery.svg
@@ -0,0 +1,269 @@
+
+
diff --git a/images/screenshot.png b/images/screenshot.png
index d301af7..9e20609 100644
Binary files a/images/screenshot.png and b/images/screenshot.png differ
diff --git a/images/system-log-out.svg b/images/system-log-out.svg
new file mode 100644
index 0000000..bd30fc4
--- /dev/null
+++ b/images/system-log-out.svg
@@ -0,0 +1,262 @@
+
+
diff --git a/main.py b/main.py
index 4c6c2ce..c4d987b 100644
--- a/main.py
+++ b/main.py
@@ -16,7 +16,8 @@ def __init__(self):
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
- options = ['dnd', 'lock', 'suspend', 'sleep', 'restart', 'reboot', 'shutdown', 'power-off', ]
+ options = ['dnd', 'battery', 'lock', 'logout', 'suspend',
+ 'sleep', 'restart', 'reboot', 'shutdown', 'power-off', ]
actions = []
my_list = event.query.split(" ")
if len(my_list) == 1:
@@ -46,6 +47,12 @@ def on_event(self, event, extension):
elif option in ['dnd']:
actions.append(dnd_item())
included.append('dnd')
+ elif option in ['logout']:
+ actions.append(logout_item())
+ included.append('logout')
+ elif option in ['battery']:
+ actions.append(battery_percentage_item())
+ included.append('battery')
return RenderResultListAction(actions)
@@ -53,41 +60,61 @@ def on_event(self, event, extension):
def reboot_item():
return ExtensionResultItem(icon='images/system-reboot.svg',
name='Reboot',
- description='Reboot computer',
+ description='Reboot computer.',
on_enter=RunScriptAction(SessionAction.reboot(), None))
def shutdown_item():
return ExtensionResultItem(icon='images/system-shutdown.svg',
name='Shutdown',
- description='Power off computer',
+ description='Power off computer.',
on_enter=RunScriptAction(SessionAction.power_off(), None))
def lock_screen_item():
return ExtensionResultItem(icon='images/system-lock-screen.svg',
name='Lock',
- description='Lock screen',
+ description='Lock screen.',
on_enter=RunScriptAction(SessionAction.lock(), None))
def suspend_item():
return ExtensionResultItem(icon='images/system-suspend.svg',
name='Suspend',
- description='Suspend session',
+ description='Suspend session.',
on_enter=RunScriptAction(SessionAction.suspend(), None))
+def logout_item():
+ return ExtensionResultItem(icon='images/system-log-out.svg',
+ name='Log Out',
+ description='This will close all open applications.',
+ on_enter=RunScriptAction(SessionAction.logout(), None))
+
+
+def battery_percentage_item():
+ if SessionAction.get_battery_percentage_state():
+ return ExtensionResultItem(icon='images/battery.svg',
+ name='Hide battery percentage.',
+ description='Hide battery percentage from wingpanel.',
+ on_enter=RunScriptAction(SessionAction.hide_battery_percentage(), None))
+ else:
+ return ExtensionResultItem(icon='images/battery.svg',
+ name='Show battery percentage.',
+ description='Show battery percentage in wingpanel.',
+ on_enter=RunScriptAction(SessionAction.show_battery_percentage(), None))
+
+
def dnd_item():
if SessionAction.get_dnd_state():
return ExtensionResultItem(icon='images/system-notifications.svg',
name='Disable DND',
- description='Turn off DND mode',
+ description='Turn off DND mode.',
on_enter=RunScriptAction(SessionAction.dnd_off(), None))
else:
return ExtensionResultItem(icon='images/system-notifications.svg',
name='Enable DND',
- description='Turn on DND mode',
+ description='Turn on DND mode.',
on_enter=RunScriptAction(SessionAction.dnd_on(), None))
diff --git a/utils.py b/utils.py
index 95ab99f..feb40cc 100644
--- a/utils.py
+++ b/utils.py
@@ -7,6 +7,10 @@ class SessionAction(object):
def lock(cls):
return 'dbus-send --session --type=method_call --dest=org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.Lock uint32:1'
+ @classmethod
+ def logout(cls):
+ return 'dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1/user/self org.freedesktop.login1.User.Terminate'
+
@classmethod
def reboot(cls):
return 'dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Reboot boolean:false'
@@ -27,8 +31,26 @@ def dnd_on(cls):
def dnd_off(cls):
return 'gsettings set org.pantheon.desktop.gala.notifications do-not-disturb false'
+ @classmethod
+ def show_battery_percentage(cls):
+ return 'gsettings set org.pantheon.desktop.wingpanel.indicators.power show-percentage true'
+
+ @classmethod
+ def hide_battery_percentage(cls):
+ return 'gsettings set org.pantheon.desktop.wingpanel.indicators.power show-percentage false'
+
+ @classmethod
+ def get_dnd_state(cls):
+ schema_name = 'org.pantheon.desktop.gala.notifications'
+ dnd_key = 'do-not-disturb'
+ return cls._get_state(schema_name, dnd_key)
+
+ @classmethod
+ def get_battery_percentage_state(cls):
+ schema_name = 'org.pantheon.desktop.wingpanel.indicators.power'
+ battery_percentage_key = 'show-percentage'
+ return cls._get_state(schema_name, battery_percentage_key)
+
@staticmethod
- def get_dnd_state():
- schema_name = "org.pantheon.desktop.gala.notifications"
- dnd_key = "do-not-disturb"
- return subprocess.check_output(["gsettings", "get", schema_name, dnd_key])[:-1] == 'true'
+ def _get_state(schema_name, key):
+ return subprocess.check_output(["gsettings", "get", schema_name, key])[:-1] == 'true'