Xrandr making DisplayWidth() return incorrect value?

16 views Asked by At

I'm beginning to work on a window manager in X using xlib. My window manager is called Bonsai and I am running DWM for my own use.

For running both of these I have an xinit file (.xinitrc for dwm and .bonsairc for my own) which I use with startx to launch the server and wm. The final lines of both of these files is xrandr --output DP-3 --mode 1920x1080 --rate 165 --output HDMI-1 --same-as DP-3 & exec <wm>, where is the path to the binary for the wm to launch it.

One of the first things I do within my wm (and it is done very similarly in dwm, looking at the source), is get the screen width with the macro call DisplayWidth() on the opened display. For debugging I am just printing this to stderr so I can log it. The code looks like this

    dpy = XOpenDisplay(NULL);
    if (!dpy) {
        fprintf(stderr, "display didn't open.");
        return EXIT_FAILURE;
    }
    screen = DefaultScreen(dpy);
    sw = DisplayWidth(dpy, screen);
    sh = DisplayHeight(dpy, screen);
    fprintf(stderr, "%dX%d\n", sw, sh);
    ...

The issue I am running into is that this erroneously reports '3840x1080', which is twice as wide as is expected. I have no issues with my resolution/screen dimensions when I am using DWM (which uses the same xinit as described), but when I replace --output HDMI-1 --same-as DP-3 with --output HDMI-1 --off, the error is fixed and it correctly reports 1920x1080.

0

There are 0 answers