Skip to content

Commit

Permalink
Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
lioaslan committed Apr 6, 2022
1 parent 36bc1a5 commit 9541555
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ dmypy.json

# Pyre type checker
.pyre/
nohup.out
44 changes: 44 additions & 0 deletions monitors-chosen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import subprocess
import os

HOME = os.environ["HOME"]
PLANK_CONFIG_PATH = f'{HOME}/.config/dconf/user.conf'

def main():
monitors = subprocess.run(
'xrandr | grep " connected "', shell=True, stdout=subprocess.PIPE
).stdout.decode("utf-8")
number_monitors = len(monitors.split("\n")) - 1

subprocess.run(f"dconf dump / >{PLANK_CONFIG_PATH}", shell=True)

plank_config = ""
with open(f"{PLANK_CONFIG_PATH}") as fin:
for line in fin.readlines():
if line.__contains__("enabled-docks="):
dock_arr = ["dock".__add__(str(x + 1)) for x in range(number_monitors)]
dock_arr = '"{0}"'.format('","'.join(dock_arr))
line = f"enabled-docks=[{dock_arr}]"
plank_config += line
print(plank_config)

fout = open(f'{PLANK_CONFIG_PATH}', 'w')
fout.write(plank_config)

subprocess.run(f'dconf load / <{PLANK_CONFIG_PATH}', shell=True)
subprocess.run('sudo killall plank', shell=True)
subprocess.run('nohup plank &', shell=True)

if number_monitors == 2:
subprocess.run(
"xrandr --output eDP-1 --mode 1920x1080 --pos 0x0 --output DP-3 --mode 1920x1080 --pos 1920x0",
shell=True,
)
if number_monitors == 3:
subprocess.run(
"xrandr --output DP-1 --mode 1920x1080 --pos 0x0 --output DP-3 --mode 1920x1080 --pos 1920x0 --output eDP-1 --mode 1920x1080 --pos 3840x0",
shell=True,
)

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyinstaller==4.10
9 changes: 9 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

PWD=$(pwd)
INSTALL_DIR='/usr/local/monitors-chosen'
pyinstaller --onedir --noconfirm $PWD/monitors-chosen.py
sudo rm -rf $INSTALL_DIR
sudo mkdir -p $INSTALL_DIR
sudo cp -r $PWD/dist $INSTALL_DIR
sudo ln -sf $INSTALL_DIR/dist/monitors-chosen/monitors-chosen /usr/local/bin/monitors-chosen

0 comments on commit 9541555

Please sign in to comment.