Skip to content
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

After aquamarine kanshi does not work well #7059

Closed
leiserfg opened this issue Jul 26, 2024 · 39 comments
Closed

After aquamarine kanshi does not work well #7059

leiserfg opened this issue Jul 26, 2024 · 39 comments
Labels
bug Something isn't working
Milestone

Comments

@leiserfg
Copy link
Contributor

leiserfg commented Jul 26, 2024

Regression?

Yes

System Info and Version

Nixos with hyprland compiled from 57371b9

Description

I use hyprland with kanshi (basically to turn off the laptop screen whenever I connect it to an external monitor). After aquamarine that does not work well, if I run hyprctl monitors it only shows the active (external) monitor as it should, but the laptop screen is still on (just not getting new frames). Disconnecting the external monitor (which should restart the laptop screen) crashes hyprland.

Besides that, the cursor looks tiny in apps not based in gtk (looks fine in firefox and waybar, but wrong in the wallpaper and kitty).

Those issues don't happen in 0.41.2+date=2024-07-20_f642fb9.

How to reproduce

In case it matters, I'm using a framework13 with AMD igpu.

Crash reports, logs, images, videos

No response

@leiserfg leiserfg added the bug Something isn't working label Jul 26, 2024
@leiserfg leiserfg changed the title After aquamarine kamshi does not work will After aquamarine kanshi does not work will Jul 26, 2024
@leiserfg
Copy link
Contributor Author

I also noticed that the screen turns white when hyprland starts (maybe it happens when kanshi rule gets applied).

@leiserfg leiserfg changed the title After aquamarine kanshi does not work will After aquamarine kanshi does not work well Jul 26, 2024
@vaxerski
Copy link
Member

where crash report

@mauricekraus
Copy link

@leiserfg, regarding the white flashing this is a dupe: #6950

@leiserfg
Copy link
Contributor Author

I'm testing now in 04b40ea
Unplugging the external monitor no longer crashes, but the laptop screen is still on when it should be off (dpms maybe?). Given that it's not crashing I don't have a crash report to send, is there something I can?

@leiserfg
Copy link
Contributor Author

leiserfg commented Jul 27, 2024

I ran hyprctl monitors all and I'm getting:

Monitor eDP-1 (ID 0):
	[email protected] at 0x0
	description: BOE 0x0BCA
	make: BOE
	model: 0x0BCA
	serial: 
	active workspace: 0 ()
	special workspace: 0 ()
	reserved: 0 27 0 0
	scale: 1.17
	transform: 0
	focused: no
	dpmsStatus: 1
	vrr: 0
	activelyTearing: false
	disabled: true
	currentFormat: XRGB8888
	availableModes: [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] 

Monitor DP-3 (ID 1):
	[email protected] at 0x0
	description: Dell Inc. DELL S2721QS DY1CM43
	make: Dell Inc.
	model: DELL S2721QS
	serial: DY1CM43
	active workspace: 1 (1)
	special workspace: 0 ()
	reserved: 0 27 0 0
	scale: 1.50
	transform: 0
	focused: yes
	dpmsStatus: 1
	vrr: 0
	activelyTearing: false
	disabled: false
	currentFormat: XRGB8888
	availableModes: [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] 

@leiserfg
Copy link
Contributor Author

leiserfg commented Jul 27, 2024

Shouldn't dpmsStatus be different for eDP-1?

Edit: self reply No, in "stable" it's also like that, the only difference I see is:

< 	reserved: 0 27 0 0
< 	scale: 1.17
---
> 	reserved: 0 0 0 0
> 	scale: 2.00

@299792458ms
Copy link

@leiserfg Would recommend shikane as a better alternative that might solve(or not) the current conflict you are having since I have no problems with it.

@leiserfg
Copy link
Contributor Author

Thanks, I will try it, but IMHO it still needs to be fixed.

@leiserfg
Copy link
Contributor Author

leiserfg commented Jul 28, 2024

@299792458ms I tried with shikane and got the same problem, but I discovered that if I disable the monitor, by using wdisplays the issue does not happen.

@299792458ms
Copy link

@leiserfg It happpened to me now, it does not happen 100% of the time though and it does not crash Hyprland if the cable is removed while the external monitor profile is active.

Ln 503 where profile switches: https://pastebin.com/9d8751aW
Shikane config: https://pastebin.com/3kx38Xh3
I dont know if this is useful at all.

@alexandru0-dev
Copy link

same problem here, hyprctrl says the monitor is disabled but remains on, seems is unresponsive/cannot switch to that monitor.
Unplugging the external monitor results in a crash as already reported.

@vaxerski here are the hyprlandCrashReport.txt and the hyprland.log

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 2, 2024

I was reading the code of kanshi and wdisplay and the only difference I noticed is that the former does not call wl_display_roundtrip, but maybe I'm missing something else.

@alexandru0-dev
Copy link

@leiserfg, after stopping kanshi i could use wdisplay and get the monitor to shutdown, tho when disabling the laptop monitor, the monitor disabled correctly but I got a:

Gdk-Message: 21:16:34.347: Lost connection to Wayland compositor.

message on wdisplay and also the application killed itself

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 3, 2024

I'm back in master:
hyprctl keyword monitor "eDP-1,disable" does the same (last frame frozen in the monitor).
The only thing that gets the monitor eDP-1 to turn off is wdisplays and it works only sometimes, and crashes right after (regardless of working or not) and I get the same error report as @alexandru0-dev

@leiserfg

This comment was marked as outdated.

@vaxerski
Copy link
Member

vaxerski commented Aug 3, 2024

can you attach a WAYLAND_DEBUG=1 wdisplays |& tee ~/wdisplays.log

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 3, 2024

Disabling eDP-1 with wdisplays in master.
wdisplays.log

@leiserfg

This comment was marked as outdated.

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 5, 2024

I've just tested master again, and now I can describe the issue in more detail:
The problem happens when a program tries to disable eDP-1 and enable another display when the second display is not fully "available".
For instance:

  • if I keep the external monitor connected, with kanshi in the config as exec-once=kanshi, and then start the issue happens.

  • if I keep the external monitor connected, with kanshi in the config as exec-once=sleep 10 & kanshi, and then start the issue does happens.

  • but if I keep the external monitor disconnected, with kanshi in the config as exec-once=sleep 10 & kanshi, and then start and after 15s I plug the external monitor the issue happens.

It looks like waiting until the monitor is fully "provisioned" before advertising it could solve the problem but not sure if that is the most correct thing to do.

Given the weirdness of the issue, most probably my bisect was incorrect.

@aruhier
Copy link
Contributor

aruhier commented Aug 5, 2024

I'll try to give some debug when it will happen again, but it's also something I get quite often on v0.41.2 with kanshine and shikane on connecting/disconnecting screens through USB-C. So it might not be entirely new.

I didn't try master yet (libinput 1.26 is not shipped on my distro yet, a requirement for aquamarine).

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 5, 2024

In v0.41.2 I have seen crashes when disconnecting a monitor, but never when connecting.

@aruhier
Copy link
Contributor

aruhier commented Aug 5, 2024

It's true, for me I think it only happens when connecting because the screen state flickers. Anyway, I'll post a debug log to see if it's related.

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 7, 2024

@vaxerski any pointer on where to look, I can try to fix it myself but I'm very rusty at C++ and don't know what to check. Gosh, 0.42.0 is out already and this is still broken 😢

@vaxerski
Copy link
Member

vaxerski commented Aug 7, 2024

we can't fix all bugs ever before releasing any update

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 7, 2024

I know, and I think it was a smooth one given the number of changes (thanks a lot to you and the other contributors). Is just that this one issue is very annoying, I have to turn on and off the laptop screen many times a day.

@vaxerski vaxerski added this to the 0.43.0 milestone Aug 7, 2024
@Vladimir-csp
Copy link
Contributor

An option to disable continuous monitor handling on hyprland's side would be handy. Otherwise hyprland and kanshi try doing different things.

@leiserfg
Copy link
Contributor Author

leiserfg commented Aug 8, 2024

@Vladimir-csp I'm not sure that's a good idea, every other wm (pre-aquamarine hyprland included) can handle that. Also, whatever breaks this also breaks wdisplays and potentially changing monitor rules on the fly.

@Vladimir-csp
Copy link
Contributor

Sorry for offtopic, I meant that for avoiding situations when hyprland autoenables output that kanshi then switches off. Lots of flicker and workspaces flying around for nothing.

@Vladimir-csp
Copy link
Contributor

Vladimir-csp commented Aug 15, 2024

Concocted a hyprland-native pattern-matching output manager:

Code
#!/bin/sh

# by https://github.com/Vladimir-csp/, WTFPL

