Skip to content

Commit

Permalink
Dock position will now be respected
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Claude Jung committed Jan 30, 2023
1 parent cbf27ed commit 9cda3a6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 16 deletions.
Binary file modified Window Manager.alfredworkflow
Binary file not shown.
22 changes: 16 additions & 6 deletions src/WindowManager.py
Expand Up @@ -66,20 +66,30 @@ def delete_dimension(self, app_id: str) -> None:
jsn.pop(app_id, False)
self._save_json_file(jsn)

def _file_check(self, file: str) -> str:
if not os.path.exists(file):
with open(file, "w") as f:
pass
return file

def _read_json_file(self) -> dict:
"""
Read json file
Returns:
dict: json of the file
"""
jsn = dict()
if os.path.exists(self.file):
with open(self.file, "r") as f:
jsn: dict = json.load(f)
return jsn

def _save_json_file(self, jsn: dict) -> None:
"""
Save the json to a file
Args:
jsn (dict): json with dimensions
"""
with open(self.file, "w") as f:
f.seek(0)
json.dump(jsn, f)
Expand Down
42 changes: 40 additions & 2 deletions src/info.plist
Expand Up @@ -257,6 +257,16 @@
</array>
<key>C57CE0D7-D6BB-49AC-83C0-7B26EF57644A</key>
<array>
<dict>
<key>destinationuid</key>
<string>CED69719-04CB-480C-9DEC-CD201ADCA5C8</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>D9985E7C-DCF8-4D3B-8FBC-0F7B70D3F973</string>
Expand Down Expand Up @@ -504,6 +514,23 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argument</key>
<string>'{query}', {variables}</string>
<key>cleardebuggertext</key>
<false/>
<key>processoutputs</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.utility.debug</string>
<key>uid</key>
<string>CED69719-04CB-480C-9DEC-CD201ADCA5C8</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -1335,12 +1362,16 @@
<key>readme</key>
<string># Window Manager
Alfred Workflow to move/resize/position windows
## Requirements
* [Automation Tasks](https://www.alfredapp.com/help/workflows/automations/automation-task/)
## Usage
Keyboard shortcuts below are suggestions:
* ⇧↓ : Move to next screen
* ⇧↑ : Move to previous screen
* ^⌥M : Maximize
Expand Down Expand Up @@ -1574,6 +1605,13 @@
<key>ypos</key>
<real>1370</real>
</dict>
<key>CED69719-04CB-480C-9DEC-CD201ADCA5C8</key>
<dict>
<key>xpos</key>
<real>615</real>
<key>ypos</key>
<real>305</real>
</dict>
<key>CFAD3BF2-AB4B-4DA4-ADD9-3C68698ABA6E</key>
<dict>
<key>xpos</key>
Expand Down Expand Up @@ -1602,7 +1640,7 @@
<key>D5D03267-BC05-4901-A995-FF97DC4788D2</key>
<dict>
<key>xpos</key>
<real>395</real>
<real>390</real>
<key>ypos</key>
<real>405</real>
</dict>
Expand Down Expand Up @@ -1708,7 +1746,7 @@
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.0.0</string>
<string>1.1.0</string>
<key>webaddress</key>
<string>https://github.com/Acidham/alfred-window-manager</string>
</dict>
Expand Down
36 changes: 28 additions & 8 deletions src/window_pos.py
@@ -1,12 +1,21 @@
#!/usr/bin/python3

import json
import os
import sys

from Alfred3 import AlfJson, Tools
from WindowManager import Dimensions, Screen, Window


def get_dock_position() -> str:
return os.popen('defaults read com.apple.dock orientation').read().strip()


def get_dock_size() -> int:
ts = int(os.popen('defaults read com.apple.dock tilesize').read().strip())
autohide = int(os.popen('defaults read com.apple.dock autohide').read().strip())
return int((ts+20)/2) if autohide == 0 else 0


cache_dir = Tools.getCacheDir()
cache_file = os.path.join(cache_dir, "dimensions.json")
Tools.log(f"Cache File: {cache_file}")
Expand All @@ -15,6 +24,7 @@


window_postion = Tools.getArgv(1)
# window_postion = '{"x":521,"y":404,"width":1073,"height":565}' # uncomment for testing
direction = Tools.getEnv("direction")

# Get Window positions of Frontmost app
Expand All @@ -34,16 +44,26 @@
screen_width = Scr.screen_width()
screen_height = Scr.screen_height()

if direction == "left": # calculate dimensions for moving right side of the screen
window_x_new = 10
window_y_new = 10
window_width_new = int(screen_width/2) - 60
window_height_new = int(screen_height)
dock_position = get_dock_position()
dock_size = get_dock_size()

# Calculate new Window dimensions based on window move direction and Dock position
window_x_new = 0
window_y_new = 0
if direction == "left": # calculate dimensions for moving right side of the screen
window_width_new = int(screen_width/2)
window_height_new = screen_height
if dock_position == "left":
window_x_new = dock_size
window_width_new -= 2 * dock_size

if direction == "right": # calculate dimensions for moving right side of the screen
window_x_new = int(screen_width/2)
window_y_new = 10
window_width_new = int(screen_width/2)
window_height_new = int(screen_height)
if dock_position == "right":
window_x_new = screen_width - dock_size
window_width_new -= - 2 * dock_size

vars = {"x": window_x_new,
"y": window_y_new,
Expand Down

0 comments on commit 9cda3a6

Please sign in to comment.