152 lines
4.4 KiB
Fish
Executable File
152 lines
4.4 KiB
Fish
Executable File
#!/usr/bin/env
|
|
import notify
|
|
import config
|
|
|
|
alias hc=herbstclient
|
|
|
|
set_log_color "ff99cc"
|
|
|
|
# group_active_reset resets the active group to 1
|
|
function group_active_reset
|
|
new_config \
|
|
-t uint \
|
|
-n ActiveGroup \
|
|
-v 1
|
|
end
|
|
|
|
function group_switch
|
|
set -f current (get_config ActiveGroup)
|
|
|
|
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
|
|
log "invalid group index [$arg], use '+', '-', or a real integer"
|
|
return 1
|
|
end
|
|
|
|
# update the tag it should now be on, if it switched
|
|
if test (get_config ActiveGroup) -ne $current
|
|
update_tag $current
|
|
end
|
|
group_set_keybinds
|
|
set -f active (get_config ActiveGroup)
|
|
notify "Group $active"
|
|
log "group $current -> $active"
|
|
end
|
|
|
|
# move_to_group moves the focused window to the
|
|
# relative tag on a given group
|
|
function move_to_group
|
|
set -f move_to "$argv"
|
|
set -f active (get_config ActiveGroup)
|
|
if test "$move_to" = "$active"
|
|
log "ignoring move as it's already in the active group"
|
|
return 0
|
|
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)]"
|
|
return 1
|
|
end
|
|
set -f new_tag (translate_tag $active $move_to)
|
|
log "moving window to group [$move_to]" \
|
|
"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]
|
|
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]"\
|
|
"becomes actual tag [$actual_tag_to]"
|
|
echo $actual_tag_to
|
|
end
|
|
|
|
function update_tag
|
|
set -f new_tag (translate_tag $argv \
|
|
$(get_config ActiveGroup))
|
|
log "moving frame focus to tag: [$new_tag]"
|
|
hc use_index $new_tag
|
|
end
|
|
|
|
function group_down
|
|
set -f active_grp (get_config ActiveGroup)
|
|
if not set -q active_grp; or \
|
|
test $active_grp -eq 1
|
|
# Treat unset == 1, so move back to the last one
|
|
set_config -n ActiveGroup -v (get_config GroupCount)
|
|
else
|
|
set_config -n ActiveGroup -v (math $active_grp - 1)
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
function group_index
|
|
if test $argv -gt (get_config GroupCount)
|
|
set -f $argv (get_config GroupCount)
|
|
else if test $argv -lt 1
|
|
set -f $argv 1
|
|
end
|
|
|
|
set_config -n ActiveGroup -v $argv
|
|
end
|
|
|
|
# group_set_keybinds sets the keybinds to the given tab group
|
|
function group_set_keybinds
|
|
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)
|
|
set -l actual_tag (math $tag + $offset)
|
|
hc keybind $hlwm_mod-$tag use_index \
|
|
(math $actual_tag - 1)
|
|
hc keybind $hlwm_mod-Shift-$tag move_index \
|
|
(math $actual_tag - 1)
|
|
end
|
|
end |