diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2021-11-23 18:18:05 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2021-11-23 18:18:05 -0500 |
commit | 5426d76142d742fa0419f404e36af62e3a3236b9 (patch) | |
tree | 579ff5a08fc61466d57324edd742e15bca385ba8 | |
parent | 3e7571030df2404873c8320ff976fb3fb41448c9 (diff) | |
download | lite-xl-plugins-5426d76142d742fa0419f404e36af62e3a3236b9.tar.gz lite-xl-plugins-5426d76142d742fa0419f404e36af62e3a3236b9.zip |
Commit on behalf of @mart-on-windows.
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | plugins/opacity.lua | 62 |
2 files changed, 63 insertions, 0 deletions
@@ -116,6 +116,7 @@ Plugin | Description [`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))* ~~[`nagbar`](https://github.com/takase1121/lite-nagbar)*~~ | integrated in lite-xl ~~consistent and _beautiful_ confirmation dialogs for lite and lite-xl *([gif](https://raw.githubusercontent.com/takase1121/lite-nagbar/master/assets/preview.gif))*~~ [`navigate`](plugins/navigate.lua?raw=1) | Allows moving back and forward between document positions, reducing the amount of scrolling +[`opacity`](plugins/opacity.lua?raw=1) | Change the opaqueness/transparency of `lite-xl` using shift+mousewheel or a command. [`open_ext`](plugins/open_ext.lua?raw=1) | Automatically prompts you if you tried to open a binary file in the editor [`openfilelocation`](plugins/openfilelocation.lua?raw=1) | Opens the parent directory of the current file in the file manager [`openselected`](plugins/openselected.lua?raw=1) | Opens the selected filename or url diff --git a/plugins/opacity.lua b/plugins/opacity.lua new file mode 100644 index 0000000..8dd0d9a --- /dev/null +++ b/plugins/opacity.lua @@ -0,0 +1,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", +} |