Skip to content

Instantly share code, notes, and snippets.

@unkn-one
Last active May 29, 2019 10:47
Show Gist options
  • Save unkn-one/ffd6568dc773e175435c7a86c69818b7 to your computer and use it in GitHub Desktop.
Save unkn-one/ffd6568dc773e175435c7a86c69818b7 to your computer and use it in GitHub Desktop.
Automatically move taskbar when monitor orientation changes
#NoEnv
#SingleInstance force
#Persistent
OnMessage(0x7E, "WM_DISPLAYCHANGE")
return
WM_DISPLAYCHANGE(wParam, lParam) {
x := lParam & 0xffff ;new horizontal res
y := (lParam >> 16) & 0xffff ;new vertical res
if (x > y) {
TaskbarMove("Left")
return
} else {
TaskbarMove("Bottom")
return
}
}
/*
** TaskbarMove by JSLover - r.secsrv.net/JSLover - r.secsrv.net/JSLoverAHK
** https://github.com/gerdami/AutoHotkey/blob/master/TaskbarMove.ahk
*/
TaskbarMove(p_pos) {
label:="TaskbarMove_" p_pos
WinExist("ahk_class Shell_TrayWnd")
SysGet, s, Monitor
if (IsLabel(label)) {
Goto, %label%
}
return
TaskbarMove_Top:
TaskbarMove_Bottom:
WinMove(sLeft, s%p_pos%, sRight, 0)
return
TaskbarMove_Left:
TaskbarMove_Right:
WinMove(s%p_pos%, sTop, 0, sBottom)
return
}
WinMove(p_x, p_y, p_w="", p_h="", p_hwnd="") {
WM_ENTERSIZEMOVE:=0x0231
WM_EXITSIZEMOVE :=0x0232
if (p_hwnd!="") {
WinExist("ahk_id " p_hwnd)
}
SendMessage, WM_ENTERSIZEMOVE
;//Tooltip WinMove(%p_x%`, %p_y%`, %p_w%`, %p_h%)
WinMove, , , p_x, p_y, p_w, p_h
SendMessage, WM_EXITSIZEMOVE
}
@mikehudson2
Copy link

mikehudson2 commented May 29, 2019

When testing on Surface Book 2 15 inch I found that the script worked as described whilst the screen was detached from the keyboard. However, when re-attached to the keyboard the taskbar moved again, to the top of the screen. This seems only to happen when the Surface Book is connected to a Surface Dock, and possibly it's related to the Surface Dock being connected to a secondary monitor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment