You are not logged in.
Pages: 1
Hello! I'm new to this Linux thing but I think I have my first little contribution!!
I was using this CompizSnap script to emulate Aero snap window resizing on my desktop. (http://mikesubuntu.com/2010/06/snap-win … ng-compiz/)
I'm not sure if there is a different script but I didn't like how you had to select a mouse input ahead of time and the one I use would change as I move my laptop around and it would only work on whichever one it was set to and it was set in a handful of files. I think I fixed that (at least on my setup). Then I reorganized them into single files (controlled by argument) instead of different ones for left,right,top and changed a few things. I was trying to get data extractions to be performed in one command/process. I'm not sure if it's even better and I'm vaguely aware of some bad practices that I theorize may make it run significantly slower (still ~instant of course). Specifically, .*? pattern matching. But I hardly know what I'm doing so it's a work in progress for now! Any input on how to make it better is hella appreciated!
Alright so check this out. Two files: One to resize windows and one that triggers the resize windows script if the mouse is let go while still on the edge of the screen (initially triggered by compiz for me, setup through commands/edge/key bindings). The path of the resize script has to be set in the first one-- is there a better way to do that? I thought about using relative pathing but that seems wrong.
snap_window:
#!/bin/sh
#
# this script attempts to replicate the window snap function from windows!
# aka resizes the active window to the left half, the right half, or maximizes.
# commonly triggered by moving a window to the edge of the screen or
# by pressing something like <super><arrow>
# the original script that provided this is CompizSnap and the only thing I did
# was rearrange some things to use one file with arguments instead of separate
# files.
#
# CompizSnap is a collaborative project from ubuntuforums.org and is free
# software. This script adds window snapping functionality to compiz using the
# commands plugin.
#
# http://mikesubuntu.com/2010/06/snap-windows-to-sides-like-windows-7-using-compiz/
width=$( xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x' )
half=$(( ( $width / 2 ) - 10 ))
case "$1" in
left)
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$half,-10
;;
right)
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$half,0,$half,-1
;;
*) # maximize
wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
;;
esac
snap_window_wait_for_mouse:
#!/bin/sh
#
# this is a modified version of compiz snap that attempts to work on every
# connected mouse instead of a single one.
#
# original:
# http://mikesubuntu.com/2010/06/snap-windows-to-sides-like-windows-7-using-compiz/
border_threshold_px=10
mice=( $(xinput list | # list of all input devices
awk ' /Virtual core pointer/ {flag=1;next} # next two lines constrain
/Virtual core keyboard/ {flag=0} # to just mice
flag{
# the mice lines might look like:
# â¡ Virtual core pointer id=2 [master pointer (3)]
# tear this into...
split($0,id_to_end,"="); # 2 [master pointer (3)]
split(id_to_end[2],id," "); # 2
print id[1]
} ') )
for mouse in ${mice[@]}
do
if /usr/bin/xinput --query-state "$mouse" | grep down
then
while( /usr/bin/xinput --query-state "$mouse" | grep down )
do
sleep 0.05
done
# check if mouse is still at a border when released
read x y <<< $( xinput --query-state $mouse |
sed -n 's/valuator\[[01]\]=\([0-9]\+\)$/\1/p' )
screen_x=$( xdpyinfo |
sed -n 's/.*dimensions:\s*\([0-9]\+\)x.*/\1/p' )
if [ $x -le $border_threshold_px ]
then
:
elif [ $y -le $border_threshold_px ]
then
:
elif [ $x -ge $(( screen_x - border_threshold_px )) ]
then
:
else
exit 0
fi
sh /usr/local/bin/window_snap/snap_window $1
exit
fi
done
The way I personally have it configured is I put the files in /usr/local/bin/window_snap/ and set the compiz custom commands (top left menu icon in ccsm) to:
sh /usr/local/bin/window_snap/snap_window_wait_for_mouse left
sh /usr/local/bin/window_snap/snap_window_wait_for_mouse right
sh /usr/local/bin/window_snap/snap_window_wait_for_mouse max
sh /usr/local/bin/window_snap/snap_window left
sh /usr/local/bin/window_snap/snap_window right
sh /usr/local/bin/window_snap/snap_window max
I then set the first 3 to edge bindings to be triggered when a window is dragged to the edge of the screen and then the next 3 to <super>{<left>,<right><up>}
Same dependency on wmctrl.
My Problems
I don't really know when to to prefer sed vs. awk. awk seems to get strange when you do stranger data extraction but it is scriptable so I think there is a lot of expressive power there for other uses. I was trying (atm unsuccessfully) to make sed quit after it found the first match instead of searching the rest of the string (e.g. for finding the screen x resolution).
The previous scripts solution was:
width=$( xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x' )
and my try was:
screen_x=$( xdpyinfo | sed -n 's/.*dimensions:\s*\([0-9]\+\)x.*/\1/p' )
The other one was getting the mice xinput ids from "xinput list". I eventually chose to use only awk but before I used both awk and sed but felt that was cheating.
mice=( $(xinput list | # list of all input devices
awk ' /Virtual core pointer/ {flag=1;next} # next two lines constrain
/Virtual core keyboard/ {flag=0} # to just mice
flag{
# the mice lines might look like:
# â¡ Virtual core pointer id=2 [master pointer (3)]
# tear this into...
split($0,id_to_end,"="); # 2 [master pointer (3)]
split(id_to_end[2],id," "); # 2
print id[1]
} ') )
mice=($(xinput list | awk ' /Virtual core pointer/ {flag=1;next} /Virtual core keyboard/ {flag=0} flag{ print $0 }' | sed -r 's/.*?id=([0-9]+).*?$/\1/g'))
Hope someone thinks its neat or something!
Offline
Pages: 1