Waybar and Wodi

This commit is contained in:
OdiousImp2604
2021-01-24 13:47:49 +00:00
committed by GitHub
parent 02d4a89da6
commit c4b69bf43e
16 changed files with 845 additions and 115 deletions

View File

@@ -1,4 +1,4 @@
hide_search=false
hide_scroll=true
show=drun,run
width=700

View File

@@ -1,59 +1,52 @@
#entry {
border-radius: 5px;
padding: 3px;
margin: 0px 3px 3px 3px;
/*
Arc-Dark Color Scheme
*/
@define-color highlight #5294e2;
@define-color base1 #404552;
@define-color base2 #40455;
*{
font-family: UbuntuMono;
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
#entry:selected {
background-color:#4b3766;
font-weight: bold;
}
#text:selected {
color: #d8dee9;
}
#window {
background-color: transparent;
font-family: Ubuntu Mono;
window {
}
#input {
border: none;
background-color: #4c566a;
padding: 10px;
margin: 15px 15px 10px 15px;
border-radius: 5px;
margin-bottom: 10px;
border-radius: 3px;
border:none;
color: white;
}
#inner-box {
color: #4b3766;
padding-top: 5px;
margin: 0px 10px 10px 10px;
background-color: @base2;
}
#outer-box {
margin: 15px;
background-color: rgba(53,59,73,1.0);
box-shadow: 0px 0px 5px 0 #0F0F0F;
margin: 3px;
padding:15px;
background-color: @base2;
}
#scroll {
margin-bottom: 10px;
}
#text {
padding: 5px;
color: #d8dee9;
background-color: transparent;
}
#img {
background-color: transparent;
padding: 5px;
color: white;
}
#entry:nth-child(even){
background-color: @base1;
}
#entry:selected {
background-color: @highlight;
}
#text:selected {
}

6
.config/wofi/window.sh Normal file
View File

@@ -0,0 +1,6 @@
swaymsg -t get_tree |
jq -r '.nodes[].nodes[] | if .nodes then [recurse(.nodes[])] else [] end + .floating_nodes | .[] | select(.nodes==[]) | ((.id | tostring) + "" + .name)' |
wofi -c ~/.config/wofi/menu -s ~/.config/wofi/sway.css --show dmenu | {
read -r id name
swaymsg "[con_id=$id]" focused
}

100
.config/wofi/windows.py Normal file
View File

@@ -0,0 +1,100 @@
#!/bin/python3
from argparse import ArgumentParser
import subprocess
import json
enter="\n"
# Returns a list of all json window objects
def get_windows():
command="swaymsg -t get_tree"
active_outputs = []
process = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
data = json.loads(process.communicate()[0])
# Select outputs that are active
windows = []
for output in data['nodes']:
# The scratchpad (under __i3) is not supported
if output.get('name') != '__i3' and output.get('type') == 'output':
workspaces = output.get('nodes')
for ws in workspaces:
if ws.get('type') == 'workspace':
windows += extract_nodes_iterative(ws)
return windows
# Extracts all windows from a sway workspace json object
def extract_nodes_iterative(workspace):
all_nodes = []
floating_nodes = workspace.get('floating_nodes')
for floating_node in floating_nodes:
all_nodes.append(floating_node)
nodes = workspace.get('nodes')
for node in nodes:
# Leaf node
if len(node.get('nodes')) == 0:
all_nodes.append(node)
# Nested node, handled iterative
else:
for inner_node in node.get('nodes'):
nodes.append(inner_node)
return all_nodes
# Returns an array of all windows
def parse_windows(windows):
parsed_windows = []
for window in windows:
parsed_windows.append(window.get('name'))
return parsed_windows
# Returns a newline seperated UFT-8 encoded string of all windows for wofi
def build_wofi_string(windows):
return enter.join(windows).encode("UTF-8")
# Executes wofi with the given input string
def show_wofi(windows):
command="wofi -c ~/.config/wofi/menu -s ~/.config/wofi/sway.css -p \"Windows: \" -d -i --hide-scroll"
process = subprocess.Popen(command,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
return process.communicate(input=windows)[0]
# Returns the sway window id of the window that was selected by the user inside wofi
def parse_id(windows, parsed_windows, selected):
selected = (selected.decode("UTF-8"))[:-1] # Remove new line character
window_index = int(parsed_windows.index(selected)) # Get index of selected window in the parsed window array
return str(windows[window_index].get('id')) # Get sway window id based on the index
# Switches the focus to the given id
def switch_window(id):
command="swaymsg [con_id={}] focus".format(id)
process = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
process.communicate()[0]
# Entry point
if __name__ == "__main__":
parser = ArgumentParser(description="Wofi based window switcher")
windows = get_windows()
parsed_windows = parse_windows(windows)
wofi_string = build_wofi_string(parsed_windows)
selected = show_wofi(wofi_string)
selected_id = parse_id(windows, parsed_windows, selected)
switch_window(selected_id)