Skip to content

Fix handling of non V1.5 XRandr.#364

Merged
tsipinakis merged 2 commits intodunst-project:masterfrom
SteveJones:master
Nov 4, 2017
Merged

Fix handling of non V1.5 XRandr.#364
tsipinakis merged 2 commits intodunst-project:masterfrom
SteveJones:master

Conversation

@SteveJones
Copy link
Copy Markdown

Due to the way Xlib handles errors XRRGetMonitors will cause dunst to exit if
the server doesn't support version 1.5 of Randr. The check for null is
effectively dead code. Change the code to fetch the Randr version and fallback
if the version is less than 1.5 when getting monitors.

Copy link
Copy Markdown
Member

@tsipinakis tsipinakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in reviewing this, I wasn't home for the past few days.

Comment thread src/x11/screen.c Outdated

int randr_event_base = 0;

static int randr_major_version = 1;
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why default these to 1 and 5? I think setting them to 0 would be a better choice.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was me reading the protocol docs which say that the client has to send the version it expects, but the xrandr code sends this itself, it doesn't use the initial value of the pointers you pass in. I'll fix this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was me reading the protocol docs which say that the client has to send the version it expects

Where does it say that? It's not mentioned anywhere in the xrandr man page?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the protocol specification, but the library API doesn't match that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it, JFTR in this document search for QueryVersion.

The client sends the highest supported version to the server
and the server sends the highest version it supports, but no
higher than the requested version. Major versions changes can
introduce incompatibilities in existing functionality, minor
version changes introduce only backward compatible changes.
It is the clients responsibility to ensure that the server
supports a version which is compatible with its expectations.

In that case it should probably be left in even though it's not doing anything currently and the change is trivial I think it's best to go with the spec.

Comment thread src/x11/screen.c
int n;
XRRMonitorInfo *m = XRRGetMonitors(xctx.dpy, RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)), true, &n);

if (m == NULL || n == -1) {
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In xrandr.c I see that there's an error check for n == -1 so this check should probably stay and have a separate check for version.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looking at https://cgit.freedesktop.org/xorg/lib/libXrandr/tree/src/XrrMonitor.c it's checking a weird edge case where the server returns 0 monitors, but I guess that's possible. I'll put the check back.

Comment thread src/x11/screen.c Outdated
XRRMonitorInfo *m = XRRGetMonitors(xctx.dpy, RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)), true, &n);

if (m == NULL || n == -1) {
if (randr_minor_version < 5) {
Copy link
Copy Markdown
Member

@tsipinakis tsipinakis Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're only checking for minor < 5 here which is going to break at the next major version. A more complete check would be randr_major_version < 1 || (randr_major_version == 1 && randr_minor_version < 5)

Additionally, there should probably be a more descriptive error message mentioning the outdated version.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@tsipinakis
Copy link
Copy Markdown
Member

@SteveJones Ping, are you still active?

@SteveJones
Copy link
Copy Markdown
Author

Hi yeah, sorry this slipped my mind. I'll try and get this fixed up in the next day or so.

@tsipinakis
Copy link
Copy Markdown
Member

tsipinakis commented Sep 11, 2017

Looks like you misspelled the major version variable.

Have you tested this in a system with an outdated xrandr version (and probably on one with no xrandr installed at all)? Just to confirm that it works as intended.

@SteveJones
Copy link
Copy Markdown
Author

That'll teach me to add in a cosmetic change after testing it builds (it won't).

I've tested it on outdated, XRandR, it's why I wrote it.

Copy link
Copy Markdown
Member

@tsipinakis tsipinakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor mistake after that this should be ready to be merged

Can you squash the commits to avoid polluting the history?

PS: Sorry for the delay (again) you caught me both times on days that I was out.

Comment thread src/x11/screen.c Outdated
void randr_update()
{
if (randr_minor_version < 5) {
if (randr_major_version > 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this just as I was about to click merge:

We're checking for the error condition so it should be randr_major_version < 1

@SteveJones
Copy link
Copy Markdown
Author

Right, fixed that and squashed. Tests just passed. It builds and seems happy. Should be good to go.

@tsipinakis
Copy link
Copy Markdown
Member

It builds and seems happy. Should be good to go.

Apparently not :p Just realised you used tabs, we're using 8 spaces for indentation. should be a quick fix.

@bebehei
Copy link
Copy Markdown
Member

bebehei commented Sep 18, 2017

Apparently not :p Just realised you used tabs, we're using 8 spaces for indentation. should be a quick fix.

If we're so nitpicky now, please also remove the last point on your commit headline. It's a common standard.

@tsipinakis
Copy link
Copy Markdown
Member

If we're so nitpicky now

That's not a nitpick in my opinion, it's adhering to the projects code style else it just becomes a mess.

The commit message format is generally up to the contributor and I don't interfere with that, just give hints about the correct standards (and I didn't actually notice the period this time).

@bebehei bebehei mentioned this pull request Oct 15, 2017
@tsipinakis
Copy link
Copy Markdown
Member

Ping @SteveJones

Due to the way Xlib handles errors XRRGetMonitors will cause dunst to exit if
the server doesn't support version 1.5 of RandR. The check for null is
effectively dead code but in theory the number of monitors can be < 1 so treat
this as an error. Change the code to fetch the RandR version and fallback if
the version is less than 1.5 when getting monitors.

This fix was brought up by @SteveJones on GitHub
Albeit it's possible to run with XRandR extension < 1.5,
dunst needs the headers of libxrandr 1.5.
@bebehei
Copy link
Copy Markdown
Member

bebehei commented Nov 2, 2017

I misused my privileges the first time now pushed the stylefixes to this PR.

@bebehei bebehei requested a review from tsipinakis November 2, 2017 22:59
@tsipinakis tsipinakis merged commit fd81bd1 into dunst-project:master Nov 4, 2017
karlicoss pushed a commit to karlicoss/dunst that referenced this pull request Mar 21, 2019
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

Successfully merging this pull request may close these issues.

3 participants