From 349355938e0845910b9a5594b2cd01e4785dd27d Mon Sep 17 00:00:00 2001 From: zoe Date: Mon, 15 May 2023 09:56:19 +0200 Subject: [PATCH] add sway --- home.nix | 1 + sway/__pycache__/audiotools.cpython-311.pyc | Bin 0 -> 2531 bytes sway/audiotools.py | 58 +++++ sway/brightness.py | 47 ++++ sway/config.nix | 234 ++++++++++++++++++++ sway/i3status-rust.nix | 8 + sway/mainbar.nix | 88 ++++++++ sway/play_pause.py | 8 + sway/settings.nix | 7 + sway/volume.py | 11 + sync.sh | 2 +- 11 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 sway/__pycache__/audiotools.cpython-311.pyc create mode 100755 sway/audiotools.py create mode 100755 sway/brightness.py create mode 100644 sway/config.nix create mode 100644 sway/i3status-rust.nix create mode 100644 sway/mainbar.nix create mode 100644 sway/play_pause.py create mode 100644 sway/settings.nix create mode 100644 sway/volume.py diff --git a/home.nix b/home.nix index a85b0b9..264d01c 100644 --- a/home.nix +++ b/home.nix @@ -7,6 +7,7 @@ in ./fish/settings.nix ./variables.nix ./i3/settings.nix + ./sway/settings.nix ./kitty/settings.nix ./rofi/settings.nix ./i3/i3status-rust.nix diff --git a/sway/__pycache__/audiotools.cpython-311.pyc b/sway/__pycache__/audiotools.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f6631ac077f0cd0968008f5dee2aacdb2e78eb03 GIT binary patch literal 2531 zcmb7GYiJx*6ux(6XZDrZ%xoX2SzD&o+OFhbn}s$}YMYoA1=G~1rLhv$y_3z<-JLLx zHctprBrUOxq9p$kil&to^pBvRAo{02vtc32V6jwGf#xx3kQCrzbZ?wot> z>zsSfIrlqrT@V5YO3P0Ji9a}mexaRGVb+=Zb-+v^f(TBbZbX=is2dYjVR{+jx#;O; z30L5G;5`I)p{RF>ZtX~{3n(;xpe%g%f5Qc7m@r9Z6#0<}{Zcts<_SwYNyaQqKzpuq z9(0SF1O8^YKZ+kIgC}0%o27amD#T9$w}Ng-NzY?yWLz3OCE=us2%Bpg!LwlBhszuc z-7F82&=X~TmM^mvjC=hY*z0E5W+Tl1)sbXJ&=5#>%faC5F0=<>w{Oa~Od?W!4R5~l zOkwW;dj?&=QL$r09Q}f|ibJJnl-=B&PDtf|9*}P%KP0NU4$`Q>nZC_e3<0Njz zhkW(*y_%kmn?urYTsKw291R49P1Q^(qtNI5Ssn$it;2qgJReb>%A< zD=r?5GB#h7U~`2b+efU7VXD1@7B%m^t6#{&qdJYGD63aNW6@jEVJiZRGcz|OXEd`< z%_L=0lMO|Y`xISiXlRIf?SNsu)30j@#V~BHQ|nhUwx{#u&UTwG9^YnlD`N)}S~_iI z)I{7=Y@R3yjVMvpW>lhkL4_U6Xcu~@VL*pLBUP5=wf&8KT3Trw(v-%AgqG=5lZ_d5 zKr zwa+>nlImfD6ow5_*zx;>(1S4Ax(j4&3)X-vAS;xN2OrcT|CWi+T`FhCRP{&Iv;3lb za6vwpm18+M_T{OZd}vWVvLGMH%13kZ(X4nZCmzd-kwtOeg19d$Mss5H#_pV0=XgCr z$O)ioX*tLV(lYDygAyQ)o2)t_rWf^vCqnZzuN3R;*RnMyv%b!puXDbluCA^c)bH=N z1=_;s$8eRtUBd-8D<5({EJfXO7J!8ep&8b0sUwUtd|iq zTYh7uG1?Nwy^pXJDDfDm@(8J(4N|!ZsheUC0W@{v<>nYge2=-#zj2-WL`4h&L~x+Z8oWxHvekeFcp1>Ih$FcwphdR61CzQe#-{(_8Q*1^fwfEudHF} zx&U)_RiaNxyxRk?(+|kQsu|PfjQ*5L8&g;NZLhAtlT0XpPuMUh!pb^D9$NyPJw^RJ z=e3lTR&<&k_rhm<3S-Er7`YJ?JaB6(8&kAD;VHkggJegFFHmU-Ws%Phn3D+q|=Cih`GigJY$ z6wp@R2LpvT(5a5kk$#X4(12O int: + s: str = str(subprocess.check_output(["amixer", "get", "Master"])) + try: + # turns the front left argument into an int + return int( + # the thing we're looking for is in the fifth line + s.split(r"\n")[5] + .strip() + # and is the 4th word + .split(" ")[4] + .replace("[", "") + .replace("]", "") + .replace("%", "") + ) + except: + return -1 + + +def display_volume(volume: int): + subprocess.call( + ["dunstify", "volume 蓼", "-h", "int:value:" + str(volume), "-r", "39489384"] + ) diff --git a/sway/brightness.py b/sway/brightness.py new file mode 100755 index 0000000..53cc459 --- /dev/null +++ b/sway/brightness.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +import subprocess +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("brightnesschange") +args = parser.parse_args() + + +def get_brightness() -> str: + return str( + ( + int( + subprocess.check_output( + ["cat", "/sys/class/backlight/intel_backlight/brightness"] + ) + ) + / int( + subprocess.check_output( + ["cat", "/sys/class/backlight/intel_backlight/max_brightness"] + ) + ) + * 100 + ).__round__() + ) + + +subprocess.check_output( + [ + "brightnessctl", + "set", + args.brightnesschange, + ] +) + +print(get_brightness()) + +subprocess.call( + [ + "dunstify", + "brightness", + "-h", + "int:value:" + get_brightness(), + "-r", + "294893284", + ] +) diff --git a/sway/config.nix b/sway/config.nix new file mode 100644 index 0000000..9c1775f --- /dev/null +++ b/sway/config.nix @@ -0,0 +1,234 @@ +{ pkgs, lib, config, ... }: +let + mod = "Mod4"; + term = "kitty"; + color_bg = "#${config.color.background}"; + color_fg = "#${config.color.foreground}"; + color_active = "#${config.color.green}"; + color_inactive = "#${config.color.cyan}"; + color_indicator = "#${config.color.magenta}"; + color_evil = "#${config.color.red}"; + ws1 = "1"; + ws2 = "2"; + ws3 = "3"; + ws4 = "4"; + ws5 = "5"; + ws6 = "6"; + ws7 = "7"; + ws8 = "8"; + ws9 = "9"; + ws10 = "10"; +in +{ + home-manager.users.zoe.wayland.windowManager.sway.config = { + modifier = mod; + terminal = term; + menu = + "exec rofi -combi-modi window#drun#ssh -show-icons -show combi -modi combi"; + fonts = { + names = [ "CaskaydiaCove Nerd Font" ]; + size = 11.0; + }; + + colors = { + background = color_bg; + focused = { + background = color_bg; + border = color_active; + childBorder = color_active; + indicator = color_indicator; + text = color_fg; + }; + focusedInactive = { + background = color_bg; + border = color_inactive; + childBorder = color_inactive; + indicator = color_indicator; + text = color_fg; + }; + unfocused = { + background = color_bg; + border = color_inactive; + childBorder = color_inactive; + indicator = color_indicator; + text = color_fg; + }; + urgent = { + background = color_bg; + border = color_evil; + childBorder = color_evil; + indicator = color_indicator; + text = color_fg; + }; + }; + + keybindings = lib.mkOptionDefault { + # launch things + ## calculator + "${mod}+c" = "exec rofi -show calc"; + ## emoji + "${mod}+period" = "exec kaokao | xclip -selection clipboard"; + ## THE PICTURES + "${mod}+s" = "exec flameshot gui --clipboard"; + + ## find mouse cursor + "${mod}+x" = + "exec find-cursor --color '#282828' -o 2 --outline-color '#EBDBB2'"; + + ## modes + "${mod}+r" = "mode resize"; + "${mod}+b" = "mode brightness"; + "${mod}+m" = "mode media"; + "${mod}+w" = "mode move"; + "${mod}+v" = "mode focus"; + + ## workspaces + "${mod}+Tab" = "workspace next"; + "${mod}+q" = "exec i3layouts-rofi"; + + ## tablet to next screen + "${mod}+p" = "exec xsetwacom set 'Wacom Intuos S 2 Pen stylus' MapToOutput next"; + }; + + modes = { + resize = { + Escape = "mode default"; + v = "mode focus"; + w = "mode move"; + j = "resize grow height 10 px or 10 ppt"; + l = "resize shrink width 10 px or 10 ppt"; + h = "resize grow width 10 px or 10 ppt"; + k = "resize shrink height 10 px or 10 ppt"; + }; + brightness = { + Escape = "mode default"; + k = "exec /etc/nixos/i3/brightness.py 10+"; + j = "exec /etc/nixos/i3/brightness.py 10-"; + }; + media = { + Escape = "mode default"; + j = "exec --no-startup-id python3 /etc/nixos/i3/volume.py 1%-"; + k = "exec --no-startup-id python3 /etc/nixos/i3/volume.py 1%+"; + m = "exec --no-startup-id amixer set Master toggle"; + n = "exec --no-startup-id amixer set Capture toggle"; + p = "exec --no-startup-id playerctld shift"; + "Shift+j" = "exec --no-startup-id playerctl volume 0.05-"; + "Shift+k" = "exec --no-startup-id playerctl volume 0.05+"; + space = "exec --no-startup-id playerctl play-pause"; + l = "exec playerctl next"; + h = "exec playerctl previous"; + }; + move = { + Escape = "mode default"; + v = "mode focus"; + r = "mode resize"; + j = "exec i3l move down"; + k = "exec i3l move up"; + h = "exec i3l move left"; + l = "exec i3l move right"; + s = "exec i3l swap container with previous"; + Tab = "exec i3-msg move workspace next && i3-msg workspace next"; + "1" = "move workspace ${ws1}"; + "2" = "move workspace ${ws2}"; + "3" = "move workspace ${ws3}"; + "4" = "move workspace ${ws4}"; + "5" = "move workspace ${ws5}"; + "6" = "move workspace ${ws6}"; + "7" = "move workspace ${ws7}"; + "8" = "move workspace ${ws8}"; + "9" = "move workspace ${ws9}"; + "0" = "move workspace ${ws10}"; + }; + focus = { + Escape = "mode default"; + w = "mode move"; + r = "mode resize"; + h = "focus left"; + j = "focus down"; + k = "focus up"; + l = "focus right"; + Tab = "workspace next"; + "1" = "workspace ${ws1}"; + "2" = "workspace ${ws2}"; + "3" = "workspace ${ws3}"; + "4" = "workspace ${ws4}"; + "5" = "workspace ${ws5}"; + "6" = "workspace ${ws6}"; + "7" = "workspace ${ws7}"; + "8" = "workspace ${ws8}"; + "9" = "workspace ${ws9}"; + "0" = "workspace ${ws10}"; + }; + }; + + window = { + titlebar = false; + border = 4; + }; + gaps = { + inner = 0; + outer = 0; + }; + + bars = [{ + position = "top"; + command = "waybar"; + statusCommand = + "i3status-rs $HOME/.config/i3status-rust/config-main.toml"; + fonts = { + names = [ "CaskaydiaCove Nerd Font" ]; + size = 11.0; + }; + colors = { + background = color_bg; + activeWorkspace = { + border = color_active; + background = color_bg; + text = color_active; + }; + inactiveWorkspace = { + border = color_bg; + background = color_bg; + text = color_inactive; + }; + focusedWorkspace = { + border = color_active; + background = color_active; + text = color_bg; + }; + bindingMode = { + background = color_bg; + border = color_bg; + text = color_fg; + }; + }; + }]; + + startup = [ + { + command = "--no-startup-id feh --bg-scale /etc/nixos/wallpaper.png"; + always = true; + } + { + command = "picom --experimental-backends"; + always = true; + } + { + command = "--no-startup-id i3-layouts"; + always = true; + } + ]; + }; + home-manager.users.zoe.xsession.windowManager.i3.extraConfig = '' + set $i3l companion to workspace 1 + set $i3l companion to workspace 2 + set $i3l companion to workspace 3 + set $i3l companion to workspace 4 + set $i3l companion to workspace 5 + set $i3l companion to workspace 6 + set $i3l companion to workspace 7 + set $i3l companion to workspace 8 + set $i3l companion to workspace 9 + set $i3l companion to workspace 10 + ''; +} diff --git a/sway/i3status-rust.nix b/sway/i3status-rust.nix new file mode 100644 index 0000000..95a9825 --- /dev/null +++ b/sway/i3status-rust.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: { + imports = [ ./mainbar.nix ]; + + home-manager.users.zoe.programs.i3status-rust = { + enable = true; + package = pkgs.unstable.i3status-rust; + }; +} diff --git a/sway/mainbar.nix b/sway/mainbar.nix new file mode 100644 index 0000000..b15069f --- /dev/null +++ b/sway/mainbar.nix @@ -0,0 +1,88 @@ +{ config, ... }: + let + music = { + block = "music"; + format = "{$icon $player {$volume_icon $volume|} $play $combo.str(max_w:25,rot_interval:0.5)|}"; + }; + pomodoro = { + block = "pomodoro"; + }; + in +{ + home-manager.users.zoe.programs.i3status-rust.bars.main = { + blocks = [ + music + # audio in + { + block = "sound"; + device_kind = "source"; + format = "$icon"; + driver = "pulseaudio"; + step_width = 1; + } + + # audio out + { + block = "sound"; + format = "{$icon $volume|$icon}"; + driver = "pulseaudio"; + headphones_indicator = true; + step_width = 1; + } + + # brightness + { + block = "backlight"; + } + + # network + { + block = "net"; + format = "$icon $device {$signal_strength $ssid |󰈁}"; + } + + # battery + { + block = "battery"; + driver = "upower"; + format = "$icon $percentage $power"; + full_format = "$icon $percentage $power"; + empty_format = "$icon $percentage $power"; + not_charging_format = "$icon $percentage $power"; + } + pomodoro + # time + { + block = "time"; + format = "$icon $timestamp.datetime(f:%R)"; + timezone = "Europe/Berlin"; + interval = 60; + } + ]; + + settings = { + icons = {icons = "material-nf";}; + theme = { + theme = "gruvbox-light"; + overrides = { + separator = " "; + # background + good_bg = "#${config.color.background}"; + critical_bg = "#${config.color.background}"; + idle_bg = "#${config.color.background}"; + info_bg = "#${config.color.background}"; + seperator_bg = "#${config.color.background}"; + warning_bg = "#${config.color.background}"; + + # foreground + critical_fg = "#${config.color.red}"; + good_fg = "#${config.color.green}"; + info_fg = "#${config.color.foreground}"; + idle_fg = "#${config.color.cyan}"; + separator_fg = "#${config.color.foreground}"; + warning_fg = "#${config.color.yellow}"; + }; + }; + }; + }; +} diff --git a/sway/play_pause.py b/sway/play_pause.py new file mode 100644 index 0000000..4e047c4 --- /dev/null +++ b/sway/play_pause.py @@ -0,0 +1,8 @@ +import subprocess +import audiotools + +try: + subprocess.Popen(["playerctl", "play-pause"]).wait() + audiotools.show_now_playing() +except: + pass diff --git a/sway/settings.nix b/sway/settings.nix new file mode 100644 index 0000000..b77a563 --- /dev/null +++ b/sway/settings.nix @@ -0,0 +1,7 @@ +{ pkgs, lib, ... }: { + imports = [ ./config.nix ]; + home-manager.users.zoe.wayland.windowManager.sway = { + package = pkgs.sway; + enable = true; + }; +} diff --git a/sway/volume.py b/sway/volume.py new file mode 100644 index 0000000..b2eba27 --- /dev/null +++ b/sway/volume.py @@ -0,0 +1,11 @@ +# script that changes the volume and then shows a notfication with it using dunst +import subprocess +import argparse +import audiotools + +parser = argparse.ArgumentParser() +parser.add_argument("volchange") +args = parser.parse_args() + +subprocess.check_output(["amixer", "set", "Master", args.volchange]) +audiotools.display_volume(audiotools.get_amixer_volume()) diff --git a/sync.sh b/sync.sh index fc08189..940ac66 100755 --- a/sync.sh +++ b/sync.sh @@ -7,7 +7,7 @@ git pull # cp -r /etc/nixos/ ./backup # copy over all the files to /etc/nixos/ -sudo cp -ru ./flake.nix ./configuration.nix ./wallpaper.png ./dunst ./helix ./rofi ./i3 ./fish ./kitty ./nvim/ ./disks.nix ./variables.nix ./programs.nix ./defaults.nix ./packages.nix ./home.nix ./services.nix ./user.nix /etc/nixos/ +sudo cp -ru ./flake.nix ./configuration.nix ./wallpaper.png ./dunst ./helix ./rofi ./i3 ./sway ./fish ./kitty ./nvim/ ./disks.nix ./variables.nix ./programs.nix ./defaults.nix ./packages.nix ./home.nix ./services.nix ./user.nix /etc/nixos/ cp -u ./.xinitrc $HOME