Pointer-based screen detection

performance
Kamil Sołtysik 6 years ago committed by Fox Kiester
parent 183d983e4d
commit 60435d240f
No known key found for this signature in database
GPG Key ID: 316E205D6017DBFF

41
tdrop

@ -43,6 +43,8 @@ options:
for width or height to values relative to the size of the for width or height to values relative to the size of the
current monitor and force resizing of the dropdown when current monitor and force resizing of the dropdown when
the monitor changes (default: false) the monitor changes (default: false)
-t use mouse pointer location for detecting which monitor is the current
one
--wm set the window manager name to mimic another window manager --wm set the window manager name to mimic another window manager
(for use with -a) (for use with -a)
--class name manually specify the class of the window (can be obtained with xprop) --class name manually specify the class of the window (can be obtained with xprop)
@ -91,11 +93,12 @@ clearwid=false
cancel_auto_show=true cancel_auto_show=true
auto_detect_wm=false auto_detect_wm=false
monitor_aware=false monitor_aware=false
pointer_monitor_detection=false
wm= wm=
user_set_wm=false user_set_wm=false
class= class=
name= name=
while getopts :h:w:x:y:s:n:c:C:l:L:p:P:u:U:d:f:-:am opt while getopts :h:w:x:y:s:n:c:C:l:L:p:P:u:U:d:f:-:amt opt
do do
case $opt in case $opt in
h) height=$OPTARG;; h) height=$OPTARG;;
@ -118,8 +121,9 @@ do
f) program_flags=$OPTARG;; f) program_flags=$OPTARG;;
a) auto_detect_wm=true;; a) auto_detect_wm=true;;
m) monitor_aware=true;; m) monitor_aware=true;;
t) pointer_monitor_detection=true;;
-) -)
if [[ $OPTARG =~ ^(auto-detect-wm|monitor-aware|clear|no-cancel|help)$ ]] || \ if [[ $OPTARG =~ ^(auto-detect-wm|monitor-aware|pointer-monitor-detection|clear|no-cancel|help)$ ]] || \
[[ $OPTARG == *=* ]]; then [[ $OPTARG == *=* ]]; then
OPTION=${OPTARG%%=*} OPTION=${OPTARG%%=*}
OPTARG=${OPTARG#*=} OPTARG=${OPTARG#*=}
@ -150,6 +154,7 @@ do
program-flags) program_flags=$OPTARG;; program-flags) program_flags=$OPTARG;;
auto-detect-wm) auto_detect_wm=true;; auto-detect-wm) auto_detect_wm=true;;
monitor-aware) monitor_aware=true;; monitor-aware) monitor_aware=true;;
pointer-monitor-detection) pointer_monitor_detection=true;;
wm) wm=$OPTARG wm) wm=$OPTARG
user_set_wm=true;; user_set_wm=true;;
class) class=$OPTARG;; class) class=$OPTARG;;
@ -268,16 +273,26 @@ update_geometry_settings_for_monitor() {
x_width=$(echo "$monitor_geo" | gawk -F 'x' '{print $1}') x_width=$(echo "$monitor_geo" | gawk -F 'x' '{print $1}')
y_height=$(echo "$monitor_geo" | gawk -F 'x|+' '{print $2}') y_height=$(echo "$monitor_geo" | gawk -F 'x|+' '{print $2}')
else else
local wid wininfo window_x window_y monitors_info x_end y_end local current_x current_y monitors_info x_end y_end
# determine current monitor in generic way if ! $pointer_monitor_detection; then
wid=$(xdotool getactivewindow) # determine current monitor using active window
if [[ -z $wid ]]; then local wid wininfo
# will try again after remapping or creating the dropdown wid=$(xdotool getactivewindow)
return 1 if [[ -z $wid ]]; then
# will try again after remapping or creating the dropdown
return 1
fi
wininfo=$(xwininfo -id "$wid")
current_x=$(echo "$wininfo" | gawk '/Absolute.*X/ {print $4}')
current_y=$(echo "$wininfo" | gawk '/Absolute.*Y/ {print $4}')
else
# determine current monitor using pointer location
local pointerinfo
pointerinfo=$(xdotool getmouselocation --shell)
current_x=$(echo "$pointerinfo" | sed -n 's/X=//p')
current_y=$(echo "$pointerinfo" | sed -n 's/Y=//p')
fi fi
wininfo=$(xwininfo -id "$wid")
window_x=$(echo "$wininfo" | gawk '/Absolute.*X/ {print $4}')
window_y=$(echo "$wininfo" | gawk '/Absolute.*Y/ {print $4}')
monitors_info=$(xrandr --query | gawk '/ connected/ {gsub("primary ",""); print}') monitors_info=$(xrandr --query | gawk '/ connected/ {gsub("primary ",""); print}')
while read -r monitor; do while read -r monitor; do
monitor_geo=$(echo "$monitor" | gawk '{print $3}') monitor_geo=$(echo "$monitor" | gawk '{print $3}')
@ -288,8 +303,8 @@ update_geometry_settings_for_monitor() {
y_height=$(echo "$monitor_geo" | gawk -F 'x|+' '{print $2}') y_height=$(echo "$monitor_geo" | gawk -F 'x|+' '{print $2}')
x_end=$((x_begin+x_width)) x_end=$((x_begin+x_width))
y_end=$((y_begin+y_height)) y_end=$((y_begin+y_height))
if [[ $window_x -ge $x_begin ]] && [[ $window_x -lt $x_end ]] && \ if [[ $current_x -ge $x_begin ]] && [[ $current_x -lt $x_end ]] && \
[[ $window_y -ge $y_begin ]] && [[ $window_y -lt $y_end ]]; then [[ $current_y -ge $y_begin ]] && [[ $current_y -lt $y_end ]]; then
current_monitor=$(echo "$monitor" | gawk '{print $1}') current_monitor=$(echo "$monitor" | gawk '{print $1}')
break break
fi fi

@ -83,6 +83,9 @@ If there are available settings for the detected window manager for the -l, -L,
\fB-m\fR, \fB --monitor-aware\fR \fB-m\fR, \fB --monitor-aware\fR
This option only applies for dropdowns (not auto-hiding and auto-showing). Specify that geometry values should be relative to the current monitor. For example, if the width is a percentage or negative value, the pixel width will be calculated as a percentage of the current monitor's width (instead of the combined width of all monitors). If the monitor changes, this option will cause a dropdown to be resized to fit the given percentages. Note that this option assumes xrandr is being used and requires xrandr to work. (default: false) This option only applies for dropdowns (not auto-hiding and auto-showing). Specify that geometry values should be relative to the current monitor. For example, if the width is a percentage or negative value, the pixel width will be calculated as a percentage of the current monitor's width (instead of the combined width of all monitors). If the monitor changes, this option will cause a dropdown to be resized to fit the given percentages. Note that this option assumes xrandr is being used and requires xrandr to work. (default: false)
.TP .TP
\fB-t\fR, \fB --pointer-monitor-detection\fR
Use mouse pointer location for detecting which monitor is the current one so terminal will be displayed on it. Without this option, the monitor with currently active window is considered the current one. This option is only effective if -m / --monitor-aware option is enabled.
.TP
\fB --wm=NAME\fR \fB --wm=NAME\fR
Specify the window manager name (which determines the default settings when -a is specified). This may be useful if you've change the name of your window manager using wmname as this will prevent tdrop from correctly detecting the real window manager name. This could also potentially be useful if the all the default -a settings for another window manager work with the current one (e.g. if using a similar but differently named fork of some window manager). (default: automatically detected) Specify the window manager name (which determines the default settings when -a is specified). This may be useful if you've change the name of your window manager using wmname as this will prevent tdrop from correctly detecting the real window manager name. This could also potentially be useful if the all the default -a settings for another window manager work with the current one (e.g. if using a similar but differently named fork of some window manager). (default: automatically detected)
.TP .TP

Loading…
Cancel
Save