From 8283480fd1ade430fe2829e63cfe45b4ab3d268b Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 2 Apr 2023 15:52:45 -0400 Subject: [PATCH] rofi brightness menu --- modules/nixos/graphical/default.nix | 4 ++ modules/nixos/graphical/i3.nix | 2 + modules/nixos/graphical/rofi.nix | 2 +- modules/nixos/graphical/rofi/brightness.nix | 49 +++++++++++++++++++ modules/nixos/graphical/rofi/brightness.sh | 10 ---- modules/nixos/graphical/rofi/power.nix | 5 +- modules/nixos/graphical/rofi/rofi-prompt.sh | 3 ++ .../graphical/rofi/themes/brightness.rasi | 6 +++ .../nixos/graphical/rofi/themes/common.rasi | 5 -- .../nixos/graphical/rofi/themes/power.rasi | 5 ++ 10 files changed, 74 insertions(+), 17 deletions(-) create mode 100755 modules/nixos/graphical/rofi/brightness.nix delete mode 100755 modules/nixos/graphical/rofi/brightness.sh create mode 100644 modules/nixos/graphical/rofi/themes/brightness.rasi diff --git a/modules/nixos/graphical/default.nix b/modules/nixos/graphical/default.nix index a2927bd..4e2173e 100644 --- a/modules/nixos/graphical/default.nix +++ b/modules/nixos/graphical/default.nix @@ -21,6 +21,10 @@ type = lib.types.str; description = "Command to use for switching audio sink"; }; + brightnessCommand = lib.mkOption { + type = lib.types.str; + description = "Command to use for adjusting brightness"; + }; toggleBarCommand = lib.mkOption { type = lib.types.str; description = "Command to hide and show the status bar."; diff --git a/modules/nixos/graphical/i3.nix b/modules/nixos/graphical/i3.nix index a861533..53edb05 100644 --- a/modules/nixos/graphical/i3.nix +++ b/modules/nixos/graphical/i3.nix @@ -121,6 +121,8 @@ in { "Mod1+Tab" = "exec --no-startup-id ${config.altTabCommand}"; "${modifier}+Shift+period" = "exec --no-startup-id ${config.powerCommand}"; + "${modifier}+Shift+m" = + "exec --no-startup-id ${config.brightnessCommand}"; "${modifier}+Shift+c" = "reload"; "${modifier}+Shift+r" = "restart"; "${modifier}+Shift+q" = '' diff --git a/modules/nixos/graphical/rofi.nix b/modules/nixos/graphical/rofi.nix index 396219d..ed9d32a 100644 --- a/modules/nixos/graphical/rofi.nix +++ b/modules/nixos/graphical/rofi.nix @@ -6,7 +6,7 @@ let in { - imports = [ ./rofi/power.nix ]; + imports = [ ./rofi/power.nix ./rofi/brightness.nix ]; config = lib.mkIf (pkgs.stdenv.isLinux && config.services.xserver.enable) { diff --git a/modules/nixos/graphical/rofi/brightness.nix b/modules/nixos/graphical/rofi/brightness.nix new file mode 100755 index 0000000..351a9b8 --- /dev/null +++ b/modules/nixos/graphical/rofi/brightness.nix @@ -0,0 +1,49 @@ +{ config, pkgs, ... }: +let + + rofi = config.home-manager.users.${config.user}.programs.rofi.finalPackage; + +in { + + # Adapted from: + # A rofi powered menu to execute brightness choices. + + config.brightnessCommand = builtins.toString + (pkgs.writeShellScript "brightness" '' + + dimmer="" + medium="" + brighter="" + + chosen=$(printf '%s;%s;%s\n' \ + "$dimmer" \ + "$medium" \ + "$brighter" \ + | ${rofi}/bin/rofi \ + -theme-str '@import "brightness.rasi"' \ + -hover-select \ + -me-select-entry ''' \ + -me-accept-entry MousePrimary \ + -dmenu \ + -sep ';' \ + -selected-row 1) + + case "$chosen" in + "$dimmer") + ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 25; ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 25 + ;; + + "$medium") + ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 75; ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 75 + ;; + + "$brighter") + ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 100; ${pkgs.ddcutil}/bin/ddcutil --display 2 setvcp 10 100 + ;; + + *) exit 1 ;; + esac + + ''); + +} diff --git a/modules/nixos/graphical/rofi/brightness.sh b/modules/nixos/graphical/rofi/brightness.sh deleted file mode 100755 index 977f433..0000000 --- a/modules/nixos/graphical/rofi/brightness.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# THEME="$HOME/.config/rofi/config.rasi" - -ICON_UP="" -ICON_DOWN="" -ICON_OPT="" -options="$ICON_UP\n$ICON_OPT\n$ICON_DOWN" -chosen="$(echo -e "$options" | rofi -theme-str 'listview { layout:horizontal; }' -dmenu)" -echo "$chosen" diff --git a/modules/nixos/graphical/rofi/power.nix b/modules/nixos/graphical/rofi/power.nix index 9c71802..ea61b2e 100755 --- a/modules/nixos/graphical/rofi/power.nix +++ b/modules/nixos/graphical/rofi/power.nix @@ -23,7 +23,10 @@ in { "$suspend" \ "$log_out" \ | ${rofi}/bin/rofi \ - -theme-str '@import "power.rasi"' \ + -theme-str '@import "power.rasi"' \ + -hover-select \ + -me-select-entry ''' \ + -me-accept-entry MousePrimary \ -dmenu \ -sep ';' \ -selected-row 2) diff --git a/modules/nixos/graphical/rofi/rofi-prompt.sh b/modules/nixos/graphical/rofi/rofi-prompt.sh index fea1bfe..f304b4e 100755 --- a/modules/nixos/graphical/rofi/rofi-prompt.sh +++ b/modules/nixos/graphical/rofi/rofi-prompt.sh @@ -31,6 +31,9 @@ done chosen=$(printf '%s;%s\n' "$yes" "$no" | rofi -theme-str '@import "prompt.rasi"' \ + -hover-select \ + -me-select-entry '' \ + -me-accept-entry MousePrimary \ -p "$query" \ -dmenu \ -sep ';' \ diff --git a/modules/nixos/graphical/rofi/themes/brightness.rasi b/modules/nixos/graphical/rofi/themes/brightness.rasi new file mode 100644 index 0000000..9c45755 --- /dev/null +++ b/modules/nixos/graphical/rofi/themes/brightness.rasi @@ -0,0 +1,6 @@ +@import "common.rasi" + +#window { + width: 605px; + height: 230px; +} diff --git a/modules/nixos/graphical/rofi/themes/common.rasi b/modules/nixos/graphical/rofi/themes/common.rasi index 8e5ee97..bc3a265 100644 --- a/modules/nixos/graphical/rofi/themes/common.rasi +++ b/modules/nixos/graphical/rofi/themes/common.rasi @@ -33,11 +33,6 @@ vpn-textbox-prompt-colon-padding: @network-textbox-prompt-colon-padding; } -#window { - width: 980px; - height: 230px; -} - /** * Settings used in every rofi option menu: */ diff --git a/modules/nixos/graphical/rofi/themes/power.rasi b/modules/nixos/graphical/rofi/themes/power.rasi index abe5b23..719783c 100644 --- a/modules/nixos/graphical/rofi/themes/power.rasi +++ b/modules/nixos/graphical/rofi/themes/power.rasi @@ -1 +1,6 @@ @import "common.rasi" + +#window { + width: 980px; + height: 230px; +}