Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bshoshany committed Apr 12, 2021
0 parents commit 0c29102
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.vscode
/Demo.mp4
Binary file added Demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Barak Shoshany

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# UltraDocker

This is a simple AutoHotkey script for easy docking of windows, aimed primarily at ultrawide monitors, with aspect ratio 21:9 or higher. To use it, install [AutoHotkey](https://www.autohotkey.com/) on your Windows system and run the file `UltraDocker.ahk`.

By default, the script is triggered using the mouse 4 button, available in most gaming mice. If you do not have a mouse with 4 or more buttons, simply replace `XButton1` in the first line of the script with another key from [the list of available AutoHotkey keys](https://www.autohotkey.com/docs/KeyList.htm). For example, to use the Pause/Break button, which is a good choice since it is almost never used for any other purpose, replace `XButton1` with `Pause` in the first line.

When the trigger button or key is pressed, the currently active window will be docked based on the current location of the mouse:

* If the mouse is in the **left or right third** of the screen, the window will be docked to the left or right respectively, at **50%** of the total width of the screen. This allows docking one window to the left and one to the right, so they can be used in parallel.
* If the mouse is in the **middle third** of the screen, the window will be centered at **60%** of the total width of the screen. This allows having only one window open on the screen, in a convenient location, but without maximizing the window, which often makes it too wide; for example, when using a web browser or a text editor, it is very inconvenient to have the text extend all the way across the screen.
* If the window is maximized, it will be un-maximized first.

![UltraDocker Demo](Demo.gif)

Please note that the script will only be able to dock administrative applications (e.g. Registry Editor) if you run the script itself as administrator. Simply right-click on the script and choose "Run as administrator" from the menu.

To run the script automatically on startup, either create a shortcut to it in `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup` or create a task for it in the Task Scheduler. The latter option is preferred, as it allows you to run the script as administrator on startup without the hassle of the User Account Control (UAC) prompt.

## Version history

* Version 1.0 (2021-04-12)
* Initial release.

## Feedback

If you would like a request any additional features, or if you encounter any bugs, please feel free to open a new issue!

## Author and copyright

Copyright (c) 2021 [Barak Shoshany](http://baraksh.com) (baraksh@gmail.com). Licensed under the [MIT license](LICENSE.txt).
51 changes: 51 additions & 0 deletions UltraDocker.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
; UltraDocker v1.0 (2021-04-12)
; By Barak Shoshany (baraksh@gmail.com) (http://baraksh.com)
; GitHub repository: https://github.com/bshoshany/UltraDocker

; When the trigger (by default, mouse button 4) is pressed, dock the window to the left, center, or right, depending on the current location of the mouse.
XButton1::
; Get the unique ID (HWND) of the active window.
window := WinExist("A")
; Restore the window if it is maximized, since resizing a maximized window may lead to unexpected results.
WinGet, is_min_max, MinMax, ahk_id %window%
If (is_min_max != 0)
{
WinRestore, ahk_id %window%
}
; Get the total work area, i.e. the size of the screen minus the taskbar.
SysGet, area, MonitorWorkArea
screen_width := areaRight - areaLeft
screen_height := areaBottom - areaTop
; Find the current x position of the mouse on the screen.
CoordMode, Mouse, Screen
MouseGetPos, x
; Find the size of the window's borders by comparing the x position of the mouse with respect to the entire window and with respect to just the window's client area, which excludes the borders.
CoordMode, Mouse, Window
MouseGetPos, x1, , A
CoordMode, Mouse, Client
MouseGetPos, x2, , A
border_x := x1 - x2
; Calculate the new height of the resized window.
height := screen_height + border_x
; Dock the window based on which third of the screen the mouse is located in.
If (x < screen_width / 3)
{
; Dock to the left at 50% screen width.
width := (screen_width / 2) + (2 * border_x)
left := -border_x
}
Else If (x > screen_width * 2 / 3)
{
; Dock to the right at 50% screen width.
width := (screen_width / 2) + (2 * border_x)
left := screen_width - width + border_x
}
Else
{
; Dock to the center at 60% screen width.
width := (screen_width * 0.6) + (2 * border_x)
left := (screen_width - width) / 2
}
; Move the window to the desired position with the desired size.
WinMove, ahk_id %window%, , %left%, 0, %width%, %height%
Return

0 comments on commit 0c29102

Please sign in to comment.