From 625cbc91c5e0ce4728f8f10afb04d1c6011830d9 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Thu, 23 Nov 2023 01:23:15 -0500
Subject: [PATCH] feat(binto): switch to hyprland

---
 devices/binto/config/hypr/main.conf | 126 ++++++++++++++++++++++++++++
 devices/binto/default.nix           |   7 +-
 devices/binto/home/hyprland.nix     |  74 ++++++++++++++++
 devices/binto/home/packages.nix     |  29 ++++---
 devices/binto/modules/desktop.nix   |  44 ++++++----
 5 files changed, 253 insertions(+), 27 deletions(-)
 create mode 100644 devices/binto/config/hypr/main.conf
 create mode 100644 devices/binto/home/hyprland.nix

diff --git a/devices/binto/config/hypr/main.conf b/devices/binto/config/hypr/main.conf
new file mode 100644
index 00000000..d5d46c0a
--- /dev/null
+++ b/devices/binto/config/hypr/main.conf
@@ -0,0 +1,126 @@
+# Hypr vars
+$mainMod = SUPER
+
+
+# Monitors
+monitor=desc:Acer Technologies Acer K212HQL T3EAA0014201, 1920x1080@60,  840x1000,  1, transform, 3
+monitor=desc:BOE 0x0964,                                  1920x1200@60,  0x2920,    1
+monitor=desc:Samsung Electric Company C27JG5x HTOM100586, 2560x1440@60, 1920x120,  1
+# Desc of monitor has comma, so force its default on everything and specify everything else
+monitor=,                                                 2560x1440@165, 1920x1560, 1
+
+
+# Important stuff at launch
+exec-once = gnome-keyring-daemon --start --components=secrets
+exec-once = wl-paste --watch cliphist store
+## fix fullscreen game resolution
+exec-once = xrandr --output DP-5 --primary
+
+env = XCURSOR_SIZE,24
+exec-once = hyprctl setcursor Dracula-cursors 24
+
+
+# Autostart programs
+exec-once = bash -c "sleep 10; tmux new-session -s gsr -d 'bash -c $HOME/.config/gsr.sh'"
+# TODO: add gpu-save-replay bind
+exec-once = bash -c "sleep 5; kdeconnect-indicator"
+exec-once = bash -c "sleep 6; nextcloud --background"
+
+# Special window apps
+exec-once = [workspace special:thunder silent] thunderbird
+windowrule = workspace special:thunder silent,^(thunderbird)$
+bind = $mainMod, T, togglespecialworkspace, thunder
+
+exec-once = [workspace special:spot silent] spotify
+windowrule = workspace special:spot silent,^(Spotify)$
+bind = $mainMod, S, togglespecialworkspace, spot
+
+
+# Input settings
+input {
+    kb_layout = ca
+    kb_variant = multix
+    kb_model =
+    kb_options =
+    kb_rules =
+
+    follow_mouse = 1
+
+    touchpad {
+        natural_scroll = yes
+    }
+
+    sensitivity = 0 # -1.0 - 1.0, 0 means no modification.
+}
+
+device:razer-razer-naga-pro {
+    sensitivity = -0.5
+    accel_profile = "flat"
+}
+
+
+# Binds
+bind = $mainMod, Q, exec, alacritty
+bind = $mainMod, C, killactive,
+bind = $mainMod SHIFT, SPACE, togglefloating,
+bind = $mainMod, J, togglesplit,
+bind = SUPER, F, fullscreen
+bind = Alt Shift, Tab, cyclenext
+bind = $mainMod, V, exec, killall -r wofi || cliphist list | wofi --dmenu | cliphist decode | wl-copy
+bind =, Print, exec, bash -c 'grim -g "$(slurp)" - | swappy -f -'
+bind = $mainMod SHIFT, C, exec, wl-color-picker
+
+# Volume control
+binde =, XF86AudioRaiseVolume, exec, wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+
+binde =, XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
+
+bind =, XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle
+bind =, XF86AudioMicMute, exec, pactl set-source-mute @DEFAULT_SOURCE@ toggle
+
+# Switch workspaces with mainMod + [0-9]
+bind = $mainMod, 1, workspace, 1
+bind = $mainMod, 2, workspace, 2
+bind = $mainMod, 3, workspace, 3
+bind = $mainMod, 4, workspace, 4
+bind = $mainMod, 5, workspace, 5
+bind = $mainMod, 6, workspace, 6
+bind = $mainMod, 7, workspace, 7
+bind = $mainMod, 8, workspace, 8
+bind = $mainMod, 9, workspace, 9
+bind = $mainMod, 0, workspace, 10
+
+# Move active window to a workspace with mainMod + SHIFT + [0-9]
+bind = $mainMod SHIFT, 1, movetoworkspace, 1
+bind = $mainMod SHIFT, 2, movetoworkspace, 2
+bind = $mainMod SHIFT, 3, movetoworkspace, 3
+bind = $mainMod SHIFT, 4, movetoworkspace, 4
+bind = $mainMod SHIFT, 5, movetoworkspace, 5
+bind = $mainMod SHIFT, 6, movetoworkspace, 6
+bind = $mainMod SHIFT, 7, movetoworkspace, 7
+bind = $mainMod SHIFT, 8, movetoworkspace, 8
+bind = $mainMod SHIFT, 9, movetoworkspace, 9
+bind = $mainMod SHIFT, 0, movetoworkspace, 10
+
+# Scroll through existing workspaces with mainMod + scroll
+bind = $mainMod, mouse_down, workspace, e+1
+bind = $mainMod, mouse_up, workspace, e-1
+
+# Move/resize windows with mainMod + LMB/RMB and dragging
+bindm = $mainMod, mouse:272, movewindow
+bindm = $mainMod, mouse:273, resizewindow
+
+
+# Rules
+windowrule = tile,^(firefox)$
+
+
+# Misc
+misc {
+    disable_hyprland_logo = true
+    disable_splash_rendering = true
+    vfr = true
+}
+
+xwayland {
+	  force_zero_scaling = true
+}
diff --git a/devices/binto/default.nix b/devices/binto/default.nix
index e28cfb93..49ea3145 100644
--- a/devices/binto/default.nix
+++ b/devices/binto/default.nix
@@ -3,6 +3,7 @@
     ./hardware-configuration.nix
 
     ../../modules/audio.nix
