From cefbbbc575e5924c72d148864e3de0f51a116f8e Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 2 Sep 2026 14:30:16 +0100 Subject: [PATCH] Refactoring --- .config/hypr/apps.lua | 3 -- .config/hypr/autostart.lua | 22 ++++++----- .config/hypr/bindings.lua | 38 +----------------- .config/hypr/helpers.lua | 77 +++++++++++++++++++++++++++++++++++++ .config/hypr/hyprland.lua | 18 +++++---- .config/hypr/looknfeel.lua | 2 +- .config/hypr/monitors.lua | 23 ----------- .config/hypr/workspaces.lua | 57 +++++---------------------- 8 files changed, 112 insertions(+), 128 deletions(-) create mode 100644 .config/hypr/helpers.lua diff --git a/.config/hypr/apps.lua b/.config/hypr/apps.lua index 4c999d1..a05b374 100644 --- a/.config/hypr/apps.lua +++ b/.config/hypr/apps.lua @@ -176,7 +176,6 @@ hl.window_rule { hl.window_rule { name = 'retroarch-fullscreen', fullscreen = true, - workspace = 'name:Gaming_1', tag = '-default-opacity', opacity = '1 1', idle_inhibit = 'fullscreen', @@ -233,7 +232,6 @@ hl.window_rule { -- name = 'steam-float', -- float = true, -- no_initial_focus = true, --- workspace = 'name:Gaming_1', -- idle_inhibit = 'fullscreen', -- match = { -- class = 'steam', @@ -267,7 +265,6 @@ hl.window_rule { hl.window_rule { name = 'atlauncher-float', float = true, - workspace = 'name:Gaming_1', center = true, size = { 1100, 700 }, tag = '-default-opacity', diff --git a/.config/hypr/autostart.lua b/.config/hypr/autostart.lua index 1bd0880..c41f905 100644 --- a/.config/hypr/autostart.lua +++ b/.config/hypr/autostart.lua @@ -1,12 +1,16 @@ hl.on('hyprland.start', function() - hl.exec_cmd 'uwsm-app -- hypridle' - hl.exec_cmd 'uwsm-app -- mako' - hl.exec_cmd 'uwsm-app -- fcitx5 --disable notificationitem' - hl.exec_cmd 'uwsm-app -- Enpass -minimize' - hl.exec_cmd 'uwsm-app -- steam' - hl.exec_cmd 'nextcloud' - hl.exec_cmd 'station-bg-random' - hl.exec_cmd '/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1' - hl.exec_cmd 'dbus-update-activation-environment --systemd --all' + exec 'uwsm-app -- hypridle' + exec 'uwsm-app -- mako' + exec 'uwsm-app -- fcitx5 --disable notificationitem' + exec 'uwsm-app -- Enpass -minimize' + exec 'uwsm-app -- steam' + exec 'nextcloud' + exec 'station-bg-random' + exec '/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1' + exec 'dbus-update-activation-environment --systemd --all' +end) + +hl.on('config.reloaded', function() + toggle_laptop_monitor() end) diff --git a/.config/hypr/bindings.lua b/.config/hypr/bindings.lua index 3d68611..7085722 100644 --- a/.config/hypr/bindings.lua +++ b/.config/hypr/bindings.lua @@ -1,34 +1,10 @@ +require 'helpers' -- ========================== -- Media -- ========================== -- Only display the OSD on the currently focused monitor local osdclient = 'swayosd-client --monitor "$(hyprctl monitors -j | jq -r \'.[] | select(.focused == true).name\')"' -local exec = hl.dsp.exec_cmd -local shortcut = hl.dsp.send_shortcut - -local function bind(key, cmd, desc, opts) - opts = opts or {} - opts.desc = desc - hl.bind(key, cmd, opts) -end - -local function bindl(key, cmd, desc, opts) - opts = opts or {} - opts.locked = true - bind(key, cmd, desc, opts) -end - -local function bindlr(key, cmd, desc, opts) - opts = opts or {} - opts.repeating = true - bindl(key, cmd, desc, opts) -end - -local function notify(text) - hl.notification.create { text = text, duration = 2000 } -end - -- Laptop multimedia keys for volume and LCD brightness (with OSD) bindlr('XF86AudioRaiseVolume', exec(osdclient .. ' --output-volume raise'), 'Volume up') bindlr('XF86AudioRaiseVolume', exec(osdclient .. ' --output-volume raise'), 'Volume up') @@ -118,18 +94,6 @@ bind('SUPER + CTRL + L', function() notify('󱂬 Workspace layout set to ' .. next_layout) end, 'Toggle workspace layout') -local get_current_layout = function() - local workspace = hl.get_active_workspace() - if hl.get_active_special_workspace() then - workspace = hl.get_active_special_workspace() - end - if not workspace then - return 'dwindle' - end - - return workspace.tiled_layout -end - -- Move focus with SUPER + arrow keys bind('SUPER + H', function() if get_current_layout() == 'monocle' then diff --git a/.config/hypr/helpers.lua b/.config/hypr/helpers.lua new file mode 100644 index 0000000..793e899 --- /dev/null +++ b/.config/hypr/helpers.lua @@ -0,0 +1,77 @@ +DEFAULT_LAYOUT = 'master' + +exec = hl.dsp.exec_cmd +shortcut = hl.dsp.send_shortcut + +function bind(key, cmd, desc, opts) + opts = opts or {} + opts.desc = desc + hl.bind(key, cmd, opts) +end + +function bindl(key, cmd, desc, opts) + opts = opts or {} + opts.locked = true + bind(key, cmd, desc, opts) +end + +function bindlr(key, cmd, desc, opts) + opts = opts or {} + opts.repeating = true + bindl(key, cmd, desc, opts) +end + +function notify(text, duration) + hl.notification.create { text = text, duration = duration or 2000 } +end + +function is_lid_closed() + local file = io.open('/proc/acpi/button/lid/LID0/state', 'r') + + if not file then + file = io.open('/proc/acpi/button/lid/LID/state', 'r') + end + + if file then + local state = file:read '*a' + file:close() + return string.find(state, 'closed') ~= nil + end + + return false +end + +function toggle_laptop_monitor() + hl.monitor { + output = 'desc:BOE NE160QDM-NZ6', + disabled = is_lid_closed(), + } +end + +function get_current_layout() + local workspace = hl.get_active_workspace() + if hl.get_active_special_workspace() then + workspace = hl.get_active_special_workspace() + end + if not workspace then + return 'master' + end + + return workspace.tiled_layout +end + +function get_active_workspace() + local workspace = hl.get_active_workspace() + if hl.get_active_special_workspace() then + workspace = hl.get_active_special_workspace() + end + + return workspace +end + +function is_laptop_screen_focused() + local monitor = hl.get_active_monitor() + + return monitor and monitor.description == 'BOE NE160QDM-NZ6' +end + diff --git a/.config/hypr/hyprland.lua b/.config/hypr/hyprland.lua index a72a820..92698b0 100644 --- a/.config/hypr/hyprland.lua +++ b/.config/hypr/hyprland.lua @@ -1,8 +1,10 @@ -require("autostart") -require("workspaces") -require("bindings") -require("envs") -require("looknfeel") -require("input") -require("windows") -require("monitors") +require 'helpers' +require 'autostart' +require 'workspaces' +require 'bindings' +require 'envs' +require 'looknfeel' +require 'input' +require 'windows' +require 'monitors' + diff --git a/.config/hypr/looknfeel.lua b/.config/hypr/looknfeel.lua index 6018482..cf4f914 100644 --- a/.config/hypr/looknfeel.lua +++ b/.config/hypr/looknfeel.lua @@ -26,7 +26,7 @@ hl.config { allow_tearing = false, -- layout = scrolling, # Change to niri-like side-scrolling layout - layout = 'dwindle', + layout = 'master', }, -- https://wiki.hyprland.org/Configuring/Variables/#decoration diff --git a/.config/hypr/monitors.lua b/.config/hypr/monitors.lua index 5c04003..6e2db65 100644 --- a/.config/hypr/monitors.lua +++ b/.config/hypr/monitors.lua @@ -22,26 +22,3 @@ hl.monitor { hl.monitor { output = '', mode = 'preferred', position = 'auto', scale = 1 } -local function is_lid_closed() - local file = io.open('/proc/acpi/button/lid/LID0/state', 'r') - - if not file then - file = io.open('/proc/acpi/button/lid/LID/state', 'r') - end - - if file then - local state = file:read '*a' - file:close() - return string.find(state, 'closed') ~= nil - end - - return false -end - -function toggleLaptopMonitor() - hl.monitor { - output = 'desc:BOE NE160QDM-NZ6', - disabled = not is_lid_closed(), - } -end - diff --git a/.config/hypr/workspaces.lua b/.config/hypr/workspaces.lua index 28f0d4e..0f0885d 100644 --- a/.config/hypr/workspaces.lua +++ b/.config/hypr/workspaces.lua @@ -7,6 +7,8 @@ local workspace_map = { } local function setup_monitors() + toggle_laptop_monitor() + local monitors = hl.get_monitors() local monitor_count = #monitors @@ -42,67 +44,28 @@ local function setup_monitors() hl.dispatch(hl.dsp.window.move { workspace = new_workspace, window = active_window, follow = false }) end, { description = 'Move window to workspace ' .. workspace_map[i] }) end - - -- A hack to move to the Home workspace when Hyprland first loads - for j = monitor_count, 1, -1 do - if hl.get_workspaces()[j].id > 0 and monitor_count == 2 then - hl.dispatch(hl.dsp.focus { workspace = 'name:Home_' .. j }) - end - for k, window in pairs(hl.get_windows { workspace = j }) do - hl.dispatch(hl.dsp.window.move { window = window, workspace = 'name:Home_1', follow = true }) - end - end end hl.on('monitor.added', setup_monitors) hl.on('monitor.removed', setup_monitors) hl.on('config.reloaded', setup_monitors) -hl.bind('switch:off:Lid Switch', function() - hl.monitor { - output = 'desc:BOE NE160QDM-NZ6', - disabled = false, - } - setup_monitors() -end) +hl.bind('switch:off:Lid Switch', setup_monitors) +hl.bind('switch:on:Lid Switch', setup_monitors) -hl.bind('switch:on:Lid Switch', function() - hl.monitor { - output = 'desc:BOE NE160QDM-NZ6', - disabled = true, - } - setup_monitors() -end) +function set_laptop_workspace_to_monocle() + local workspace = get_active_workspace() -hl.on('monitor.focused', function() - local workspace = hl.get_active_workspace() - if hl.get_active_special_workspace() then - workspace = hl.get_active_special_workspace() - end if not workspace then return end - local monitor = hl.get_active_monitor() - - if monitor.description == 'BOE NE160QDM-NZ6' then + if is_laptop_screen_focused() then hl.workspace_rule { workspace = 'name:' .. tostring(workspace.name), layout = 'monocle' } end -end) +end -hl.on('config.reloaded', function() - local workspace = hl.get_active_workspace() - if hl.get_active_special_workspace() then - workspace = hl.get_active_special_workspace() - end - if not workspace then - return - end +hl.on('monitor.focused', set_laptop_workspace_to_monocle) - local monitor = hl.get_active_monitor() - - if monitor.description == 'BOE NE160QDM-NZ6' then - hl.workspace_rule { workspace = 'name:' .. tostring(workspace.name), layout = 'monocle' } - end -end) +hl.on('config.reloaded', set_laptop_workspace_to_monocle)