- Improved monitor detection with primary/secondary identification - Enhanced logging to track monitor layout and selection process - Added comprehensive debug scripts for troubleshooting monitor issues - Better error handling in monitor selection logic - Created test utilities for validating monitor selection behavior Debug tools added: - debug_monitor_issue.sh: Comprehensive monitor debugging script - test_enhanced_monitor.py: Tests monitor selection logic with logging - debug_rdp_command.py: Tests RDP command generation Fixes: - Monitor detection now identifies primary monitor correctly - Detailed logging shows exactly which monitors are selected - Better fallback handling for monitor detection errors - Enhanced command logging for easier troubleshooting
99 lines
3.2 KiB
Python
99 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
|
|
def get_best_monitor_selection(count):
|
|
"""Get the best monitor selection based on layout"""
|
|
try:
|
|
result = subprocess.run(['xfreerdp', '/monitor-list'],
|
|
capture_output=True, text=True, timeout=5)
|
|
if result.returncode == 0:
|
|
lines = result.stdout.strip().split('\n')
|
|
monitors = []
|
|
for line in lines:
|
|
# Clean up the line and split by whitespace/tabs
|
|
cleaned_line = line.strip().replace('*', '').strip()
|
|
if '[' in cleaned_line and ']' in cleaned_line and 'x' in cleaned_line and '+' in cleaned_line:
|
|
# Split by whitespace/tabs
|
|
parts = cleaned_line.split()
|
|
if len(parts) >= 3:
|
|
id_part = parts[0] # [0]
|
|
pos_part = parts[2] # +3840+0
|
|
if '[' in id_part and ']' in id_part:
|
|
monitor_id = int(id_part.strip('[]'))
|
|
x_pos = int(pos_part.split('+')[1])
|
|
monitors.append((monitor_id, x_pos))
|
|
|
|
# Sort monitors by X position (left to right)
|
|
monitors.sort(key=lambda x: x[1])
|
|
|
|
# Return the leftmost monitors
|
|
selected = [str(m[0]) for m in monitors[:count]]
|
|
return ','.join(selected)
|
|
except:
|
|
pass
|
|
|
|
# Fallback: simple sequential selection
|
|
return ','.join([str(i) for i in range(count)])
|
|
|
|
def test_command_generation():
|
|
print("=== Testing RDP Command Generation ===")
|
|
print()
|
|
|
|
# Test connection data
|
|
conn = {
|
|
'server': 'test-server',
|
|
'username': 'testuser',
|
|
'domain': '',
|
|
'resolution': 'Full Screen',
|
|
'color_depth': 32,
|
|
'sound': 'Yes',
|
|
'clipboard': 'Yes'
|
|
}
|
|
|
|
# Test different monitor configurations
|
|
test_cases = [
|
|
("2 Monitors", 2),
|
|
("3 Monitors", 3),
|
|
("All Monitors", None)
|
|
]
|
|
|
|
for multimon, count in test_cases:
|
|
print(f"Testing: {multimon}")
|
|
|
|
# Build base command
|
|
cmd = ["xfreerdp"]
|
|
cmd.append(f"/v:{conn['server']}")
|
|
cmd.append(f"/u:{conn['username']}")
|
|
cmd.append("/p:password")
|
|
|
|
if conn.get('domain'):
|
|
cmd.append(f"/d:{conn['domain']}")
|
|
|
|
# Resolution
|
|
cmd.append("/f") # Full screen
|
|
|
|
# Color depth
|
|
cmd.append(f"/bpp:{conn['color_depth']}")
|
|
|
|
# Monitor handling
|
|
if multimon == "2 Monitors":
|
|
monitor_list = get_best_monitor_selection(2)
|
|
cmd.append(f"/monitors:{monitor_list}")
|
|
elif multimon == "3 Monitors":
|
|
monitor_list = get_best_monitor_selection(3)
|
|
cmd.append(f"/monitors:{monitor_list}")
|
|
elif multimon == "All Monitors":
|
|
cmd.append("/multimon")
|
|
|
|
# Other options
|
|
cmd.append("/sound:sys")
|
|
cmd.append("+clipboard")
|
|
|
|
# Print the command
|
|
cmd_str = ' '.join(cmd).replace("/p:password", "/p:***")
|
|
print(f"Command: {cmd_str}")
|
|
print()
|
|
|
|
if __name__ == "__main__":
|
|
test_command_generation() |