custom-hypr - add script for hyprland

This commit is contained in:
huyjaky
2024-10-21 22:55:13 +07:00
parent 0cf0beb8c7
commit 39467b1bbe
9 changed files with 167 additions and 11 deletions

View File

@@ -0,0 +1,61 @@
#!/bin/bash
# Lấy thông tin của cửa sổ hiện tại chỉ một lần
window_info=$(hyprctl activewindow)
# Trích xuất giá trị cần thiết từ window_info
# 1892
window_x_position=$(echo "$window_info" | grep -oP '(?<=at: )\d+')
window_at_monitor=$(echo "$window_info" | grep 'monitor' | awk '{print $2}')
window_at_workspace=$(echo "$window_info" | grep 'workspace' | awk '{print $2}')
window_state=$(echo "$window_info" | grep 'fullscreen:' | awk '{print $2}')
current_workspace=$(hyprctl activeworkspace | grep 'workspace' | awk '{print $3}')
window_width=$(echo "$window_info" | grep 'size:' | awk '{print $2}' | cut -d',' -f1)
echo $window_stat
echo $window_x_position
echo $window_width
hyprctl dispatch fullscreenstate 0 # minimize trước khi di chuyển
# NOTE: Di chuyển cửa sổ nếu vị trí X vượt qua ngưỡng
if [ $window_x_position -eq 14 ] && [ $window_state -eq 1 ]; then
if [ $current_workspace -eq 1 ]; then
exit 1
fi
hyprctl dispatch movetoworkspace $((window_at_workspace-1))
hyprctl dispatch focusmonitor 0
hyprctl dispatch workspace $((current_workspace-2))
hyprctl dispatch focusmonitor 1
exit 0
fi
if [ $window_x_position -eq 14 ] && [ $window_width -eq 1892 ]; then
if [ $current_workspace -eq 1 ]; then
exit 1
fi
hyprctl dispatch movetoworkspace $((window_at_workspace-1))
hyprctl dispatch focusmonitor 0
hyprctl dispatch workspace $((current_workspace-2))
hyprctl dispatch focusmonitor 1
exit 0
fi
if [ $window_x_position -eq 14 ]; then
if [ $current_workspace -eq 1 ]; then
exit 1
fi
hyprctl dispatch movetoworkspace $((window_at_workspace-1))
hyprctl dispatch focusmonitor 0
hyprctl dispatch workspace $((current_workspace-2))
hyprctl dispatch focusmonitor 1
exit 0
fi
# Nếu không thoả điều kiện di chuyển, di chuyển cửa sổ sang phải
hyprctl dispatch movewindow l

View File

@@ -0,0 +1,61 @@
#!/bin/bash
# Lấy thông tin của cửa sổ hiện tại chỉ một lần
window_info=$(hyprctl activewindow)
# Trích xuất giá trị cần thiết từ window_info
# 1892
window_x_position=$(echo "$window_info" | grep -oP '(?<=at: )\d+')
window_at_monitor=$(echo "$window_info" | grep 'monitor' | awk '{print $2}')
window_at_workspace=$(echo "$window_info" | grep 'workspace' | awk '{print $2}')
window_state=$(echo "$window_info" | grep 'fullscreen:' | awk '{print $2}')
current_workspace=$(hyprctl activeworkspace | grep 'workspace' | awk '{print $3}')
window_width=$(echo "$window_info" | grep 'size:' | awk '{print $2}' | cut -d',' -f1)
echo $window_stat
echo $window_x_position
echo $window_width
hyprctl dispatch fullscreenstate 0 # minimize trước khi di chuyển
# NOTE: Di chuyển cửa sổ nếu vị trí X vượt qua ngưỡng
if [ $window_x_position -eq 1934 ] && [ $window_state -eq 1 ]; then
if [ $current_workspace -eq 6 ]; then
exit 1
fi
hyprctl dispatch movetoworkspace $((window_at_workspace+1))
hyprctl dispatch focusmonitor 1
hyprctl dispatch workspace $((current_workspace+2))
hyprctl dispatch focusmonitor 0
exit 0
fi
if [ $window_x_position -eq 1934 ] && [ $window_width -eq 1892 ]; then
if [ $current_workspace -eq 6 ]; then
exit 1
fi
hyprctl dispatch movetoworkspace $((window_at_workspace+1))
hyprctl dispatch focusmonitor 1
hyprctl dispatch workspace $((current_workspace+2))
hyprctl dispatch focusmonitor 0
exit 0
fi
if [ $window_x_position -eq 2990 ]; then
if [ $current_workspace -eq 6 ]; then
exit 1
fi
hyprctl dispatch movetoworkspace $((window_at_workspace+1))
hyprctl dispatch focusmonitor 1
hyprctl dispatch workspace $((current_workspace+2))
hyprctl dispatch focusmonitor 0
exit 0
fi
# Nếu không thoả điều kiện di chuyển, di chuyển cửa sổ sang phải
hyprctl dispatch movewindow r

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Extract workspace ID from the output of hyprctl activewindow
current_monitor=$(hyprctl activeworkspace | grep 'monitorID' | awk '{print $2}')
current_workspace=$(hyprctl activeworkspace | grep 'workspace' | awk '{print $3}')
# Determine the second workspace based on whether the current workspace is even or odd
if [ $((current_workspace % 2)) -eq 0 ]; then
second_workspace=$((current_workspace - 1))
else
second_workspace=$((current_workspace + 1))
fi
# Assign primary and secondary monitor workspaces based on the current workspace
if [ $((current_workspace % 2)) -eq 0 ]; then
primary_monitor_workspace=$((second_workspace + 2)) # left
secondary_monitor_workspace=$((current_workspace + 2)) # right
else
primary_monitor_workspace=$((current_workspace + 2))
secondary_monitor_workspace=$((second_workspace + 2))
fi
# Check if primary_monitor_workspace is less than or equal to 0
# or if secondary_monitor_workspace is greater than or equal to 11
if [ "$primary_monitor_workspace" -le 0 ] || [ "$secondary_monitor_workspace" -ge 7 ]; then
exit 1
fi
# Switch focus and workspace for both monitors
hyprctl dispatch focusmonitor 0
hyprctl dispatch workspace $primary_monitor_workspace
hyprctl dispatch focusmonitor 1
hyprctl dispatch workspace $secondary_monitor_workspace
# Optionally focus back to the original monitor if desired (adjust this part if needed)
hyprctl dispatch focusmonitor 0