From 1642626d2a0cfa0d5682f5bce884d812a030d9fe Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sun, 17 May 2026 14:53:07 -0700 Subject: [PATCH] Add Hyprland inactive opacity toggle --- docs/tiling-wm-experience.md | 1 + dotfiles/config/hypr/hyprland/binds.lua | 1 + dotfiles/config/hypr/hyprland/settings.lua | 4 +++ dotfiles/config/hypr/hyprland/state.lua | 1 + dotfiles/config/hypr/hyprland/windows.lua | 29 ++++++++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/docs/tiling-wm-experience.md b/docs/tiling-wm-experience.md index 12893695..e7e8a92c 100644 --- a/docs/tiling-wm-experience.md +++ b/docs/tiling-wm-experience.md @@ -332,6 +332,7 @@ Required behavior: follows it. This is the target replacement for the older `Super+Shift+h` binding. - `Hyper+e` focuses the next empty workspace. +- `Hyper+1` toggles inactive-window opacity reduction for the focused window. - `Hyper+5` swaps the current workspace with a selected workspace. - `Hyper+g` gathers windows of the focused class onto the current workspace. diff --git a/dotfiles/config/hypr/hyprland/binds.lua b/dotfiles/config/hypr/hyprland/binds.lua index f1f05a61..7255e852 100644 --- a/dotfiles/config/hypr/hyprland/binds.lua +++ b/dotfiles/config/hypr/hyprland/binds.lua @@ -243,6 +243,7 @@ function M.setup(ctx) move_to_next_empty_workspace(false) end, desc("Move window to next empty workspace")) bind(main_mod .. " + apostrophe", focus_next_class, desc("Focus next window class")) + bind(hyper .. " + 1", toggle_inactive_opacity_for_active_window, desc("Toggle inactive opacity reduction for active window")) bind(mod_alt .. " + W", show_active_window_info, desc("Show active window info")) end diff --git a/dotfiles/config/hypr/hyprland/settings.lua b/dotfiles/config/hypr/hyprland/settings.lua index 96101d9a..0ea0ac32 100644 --- a/dotfiles/config/hypr/hyprland/settings.lua +++ b/dotfiles/config/hypr/hyprland/settings.lua @@ -403,6 +403,10 @@ function M.setup(ctx) border_size = 2, border_color = "rgba(edb443ff) rgba(ff4d5dcc)", }) + hl.window_rule({ + match = { tag = inactive_opacity_override_tag }, + opacity = "1.0 override 1.0 override 1.0 override", + }) end ctx.apply_rules = apply_rules diff --git a/dotfiles/config/hypr/hyprland/state.lua b/dotfiles/config/hypr/hyprland/state.lua index f6e4213d..b7d723b8 100644 --- a/dotfiles/config/hypr/hyprland/state.lua +++ b/dotfiles/config/hypr/hyprland/state.lua @@ -42,6 +42,7 @@ return { [monocle_layout] = "Monocle", }, minimized_workspace = "special:minimized", + inactive_opacity_override_tag = "no-inactive-opacity", tabbed_group_restore_workspace_prefix = "special:tabbed-monocle-restore-", current_layout = columns_layout, enable_nstack = true, diff --git a/dotfiles/config/hypr/hyprland/windows.lua b/dotfiles/config/hypr/hyprland/windows.lua index 4e15b2f3..93f9c912 100644 --- a/dotfiles/config/hypr/hyprland/windows.lua +++ b/dotfiles/config/hypr/hyprland/windows.lua @@ -355,6 +355,34 @@ function M.setup(ctx) }) end + local function window_has_tag(window, tag) + for _, value in ipairs((window and window.tags) or {}) do + if tostring(value):gsub("%*$", "") == tag then + return true + end + end + + return false + end + + local function toggle_inactive_opacity_for_active_window() + local window = hl.get_active_window() + local selector = window_selector(window) + if not selector then + return + end + + local disabling_reduction = not window_has_tag(window, inactive_opacity_override_tag) + dispatch(hl.dsp.window.tag({ tag = inactive_opacity_override_tag, window = selector })) + hl.notification.create({ + text = "Inactive opacity reduction: " .. (disabling_reduction and "off for window" or "on for window"), + duration = 1600, + icon = notification_icons.info, + color = "rgba(edb443ff)", + font_size = 13, + }) + end + local function raise_or_spawn(class_fragment, command) local fragment = string.lower(class_fragment) for _, window in ipairs(hl.get_windows()) do @@ -462,6 +490,7 @@ function M.setup(ctx) ctx.gather_focused_class = gather_focused_class ctx.focus_next_class = focus_next_class ctx.show_active_window_info = show_active_window_info + ctx.toggle_inactive_opacity_for_active_window = toggle_inactive_opacity_for_active_window ctx.raise_or_spawn = raise_or_spawn ctx.minimize_active_window = minimize_active_window ctx.restore_last_minimized = restore_last_minimized