xelb icon indicating copy to clipboard operation
xelb copied to clipboard

Using xcb-randr I can not get current screen resources

Open mrosset opened this issue 2 years ago • 1 comments

Hello, I need to get the dimensions of the current monitor. However when requesting xcb:randr:GetScreenResourcesCurrent . It always returns nil. Here's a simple sexp to demonstrate.

(let* ((conn (xcb:connect))
       (setup (xcb:get-setup conn))
       (roots (slot-value setup :roots))
       (screen  (car roots))
       (root (slot-value screen :root))
       (reply (xcb:+request-unchecked+reply
		  conn
		  (make-instance 'xcb:randr:GetScreenResourcesCurrent
				 :window root))))
  (xcb:flush conn)
  (xcb:disconnect conn)
  reply)

As you can see reply evals to NIL.

I know this should work because exwm uses it with exwm--root. So I'm not sure what I'm doing wrong here. Or maybe exwm--root is special?

In C my code looks like this, and works as expected.

#include <stdio.h>
#include <xcb/randr.h>
#include <xcb/xcb.h>

int
main ()
{
  const xcb_setup_t *setup;
  xcb_connection_t *conn;
  xcb_screen_t *screen;
  xcb_window_t root;
  xcb_screen_iterator_t screen_iterator;
  xcb_randr_get_screen_resources_current_reply_t *reply;

  // connect to Xserver
  conn = xcb_connect (NULL, NULL);
  setup = xcb_get_setup (conn);

  // get the root window
  screen_iterator = xcb_setup_roots_iterator (setup);
  screen = screen_iterator.data;
  root = screen->root;

  reply = xcb_randr_get_screen_resources_current_reply (
      conn, xcb_randr_get_screen_resources_current (conn, root), NULL);

  int len = xcb_randr_get_screen_resources_current_outputs_length (reply);

  printf ("Reply:         %p\n", reply);
  printf ("Total Outputs: %d\n", len);

  xcb_flush (conn);

  xcb_disconnect (conn);

  return 0;
}

mrosset avatar May 14 '23 13:05 mrosset

The reason this does not work might be that the XELB XRandr extension is not initialized. This is done by xcb:get-extension-data, see exwm-randr.el:

  (when (= 0 (slot-value (xcb:get-extension-data exwm--connection 'xcb:randr)
                         'present))
    (error "[EXWM] RandR extension is not supported by the server"))

This not documented anywhere (that I've seen) and cost me long hours of astonishment to discover.

medranocalvo avatar Jan 12 '24 08:01 medranocalvo