From 02a3db7ebd03871fe49e1f2fc54d9a5d29ec5bdf Mon Sep 17 00:00:00 2001 From: Yessiest Date: Tue, 21 Mar 2023 22:12:35 +0400 Subject: [PATCH] Compositor inhibiting --- desktop.conf | 19 +++++++++++++++- modules/compositor.lua | 50 +++++++++++++++++++++++++++++++++++++++++ modules/powermanX.lua | 19 +++++++++++++--- modules/rules_stub.lua | 11 +++++++++ modules/static_tags.lua | 4 ++-- rc.lua | 3 ++- 6 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 modules/compositor.lua create mode 100644 modules/rules_stub.lua diff --git a/desktop.conf b/desktop.conf index 35d566d..033810a 100644 --- a/desktop.conf +++ b/desktop.conf @@ -46,7 +46,24 @@ XF86AudioPlay = ":mpc.play" XF86AudioPrev = ":mpc.prev" XF86AudioNext = ":mpc.next" - # Custom keys Print = "flameshot gui" Shift+Print = "flameshot launcher" + +# Power manager module +[powerman] +# Bad battery condition warning threshold +battery_quality_min = 33 +# Low battery warning threshold +battery_capacity_min = 15 +# Process to execute on low battery +on_low_battery = "" +# Process to execute on fully charged battery +on_charged_battery = "" +# Process to execute on critical battery condition +on_critical_condition = "" + +# Simple compositor inhibiting +[compositor] +# Command to use to spawn compositor +exec = "picom" diff --git a/modules/compositor.lua b/modules/compositor.lua new file mode 100644 index 0000000..59824fd --- /dev/null +++ b/modules/compositor.lua @@ -0,0 +1,50 @@ +-- This file is part of Reno desktop. +-- +-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +-- +-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see . +-- Compositor manager with inhibitor +local awful = require("awful") +-- Configuration variables +local cfg = config.compositor or {} +local compositor_enabled = false +local inhibitors = {} +local compositor_pid = nil +local function count(t) + local c = 0 + for _,_ in pairs(t) do + c = c + 1 + end + return c +end +if cfg.exec then + compositor_pid = awful.spawn(cfg.exec) + compositor_enabled = true + client.connect_signal("manage",function(c) + if c.inhibit_compositor then + inhibitors[c] = true + if compositor_enabled then + awful.spawn("kill "..tostring(compositor_pid)) + compositor_enabled = false + end + end + end) + client.connect_signal("unmanage",function(c) + if c.inhibit_compositor then + inhibitors[c] = nil + if count(inhibitors) == 0 then + if compositor_enabled == false then + compositor_pid = awful.spawn(cfg.exec) + compositor_enabled = true + end + end + end + end) + awesome.connect_signal("exit",function() + if compositor_enabled and compositor_pid then + awful.spawn("kill "..tostring(compositor_pid)) + end + end) +end diff --git a/modules/powermanX.lua b/modules/powermanX.lua index 1716fb1..d8d5d9a 100644 --- a/modules/powermanX.lua +++ b/modules/powermanX.lua @@ -6,6 +6,7 @@ -- -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see . -- Powerman X - second generation of the power management daemon +local awful = require("awful") local sysctl = require("syscontrol") local naughty = require("naughty") local gears = require("gears") @@ -15,6 +16,9 @@ local state_tracking = {} local cfg = config.powerman or {} local quality_min = cfg.battery_quality_min or 33 local capacity_min = cfg.battery_capacity_min or 15 +local on_low_battery = cfg.on_low_battery or "" +local on_charged_battery = cfg.on_charged_battery +local on_critical_condition = cfg.on_critical_condition -- Main loop gears.timer({ timeout = 2, @@ -24,15 +28,18 @@ gears.timer({ local data,_ = sysctl.power_supply.read_attribs(v) state_tracking[v] = state_tracking[v] or {} if data.type == "Battery" then - if (tonumber(data.quality) < quality_min) and + if (tonumber(data.quality) < quality_min) and (not state_tracking[v].quality_notification) then naughty.notify({ title = "Critical battery condition", text = "Battery "..data.name.." has reached critically low condition, seek a suitable replacement" }) state_tracking[v].quality_notification = true + if on_critical_condition then + awful.spawn(on_critical_condition) + end end - if (tonumber(data.capacity) <= capacity_min) and + if (tonumber(data.capacity) <= capacity_min) and (not data.charging) and (not state_tracking[v].capacity_notification) then naughty.notify({ @@ -40,17 +47,23 @@ gears.timer({ text = "Battery "..data.name.." capacity is at "..tostring(data.capacity).."%" }) state_tracking[v].capacity_notification = true + if on_low_battery then + awful.spawn(on_low_battery) + end end if (tonumber(data.capacity) > capacity_min) then state_tracking[v].capacity_notification = false end - if (data.capacity == "100") and + if (data.capacity == "100") and (data.charging) and (not state_tracking[v].charged_notification) then naughty.notify({ title = "Battery is completely charged", text = "Disconnect the charger from the power grid to avoid passive electricity usage." }) + if on_charged_battery then + awful.spawn(on_charged_battery) + end end if (not data.charging) then state_tracking[v].charged_notification = false diff --git a/modules/rules_stub.lua b/modules/rules_stub.lua new file mode 100644 index 0000000..e70f39b --- /dev/null +++ b/modules/rules_stub.lua @@ -0,0 +1,11 @@ +local awful = require("awful") +local gears = require("gears") +awful.rules.rules = gears.table.join(awful.rules.rules, { + { rule_any = { class = { + "steam_app_548430", + "steam_app_%d*", + "love" + }}, + properties = {inhibit_compositor = true}, + }, +}) diff --git a/modules/static_tags.lua b/modules/static_tags.lua index d31329c..1d141d6 100644 --- a/modules/static_tags.lua +++ b/modules/static_tags.lua @@ -14,13 +14,13 @@ awful.screen.connect_for_each_screen(function(s) tag:delete() end -- Add 9 default tags - awful.tag({"1", "2", "3", "4", "5", "6", "7", "8", "9"}, s, + awful.tag({"1", "2", "3", "4", "5", "6", "7", "8", "9"}, s, awful.layout.suit.floating) end) -- keybindings for tags local keys = root.keys() keys = gears.table.join(keys, - awful.key({global.modkey}, "Left", + awful.key({global.modkey}, "Left", awful.tag.viewprev, {description = "view next tag", group = "tag"}), awful.key({global.modkey}, "Right", diff --git a/rc.lua b/rc.lua index dec2a95..aa9685e 100644 --- a/rc.lua +++ b/rc.lua @@ -17,8 +17,9 @@ package.cpath = package.cpath require("modules.collect_garbage") require("modules.global") require("modules.powermanX") -require("modules.errorlog") require("modules.base") +require("modules.rules_stub") +require("modules.compositor") require("modules.binds") require("modules.xdg_data") require("modules.autostart")