kranewm

An ICCCM & EWMH compliant X11 reparenting, dynamic window manager, written in C++
git clone git://git.deurzen.net/kranewm
Log | Files | Refs | LICENSE

context.hh (3444B)


      1 #ifndef __CONTEXT_H_GUARD__
      2 #define __CONTEXT_H_GUARD__
      3 
      4 #include "../winsys/common.hh"
      5 #include "cycle.hh"
      6 
      7 #include <string>
      8 #include <unordered_set>
      9 
     10 typedef class Client* Client_ptr;
     11 typedef class Workspace* Workspace_ptr;
     12 typedef class Partition* Partition_ptr;
     13 
     14 typedef class Context final
     15 {
     16 public:
     17     Context(Index index, std::string name)
     18         : m_index(index),
     19           m_name(name),
     20           mp_partition(nullptr),
     21           mp_active(nullptr),
     22           mp_prev_active(nullptr),
     23           m_workspaces({}, true)
     24     {}
     25 
     26     Index
     27     index() const
     28     {
     29         return m_index;
     30     }
     31 
     32     std::string const&
     33     name() const
     34     {
     35         return m_name;
     36     }
     37 
     38     std::size_t
     39     size() const
     40     {
     41         return m_workspaces.size();
     42     }
     43 
     44     Workspace_ptr
     45     workspace() const
     46     {
     47         return mp_active;
     48     }
     49 
     50     Workspace_ptr
     51     prev_workspace() const
     52     {
     53         return mp_prev_active;
     54     }
     55 
     56     Partition_ptr
     57     partition() const
     58     {
     59         return mp_partition;
     60     }
     61 
     62     bool
     63     is_partitioned() const
     64     {
     65         return mp_partition != nullptr;
     66     }
     67 
     68     void
     69     set_partition(Partition_ptr partition)
     70     {
     71         mp_partition = partition;
     72     }
     73 
     74     void
     75     register_workspace(Workspace_ptr workspace)
     76     {
     77         m_workspaces.insert_at_back(workspace);
     78     }
     79 
     80     void
     81     activate_workspace(Index index)
     82     {
     83         Workspace_ptr prev_active = mp_active;
     84         m_workspaces.activate_at_index(index);
     85         mp_active = *m_workspaces.active_element();
     86 
     87         if (prev_active != mp_active)
     88             mp_prev_active = prev_active;
     89     }
     90 
     91     void
     92     activate_workspace(Workspace_ptr workspace)
     93     {
     94         Workspace_ptr prev_active = mp_active;
     95         m_workspaces.activate_element(workspace);
     96         mp_active = workspace;
     97 
     98         if (prev_active != mp_active)
     99             mp_prev_active = prev_active;
    100     }
    101 
    102     Cycle<Workspace_ptr> const&
    103     workspaces() const
    104     {
    105         return m_workspaces;
    106     }
    107 
    108     void
    109     register_sticky_client(Client_ptr client)
    110     {
    111         m_sticky_clients.insert(client);
    112     }
    113 
    114     void
    115     unregister_sticky_client(Client_ptr client)
    116     {
    117         m_sticky_clients.erase(client);
    118     }
    119 
    120     std::unordered_set<Client_ptr> const&
    121     sticky_clients() const
    122     {
    123         return m_sticky_clients;
    124     }
    125 
    126     std::deque<Workspace_ptr>::iterator
    127     begin()
    128     {
    129         return m_workspaces.begin();
    130     }
    131 
    132     std::deque<Workspace_ptr>::const_iterator
    133     begin() const
    134     {
    135         return m_workspaces.begin();
    136     }
    137 
    138     std::deque<Workspace_ptr>::const_iterator
    139     cbegin() const
    140     {
    141         return m_workspaces.cbegin();
    142     }
    143 
    144     std::deque<Workspace_ptr>::iterator
    145     end()
    146     {
    147         return m_workspaces.end();
    148     }
    149 
    150     std::deque<Workspace_ptr>::const_iterator
    151     end() const
    152     {
    153         return m_workspaces.end();
    154     }
    155 
    156     std::deque<Workspace_ptr>::const_iterator
    157     cend() const
    158     {
    159         return m_workspaces.cend();
    160     }
    161 
    162     Workspace_ptr
    163     operator[](std::size_t i)
    164     {
    165         return m_workspaces[i];
    166     }
    167 
    168     Workspace_ptr
    169     operator[](std::size_t i) const
    170     {
    171         return m_workspaces[i];
    172     }
    173 
    174 private:
    175     Index m_index;
    176     std::string m_name;
    177 
    178     Partition_ptr mp_partition;
    179 
    180     Workspace_ptr mp_active;
    181     Workspace_ptr mp_prev_active;
    182 
    183     Cycle<Workspace_ptr> m_workspaces;
    184     std::unordered_set<Client_ptr> m_sticky_clients;
    185 
    186 }* Context_ptr;
    187 
    188 #endif//__CONTEXT_H_GUARD__