Last active
April 5, 2016 20:21
-
-
Save Jacob-Vlijm/fe215a9661d303ce63ac to your computer and use it in GitHub Desktop.
script, to run in the background, for Ubuntu 14.04 + Unity, to hide the Unity launcher only on specific viewports. Requires wmctrl to be installed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Copyright (C) 2014 Jacob Vlijm | |
This program is free software: you can redistribute it and/or modify it under | |
the terms of the GNU General Public License as published by the Free Software | |
Foundation, either version 3 of the License, or any later version. This | |
program is distributed in the hope that it will be useful, but WITHOUT ANY | |
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | |
A PARTICULAR PURPOSE. See the GNU General Public License for more details. You | |
should have received a copy of the GNU General Public License along with this | |
program. If not, see <http://www.gnu.org/licenses/>. | |
""" | |
import subprocess | |
import time | |
# set the hide-launcher values for your viewports; in rows/columns | |
# the example below is for 4 viewports, launcher visible only on viewport 1 | |
hide_launcher = (False, True, True, True) | |
# don't change anything below (or it must be the time.sleep(2) interval) | |
key = " org.compiz.unityshell:/"+\ | |
"org/compiz/profiles/unity/plugins/unityshell/ " | |
pr_get = "gsettings get "; pr_set = "gsettings set " | |
check = pr_get+key+"launcher-hide-mode" | |
hide = pr_set+key+"launcher-hide-mode 1" | |
show = pr_set+key+"launcher-hide-mode 0" | |
def get_value(command): | |
return subprocess.check_output( | |
["/bin/bash", "-c", command]).decode('utf-8').strip() | |
# get screen resolution | |
output = get_value("xrandr").split(); idf = output.index("current") | |
screen_res = (int(output[idf+1]), int(output[idf+3].replace(",", ""))) | |
while True: | |
# get total span size all viewports, position data | |
wsp_info = get_value("wmctrl -d").strip() | |
scr_data = [item.split("x") for item \ | |
in wsp_info.split(" ") if "x" in item][0] | |
# get current position (viewport coordinates) | |
VP = eval(wsp_info[wsp_info.find("VP: "):].split(" ")[1]) | |
# calculated viewports rows / columns | |
VP_hor = int(scr_data[0])/int(screen_res[0]) | |
VP_vert = int(scr_data[1])/int(screen_res[1]) | |
# calculated viewport positions | |
range_hor = [i*screen_res[0] \ | |
for i in range(int(VP_hor))] | |
range_vert = [i*screen_res[1] \ | |
for i in range(int(VP_vert))] | |
viewports = [(h, range_vert[i])\ | |
for i in range(len(range_vert)) for h in range_hor] | |
current_viewport = viewports.index(VP); a_hide = get_value(check) | |
if (hide_launcher[current_viewport], a_hide == "0") == (True, True): | |
subprocess.Popen(["/bin/bash", "-c", hide]) | |
elif (hide_launcher[current_viewport], a_hide == "0") == (False, False): | |
subprocess.Popen(["/bin/bash", "-c", show]) | |
else: | |
pass | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
explanation: http://askubuntu.com/a/529621/72216