From 1b7789abefeb27dbb9833813996d36694a595836 Mon Sep 17 00:00:00 2001 From: tiynger Date: Sun, 13 Oct 2019 10:49:45 +0200 Subject: [PATCH] scratchpad shortcuts for i3 --- .config/i3/config | 12 +++++++---- .config/sxhkd/sxhkdrc | 4 ++++ .local/bin/i3cmds/i3-scratchpad-dmenu.py | 27 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .local/bin/i3cmds/i3-scratchpad-dmenu.py diff --git a/.config/i3/config b/.config/i3/config index 6d7a03d..4ea58d0 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -32,7 +32,7 @@ for_window [instance="dropdown_dropdowncalc"] border pixel 2 for_window [instance="dropdown_*"] move position center bar { - font pango:mono 13 + font pango:mono 14 status_command i3blocks position top mode dock @@ -49,6 +49,8 @@ bindsym $mod+Shift+b bar mode toggle #bindsym $mod+c taken by sxhkd +bindsym $mod+Shift+d floating toggle + bindsym $mod+Shift+f fullscreen toggle bindsym $mod+h focus left @@ -67,8 +69,10 @@ bindsym $mod+l focus right bindsym $mod+Shift+l move right 30 #bindsym $mod+m taken by sxhkd +bindsym $mod+Shift+m move scratchpad #bindsym $mod+n taken by sxhkd +#bindsym $mod+Shift+n taken by sxhkd bindsym $mod+Shift+o exec --no-startup-id i3resize right @@ -113,9 +117,9 @@ set $ws4 "CHT" set $ws5 "DOC" set $ws6 "WRK" set $ws7 "EXT" -set $ws8 "ET1" -set $ws9 "ET2" -set $ws0 "ET3" +set $ws8 "GMG" +set $ws9 "ET1" +set $ws0 "ET2" # switch to workspace bindsym $mod+1 workspace $ws1 diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index b1b84b5..96976ac 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -6,6 +6,7 @@ super + b $BROWSER super + c code +#super + shift + d taken by i3 super + f $TERMINAL -e $FILE #super + shift + f taken by i3 @@ -22,8 +23,11 @@ super + i #super + shift + l taken by i3 super + m thunderbird +#super + shift + m taken by i3 super + n $TERMINAL -e newsboat +super + shift + n + i3-scratchpad-dmenu.py #super + shift + o taken by i3 #super + q taken by i3 #super + shift + q taken by i3 diff --git a/.local/bin/i3cmds/i3-scratchpad-dmenu.py b/.local/bin/i3cmds/i3-scratchpad-dmenu.py new file mode 100644 index 0000000..b6c4883 --- /dev/null +++ b/.local/bin/i3cmds/i3-scratchpad-dmenu.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import i3ipc +import subprocess +import re + +i3 = i3ipc.Connection() + +def get_scratchpad_windows(): + scratchpad_containers = i3.get_tree().scratchpad().descendants() + return filter(lambda c: c.type == 'con' and c.name, scratchpad_containers) + +def dmenu_choose(options): + """ Show a dmenu to choose a string item from a list of *options*. """ + dmenu_process = subprocess.Popen(["dmenu", "-l", "10"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + stdoutdata, _ = dmenu_process.communicate("\n".join(options).encode()) + return stdoutdata.decode('utf-8') + +def main(): + scratchpad_windows = get_scratchpad_windows() + window_titles = [w.name for w in scratchpad_windows] + if window_titles: + window_to_restore = re.escape(dmenu_choose(window_titles).strip()) + i3.command('[title="{}"] scratchpad show'.format(window_to_restore)) + +if __name__ == '__main__': + main()