diff -r 039b3f8a3442 -r b498160cc2ab src/X11Command.h --- a/src/X11Command.h Mon Apr 05 15:37:28 2021 +0200 +++ b/src/X11Command.h Mon Apr 05 18:09:25 2021 +0200 @@ -125,19 +125,17 @@ int proximityOut = UNUSED; } eventType; - void registerEvents(const Display& display, const XDeviceInfo* deviceInfo) { + void registerEvents(const Display& display, int screen, const XDeviceInfo* deviceInfo) { bool registerProximityEvents = false; // TODO: proximity? Device device; Window window; - int screen; int eventCount = 0; XEventClass events[7]; // TODO: check array size XInputClassInfo* classInfo; int classIndex; - screen = DefaultScreen(display.display); window = RootWindow(display.display, screen); // TODO: configurable window from which we capture the events or optionally open our own window (can also provide some visual feedback/info) // Currently we can do something like: @@ -198,7 +196,8 @@ devices.items = XListInputDevices(display.display, &devices.size); for (int i = 0; i < devices.size; i++) { if (devices[i]->type) { - registerEvents(display, devices[i]); + for (int screenCount = XScreenCount(display.display), screen = 0; screen < screenCount; screen++) + registerEvents(display, screen, devices[i]); } } } @@ -297,8 +296,7 @@ } writer->writeAttribute(std::to_wstring(window)); - // writer->writeAttribute(std::to_wstring(screen?)); - // writer->writeAttribute(std::to_wstring(root_win)); + writer->writeAttribute(std::to_wstring(windowAttributes.root)); writer->writeAttribute(std::to_wstring(parentWindow)); writer->writeAttribute(&level, typeid (level)); writer->writeAttribute(fetchWindowName(display, window)); @@ -317,8 +315,7 @@ void listWindows(const Display& display, Configuration& configuration, std::shared_ptr writer, std::function relationalWriterFlush) { writer->startRelation(L"x11_window",{ {L"id", relpipe::writer::TypeId::INTEGER}, - // {L"screen", relpipe::writer::TypeId::INTEGER}, - // {L"root", relpipe::writer::TypeId::INTEGER}, + {L"root", relpipe::writer::TypeId::INTEGER}, {L"parent", relpipe::writer::TypeId::INTEGER}, {L"level", relpipe::writer::TypeId::INTEGER}, {L"name", relpipe::writer::TypeId::STRING}, @@ -330,10 +327,36 @@ {L"height", relpipe::writer::TypeId::INTEGER}, }, true); - int screen = DefaultScreen(display.display); - Window window = RootWindow(display.display, screen); + for (int screenCount = XScreenCount(display.display), screen = 0; screen < screenCount; screen++) { + Window root = RootWindow(display.display, screen); + listWindow(display, root, 0, configuration, writer, relationalWriterFlush); + } + } - listWindow(display, window, 0, configuration, writer, relationalWriterFlush); + void listScreens(const Display& display, Configuration& configuration, std::shared_ptr writer, std::function relationalWriterFlush) { + writer->startRelation(L"x11_screen",{ + {L"id", relpipe::writer::TypeId::INTEGER}, + {L"root", relpipe::writer::TypeId::INTEGER}, + {L"width", relpipe::writer::TypeId::INTEGER}, + {L"height", relpipe::writer::TypeId::INTEGER}, + // {L"width_mm", relpipe::writer::TypeId::INTEGER}, + // {L"height_mm", relpipe::writer::TypeId::INTEGER}, + }, true); + + for (int screenCount = XScreenCount(display.display), screen = 0; screen < screenCount; screen++) { + Window root = RootWindow(display.display, screen); + XWindowAttributes attributes; + if (!XGetWindowAttributes(display.display, root, &attributes)) + throw std::invalid_argument("Unable to get attributes for window: " + std::to_string(root)); + + writer->writeAttribute(std::to_wstring(screen)); + writer->writeAttribute(std::to_wstring(root)); + writer->writeAttribute(std::to_wstring(attributes.width)); + writer->writeAttribute(std::to_wstring(attributes.height)); + // writer->writeAttribute(std::to_wstring(attributes.screen->mwidth)); + // writer->writeAttribute(std::to_wstring(attributes.screen->mheight)); + } + } static int handleXError(::Display* display, XErrorEvent* errorEvent) { @@ -362,7 +385,7 @@ if (configuration.listInputDevices) listInputDevices(display, configuration, writer, relationalWriterFlush); if (configuration.listInputEvents) listInputEvents(display, configuration, writer, relationalWriterFlush); if (configuration.listWindows) listWindows(display, configuration, writer, relationalWriterFlush); - // TODO: list screens + if (configuration.listScreens) listScreens(display, configuration, writer, relationalWriterFlush); } else { throw std::invalid_argument("Unable to open display. Please check the $DISPLAY variable."); }