Skip to content

Commit

Permalink
Added src/moonterm-keybinds.lua
Browse files Browse the repository at this point in the history
Support for key combinations
  • Loading branch information
diazvictor committed Jan 26, 2021
1 parent 8e663af commit aa1b2ee
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ BINDIR ?= $(PREFIX)/bin
DESKTOP_DIR ?= $(PREFIX)/share/applications

SRC = moonterm.lua src/moonterm-dialog.lua src/moonterm-app.lua \
src/moonterm-popover.lua libraries/LIP.lua libraries/utils.lua
src/moonterm-popover.lua src/moonterm-keybinds.lua libraries/LIP.lua \
libraries/utils.lua

moonterm:
$(LUASTATIC) $(SRC) -l$(LUA) -I$(LUA_INCLUDE)
Expand Down
2 changes: 2 additions & 0 deletions moonterm.lua
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ utils = require("libraries.utils")

lgi = require("lgi")
Gtk = lgi.require('Gtk', '3.0')
Gdk = lgi.require('Gdk', '3.0')
Vte = lgi.Vte
GLib = lgi.GLib

Expand All @@ -28,5 +29,6 @@ conf = inifile:load(('%s/moonterm.ini'):format(dir))
require('src.moonterm-popover')
require('src.moonterm-app')
require('src.moonterm-dialog')
require('src.moonterm-keybinds')

app:run()
44 changes: 44 additions & 0 deletions src/moonterm-keybinds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--[[--
@package MoonTerm
@filename moonterm-keybinds.lua
@version 1.0
@author Díaz Urbaneja Víctor Eduardo Diex <victor.vector008@gmail.com>
@date 26.01.2021 00:40:09 -04
--]]

function toggle_fullscreen()
fullscreen = not fullscreen
if ( fullscreen ) then
main_window:fullscreen()
else
main_window:unfullscreen()
end
end

keybindings = {
-- alphanumeric keys
{
[Gdk.KEY_C] = function () term:copy_clipboard() end,
[Gdk.KEY_V] = function () term:paste_clipboard() end
},
-- function keys
{
[Gdk.KEY_F11] = function () toggle_fullscreen() end
}
}

function main_window:on_key_press_event(event)
local ctrl_on = event.state.CONTROL_MASK
local shift_on = event.state.SHIFT_MASK
alphanumeric_keys = keybindings[1][event.keyval]
function_keys = keybindings[2][event.keyval]

if ( alphanumeric_keys and shift_on and ctrl_on ) then
alphanumeric_keys()
elseif ( function_keys and not shift_on and not ctrl_on ) then
function_keys()
else
return false
end
return true
end

0 comments on commit aa1b2ee

Please sign in to comment.