Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 1579  / 3 Years ago, sun, june 13, 2021, 8:17:17

I was trying to control Ubuntu 14.4.1 Launcher's behavior. I want it to auto-hide every time I have browser window like firefox maxmaized. I found this solution:



#!/bin/bash

## Change value of "hide" to the command which worked for you to hide the panel
hide='gsettings set com.canonical.Unity2d.Launcher hide-mode 1;'

## Change value of "show" to the command which worked for you to show the panel when it was hidden
show='gsettings set com.canonical.Unity2d.Launcher hide-mode 0;'

## Look for the grep value, add a new browser or application name followed by "|" eg: 'firefox|google|chromium'
while [ 1 ]
do z=$(wmctrl -l -p | grep -i 'firefox|google');
if [ -n "$z" ]; then
eval $hide
else
eval $show
fi;
sleep 2;
done;


but is seems too old to work then I found this



I tried to combine the two scripts together so here is what I did:



#!/bin/bash

AUTOHIDE=$(dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode)
if [[ $AUTOHIDE -eq 1 ]]
then
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0
else
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
fi

## Look for the grep value, add a new browser or application name followed by "|" eg: 'firefox|google|chromium'
while [ 1 ]
do z=$(wmctrl -l -p | grep -i 'firefox|google');
if [ -n "$z" ]; then
eval $hide
else
eval $show
fi;
sleep 2;
done;


But script doesn't work. can anybody refine this script to me and get it to work?


More From » unity

 Answers
2

Below two versions of a script to autohide the launcher when an application's window is maximized. The scripts are tested on 14.04 / 14.10 /16.04



The differences




  • The first version is a "general" version, it makes the launcher autohide whenever a window of any application is maximized.

  • The second one makes the launcher autohide, but only on applications that you specifically define in the headsection of the script.



Both scripts recognize windows to be iconized, then there is no reason to autohide, and both scripts work workspace- specific; the launcher only switches to autohide on workspaces where actually one or more windows are maximized.



Installing wmctrl



The scripts use wmctrl to map the currently opened windows. You might have to install it:



sudo apt-get install wmctrl


The scripts






Both scripts below were updated/rewritten March 2017.






1. The "basic" version, acts on maximized windows of all applications



#!/usr/bin/env python3
import subprocess
import time

mx = "_NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ"
key = ["org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/",
"launcher-hide-mode"]

def get(cmd):
try:
return subprocess.check_output(cmd).decode("utf-8").strip()
except subprocess.CalledProcessError:
pass

def force_get(cmd):
# both xprop and wmctrl break once and a while, this is to retry if so
val = None
while not val:
val = get(cmd)
return val

def get_res():
# look up screen resolution
scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2
return [int(n) for n in scrdata[resindex].split("+")[0].split("x")]

res = get_res()
hide1 = False

while True:
time.sleep(2)
hide = False
wlist = [l.split() for l in force_get(["wmctrl", "-lpG"]).splitlines()]
# only check windows if any of the apps is running
for w in wlist:
xpr = force_get(["xprop", "-id", w[0]])
if all([
mx in xpr, not "Iconic" in xpr,
0 <= int(w[3]) < res[0], 0 <= int(w[4]) < res[1],
]):
hide = True
break
if hide != hide1:
nexts = "0" if hide == False else "1"
currset = get(["gsettings", "get", key[0], key[1]])
if nexts != currset:
subprocess.Popen([
"gsettings", "set", key[0], key[1], nexts
])
hide1 = hide


2. The application- specific version:



#!/usr/bin/env python3
import subprocess
import time

apps = ["gnome-terminal", "firefox"]
mx = "_NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ"
key = ["org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/",
"launcher-hide-mode"]

def get(cmd):
try:
return subprocess.check_output(cmd).decode("utf-8").strip()
except subprocess.CalledProcessError:
pass

def force_get(cmd):
# both xprop and wmctrl break once and a while, this is to retry if so
val = None
while not val:
val = get(cmd)
return val

def get_res():
# look up screen resolution
scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2
return [int(n) for n in scrdata[resindex].split("+")[0].split("x")]

res = get_res()
hide1 = False

while True:
time.sleep(2)
hide = False
wlist = [l.split() for l in force_get(["wmctrl", "-lpG"]).splitlines()]
pids = [get(["pgrep", app]) for app in apps]
# only check windows if any of the apps is running
if any(pids):
for w in wlist:
xpr = force_get(["xprop", "-id", w[0]])
if all([
mx in xpr, not "Iconic" in xpr,
0 <= int(w[3]) < res[0], 0 <= int(w[4]) < res[1],
any([w[2] == pid for pid in pids]),
]):
hide = True
break
if hide != hide1:
nexts = "0" if hide == False else "1"
currset = get(["gsettings", "get", key[0], key[1]])
if nexts != currset:
subprocess.Popen([
"gsettings", "set", key[0], key[1], nexts
])
hide1 = hide


How to use:



Copy either one of the scripts into an empty file,

[set, if you chose the second one, your applications to hide]

and save it as autohide.py.



Run it by the command:



python3 /path/to/autohide.py


If it acts like you want it to, add it to your startup applications.

N.B. If you use it as a startup application, you should uncomment the line:



time.sleep(10)


In the head section of the script. The script might crash if it is called before the desktop is fully loaded. Change the value (10), depending on your system.



Explanation



In a loop the script:




  • [checks the possible pids of the set applications]

  • checks the screen's resolution, to see where the windows are positiond (relative to the current workspace)

  • creates a list of current windows, their state

  • checks the current hide-mode (either 0 for not- autohide or 1 for autohide)



(only) if a change in the hide-mode needs to be made, the script changes the setting.


[#22279] Sunday, June 13, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
whipstder

Total Points: 189
Total Questions: 110
Total Answers: 99

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
;