Page 15 of 16 FirstFirst ... 513141516 LastLast
Results 141 to 150 of 158

Thread: Aero Snap function?

  1. #141
    Join Date
    Oct 2006
    Location
    Cologne, Europe
    Beans
    2,570
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Aero Snap function?

    @gpwil1: Configuration should be left out of the script.
    First of all, it's supposed to add a feature. A configuration script just needs to be run once. Adding config options to the script would mean configuring/checking every time the script is initiated.
    Additionally, the user should configure the way he/she wants it him/herself.
    For example, I don't have the "side snaps" bound to the edges but to the lower corners, because the edges are reserved for the cube plugin.
    And last but not least, users should be aware of where to set/configure features.

    If I find the time I will write an English How-To over the weekend, so it can be linked in the script's header.


    @Chrissss: We'll need additional info what that "Microsoft® Nano Transceiver" is for in this case and why it's listed twice in the pointer section.

    I guess we could narrow it down like this in the script, if no mouse is found:
    Code:
    xinput -list | grep "slave  pointer" | grep -iv "virtual\|touchpad\|trackpoint\|Macintosh mouse button emulation"
    but the issue with multiple listings won't be solved by this.

  2. #142
    Join Date
    Jun 2007
    Beans
    30
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Aero Snap function?

    Quote Originally Posted by Forlong View Post
    @gpwil1: Configuration should be left out of the script.
    First of all, it's supposed to add a feature. A configuration script just needs to be run once. Adding config options to the script would mean configuring/checking every time the script is initiated.
    Additionally, the user should configure the way he/she wants it him/herself.
    ..
    I agree it would be beneficial for users to know where to configure settings, and that others configurations may be different, but disagree with your first comment. The configuration can be done once on the initiation of the script, and would only require an if statement upon rerunning.

    The reasoning behind having it automated is to encourage new users to adopt ubuntu, making it easier is what its all about.


    For my intended purpose setting the value through ccsm doesn't help, since I am configuring a remaster from a chrooted environment through the terminal (I don't like having to copy over configuration files, I rather have a script to configure my settings).

    Anyway, it was just a suggestion.

  3. #143
    Join Date
    Aug 2007
    Location
    Anchorage
    Beans
    137
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Aero Snap function?

    Yeah only thing happened was it told me to install xdotool, then nothing happens not even any errors?

    Debian squeeze,

    any suggestions?
    Google Will Rule the world I can see it.!

  4. #144
    Join Date
    Oct 2006
    Location
    Cologne, Europe
    Beans
    2,570
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Aero Snap function?

    Run Compiz like this in the terminal and see what it says then while triggering compizsnap
    Code:
    VERBOSE=yes compiz

  5. #145
    Join Date
    Feb 2011
    Beans
    1

    Re: Aero Snap function?

    Ich habe ein paar Optimierungen angebracht:
    1) Fenster sind auch in allen Ecken positionierbar.
    2) Es werden alle Devices "slave pointer" abgefragt.
    3) Korrektur: Falls man ein Fenster erst gegen den linken und dann gegen den oberen Rand schiebt, wird in den o.g. Versionen das Fenster trotzdem links ausgerichtet.
    4) Man benötigt nur einen "Compiz-Command", der an jeder gewünschten Kante (u. Ecke) aktiviert wird (ohne angehängtem Parameter). z.B. ~/bin/compizsnap

    Für Optimierungs- und Korrekturvorschläge wäre ich dankbar.
    Hier ist das Script:

    Code:
    #!/bin/bash
    ##################################################################
    #
    # Angelehnt an:
    # http://wwww.ubuntuforums.org/showthread.php?t=1294661
    # http://linuxundich.de/de/ubuntu/aero-snap-mit-gnome-und-compiz/
    #
    ##################################################################
    
    DEVICES=`xinput -list | grep "slave  pointer" | grep -iv "virtual" | grep id= | sed 's:.*id=\([0-9]*\).*:\1:' `
    DEVICE_ARRAY=($DEVICES)
    
    DX=2
    DY=42
    WIDTH=$(xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x')
    HEIGHT=$(xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 2 -d 'x' | cut -f 1 -d p)
    WIDTH=$((WIDTH+1-1))    #Damit Leerzeichen in WIDTH u. HEIGHT wegfallen... Geht bestimmt "schöner"
    HEIGHT=$((HEIGHT+1-1))
    HWIDTH=$(($WIDTH/2-$DX))
    HHEIGHT=$(($HEIGHT/2-$DY))
    TOLERANCE=3
    
    
    do_choice() {
        X=$(xdotool getmouselocation | awk '{print $1}' | cut -d : -f 2)
        Y=$(xdotool getmouselocation | awk '{print $2}' | cut -d : -f 2)
        #Horizontal
        C=0    #center
        if [ $X -le $TOLERANCE ]; then
            C=1    #left
        fi
        if [ $X -ge $(($WIDTH-$TOLERANCE)) ]; then
            C=2    #right
        fi
        #Vertikal
        if [ $Y -le $TOLERANCE ]; then
            C=$((C+3))    #top
        fi
        if [ $Y -ge $(($HEIGHT-$TOLERANCE)) ]; then
            C=$((C+6))    #bottom
        fi
    
        case $C in
        # 0) center
        1) wmctrl -r :ACTIVE: -b remove,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HWIDTH,0 ;;             #left
        2) wmctrl -r :ACTIVE: -b remove,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$((HWIDTH+DX)),0,$HWIDTH,0 ;;     #right
        3) wmctrl -r :ACTIVE: -b remove,maximized_vert && wmctrl -r :ACTIVE: -b add,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,0,$HHEIGHT ;;            #top 
        6) wmctrl -r :ACTIVE: -b remove,maximized_vert && wmctrl -r :ACTIVE: -b add,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,$((HHEIGHT+DY)),$WIDTH,$HHEIGHT ;; #bottom
        4) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,$HWIDTH,$HHEIGHT ;;                     #topleft
        5) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,$((HWIDTH+DX)),0,$HWIDTH,$HHEIGHT ;;                 #topright
        7) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,$((HHEIGHT+DY)),$HWIDTH,$HHEIGHT ;;                 #bottomleft
        8) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,$((HWIDTH+DX)),$((HHEIGHT+DY)),$HWIDTH,$HHEIGHT ;;         #bottomright 
        esac
    }
    
    
    #Ermittlem, ob Button gedrückt ist
    DOWN=0
    for i in ${!DEVICE_ARRAY[@]}
    do
        if [ `xinput --query-state ${DEVICE_ARRAY[i]} | grep down` ]; then
            DOWN=1
        fi
    done
    
    #Button gerückt?
    if  [ $DOWN -gt 0 ]; then
        #Prüfe solange, bis Button losgelassen wurde...
        while [ $DOWN -gt 0 ]
        do 
            DOWN=0
            for i in ${!DEVICE_ARRAY[@]}
            do
                if [ `xinput --query-state ${DEVICE_ARRAY[i]} | grep down` ];then
                    DOWN=1
                fi
            done
        done
        #...dann nehme Aktionen vor.
        do_choice
    fi
    Attached Files Attached Files

  6. #146
    Join Date
    Jan 2007
    Beans
    31

    Re: Aero Snap function?

    Hi everyone!

    As the last script on this thread didn't quite cut it for me (working on several screens here), I made some additions to it (became kind of a monster )... Maybe other people find it useful.

    Big Thanks to raving for giving me a good basis to start from!

    @raving: Ich hoffe das ist ok für dich!! Ich wäre auch für Verbesserungen, Kritik und mögliche Zusammenarbeit dankbar!!

    -----

    BIG BOLD DISCLAIMER: This is my first serious attempt to bash scripting, so it may not be beautiful or structured and MANY things could be done better. Just share your thoughts and we will together improve the script!! Oh, and of course you use it on your own resposibility

    So now the script will work on multiple displays with multiple screens, and will provide feedback to the user of the future position of the window through compiz's firepaint. It's not the classiest solution to it, but was the first resource i had at hand when building this (if anyone has a suggestion on how to draw rectangles easily from a bash script with no further dependencies, let me know!). You can adjust the effect with ccsm.

    At the moment the script is configured so that the upper and left corner of side X react exactly the same as the action for side X itself, and the center of the screen just aborts any operation (you can, however, while you still hold your mouse button, still select a sector of the screen to resize your window). As this is based on raving's code, all areas in the screen could be configured to perform a different action.

    Keeping the name of the script as compizconfig is important!! As moving the mouse to a different edge of the window could trigger different copies of it, I tried to make the script aware of this fact -based on the filename.

    TL;DR Some improvements made. Here is the code, hope you enjoy it


    Code:
    #!/bin/bash
    #####################################################################
    #
    # Based on:
    # http://wwww.ubuntuforums.org/showthread.php?t=1294661
    # http://linuxundich.de/de/ubuntu/aero-snap-mit-gnome-und-compiz/
    #
    # Extended by plafuro (ubuntuforums) on 2011/3/6
    #	- Now it also works on any screen of any display
    #	- Particles used for feedback to the user 
    #	  (Needs compiz and firepaint plugin, adjust firepaint settings
    #	  for desired effect). A better way of drawing this (i.e. with
    #	  primitives) is very welcome!.
    #		
    ######################################################################
    
    ## Holding the mouse next to the edge may trigger several copies 
    ## we will try to avoid that
    
    if [ $(echo `ps -ef |grep -c compizsnap.sh`) -gt 5 ]; then
    exit
    fi
    
    ### Store all pointer devices in an array
    
    DEVICES=`xinput -list | grep "slave  pointer" | grep -iv "virtual" | grep id= | sed 's:.*id=\([0-9]*\).*:\1:' `
    DEVICE_ARRAY=($DEVICES)
    DX=2
    DY=42
    
    ### On which screen are we? 
    ### This will allow the script to work for all screens on the current display
    
    THISSCREEN=$(echo $DISPLAY  | cut -f 2 -d '.')
    THISSCREEN=$(($THISSCREEN+1))
    XINFOSTR=$(xdpyinfo -display $DISPLAY |grep 'dimensions:' | sed -n ''$THISSCREEN'p')
    
    ### General screen information
    ### Tolerance can be adjusted based on user preference 
    
    WIDTH=$(echo $XINFOSTR | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x')
    HEIGHT=$(echo $XINFOSTR | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 2 -d 'x' | cut -f 1 -d p)
    WIDTH=$(($WIDTH+1-1))    #Damit Leerzeichen in WIDTH u. HEIGHT wegfallen... Geht bestimmt "schöner"
    HEIGHT=$(($HEIGHT+1-1))
    HWIDTH=$(($WIDTH/2-$DX))
    HHEIGHT=$(($HEIGHT/2-$DY))
    VTOLERANCE=$(($HEIGHT/5))
    HTOLERANCE=$(($WIDTH/5))
    XROOT=$(xwininfo -root | grep id: | awk '{ print $4 }')
    
    ### Position of the mouse
    SECTOR=0
    
    ### Coordenates for effects
    Particle1X=0
    Particle2X=0
    Particle3X=0
    Particle4X=0
    Particle1Y=0
    Particle2Y=0
    Particle3Y=0
    Particle4Y=0
    NEWMOUSEPOSITION=0
    OLDMOUSEPOSITION=0
    
    
    ### The tolerance can be adjusted for a better recognition of the
    ### screen sector. This works well on 1280x1024 and 1920x1080
    
    VTOLERANCE=$(($HEIGHT/5))
    HTOLERANCE=$(($WIDTH/5))
    
    
    ##############################################################
    ### mousePosition
    ### This will store mouse position in the screen 
    ### as a sector (upperleft, upperright, top, bottom, etc)
    ##############################################################
    
    mousePosition(){
    
        X=$(xdotool getmouselocation | awk '{print $1}' | cut -d : -f 2)
        Y=$(xdotool getmouselocation | awk '{print $2}' | cut -d : -f 2)
    
        TEMP=0
        #Horizontal
        if [ $X -lt $(($HWIDTH-$HTOLERANCE)) ]; then
            SECTOR=1    					#left
    	TEMP=1
        fi
    
        if [ $X -gt $(($HWIDTH+$HTOLERANCE)) ]; then
            SECTOR=2    					#right
    	TEMP=1
        fi
    
        #Vertikal
        if [ $Y -lt $(($HHEIGHT-$VTOLERANCE)) ]; then
            SECTOR=$((C+3))    				#top
    	TEMP=1
        fi 
    
        if [ $Y -gt $(($HHEIGHT+$VTOLERANCE)) ]; then
            SECTOR=$((C+6))    				#bottom
    	TEMP=1
        fi
    
        if [ $TEMP -lt 1  ];then
    	SECTOR=0					#center
        fi
    
        NEWMOUSEPOSITION=$SECTOR
    
        case $SECTOR in
        0)  #CENTER
    	particlesCenter		;;
        3)  #TOP
    	particlesTop		;;   
        1)  #LEFT
    	particlesLeft		;;   
        2)  #RIGHT
    	particlesRight		;;         
        6)  #BOTTOM
    	particlesBottom		;;   
        4)  #UPPERLEFT
    	particlesUpperLeft	;;   
        5)  #UPPERRIGHT
    	particlesUpperRight     ;;   
        7)  #LOWERLEFT
    	particlesLowerLeft      ;;   
        8)  #LOWERRIGHT
    	particlesLowerRight     ;;   
        esac
    
    }
    
    ########################################################################
    ### do_SECTOR
    ### This function triggers the action corresponding to a certain sector
    ########################################################################
    
    do_Sector() {
    
        case $SECTOR in
        0) do_center     ;;
        3) do_top	     ;;   
        1) do_left       ;;
        2) do_right      ;;       
        6) do_bottom     ;;
        4) do_upperleft  ;;
        5) do_upperright ;;
        7) do_lowerleft  ;;
        8) do_lowerright ;;
        esac
    }
    
    ##########################################################################
    ### particlesXXX
    ### Particle positions for the different sectors in the screen/behaviours
    ##########################################################################
    
    particlesTop(){
    	
    	#Particle1X=0
    	#Particle1Y=0
    
    	#Particle2X=0
    	#Particle2Y=$WIDTH
    
    	#Particle3X=0
    	#Particle3Y=$HHEIGHT
    
    	#Particle4X=$WIDTH
    	#Particle4Y=$HHEIGHT
    
    	particlesFullScreen
    }
    
    
    particlesBottom(){
    
    
    	Particle1X=0
    	Particle1Y=$((HHEIGHT+DY))
    	Particle2X=$WIDTH
    	Particle2Y=$((HHEIGHT+DY))
    	Particle3X=0
    	Particle3Y=$HEIGHT
    	Particle4X=$WIDTH
    	Particle4Y=$HEIGHT
    
    }
    
    particlesLeft(){
    
    	Particle1X=0
    	Particle1Y=0
    
    	Particle2X=$HWIDTH
    	Particle2Y=0
    
    	Particle3X=0
    	Particle3Y=$HEIGHT
    
    	Particle4X=$HWIDTH
    	Particle4Y=$HEIGHT
    
    
    }
    
    particlesRight(){
    
    
    	Particle1X=$HWIDTH
    	Particle1Y=0
    
    	Particle2X=$WIDTH
    	Particle2Y=0
    
    	Particle3X=$HWIDTH
    	Particle4X=$WIDTH
    	Particle3Y=$HEIGHT
    	Particle4Y=$HEIGHT
    
    }
    
    particlesUpperRight(){
    
    particlesRight
    
    }
    
    particlesUpperLeft(){
    
    particlesLeft
    
    }
    
    
    particlesLowerRight(){
    
    particlesRight
    
    }
    
    particlesLowerLeft(){
    
    particlesLeft
    
    }
    
    particlesFullScreen(){
    
    
    	Particle1X=0
    	Particle1Y=0
    
    	Particle2X=$WIDTH
    	Particle2Y=0
    
    	Particle3X=0
    	Particle4X=$WIDTH
    	Particle3Y=$HEIGHT
    	Particle4Y=$HEIGHT
    
    }
    
    particlesCenter(){
    
    clearParticles
    	Particle1X=0
    	Particle1Y=0
    	Particle2X=0
    	Particle2Y=0
    	Particle3X=0
    	Particle4X=0
    	Particle3Y=0
    	Particle4Y=0
    
    }
    
    ###############################################################
    ### do_XXX
    ### Actions for the different sectors in the screen/behaviours
    ###############################################################
    
    
    do_top(){
    
    #wmctrl -r :ACTIVE: -b remove,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$WIDTH,$HHEIGHT
    do_FullScreen
    }
    
    do_bottom(){
    wmctrl -r :ACTIVE: -b remove,maximized_vert & wmctrl -r :ACTIVE: -e 0,0,$((HHEIGHT+DY)),$WIDTH,$HHEIGHT
    
    }
    
    do_right(){
    wmctrl -r :ACTIVE: -b remove,maximized_horz & wmctrl -r :ACTIVE: -b add,maximized_vert & wmctrl -r :ACTIVE: -e 0,$((HWIDTH+DX)),0,$HWIDTH,0
    
    }
    
    
    do_left(){
    
    wmctrl -r :ACTIVE: -b remove,maximized_horz & wmctrl -r :ACTIVE: -b add,maximized_vert & wmctrl -r :ACTIVE: -e 0,0,0,$HWIDTH,0
    
    }
    
    
    do_upperleft(){
    
    do_left
    
    }
    
    
    do_lowerleft(){
    
    do_left
    
    }
    
    
    do_upperright(){
    
    do_right
    
    }
    
    
    do_lowerright(){
    
    do_right
    
    }
    
    do_center(){
    
    clearParticles
    
    }
    
    do_FullScreen(){
    
    wmctrl -r :ACTIVE: -b add,maximized_vert & wmctrl -r :ACTIVE: -b add,maximized_horz
    
    }
    
    ####################################################################
    ### createXXX and clearParticles
    ### These funcions are meant for section previsualisation purposes,
    ### not really needed, but wanted to give the user some feedback 
    ### on what will happen if mouse button is released
    ####################################################################
    
    createSingleParticle(){
    
    dbus-send --type=method_call --dest=org.freedesktop.compiz/org/freedesktop/compiz/dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/firepaint/allscreens/add_particle org.freedesktop.compiz.activate string:'root' int32:$XROOT string:'x' double:$1 string:'y' double:$2
    
    }
    
    createParticles(){
    
    ## For the sake of performance we will avoid drawing along the x axis 
    ## if the line to draw is at the very top or the very bottom
    
    if [ $Particle1Y -gt 0 ]; then
    createParticleLineX $Particle1X $Particle2X $Particle1Y 
    fi
    
    if [ $Particle3Y -lt $HEIGHT ]; then
    createParticleLineX $Particle3X $Particle4X $Particle3Y 
    fi
    
    createParticleLineY $Particle2Y $Particle3Y $Particle2X 
    createParticleLineY $Particle1Y $Particle3Y $Particle1X
    
    }
    
    createParticleLineY(){
    
    for (( i=$1; i<$2; i=$i+40 )) 
    do
    
    createSingleParticle $3 $i
    
    done
    
    }
    
    createParticleLineX(){
    
    
    for (( i=$1; i<$2; i=$i+40)) 
    do
    
    createSingleParticle $i $3
    
    done
    
    }
    
    clearParticles(){
    
    dbus-send --type=method_call --dest=org.freedesktop.compiz/org/freedesktop/compiz/dbus-send --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/firepaint/allscreens/clear_key org.freedesktop.compiz.activate string:'root' int32:$XROOT
    
    }
    
    ##############################################################
    ### "Main" process
    ##############################################################
    
    #Ermittlem, ob Button gedrückt ist || Check for button being pressed down
    DOWN=0
    for i in ${!DEVICE_ARRAY[@]}
    do
        if [ `xinput --query-state ${DEVICE_ARRAY[i]} | grep down` ]; then
            DOWN=1
        fi
    done
    
    ## Button gerückt?  || Is the button pressed?
    if  [ $DOWN -gt 0 ]; then
    
        mousePosition
        createParticles
        OLDMOUSEPOSITION=$NEWMOUSEPOSITION			    ## Before starting the loop, save current mouse position
    
        ## Prüfe solange, bis Button losgelassen wurde... || Wait until button is released
        
        while [ $DOWN -gt 0 ]    
        do 
    
    	mousePosition 					    ## Store mouse position
    
    	if [ $NEWMOUSEPOSITION != $OLDMOUSEPOSITION ]; then ## If the mouse has moved, clear and redraw
    	   clearParticles
    	   createParticles	
    	fi
    	
            
    	OLDMOUSEPOSITION=$NEWMOUSEPOSITION
            DOWN=0
    
            for i in ${!DEVICE_ARRAY[@]}
            do
                if [ `xinput --query-state ${DEVICE_ARRAY[i]} | grep down` ];then
                    DOWN=1
    		
                fi
            done
    
        done   
        ## ...dann nehme Aktionen vor.  || When the mouse is released, clear and resize the window
        clearParticles
        do_Sector
    fi
    Attached Files Attached Files
    Last edited by plafuro; March 6th, 2011 at 10:20 AM.

  7. #147
    Join Date
    Mar 2011
    Beans
    9

    Re: Aero Snap function?

    I've never contributed to Ubuntu before, and never coded in bash (or any shell) language before today. If I am misinformed, used bad practice, or if it doesn't work for your laptop/sketch pad/tablet PC/iPad/whatHaveYou, PLEASE forgive me, and if you know it, post the info that can help me improve it.

    Such as the name of the device (IE: Microsoft Mouse/Laptop Touchpad/iPad touchscreen [Anyone got Ubuntu on their iPad? ]) along with the result of this command in the terminal:
    Code:
    xinput list
    Regardless of my shell script savvy, I do know my way around a couple handfuls of other programming/scripting languages- - And was surprised at myself for not knowing BASH prior to reading this thread.

    So I wrote this because I noticed all of the other bash scripts ran loops without any delays, which ran my dual-core, hyper-threaded, Over-Clocked processor up to around 60%-80% from a very unsteady 0%-25%.

    That's really unnecessary- it's a snap feature- and a few milliseconds delay will steady out the processor nicely.

    I took gotsanity's bash script which automatically gets the pointer by seeing which one is being pressed (which, correct me if I'm wrong, should always work? Or do I have to add support for touch-pads, too?)

    I didn't want to use the "grid" thing.. At one point I did but couldn't get it to work exactly right, and it didn't add anything special to what I already had.. I don't care about the corner ones.

    It differs a little tho- because that loop runs as a stand-alone. I re-coded it to use much less nesting (conditions/loops inside each other).

    So- all in all, it's the same- but with a few efficiency improvements, and a little bit easier tutorial to install (combined into one single script).

    I also added a comment for just about every line.. So anyone developing on this script shouldn't have any problems figuring it out.

    So.... Let's get started!

    1.) Open a Terminal

    2.) Install compiz wmctrl: (Window Management Control), and the settings manager.
    Code:
    sudo apt-get install compizconfig-settings-manager wmctrl
    3.) Create & Enter ~/.scripts directory:
    Code:
    cd 
    mkdir .scripts
    cd .scripts
    nautilus ~/.scripts
    4.) While inside "~/.scripts/", create a file named "ubuntu-snap" and paste this code in it; save it.
    Code:
    #!/bin/bash
    
    #
    # CREDITS: gotsanity, s-p-n, others from http://ubuntuforums.org/showthread.php?t=1294661
    # 
    
    # How long to wait for mouse release each iteration
    delay=0.05 # you can set this to whatever you want (in seconds)
    #default delay is 0.05 seconds (50ms)
    
    
    # ----- Don't edit below this line unless you know what you are doing.
    
    
    # Create an array of available "slave pointer" flagged input devices
    #--# (hopefully, all availabe mice)
    IDs=( $(xinput list | grep "slave  pointer" | sed s/".*id=\([0-9]*\).*"/\\1/) )
    
    # Cycle through all "items" in the IDs array
    #--# (read above for info on what IDS is)
    for mouse in ${IDs[*]}
    do
        # If this is true, we should have the correct pointer
        if ( /usr/bin/X11/xinput --query-state $mouse | grep down )
        then
            # Found the right mouse, now break out of this loop
            break
        fi
    done
    
    
    # Attempt to set a width & half
    width=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'`
    
    
    # while the mouse is down
    while (/usr/bin/X11/xinput --query-state $mouse | grep down)
    do
        # (sleeping each iteration results in much less overhead CPU)
        sleep $delay
       
        # Waiting for a release..
        continue
    done
    
    #left function
    left() {
        # condition for if() statement
        if [ "$(/usr/bin/X11/xinput --query-state $mouse | grep "valuator\[0\]=." | sed s/"valuator\[0\]="//)" -le 10 ]
        then
            # snap window to the left half of the screen
            wmctrl -r :ACTIVE: -e 0,0,0,$(($width/2)),-1
       
            # maximize vertically (So height can revert back to what it was)
            wmctrl -r :ACTIVE: -b add,maximized_vert
        fi
    }
    
    #right function
    right() {
        # condition for if() statement
        if [ "$(/usr/bin/X11/xinput --query-state $mouse | grep "valuator\[0\]=." | sed s/"valuator\[0\]="//)" -ge $(($width-10)) ]
        then
            # Generate HALF variable so we don't have to call this division twice..
            half=$(($width/2))
       
            # snap window to the right half of the screen
            wmctrl -r :ACTIVE: -e 0,$half,0,$half,-1
       
            # maximize vertically (So height can revert back to what it was)
            wmctrl -r :ACTIVE: -b add,maximized_vert
        fi
    }
    
    #maximize function
    maximize() {
        # condition for if() statement
        if [ "$(/usr/bin/X11/xinput --query-state $mouse | grep "valuator\[1\]=." | sed s/"valuator\[1\]="//)" -le 10 ]
        then
            # snap window to maximized
            wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
        fi
    }
    not
    
    # $1 is the first command-line argument (next to $0, which is the filename)
    #--# Ex: bash $0 $1. So $0 must be the filename. We're not starting to count with 1, as expected ;)
    #-- --# If you run the command "bash ~/.scripts/ubuntu-snap left" the left function will run
    case $1 in
        'left') left ;;
        'right') right ;;
        'maximize') maximize ;;
    esac
    5.) Now open up CompizConfig Settings Manager (CCSM) By going to System->Preferences->CompizConfig Settings Manager
    or (if you have Gnomenu) by searching "CompizConfig"

    6.) Click on (and enable) "Commands" and type (or c&p) these 3 commands (0, 1, 2):
    Code:
    bash ~/.scripts/ubuntu-snap left
    bash ~/.scripts/ubuntu-snap right
    bash ~/.scripts/ubuntu-snap top
    7.) (While still in "Commands" section) Click on the "Edge Bindings" tab.
    8.) Set the first 3 edge bindings (0, 1, 2) to "Left", "Right", and "Top"

    You should now have an Ubuntu "snap" feature.

    Note that I do this in courtesy of your CPUs, as all the scripts I've tested (and I looked at a few that appeared to) run up my CPU.

    Therefore, I've used a sleep statement to avoid this.

    Depending on your CPU (mine doesn't even quite "max out" with the "while(waiting) continue"), but it's also brand new, 3.5Ghz via OC, and hyper-threaded..

    With that said, you might want to set the delay higher (for better performance), or lower (for quicker snap). I chose 50ms because you won't even notice the difference from before.. unless your CPU was overloading, in which case it'll be much more responsive. If your computer is STILL using excess wanted CPU because of this script, you should try increasing the delay to a quarter second (.25 or 250ms). Adjust higher as needed, lower as wanted, 0 to defeat the purpose .

    As is, for me, the 50ms pause isn't noticeable for the snap duration or the CPU usage.



    If anyone wants to add the corner bindings, please continue the development


    Edit: Next, I want to add a shading/overlay on the desktop to signal where the window is going to snap & resize to, and temporarily hide the window. Like on Windows 7, it'll make the window invisible and show an outline of where the window is going to be when you release the mouse button.

    Also, I want to assemble all the parts of this tutorial to install via a single script. (It can be a .deb package, a tar.gz, or a shell script- something that's easy.. like a one-click install)

    Problem is, I don't know where/how to manipulate the window and desktop in such a way to hide the window and display a shaded box on the desktop.. And I don't know how to execute an "apt-get" in a bash script, or exactly the right way to dynamically add compiz commands & bindings.
    Last edited by s-p-n; March 27th, 2011 at 07:45 AM.

  8. #148
    Join Date
    Jun 2007
    Beans
    30
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Aero Snap function?

    Quote Originally Posted by s-p-n View Post
    Problem is, I don't know where/how to manipulate the window and desktop in such a way to hide the window and display a shaded box on the desktop.. And I don't know how to execute an "apt-get" in a bash script, or exactly the right way to dynamically add compiz commands & bindings.

    Check my previous post to see how to automate the compiz commands and bindings.

  9. #149
    Join Date
    Mar 2011
    Location
    Iowa, US
    Beans
    5
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Aero Snap function?

    s-p-n, your script is awesome. I was using a grid script before and it was pretty unreliable. Yours is fast, responsive, and the windows go back to their original size which is sweet.

    I've had just two problems with it.
    1. Your third compiz command (command 2) says top, when it should say maximize, or it won't work.
    2. The active window is snapped when my mouse goes to any of the edge-binding areas, even when I am not dragging the window there.

    Other than those things, I really like your script.

  10. #150
    Join Date
    Jul 2010
    Beans
    7

    Re: Aero Snap function?

    Quote Originally Posted by plafuro View Post
    Hi everyone!

    As the last script on this thread didn't quite cut it for me (working on several screens here), I made some additions to it (became kind of a monster )... Maybe other people find it useful.
    I've tried everything to get this to work with my dual-monitor setup, and I'm hitting dead ends. Perhaps I'm installing the scripts wrong?

    I pasted the code into a file named compizsnap.sh in ~/.scripts, set 'bash ~/.scripts/compizsnap.sh' without quotes as command 0 in ccsm, and set every edge binding for command 0. No change. I have firepaint installed and activated as well. Help me out!

    EDIT: I installed xdotool and now it's working I believe, but I can't get it to snap to only the right half of my right monitor, for example. It fills up the entire right screen, the entire left screen, or the bottom half of the screen across both monitors. I believe the problem is with "echo $DISPLAY | cut -f 2 -d '.'". Since I am using TwinView, this will return 0 no matter which monitor I run the command on. Any ideas?
    Last edited by JBauerIV; May 4th, 2011 at 08:50 PM. Reason: Partially fixed problem

Page 15 of 16 FirstFirst ... 513141516 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •