Skip to content
This repository has been archived by the owner on Jan 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #8 from nivit/add-command-keybindings
Browse files Browse the repository at this point in the history
Add keyboard shortcuts.
  • Loading branch information
okitavera authored Jul 4, 2019
2 parents 2406094 + be5263d commit b473c5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/clearine.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from Clearine.helper import Helper

config = {}
shortcuts = {}
root_module = os.path.dirname(os.path.abspath(__file__))
class Clearine(Gtk.Window):
def __init__(self):
Expand All @@ -72,6 +73,7 @@ def setprops(self):
def setcontent(self):
# fetch a plain-text clearine.conf configuration
global config
global shortcuts

status = logging.getLogger(self.__class__.__name__)
dotcat = configparser.ConfigParser()
Expand Down Expand Up @@ -167,6 +169,14 @@ def find_key(data, section, key, default):
config["command-shutdown"] = find_key("str", "command", "shutdown", "pkexec shutdown -h now")
config["command-lock"] = find_key("str", "command", "lock", "i3lock")

shortcuts = {
find_key("str", "shortcuts", "cancel", "Escape"): "cancel",
find_key("str", "shortcuts", "lock", "K"): "lock",
find_key("str", "shortcuts", "logout", "L"): "logout",
find_key("str", "shortcuts", "restart", "R"): "restart",
find_key("str", "shortcuts", "shutdown", "S"): "shutdown"
}

# Setup all content inside Gtk.Window
if config["main-mode"] == "horizontal":
button_group = Gtk.VBox()
Expand Down Expand Up @@ -371,8 +381,15 @@ def do(self, widget, button):

def on_keypressed (self, widget, event):
# handling an event when user press some key
if event.keyval == Gdk.KEY_Escape:
sys.exit()
key = Gdk.keyval_name(event.keyval)

if key in shortcuts.keys():
command = shortcuts[key]
if command == "cancel":
sys.exit()
else:
os.system(config["command-%s" % command])

def on_state_changed(self, widget, event):
if event.new_window_state:
self.fullscreen()
Expand Down
7 changes: 7 additions & 0 deletions src/data/clearine.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
restart = systemctl reboot
shutdown = systemctl poweroff

[shortcuts]
cancel = Escape
lock = K
logout = L
restart = R
shutdown = S

[card]
# set background color and border radius for card
background-color = #e1e5e8
Expand Down

0 comments on commit b473c5a

Please sign in to comment.