From 6b2beaf940a8594fb59c52f371cc0620f47dd226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Wed, 14 Dec 2016 18:11:24 +0100 Subject: [PATCH] =?UTF-8?q?i3status=20=E2=86=92=20py3status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/.config/i3/bin/calendar-widget | 17 ++++++++ files/.config/i3/config | 2 +- files/.i3/py3status/microphone.py | 63 ++++++++++++++++++++++++++++ files/.i3status.conf | 12 ++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100755 files/.config/i3/bin/calendar-widget create mode 100644 files/.i3/py3status/microphone.py diff --git a/files/.config/i3/bin/calendar-widget b/files/.config/i3/bin/calendar-widget new file mode 100755 index 0000000..d5be03e --- /dev/null +++ b/files/.config/i3/bin/calendar-widget @@ -0,0 +1,17 @@ +#!/bin/bash +# Toggles the calendar. If $1=x $2=y, the calendar bottom-right corner is +# placed at x,y. + +if ! ps -Ao "%c %u" | grep "orage" | grep -q "$(whoami)"; then + # Orage non lancé + orage > /dev/null 2>/dev/null & + sleep 0.42 +fi + +orage --toggle + +if (( $# >= 2 )); then +# sleep 0.2 + i3-msg [class='Orage'] move absolute position "$(($1 - 290))px" \ + "$(($2 - 215))px" > /dev/null +fi diff --git a/files/.config/i3/config b/files/.config/i3/config index 084b934..691f78e 100644 --- a/files/.config/i3/config +++ b/files/.config/i3/config @@ -199,7 +199,7 @@ bar { tray_output LVDS1 # position top font pango:DejaVu Sans Mono, Awesome 8 - status_command i3status + status_command py3status -dl /tmp/py3log # tray_output primary } diff --git a/files/.i3/py3status/microphone.py b/files/.i3/py3status/microphone.py new file mode 100644 index 0000000..f5bd184 --- /dev/null +++ b/files/.i3/py3status/microphone.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +""" +Displays and controls the mute status of the default microphone. + +Displays whether the current microphone is muted or not. A click on the icon +will toggle this status. Relies on pulseaudio. + +Configuration parameters: + format_muted: text displayed when muted + (default FontAwesome) + format_unmuted: text displayed when unmuted + (default FontAwesome) + +Colors: + color_mute: when muted + color_unmute: when unmuted +""" + +import subprocess + + +class Py3status: + format_muted = '\uf131' # FontAwesome + format_unmuted = '\uf130' # FontAwesome + + class Error(Exception): + pass + + def microphone(self): + isMute = self.__getMuteStatus__() + color = self.py3.COLOR_MUTE if isMute else self.py3.COLOR_UNMUTE + text = self.format_muted if isMute else self.format_unmuted + return { + 'full_text': text, + 'color': color, + } + + def __getPaList__(self): + try: + paOutput = subprocess.check_output(["pacmd", "list-sources"]) + except CalledProcessError: + raise Error() + + return paOutput.decode() + + def __getMuteStatus__(self): + paList = self.__getPaList__() + fromCurrent = paList[paList.find('* index:'):] + MUTED_STR = 'muted: ' + fromMutestat = fromCurrent[fromCurrent.find(MUTED_STR) + + len(MUTED_STR):] + return fromMutestat[:3] == 'yes' + + def __toggleMuteStatus__(self): + isMuted = self.__getMuteStatus__() + paList = self.__getPaList__() + fromCurrent = paList[paList.find('* index: ')+len('* index: '):] + sourceId = int(fromCurrent[:fromCurrent.find('\n')]) + subprocess.call(['pacmd', 'set-source-mute', str(sourceId), + str(int(not isMuted))]) + + def on_click(self, event): + self.__toggleMuteStatus__() diff --git a/files/.i3status.conf b/files/.i3status.conf index 404cb40..2f4534b 100644 --- a/files/.i3status.conf +++ b/files/.i3status.conf @@ -21,11 +21,22 @@ order += "path_exists VPN" order += "wireless wlo1" order += "ethernet eno1" #order += "volume master" +order += "microphone" order += "battery 1" +order += "arch_updates" order += "load" order += "cpu_temperature 0" order += "tztime local" +arch_updates { + format = "\uf0ed {pacman}" +} + +microphone { + color_unmute = "#E73235" + color_mute = "#FFFFFF" +} + volume master { format = " %volume" format_muted = " %volume" @@ -68,6 +79,7 @@ run_watch VPN { tztime local { format = "%d-%m-%Y %H:%M" + on_click 1 = "exec /home/tobast/.config/i3/bin/calendar-widget $X_POS $Y_POS &" } load {