1 #ifndef CLIENTMANAGER_H
2 #define CLIENTMANAGER_H
3 
4 #include <X11/X.h>
5 #include <unordered_map>
6 
7 #include "commandio.h"
8 #include "link.h"
9 #include "object.h"
10 #include "signal.h"
11 
12 class Client;
13 class ClientChanges;
14 class Completion;
15 class Ewmh;
16 class HSTag;
17 class Settings;
18 class Theme;
19 
20 // Note: this is basically a singleton
21 
22 class ClientManager : public Object
23 {
24 public:
25     ClientManager();
26     ~ClientManager() override;
27     void injectDependencies(Settings* s, Theme* t, Ewmh* e);
28 
29     Client* client(Window window);
30     Client* client(const std::string &identifier);
31     void completeClients(Completion& complete);
32     const std::unordered_map<Window, Client*>&
clients()33     clients() { return clients_; }
34 
35     void add(Client* client);
36     void remove(Window window);
37 
38     void unmap_notify(Window win);
39     void force_unmanage(Client* client);
40 
41     void setDragged(Client* client);
42 
43     Signal_<HSTag*> needsRelayout;
44     Signal_<Client*> clientStateChanged; //! floating or minimized changed
45     Link_<Client> focus;
46     Link_<Client> dragged;
47 
48     int pseudotile_cmd(Input input, Output output);
49     int fullscreen_cmd(Input input, Output output);
50     void pseudotile_complete(Completion& complete);
51     void fullscreen_complete(Completion& complete);
52 
53     // adds a new client to list of managed client windows
54     Client* manage_client(Window win, bool visible_already, bool force_unmanage,
55                           std::function<void(ClientChanges&)> additionalRules = {});
56     ClientChanges applyDefaultRules(Window win);
57 
58     int applyRulesCmd(Input input, Output output);
59     int applyRules(Client* client, Output output, bool changeFocus = true);
60     int applyChanges(Client* client, ClientChanges changes, Output output);
61     void applyRulesCompletion(Completion& complete);
62     int applyTmpRuleCmd(Input input, Output output);
63     void applyTmpRuleCompletion(Completion& complete);
64 
65 protected:
66     int clientSetAttribute(std::string attribute, Input input, Output output);
67     void setSimpleClientAttributes(Client* client, const ClientChanges& changes);
68     Theme* theme;
69     Settings* settings;
70     Ewmh* ewmh;
71     std::unordered_map<Window, Client*> clients_;
72     friend class Client;
73 };
74 
75 #endif
76