kranewm

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

screen.hh (2753B)


      1 #ifndef __WINSYS_SCREEN_H_GUARD__
      2 #define __WINSYS_SCREEN_H_GUARD__
      3 
      4 #include "common.hh"
      5 #include "geometry.hh"
      6 #include "window.hh"
      7 #include "util.hh"
      8 
      9 #include <set>
     10 #include <unordered_map>
     11 #include <vector>
     12 
     13 namespace winsys
     14 {
     15 
     16     class Screen final
     17     {
     18     public:
     19         Screen(Index index, Region region)
     20             : m_index(index),
     21               m_full_region(region),
     22               m_placeable_region(region),
     23               m_windows({}),
     24               m_struts({
     25                   { Edge::Left,   {{}, s_strut_comparer} },
     26                   { Edge::Top,    {{}, s_strut_comparer} },
     27                   { Edge::Right,  {{}, s_strut_comparer} },
     28                   { Edge::Bottom, {{}, s_strut_comparer} },
     29               }),
     30               m_showing_struts(true)
     31         {}
     32 
     33         Region
     34         full_region() const
     35         {
     36             return m_full_region;
     37         }
     38 
     39         Region
     40         placeable_region() const
     41         {
     42             return m_placeable_region;
     43         }
     44 
     45         bool
     46         showing_struts() const
     47         {
     48             return m_showing_struts;
     49         }
     50 
     51         bool
     52         contains_strut(Window window) const
     53         {
     54             return m_windows.count(window) > 0;
     55         }
     56 
     57         bool
     58         contains(Pos pos) const
     59         {
     60             return m_full_region.contains(pos);
     61         }
     62 
     63         bool
     64         contains(Region region) const
     65         {
     66             return m_full_region.contains(region);
     67         }
     68 
     69         Index
     70         index() const
     71         {
     72             return m_index;
     73         }
     74 
     75         void
     76         set_index(Index index)
     77         {
     78             m_index = index;
     79         }
     80 
     81         std::optional<int>
     82         max_strut_at_edge(winsys::Edge edge)
     83         {
     84             return m_struts.at(edge).empty()
     85                 ? std::nullopt
     86                 : std::optional(m_struts[edge].rbegin()->width);
     87         }
     88 
     89         std::vector<Window> show_and_get_struts(bool);
     90 
     91         void add_struts(std::vector<std::optional<Strut>>);
     92         void add_strut(Edge, Strut);
     93         void add_strut(Edge, Window, int);
     94         void update_strut(Edge, Window, int);
     95         void remove_strut(Window);
     96 
     97         void compute_placeable_region();
     98 
     99     private:
    100         Index m_index;
    101 
    102         Region m_full_region;
    103         Region m_placeable_region;
    104 
    105         static constexpr struct StrutComparer final {
    106             bool
    107             operator()(const Strut& lhs, const Strut& rhs) const
    108             {
    109                 return lhs.width < rhs.width;
    110             }
    111         } s_strut_comparer{};
    112 
    113         std::unordered_map<Window, std::vector<Edge>> m_windows;
    114         std::unordered_map<Edge, std::set<Strut, StrutComparer>> m_struts;
    115 
    116         bool m_showing_struts;
    117 
    118     };
    119 
    120 }
    121 
    122 #endif//__WINSYS_SCREEN_H_GUARD__