Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: Detecting maximized window(s) is this possible?

  1. #21
    Join Date
    Nov 2008
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Detecting maximized window(s) is this possible?

    I tried to simplify some things, let me know what you think:

    Code:
    #!/bin/bash
    # sudo apt-get install wmctrl
    
    ps -ef | grep "$0" | grep -v "grep\|$$\|/bin/sh" | awk '!/awk/ {print $2}' | xargs -r kill
    
    if [ "$DESKTOP_SESSION" != "ubuntu" ]; then exit 0; fi
    
    RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel")
    
    while [ "$RACE" -lt "3" ]; do RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel"); sleep 1; done
    
    MAX_W=$(wmctrl -lG | awk '{if ($5 > max) { max = $5;}} END {print max}')
    MAX_H=$(wmctrl -lG | awk '{if ($6 > max) { max = $6;}} END {print max}')
    LAUNCHER=$(wmctrl -lG | grep launcher | awk '{print $5}')
    PANEL=$(wmctrl -lG | grep panel | awk '{print $6}')
    WIDTH=$(expr $MAX_W - $LAUNCHER)
    HEIGHT=$(expr $MAX_H - $PANEL)
    
    while true; do sleep 1
    
    SHOW_LAUNCHER=$(wmctrl -lG | grep -v "Hud\|Dash" | awk -v LAUNCHER=$LAUNCHER -v PANEL=$PANEL '$3==LAUNCHER && $4==PANEL' | grep -c "$WIDTH $HEIGHT")
    HIDE_LAUNCHER=$(wmctrl -lG | grep -v "Hud\|Dash" | awk -v PANEL=$PANEL '$3==0 && $4==PANEL' | grep -c "$MAX_W $HEIGHT")
    
    if [ "$SHOW_LAUNCHER" -eq "0" -a "$HIDE_LAUNCHER" -eq "0" ]; then
    	CURRENT=$(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode")
    	if [ "$CURRENT" -ne "0" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 0; fi
    else
    	CURRENT=$(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode")
    	if [ "$CURRENT" -ne "1" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 1; fi
    fi
    done
    Last edited by jsevi83; March 28th, 2012 at 04:58 PM.

  2. #22
    Join Date
    Jun 2010
    Beans
    699

    Re: Detecting maximized window(s) is this possible?

    I added logic for majority of things i thought could cause problems for users and in the end nothing has to be setup manually by the user and it works because of that i didn't put much thought into it anymore but sure it can be optimized if anybody wants to.

    I thought i could put more autodetection in "while loop" too and user could change settings in real time but i like less operations executed in each interval and i didn't change this. Log out / log in is still required after changes are made because of that.

    If i understand correctly and i didn't test much and i assume it works fine:

    -Dimension autodetection was added and if this changes in the future Unity the script would still work.
    -Some cleanups/optimization that remove unnecessary operations was made.

    Great work!

    Maybe a note on delay. Changing delay below 2 in my tests didn't make any real difference but setting value too low could create unnecessary problems for users on some hardware.

    The "real goal" of this script was to demonstrate to Unity developers why this should be implemented in Unity by default and i hope this will be the final outcome!

  3. #23
    Join Date
    Jul 2010
    Beans
    25

    Re: Detecting maximized window(s) is this possible?

    Am I right in thinking that the reason for this script is to allow us to have dodge windows behaviour of the launcher? If so then why are you hiding the launcher for maximised windows?
    wmctrl -lpG gives not only the size of the windows but the location too. The 4th and 5th columns are the x and y position of the top left corner of the window so would it not just be possible to put an 'if' command in the script and say 'if x position (=<) width of launcher then autohide mode'?

    Im not a scripter or coder so I may be wrong but if it was possible that would give you dodge behaviour back.

  4. #24
    Join Date
    Jun 2010
    Beans
    699

    Re: Detecting maximized window(s) is this possible?

    Am I right in thinking that the reason for this script is to allow us to have dodge windows behaviour of the launcher?
    No, this script is just "proof of concept" how hide launcher when at least one window is maximized could work. I use it because i want to use the whole screen when i have application maximized and dodge windows was removed and i shared it if anybody else wants to use it too.

    wmctrl -lpG gives not only the size of the windows but the location too. The 4th and 5th columns are the x and y position of the top left corner of the window so would it not just be possible to put an 'if' command in the script and say 'if x position (=<) width of launcher then autohide mode'?
    Probably it could be possible yes BUT with bash script there is very little control on how launcher should behave. You probably notice that icon on desktop change position on launcher hide/show and if "dodge windows" would be implementer in this bash script this could not be done smooth.

    Im not a scripter or coder so I may be wrong but if it was possible that would give you dodge behaviour back.
    Technical it would probably be possible but it would not work smooth. It has to be "built in" Unity to work smooth.

    Short answer: this script is not "dodge windows" replacement it's "prof of concept" how hide launcher when at least one windows is maximized could work. But if this behavior would be implemented in Unity then it would work smoother than with current script. Script simply put can't control anything beyond simple switching between "always and never hide" mode!

  5. #25
    Join Date
    Nov 2008
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Detecting maximized window(s) is this possible?

    I changed the script a little so the launcher also hides when a window is covering it (and not only when there are maximized windows). It will also work properly if the user changes the size of the dash.


    Code:
    #!/bin/bash
    
    ps -ef | grep "$0" | grep -v "grep\|$$\|/bin/sh" | awk '!/awk/ {print $2}' | xargs -r kill
    
    if [ "$DESKTOP_SESSION" != "ubuntu" ]; then exit 0; fi
    
    RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel"); while [ "$RACE" -lt "3" ]; do RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel"); sleep 1; done
    
    MAX_W=$(wmctrl -lG | awk '{if ($5 > max) { max = $5;}} END {print max}')
    MAX_H=$(wmctrl -lG | awk '{if ($6 > max) { max = $6;}} END {print max}')
    PANEL=$(wmctrl -lG | grep panel | awk '{print $6}')
    HEIGHT=$(expr $MAX_H - $PANEL)
    
    while true; do sleep 1
    
    LAUNCHER=$(wmctrl -lG | grep launcher | awk '{print $5}')
    WIDTH=$(expr $MAX_W - $LAUNCHER)
    
    COVERED=$(wmctrl -lG | grep -v "N/A\|$MAX_H" | awk '{print $3}' | awk -v LAUNCHER=$LAUNCHER '{if($1<LAUNCHER)print $1}' | wc -l)
    MAXIMIZED=$(wmctrl -lG | awk -v LAUNCHER=$LAUNCHER -v PANEL=$PANEL '$3==LAUNCHER && $4==PANEL' | grep -c "$WIDTH $HEIGHT")
    CURRENT=$(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode")
    
    if [ "$COVERED" -eq "0" -a "$MAXIMIZED" -eq "0" ]; then
    	if [ "$CURRENT" -ne "0" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 0; fi
    else
    	if [ "$CURRENT" -ne "1" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 1; fi
    fi
    done

  6. #26
    Join Date
    Apr 2009
    Beans
    862

    Re: Detecting maximized window(s) is this possible?

    I'm slightly confused here. I have been a bit busy lately so out of the loop.
    So there seems to be 2 scripts now.

    The one by EgoGratis is still just hiding on maximized windows and the one modified by jsevi83 is now almost like the full dodge behaviour right?

    I just need to know because although you are both doing great work, I don't want full-on dodge myself, just dodge for maximized windows.

  7. #27
    Join Date
    Jun 2010
    Beans
    699

    Re: Detecting maximized window(s) is this possible?

    It will also work properly if the user changes the size of the dash.
    Launcher and not Dash? Yes this is one possibility but i prefer less operation executed in each interval but users have both options now and can decide for themselves.

    The one by EgoGratis is still just hiding on maximized windows and the one modified by jsevi83 is now almost like the full dodge behaviour right?
    Yes, this is true. My last script only does hide when at least one windows is maximized for Single Screen / Multi workspaces and when changing for example louncher size log out / log in is required. I preferred it like this with bash script approach.

    Script from @jsevi83 tries to imitate old Dodge Windows behavior and he puts "real time" auto detection inside the loop and when changing for example launcher size log out / log in is not required.

    So basically my script: Does auto detection on log in once and only hides launcher when at least one windows is maximized.

    @jsevi83 script: tries to auto detect some changes in every interval and tries to be more like old Dodge Windows behavior.

  8. #28
    Join Date
    Nov 2008
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Detecting maximized window(s) is this possible?

    Here are both scripts, very similar to each other. The only difference is that the first script has the value MAXIMIZED2 and the second script has the value COVERED.


    - HIDE THE LAUNCHER WITH MAXIMIZED WINDOWS:
    Code:
    #!/bin/bash
    
    ps -ef | grep "$0" | grep -v "grep\|$$\|/bin/sh" | awk '!/awk/ {print $2}' | xargs -r kill
    
    if [ "$DESKTOP_SESSION" != "ubuntu" ]; then exit 0; fi
    
    RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel"); while [ "$RACE" -lt "3" ]; do RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel"); sleep 1; done
    
    MAX_W=$(wmctrl -lG | awk '{if ($5 > max) { max = $5;}} END {print max}')
    MAX_H=$(wmctrl -lG | awk '{if ($6 > max) { max = $6;}} END {print max}')
    LAUNCHER=$(wmctrl -lG | grep launcher | awk '{print $5}')
    PANEL=$(wmctrl -lG | grep panel | awk '{print $6}')
    WIDTH=$(expr $MAX_W - $LAUNCHER)
    HEIGHT=$(expr $MAX_H - $PANEL)
    
    while true; do sleep 1
    
    CURRENT=$(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode")
    MAXIMIZED=$(wmctrl -lG | awk -v LAUNCHER=$LAUNCHER -v PANEL=$PANEL '$3==LAUNCHER && $4==PANEL' | grep -c "$WIDTH $HEIGHT")
    MAXIMIZED2=$(wmctrl -lG | grep -v "N/A" | awk -v PANEL=$PANEL '$3==0 && $4==PANEL' | grep -c "$MAX_W $HEIGHT")
    
    if [ "$MAXIMIZED" -eq "0" -a "$MAXIMIZED2" -eq "0" ]; then
    	if [ "$CURRENT" -ne "0" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 0; fi
    else
    	if [ "$CURRENT" -ne "1" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 1; fi
    fi
    done


    - OLD DODGE WINDOWS BEHAVIOUR:
    Code:
    #!/bin/bash
    
    ps -ef | grep "$0" | grep -v "grep\|$$\|/bin/sh" | awk '!/awk/ {print $2}' | xargs -r kill
    
    if [ "$DESKTOP_SESSION" != "ubuntu" ]; then exit 0; fi
    
    RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel"); while [ "$RACE" -lt "3" ]; do RACE=$(wmctrl -l | grep -c "DNDCollectionWindow\|launcher\|panel"); sleep 1; done
    
    MAX_W=$(wmctrl -lG | awk '{if ($5 > max) { max = $5;}} END {print max}')
    MAX_H=$(wmctrl -lG | awk '{if ($6 > max) { max = $6;}} END {print max}')
    LAUNCHER=$(wmctrl -lG | grep launcher | awk '{print $5}')
    PANEL=$(wmctrl -lG | grep panel | awk '{print $6}')
    WIDTH=$(expr $MAX_W - $LAUNCHER)
    HEIGHT=$(expr $MAX_H - $PANEL)
    
    while true; do sleep 1
    
    CURRENT=$(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode")
    MAXIMIZED=$(wmctrl -lG | awk -v LAUNCHER=$LAUNCHER -v PANEL=$PANEL '$3==LAUNCHER && $4==PANEL' | grep -c "$WIDTH $HEIGHT")
    COVERED=$(wmctrl -lG | grep -v "N/A\|$MAX_H" | awk -v LAUNCHER=$LAUNCHER '{if($3<LAUNCHER)print $0}' | wc -l)
    
    if [ "$MAXIMIZED" -eq "0" -a "$COVERED" -eq "0" ]; then
    	if [ "$CURRENT" -ne "0" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 0; fi
    else
    	if [ "$CURRENT" -ne "1" ]; then gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 1; fi
    fi
    done
    Last edited by jsevi83; March 31st, 2012 at 06:27 PM.

  9. #29
    Join Date
    Apr 2009
    Beans
    1

    Exclamation Re: Detecting maximized window(s) is this possible?

    Hi,

    the script didn't work at all - but I figured out why and how to fix it.

    In case someone else is experiencing similar problems:

    The line
    Code:
    MAXIMIZED=$(wmctrl -lG | awk -v LAUNCHER=$LAUNCHER -v PANEL=$PANEL '$3==LAUNCHER && $4==PANEL' | grep -c "$WIDTH $HEIGHT")
    expects there to be ONE space between the width and height values returned by wmctrl. This is not the case on my (fresh) Ubuntu 12.04 Beta 2 setup with the newest wmctrl installed.
    In fact the number of spaces varies to align the numbers.

    Following replacement for above line fixes the problem using regex:
    Code:
    MAXIMIZED=$(wmctrl -lG | awk -v LAUNCHER=$LAUNCHER -v PANEL=$PANEL '$3==LAUNCHER && $4==PANEL' | grep -c "$WIDTH[ ]\{1,\}$HEIGHT")


    Moritz

    PS anyway thanks a million for the script!

  10. #30
    Join Date
    Jun 2010
    Beans
    699

    Re: Detecting maximized window(s) is this possible?

    Nice. If more users will experience this problem i can make it default and investigate a bit but for now i will leave it as it is.

Page 3 of 3 FirstFirst 123

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
  •