From aa1b2ee69f2fdeaf49cef49ee8a57213d6d3d766 Mon Sep 17 00:00:00 2001 From: diazvictor Date: Tue, 26 Jan 2021 02:04:08 -0400 Subject: [PATCH] Added src/moonterm-keybinds.lua Support for key combinations --- Makefile | 3 ++- moonterm.lua | 2 ++ src/moonterm-keybinds.lua | 44 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) mode change 100755 => 100644 moonterm.lua create mode 100644 src/moonterm-keybinds.lua diff --git a/Makefile b/Makefile index 61a448b..b5000d8 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/moonterm.lua b/moonterm.lua old mode 100755 new mode 100644 index 436b9b3..efdf926 --- a/moonterm.lua +++ b/moonterm.lua @@ -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 @@ -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() diff --git a/src/moonterm-keybinds.lua b/src/moonterm-keybinds.lua new file mode 100644 index 0000000..f59524d --- /dev/null +++ b/src/moonterm-keybinds.lua @@ -0,0 +1,44 @@ +--[[-- + @package MoonTerm + @filename moonterm-keybinds.lua + @version 1.0 + @author Díaz Urbaneja Víctor Eduardo Diex + @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