From 6b7bef9c07bcb5af2a21776a1e404a224ee54134 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Fri, 20 Sep 2024 18:58:17 +0300 Subject: [PATCH] [~] Refactor --- d1/f1.sh | 1 + dotfiles/.local/bin/commands | 41 ++++++++++++++++++------- dotfiles/.sway/config | 17 +++++----- dotfiles/etc/udev/rules.d/40-leds.rules | 1 + 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/d1/f1.sh b/d1/f1.sh index 30dc164..821f204 100644 --- a/d1/f1.sh +++ b/d1/f1.sh @@ -7,6 +7,7 @@ cp dotfiles/.sway/config ~/.sway/config cp dotfiles/.zshenv ~/.zshenv cp dotfiles/.zshrc ~/.zshrc cp dotfiles/.vimrc ~/.vimrc +cp dotfiles/.tmux.conf ~/.tmux.conf cp dotfiles/.py3.vimrc ~/.py3.vimrc cp dotfiles/.py3.vimrc ~/.py3.vimrc cp dotfiles/.gitconfig ~/.gitconfig diff --git a/dotfiles/.local/bin/commands b/dotfiles/.local/bin/commands index b1a10f4..a026acd 100755 --- a/dotfiles/.local/bin/commands +++ b/dotfiles/.local/bin/commands @@ -161,8 +161,12 @@ def intercept_output( def player_metadata(): for k in range(20): try: + metadata = { + k : subprocess.check_output(['playerctl', 'metadata', k]).decode('utf-8').strip() + for k in ['artist', 'title'] + } + return '%s - %s' % (metadata['artist'], metadata['title']) time.sleep(1.0) - return subprocess.check_output(['playerctl', 'metadata']).decode('utf-8').strip() except: continue @@ -2508,15 +2512,16 @@ def desktop_services(argv): self.bg is None or \ not self.bg.poll() is None ) and not self.bg_terminate: - self.bg = subprocess.Popen([ - 'swaybg', - '--output', - '*', - '--image', - options.background_image, - '--mode', - 'fill', - ]) + if not options.background_image is None: + self.bg = subprocess.Popen([ + 'swaybg', + '--output', + '*', + '--image', + options.background_image, + '--mode', + 'fill', + ]) def background_terminate(self, *args, **kwargs): if not self.bg is None: @@ -3267,6 +3272,8 @@ def media_keys(argv): 'media-next', 'media-prev', 'media-lower-volume', + 'media-raise-volume', + 'media-toggle-volume', ] msg = None @@ -3288,7 +3295,7 @@ def media_keys(argv): ]) return t2['Title'].strip()[:128] - if is_mocp: + if is_mocp(): mode = 'mocp' else: mode = 'playerctl' @@ -3332,6 +3339,18 @@ def media_keys(argv): 'get-sink-volume', '@DEFAULT_SINK@' ]).decode('utf-8').strip() + elif options.command == 'media-toggle-volume': + subprocess.check_call([ + 'pactl', + 'set-sink-mute', + '@DEFAULT_SINK@', + 'toggle', + ]) + msg = subprocess.check_output([ + 'pactl', + 'get-sink-volume', + '@DEFAULT_SINK@' + ]).decode('utf-8').strip() elif options.command == 'media-raise-volume': subprocess.check_call([ 'pactl', diff --git a/dotfiles/.sway/config b/dotfiles/.sway/config index 97255be..b2ad10b 100644 --- a/dotfiles/.sway/config +++ b/dotfiles/.sway/config @@ -84,33 +84,36 @@ bindgesture swipe:4:up exec $lock_cmd # bindsym $mod+Shift+l exec $lock_cmd -bindsym XF86KbdBrightnessDown \ +bindsym --locked XF86KbdBrightnessDown \ exec commands \ desktop-services \ --backlight-decrease \ --backlight-type keyboard -bindsym XF86KbdBrightnessUp \ +bindsym --locked XF86KbdBrightnessUp \ exec commands \ desktop-services \ --backlight-increase \ --backlight-type keyboard -bindsym XF86MonBrightnessDown \ +bindsym --locked XF86MonBrightnessDown \ exec commands \ desktop-services \ --backlight-decrease \ --backlight-type output -bindsym XF86MonBrightnessUp \ +bindsym --locked XF86MonBrightnessUp \ exec commands \ desktop-services \ --backlight-increase \ --backlight-type output -bindsym XF86AudioPlay exec bash -c "commands media-play-pause" -bindsym XF86AudioNext exec bash -c "commands media-next" -bindsym XF86AudioPrev exec bash -c "commands media-prev" +bindsym --locked XF86AudioPlay exec bash -c "commands media-play-pause" +bindsym --locked XF86AudioRaiseVolume exec bash -c "commands media-raise-volume" +bindsym --locked XF86AudioLowerVolume exec bash -c "commands media-lower-volume" +bindsym --locked XF86AudioMute exec bash -c "commands media-toggle-volume" +bindsym --locked XF86AudioNext exec bash -c "commands media-next" +bindsym --locked XF86AudioPrev exec bash -c "commands media-prev" # Start a terminal diff --git a/dotfiles/etc/udev/rules.d/40-leds.rules b/dotfiles/etc/udev/rules.d/40-leds.rules index c1a55ed..1b82b85 100644 --- a/dotfiles/etc/udev/rules.d/40-leds.rules +++ b/dotfiles/etc/udev/rules.d/40-leds.rules @@ -1,2 +1,3 @@ ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/pci0000:00/0000:00:1b.0/hdaudioC0D0/leds/hda::mute", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" ACTION=="add|change", SUBSYSTEM=="leds", DEVPATH=="/devices/platform/applesmc.768/leds/smc::kbd_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness" +ACTION=="add|change", DEVPATH=="/class/backlight/intel_backlight", RUN{program}+="/usr/bin/chmod 666 /sys$devpath/brightness"