Skip to content

Commit

Permalink
A new algorithm for the opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf committed Apr 28, 2017
1 parent 66c58cd commit ac3494e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Optionally edit any subset of the following settings, the defaults are:
switcher.settings.preview_box_title_color = {0,0,0,1}, -- the font color

switcher.settings.client_opacity = false, -- opacity for unselected clients
switcher.settings.client_opacity_value = 0.5, -- alpha-value
switcher.settings.client_opacity_value = 0.8, -- alpha-value
switcher.settings.client_opacity_value_in_focus = 0.2, -- alpha-value for the current in-focus client
```

Then add key-bindings. On my particular system, and I guess most,
Expand Down
42 changes: 27 additions & 15 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ local settings = {
preview_box_title_color = {0,0,0,1},

client_opacity = false,
client_opacity_value = 0.5,
client_opacity_value = 0.8,
client_opacity_value_in_focus = 0.2,
}

-- Create a wibox to contain all the client-widgets
Expand Down Expand Up @@ -366,31 +367,42 @@ local function updatePreview()
end
end

local function clientOpacity()
if not settings.client_opacity then return end

for i,data in pairs(altTabTable) do
data.client.opacity = 0
end

if client.focus == altTabTable[altTabIndex].client then
-- Let's normalize the value up to 1.
local opacityFocusSelected = settings.client_opacity_value + settings.client_opacity_value_in_focus
if opacityFocusSelected > 1 then opacityFocusSelected = 1 end
client.focus.opacity = opacityFocusSelected
else
-- Let's normalize the value up to 1.
local opacityFocus = settings.client_opacity_value_in_focus
if opacityFocus > 1 then opacityFocus = 1 end
local opacitySelected = settings.client_opacity_value
if opacitySelected > 1 then opacitySelected = 1 end

client.focus.opacity = opacityFocus
altTabTable[altTabIndex].client.opacity = opacitySelected
end
end

-- This starts the timer for updating and it shows the preview UI.
local function showPreview()
preview_live_timer.timeout = 1 / settings.preview_box_fps
preview_live_timer:connect_signal("timeout", updatePreview)
preview_live_timer:start()

preview()

preview_wbox.visible = true
end


local function clientOpacity()
if not settings.client_opacity then return end

for i,data in pairs(altTabTable) do
if i == altTabIndex then
data.client.opacity = 1
else
data.client.opacity = settings.client_opacity_value
end
end
clientOpacity()
end


local function cycle(dir)
-- Switch to next client
altTabIndex = altTabIndex + dir
Expand Down

0 comments on commit ac3494e

Please sign in to comment.