Last active
August 29, 2015 13:57
-
-
Save blueyed/9851631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Opacity handling. | |
local M = {} | |
M = { | |
opacity_unfocused_screen = 0.98, | |
opacity_unfocused_screen_last_client = 1, | |
} | |
local locked_opacity = {} | |
local capi = { | |
client = client, | |
} | |
M.adjust = function(c, delta) | |
c.opacity = c.opacity + delta | |
table.insert(locked_opacity, c) | |
end | |
M.get_opacity_for_client = function(c) | |
if capi.client.focus == c then | |
if c.class and c.class:lower():find("firefox") then | |
opacity = 1 | |
else | |
opacity = 0.99 | |
end | |
else | |
if c.class and c.class:lower():find("firefox") then | |
opacity = 1 | |
else | |
opacity = 0.85 | |
end | |
end | |
return opacity | |
end | |
M.autoset_opacity = function(c, opacity) | |
local opacity = opacity or M.get_opacity_for_client(c) | |
for _,v in ipairs(locked_opacity) do | |
if c == v then | |
-- TODO: provide a way to unlock it. | |
-- bnote("opacity locked for "..tostring(c)) | |
return | |
end | |
end | |
c.opacity = opacity | |
end | |
-- }}} | |
-- Opacity on (un)focus. | |
local opacity_last_focused_client = nil | |
client.connect_signal("focus", function(c) | |
-- bnote(bdump({opacity_last_focused_client, c.screen})) | |
if opacity_last_focused_client and c.screen ~= opacity_last_focused_client.screen then | |
-- Init opacity for clients on new screen. | |
local clients = awful.client.visible(c.screen) | |
for _, _c in pairs(clients) do | |
M.autoset_opacity(_c) | |
-- bnote(bdump({"autoset", c=_c, opacity=_c.opacity})) | |
end | |
-- Opacity=1 for all clients when focus moved to another screen. | |
local clients = awful.client.visible(opacity_last_focused_client.screen) | |
for _, _c in pairs(clients) do | |
M.autoset_opacity(_c, M.opacity_unfocused_screen) | |
end | |
opacity_last_focused_client.opacity = M.opacity_unfocused_screen_last_client | |
else | |
M.autoset_opacity(c) | |
end | |
-- bnote(c.opacity) | |
end) | |
client.connect_signal("unfocus", function(c) | |
M.autoset_opacity(c) | |
opacity_last_focused_client = c | |
-- bnote(c.opacity) | |
end) | |
-- for s = 1, screen.count() do screen[s]:connect_signal("arrange", function () | |
-- -- Set full opacity for clients on non-focused screen. | |
-- if capi.client.focus and capi.client.focus.screen ~= s then | |
-- local clients = awful.client.visible(s) | |
-- for _, c in pairs(clients) do | |
-- M.autoset_opacity(c, 1) | |
-- end | |
-- end | |
-- end) | |
-- end | |
return M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment