Determine monitor in better way on bspwm and i3

Addresses #3

This ensures that -m will work even when the focused workspace on a
monitor is empty.
long-opts
noctuid 9 years ago
parent dbc3656da8
commit 0d369bef73

21
tdrop

@ -146,7 +146,25 @@ update_geometry_settings_for_monitor() {
# monitor IF the monitor has changed since the last time the dropdown
# was used
# determine curent monitor
# it is conceivable that a user may want to use -m but not -a, so
# get the wm from with
# in this function
wm=$(get_window_manager)
if [[ $wm == bspwm ]]; then
current_monitor=$(bspc query -m -M)
elif [[ $wm == i3 ]]; then
# I'd rather not make jq a dependency
current_monitor=$(i3-msg -t get_workspaces | sed 's/{"num"/\n/g' | awk -F ',' '/focused":true/ {sub(".*output",""); gsub("[:\"]",""); print $1}')
fi
if [[ -n $current_monitor ]]; then
monitor_geo=$(xrandr --query | awk "/$current_monitor/ {gsub(\"primary \",\"\"); print \$3}")
x_begin=$(echo "$monitor_geo" | awk -F '+' '{print $2}')
y_begin=$(echo "$monitor_geo" | awk -F '+' '{print $3}')
x_width=$(echo "$monitor_geo" | awk -F 'x' '{print $1}')
y_height=$(echo "$monitor_geo" | awk -F 'x|+' '{print $2}')
else
# determine current monitor in generic (hacky) way
wininfo=$(xwininfo -id "$(xdotool getactivewindow)")
window_x=$(echo "$wininfo" | awk '/Absolute.*X/ {print $4}')
window_y=$(echo "$wininfo" | awk '/Absolute.*Y/ {print $4}')
@ -165,6 +183,7 @@ update_geometry_settings_for_monitor() {
break
fi
done <<< "$monitors_info"
fi
# update x and y offsets, so that will appear on correct screen
# (required for some WMs apparently, but not for others)

Loading…
Cancel
Save