# Operates in 'hypr' config dir.
# Expects 'source = monitors.conf' line in hyprland.conf.
# Manages 'monitors.conf'.
# Triggered by 'monitoraddedv2', 'monitorremoved' events on hyprland socket.
#
# Represents currently connected monitors as lines:
#
#   id:N;monitor:Port;description:Description;
#
# Checks 'monitors.d/*.conf' candidates which have at least one regexp or
# substring check defined as lines starting with '#re:' or 'str:':
#
#   #re: some regexp
#   #str: some substring
#
# These are checked against connected monitors representation described above.
# At least one check should be defined, all must match for file to be selected.
#
# The first matched candidate config is linked as 'monitors.conf', then
# 'hyprctl reload' is executed.
#
# If no candidate was matched, 'monitors.d/auto.conf' is selected (generated if
# not found).
#
# Example config:
#
#  # monitors.d/home.conf
#  # External monitor at home
#  #re: description:Dell.*ABCDEFG.*;
#  monitor = ,preferred,auto,1,vrr,2
#  monitor = eDP-1,disable
#  # any other setup-specific configuration

set -e

CONFIG_BASE="${XDG_CONFIG_HOME:-$HOME/.config}/hypr"
HYPRSOCKET="UNIX-CONNECT:${XDG_RUNTIME_DIR}/hypr/${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
AUTO_PROFILE='monitor = ,preferred,auto,1,vrr,2'
N='
'

get_monitors() {
	# Fills CURRENT_MONITORS var with monitors ids, names, and descriptions
	# initiate config string
	CURRENT_MONITORS=''
	unset CURRENTMON
	while read -r line <&3; do
		case "$line" in
		'Monitor '*:)
			# start new line for new monitor
			if [ -n "${CURRENTMON-}" ]; then
				CURRENT_MONITORS="${CURRENT_MONITORS}${N}"
			fi
			# extract id and monitor
			MONITOR=${line#Monitor }
			ID=${MONITOR#*(ID }
			ID=${ID%):}
			MONITOR=${MONITOR% (*}
			# append to CURRENT_MONITORS
			CURRENT_MONITORS="${CURRENT_MONITORS}id:${ID};monitor:${MONITOR};"
			CURRENTMON=${MONITOR}
			;;
		'description: '*)
			: "${CURRENTMON?Found '$line' outside monitor section}"
			IFS=':' read -r _key value <<- EOL
				$line
			EOL
			read -r value <<- EOL
				$value
			EOL
			CURRENT_MONITORS="${CURRENT_MONITORS}description:${value};"
			;;
		esac
	done 3<<- EOF
		$(LANG=C hyprctl monitors all)
	EOF
}

select_config() {
	# Finds configs in monitors.d which have #re: or #str:
	# conditions that all match against CURRENT_MONITORS
	# default:
	CONF_FILE='monitors.d/auto.conf'
	for file in monitors.d/*.conf; do
		# skip auto.conf
		case "$file" in
		monitors.d/auto.conf) continue ;;
		esac

		echo "Considering: ${file#*/}"
		match=false
		while read -r line <&3; do
			case "$line" in
			'#re:'*)
				# drop prefix
				re=${line#"#re:"}
				# strip whitespace
				read -r re <<- EOF
					$re
				EOF
				echo "Matching regexp: $re"
				if echo "$CURRENT_MONITORS" | grep -qEe "$re"; then
					match=true
				else
					match=false
					break
				fi
				;;
			'#str:'*)
				# drop prefix
				str=${line#"#str:"}
				# strip whitespace
				read -r str <<- EOF
					$str
				EOF
				echo "Matching substring: $str"
				case "$CURRENT_MONITORS" in
				*"$str"*) match=true ;;
				*)
					match=false
					break
					;;
				esac
				;;
			esac
		done 3< "$file"
		case "$match" in
		true)
			echo Matched
			CONF_FILE=$file
			break
			;;
		*)
			echo Rejected
			;;
		esac
	done
}

check_and_apply() {
	# does the thing
	get_monitors
	echo "Current configuration:"
	echo "$CURRENT_MONITORS"

	select_config
	if [ "${CONF_FILE}" != "$(readlink monitors.conf)" ]; then
		echo "Applying config: ${CONF_FILE#*/}"
		ln -sf "$CONF_FILE" monitors.conf
		sleep 1
		hyprctl reload
	else
		echo "Config '${CONF_FILE#*/}' already applied"
	fi
}

cd "$CONFIG_BASE"
echo "Operating in: '$CONFIG_BASE'"

