Better keybinding functionality

makes sure we don't start multiple instances by misstake
main
Micke Nordin 4 years ago
parent 9367d45d69
commit 80f9d78855

@ -12,10 +12,15 @@ wget -O ~/.local/bin/swayswitch https://github.com/mickenordin/swayswitch/blob/m
chmod +x ~/.local/bin/swayswitch chmod +x ~/.local/bin/swayswitch
``` ```
## Usage ## Usage
Add a keybinding to ~/.config/sway/config: Add sway config to ~/.config/sway/config:
``` ```
bindsym $mod+Tab exec ~/.local/bin/swayswitch mode "switcher" {
# Remove normal bidnings and set a dummy variable so we do something
set $hello "hello"
}
bindsym $mod+Tab exec ~/.local/bin/swayswitch, mode "switcher"
``` ```
Reload config and open up window switcher with $mod+tab. Reload config and open up window switcher with $mod+tab.

@ -20,6 +20,7 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
wx.Frame.__init__(self, None, title="", style=wx.STAY_ON_TOP) # pylint: disable=no-member wx.Frame.__init__(self, None, title="", style=wx.STAY_ON_TOP) # pylint: disable=no-member
# create a panel in the frame # create a panel in the frame
self.pnl = wx.Panel(self) # pylint: disable=no-member self.pnl = wx.Panel(self) # pylint: disable=no-member
# get windows from sway # get windows from sway
windows = get_windows() windows = get_windows()
label_len = 20 label_len = 20
@ -41,6 +42,7 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
label = window['name'] label = window['name']
if len(label) > label_len: if len(label) > label_len:
label = label[:label_len] label = label[:label_len]
label = "ws" + str(window['workspace']) + ":\n" + label
winid = window['id'] winid = window['id']
size = wx.Window.GetFont(self).GetPointSize() * label_len # pylint: disable=no-member size = wx.Window.GetFont(self).GetPointSize() * label_len # pylint: disable=no-member
btn = wx.Button( # pylint: disable=no-member btn = wx.Button( # pylint: disable=no-member
@ -61,13 +63,16 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
"""Intercept esc key press""" """Intercept esc key press"""
keycode = event.GetUnicodeKey() keycode = event.GetUnicodeKey()
if keycode == wx.WXK_ESCAPE: # pylint: disable=no-member if keycode == wx.WXK_ESCAPE: # pylint: disable=no-member
"""enter normal mode and exit"""
command = 'swaymsg mode "default"'
subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
self.Close(True) self.Close(True)
else: else:
event.Skip(True) event.Skip(True)
def switch_window(self, event, winid): # pylint: disable=unused-argument def switch_window(self, event, winid): # pylint: disable=unused-argument
"""Switches the focus to the given id""" """Switches the focus to the given id and enter normalmode"""
command = "swaymsg [con_id={}] focus".format(winid) command = 'swaymsg [con_id={}] focus, mode "default"'.format(winid)
subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
self.Close(True) self.Close(True)
@ -101,6 +106,7 @@ def extract_nodes_iterative(workspace):
floating_nodes = workspace.get('floating_nodes') floating_nodes = workspace.get('floating_nodes')
for floating_node in floating_nodes: for floating_node in floating_nodes:
floating_node['workspace'] = workspace['num']
all_nodes.append(floating_node) all_nodes.append(floating_node)
nodes = workspace.get('nodes') nodes = workspace.get('nodes')
@ -109,10 +115,12 @@ def extract_nodes_iterative(workspace):
# Leaf node # Leaf node
if len(node.get('nodes')) == 0: if len(node.get('nodes')) == 0:
node['workspace'] = workspace['num']
all_nodes.append(node) all_nodes.append(node)
# Nested node, handled iterative # Nested node, handled iterative
else: else:
for inner_node in node.get('nodes'): for inner_node in node.get('nodes'):
inner_node['workspace'] = workspace['num']
nodes.append(inner_node) nodes.append(inner_node)
return all_nodes return all_nodes

Loading…
Cancel
Save