Last active
January 23, 2025 14:17
-
-
Save xdegeneratex/e28e4554e2167a04c7522f013bce4a4c to your computer and use it in GitHub Desktop.
Create a VLC window grid - AHK v1
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
| #Persistent ; Keep the script running indefinitely | |
| #SingleInstance Force ; Replace the existing instance and do not ask for confirmation | |
| SetTitleMatchMode, 2 ; Allow partial matching of window titles (e.g., "VLC" will match "VLC media player") | |
| ; Max window size | |
| MaxWidth := 420 ; Maximum width of the VLC windows | |
| MaxHeight := 340 ; Maximum height of the VLC windows | |
| ; Grid spacing (adjust for padding between windows) | |
| Spacing := 58 ; Distance between windows in the grid layout | |
| ; Get the screen dimensions | |
| SysGet, ScreenWidth, 78 ; Screen width (in pixels) | |
| SysGet, ScreenHeight, 79 ; Screen height (in pixels) | |
| ; Hotkey: Alt + 0 (Arrange VLC windows) | |
| !0:: | |
| ; Get a list of all open VLC windows | |
| DetectHiddenWindows, Off ; Enable detection of hidden windows | |
| WinGet, vlcList, List, VLC ; Get a list of all windows with "VLC" in their title | |
| ; Calculate the number of columns that can fit in one row (based on screen width and window width) | |
| ColCount := Floor(ScreenWidth / (MaxWidth + Spacing)) | |
| ; Calculate the number of rows needed to fit all windows | |
| RowCount := Ceil(vlcList / ColCount) | |
| ; Adjust the MaxHeight and starting yPos if there are fewer rows | |
| ; This logic is based on the assumption that the screen height is 1080 pixels and adjusts the grid layout. | |
| if (RowCount < 3) { | |
| MaxHeight := 420 ; Reset height if row count is less than 3 | |
| yPos := 105 ; Set a higher initial y-position (top padding) for better layout | |
| } | |
| ; Calculate the total height of the grid | |
| TotalHeightOfGrid := RowCount * MaxHeight + (RowCount - 1) * Spacing - Spacing - 10 ; Account for spacing between rows | |
| ; Variables for positioning | |
| xPos := 0 ; Initial horizontal position for the first window | |
| yPos := (ScreenHeight - TotalHeightOfGrid) / 2 ; Center the grid vertically on the screen | |
| ; Ensure the window width and height do not exceed the maximum size | |
| Width := MaxWidth | |
| Height := MaxHeight | |
| ; Loop through each VLC window in the list | |
| Loop, % vlcList | |
| { | |
| ; Get the window ID for the current VLC window | |
| thisVLC := vlcList%A_Index% ; Access the window ID of the current VLC window | |
| ; Calculate the row and column for this window | |
| row := Ceil(A_Index / ColCount) ; Determine which row the window is in (1-based index) | |
| col := Mod(A_Index - 1, ColCount) ; Determine the column in the row (0-based index) | |
| ; Calculate how many windows are in this row | |
| windowsInRow := Min(ColCount, vlcList - ((row - 1) * ColCount)) | |
| ; Calculate the total width of the current row (including spacing between windows) | |
| RowWidth := (windowsInRow * Width) + ((windowsInRow - 1) * Spacing) + Spacing + 10 ; Total width of the row | |
| ; Center the row horizontally by adjusting the xPos for each window in the row | |
| rowXPos := (ScreenWidth - RowWidth) / 2 + col * (Width + Spacing) ; Horizontal position for the current window in the row | |
| ; Move and resize the window based on the calculated position and size | |
| WinMove, ahk_id %thisVLC%, , rowXPos, yPos, Width, Height ; Move the window to (rowXPos, yPos) and resize it | |
| ; If the current window is the last in the row, increment yPos to start a new row | |
| if (col + 1 >= windowsInRow) { | |
| yPos += Height ; Move to the next row | |
| } | |
| } | |
| ; Loop through each VLC window and bring it to the foreground | |
| Loop, % vlcList | |
| { | |
| thisVLC := vlcList%A_Index% ; Access the window ID of the current VLC window | |
| WinActivate, ahk_id %thisVLC% ; Activate the window to bring it to the foreground | |
| } | |
| ; Mouse Hover Activation | |
| SetTimer, CheckMouse, 10 ; Set a timer to check the mouse position every 10 milliseconds | |
| return | |
| ; Function to check the window under the mouse | |
| CheckMouse: | |
| MouseGetPos, mouseX, mouseY, windowUnderMouse ; Get the mouse position and the window under the cursor | |
| if (windowUnderMouse != lastWindow) ; Only proceed if the window under the mouse has changed | |
| { | |
| lastWindow := windowUnderMouse ; Store the current window as the last window | |
| WinGetTitle, windowTitle, ahk_id %windowUnderMouse% ; Get the title of the window under the mouse | |
| ; If the window title contains "VLC", activate it | |
| if InStr(windowTitle, "VLC media") { | |
| WinActivate, ahk_id %windowUnderMouse% ; Activate the VLC window under the mouse | |
| } | |
| } | |
| return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment