From 7ec776db74c41d72eeccd1cfa3f3d1cec56be3d5 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Mon, 26 Aug 2019 15:16:50 +0200 Subject: [PATCH] More stuff --- .config/awesome/autohidewibox.conf | 39 +++++++ .config/awesome/autohidewibox.py | 171 +++++++++++++++++++++++++++++ .config/awesome/autorun.sh | 3 + .config/awesome/rc.lua | 52 +++++---- .config/awesome/theme.lua | 4 +- 5 files changed, 247 insertions(+), 22 deletions(-) create mode 100644 .config/awesome/autohidewibox.conf create mode 100755 .config/awesome/autohidewibox.py diff --git a/.config/awesome/autohidewibox.conf b/.config/awesome/autohidewibox.conf new file mode 100644 index 0000000..ce7d83b --- /dev/null +++ b/.config/awesome/autohidewibox.conf @@ -0,0 +1,39 @@ +[autohidewibox] + + # Select your awesome version + # Possible values: 3, 4 + awesomeVersion=4 + + # A comma-separated list of keys. + # Some suggestions: + # 133 - Meta-L + # 134 - Meta-R + # 37 - Ctrl-L + # 105 - Ctrl-R + # 66 - CapsLock + superKeys=133,134 + + # The show/hide behavior. Possible values: + # 'transient': The wibox is only shown while a super key is pressed. + # 'toggle': Pressing and releasing a super key (press and release) toggles + # the wibox visibility. + # Default = transient. + mode=transient + + # The name of one or more (comma separated) + # wiboxes which to autohide. + wiboxname=mywibox + + # Delay execution in ms + delayShow=600 + delayHide=0 + + # Custom commands to send to awesome + # Use this to call custom-defined event functions in your awesome config + # (Note: You can leave 'wiboxname' above empty, or remove it completely) + customhide=stopgaps() + customshow=startgaps() + + # Used for debug/development purposes. Prints extra bits information. + # Possible values: 0, 1 + debug=0 diff --git a/.config/awesome/autohidewibox.py b/.config/awesome/autohidewibox.py new file mode 100755 index 0000000..5652a32 --- /dev/null +++ b/.config/awesome/autohidewibox.py @@ -0,0 +1,171 @@ +#!/usr/bin/python3 + +import subprocess +import re +import configparser +import os.path as path +import sys +import threading + +MODE_TRANSIENT = "transient" +MODE_TOGGLE = "toggle" + +config = configparser.ConfigParser() +try: + userconf = path.join(path.expanduser("~"), ".config/autohidewibox.conf") + if len(sys.argv)>1 and path.isfile(sys.argv[1]): + config.read(sys.argv[1]) + elif path.isfile(userconf): + config.read(userconf) + else: + config.read("/etc/autohidewibox.conf") +except configparser.MissingSectionHeaderError: + pass + + +awesomeVersion = config.get( "autohidewibox", "awesomeVersion", fallback=4) +superKeys = config.get( "autohidewibox", "superKeys", fallback="133,134").split(",") +wiboxes = config.get( "autohidewibox", "wiboxname", fallback="mywibox").split(",") +customhide = config.get( "autohidewibox", "customhide", fallback=None) +customshow = config.get( "autohidewibox", "customshow", fallback=None) +delayShow = config.getfloat( "autohidewibox", "delayShow", fallback=0) +delayHide = config.getfloat( "autohidewibox", "delayHide", fallback=0) +mode = config.get( "autohidewibox", "mode", fallback=MODE_TRANSIENT) +debug = config.getboolean("autohidewibox", "debug", fallback=False) + +# (remove the following line if your wibox variables have strange characters) +wiboxes = [ w for w in wiboxes if re.match("^[a-zA-Z_][a-zA-Z0-9_]*$", w) ] +#python>=3.4: wiboxes = [ w for w in wiboxes if re.fullmatch("[a-zA-Z_][a-zA-Z0-9_]*", w) ] + +delay = {True: delayShow, False: delayHide} +delayThread = None +wiboxIsCurrentlyVisible = False +waitingFor = False +nonSuperKeyWasPressed = False +cancel = threading.Event() + +shPath = "" +shPotentialPaths = ["/usr/bin/sh", "/bin/sh"] +for p in shPotentialPaths: + if path.exists(p): + shPath = p + break +if shPath == "": + print("Can't find sh in any of: " + ",".join(shPotentialPaths), file=sys.stderr) + sys.exit(1) + +hideCommand3 = "for k,v in pairs({wibox}) do v.visible = {state} end" +hideCommand4 = "for s in screen do s.{wibox}.visible = {state} end" +try: + hideCommand = hideCommand4 if int(awesomeVersion) >= 4 else hideCommand3 +except ValueError: + hideCommand = hideCommand4 + + +def _debug(*args): + if debug: + print(*args) + + +def setWiboxState(state=True, immediate=False): + global delayThread, waitingFor, cancel, wiboxIsCurrentlyShown + wiboxIsCurrentlyShown = state + dbgPstate = "show" if state else "hide" + if delay[not state] > 0: + _debug(dbgPstate, "delay other") + if type(delayThread) == threading.Thread and delayThread.is_alive(): + # two consecutive opposing events cancel out. second event should not be called + _debug(dbgPstate, "delay other, thread alive -> cancel") + cancel.set() + return + if delay[state] > 0 and not immediate: + _debug(dbgPstate + " delay same") + if not (type(delayThread) == threading.Thread and delayThread.is_alive()): + _debug(dbgPstate, "delay same, thread dead -> start wait") + waitingFor = state + cancel.clear() + delayThread = threading.Thread(group=None, target=waitDelay, kwargs={"state": state}) + delayThread.daemon = True + delayThread.start() + # a second event setting the same state is silently discarded + return + _debug("state:", dbgPstate) + customcmd = customshow if state else customhide + if customcmd: + subprocess.call( + shPath + " " + + "-c \"echo '" + + customcmd + + "' | awesome-client\"", + shell=True) + for wibox in wiboxes: + subprocess.call( + shPath + " " + + "-c \"echo '" + + hideCommand.format(wibox=wibox, state="true" if state else "false") + + "' | awesome-client\"", + shell=True) + + + +def waitDelay(state=True): + if not cancel.wait(delay[state]/1000): + setWiboxState(state=state, immediate=True) + + +try: + setWiboxState(False) + + proc = subprocess.Popen(['xinput', '--test-xi2', '--root', '3'], stdout=subprocess.PIPE) + + field = None + keystate = None + + for line in proc.stdout: + l = line.decode("utf-8").strip() + eventmatch = re.match("EVENT type (\\d+) \\(.+\\)", l) + detailmatch = re.match("detail: (\\d+)", l) + + if eventmatch: + _debug(eventmatch) + try: + field = "event" + keystate = eventmatch.group(1) + _debug("found event, waiting for detail...") + except IndexError: + field = None + keystate = None + + if (field is "event") and detailmatch: + _debug(detailmatch) + try: + if detailmatch.group(1) in superKeys: + _debug("is a super key") + if keystate == "13": # press + nonSuperKeyWasPressed = False + if mode == MODE_TRANSIENT: + _debug("showing wibox") + setWiboxState(True) + if keystate == "14": # release + if mode == MODE_TRANSIENT: + _debug("hiding wibox") + setWiboxState(False) + # Avoid toggling the wibox when a super key is used in conjunction + # with another key. + elif mode == MODE_TOGGLE and not nonSuperKeyWasPressed: + _debug("toggling wibox") + setWiboxState(not wiboxIsCurrentlyShown) + nonSuperKeyWasPressed = False + else: + nonSuperKeyWasPressed = True + except IndexError: + _debug("Couldn't parse keystate number.") + pass + finally: + field = None + keystate = None +except KeyboardInterrupt: + pass +finally: + setWiboxState(True, True) + # print("Shutting down") diff --git a/.config/awesome/autorun.sh b/.config/awesome/autorun.sh index ea5946d..713990c 100755 --- a/.config/awesome/autorun.sh +++ b/.config/awesome/autorun.sh @@ -8,3 +8,6 @@ function run { } . ~/.config/compton/launch.sh +run ~/.config/awesome/autohidewibox.py ~/.config/awesome/autohidewibox.conf +run ~/setbg.sh +run dunst diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index c6f5ab1..dd198fa 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -232,8 +232,22 @@ root.buttons(gears.table.join( )) -- }}} +function startgaps () + beautiful.useless_gap = 10 +end + +function stopgaps () + beautiful.useless_gap = 0 +end + +key.connect_signal("press", function(k) + print("hello") +end) + + -- {{{ Key bindings globalkeys = gears.table.join( + awful.key({ modkey, }, "", startgaps, stopgaps), awful.key({ modkey, }, "s", hotkeys_popup.show_help, {description="show help", group="awesome"}), awful.key({ modkey, }, "Left", awful.tag.viewprev, @@ -332,7 +346,23 @@ globalkeys = gears.table.join( awful.key({ modkey }, "p", function() menubar.show() end, {description = "show the menubar", group = "launcher"}), awful.key({ modkey }, "d", function() awful.spawn("rofi -show run") end, - {description = "launch rofi", group = "launcher"}) + {description = "launch rofi", group = "launcher"}), + + awful.key({ modkey, "Shift" }, "m", + function (c) + awful.spawn("dmenu_script minecraft.sh") + end , + {description = "Play Minecraft"}), + awful.key({ modkey, "Shift" }, "f", + function (c) + awful.spawn("dmenu_script factorio.sh") + end , + {description = "Play Factorio"}), + awful.key({ modkey, "Shift" }, "g", + function (c) + awful.spawn("dmenu_script lutris.sh") + end , + {description = "Play a Game"}) ) clientkeys = gears.table.join( @@ -358,25 +388,7 @@ clientkeys = gears.table.join( -- minimized, since minimized clients can't have the focus. c.minimized = true end , - {description = "minimize", group = "client"}), - awful.key({ modkey, }, "m", - function (c) - c.maximized = not c.maximized - c:raise() - end , - {description = "(un)maximize", group = "client"}), - awful.key({ modkey, "Control" }, "m", - function (c) - c.maximized_vertical = not c.maximized_vertical - c:raise() - end , - {description = "(un)maximize vertically", group = "client"}), - awful.key({ modkey, "Shift" }, "m", - function (c) - c.maximized_horizontal = not c.maximized_horizontal - c:raise() - end , - {description = "(un)maximize horizontally", group = "client"}) + {description = "minimize", group = "client"}) ) -- Bind all key numbers to tags. diff --git a/.config/awesome/theme.lua b/.config/awesome/theme.lua index 776894f..32c738d 100644 --- a/.config/awesome/theme.lua +++ b/.config/awesome/theme.lua @@ -11,7 +11,7 @@ local themes_path = gfs.get_themes_dir() local theme = {} -theme.font = "sans 8" +theme.font = "sans 10" theme.bg_normal = "#222222" theme.bg_focus = "#535d6c" @@ -25,7 +25,7 @@ theme.fg_urgent = "#ffffff" theme.fg_minimize = "#ffffff" theme.useless_gap = dpi(0) -theme.border_width = dpi(1) +theme.border_width = dpi(0) theme.border_normal = "#000000" theme.border_focus = "#535d6c" theme.border_marked = "#91231c"