Skip to content
  • Martin Flöser's avatar
    [kwin] Use std::find_if and lambda functions for Workspace::findClient · bc0a9cb5
    Martin Flöser authored
    Instead of passing the macro based Predicate to findClient it now
    expects a function which can be passed to std::find_if.
    
    Existing code like:
    xcb_window_t window; // our test window
    Client *c = findClient(WindowMatchPredicated(window));
    
    becomes:
    Client *c = findClient([window](const Client *c) {
        return c->window() == window;
    });
    
    The advantage is that it is way more flexible and has the logic what
    to check for directly with the code and not hidden in the macro
    definition.
    
    In addition there is a simplified overload for the very common case of
    matching a window id against one of Client's windows. This overloaded
    method takes a Predicate and the window id.
    
    Above example becomes:
    Client *c = findClient(Predicate::WindowMatch, w);
    
    Existing code is migrated to use the simplified method taking
    MatchPredicate and window id. The very few cases where a more complex
    condition is tested the lambda function is used. As these are very
    local tests only used in one function it's not worthwhile to add further
    overloads to the findClient method in Workspace.
    
    With this change all the Predicate macro definitions are removed from
    utils.h as they are now completely unused.
    
    REVIEW: 116916
    bc0a9cb5