baskerville / bspwm

A tiling window manager based on binary space partitioning
BSD 2-Clause "Simplified" License
7.72k stars 415 forks source link

Is it possible to get window class and type in external_rule? #398

Closed ghost closed 8 years ago

ghost commented 8 years ago

I want to rule all floating dialog to under mouse Like New File/New Folder, Permission Dialog etc.... Thank you for your advice

ghost commented 8 years ago

I changed title too much.... and sorry for my english.

Chrysostomus commented 8 years ago

I would use external rule to check if the new window is floating, then output id of the floating window to another scripts that uses xdotool and/or xdo/wmutils to move the window under the cursor.

something like

#!/bin/sh
wid=$1
bspc query -T -n $wid | grep - q '"state":"floating"' && window-placer $wid

best way to get mouse position is eval $(xdotool getmouselocation --shell)

The rest depends a bit on how would you like to place that window relative to cursor? I'm guessing on the center, but not outside the desktop?

Chrysostomus commented 8 years ago

Here are some example scripts that may or may not be useful on building your own: https://github.com/Chrysostomus/bspwm-scripts/blob/master/bin/window-placer https://github.com/Chrysostomus/rootmenu/blob/master/bin/dboxmenu

Chrysostomus commented 8 years ago

Here is an example script that places window centered around cursor, but still fully within the desktop. Could be improved to use less different tools. Right now it uses xdotool, xdo and wmutils.

#!/bin/sh
#
### window-placer

window=$1
eval $(xdotool getmouselocation --shell)
monitor_widht=$(wattr w $(lsw -r))
monitor_height=$(wattr h $(lsw -r))
window_height=$(wattr h $window)
window_widht=$(wattr w $window)
maxx=$(( monitor_widht - window_widht - 5 ))
minx=0
miny=$PANEL_HEIGHT
maxy=$(( monitor_height - window_height - 5 ))
XP=$((X - window_widht / 2))
[ $XP -gt $maxx ] && XP=$maxx
[ $XP -lt $minx ] && XP=$minx
YP=$((Y - window_height / 2))
[ $YP -lt $miny ] && YP=$miny
[ $YP -gt $maxy ] && YP=$maxy

echo "$Y $YP $X $XP"
xdo move -x $XP -y $YP $window
Chrysostomus commented 8 years ago

This one uses just xdotool and wmutils. If you know your resolution and have only 1 monitor, you can hard code it and drop wmutils too.

#!/bin/sh
#
###

window=$1
eval $(xdotool getwindowgeometry --shell $window)
eval $(xdotool getmouselocation --shell)
monitor_widht=$(wattr w $(lsw -r))
monitor_height=$(wattr h $(lsw -r))
window_height=$HEIGHT
window_widht=$WIDTH
maxx=$(( monitor_widht - window_widht - 5 ))
minx=0
miny=$PANEL_HEIGHT
maxy=$(( monitor_height - window_height - 5 ))
XP=$((X - window_widht / 2))
[ $XP -gt $maxx ] && XP=$maxx
[ $XP -lt $minx ] && XP=$minx
YP=$((Y - window_height / 2))
[ $YP -lt $miny ] && YP=$miny
[ $YP -gt $maxy ] && YP=$maxy

xdotool windowmove $window $XP $YP```