In yesterday's post, I mentioned that I was going to be refactoring my classes to inherit from the generated QtWayland::CLASS interfaces from QtWaylandScanner.Excluding one function that I still need to mull over a bit on how I want to implement (my WaylandOutputHead::zwlr_output_head_v1_current_mode function), I have completely refactored my chonker WaylandOutputManager class 🥳Structured it in the following way:
WaylandOrchestrator - This is the top level singleton class that will handle the global registry and the output manager. It will have a ref to the WaylandOutputManager so I can go from the singleton -> manager -> function like getting the output heads.
WaylandOutputManager - This class handles the output heads. It inherits from QtWayland::zwlr_output_manager_v1, has a QList of WaylandOutputHead (moved it from std::vector since I might as well while I am moving it all over to Qt bits anyways) and our function for getting a specific output head based on its serial.
WaylandOutputHead - This class handles an individual output head. It inherits from QtWayland::zwlr_output_head_v1 and has all the properties of an output head (name, description, size, modes (which is a QList of WaylandOutputMode), position, scale, etc.).
WaylandOutputMode - This class handles an individual output mode. It inherits from QtWayland::zwlr_output_mode_v1 and has all the properties of an output mode (width, height, refresh rate, flags, etc.).
Each of these classes now has their respective function overrides for specific Wayland events. To list a few:
WaylandOutputManager::zwlr_output_manager_v1_head - This is called when a new output head is added to the manager.
WaylandOutputHead::zwlr_output_head_v1_name - This is called when the name of the output head changes or during the first roundtrip. It is a very simple function that just sets the internal member to the new name.
WaylandOutputHead::zwlr_output_head_v1_mode - This is called when we get a new mode for the output head. It will create a new WaylandOutputMode object and add it to the list of modes for the head.
WaylandOutputMode::zwlr_output_mode_v1_size - This is called when the size of the mode changes or during the first roundtrip.
Separating them all out feels just so much more ergonomic and easier to parse.Plan for tomorrow is to go through the rest of my code where I was using WaylandOutputManager and swap them over to the orchestrator, then hook up some signals / slots that I set up today as I was working on the classes. After all, that's the reason I shifted it to being a Qt application instead of a generic C++ one at all -- the Qt event loop and signals / slots make callbacks much easier!Will be interesting to see if this thing flies when all is said and done 🙂