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

duplicate events #9

Open
vredesbyyrd opened this issue Apr 21, 2021 · 5 comments
Open

duplicate events #9

vredesbyyrd opened this issue Apr 21, 2021 · 5 comments

Comments

@vredesbyyrd
Copy link

vredesbyyrd commented Apr 21, 2021

Hi, thanks for sharing this tool, it appears to be exactly what I was looking for.

Currently events are duplicated whenever I plug/unplug my 2nd display, similar to behavior described in issue #5.

Environment info:

  • Arch linux, Budgie, kernel 5.11.15-1-ck-skylake
  • ThinkPad X1 Carbon 6th
  • srandrd 0.6.1

Command: srandrd -v -n display_handler.sh

display_handler.sh ...

#!/bin/sh

SET_PACWALL=$(set-pacwall.sh)

case "${SRANDRD_OUTPUT} ${SRANDRD_EVENT}" in
  "HDMI1 connected") "$SET_PACWALL" &>/dev/null &;;
  "HDMI1 disconnected") "$SET_PACWALL" &>/dev/null &;;
esac

Command output for one plug/unplug "cycle":


Event: HDMI-1 connected
Time: 250369192
Size: 474mm x 296mm
EDID (vendor, product, serial): AC10F01145384D4C
Event: HDMI-1 connected
Time: 250401280
CRTC: 64
Size: 1680x1050
EDID (vendor, product, serial): AC10F01145384D4C
Event: HDMI-1 disconnected
Time: 250401280
CRTC: 64
Size: 1680x1050
EDID (vendor, product, serial): AC10F01145384D4C
Event: HDMI-1 disconnected
Time: 250435295
Size: 0mm x 0mm
EDID (vendor, product, serial): AC10F01145384D4C

Any thoughts? Thanks for your time.

@nadavwr
Copy link

nadavwr commented May 21, 2021

I'm also experiencing this. Built against master (4e4b754) on Arch.
I'm running Arch as a vmware guest, and each disconnect or connect event is listed twice.
udevadm monitor -u only Iists one entry per event.

@tummychow
Copy link

Having the same problem. A similar project (troglobit/xplugd#8) seems to have the same problem as well. I can't speak to other people's setups, but the problem seems to be when you call xrandr inside of your srandrd script. I recommend using xev -event randr to debug, since this shows the raw event stream (and proves that the bug is not in srandrd).

In my setup, I have a laptop with an internal display (eDP-1), and an external HDMI display (HDMI-1). If I plug in the HDMI display without srandrd running, here's the event output I see:

$ xev -event randr
Outer window is 0x2800001, inner window is 0x2800002

RRScreenChangeNotify event, serial 25, synthetic NO, window 0x2800001,
    root 0x679, timestamp 1034600, config_timestamp 1182251
    size_index 65535, subpixel_order SubPixelUnknown
    rotation RR_Rotate_0
    width 3843, height 1080, mwidth 1014, mheight 285

RRNotify event, serial 25, synthetic NO, window 0x2800001,
    subtype XRROutputChangeNotifyEvent
    output HDMI-1, crtc 64, mode 1920x1080 (1920x1080)
    rotation RR_Rotate_0
    connection RR_Connected, subpixel_order SubPixelUnknown

But my srandrd script normally runs an xrandr --auto on the output that just got connected/disconnected. If I have srandrd running when I connect the monitor, I get this instead:

xev -event randr
Outer window is 0x3000001, inner window is 0x3000002

RRScreenChangeNotify event, serial 25, synthetic NO, window 0x3000001,
    root 0x679, timestamp 1443009, config_timestamp 1452579
    size_index 0, subpixel_order SubPixelUnknown
    rotation RR_Rotate_0
    width 1920, height 1080, mwidth 506, mheight 285

RRNotify event, serial 25, synthetic NO, window 0x3000001,
    subtype XRROutputChangeNotifyEvent
    output HDMI-1, crtc None, mode None
    rotation RR_Rotate_0
    connection RR_Connected, subpixel_order SubPixelUnknown

RRScreenChangeNotify event, serial 30, synthetic NO, window 0x3000001,
    root 0x679, timestamp 1443009, config_timestamp 1452579
    size_index 65535, subpixel_order SubPixelUnknown
    rotation RR_Rotate_0
    width 3843, height 1080, mwidth 1014, mheight 285

RRScreenChangeNotify event, serial 30, synthetic NO, window 0x3000001,
    root 0x679, timestamp 1443009, config_timestamp 1452579
    size_index 65535, subpixel_order SubPixelUnknown
    rotation RR_Rotate_0
    width 3843, height 1080, mwidth 1014, mheight 285

RRNotify event, serial 30, synthetic NO, window 0x3000001,
    subtype XRRCrtcChangeNotifyEvent
    crtc 64, mode 1920x1080, rotation RR_Rotate_0
    x 1923, y 0, width 1920, height 1080

RRNotify event, serial 30, synthetic NO, window 0x3000001,
    subtype XRROutputChangeNotifyEvent
    output HDMI-1, crtc 64, mode 1920x1080 (1920x1080)
    rotation RR_Rotate_0
    connection RR_Connected, subpixel_order SubPixelUnknown

As you can see, the second output has two XRROutputChangeNotifyEvent events with an output HDMI-1 in them. This is probably the duplication that we're observing. (Another observation: my srandrd script runs xrandr --auto on both the connect and disconnect events. If I only run it on the connect event, I get no duplication. If I only run it on the disconnect event, I still get duplication.)

I tried replacing my --auto with --preferred and it went back to the regular behavior without duplicated events. So the problem arises when you disable an output (--auto, --off) in your srandrd script. Unfortunately, I really do want to enable/disable outputs in my srandrd script (otherwise the screen area doesn't shrink back to normal when I unplug a monitor). Perhaps I'll see if the mode None event can be filtered out; otherwise I'll have to debounce my script.

@tummychow
Copy link

tummychow commented Aug 8, 2021

Hmm, my initial idea was "ignore all events with mode None but it seems to be a bit more complex. The sequence of events seems to be like this:

  1. I plug the monitor in (produces a connected event with mode None)
  2. in response to event 1, srandrd runs xrandr --auto (produces a connected event with mode 1920x1080)
  3. I unplug the monitor (produces a disconnected event with mode 1920x1080)
  4. in response to event 3, srandrd runs xrandr --auto (produces a disconnected event with mode None)

The problem is that, if all the mode None events are ignored, then plugging the monitor in does not produce event 1, thus xrandr --auto never gets run. Then when I unplug the monitor, it produces event 4 instead of event 3 (the monitor never go a mode applied, because xrandr --auto never got run).

I wound up with a more complex approach, where I ignore connected events with a mode, and disconnected events without a mode. Frankly I'm not sure this is a good idea. Maybe the behavior should be gated behind a CLI option? But I'll share it here if other people want to try: tummychow@9016750 The conditionals come from https://cgit.freedesktop.org/xorg/app/xev/tree/xev.c?h=xev-1.2.4#n956 .

e: Perhaps a better solution is to add an SRANDRD_MODE envar that contains the mode (or is empty if the mode is unset). This would allow users to debounce the duplicate events themselves if they wanted to. But I'm too lazy to implement that now that my setup works.

@jceb
Copy link
Owner

jceb commented Aug 13, 2023

Is this still an issue?

@schoolsplay
Copy link

Yes, still an issue.
Im on Ubuntu 22.04 and as a 'display_handler' I use a simple bash script that echos the data it receives from srandrd into a file.
It receives connect/disconnect event twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants