aboutsummaryrefslogtreecommitdiff
path: root/plugins/opacity.lua
blob: 8dd0d9a87fc3713e682670566965d2d550d2f1c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-- mod-version:2 -- lite-xl 2.0
local common = require "core.common"
local command = require "core.command"
local keymap = require "core.keymap"
local RootView = require "core.rootview"

local opacity_on = true
local use_mousewheel = true
local opacity_steps = 0.05
local default_opacity = 1
local current_opacity = default_opacity

local function set_opacity(opacity)
  if not opacity_on then opacity_on = true end
  current_opacity = common.clamp(opacity, 0.2, 1)
  system.set_window_opacity(current_opacity)
end

local on_mouse_wheel = RootView.on_mouse_wheel

function RootView:on_mouse_wheel(d, ...)
  if keymap.modkeys["shift"] and use_mousewheel then
    if d < 0 then command.perform "opacity:decrease" end
    if d > 0 then command.perform "opacity:increase" end
  else
    return on_mouse_wheel(self, d, ...)
  end
end

local function tog_opacity()
  opacity_on = not opacity_on
  if opacity_on then
    system.set_window_opacity(current_opacity)
  else
    system.set_window_opacity(default_opacity)
  end
end

local function res_opacity()
  set_opacity(default_opacity)
end

local function inc_opacity()
  set_opacity(current_opacity + opacity_steps)
end

local function dec_opacity()
  set_opacity(current_opacity - opacity_steps)
end

command.add(nil, {
  ["opacity:toggle"  ] = function() tog_opacity() end,
  ["opacity:reset"   ] = function() res_opacity() end,
  ["opacity:decrease"] = function() dec_opacity() end,
  ["opacity:increase"] = function() inc_opacity() end,
  ["opacity:toggle mouse wheel use"] = function() use_mousewheel = not use_mousewheel end,
})

keymap.add {
  ["shift+f11"] = "opacity:toggle",
  ["ctrl+f11"]  = "opacity:toggle mouse wheel use",
}