# HG changeset patch # User František Kučera # Date 1617638965 -7200 # Node ID b498160cc2abb91ce953d9acfbd55490fae4abaf # Parent 039b3f8a344244750b2fff0477ac586be85b5677 list screens: --list-screens + support multiple screens in --list-windows and --list-input-events diff -r 039b3f8a3442 -r b498160cc2ab bash-completion.sh --- a/bash-completion.sh Mon Apr 05 15:37:28 2021 +0200 +++ b/bash-completion.sh Mon Apr 05 18:09:25 2021 +0200 @@ -30,11 +30,13 @@ if [[ "$w1" == "--list-input-devices" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w1" == "--list-input-events" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) elif [[ "$w1" == "--list-windows" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) + elif [[ "$w1" == "--list-screens" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) else OPTIONS=( "--list-input-devices" "--list-input-events" "--list-windows" + "--list-screens" ) COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) fi diff -r 039b3f8a3442 -r b498160cc2ab src/CLIParser.h --- a/src/CLIParser.h Mon Apr 05 15:37:28 2021 +0200 +++ b/src/CLIParser.h Mon Apr 05 18:09:25 2021 +0200 @@ -51,6 +51,7 @@ static const relpipe::common::type::StringX OPTION_LIST_INPUT_DEVICES; static const relpipe::common::type::StringX OPTION_LIST_INPUT_EVENTS; static const relpipe::common::type::StringX OPTION_LIST_WINDOWS; + static const relpipe::common::type::StringX OPTION_LIST_SCREENS; Configuration parse(const std::vector& arguments) { Configuration c; @@ -66,6 +67,8 @@ c.listInputEvents = parseBoolean(readNext(arguments, i)); } else if (option == OPTION_LIST_WINDOWS) { c.listWindows = parseBoolean(readNext(arguments, i)); + } else if (option == OPTION_LIST_SCREENS) { + c.listScreens = parseBoolean(readNext(arguments, i)); } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); } @@ -79,6 +82,7 @@ const relpipe::common::type::StringX CLIParser::OPTION_LIST_INPUT_DEVICES = L"--list-input-devices"; const relpipe::common::type::StringX CLIParser::OPTION_LIST_INPUT_EVENTS = L"--list-input-events"; const relpipe::common::type::StringX CLIParser::OPTION_LIST_WINDOWS = L"--list-windows"; +const relpipe::common::type::StringX CLIParser::OPTION_LIST_SCREENS = L"--list-screens"; } } diff -r 039b3f8a3442 -r b498160cc2ab src/Configuration.h --- a/src/Configuration.h Mon Apr 05 15:37:28 2021 +0200 +++ b/src/Configuration.h Mon Apr 05 18:09:25 2021 +0200 @@ -31,6 +31,7 @@ bool listInputDevices = false; bool listInputEvents = false; bool listWindows = false; + bool listScreens = false; virtual ~Configuration() { } 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."); }