mkdir -pv monitors.d

if [ ! -f monitors.d/auto.conf ]; then
	echo "$AUTO_PROFILE" > monitors.d/auto.conf
	echo "Created default 'monitors.d/auto.conf'"
fi

# check for socket
if [ ! -S "${HYPRSOCKET#UNIX-CONNECT:}" ]; then
	echo "Socket '$HYPRSOCKET' not found!" >&2
	exit 1
fi

# check hyprland.conf for proper source keyword
if [ ! -f hyprland.conf ]; then
	echo "'hyprland.conf' not found!" >&2
	exit 1
fi

SOURCED_MON=false
while IFS='=' read -r keyword value; do
	# strin whitespace
	read -r keyword <<- EOF
		$keyword
	EOF
	read -r value <<- EOF
		$value
	EOF
	case "${keyword}=${value}" in
	'source=monitors.conf')
		SOURCED_MON=true
		break
		;;
	esac
done < hyprland.conf

case "$SOURCED_MON" in
true) true ;;
*)
	echo "No 'source = monitors.conf' in hyprland.conf" >&2
	exit 1
	;;
esac

# do the thing once
check_and_apply

# main event cycle
socat -U - "$HYPRSOCKET" |
	while IFS='>' read -r EVENT _empty CONTENT; do
		case "$EVENT" in
		monitoraddedv2 | monitorremoved)
			# skip headless monitor events
			case "$CONTENT" in
			*HEADLESS*) continue ;;
			esac

			echo "Triggered by: ${EVENT}>>$CONTENT"
			check_and_apply

			;;
		esac
	done

It does not crash hyprland, but weird things happen when switching: waybar is duplicated/triplicated (fixed by reload), and visible windows sometimes crash.

@leiserfg
Copy link
Contributor Author

@Vladimir-csp If you are going that route, it's better to call hyprctl keyword monitor ... than to patch the config, I'm thinking of doing the same until some caritative soul takes care of the real problem.

@Vladimir-csp
Copy link
Contributor

@Vladimir-csp If you are going that route, it's better to call hyprctl keyword monitor ... than to patch the config, I'm thinking of doing the same until some caritative soul takes care of the real problem.

This would not survive the next reload.

@299792458ms
Copy link

@Vladimir-csp If you are going that route, it's better to call hyprctl keyword monitor ... than to patch the config, I'm thinking of doing the same until some caritative soul takes care of the real problem.

This would not survive the next reload.

One can restart only the configuration file with hyprctl reload config-only. Maybe it could work that way?

I have it like this:

bind = $mod SHIFT, R, exec, hyprctl reload config-only; notify-send "hyprctl" "restarted (config only)" -i ~/Pictures/icons/hypr_logo.svg -t 2000
bind = $mod SHIFT CTRL, R, exec, hyprctl reload; notify-send "hyprctl" "restarted" -i ~/Pictures/icons/hypr_logo.svg -t 2000

@Vladimir-csp
Copy link
Contributor

One can restart only the configuration file with hyprctl reload config-only. Maybe it could work that way?

Cool feature, but I also tweak gaps in those fragments via a var, it would be nuked.

@leiserfg
Copy link
Contributor Author

I'm currently doing

bind = $mod, S, exec, sh -c "hyprctl monitors | grep eDP-1 &&  hyprctl keyword monitor eDP-1,disable || hyprctl keyword monitor eDP-1,preferred,auto,auto"

To just toggle the laptop screen.

@vaxerski
Copy link
Member

please check out #7571

@vaxerski vaxerski modified the milestones: 0.43.0, 0.44.0 Sep 10, 2024
@leiserfg
Copy link
Contributor Author

@vaxerski I think this is linked to the problem of FallbackMonitor not working correctly either (even without an external displays manager).

@leiserfg
Copy link
Contributor Author

leiserfg commented Sep 25, 2024

I spoke with the author of shikane and he told me the issue is that hyprland should send Finished events when physically disconnecting monitors but it sends Disabled instead.

@levnikmyskin
Copy link
Contributor

I think that's happened in the past already. If that's really the problem it shouldn't be too hard to fix. I'll look into it eventually, but not in these next days

@leiserfg
Copy link
Contributor Author

leiserfg commented Sep 26, 2024

I forwarded the comments from Hendrik Wolff (the shikane guy) to vaxry and that helped him fix the issue in #7571 so it seems this can be closed soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants