Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 30

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

  1. #11
    Join Date
    Nov 2008
    Location
    Whakatane, NZ
    Beans
    634
    Distro
    Ubuntu

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

    Quote Originally Posted by EgoGratis View Post
    I have got PM from stinkeye mentioning Dash doesn't work well with the script and suggested solution. I could not reproduce the problem with Dash but i noticed similar behavior with Hud. Both stinkeye and i noticed some problems when login out and in the session again or in session other that Unity 3D so i added some fixes/features:

    1.) I moved all user setting to the top of the script.

    2.) I added session detection the script will only run in Unity 3D.

    3.) I added detection if the script is already running when login occurs. If it detects script that was left from login out of Unity 3D and login in again it closes it and starts new one. If it detects script that was left from login out of Unity 3D and login in other session than Unity 3D it closes the running script and it does not start another one.

    4.) I added both Hud and Dash exceptions so they won't interfere with the script anymore!

    Code:
    #!/bin/bash
    # Install wmctrl before using: sudo apt-get install wmctrl
    
    
    # Change settings
    DELAY="2" # Set delay
    
    SHOW_X="X" # Use wmctrl -lpG and find max X Y values when launcher is in never hide mode
    SHOW_Y="Y" 
    
    HIDE_X="X" # Use wmctrl -lpG and find max X Y values when launcher is in autohide mode
    HIDE_Y="Y"
    
    SCRIPT_PATH="/home/user_name/launcher.sh" # Change path
    
    
    # End of user settings
    ps -ef | grep "$SCRIPT_PATH" | grep -v "grep\|$$\|/bin/sh" | awk '!/awk/ {print $2}' | xargs -r kill
    
    if [ $DESKTOP_SESSION != ubuntu ]; then
    	exit 0
    fi
    
    while true; do
    sleep $DELAY
    
    SHOW_LAUNCHER=$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$SHOW_X $SHOW_Y") 
    HIDE_LAUNCHER=$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$HIDE_X $HIDE_Y") 
    
    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
    For the uninitiated, how does one actually apply this script? Do you just open terminal and cut and paste, or something else?

    Any help would be much appreciated.

    Cheers.
    Windows free since '09 - never looked back!

  2. #12
    Join Date
    Oct 2008
    Beans
    3,509

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

    Quote Originally Posted by Baldrick_NZ View Post
    For the uninitiated, how does one actually apply this script? Do you just open terminal and cut and paste, or something else?

    Any help would be much appreciated.

    Cheers.
    Firstly install wmctrl (Search in the software centre)
    and create a folder in your home directory called scripts.


    Put the launcher into never hide mode with this terminal command...
    Code:
    gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 0
    Then maximize firefox and get your maximized xy values by entering in the terminal...
    Code:
    wmctrl -lpG
    eg
    Code:
    glen@Oneiric:~$ wmctrl -lpG
    0x01600004  0 1935   0    0    1680 1050 Oneiric Desktop
    0x02400002  0 0      -1780 -1150 1680 1050     N/A DNDCollectionWindow
    0x02400003  0 0      0    24   50   1026     N/A launcher
    0x02400004  0 0      0    0    1680 24       N/A panel
    0x01000004  0 1921   1380 0    24   24   Oneiric compiz
    0x03a00002  0 0      65   440  410  610  Oneiric conkygmail
    0x03c00002 -1 0      489  39   602  302  Oneiric sbreeze
    0x03e00002  0 0      1108 38   564  412  Oneiric myconky
    0x04400002  0 0      1337 69   104  17   Oneiric Conky (Oneiric)
    0x0460001d  0 3060   50   24   1630 1026 Oneiric Ubuntu Forums - Reply to Topic - Opera
    0x02400012  0 0      -1730 -1126 1630 1026     N/A Dash
    0x04a00004  0 26518  2024 297  815  609  Oneiric launcher.sh (~/scripts) - gedit
    0x04c000d1  0 28327  50   24   1630 1026 Oneiric Ubuntu Start Page - Mozilla Firefox
    0x04e00006  0 28754  770  125  902  192  Oneiric glen@Oneiric: ~
    These are your x y values for a maximized window with the launcher showing.


    Now hide the launcher with...
    Code:
    gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 1
    Enter (Hint: pressing the up arrow when in the terminal will cycle through previous commands)
    Code:
    wmctrl -lpG
    and you will get your x y values when the launcher is hidden.
    eg
    Code:
    glen@Oneiric:~$ wmctrl -lpG
    0x01600004  0 1935   0    0    1680 1050 Oneiric Desktop
    0x02400002  0 0      -1780 -1150 1680 1050     N/A DNDCollectionWindow
    0x02400003  0 0      -150 -1126 50   1026     N/A launcher
    0x02400004  0 0      0    0    1680 24       N/A panel
    0x01000004  0 1921   1380 0    24   24   Oneiric compiz
    0x03a00002  0 0      65   440  410  610  Oneiric conkygmail
    0x03c00002 -1 0      489  39   602  302  Oneiric sbreeze
    0x03e00002  0 0      1108 38   564  412  Oneiric myconky
    0x04400002  0 0      1337 69   104  17   Oneiric Conky (Oneiric)
    0x0460001d  0 3060   0    24   1680 1026 Oneiric Ubuntu Forums - Reply to Topic - Opera
    0x02400012  0 0      -1730 -1126 1630 1026     N/A Dash
    0x04a00004  0 26518  2024 297  815  609  Oneiric launcher.sh (~/scripts) - gedit
    0x04c000d1  0 28327  0    24   1680 1026 Oneiric Ubuntu Start Page - Mozilla Firefox
    0x04e00006  0 28754  770  125  902  401  Oneiric glen@Oneiric: ~
    These are your x y values for a maximized window with the launcher hidden.

    Open gedit and copy and paste in the script.
    Edit the script to reflect your values.
    eg this is the section of the script I edited for my resolution and username.
    Code:
    # Change settings
    DELAY="2" # Set delay
    
    SHOW_X="1630" # Use wmctrl -lpG and find max X Y values when launcher is in never hide mode
    SHOW_Y="1026" 
    
    HIDE_X="1680" # Use wmctrl -lpG and find max X Y values when launcher is in autohide mode
    HIDE_Y="1026"
    
    SCRIPT_PATH="/home/glen/scripts/launcher.sh" # Change path
    Change to your user name and add the scripts foder, then save as
    launcher.sh in the scripts folder in your home directory.
    You can save anywhere,really, just make sure "SCRIPT_PATH=" points to where you saved it.

    Right click on the launcher.sh file
    Properties > permissions and mark execute.

    To test, left click on launcher.sh and choose "run in terminal".
    Unmaximize all windows and then maximize one.

    If it works and is what you want add it to start up applications
    by browsing to where you saved the script.
    Attached Images Attached Images
    Last edited by stinkeye; March 12th, 2012 at 04:21 AM.

  3. #13
    Join Date
    Nov 2008
    Location
    Whakatane, NZ
    Beans
    634
    Distro
    Ubuntu

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

    Thanks for that... Do I have to use firefox, or will chrome do instead? I don't have FF installed.

    Cheers.
    Windows free since '09 - never looked back!

  4. #14
    Join Date
    Oct 2008
    Beans
    3,509

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

    Quote Originally Posted by Baldrick_NZ View Post
    Thanks for that... Do I have to use firefox, or will chrome do instead? I don't have FF installed.

    Cheers.
    Any window will do.I just tried to use any easily identifiable one.

  5. #15
    Join Date
    Jun 2010
    Beans
    699

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

    I noticed how hard it is to set up the script and thought if i can do something about that!

    Code:
    #!/bin/bash
    # Install wmctrl before using: sudo apt-get install wmctrl
    
    # User settings
    sleep 8 # Time it takes before script starts with autodetection
    
    DELAY="2" # Set delay
    
    # End of user settings
    
    ps -ef | grep "$0" | grep -v "grep\|$$\|/bin/sh" | awk '!/awk/ {print $2}' | xargs -r kill
    
    if [ "$DESKTOP_SESSION" != "ubuntu" ]; then
        exit 0
    fi
    
    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}')"
    
    HIDE_Y="$(expr $MAX_H - 24)"
    
    SHOW_X="$(expr $MAX_W - $(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/icon_size") - 17)"
    SHOW_Y="$(expr $MAX_H - 24)"
    
    while true; do
    sleep $DELAY
    
    SHOW_LAUNCHER="$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$SHOW_X $SHOW_Y")" 
    HIDE_LAUNCHER="$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$MAX_W $HIDE_Y")"
    
    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
    Only two setting are left and the script should work on most of the computers. If script does not work then probably 2 things happened:

    1.) Scripts starts autodetection before session is loaded. Increase the sleep time.
    2.) Something changed in Unity or another theme is used with different dimensions. Use manual setup or change the script.

    Installation:
    -Create empty file and copy/paste the code into it. Save the file and make it executable.
    -Create entry in Startup Applications and in command filed point to the script as stinkeye suggested on the picture.

    Log out/ Log in and it should work. If Launcher size gets changed Log out/ Log in again and it should work again. I could probably make autodetection if launcher is changed in real-time but i think it's better if less operation gets executed in every interval!

  6. #16
    Join Date
    Nov 2008
    Location
    Whakatane, NZ
    Beans
    634
    Distro
    Ubuntu

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

    Quote Originally Posted by EgoGratis View Post
    I noticed how hard it is to set up the script and thought if i can do something about that!

    Code:
    #!/bin/bash
    # Install wmctrl before using: sudo apt-get install wmctrl
    
    # User settings
    sleep 8 # Time it takes before script starts with autodetection
    
    DELAY="2" # Set delay
    
    # End of user settings
    
    ps -ef | grep "$0" | grep -v "grep\|$$\|/bin/sh" | awk '!/awk/ {print $2}' | xargs -r kill
    
    if [ "$DESKTOP_SESSION" != "ubuntu" ]; then
        exit 0
    fi
    
    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}')"
    
    HIDE_Y="$(expr $MAX_H - 24)"
    
    SHOW_X="$(expr $MAX_W - $(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/icon_size") - 17)"
    SHOW_Y="$(expr $MAX_H - 24)"
    
    while true; do
    sleep $DELAY
    
    SHOW_LAUNCHER="$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$SHOW_X $SHOW_Y")" 
    HIDE_LAUNCHER="$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$MAX_W $HIDE_Y")"
    
    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
    Only two setting are left and the script should work on most of the computers. If script does not work then probably 2 things happened:

    1.) Scripts starts autodetection before session is loaded. Increase the sleep time.
    2.) Something changed in Unity or another theme is used with different dimensions. Use manual setup or change the script.

    Installation:
    -Create empty file and copy/paste the code into it. Save the file and make it executable.
    -Create entry in Startup Applications and in command filed point to the script as stinkeye suggested on the picture.

    Log out/ Log in and it should work. If Launcher size gets changed Log out/ Log in again and it should work again. I could probably make autodetection if launcher is changed in real-time but i think it's better if less operation gets executed in every interval!
    Worked for me, thanks guys!!

    EDIT: Well it almost worked. Worked fine when logging out/in, but on re-boot it holds the launcher at auto-hide. The script appears to override any changes you make to Ubuntu Tweak, so you can't change to never hide whilst this script is enabled. So close, but no cigar. Almost there...
    Last edited by Baldrick_NZ; March 13th, 2012 at 08:36 PM.
    Windows free since '09 - never looked back!

  7. #17
    Join Date
    Jun 2010
    Beans
    699

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

    Worked fine when logging out/in, but on re-boot it holds the launcher at auto-hide.
    There should not be any difference between log out/ log in and reboot. Try to increase sleep time from 8 to 16 maybe it tries to autodetect settings before session is loaded or if u have fast PC you have to wait few seconds after login for the script to start to work.

    The script appears to override any changes you make to Ubuntu Tweak, so you can't change to never hide whilst this script is enabled.
    True, when the script is running you only get one mode: hide launcher when at least one window is maximized. If u want any other mode you have to close the script first (System Monitor).
    Last edited by EgoGratis; March 13th, 2012 at 11:12 PM.

  8. #18
    Join Date
    Jun 2010
    Beans
    699

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

    Race condition is not something user should think about. This should be done automatically and i added detection when autoconfiguration should start. You will not have problems any more with reboots and you don't have to set sleep time based on how fast sessions loads and if sessions loads fast there is no waiting anymore for the script to start working. There is only one setting left now and it does not need to be changed for the script to work.

    Code:
    #!/bin/bash
    # Install wmctrl before using: sudo apt-get install wmctrl
    
    # User settings
    DELAY="2" # Set delay
    
    # End of user settings
    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 | awk '{print $4}' | grep -c "panel\|launcher\|DNDCollectionWindow")"
    
    while [ "$RACE" -lt "3" ]; do
        RACE="$(wmctrl -l | awk '{print $4}' | grep -c "panel\|launcher\|DNDCollectionWindow")"
        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}')"
    
    HIDE_Y="$(expr $MAX_H - 24)"
    
    SHOW_X="$(expr $MAX_W - $(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/icon_size") - 17)"
    SHOW_Y="$(expr $MAX_H - 24)"
    
    while true; do
    sleep $DELAY
    
    SHOW_LAUNCHER="$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$SHOW_X $SHOW_Y")" 
    HIDE_LAUNCHER="$(wmctrl -lpG | grep -v "Hud\|Dash" | grep -c "$MAX_W $HIDE_Y")"
    
    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

  9. #19
    Join Date
    Jun 2010
    Beans
    699

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

    -I removed all user specific settings because they are not needed and if set wrong can cause troubles.
    -I added Single Screen / Multi Workspaces support.

    Code:
    #!/bin/bash
    # Install wmctrl before using: 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 | awk '{print $4}' | grep -c "panel\|launcher\|DNDCollectionWindow")"
    
    while [ "$RACE" -lt "3" ]; do
        RACE="$(wmctrl -l | awk '{print $4}' | grep -c "panel\|launcher\|DNDCollectionWindow")"
        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}')"
    
    HIDE_Y="$(expr $MAX_H - 24)"
    
    SHOW_X="$(expr $MAX_W - $(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/icon_size") - 17)"
    SHOW_Y="$(expr $MAX_H - 24)"
    
    LAUNCHER="$(expr $(gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/icon_size") + 17)"
    
    while true; do
    sleep 2
    
    SHOW_LAUNCHER="$(wmctrl -lG | grep -v "Hud\|Dash" | awk -v LAUNCHER=$LAUNCHER '$3==LAUNCHER && $4==24' | grep -c "$SHOW_X $SHOW_Y")"
    HIDE_LAUNCHER="$(wmctrl -lG | grep -v "Hud\|Dash" | awk '$3==0 && $4==24' | grep -c "$MAX_W $HIDE_Y")"
    
    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

  10. #20
    Join Date
    Nov 2008
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

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

    For what I see, SHOW_Y and HIDE_Y are the same values (maybe one can be omitted). I also don't know if using "- 24", "- 17" and "+ 17" is the best way. What about these lines after MAX_W and MAX_H?

    LAUNCHER="$(wmctrl -lG | grep launcher | awk '{print $5}')"
    PANEL="$(wmctrl -lG | grep panel | awk '{print $6}')"

    SHOW_X="$(expr $MAX_W - $LAUNCHER)"
    SHOW_Y="$(expr $MAX_H - $PANEL)"
    HIDE_Y="$(expr $MAX_H - $PANEL)"

Page 2 of 3 FirstFirst 123 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
  •