model.hh (7662B)
1 #pragma once 2 3 #include <kranewl/common.hh> 4 #include <kranewl/cycle.hh> 5 #include <kranewl/geometry.hh> 6 #include <kranewl/input/bindings.hh> 7 #include <kranewl/layout.hh> 8 #include <kranewl/placement.hh> 9 #include <kranewl/rules.hh> 10 #include <kranewl/search.hh> 11 #include <kranewl/tree/layer.hh> 12 #include <kranewl/tree/view.hh> 13 14 #include <optional> 15 #include <string> 16 #include <unordered_map> 17 #include <variant> 18 19 extern "C" { 20 #include <sys/types.h> 21 } 22 23 typedef class Output* Output_ptr; 24 typedef class Context* Context_ptr; 25 typedef class Workspace* Workspace_ptr; 26 typedef class Server* Server_ptr; 27 typedef struct View* View_ptr; 28 typedef struct XWayland* XWayland_ptr; 29 typedef struct XDGView* XDGView_ptr; 30 #ifdef XWAYLAND 31 typedef struct XWaylandView* XWaylandView_ptr; 32 typedef struct XWaylandUnmanaged* XWaylandUnmanaged_ptr; 33 #endif 34 class Config; 35 36 class Model final 37 { 38 public: 39 Model(Config const&); 40 ~Model(); 41 42 void evaluate_user_env_vars(std::optional<std::string> const&); 43 void retrieve_user_default_rules(std::optional<std::string> const&); 44 void run_user_autostart(std::optional<std::string> const&); 45 46 void register_server(Server_ptr); 47 void exit(); 48 49 View_ptr focused_view() const; 50 Workspace_ptr workspace(Index) const; 51 Context_ptr context(Index) const; 52 Output_ptr output(Index) const; 53 54 Cycle<Output_ptr> const& outputs() const; 55 Cycle<Context_ptr> const& contexts() const; 56 Cycle<Workspace_ptr> const& workspaces() const; 57 58 KeyBindings const& key_bindings() const; 59 CursorBindings const& cursor_bindings() const; 60 61 Output_ptr create_output(struct wlr_output*, struct wlr_scene_output*, Region const&&); 62 void register_output(Output_ptr); 63 void unregister_output(Output_ptr); 64 void output_reserve_context(Output_ptr); 65 66 XDGView_ptr create_xdg_shell_view(struct wlr_xdg_surface*, Seat_ptr); 67 #ifdef XWAYLAND 68 XWaylandView_ptr create_xwayland_view( 69 struct wlr_xwayland_surface*, 70 Seat_ptr, 71 XWayland_ptr 72 ); 73 74 XWaylandUnmanaged_ptr create_xwayland_unmanaged( 75 struct wlr_xwayland_surface*, 76 Seat_ptr, 77 XWayland_ptr 78 ); 79 80 void destroy_unmanaged(XWaylandUnmanaged_ptr); 81 #endif 82 void initialize_view(View_ptr, Workspace_ptr); 83 void register_view(View_ptr, Workspace_ptr); 84 void unregister_view(View_ptr); 85 void destroy_view(View_ptr); 86 87 Layer_ptr create_layer(struct wlr_layer_surface_v1*, Output_ptr, SceneLayer); 88 void register_layer(Layer_ptr); 89 90 void focus_view(View_ptr); 91 void refocus(); 92 void place_view(Placement&); 93 void relayer_view(View_ptr, SceneLayer); 94 95 bool view_matches_search(View_ptr, SearchSelector const&) const; 96 View_ptr search_view(SearchSelector const&); 97 void jump_view(SearchSelector const&); 98 99 void focus_output(Output_ptr); 100 101 void cursor_interactive(Cursor::Mode, View_ptr); 102 void abort_cursor_interactive(); 103 104 void cycle_focus(Direction); 105 void cycle_focus_track(Direction); 106 void drag_focus_track(Direction); 107 108 void toggle_track(); 109 void activate_track(SceneLayer); 110 void cycle_track(Direction); 111 112 void sync_focus(); 113 void relayer_views(Workspace_ptr); 114 void relayer_views(Context_ptr); 115 void relayer_views(Output_ptr); 116 void move_view_to_track(View_ptr, SceneLayer, bool = false); 117 118 void reverse_views(); 119 void rotate_views(Direction); 120 void shuffle_main(Direction); 121 void shuffle_stack(Direction); 122 123 void move_focus_to_workspace(Index); 124 void move_view_to_workspace(View_ptr, Index); 125 void move_view_to_workspace(View_ptr, Workspace_ptr); 126 void move_focus_to_next_workspace(Direction); 127 void move_view_to_next_workspace(View_ptr, Direction); 128 void move_focus_to_context(Index); 129 void move_view_to_context(View_ptr, Index); 130 void move_view_to_context(View_ptr, Context_ptr); 131 void move_focus_to_next_context(Direction); 132 void move_view_to_next_context(View_ptr, Direction); 133 void move_focus_to_output(Index); 134 void move_view_to_output(View_ptr, Index); 135 void move_view_to_output(View_ptr, Output_ptr); 136 void move_focus_to_next_output(Direction); 137 void move_view_to_next_output(View_ptr, Direction); 138 void move_view_to_focused_output(View_ptr); 139 140 void toggle_workspace(); 141 void toggle_workspace_current_context(); 142 void activate_next_workspace(Direction); 143 void activate_next_workspace_current_context(Direction); 144 void activate_workspace(Index); 145 void activate_workspace_current_context(Index); 146 void activate_workspace(Workspace_ptr); 147 void toggle_context(); 148 void activate_next_context(Direction); 149 void activate_context(Index); 150 void activate_context(Context_ptr); 151 void toggle_output(); 152 void activate_output(Index); 153 void activate_output(Output_ptr); 154 155 void toggle_layout(); 156 void set_layout(LayoutHandler::LayoutKind); 157 void set_layout_retain_region(LayoutHandler::LayoutKind); 158 159 void toggle_layout_data(); 160 void cycle_layout_data(Direction); 161 void copy_data_from_prev_layout(); 162 163 void change_gap_size(Util::Change<int>); 164 void change_main_count(Util::Change<int>); 165 void change_main_factor(Util::Change<float>); 166 void change_margin(Util::Change<int>); 167 void change_margin(Edge, Util::Change<int>); 168 void reset_gap_size(); 169 void reset_margin(); 170 void reset_layout_data(); 171 172 void save_layout(std::size_t) const; 173 void load_layout(std::size_t); 174 175 void apply_layout(Index); 176 void apply_layout(Workspace_ptr); 177 178 void kill_focus(); 179 void kill_view(View_ptr); 180 181 void set_floating_focus(Toggle); 182 void set_floating_view(Toggle, View_ptr); 183 void set_fullscreen_focus(Toggle); 184 void set_fullscreen_view(Toggle, View_ptr); 185 void set_sticky_focus(Toggle); 186 void set_sticky_view(Toggle, View_ptr); 187 void set_contained_focus(Toggle); 188 void set_contained_view(Toggle, View_ptr); 189 void set_invincible_focus(Toggle); 190 void set_invincible_view(Toggle, View_ptr); 191 void set_iconifyable_focus(Toggle); 192 void set_iconifyable_view(Toggle, View_ptr); 193 void set_iconify_focus(Toggle); 194 void set_iconify_view(Toggle, View_ptr); 195 196 void center_focus(); 197 void center_view(View_ptr); 198 void nudge_focus(Edge, Util::Change<std::size_t>); 199 void nudge_view(Edge, Util::Change<std::size_t>, View_ptr); 200 void stretch_focus(Edge, Util::Change<int>); 201 void stretch_view(Edge, Util::Change<int>, View_ptr); 202 void inflate_focus(Util::Change<int>); 203 void inflate_view(Util::Change<int>, View_ptr); 204 void snap_focus(uint32_t); 205 void snap_view(View_ptr, uint32_t); 206 207 void pop_deiconify(); 208 void deiconify_all(); 209 210 void set_focus_follows_cursor(Toggle, Workspace_ptr); 211 void set_focus_follows_cursor(Toggle, Context_ptr); 212 213 void spawn_external(std::string&&) const; 214 215 Output_ptr mp_output; 216 Context_ptr mp_context; 217 Workspace_ptr mp_workspace; 218 219 private: 220 Server_ptr mp_server; 221 Config const& m_config; 222 223 bool m_running; 224 225 Cycle<Output_ptr> m_outputs; 226 Cycle<Context_ptr> m_contexts; 227 Cycle<Workspace_ptr> m_workspaces; 228 229 Output_ptr mp_prev_output; 230 Context_ptr mp_prev_context; 231 Workspace_ptr mp_prev_workspace; 232 233 std::unordered_map<Uid, View_ptr> m_view_map; 234 std::unordered_map<Uid, Node_ptr> m_unmanaged_map; 235 std::unordered_map<pid_t, View_ptr> m_pid_map; 236 std::unordered_map<View_ptr, Region> m_fullscreen_map; 237 238 std::vector<View_ptr> m_sticky_views; 239 240 View_ptr mp_focus; 241 View_ptr mp_jumped_from; 242 243 std::vector<std::tuple<SearchSelector_ptr, Rules>> m_default_rules; 244 245 const KeyBindings m_key_bindings; 246 const CursorBindings m_cursor_bindings; 247 248 };