+    ../../modules/greetd
     ../../modules/kmscon.nix
     ../../modules/printer.nix
     ../../modules/proton-bridge.nix
@@ -16,7 +17,8 @@
 
   services.device-vars = {
     username = "matt";
-    fontSize = 10.0;
+    configDir = "/home/matt/.nix/devices/binto/config";
+    fontSize = 12.5;
   };
 
   users.users.matt = {
@@ -37,7 +39,10 @@
         ../../home/alacritty.nix
         ../../home/dconf.nix
         ../../home/firefox
+        ../../home/theme.nix
+        ../../home/wofi
 
+        ./home/hyprland.nix
         ./home/packages.nix
       ];
 
diff --git a/devices/binto/home/hyprland.nix b/devices/binto/home/hyprland.nix
new file mode 100644
index 00000000..e90aa6e1
--- /dev/null
+++ b/devices/binto/home/hyprland.nix
@@ -0,0 +1,74 @@
+{ pkgs, config, hyprland, osConfig, ... }: let
+  configDir = config.services.device-vars.configDir;
+  symlink = config.lib.file.mkOutOfStoreSymlink;
+
+  polkit = pkgs.plasma5Packages.polkit-kde-agent;
+in {
+  # FIXME: steam flicker issues
+  wayland.windowManager.hyprland = {
+    enable = true;
+    enableNvidiaPatches = true;
+    package = hyprland.packages.x86_64-linux.default;
+
+    settings = {
+      # Nvidia stuff
+      env = [
+        "LIBVA_DRIVER_NAME, nvidia"
+        "XDG_SESSION_TYPE, wayland"
+        "GBM_BACKEND, nvidia-drm"
+        "__GLX_VENDOR_LIBRARY_NAME, nvidia"
+        "WLR_NO_HARDWARE_CURSORS, 1"
+      ];
+
+      exec-once = [
+        "${polkit}/libexec/polkit-kde-authentication-agent-1"
+        "${osConfig.programs.kdeconnect.package}/libexec/kdeconnectd"
+        "swww init --no-cache && swww img -t none ${pkgs.dracula-theme}/wallpapers/waves.png"
+      ];
+
+      source = [ "~/.config/hypr/main.conf" ];
+    };
+  };
+
+  xdg.configFile = {
+    "hypr/main.conf".source = symlink "${configDir}/hypr/main.conf";
+  };
+
+  home.packages = with pkgs; [
+    libnotify
+    playerctl
+    bluez-tools
+    brightnessctl
+    pulseaudio
+    libinput
+
+    ## gui
+    pavucontrol # TODO: replace with ags widget
+    networkmanagerapplet # TODO: replace with ags widget
+    blueberry # TODO: replace with ags widget
+
+
+    # Hyprland
+    swww
+    xclip
+    wl-clipboard
+    cliphist
+
+    ## gui
+    gtklock
+    wl-color-picker
+    grim
+    slurp
+    swappy
+
+    ## libs
+    qt5.qtwayland
+    qt6.qtwayland
+    xorg.xrandr
+    nvidia-vaapi-driver
+    libayatana-appindicator
+    xdg-utils
+    evtest
+    glib
+  ];
+}
diff --git a/devices/binto/home/packages.nix b/devices/binto/home/packages.nix
index 6c468fe5..7fcce0b6 100644
--- a/devices/binto/home/packages.nix
+++ b/devices/binto/home/packages.nix
@@ -1,18 +1,23 @@
 {...}: {
   # Disable compositor in X11 for best performance
   # TODO: add mic sound
-  xdg.configFile."gpu-screen-recorder.env".text = ''
-    WINDOW=focused
-    CONTAINER=mp4
-    QUALITY=very_high
-    CODEC=auto
-    AUDIO_CODEC=opus
-    FRAMERATE=60
-    REPLAYDURATION=1200
-    OUTPUTDIR=/home/matt/Videos/Replay
-    MAKEFOLDERS=yes
-    ADDITIONAL_ARGS="-s 2560x1440"
-  '';
+  xdg.configFile."gsr.sh" = {
+    executable = true;
+    text = ''
+      export WINDOW=DP-5
+      export CONTAINER=mkv
+      export QUALITY=very_high
+      export CODEC=auto
+      export AUDIO_CODEC=aac
+      export FRAMERATE=60
+      export REPLAYDURATION=1200
+      export OUTPUTDIR=/home/matt/Videos/Replay
+      export MAKEFOLDERS=yes
+      # export ADDITIONAL_ARGS=
+
+      exec /bin/sh -c 'AUDIO="''${AUDIO_DEVICE:-$(pactl get-default-sink).monitor}"; gpu-screen-recorder -v no -w $WINDOW -c $CONTAINER -q $QUALITY -k $CODEC -ac $AUDIO_CODEC -a "$AUDIO" -f $FRAMERATE -r $REPLAYDURATION -o "$OUTPUTDIR" -mf $MAKEFOLDERS $ADDITIONAL_ARGS'
+    '';
+  };
 
   xdg.desktopEntries."com.github.iwalton3.jellyfin-media-player" = {
     name = "Jellyfin Media Player";
diff --git a/devices/binto/modules/desktop.nix b/devices/binto/modules/desktop.nix
index 3f2f97e1..5984a6ba 100644
--- a/devices/binto/modules/desktop.nix
+++ b/devices/binto/modules/desktop.nix
@@ -1,28 +1,52 @@
 {
   pkgs,
-  lib,
+  hyprland,
   ...
 }: {
   programs.dconf.enable = true;
 
   services = {
     xserver = {
-      enable = true;
+      displayManager = {
+        sessionPackages = [
+          hyprland.packages.x86_64-linux.default
+        ];
+      };
 
-      # Enable the KDE Plasma Desktop Environment.
-      displayManager.sddm.enable = true;
-      desktopManager.plasma5.enable = true;
+      libinput.enable = true;
     };
+
+    greetd = {
+      settings = {
+        initial_session = {
+          command = "${hyprland.packages.x86_64-linux.default}/bin/Hyprland";
+          user = "matt";
+        };
+      };
+    };
+
     dbus.enable = true;
     gvfs.enable = true;
     flatpak.enable = true;
   };
 
+  programs.kdeconnect.enable = true;
+
+  xdg.portal = {
+    enable = true;
+    wlr.enable = true;
+    extraPortals = [
+      pkgs.xdg-desktop-portal-gtk
+    ];
+  };
+
   environment.systemPackages = with pkgs; [
     p7zip # for reshade
     xclip
     wl-clipboard
-    vlc
+
+    # FIXME: vlc stutters
+    mpv
     flat-remix-icon-theme
     nextcloud-client
     libreoffice-qt
@@ -42,12 +66,4 @@
     bluej
     xournalpp
   ];
-
-  environment.plasma5.excludePackages = with pkgs.libsForQt5; [
-    elisa
-    oxygen
-    khelpcenter
-    konsole
-    plasma-browser-integration
-  ];
 }