Page 1 of 3 123 LastLast
Results 1 to 10 of 30

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

  1. #1
    Join Date
    Jun 2010
    Beans
    699

    Detecting maximized window(s) is this possible?

    Is there a way i could detect maximized window(s) in Ubuntu (Gnome 3) and do that reliable? And if it is is there a way i could run a script that would do one thing when it would detect maximized window(s) and another when there would be no maximized window(s)?

    Thanks!

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

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

    Have a look at wmctrl.
    eg on my res of 1680x1050 in unity, maximized windows show "1630 x 1026" dimension.
    Code:
    glen@Oneiric:~$ wmctrl -lpG
    0x01600004  0 30241  0    0    1680 1050 Oneiric Desktop
    0x02c00002  0 0      -1780 -1150 1680 1050     N/A DNDCollectionWindow
    0x02c00003  0 0      0    24   50   1026     N/A launcher
    0x02c00004  0 0      0    0    1680 24       N/A panel
    0x01000004  0 30227  1362 0    48   24   Oneiric compiz
    0x03c00002  0 0      65   440  410  610  Oneiric conkygmail
    0x03e00002  0 0      489  39   602  302  Oneiric sbreeze
    0x04000002  0 0      1108 38   564  429  Oneiric myconky
    0x04600002  0 0      1337 69   104  17   Oneiric Conky (Oneiric)
    0x0480000d  0 31079  1200 598  300  300  Oneiric MacSlow's Cairo-Clock
    0x0440001d  0 31338  50   24   1630 1026 Oneiric Ubuntu Forums - Reply to Topic - Opera
    0x04e00006  0 17273  112  302  1212 686  Oneiric glen@Oneiric: ~
    0x0160037a  0 30241  50   24   1630 1026 Oneiric Home
    
    glen@Oneiric:~$ wmctrl -lpG | grep "1630 1026"
    0x0440001d  0 31338  50   24   1630 1026 Oneiric Ubuntu Forums - Reply to Topic - Opera
    0x0160037a  0 30241  50   24   1630 1026 Oneiric Home
    Grep can be used with a count option
    eg
    Code:
    glen@Oneiric:~$ wmctrl -lpG | grep -c "1630 1026"
    2

    Code:
    #!/bin/bash
    
    MAXIMIZED=$(wmctrl -lpG | grep -c "1630 1026")
    
    if [ "$MAXIMIZED" == "0" ]; then
    	notify-send "None Maximized"
    else
    	notify-send "$MAXIMIZED Maximized"
    
    fi
    Only seems to work when run in terminal though???
    Last edited by stinkeye; March 5th, 2012 at 06:39 PM.

  3. #3
    Join Date
    Jun 2010
    Beans
    699

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

    I tried it and it works. Fantastic! Now could this be done.

    If output of command:

    Code:
    wmctrl -lpG | grep -c "x y"
    Returns 0 it reads:

    Code:
    gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode"
    If output is not 0 then:

    Code:
    gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 0
    If output of command:

    Code:
    wmctrl -lpG | grep -c "x y"
    Is not 0 then it reads:

    Code:
    gconftool-2 --get "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode"
    If output is not 1 then:

    Code:
    gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 1
    I found it here:

    http://askubuntu.com/questions/41241...r-hide-setting

    And last but not least this should always run in the background and monitor behavior automatically and act accordingly. What would be the best way to do this? It's complex i know but i hope somebody knows the answer and solution and i hope it can be done and that it will work well too! Any suggestion?
    Last edited by EgoGratis; March 5th, 2012 at 06:39 PM.

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

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

    I'm just an amateur "learn by mistakes" scripter so I'll leave it up to someone who will do it properly.
    Probably just need a while true; do loop to run in background.

  5. #5
    Join Date
    Jun 2010
    Beans
    699

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

    I'm just an amateur "learn by mistakes" scripter
    That solved important piece of the puzzle! Thanks!

  6. #6
    Join Date
    Jun 2010
    Beans
    699

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

    Based on your valuable input i managed to do this:

    Code:
    #!/bin/bash
    # Install wmctrl before using: sudo apt-get install wmctrl
    
    while true; do
    sleep 2 # Set delay
    
    SHOW_LAUNCHER=$(wmctrl -lpG | grep -c "x y") # Use wmctrl -lpG and find max value when Launcher is in neverhide mode
    HIDE_LAUNCHER=$(wmctrl -lpG | grep -c "x y") # Use wmctrl -lpG and find max value when Launcher is in autohide mode
    
    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
    It works in Unity 3D on single screen/workspace and yes it "imitates" Dodge Windows in Ubuntu 12.04. For more advanced functionality more skillful programmer should probably use window manager to detect maximized widows (_NET_WM_STATE, ATOM[])

    http://standards.freedesktop.org/wm-...-spec-1.3.html

    And then show/hide launcher. And Launcher should be shown on screens/workspaces that have no maximized window(s)... But that is beyond the scope of this topic.

    Thanks!

  7. #7
    Join Date
    Oct 2008
    Beans
    3,509

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

    Well done.
    I put in my x y values and it worked.
    Maximized windows being a different size when the launcher is hidden
    makes it a bit harder.
    Last edited by stinkeye; March 6th, 2012 at 05:29 PM.

  8. #8
    Join Date
    Jun 2010
    Beans
    699

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

    Maximized windows being a different size when the launcher is hidden makes it a bit harder.
    If you don't want to use GUI editor to set the launcher in autohide then:


    Code:
    gconftool-2 --type int --set "/apps/compiz-1/plugins/unityshell/screen0/options/launcher_hide_mode" 1
    wmctrl -lpG
    This should be easy!

    P.S. I think i misunderstood.

    You probably thought bash script is a bit harder to make!
    Last edited by EgoGratis; March 6th, 2012 at 05:45 PM.

  9. #9
    Join Date
    Jun 2011
    Beans
    60
    Distro
    Ubuntu

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

    I want to say thanks to EgoGratis for this initiative.

    To everyone: please subscribe to this bug if you don't agree with the decision to remove the dodge feature (instead of making it non-default) and not even replace it with a simple intellihide.

  10. #10
    Join Date
    Jun 2010
    Beans
    699

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

    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

Page 1 of 3 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
  •