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

Using xcb-randr I can not get current screen resources #29

Open
mrosset opened this issue May 14, 2023 · 1 comment
Open

Using xcb-randr I can not get current screen resources #29

mrosset opened this issue May 14, 2023 · 1 comment

Comments

@mrosset
Copy link

mrosset commented May 14, 2023

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;
}
@medranocalvo
Copy link
Contributor

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.

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

2 participants