Skip to content

Instantly share code, notes, and snippets.

@thugcee
Forked from jpentland/tabc.sh
Last active May 18, 2022 09:46
Show Gist options
  • Save thugcee/87158c313070c666efd43c0a64a2a2e7 to your computer and use it in GitHub Desktop.
Save thugcee/87158c313070c666efd43c0a64a2a2e7 to your computer and use it in GitHub Desktop.
Suckless' tabbed integration with BSPWM. This configuration supports joining any two neighbouring windows into a new tabbed, removing windows from tabbed and when last window is from tabbed removed then tabbed instance is closed. This slightly modified `tabc.sh` allows to omit id of the removed window (the current one is removed by default).
# Remove current tab from tabbed
super + mod1 + t; r
tabc.sh $(bspc query -N -n focused) remove
# At given direction: join two windows into a new tabbed or add window to an existing tabbed
super + mod1 + t; {Left,Down,Up,Right}
tabc.sh $(bspc query -N -n {west,south,north,east}) add $(bspc query -N -n focused)
#define MODKEY Mod4Mask
static Key keys[] = {
/* modifier key function argument */
{ MODKEY|Mod1Mask, XK_Return, focusonce, { 0 } },
{ MODKEY|Mod1Mask, XK_Return, spawn, { 0 } },
{ MODKEY|Mod1Mask, XK_Next, rotate, { .i = +1 } },
{ MODKEY|Mod1Mask, XK_Prior, rotate, { .i = -1 } },
{ MODKEY|Mod1Mask|ShiftMask, XK_Prior, movetab, { .i = -1 } },
{ MODKEY|Mod1Mask|ShiftMask, XK_Next, movetab, { .i = +1 } },
#!/bin/sh
# Usage:
# tabc.sh <tabbed-id> <command>
# Commands:
# add <window-id> - Add window to tabbed
# remove <window-id> - Remove window from tabbed
# list - List all clients of tabbed
TABBED_CONFIG="-c -k -o #111111 -O #7A7777 -t #8F8E24 -T #FFFFFF"
#
# Functions
#
# Get wid of root window
get_root_wid () {
xwininfo -root | awk '/Window id:/{print $4}'
}
# Get children of tabbed
get_clients () {
id=$1
xwininfo -id $id -children | sed -n '/[0-9]\+ \(child\|children\):/,$s/ \+\(0x[0-9a-z]\+\).*/\1/p'
}
# Get class of a wid
get_class () {
id=$1
xprop -id $id | sed -n '/WM_CLASS/s/.*, "\(.*\)"/\1/p'
}
#
# Main Program
#
tabbed=$1; shift
cmd=$1; shift
if [ "$(get_class $tabbed)" != "tabbed" ]; then
# It looks like what supposed to be an id of a tabbed window is not a
# tabbed.
if [ $cmd = "add" ]; then
# But this is the `add` command so lets join booth windows in a
# new tabbed instance. First start tabbed, add the target window
# and then proceed to normal `add`.
sibling=$tabbed
tabbed=$(tabbed $TABBED_CONFIG -d) && xdotool windowreparent $sibling $tabbed || exit 2
else
# For other commands we need tunning tabbed instance
echo "$tabbed is not an instance of tabbed"
exit 1
fi
fi
case $cmd in
add)
wid=$1; shift
xdotool windowreparent $wid $tabbed
;;
remove)
wid=$1
# When there isn't supplied an id of a window to be removed
# from tabbed then remove the currently active one.
test -n "$win" || wid=$(get_clients $tabbed| head -1)
xdotool windowreparent $wid $(get_root_wid)
;;
list)
get_clients $tabbed
;;
esac
@gh4dp
Copy link

gh4dp commented Jan 26, 2021

I do not understand the purpose of tabbed_slash_config.h, I could imagine placing it into the source code and do make install and somehow something would be added/facilitated, but that's all.

Do I need to modify the make file?

Could you explain ?

@thugcee
Copy link
Author

thugcee commented Jan 26, 2021

I do not understand the purpose of tabbed_slash_config.h, I could imagine placing it into the source code and do make install and somehow something would be added/facilitated, but that's all.

Sorry maybe I should explain it better. It's tabbed/config.h (gist file names can't contain /, that's why you see _slash_).
So you should put or rather replace part of config.h in tabbed's source code. Tabbed follows suckless philosophy and to change it's configuration you have to edit and recompile code.

Do I need to modify the make file?

No.

@thugcee
Copy link
Author

thugcee commented May 10, 2021

License for above code is MIT (https://mit-license.org/).

@trn1ty
Copy link

trn1ty commented May 10, 2021

Thank you! Sorry I deleted my comment, I noticed this isn't actually the upstream so I assume tabc.sh is under whatever license jpentland chooses (assuming there is license and the license wants derivatives to share alike).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment