Xfce Forum

Sub domains
 

You are not logged in.

#1 2017-10-20 09:37:12

marko
Member
Registered: 2017-10-20
Posts: 21

How does Xfce detect when a monitor is connected?

Hi all,

Currently, there are 3 ways that I know of that can be used to detect when the end user plugs or unplugs a monitor:

1. Via a udev rule
2. Via xrandr
3. Via reading /sys/class/drm/cardX-x/status but this doesn't always show the status correctly.

Now I've noticed, Xfce automatically brings up the Display Configuration Utility when the monitor video cable is plugged in.

Please tell me how, what C/C++ API call or linux specific system callback or polling is Xfce using to detect this. I would *really* love to know this.

I've already done this via a udev rule and referencing a script to run when this happens but the problem is, this rule does not work when the NVIDIA drivers are installed.

Creating a script that polls /sys/class/drm/cardX-x/status is not reliable because it doesn't always report the correct status. For instance, my HDMI cable was disconnected but /sys/class/drm/card0-HDMI-A-1/status returned "connected" and that's not good.

Creating a script and running xrandr every few seconds is a bit heavy so this is no good either.

One alternative that works is to replace /usr/bin/xfce4-display-settings with my own script but I'd rather not do that and I would really like to know how does Xfce detect when a monitor is plugged in.

BTW, Xfce is the best DE of all times. I can never use anything else but Xfce.

Last edited by marko (2017-10-20 09:39:23)

Offline

#2 2017-10-20 23:49:18

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,486

Re: How does Xfce detect when a monitor is connected?

Hello and welcome.

Just had a quick look at the code and it looks like it reacts to an xrandr RRScreenChangeNotify event. See: https://git.xfce.org/xfce/xfce4-setting … ays.c#n427.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2017-10-21 02:21:03

marko
Member
Registered: 2017-10-20
Posts: 21

Re: How does Xfce detect when a monitor is connected?

Thanks! I will take a look at it.

Offline

#4 2017-10-21 11:13:02

marko
Member
Registered: 2017-10-20
Posts: 21

Re: How does Xfce detect when a monitor is connected?

Here is a perfectly (tested) working example: https://gist.github.com/mafrasi2/4ee01e … e463f32fca

More info: https://www.x.org/archive//X11R7.7/doc/ … dr.3.xhtml

"A XRRScreenChangeNotifyEvent is sent to a client that has requested notification whenever the screen configuration is changed. A client can perform this request by calling XRRSelectInput, passing the display, the root window, and the RRScreenChangeNotifyMask mask.

XRRScreenConfiguration is an opaque data type containing the configuration information for a screen."

Last edited by marko (2017-10-21 11:16:10)

Offline

#5 2017-10-21 19:21:57

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,486

Re: How does Xfce detect when a monitor is connected?

Nice. Thanks for posting back a solution.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#6 2017-10-21 21:39:47

marko
Member
Registered: 2017-10-20
Posts: 21

Re: How does Xfce detect when a monitor is connected?

No problems and again, Xfce is absolutely awesome. Keep up the good work with the GTK 3.x port please and I expect the same level of customization, responsiveness and stability (not concerned about memory consumption, have plenty of it). One concerning thing which I hope won't be overlooked is the panel icon spacing / padding / sizing. Right now, my xfce4-panel icon spacing, padding and sizing between icons (launcher shortcuts and notification icons) is all equal (top, bottom, left and right) - this padding and sizing is adjustable via the theme. "Please" preserve this functionality with GTK 3.x. It's very pleasant to the eyes - it's all aesthetically spaced out.

Last edited by marko (2017-10-22 00:54:45)

Offline

#7 2017-10-22 12:09:58

filipbekic01
Member
From: Serbia
Registered: 2015-11-25
Posts: 7

Re: How does Xfce detect when a monitor is connected?

Hey marko, thanks for the script, lovely.

I also have high hopes for GTK3 porting, can't wait actually. Huge fan of xfce4 too smile

Offline

#8 2017-10-22 13:16:00

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,486

Re: How does Xfce detect when a monitor is connected?

marko wrote:

Keep up the good work with the GTK 3.x port please and I expect the same level of customization, responsiveness and stability (not concerned about memory consumption, have plenty of it).

filipbekic01 wrote:

I also have high hopes for GTK3 porting, can't wait actually.

The GTK3 port is looking good. Here is the current status. Looks alot like GTK2 Xfce, but with the newer toolkit:

screenshot2017-10-2209-03-52.png
(Xfce built off of current git tree - latest development versions of components)

Still as configurable as the GTK2 version, with theme/appearance tweaks now being done via css in gtk.css (instead of gtkrc-2.0). xfce4-panel still supports the older GTK2 plugins so they can still be used if they are not ported over to GTK3.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#9 2017-11-22 05:35:14

astro
Member
Registered: 2017-11-22
Posts: 2

Re: How does Xfce detect when a monitor is connected?

I just installed and am using 4.12.1, and this feature is not working.

I plug in HDMI, the second monitor flashes through it's different outputs, stops at HDMI, then says "no signal", then goes black.

I opened up the display settings and selected "Configure new displays when connected", and that has not resolved my issue, and the secondary monitor is not available for selection in the drop down.

`xrandr --query` displays: HDMI-1 disconnected

Last edited by astro (2017-11-22 05:35:57)

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.015 seconds, 8 queries executed - Memory usage: 558.11 KiB (Peak: 574.95 KiB) ]