This commit is contained in:
Yuri Zamyatin 2025-09-26 05:08:39 +00:00
parent d8eae8a1a5
commit 6bf779a68e
No known key found for this signature in database
GPG Key ID: 4009A4CD0333B579
6 changed files with 42 additions and 34 deletions

View File

@ -1,15 +1,19 @@
#!/bin/bash
parent_has_sibl=$(swaymsg -t get_tree | jq '
def find_focused_path:
if .focused then [.]
elif .nodes then
[.] + (.nodes[] | find_focused_path | select(length > 0))
else empty
def check_focused(parent; grandparent):
if .focused then
if grandparent and (grandparent.type == "con" or grandparent.type == "workspace") and (grandparent.nodes | length) > 1 then 1 else 0 end
else
. as $current |
((.nodes[]? | check_focused($current; parent)),
(.floating_nodes[]? | check_focused($current; parent)))
end;
find_focused_path | if length >= 3 and .[-2].type=="con" then 1 else 0 end
first(check_focused(null; null) // 0)
')
#echo "$parent_has_sibl"
if [ "$parent_has_sibl" = 1 ]; then
swaymsg "focus parent; focus $1 sibling; focus child"
else

View File

@ -1,18 +1,17 @@
MAX_TITLE_LENGTH=600
get_windows_with_workspace() {
swaymsg -t get_tree | jq -r --arg max_len "$MAX_TITLE_LENGTH" '
def get_workspace_name(node):
if node.type == "workspace" then node.name
elif node.parent then get_workspace_name(node.parent)
else "Unknown" end;
swaymsg -t get_tree | jq -r '
def calc_ws_name(ws_name):
if ws_name == "__i3_scratch" then "_"
elif (ws_name | test("^[0-9]+:")) then (ws_name | sub("^[0-9]+:"; ""))
else ws_name
end;
def get_windows(workspace_name):
if .type == "con" and .pid != null and (.name // "") != "" then
if (.type == "con" or .type == "floating_con") and .pid != null and (.name // "") != "" then
{
id: .id,
name: .name,
app_id: (.app_id // .window_properties.class // "Unknown"),
name: .name | ascii_downcase,
app_id: (.app_id // .window_properties.class // "unknown") | ascii_downcase,
workspace: workspace_name,
focused: .focused
}
@ -20,37 +19,32 @@ get_windows_with_workspace() {
(.nodes[]? | get_windows(workspace_name)),
(.floating_nodes[]? | get_windows(workspace_name));
def get_workspaces:
def traverse_all:
if .type == "workspace" then
. as $ws | .name as $ws_name | get_windows($ws_name)
. as $ws | (.name | calc_ws_name(.)) as $ws_name | get_windows($ws_name)
else empty end,
(.nodes[]? | get_workspaces);
(.nodes[]? | traverse_all);
get_workspaces |
traverse_all |
"\(.id)|\(.app_id)|\(.name)|\(.workspace)|\(.focused)"
'
}
window_list=$(get_windows_with_workspace)
formatted_list=$(echo "$window_list" | while IFS='|' read -r id app_id name workspace focused; do
if [ ${#name} -gt $MAX_TITLE_LENGTH ]; then
truncated_name="${name:0:$((MAX_TITLE_LENGTH-3))}..."
else
truncated_name="$name"
fi
if [ "$focused" = "true" ]; then
indicator="> "
else
indicator=" "
fi
printf "[%s/%s]%s %s: %s\n" "$workspace" "$id" "$indicator" "$app_id" "$truncated_name"
printf "%s%s%s %s %s\n" "$workspace" "$indicator" "$id" "$app_id" "$name"
done)
selection=$(echo "$formatted_list" | bemenu --prompt "/" --index "$(echo "$formatted_list" | awk '/]>/ {print NR-1 ":" $0}')" )
selection=$(echo "$formatted_list" | bemenu --width-factor 100 --prompt "/" --index "$(echo "$formatted_list" | awk 'substr($0,2,1)==">" {print NR-1}')" )
[ -z "$selection" ] && exit 0
window_id=$(echo "$selection" | sed 's/.*\/\([^]]*\)].*/\1/')
window_id=$(echo "$selection" | sed -E 's/^...([0-9]+).*/\1/')
if [ -n "$window_id" ]; then
swaymsg "[con_id=\"$window_id\"] focus"

View File

@ -5,3 +5,7 @@
defaultBranch = main
[pull]
rebase = false
[safe]
directory = *
[commit]
gpgsign = true

View File

@ -116,10 +116,10 @@ bindsym --to-code {
bindsym --to-code {
$mod+d scratchpad show
$altmod+d sticky enable; move scratchpad
$mod+k focus floating
$altmod+k floating enable; sticky enable
$mod+h focus tiling
$altmod+h focus floating; floating disable; sticky disable
$mod+k focus tiling
$altmod+k focus floating; floating disable; sticky disable
$mod+h focus floating
$altmod+h floating enable; sticky enable
$mod+x exec wtype -M ctrl x -m ctrl
$mod+c exec wtype -M ctrl c -m ctrl
$mod+v exec wtype -M ctrl v -m ctrl

View File

@ -63,3 +63,9 @@ set keymap vi-insert
"\C-h":operate-and-get-next
#################################
########### custom ##############
$if qalc
set show-mode-in-prompt off
$endif
#################################

View File

@ -93,7 +93,7 @@ noremap! <C-e> <C-j>
" i -> k
noremap i k
noremap I K
noremap! <C-i> <C-k>
"noremap! <C-i> <C-k> " breaks tab
" o -> l
noremap o l
noremap O L
@ -145,7 +145,7 @@ noremap! <C-е> <C-ж>
" i -> k
noremap и к
noremap И К
noremap! <C-и> <C-к>
"noremap! <C-и> <C-к> " breaks tab
" o -> l
noremap о л
noremap О Л