kranewm

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

layout.hh (5563B)


      1 #ifndef __LAYOUT_H_GUARD__
      2 #define __LAYOUT_H_GUARD__
      3 
      4 #include "cycle.hh"
      5 #include "placement.hh"
      6 #include "../winsys/decoration.hh"
      7 #include "../winsys/util.hh"
      8 
      9 #include <vector>
     10 #include <deque>
     11 #include <unordered_map>
     12 
     13 class LayoutHandler final
     14 {
     15     typedef std::deque<Client_ptr>::const_iterator client_iter;
     16     typedef std::vector<Placement>& placement_vector;
     17 
     18 public:
     19     enum class LayoutKind
     20     {
     21         /// free layouts
     22         Float,
     23         FramelessFloat,
     24         SingleFloat,
     25         FramelessSingleFloat,
     26 
     27         // overlapping tiled layouts
     28         Center,
     29         Monocle,
     30         MainDeck,
     31         StackDeck,
     32         DoubleDeck,
     33 
     34         // non-overlapping tiled layouts
     35         Paper,
     36         CompactPaper,
     37         DoubleStack,
     38         CompactDoubleStack,
     39         HorizontalStack,
     40         CompactHorizontalStack,
     41         VerticalStack,
     42         CompactVerticalStack,
     43     };
     44 
     45 private:
     46     typedef struct Layout final
     47     {
     48         typedef struct LayoutData final
     49         {
     50             constexpr static std::size_t MAX_MAIN_COUNT = 16;
     51             constexpr static std::size_t MAX_GAP_SIZE = 300;
     52             constexpr static winsys::Extents MAX_MARGIN
     53                 = winsys::Extents { 700, 700, 400, 400 };
     54 
     55             LayoutData(
     56                 winsys::Extents margin,
     57                 std::size_t gap_size,
     58                 std::size_t main_count,
     59                 float main_factor
     60             )
     61                 : margin(margin),
     62                   gap_size(gap_size),
     63                   main_count(main_count),
     64                   main_factor(main_factor)
     65             {}
     66 
     67             // generic layout data
     68             winsys::Extents margin;
     69             std::size_t gap_size;
     70 
     71             // tiled layout data
     72             std::size_t main_count;
     73             float main_factor;
     74         }* LayoutData_ptr;
     75 
     76     private:
     77         struct LayoutConfig final
     78         {
     79             Placement::PlacementMethod method;
     80             winsys::Decoration decoration;
     81             bool margin;
     82             bool gap;
     83             bool persistent;
     84             bool single;
     85             bool wraps;
     86         };
     87 
     88     public:
     89         Layout(LayoutKind);
     90         ~Layout();
     91 
     92         inline bool
     93         operator==(const Layout& other) const
     94         {
     95             return other.kind == kind;
     96         }
     97 
     98         const LayoutKind kind;
     99         const LayoutConfig config;
    100 
    101         const LayoutData default_data;
    102         Cycle<LayoutData_ptr> data;
    103 
    104         static LayoutConfig kind_to_config(LayoutKind kind);
    105         static LayoutData kind_to_default_data(LayoutKind kind);
    106 
    107     }* Layout_ptr;
    108 
    109 public:
    110     LayoutHandler();
    111     ~LayoutHandler();
    112 
    113     void arrange(winsys::Region, placement_vector, client_iter, client_iter) const;
    114 
    115     LayoutKind kind() const;
    116     void set_kind(LayoutKind);
    117     void set_prev_kind();
    118 
    119     bool layout_is_free() const;
    120     bool layout_has_margin() const;
    121     bool layout_has_gap() const;
    122     bool layout_is_persistent() const;
    123     bool layout_is_single() const;
    124     bool layout_wraps() const;
    125 
    126     std::size_t gap_size() const;
    127     std::size_t main_count() const;
    128     float main_factor() const;
    129     winsys::Extents margin() const;
    130 
    131     void copy_data_from_prev_layout();
    132     void set_prev_layout_data();
    133 
    134     void change_gap_size(Util::Change<int>);
    135     void change_main_count(Util::Change<int>);
    136     void change_main_factor(Util::Change<float>);
    137     void change_margin(Util::Change<int>);
    138     void change_margin(winsys::Edge, Util::Change<int>);
    139     void reset_gap_size();
    140     void reset_margin();
    141     void reset_layout_data();
    142     void cycle_layout_data(winsys::Direction);
    143 
    144     void save_layout(std::size_t) const;
    145     void load_layout(std::size_t);
    146 
    147 private:
    148     LayoutKind m_kind;
    149     LayoutKind m_prev_kind;
    150 
    151     std::unordered_map<LayoutKind, Layout_ptr> m_layouts;
    152 
    153     Layout_ptr mp_layout;
    154     Layout_ptr mp_prev_layout;
    155 
    156     void arrange_float(winsys::Region, placement_vector, client_iter, client_iter) const;
    157     void arrange_frameless_float(winsys::Region, placement_vector, client_iter, client_iter) const;
    158     void arrange_single_float(winsys::Region, placement_vector, client_iter, client_iter) const;
    159     void arrange_frameless_single_float(winsys::Region, placement_vector, client_iter, client_iter) const;
    160     void arrange_center(winsys::Region, placement_vector, client_iter, client_iter) const;
    161     void arrange_monocle(winsys::Region, placement_vector, client_iter, client_iter) const;
    162     void arrange_main_deck(winsys::Region, placement_vector, client_iter, client_iter) const;
    163     void arrange_stack_deck(winsys::Region, placement_vector, client_iter, client_iter) const;
    164     void arrange_double_deck(winsys::Region, placement_vector, client_iter, client_iter) const;
    165     void arrange_paper(winsys::Region, placement_vector, client_iter, client_iter) const;
    166     void arrange_compact_paper(winsys::Region, placement_vector, client_iter, client_iter) const;
    167     void arrange_double_stack(winsys::Region, placement_vector, client_iter, client_iter) const;
    168     void arrange_compact_double_stack(winsys::Region, placement_vector, client_iter, client_iter) const;
    169     void arrange_horizontal_stack(winsys::Region, placement_vector, client_iter, client_iter) const;
    170     void arrange_compact_horizontal_stack(winsys::Region, placement_vector, client_iter, client_iter) const;
    171     void arrange_vertical_stack(winsys::Region, placement_vector, client_iter, client_iter) const;
    172     void arrange_compact_vertical_stack(winsys::Region, placement_vector, client_iter, client_iter) const;
    173 
    174 };
    175 
    176 #endif//__LAYOUT_H_GUARD__