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