2023-01-04 01:28:50 +00:00
|
|
|
#!/usr/bin/env
|
|
|
|
import notify
|
2023-01-05 16:33:27 +00:00
|
|
|
import config
|
2023-01-04 01:28:50 +00:00
|
|
|
|
|
|
|
alias hc=herbstclient
|
|
|
|
|
2023-01-05 16:33:27 +00:00
|
|
|
set_log_color "ff99cc"
|
2023-01-04 01:28:50 +00:00
|
|
|
|
2023-01-05 16:33:27 +00:00
|
|
|
# group_active_reset resets the active group to 1
|
2023-01-04 14:23:25 +00:00
|
|
|
function group_active_reset
|
2023-01-05 16:33:27 +00:00
|
|
|
new_config \
|
|
|
|
-t uint \
|
|
|
|
-n ActiveGroup \
|
|
|
|
-v 1
|
2023-01-04 01:28:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function group_switch
|
2023-01-05 16:33:27 +00:00
|
|
|
set -f current (get_config ActiveGroup)
|
2023-01-04 14:23:25 +00:00
|
|
|
|
|
|
|
set -f arg $argv[1]
|
|
|
|
if not set -q arg
|
|
|
|
set -f arg '+'
|
|
|
|
end
|
|
|
|
if test "$arg" = "+"
|
|
|
|
group_up
|
|
|
|
else if test "$arg" = "-"
|
|
|
|
group_down
|
|
|
|
else if test $arg -eq $arg
|
|
|
|
# is a number
|
|
|
|
group_index $arg
|
|
|
|
else
|
2023-01-05 16:33:27 +00:00
|
|
|
log "invalid group index [$arg], use '+', '-', or a real integer"
|
2023-01-04 14:23:25 +00:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# update the tag it should now be on, if it switched
|
2023-01-05 16:33:27 +00:00
|
|
|
if test (get_config ActiveGroup) -ne $current
|
2023-01-04 14:23:25 +00:00
|
|
|
update_tag $current
|
|
|
|
end
|
|
|
|
group_set_keybinds
|
2023-01-05 16:33:27 +00:00
|
|
|
set -f active (get_config ActiveGroup)
|
|
|
|
notify "Group $active"
|
|
|
|
log "group $current -> $active"
|
2023-01-04 14:23:25 +00:00
|
|
|
end
|
|
|
|
|
2023-01-05 16:33:27 +00:00
|
|
|
# move_to_group moves the focused window to the
|
|
|
|
# relative tag on a given group
|
2023-01-04 14:23:25 +00:00
|
|
|
function move_to_group
|
|
|
|
set -f move_to "$argv"
|
2023-01-05 16:33:27 +00:00
|
|
|
set -f active (get_config ActiveGroup)
|
|
|
|
if test "$move_to" = "$active"
|
|
|
|
log "ignoring move as it's already in the active group"
|
2023-01-04 14:23:25 +00:00
|
|
|
return 0
|
2023-01-05 16:33:27 +00:00
|
|
|
else if test $move_to -lt 1; or \
|
|
|
|
$move_to -gt (get_config GroupCount)
|
|
|
|
log "invalid group index [$move_to]:" \
|
|
|
|
"out of range [1:$(get_config GroupCount)]"
|
2023-01-04 14:23:25 +00:00
|
|
|
return 1
|
|
|
|
end
|
2023-01-05 16:33:27 +00:00
|
|
|
set -f new_tag (translate_tag $active $move_to)
|
|
|
|
log "moving window to group [$move_to]" \
|
2023-01-04 14:23:25 +00:00
|
|
|
"tag -> $new_tag"
|
|
|
|
end
|
|
|
|
|
|
|
|
# translate_tag translates the current tag from
|
|
|
|
# the group provided in the first argument,
|
|
|
|
# from which the relative tag is calculated, to
|
|
|
|
# what the tag should be if it was in the second argument
|
|
|
|
function translate_tag
|
|
|
|
set -f current_actual (hc attr tags.focus.index)
|
|
|
|
set -f tl_from $argv[1]
|
|
|
|
set -f tl_to $argv[2]
|
2023-01-05 16:33:27 +00:00
|
|
|
set -f offset_from \
|
|
|
|
(math \
|
|
|
|
(math $tl_from - 1) x \
|
|
|
|
(get_config TagsPerGroup))
|
|
|
|
set -f offset_to \
|
|
|
|
(math \
|
|
|
|
(math $tl_to - 1) x \
|
|
|
|
(get_config TagsPerGroup))
|
|
|
|
set -f relative_tag_from \
|
|
|
|
(math $current_actual - $offset_from)
|
|
|
|
log \
|
|
|
|
"calculated relative tag to" \
|
|
|
|
"group [$tl_from] to be" \
|
|
|
|
"[$relative_tag_from]"
|
|
|
|
set -f actual_tag_to \
|
|
|
|
(math $relative_tag_from + $offset_to)
|
|
|
|
log \
|
|
|
|
"relative tag" \
|
|
|
|
"[$relative_tag_from]" \
|
|
|
|
"translated to group [$tl_to]"\
|
2023-01-04 14:23:25 +00:00
|
|
|
"becomes actual tag [$actual_tag_to]"
|
|
|
|
echo $actual_tag_to
|
|
|
|
end
|
|
|
|
|
|
|
|
function update_tag
|
2023-01-05 16:33:27 +00:00
|
|
|
set -f new_tag (translate_tag $argv \
|
|
|
|
$(get_config ActiveGroup))
|
|
|
|
log "moving frame focus to tag: [$new_tag]"
|
2023-01-04 14:23:25 +00:00
|
|
|
hc use_index $new_tag
|
|
|
|
end
|
|
|
|
|
|
|
|
function group_down
|
2023-01-05 16:33:27 +00:00
|
|
|
set -f active_grp (get_config ActiveGroup)
|
|
|
|
if not set -q active_grp; or \
|
|
|
|
test $active_grp -eq 1
|
2023-01-04 14:23:25 +00:00
|
|
|
# Treat unset == 1, so move back to the last one
|
2023-01-05 16:33:27 +00:00
|
|
|
set_config -n ActiveGroup -v (get_config GroupCount)
|
2023-01-04 14:23:25 +00:00
|
|
|
else
|
2023-01-05 16:33:27 +00:00
|
|
|
set_config -n ActiveGroup -v (math $active_grp - 1)
|
2023-01-04 14:23:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-05 16:33:27 +00:00
|
|
|
function group_up
|
|
|
|
set -f active_grp (get_config ActiveGroup)
|
|
|
|
if test $active_grp -le 1
|
|
|
|
set_config -n ActiveGroup -v 2
|
|
|
|
else if test $active_grp -eq (get_config GroupCount)
|
|
|
|
set_config -n ActiveGroup -v 1
|
|
|
|
else
|
|
|
|
set_config -n ActiveGroup \
|
|
|
|
-v (math $active_grp + 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-04 14:23:25 +00:00
|
|
|
function group_index
|
2023-01-05 16:33:27 +00:00
|
|
|
if test $argv -gt (get_config GroupCount)
|
|
|
|
set -f $argv (get_config GroupCount)
|
2023-01-04 14:23:25 +00:00
|
|
|
else if test $argv -lt 1
|
|
|
|
set -f $argv 1
|
|
|
|
end
|
|
|
|
|
2023-01-05 16:33:27 +00:00
|
|
|
set_config -n ActiveGroup -v $argv
|
2023-01-04 01:28:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# group_set_keybinds sets the keybinds to the given tab group
|
|
|
|
function group_set_keybinds
|
2023-01-05 16:33:27 +00:00
|
|
|
set_default hlwm_mod (get_config ModKey)
|
|
|
|
set -f grp (get_config ActiveGroup)
|
|
|
|
set -f tags_per (get_config TagsPerGroup)
|
|
|
|
log "setting keybinds for group: $grp"
|
|
|
|
set -l offset (math \
|
|
|
|
(math $grp-1) x $tags_per)
|
|
|
|
for tag in (seq $tags_per)
|
2023-01-04 01:28:50 +00:00
|
|
|
set -l actual_tag (math $tag + $offset)
|
2023-01-05 16:33:27 +00:00
|
|
|
hc keybind $hlwm_mod-$tag use_index \
|
|
|
|
(math $actual_tag - 1)
|
|
|
|
hc keybind $hlwm_mod-Shift-$tag move_index \
|
|
|
|
(math $actual_tag - 1)
|
2023-01-04 01:28:50 +00:00
|
|
|
end
|
|
|
|
end
|