From 2be0e3847b3e3bb3cfab41853bc7a1ecf7ae17c1 Mon Sep 17 00:00:00 2001 From: kiana-S Date: Fri, 9 Feb 2024 17:17:48 -0500 Subject: [PATCH] Switch from sway to hyprland --- config/login.nix | 2 +- config/packages.nix | 2 + home-manager/wayland/default.nix | 4 +- home-manager/wayland/hyprland.nix | 158 ++++++++++++++++++ home-manager/wayland/rofi/config.rasi | 5 +- home-manager/wayland/rofi/noicons.rasi | 6 - home-manager/wayland/rofi/workspace.sh | 8 - home-manager/wayland/rofi/workspacemove.sh | 8 - home-manager/wayland/sway.nix | 140 ---------------- home-manager/wayland/waybar.nix | 40 +---- .../wayland/{swaytools.nix => wltools.nix} | 0 scripts/autostart | 9 + scripts/exit | 4 + scripts/multimedia | 4 + scripts/screenshot | 4 + scripts/screenshot-slurp | 4 + 16 files changed, 194 insertions(+), 204 deletions(-) create mode 100644 home-manager/wayland/hyprland.nix delete mode 100644 home-manager/wayland/rofi/noicons.rasi delete mode 100755 home-manager/wayland/rofi/workspace.sh delete mode 100755 home-manager/wayland/rofi/workspacemove.sh delete mode 100644 home-manager/wayland/sway.nix rename home-manager/wayland/{swaytools.nix => wltools.nix} (100%) create mode 100755 scripts/autostart create mode 100755 scripts/exit create mode 100755 scripts/multimedia create mode 100755 scripts/screenshot create mode 100755 scripts/screenshot-slurp diff --git a/config/login.nix b/config/login.nix index d941565..e009dbc 100644 --- a/config/login.nix +++ b/config/login.nix @@ -22,7 +22,7 @@ lib.mkIf (config.platform != "mobile") services.xserver = { enable = true; - displayManager.defaultSession = "sway"; + displayManager.defaultSession = "hyprland"; displayManager.sddm = { enable = true; theme = "tokyo-night-sddm"; diff --git a/config/packages.nix b/config/packages.nix index 84802f2..d879bd7 100644 --- a/config/packages.nix +++ b/config/packages.nix @@ -23,6 +23,8 @@ gcc ]; + programs.hyprland.enable = true; + programs.fish.enable = true; programs.sway.enable = true; programs.sway.extraPackages = []; diff --git a/home-manager/wayland/default.nix b/home-manager/wayland/default.nix index ba603ce..f4a3402 100644 --- a/home-manager/wayland/default.nix +++ b/home-manager/wayland/default.nix @@ -6,8 +6,8 @@ }; imports = [ - ./sway.nix - ./swaytools.nix + ./hyprland.nix + ./wltools.nix ./waybar.nix ]; } diff --git a/home-manager/wayland/hyprland.nix b/home-manager/wayland/hyprland.nix new file mode 100644 index 0000000..8be5550 --- /dev/null +++ b/home-manager/wayland/hyprland.nix @@ -0,0 +1,158 @@ +{ config, pkgs, lib, ... }: +let +scripts = ../../scripts; +modifier = "SUPER"; +terminal = "alacritty"; +in { + home.packages = with pkgs; [ + swaybg + swayidle + wl-clipboard + wtype + wlroots + grim + slurp + imv + ]; + + wayland.windowManager.hyprland = { + enable = true; + enableNvidiaPatches = config.platform == "desktop"; + systemd.enable = true; + xwayland.enable = true; + + settings = { + "$mod" = modifier; + "$terminal" = terminal; + "$menu" = "rofi -show drun"; + + exec-once = [ + "${scripts}/autostart ${../../assets/background.png}" + ]; + + general = { + border_size = 3; + gaps_in = 8; + gaps_out = 8; + + cursor_inactive_timeout = 5; + resize_on_border = true; + + "col.inactive_border" = "rgb(474f6f)"; + "col.active_border" = "rgb(7bc5e4)"; + "col.nogroup_border" = "rgb(d5556f)"; + "col.nogroup_border_active" = "rgb(d5556f)"; + }; + + decoration = { + rounding = 10; + + "col.shadow" = "rgba(1a1b26c0)"; + }; + + group.groupbar = { + font_family = "JetBrainsMono Nerd Font"; + font_size = 14; + }; + + animations = { + bezier = [ "overshot, 0.13, 0.99, 0.29, 1.1" ]; + animation = [ + "windowsMove, 1, 4, overshot, slide" + "windowsIn, 1, 2, default, popin 70%" + "windowsOut, 1, 2, default, popin 70%" + "border, 1, 8, default," + "fade, 1, 8, default," + "workspaces, 1, 4, overshot, slide" + ]; + }; + + misc.disable_hyprland_logo = true; + + bind = [ + "$mod, Return, exec, $terminal" + "$mod, D, exec, $menu" + "$mod, E, exec, ${scripts}/exit" + "$mod Shift, E, exit," + "$mod, M, exec, swaylock" + + # Emacs Everywhere + "$mod, Q, exec, $HOME/.emacs.d/bin/doom +everywhere" + + # Windows + "$mod, Left, movefocus, l" + "$mod, Right, movefocus, r" + "$mod, Up, movefocus, u" + "$mod, Down, movefocus, d" + "$mod, H, movefocus, l" + "$mod, L, movefocus, r" + "$mod, K, movefocus, u" + "$mod, J, movefocus, d" + + "$mod Shift, Left, movewindow, l" + "$mod Shift, Right, movewindow, r" + "$mod Shift, Up, movewindow, u" + "$mod Shift, Down, movewindow, d" + "$mod Shift, H, movewindow, l" + "$mod Shift, L, movewindow, r" + "$mod Shift, K, movewindow, u" + "$mod Shift, J, movewindow, d" + + "$mod Shift, Q, killactive," + "$mod, G, togglegroup," + "$mod, Tab, changegroupactive, f" + "$mod Shift, Tab, changegroupactive, b" + + # Workspaces + "$mod, 1, workspace, 1" + "$mod, 2, workspace, 2" + "$mod, 3, workspace, 3" + "$mod, 4, workspace, 4" + "$mod, 5, workspace, 5" + "$mod, 6, workspace, 6" + "$mod, 7, workspace, 7" + "$mod, 8, workspace, 8" + "$mod, 9, workspace, 9" + "$mod, 0, workspace, 10" + + # Workspace Movement + "$mod Shift, 1, movetoworkspace, 1" + "$mod Shift, 2, movetoworkspace, 2" + "$mod Shift, 3, movetoworkspace, 3" + "$mod Shift, 4, movetoworkspace, 4" + "$mod Shift, 5, movetoworkspace, 5" + "$mod Shift, 6, movetoworkspace, 6" + "$mod Shift, 7, movetoworkspace, 7" + "$mod Shift, 8, movetoworkspace, 8" + "$mod Shift, 9, movetoworkspace, 9" + "$mod Shift, 0, movetoworkspace, 10" + ]; + + bindl = let + # Volume using pamixer + audio-disp = "${scripts}/multimedia Volume pamixer $(pamixer --get-volume)"; + audio = cmd: "pamixer ${cmd} && ${audio-disp}"; + # Brightness using brightnessctl + brightness-disp = ''${scripts}/multimedia Brightness brightnessctl $(brightnessctl -e -m | cut -d "," -f4 | tr -d "%")''; + brightness = x: "brightnessctl -e set ${x} && ${brightness-disp}"; + in [ + # Special XF86 key bindings + ", XF86AudioRaiseVolume, exec, ${audio "-i 2"}" + ", XF86AudioLowerVolume, exec, ${audio "-d 2"}" + "Shift, XF86AudioRaiseVolume, exec, ${audio "-i 2 --allow-boost"}" + "Shift, XF86AudioLowerVolume, exec, ${audio "-d 2 --allow-boost"}" + ", XF86AudioMute, exec, pamixer --toggle-mute" + ", XF86AudioMicMute, exec, pactl set-source-mute @DEFAULT_SOURCE@ toggle" + ", XF86MonBrightnessDown, exec, ${brightness "4%-"}" + ", XF86MonBrightnessUp, exec, ${brightness "4%+"}" + ", XF86AudioPlay, exec, playerctl play-pause" + ", XF86AudioNext, exec, playerctl next" + ", XF86AudioPrev, exec, playerctl previous" + + # Screenshot + ", Print, exec, ${scripts}/screenshot" + "Shift, Print, exec, ${scripts}/screenshot-slurp" + ]; + }; + }; +} diff --git a/home-manager/wayland/rofi/config.rasi b/home-manager/wayland/rofi/config.rasi index fd26efb..152d6c1 100644 --- a/home-manager/wayland/rofi/config.rasi +++ b/home-manager/wayland/rofi/config.rasi @@ -1,6 +1,6 @@ configuration { cycle: false; - modi: "drun,run,workspace:~/.config/rofi/workspace.sh,workspacemove:~/.config/rofi/workspacemove.sh"; + modi: "drun"; font: "JetBrainsMono Nerd Font 14"; location: 0; terminal: "alacritty"; @@ -10,9 +10,6 @@ configuration { drun-display-format: "{name}"; display-drun: "  Apps "; - display-run: "  Run "; - display-workspace: "  Workspace "; - display-workspacemove: "  Move to Workspace "; // Bindings kb-remove-to-eol: ""; diff --git a/home-manager/wayland/rofi/noicons.rasi b/home-manager/wayland/rofi/noicons.rasi deleted file mode 100644 index 3ea7a8f..0000000 --- a/home-manager/wayland/rofi/noicons.rasi +++ /dev/null @@ -1,6 +0,0 @@ - -@import "config.rasi" - -configuration { - show-icons: false; -} diff --git a/home-manager/wayland/rofi/workspace.sh b/home-manager/wayland/rofi/workspace.sh deleted file mode 100755 index 707441e..0000000 --- a/home-manager/wayland/rofi/workspace.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -if [ $# -ne 0 ]; then - swaymsg workspace "$@" > /dev/null -else - swaymsg -t get_workspaces | - jq -r 'map(.name) + ["10:browser","20:terminal","30:code","40:files","50:discord","60:settings"] | unique | .[]' -fi diff --git a/home-manager/wayland/rofi/workspacemove.sh b/home-manager/wayland/rofi/workspacemove.sh deleted file mode 100755 index 1a68a01..0000000 --- a/home-manager/wayland/rofi/workspacemove.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -if [ $# -ne 0 ]; then - swaymsg move container to workspace "$@" > /dev/null -else - swaymsg -t get_workspaces | - jq -r 'map(.name) + ["10:browser","20:terminal","30:code","40:files","50:discord","60:settings"] | unique | .[]' -fi diff --git a/home-manager/wayland/sway.nix b/home-manager/wayland/sway.nix deleted file mode 100644 index 75d85e4..0000000 --- a/home-manager/wayland/sway.nix +++ /dev/null @@ -1,140 +0,0 @@ -{ pkgs, lib, ... }: -let -modifier = "Mod4"; -terminal = "alacritty"; -in { - home.packages = with pkgs; [ - swayidle - wl-clipboard - wtype - wlroots - grim - slurp - imv - ]; - - wayland.windowManager.sway = { - enable = true; - wrapperFeatures.gtk = true; - config = { - inherit modifier terminal; - menu = "rofi -show drun"; - - fonts = { - names = [ "JetBrainsMono Nerd Font" ]; - style = "Medium"; - size = 10.0; - }; - - bars = [{ command = "waybar"; }]; - - window.border = 3; - gaps = { - inner = 8; - outer = 0; - }; - colors = { - unfocused.border = "#474f6f"; - unfocused.background = "#1a1b26"; - unfocused.text = "#a9b1d6"; - unfocused.indicator = "#474f6f"; - unfocused.childBorder = "#474f6f"; - - focused.border = "#7bc5e4"; - focused.background = "#1a1b26"; - focused.text = "#a9b1d6"; - focused.indicator = "#7bc5e4"; - focused.childBorder = "#7bc5e4"; - - focusedInactive.border = "#787c99"; - focusedInactive.background = "#1a1b26"; - focusedInactive.text = "#a9b1d6"; - focusedInactive.indicator = "#787c99"; - focusedInactive.childBorder = "#787c99"; - - urgent.border = "#d5556f"; - urgent.background = "#444b6a"; - urgent.text = "#ffffff"; - urgent.indicator = "#d5556f"; - urgent.childBorder = "#d5556f"; - }; - - startup = map (x: { command = x; }) [ - ''swayidle timeout 120 'swaylock -f --grace=180' \ - timeout 600 'systemctl suspend' \ - before-sleep 'swaylock -f' '' - ''export XDG_SESSION_TYPE=wayland'' - ''export XDG_CURRENT_DESKTOP=sway'' - ]; - - keybindings = let - multimedia = summary: app: value: - '' - notify-send ${summary} -c multimedia -a ${app} \ - $(makoctl list | jq -r 'first(.data[][]|select(.category.data=="multimedia")|.id.data|["-r",.])[]') \ - -h INT:value:$(${value}) - ''; - # Volume using pamixer - audio-disp = multimedia "Volume" "pamixer" "pamixer --get-volume"; - audio = cmd: "exec pamixer ${cmd} && ${audio-disp}"; - # Brightness using brightnessctl - brightness-disp = multimedia "Brightness" "brightnessctl" ''brightnessctl -e -m | cut -d "," -f4 | tr -d "%"''; - brightness = x: "exec brightnessctl -e set ${x} && ${brightness-disp}"; - # Play controls using playerctl - playerctl = cmd: "exec playerctl ${cmd}"; - # Grim screenshot file name - filename = ''~/Pictures/$(date +%Y-%m-%d_%H-%M-%S).png''; - in pkgs.lib.mkOptionDefault { - "${modifier}+Shift+d" = "exec rofi -show run -config ~/.config/rofi/noicons.rasi"; - "${modifier}+w" = "exec rofi -show workspace -config ~/.config/rofi/noicons.rasi"; - "${modifier}+Shift+w" = "exec rofi -show workspacemove -config ~/.config/rofi/noicons.rasi"; - - "${modifier}+t" = "layout tabbed"; - "${modifier}+Shift+m" = "exec swaylock"; - - # Emacs Everywhere - "${modifier}+q" = "exec ~/.emacs.d/bin/doom +everywhere"; - - # Screenshot - "Print" = ''exec grim ${filename}''; - "Shift+Print" = ''exec grim -g "$(slurp)" ${filename}''; - "Mod1+Print" = ''exec grim -g "$(swaymsg -t get_tree | jq -j '.. | \ - select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"')" ${filename}''; - - # Special XF86 key bindings - "XF86AudioRaiseVolume" = audio "-i 2"; - "XF86AudioLowerVolume" = audio "-d 2"; - "Shift+XF86AudioRaiseVolume" = audio "-i 2 --allow-boost"; - "Shift+XF86AudioLowerVolume" = audio "-d 2 --allow-boost"; - "XF86AudioMute" = ''exec pamixer --toggle-mute''; - "XF86AudioMicMute" = ''exec pactl set-source-mute @DEFAULT_SOURCE@ toggle''; - "XF86MonBrightnessDown" = brightness "4%-"; - "XF86MonBrightnessUp" = brightness "4%+"; - "XF86AudioPlay" = playerctl "play-pause"; - "XF86AudioNext" = playerctl "next"; - "XF86AudioPrev" = playerctl "previous"; - - # Exit - "${modifier}+Shift+e" = ''exec pkill -0 swaynag || \ - swaynag -t exit -m "Do you really want to exit?" \ - -B "Reboot" "reboot" -B "Shutdown" "poweroff" -b "Exit" "swaymsg exit"''; - - # Workspaces - "${modifier}+1" = "workspace 10:browser"; - "${modifier}+2" = "workspace 20:terminal"; - "${modifier}+3" = "workspace 30:code"; - "${modifier}+4" = "workspace 40:files"; - "${modifier}+5" = "workspace 50:discord"; - "${modifier}+6" = "workspace 60:settings"; - "${modifier}+Shift+1" = "move container to workspace 10:browser"; - "${modifier}+Shift+2" = "move container to workspace 20:terminal"; - "${modifier}+Shift+3" = "move container to workspace 30:code"; - "${modifier}+Shift+4" = "move container to workspace 40:files"; - "${modifier}+Shift+5" = "move container to workspace 50:discord"; - "${modifier}+Shift+6" = "move container to workspace 60:settings"; - }; - - output."*".bg = "${../../assets/background.png} fill"; - }; - }; -} diff --git a/home-manager/wayland/waybar.nix b/home-manager/wayland/waybar.nix index 00b75b9..c3f11bf 100644 --- a/home-manager/wayland/waybar.nix +++ b/home-manager/wayland/waybar.nix @@ -10,8 +10,9 @@ margin = "8 8 0"; - modules-left = [ "sway/workspaces" "sway/mode" "custom/sep" "cpu" "memory" "temperature" ]; - modules-center = [ "sway/window" ]; + modules-left = [ "hyprland/workspaces" "custom/sep" "cpu" "memory" "temperature" ]; + + modules-center = [ "hyprland/window" ]; modules-right = if config.platform == "laptop" then @@ -21,33 +22,6 @@ modules = { - "sway/workspaces" = { - disable-scroll = true; - all-outputs = true; - numeric-first = true; - format = "{icon}"; - - persistent_workspaces = { - "10:browser" = []; - "20:terminal" = []; - "30:code" = []; - "40:files" = []; - "50:discord" = []; - "60:settings" = []; - }; - - format-icons = { - browser = "${spanfa}"; - terminal = "${spanfa}"; - code = "${spanfa}"; - files = "${spanfa}"; - discord = "${spanfa}"; - settings = "${spanfa}"; - }; - }; - "sway/mode" = { - format = "{}"; - }; "mpd" = { format = "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) ⸨{songPosition}|{queueLength}⸩ "; format-disconnected = "Disconnected "; @@ -200,17 +174,13 @@ background: @background; border: none; padding: 0px 3px; + text-shadow: 0px 0px 2px shade(@blue, 1.1); } - #workspaces button.persistent {color: @empty;} - #workspaces button.focused { + #workspaces button.active { color: shade(@pink, 1.1); text-shadow: 0px 0px 2px shade(@pink, 1.2); } - #workspaces button.urgent { - background-color: @altred; - color: #ffffff; - } #clock, #battery, diff --git a/home-manager/wayland/swaytools.nix b/home-manager/wayland/wltools.nix similarity index 100% rename from home-manager/wayland/swaytools.nix rename to home-manager/wayland/wltools.nix diff --git a/scripts/autostart b/scripts/autostart new file mode 100755 index 0000000..b0e474d --- /dev/null +++ b/scripts/autostart @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +swaybg -o '*' -i "$1" -m fill & + +waybar & + +swayidle timeout 120 'swaylock -f --grace=180' \ + timeout 600 'systemctl suspend' \ + before-sleep 'swaylock -f' & diff --git a/scripts/exit b/scripts/exit new file mode 100755 index 0000000..74fc278 --- /dev/null +++ b/scripts/exit @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +pkill -0 swaynag || \ + swaynag -t exit -m "Do you really want to exit?" \ + -B "Reboot" "reboot" -B "Shutdown" "poweroff" -b "Exit" "hyprctl dispatch exit" diff --git a/scripts/multimedia b/scripts/multimedia new file mode 100755 index 0000000..184b014 --- /dev/null +++ b/scripts/multimedia @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +notify-send "$1" -c multimedia -a "$2" \ + $(makoctl list | jq -r 'first(.data[][]|select(.category.data=="multimedia")|.id.data|["-r",.])[]') \ + -h "INT:value:$3" diff --git a/scripts/screenshot b/scripts/screenshot new file mode 100755 index 0000000..531758e --- /dev/null +++ b/scripts/screenshot @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +grim - | wl-copy +notify-send "Screenshot saved to clipboard" \ + -a grim -c screenshot -u low diff --git a/scripts/screenshot-slurp b/scripts/screenshot-slurp new file mode 100755 index 0000000..b5ecb02 --- /dev/null +++ b/scripts/screenshot-slurp @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +grim -g "$(slurp)" - | wl-copy +notify-send "Screenshot saved to clipboard" \ + -a grim -c screenshot -u low