diff options
author | 2014-10-25 00:30:36 -0400 | |
---|---|---|
committer | 2014-10-25 00:30:36 -0400 | |
commit | 83c20c89439386f31050718c94551d863298cdb9 (patch) | |
tree | 536dd52392df00ded7bbc5f650ea0eb0d397d52d /core/ui.lua | |
parent | 1de8c1bb596a7dbff39ab55685ead31a5d0c9373 (diff) | |
download | textadept-83c20c89439386f31050718c94551d863298cdb9.tar.gz textadept-83c20c89439386f31050718c94551d863298cdb9.zip |
Improvements to terminal mouse handling.
Emit events for unhandled mouse events and connect to such events in order to
focus and resize views.
Patch libtermkey with new Win32 PDCurses driver for unified key/mouse input.
Update CDK patch to always use libtermkey and to ignore mouse events.
Requires Scinterm r97 (changeset 8d1a625c9b4d).
Thanks to Chris Emerson for proof of concept code that handles mouse events and
for the code that focuses and resizes views.
Diffstat (limited to 'core/ui.lua')
-rw-r--r-- | core/ui.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/ui.lua b/core/ui.lua index 9d7788be..24a5cbaf 100644 --- a/core/ui.lua +++ b/core/ui.lua @@ -401,6 +401,55 @@ events_connect(events.BUFFER_DELETED, function() if i and _BUFFERS[buffer] ~= i then view:goto_buffer(i) end end) +-- Enables and disables mouse mode in curses and focuses and resizes views based +-- on mouse events. +if CURSES then + if not WIN32 then + io.stdout:write("\x1b[?1002h") -- enable mouse mode + io.stdout:flush() + events.connect(events.QUIT, function() + io.stdout:write("\x1b[?1002l") -- disable mouse mode + io.stdout:flush() + end, 1) + end + + -- Retrieves the view or split at the given terminal coordinates. + -- @param view View or split to test for coordinates within. + -- @param y The y terminal coordinate. + -- @param x The x terminal coordinate. + local function get_view(view, y, x) + if not view[1] and not view[2] then return view end + local vertical, size = view.vertical, view.size + if vertical and x < size or not vertical and y < size then + return get_view(view[1], y, x) + elseif vertical and x > size or not vertical and y > size then + -- Zero y or x relative to the other view based on split orientation. + return get_view(view[2], vertical and y or y - size - 1, + vertical and x - size - 1 or x) + else + return view -- in-between views; return the split itself + end + end + + local resize + events.connect(events.MOUSE, function(event, button, y, x) + if event == buffer.MOUSE_RELEASE or button ~= 1 then return end + if event == buffer.MOUSE_PRESS then + local view = get_view(ui.get_split_table(), y - 1, x) -- title is at y=1 + if not view[1] and not view[2] then + ui.goto_view(_VIEWS[view]) + resize = nil + else + resize = function(y2, x2) + view[1].size = view.size + (view.vertical and x2 - x or y2 - y) + end + end + elseif resize then + resize(y, x) + end + end) +end + events_connect(events.ERROR, ui.print) --[[ The tables below were defined in C. |