-
Notifications
You must be signed in to change notification settings - Fork 265
RK3576: DP Alt Mode display management (automatic display switching) #2678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
projects/ROCKNIX/packages/apps/screen-switch/scripts/screen_switch
This file was deleted.
Oops, something went wrong.
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
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
74 changes: 74 additions & 0 deletions
74
projects/ROCKNIX/packages/sysutils/system-utils/sources/scripts/output_monitor
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/bin/bash | ||
| # SPDX-License-Identifier: GPL-2.0-or-later | ||
| # Copyright (C) 2025 ROCKNIX (https://github.com/ROCKNIX) | ||
| # | ||
| # Monitors external display outputs (DP, HDMI) via sway IPC and powers | ||
| # internal panels (DSI, eDP) off/on accordingly. | ||
| # | ||
| # The sway IPC subscription is used rather than udev because the actions | ||
| # (wlr-randr, swaymsg) require sway to be running and to have already | ||
| # processed the new output. Subscribing to sway output events is | ||
| # inherently synchronized with sway's internal state, avoiding the need | ||
| # for retry logic after a kernel hotplug uevent. | ||
|
|
||
| . /etc/profile | ||
|
|
||
| # Exit if this device has no external display connectors at all | ||
| ls /sys/class/drm/card*-DP-* /sys/class/drm/card*-HDMI-A-* 2>/dev/null | grep -q . || exit 0 | ||
|
|
||
| _LAST_STATE="init" | ||
|
|
||
| _get_active_externals() { | ||
| wlr-randr 2>/dev/null | awk ' | ||
| /^(DP|HDMI|DisplayPort)-/ { name=$1; in_ext=1; next } | ||
| /^[A-Za-z]/ { in_ext=0 } | ||
| in_ext && /Enabled: yes/ { print name } | ||
| ' | ||
| } | ||
|
|
||
| _get_all_internals() { | ||
| wlr-randr 2>/dev/null | awk '/^(DSI|eDP|LVDS)-/ { print $1 }' | ||
| } | ||
|
|
||
| _apply() { | ||
| local state="internal" | ||
| [ -n "$(_get_active_externals)" ] && state="external" | ||
| [ "$_LAST_STATE" = "$state" ] && return | ||
| local prev="$_LAST_STATE" | ||
| _LAST_STATE="$state" | ||
|
|
||
| if [ "$state" = "external" ]; then | ||
| local ext_out | ||
| ext_out=$(_get_active_externals | head -1) | ||
| while IFS= read -r out; do | ||
| wlr-randr --output "$out" --off 2>/dev/null | ||
| done < <(_get_all_internals) | ||
| if [ -n "$ext_out" ]; then | ||
| swaymsg "[app_id=\"emulationstation\"] move output ${ext_out}" 2>/dev/null || true | ||
| fi | ||
| # Stop USB gadget: its data lanes conflict with DP Alt Mode on RK3576 | ||
| systemctl is-active --quiet usbgadget && systemctl stop usbgadget | ||
| else | ||
| # Only re-enable internal panels on actual disconnect, not first-boot | ||
| if [ "$prev" != "init" ]; then | ||
| while IFS= read -r out; do | ||
| wlr-randr --output "$out" --preferred --on 2>/dev/null | ||
| done < <(_get_all_internals) | ||
| fi | ||
| fi | ||
|
|
||
|
|
||
| } | ||
|
|
||
| # Allow sway to finish initialising outputs before first check | ||
| sleep 3 | ||
|
|
||
| while true; do | ||
| _apply | ||
| # Block until sway reports an output event (or 10s timeout). | ||
| # The timeout acts as a periodic retry to catch events missed when sway | ||
| # fires before finishing output configuration (e.g. boot-time hotplug). | ||
| # grep -q exits on first '"change"' match, terminating swaymsg cleanly. | ||
| timeout 10 swaymsg -t subscribe '["output"]' 2>/dev/null | grep -q '"change"' || true | ||
| sleep 0.3 | ||
| done |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.